@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.
Files changed (65) hide show
  1. package/CHANGELOG.md +370 -358
  2. package/README.md +4 -3
  3. package/afm-jira/tsconfig.json +24 -0
  4. package/dist/cjs/components/interaction-surface.partial.js +1 -1
  5. package/dist/cjs/index.js +0 -7
  6. package/dist/cjs/internal/color-map.js +1 -1
  7. package/dist/es2019/components/interaction-surface.partial.js +1 -1
  8. package/dist/es2019/index.js +0 -1
  9. package/dist/es2019/internal/color-map.js +1 -1
  10. package/dist/esm/components/interaction-surface.partial.js +1 -1
  11. package/dist/esm/index.js +0 -1
  12. package/dist/esm/internal/color-map.js +1 -1
  13. package/dist/types/components/interaction-surface.partial.d.ts +1 -1
  14. package/dist/types/index.d.ts +0 -2
  15. package/dist/types/internal/color-map.d.ts +1 -1
  16. package/dist/types-ts4.5/components/interaction-surface.partial.d.ts +1 -1
  17. package/dist/types-ts4.5/index.d.ts +0 -2
  18. package/dist/types-ts4.5/internal/color-map.d.ts +1 -1
  19. package/docs/01-basic.tsx +11 -13
  20. package/examples/99-interactions.tsx +174 -176
  21. package/package.json +6 -10
  22. package/report.api.md +127 -126
  23. package/scripts/__tests__/__snapshots__/codegen.test.tsx.snap +540 -540
  24. package/scripts/__tests__/codegen.test.tsx +15 -17
  25. package/scripts/codegen-styles.tsx +25 -92
  26. package/scripts/color-codegen-template.tsx +69 -82
  27. package/scripts/color-map-template.tsx +24 -29
  28. package/scripts/dimension-codegen-template.tsx +32 -35
  29. package/scripts/interaction-codegen.tsx +61 -74
  30. package/scripts/misc-codegen-template.tsx +23 -25
  31. package/scripts/utils.tsx +30 -34
  32. package/src/components/__tests__/unit/interaction-suface.test.tsx +61 -62
  33. package/src/components/interaction-surface.partial.tsx +412 -416
  34. package/src/components/surface-provider.tsx +1 -1
  35. package/src/components/types.tsx +10 -10
  36. package/src/constants.tsx +9 -9
  37. package/src/index.tsx +0 -2
  38. package/src/internal/color-map.tsx +28 -28
  39. package/src/internal/role-to-element.tsx +21 -21
  40. package/tsconfig.app.json +44 -44
  41. package/tsconfig.dev.json +71 -83
  42. package/dist/cjs/components/text.partial.js +0 -280
  43. package/dist/cjs/internal/spacing-scale.js +0 -15
  44. package/dist/es2019/components/text.partial.js +0 -271
  45. package/dist/es2019/internal/spacing-scale.js +0 -9
  46. package/dist/esm/components/text.partial.js +0 -274
  47. package/dist/esm/internal/spacing-scale.js +0 -9
  48. package/dist/types/components/text.partial.d.ts +0 -157
  49. package/dist/types/internal/spacing-scale.d.ts +0 -9
  50. package/dist/types-ts4.5/components/text.partial.d.ts +0 -162
  51. package/dist/types-ts4.5/internal/spacing-scale.d.ts +0 -24
  52. package/examples/02-text-advanced.tsx +0 -30
  53. package/examples/02-text.tsx +0 -110
  54. package/examples/06-section-message.tsx +0 -82
  55. package/examples/07-comment.tsx +0 -51
  56. package/examples/08-lozenge.tsx +0 -34
  57. package/scripts/spacing-codegen-template.tsx +0 -66
  58. package/scripts/spacing-scale-template.tsx +0 -24
  59. package/scripts/typography-codegen-template.tsx +0 -72
  60. package/src/components/__tests__/unit/text.test.tsx +0 -64
  61. package/src/components/__tests__/vr-tests/__snapshots__/text-snapshot-test/text--default.png +0 -0
  62. package/src/components/__tests__/vr-tests/text-snapshot-test.vr.tsx +0 -6
  63. package/src/components/text.partial.tsx +0 -375
  64. package/src/internal/spacing-scale.tsx +0 -24
  65. 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
