@atlaskit/primitives 7.0.0 → 7.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +1 -1
- package/CHANGELOG.md +19 -1
- package/LICENSE.md +6 -8
- package/constellation/anchor/code.mdx +3 -3
- package/constellation/anchor/examples.mdx +33 -39
- package/constellation/anchor/usage.mdx +60 -30
- package/constellation/bleed/code.mdx +3 -3
- package/constellation/bleed/examples.mdx +17 -13
- package/constellation/box/code.mdx +3 -3
- package/constellation/box/examples.mdx +25 -19
- package/constellation/box/usage.mdx +15 -5
- package/constellation/flex/code.mdx +3 -3
- package/constellation/flex/examples.mdx +12 -11
- package/constellation/grid/code.mdx +3 -3
- package/constellation/grid/examples.mdx +15 -10
- package/constellation/inline/code.mdx +3 -3
- package/constellation/inline/examples.mdx +32 -38
- package/constellation/inline/usage.mdx +15 -6
- package/constellation/overview/index.mdx +29 -27
- package/constellation/pressable/code.mdx +5 -4
- package/constellation/pressable/examples.mdx +41 -55
- package/constellation/pressable/usage.mdx +59 -36
- package/constellation/responsive/01-show/code.mdx +3 -3
- package/constellation/responsive/01-show/examples.mdx +9 -13
- package/constellation/responsive/02-hide/code.mdx +3 -3
- package/constellation/responsive/02-hide/examples.mdx +9 -13
- package/constellation/responsive/03-breakpoints/examples.mdx +3 -3
- package/constellation/responsive/examples.mdx +10 -10
- package/constellation/responsive/usage.mdx +23 -15
- package/constellation/stack/code.mdx +3 -3
- package/constellation/stack/examples.mdx +26 -20
- package/constellation/stack/usage.mdx +13 -5
- package/constellation/text/code.mdx +3 -3
- package/constellation/text/examples.mdx +29 -15
- package/constellation/text/usage.mdx +6 -3
- package/constellation/xcss/examples.mdx +7 -5
- package/constellation/xcss/migration.mdx +32 -25
- package/constellation/xcss/usage.mdx +72 -60
- package/dist/cjs/components/anchor.js +4 -4
- package/dist/cjs/components/pressable.js +1 -1
- package/dist/cjs/xcss/style-maps.partial.js +13 -13
- package/dist/es2019/components/anchor.js +4 -4
- package/dist/es2019/components/pressable.js +1 -1
- package/dist/es2019/xcss/style-maps.partial.js +13 -13
- package/dist/esm/components/anchor.js +4 -4
- package/dist/esm/components/pressable.js +1 -1
- package/dist/esm/xcss/style-maps.partial.js +13 -13
- package/dist/types/components/anchor.d.ts +4 -4
- package/dist/types/responsive/index.d.ts +2 -2
- package/dist/types/xcss/style-maps.partial.d.ts +13 -13
- package/dist/types-ts4.5/components/anchor.d.ts +4 -4
- package/dist/types-ts4.5/responsive/index.d.ts +2 -2
- package/dist/types-ts4.5/xcss/style-maps.partial.d.ts +13 -13
- package/extract-react-types/anchor-props.tsx +108 -116
- package/extract-react-types/bleed-props.tsx +17 -22
- package/extract-react-types/box-props.tsx +67 -70
- package/extract-react-types/flex-props.tsx +61 -61
- package/extract-react-types/grid-props.tsx +92 -92
- package/extract-react-types/hide-props.tsx +35 -35
- package/extract-react-types/inline-props.tsx +68 -68
- package/extract-react-types/pressable-props.tsx +101 -107
- package/extract-react-types/show-props.tsx +35 -35
- package/extract-react-types/stack-props.tsx +55 -55
- package/package.json +2 -2
- package/report.api.md +940 -965
- package/scripts/border-codegen-template.tsx +40 -47
- package/scripts/codegen-file-templates/dimensions.tsx +8 -8
- package/scripts/codegen-file-templates/layer.tsx +9 -9
- package/scripts/codegen-styles.tsx +97 -103
- package/scripts/color-codegen-template.tsx +61 -73
- package/scripts/elevation-codegen-template.tsx +50 -62
- package/scripts/inverse-color-map-template.tsx +26 -31
- package/scripts/misc-codegen-template.tsx +4 -9
- package/scripts/spacing-codegen-template.tsx +25 -31
- package/scripts/typography-codegen-template.tsx +59 -65
- package/scripts/utils.tsx +36 -43
|
@@ -1,86 +1,74 @@
|
|
|
1
1
|
import format from '@af/formatting/sync';
|
|
2
2
|
import { CURRENT_SURFACE_CSS_VAR } from '@atlaskit/tokens';
|
|
3
|
-
import {
|
|
4
|
-
legacyLightTokens as legacyTokens,
|
|
5
|
-
light as tokens,
|
|
6
|
-
} from '@atlaskit/tokens/tokens-raw';
|
|
3
|
+
import { legacyLightTokens as legacyTokens, light as tokens } from '@atlaskit/tokens/tokens-raw';
|
|
7
4
|
|
|
8
|
-
import {
|
|
9
|
-
capitalize,
|
|
10
|
-
constructTokenFunctionCall,
|
|
11
|
-
type ShadowDefinition,
|
|
12
|
-
} from './utils';
|
|
5
|
+
import { capitalize, constructTokenFunctionCall, type ShadowDefinition } from './utils';
|
|
13
6
|
|
|
14
7
|
type Token = {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
8
|
+
token: string;
|
|
9
|
+
fallback: string | ShadowDefinition;
|
|
10
|
+
isDeprecated: boolean;
|
|
18
11
|
};
|
|
19
12
|
|
|
20
13
|
// NB: Fallback CSS variables can be deleted when tokens are no longer behind a feature flag
|
|
21
14
|
const tokenStyles = {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
filterFn: <T extends Token>(t: T) =>
|
|
41
|
-
t.token.startsWith(tokenStyles.surface.prefix),
|
|
42
|
-
},
|
|
15
|
+
opacity: {
|
|
16
|
+
objectName: 'opacity',
|
|
17
|
+
prefix: 'opacity.',
|
|
18
|
+
cssProperty: 'opacity',
|
|
19
|
+
filterFn: <T extends Token>(t: T) => t.token.startsWith(tokenStyles.opacity.prefix),
|
|
20
|
+
},
|
|
21
|
+
shadow: {
|
|
22
|
+
objectName: 'shadow',
|
|
23
|
+
prefix: 'elevation.shadow.',
|
|
24
|
+
cssProperty: 'boxShadow',
|
|
25
|
+
filterFn: <T extends Token>(t: T) => t.token.startsWith(tokenStyles.shadow.prefix),
|
|
26
|
+
},
|
|
27
|
+
surface: {
|
|
28
|
+
objectName: 'surfaceColor',
|
|
29
|
+
prefix: 'elevation.surface.',
|
|
30
|
+
cssProperty: CURRENT_SURFACE_CSS_VAR,
|
|
31
|
+
filterFn: <T extends Token>(t: T) => t.token.startsWith(tokenStyles.surface.prefix),
|
|
32
|
+
},
|
|
43
33
|
} as const;
|
|
44
34
|
|
|
45
35
|
const bothTokens = tokens.map((t, i) => [t, legacyTokens[i]]);
|
|
46
36
|
|
|
47
37
|
const activeTokens = bothTokens
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
38
|
+
.filter(([t]) => t.attributes.state !== 'deleted')
|
|
39
|
+
.map((t) => t)
|
|
40
|
+
.map(
|
|
41
|
+
([t, legacy]): Token => ({
|
|
42
|
+
token: t.name,
|
|
43
|
+
fallback: legacy.value as string | ShadowDefinition,
|
|
44
|
+
isDeprecated: t.attributes.state === 'deprecated',
|
|
45
|
+
}),
|
|
46
|
+
);
|
|
57
47
|
|
|
58
|
-
export const createElevationStylesFromTemplate = (
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
throw new Error(`[codegen] Unknown option found "${property}"`);
|
|
63
|
-
}
|
|
48
|
+
export const createElevationStylesFromTemplate = (property: keyof typeof tokenStyles) => {
|
|
49
|
+
if (!tokenStyles[property]) {
|
|
50
|
+
throw new Error(`[codegen] Unknown option found "${property}"`);
|
|
51
|
+
}
|
|
64
52
|
|
|
65
|
-
|
|
53
|
+
const { filterFn, objectName } = tokenStyles[property];
|
|
66
54
|
|
|
67
|
-
|
|
68
|
-
|
|
55
|
+
return (
|
|
56
|
+
format(
|
|
57
|
+
`
|
|
69
58
|
export const ${objectName}Map = {
|
|
70
59
|
${activeTokens
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
60
|
+
.filter(filterFn)
|
|
61
|
+
// @ts-ignore
|
|
62
|
+
.map((t) => ({ ...t, token: t.token.replaceAll('.[default]', '') }))
|
|
63
|
+
.map((t) => {
|
|
64
|
+
return `
|
|
76
65
|
${t.isDeprecated ? '// @deprecated' : ''}
|
|
77
66
|
'${t.token}': ${constructTokenFunctionCall(t.token, t.fallback)}
|
|
78
67
|
`.trim();
|
|
79
|
-
|
|
80
|
-
|
|
68
|
+
})
|
|
69
|
+
.join(',\n\t')}
|
|
81
70
|
} as const;`,
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
);
|
|
71
|
+
'typescript',
|
|
72
|
+
) + `\nexport type ${capitalize(objectName)} = keyof typeof ${objectName}Map;\n`
|
|
73
|
+
);
|
|
86
74
|
};
|
|
@@ -4,43 +4,38 @@ import { light as tokens } from '@atlaskit/tokens/tokens-raw';
|
|
|
4
4
|
import { compose, isAccent, not, pick } from './utils';
|
|
5
5
|
|
|
6
6
|
type Token = {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
token: string;
|
|
8
|
+
fallback: string;
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
const activeTokens = tokens
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
.filter(t => t.token.includes('bold'))
|
|
25
|
-
// @ts-ignore
|
|
26
|
-
.map(t => ({ ...t, token: t.token.replaceAll('.[default]', '') }));
|
|
12
|
+
.filter((t) => t.attributes.state !== 'deleted' && t.attributes.state !== 'deprecated')
|
|
13
|
+
.map(
|
|
14
|
+
(t): Token => ({
|
|
15
|
+
token: t.name,
|
|
16
|
+
fallback: t.value as string,
|
|
17
|
+
}),
|
|
18
|
+
)
|
|
19
|
+
.filter(compose(pick('token'), not(isAccent)))
|
|
20
|
+
.filter((t) => t.token.includes('background'))
|
|
21
|
+
.filter((t) => t.token.includes('bold'))
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
.map((t) => ({ ...t, token: t.token.replaceAll('.[default]', '') }));
|
|
27
24
|
|
|
28
25
|
export const createInverseColorMapTemplate = () => {
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
return format(
|
|
27
|
+
`
|
|
31
28
|
export const inverseColorMap = {
|
|
32
29
|
${activeTokens
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
})
|
|
42
|
-
.join(',\n\t')}
|
|
30
|
+
.map((t) => {
|
|
31
|
+
// handle the default case eg color.border or color.text
|
|
32
|
+
const propName = t.token;
|
|
33
|
+
return `'${propName}': '${
|
|
34
|
+
propName.includes('warning') ? 'color.text.warning.inverse' : 'color.text.inverse'
|
|
35
|
+
}'`;
|
|
36
|
+
})
|
|
37
|
+
.join(',\n\t')}
|
|
43
38
|
} as const;`,
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
'typescript',
|
|
40
|
+
);
|
|
46
41
|
};
|
|
@@ -2,14 +2,9 @@ import { readFileSync } from 'fs';
|
|
|
2
2
|
import { join } from 'path';
|
|
3
3
|
|
|
4
4
|
export const createStylesFromFileTemplate = (
|
|
5
|
-
|
|
6
|
-
| 'border-color'
|
|
7
|
-
| 'border-radius'
|
|
8
|
-
| 'border-width'
|
|
9
|
-
| 'dimensions'
|
|
10
|
-
| 'layer',
|
|
5
|
+
property: 'border-color' | 'border-radius' | 'border-width' | 'dimensions' | 'layer',
|
|
11
6
|
) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
const path = join(__dirname, './codegen-file-templates', `${property}.tsx`);
|
|
8
|
+
const source = readFileSync(path);
|
|
9
|
+
return source;
|
|
15
10
|
};
|
|
@@ -6,40 +6,34 @@ import { constructTokenFunctionCall } from './utils';
|
|
|
6
6
|
const spacingTokenPrefix = 'space.';
|
|
7
7
|
const negativeSuffix = '.negative';
|
|
8
8
|
const positiveSpaceTokens = tokens
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
.filter((token) => token.name.startsWith(spacingTokenPrefix))
|
|
10
|
+
.filter((token) => !token.name.includes(negativeSuffix))
|
|
11
|
+
.map((t) => ({
|
|
12
|
+
name: t.cleanName, // Need to use cleanName to avoid getting '[default]' in the token names
|
|
13
|
+
fallback: t.value,
|
|
14
|
+
}));
|
|
15
15
|
|
|
16
16
|
const negativeSpaceTokens = tokens
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
.filter((token) => token.name.startsWith(spacingTokenPrefix))
|
|
18
|
+
.filter((token) => token.name.includes(negativeSuffix))
|
|
19
|
+
.map((t) => ({
|
|
20
|
+
name: t.cleanName,
|
|
21
|
+
fallback: t.value,
|
|
22
|
+
}));
|
|
23
23
|
|
|
24
24
|
export const createSpacingStylesFromTemplate = () => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
)
|
|
38
|
-
.join('\n')}}`,
|
|
39
|
-
`export type NegativeSpace = keyof typeof negativeSpaceMap;\n`,
|
|
40
|
-
`export const allSpaceMap = { ...positiveSpaceMap, ...negativeSpaceMap };\n`,
|
|
41
|
-
`export type AllSpace = keyof typeof allSpaceMap;\n`,
|
|
42
|
-
].join('\n');
|
|
25
|
+
const output = [
|
|
26
|
+
`export const positiveSpaceMap = {\n${positiveSpaceTokens
|
|
27
|
+
.map(({ name, fallback }) => `'${name}': ${constructTokenFunctionCall(name, fallback)},`)
|
|
28
|
+
.join('\n')}}`,
|
|
29
|
+
`export type Space = keyof typeof positiveSpaceMap;\n`,
|
|
30
|
+
`export const negativeSpaceMap = {\n${negativeSpaceTokens
|
|
31
|
+
.map(({ name, fallback }) => `'${name}': ${constructTokenFunctionCall(name, fallback)},`)
|
|
32
|
+
.join('\n')}}`,
|
|
33
|
+
`export type NegativeSpace = keyof typeof negativeSpaceMap;\n`,
|
|
34
|
+
`export const allSpaceMap = { ...positiveSpaceMap, ...negativeSpaceMap };\n`,
|
|
35
|
+
`export type AllSpace = keyof typeof allSpaceMap;\n`,
|
|
36
|
+
].join('\n');
|
|
43
37
|
|
|
44
|
-
|
|
38
|
+
return format(output, 'typescript');
|
|
45
39
|
};
|
|
@@ -4,90 +4,84 @@ import { typographyAdg3 as tokens } from '@atlaskit/tokens/tokens-raw';
|
|
|
4
4
|
import { capitalize, constructTokenFunctionCall } from './utils';
|
|
5
5
|
|
|
6
6
|
type Token = {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
name: string;
|
|
8
|
+
fallback: string;
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
const activeTokens: Token[] = tokens
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
.filter((t) => t.attributes.state === 'active')
|
|
13
|
+
.map((t) => ({
|
|
14
|
+
name: t.name,
|
|
15
|
+
fallback: t.value,
|
|
16
|
+
}));
|
|
17
17
|
|
|
18
18
|
const typographyProperties = [
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
19
|
+
{
|
|
20
|
+
objectName: 'fontSize',
|
|
21
|
+
cssProperty: 'font',
|
|
22
|
+
prefix: 'font.body',
|
|
23
|
+
filterFn: <T extends Token>(t: T) => t.name.startsWith('font.body'),
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
objectName: 'fontWeight',
|
|
27
|
+
cssProperty: 'fontWeight',
|
|
28
|
+
prefix: 'font.weight.',
|
|
29
|
+
filterFn: <T extends Token>(t: T) => t.name.startsWith('font.weight'),
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
objectName: 'fontFamily',
|
|
33
|
+
cssProperty: 'fontFamily',
|
|
34
|
+
prefix: 'font.family.',
|
|
35
|
+
filterFn: <T extends Token>(t: T) => t.name.startsWith('font.family'),
|
|
36
|
+
},
|
|
37
37
|
] as const;
|
|
38
38
|
|
|
39
39
|
const bodySizeMap = {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
'body.small': 'small',
|
|
41
|
+
'body.UNSAFE_small': 'UNSAFE_small',
|
|
42
|
+
body: 'medium',
|
|
43
|
+
'body.large': 'large',
|
|
44
44
|
};
|
|
45
45
|
|
|
46
46
|
const removeVerbosity = (name: string): string => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
const partialRemove = ['font.body'];
|
|
48
|
+
if (partialRemove.some((s) => name.includes(s))) {
|
|
49
|
+
// @ts-expect-error Indexing bodySizeMap
|
|
50
|
+
return bodySizeMap[name.replace('font.', '')];
|
|
51
|
+
}
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
const fullRemove = ['font.weight'];
|
|
54
|
+
const removeIndex = fullRemove.findIndex((s) => name.includes(s));
|
|
55
|
+
if (removeIndex > -1) {
|
|
56
|
+
return name.replace(`${fullRemove[removeIndex]}.`, '');
|
|
57
|
+
}
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
return name;
|
|
60
60
|
};
|
|
61
61
|
|
|
62
62
|
export const createTypographyStylesFromTemplate = () => {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
return typographyProperties
|
|
64
|
+
.map((typographyProperty) => {
|
|
65
|
+
const { filterFn, objectName } = typographyProperty;
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
return (
|
|
68
|
+
format(
|
|
69
|
+
`
|
|
70
70
|
export const ${objectName}Map = {
|
|
71
71
|
${activeTokens
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
'${removeVerbosity(token.name)}': ${constructTokenFunctionCall(
|
|
78
|
-
token.name,
|
|
79
|
-
token.fallback,
|
|
80
|
-
)}
|
|
72
|
+
.filter(filterFn)
|
|
73
|
+
.map((t) => ({ ...t, name: t.name.replace(/\.\[default\]/g, '') }))
|
|
74
|
+
.sort((a, b) => (a.name < b.name ? -1 : 1))
|
|
75
|
+
.map((token) => {
|
|
76
|
+
return `
|
|
77
|
+
'${removeVerbosity(token.name)}': ${constructTokenFunctionCall(token.name, token.fallback)}
|
|
81
78
|
`.trim();
|
|
82
|
-
|
|
83
|
-
|
|
79
|
+
})
|
|
80
|
+
.join(',\n\t')}
|
|
84
81
|
};`,
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
);
|
|
91
|
-
})
|
|
92
|
-
.join('\n');
|
|
82
|
+
'typescript',
|
|
83
|
+
) + `\nexport type ${capitalize(objectName)} = keyof typeof ${objectName}Map;\n`
|
|
84
|
+
);
|
|
85
|
+
})
|
|
86
|
+
.join('\n');
|
|
93
87
|
};
|
package/scripts/utils.tsx
CHANGED
|
@@ -1,69 +1,62 @@
|
|
|
1
1
|
import type { CSSProperties } from 'react';
|
|
2
2
|
|
|
3
3
|
export const tokenCall = (token: string, fallback: string | ShadowDefinition) =>
|
|
4
|
-
|
|
4
|
+
`token('${token}', '${fallback}')`;
|
|
5
5
|
|
|
6
6
|
export const tokenToStyle = (
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
prop: keyof CSSProperties,
|
|
8
|
+
token: string,
|
|
9
|
+
fallback: string | ShadowDefinition,
|
|
10
10
|
) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
if (Array.isArray(fallback)) {
|
|
12
|
+
fallback = constructShadow(fallback);
|
|
13
|
+
}
|
|
14
|
+
return `css({\n\t${prop}: ${tokenCall(token, fallback)}\n})`;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
export const constructTokenFunctionCall = (
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (Array.isArray(fallback)) {
|
|
22
|
-
fallback = constructShadow(fallback);
|
|
23
|
-
}
|
|
17
|
+
export const constructTokenFunctionCall = (token: string, fallback: string | ShadowDefinition) => {
|
|
18
|
+
if (Array.isArray(fallback)) {
|
|
19
|
+
fallback = constructShadow(fallback);
|
|
20
|
+
}
|
|
24
21
|
|
|
25
|
-
|
|
22
|
+
return `token('${token}', '${fallback}')`;
|
|
26
23
|
};
|
|
27
24
|
|
|
28
25
|
export type ShadowDefinition = Array<{
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
26
|
+
radius: number;
|
|
27
|
+
offset: {
|
|
28
|
+
x: number;
|
|
29
|
+
y: number;
|
|
30
|
+
};
|
|
31
|
+
color: string;
|
|
32
|
+
opacity: number;
|
|
36
33
|
}>;
|
|
37
34
|
|
|
38
35
|
const constructShadow = (shadowObject: ShadowDefinition) => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
`${shadow.offset.x}px ${shadow.offset.y}px ${shadow.radius}px ${shadow.color}`,
|
|
43
|
-
)
|
|
44
|
-
.join(', ');
|
|
36
|
+
return shadowObject
|
|
37
|
+
.map((shadow) => `${shadow.offset.x}px ${shadow.offset.y}px ${shadow.radius}px ${shadow.color}`)
|
|
38
|
+
.join(', ');
|
|
45
39
|
};
|
|
46
40
|
|
|
47
41
|
type BooleanCallback<T> = (args: T) => boolean;
|
|
48
42
|
|
|
49
43
|
export const compose =
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
44
|
+
(...fns: ((...any: any[]) => any)[]) =>
|
|
45
|
+
(x: any) =>
|
|
46
|
+
fns.reduce((res, fn) => fn(res), x);
|
|
53
47
|
export const pick =
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
48
|
+
<T extends any>(key: keyof T) =>
|
|
49
|
+
(obj: T) =>
|
|
50
|
+
obj[key];
|
|
57
51
|
export const isAccent = (str: string) => str.includes('accent');
|
|
58
52
|
export const isPressed = (str: string) => str.includes('pressed');
|
|
59
53
|
export const isHovered = (str: string) => str.includes('hovered');
|
|
60
54
|
export const not =
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
55
|
+
<T extends any>(cb: BooleanCallback<T>) =>
|
|
56
|
+
(val: T) =>
|
|
57
|
+
!cb(val);
|
|
64
58
|
export const or =
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
export const capitalize = (str: string) =>
|
|
69
|
-
str.charAt(0).toUpperCase() + str.slice(1);
|
|
59
|
+
<T extends any>(...fns: BooleanCallback<T>[]) =>
|
|
60
|
+
(val: T) =>
|
|
61
|
+
fns.some((fn) => fn(val));
|
|
62
|
+
export const capitalize = (str: string) => str.charAt(0).toUpperCase() + str.slice(1);
|