Skip to content

Commit bda0e63

Browse files
committed
Rename 'genericButton' -> 'controlButton'
Also avoided variable name negation by renaming its argument 'notMinimal' -> 'minimal'. Refactor ReplControl to list declarations in decreasing levels of abstraction. (addresses review in PR #35)
1 parent 5c9fa5e commit bda0e63

File tree

1 file changed

+32
-34
lines changed

1 file changed

+32
-34
lines changed
Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import * as React from 'react'
2-
31
import { Button, IconName, Intent } from '@blueprintjs/core'
2+
import * as React from 'react'
43

54
import { sourceChapters } from '../../reducers/states'
65

@@ -14,48 +13,47 @@ export interface IReplControlProps {
1413
handleChapterSelect: (e: React.ChangeEvent<HTMLSelectElement>) => void
1514
}
1615

17-
const chapterSelect = (handleSelect = (e: React.ChangeEvent<HTMLSelectElement>) => {}) => (
18-
<div className="pt-select pt-select">
19-
<select defaultValue={sourceChapters.slice(-1)[0].toString()} onChange={handleSelect}>
20-
{sourceChapters.map(chap => (
21-
<option key={chap} value={chap}>
22-
{`Source \xa7${chap}`}
23-
</option>
24-
))}
25-
</select>
26-
</div>
27-
)
28-
2916
class ReplControl extends React.Component<IReplControlProps, {}> {
3017
public render() {
31-
const genericButton = (
32-
label: string,
33-
icon: IconName,
34-
handleClick = () => {},
35-
intent = Intent.NONE,
36-
notMinimal = false
37-
) => (
38-
<Button
39-
onClick={handleClick}
40-
className={(notMinimal ? '' : 'pt-minimal') + ' col-xs-12'}
41-
intent={intent}
42-
icon={icon}
43-
>
44-
{label}
45-
</Button>
46-
)
47-
const evalButton = genericButton('', 'code', this.props.handleReplEval)
48-
const clearButton = genericButton('', 'remove', this.props.handleReplOutputClear)
4918
return (
5019
<div className="row end-xs">
5120
<div className="pt-control-group pt-fill">
5221
{chapterSelect(this.props.handleChapterSelect)}
53-
{evalButton}
54-
{clearButton}
22+
{controlButton('', 'code', this.props.handleReplEval)}
23+
{controlButton('', 'remove', this.props.handleReplOutputClear)}
5524
</div>
5625
</div>
5726
)
5827
}
5928
}
6029

30+
const controlButton = (
31+
label: string,
32+
icon: IconName,
33+
handleClick = () => {},
34+
intent = Intent.NONE,
35+
minimal = true
36+
) => (
37+
<Button
38+
onClick={handleClick}
39+
className={(minimal ? 'pt-minimal' : '') + ' col-xs-12'}
40+
intent={intent}
41+
icon={icon}
42+
>
43+
{label}
44+
</Button>
45+
)
46+
47+
const chapterSelect = (handleSelect = (e: React.ChangeEvent<HTMLSelectElement>) => {}) => (
48+
<div className="pt-select pt-select">
49+
<select defaultValue={sourceChapters.slice(-1)[0].toString()} onChange={handleSelect}>
50+
{sourceChapters.map(chap => (
51+
<option key={chap} value={chap}>
52+
{`Source \xa7${chap}`}
53+
</option>
54+
))}
55+
</select>
56+
</div>
57+
)
58+
6159
export default ReplControl

0 commit comments

Comments
 (0)