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

feat: add prop size to VisualPicker component #1527

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions src/components/VisualPicker/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface VisualPickerProps extends BaseProps {
error?: ReactNode;
children?: ReactNode;
multiple?: boolean;
size?: string;
Copy link
Member

@LeandroTorresSicilia LeandroTorresSicilia May 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

be more specific here like:
size?: 'small' | 'medium' | 'large';

}

declare const VisualPicker: React.ComponentType<VisualPickerProps>;
Expand Down
6 changes: 6 additions & 0 deletions src/components/VisualPicker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ class VisualPicker extends Component {
value,
multiple,
className,
size,
} = this.props;
const context = {
ariaDescribedby: this.getErrorMessageId(),
groupName: this.groupNameId,
privateOnChange: this.handleChange,
value,
multiple,
size,
};

return (
Expand Down Expand Up @@ -103,6 +105,9 @@ VisualPicker.propTypes = {
className: PropTypes.string,
/** It is an object with custom style applied to the root element. */
style: PropTypes.object,
/** The size of the VisualPicker. Valid values are small, medium, and large.
* This value defaults to medium. */
size: PropTypes.oneOf(['small', 'medium', 'large']),
/**
* This prop that should not be visible in the documentation.
* @ignore
Expand All @@ -122,6 +127,7 @@ VisualPicker.defaultProps = {
error: null,
className: undefined,
style: undefined,
size: 'medium',
children: [],
multiple: false,
};
Expand Down
4 changes: 2 additions & 2 deletions src/components/VisualPickerOption/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class PickerOption extends Component {
}

render() {
const { disabled, children, footer, style, className } = this.props;
const { disabled, children, footer, style, className, size } = this.props;
const { groupName, ariaDescribedby } = this.props;

return (
Expand All @@ -63,7 +63,7 @@ class PickerOption extends Component {
/>

<StyledLabel data-id="visual-picker_option-label" htmlFor={this.inputId}>
<StyledContent data-id="visual-picker_option">
<StyledContent data-id="visual-picker_option" size={size}>
<RenderIf isTrue={this.isChecked()}>
<StyledCheckedTriangle />
<StyledCheckmarkIcon />
Expand Down
15 changes: 15 additions & 0 deletions src/components/VisualPickerOption/styled/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@ const StyledContent = attachThemeAttrs(styled.span)`
justify-content: center;
align-items: center;
position: relative;
${props =>
props.size === 'large' &&
`
height: 210px;
`};
${props =>
props.size === 'medium' &&
`
height: 142px;
`};
${props =>
props.size === 'small' &&
`
height: 100px;
`};
Copy link
Member

@LeandroTorresSicilia LeandroTorresSicilia May 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here you can use a map like:

const sizeMap = {
    large: '210px',
    medium: '142px',
    small: '100px',
};

and then:
height: ${props => sizeMap[props.size] || 142px}
and thus avoid all conditionals

`;

export default StyledContent;