generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 42
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 (#…
…8803) 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 are very simple CSF examples for the StaticAlert and USLink components 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
authored
Apr 3, 2023
1 parent
161feca
commit 5fc30cd
Showing
7 changed files
with
6,730 additions
and
253 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
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,22 @@ | ||
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/", | ||
}, | ||
}, | ||
}; |
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,59 @@ | ||
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 MockDate from "mockdate"; | ||
|
||
import "../src/content/generated/global.out.css"; | ||
|
||
// mock all dates in stories to make sure we don't run into date-related inconsistencies | ||
MockDate.set("2023-01-01"); | ||
|
||
export const parameters = { | ||
actions: { argTypesRegex: "^on[A-Z].*" }, | ||
controls: { | ||
matchers: { | ||
color: /(background|color)$/i, | ||
date: /Date$/, | ||
}, | ||
}, | ||
options: { | ||
storySort: { | ||
method: "alphabetical", | ||
order: [], | ||
}, | ||
}, | ||
}; | ||
|
||
initializeWorker(); | ||
|
||
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, | ||
mswDecorator, | ||
]; |
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,27 @@ | ||
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: "radio", | ||
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)", | ||
}; |
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,50 @@ | ||
import React from "react"; | ||
import { ComponentMeta, ComponentStory } from "@storybook/react"; | ||
|
||
import { USExtLink, USLink, USLinkButton } from "./USLink"; | ||
|
||
export default { | ||
title: "components/USLink", | ||
component: USLink, | ||
} as ComponentMeta<typeof USLink>; | ||
|
||
export const Default: ComponentStory<typeof USLink> = (args) => ( | ||
<USLink {...args} /> | ||
); | ||
Default.args = { | ||
className: "", | ||
children: "This is a link", | ||
}; | ||
|
||
export const Button: ComponentStory<typeof USLinkButton> = (args) => ( | ||
<USLinkButton {...args} /> | ||
); | ||
Button.args = { | ||
children: "This is a link styled as a button", | ||
secondary: false, | ||
base: false, | ||
inverse: false, | ||
unstyled: false, | ||
}; | ||
Button.argTypes = { | ||
accentStyle: { | ||
control: { | ||
type: "radio", | ||
options: ["", "cool", "warm"], | ||
}, | ||
}, | ||
size: { | ||
control: { | ||
type: "radio", | ||
options: ["", "big"], | ||
}, | ||
}, | ||
}; | ||
|
||
export const ExtLink: ComponentStory<typeof USExtLink> = (args) => ( | ||
<USExtLink {...args} /> | ||
); | ||
ExtLink.args = { | ||
className: "", | ||
children: "This is an external link", | ||
}; |
Oops, something went wrong.