-
Notifications
You must be signed in to change notification settings - Fork 317
/
Copy pathIconsExample.js
96 lines (87 loc) · 3.26 KB
/
IconsExample.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// @flow
import * as React from 'react';
import uniqueId from 'lodash/uniqueId';
import classNames from 'classnames';
type Props = {
icons: Array<{
component: React.ComponentType<{}>,
name: string,
propsDocumentation: React.ComponentType<{}>,
}>,
};
type State = {
darkBackgroundEnabled: boolean,
expandedPropsComponent: string,
};
class IconsExample extends React.Component<Props, State> {
constructor() {
super();
this.state = {
darkBackgroundEnabled: false,
expandedPropsComponent: '',
};
}
darkToggleId = uniqueId('dark-toggle-');
togglePropsSection = (iconName: string) => {
if (iconName === this.state.expandedPropsComponent) {
this.setState({ expandedPropsComponent: '' });
} else {
this.setState({ expandedPropsComponent: iconName });
}
};
renderPropsSection = (iconName: string, PropsComponent: React.ComponentType<{}>) => {
const isExpanded = iconName === this.state.expandedPropsComponent;
if (!PropsComponent) {
return null;
}
return (
<div className="props-section">
{isExpanded && (
<code className="props-code">
<PropsComponent />
</code>
)}
<button type="button" className="btn-toggle-props" onClick={() => this.togglePropsSection(iconName)}>
{isExpanded ? 'Hide Props' : 'View Props'}
</button>
</div>
);
};
render() {
const { icons } = this.props;
return (
<div className="icons-example">
<label htmlFor={this.darkToggleId}>
<input
className="dark-toggle"
type="checkbox"
id={this.darkToggleId}
value={this.state.darkBackgroundEnabled}
onChange={() => {
this.setState(state => {
return { darkBackgroundEnabled: !state.darkBackgroundEnabled };
});
}}
/>
Enable dark background
</label>
<div className={classNames('icon-set', { dark: this.state.darkBackgroundEnabled })}>
{icons.map(icon => {
const Component = icon.component;
const PropsComponent = icon.propsDocumentation;
const isExpanded = icon.name === this.state.expandedPropsComponent;
return (
<div className={classNames('icon', { 'is-expanded': isExpanded })} key={icon.name}>
<Component />
{/* eslint-disable-next-line jsx-a11y/label-has-for */}
<label className="icon-label">{icon.name}</label>
{this.renderPropsSection(icon.name, PropsComponent)}
</div>
);
})}
</div>
</div>
);
}
}
export default IconsExample;