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

Fixed Colorblindness Emulation #6297

Merged
merged 1 commit into from
Mar 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions addons/a11y/src/components/ColorBlindness.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ import { Icons, IconButton, WithTooltip, TooltipLinkList } from '@storybook/comp

const getIframe = memoize(1)(() => document.getElementById('storybook-preview-iframe'));

const getFilter = (filter: string | null) => {
if (filter === null) {
Copy link
Member

Choose a reason for hiding this comment

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

is !filter better?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It could, but I wanted to be "strict" and consistent, since the reset is this.setFilter(null); and there's a similar check if (filter !== null) {

return 'none';
}
if (filter === 'mono') {
return 'grayscale(100%)';
}
return `url('#${filter}')`;
};

const ColorIcon = styled.span(
{
background: 'linear-gradient(to right, #F44336, #FF9800, #FFEB3B, #8BC34A, #2196F3, #9C27B0)',
Expand All @@ -17,7 +27,7 @@ const ColorIcon = styled.span(
width: '1rem',
},
({ filter }: { filter: string | null }) => ({
filter: filter === 'mono' ? 'grayscale(100%)' : `url('#${filter}')`,
filter: getFilter(filter),
}),
({ theme }) => ({
boxShadow: `${theme.appBorderColor} 0 0 0 1px inset`,
Expand All @@ -42,7 +52,7 @@ export class ColorBlindness extends Component<ColorBlindnessProps, ColorBlindnes
const iframe = getIframe();

if (iframe) {
iframe.style.filter = filter === 'mono' ? 'grayscale(100%)' : `url('#${filter}')`;
iframe.style.filter = getFilter(filter);
this.setState({
expanded: false,
filter,
Expand Down Expand Up @@ -78,6 +88,7 @@ export class ColorBlindness extends Component<ColorBlindnessProps, ColorBlindnes
this.setFilter(i);
},
right: <ColorIcon filter={i} />,
active: filter === i,
}));

if (filter !== null) {
Expand All @@ -89,6 +100,7 @@ export class ColorBlindness extends Component<ColorBlindnessProps, ColorBlindnes
this.setFilter(null);
},
right: undefined,
active: false,
},
...colorList,
];
Expand Down
6 changes: 5 additions & 1 deletion addons/a11y/src/register.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import { A11YPanel } from './components/A11YPanel';
import { addons, types } from '@storybook/addons';

const Hidden = styled.div(() => ({
display: 'none',
'&, & svg': {
position: 'absolute',
width: 0,
height: 0,
},
}));

const PreviewWrapper: FunctionComponent<{}> = p => (
Expand Down