@atlaskit/primitives 0.0.1
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/CHANGELOG.md +7 -0
- package/LICENSE.md +13 -0
- package/README.md +9 -0
- package/box/package.json +15 -0
- package/dist/cjs/components/box.js +13 -0
- package/dist/cjs/components/inline.partial.js +13 -0
- package/dist/cjs/components/internal/box.partial.js +605 -0
- package/dist/cjs/components/stack.partial.js +13 -0
- package/dist/cjs/components/types.js +5 -0
- package/dist/cjs/constants.js +18 -0
- package/dist/cjs/index.js +26 -0
- package/dist/cjs/internal/color-map.js +42 -0
- package/dist/cjs/version.json +5 -0
- package/dist/es2019/components/box.js +1 -0
- package/dist/es2019/components/inline.partial.js +2 -0
- package/dist/es2019/components/internal/box.partial.js +597 -0
- package/dist/es2019/components/stack.partial.js +2 -0
- package/dist/es2019/components/types.js +1 -0
- package/dist/es2019/constants.js +11 -0
- package/dist/es2019/index.js +3 -0
- package/dist/es2019/internal/color-map.js +35 -0
- package/dist/es2019/version.json +5 -0
- package/dist/esm/components/box.js +1 -0
- package/dist/esm/components/inline.partial.js +2 -0
- package/dist/esm/components/internal/box.partial.js +600 -0
- package/dist/esm/components/stack.partial.js +2 -0
- package/dist/esm/components/types.js +1 -0
- package/dist/esm/constants.js +11 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/internal/color-map.js +35 -0
- package/dist/esm/version.json +5 -0
- package/dist/types/components/box.d.ts +1 -0
- package/dist/types/components/inline.partial.d.ts +1 -0
- package/dist/types/components/internal/box.partial.d.ts +348 -0
- package/dist/types/components/stack.partial.d.ts +1 -0
- package/dist/types/components/types.d.ts +13 -0
- package/dist/types/constants.d.ts +12 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/internal/color-map.d.ts +36 -0
- package/inline/package.json +15 -0
- package/package.json +89 -0
- package/report.api.md +43 -0
- package/scripts/__tests__/__snapshots__/codegen.test.tsx.snap +181 -0
- package/scripts/__tests__/codegen.test.tsx +20 -0
- package/scripts/codegen-styles.tsx +124 -0
- package/scripts/color-codegen-template.tsx +111 -0
- package/scripts/color-map-template.tsx +52 -0
- package/scripts/dimension-codegen-template.tsx +63 -0
- package/scripts/misc-codegen-template.tsx +43 -0
- package/scripts/spacing-codegen-template.tsx +84 -0
- package/scripts/utils.tsx +55 -0
- package/stack/package.json +15 -0
- package/tmp/api-report-tmp.d.ts +19 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`@atlaskit/primitives bg styles are generated correctly 1`] = `
|
|
4
|
+
"const backgroundColorMap = {
|
|
5
|
+
disabled: css({
|
|
6
|
+
backgroundColor: token('color.background.disabled', '#091e4289'),
|
|
7
|
+
}),
|
|
8
|
+
input: css({
|
|
9
|
+
backgroundColor: token('color.background.input', '#FAFBFC'),
|
|
10
|
+
}),
|
|
11
|
+
'inverse.subtle': css({
|
|
12
|
+
backgroundColor: token('color.background.inverse.subtle', '#00000029'),
|
|
13
|
+
}),
|
|
14
|
+
neutral: css({
|
|
15
|
+
backgroundColor: token('color.background.neutral', '#DFE1E6'),
|
|
16
|
+
}),
|
|
17
|
+
'neutral.subtle': css({
|
|
18
|
+
backgroundColor: token('color.background.neutral.subtle', 'transparent'),
|
|
19
|
+
}),
|
|
20
|
+
'neutral.bold': css({
|
|
21
|
+
backgroundColor: token('color.background.neutral.bold', '#42526E'),
|
|
22
|
+
}),
|
|
23
|
+
selected: css({
|
|
24
|
+
backgroundColor: token('color.background.selected', '#DEEBFF'),
|
|
25
|
+
}),
|
|
26
|
+
'selected.bold': css({
|
|
27
|
+
backgroundColor: token('color.background.selected.bold', '#0052CC'),
|
|
28
|
+
}),
|
|
29
|
+
'brand.bold': css({
|
|
30
|
+
backgroundColor: token('color.background.brand.bold', '#0052CC'),
|
|
31
|
+
}),
|
|
32
|
+
danger: css({
|
|
33
|
+
backgroundColor: token('color.background.danger', '#FFEBE6'),
|
|
34
|
+
}),
|
|
35
|
+
'danger.bold': css({
|
|
36
|
+
backgroundColor: token('color.background.danger.bold', '#DE350B'),
|
|
37
|
+
}),
|
|
38
|
+
warning: css({
|
|
39
|
+
backgroundColor: token('color.background.warning', '#FFFAE6'),
|
|
40
|
+
}),
|
|
41
|
+
'warning.bold': css({
|
|
42
|
+
backgroundColor: token('color.background.warning.bold', '#FFAB00'),
|
|
43
|
+
}),
|
|
44
|
+
success: css({
|
|
45
|
+
backgroundColor: token('color.background.success', '#E3FCEF'),
|
|
46
|
+
}),
|
|
47
|
+
'success.bold': css({
|
|
48
|
+
backgroundColor: token('color.background.success.bold', '#00875A'),
|
|
49
|
+
}),
|
|
50
|
+
discovery: css({
|
|
51
|
+
backgroundColor: token('color.background.discovery', '#EAE6FF'),
|
|
52
|
+
}),
|
|
53
|
+
'discovery.bold': css({
|
|
54
|
+
backgroundColor: token('color.background.discovery.bold', '#5243AA'),
|
|
55
|
+
}),
|
|
56
|
+
information: css({
|
|
57
|
+
backgroundColor: token('color.background.information', '#DEEBFF'),
|
|
58
|
+
}),
|
|
59
|
+
'information.bold': css({
|
|
60
|
+
backgroundColor: token('color.background.information.bold', '#0052CC'),
|
|
61
|
+
}),
|
|
62
|
+
'color.blanket': css({
|
|
63
|
+
backgroundColor: token('color.blanket', '#091e4289'),
|
|
64
|
+
}),
|
|
65
|
+
'color.blanket.selected': css({
|
|
66
|
+
backgroundColor: token('color.blanket.selected', '#388BFF14'),
|
|
67
|
+
}),
|
|
68
|
+
'color.blanket.danger': css({
|
|
69
|
+
backgroundColor: token('color.blanket.danger', '#EF5C4814'),
|
|
70
|
+
}),
|
|
71
|
+
'elevation.surface': css({
|
|
72
|
+
backgroundColor: token('elevation.surface', '#FFFFFF'),
|
|
73
|
+
}),
|
|
74
|
+
'elevation.surface.overlay': css({
|
|
75
|
+
backgroundColor: token('elevation.surface.overlay', '#FFFFFF'),
|
|
76
|
+
}),
|
|
77
|
+
'elevation.surface.raised': css({
|
|
78
|
+
backgroundColor: token('elevation.surface.raised', '#FFFFFF'),
|
|
79
|
+
}),
|
|
80
|
+
'elevation.surface.sunken': css({
|
|
81
|
+
backgroundColor: token('elevation.surface.sunken', '#F4F5F7'),
|
|
82
|
+
}),
|
|
83
|
+
} as const;
|
|
84
|
+
|
|
85
|
+
export type BackgroundColor = keyof typeof backgroundColorMap;
|
|
86
|
+
"
|
|
87
|
+
`;
|
|
88
|
+
|
|
89
|
+
exports[`@atlaskit/primitives border styles are generated correctly 1`] = `
|
|
90
|
+
"const borderColorMap = {
|
|
91
|
+
'color.border': css({
|
|
92
|
+
borderColor: token('color.border', '#091e4221'),
|
|
93
|
+
}),
|
|
94
|
+
disabled: css({
|
|
95
|
+
borderColor: token('color.border.disabled', '#FAFBFC'),
|
|
96
|
+
}),
|
|
97
|
+
focused: css({
|
|
98
|
+
borderColor: token('color.border.focused', '#4C9AFF'),
|
|
99
|
+
}),
|
|
100
|
+
input: css({
|
|
101
|
+
borderColor: token('color.border.input', '#FAFBFC'),
|
|
102
|
+
}),
|
|
103
|
+
inverse: css({
|
|
104
|
+
borderColor: token('color.border.inverse', '#FFFFFF'),
|
|
105
|
+
}),
|
|
106
|
+
selected: css({
|
|
107
|
+
borderColor: token('color.border.selected', '#0052CC'),
|
|
108
|
+
}),
|
|
109
|
+
brand: css({
|
|
110
|
+
borderColor: token('color.border.brand', '#0052CC'),
|
|
111
|
+
}),
|
|
112
|
+
danger: css({
|
|
113
|
+
borderColor: token('color.border.danger', '#FF5630'),
|
|
114
|
+
}),
|
|
115
|
+
warning: css({
|
|
116
|
+
borderColor: token('color.border.warning', '#FFC400'),
|
|
117
|
+
}),
|
|
118
|
+
success: css({
|
|
119
|
+
borderColor: token('color.border.success', '#00875A'),
|
|
120
|
+
}),
|
|
121
|
+
discovery: css({
|
|
122
|
+
borderColor: token('color.border.discovery', '#998DD9'),
|
|
123
|
+
}),
|
|
124
|
+
information: css({
|
|
125
|
+
borderColor: token('color.border.information', '#0065FF'),
|
|
126
|
+
}),
|
|
127
|
+
bold: css({
|
|
128
|
+
borderColor: token('color.border.bold', '#344563'),
|
|
129
|
+
}),
|
|
130
|
+
} as const;
|
|
131
|
+
|
|
132
|
+
export type BorderColor = keyof typeof borderColorMap;
|
|
133
|
+
"
|
|
134
|
+
`;
|
|
135
|
+
|
|
136
|
+
exports[`@atlaskit/primitives text styles are generated correctly 1`] = `
|
|
137
|
+
"const textColorMap = {
|
|
138
|
+
'color.text': css({
|
|
139
|
+
color: token('color.text', '#172B4D'),
|
|
140
|
+
}),
|
|
141
|
+
disabled: css({
|
|
142
|
+
color: token('color.text.disabled', '#A5ADBA'),
|
|
143
|
+
}),
|
|
144
|
+
inverse: css({
|
|
145
|
+
color: token('color.text.inverse', '#FFFFFF'),
|
|
146
|
+
}),
|
|
147
|
+
selected: css({
|
|
148
|
+
color: token('color.text.selected', '#0052CC'),
|
|
149
|
+
}),
|
|
150
|
+
brand: css({
|
|
151
|
+
color: token('color.text.brand', '#0065FF'),
|
|
152
|
+
}),
|
|
153
|
+
danger: css({
|
|
154
|
+
color: token('color.text.danger', '#DE350B'),
|
|
155
|
+
}),
|
|
156
|
+
warning: css({
|
|
157
|
+
color: token('color.text.warning', '#974F0C'),
|
|
158
|
+
}),
|
|
159
|
+
'warning.inverse': css({
|
|
160
|
+
color: token('color.text.warning.inverse', '#172B4D'),
|
|
161
|
+
}),
|
|
162
|
+
success: css({
|
|
163
|
+
color: token('color.text.success', '#006644'),
|
|
164
|
+
}),
|
|
165
|
+
discovery: css({
|
|
166
|
+
color: token('color.text.discovery', '#403294'),
|
|
167
|
+
}),
|
|
168
|
+
information: css({
|
|
169
|
+
color: token('color.text.information', '#0052CC'),
|
|
170
|
+
}),
|
|
171
|
+
subtlest: css({
|
|
172
|
+
color: token('color.text.subtlest', '#7A869A'),
|
|
173
|
+
}),
|
|
174
|
+
subtle: css({
|
|
175
|
+
color: token('color.text.subtle', '#42526E'),
|
|
176
|
+
}),
|
|
177
|
+
} as const;
|
|
178
|
+
|
|
179
|
+
export type TextColor = keyof typeof textColorMap;
|
|
180
|
+
"
|
|
181
|
+
`;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createColorStylesFromTemplate } from '../color-codegen-template';
|
|
2
|
+
describe('@atlaskit/primitives', () => {
|
|
3
|
+
test('text styles are generated correctly', () => {
|
|
4
|
+
expect(createColorStylesFromTemplate('text')).toMatchSnapshot();
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
test('bg styles are generated correctly', () => {
|
|
8
|
+
expect(createColorStylesFromTemplate('background')).toMatchSnapshot();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test('border styles are generated correctly', () => {
|
|
12
|
+
expect(createColorStylesFromTemplate('border')).toMatchSnapshot();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test('incorrect config throws', () => {
|
|
16
|
+
expect(() =>
|
|
17
|
+
createColorStylesFromTemplate('fizzbuzz' as any),
|
|
18
|
+
).toThrowError();
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import { writeFile } from 'fs/promises';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
|
|
5
|
+
import { createPartialSignedArtifact, createSignedArtifact } from '@af/codegen';
|
|
6
|
+
|
|
7
|
+
import { createColorStylesFromTemplate } from './color-codegen-template';
|
|
8
|
+
import { createColorMapTemplate } from './color-map-template';
|
|
9
|
+
import { createDimensionStylesFromTemplate } from './dimension-codegen-template';
|
|
10
|
+
import { createStylesFromTemplate } from './misc-codegen-template';
|
|
11
|
+
import { createSpacingStylesFromTemplate } from './spacing-codegen-template';
|
|
12
|
+
|
|
13
|
+
const colorMapOutputFolder = join(__dirname, '../', 'src', 'internal');
|
|
14
|
+
const colorTokensDependencyPath = require.resolve(
|
|
15
|
+
'../../tokens/src/artifacts/tokens-raw/atlassian-light',
|
|
16
|
+
);
|
|
17
|
+
const spacingTokensDependencyPath = require.resolve(
|
|
18
|
+
'../../tokens/src/artifacts/tokens-raw/atlassian-spacing',
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
writeFile(
|
|
22
|
+
join(colorMapOutputFolder, 'color-map.tsx'),
|
|
23
|
+
createSignedArtifact(createColorMapTemplate(), 'yarn codegen-styles', {
|
|
24
|
+
description:
|
|
25
|
+
'The color map is used to map a background color token to a matching text color that will meet contrast.',
|
|
26
|
+
dependencies: [colorTokensDependencyPath],
|
|
27
|
+
outputFolder: colorMapOutputFolder,
|
|
28
|
+
}),
|
|
29
|
+
).then(() => console.log(join(colorMapOutputFolder, 'color-map.tsx')));
|
|
30
|
+
|
|
31
|
+
// generate colors
|
|
32
|
+
Promise.all(
|
|
33
|
+
[{ target: 'box.partial.tsx' }].map(({ target }) => {
|
|
34
|
+
const targetPath = join(
|
|
35
|
+
__dirname,
|
|
36
|
+
'../',
|
|
37
|
+
'src',
|
|
38
|
+
'components',
|
|
39
|
+
'internal',
|
|
40
|
+
target,
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
const source = createPartialSignedArtifact(
|
|
44
|
+
options => options.map(createColorStylesFromTemplate).join('\n'),
|
|
45
|
+
'yarn codegen-styles',
|
|
46
|
+
{
|
|
47
|
+
id: 'colors',
|
|
48
|
+
absoluteFilePath: targetPath,
|
|
49
|
+
dependencies: [colorTokensDependencyPath],
|
|
50
|
+
},
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
return writeFile(targetPath, source).then(() =>
|
|
54
|
+
console.log(`${targetPath} written!`),
|
|
55
|
+
);
|
|
56
|
+
}),
|
|
57
|
+
)
|
|
58
|
+
.then(() => {
|
|
59
|
+
// generate spacing values
|
|
60
|
+
return Promise.all(
|
|
61
|
+
[
|
|
62
|
+
{ path: ['internal', 'box.partial.tsx'] },
|
|
63
|
+
// { target: 'stack.partial.tsx' },
|
|
64
|
+
// { target: 'inline.partial.tsx' },
|
|
65
|
+
].map(({ path }) => {
|
|
66
|
+
const targetPath = join(__dirname, '../', 'src', 'components', ...path);
|
|
67
|
+
|
|
68
|
+
const source = createPartialSignedArtifact(
|
|
69
|
+
options => options.map(createSpacingStylesFromTemplate).join('\n'),
|
|
70
|
+
'yarn codegen-styles',
|
|
71
|
+
{
|
|
72
|
+
id: 'spacing',
|
|
73
|
+
absoluteFilePath: targetPath,
|
|
74
|
+
dependencies: [spacingTokensDependencyPath],
|
|
75
|
+
},
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
return writeFile(targetPath, source).then(() =>
|
|
79
|
+
console.log(`${targetPath} written!`),
|
|
80
|
+
);
|
|
81
|
+
}),
|
|
82
|
+
);
|
|
83
|
+
})
|
|
84
|
+
.then(() => {
|
|
85
|
+
// generate other values
|
|
86
|
+
return Promise.all(
|
|
87
|
+
[{ path: ['internal', 'box.partial.tsx'] }].map(({ path }) => {
|
|
88
|
+
const targetPath = join(__dirname, '../', 'src', 'components', ...path);
|
|
89
|
+
|
|
90
|
+
const source = createPartialSignedArtifact(
|
|
91
|
+
options => options.map(createStylesFromTemplate).join('\n'),
|
|
92
|
+
'yarn codegen-styles',
|
|
93
|
+
{ id: 'misc', absoluteFilePath: targetPath },
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
return writeFile(targetPath, source).then(() =>
|
|
97
|
+
console.log(`${targetPath} written!`),
|
|
98
|
+
);
|
|
99
|
+
}),
|
|
100
|
+
);
|
|
101
|
+
})
|
|
102
|
+
.then(() => {
|
|
103
|
+
const targetPath = join(
|
|
104
|
+
__dirname,
|
|
105
|
+
'../',
|
|
106
|
+
'src',
|
|
107
|
+
'components',
|
|
108
|
+
'internal',
|
|
109
|
+
'box.partial.tsx',
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
const source = createPartialSignedArtifact(
|
|
113
|
+
options => options.map(createDimensionStylesFromTemplate).join('\n'),
|
|
114
|
+
'yarn codegen-styles',
|
|
115
|
+
{
|
|
116
|
+
id: 'dimensions',
|
|
117
|
+
absoluteFilePath: targetPath,
|
|
118
|
+
},
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
return writeFile(targetPath, source).then(() =>
|
|
122
|
+
console.log(`${targetPath} written!`),
|
|
123
|
+
);
|
|
124
|
+
});
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import prettier from 'prettier';
|
|
2
|
+
import parserTypeScript from 'prettier/parser-typescript';
|
|
3
|
+
|
|
4
|
+
// eslint-disable-next-line @atlassian/tangerine/import/entry-points
|
|
5
|
+
import legacyTokens from '@atlaskit/tokens/src/artifacts/tokens-raw/atlassian-legacy-light';
|
|
6
|
+
// eslint-disable-next-line @atlassian/tangerine/import/entry-points
|
|
7
|
+
import tokens from '@atlaskit/tokens/src/artifacts/tokens-raw/atlassian-light';
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
capitalize,
|
|
11
|
+
compose,
|
|
12
|
+
isAccent,
|
|
13
|
+
isHovered,
|
|
14
|
+
isPressed,
|
|
15
|
+
not,
|
|
16
|
+
pick,
|
|
17
|
+
ShadowDefintion,
|
|
18
|
+
tokenToStyle,
|
|
19
|
+
} from './utils';
|
|
20
|
+
|
|
21
|
+
type Token = {
|
|
22
|
+
token: string;
|
|
23
|
+
fallback: string | ShadowDefintion;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// NB: Fallback CSS variables can be deleted when tokens are no longer behind a feature flag
|
|
27
|
+
const tokenStyles = {
|
|
28
|
+
text: {
|
|
29
|
+
objectName: 'textColor',
|
|
30
|
+
prefix: 'color.text.',
|
|
31
|
+
cssProperty: 'color',
|
|
32
|
+
filterFn: <T extends Token>(t: T) =>
|
|
33
|
+
t.token.startsWith(tokenStyles.text.prefix),
|
|
34
|
+
},
|
|
35
|
+
background: {
|
|
36
|
+
objectName: 'backgroundColor',
|
|
37
|
+
prefix: 'color.background.',
|
|
38
|
+
cssProperty: 'backgroundColor',
|
|
39
|
+
filterFn: <T extends Token>(t: T) =>
|
|
40
|
+
t.token.startsWith(tokenStyles.background.prefix) ||
|
|
41
|
+
t.token.startsWith('elevation.surface') ||
|
|
42
|
+
t.token.startsWith('color.blanket'),
|
|
43
|
+
},
|
|
44
|
+
border: {
|
|
45
|
+
objectName: 'borderColor',
|
|
46
|
+
prefix: 'color.border.',
|
|
47
|
+
cssProperty: 'borderColor',
|
|
48
|
+
filterFn: <T extends Token>(t: T) =>
|
|
49
|
+
t.token.startsWith(tokenStyles.border.prefix),
|
|
50
|
+
},
|
|
51
|
+
shadow: {
|
|
52
|
+
objectName: 'shadow',
|
|
53
|
+
prefix: 'elevation.shadow.',
|
|
54
|
+
cssProperty: 'boxShadow',
|
|
55
|
+
filterFn: <T extends Token>(t: T) =>
|
|
56
|
+
t.token.startsWith(tokenStyles.shadow.prefix),
|
|
57
|
+
},
|
|
58
|
+
} as const;
|
|
59
|
+
|
|
60
|
+
const bothTokens = tokens.map((t, i) => [t, legacyTokens[i]]);
|
|
61
|
+
|
|
62
|
+
const activeTokens = bothTokens
|
|
63
|
+
.filter(
|
|
64
|
+
([t]) =>
|
|
65
|
+
t.attributes.state !== 'deleted' && t.attributes.state !== 'deprecated',
|
|
66
|
+
)
|
|
67
|
+
.map(
|
|
68
|
+
([t, legacy]): Token => ({
|
|
69
|
+
token: t.name,
|
|
70
|
+
fallback: legacy.value as string | ShadowDefintion,
|
|
71
|
+
}),
|
|
72
|
+
)
|
|
73
|
+
.filter(compose(pick('token'), not(isAccent)))
|
|
74
|
+
.filter(compose(pick('token'), not(isPressed)))
|
|
75
|
+
.filter(compose(pick('token'), not(isHovered)));
|
|
76
|
+
|
|
77
|
+
export const createColorStylesFromTemplate = (
|
|
78
|
+
colorProperty: keyof typeof tokenStyles,
|
|
79
|
+
) => {
|
|
80
|
+
if (!tokenStyles[colorProperty]) {
|
|
81
|
+
throw new Error(`[codegen] Unknown option found "${colorProperty}"`);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const { prefix, cssProperty, filterFn, objectName } =
|
|
85
|
+
tokenStyles[colorProperty];
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
prettier.format(
|
|
89
|
+
`
|
|
90
|
+
const ${objectName}Map = {
|
|
91
|
+
${activeTokens
|
|
92
|
+
.filter(filterFn)
|
|
93
|
+
// @ts-ignore
|
|
94
|
+
.map(t => ({ ...t, token: t.token.replaceAll('.[default]', '') }))
|
|
95
|
+
.map(t => {
|
|
96
|
+
// handle the default case eg color.border or color.text
|
|
97
|
+
const propName = t.token.replace(prefix, '');
|
|
98
|
+
return `'${propName}': ${tokenToStyle(cssProperty, t.token, t.fallback)}`;
|
|
99
|
+
})
|
|
100
|
+
.join(',\n\t')}
|
|
101
|
+
} as const;`,
|
|
102
|
+
{
|
|
103
|
+
singleQuote: true,
|
|
104
|
+
parser: 'typescript',
|
|
105
|
+
trailingComma: 'all',
|
|
106
|
+
plugins: [parserTypeScript],
|
|
107
|
+
},
|
|
108
|
+
) +
|
|
109
|
+
`\nexport type ${capitalize(objectName)} = keyof typeof ${objectName}Map;\n`
|
|
110
|
+
);
|
|
111
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import prettier from 'prettier';
|
|
2
|
+
import parserTypeScript from 'prettier/parser-typescript';
|
|
3
|
+
|
|
4
|
+
// eslint-disable-next-line @atlassian/tangerine/import/entry-points
|
|
5
|
+
import tokens from '@atlaskit/tokens/src/artifacts/tokens-raw/atlassian-light';
|
|
6
|
+
|
|
7
|
+
import { compose, isAccent, not, pick } from './utils';
|
|
8
|
+
|
|
9
|
+
type Token = {
|
|
10
|
+
token: string;
|
|
11
|
+
fallback: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const activeTokens = tokens
|
|
15
|
+
.filter(
|
|
16
|
+
t =>
|
|
17
|
+
t.attributes.state !== 'deleted' && t.attributes.state !== 'deprecated',
|
|
18
|
+
)
|
|
19
|
+
.map(
|
|
20
|
+
(t): Token => ({
|
|
21
|
+
token: t.name,
|
|
22
|
+
fallback: t.value as string,
|
|
23
|
+
}),
|
|
24
|
+
)
|
|
25
|
+
.filter(compose(pick('token'), not(isAccent)))
|
|
26
|
+
.filter(t => t.token.includes('background'))
|
|
27
|
+
.filter(t => t.token.includes('bold'))
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
.map(t => ({ ...t, token: t.token.replaceAll('.[default]', '') }));
|
|
30
|
+
|
|
31
|
+
export const createColorMapTemplate = () => {
|
|
32
|
+
return prettier.format(
|
|
33
|
+
`
|
|
34
|
+
export default {
|
|
35
|
+
${activeTokens
|
|
36
|
+
.map(t => {
|
|
37
|
+
// handle the default case eg color.border or color.text
|
|
38
|
+
const propName = t.token.replace('color.background.', '');
|
|
39
|
+
return `'${propName}': '${
|
|
40
|
+
propName.includes('warning') ? 'warning.inverse' : 'inverse'
|
|
41
|
+
}'`;
|
|
42
|
+
})
|
|
43
|
+
.join(',\n\t')}
|
|
44
|
+
} as const;`,
|
|
45
|
+
{
|
|
46
|
+
singleQuote: true,
|
|
47
|
+
parser: 'typescript',
|
|
48
|
+
trailingComma: 'all',
|
|
49
|
+
plugins: [parserTypeScript],
|
|
50
|
+
},
|
|
51
|
+
);
|
|
52
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import prettier from 'prettier';
|
|
2
|
+
import parserTypeScript from 'prettier/parser-typescript';
|
|
3
|
+
|
|
4
|
+
import { capitalize } from './utils';
|
|
5
|
+
|
|
6
|
+
const dimensionProperties = {
|
|
7
|
+
width: {
|
|
8
|
+
cssProperty: 'width',
|
|
9
|
+
},
|
|
10
|
+
height: {
|
|
11
|
+
cssProperty: 'height',
|
|
12
|
+
},
|
|
13
|
+
} as const;
|
|
14
|
+
|
|
15
|
+
// placeholder adapted from packages/design-system/avatar/src/constants.ts
|
|
16
|
+
const dimensions = {
|
|
17
|
+
'size.100': '16px',
|
|
18
|
+
'size.200': '24px',
|
|
19
|
+
'size.300': '32px',
|
|
20
|
+
'size.400': '40px',
|
|
21
|
+
'size.500': '48px',
|
|
22
|
+
'size.600': '96px',
|
|
23
|
+
'size.1000': '192px',
|
|
24
|
+
'100%': '100%',
|
|
25
|
+
} as const;
|
|
26
|
+
|
|
27
|
+
const activeTokens = Object.entries(dimensions).map(([name, value]) => ({
|
|
28
|
+
name,
|
|
29
|
+
value,
|
|
30
|
+
}));
|
|
31
|
+
|
|
32
|
+
export const createDimensionStylesFromTemplate = (
|
|
33
|
+
spacingProperty: keyof typeof dimensionProperties,
|
|
34
|
+
) => {
|
|
35
|
+
if (!dimensionProperties[spacingProperty]) {
|
|
36
|
+
throw new Error(`[codegen] Unknown option found "${spacingProperty}"`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const { cssProperty } = dimensionProperties[spacingProperty];
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
prettier.format(
|
|
43
|
+
`
|
|
44
|
+
const ${spacingProperty}Map = {
|
|
45
|
+
${activeTokens
|
|
46
|
+
.sort((a, b) => (a.name < b.name ? -1 : 1))
|
|
47
|
+
.map(token => {
|
|
48
|
+
return `'${token.name}': css({ ${cssProperty}: '${token.value}' })`;
|
|
49
|
+
})
|
|
50
|
+
.join(',\n\t')}
|
|
51
|
+
};`,
|
|
52
|
+
{
|
|
53
|
+
singleQuote: true,
|
|
54
|
+
trailingComma: 'all',
|
|
55
|
+
parser: 'typescript',
|
|
56
|
+
plugins: [parserTypeScript],
|
|
57
|
+
},
|
|
58
|
+
) +
|
|
59
|
+
`\nexport type ${capitalize(
|
|
60
|
+
spacingProperty,
|
|
61
|
+
)} = keyof typeof ${spacingProperty}Map;\n`
|
|
62
|
+
);
|
|
63
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import prettier from 'prettier';
|
|
2
|
+
import parserTypeScript from 'prettier/parser-typescript';
|
|
3
|
+
|
|
4
|
+
import { Layer } from '../src/constants';
|
|
5
|
+
|
|
6
|
+
const styleProperties: Record<'layer', Record<Layer, number>> = {
|
|
7
|
+
layer: {
|
|
8
|
+
card: 100,
|
|
9
|
+
navigation: 200,
|
|
10
|
+
dialog: 300,
|
|
11
|
+
layer: 400,
|
|
12
|
+
blanket: 500,
|
|
13
|
+
modal: 510,
|
|
14
|
+
flag: 600,
|
|
15
|
+
spotlight: 700,
|
|
16
|
+
tooltip: 800,
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const createStylesFromTemplate = (
|
|
21
|
+
property: keyof typeof styleProperties,
|
|
22
|
+
) => {
|
|
23
|
+
if (!styleProperties[property]) {
|
|
24
|
+
throw new Error(`[codegen] Unknown option found "${property}"`);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return prettier.format(
|
|
28
|
+
`
|
|
29
|
+
const ${property}Map = {
|
|
30
|
+
${Object.keys(styleProperties[property])
|
|
31
|
+
.map(key => {
|
|
32
|
+
return `'${key}': css({ zIndex: LAYERS['${key}'] })`;
|
|
33
|
+
})
|
|
34
|
+
.join(',\n\t')}
|
|
35
|
+
};`,
|
|
36
|
+
{
|
|
37
|
+
singleQuote: true,
|
|
38
|
+
trailingComma: 'all',
|
|
39
|
+
parser: 'typescript',
|
|
40
|
+
plugins: [parserTypeScript],
|
|
41
|
+
},
|
|
42
|
+
);
|
|
43
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import prettier from 'prettier';
|
|
2
|
+
import parserTypeScript from 'prettier/parser-typescript';
|
|
3
|
+
|
|
4
|
+
import { spacing as tokens } from '@atlaskit/tokens/tokens-raw';
|
|
5
|
+
|
|
6
|
+
import { capitalize, tokenToStyle } from './utils';
|
|
7
|
+
|
|
8
|
+
const spacingProperties = {
|
|
9
|
+
padding: {
|
|
10
|
+
cssProperty: 'padding',
|
|
11
|
+
},
|
|
12
|
+
paddingBlock: {
|
|
13
|
+
cssProperty: 'paddingBlock',
|
|
14
|
+
},
|
|
15
|
+
paddingBlockStart: {
|
|
16
|
+
cssProperty: 'paddingBlockStart',
|
|
17
|
+
},
|
|
18
|
+
paddingBlockEnd: {
|
|
19
|
+
cssProperty: 'paddingBlockEnd',
|
|
20
|
+
},
|
|
21
|
+
paddingInline: {
|
|
22
|
+
cssProperty: 'paddingInline',
|
|
23
|
+
},
|
|
24
|
+
paddingInlineStart: {
|
|
25
|
+
cssProperty: 'paddingInlineStart',
|
|
26
|
+
},
|
|
27
|
+
paddingInlineEnd: {
|
|
28
|
+
cssProperty: 'paddingInlineEnd',
|
|
29
|
+
},
|
|
30
|
+
gap: {
|
|
31
|
+
cssProperty: 'gap',
|
|
32
|
+
},
|
|
33
|
+
columnGap: {
|
|
34
|
+
cssProperty: 'columnGap',
|
|
35
|
+
},
|
|
36
|
+
rowGap: {
|
|
37
|
+
cssProperty: 'rowGap',
|
|
38
|
+
},
|
|
39
|
+
} as const;
|
|
40
|
+
|
|
41
|
+
const onlySpaceTokens = tokens.filter(token => token.name.startsWith('space.'));
|
|
42
|
+
|
|
43
|
+
const activeTokens = onlySpaceTokens.map(t => ({
|
|
44
|
+
name: t.name,
|
|
45
|
+
fallback: t.attributes.pixelValue!,
|
|
46
|
+
}));
|
|
47
|
+
|
|
48
|
+
export const createSpacingStylesFromTemplate = (
|
|
49
|
+
spacingProperty: keyof typeof spacingProperties,
|
|
50
|
+
) => {
|
|
51
|
+
if (!spacingProperties[spacingProperty]) {
|
|
52
|
+
throw new Error(`[codegen] Unknown option found "${spacingProperty}"`);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const { cssProperty } = spacingProperties[spacingProperty];
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
prettier.format(
|
|
59
|
+
`
|
|
60
|
+
const ${spacingProperty}Map = {
|
|
61
|
+
${activeTokens
|
|
62
|
+
.sort((a, b) => (a.name < b.name ? -1 : 1))
|
|
63
|
+
.map(token => {
|
|
64
|
+
const propName = token.name;
|
|
65
|
+
return `'${propName}': ${tokenToStyle(
|
|
66
|
+
cssProperty,
|
|
67
|
+
token.name,
|
|
68
|
+
token.fallback,
|
|
69
|
+
)}`;
|
|
70
|
+
})
|
|
71
|
+
.join(',\n\t')}
|
|
72
|
+
};`,
|
|
73
|
+
{
|
|
74
|
+
singleQuote: true,
|
|
75
|
+
trailingComma: 'all',
|
|
76
|
+
parser: 'typescript',
|
|
77
|
+
plugins: [parserTypeScript],
|
|
78
|
+
},
|
|
79
|
+
) +
|
|
80
|
+
`\nexport type ${capitalize(
|
|
81
|
+
spacingProperty,
|
|
82
|
+
)} = keyof typeof ${spacingProperty}Map;\n`
|
|
83
|
+
);
|
|
84
|
+
};
|