Simplify usage of radio buttons

Allowing for the entire component to be disabled rather than specifying
on a button basis
pull/10616/head
Alex P 2018-06-29 18:29:42 -07:00
parent bce19414de
commit 2f1363d8ed
2 changed files with 24 additions and 24 deletions

View File

@ -9,17 +9,13 @@ import {
BUTTON_SHAPES, BUTTON_SHAPES,
} from 'src/reusable_ui/constants' } from 'src/reusable_ui/constants'
export interface RadioButton {
text: string
disabled?: boolean
}
interface Props { interface Props {
color?: ComponentColor color?: ComponentColor
size?: ComponentSize size?: ComponentSize
shape?: ButtonShape shape?: ButtonShape
buttons: RadioButton[] disabled?: boolean
activeButton: RadioButton buttons: string[]
activeButton: string
onChange: (RadioButton) => void onChange: (RadioButton) => void
} }
@ -28,6 +24,7 @@ class RadioButtons extends Component<Props> {
color: COMPONENT_COLORS.default, color: COMPONENT_COLORS.default,
size: COMPONENT_SIZES.small, size: COMPONENT_SIZES.small,
shape: BUTTON_SHAPES.none, shape: BUTTON_SHAPES.none,
disabled: false,
} }
public render() { public render() {
@ -39,11 +36,11 @@ class RadioButtons extends Component<Props> {
return buttons.map(button => ( return buttons.map(button => (
<div <div
key={button.text} key={button}
className={this.buttonClassName(button)} className={this.buttonClassName(button)}
onClick={this.handleButtonClick(button)} onClick={this.handleButtonClick(button)}
> >
{button.text} {button}
</div> </div>
)) ))
} }
@ -60,18 +57,17 @@ class RadioButtons extends Component<Props> {
) )
} }
private buttonClassName = (button: RadioButton): string => { private buttonClassName = (button: string): string => {
const {activeButton} = this.props const {activeButton} = this.props
return classnames('radio-button', { return classnames('radio-button', {
disabled: button.disabled,
active: _.isEqual(button, activeButton), active: _.isEqual(button, activeButton),
}) })
} }
private handleButtonClick = (button: RadioButton) => () => { private handleButtonClick = (button: string) => () => {
const {onChange} = this.props const {onChange, disabled} = this.props
if (button.disabled) { if (disabled) {
return return
} }

View File

@ -34,16 +34,6 @@
&.active { &.active {
background-color: $g5-pepper; background-color: $g5-pepper;
} }
&.disabled,
&.disabled:hover {
background-color: $g2-kevlar;
font-style: italic;
color: $g7-graphite;
}
&.disabled.active {
background-color: $g5-pepper;
color: $g10-wolf;
}
} }
/* Size Modifiers */ /* Size Modifiers */
@ -151,6 +141,20 @@
} }
} }
/* Disabled State */
.radio-buttons.disabled {
.radio-button,
.radio-button:hover {
background-color: $g2-kevlar;
font-style: italic;
color: $g7-graphite;
}
.radio-button.active {
background-color: $g5-pepper;
color: $g10-wolf;
}
}
/* /*
Todo: Replace all instances of these styles with new pattern then Todo: Replace all instances of these styles with new pattern then