Skip to content

Commit

Permalink
feat(list-box): introduce size variants (carbon-design-system#4731)
Browse files Browse the repository at this point in the history
  • Loading branch information
asudoh authored Dec 9, 2019
1 parent e90f5d4 commit 0723836
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 9 deletions.
20 changes: 17 additions & 3 deletions packages/components/src/components/dropdown/_dropdown.scss
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,22 @@
}
}

.#{$prefix}--dropdown--xl {
height: rem(48px);
}

.#{$prefix}--dropdown--xl .#{$prefix}--dropdown__arrow {
top: rem(16px);
}

.#{$prefix}--dropdown--sm {
height: rem(32px);
}

.#{$prefix}--dropdown--sm .#{$prefix}--dropdown__arrow {
top: rem(8px);
}

.#{$prefix}--dropdown--open {
border-bottom-color: $ui-03;
}
Expand Down Expand Up @@ -138,9 +154,7 @@
.#{$prefix}--dropdown-text {
@include type-style('body-short-01');
display: block;
height: rem(40px);
padding-top: $carbon--spacing-04;
padding-bottom: $carbon--spacing-04;
height: calc(100% + 1px); // Account for the border in `.bx--dropdown`
padding-left: $carbon--spacing-05;
padding-right: rem(42px); // 2rem + SVG width
white-space: nowrap;
Expand Down
15 changes: 13 additions & 2 deletions packages/components/src/components/list-box/_list-box.scss
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ $list-box-menu-width: rem(300px);
}
}

.#{$prefix}--list-box--xl {
height: rem(48px);
max-height: rem(48px);
}

.#{$prefix}--list-box--sm {
height: rem(32px);
max-height: rem(32px);
}

.#{$prefix}--list-box--expanded {
border-bottom-color: $ui-03;
}
Expand All @@ -105,9 +115,10 @@ $list-box-menu-width: rem(300px);
// invalid states
.#{$prefix}--list-box__invalid-icon {
position: absolute;
top: $carbon--spacing-04;
top: 50%;
right: $carbon--spacing-08;
fill: $support-01;
transform: translateY(-50%);
}

.#{$prefix}--list-box--inline .#{$prefix}--list-box__invalid-icon {
Expand Down Expand Up @@ -247,7 +258,7 @@ $list-box-menu-width: rem(300px);
display: inline-flex;
align-items: center;
vertical-align: top;
height: rem(40px);
height: calc(100% + 1px); // Account for the border in `.bx--list-box`
padding: 0 $carbon--spacing-09 0 $carbon--spacing-05;
cursor: pointer;
outline: none;
Expand Down
9 changes: 8 additions & 1 deletion packages/react/src/components/ComboBox/ComboBox-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import React, { useState } from 'react';
import { storiesOf } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import { withKnobs, boolean, text } from '@storybook/addon-knobs';
import { withKnobs, boolean, select, text } from '@storybook/addon-knobs';
import ComboBox from '../ComboBox';
import Button from '../Button';
import WithState from '../../tools/withState';
Expand Down Expand Up @@ -38,6 +38,12 @@ const items = [
},
];

const sizes = {
'Extra large size (xl)': 'xl',
'Regular size (lg)': '',
'Small size (sm)': 'sm',
};

