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

feat(eslint-config-carbon): add storybook config #10335

Merged
Merged
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions config/eslint-config-carbon/internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ module.exports = {
require.resolve('./base'),
require.resolve('./plugins/jest'),
require.resolve('./plugins/react'),
require.resolve('./plugins/storybook'),
],
};
1 change: 1 addition & 0 deletions config/eslint-config-carbon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-react": "^7.24.0",
"eslint-plugin-react-hooks": "^4.2.0",
"eslint-plugin-storybook": "^0.5.5",
"eslint-restricted-globals": "^0.2.0"
},
"devDependencies": {
Expand Down
59 changes: 59 additions & 0 deletions config/eslint-config-carbon/plugins/storybook.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* Copyright IBM Corp. 2018, 2018
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

/**
* ESLint configuration for eslint-plugin-storybook
*
* @see https://github.com/storybookjs/eslint-plugin-storybook
*/
module.exports = {
plugins: ['storybook'],
overrides: [
{
files: ['*.stories.js', '*-story.js'],
extends: ['plugin:storybook/recommended'],
rules: {
// Interactions should be awaited
'storybook/await-interactions': 'error',

// Pass a context when invoking play function of another story
'storybook/context-in-play-function': 'error',

// The component property should be set
'storybook/csf-component': 'error',

// Story files should have a default export
'storybook/default-exports': 'error',

// Deprecated hierachy separator in title property
'storybook/hierarchy-separator': 'error',

'storybook/no-redundant-story-name': 'error',

// storiesOf is deprecated and should not be used
'storybook/no-stories-of': 'error',

// Do not define a title in meta
'storybook/no-title-property-in-meta': 'off',

// Stories should use PascalCase
'storybook/prefer-pascal-case': 'error',

// A story file must contain at least one story export
'storybook/story-exports': 'error',

// Use expect from @storybook/jest
'storybook/use-storybook-expect': 'error',

// Do not use testing-library directly on stories
'storybook/use-storybook-testing-library': 'error',
},
},
],
};
3 changes: 3 additions & 0 deletions packages/carbon-react/.storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ module.exports = {
core: {
builder: 'webpack5',
},
features: {
previewCsfV3: true,
},
stories: [
'./Welcome/Welcome.stories.js',
'../src/**/*.stories.js',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const Condensed = () => {
);
};

export const fullWidth = () => (
export const FullWidth = () => (
<Grid fullWidth>
<Column sm={4} />
<Column sm={4} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import './Icons.stories.scss';
import React from 'react';
import { Bee, Bicycle, ChevronUp } from '../../../icons';

// eslint-disable-next-line storybook/csf-component
joshblack marked this conversation as resolved.
Show resolved Hide resolved
export default {
title: 'Elements/Icons',
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import './story.scss';

import React from 'react';

// eslint-disable-next-line storybook/csf-component
export default {
title: 'Elements/IBM Plex',
argTypes: {
Expand Down
4 changes: 4 additions & 0 deletions packages/react/.storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ module.exports = {
builder: 'webpack5',
},

features: {
previewCsfV3: true,
},

staticDirs: [path.join(__dirname, 'assets')],

stories: glob.sync(
Expand Down
12 changes: 7 additions & 5 deletions packages/react/src/components/Accordion/Accordion-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default {
},
};

export const accordion = () => (
export const AccordionStory = () => (
<Accordion>
<AccordionItem title="Section 1 title">
<p>
Expand Down Expand Up @@ -76,9 +76,11 @@ export const accordion = () => (
</Accordion>
);

export const skeleton = () => <AccordionSkeleton open count={4} />;
AccordionStory.storyName = 'Accordion';

skeleton.decorators = [
export const Skeleton = () => <AccordionSkeleton open count={4} />;

Skeleton.decorators = [
(story) => <div style={{ width: '500px' }}>{story()}</div>,
];

Expand All @@ -93,7 +95,7 @@ const sizes = {
'Large (lg)': 'lg',
};

export const playground = () => (
export const Playground = () => (
<Accordion
disabled={boolean('Disable entire Accordion (disabled)', false)}
size={
Expand Down Expand Up @@ -146,7 +148,7 @@ export const playground = () => (
</Accordion>
);

export const skeletonPlayground = () => (
export const SkeletonPlayground = () => (
<div style={{ width: '500px' }}>
<AccordionSkeleton
align={select(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default {
},
};

export const aspectRatio = () => {
export const AspectRatioStory = () => {
return (
<Grid>
<Row>
Expand All @@ -48,7 +48,9 @@ export const aspectRatio = () => {
);
};

export const playground = () => {
AspectRatioStory.storyName = 'AspectRatio';

export const Playground = () => {
const ratio = select(
'ratio',
['16x9', '9x16', '2x1', '1x2', '4x3', '3x4', '1x1'],
Expand Down
10 changes: 6 additions & 4 deletions packages/react/src/components/Breadcrumb/Breadcrumb-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default {
},
};

export const breadcrumb = () => (
export const BreadcrumbStory = () => (
<Breadcrumb>
<BreadcrumbItem>
<a href="/#">Breadcrumb 1</a>
Expand All @@ -41,7 +41,9 @@ export const breadcrumb = () => (
</Breadcrumb>
);

export const breadcrumbWithOverflowMenu = () => (
BreadcrumbStory.storyName = 'Breadcrumb';

export const BreadcrumbWithOverflowMenu = () => (
<Breadcrumb>
<BreadcrumbItem>
<a href="/#">Breadcrumb 1</a>
Expand All @@ -58,15 +60,15 @@ export const breadcrumbWithOverflowMenu = () => (
</Breadcrumb>
);

export const skeleton = () => <BreadcrumbSkeleton />;
export const Skeleton = () => <BreadcrumbSkeleton />;

const props = () => ({
className: 'some-class',
noTrailingSlash: boolean('No trailing slash (noTrailingSlash)', false),
onClick: action('onClick'),
});

export const playground = () => (
export const Playground = () => (
<Breadcrumb {...props()}>
<BreadcrumbItem>
<a href="/#">Breadcrumb 1</a>
Expand Down
10 changes: 5 additions & 5 deletions packages/react/src/components/Button/Button-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ const props = {

export default {
title: 'Components/Button',
component: Button,
subcomponents: {
ButtonSet,
ButtonSkeleton,
},
decorators: [withKnobs],
parameters: {
component: Button,
subcomponents: {
ButtonSet,
ButtonSkeleton,
},
docs: {
page: mdx,
},
Expand Down
10 changes: 4 additions & 6 deletions packages/react/src/components/Button/next/Button.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ import ButtonSet from '../../ButtonSet';

export default {
title: 'Components/Button',
parameters: {
component: Button,
subcomponents: {
ButtonSet,
ButtonSkeleton,
},
component: Button,
subcomponents: {
ButtonSet,
ButtonSkeleton,
},
};

Expand Down
14 changes: 8 additions & 6 deletions packages/react/src/components/Checkbox/Checkbox-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default {
},
};

export const checkboxNativeValidation = () => {
export const CheckboxNativeValidation = () => {
function onSubmit(e) {
e.preventDefault();
var cb = e.target.querySelector('input[type=checkbox]');
Expand All @@ -57,7 +57,7 @@ export const checkboxNativeValidation = () => {
);
};

export const checkbox = () => {
export const CheckboxStory = () => {
return (
<fieldset className={`${prefix}--fieldset`}>
<legend className={`${prefix}--label`}>Checkbox heading</legend>
Expand All @@ -67,7 +67,9 @@ export const checkbox = () => {
);
};

export const unstable_Checkbox = () => {
CheckboxStory.storyName = 'Checkbox';

export const UnstableCheckbox = () => {
return (
<FeatureFlags flags={{ 'enable-v11-release': true }}>
<fieldset className={`${prefix}--fieldset`}>
Expand All @@ -87,11 +89,11 @@ export const unstable_Checkbox = () => {
);
};

unstable_Checkbox.story = {
UnstableCheckbox.story = {
name: 'unstable_Checkbox',
};

export const skeleton = () => <CheckboxSkeleton />;
export const Skeleton = () => <CheckboxSkeleton />;

const props = () => ({
checked: boolean('Checked (checked)', false),
Expand All @@ -104,7 +106,7 @@ const props = () => ({
onChange: action('onChange'),
});

export const playground = () => (
export const Playground = () => (
<fieldset className={`${prefix}--fieldset`}>
<legend
className={classNames(`${prefix}--label`, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default {
},
};

export const checkbox = () => {
export const CheckboxStory = () => {
return (
<fieldset className={`${prefix}--fieldset`}>
<legend className={`${prefix}--label`}>Checkbox heading</legend>
Expand All @@ -28,4 +28,6 @@ export const checkbox = () => {
);
};

export const skeleton = () => <CheckboxSkeleton />;
CheckboxStory.storyName = 'Checkbox';

export const Skeleton = () => <CheckboxSkeleton />;
12 changes: 6 additions & 6 deletions packages/react/src/components/CodeSnippet/CodeSnippet-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ const props = () => ({
),
});

export const inline = () => (
export const Inline = () => (
<CodeSnippet type="inline" feedback="Copied to clipboard">
{'node -v'}
</CodeSnippet>
);

export const multiline = () => (
export const Multiline = () => (
<CodeSnippet type="multi" feedback="Copied to clipboard">
{` "scripts": {
"build": "lerna run build --stream --prefix --npm-client yarn",
Expand Down Expand Up @@ -146,14 +146,14 @@ export const multiline = () => (
</CodeSnippet>
);

export const singleline = () => (
export const Singleline = () => (
<CodeSnippet type="single" feedback="Copied to clipboard">
yarn add carbon-components@latest carbon-components-react@latest
@carbon/icons-react@latest carbon-icons@latest
</CodeSnippet>
);

export const skeleton = () => (
export const Skeleton = () => (
<div>
<CodeSnippetSkeleton type="single" style={{ marginBottom: 8 }} />
<CodeSnippetSkeleton type="multi" />
Expand All @@ -180,7 +180,7 @@ const lightPropMessage = (
</small>
);

export const withChildrenNodes = () => (
export const WithChildrenNodes = () => (
<CodeSnippet {...props()} type="multi" copyText={snippetText().multi}>
{snippetText()
.multi.split('\n')
Expand All @@ -193,7 +193,7 @@ export const withChildrenNodes = () => (
</CodeSnippet>
);

export const playground = () => (
export const Playground = () => (
<div className={props().light ? 'bx--tile' : ''}>
{props().light && lightPropMessage}
<br />
Expand Down
Loading