@brightlocal/ui-components 0.1.4 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/README.md +2 -1
  2. package/dist/alert.cjs +1 -1
  3. package/dist/alert.d.ts +10 -1
  4. package/dist/alert.d.ts.map +1 -1
  5. package/dist/alert.js +6 -2
  6. package/dist/card.cjs +1 -1
  7. package/dist/card.d.ts +6 -2
  8. package/dist/card.d.ts.map +1 -1
  9. package/dist/card.js +89 -73
  10. package/dist/centred-layout.cjs +1 -1
  11. package/dist/centred-layout.d.ts +49 -25
  12. package/dist/centred-layout.d.ts.map +1 -1
  13. package/dist/centred-layout.js +57 -32
  14. package/dist/checkbox.cjs +1 -1
  15. package/dist/checkbox.d.ts.map +1 -1
  16. package/dist/checkbox.js +19 -19
  17. package/dist/chip.cjs +1 -0
  18. package/dist/chip.d.ts +61 -0
  19. package/dist/chip.d.ts.map +1 -0
  20. package/dist/chip.js +165 -0
  21. package/dist/combobox.cjs +1 -1
  22. package/dist/combobox.d.ts +75 -59
  23. package/dist/combobox.d.ts.map +1 -1
  24. package/dist/combobox.js +244 -191
  25. package/dist/date-picker.cjs +1 -1
  26. package/dist/date-picker.d.ts +89 -52
  27. package/dist/date-picker.d.ts.map +1 -1
  28. package/dist/date-picker.js +228 -210
  29. package/dist/dropdown-menu.d.ts.map +1 -1
  30. package/dist/header.cjs +1 -0
  31. package/dist/header.d.ts +42 -0
  32. package/dist/header.d.ts.map +1 -0
  33. package/dist/header.js +22 -0
  34. package/dist/index.cjs +1 -1
  35. package/dist/index.d.ts +3 -0
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +428 -388
  38. package/dist/input-chip.cjs +1 -0
  39. package/dist/input-chip.d.ts +117 -0
  40. package/dist/input-chip.d.ts.map +1 -0
  41. package/dist/input-chip.js +284 -0
  42. package/dist/input-group.cjs +1 -1
  43. package/dist/input-group.d.ts +5 -0
  44. package/dist/input-group.d.ts.map +1 -1
  45. package/dist/input-group.js +47 -39
  46. package/dist/input-otp.cjs +1 -1
  47. package/dist/input-otp.d.ts +45 -32
  48. package/dist/input-otp.d.ts.map +1 -1
  49. package/dist/input-otp.js +138 -114
  50. package/dist/input-password.cjs +1 -1
  51. package/dist/input-password.d.ts +151 -19
  52. package/dist/input-password.d.ts.map +1 -1
  53. package/dist/input-password.js +197 -91
  54. package/dist/input.cjs +1 -1
  55. package/dist/input.d.ts +4 -0
  56. package/dist/input.d.ts.map +1 -1
  57. package/dist/input.js +26 -24
  58. package/dist/logo.cjs +1 -1
  59. package/dist/logo.js +13 -13
  60. package/dist/progress.cjs +1 -1
  61. package/dist/progress.d.ts +10 -0
  62. package/dist/progress.d.ts.map +1 -1
  63. package/dist/progress.js +45 -36
  64. package/dist/radio-group.cjs +1 -1
  65. package/dist/radio-group.d.ts +4 -0
  66. package/dist/radio-group.d.ts.map +1 -1
  67. package/dist/radio-group.js +49 -47
  68. package/dist/select.cjs +1 -1
  69. package/dist/select.d.ts +3 -1
  70. package/dist/select.d.ts.map +1 -1
  71. package/dist/select.js +57 -56
  72. package/dist/slider.cjs +1 -1
  73. package/dist/slider.d.ts +31 -3
  74. package/dist/slider.d.ts.map +1 -1
  75. package/dist/slider.js +53 -43
  76. package/dist/textarea.cjs +1 -1
  77. package/dist/textarea.d.ts +4 -0
  78. package/dist/textarea.d.ts.map +1 -1
  79. package/dist/textarea.js +19 -18
  80. package/dist/toggle.cjs +1 -1
  81. package/dist/toggle.d.ts.map +1 -1
  82. package/dist/toggle.js +17 -17
  83. package/package.json +1 -1
  84. package/src/components/alert.tsx +10 -1
  85. package/src/components/card.tsx +66 -38
  86. package/src/components/centred-layout.tsx +115 -38
  87. package/src/components/checkbox.tsx +2 -3
  88. package/src/components/chip.tsx +249 -0
  89. package/src/components/combobox.tsx +490 -298
  90. package/src/components/date-picker.tsx +410 -266
  91. package/src/components/dropdown-menu.tsx +6 -1
  92. package/src/components/header.tsx +69 -0
  93. package/src/components/input-chip.tsx +548 -0
  94. package/src/components/input-group.tsx +17 -2
  95. package/src/components/input-otp.tsx +161 -78
  96. package/src/components/input-password.tsx +473 -128
  97. package/src/components/input.tsx +11 -3
  98. package/src/components/logo.tsx +1 -1
  99. package/src/components/progress.tsx +21 -2
  100. package/src/components/radio-group.tsx +11 -0
  101. package/src/components/select.tsx +5 -2
  102. package/src/components/slider.tsx +85 -15
  103. package/src/components/textarea.tsx +15 -5
  104. package/src/components/toggle.tsx +13 -15
  105. package/src/index.ts +3 -0
