-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathChipField.tsx
More file actions
73 lines (66 loc) · 1.95 KB
/
Copy pathChipField.tsx
File metadata and controls
73 lines (66 loc) · 1.95 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { iconSize, iconStrokeWidth } from "@dashboard/components/icons";
import { Box, type BoxProps, Button, Text } from "@saleor/macaw-ui-next";
import { X } from "lucide-react";
import { forwardRef, type ReactNode } from "react";
import { Link } from "react-router-dom";
const ChipLabel = ({ url, label }: { url?: string; label: ReactNode }) => {
const labelContent = (
<Text textDecoration={url ? { hover: "underline" } : undefined}>{label}</Text>
);
if (url) {
return <Link to={url}>{labelContent}</Link>;
}
return labelContent;
};
type ChipFieldProps = {
label: ReactNode;
startAdornment?: ReactNode;
onClose?: () => void;
loading?: boolean;
url?: string;
} & BoxProps;
export const ChipField = forwardRef<HTMLDivElement, ChipFieldProps>(
({ label, startAdornment, onClose, loading, url, className, style, ...props }, ref) => {
const handleClose = (event: React.MouseEvent<HTMLButtonElement>) => {
event.preventDefault();
if (onClose) {
onClose();
}
};
return (
<Box
ref={ref}
style={style}
as="div"
className={className}
borderWidth={1}
borderStyle="solid"
borderColor={"default1"}
borderRadius={4}
paddingY={1}
paddingX={1.5}
paddingRight={1}
backgroundColor={"default1"}
opacity={"1"}
{...props}
>
<Box display="flex" alignItems="center" gap={1.5} paddingLeft={2}>
{startAdornment}
<ChipLabel label={label} url={url} />
<Box marginLeft={1}>
<Button
variant="tertiary"
size="small"
onClick={handleClose}
data-test-id="button-close"
disabled={loading}
type="button"
icon={<X size={iconSize.small} strokeWidth={iconStrokeWidth} />}
/>
</Box>
</Box>
</Box>
);
},
);
ChipField.displayName = "ChipField";