Skip to content

Commit f79b234

Browse files
committed
Reduce some duplication by introducing Button component
1 parent c4008f2 commit f79b234

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

src/js/Button.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import PropTypes from 'prop-types';
2+
import React from 'react';
3+
4+
class Button extends React.PureComponent {
5+
static propTypes = {
6+
children: PropTypes.node.isRequired,
7+
title: PropTypes.string.isRequired,
8+
};
9+
10+
render() {
11+
const { children, title, ...props } = this.props;
12+
13+
return (
14+
<button
15+
aria-label={title}
16+
title={title}
17+
type="button"
18+
{...props}
19+
>
20+
{children}
21+
</button>
22+
);
23+
}
24+
}
25+
26+
export default Button;

src/js/CheckboxTree.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import PropTypes from 'prop-types';
44
import React from 'react';
55
import nanoid from 'nanoid';
66

7+
import Button from './Button';
78
import TreeNode from './TreeNode';
89
import iconsShape from './iconsShape';
910
import listShape from './listShape';
@@ -332,24 +333,20 @@ class CheckboxTree extends React.Component {
332333

333334
return (
334335
<div className="rct-options">
335-
<button
336-
aria-label="Expand all"
336+
<Button
337337
className="rct-option rct-option-expand-all"
338338
title="Expand all"
339-
type="button"
340339
onClick={this.onExpandAll}
341340
>
342341
{expandAll}
343-
</button>
344-
<button
345-
aria-label="Expand all"
342+
</Button>
343+
<Button
346344
className="rct-option rct-option-collapse-all"
347345
title="Collapse all"
348-
type="button"
349346
onClick={this.onCollapseAll}
350347
>
351348
{collapseAll}
352-
</button>
349+
</Button>
353350
</div>
354351
);
355352
}

src/js/TreeNode.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import classNames from 'classnames';
22
import PropTypes from 'prop-types';
33
import React from 'react';
44

5+
import Button from './Button';
56
import NativeCheckbox from './NativeCheckbox';
67
import iconsShape from './iconsShape';
78
import nodeShape from './nodeShape';
@@ -120,16 +121,14 @@ class TreeNode extends React.Component {
120121
}
121122

122123
return (
123-
<button
124-
aria-label="Toggle"
124+
<Button
125125
className="rct-collapse rct-collapse-btn"
126126
disabled={expandDisabled}
127127
title="Toggle"
128-
type="button"
129128
onClick={this.onExpand}
130129
>
131130
{this.renderCollapseIcon()}
132-
</button>
131+
</Button>
133132
);
134133
}
135134

0 commit comments

Comments
 (0)