- token: string;
16
- fallback: string;
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
- text: {
22
- prefix: 'color.text.',
23
- cssProperty: 'color',
24
- filterFn: <T extends Token>(t: T) => t.token.startsWith(colors.text.prefix),
25
- },
26
- background: {
27
- prefix: 'color.background.',
28
- cssProperty: 'backgroundColor',
29
- filterFn: <T extends Token>(t: T) =>
30
- t.token.startsWith(colors.background.prefix) ||
31
- t.token.startsWith('elevation.surface') ||
32
- t.token.startsWith('color.blanket'),
33
- },
34
- border: {
35
- prefix: 'color.border.',
36
- cssProperty: 'borderColor',
37
- filterFn: <T extends Token>(t: T) =>
38
- t.token.startsWith(colors.border.prefix),
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
- .filter(
44
- (t) =>
45
- t.attributes.state !== 'deleted' && t.attributes.state !== 'deprecated',
46
- )
47
- .map(
48
- (t): Token => ({
49
- token: t.name,
50
- fallback: t.value as string,
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
- colorProperty: keyof typeof colors,
60
- ) => {
61
- if (!colors[colorProperty]) {
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
- const { prefix, cssProperty, filterFn } = colors[colorProperty];
51
+ const { prefix, cssProperty, filterFn } = colors[colorProperty];
66
52
 
67
- return (format(
68
- `
53
+ return (
54
+ format(
55
+ `
69
56
  const ${colorProperty}ActiveColorMap = {
70
57
  ${pressedTokens
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('.pressed', '');
77
- return `'${propName}': css({\n\t':active': { ${cssProperty}: token('${t.token}') }\n})`;
78
- })
79
- .join(',\n\t')}
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
- .filter(filterFn)
85
- // @ts-ignore
86
- .map((t) => ({ ...t, token: t.token.replaceAll('.[default]', '') }))
87
- .map((t) => {
88
- // handle the default case eg color.border or color.text
89
- const propName = t.token.replace(prefix, '').replace('.hovered', '');
90
- return `'${propName}': css({\n\t':hover': { ${cssProperty}: token('${t.token}') }\n})`;
91
- })
92
- .join(',\n\t')}
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
- 'typescript',
95
- ) +
96
- `\ntype Interaction${capitalize(
97
- colorProperty,
98
- )}Color = keyof typeof ${colorProperty}HoverColorMap;\n`
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
- 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
- },
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
- property: keyof typeof styleProperties,
21
- ) => {
22
- if (!styleProperties[property]) {
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
- return format(
27
- `
24
+ return format(
25
+ `
28
26
  const ${property}Map = {
29
27
  ${Object.keys(styleProperties[property])
30
- .map((key) => {
31
- return `'${key}': css({ zIndex: LAYERS['${key}'] })`;
32
- })
33
- .join(',\n\t')}
28
+ .map((key) => {
29
+ return `'${key}': css({ zIndex: LAYERS['${key}'] })`;
30
+ })
31
+ .join(',\n\t')}
34
32
  };`,
35
- 'typescript',
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
- prop: keyof CSSProperties,
5
- token: string,
6
- fallback: string | ShadowDefintion,
4
+ prop: keyof CSSProperties,
5
+ token: string,
6
+ fallback: string | ShadowDefintion,
7
7
  ) => {
8
- if (Array.isArray(fallback)) {
9
- fallback = constructShadow(fallback);
10
- }
11
- return `css({\n\t${prop}: token('${token}', '${fallback}')\n})`;
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
- radius: number;
16
- offset: {
17
- x: number;
18
- y: number;
19
- };
20
- color: string;
21
- opacity: number;
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
- return shadowObject
26
- .map(
27
- (shadow) =>
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
- (...fns: ((...any: any[]) => any)[]) =>
37
- (x: any) =>
38
- fns.reduce((res, fn) => fn(res), x);
33
+ (...fns: ((...any: any[]) => any)[]) =>
34
+ (x: any) =>
35
+ fns.reduce((res, fn) => fn(res), x);
39
36
  export const pick =
40
- <T extends any>(key: keyof T) =>
41
- (obj: T) =>
42
- obj[key];
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
- <T extends any>(cb: BooleanCallback<T>) =>
48
- (val: T) =>
49
- !cb(val);
44
+ <T extends any>(cb: BooleanCallback<T>) =>
45
+ (val: T) =>
46
+ !cb(val);
50
47
  export const or =
51
- <T extends any>(...fns: BooleanCallback<T>[]) =>
52
- (val: T) =>
53
- fns.some((fn) => fn(val));
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
- it('should render by itself', () => {
15
- const { getByTestId } = render(
16
- <InteractionSurface testId="basic">
17
- <></>
18
- </InteractionSurface>,
19
- );
20
- expect(getByTestId('basic')).toBeInTheDocument();
21
- });
22
- it('should render given a neutral hover interaction by default', () => {
23
- const { getByTestId } = render(
24
- <div style={{ position: 'relative' }}>
25
- <InteractionSurface testId="surface">hello</InteractionSurface>
26
- </div>,
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
- const surfaceElement = getByTestId('surface');
30
- expect(getComputedStyle(surfaceElement).backgroundColor).toBe('');
31
- act(() => {
32
- fireEvent.mouseOver(surfaceElement);
33
- expect(surfaceElement).toHaveStyle(
34
- `background-color: ${token('color.background.neutral.bold.hovered')}`,
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
- it('should render given a brand hover interaction by if set as brand', () => {
40
- const { getByTestId } = render(
41
- <div style={{ position: 'relative' }}>
42
- <InteractionSurface appearance="brand.bold" testId="surface">
43
- hello
44
- </InteractionSurface>
45
- </div>,
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
- const surfaceElement = getByTestId('surface');
49
- expect(getComputedStyle(surfaceElement).backgroundColor).toBe('');
50
- act(() => {
51
- fireEvent.mouseOver(surfaceElement);
52
- expect(surfaceElement).toHaveStyle(
53
- `background-color: ${token('color.background.brand.bold.hovered')}`,
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
- it('should render an inherited hover state if a Box context is present', () => {
59
- const { getByTestId } = render(
60
- <Box backgroundColor="color.background.brand.bold">
61
- <InteractionSurface testId="surface">
62
- <Text>hello</Text>
63
- </InteractionSurface>
64
- </Box>,
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
- const surfaceElement = getByTestId('surface');
68
- expect(getComputedStyle(surfaceElement).backgroundColor).toBe('');
69
- act(() => {
70
- fireEvent.mouseOver(surfaceElement);
71
- expect(surfaceElement).toHaveStyle(
72
- `background-color: ${token('color.background.brand.bold.hovered')}`,
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
  });