@atlaskit/ds-explorations 3.5.2 → 4.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 +370 -358
- package/README.md +4 -3
- package/afm-jira/tsconfig.json +24 -0
- package/dist/cjs/components/interaction-surface.partial.js +1 -1
- package/dist/cjs/index.js +0 -7
- package/dist/cjs/internal/color-map.js +1 -1
- package/dist/es2019/components/interaction-surface.partial.js +1 -1
- package/dist/es2019/index.js +0 -1
- package/dist/es2019/internal/color-map.js +1 -1
- package/dist/esm/components/interaction-surface.partial.js +1 -1
- package/dist/esm/index.js +0 -1
- package/dist/esm/internal/color-map.js +1 -1
- package/dist/types/components/interaction-surface.partial.d.ts +1 -1
- package/dist/types/index.d.ts +0 -2
- package/dist/types/internal/color-map.d.ts +1 -1
- package/dist/types-ts4.5/components/interaction-surface.partial.d.ts +1 -1
- package/dist/types-ts4.5/index.d.ts +0 -2
- package/dist/types-ts4.5/internal/color-map.d.ts +1 -1
- package/docs/01-basic.tsx +11 -13
- package/examples/99-interactions.tsx +174 -176
- package/package.json +6 -10
- package/report.api.md +127 -126
- package/scripts/__tests__/__snapshots__/codegen.test.tsx.snap +540 -540
- package/scripts/__tests__/codegen.test.tsx +15 -17
- package/scripts/codegen-styles.tsx +25 -92
- package/scripts/color-codegen-template.tsx +69 -82
- package/scripts/color-map-template.tsx +24 -29
- package/scripts/dimension-codegen-template.tsx +32 -35
- package/scripts/interaction-codegen.tsx +61 -74
- package/scripts/misc-codegen-template.tsx +23 -25
- package/scripts/utils.tsx +30 -34
- package/src/components/__tests__/unit/interaction-suface.test.tsx +61 -62
- package/src/components/interaction-surface.partial.tsx +412 -416
- package/src/components/surface-provider.tsx +1 -1
- package/src/components/types.tsx +10 -10
- package/src/constants.tsx +9 -9
- package/src/index.tsx +0 -2
- package/src/internal/color-map.tsx +28 -28
- package/src/internal/role-to-element.tsx +21 -21
- package/tsconfig.app.json +44 -44
- package/tsconfig.dev.json +71 -83
- package/dist/cjs/components/text.partial.js +0 -280
- package/dist/cjs/internal/spacing-scale.js +0 -15
- package/dist/es2019/components/text.partial.js +0 -271
- package/dist/es2019/internal/spacing-scale.js +0 -9
- package/dist/esm/components/text.partial.js +0 -274
- package/dist/esm/internal/spacing-scale.js +0 -9
- package/dist/types/components/text.partial.d.ts +0 -157
- package/dist/types/internal/spacing-scale.d.ts +0 -9
- package/dist/types-ts4.5/components/text.partial.d.ts +0 -162
- package/dist/types-ts4.5/internal/spacing-scale.d.ts +0 -24
- package/examples/02-text-advanced.tsx +0 -30
- package/examples/02-text.tsx +0 -110
- package/examples/06-section-message.tsx +0 -82
- package/examples/07-comment.tsx +0 -51
- package/examples/08-lozenge.tsx +0 -34
- package/scripts/spacing-codegen-template.tsx +0 -66
- package/scripts/spacing-scale-template.tsx +0 -24
- package/scripts/typography-codegen-template.tsx +0 -72
- package/src/components/__tests__/unit/text.test.tsx +0 -64
- package/src/components/__tests__/vr-tests/__snapshots__/text-snapshot-test/text--default.png +0 -0
- package/src/components/__tests__/vr-tests/text-snapshot-test.vr.tsx +0 -6
- package/src/components/text.partial.tsx +0 -375
- package/src/internal/spacing-scale.tsx +0 -24
- package/text/package.json +0 -15
|
@@ -1,100 +1,87 @@
|
|
|
1
1
|
import format from '@af/formatting/sync';
|
|
2
2
|
import { light as tokens } from '@atlaskit/tokens/tokens-raw';
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
capitalize,
|
|
6
|
-
compose,
|
|
7
|
-
isAccent,
|
|
8
|
-
isHovered,
|
|
9
|
-
isPressed,
|
|
10
|
-
or,
|
|
11
|
-
pick,
|
|
12
|
-
} from './utils';
|
|
4
|
+
import { capitalize, compose, isAccent, isHovered, isPressed, or, pick } from './utils';
|
|
13
5
|
|
|
14
6
|
type Token = {
|
|
15
|
-
|
|
16
|
-
|
|
7
|
+
token: string;
|
|
8
|
+
fallback: string;
|
|
17
9
|
};
|
|
18
10
|
|
|
19
11
|
// NB: Fallback CSS variables can be deleted when tokens are no longer behind a feature flag
|
|
20
12
|
const colors = {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
},
|
|
13
|
+
text: {
|
|
14
|
+
prefix: 'color.text.',
|
|
15
|
+
cssProperty: 'color',
|
|
16
|
+
filterFn: <T extends Token>(t: T) => t.token.startsWith(colors.text.prefix),
|
|
17
|
+
},
|
|
18
|
+
background: {
|
|
19
|
+
prefix: 'color.background.',
|
|
20
|
+
cssProperty: 'backgroundColor',
|
|
21
|
+
filterFn: <T extends Token>(t: T) =>
|
|
22
|
+
t.token.startsWith(colors.background.prefix) ||
|
|
23
|
+
t.token.startsWith('elevation.surface') ||
|
|
24
|
+
t.token.startsWith('color.blanket'),
|
|
25
|
+
},
|
|
26
|
+
border: {
|
|
27
|
+
prefix: 'color.border.',
|
|
28
|
+
cssProperty: 'borderColor',
|
|
29
|
+
filterFn: <T extends Token>(t: T) => t.token.startsWith(colors.border.prefix),
|
|
30
|
+
},
|
|
40
31
|
} as const;
|
|
41
32
|
|
|
42
33
|
const activeTokens = tokens
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}),
|
|
52
|
-
)
|
|
53
|
-
.filter(compose(pick('token'), or(isAccent, isPressed, isHovered)));
|
|
34
|
+
.filter((t) => t.attributes.state !== 'deleted' && t.attributes.state !== 'deprecated')
|
|
35
|
+
.map(
|
|
36
|
+
(t): Token => ({
|
|
37
|
+
token: t.name,
|
|
38
|
+
fallback: t.value as string,
|
|
39
|
+
}),
|
|
40
|
+
)
|
|
41
|
+
.filter(compose(pick('token'), or(isAccent, isPressed, isHovered)));
|
|
54
42
|
|
|
55
43
|
const pressedTokens = activeTokens.filter(compose(pick('token'), isPressed));
|
|
56
44
|
const hoveredTokens = activeTokens.filter(compose(pick('token'), isHovered));
|
|
57
45
|
|
|
58
|
-
export const createInteractionStylesFromTemplate = (
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
throw new Error(`[codegen] Unknown option found "${colorProperty}"`);
|
|
63
|
-
}
|
|
46
|
+
export const createInteractionStylesFromTemplate = (colorProperty: keyof typeof colors) => {
|
|
47
|
+
if (!colors[colorProperty]) {
|
|
48
|
+
throw new Error(`[codegen] Unknown option found "${colorProperty}"`);
|
|
49
|
+
}
|
|
64
50
|
|
|
65
|
-
|
|
51
|
+
const { prefix, cssProperty, filterFn } = colors[colorProperty];
|
|
66
52
|
|
|
67
|
-
|
|
68
|
-
|
|
53
|
+
return (
|
|
54
|
+
format(
|
|
55
|
+
`
|
|
69
56
|
const ${colorProperty}ActiveColorMap = {
|
|
70
57
|
${pressedTokens
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
58
|
+
.filter(filterFn)
|
|
59
|
+
// @ts-ignore
|
|
60
|
+
.map((t) => ({ ...t, token: t.token.replaceAll('.[default]', '') }))
|
|
61
|
+
.map((t) => {
|
|
62
|
+
// handle the default case eg color.border or color.text
|
|
63
|
+
const propName = t.token.replace(prefix, '').replace('.pressed', '');
|
|
64
|
+
return `'${propName}': css({\n\t':active': { ${cssProperty}: token('${t.token}') }\n})`;
|
|
65
|
+
})
|
|
66
|
+
.join(',\n\t')}
|
|
80
67
|
};
|
|
81
68
|
|
|
82
69
|
const ${colorProperty}HoverColorMap = {
|
|
83
70
|
${hoveredTokens
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
71
|
+
.filter(filterFn)
|
|
72
|
+
// @ts-ignore
|
|
73
|
+
.map((t) => ({ ...t, token: t.token.replaceAll('.[default]', '') }))
|
|
74
|
+
.map((t) => {
|
|
75
|
+
// handle the default case eg color.border or color.text
|
|
76
|
+
const propName = t.token.replace(prefix, '').replace('.hovered', '');
|
|
77
|
+
return `'${propName}': css({\n\t':hover': { ${cssProperty}: token('${t.token}') }\n})`;
|
|
78
|
+
})
|
|
79
|
+
.join(',\n\t')}
|
|
93
80
|
};`,
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
81
|
+
'typescript',
|
|
82
|
+
) +
|
|
83
|
+
`\ntype Interaction${capitalize(
|
|
84
|
+
colorProperty,
|
|
85
|
+
)}Color = keyof typeof ${colorProperty}HoverColorMap;\n`
|
|
86
|
+
);
|
|
100
87
|
};
|
|
@@ -3,35 +3,33 @@ import format from '@af/formatting/sync';
|
|
|
3
3
|
import type { Layer } from '../src/constants';
|
|
4
4
|
|
|
5
5
|
const styleProperties: Record<'layer', Record<Layer, number>> = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
6
|
+
layer: {
|
|
7
|
+
card: 100,
|
|
8
|
+
navigation: 200,
|
|
9
|
+
dialog: 300,
|
|
10
|
+
layer: 400,
|
|
11
|
+
blanket: 500,
|
|
12
|
+
modal: 510,
|
|
13
|
+
flag: 600,
|
|
14
|
+
spotlight: 700,
|
|
15
|
+
tooltip: 800,
|
|
16
|
+
},
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
export const createStylesFromTemplate = (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
throw new Error(`[codegen] Unknown option found "${property}"`);
|
|
24
|
-
}
|
|
19
|
+
export const createStylesFromTemplate = (property: keyof typeof styleProperties) => {
|
|
20
|
+
if (!styleProperties[property]) {
|
|
21
|
+
throw new Error(`[codegen] Unknown option found "${property}"`);
|
|
22
|
+
}
|
|
25
23
|
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
return format(
|
|
25
|
+
`
|
|
28
26
|
const ${property}Map = {
|
|
29
27
|
${Object.keys(styleProperties[property])
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
.map((key) => {
|
|
29
|
+
return `'${key}': css({ zIndex: LAYERS['${key}'] })`;
|
|
30
|
+
})
|
|
31
|
+
.join(',\n\t')}
|
|
34
32
|
};`,
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
'typescript',
|
|
34
|
+
);
|
|
37
35
|
};
|
package/scripts/utils.tsx
CHANGED
|
@@ -1,55 +1,51 @@
|
|
|
1
1
|
import type { CSSProperties } from 'react';
|
|
2
2
|
|
|
3
3
|
export const tokenToStyle = (
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
prop: keyof CSSProperties,
|
|
5
|
+
token: string,
|
|
6
|
+
fallback: string | ShadowDefintion,
|
|
7
7
|
) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
if (Array.isArray(fallback)) {
|
|
9
|
+
fallback = constructShadow(fallback);
|
|
10
|
+
}
|
|
11
|
+
return `css({\n\t${prop}: token('${token}', '${fallback}')\n})`;
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
export type ShadowDefintion = Array<{
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
radius: number;
|
|
16
|
+
offset: {
|
|
17
|
+
x: number;
|
|
18
|
+
y: number;
|
|
19
|
+
};
|
|
20
|
+
color: string;
|
|
21
|
+
opacity: number;
|
|
22
22
|
}>;
|
|
23
23
|
|
|
24
24
|
const constructShadow = (shadowObject: ShadowDefintion) => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
`${shadow.offset.x}px ${shadow.offset.y}px ${shadow.radius}px ${shadow.color}`,
|
|
29
|
-
)
|
|
30
|
-
.join(', ');
|
|
25
|
+
return shadowObject
|
|
26
|
+
.map((shadow) => `${shadow.offset.x}px ${shadow.offset.y}px ${shadow.radius}px ${shadow.color}`)
|
|
27
|
+
.join(', ');
|
|
31
28
|
};
|
|
32
29
|
|
|
33
30
|
type BooleanCallback<T> = (args: T) => boolean;
|
|
34
31
|
|
|
35
32
|
export const compose =
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
(...fns: ((...any: any[]) => any)[]) =>
|
|
34
|
+
(x: any) =>
|
|
35
|
+
fns.reduce((res, fn) => fn(res), x);
|
|
39
36
|
export const pick =
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
<T extends any>(key: keyof T) =>
|
|
38
|
+
(obj: T) =>
|
|
39
|
+
obj[key];
|
|
43
40
|
export const isAccent = (str: string) => str.includes('accent');
|
|
44
41
|
export const isPressed = (str: string) => str.includes('pressed');
|
|
45
42
|
export const isHovered = (str: string) => str.includes('hovered');
|
|
46
43
|
export const not =
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
<T extends any>(cb: BooleanCallback<T>) =>
|
|
45
|
+
(val: T) =>
|
|
46
|
+
!cb(val);
|
|
50
47
|
export const or =
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
export const capitalize = (str: string) =>
|
|
55
|
-
str.charAt(0).toUpperCase() + str.slice(1);
|
|
48
|
+
<T extends any>(...fns: BooleanCallback<T>[]) =>
|
|
49
|
+
(val: T) =>
|
|
50
|
+
fns.some((fn) => fn(val));
|
|
51
|
+
export const capitalize = (str: string) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
@@ -2,75 +2,74 @@ import React from 'react';
|
|
|
2
2
|
|
|
3
3
|
import { act, fireEvent, render } from '@testing-library/react';
|
|
4
4
|
|
|
5
|
-
import { Box } from '@atlaskit/primitives';
|
|
5
|
+
import { Box, Text } from '@atlaskit/primitives';
|
|
6
6
|
import { token } from '@atlaskit/tokens';
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
UNSAFE_InteractionSurface as InteractionSurface,
|
|
10
|
-
UNSAFE_Text as Text,
|
|
11
|
-
} from '../../../index';
|
|
8
|
+
import { UNSAFE_InteractionSurface as InteractionSurface } from '../../../index';
|
|
12
9
|
|
|
13
10
|
describe('InteractionSurface component', () => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
11
|
+
it('should render by itself', () => {
|
|
12
|
+
const { getByTestId } = render(
|
|
13
|
+
<InteractionSurface testId="basic">
|
|
14
|
+
<></>
|
|
15
|
+
</InteractionSurface>,
|
|
16
|
+
);
|
|
17
|
+
expect(getByTestId('basic')).toBeInTheDocument();
|
|
18
|
+
});
|
|
19
|
+
it('should render given a neutral hover interaction by default', () => {
|
|
20
|
+
const { getByTestId } = render(
|
|
21
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
|
|
22
|
+
<div style={{ position: 'relative' }}>
|
|
23
|
+
<InteractionSurface testId="surface">hello</InteractionSurface>
|
|
24
|
+
</div>,
|
|
25
|
+
);
|
|
28
26
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
27
|
+
const surfaceElement = getByTestId('surface');
|
|
28
|
+
expect(getComputedStyle(surfaceElement).backgroundColor).toBe('');
|
|
29
|
+
act(() => {
|
|
30
|
+
fireEvent.mouseOver(surfaceElement);
|
|
31
|
+
expect(surfaceElement).toHaveStyle(
|
|
32
|
+
`background-color: ${token('color.background.neutral.bold.hovered')}`,
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
38
36
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
37
|
+
it('should render given a brand hover interaction by if set as brand', () => {
|
|
38
|
+
const { getByTestId } = render(
|
|
39
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
|
|
40
|
+
<div style={{ position: 'relative' }}>
|
|
41
|
+
<InteractionSurface appearance="brand.bold" testId="surface">
|
|
42
|
+
hello
|
|
43
|
+
</InteractionSurface>
|
|
44
|
+
</div>,
|
|
45
|
+
);
|
|
47
46
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
47
|
+
const surfaceElement = getByTestId('surface');
|
|
48
|
+
expect(getComputedStyle(surfaceElement).backgroundColor).toBe('');
|
|
49
|
+
act(() => {
|
|
50
|
+
fireEvent.mouseOver(surfaceElement);
|
|
51
|
+
expect(surfaceElement).toHaveStyle(
|
|
52
|
+
`background-color: ${token('color.background.brand.bold.hovered')}`,
|
|
53
|
+
);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
57
56
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
57
|
+
it('should render an inherited hover state if a Box context is present', () => {
|
|
58
|
+
const { getByTestId } = render(
|
|
59
|
+
<Box backgroundColor="color.background.brand.bold">
|
|
60
|
+
<InteractionSurface testId="surface">
|
|
61
|
+
<Text>hello</Text>
|
|
62
|
+
</InteractionSurface>
|
|
63
|
+
</Box>,
|
|
64
|
+
);
|
|
66
65
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
66
|
+
const surfaceElement = getByTestId('surface');
|
|
67
|
+
expect(getComputedStyle(surfaceElement).backgroundColor).toBe('');
|
|
68
|
+
act(() => {
|
|
69
|
+
fireEvent.mouseOver(surfaceElement);
|
|
70
|
+
expect(surfaceElement).toHaveStyle(
|
|
71
|
+
`background-color: ${token('color.background.brand.bold.hovered')}`,
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
76
75
|
});
|