Skip to content

Commit

Permalink
Merge pull request #663 from CraveFood/storybook
Browse files Browse the repository at this point in the history
Update storybook to the latest version
  • Loading branch information
alcferreira authored Jan 3, 2019
2 parents bf00324 + b06c364 commit ddf53a9
Show file tree
Hide file tree
Showing 90 changed files with 6,531 additions and 7,529 deletions.
3 changes: 0 additions & 3 deletions .babelrc

This file was deleted.

6 changes: 6 additions & 0 deletions .storybook/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from "react";
import { createGlobalStyle } from "styled-components";
import { configure, addDecorator } from "@storybook/react";
import { withInfo } from "@storybook/addon-info";

const req = require.context(
"../",
Expand Down Expand Up @@ -177,6 +178,11 @@ function withGlobalStyle(storyFn) {
);
}

// avoid the withInfo decorator when generating snapshots/running tests
if (process.env.NODE_ENV !== "test") {
addDecorator(withInfo);
}

addDecorator(withGlobalStyle);

configure(loadStories, module);
2 changes: 2 additions & 0 deletions .storybook/jest/require.context.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import registerRequireContextHook from "babel-plugin-require-context-hook/register";
registerRequireContextHook();
5 changes: 0 additions & 5 deletions Storyshots.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ import { addSerializer } from "jest-specific-snapshot";
// and https://github.com/storybooks/storybook/issues/887#issuecomment-357073807
addSerializer(styleSheetSerializer);

//mock withInfo to exclude info HTML from the snapshots
jest.mock("@storybook/addon-info", () => ({
withInfo: () => fn => fn
}));

