Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorganise props of multiline and localized inputs and fields #389

Merged
merged 1 commit into from
Jan 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions src/components/fields/localized-multiline-text-field/README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,17 @@ class LocalizedMultilineTextField extends React.Component {
selectedLanguage: PropTypes.string.isRequired,
onBlur: PropTypes.func,
onFocus: PropTypes.func,
isMultilineDefaultExpanded: PropTypes.bool,
hideLanguageControls: PropTypes.bool,
areLanguagesDefaultOpened: (props, propName, componentName, ...rest) => {
if (props.hideLanguageControls && typeof props[propName] === 'boolean') {
defaultExpandMultilineText: PropTypes.bool,
hideLanguageExpansionControls: PropTypes.bool,
defaultExpandLanguages: (props, propName, componentName, ...rest) => {
if (
props.hideLanguageExpansionControls &&
typeof props[propName] === 'boolean'
) {
throw new Error(
oneLine`
${componentName}: "${propName}" does not have any effect when
"hideLanguageControls" is set.
"hideLanguageExpansionControls" is set.
`
);
}
Expand Down Expand Up @@ -107,9 +110,11 @@ class LocalizedMultilineTextField extends React.Component {
selectedLanguage={this.props.selectedLanguage}
onBlur={this.props.onBlur}
onFocus={this.props.onFocus}
isMultilineDefaultExpanded={this.props.isMultilineDefaultExpanded}
hideLanguageControls={this.props.hideLanguageControls}
areLanguagesDefaultOpened={this.props.areLanguagesDefaultOpened}
defaultExpandMultilineText={this.props.defaultExpandMultilineText}
hideLanguageExpansionControls={
this.props.hideLanguageExpansionControls
}
defaultExpandLanguages={this.props.defaultExpandLanguages}
isAutofocussed={this.props.isAutofocussed}
isDisabled={this.props.isDisabled}
isReadOnly={this.props.isReadOnly}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ it('should have an HTML name for input, according to the language', () => {
it('should have an HTML name for every input when all inputs are visible', () => {
const { container } = renderLocalizedMultilineTextField({
name: 'foo',
areLanguagesDefaultOpened: true,
defaultExpandLanguages: true,
});
expect(container.querySelector('[name="foo.en"]')).toBeInTheDocument();
expect(container.querySelector('[name="foo.de"]')).toBeInTheDocument();
Expand Down Expand Up @@ -170,7 +170,7 @@ describe('when disabled', () => {
it('should disable all inputs when all languages are visible', () => {
const { getByLabelText } = renderLocalizedMultilineTextField({
isDisabled: true,
areLanguagesDefaultOpened: true,
defaultExpandLanguages: true,
});
expect(getByLabelText('EN')).toHaveAttribute('disabled');
expect(getByLabelText('DE')).toHaveAttribute('disabled');
Expand All @@ -187,7 +187,7 @@ describe('when readOnly', () => {
it('should disable all inputs when all languages are visible', () => {
const { getByLabelText } = renderLocalizedMultilineTextField({
isReadOnly: true,
areLanguagesDefaultOpened: true,
defaultExpandLanguages: true,
});
expect(getByLabelText('EN')).toHaveAttribute('readonly');
expect(getByLabelText('DE')).toHaveAttribute('readonly');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ storiesOf('Fields', module)
const name = text('name', '');
const hint = text('hint', 'More information about the product');

const areLanguagesDefaultOpened = boolean(
'areLanguagesDefaultOpened',
const defaultExpandLanguages = boolean(
'defaultExpandLanguages',
false
);
const isMultilineDefaultExpanded = boolean(
'isMultilineDefaultExpanded',
const defaultExpandMultilineText = boolean(
'defaultExpandMultilineText',
false
);

const key = `${isMultilineDefaultExpanded}-${areLanguagesDefaultOpened}`;
const key = `${defaultExpandMultilineText}-${defaultExpandLanguages}`;

const errorsByLanguage = boolean('errorsByLanguage', false);

Expand Down Expand Up @@ -83,13 +83,16 @@ storiesOf('Fields', module)
)}
onBlur={action('onBlur')}
onFocus={action('onFocus')}
hideLanguageControls={boolean('hideLanguageControls', false)}
areLanguagesDefaultOpened={
hideLanguageExpansionControls={boolean(
'hideLanguageExpansionControls',
false
)}
defaultExpandLanguages={
// we need to set undefined instead of false to avoid prop-type
// warnings in case hideLanguageControls is true
areLanguagesDefaultOpened || undefined
// warnings in case hideLanguageExpansionControls is true
defaultExpandLanguages || undefined
}
isMultilineDefaultExpanded={isMultilineDefaultExpanded}
defaultExpandMultilineText={defaultExpandMultilineText}
isAutofocussed={boolean('isAutofocussed', false)}
isDisabled={boolean('isDisabled', false)}
isReadOnly={boolean('isReadOnly', false)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const component = () => (
onChange={() => {}}
selectedLanguage="en"
horizontalConstraint="m"
isMultilineDefaultExpanded={true}
defaultExpandMultilineText={true}
/>
</Spec>
<Spec label="when multiline text and languages are expanded by default">
Expand All @@ -37,8 +37,8 @@ export const component = () => (
onChange={() => {}}
selectedLanguage="en"
horizontalConstraint="m"
isMultilineDefaultExpanded={true}
areLanguagesDefaultOpened={true}
defaultExpandMultilineText={true}
defaultExpandLanguages={true}
/>
</Spec>
<Spec label="when language controls are hidden">
Expand All @@ -48,7 +48,7 @@ export const component = () => (
onChange={() => {}}
selectedLanguage="en"
horizontalConstraint="m"
hideLanguageControls={true}
hideLanguageExpansionControls={true}
/>
</Spec>
<Spec label="when languages are opened by default">
Expand All @@ -58,7 +58,7 @@ export const component = () => (
onChange={() => {}}
selectedLanguage="en"
horizontalConstraint="m"
areLanguagesDefaultOpened={true}
defaultExpandLanguages={true}
/>
</Spec>
<Spec label="when read-only and open">
Expand All @@ -69,7 +69,7 @@ export const component = () => (
selectedLanguage="en"
horizontalConstraint="m"
isReadOnly={true}
areLanguagesDefaultOpened={true}
defaultExpandLanguages={true}
/>
</Spec>
<Spec label="when read-only and closed">
Expand All @@ -90,7 +90,7 @@ export const component = () => (
selectedLanguage="en"
horizontalConstraint="m"
isDisabled={true}
areLanguagesDefaultOpened={true}
defaultExpandLanguages={true}
/>
</Spec>
<Spec label="when disabled and closed">
Expand Down
Loading