const props = () => ({
id: text('Combobox ID (id)', 'carbon-combobox-example'),
placeholder: text('Placeholder text (placeholder)', 'Filter...'),
Expand All @@ -47,6 +53,7 @@ const props = () => ({
disabled: boolean('Disabled (disabled)', false),
invalid: boolean('Invalid (invalid)', false),
invalidText: text('Invalid text (invalidText)', 'A valid value is required'),
size: select('Field size (size)', sizes, '') || undefined,
onChange: action('onChange'),
});

Expand Down
7 changes: 7 additions & 0 deletions packages/react/src/components/ComboBox/ComboBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ export default class ComboBox extends React.Component {
*/
type: ListBoxPropTypes.ListBoxType,

/**
* Specify the size of the ListBox. Currently supports either `sm`, `lg` or `xl` as an option.
*/
size: ListBoxPropTypes.ListBoxSize,

/**
* Callback function to notify consumer when the text input changes.
* This provides support to change available items based on the text.
Expand Down Expand Up @@ -262,6 +267,7 @@ export default class ComboBox extends React.Component {
invalidText,
light,
type, // eslint-disable-line no-unused-vars
size,
shouldFilterItem, // eslint-disable-line no-unused-vars
onChange, // eslint-disable-line no-unused-vars
onInputChange, // eslint-disable-line no-unused-vars
Expand Down Expand Up @@ -321,6 +327,7 @@ export default class ComboBox extends React.Component {
invalidText={invalidText}
isOpen={isOpen}
light={light}
size={size}
{...getRootProps({ refKey: 'innerRef' })}>
<ListBox.Field
id={id}
Expand Down
7 changes: 7 additions & 0 deletions packages/react/src/components/Dropdown/Dropdown-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,16 @@ const types = {
'Inline (inline)': 'inline',
};

const sizes = {
'Extra large size (xl)': 'xl',
'Regular size (lg)': '',
'Small size (sm)': 'sm',
};

const props = () => ({
id: text('Dropdown ID (id)', 'carbon-dropdown-example'),
type: select('Dropdown type (type)', types, 'default'),
size: select('Field size (size)', sizes, '') || undefined,
label: text('Label (label)', 'Dropdown menu options'),
ariaLabel: text('Aria Label (ariaLabel)', 'Dropdown'),
disabled: boolean('Disabled (disabled)', false),
Expand Down
7 changes: 7 additions & 0 deletions packages/react/src/components/Dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ export default class Dropdown extends React.Component {
*/
type: ListBoxPropTypes.ListBoxType,

/**
* Specify the size of the ListBox. Currently supports either `sm`, `lg` or `xl` as an option.
*/
size: ListBoxPropTypes.ListBoxSize,

/**
* In the case you want to control the dropdown selection entirely.
*/
Expand Down Expand Up @@ -167,6 +172,7 @@ export default class Dropdown extends React.Component {
itemToString,
itemToElement,
type,
size,
initialSelectedItem,
selectedItem,
id,
Expand Down Expand Up @@ -240,6 +246,7 @@ export default class Dropdown extends React.Component {
}) => (
<ListBox
type={type}
size={size}
id={dropdownId}
aria-label={ariaLabel}
className={className({ isOpen })}
Expand Down
9 changes: 8 additions & 1 deletion packages/react/src/components/ListBox/ListBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import cx from 'classnames';
import React from 'react';
import PropTypes from 'prop-types';
import { settings } from 'carbon-components';
import { ListBoxType } from './ListBoxPropTypes';
import { ListBoxType, ListBoxSize } from './ListBoxPropTypes';

const { prefix } = settings;

Expand All @@ -34,6 +34,7 @@ const ListBox = ({
disabled,
innerRef,
type,
size,
invalid,
invalidText,
light,
Expand All @@ -43,6 +44,7 @@ const ListBox = ({
const className = cx({
[containerClassName]: !!containerClassName,
[`${prefix}--list-box`]: true,
[`${prefix}--list-box--${size}`]: size,
[`${prefix}--list-box--inline`]: type === 'inline',
[`${prefix}--list-box--disabled`]: disabled,
[`${prefix}--list-box--light`]: light,
Expand Down Expand Up @@ -95,6 +97,11 @@ ListBox.propTypes = {
* `inline` as an option.
*/
type: ListBoxType.isRequired,

/**
* Specify the size of the ListBox. Currently supports either `sm`, `lg` or `xl` as an option.
*/
size: ListBoxSize,
};

ListBox.defaultProps = {
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/components/ListBox/ListBoxPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
import PropTypes from 'prop-types';

export const ListBoxType = PropTypes.oneOf(['default', 'inline']);
export const ListBoxSize = PropTypes.oneOf(['sm', 'lg', 'xl']);
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Downshift from 'downshift';
import isEqual from 'lodash.isequal';
import { settings } from 'carbon-components';
import { WarningFilled16 } from '@carbon/icons-react';
import ListBox from '../ListBox';
import ListBox, { PropTypes as ListBoxPropTypes } from '../ListBox';
import Checkbox from '../Checkbox';
import Selection from '../../internal/Selection';
import { sortingPropTypes } from './MultiSelectPropTypes';
Expand Down Expand Up @@ -65,6 +65,11 @@ export default class FilterableMultiSelect extends React.Component {
*/
locale: PropTypes.string,

/**
* Specify the size of the ListBox. Currently supports either `sm`, `lg` or `xl` as an option.
*/
size: ListBoxPropTypes.ListBoxSize,

/**
* `onChange` is a utility for this controlled component to communicate to a
* consuming component what kind of internal state changes are occuring.
Expand Down Expand Up @@ -259,6 +264,7 @@ export default class FilterableMultiSelect extends React.Component {
initialSelectedItems,
id,
locale,
size,
placeholder,
sortItems,
compareItems,
Expand Down Expand Up @@ -345,6 +351,7 @@ export default class FilterableMultiSelect extends React.Component {
invalid={invalid}
invalidText={invalidText}
isOpen={isOpen}
size={size}
{...getRootProps({ refKey: 'innerRef' })}>
<ListBox.Field
id={id}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ const types = {
'Inline (inline)': 'inline',
};

const sizes = {
'Extra large size (xl)': 'xl',
'Regular size (lg)': '',
'Small size (sm)': 'sm',
};

const props = () => ({
id: text('MultiSelect ID (id)', 'carbon-multiselect-example'),
titleText: text('Title (titleText)', 'Multiselect title'),
Expand All @@ -63,6 +69,7 @@ const props = () => ({
light: boolean('Light variant (light)', false),
useTitleInItem: boolean('Show tooltip on hover', false),
type: select('UI type (Only for `<MultiSelect>`) (type)', types, 'default'),
size: select('Field size (size)', sizes, '') || undefined,
label: text('Label (label)', defaultLabel),
invalid: boolean('Show form validation UI (invalid)', false),
invalidText: text(
Expand Down
9 changes: 8 additions & 1 deletion packages/react/src/components/MultiSelect/MultiSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Downshift from 'downshift';
import isEqual from 'lodash.isequal';
import { settings } from 'carbon-components';
import { WarningFilled16 } from '@carbon/icons-react';
import ListBox from '../ListBox';
import ListBox, { PropTypes as ListBoxPropTypes } from '../ListBox';
import Checkbox from '../Checkbox';
import Selection from '../../internal/Selection';
import { sortingPropTypes } from './MultiSelectPropTypes';
Expand Down Expand Up @@ -78,6 +78,11 @@ export default class MultiSelect extends React.Component {
*/
type: PropTypes.oneOf(['default', 'inline']),

/**
* Specify the size of the ListBox. Currently supports either `sm`, `lg` or `xl` as an option.
*/
size: ListBoxPropTypes.ListBoxSize,

/**
* Specify title to show title on hover
*/
Expand Down Expand Up @@ -222,6 +227,7 @@ export default class MultiSelect extends React.Component {
helperText,
label,
type,
size,
disabled,
initialSelectedItems,
sortItems,
Expand Down Expand Up @@ -298,6 +304,7 @@ export default class MultiSelect extends React.Component {
<ListBox
id={id}
type={type}
size={size}
className={className}
disabled={disabled}
light={light}
Expand Down

0 comments on commit 0723836

Please sign in to comment.