@atlaskit/ds-explorations 0.0.3 → 0.1.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/CHANGELOG.md +32 -0
- package/dist/cjs/components/box.partial.js +355 -185
- package/dist/cjs/components/inline.partial.js +124 -0
- package/dist/cjs/components/interaction-surface.partial.js +253 -0
- package/dist/cjs/components/stack.partial.js +116 -0
- package/dist/cjs/components/surface-provider.js +31 -0
- package/dist/cjs/components/text.partial.js +152 -49
- package/dist/cjs/components/types.js +5 -0
- package/dist/cjs/constants.js +3 -0
- package/dist/cjs/index.js +50 -3
- package/dist/cjs/internal/color-map.js +42 -0
- package/dist/cjs/internal/role-to-element.js +36 -0
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/components/box.partial.js +259 -113
- package/dist/es2019/components/inline.partial.js +111 -0
- package/dist/es2019/components/interaction-surface.partial.js +243 -0
- package/dist/es2019/components/stack.partial.js +106 -0
- package/dist/es2019/components/surface-provider.js +20 -0
- package/dist/es2019/components/text.partial.js +122 -35
- package/dist/es2019/components/types.js +1 -0
- package/dist/es2019/constants.js +3 -0
- package/dist/es2019/index.js +6 -1
- package/dist/es2019/internal/color-map.js +34 -0
- package/dist/es2019/internal/role-to-element.js +28 -0
- package/dist/es2019/version.json +1 -1
- package/dist/esm/components/box.partial.js +274 -109
- package/dist/esm/components/inline.partial.js +110 -0
- package/dist/esm/components/interaction-surface.partial.js +242 -0
- package/dist/esm/components/stack.partial.js +105 -0
- package/dist/esm/components/surface-provider.js +20 -0
- package/dist/esm/components/text.partial.js +132 -34
- package/dist/esm/components/types.js +1 -0
- package/dist/esm/constants.js +3 -0
- package/dist/esm/index.js +6 -1
- package/dist/esm/internal/color-map.js +34 -0
- package/dist/esm/internal/role-to-element.js +28 -0
- package/dist/esm/version.json +1 -1
- package/dist/types/components/box.partial.d.ts +157 -76
- package/dist/types/components/inline.partial.d.ts +52 -0
- package/dist/types/components/interaction-surface.partial.d.ts +45 -0
- package/dist/types/components/stack.partial.d.ts +47 -0
- package/dist/types/components/surface-provider.d.ts +15 -0
- package/dist/types/components/text.partial.d.ts +100 -28
- package/dist/types/components/types.d.ts +13 -0
- package/dist/types/constants.d.ts +3 -0
- package/dist/types/index.d.ts +8 -2
- package/dist/types/internal/color-map.d.ts +34 -0
- package/dist/types/internal/role-to-element.d.ts +32 -0
- package/examples/00-basic.tsx +18 -1
- package/examples/01-box.tsx +126 -2
- package/examples/02-text.tsx +76 -2
- package/examples/03-stack.tsx +125 -0
- package/examples/04-inline.tsx +134 -0
- package/examples/{03-badge.tsx → 05-badge.tsx} +4 -4
- package/examples/{04-section-message.tsx → 06-section-message.tsx} +6 -6
- package/examples/{05-comment.tsx → 07-comment.tsx} +11 -9
- package/examples/08-lozenge.tsx +29 -0
- package/examples/99-interactions.tsx +175 -0
- package/package.json +8 -5
- package/report.api.md +457 -4
- package/scripts/__tests__/__snapshots__/codegen.test.tsx.snap +244 -50
- package/scripts/__tests__/codegen.test.tsx +5 -0
- package/scripts/codegen-styles.tsx +46 -10
- package/scripts/color-codegen-template.tsx +34 -12
- package/scripts/color-map-template.tsx +52 -0
- package/scripts/interaction-codegen.tsx +109 -0
- package/scripts/spacing-codegen-template.tsx +9 -1
- package/scripts/utils.tsx +5 -1
- package/src/components/__tests__/unit/box.test.tsx +50 -0
- package/src/components/__tests__/unit/inline.test.tsx +43 -0
- package/src/components/__tests__/unit/interaction-suface.test.tsx +70 -0
- package/src/components/__tests__/unit/stack.test.tsx +31 -0
- package/src/components/__tests__/unit/text.test.tsx +33 -0
- package/src/components/__tests__/visual-regression/__image_snapshots__/box-snapshot-test-tsx-box-basic-example-should-match-production-example-1-snap.png +3 -0
- package/src/components/__tests__/visual-regression/__image_snapshots__/box-snapshot-test-tsx-box-example-with-alignment-should-match-snapshot-1-snap.png +3 -0
- package/src/components/__tests__/visual-regression/__image_snapshots__/box-snapshot-test-tsx-box-example-with-background-and-padding-block-should-match-snapshot-1-snap.png +3 -0
- package/src/components/__tests__/visual-regression/__image_snapshots__/box-snapshot-test-tsx-box-example-with-background-and-padding-inline-should-match-snapshot-1-snap.png +3 -0
- package/src/components/__tests__/visual-regression/__image_snapshots__/box-snapshot-test-tsx-box-example-with-background-and-padding-should-match-snapshot-1-snap.png +3 -0
- package/src/components/__tests__/visual-regression/__image_snapshots__/box-snapshot-test-tsx-box-example-with-background-color-should-match-snapshot-1-snap.png +3 -0
- package/src/components/__tests__/visual-regression/__image_snapshots__/box-snapshot-test-tsx-box-example-with-border-color-should-match-snapshot-1-snap.png +3 -0
- package/src/components/__tests__/visual-regression/__image_snapshots__/box-snapshot-test-tsx-box-example-with-border-should-match-snapshot-1-snap.png +3 -0
- package/src/components/__tests__/visual-regression/__image_snapshots__/inline-snapshot-test-tsx-inline-alignment-example-should-match-snapshot-1-snap.png +3 -0
- package/src/components/__tests__/visual-regression/__image_snapshots__/inline-snapshot-test-tsx-inline-spacing-example-should-match-snapshot-1-snap.png +3 -0
- package/src/components/__tests__/visual-regression/__image_snapshots__/stack-snapshot-test-tsx-stack-alignment-example-should-match-snapshot-1-snap.png +3 -0
- package/src/components/__tests__/visual-regression/__image_snapshots__/stack-snapshot-test-tsx-stack-spacing-example-should-match-snapshot-1-snap.png +3 -0
- package/src/components/__tests__/visual-regression/__image_snapshots__/text-snapshot-test-tsx-text-example-with-font-sizes-should-match-snapshot-1-snap.png +3 -0
- package/src/components/__tests__/visual-regression/__image_snapshots__/text-snapshot-test-tsx-text-example-with-font-weights-should-match-snapshot-1-snap.png +3 -0
- package/src/components/__tests__/visual-regression/__image_snapshots__/text-snapshot-test-tsx-text-example-with-line-heights-should-match-snapshot-1-snap.png +3 -0
- package/src/components/__tests__/visual-regression/__image_snapshots__/text-snapshot-test-tsx-text-example-with-testing-should-match-snapshot-1-snap.png +3 -0
- package/src/components/__tests__/visual-regression/box-snapshot-test.tsx +33 -0
- package/src/components/__tests__/visual-regression/inline-snapshot-test.tsx +28 -0
- package/src/components/__tests__/visual-regression/stack-snapshot-test.tsx +28 -0
- package/src/components/__tests__/visual-regression/text-snapshot-test.tsx +31 -0
- package/src/components/box.partial.tsx +305 -127
- package/src/components/inline.partial.tsx +120 -0
- package/src/components/interaction-surface.partial.tsx +237 -0
- package/src/components/stack.partial.tsx +104 -0
- package/src/components/surface-provider.tsx +25 -0
- package/src/components/text.partial.tsx +149 -38
- package/src/components/types.tsx +15 -0
- package/src/constants.tsx +3 -0
- package/src/index.tsx +8 -1
- package/src/internal/color-map.tsx +34 -0
- package/src/internal/role-to-element.tsx +34 -0
- package/dist/cjs/components/inline.js +0 -45
- package/dist/cjs/components/stack.js +0 -33
- package/dist/es2019/components/inline.js +0 -31
- package/dist/es2019/components/stack.js +0 -22
- package/dist/esm/components/inline.js +0 -30
- package/dist/esm/components/stack.js +0 -21
- package/dist/types/components/inline.d.ts +0 -19
- package/dist/types/components/stack.d.ts +0 -16
- package/src/components/inline.tsx +0 -49
- package/src/components/stack.tsx +0 -30
|
@@ -0,0 +1,109 @@
|
|
|
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 {
|
|
8
|
+
capitalize,
|
|
9
|
+
compose,
|
|
10
|
+
isAccent,
|
|
11
|
+
isHovered,
|
|
12
|
+
isPressed,
|
|
13
|
+
or,
|
|
14
|
+
pick,
|
|
15
|
+
} from './utils';
|
|
16
|
+
|
|
17
|
+
type Token = {
|
|
18
|
+
token: string;
|
|
19
|
+
fallback: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// NB: Fallback CSS variables can be deleted when tokens are no longer behind a feature flag
|
|
23
|
+
const colors = {
|
|
24
|
+
text: {
|
|
25
|
+
prefix: 'color.text.',
|
|
26
|
+
cssProperty: 'color',
|
|
27
|
+
filterFn: <T extends Token>(t: T) => t.token.startsWith(colors.text.prefix),
|
|
28
|
+
},
|
|
29
|
+
background: {
|
|
30
|
+
prefix: 'color.background.',
|
|
31
|
+
cssProperty: 'backgroundColor',
|
|
32
|
+
filterFn: <T extends Token>(t: T) =>
|
|
33
|
+
t.token.startsWith(colors.background.prefix) ||
|
|
34
|
+
t.token.startsWith('elevation.surface') ||
|
|
35
|
+
t.token.startsWith('color.blanket'),
|
|
36
|
+
},
|
|
37
|
+
border: {
|
|
38
|
+
prefix: 'color.border.',
|
|
39
|
+
cssProperty: 'borderColor',
|
|
40
|
+
filterFn: <T extends Token>(t: T) =>
|
|
41
|
+
t.token.startsWith(colors.border.prefix),
|
|
42
|
+
},
|
|
43
|
+
} as const;
|
|
44
|
+
|
|
45
|
+
const activeTokens = tokens
|
|
46
|
+
.filter(
|
|
47
|
+
(t) =>
|
|
48
|
+
t.attributes.state !== 'deleted' && t.attributes.state !== 'deprecated',
|
|
49
|
+
)
|
|
50
|
+
.map(
|
|
51
|
+
(t): Token => ({
|
|
52
|
+
token: t.name,
|
|
53
|
+
fallback: t.value as string,
|
|
54
|
+
}),
|
|
55
|
+
)
|
|
56
|
+
.filter(compose(pick('token'), or(isAccent, isPressed, isHovered)));
|
|
57
|
+
|
|
58
|
+
const pressedTokens = activeTokens.filter(compose(pick('token'), isPressed));
|
|
59
|
+
const hoveredTokens = activeTokens.filter(compose(pick('token'), isHovered));
|
|
60
|
+
|
|
61
|
+
export const createInteractionStylesFromTemplate = (
|
|
62
|
+
colorProperty: keyof typeof colors,
|
|
63
|
+
) => {
|
|
64
|
+
if (!colors[colorProperty]) {
|
|
65
|
+
throw new Error(`[codegen] Unknown option found "${colorProperty}"`);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const { prefix, cssProperty, filterFn } = colors[colorProperty];
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
prettier.format(
|
|
72
|
+
`
|
|
73
|
+
const ${colorProperty}ActiveColorMap = {
|
|
74
|
+
${pressedTokens
|
|
75
|
+
.filter(filterFn)
|
|
76
|
+
// @ts-ignore
|
|
77
|
+
.map((t) => ({ ...t, token: t.token.replaceAll('.[default]', '') }))
|
|
78
|
+
.map((t) => {
|
|
79
|
+
// handle the default case eg color.border or color.text
|
|
80
|
+
const propName = t.token.replace(prefix, '').replace('.pressed', '');
|
|
81
|
+
return `'${propName}': css({\n\t':active': { ${cssProperty}: token('${t.token}') }\n})`;
|
|
82
|
+
})
|
|
83
|
+
.join(',\n\t')}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const ${colorProperty}HoverColorMap = {
|
|
87
|
+
${hoveredTokens
|
|
88
|
+
.filter(filterFn)
|
|
89
|
+
// @ts-ignore
|
|
90
|
+
.map((t) => ({ ...t, token: t.token.replaceAll('.[default]', '') }))
|
|
91
|
+
.map((t) => {
|
|
92
|
+
// handle the default case eg color.border or color.text
|
|
93
|
+
const propName = t.token.replace(prefix, '').replace('.hovered', '');
|
|
94
|
+
return `'${propName}': css({\n\t':hover': { ${cssProperty}: token('${t.token}') }\n})`;
|
|
95
|
+
})
|
|
96
|
+
.join(',\n\t')}
|
|
97
|
+
};`,
|
|
98
|
+
{
|
|
99
|
+
singleQuote: true,
|
|
100
|
+
parser: 'typescript',
|
|
101
|
+
trailingComma: 'all',
|
|
102
|
+
plugins: [parserTypeScript],
|
|
103
|
+
},
|
|
104
|
+
) +
|
|
105
|
+
`\ntype Interaction${capitalize(
|
|
106
|
+
colorProperty,
|
|
107
|
+
)}Color = keyof typeof ${colorProperty}HoverColorMap;\n`
|
|
108
|
+
);
|
|
109
|
+
};
|
|
@@ -10,6 +10,9 @@ const spacingProperties = {
|
|
|
10
10
|
height: {
|
|
11
11
|
cssProperty: 'height',
|
|
12
12
|
},
|
|
13
|
+
padding: {
|
|
14
|
+
cssProperty: 'padding',
|
|
15
|
+
},
|
|
13
16
|
paddingBlock: {
|
|
14
17
|
cssProperty: 'paddingBlock',
|
|
15
18
|
},
|
|
@@ -39,6 +42,11 @@ const ${spacingProperty}Map = {
|
|
|
39
42
|
})
|
|
40
43
|
.join(',\n\t')}
|
|
41
44
|
};`,
|
|
42
|
-
{
|
|
45
|
+
{
|
|
46
|
+
singleQuote: true,
|
|
47
|
+
trailingComma: 'all',
|
|
48
|
+
parser: 'typescript',
|
|
49
|
+
plugins: [parserTypeScript],
|
|
50
|
+
},
|
|
43
51
|
);
|
|
44
52
|
};
|
package/scripts/utils.tsx
CHANGED
|
@@ -10,13 +10,17 @@ export const tokenToStyle = (
|
|
|
10
10
|
})\n})`;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
+
type BooleanCallback<T> = (args: T) => boolean;
|
|
14
|
+
|
|
13
15
|
export const compose = (...fns: ((...any: any[]) => any)[]) => (x: any) =>
|
|
14
16
|
fns.reduce((res, fn) => fn(res), x);
|
|
15
17
|
export const pick = <T extends any>(key: keyof T) => (obj: T) => obj[key];
|
|
16
18
|
export const isAccent = (str: string) => str.includes('accent');
|
|
17
19
|
export const isPressed = (str: string) => str.includes('pressed');
|
|
18
20
|
export const isHovered = (str: string) => str.includes('hovered');
|
|
19
|
-
export const not = <T extends any>(cb:
|
|
21
|
+
export const not = <T extends any>(cb: BooleanCallback<T>) => (val: T) =>
|
|
20
22
|
!cb(val);
|
|
23
|
+
export const or = <T extends any>(...fns: BooleanCallback<T>[]) => (val: T) =>
|
|
24
|
+
fns.some((fn) => fn(val));
|
|
21
25
|
export const capitalize = (str: string) =>
|
|
22
26
|
str.charAt(0).toUpperCase() + str.slice(1);
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { render } from '@testing-library/react';
|
|
4
|
+
|
|
5
|
+
import { token } from '@atlaskit/tokens';
|
|
6
|
+
|
|
7
|
+
import { UNSAFE_Box as Box, UNSAFE_Text as Text } from '../../../index';
|
|
8
|
+
|
|
9
|
+
describe('Box component', () => {
|
|
10
|
+
const testId = 'test';
|
|
11
|
+
|
|
12
|
+
it('should render box', () => {
|
|
13
|
+
const { getByText } = render(<Box>Box</Box>);
|
|
14
|
+
expect(getByText('Box')).toBeInTheDocument();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
describe('with SurfaceContext', () => {
|
|
18
|
+
it('should invert text color when box sets background', () => {
|
|
19
|
+
const { getByText } = render(
|
|
20
|
+
<Box backgroundColor={['brand.bold', '']}>
|
|
21
|
+
<Text>Text</Text>
|
|
22
|
+
</Box>,
|
|
23
|
+
);
|
|
24
|
+
const element = getByText('Text');
|
|
25
|
+
expect(element).toHaveStyleDeclaration(
|
|
26
|
+
'color',
|
|
27
|
+
token('color.text.inverse', 'var(--ds-co-fb)'),
|
|
28
|
+
);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('should respect text color when text sets its own color', () => {
|
|
32
|
+
const { getByText } = render(
|
|
33
|
+
<Box backgroundColor={['brand.bold', '']}>
|
|
34
|
+
<Text color={['disabled', '']}>Text</Text>
|
|
35
|
+
</Box>,
|
|
36
|
+
);
|
|
37
|
+
const element = getByText('Text');
|
|
38
|
+
expect(element).toHaveStyleDeclaration(
|
|
39
|
+
'color',
|
|
40
|
+
token('color.text.disabled', 'var(--ds-co-fb)'),
|
|
41
|
+
);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should render with a given test id', () => {
|
|
46
|
+
const { getByTestId } = render(<Box testId={testId}>Box with testid</Box>);
|
|
47
|
+
const element = getByTestId(testId);
|
|
48
|
+
expect(element).toBeInTheDocument();
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { render } from '@testing-library/react';
|
|
4
|
+
|
|
5
|
+
import { UNSAFE_Box as Box, UNSAFE_Inline as Inline } from '../../../index';
|
|
6
|
+
|
|
7
|
+
describe('Inline component', () => {
|
|
8
|
+
const testId = 'test';
|
|
9
|
+
|
|
10
|
+
it('should render inline', () => {
|
|
11
|
+
const { getByText } = render(
|
|
12
|
+
<Inline gap="sp-50">
|
|
13
|
+
<Box>1</Box>
|
|
14
|
+
<Box>2</Box>
|
|
15
|
+
</Inline>,
|
|
16
|
+
);
|
|
17
|
+
expect(getByText('1')).toBeInTheDocument();
|
|
18
|
+
expect(getByText('2')).toBeInTheDocument();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('should render inline with dividers', () => {
|
|
22
|
+
const { getByText } = render(
|
|
23
|
+
<Inline gap="sp-50" divider="/">
|
|
24
|
+
<Box>1</Box>
|
|
25
|
+
<Box>2</Box>
|
|
26
|
+
</Inline>,
|
|
27
|
+
);
|
|
28
|
+
expect(getByText('1')).toBeInTheDocument();
|
|
29
|
+
expect(getByText('2')).toBeInTheDocument();
|
|
30
|
+
expect(getByText('/')).toBeInTheDocument();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('should render with a given test id', () => {
|
|
34
|
+
const { getByTestId } = render(
|
|
35
|
+
<Inline gap="sp-50" testId={testId}>
|
|
36
|
+
<Box>1</Box>
|
|
37
|
+
<Box>2</Box>
|
|
38
|
+
</Inline>,
|
|
39
|
+
);
|
|
40
|
+
const element = getByTestId(testId);
|
|
41
|
+
expect(element).toBeInTheDocument();
|
|
42
|
+
});
|
|
43
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { act, fireEvent, render } from '@testing-library/react';
|
|
4
|
+
|
|
5
|
+
import { token } from '@atlaskit/tokens';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
UNSAFE_Box as Box,
|
|
9
|
+
UNSAFE_InteractionSurface as InteractionSurface,
|
|
10
|
+
} from '../../../index';
|
|
11
|
+
|
|
12
|
+
describe('InteractionSurface component', () => {
|
|
13
|
+
it('should render by itself', () => {
|
|
14
|
+
const { getByTestId } = render(<InteractionSurface testId="basic" />);
|
|
15
|
+
expect(getByTestId('basic')).toBeInTheDocument();
|
|
16
|
+
});
|
|
17
|
+
it('should render given a neutral hover interaction by default', () => {
|
|
18
|
+
const { getByTestId } = render(
|
|
19
|
+
<div style={{ position: 'relative' }}>
|
|
20
|
+
<InteractionSurface testId="surface" />
|
|
21
|
+
hello
|
|
22
|
+
</div>,
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
const surfaceElement = getByTestId('surface');
|
|
26
|
+
expect(getComputedStyle(surfaceElement).backgroundColor).toBe('');
|
|
27
|
+
act(() => {
|
|
28
|
+
fireEvent.mouseOver(surfaceElement);
|
|
29
|
+
expect(surfaceElement).toHaveStyle(
|
|
30
|
+
`background-color: ${token('color.background.neutral.bold.hovered')}`,
|
|
31
|
+
);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('should render given a brand hover interaction by if set as brand', () => {
|
|
36
|
+
const { getByTestId } = render(
|
|
37
|
+
<div style={{ position: 'relative' }}>
|
|
38
|
+
<InteractionSurface appearance="brand.bold" testId="surface" />
|
|
39
|
+
hello
|
|
40
|
+
</div>,
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
const surfaceElement = getByTestId('surface');
|
|
44
|
+
expect(getComputedStyle(surfaceElement).backgroundColor).toBe('');
|
|
45
|
+
act(() => {
|
|
46
|
+
fireEvent.mouseOver(surfaceElement);
|
|
47
|
+
expect(surfaceElement).toHaveStyle(
|
|
48
|
+
`background-color: ${token('color.background.brand.bold.hovered')}`,
|
|
49
|
+
);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('should render an inherited hover state if a Box context is present', () => {
|
|
54
|
+
const { getByTestId } = render(
|
|
55
|
+
<Box backgroundColor={['brand.bold', '']}>
|
|
56
|
+
<InteractionSurface testId="surface" />
|
|
57
|
+
hello
|
|
58
|
+
</Box>,
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const surfaceElement = getByTestId('surface');
|
|
62
|
+
expect(getComputedStyle(surfaceElement).backgroundColor).toBe('');
|
|
63
|
+
act(() => {
|
|
64
|
+
fireEvent.mouseOver(surfaceElement);
|
|
65
|
+
expect(surfaceElement).toHaveStyle(
|
|
66
|
+
`background-color: ${token('color.background.brand.bold.hovered')}`,
|
|
67
|
+
);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { render } from '@testing-library/react';
|
|
4
|
+
|
|
5
|
+
import { UNSAFE_Box as Box, UNSAFE_Stack as Stack } from '../../../index';
|
|
6
|
+
|
|
7
|
+
describe('Stack component', () => {
|
|
8
|
+
const testId = 'test';
|
|
9
|
+
|
|
10
|
+
it('should render stack', () => {
|
|
11
|
+
const { getByText } = render(
|
|
12
|
+
<Stack gap="sp-50">
|
|
13
|
+
<Box>1</Box>
|
|
14
|
+
<Box>2</Box>
|
|
15
|
+
</Stack>,
|
|
16
|
+
);
|
|
17
|
+
expect(getByText('1')).toBeInTheDocument();
|
|
18
|
+
expect(getByText('2')).toBeInTheDocument();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('should render with a given test id', () => {
|
|
22
|
+
const { getByTestId } = render(
|
|
23
|
+
<Stack gap="sp-50" testId={testId}>
|
|
24
|
+
<Box>1</Box>
|
|
25
|
+
<Box>2</Box>
|
|
26
|
+
</Stack>,
|
|
27
|
+
);
|
|
28
|
+
const element = getByTestId(testId);
|
|
29
|
+
expect(element).toBeInTheDocument();
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { render } from '@testing-library/react';
|
|
4
|
+
|
|
5
|
+
import { UNSAFE_Text as Text } from '../../../index';
|
|
6
|
+
|
|
7
|
+
describe('Text component', () => {
|
|
8
|
+
it('should render given text', () => {
|
|
9
|
+
const { getByText } = render(<Text>Text</Text>);
|
|
10
|
+
expect(getByText('Text')).toBeInTheDocument();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('should render with given test id', () => {
|
|
14
|
+
const { getByTestId } = render(<Text testId="test">Text</Text>);
|
|
15
|
+
expect(getByTestId('test')).toBeInTheDocument();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe('"as" prop behaviour', () => {
|
|
19
|
+
it('renders without errors when a valid "as" value is given', () => {
|
|
20
|
+
const { getByText } = render(<Text as="div">Text</Text>);
|
|
21
|
+
expect(getByText('Text')).toBeInTheDocument();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('throws when an invalid "as" value is given', () => {
|
|
25
|
+
// @ts-ignore purposefully providing an invalid value to test invariant behaviour
|
|
26
|
+
expect(() => render(<Text as="label">Text</Text>)).toThrow(
|
|
27
|
+
new Error(
|
|
28
|
+
'Invariant failed: @atlaskit/ds-explorations: Text received an invalid "as" value of "label"',
|
|
29
|
+
),
|
|
30
|
+
);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getExampleUrl,
|
|
3
|
+
loadPage,
|
|
4
|
+
takeElementScreenShot,
|
|
5
|
+
} from '@atlaskit/visual-regression/helper';
|
|
6
|
+
|
|
7
|
+
describe('Box', () => {
|
|
8
|
+
[
|
|
9
|
+
'borderColor',
|
|
10
|
+
'backgroundColor',
|
|
11
|
+
'background-and-padding',
|
|
12
|
+
'background-and-paddingBlock',
|
|
13
|
+
'background-and-paddingInline',
|
|
14
|
+
].forEach((selector) => {
|
|
15
|
+
it(`example with ${selector} should match snapshot`, async () => {
|
|
16
|
+
const url = getExampleUrl(
|
|
17
|
+
'design-system',
|
|
18
|
+
'ds-explorations',
|
|
19
|
+
'box',
|
|
20
|
+
global.__BASEURL__,
|
|
21
|
+
);
|
|
22
|
+
const { page } = global;
|
|
23
|
+
|
|
24
|
+
await loadPage(page, url);
|
|
25
|
+
|
|
26
|
+
const image = await takeElementScreenShot(
|
|
27
|
+
page,
|
|
28
|
+
`[data-testid="box-with-${selector}"]`,
|
|
29
|
+
);
|
|
30
|
+
expect(image).toMatchProdImageSnapshot();
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getExampleUrl,
|
|
3
|
+
loadPage,
|
|
4
|
+
takeElementScreenShot,
|
|
5
|
+
} from '@atlaskit/visual-regression/helper';
|
|
6
|
+
|
|
7
|
+
describe('Inline', () => {
|
|
8
|
+
it.each(['spacing', 'alignment'])(
|
|
9
|
+
`%s example should match snapshot`,
|
|
10
|
+
async (selector) => {
|
|
11
|
+
const url = getExampleUrl(
|
|
12
|
+
'design-system',
|
|
13
|
+
'ds-explorations',
|
|
14
|
+
'inline',
|
|
15
|
+
global.__BASEURL__,
|
|
16
|
+
);
|
|
17
|
+
const { page } = global;
|
|
18
|
+
|
|
19
|
+
await loadPage(page, url);
|
|
20
|
+
|
|
21
|
+
const image = await takeElementScreenShot(
|
|
22
|
+
page,
|
|
23
|
+
`[data-testid="inline-${selector}"]`,
|
|
24
|
+
);
|
|
25
|
+
expect(image).toMatchProdImageSnapshot();
|
|
26
|
+
},
|
|
27
|
+
);
|
|
28
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getExampleUrl,
|
|
3
|
+
loadPage,
|
|
4
|
+
takeElementScreenShot,
|
|
5
|
+
} from '@atlaskit/visual-regression/helper';
|
|
6
|
+
|
|
7
|
+
describe('Stack', () => {
|
|
8
|
+
it.each(['spacing', 'alignment'])(
|
|
9
|
+
`%s example should match snapshot`,
|
|
10
|
+
async (selector) => {
|
|
11
|
+
const url = getExampleUrl(
|
|
12
|
+
'design-system',
|
|
13
|
+
'ds-explorations',
|
|
14
|
+
'stack',
|
|
15
|
+
global.__BASEURL__,
|
|
16
|
+
);
|
|
17
|
+
const { page } = global;
|
|
18
|
+
|
|
19
|
+
await loadPage(page, url);
|
|
20
|
+
|
|
21
|
+
const image = await takeElementScreenShot(
|
|
22
|
+
page,
|
|
23
|
+
`[data-testid="stack-${selector}"]`,
|
|
24
|
+
);
|
|
25
|
+
expect(image).toMatchProdImageSnapshot();
|
|
26
|
+
},
|
|
27
|
+
);
|
|
28
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import __noop from '@atlaskit/ds-lib/noop';
|
|
2
|
+
import {
|
|
3
|
+
getExampleUrl,
|
|
4
|
+
loadPage,
|
|
5
|
+
takeElementScreenShot,
|
|
6
|
+
} from '@atlaskit/visual-regression/helper';
|
|
7
|
+
|
|
8
|
+
describe('Text', () => {
|
|
9
|
+
['font-sizes', 'font-weights', 'line-heights', 'testing'].forEach(
|
|
10
|
+
(testId) => {
|
|
11
|
+
it(`example with ${testId} should match snapshot`, async () => {
|
|
12
|
+
const url = getExampleUrl(
|
|
13
|
+
'design-system',
|
|
14
|
+
'ds-explorations',
|
|
15
|
+
'text',
|
|
16
|
+
global.__BASEURL__,
|
|
17
|
+
);
|
|
18
|
+
const { page } = global;
|
|
19
|
+
|
|
20
|
+
await loadPage(page, url);
|
|
21
|
+
|
|
22
|
+
const image = await takeElementScreenShot(
|
|
23
|
+
page,
|
|
24
|
+
`[data-testid="${testId}"]`,
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
expect(image).toMatchProdImageSnapshot();
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
);
|
|
31
|
+
});
|