Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storybook UI theming #3628

Merged
merged 118 commits into from
Jul 1, 2018
Merged
Show file tree
Hide file tree
Changes from 103 commits
Commits
Show all changes
118 commits
Select commit Hold shift + click to select a range
898c1f4
WIP
ndelangen May 19, 2018
bae0a2a
Merge branch 'feature/more-components' into feature/theming
ndelangen May 19, 2018
f546481
FIX drag blocker
ndelangen May 20, 2018
ee4a416
REFACTOR consolidate Tabs component && CHANGE registerAddon api to in…
ndelangen May 22, 2018
c6e704c
DOCUMENT new api for registering addon panels
ndelangen May 22, 2018
4c39c8b
CHANGE location and styling of Dimensions component
ndelangen May 22, 2018
313486f
FIX tests
ndelangen May 22, 2018
b45b078
Merge branch 'master' into feature/theming
ndelangen May 22, 2018
4ea75bb
REMOVE mobile header
ndelangen May 23, 2018
b668f5a
ADD theme variables for Tabs
ndelangen May 23, 2018
af097bc
FIX snapshots
ndelangen May 24, 2018
af506f2
Merge branch 'master' into feature/theming
ndelangen May 24, 2018
e6096cc
CHANGE to use custom version of react-treebeard with emotion for styling
ndelangen May 24, 2018
e9ce090
REMOVE basefonts from jest-addon Panel
ndelangen May 24, 2018
eddf2b7
REMOVE basefonts from viewport stories
ndelangen May 24, 2018
74de615
REMOVE basefonts from button
ndelangen May 24, 2018
79fc816
REMOVE basefonts from dimensions
ndelangen May 24, 2018
f72ce62
REMOVE basefonts from placeholder
ndelangen May 24, 2018
63613ec
FIX typo in Tabs stories
ndelangen May 24, 2018
92850ed
REMOVE basefonts from searchbox
ndelangen May 24, 2018
011142c
REMOVE basefonts from shortcuthelp
ndelangen May 24, 2018
98dc2fa
IMRPOVE theming for stories panel
ndelangen May 24, 2018
a2af2be
IMPROVE background theming
ndelangen May 24, 2018
f00243a
FIX & REFACTOR search box
ndelangen May 24, 2018
78c9a3e
FIX snapshots
ndelangen May 25, 2018
57c50f4
IMPROVE theme
ndelangen May 25, 2018
35c8838
WIP
ndelangen May 26, 2018
c801905
WIP
ndelangen May 27, 2018
2f5cf2f
ADD PanelActionBar component
ndelangen May 27, 2018
4230448
IMPROVE styling ActionBar
ndelangen May 27, 2018
ac9278f
FIX performance addon-knobs && REMOVE knobs in URLquery && ADD copy k…
ndelangen May 27, 2018
2a49259
Merge branch 'master' into feature/theming
ndelangen May 27, 2018
bab52c7
WIP
ndelangen May 28, 2018
b8f8d95
FIX knobs speed && REMOVE throttle
ndelangen May 28, 2018
8714ed7
ADD bordered mode for Tabs
ndelangen May 28, 2018
87be909
CLEANUP
ndelangen May 28, 2018
b6549d6
FIX speed knobs object type
ndelangen May 28, 2018
9187462
FIX linting
ndelangen May 28, 2018
d0b507e
FIX tests
ndelangen May 28, 2018
dd6037f
Merge branch 'master' into feature/theming
ndelangen May 30, 2018
26fe6f5
FIX knobs Array
ndelangen May 30, 2018
e76e9c7
Only run a11y analysis on demand
manuel-magnetix May 30, 2018
46cdbac
Use named export for event name
manuel-magnetix May 30, 2018
5c32f8e
ADD theming support for addon-action
ndelangen May 30, 2018
8701b83
ADD dark theme && ADD theme for action react-inspector
ndelangen May 30, 2018
b542d4c
FIX colour text in button of ActionBar
ndelangen May 30, 2018
5fc9c08
Merge pull request #3690 from DerJacques/feature/only-run-a11y-on-demand
ndelangen May 30, 2018
8366b67
ADD success & fail colours to theme
ndelangen May 30, 2018
978e7e5
CONSOLIDATE a11y ActionBar && theme a11y addon
ndelangen May 30, 2018
5ac92f3
IMPROVE styling of a11y header
ndelangen May 30, 2018
26b2bc5
ADD theming for addon-background
ndelangen May 30, 2018
407369b
FIX addon-notes so stateful containers always renders
ndelangen May 30, 2018
3ce57aa
FIX snapshots
ndelangen May 31, 2018
fb372a0
FIX theming of a11y
ndelangen May 31, 2018
c3f43d9
FIX lint issues
ndelangen May 31, 2018
12237db
FIX snapshot
ndelangen May 31, 2018
6d3c806
IMPROVE tabs
ndelangen May 31, 2018
996d276
theme knobs array
ndelangen Jun 1, 2018
9d503c2
REFACTOR form components
ndelangen Jun 1, 2018
7395379
ADD react-textarea-autosize to components
ndelangen Jun 1, 2018
4389c20
FIX tabs overflow
ndelangen Jun 1, 2018
cc68e66
theme viewport
ndelangen Jun 1, 2018
d2faeb7
REFACTOR knobs field to use field component
ndelangen Jun 1, 2018
1a5e90d
ADD todo statement to add theming for storysource addon
ndelangen Jun 1, 2018
41badab
theme knobs button
ndelangen Jun 1, 2018
1b5daf3
theme knobs color
ndelangen Jun 1, 2018
19bf77c
theme knobs files
ndelangen Jun 1, 2018
b642121
theme knobs number
ndelangen Jun 1, 2018
e66d323
theme knobs object
ndelangen Jun 1, 2018
29ac4c8
theme knobs select
ndelangen Jun 1, 2018
18ef6de
theme knobs text
ndelangen Jun 1, 2018
f877ac9
theme knobs date
ndelangen Jun 1, 2018
bd595a4
FIX knob object
ndelangen Jun 1, 2018
398bcf9
IMPROVE themes
ndelangen Jun 1, 2018
44a8c36
ADD displayNames to styled components to improve debugging & snapshots
ndelangen Jun 1, 2018
370b56f
REMOVE unneeded components
ndelangen Jun 1, 2018
1ded5f9
FIX unittest && FIX snapshots
ndelangen Jun 2, 2018
c49dff9
CLEANUP remove redundant dependencies
ndelangen Jun 2, 2018
9ea4117
REMOVE commented code
ndelangen Jun 2, 2018
44fb086
CLEANUP knobs panel
ndelangen Jun 2, 2018
a1bdf16
REFACTOR knobs PropField &7 REMOVE redundant component && ADD theme v…
ndelangen Jun 2, 2018
6d198dd
ADD validation styles to form input && ADD stories
ndelangen Jun 2, 2018
9c3788c
ADD theming to header
ndelangen Jun 2, 2018
0289456
ADD stories for bordered tabs
ndelangen Jun 2, 2018
53ba1cf
REFACTOR move ThemeProvider to ui root && ADD theming for modal
ndelangen Jun 2, 2018
f735795
FIX shortcurts help story
ndelangen Jun 2, 2018
28eb275
FIX correct prop to have defaultValue for Textarea story
ndelangen Jun 2, 2018
313c8f3
FIX storyshots & snapshots
ndelangen Jun 2, 2018
6ec6328
Merge branch 'master' into feature/theming
ndelangen Jun 2, 2018
128066d
theme searchbox && FIX unittest
ndelangen Jun 2, 2018
b022803
FIX linting
ndelangen Jun 2, 2018
d90aa8d
FIX linting
ndelangen Jun 2, 2018
1dba82b
ADD ability to set theme using setOptions
ndelangen Jun 3, 2018
677558c
Compose containers with withRef = false to fix react warnings
shilman Jun 3, 2018
a5d5567
Layout theme can be null so it shouldn't be a required prop
shilman Jun 3, 2018
c4cee7a
Render addon panels inside a fragment with key to remove warnings
shilman Jun 3, 2018
b2c3d90
Merge branch 'master' into feature/theming
ndelangen Jun 3, 2018
fe0311f
Fix broken snapshot tests for layout with required parameters
shilman Jun 3, 2018
9344955
Merge branch 'feature/theming' of github.com:storybooks/storybook int…
ndelangen Jun 4, 2018
959880e
CHANGE layoutMargin
ndelangen Jun 4, 2018
9d2a015
RENAME 'React Storybook' to 'Storybook'
ndelangen Jun 4, 2018
7d14ef9
ADD docs for theming
ndelangen Jun 4, 2018
97b8165
FIX alignment bug && FIX snapshot
ndelangen Jun 5, 2018
b3ca126
ADD explanation for knobstore's complex code && RENAME equal to deepE…
ndelangen Jun 6, 2018
691aece
FIX jest addon panel not rendering when switching panels
ndelangen Jun 6, 2018
2995b30
Improve writing-addons doc to mention theming & re-using components
ndelangen Jun 6, 2018
2991bc3
FIX minor typo
ndelangen Jun 6, 2018
a9cdac8
FIX barBorder in dark theme being barely visible
ndelangen Jun 6, 2018
18b5a43
Merge branch 'master' into feature/theming
ndelangen Jun 6, 2018
0e84684
FIX theme of shortcutModal & searchboxModal
ndelangen Jun 13, 2018
ed96067
Merge branch 'master' into feature/theming
ndelangen Jun 13, 2018
0a2a99c
CLEANUP
ndelangen Jun 13, 2018
62d1236
FIX snapshots
ndelangen Jun 13, 2018
61e0b4a
Merge branch 'master' into feature/theming
ndelangen Jun 21, 2018
c626f54
Merge branch 'master' into feature/theming
ndelangen Jun 21, 2018
79a5e34
REFACTOR Tabs to use children for data
ndelangen Jun 21, 2018
6db311d
FIX snapshots and Tabs implementation
ndelangen Jun 25, 2018
0dce8f9
Merge branch 'master' into feature/theming
Hypnosphi Jun 28, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion addons/a11y/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"@storybook/core-events": "4.0.0-alpha.8",
"axe-core": "^3.0.2",
"babel-runtime": "^6.26.0",
"emotion": "^9.1.3",
"global": "^4.3.2",
"prop-types": "^15.6.1",
"react-emotion": "^9.1.3"
Expand Down
100 changes: 64 additions & 36 deletions addons/a11y/src/components/Panel.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,93 @@
import React, { Component } from 'react';
import addons from '@storybook/addons';
import PropTypes from 'prop-types';

