-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathshadow-css.ts
40 lines (35 loc) · 940 Bytes
/
shadow-css.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import {Transform, TransformedToken} from 'style-dictionary/types'
import {isShadow} from '../filter/isShadow.js'
import {getValue} from '../utilities/getValue.js'
type TokenShadow = {
color: string
offsetX: string
offsetY: string
blur: string
spread: string
inset: boolean
}
const formatShadow = ({
offsetX = '0',
offsetY = '0',
blur = '0',
spread = '0',
color,
inset = false,
}: TokenShadow): string => `${offsetX} ${offsetY} ${blur} ${spread} ${color} ${inset ? 'inset' : ''}`.trim()
export const shadowCss: Transform = {
name: 'shadow/css',
type: `value`,
transitive: true,
filter: isShadow,
transform: (token: TransformedToken) => {
const tokenValue = getValue<TokenShadow>(token)
if (Array.isArray(tokenValue)) {
return tokenValue.map(formatShadow).join(', ')
}
if (typeof tokenValue === 'object') {
return formatShadow(tokenValue)
}
return tokenValue
},
}