import { Counter } from '@megafon/ui-core';
Код DemoCounterWrappertype childrenPropTypes = {onChange: (value: number) => void;initialValue: number;value?: number;}interface IDemoCounterWrapperProps {children: (prop: childrenPropTypes) => JSX.Element;initialValue: number;isControlled?: boolean;}export const DemoCounterWrapper: React.FC<IDemoCounterWrapperProps> = ({isControlled,initialValue = 0,children,}) => {const [value, setValue] = React.useState(initialValue);const childrenProps: childrenPropTypes = {onChange: setValue,initialValue,};if (isControlled) {childrenProps.value = value;}return (<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-around', textAlign: 'center', flexDirection: 'column' }}><p style={{ marginTop: 0, marginBottom: '15px' }}>Value: {value}</p>{children(childrenProps)}</div>);};
<DemoCounterWrapper initialValue={3}> {({ onChange, initialValue }) => <Counter initialValue={initialValue} onChange={onChange} min={3} max={33} /> } </DemoCounterWrapper>
<DemoCounterWrapper initialValue={18}> {({ onChange, initialValue }) => <Counter initialValue={initialValue} onChange={onChange} min={3} max={33} /> } </DemoCounterWrapper>
<DemoCounterWrapper initialValue={33}> {({ onChange, initialValue }) => <Counter initialValue={initialValue} onChange={onChange} min={3} max={33} /> } </DemoCounterWrapper>
Компонент контроллируется родителем.
<DemoCounterWrapper isControlled initialValue={5}> {({ onChange, value }) => ( <Counter isControlled value={value} onChange={onChange} /> )} </DemoCounterWrapper>
<DemoCounterWrapper> {({ onChange }) => <Counter onChange={onChange} disabled /> } </DemoCounterWrapper>
Prop name | Type | Default | Description |
---|---|---|---|
dataAttrs | { root?: Record<string, string>; minus?: Record<string, string>; plus?: Record<string, string>; input?: Record<string, string>; } | Дополнительные data атрибуты к внутренним элементам | |
isControlled | boolean | false | Переводит компонент в контролируемое состояние |
value | number | Внешнее значение для контролируемого компонента | |
initialValue | number | Начальное значение | |
min | number | 0 | Минимальное доступное значение |
max | number | 999999 | Максимальное доступное значение |
disabled | boolean | false | Отключение счетчика |
onChange | (value: number) => void | Обработчик изменения значения 'value' | |
className | string | Дополнительный класс для корневого элемента | |
classes | { root?: string; buttonMinus?: string; buttonPlus?: string; input?: string; } | {} | Дополнительные классы для корневого и внутренних элементов |