import styled from 'react-emotion';

import { CHECK_EVENT_ID } from '../shared';
import { STORY_RENDERED } from '@storybook/core-events';
import { ActionBar, ActionButton } from '@storybook/components';

import { CHECK_EVENT_ID, RERUN_EVENT_ID, REQUEST_CHECK_EVENT_ID } from '../shared';

import Tabs from './Tabs';
import Report from './Report';

const Passes = styled('span')({
color: '#0D6731',
});
const Passes = styled('span')(({ theme }) => ({
color: theme.successColor,
}));

const Violations = styled('span')({
color: '#AC2300',
});
const Violations = styled('span')(({ theme }) => ({
color: theme.failColor,
}));

class Panel extends Component {
constructor(props, ...args) {
super(props, ...args);
this.state = {
passes: [],
violations: [],
};
this.channel = addons.getChannel();

this.onUpdate = this.onUpdate.bind(this);
}
static propTypes = {
active: PropTypes.bool.isRequired,
channel: PropTypes.shape({
on: PropTypes.func,
emit: PropTypes.func,
removeListener: PropTypes.func,
}).isRequired,
};

state = {
passes: [],
violations: [],
};

componentDidMount() {
this.channel.on(CHECK_EVENT_ID, this.onUpdate);
this.props.channel.on(CHECK_EVENT_ID, this.onUpdate);
this.props.channel.on(STORY_RENDERED, this.requestCheck);
this.props.channel.on(RERUN_EVENT_ID, this.requestCheck);
}

componentDidUpdate(prevProps) {
if (!prevProps.active && this.props.active) {
this.requestCheck();
}
}

componentWillUnmount() {
this.channel.removeListener(CHECK_EVENT_ID, this.onUpdate);
this.props.channel.removeListener(CHECK_EVENT_ID, this.onUpdate);
this.props.channel.removeListener(STORY_RENDERED, this.requestCheck);
this.props.channel.removeListener(RERUN_EVENT_ID, this.requestCheck);
}

onUpdate({ passes, violations }) {
onUpdate = ({ passes, violations }) => {
this.setState({
passes,
violations,
});
}
};

requestCheck = () => {
if (this.props.active) {
this.props.channel.emit(REQUEST_CHECK_EVENT_ID);
}
};

render() {
const { passes, violations } = this.state;
const { active } = this.props;

return (
<Tabs
tabs={[
{
label: <Violations>{violations.length} Violations</Violations>,
panel: <Report passes={false} items={violations} empty="No a11y violations found." />,
},
{
label: <Passes>{passes.length} Passes</Passes>,
panel: <Report passes items={passes} empty="No a11y check passed" />,
},
]}
/>
);
return active ? (
<div>
<Tabs
tabs={[
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implement this as children?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well I could I'm unsure it would be an improvement. As each tab gets a active prop passed from the Tabs|TabState component.

Do you have an implementation in mind, that looks better than this?

Copy link
Member

@Hypnosphi Hypnosphi Jun 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would look better to me:

<Tabs>
  <Tab label={<Violations>{violations.length} Violations</Violations>}>
    <Report passes={false} items={violations} empty="No a11y violations found." />
  <Tab>
  <Tab label={<Passes>{passes.length} Passes</Passes>}>
    <Report passes items={passes} empty="No a11y check passed" />
  </Tab>
</Tabs>

To implement it, you can just change those lines to

{React.Children.map(children, (tab, index) => (
  <Item
    // eslint-disable-next-line react/no-array-index-key
    key={index}
    active={active === index ? true : undefined}
    onClick={() => this.onToggle(index)}
  >
    {tab.props.label}
  </Item>
))}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, we could also use some tab identifier other than index

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just pushed a refactor to make this component behave more like your proposal. Do you like it?

{
label: <Violations>{violations.length} Violations</Violations>,
panel: <Report passes={false} items={violations} empty="No a11y violations found." />,
},
{
label: <Passes>{passes.length} Passes</Passes>,
panel: <Report passes items={passes} empty="No a11y check passed" />,
},
]}
/>
<ActionBar>
<ActionButton onClick={this.requestCheck}>RERUN TEST</ActionButton>
</ActionBar>
</div>
) : null;
}
}

