Skip to content

Commit 7fb2939

Browse files
committed
chore: support insert true DTCG shadow, prep TODOs for next major
1 parent 5066620 commit 7fb2939

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

src/css/transformShadow.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
1-
import { SingleBoxShadowToken, BoxShadowTypes } from '@tokens-studio/types';
1+
import { BoxShadowTypes, SingleBoxShadowToken, TokenBoxshadowValue } from '@tokens-studio/types';
22

33
export function transformShadow(value: SingleBoxShadowToken['value']) {
4-
const alignShadowType = (val: string) => {
5-
return val === 'innerShadow' || val === 'inset' ? 'inset' : undefined;
4+
/**
5+
* @param {string} val
6+
* @returns {BoxShadowTypes}
7+
*/
8+
const alignShadowType = (val: TokenBoxshadowValue & { inset?: boolean }) => {
9+
if ([BoxShadowTypes.INNER_SHADOW, 'inset'].includes(val.type)) {
10+
val.inset = true;
11+
// TODO: delete lines below in next major change, only have to set inset=true, nothing else
12+
val.type = 'inset' as BoxShadowTypes;
13+
} else if (val.type) {
14+
val.type = undefined as BoxShadowTypes & undefined;
15+
}
16+
17+
// TODO: enable line below in next major change
18+
// delete (val as Partial<TokenBoxshadowValue>).type;
19+
return val;
620
};
721

822
if (Array.isArray(value)) {
9-
return value.map(v => ({
10-
...v,
11-
type: alignShadowType(v.type),
12-
}));
23+
return value.map(alignShadowType);
1324
}
1425

1526
if (typeof value === 'object') {
16-
value.type = alignShadowType(value.type) as BoxShadowTypes;
27+
return alignShadowType(value);
1728
}
1829
return value;
1930
}

test/spec/css/transformShadow.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ describe('transformShadow', () => {
2323
spread: '0',
2424
color: 'rgba(0,0,0,0.4)',
2525
type: 'inset',
26+
inset: true,
2627
});
2728

2829
expect(
@@ -42,6 +43,7 @@ describe('transformShadow', () => {
4243
spread: '0',
4344
color: 'rgba(0,0,0,0.4)',
4445
type: 'inset',
46+
inset: true,
4547
});
4648
});
4749

@@ -75,6 +77,7 @@ describe('transformShadow', () => {
7577
spread: '0',
7678
color: 'rgba(0,0,0,0.4)',
7779
type: 'inset',
80+
inset: true,
7881
},
7982
{
8083
x: '2',
@@ -83,6 +86,7 @@ describe('transformShadow', () => {
8386
spread: '0',
8487
color: 'rgba(0,0,0,0.4)',
8588
type: 'inset',
89+
inset: true,
8690
},
8791
]);
8892
});

0 commit comments

Comments
 (0)