Skip to content
This repository has been archived by the owner on Feb 29, 2020. It is now read-only.

Commit

Permalink
chore(storybook): #1039 Implement React Storybook support
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Mosedale committed Aug 10, 2016
1 parent e4697d7 commit f1e1375
Show file tree
Hide file tree
Showing 19 changed files with 217 additions and 74 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ logs/
firefox/
lib/vendor.bundle.js
activity-streams-env/
!.*
9 changes: 9 additions & 0 deletions .storybook/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const {configure} = require("@kadira/storybook");

function loadStories() {
require("../content-test/components/Spotlight.story");
require("../content-test/components/ContextMenu.story");
// require as many stories as you need.
}

configure(loadStories, module);
1 change: 1 addition & 0 deletions .storybook/head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<link rel="stylesheet" href="main.css" />
19 changes: 19 additions & 0 deletions .storybook/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"use strict";
const {plugins, resolve} = require("../webpack.common");

module.exports = storybookBaseConfig =>
Object.assign(storybookBaseConfig, {
resolve,
module: {
loaders: [
{test: /\.json$/, loader: "json"},
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: "babel"
}
]
},
devtool: "eval-sourcemap",
plugins: storybookBaseConfig.plugins.concat(plugins)
});
2 changes: 1 addition & 1 deletion content-src/components/ActivityFeed/ActivityFeed.scss
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
}

&.bookmark .star {
background: url('img/glyph-bookmark-16-blue.svg') no-repeat center center;
background: url('#{$image-path}glyph-bookmark-16-blue.svg') no-repeat center center;
background-size: 18px;
border: 0;
height: 18px;
Expand Down
2 changes: 1 addition & 1 deletion content-src/components/LinkMenuButton/LinkMenuButton.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
width: $link-menu-button-size;
height: $link-menu-button-size;
background-color: $white;
background-image: url('img/glyph-more-16.svg');
background-image: url('#{$image-path}glyph-more-16.svg');
background-position: 65%;
background-repeat: no-repeat;
background-clip: padding-box;
Expand Down
2 changes: 1 addition & 1 deletion content-src/components/LoadMore/LoadMore.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
display: inline-block;
width: 15px;
height: 15px;
background-image: url('img/glyph-showmore-16.svg');
background-image: url('#{$image-path}glyph-showmore-16.svg');
background-size: 15px;
}

Expand Down
2 changes: 1 addition & 1 deletion content-src/components/Loader/Loader.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
width: $loader-size;
height: $loader-size;
display: inline-block;
background-image: url('img/[email protected]');
background-image: url('#{$image-path}[email protected]');
background-size: $loader-size $loader-size;
}
}
4 changes: 2 additions & 2 deletions content-src/components/MediaPreview/MediaPreview.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
content: '';
width: 65px;
height: 40px;
background: url('img/[email protected]') no-repeat center center;
background: url('#{$image-path}[email protected]') no-repeat center center;
background-size: 65px 40px;
display: block;
}

&:hover::after {
background-image: url('img/[email protected]');
background-image: url('#{$image-path}[email protected]');
}

&.isPlaying::after {
Expand Down
12 changes: 6 additions & 6 deletions content-src/components/Search/Search.scss
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

&:hover > #historyIcon,
&.active > #historyIcon {
background-image: url('img/glyph-search-history.svg#search-history-active');
background-image: url('#{$image-path}glyph-search-history.svg#search-history-active');
}
}
}
Expand All @@ -76,7 +76,7 @@
display: inline-block;
margin-right: 10px;
margin-bottom: -3px;
background-image: url('img/glyph-search-history.svg#search-history');
background-image: url('#{$image-path}glyph-search-history.svg#search-history');
}

.search-partners {
Expand Down Expand Up @@ -150,13 +150,13 @@
transition: box-shadow 150ms;
box-shadow: 0 0 0 0.5px $search-shadow;
background-color: $search-blue;
background-image: url('img/glyph-forward-16-white.svg');
background-image: url('#{$image-path}glyph-forward-16-white.svg');
color: $white;
}
}

.search-label {
background: url('img/glyph-search-16.svg') no-repeat center center;
background: url('#{$image-path}glyph-search-16.svg') no-repeat center center;
background-size: 20px;
position: absolute;
top: 0;
Expand All @@ -177,7 +177,7 @@
padding: 0;
transition: box-shadow 150ms;
box-shadow: none;
background: $search-button-grey url('img/glyph-forward-16.svg') no-repeat center center;
background: $search-button-grey url('#${image-path}glyph-forward-16.svg') no-repeat center center;
background-size: 16px 16px;

&:hover {
Expand All @@ -186,7 +186,7 @@
transition: box-shadow 150ms;
box-shadow: 0 0 0 0.5px $search-shadow;
background-color: $search-blue;
background-image: url('img/glyph-forward-16-white.svg');
background-image: url('#{$image-path}glyph-forward-16-white.svg');
color: $white;
}
}
Expand Down
2 changes: 1 addition & 1 deletion content-src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const Root = React.createClass({
});