Expand Down
8 changes: 4 additions & 4 deletions addons/a11y/src/components/Report/Info.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ import PropTypes from 'prop-types';

import styled from 'react-emotion';

const Wrapper = styled('div')({
backgroundColor: 'rgb(234, 234, 234)',
const Wrapper = styled('div')(({ theme }) => ({
backgroundColor: theme.barFill,
padding: '12px',
marginBottom: '10px',
});
}));
const Help = styled('p')({
margin: '0 0 12px',
});
const Link = styled('a')({
marginTop: '12px',
textDecoration: 'underline',
color: 'rgb(130, 130, 130)',
color: 'inherit',
display: 'block',
});

Expand Down
19 changes: 14 additions & 5 deletions addons/a11y/src/components/Report/Item.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,28 @@ import Info from './Info';
import Tags from './Tags';
import Elements from './Elements';

const Wrapper = styled('div')({
const Wrapper = styled('div')(({ theme }) => ({
padding: '0 14px',
cursor: 'pointer',
borderBottom: '1px solid rgb(234, 234, 234)',
});
borderBottom: theme.mainBorder,
}));

const HeaderBar = styled('button')({
const HeaderBar = styled('button')(({ theme }) => ({
padding: '12px 0px',
display: 'block',
width: '100%',
border: 0,
background: 'none',
});
color: 'inherit',

borderTop: '3px solid transparent',
borderBottom: '3px solid transparent',

'&:focus': {
outline: '0 none',
borderBottom: `3px solid ${theme.highlightColor}`,
},
}));

