Skip to content

Commit 06be29b

Browse files
authored
Improve S2 chromatic story coverage (#6999)
* add play functions to s2 chromatic overlay stories * move overlay chromatic stories into separate stories this is because we can only have one overay open at a time and so the open overlay doesnt cover the other elements in the main chromatic stories * add RTL and dark theme stories for overlay chromatics stories * add more power set stories and fix lint * fix chromatic error * fix lint and add button + checkbox powersets * add colorarea,field and reusue shortName * Add colorslider, add contextual help, and use original stories in chromatic ones if needed * split up powersets that were too big * ugh lint * adding data-testids and other review comments
1 parent 99b388e commit 06be29b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1863
-81
lines changed

.chromatic/custom-addons/chromatic/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const withChromaticProvider = makeDecorator({
2727
height = options.height;
2828
}
2929

30-
if (context.title.includes('S2/')) {
30+
if (context.title.includes('S2')) {
3131
return <RenderS2 getStory={getStory} context={context} options={options} selectedLocales={selectedLocales} height={height} minHeight={minHeight} />
3232
} else {
3333
return <RenderV3 getStory={getStory} context={context} options={options} selectedLocales={selectedLocales} height={height} minHeight={minHeight} />
@@ -45,7 +45,7 @@ function RenderS2({getStory, context, options, selectedLocales, height, minHeigh
4545
<div style={{display: 'flex', flexDirection: 'column', height, minHeight, width: '90vw'}}>
4646
{colorSchemes.map(colorScheme =>
4747
backgrounds.map(background =>
48-
(colorScheme === 'light' ? selectedLocales : ['en-US']).map(locale =>
48+
(colorScheme === 'light' || context.title.includes('RTL') ? selectedLocales : ['en-US']).map(locale =>
4949
<S2Provider key={`${colorScheme}_${background}_${locale}`} background={background} colorScheme={colorScheme} locale={locale}>
5050
<div style={{margin: '8px'}}>
5151
<h1 style={{margin: 0, padding: 0, color: colorScheme === 'dark' ? 'white' : 'black'}}>{`${colorScheme}, ${background}, ${locale}`}</h1>

.chromatic/main.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ module.exports = {
66
},
77
stories: [
88
'../packages/**/chromatic/**/*.stories.@(js|jsx|ts|tsx)',
9-
'../packages/@react-spectrum/s2/stories/*.stories.@(js|jsx|mjs|ts|tsx)'
9+
'../packages/@react-spectrum/s2/stories/*.stories.@(js|jsx|mjs|ts|tsx)',
10+
'../packages/@react-spectrum/s2/chromatic/*.stories.@(js|jsx|mjs|ts|tsx)'
1011
],
1112
addons: process.env.NODE_ENV === 'production' ? [] : [
1213
'@storybook/addon-actions',

.chromatic/preview.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const parameters = {
1414
options: {
1515
storySort: {
1616
method: 'alphabetical',
17-
order: ['*', 'S2']
17+
order: ['*', 'S2', 'S2 Chromatic']
1818
}
1919
},
2020
a11y: {},
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* Copyright 2024 Adobe. All rights reserved.
3+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License. You may obtain a copy
5+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under
8+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
* OF ANY KIND, either express or implied. See the License for the specific language
10+
* governing permissions and limitations under the License.
11+
*/
12+
13+
import {ActionButton, Text} from '../src';
14+
import {Fonts, UnsafeClassName} from '../stories/ActionButton.stories';
15+
import {generatePowerset} from '@react-spectrum/story-utils';
16+
import type {Meta} from '@storybook/react';
17+
import NewIcon from '../s2wf-icons/S2_Icon_New_20_N.svg';
18+
import {shortName} from './utils';
19+
import {StaticColorProvider} from '../stories/utils';
20+
import {style} from '../style/spectrum-theme' with { type: 'macro' };
21+
22+
const meta: Meta<typeof ActionButton> = {
23+
component: ActionButton,
24+
parameters: {
25+
chromaticProvider: {disableAnimations: true}
26+
},
27+
title: 'S2 Chromatic/ActionButton'
28+
};
29+
30+
export default meta;
31+
32+
let states = [
33+
{isQuiet: true},
34+
{isDisabled: true},
35+
{size: ['XS', 'S', 'M', 'L', 'XL']},
36+
{staticColor: ['black', 'white']}
37+
];
38+
39+
let combinations = generatePowerset(states);
40+
41+
const Template = (args) => {
42+
let {children, ...otherArgs} = args;
43+
return (
44+
<div className={style({display: 'grid', gridTemplateColumns: 'repeat(4, minmax(0, 250px))', gridAutoFlow: 'row', justifyItems: 'start', gap: 24, width: '[100vw]'})}>
45+
{combinations.map(c => {
46+
let fullComboName = Object.keys(c).map(k => `${k}: ${c[k]}`).join(' ');
47+
let key = Object.keys(c).map(k => shortName(k, c[k])).join(' ');
48+
if (!key) {
49+
key = 'default';
50+
}
51+
52+
let button = <ActionButton key={key} data-testid={fullComboName} {...otherArgs} {...c}>{children ? children : key}</ActionButton>;
53+
if (c.staticColor != null) {
54+
return (
55+
<StaticColorProvider staticColor={c.staticColor}>
56+
{button}
57+
</StaticColorProvider>
58+
);
59+
}
60+
61+
return button;
62+
})}
63+
</div>
64+
);
65+
};
66+
67+
export const Default = {
68+
render: Template
69+
};
70+
71+
export const WithIcon = {
72+
render: Template,
73+
args: {
74+
children: <><NewIcon /><Text>Press me</Text></>
75+
}
76+
};
77+
78+
export const IconOnly = {
79+
render: Template,
80+
args: {
81+
children: <NewIcon />
82+
}
83+
};
84+
85+
export {Fonts, UnsafeClassName};
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2024 Adobe. All rights reserved.
3+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License. You may obtain a copy
5+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under
8+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
* OF ANY KIND, either express or implied. See the License for the specific language
10+
* governing permissions and limitations under the License.
11+
*/
12+
13+
import {ActionMenu} from '../src';
14+
import {DynamicExample, Example} from '../stories/ActionMenu.stories';
15+
import type {Meta, StoryObj} from '@storybook/react';
16+
import {userEvent, within} from '@storybook/testing-library';
17+
18+
const meta: Meta<typeof ActionMenu> = {
19+
component: ActionMenu,
20+
parameters: {
21+
chromaticProvider: {colorSchemes: ['light'], backgrounds: ['base'], locales: ['en-US'], disableAnimations: true}
22+
},
23+
title: 'S2 Chromatic/ActionMenu'
24+
};
25+
26+
export default meta;
27+
type Story = StoryObj<typeof ActionMenu<any>>;
28+
29+
export const Static: Story = {...Example};
30+
31+
Static.play = async ({canvasElement}) => {
32+
await userEvent.tab();
33+
await userEvent.keyboard('[Enter]');
34+
let body = canvasElement.ownerDocument.body;
35+
await within(body).findByRole('menu');
36+
};
37+
38+
export const Dynamic = {...DynamicExample};
39+
40+
Dynamic.play = async ({canvasElement}) => {
41+
await userEvent.tab();
42+
await userEvent.keyboard('[Enter]');
43+
let body = canvasElement.ownerDocument.body;
44+
await within(body).findByRole('menu');
45+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2024 Adobe. All rights reserved.
3+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License. You may obtain a copy
5+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under
8+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
* OF ANY KIND, either express or implied. See the License for the specific language
10+
* governing permissions and limitations under the License.
11+
*/
12+
13+
import {ActionMenu} from '../src';
14+
15+
import type {Meta} from '@storybook/react';
16+
17+
const meta: Meta<typeof ActionMenu> = {
18+
component: ActionMenu,
19+
parameters: {
20+
chromaticProvider: {colorSchemes: ['dark'], backgrounds: ['base'], locales: ['ar-AE'], disableAnimations: true}
21+
},
22+
title: 'S2 Chromatic/ActionMenuRTL'
23+
};
24+
25+
export default meta;
26+
export {Static, Dynamic} from './ActionMenu.stories';
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2024 Adobe. All rights reserved.
3+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License. You may obtain a copy
5+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under
8+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
* OF ANY KIND, either express or implied. See the License for the specific language
10+
* governing permissions and limitations under the License.
11+
*/
12+
13+
import {AlertDialog} from '../src';
14+
import {Example as Base} from '../stories/AlertDialog.stories';
15+
import type {Meta, StoryObj} from '@storybook/react';
16+
import {userEvent, within} from '@storybook/testing-library';
17+
18+
const meta: Meta<typeof AlertDialog> = {
19+
component: AlertDialog,
20+
parameters: {
21+
layout: 'centered',
22+
chromaticProvider: {colorSchemes: ['light'], backgrounds: ['base'], locales: ['en-US'], disableAnimations: true}
23+
},
24+
title: 'S2 Chromatic/AlertDialog'
25+
};
26+
27+
export default meta;
28+
29+
export const Example = {...Base} as StoryObj;
30+
31+
Example.play = async ({canvasElement}) => {
32+
await userEvent.tab();
33+
await userEvent.keyboard('[Enter]');
34+
let body = canvasElement.ownerDocument.body;
35+
await within(body).findByRole('alertdialog');
36+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2024 Adobe. All rights reserved.
3+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License. You may obtain a copy
5+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under
8+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
* OF ANY KIND, either express or implied. See the License for the specific language
10+
* governing permissions and limitations under the License.
11+
*/
12+
13+
import {AlertDialog} from '../src';
14+
15+
import type {Meta} from '@storybook/react';
16+
17+
const meta: Meta<typeof AlertDialog> = {
18+
component: AlertDialog,
19+
parameters: {
20+
chromaticProvider: {colorSchemes: ['dark'], backgrounds: ['base'], locales: ['ar-AE'], disableAnimations: true}
21+
},
22+
title: 'S2 Chromatic/AlertDialogRTL'
23+
};
24+
25+
export default meta;
26+
export {Example} from './AlertDialog.stories';
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2024 Adobe. All rights reserved.
3+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License. You may obtain a copy
5+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under
8+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
* OF ANY KIND, either express or implied. See the License for the specific language
10+
* governing permissions and limitations under the License.
11+
*/
12+
13+
import {Avatar} from '../src';
14+
import type {Meta} from '@storybook/react';
15+
import {style} from '../style/spectrum-theme' with { type: 'macro' };
16+
17+
const meta: Meta<typeof Avatar> = {
18+
component: Avatar,
19+
parameters: {
20+
chromaticProvider: {backgrounds: ['base', 'layer-1', 'layer-2'], disableAnimations: true}
21+
},
22+
title: 'S2 Chromatic/Avatar'
23+
};
24+
25+
export default meta;
26+
27+
export const Default = {
28+
render: () => <Avatar alt="design provided" src="https://i.imgur.com/xIe7Wlb.png" />
29+
};
30+
31+
export const OverBackground = {
32+
render: () => (
33+
<div className={style({backgroundColor: 'indigo-800', padding: 40})}>
34+
<Avatar alt="design provided" src="https://i.imgur.com/xIe7Wlb.png" />
35+
</div>
36+
)
37+
};
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright 2024 Adobe. All rights reserved.
3+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License. You may obtain a copy
5+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under
8+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
* OF ANY KIND, either express or implied. See the License for the specific language
10+
* governing permissions and limitations under the License.
11+
*/
12+
13+
import {Badge} from '../src';
14+
import {Example} from '../stories/Badge.stories';
15+
import {generatePowerset} from '@react-spectrum/story-utils';
16+
import type {Meta} from '@storybook/react';
17+
import {shortName} from './utils';
18+
import {style} from '../style/spectrum-theme' with { type: 'macro' };
19+
20+
const meta: Meta<typeof Badge> = {
21+
component: Badge,
22+
parameters: {
23+
chromaticProvider: {disableAnimations: true}
24+
},
25+
title: 'S2 Chromatic/Badge'
26+
};
27+
28+
export default meta;
29+
30+
let states = [
31+
{size: ['S', 'M', 'L', 'XL']},
32+
{fillStyle: ['bold', 'subtle', 'outline']},
33+
{variant: ['accent', 'informative', 'neutral', 'positive', 'notice', 'negative', 'gray', 'red', 'orange', 'yellow', 'charteuse', 'celery', 'green', 'seafoam', 'cyan', 'blue', 'indigo', 'purple', 'fuchsia', 'magenta', 'pink', 'turquoise', 'brown', 'cinnamon', 'silver']}
34+
];
35+
36+
let combinations = generatePowerset(states);
37+
let chunkSize = Math.ceil(combinations.length / 3);
38+
39+
const Template = ({combos, ...args}) => {
40+
return (
41+
<div className={style({display: 'grid', gridTemplateColumns: 'repeat(4, minmax(0, 250px))', gridAutoFlow: 'row', alignItems: 'center', justifyItems: 'start', gap: 24, width: '[100vw]'})}>
42+
{combos.map(c => {
43+
let fullComboName = Object.keys(c).map(k => `${k}: ${c[k]}`).join(' ');
44+
let key = Object.keys(c).map(k => shortName(k, c[k])).join(' ');
45+
if (!key) {
46+
key = 'default';
47+
}
48+
49+
return <Badge key={key} data-testid={fullComboName} {...args} {...c}>{key}</Badge>;
50+
})}
51+
</div>
52+
);
53+
};
54+
55+
export const Default = {
56+
render: Template,
57+
name: 'all visual option combos 1 of 3',
58+
args: {combos: combinations.slice(0, chunkSize)}
59+
};
60+
61+
export const ComboPt2 = {
62+
render: Template,
63+
args: {combos: combinations.slice(chunkSize, chunkSize * 2)},
64+
name: 'all visual option combos 2 of 3'
65+
};
66+
67+
export const ComboPt3 = {
68+
render: Template,
69+
args: {combos: combinations.slice(chunkSize * 2, chunkSize * 3)},
70+
name: 'all visual option combos 3 of 3'
71+
};
72+
73+
export {Example};

0 commit comments

Comments
 (0)