Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions src/css/transformShadow.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
import { SingleBoxShadowToken, BoxShadowTypes } from '@tokens-studio/types';
import { BoxShadowTypes, SingleBoxShadowToken, TokenBoxshadowValue } from '@tokens-studio/types';

export function transformShadow(value: SingleBoxShadowToken['value']) {
const alignShadowType = (val: string) => {
return val === 'innerShadow' || val === 'inset' ? 'inset' : undefined;
/**
* @param {string} val
* @returns {BoxShadowTypes}
*/
const alignShadowType = (val: TokenBoxshadowValue & { inset?: boolean }) => {
if ([BoxShadowTypes.INNER_SHADOW, 'inset'].includes(val.type)) {
val.inset = true;
// TODO: delete lines below in next major change, only have to set inset=true, nothing else
val.type = 'inset' as BoxShadowTypes;
} else if (val.type) {
val.type = undefined as BoxShadowTypes & undefined;
}

// TODO: enable line below in next major change
// delete (val as Partial<TokenBoxshadowValue>).type;
return val;
};

if (Array.isArray(value)) {
return value.map(v => ({
...v,
type: alignShadowType(v.type),
}));
return value.map(alignShadowType);
}

if (typeof value === 'object') {
value.type = alignShadowType(value.type) as BoxShadowTypes;
return alignShadowType(value);
}
return value;
}
4 changes: 4 additions & 0 deletions test/spec/css/transformShadow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('transformShadow', () => {
spread: '0',
color: 'rgba(0,0,0,0.4)',
type: 'inset',
inset: true,
});

expect(
Expand All @@ -42,6 +43,7 @@ describe('transformShadow', () => {
spread: '0',
color: 'rgba(0,0,0,0.4)',
type: 'inset',
inset: true,
});
});

Expand Down Expand Up @@ -75,6 +77,7 @@ describe('transformShadow', () => {
spread: '0',
color: 'rgba(0,0,0,0.4)',
type: 'inset',
inset: true,
},
{
x: '2',
Expand All @@ -83,6 +86,7 @@ describe('transformShadow', () => {
spread: '0',
color: 'rgba(0,0,0,0.4)',
type: 'inset',
inset: true,
},
]);
});
Expand Down