class Item extends Component {
static propTypes = {
Expand Down
17 changes: 0 additions & 17 deletions addons/a11y/src/components/Report/RerunButton.js

This file was deleted.

10 changes: 4 additions & 6 deletions addons/a11y/src/components/Report/Tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ const Wrapper = styled('div')({
margin: '12px 0',
});

const Item = styled('div')({
const Item = styled('div')(({ theme }) => ({
margin: '0 6px',
padding: '5px',
border: '1px solid rgb(234, 234, 234)',
borderRadius: '2px',
color: 'rgb(130, 130, 130)',
fontSize: '12px',
});
border: theme.mainBorder,
borderRadius: theme.mainBorderRadius,
}));

function Tags({ tags }) {
return <Wrapper>{tags.map(tag => <Item key={tag}>{tag}</Item>)}</Wrapper>;
Expand Down
10 changes: 0 additions & 10 deletions addons/a11y/src/components/Report/index.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
import React from 'react';
import PropTypes from 'prop-types';
import addons from '@storybook/addons';
import { Placeholder } from '@storybook/components';

import { RERUN_EVENT_ID } from '../../shared';

import RerunButton from './RerunButton';
import Item from './Item';

function onRerunClick() {
const channel = addons.getChannel();
channel.emit(RERUN_EVENT_ID);
}

const Report = ({ items, empty, passes }) => (
<div>
{items.length ? (
items.map(item => <Item passes={passes} item={item} key={item.id} />)
) : (
<Placeholder>{empty}</Placeholder>
)}
<RerunButton onClick={onRerunClick}>Re-run tests</RerunButton>
</div>
);

Expand Down
20 changes: 13 additions & 7 deletions addons/a11y/src/components/Tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import styled from 'react-emotion';
const Container = styled('div')({
width: '100%',
position: 'relative',
minHeight: '100%',
});

const List = styled('div')({
borderBottom: '1px solid rgb(234, 234, 234)',
const List = styled('div')(({ theme }) => ({
borderBottom: theme.mainBorder,
flexWrap: 'wrap',
display: 'flex',
});
}));

const Item = styled('button')(
({ active }) =>
Expand All @@ -22,9 +23,7 @@ const Item = styled('button')(
fontWeight: 600,
}
: {},
{
color: 'rgb(68, 68, 68)',
fontSize: '11px',
({ theme }) => ({
textDecoration: 'none',
textTransform: 'uppercase',
padding: '10px 15px',
Expand All @@ -33,9 +32,16 @@ const Item = styled('button')(
fontWeight: 500,
opacity: 0.7,
border: 'none',
borderTop: '3px solid transparent',
borderBottom: '3px solid transparent',
background: 'none',
flex: 1,
}

'&:focus': {
outline: '0 none',
borderBottom: `3px solid ${theme.highlightColor}`,
},
})
);

class Tabs extends Component {
Expand Down
9 changes: 4 additions & 5 deletions addons/a11y/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import addons from '@storybook/addons';
import Events from '@storybook/core-events';
import { logger } from '@storybook/client-logger';

import { CHECK_EVENT_ID, RERUN_EVENT_ID } from './shared';
import { CHECK_EVENT_ID, REQUEST_CHECK_EVENT_ID } from './shared';

let axeOptions = {};

Expand All @@ -23,11 +23,10 @@ const runA11yCheck = () => {

const a11ySubscription = () => {
const channel = addons.getChannel();
channel.on(Events.STORY_RENDERED, runA11yCheck);
channel.on(RERUN_EVENT_ID, runA11yCheck);
channel.on(REQUEST_CHECK_EVENT_ID, runA11yCheck);

return () => {
channel.removeListener(Events.STORY_RENDERED, runA11yCheck);
channel.removeListener(RERUN_EVENT_ID, runA11yCheck);
channel.removeListener(REQUEST_CHECK_EVENT_ID, runA11yCheck);
};
};

Expand Down
8 changes: 4 additions & 4 deletions addons/a11y/src/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import Panel from './components/Panel';
import { ADDON_ID, PANEL_ID } from './shared';

function init() {
addons.register(ADDON_ID, () => {
addons.register(ADDON_ID, api => {
const channel = addons.getChannel();
addons.addPanel(PANEL_ID, {
title: 'Accessibility',
render() {
return <Panel />;
},
// eslint-disable-next-line react/prop-types
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally not a huge fan of these. Is there a reason?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm passing down a function, not a component..

Or is the comment regarding the switched based on active?

render: ({ active }) => <Panel channel={channel} api={api} active={active} />,
});
});
}
Expand Down
3 changes: 2 additions & 1 deletion addons/a11y/src/shared/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ const ADDON_ID = '@storybook/addon-a11y';
const PANEL_ID = `${ADDON_ID}/panel`;
const CHECK_EVENT_ID = `${ADDON_ID}/check`;
const RERUN_EVENT_ID = `${ADDON_ID}/rerun`;
const REQUEST_CHECK_EVENT_ID = `${ADDON_ID}/request-check`;

export { ADDON_ID, PANEL_ID, CHECK_EVENT_ID, RERUN_EVENT_ID };
export { ADDON_ID, PANEL_ID, CHECK_EVENT_ID, RERUN_EVENT_ID, REQUEST_CHECK_EVENT_ID };
2 changes: 1 addition & 1 deletion addons/actions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@storybook/core-events": "4.0.0-alpha.8",
"babel-runtime": "^6.26.0",
"deep-equal": "^1.0.1",
"emotion": "^9.1.3",
"emotion-theming": "^9.1.2",
"global": "^4.3.2",
"lodash.isequal": "^4.5.0",
"make-error": "^1.3.4",
Expand Down