generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Experience 8346: Add configuration for local instance of Storybook
This changeset adds the initial configuration needed to spin up Storybook locally. It's incredibly simple right now, but it should include most addons that we need. Also included is a very simple CSF example for the StaticAlert component as a proof-of-concept. There's a known error with React 18 [here](storybookjs/storybook#17831 (comment)), but it shouldn't affect us for the time being. We could also install the bleeding-edge version of Storybook, but it looks like there are other issues with that as well -- so I recommend just sticking with the latest stable version until the next version is officially out.
- Loading branch information
Stephen Kao
committed
Mar 22, 2023
1 parent
e178ef5
commit 3e6a744
Showing
6 changed files
with
6,533 additions
and
344 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,102 +1,73 @@ | ||
module.exports = { | ||
extends: [ | ||
"react-app", | ||
"plugin:import/recommended", | ||
"plugin:import/typescript", | ||
"prettier", | ||
], | ||
plugins: ["testing-library", "unused-imports", "jest-dom", "prettier"], | ||
env: { | ||
browser: true, | ||
node: false, | ||
es6: true, | ||
}, | ||
globals: { | ||
RequestInit: true, | ||
process: "readonly", | ||
cy: "readonly", | ||
}, | ||
extends: ["react-app", "plugin:import/recommended", "plugin:import/typescript", "prettier", "plugin:storybook/recommended"], | ||
plugins: ["testing-library", "unused-imports", "jest-dom", "prettier"], | ||
env: { | ||
browser: true, | ||
node: false, | ||
es6: true | ||
}, | ||
globals: { | ||
RequestInit: true, | ||
process: "readonly", | ||
cy: "readonly" | ||
}, | ||
rules: { | ||
"import/no-unresolved": "off", | ||
"import/first": "warn", | ||
"import/order": ["warn", { | ||
"newlines-between": "always", | ||
pathGroups: [{ | ||
pattern: "~/**", | ||
group: "external", | ||
position: "after" | ||
}] | ||
}], | ||
"import/newline-after-import": "warn", | ||
"import/no-commonjs": "off", | ||
"import/no-named-as-default": "off", | ||
"prettier/prettier": "error", | ||
"arrow-body-style": "off", | ||
"prefer-arrow-callback": "off", | ||
"unused-imports/no-unused-imports": "error", | ||
"unused-imports/no-unused-vars": ["warn", { | ||
vars: "all", | ||
varsIgnorePattern: "^_", | ||
args: "after-used", | ||
argsIgnorePattern: "^_" | ||
}], | ||
camelcase: ["warn", { | ||
allow: ["days_to_show", "organization_id", "sending_at"] | ||
}] | ||
}, | ||
overrides: [{ | ||
files: ["**/*.stories.*"], | ||
rules: { | ||
"import/no-unresolved": "off", | ||
"import/first": "warn", | ||
"import/order": [ | ||
"warn", | ||
{ | ||
"newlines-between": "always", | ||
pathGroups: [ | ||
{ | ||
pattern: "~/**", | ||
group: "external", | ||
position: "after", | ||
}, | ||
], | ||
}, | ||
], | ||
"import/newline-after-import": "warn", | ||
"import/no-commonjs": "off", | ||
"import/no-named-as-default": "off", | ||
"prettier/prettier": "error", | ||
"arrow-body-style": "off", | ||
"prefer-arrow-callback": "off", | ||
"unused-imports/no-unused-imports": "error", | ||
"unused-imports/no-unused-vars": [ | ||
"warn", | ||
{ | ||
vars: "all", | ||
varsIgnorePattern: "^_", | ||
args: "after-used", | ||
argsIgnorePattern: "^_", | ||
}, | ||
], | ||
camelcase: [ | ||
"warn", | ||
{ | ||
allow: ["days_to_show", "organization_id", "sending_at"], | ||
}, | ||
], | ||
}, | ||
overrides: [ | ||
{ | ||
files: ["**/*.stories.*"], | ||
rules: { | ||
"import/no-anonymous-default-export": "off", | ||
}, | ||
}, | ||
{ | ||
files: [ | ||
"./src/**/__tests__/**/*.[jt]s?(x)", | ||
"./src/**/?(*.)+(spec|test).[jt]s?(x)", | ||
], | ||
extends: [ | ||
"plugin:testing-library/react", | ||
"plugin:jest-dom/recommended", | ||
], | ||
rules: { | ||
"testing-library/no-render-in-setup": [ | ||
"error", | ||
{ | ||
allowTestingFrameworkSetupHook: "beforeEach", | ||
}, | ||
], | ||
"testing-library/no-node-access": "off", | ||
"testing-library/prefer-screen-queries": "warn", | ||
"testing-library/no-unnecessary-act": "warn", | ||
"testing-library/no-await-sync-query": "warn", | ||
}, | ||
}, | ||
{ | ||
plugins: ["chai-friendly"], | ||
files: ["**/cypress/**/*.[jt]s?(x)"], | ||
extends: ["plugin:cypress/recommended"], | ||
rules: { | ||
"no-unused-expressions": "off", | ||
"@typescript-eslint/no-unused-expressions": "off", | ||
"chai-friendly/no-unused-expressions": "error", | ||
}, | ||
}, | ||
], | ||
settings: { | ||
"import/resolver": {}, | ||
}, | ||
ignorePatterns: ["node_modules/", "build/", "src/reportWebVitals.js"], | ||
}; | ||
"import/no-anonymous-default-export": "off" | ||
} | ||
}, { | ||
files: ["./src/**/__tests__/**/*.[jt]s?(x)", "./src/**/?(*.)+(spec|test).[jt]s?(x)"], | ||
extends: ["plugin:testing-library/react", "plugin:jest-dom/recommended"], | ||
rules: { | ||
"testing-library/no-render-in-setup": ["error", { | ||
allowTestingFrameworkSetupHook: "beforeEach" | ||
}], | ||
"testing-library/no-node-access": "off", | ||
"testing-library/prefer-screen-queries": "warn", | ||
"testing-library/no-unnecessary-act": "warn", | ||
"testing-library/no-await-sync-query": "warn" | ||
} | ||
}, { | ||
plugins: ["chai-friendly"], | ||
files: ["**/cypress/**/*.[jt]s?(x)"], | ||
extends: ["plugin:cypress/recommended"], | ||
rules: { | ||
"no-unused-expressions": "off", | ||
"@typescript-eslint/no-unused-expressions": "off", | ||
"chai-friendly/no-unused-expressions": "error" | ||
} | ||
}], | ||
settings: { | ||
"import/resolver": {} | ||
}, | ||
ignorePatterns: ["node_modules/", "build/", "src/reportWebVitals.js"] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module.exports = { | ||
stories: [ | ||
"../src/**/*.stories.mdx", | ||
"../src/**/*.stories.@(js|jsx|ts|tsx)", | ||
], | ||
addons: [ | ||
"@storybook/addon-links", | ||
"@storybook/addon-essentials", | ||
"@storybook/addon-interactions", | ||
"@storybook/addon-a11y", | ||
], | ||
framework: "@storybook/react", | ||
core: { | ||
builder: "@storybook/builder-webpack5", | ||
}, | ||
refs: { | ||
trussworks: { | ||
title: "Trussworks Storybook", | ||
url: "https://trussworks.github.io/react-uswds/", | ||
expanded: false, // optional, true by default | ||
}, | ||
}, | ||
staticDirs: ["../src/content", "../src/content/product"], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { initializeWorker, mswDecorator } from "msw-storybook-addon"; | ||
import { CacheProvider } from "rest-hooks"; | ||
import { BrowserRouter } from "react-router-dom"; | ||
import { HelmetProvider } from "react-helmet-async"; | ||
|
||
import "../src/content/generated/global.out.css"; | ||
|
||
export const parameters = { | ||
actions: { argTypesRegex: "^on[A-Z].*" }, | ||
controls: { | ||
matchers: { | ||
color: /(background|color)$/i, | ||
date: /Date$/, | ||
}, | ||
}, | ||
options: { | ||
storySort: { | ||
method: "alphabetical", | ||
order: [], | ||
}, | ||
}, | ||
}; | ||
|
||
function withRestHooksCacheProvider(Story) { | ||
return ( | ||
<CacheProvider> | ||
<Story /> | ||
</CacheProvider> | ||
); | ||
} | ||
|
||
function withRouter(Story) { | ||
return ( | ||
<BrowserRouter> | ||
<Story /> | ||
</BrowserRouter> | ||
); | ||
} | ||
|
||
function withHelmet(Story) { | ||
return ( | ||
<HelmetProvider> | ||
<Story /> | ||
</HelmetProvider> | ||
); | ||
} | ||
|
||
export const decorators = [withHelmet, withRouter, withRestHooksCacheProvider]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// MyComponent.story.ts|tsx | ||
|
||
import React from "react"; | ||
|
||
import { ComponentMeta, ComponentStory } from "@storybook/react"; | ||
|
||
import { StaticAlert, StaticAlertType } from "./StaticAlert"; | ||
|
||
export default { | ||
title: "components/StaticAlert", | ||
component: StaticAlert, | ||
argTypes: { | ||
type: { | ||
control: { | ||
type: "select", | ||
options: Object.values(StaticAlertType), | ||
}, | ||
}, | ||
}, | ||
} as ComponentMeta<typeof StaticAlert>; | ||
|
||
export const Default: ComponentStory<typeof StaticAlert> = (args) => ( | ||
<StaticAlert {...args} /> | ||
); | ||
Default.args = { | ||
type: StaticAlertType.Success, | ||
heading: "StaticAlert Heading", | ||
message: "This is the message of the StaticAlert", | ||
children: "Children are optional! (Try clearing me out)", | ||
}; |
Oops, something went wrong.