initStoryshots({
framework: "react",
test: multiSnapshotWithOptions({})
Expand Down
26 changes: 26 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module.exports = api => {
api.cache(true);
return {
presets: ["@babel/preset-env", "@babel/preset-react"],
plugins: [
// Stage 2 plugins
["@babel/plugin-proposal-decorators", { legacy: true }],
"@babel/plugin-proposal-function-sent",
"@babel/plugin-proposal-export-namespace-from",
"@babel/plugin-proposal-numeric-separator",
"@babel/plugin-proposal-throw-expressions",
// Stage 3 plugins
"@babel/plugin-syntax-dynamic-import",
"@babel/plugin-syntax-import-meta",
["@babel/plugin-proposal-class-properties", { loose: false }],
"@babel/plugin-proposal-json-strings"
],
env: {
test: {
plugins: ["babel-plugin-require-context-hook"]
}
},
//allow imports from transpiled farmblocks packages
sourceType: "unambiguous"
};
};
3 changes: 2 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const coveragePathIgnorePatterns = [".story.js", "lib/*"];
const completeConfig = {
verbose: true,
coveragePathIgnorePatterns,
setupTestFrameworkScriptFile: "<rootDir>/jest.testFramework.js"
setupTestFrameworkScriptFile: "<rootDir>/jest.testFramework.js",
setupFiles: ["./.storybook/jest/require.context.js"]
};

const fastConfig = {
Expand Down
37 changes: 25 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,33 @@
"url": "git+https://github.com/CraveFood/farmblocks.git"
},
"devDependencies": {
"@babel/cli": "^7.2.3",
"@babel/core": "^7.2.2",
"@babel/plugin-proposal-class-properties": "^7.2.3",
"@babel/plugin-proposal-decorators": "^7.2.3",
"@babel/plugin-proposal-export-namespace-from": "^7.2.0",
"@babel/plugin-proposal-function-sent": "^7.2.0",
"@babel/plugin-proposal-json-strings": "^7.2.0",
"@babel/plugin-proposal-numeric-separator": "^7.2.0",
"@babel/plugin-proposal-throw-expressions": "^7.2.0",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/plugin-syntax-import-meta": "^7.2.0",
"@babel/preset-env": "^7.2.3",
"@babel/preset-flow": "^7.0.0",
"@babel/preset-react": "^7.0.0",
"@babel/runtime": "^7.2.0",
"@crave/farmblocks-dev-scaffold": "^1.0.0",
"@storybook/addon-actions": "^3.4.6",
"@storybook/addon-info": "^3.4.6",
"@storybook/addon-links": "^3.4.6",
"@storybook/addon-storyshots": "^3.4.6",
"@storybook/addons": "^3.4.6",
"@storybook/react": "^3.4.6",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"@storybook/addon-actions": "^4.1.3",
"@storybook/addon-info": "^4.1.3",
"@storybook/addon-links": "^4.1.3",
"@storybook/addon-storyshots": "^4.1.3",
"@storybook/addons": "^4.1.3",
"@storybook/react": "^4.1.3",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^10.0.0",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"babel-runtime": "^6.26.0",
"babel-jest": "^23.4.2",
"babel-loader": "^8.0.0",
"babel-plugin-require-context-hook": "^1.0.0",
"commitizen": "^3.0.4",
"coveralls": "^3.0.1",
"cz-lerna-changelog": "^1.2.1",
Expand Down
11 changes: 3 additions & 8 deletions packages/alert/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,15 @@
"author": "Crave Food Systems and AUTHORS",
"license": "MIT",
"main": "lib/index.js",
"files": [
"AUTHORS",
"LICENSE",
"README.md",
"CHANGELOG.md",
"lib"
],
"files": ["AUTHORS", "LICENSE", "README.md", "CHANGELOG.md", "lib"],
"publishConfig": {
"access": "public"
},
"scripts": {
"test": "jest",
"clean": "rm -rf lib",
"build": "yarn clean && babel src -d lib --ignore '*.test.js,*.story.js'",
"build":
"yarn clean && babel --root-mode upward src -d lib --ignore 'src/**/*.test.js','src/**/*.story.js'",
"prestorybook": "cp -Rf ../../.storybook .",
"storybook": "start-storybook -p 6006"
},
Expand Down
181 changes: 77 additions & 104 deletions packages/alert/src/Alert.story.js
Original file line number Diff line number Diff line change
@@ -1,118 +1,91 @@
import React from "react";
import styled from "styled-components";
import { storiesOf } from "@storybook/react";
import { withInfo } from "@storybook/addon-info";
import { action } from "@storybook/addon-actions";

import Alert from ".";
import { POSITIVE, NEWS, NEGATIVE, ATTENTION } from "./constants/alertTypes";

const ExtendedAlert = styled(Alert)`
const StyledAlert = styled(Alert)`
transform: rotate(5deg);
`;

const ExtendedAlert = props => <StyledAlert {...props} />;

storiesOf("Alert", module)
.add(
"default",
withInfo()(() => (
<Alert text="Default is set to news type, and have default onDismiss function that hides the alert." />
))
)
.add(
"default at bottom",
withInfo()(() => (
<Alert
bottomAligned
text="Default is set to news type, and have default onDismiss function that hides the alert."
/>
))
)
.add(
"visibleTime 2 seconds",
withInfo()(() => (
<Alert
text="This message will self-destruct in 2 seconds"
visibleTime={2000}
/>
))
)
.add(
"non dismissable",
withInfo()(() => <Alert dismissable={false} text="I can't be dismissed!" />)
)
.add(
"with custom z-index",
withInfo()(() => (
<div>
<div
style={{
width: 120,
height: 120,
position: "absolute",
zIndex: 10,
background: "gray"
}}
/>
<div
style={{
width: 100,
height: 100,
position: "absolute",
zIndex: 12,
background: "rgba(0, 0, 0, 0.7)"
}}
/>
<Alert text="should display between the two" zIndex={11} />
</div>
))
)
.add(
"type positive",
withInfo()(() => (
<Alert
dismissable
type={POSITIVE}
text="Positive alert!"
onDismiss={action("dismiss triggered")}
/>
))
)
.add(
"type news",
withInfo()(() => (
<Alert
dismissable
type={NEWS}
text="New alert!"
onDismiss={action("dismiss triggered")}
/>
))
)
.add(
"type negative",
withInfo()(() => (
<Alert
dismissable
type={NEGATIVE}
text="Negative alert!"
onDismiss={action("dismiss triggered")}
.add("default", () => (
<Alert text="Default is set to news type, and have default onDismiss function that hides the alert." />
))
.add("default at bottom", () => (
<Alert
bottomAligned
text="Default is set to news type, and have default onDismiss function that hides the alert."
/>
))
.add("visibleTime 2 seconds", () => (
<Alert
text="This message will self-destruct in 2 seconds"
visibleTime={2000}
/>
))
.add("non dismissable", () => (
<Alert dismissable={false} text="I can't be dismissed!" />
))
.add("with custom z-index", () => (
<div>
<div
style={{
width: 120,
height: 120,
position: "absolute",
zIndex: 10,
background: "gray"
}}
/>
))
)
.add(
"type attention",
withInfo()(() => (
<Alert
dismissable
type={ATTENTION}
text="Attention alert!"
onDismiss={action("dismiss triggered")}
<div
style={{
width: 100,
height: 100,
position: "absolute",
zIndex: 12,
background: "rgba(0, 0, 0, 0.7)"
}}
/>
))
)
.add(
"extended style",
withInfo()(() => (
<ExtendedAlert text="Extended with 'transform: rotate(5deg)'" />
))
);
<Alert text="should display between the two" zIndex={11} />
</div>
))
.add("type positive", () => (
<Alert
dismissable
type={POSITIVE}
text="Positive alert!"
onDismiss={action("dismiss triggered")}
/>
))
.add("type news", () => (
<Alert
dismissable
type={NEWS}
text="New alert!"
onDismiss={action("dismiss triggered")}
/>
))
.add("type negative", () => (
<Alert
dismissable
type={NEGATIVE}
text="Negative alert!"
onDismiss={action("dismiss triggered")}
/>
))
.add("type attention", () => (
<Alert
dismissable
type={ATTENTION}
text="Attention alert!"
onDismiss={action("dismiss triggered")}
/>
))
.add("extended style", () => (
<ExtendedAlert text="Extended with 'transform: rotate(5deg)'" />
));
27 changes: 10 additions & 17 deletions packages/alert/src/BrieflyDisplay.story.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
import React from "react";
import { storiesOf } from "@storybook/react";
import { withInfo } from "@storybook/addon-info";

import BrieflyDisplay from "./BrieflyDisplay";

storiesOf("Alert (private)/BrieflyDisplay", module)
.add(
"default",
withInfo()(() => (
<BrieflyDisplay>
<p>this text should be displayed for the default time</p>
</BrieflyDisplay>
))
)
.add(
"display for 5 seconds",
withInfo()(() => (
<BrieflyDisplay time={5000}>
<p>This text should be displayed for 5 seconds</p>
</BrieflyDisplay>
))
);
.add("default", () => (
<BrieflyDisplay>
<p>this text should be displayed for the default time</p>
</BrieflyDisplay>
))
.add("display for 5 seconds", () => (
<BrieflyDisplay time={5000}>
<p>This text should be displayed for 5 seconds</p>
</BrieflyDisplay>
));
Loading

0 comments on commit ddf53a9

Please sign in to comment.