The AmountControl is a three-segment control used to increase or decrease an incremental value.
You should have the chayns-components package installed. If that is not the
case already, run
yarn add chayns-componentsor
npm i chayns-componentsAfter the chayns-components package is installed, you can import the component
and use it with React:
import React from 'react'
import { AmountControl } from 'chayns-components';
// ...
<AmountControl {...} />The AmountControl-component takes the following props:
| Name | Type | Default | Required |
|---|---|---|---|
| buttonText | string |
||
| amount | number |
0 |
|
| onChange | function |
||
| onInput | function |
||
| onAdd | function |
||
| onRemove | function |
||
| disabled | boolean |
false |
|
| disableInput | boolean |
||
| disableAdd | boolean |
false |
|
| disableRemove | boolean |
false |
|
| className | string |
'' |
|
| autoInput | boolean |
false |
|
| buttonFormatHandler | function |
||
| showInput | boolean |
false |
|
| showAddButton | boolean |
||
| icon | string | object |
||
| plusIcon | string | object |
'fa fa-plus' |
|
| minusIcon | string | object |
'fa fa-minus' |
|
| removeIcon | string | object |
||
| removeColor | string |
||
| addColor | string |
||
| iconColor | string |
||
| equalize | string |
||
| focusOnClick | boolean |
true |
|
| contentWidth | number |
||
| min | number |
||
| max | number |
||
| stopPropagation | boolean |
false |
|
| hasAlwaysControls | boolean |
false |
buttonText?: stringThis text will be shown in the button when the amount-prop is 0.
amount?: numberThis component works as a controlled input and this prop defines its current state.
onChange?: functionThis callback will be called when the amount is changed by the user.
onInput?: functionAlias for onChange.
onAdd?: functionCalled when the user clicks the increment-button.
onRemove?: functionCalled when the user clicks the decrement-button.
disabled?: booleanDisables any interaction and switches to a disabled style.
disableInput?: booleanDisables the input field and forces the user to use the buttons to control the value.
disableAdd?: booleanDisables the increment-button and disables the ability to increment the value.
disableRemove?: booleanDisables the decrement-button and disables the ability to decrement the value.
className?: stringA classname that is applied to the wrapper of the component.
autoInput?: booleanShows an input field once the amount is greater than 10.
buttonFormatHandler?: functionA function that returns the content of the button.
showInput?: booleanWhether to show the input.
showAddButton?: booleanWhether the add button should be shown/rendered.
icon?: string | objectDisplays an icon on the left side of the button if the amount is 0. Supply a
FontAwesome-string like "fa fa-plane".
plusIcon?: string | objectThe icon shown on the increment-button.
minusIcon?: string | objectThe icon shown on the decrement-button.
removeIcon?: string | objectThe icon the reset the amount to 0.
removeColor?: stringThe color of the remove icon.
addColor?: stringThe color of the icon in the increment-button.
iconColor?: stringThe color of the icon to the left of the button.
equalize?: stringMultiple AmountControl with the same equalize-prop will sync their width.
focusOnClick?: booleanEnables the input autofocus.
contentWidth?: numberThe width of the AmountControl content.
min?: numberThe minimum value of the AmountControl (the input field is not validated).
max?: numberThe maximum value of the AmountControl (the input field is not validated).
stopPropagation?: booleanStop propagation of click events to parent components.
hasAlwaysControls?: booleanAlways show the increment and decrement buttons.