@@ -209,4 +209,13 @@ function AlertWarning({
209
209
  );
210
210
  }
211
211
 
212
- export { AlertSuccess, AlertInfo, AlertDestructive, AlertWarning };
212
+ export {
213
+ Alert,
214
+ AlertTitle,
215
+ AlertDescription,
216
+ alertVariants,
217
+ AlertSuccess,
218
+ AlertInfo,
219
+ AlertDestructive,
220
+ AlertWarning,
221
+ };
@@ -3,6 +3,16 @@ import { cva } from "class-variance-authority";
3
3
 
4
4
  import { cn } from "@brightlocal/ui-components/lib/utils";
5
5
 
6
+ /**
7
+ * Card variant type
8
+ */
9
+ type CardVariant = "default" | "transparent" | "border" | "transparent-flush";
10
+
11
+ /**
12
+ * Context to pass variant information to sub-components
13
+ */
14
+ const CardContext = React.createContext<{ flush: boolean }>({ flush: false });
15
+
6
16
  const cardVariants = cva(
7
17
  ["flex", "flex-col", "gap-8", "rounded-[14px]", "py-8", "transition-colors"],
8
18
  {
@@ -21,6 +31,7 @@ const cardVariants = cva(
21
31
  "border",
22
32
  "border-border",
23
33
  ],
34
+ "transparent-flush": ["bg-transparent", "text-foreground"],
24
35
  },
25
36
  },
26
37
  defaultVariants: {
@@ -37,7 +48,7 @@ type CardProps = React.ComponentProps<"div"> & {
37
48
  * Visual style variant of the card
38
49
  * @default "default"
39
50
  */
40
- variant?: "default" | "transparent" | "border";
51
+ variant?: CardVariant;
41
52
  /**
42
53
  * Data hook for automated testing (required)
43
54
  */
@@ -64,20 +75,27 @@ const Card = React.forwardRef<HTMLDivElement, CardProps>(
64
75
  dataHook,
65
76
  trackingEl,
66
77
  trackingLabel,
78
+ children,
67
79
  ...props
68
80
  },
69
81
  ref
70
82
  ) => {
83
+ const flush = variant === "transparent-flush";
84
+
71
85
  return (
72
- <div
73
- ref={ref}
74
- className={cn(cardVariants({ variant }), className)}
75
- data-hook={dataHook}
76
- data-slot="card"
77
- data-tracking-el={trackingEl || `card-${variant}`}
78
- data-tracking-label={trackingLabel}
79
- {...props}
80
- />
86
+ <CardContext.Provider value={{ flush }}>
87
+ <div
88
+ ref={ref}
89
+ className={cn(cardVariants({ variant }), className)}
90
+ data-hook={dataHook}
91
+ data-slot="card"
92
+ data-tracking-el={trackingEl || `card-${variant}`}
93
+ data-tracking-label={trackingLabel}
94
+ {...props}
95
+ >
96
+ {children}
97
+ </div>
98
+ </CardContext.Provider>
81
99
  );
82
100
  }
83
101
  );
