Start integrating accessibility changes to storybook feature

This commit is contained in:
Cassie Tarakajian 2020-05-09 00:52:48 -04:00
parent 148ab78466
commit 6d749615cc
9 changed files with 40 additions and 77 deletions

View file

@ -153,11 +153,11 @@ const StyledIconButton = styled.button`
const Button = ({ const Button = ({
children, href, iconAfterName, iconBeforeName, kind, label, to, type, ...props children, href, iconAfterName, iconBeforeName, kind, label, to, type, ...props
}) => { }) => {
const iconAfter = iconAfterName && <Icon name={iconAfterName} />; const IconAfter = Icon[iconAfterName];
const iconBefore = iconBeforeName && <Icon name={iconBeforeName} />; const IconBefore = Icon[iconBeforeName];
const hasChildren = React.Children.count(children) > 0; const hasChildren = React.Children.count(children) > 0;
const content = <>{iconBefore}{hasChildren && <span>{children}</span>}{iconAfter}</>; const content = <>{IconBefore}{hasChildren && <span>{children}</span>}{IconAfter}</>;
let StyledComponent = StyledButton; let StyledComponent = StyledButton;
@ -190,7 +190,7 @@ Button.defaultProps = {
type: 'button', type: 'button',
}; };
Button.iconNames = Icon.names; Button.iconNames = Object.keys(Icon);
Button.kinds = kinds; Button.kinds = kinds;
Button.propTypes = { Button.propTypes = {

View file

@ -36,17 +36,17 @@ export const ReactRouterLink = () => (
); );
export const ButtonWithIconBefore = () => ( export const ButtonWithIconBefore = () => (
<Button iconBeforeName={Button.iconNames.github}>Create</Button> <Button iconBeforeName={Button.iconNames.Github}>Create</Button>
); );
export const ButtonWithIconAfter = () => ( export const ButtonWithIconAfter = () => (
<Button iconAfterName={Button.iconNames.github}>Create</Button> <Button iconAfterName={Button.iconNames.Github}>Create</Button>
); );
export const InlineButtonWithIconAfter = () => ( export const InlineButtonWithIconAfter = () => (
<Button kind={Button.kinds.inline} iconAfterName={Button.iconNames.sortArrowDown}>File name</Button> <Button kind={Button.kinds.inline} iconAfterName={Button.iconNames.SortArrowDown}>File name</Button>
); );
export const InlineIconOnlyButton = () => ( export const InlineIconOnlyButton = () => (
<Button kind={Button.kinds.inline} iconAfterName={Button.iconNames.plus} label="Add to collection" /> <Button kind={Button.kinds.inline} iconAfterName={Button.iconNames.Plus} label="Add to collection" />
); );

View file

@ -1,48 +1,25 @@
/* eslint-disable global-require */
import InlineSVG from 'react-inlinesvg';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import React from 'react';
import lodash from 'lodash';
import styled from 'styled-components';
const icons = { import SortArrowUp from '../images/sort-arrow-up.svg';
sortArrowUp: require('../images/sort-arrow-up.svg'), import SortArrowDown from '../images/sort-arrow-down.svg';
sortArrowDown: require('../images/sort-arrow-down.svg'), import Github from '../images/github.svg';
github: require('../images/github.svg'), import Google from '../images/google.svg';
google: require('../images/google.svg'), import Plus from '../images/plus-icon.svg';
plus: require('../images/plus-icon.svg'), import Close from '../images/close.svg';
close: require('../images/close.svg'),
// https://www.scottohara.me/blog/2019/05/22/contextual-images-svgs-and-a11y.html
// could do something like, if there's an aria-label prop, give it role="img" focusable="false"
// otherwise, give it aria-hidden="true" focusable="false"
const Icons = {
SortArrowUp,
SortArrowDown,
Github,
Google,
Plus,
Close
}; };
/* export default Icons;
names will be an mirror-object of icon names:
{
github: 'github',
...
}
*/
const names = lodash.mapValues(icons, (value, key) => key);
export const ValidIconNameType = PropTypes.oneOf(Object.keys(names)); export const ValidIconNameType = PropTypes.oneOf(Object.keys(Icons));
const StyledInlineSVG = styled(InlineSVG)`
> svg {
width: 100%;
height: 100%;
}
`;
function Icon({ name, ...props }) {
return (
<StyledInlineSVG src={icons[name]} {...props} />
);
}
Icon.names = names;
Icon.propTypes = {
name: ValidIconNameType.isRequired
};
export default Icon;

View file

@ -9,9 +9,10 @@ export default {
}; };
export const AllIcons = () => { export const AllIcons = () => {
const firstIconName = Object.keys(Icon.names)[0]; const names = Object.keys(Icon);
const SelectedIcon = Icon[select('name', names, names[0])];
return ( return (
<Icon name={select('name', Icon.names, firstIconName)} /> <SelectedIcon />
); );
}; };

View file

@ -80,7 +80,7 @@ class APIKeyForm extends React.Component {
value={this.state.keyLabel} value={this.state.keyLabel}
/> />
<Button <Button
iconBeforeName={Button.iconNames.plus} iconBeforeName={Button.iconNames.Plus}
disabled={this.state.keyLabel === ''} disabled={this.state.keyLabel === ''}
type="submit" type="submit"
label="Create new key" label="Create new key"

View file

@ -53,7 +53,7 @@ const ShareURL = ({ value }) => {
return ( return (
<div className="collection-share" ref={node}> <div className="collection-share" ref={node}>
<Button <Button
iconAfterName={Button.iconNames.sortArrowDown} iconAfterName={Button.iconNames.SortArrowDown}
onClick={() => setShowURL(!showURL)} onClick={() => setShowURL(!showURL)}
>Share >Share
</Button> </Button>

View file

@ -7,18 +7,18 @@ import { remSize } from '../../../theme';
import Button from '../../../common/Button'; import Button from '../../../common/Button';
const authUrls = { const authUrls = {
github: '/auth-github', Github: '/auth-github',
google: '/auth/google/' Google: '/auth/google/'
}; };
const labels = { const labels = {
github: 'Login with GitHub', Github: 'Login with GitHub',
google: 'Login with Google' Google: 'Login with Google'
}; };
const services = { const services = {
github: 'github', Github: 'github',
google: 'google' Google: 'google'
}; };
const StyledButton = styled(Button)` const StyledButton = styled(Button)`
@ -39,7 +39,7 @@ function SocialAuthButton({ service }) {
SocialAuthButton.services = services; SocialAuthButton.services = services;
SocialAuthButton.propTypes = { SocialAuthButton.propTypes = {
service: PropTypes.oneOf(['github', 'google']).isRequired service: PropTypes.oneOf(['Github', 'Google']).isRequired
}; };
export default SocialAuthButton; export default SocialAuthButton;

14
package-lock.json generated
View file

@ -26924,11 +26924,6 @@
"use-sidecar": "^1.0.1" "use-sidecar": "^1.0.1"
} }
}, },
"react-from-dom": {
"version": "0.3.1",
"resolved": "https://registry.npmjs.org/react-from-dom/-/react-from-dom-0.3.1.tgz",
"integrity": "sha512-PeNBa8iuzoD7qHA9O7YpGnXFvC+XFFwStmFh2/r2zJAvEIaRg6EwOj+EPcDIFwyYBhqPIItxIx/dGdeWiFivjQ=="
},
"react-helmet": { "react-helmet": {
"version": "5.2.1", "version": "5.2.1",
"resolved": "https://registry.npmjs.org/react-helmet/-/react-helmet-5.2.1.tgz", "resolved": "https://registry.npmjs.org/react-helmet/-/react-helmet-5.2.1.tgz",
@ -27015,15 +27010,6 @@
"prop-types": "^15.6.1" "prop-types": "^15.6.1"
} }
}, },
"react-inlinesvg": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/react-inlinesvg/-/react-inlinesvg-1.2.0.tgz",
"integrity": "sha512-IsznU+UzpUwDGzBWbf0bfSRA5Jbqz87xeoqLM/nSIDPkoHksInF1wCGybTSn4sIui+30TqboRQP1wAelNTkdog==",
"requires": {
"exenv": "^1.2.2",
"react-from-dom": "^0.3.0"
}
},
"react-input-autosize": { "react-input-autosize": {
"version": "2.2.2", "version": "2.2.2",
"resolved": "https://registry.npmjs.org/react-input-autosize/-/react-input-autosize-2.2.2.tgz", "resolved": "https://registry.npmjs.org/react-input-autosize/-/react-input-autosize-2.2.2.tgz",

View file

@ -178,7 +178,6 @@
"react-dom": "^16.12.0", "react-dom": "^16.12.0",
"react-helmet": "^5.1.3", "react-helmet": "^5.1.3",
"react-hot-loader": "^4.12.19", "react-hot-loader": "^4.12.19",
"react-inlinesvg": "^1.2.0",
"react-redux": "^5.1.2", "react-redux": "^5.1.2",
"react-router": "^3.2.5", "react-router": "^3.2.5",
"react-split-pane": "^0.1.89", "react-split-pane": "^0.1.89",