Skip to content

Commit

Permalink
feat(global): add missing disabled states
Browse files Browse the repository at this point in the history
  • Loading branch information
zouxuoz committed May 30, 2019
1 parent 331da97 commit 0ace122
Show file tree
Hide file tree
Showing 22 changed files with 45 additions and 8 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions e2e/__tests__/radio.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { baisy } from '../setup/TestSuiter';

const SUITES = [
baisy.suite('Components/RadioGroupField', 'default'),
baisy.suite('Components/RadioGroupField', 'disabled'),
baisy.suite('Components/RadioGroupField', 'with error'),
];

Expand Down
1 change: 1 addition & 0 deletions e2e/__tests__/text-area.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const SUITES = [
}),
baisy.suite('Components/TextArea', 'without value'),
baisy.suite('Components/TextArea', 'with placeholder'),
baisy.suite('Components/TextArea', 'with disabled'),
];


Expand Down
6 changes: 4 additions & 2 deletions src/components/DateInput/DateInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type DateInputProps = {
withPortal?: boolean,
stretch?: boolean,
clearable?: boolean,
disabled?: boolean,
placeholder?: string,
};

Expand Down Expand Up @@ -121,14 +122,14 @@ class DateInput extends React.Component<DateInputProps, DateInputState> {
render() {
const collectedProps = this.collectProps();

const { value, withTime, withPortal, stretch, onChange, clearable, placeholder, ...rest } = this.props;
const { value, withTime, withPortal, stretch, onChange, clearable, disabled, placeholder, ...rest } = this.props;

const { textValue, isOpen } = this.state;
const mask = withTime ? utils.DATETIME_MASK : utils.DATE_MASK;

return (
<Dropdown
isOpen={ isOpen }
isOpen={ isOpen && !disabled }
stretch={ stretch }
onCloseDropdown={ this.close }
onOpenDropdown={ this.open }
Expand All @@ -142,6 +143,7 @@ class DateInput extends React.Component<DateInputProps, DateInputState> {
onChange={ this.onChangeText }
onBlur={ this.onBlur }
clearable={ clearable }
disabled={ disabled }
/>
</Dropdown.Head>
<Dropdown.Body withPortal={ withPortal } modifiers={{
Expand Down
3 changes: 3 additions & 0 deletions src/components/DateInput/DateInput.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export default (asStory) => {
withTime
/>
</StateContainer>
<StateContainer value={ null }>
<DateInput placeholder="mm/dd/yyyy" disabled />
</StateContainer>
</Column>
));
});
Expand Down
1 change: 1 addition & 0 deletions src/components/DateInput/DateInputValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type DateInputValueProps = {
value: ?string,
mask: string,
clearable?: boolean,
disabled?: boolean,
};

const DateInputValue = ({ value, onChange, ...props }: DateInputValueProps) => (
Expand Down
5 changes: 4 additions & 1 deletion src/components/Radio/RadioGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type RadioProps = {
hasError?: boolean,
/** options to define radio items */
options?: Array<({ value: any, label: string })>,
/** disabled */
disabled?: boolean,
}

class RadioGroup extends PureComponent<RadioProps> {
Expand Down Expand Up @@ -55,7 +57,7 @@ class RadioGroup extends PureComponent<RadioProps> {
}

render() {
const { children, value, direction, gap, onChange, hasError, ...rest } = this.props;
const { children, value, direction, gap, onChange, hasError, disabled, ...rest } = this.props;

return (
<FlexLayout { ...rest } direction={ direction } gap={ gap }>
Expand All @@ -66,6 +68,7 @@ class RadioGroup extends PureComponent<RadioProps> {
selectedValue: value,
name: this.getGroupName(),
hasError,
...(disabled ? { disabled } : {}),
}))
}
</FlexLayout>
Expand Down
4 changes: 4 additions & 0 deletions src/components/RadioGroupField/RadioGroupField.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type RadioGroupFieldProps = {
direction?: 'row' | 'column',
/** options to define radio items */
options?: Array<({ value: any, label: string })>,
/** disabled */
disabled?: boolean,
};

const RadioGroupField = ({
Expand All @@ -32,6 +34,7 @@ const RadioGroupField = ({
input,
meta,
options,
disabled,
...rest
}: RadioGroupFieldProps) => {
const { name, value, onChange } = input;
Expand All @@ -48,6 +51,7 @@ const RadioGroupField = ({
onChange={ onChange }
options={ options }
value={ value }
disabled={ disabled }
>
{ children }
</Radio.Group>
Expand Down
8 changes: 7 additions & 1 deletion src/components/RadioGroupField/RadioGroupField.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ import React from 'react';
export default (asStory) => {
asStory('Components/RadioGroupField', module, (story, { RadioGroupField, Radio }) => {
story

.add('default', () => (
<RadioGroupField direction="row" input={{ value: 1 }} meta={{ }}>
<Radio.Item label="Radio" value={ 1 } />
<Radio.Item label="Radio" value={ 2 } />
<Radio.Item label="Radio" value={ 3 } />
</RadioGroupField>
))
.add('disabled', () => (
<RadioGroupField direction="row" input={{ value: 1 }} meta={{ }} disabled>
<Radio.Item label="Radio" value={ 1 } />
<Radio.Item label="Radio" value={ 2 } />
<Radio.Item label="Radio" value={ 3 } />
</RadioGroupField>
))
.add('with error', () => (
<RadioGroupField direction="row" input={{ }} meta={{ error: 'Required', touched: true }}>
<Radio.Item label="Radio" value={ 1 } />
Expand Down
4 changes: 2 additions & 2 deletions src/components/Select/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ type SelectPropsFromHOCs = {|
|}

const customStyles = ({ hasError, zIndex = Z_INDEX.DROPDOWN, COLORS }) => ({
control: (style, { isFocused }) => ({
control: (style, { isFocused, isDisabled }) => ({
...style,
minHeight: '36px',
backgroundColor: COLORS.WHITE,
backgroundColor: isDisabled ? COLORS.LIGHT_GRAY5 : COLORS.WHITE,
borderColor: hasError ? COLORS.DANGER : (isFocused ? COLORS.PRIMARY : COLORS.PRIMARY_BORDER_COLOR),
boxShadow: null,
'&:hover': {
Expand Down
3 changes: 3 additions & 0 deletions src/components/Select/Select.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ export default (asStory) => {
multiple
/>
</StateContainer>
<StateContainer value={ null }>
<Select name="name" placeholder="Select an option" options={ OPTIONS } disabled />
</StateContainer>
</Column>
));
});
Expand Down
3 changes: 3 additions & 0 deletions src/components/SelectField/SelectField.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export default (asStory) => {
<StateContainer value={ [OPTIONS[1].value, OPTIONS[2].value] } withForm>
<SelectField label="Multiple select" name="name" placeholder="Select an option" options={ OPTIONS } multiple />
</StateContainer>
<StateContainer value={ [OPTIONS[1].value, OPTIONS[2].value] } withForm>
<SelectField label="Multiple select" name="name" placeholder="Select an option" options={ OPTIONS } disabled />
</StateContainer>
</Column>
));
});
Expand Down
3 changes: 3 additions & 0 deletions src/components/TextArea/TextArea.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export default (asStory) => {
))
.add('with placeholder', () => (
<TextArea name="input" placeholder="placeholder" onChange={ () => null } cols={ 100 } rows={ 5 } />
))
.add('with disabled', () => (
<TextArea name="input" placeholder="placeholder" onChange={ () => null } cols={ 100 } rows={ 5 } disabled />
));
});
};
Expand Down
8 changes: 6 additions & 2 deletions src/components/TextArea/TextArea.theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createThemeTag } from '../../theme/createThemeTag';
const name = 'textArea';

const [TextAreaTag, theme] = createThemeTag(name, ({ COLORS, SIZES }: *) => ({
root: {
root: (props) => ({
outline: 'none',
border: `1px solid ${COLORS.PRIMARY_BORDER_COLOR}`,
borderRadius: SIZES.MAIN_BORDER_RADIUS,
Expand All @@ -14,10 +14,14 @@ const [TextAreaTag, theme] = createThemeTag(name, ({ COLORS, SIZES }: *) => ({
fontWeight: 400,
padding: '8px',

backgroundColor: (props.disabled || props.readOnly)
? COLORS.LIGHT_GRAY5
: COLORS.WHITE,

'&::placeholder': {
color: COLORS.PLACEHOLDER_COLOR,
},
},
}),
modifiers: {
stretch: {
height: '100%',
Expand Down
3 changes: 3 additions & 0 deletions src/components/TextAreaField/TextAreaField.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export default (asStory) => {
))
.add('with placeholder', () => (
<TextAreaField label="Area" input={{ name: 'input', onChange: () => null }} placeholder="placeholder" />
))
.add('with disabled', () => (
<TextAreaField label="Area" input={{ name: 'input', onChange: () => null }} placeholder="placeholder" disabled />
));
});
};
Expand Down

0 comments on commit 0ace122

Please sign in to comment.