Skip to content

Commit

Permalink
feat(number-input): add size variants (#5459)
Browse files Browse the repository at this point in the history
* feat(number-input): add size variants

* fix(number-input): update disabled styles

* docs(number-input): use undefined instead of empty string

* docs(components): rename large to default size
  • Loading branch information
tw15egan authored Mar 3, 2020
1 parent c44b4e6 commit d68e6d2
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
46 changes: 46 additions & 0 deletions packages/components/src/components/number-input/_number-input.scss
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
cursor: not-allowed;
background-color: $disabled-background-color;
color: $disabled;
border-bottom-color: transparent;
}

.#{$prefix}--number__input-wrapper {
Expand Down Expand Up @@ -220,6 +221,51 @@
}
}

// Size Variant styles
.#{$prefix}--number--xl input[type='number'] {
height: rem(48px);
}

.#{$prefix}--number--xl .#{$prefix}--number__control-btn {
height: rem(24px);
}

.#{$prefix}--number--xl.#{$prefix}--number--mobile
.#{$prefix}--number__control-btn {
height: rem(48px);
width: rem(48px);
}

.#{$prefix}--number--xl .#{$prefix}--number__control-btn.up-icon svg {
top: rem(6.6px); // Needed to maintain arrow spacing between input sizes.
}

.#{$prefix}--number--xl .#{$prefix}--number__control-btn.down-icon svg {
top: rem(-6.6px); // Needed to maintain arrow spacing between input sizes.
}

.#{$prefix}--number--sm input[type='number'] {
height: rem(32px);
}

.#{$prefix}--number--sm .#{$prefix}--number__control-btn {
height: rem(16px);
}

.#{$prefix}--number--sm.#{$prefix}--number--mobile
.#{$prefix}--number__control-btn {
height: rem(32px);
width: rem(32px);
}

.#{$prefix}--number--sm .#{$prefix}--number__control-btn.up-icon svg {
top: rem(3.4px); // Needed to maintain arrow spacing between input sizes.
}

.#{$prefix}--number--sm .#{$prefix}--number__control-btn.down-icon svg {
top: rem(-3.4px); // Needed to maintain arrow spacing between input sizes.
}

//No label positioning adjustment
.#{$prefix}--number--nolabel .bx--label + .bx--form__helper-text {
margin-top: 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@ import {
number,
text,
object,
select,
} from '@storybook/addon-knobs';
import NumberInput from '../NumberInput';
import NumberInputSkeleton from '../NumberInput/NumberInput.Skeleton';

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

const props = () => ({
className: 'some-class',
id: 'tj-input',
Expand All @@ -28,6 +35,7 @@ const props = () => ({
max: number('Maximum value (max)', 100),
value: number('Value (value)', 50),
step: number('Step of up/down arrow (step)', 10),
size: select('Field size (size)', sizes, undefined) || undefined,
disabled: boolean('Disabled (disabled)', false),
readOnly: boolean('Read only (readOnly)', false),
invalid: boolean('Show form validation UI (invalid)', false),
Expand Down
8 changes: 7 additions & 1 deletion packages/react/src/components/NumberInput/NumberInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ class NumberInput extends Component {
* `true` to use the mobile variant.
*/
isMobile: PropTypes.bool,
/**
* Specify the size of the Number Input. Currently supports either `sm` or `xl` as an option.
*/
size: PropTypes.oneOf(['sm', 'xl']),
};

static defaultProps = {
Expand Down Expand Up @@ -176,7 +180,7 @@ class NumberInput extends Component {
}

/**
* The DOM node refernce to the `<input>`.
* The DOM node reference to the `<input>`.
* @type {HTMLInputElement}
*/
_inputRef = null;
Expand Down Expand Up @@ -281,6 +285,7 @@ class NumberInput extends Component {
innerRef: ref,
translateWithId: t,
isMobile,
size,
...other
} = this.props;

Expand All @@ -292,6 +297,7 @@ class NumberInput extends Component {
[`${prefix}--number--light`]: light,
[`${prefix}--number--nolabel`]: hideLabel,
[`${prefix}--number--mobile`]: isMobile,
[`${prefix}--number--${size}`]: size,
}
);

Expand Down

0 comments on commit d68e6d2

Please sign in to comment.