Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve S2 chromatic story coverage #6999

Open
wants to merge 13 commits into
base: combine_chromatic
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .chromatic/custom-addons/chromatic/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const withChromaticProvider = makeDecorator({
height = options.height;
}

if (context.title.includes('S2/')) {
if (context.title.includes('S2')) {
return <RenderS2 getStory={getStory} context={context} options={options} selectedLocales={selectedLocales} height={height} minHeight={minHeight} />
} else {
return <RenderV3 getStory={getStory} context={context} options={options} selectedLocales={selectedLocales} height={height} minHeight={minHeight} />
Expand All @@ -45,7 +45,7 @@ function RenderS2({getStory, context, options, selectedLocales, height, minHeigh
<div style={{display: 'flex', flexDirection: 'column', height, minHeight, width: '90vw'}}>
{colorSchemes.map(colorScheme =>
backgrounds.map(background =>
(colorScheme === 'light' ? selectedLocales : ['en-US']).map(locale =>
(colorScheme === 'light' || context.title.includes('RTL') ? selectedLocales : ['en-US']).map(locale =>
<S2Provider key={`${colorScheme}_${background}_${locale}`} background={background} colorScheme={colorScheme} locale={locale}>
<div style={{margin: '8px'}}>
<h1 style={{margin: 0, padding: 0, color: colorScheme === 'dark' ? 'white' : 'black'}}>{`${colorScheme}, ${background}, ${locale}`}</h1>
Expand Down
3 changes: 2 additions & 1 deletion .chromatic/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ module.exports = {
},
stories: [
'../packages/**/chromatic/**/*.stories.@(js|jsx|ts|tsx)',
'../packages/@react-spectrum/s2/stories/*.stories.@(js|jsx|mjs|ts|tsx)'
'../packages/@react-spectrum/s2/stories/*.stories.@(js|jsx|mjs|ts|tsx)',
'../packages/@react-spectrum/s2/chromatic/*.stories.@(js|jsx|mjs|ts|tsx)'
],
addons: process.env.NODE_ENV === 'production' ? [] : [
'@storybook/addon-actions',
Expand Down
2 changes: 1 addition & 1 deletion .chromatic/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const parameters = {
options: {
storySort: {
method: 'alphabetical',
order: ['*', 'S2']
order: ['*', 'S2', 'S2 Chromatic']
}
},
a11y: {},
Expand Down
85 changes: 85 additions & 0 deletions packages/@react-spectrum/s2/chromatic/ActionButton.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright 2024 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

import {ActionButton, Text} from '../src';
import {Fonts, UnsafeClassName} from '../stories/ActionButton.stories';
import {generatePowerset} from '@react-spectrum/story-utils';
import type {Meta} from '@storybook/react';
import NewIcon from '../s2wf-icons/S2_Icon_New_20_N.svg';
import {shortName} from './utils';
import {StaticColorProvider} from '../stories/utils';
import {style} from '../style/spectrum-theme' with { type: 'macro' };

const meta: Meta<typeof ActionButton> = {
component: ActionButton,
parameters: {
chromaticProvider: {disableAnimations: true}
},
title: 'S2 Chromatic/ActionButton'
};

export default meta;

let states = [
{isQuiet: true},
{isReadOnly: true},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think Readonly is allowed on ActionButton?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops, thanks copy pasta

{isDisabled: true},
{size: ['XS', 'S', 'M', 'L', 'XL']},
{staticColor: ['black', 'white']}
];

let combinations = generatePowerset(states);

const Template = (args) => {
let {children, ...otherArgs} = args;
return (
<div className={style({display: 'grid', gridTemplateColumns: 'repeat(4, minmax(0, 250px))', gridAutoFlow: 'row', justifyItems: 'start', gap: 24, width: '[100vw]'})}>
{combinations.map(c => {
let key = Object.keys(c).map(k => shortName(k, c[k])).join(' ');
if (!key) {
key = 'default';
}

let button = <ActionButton key={key} {...otherArgs} {...c}>{children ? children : key}</ActionButton>;
if (c.staticColor != null) {
return (
<StaticColorProvider staticColor={c.staticColor}>
{button}
</StaticColorProvider>
);
}

return button;
})}
</div>
);
};

export const Default = {
render: Template
};

export const WithIcon = {
render: Template,
args: {
children: <><NewIcon /><Text>Press me</Text></>
}
};

export const IconOnly = {
render: Template,
args: {
children: <NewIcon />
}
};

export {Fonts, UnsafeClassName};
45 changes: 45 additions & 0 deletions packages/@react-spectrum/s2/chromatic/ActionMenu.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2024 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

import {ActionMenu} from '../src';
import {DynamicExample, Example} from '../stories/ActionMenu.stories';
import type {Meta, StoryObj} from '@storybook/react';
import {userEvent, within} from '@storybook/testing-library';

const meta: Meta<typeof ActionMenu> = {
component: ActionMenu,
parameters: {
chromaticProvider: {colorSchemes: ['light'], backgrounds: ['base'], locales: ['en-US'], disableAnimations: true}
},
title: 'S2 Chromatic/ActionMenu'
};

export default meta;
type Story = StoryObj<typeof ActionMenu<any>>;

export const Static: Story = {...Example};

Static.play = async ({canvasElement}) => {
await userEvent.tab();
await userEvent.keyboard('[Enter]');
let body = canvasElement.ownerDocument.body;
await within(body).findByRole('menu');
Comment on lines +33 to +35
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can use your menu utils?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why tab and enter? why not use a single command which will do both? await userEvent.click(getByRole('button'))?

};

export const Dynamic = {...DynamicExample};

Dynamic.play = async ({canvasElement}) => {
await userEvent.tab();
await userEvent.keyboard('[Enter]');
let body = canvasElement.ownerDocument.body;
await within(body).findByRole('menu');
};
26 changes: 26 additions & 0 deletions packages/@react-spectrum/s2/chromatic/ActionMenuRTL.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2024 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

import {ActionMenu} from '../src';

import type {Meta} from '@storybook/react';

const meta: Meta<typeof ActionMenu> = {
component: ActionMenu,
parameters: {
chromaticProvider: {colorSchemes: ['dark'], backgrounds: ['base'], locales: ['ar-AE'], disableAnimations: true}
},
title: 'S2 Chromatic/ActionMenuRTL'
};

export default meta;
export {Static, Dynamic} from './ActionMenu.stories';
36 changes: 36 additions & 0 deletions packages/@react-spectrum/s2/chromatic/AlertDialog.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2024 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

import {AlertDialog} from '../src';
import {Example as Base} from '../stories/AlertDialog.stories';
import type {Meta, StoryObj} from '@storybook/react';
import {userEvent, within} from '@storybook/testing-library';

const meta: Meta<typeof AlertDialog> = {
component: AlertDialog,
parameters: {
layout: 'centered',
chromaticProvider: {colorSchemes: ['light'], backgrounds: ['base'], locales: ['en-US'], disableAnimations: true}
},
title: 'S2 Chromatic/AlertDialog'
};

export default meta;

export const Example = {...Base} as StoryObj;

Example.play = async ({canvasElement}) => {
await userEvent.tab();
await userEvent.keyboard('[Enter]');
let body = canvasElement.ownerDocument.body;
await within(body).findByRole('alertdialog');
};
26 changes: 26 additions & 0 deletions packages/@react-spectrum/s2/chromatic/AlertDialogRTL.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2024 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

import {AlertDialog} from '../src';

import type {Meta} from '@storybook/react';

const meta: Meta<typeof AlertDialog> = {
component: AlertDialog,
parameters: {
chromaticProvider: {colorSchemes: ['dark'], backgrounds: ['base'], locales: ['ar-AE'], disableAnimations: true}
},
title: 'S2 Chromatic/AlertDialogRTL'
};

export default meta;
export {Example} from './AlertDialog.stories';
37 changes: 37 additions & 0 deletions packages/@react-spectrum/s2/chromatic/Avatar.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2024 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

import {Avatar} from '../src';
import type {Meta} from '@storybook/react';
import {style} from '../style/spectrum-theme' with { type: 'macro' };

const meta: Meta<typeof Avatar> = {
component: Avatar,
parameters: {
chromaticProvider: {backgrounds: ['base', 'layer-1', 'layer-2'], disableAnimations: true}
},
title: 'S2 Chromatic/Avatar'
};

export default meta;

export const Default = {
render: () => <Avatar alt="design provided" src="https://i.imgur.com/xIe7Wlb.png" />
};

export const OverBackground = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need one which uses the spectrum layer background? or maybe taken care of by AvatarGroup stories when we get those

render: () => (
<div className={style({backgroundColor: 'indigo-800', padding: 40})}>
<Avatar alt="design provided" src="https://i.imgur.com/xIe7Wlb.png" />
</div>
)
};
72 changes: 72 additions & 0 deletions packages/@react-spectrum/s2/chromatic/Badge.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright 2024 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

import {Badge} from '../src';
import {Example} from '../stories/Badge.stories';
import {generatePowerset} from '@react-spectrum/story-utils';
import type {Meta} from '@storybook/react';
import {shortName} from './utils';
import {style} from '../style/spectrum-theme' with { type: 'macro' };

const meta: Meta<typeof Badge> = {
component: Badge,
parameters: {
chromaticProvider: {disableAnimations: true}
},
title: 'S2 Chromatic/Badge'
};

export default meta;

let states = [
{size: ['S', 'M', 'L', 'XL']},
{fillStyle: ['bold', 'subtle', 'outline']},
{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']}
];

let combinations = generatePowerset(states);
let chunkSize = Math.ceil(combinations.length / 3);

const Template = ({combos, ...args}) => {
return (
<div className={style({display: 'grid', gridTemplateColumns: 'repeat(4, minmax(0, 250px))', gridAutoFlow: 'row', alignItems: 'center', justifyItems: 'start', gap: 24, width: '[100vw]'})}>
{combos.map(c => {
let key = Object.keys(c).map(k => shortName(k, c[k])).join(' ');
if (!key) {
key = 'default';
}

return <Badge key={key} {...args} {...c}>{key}</Badge>;
})}
</div>
);
};

export const Default = {
render: Template,
name: 'all visual option combos 1 of 3',
args: {combos: combinations.slice(0, chunkSize)}
};

export const ComboPt2 = {
render: Template,
args: {combos: combinations.slice(chunkSize, chunkSize * 2)},
name: 'all visual option combos 2 of 3'
};

export const ComboPt3 = {
render: Template,
args: {combos: combinations.slice(chunkSize * 2, chunkSize * 3)},
name: 'all visual option combos 3 of 3'
};

export {Example};
Loading