Skip to content

Commit 6d74961

Browse files
committed
Start integrating accessibility changes to storybook feature
1 parent 148ab78 commit 6d74961

File tree

9 files changed

+40
-77
lines changed

9 files changed

+40
-77
lines changed

Diff for: client/common/Button.jsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,11 @@ const StyledIconButton = styled.button`
153153
const Button = ({
154154
children, href, iconAfterName, iconBeforeName, kind, label, to, type, ...props
155155
}) => {
156-
const iconAfter = iconAfterName && <Icon name={iconAfterName} />;
157-
const iconBefore = iconBeforeName && <Icon name={iconBeforeName} />;
156+
const IconAfter = Icon[iconAfterName];
157+
const IconBefore = Icon[iconBeforeName];
158158
const hasChildren = React.Children.count(children) > 0;
159159

160-
const content = <>{iconBefore}{hasChildren && <span>{children}</span>}{iconAfter}</>;
160+
const content = <>{IconBefore}{hasChildren && <span>{children}</span>}{IconAfter}</>;
161161

162162
let StyledComponent = StyledButton;
163163

@@ -190,7 +190,7 @@ Button.defaultProps = {
190190
type: 'button',
191191
};
192192

193-
Button.iconNames = Icon.names;
193+
Button.iconNames = Object.keys(Icon);
194194
Button.kinds = kinds;
195195

196196
Button.propTypes = {

Diff for: client/common/Button.stories.jsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@ export const ReactRouterLink = () => (
3636
);
3737

3838
export const ButtonWithIconBefore = () => (
39-
<Button iconBeforeName={Button.iconNames.github}>Create</Button>
39+
<Button iconBeforeName={Button.iconNames.Github}>Create</Button>
4040
);
4141

4242
export const ButtonWithIconAfter = () => (
43-
<Button iconAfterName={Button.iconNames.github}>Create</Button>
43+
<Button iconAfterName={Button.iconNames.Github}>Create</Button>
4444
);
4545

4646
export const InlineButtonWithIconAfter = () => (
47-
<Button kind={Button.kinds.inline} iconAfterName={Button.iconNames.sortArrowDown}>File name</Button>
47+
<Button kind={Button.kinds.inline} iconAfterName={Button.iconNames.SortArrowDown}>File name</Button>
4848
);
4949

5050
export const InlineIconOnlyButton = () => (
51-
<Button kind={Button.kinds.inline} iconAfterName={Button.iconNames.plus} label="Add to collection" />
51+
<Button kind={Button.kinds.inline} iconAfterName={Button.iconNames.Plus} label="Add to collection" />
5252
);

Diff for: client/common/Icon.jsx

+20-43
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,25 @@
1-
/* eslint-disable global-require */
2-
import InlineSVG from 'react-inlinesvg';
31
import PropTypes from 'prop-types';
4-
import React from 'react';
5-
import lodash from 'lodash';
6-
import styled from 'styled-components';
72

8-
const icons = {
9-
sortArrowUp: require('../images/sort-arrow-up.svg'),
10-
sortArrowDown: require('../images/sort-arrow-down.svg'),
11-
github: require('../images/github.svg'),
12-
google: require('../images/google.svg'),
13-
plus: require('../images/plus-icon.svg'),
14-
close: require('../images/close.svg'),
3+
import SortArrowUp from '../images/sort-arrow-up.svg';
4+
import SortArrowDown from '../images/sort-arrow-down.svg';
5+
import Github from '../images/github.svg';
6+
import Google from '../images/google.svg';
7+
import Plus from '../images/plus-icon.svg';
8+
import Close from '../images/close.svg';
9+
10+
// https://www.scottohara.me/blog/2019/05/22/contextual-images-svgs-and-a11y.html
11+
// could do something like, if there's an aria-label prop, give it role="img" focusable="false"
12+
// otherwise, give it aria-hidden="true" focusable="false"
13+
14+
const Icons = {
15+
SortArrowUp,
16+
SortArrowDown,
17+
Github,
18+
Google,
19+
Plus,
20+
Close
1521
};
1622

17-
/*
18-
names will be an mirror-object of icon names:
19-
{
20-
github: 'github',
21-
...
22-
}
23-
*/
24-
const names = lodash.mapValues(icons, (value, key) => key);
23+
export default Icons;
2524

26-
export const ValidIconNameType = PropTypes.oneOf(Object.keys(names));
27-
28-
const StyledInlineSVG = styled(InlineSVG)`
29-
> svg {
30-
width: 100%;
31-
height: 100%;
32-
}
33-
`;
34-
35-
function Icon({ name, ...props }) {
36-
return (
37-
<StyledInlineSVG src={icons[name]} {...props} />
38-
);
39-
}
40-
41-
42-
Icon.names = names;
43-
44-
Icon.propTypes = {
45-
name: ValidIconNameType.isRequired
46-
};
47-
48-
export default Icon;
25+
export const ValidIconNameType = PropTypes.oneOf(Object.keys(Icons));

Diff for: client/common/Icon.stories.jsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ export default {
99
};
1010

1111
export const AllIcons = () => {
12-
const firstIconName = Object.keys(Icon.names)[0];
12+
const names = Object.keys(Icon);
1313

14+
const SelectedIcon = Icon[select('name', names, names[0])];
1415
return (
15-
<Icon name={select('name', Icon.names, firstIconName)} />
16+
<SelectedIcon />
1617
);
1718
};

Diff for: client/modules/User/components/APIKeyForm.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class APIKeyForm extends React.Component {
8080
value={this.state.keyLabel}
8181
/>
8282
<Button
83-
iconBeforeName={Button.iconNames.plus}
83+
iconBeforeName={Button.iconNames.Plus}
8484
disabled={this.state.keyLabel === ''}
8585
type="submit"
8686
label="Create new key"

Diff for: client/modules/User/components/Collection.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const ShareURL = ({ value }) => {
5353
return (
5454
<div className="collection-share" ref={node}>
5555
<Button
56-
iconAfterName={Button.iconNames.sortArrowDown}
56+
iconAfterName={Button.iconNames.SortArrowDown}
5757
onClick={() => setShowURL(!showURL)}
5858
>Share
5959
</Button>

Diff for: client/modules/User/components/SocialAuthButton.jsx

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ import { remSize } from '../../../theme';
77
import Button from '../../../common/Button';
88

99
const authUrls = {
10-
github: '/auth-github',
11-
google: '/auth/google/'
10+
Github: '/auth-github',
11+
Google: '/auth/google/'
1212
};
1313

1414
const labels = {
15-
github: 'Login with GitHub',
16-
google: 'Login with Google'
15+
Github: 'Login with GitHub',
16+
Google: 'Login with Google'
1717
};
1818

1919
const services = {
20-
github: 'github',
21-
google: 'google'
20+
Github: 'github',
21+
Google: 'google'
2222
};
2323

2424
const StyledButton = styled(Button)`
@@ -39,7 +39,7 @@ function SocialAuthButton({ service }) {
3939
SocialAuthButton.services = services;
4040

4141
SocialAuthButton.propTypes = {
42-
service: PropTypes.oneOf(['github', 'google']).isRequired
42+
service: PropTypes.oneOf(['Github', 'Google']).isRequired
4343
};
4444

4545
export default SocialAuthButton;

Diff for: package-lock.json

-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@
178178
"react-dom": "^16.12.0",
179179
"react-helmet": "^5.1.3",
180180
"react-hot-loader": "^4.12.19",
181-
"react-inlinesvg": "^1.2.0",
182181
"react-redux": "^5.1.2",
183182
"react-router": "^3.2.5",
184183
"react-split-pane": "^0.1.89",

0 commit comments

Comments
 (0)