1
0
Fork 0

🚧 Added storybook for React components

This commit is contained in:
Joost De Cock 2019-04-21 15:31:08 +02:00
parent 067338271d
commit 4d7b7df674
14 changed files with 3332 additions and 192 deletions

View file

@ -0,0 +1,4 @@
import "storybook-addon-material-ui";
import "@storybook/addon-backgrounds/register";
import "@storybook/addon-knobs/register";
//import '@storybook/addon-notes/register';

View file

@ -0,0 +1,11 @@
export const dark = [
{
name: "dark",
value: "#212529",
default: true
}
];
export default {
dark
};

View file

@ -0,0 +1,17 @@
import { configure } from "@storybook/react";
import { addParameters } from "@storybook/react";
function loadStories() {
// Load all 'stories.js' files under src
const req = require.context("../src", true, /stories\.js$/);
req.keys().forEach(filename => req(filename));
}
//addParameters({
// backgrounds: [
// { name: 'Light', value: '#f8f9fa', default: true },
// { name: 'Dark', value: '#212529' },
// ],
//});
configure(loadStories, module);

View file

@ -21,7 +21,8 @@
"modulebuild": "BABEL_ENV=production rollup -c -o ../../dist/components/index.mjs -f es",
"build": "./scripts/build.sh",
"test": "echo \"components: No tests configured. Perhaps you'd like to do this?\" && exit 0",
"pubtest": "npm publish --registry http://localhost:6662"
"pubtest": "npm publish --registry http://localhost:6662",
"storybook": "start-storybook -p 6663"
},
"peerDependencies": {
"react": "^16.4.1",

View file

@ -0,0 +1,10 @@
import React from "react";
import { storiesOf, addDecorator } from "@storybook/react";
import Emblem from ".";
import "../../../../dist/css-theme/theme.css";
storiesOf("Graphics/Emblem", module).add(
"FreeSewing",
() => <Emblem t1="Free" t2="Sewing" />,
{ notes: { markdown: ` test **here**` } }
);

View file

@ -0,0 +1,15 @@
import React from "react";
import { storiesOf, addDecorator } from "@storybook/react";
//import {muiTheme} from 'storybook-addon-material-ui';
import Logo from ".";
storiesOf("Graphics/Logo", module)
// .addDecorator(muiTheme())
.add("Default", () => <Logo />)
.add("Custom size", () => <Logo size={100} />)
.add("Custom color", () => (
<div style={{ color: "green" }}>
<Logo />
</div>
))
.add("Embedded", () => <Logo embed={true} />);

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,10 @@
import React from "react";
import { storiesOf } from "@storybook/react";
import Ogol from ".";
import "../../../../dist/css-theme/theme.css";
import { dark as backgrounds } from "../../.storybook/backgrounds";
storiesOf("Graphics/Ogol", module)
.add("Default", () => <Ogol />, { backgrounds })
.add("Custom color", () => <Ogol color="green" />, { backgrounds })
.add("Custom size", () => <Ogol size={200} />, { backgrounds });

View file

@ -0,0 +1,43 @@
import React, { useState } from "react";
import PropTypes from "prop-types";
import Radio from "@material-ui/core/Radio";
import RadioGroup from "@material-ui/core/RadioGroup";
import FormControlLabel from "@material-ui/core/FormControlLabel";
const Bool = props => {
const [value, setValue] = useState(props.dflt);
const toggle = () => {
props.updateOption(props.name, !value);
setValue(!value);
};
return (
<RadioGroup onChange={toggle} value={JSON.stringify(value)}>
<FormControlLabel
control={<Radio color="primary" />}
value="false"
checked={value === "false" ? true : false}
label={props.labels[0]}
/>
<FormControlLabel
control={<Radio color="primary" />}
value="true"
checked={value === "true" ? true : false}
label={props.labels[1]}
/>
</RadioGroup>
);
};
Bool.propTypes = {
dflt: PropTypes.bool,
labels: PropTypes.arrayOf(PropTypes.string),
updateOption: PropTypes.func.isRequired,
name: PropTypes.string.isRequired
};
Bool.defaultProps = {
dflt: false,
labels: ["false", "true"]
};
export default Bool;

View file

@ -0,0 +1,19 @@
import React from "react";
import { storiesOf } from "@storybook/react";
import Bool from ".";
const props = {
updateOption: (name, value) =>
console.log(`Updated option ${name}, value is now: ${value}`),
name: "exampleBoolOption"
};
const noyes = ["No", "Yes"];
storiesOf("Draft/Options/Bool", module)
.add("Default", () => <Bool {...props} />)
.add("Default: false", () => <Bool {...props} dflt={false} />)
.add("Default: true", () => <Bool {...props} dflt={true} />)
.add("With labels, No", () => <Bool {...props} dflt={false} labels={noyes} />)
.add("With labels, Yes", () => (
<Bool {...props} dflt={true} labels={noyes} />
));