@@ -102,17 +120,21 @@ type CardSubComponentProps = React.ComponentProps<"div"> & {
102
120
  * Header section of the Card containing title and description.
103
121
  */
104
122
  const CardHeader = React.forwardRef<HTMLDivElement, CardSubComponentProps>(
105
- ({ className, ...props }, ref) => (
106
- <div
107
- ref={ref}
108
- className={cn(
109
- "@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-1.5 px-8 has-data-[slot=card-action]:grid-cols-[1fr_auto]",
110
- className
111
- )}
112
- data-slot="card-header"
113
- {...props}
114
- />
115
- )
123
+ ({ className, ...props }, ref) => {
124
+ const { flush } = React.useContext(CardContext);
125
+ return (
126
+ <div
127
+ ref={ref}
128
+ className={cn(
129
+ "@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-1.5 has-data-[slot=card-action]:grid-cols-[1fr_auto]",
130
+ !flush && "px-8",
131
+ className
132
+ )}
133
+ data-slot="card-header"
134
+ {...props}
135
+ />
136
+ );
137
+ }
116
138
  );
117
139
  CardHeader.displayName = "CardHeader";
118
140
 
@@ -171,14 +193,17 @@ CardAction.displayName = "CardAction";
171
193
  * Main content area of the Card.
172
194
  */
173
195
  const CardContent = React.forwardRef<HTMLDivElement, CardSubComponentProps>(
174
- ({ className, ...props }, ref) => (
175
- <div
176
- ref={ref}
177
- className={cn("px-8", className)}
178
- data-slot="card-content"
179
- {...props}
180
- />
181
- )
196
+ ({ className, ...props }, ref) => {
197
+ const { flush } = React.useContext(CardContext);
198
+ return (
199
+ <div
200
+ ref={ref}
201
+ className={cn(!flush && "px-8", className)}
202
+ data-slot="card-content"
203
+ {...props}
204
+ />
205
+ );
206
+ }
182
207
  );
183
208
  CardContent.displayName = "CardContent";
184
209
 
@@ -186,14 +211,17 @@ CardContent.displayName = "CardContent";
186
211
  * Footer section of the Card for actions or metadata.
187
212
  */
188
213
  const CardFooter = React.forwardRef<HTMLDivElement, CardSubComponentProps>(
189
- ({ className, ...props }, ref) => (
190
- <div
191
- ref={ref}
192
- className={cn("flex items-center px-8", className)}
193
- data-slot="card-footer"
194
- {...props}
195
- />
196
- )
214
+ ({ className, ...props }, ref) => {
215
+ const { flush } = React.useContext(CardContext);
216
+ return (
217
+ <div
218
+ ref={ref}
219
+ className={cn("flex items-center", !flush && "px-8", className)}
220
+ data-slot="card-footer"
221
+ {...props}
222
+ />
223
+ );
224
+ }
197
225
  );
198
226
  CardFooter.displayName = "CardFooter";
199
227
 
@@ -207,4 +235,4 @@ export {
207
235
  CardContent,
208
236
  };
209
237
 
210
- export type { CardProps, CardSubComponentProps };
238
+ export type { CardProps, CardSubComponentProps, CardVariant };
@@ -2,28 +2,39 @@ import * as React from "react";
2
2
 
3
3
  import { cn } from "@brightlocal/ui-components/lib/utils";
4
4
 
5
+ /* -------------------------------------------------------------------------------------------------
6
+ * CentredLayout Root
7
+ * -----------------------------------------------------------------------------------------------*/
8
+
5
9
  /**
6
- * CentredLayout provides a responsive centered container with max-width constraints
7
- * based on different breakpoint sizes.
10
+ * CentredLayout provides a responsive centered container with max-width constraint.
8
11
  *
9
- * Breakpoints align with Tailwind's default breakpoints:
10
- * - XL: 1280px (max-w-7xl)
11
- * - LG: 1024px (max-w-5xl)
12
- * - MD: 768px (max-w-3xl)
13
- * - SM: 640px (max-w-2xl)
12
+ * Spacing tokens used:
13
+ * - Padding: p-6 (spacing.6 = 24px) all around
14
+ * - Header to content gap: gap-4 (spacing.4 = 16px)
15
+ * - Max width: max-w-7xl (1280px) by default
14
16
  *
15
- * The component centers content horizontally and applies consistent padding
16
- * across all breakpoints.
17
- */
18
-
19
- /**
20
- * Breakpoint variants for CentredLayout
21
- * - xl: Extra large breakpoint (1280px max-width)
22
- * - lg: Large breakpoint (1024px max-width)
23
- * - md: Medium breakpoint (768px max-width)
24
- * - sm: Small breakpoint (640px max-width)
17
+ * The component centers content horizontally and vertically.
18
+ *
19
+ * @example
20
+ * // Basic usage
21
+ * <CentredLayout dataHook="my-layout">
22
+ * <CentredLayoutContent>
23
+ * <Card>...</Card>
24
+ * </CentredLayoutContent>
25
+ * </CentredLayout>
26
+ *
27
+ * @example
28
+ * // With Header
29
+ * <CentredLayout dataHook="my-layout">
30
+ * <CentredLayoutHeader>
31
+ * <Header dataHook="my-header"><Logo /></Header>
32
+ * </CentredLayoutHeader>
33
+ * <CentredLayoutContent>
34
+ * <Card>...</Card>
35
+ * </CentredLayoutContent>
36
+ * </CentredLayout>
25
37
  */
26
- export type CentredLayoutBreakpoint = "xl" | "lg" | "md" | "sm";
27
38
 
28
39
  interface CentredLayoutProps extends React.ComponentProps<"div"> {
29
40
  /**
@@ -39,12 +50,7 @@ interface CentredLayoutProps extends React.ComponentProps<"div"> {
39
50
  */
40
51
  trackingLabel?: string;
41
52
  /**
42
- * Breakpoint size variant
43
- * @default "xl"
44
- */
45
- breakpoint?: CentredLayoutBreakpoint;
46
- /**
47
- * Custom max-width value (overrides breakpoint)
53
+ * Custom max-width value (overrides default 1280px)
48
54
  */
49
55
  maxWidth?: string | number;
50
56
  }
@@ -56,7 +62,6 @@ const CentredLayout = React.forwardRef<HTMLDivElement, CentredLayoutProps>(
56
62
  (
57
63
  {
58
64
  className,
59
- breakpoint = "xl",
60
65
  maxWidth,
61
66
  children,
62
67
  dataHook,
@@ -66,15 +71,7 @@ const CentredLayout = React.forwardRef<HTMLDivElement, CentredLayoutProps>(
66
71
  },
67
72
  ref
68
73
  ) => {
69
- // Map breakpoints to Tailwind max-width utility classes
70
- const breakpointMaxWidthClass: Record<CentredLayoutBreakpoint, string> = {
71
- xl: "max-w-7xl",
72
- lg: "max-w-5xl",
73
- md: "max-w-3xl",
74
- sm: "max-w-2xl",
75
- };
76
-
77
- // If custom maxWidth is provided, use inline style; otherwise use Tailwind class
74
+ // If custom maxWidth is provided, use inline style; otherwise use default max-w-7xl
78
75
  const maxWidthStyle =
79
76
  maxWidth !== undefined
80
77
  ? {
@@ -86,8 +83,9 @@ const CentredLayout = React.forwardRef<HTMLDivElement, CentredLayoutProps>(
86
83
  <div
87
84
  ref={ref}
88
85
  className={cn(
89
- "bg-background flex min-h-screen items-center justify-center p-6",
90
- !maxWidth && breakpointMaxWidthClass[breakpoint],
86
+ // Base styles with p-6 padding (container-padding-x token) and gap-4 for header/content spacing
87
+ "bg-background flex min-h-screen flex-col items-center justify-center gap-4 p-6",
88
+ !maxWidth && "max-w-7xl",
91
89
  className
92
90
  )}
93
91
  data-hook={dataHook}
@@ -105,6 +103,85 @@ const CentredLayout = React.forwardRef<HTMLDivElement, CentredLayoutProps>(
105
103
 
106
104
  CentredLayout.displayName = "CentredLayout";
107
105
 
108
- export { CentredLayout };
106
+ /* -------------------------------------------------------------------------------------------------
107
+ * CentredLayoutHeader
108
+ * -----------------------------------------------------------------------------------------------*/
109
+
110
+ interface CentredLayoutHeaderProps extends React.ComponentProps<"div"> {
111
+ /**
112
+ * Header content (e.g., Header component with Logo)
113
+ */
114
+ children: React.ReactNode;
115
+ }
116
+
117
+ /**
118
+ * CentredLayoutHeader component for rendering header content at the top of CentredLayout.
119
+ * Content is centered on mobile/tablet, left-aligned from lg breakpoint onwards.
120
+ */
121
+ const CentredLayoutHeader = React.forwardRef<
122
+ HTMLDivElement,
123
+ CentredLayoutHeaderProps
124
+ >(({ className, children, ...props }, ref) => {
125
+ return (
126
+ <div
127
+ ref={ref}
128
+ className={cn(
129
+ "flex w-full items-center justify-center lg:justify-start",
130
+ className
131
+ )}
132
+ data-slot="centred-layout-header"
133
+ {...props}
134
+ >
135
+ {children}
136
+ </div>
137
+ );
138
+ });
139
+
140
+ CentredLayoutHeader.displayName = "CentredLayoutHeader";
141
+
142
+ /* -------------------------------------------------------------------------------------------------
143
+ * CentredLayoutContent
144
+ * -----------------------------------------------------------------------------------------------*/
145
+
146
+ interface CentredLayoutContentProps extends React.ComponentProps<"div"> {
147
+ /**
148
+ * Main content to render inside the centered layout
149
+ */
150
+ children: React.ReactNode;
151
+ }
152
+
153
+ /**
154
+ * CentredLayoutContent component for rendering the main content area of CentredLayout.
155
+ */
156
+ const CentredLayoutContent = React.forwardRef<
157
+ HTMLDivElement,
158
+ CentredLayoutContentProps
159
+ >(({ className, children, ...props }, ref) => {
160
+ return (
161
+ <div
162
+ ref={ref}
163
+ className={cn(
164
+ "flex flex-1 flex-col items-center justify-center",
165
+ className
166
+ )}
167
+ data-slot="centred-layout-content"
168
+ {...props}
169
+ >
170
+ {children}
171
+ </div>
172
+ );
173
+ });
174
+
175
+ CentredLayoutContent.displayName = "CentredLayoutContent";
176
+
177
+ /* -------------------------------------------------------------------------------------------------
178
+ * Exports
179
+ * -----------------------------------------------------------------------------------------------*/
180
+
181
+ export { CentredLayout, CentredLayoutHeader, CentredLayoutContent };
109
182
 
110
- export type { CentredLayoutProps };
183
+ export type {
184
+ CentredLayoutProps,
185
+ CentredLayoutHeaderProps,
186
+ CentredLayoutContentProps,
187
+ };
@@ -3,7 +3,6 @@ import * as React from "react";
3
3
  import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
4
4
  import { CheckIcon } from "@brightlocal/icons";
5
5
  import { cva, type VariantProps } from "class-variance-authority";
6
-
7
6
  import { cn } from "@brightlocal/ui-components/lib/utils";
8
7
 
9
8
  const checkboxVariants = cva(
@@ -23,8 +22,8 @@ const checkboxVariants = cva(
23
22
  variants: {
24
23
  error: {
25
24
  true: [
26
- // Error state - red border with 40% opacity
27
- "border-destructive/40 dark:border-destructive/60",
25
+ // Error state - red-600 border with 40% opacity (light) / red-400 with 60% opacity (dark)
26
+ "border-red-600/40 dark:border-red-400/60",
28
27
  // Error focus state - solid red border with destructive shadow
29
28
  "focus-visible:border-destructive focus-visible:shadow-destructive",
30
29
  ],
@@ -0,0 +1,249 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import { cva } from "class-variance-authority";
5
+ import { X, LoaderCircle } from "@brightlocal/icons";
6
+
7
+ import { cn } from "@brightlocal/ui-components/lib/utils";
8
+ import {
9
+ Tooltip,
10
+ TooltipContent,
11
+ TooltipProvider,
12
+ TooltipTrigger,
13
+ } from "@brightlocal/ui-components/tooltip";
14
+
15
+ /**
16
+ * Chip size options
17
+ */
18
+ type ChipSize = "md" | "lg";
19
+
20
+ const chipVariants = cva(
21
+ [
22
+ // Base styles
23
+ "inline-flex",
24
+ "items-center",
25
+ "justify-center",
26
+ "gap-0.5",
27
+ "rounded-full",
28
+ "font-medium",
29
+ "whitespace-nowrap",
30
+ "shrink-0",
31
+ "select-none",
32
+ // Background and text colors
33
+ "bg-secondary",
34
+ "text-foreground",
35
+ // Transitions
36
+ "transition-[color,background-color,box-shadow]",
37
+ "duration-150",
38
+ "ease-in-out",
39
+ // Hover state
40
+ "hover:bg-secondary/80",
41
+ // Focus state - direct focus on chip (for keyboard navigation)
42
+ "focus:outline-none",
43
+ "focus-visible:shadow-default",
44
+ // Disabled state
45
+ "disabled:pointer-events-none",
46
+ "disabled:opacity-50",
47
+ "aria-disabled:pointer-events-none",
48
+ "aria-disabled:opacity-50",
49
+ ],
50
+ {
51
+ variants: {
52
+ size: {
53
+ md: ["h-7", "pl-2.5", "pr-1", "text-xs"],
54
+ lg: ["h-8", "pl-4", "pr-2", "text-base"],
55
+ },
56
+ },
57
+ defaultVariants: {
58
+ size: "md",
59
+ },
60
+ }
61
+ );
62
+
63
+ const chipDeleteButtonVariants = cva(
64
+ [
65
+ // Base styles
66
+ "inline-flex",
67
+ "items-center",
68
+ "justify-center",
69
+ "rounded-full",
70
+ "cursor-pointer",
71
+ // Colors
72
+ "text-muted-foreground",
73
+ // Hover
74
+ "hover:text-foreground",
75
+ // Focus
76
+ "outline-none",
77
+ "focus-visible:text-foreground",
78
+ // Disabled
79
+ "disabled:pointer-events-none",
80
+ "disabled:opacity-50",
81
+ ],
82
+ {
83
+ variants: {
84
+ size: {
85
+ md: ["size-6"],
86
+ lg: ["size-6"],
87
+ },
88
+ },
89
+ defaultVariants: {
90
+ size: "md",
91
+ },
92
+ }
93
+ );
94
+
95
+ /**
96
+ * Props for the Chip component
97
+ */
98
+ interface ChipProps extends Omit<React.ComponentProps<"div">, "children"> {
99
+ /**
100
+ * Chip content (text label)
101
+ */
102
+ children: React.ReactNode;
103
+ /**
104
+ * Size variant of the chip
105
+ * @default "md"
106
+ */
107
+ size?: ChipSize;
108
+ /**
109
+ * Show loading spinner instead of delete button
110
+ * @default false
111
+ */
112
+ loading?: boolean;
113
+ /**
114
+ * Disable the chip and its delete button
115
+ * @default false
116
+ */
117
+ disabled?: boolean;
118
+ /**
119
+ * Callback when delete button is clicked
120
+ */
121
+ onRemove?: (event: React.MouseEvent<HTMLButtonElement>) => void;
122
+ /**
123
+ * Data hook for automated testing (required)
124
+ */
125
+ dataHook: string;
126
+ /**
127
+ * Tracking element identifier for analytics
128
+ */
129
+ trackingEl?: string;
130
+ /**
131
+ * Tracking label for analytics context
132
+ */
133
+ trackingLabel?: string;
134
+ /**
135
+ * Maximum width of the chip label before truncation
136
+ * @default 200
137
+ */
138
+ maxWidth?: number;
139
+ }
140
+
141
+ /**
142
+ * Chip component for displaying removable tags or selections.
143
+ * Used for filter selections, tag lists, and multi-select values.
144
+ */
145
+ const Chip = React.forwardRef<HTMLDivElement, ChipProps>(
146
+ (
147
+ {
148
+ className,
149
+ children,
150
+ size = "md",
151
+ loading = false,
152
+ disabled = false,
153
+ onRemove,
154
+ dataHook,
155
+ trackingEl,
156
+ trackingLabel,
157
+ maxWidth = 200,
158
+ ...props
159
+ },
160
+ ref
161
+ ) => {
162
+ const isDisabled = disabled || loading;
163
+ const iconSize = size === "lg" ? 16 : 16;
164
+ const labelRef = React.useRef<HTMLSpanElement>(null);
165
+ const [isTruncated, setIsTruncated] = React.useState(false);
166
+
167
+ React.useEffect(() => {
168
+ const checkTruncation = () => {
169
+ if (labelRef.current) {
170
+ setIsTruncated(
171
+ labelRef.current.scrollWidth > labelRef.current.clientWidth
172
+ );
173
+ }
174
+ };
175
+
176
+ checkTruncation();
177
+ window.addEventListener("resize", checkTruncation);
178
+ return () => window.removeEventListener("resize", checkTruncation);
179
+ }, [children]);
180
+
181
+ const labelContent = (
182
+ <span
183
+ ref={labelRef}
184
+ className="truncate"
185
+ data-slot="chip-label"
186
+ style={{ maxWidth }}
187
+ >
188
+ {children}
189
+ </span>
190
+ );
191
+
192
+ return (
193
+ <div
194
+ ref={ref}
195
+ aria-disabled={isDisabled ? "true" : undefined}
196
+ className={cn(chipVariants({ size }), className)}
197
+ data-hook={dataHook}
198
+ data-slot="chip"
199
+ data-tracking-el={trackingEl}
200
+ data-tracking-label={trackingLabel}
201
+ {...props}
202
+ >
203
+ {isTruncated ? (
204
+ <TooltipProvider>
205
+ <Tooltip>
206
+ <TooltipTrigger asChild>{labelContent}</TooltipTrigger>
207
+ <TooltipContent dataHook={`${dataHook}-tooltip`} sideOffset={8}>
208
+ {children}
209
+ </TooltipContent>
210
+ </Tooltip>
211
+ </TooltipProvider>
212
+ ) : (
213
+ labelContent
214
+ )}
215
+ {loading ? (
216
+ <span
217
+ aria-label="Loading"
218
+ className={cn(chipDeleteButtonVariants({ size }))}
219
+ data-slot="chip-loading"
220
+ role="status"
221
+ >
222
+ <LoaderCircle
223
+ className="animate-spin motion-reduce:animate-none"
224
+ size={iconSize}
225
+ />
226
+ </span>
227
+ ) : (
228
+ <button
229
+ aria-label={`Remove ${typeof children === "string" ? children : "chip"}`}
230
+ className={cn(chipDeleteButtonVariants({ size }))}
231
+ data-slot="chip-delete"
232
+ data-tracking-el={trackingEl ? `${trackingEl}-delete` : undefined}
233
+ disabled={isDisabled}
234
+ tabIndex={-1}
235
+ type="button"
236
+ onClick={onRemove}
237
+ >
238
+ <X size={iconSize} />
239
+ </button>
240
+ )}
241
+ </div>
242
+ );
243
+ }
244
+ );
245
+
246
+ Chip.displayName = "Chip";
247
+
248
+ export { Chip, chipVariants };
249
+ export type { ChipProps, ChipSize };