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 2 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
3 changes: 2 additions & 1 deletion src/components/VisualPicker/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ReactNode, ComponentType } from 'react';
import { BaseProps } from '../types';
import { BaseProps, VisualPickerSize } from '../types';

type Value = string[] | string;

Expand All @@ -13,6 +13,7 @@ export interface VisualPickerProps extends BaseProps {
error?: ReactNode;
children?: ReactNode;
multiple?: boolean;
size?: VisualPickerSize;
}

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
3 changes: 2 additions & 1 deletion src/components/VisualPickerOption/styled/content.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import styled from 'styled-components';
import attachThemeAttrs from '../../../styles/helpers/attachThemeAttrs';

const sizeMap = { large: '210px', medium: '142px', small: '100px' };
const StyledContent = attachThemeAttrs(styled.span)`
height: 142px;
height: ${props => sizeMap[props.size] || '142px'};
Copy link
Contributor

Choose a reason for hiding this comment

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

size is always defined because in defaultProps you put medium

Choose a reason for hiding this comment

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

@yvmunayev
I think we need do a fallback to || '142px' since the user can pass a wrong size value and the component should render nicely

Copy link
Contributor

@yvmunayev yvmunayev May 8, 2020

Choose a reason for hiding this comment

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

@rgah2107 check here, I'm wrong and if necessary put:

height: ${props => sizeMap[props.size] || '142px'};

width: 100%;
border-radius: 22px;
box-shadow: ${props => props.shadows.shadow_4};
Expand Down
1 change: 1 addition & 0 deletions src/components/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type ButtonIconVariant =
| 'border-filled'
| 'border-inverse'
| 'inverse';
export type VisualPickerSize = 'small' | 'medium' | 'large';

export type IconPosition = 'left' | 'right';

Expand Down