-
Notifications
You must be signed in to change notification settings - Fork 691
Expand file tree
/
Copy pathArrayButton.tsx
More file actions
33 lines (26 loc) · 831 Bytes
/
ArrayButton.tsx
File metadata and controls
33 lines (26 loc) · 831 Bytes
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
import React from 'react';
import type { IconButtonProps } from 'toolkit/chakra/icon-button';
import AddButton from 'toolkit/components/buttons/AddButton';
import RemoveButton from 'toolkit/components/buttons/RemoveButton';
interface Props extends Omit<IconButtonProps, 'type'> {
index: number;
type: 'add' | 'remove';
}
const ArrayButton = ({ type, index, onClick, ...props }: Props) => {
const handleClick = React.useCallback((event: React.MouseEvent<HTMLButtonElement>) => {
event.stopPropagation();
onClick?.(event);
}, [ onClick ]);
const Button = type === 'add' ? AddButton : RemoveButton;
return (
<Button
as="div"
role="button"
data-index={ index }
size="2xs_alt"
onClick={ handleClick }
{ ...props }
/>
);
};
export default React.memo(ArrayButton);