function renderRootWhenAddonIsReady() {
if (window.navigator.activity_streams_addon) {
if (window.navigator.activity_streams_addon || __CONFIG__.USE_SHIM) {
ReactDOM.render(<Root />, document.getElementById("root"));
} else {
// If the content bridge to the addon isn't set up yet, try again soon.
Expand Down
42 changes: 21 additions & 21 deletions content-src/styles/icons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,86 +12,86 @@
}

&.icon-activity-stream {
background-image: url('img/glyph-activityStream-16.svg');
background-image: url('#{$image-path}glyph-activityStream-16.svg');
}

&.icon-arrow {
background-image: url('img/glyph-showmore-16.svg');
background-image: url('#{$image-path}glyph-showmore-16.svg');
}

&.icon-bookmark {
background-image: url('img/glyph-bookmark-16.svg');
background-image: url('#{$image-path}glyph-bookmark-16.svg');
}

&.icon-bookmark-white {
background-image: url('img/glyph-bookmark-16-white.svg');
background-image: url('#{$image-path}glyph-bookmark-16-white.svg');
}

&.icon-bookmark-remove {
background-image: url('img/glyph-bookmark-remove-16.svg');
background-image: url('#{$image-path}glyph-bookmark-remove-16.svg');
}

&.icon-delete {
background-image: url('img/glyph-delete-16.svg');
background-image: url('#{$image-path}glyph-delete-16.svg');
}

&.icon-dismiss {
background-image: url('img/glyph-dismiss-16.svg');
background-image: url('#{$image-path}glyph-dismiss-16.svg');
}

&.icon-firefox-white {
background-image: url('img/glyph-firefox-white-16.svg');
background-image: url('#{$image-path}glyph-firefox-white-16.svg');
}

&.icon-new-window {
background-image: url('img/glyph-newWindow-16.svg');
background-image: url('#{$image-path}glyph-newWindow-16.svg');
}

&.icon-new-window-private {
background-image: url('img/glyph-newWindow-private-16.svg');
background-image: url('#{$image-path}glyph-newWindow-private-16.svg');
}

&.icon-forward {
background-image: url('img/glyph-forward-16.svg');
background-image: url('#{$image-path}glyph-forward-16.svg');
}

&.icon-search {
background-image: url('img/glyph-search-16.svg');
background-image: url('#{$image-path}glyph-search-16.svg');
}

&.icon-settings {
background-image: url('img/glyph-settings-16.svg');
background-image: url('#{$image-path}glyph-settings-16.svg');
}

&.icon-showMore {
background-image: url('img/glyph-showmore-16.svg');
background-image: url('#{$image-path}glyph-showmore-16.svg');
}

&.icon-timeline {
background-image: url('img/list-icon.svg');
background-image: url('#{$image-path}list-icon.svg');
}

&.icon-check {
background-image: url('img/glyph-check-16.svg');
background-image: url('#{$image-path}glyph-check-16.svg');
}

&.icon-pocket {
background-image: url('img/glyph-pocket-16.svg');
background-image: url('#{$image-path}glyph-pocket-16.svg');
}

&.icon-historyItem {
background-image: url('img/glyph-historyItem-16.svg');
background-image: url('#{$image-path}glyph-historyItem-16.svg');
}

&.icon-sync {
background-image: url('img/glyph-sync-16.svg');
background-image: url('#{$image-path}glyph-sync-16.svg');
}

&.icon-tab {
background-image: url('img/glyph-tab-16.svg');
background-image: url('#{$image-path}glyph-tab-16.svg');
}

&.icon-topic {
background-image: url('img/glyph-topic-16.svg');
background-image: url('#{$image-path}glyph-topic-16.svg');
}
}
2 changes: 2 additions & 0 deletions content-src/styles/variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ $context-menu-item-padding: 3px 12px;

$icon-size: 16px;

$image-path: 'img/';

$tooltip-height: 50px;
$tooltip-background-color: #FFF3CE;
$tooltip-border-radius: 5px;
Expand Down
46 changes: 46 additions & 0 deletions content-test/components/ContextMenu.story.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const React = require("react");
const {storiesOf} = require("@kadira/storybook");
const ContextMenu = require("components/ContextMenu/ContextMenu");

const DEFAULT_OPTIONS = [
{label: "Apples", onClick: () => {}},
{label: "Oranges", onClick: () => {}},
{label: "Grapes", onClick: () => {}}
];

// This is so we can show the context menu. Note that this is only
// necessary because ContextMenu has certain implicit dependencies on
// its container. Fully encapsulated components (hopefully any new
// new ones!) should be renderable without needing a container!
const ContextMenuContainer = React.createClass({
getInitialState() {
return {visible: true};
},
render() {
const style = {
position: "relative",
display: "flex",
alignItems: "center",
justifyContent: "center",
width: 150,
height: 60,
border: "1px dashed #DDD"
};
const buttonStyle = {
fontSize: 11,
display: "inline-block"
};
return (<div style={style}>
<ContextMenu
options={this.props.options}
visible={this.state.visible}
onUpdate={visible => this.setState({visible})} />
<button style={buttonStyle} onClick={() => this.setState({visible: !this.state.visible})}>Toggle menu</button>
</div>);
}
});

storiesOf("ContextMenu", module)
.add("default props", () => (
<ContextMenuContainer options={DEFAULT_OPTIONS} />
));
47 changes: 47 additions & 0 deletions content-test/components/Spotlight.story.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const React = require("react");
const {SpotlightItem} = require("components/Spotlight/Spotlight");
const {storiesOf, action} = require("@kadira/storybook");
const {createMockProvider} = require("../test-utils");
const {createSite} = require("../faker");
const Provider = createMockProvider({dispatch: action("dispatched a redux action")});

// XXX should get rid of container here. See comment in ContextMenu.story
// for details.
const Container = props => (
<Provider>
<div style={{padding: "20px"}}>
{props.children}
</div>
</Provider>
);

// Note that if a site image is not in the cache, it can take a while
// (eg 10 seconds) to load, because the image load starts very late, for
// unclear reasons. Presumably something to do with faker, tippy-top-sites,
// lorempixel (used by faker for the images), or Spotlight (aka Highlight)
// itself.
storiesOf("Highlight", module)
.add("All valid properties", () => {
const site = createSite({images: 1});
site.bestImage = site.images[0];
return (<Container><SpotlightItem {...site} /></Container>);
})
.add("Missing an image", () => {
const site = createSite({images: 0});
return (<Container><SpotlightItem {...site} /></Container>);
})
.add("Missing a favicon_url", () => {
const site = createSite({images: 1});
site.bestImage = site.images[0];
site.favicon_url = null;
site.favicon = null;
site.favicon_color = null;
site.favicon_colors = null;
return (<Container><SpotlightItem {...site} /></Container>);
})
.add("Missing a description", () => {
const site = createSite({images: 1});
site.bestImage = site.images[0];
site.description = null;
return (<Container><SpotlightItem {...site} /></Container>);
});
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"url-parse": "1.1.1"
},
"devDependencies": {
"@kadira/storybook": "2.2.1",
"babel": "6.5.2",
"babel-core": "6.13.2",
"babel-loader": "6.2.4",
Expand Down Expand Up @@ -170,7 +171,7 @@
"firefox": "npm run bundle:webpackAddon && jpm run -b nightly --prefs ./dev-prefs.json",
"test": "npm-run-all test:*",
"pretest": "npm run bundle && npm run copyTestImages && npm run copyTopSitesJson",
"test:lint": "eslint --ext=.js,.jsx,.json . && sass-lint -v -q",
"test:lint": "eslint --ext=.js,.jsx,.json . .storybook && sass-lint -v -q",
"test:checkbinary": "echo \"JPM_FIREFOX_BINARY: ${JPM_FIREFOX_BINARY}\"",
"test:jpm": "jpm test -b ${JPM_FIREFOX_BINARY:-\"nightly\"} --prefs ./test-prefs.json -v",
"test:karma": "NODE_ENV=test karma start",
Expand All @@ -179,6 +180,7 @@
"package": "npm run bundle && jpm xpi && mv activity-streams.xpi dist/activity-streams-$npm_package_version.xpi",
"travis": "npm run test",
"prepush": "npm run test:lint && npm run yamscripts",
"storybook": "start-storybook -p 9001 -s ./data/content",
"help": "yamscripts help",
"yamscripts": "yamscripts compile",
"__": "# NOTE: THESE SCRIPTS ARE COMPILED!!! EDIT yamscripts.yml instead!!!"
Expand Down
Loading

0 comments on commit f1e1375

Please sign in to comment.