-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathStepButton.tsx
More file actions
43 lines (34 loc) · 1.17 KB
/
StepButton.tsx
File metadata and controls
43 lines (34 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import React from 'react';
import {Minus, Plus} from '@gravity-ui/icons';
import {Button, Icon} from '@gravity-ui/uikit';
import block from 'bem-cn-lite';
import type {ValueOf} from 'shared';
import './NumberInput.scss';
const b = block('number-input');
export const STEP_BUTTON_DIRECTION = {
Plus: '+',
Minus: '-',
} as const;
export type StepButtonDirection = ValueOf<typeof STEP_BUTTON_DIRECTION>;
interface StepButtonProps {
direction: StepButtonDirection;
disabled: boolean;
onClick: () => void;
}
const DIRECTION_CONFIG: Record<
StepButtonDirection,
{icon: typeof Plus | typeof Minus; pin: 'brick-round' | 'round-brick'}
> = {
[STEP_BUTTON_DIRECTION.Plus]: {icon: Plus, pin: 'brick-round'},
[STEP_BUTTON_DIRECTION.Minus]: {icon: Minus, pin: 'round-brick'},
};
export const StepButton: React.FC<StepButtonProps> = ({direction, disabled, onClick}) => {
const {icon, pin} = DIRECTION_CONFIG[direction];
return (
<div className={b('input-button')}>
<Button view="outlined" pin={pin} width="max" disabled={disabled} onClick={onClick}>
<Icon data={icon} />
</Button>
</div>
);
};