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

Merged
merged 14 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
112 changes: 112 additions & 0 deletions packages/@react-spectrum/s2/chromatic/ActionButton.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* 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 {generatePowerset} from '@react-spectrum/story-utils';
import type {Meta} from '@storybook/react';
import NewIcon from '../s2wf-icons/S2_Icon_New_20_N.svg';
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},
snowystinger marked this conversation as resolved.
Show resolved Hide resolved
{isDisabled: true},
{size: ['XS', 'S', 'M', 'L', 'XL']},
{staticColor: ['black', 'white']}
];

let combinations = generatePowerset(states);

function shortName(key, value) {
let returnVal = '';
switch (key) {
case 'isQuiet':
returnVal = 'q';
break;
case 'isReadOnly':
returnVal = 'ro';
break;
case 'isDisabled':
returnVal = 'd';
break;
case 'size':
returnVal = `size: ${value}`;
break;
case 'staticColor':
returnVal = `static: ${value}`;
break;

}
return returnVal;
}

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 />
}
};

// TODO: eventually make all none S2 chromatic stories have
// chromatic: {
// disableSnapshot: true
// }
// so that we centralize the chromatic stories. Wait until all these chromatic stories are finished
// and we run chromatic one last time to ensure a good baseline, then have all the stories in the
// chromatic folder import the original stories and rexport them
Copy link
Member Author

Choose a reason for hiding this comment

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

As we add powerset stories, some/all of the currently snapshotted S2 stories are redundant/extraneous so we'll want to centralize them all into this folder eventually

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');
snowystinger marked this conversation as resolved.
Show resolved Hide resolved
};

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

Copy link
Member Author

Choose a reason for hiding this comment

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

not quite sure the ask here, the base story goes through all the layer backgrounds if that is what is being asked for here
image

Copy link
Member

@snowystinger snowystinger Sep 20, 2024

Choose a reason for hiding this comment

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

Avatars can have a border around them that matches the layer color

      base
      'layer-1'
      'layer-2'
      pasteboard
      elevated

But I don't think they have that border unless in a Card or AvatarGroup? Which, I guess we can rely on those to test it

render: () => (
<div className={style({backgroundColor: 'indigo-800', padding: 40})}>
<Avatar alt="design provided" src="https://i.imgur.com/xIe7Wlb.png" />
</div>
)
};
70 changes: 70 additions & 0 deletions packages/@react-spectrum/s2/chromatic/Badge.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* 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 {generatePowerset} from '@react-spectrum/story-utils';
import type {Meta} from '@storybook/react';
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);

function shortName(key, value) {
let returnVal = '';
switch (key) {
case 'size':
returnVal = `size: ${value}`;
break;
case 'fillStyle':
returnVal = `fill: ${value}`;
break;
case 'variant':
returnVal = `var: ${value}`;
break;

}
return returnVal;
}

const Template = (args) => {
return (
<div className={style({display: 'grid', gridTemplateColumns: 'repeat(4, minmax(0, 250px))', gridAutoFlow: 'row', alignItems: 'center', 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';
}

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

export const Default = {
render: Template
};
Loading