@brightlocal/ui-components 0.1.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 (320) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +349 -0
  3. package/dist/accordion.cjs +1 -0
  4. package/dist/accordion.d.ts +32 -0
  5. package/dist/accordion.d.ts.map +1 -0
  6. package/dist/accordion.js +107 -0
  7. package/dist/alert-dialog.cjs +1 -0
  8. package/dist/alert-dialog.d.ts +15 -0
  9. package/dist/alert-dialog.d.ts.map +1 -0
  10. package/dist/alert-dialog.js +146 -0
  11. package/dist/alert.cjs +1 -0
  12. package/dist/alert.d.ts +16 -0
  13. package/dist/alert.d.ts.map +1 -0
  14. package/dist/alert.js +174 -0
  15. package/dist/aspect-ratio.cjs +1 -0
  16. package/dist/aspect-ratio.d.ts +10 -0
  17. package/dist/aspect-ratio.d.ts.map +1 -0
  18. package/dist/aspect-ratio.js +22 -0
  19. package/dist/avatar.cjs +1 -0
  20. package/dist/avatar.d.ts +11 -0
  21. package/dist/avatar.d.ts.map +1 -0
  22. package/dist/avatar.js +46 -0
  23. package/dist/badge.cjs +1 -0
  24. package/dist/badge.d.ts +19 -0
  25. package/dist/badge.d.ts.map +1 -0
  26. package/dist/badge.js +50 -0
  27. package/dist/blocks/data-table.cjs +1 -0
  28. package/dist/blocks/data-table.d.ts +303 -0
  29. package/dist/blocks/data-table.d.ts.map +1 -0
  30. package/dist/blocks/data-table.js +555 -0
  31. package/dist/blocks/sidebar.cjs +1 -0
  32. package/dist/blocks/sidebar.d.ts +744 -0
  33. package/dist/blocks/sidebar.d.ts.map +1 -0
  34. package/dist/blocks/sidebar.js +839 -0
  35. package/dist/breadcrumb.cjs +1 -0
  36. package/dist/breadcrumb.d.ts +12 -0
  37. package/dist/breadcrumb.d.ts.map +1 -0
  38. package/dist/breadcrumb.js +102 -0
  39. package/dist/button.cjs +1 -0
  40. package/dist/button.d.ts +73 -0
  41. package/dist/button.d.ts.map +1 -0
  42. package/dist/button.js +195 -0
  43. package/dist/calendar.cjs +1 -0
  44. package/dist/calendar.d.ts +28 -0
  45. package/dist/calendar.d.ts.map +1 -0
  46. package/dist/calendar.js +191 -0
  47. package/dist/card.cjs +1 -0
  48. package/dist/card.d.ts +28 -0
  49. package/dist/card.d.ts.map +1 -0
  50. package/dist/card.js +131 -0
  51. package/dist/carousel.cjs +1 -0
  52. package/dist/carousel.d.ts +21 -0
  53. package/dist/carousel.d.ts.map +1 -0
  54. package/dist/carousel.js +185 -0
  55. package/dist/centred-layout.cjs +1 -0
  56. package/dist/centred-layout.d.ts +49 -0
  57. package/dist/centred-layout.d.ts.map +1 -0
  58. package/dist/centred-layout.js +35 -0
  59. package/dist/chart.cjs +10 -0
  60. package/dist/chart.d.ts +83 -0
  61. package/dist/chart.d.ts.map +1 -0
  62. package/dist/chart.js +254 -0
  63. package/dist/checkbox.cjs +1 -0
  64. package/dist/checkbox.d.ts +15 -0
  65. package/dist/checkbox.d.ts.map +1 -0
  66. package/dist/checkbox.js +96 -0
  67. package/dist/collapsible.cjs +1 -0
  68. package/dist/collapsible.d.ts +18 -0
  69. package/dist/collapsible.d.ts.map +1 -0
  70. package/dist/collapsible.js +58 -0
  71. package/dist/combobox.cjs +1 -0
  72. package/dist/combobox.d.ts +65 -0
  73. package/dist/combobox.d.ts.map +1 -0
  74. package/dist/combobox.js +203 -0
  75. package/dist/command.cjs +1 -0
  76. package/dist/command.d.ts +44 -0
  77. package/dist/command.d.ts.map +1 -0
  78. package/dist/command.js +166 -0
  79. package/dist/context-menu.cjs +1 -0
  80. package/dist/context-menu.d.ts +42 -0
  81. package/dist/context-menu.d.ts.map +1 -0
  82. package/dist/context-menu.js +226 -0
  83. package/dist/date-picker.cjs +1 -0
  84. package/dist/date-picker.d.ts +54 -0
  85. package/dist/date-picker.d.ts.map +1 -0
  86. package/dist/date-picker.js +95 -0
  87. package/dist/dialog.cjs +1 -0
  88. package/dist/dialog.d.ts +20 -0
  89. package/dist/dialog.d.ts.map +1 -0
  90. package/dist/dialog.js +130 -0
  91. package/dist/drawer.cjs +1 -0
  92. package/dist/drawer.d.ts +22 -0
  93. package/dist/drawer.d.ts.map +1 -0
  94. package/dist/drawer.js +149 -0
  95. package/dist/dropdown-menu.cjs +1 -0
  96. package/dist/dropdown-menu.d.ts +253 -0
  97. package/dist/dropdown-menu.d.ts.map +1 -0
  98. package/dist/dropdown-menu.js +325 -0
  99. package/dist/field.cjs +1 -0
  100. package/dist/field.d.ts +21 -0
  101. package/dist/field.d.ts.map +1 -0
  102. package/dist/field.js +148 -0
  103. package/dist/global-layout.cjs +1 -0
  104. package/dist/global-layout.d.ts +60 -0
  105. package/dist/global-layout.d.ts.map +1 -0
  106. package/dist/global-layout.js +87 -0
  107. package/dist/hooks/use-mobile.cjs +1 -0
  108. package/dist/hooks/use-mobile.d.ts +2 -0
  109. package/dist/hooks/use-mobile.d.ts.map +1 -0
  110. package/dist/hooks/use-mobile.js +16 -0
  111. package/dist/hover-card.cjs +1 -0
  112. package/dist/hover-card.d.ts +43 -0
  113. package/dist/hover-card.d.ts.map +1 -0
  114. package/dist/hover-card.js +71 -0
  115. package/dist/index.cjs +1 -0
  116. package/dist/index.d.ts +61 -0
  117. package/dist/index.d.ts.map +1 -0
  118. package/dist/index.js +412 -0
  119. package/dist/input-base.cjs +1 -0
  120. package/dist/input-base.d.ts +28 -0
  121. package/dist/input-base.d.ts.map +1 -0
  122. package/dist/input-base.js +56 -0
  123. package/dist/input-group.cjs +1 -0
  124. package/dist/input-group.d.ts +26 -0
  125. package/dist/input-group.d.ts.map +1 -0
  126. package/dist/input-group.js +116 -0
  127. package/dist/input-otp.cjs +1 -0
  128. package/dist/input-otp.d.ts +45 -0
  129. package/dist/input-otp.d.ts.map +1 -0
  130. package/dist/input-otp.js +186 -0
  131. package/dist/input-password.cjs +1 -0
  132. package/dist/input-password.d.ts +38 -0
  133. package/dist/input-password.d.ts.map +1 -0
  134. package/dist/input-password.js +101 -0
  135. package/dist/input.cjs +1 -0
  136. package/dist/input.d.ts +32 -0
  137. package/dist/input.d.ts.map +1 -0
  138. package/dist/input.js +146 -0
  139. package/dist/label.cjs +1 -0
  140. package/dist/label.d.ts +12 -0
  141. package/dist/label.d.ts.map +1 -0
  142. package/dist/label.js +34 -0
  143. package/dist/lib/utils.cjs +1 -0
  144. package/dist/lib/utils.d.ts +3 -0
  145. package/dist/lib/utils.d.ts.map +1 -0
  146. package/dist/lib/utils.js +8 -0
  147. package/dist/link.cjs +1 -0
  148. package/dist/link.d.ts +29 -0
  149. package/dist/link.d.ts.map +1 -0
  150. package/dist/link.figma.d.ts +2 -0
  151. package/dist/link.figma.d.ts.map +1 -0
  152. package/dist/link.js +71 -0
  153. package/dist/logo.cjs +1 -0
  154. package/dist/logo.d.ts +25 -0
  155. package/dist/logo.d.ts.map +1 -0
  156. package/dist/logo.js +71 -0
  157. package/dist/menubar.cjs +1 -0
  158. package/dist/menubar.d.ts +106 -0
  159. package/dist/menubar.d.ts.map +1 -0
  160. package/dist/menubar.js +270 -0
  161. package/dist/navigation-menu.cjs +1 -0
  162. package/dist/navigation-menu.d.ts +108 -0
  163. package/dist/navigation-menu.d.ts.map +1 -0
  164. package/dist/navigation-menu.js +175 -0
  165. package/dist/pagination.cjs +1 -0
  166. package/dist/pagination.d.ts +81 -0
  167. package/dist/pagination.d.ts.map +1 -0
  168. package/dist/pagination.js +216 -0
  169. package/dist/popover.cjs +1 -0
  170. package/dist/popover.d.ts +8 -0
  171. package/dist/popover.d.ts.map +1 -0
  172. package/dist/popover.js +44 -0
  173. package/dist/progress.cjs +1 -0
  174. package/dist/progress.d.ts +29 -0
  175. package/dist/progress.d.ts.map +1 -0
  176. package/dist/progress.js +64 -0
  177. package/dist/radio-group.cjs +1 -0
  178. package/dist/radio-group.d.ts +33 -0
  179. package/dist/radio-group.d.ts.map +1 -0
  180. package/dist/radio-group.js +193 -0
  181. package/dist/rating.cjs +1 -0
  182. package/dist/rating.d.ts +22 -0
  183. package/dist/rating.d.ts.map +1 -0
  184. package/dist/rating.js +51 -0
  185. package/dist/resizable.cjs +1 -0
  186. package/dist/resizable.d.ts +14 -0
  187. package/dist/resizable.d.ts.map +1 -0
  188. package/dist/resizable.js +46 -0
  189. package/dist/scroll-area.cjs +1 -0
  190. package/dist/scroll-area.d.ts +12 -0
  191. package/dist/scroll-area.d.ts.map +1 -0
  192. package/dist/scroll-area.js +67 -0
  193. package/dist/select.cjs +1 -0
  194. package/dist/select.d.ts +77 -0
  195. package/dist/select.d.ts.map +1 -0
  196. package/dist/select.js +259 -0
  197. package/dist/separator.cjs +1 -0
  198. package/dist/separator.d.ts +14 -0
  199. package/dist/separator.d.ts.map +1 -0
  200. package/dist/separator.js +43 -0
  201. package/dist/sheet.cjs +1 -0
  202. package/dist/sheet.d.ts +38 -0
  203. package/dist/sheet.d.ts.map +1 -0
  204. package/dist/sheet.js +190 -0
  205. package/dist/skeleton.cjs +1 -0
  206. package/dist/skeleton.d.ts +5 -0
  207. package/dist/skeleton.d.ts.map +1 -0
  208. package/dist/skeleton.js +15 -0
  209. package/dist/slider.cjs +1 -0
  210. package/dist/slider.d.ts +19 -0
  211. package/dist/slider.d.ts.map +1 -0
  212. package/dist/slider.js +69 -0
  213. package/dist/sonner.cjs +1 -0
  214. package/dist/sonner.d.ts +188 -0
  215. package/dist/sonner.d.ts.map +1 -0
  216. package/dist/sonner.js +150 -0
  217. package/dist/split-layout.cjs +1 -0
  218. package/dist/split-layout.d.ts +42 -0
  219. package/dist/split-layout.d.ts.map +1 -0
  220. package/dist/split-layout.js +108 -0
  221. package/dist/switch.cjs +1 -0
  222. package/dist/switch.d.ts +43 -0
  223. package/dist/switch.d.ts.map +1 -0
  224. package/dist/switch.figma.d.ts +2 -0
  225. package/dist/switch.figma.d.ts.map +1 -0
  226. package/dist/switch.js +110 -0
  227. package/dist/table.cjs +1 -0
  228. package/dist/table.d.ts +95 -0
  229. package/dist/table.d.ts.map +1 -0
  230. package/dist/table.js +164 -0
  231. package/dist/tabs.cjs +1 -0
  232. package/dist/tabs.d.ts +29 -0
  233. package/dist/tabs.d.ts.map +1 -0
  234. package/dist/tabs.js +96 -0
  235. package/dist/textarea.cjs +1 -0
  236. package/dist/textarea.d.ts +23 -0
  237. package/dist/textarea.d.ts.map +1 -0
  238. package/dist/textarea.js +47 -0
  239. package/dist/toggle-group.cjs +1 -0
  240. package/dist/toggle-group.d.ts +25 -0
  241. package/dist/toggle-group.d.ts.map +1 -0
  242. package/dist/toggle-group.js +74 -0
  243. package/dist/toggle.cjs +1 -0
  244. package/dist/toggle.d.ts +44 -0
  245. package/dist/toggle.d.ts.map +1 -0
  246. package/dist/toggle.figma.d.ts +2 -0
  247. package/dist/toggle.figma.d.ts.map +1 -0
  248. package/dist/toggle.js +57 -0
  249. package/dist/tooltip.cjs +1 -0
  250. package/dist/tooltip.d.ts +66 -0
  251. package/dist/tooltip.d.ts.map +1 -0
  252. package/dist/tooltip.js +78 -0
  253. package/package.json +184 -0
  254. package/src/blocks/data-table.tsx +1166 -0
  255. package/src/blocks/sidebar.tsx +1830 -0
  256. package/src/components/.gitkeep +0 -0
  257. package/src/components/accordion.tsx +142 -0
  258. package/src/components/alert-dialog.tsx +157 -0
  259. package/src/components/alert.tsx +199 -0
  260. package/src/components/aspect-ratio.tsx +30 -0
  261. package/src/components/avatar.tsx +56 -0
  262. package/src/components/badge.tsx +72 -0
  263. package/src/components/breadcrumb.tsx +109 -0
  264. package/src/components/button.tsx +296 -0
  265. package/src/components/calendar.tsx +234 -0
  266. package/src/components/card.tsx +158 -0
  267. package/src/components/carousel.tsx +256 -0
  268. package/src/components/centred-layout.tsx +91 -0
  269. package/src/components/chart.tsx +456 -0
  270. package/src/components/checkbox.tsx +132 -0
  271. package/src/components/collapsible.tsx +68 -0
  272. package/src/components/combobox.tsx +321 -0
  273. package/src/components/command.tsx +220 -0
  274. package/src/components/context-menu.tsx +305 -0
  275. package/src/components/date-picker.tsx +155 -0
  276. package/src/components/dialog.tsx +152 -0
  277. package/src/components/drawer.tsx +168 -0
  278. package/src/components/dropdown-menu.tsx +575 -0
  279. package/src/components/field.tsx +155 -0
  280. package/src/components/global-layout.tsx +153 -0
  281. package/src/components/hover-card.tsx +121 -0
  282. package/src/components/input-base.tsx +86 -0
  283. package/src/components/input-group.tsx +158 -0
  284. package/src/components/input-otp.tsx +327 -0
  285. package/src/components/input-password.tsx +191 -0
  286. package/src/components/input.tsx +220 -0
  287. package/src/components/label.tsx +42 -0
  288. package/src/components/link.figma.tsx +71 -0
  289. package/src/components/link.tsx +105 -0
  290. package/src/components/logo.tsx +97 -0
  291. package/src/components/menubar.tsx +379 -0
  292. package/src/components/navigation-menu.tsx +324 -0
  293. package/src/components/pagination.tsx +368 -0
  294. package/src/components/popover.tsx +46 -0
  295. package/src/components/progress.tsx +100 -0
  296. package/src/components/radio-group.tsx +281 -0
  297. package/src/components/rating.tsx +87 -0
  298. package/src/components/resizable.tsx +66 -0
  299. package/src/components/scroll-area.tsx +72 -0
  300. package/src/components/select.tsx +442 -0
  301. package/src/components/separator.tsx +53 -0
  302. package/src/components/sheet.tsx +220 -0
  303. package/src/components/skeleton.tsx +17 -0
  304. package/src/components/slider.tsx +86 -0
  305. package/src/components/sonner.tsx +396 -0
  306. package/src/components/split-layout.tsx +155 -0
  307. package/src/components/switch.figma.tsx +115 -0
  308. package/src/components/switch.tsx +173 -0
  309. package/src/components/table.tsx +277 -0
  310. package/src/components/tabs.tsx +142 -0
  311. package/src/components/textarea.tsx +77 -0
  312. package/src/components/toggle-group.tsx +109 -0
  313. package/src/components/toggle.figma.tsx +81 -0
  314. package/src/components/toggle.tsx +103 -0
  315. package/src/components/tooltip.tsx +156 -0
  316. package/src/hooks/.gitkeep +0 -0
  317. package/src/hooks/use-mobile.ts +21 -0
  318. package/src/index.ts +67 -0
  319. package/src/lib/utils.ts +6 -0
  320. package/src/types/external-modules.d.ts +16 -0
@@ -0,0 +1,17 @@
1
+ import { cn } from "@brightlocal/ui-components/lib/utils";
2
+
3
+ type SkeletonProps = React.ComponentProps<"div">;
4
+
5
+ function Skeleton({ className, ...props }: SkeletonProps) {
6
+ return (
7
+ <div
8
+ className={cn("bg-accent animate-pulse rounded-md", className)}
9
+ data-slot="skeleton"
10
+ {...props}
11
+ />
12
+ );
13
+ }
14
+
15
+ export { Skeleton };
16
+
17
+ export type { SkeletonProps };
@@ -0,0 +1,86 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import * as SliderPrimitive from "@radix-ui/react-slider";
5
+
6
+ import { cn } from "@brightlocal/ui-components/lib/utils";
7
+
8
+ export interface SliderProps extends React.ComponentProps<
9
+ typeof SliderPrimitive.Root
10
+ > {
11
+ /**
12
+ * Required data-hook attribute for testing and analytics
13
+ */
14
+ dataHook: string;
15
+ /**
16
+ * Optional analytics element identifier
17
+ */
18
+ trackingEl?: string;
19
+ /**
20
+ * Optional analytics label context
21
+ */
22
+ trackingLabel?: string;
23
+ }
24
+
25
+ function Slider({
26
+ className,
27
+ dataHook,
28
+ defaultValue,
29
+ max = 100,
30
+ min = 0,
31
+ trackingEl,
32
+ trackingLabel,
33
+ value,
34
+ ...props
35
+ }: SliderProps) {
36
+ const _values = React.useMemo(
37
+ () =>
38
+ Array.isArray(value)
39
+ ? value
40
+ : Array.isArray(defaultValue)
41
+ ? defaultValue
42
+ : [min, max],
43
+ [value, defaultValue, min, max]
44
+ );
45
+
46
+ return (
47
+ <SliderPrimitive.Root
48
+ className={cn(
49
+ "relative flex w-full touch-none items-center select-none data-[disabled]:opacity-50 data-[orientation=vertical]:h-full data-[orientation=vertical]:min-h-44 data-[orientation=vertical]:w-auto data-[orientation=vertical]:flex-col",
50
+ className
51
+ )}
52
+ data-hook={dataHook}
53
+ data-slot="slider"
54
+ data-tracking-el={trackingEl}
55
+ data-tracking-label={trackingLabel}
56
+ defaultValue={defaultValue}
57
+ max={max}
58
+ min={min}
59
+ value={value}
60
+ {...props}
61
+ >
62
+ <SliderPrimitive.Track
63
+ className={cn(
64
+ "bg-muted relative grow overflow-hidden rounded-full data-[orientation=horizontal]:h-1.5 data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-1.5"
65
+ )}
66
+ data-slot="slider-track"
67
+ >
68
+ <SliderPrimitive.Range
69
+ className={cn(
70
+ "bg-primary absolute data-[orientation=horizontal]:h-full data-[orientation=vertical]:w-full"
71
+ )}
72
+ data-slot="slider-range"
73
+ />
74
+ </SliderPrimitive.Track>
75
+ {Array.from({ length: _values.length }, (_, index) => (
76
+ <SliderPrimitive.Thumb
77
+ key={index}
78
+ className="border-primary bg-background ring-ring/50 block size-4 shrink-0 rounded-full border shadow-sm transition-[color,box-shadow] hover:ring-4 focus-visible:ring-4 focus-visible:outline-hidden disabled:pointer-events-none disabled:opacity-50"
79
+ data-slot="slider-thumb"
80
+ />
81
+ ))}
82
+ </SliderPrimitive.Root>
83
+ );
84
+ }
85
+
86
+ export { Slider };
@@ -0,0 +1,396 @@
1
+ "use client";
2
+
3
+ import {
4
+ AlertTriangle,
5
+ CheckCircle2,
6
+ Info,
7
+ Loader2,
8
+ XCircle,
9
+ } from "lucide-react";
10
+ import { cva } from "class-variance-authority";
11
+ import { toast as sonnerToast, Toaster as SonnerToaster } from "sonner";
12
+
13
+ import {
14
+ Button,
15
+ ButtonVariant,
16
+ ButtonSize,
17
+ } from "@brightlocal/ui-components/button";
18
+ import { cn } from "@brightlocal/ui-components/lib/utils";
19
+
20
+ /**
21
+ * Internal props for the Toast component.
22
+ * Includes the `id` field which is managed internally by Sonner.
23
+ * @internal
24
+ */
25
+ type ToastProps = {
26
+ /** Internal toast ID assigned by Sonner */
27
+ id: string | number;
28
+ /** The main heading text of the toast */
29
+ title: string;
30
+ /** Optional description text displayed below the title */
31
+ description?: string;
32
+ /** Optional action button configuration */
33
+ button?: {
34
+ /** Button label text */
35
+ label?: string;
36
+ /** Click handler for the button */
37
+ onClick?: () => void;
38
+ /** Visual variant of the button */
39
+ variant?: ButtonVariant;
40
+ };
41
+ /** Color theme for the toast */
42
+ colorSchema?: SonnerColorSchema;
43
+ /** Icon to display in the toast */
44
+ icon?: ToastIconType | null;
45
+ };
46
+
47
+ export enum SonnerIcon {
48
+ INFO = "info",
49
+ SUCCESS = "success",
50
+ WARNING = "warning",
51
+ ERROR = "error",
52
+ LOADING = "loading",
53
+ }
54
+
55
+ export type ToastIconType = SonnerIcon | null;
56
+
57
+ export enum SonnerColorSchema {
58
+ DEFAULT = "default",
59
+ SUCCESS = "success",
60
+ }
61
+
62
+ type SonnerCustomOptions = {
63
+ className?: string;
64
+ id?: string | number;
65
+ };
66
+
67
+ /**
68
+ * Input type for creating a toast. The `id` is optional as it will be generated if not provided.
69
+ */
70
+ type ToastInput = Omit<ToastProps, "id"> & { id?: string | number };
71
+
72
+ // CVA variant definitions extracted for reusability and testing
73
+ const CONTAINER_VARIANTS = cva(
74
+ [
75
+ "flex",
76
+ "items-center",
77
+ "justify-between",
78
+ "w-full",
79
+ "md:w-auto",
80
+ "md:min-w-[364px]",
81
+ "rounded-md",
82
+ "border",
83
+ "border-border",
84
+ "p-4",
85
+ "gap-2",
86
+ "shadow-lg",
87
+ ].join(" "),
88
+ {
89
+ variants: {
90
+ colorSchema: {
91
+ default: "bg-white dark:bg-popover",
92
+ success: "bg-green-200 dark:bg-popover",
93
+ },
94
+ },
95
+ defaultVariants: {
96
+ colorSchema: "default",
97
+ },
98
+ }
99
+ );
100
+
101
+ const TITLE_VARIANTS = cva("text-sm leading-normal font-medium", {
102
+ variants: {
103
+ colorSchema: {
104
+ default: "text-foreground",
105
+ success: "text-green-900",
106
+ },
107
+ },
108
+ defaultVariants: {
109
+ colorSchema: "default",
110
+ },
111
+ });
112
+
113
+ const DESCRIPTION_VARIANTS = cva("text-sm leading-normal", {
114
+ variants: {
115
+ colorSchema: {
116
+ default: "text-muted-foreground",
117
+ success: "text-green-900",
118
+ },
119
+ },
120
+ defaultVariants: {
121
+ colorSchema: "default",
122
+ },
123
+ });
124
+
125
+ const ICON_VARIANTS = cva("size-5", {
126
+ variants: {
127
+ colorSchema: {
128
+ default: "text-foreground",
129
+ success: "text-green-900",
130
+ },
131
+ },
132
+ defaultVariants: {
133
+ colorSchema: "default",
134
+ },
135
+ });
136
+
137
+ /**
138
+ * Renders the appropriate icon for a toast based on the icon type.
139
+ * Extracted as a standalone utility for reusability.
140
+ *
141
+ * @param type - The type of icon to render (from SonnerIcon enum or null)
142
+ * @param schema - The color schema to apply to the icon
143
+ * @returns The rendered icon component or null
144
+ */
145
+ function renderToastIcon(type: ToastIconType, schema: "default" | "success") {
146
+ switch (type) {
147
+ case SonnerIcon.INFO:
148
+ return <Info className={cn(ICON_VARIANTS({ colorSchema: schema }))} />;
149
+ case SonnerIcon.SUCCESS:
150
+ return (
151
+ <CheckCircle2 className={cn(ICON_VARIANTS({ colorSchema: schema }))} />
152
+ );
153
+ case SonnerIcon.WARNING:
154
+ return (
155
+ <AlertTriangle className={cn(ICON_VARIANTS({ colorSchema: schema }))} />
156
+ );
157
+ case SonnerIcon.ERROR:
158
+ return <XCircle className={cn(ICON_VARIANTS({ colorSchema: schema }))} />;
159
+ case SonnerIcon.LOADING:
160
+ return (
161
+ <Loader2
162
+ className={cn(ICON_VARIANTS({ colorSchema: schema }), "animate-spin")}
163
+ />
164
+ );
165
+ default:
166
+ return null;
167
+ }
168
+ }
169
+
170
+ function sonner(toast: ToastInput, options?: SonnerCustomOptions): void {
171
+ const { id: providedId, ...rest } = toast;
172
+ const mergedOptions: SonnerCustomOptions | undefined =
173
+ providedId != null
174
+ ? { ...options, id: options?.id ?? providedId }
175
+ : options;
176
+
177
+ sonnerToast.custom((id) => {
178
+ // Wrap button onClick to include dismiss logic
179
+ const buttonWithDismiss =
180
+ rest.button && rest.button.label
181
+ ? {
182
+ label: rest.button.label,
183
+ variant: rest.button.variant,
184
+ onClick: () => {
185
+ if (rest.button?.onClick) {
186
+ rest.button.onClick();
187
+ }
188
+ sonnerToast.dismiss(id);
189
+ },
190
+ }
191
+ : undefined;
192
+
193
+ return (
194
+ <Toast
195
+ button={buttonWithDismiss}
196
+ colorSchema={rest.colorSchema}
197
+ description={rest.description}
198
+ icon={rest.icon ?? undefined}
199
+ id={id}
200
+ title={rest.title}
201
+ />
202
+ );
203
+ }, mergedOptions);
204
+ }
205
+
206
+ /**
207
+ * Internal Toast component that renders the custom toast UI.
208
+ * This component is not meant to be used directly - use the `sonner()` function instead.
209
+ *
210
+ * @internal
211
+ * @param props - Toast properties
212
+ * @returns Rendered toast component
213
+ */
214
+ function Toast(props: ToastProps) {
215
+ const { button, description, icon, title, colorSchema } = props;
216
+
217
+ const resolveSchema = (schema?: SonnerColorSchema): "default" | "success" =>
218
+ schema === SonnerColorSchema.SUCCESS ? "success" : "default";
219
+
220
+ const schema = resolveSchema(colorSchema);
221
+
222
+ return (
223
+ <div
224
+ aria-atomic="true"
225
+ aria-live="polite"
226
+ className={cn(CONTAINER_VARIANTS({ colorSchema: schema }))}
227
+ role="status"
228
+ >
229
+ <div className="flex flex-1 items-start gap-2">
230
+ {icon !== null && icon !== undefined && renderToastIcon(icon, schema)}
231
+ <div className="w-full">
232
+ <p className={cn(TITLE_VARIANTS({ colorSchema: schema }))}>{title}</p>
233
+ {description && (
234
+ <p className={cn(DESCRIPTION_VARIANTS({ colorSchema: schema }))}>
235
+ {description}
236
+ </p>
237
+ )}
238
+ </div>
239
+ </div>
240
+
241
+ {button?.label && (
242
+ <Button
243
+ aria-label={button.label}
244
+ className="min-h-6 px-2 py-0 text-xs leading-normal font-medium"
245
+ dataHook="toast-action"
246
+ size={ButtonSize.DEFAULT}
247
+ variant={button.variant}
248
+ onClick={button.onClick}
249
+ >
250
+ {button.label}
251
+ </Button>
252
+ )}
253
+ </div>
254
+ );
255
+ }
256
+
257
+ /**
258
+ * Sonner toaster component that must be mounted once in your application root.
259
+ * This component manages the toast container and handles toast display, stacking, and animations.
260
+ *
261
+ * **Important - Mounting Location:**
262
+ * Always mount <Sonner /> at the root level of your app or at the story decorator level in Storybook.
263
+ * DO NOT mount it inside individual components, as this will break the fixed positioning.
264
+ * The component needs to be a direct child of the body/root to position correctly relative to the viewport.
265
+ *
266
+ * **Animations:**
267
+ * Entry and exit animations are automatically handled by the underlying Sonner library.
268
+ * Toasts slide in from top-right and fade out when dismissed.
269
+ * No additional animation classes or configuration are required - animations work out of the box.
270
+ * The library provides smooth, performant transitions using CSS transforms and opacity.
271
+ *
272
+ * @example
273
+ * // CORRECT: Mount in your app root (App.tsx or layout.tsx)
274
+ * import { Sonner } from '@brightlocal/ui-components/sonner';
275
+ *
276
+ * function App() {
277
+ * return (
278
+ * <>
279
+ * <Sonner />
280
+ * <YourAppContent />
281
+ * </>
282
+ * );
283
+ * }
284
+ *
285
+ * @example
286
+ * // CORRECT: In Storybook, mount in decorator
287
+ * const meta: Meta = {
288
+ * decorators: [
289
+ * (Story) => (
290
+ * <>
291
+ * <Sonner />
292
+ * <Story />
293
+ * </>
294
+ * ),
295
+ * ],
296
+ * };
297
+ *
298
+ * @example
299
+ * // WRONG: Do not mount inside components
300
+ * function MyComponent() {
301
+ * return (
302
+ * <>
303
+ * <Sonner />
304
+ * <div>Content</div>
305
+ * </>
306
+ * );
307
+ * }
308
+ *
309
+ * @example
310
+ * // Then use sonner() anywhere in your app
311
+ * import { sonner, SonnerIcon } from '@brightlocal/ui-components/sonner';
312
+ *
313
+ * function MyComponent() {
314
+ * const handleClick = () => {
315
+ * sonner({
316
+ * title: "Success!",
317
+ * icon: SonnerIcon.SUCCESS
318
+ * });
319
+ * };
320
+ *
321
+ * return <button onClick={handleClick}>Show Toast</button>;
322
+ * }
323
+ */
324
+ function Sonner() {
325
+ return <SonnerToaster position="top-right" />;
326
+ }
327
+
328
+ /**
329
+ * @module Sonner
330
+ *
331
+ * A custom toast notification system built on top of Sonner library.
332
+ * Provides a fully styled, accessible toast component with support for:
333
+ * - Multiple icon types (info, success, warning, error, loading)
334
+ * - Action buttons
335
+ * - Color schemas
336
+ * - Dark mode
337
+ * - Customizable positioning and timing
338
+ *
339
+ * @example
340
+ * ```tsx
341
+ * // 1. Mount the Sonner component in your app root
342
+ * import { Sonner } from '@brightlocal/ui-components/sonner';
343
+ * import { toast } from 'sonner';
344
+ *
345
+ * <Sonner />
346
+ *
347
+ * // 2. Show toasts anywhere in your app
348
+ * import { sonner, SonnerIcon, SonnerColorSchema } from '@brightlocal/ui-components/sonner';
349
+ *
350
+ * // Simple toast
351
+ * sonner({ title: "Hello world" });
352
+ *
353
+ * // Success toast with action
354
+ * sonner({
355
+ * title: "Changes saved",
356
+ * description: "Your changes have been saved successfully.",
357
+ * icon: SonnerIcon.SUCCESS,
358
+ * colorSchema: SonnerColorSchema.SUCCESS,
359
+ * button: {
360
+ * label: "Undo",
361
+ * onClick: () => undoChanges()
362
+ * }
363
+ * });
364
+ *
365
+ * // Loading toast that updates when operation completes
366
+ * // Note: Store the toast ID to update or dismiss the loading toast
367
+ * const loadingToastId = 'upload-operation';
368
+ *
369
+ * // Show loading toast
370
+ * sonner({
371
+ * title: "Uploading...",
372
+ * description: "Please wait while we upload your file.",
373
+ * icon: SonnerIcon.LOADING,
374
+ * id: loadingToastId
375
+ * });
376
+ *
377
+ * // After operation completes, dismiss the loading toast and show success
378
+ * try {
379
+ * await uploadFile();
380
+ * toast.dismiss(loadingToastId);
381
+ * sonner({
382
+ * title: "Upload complete!",
383
+ * icon: SonnerIcon.SUCCESS,
384
+ * colorSchema: SonnerColorSchema.SUCCESS
385
+ * });
386
+ * } catch (error) {
387
+ * toast.dismiss(loadingToastId);
388
+ * sonner({
389
+ * title: "Upload failed",
390
+ * description: error.message,
391
+ * icon: SonnerIcon.ERROR
392
+ * });
393
+ * }
394
+ * ```
395
+ */
396
+ export { sonner, Sonner };
@@ -0,0 +1,155 @@
1
+ import * as React from "react";
2
+ import { cva } from "class-variance-authority";
3
+ import { cn } from "@brightlocal/ui-components/lib/utils";
4
+
5
+ // Outer wrapper - allows backgrounds to extend full-width
6
+ const splitLayoutVariants = [
7
+ "flex",
8
+ "w-full",
9
+ "min-h-screen",
10
+ // Responsive behavior: stack on small screens, side-by-side on large
11
+ "flex-col",
12
+ "lg:flex-row",
13
+ ];
14
+
15
+ // Background section - extends full-width with background color
16
+ const splitLayoutSectionVariants = cva(
17
+ ["flex", "flex-1", "items-center", "overflow-auto", "p-6"],
18
+ {
19
+ variants: {
20
+ side: {
21
+ left: [
22
+ "bg-background", // base/background token
23
+ "justify-center", // Center on mobile
24
+ "lg:justify-end", // Align to right on large screens
25
+ "lg:pr-[46px]", // 46px spacing from right edge on LG
26
+ "xl:pr-[110px]", // 110px spacing from right edge on XL and bigger
27
+ ],
28
+ right: [
29
+ "bg-card", // base/card token (handles both light and dark modes)
30
+ "hidden", // Hidden on mobile (MD and SM breakpoints)
31
+ "lg:flex", // Visible on large screens (LG and XL breakpoints)
32
+ "justify-center", // Center on mobile
33
+ "lg:justify-start", // Align to left on large screens
34
+ "lg:pl-[46px]", // 46px spacing from left edge on LG
35
+ "xl:pl-[110px]", // 110px spacing from left edge on XL and bigger
36
+ ],
37
+ },
38
+ },
39
+ defaultVariants: {
40
+ side: "left",
41
+ },
42
+ }
43
+ );
44
+
45
+ interface SplitLayoutProps extends React.ComponentProps<"div"> {
46
+ /** Data hook for automated testing (REQUIRED) */
47
+ dataHook: string;
48
+ /** Tracking element identifier for analytics */
49
+ trackingEl?: string;
50
+ /** Tracking label for analytics context */
51
+ trackingLabel?: string;
52
+ /** Content for the left/first section */
53
+ left?: React.ReactNode;
54
+ /** Content for the right/second section */
55
+ right?: React.ReactNode;
56
+ }
57
+
58
+ /**
59
+ * SplitLayout component for creating responsive two-column layouts
60
+ *
61
+ * Displays content in two sections side-by-side on large screens (≥1024px),
62
+ * and shows only the left section on smaller screens (hiding the right/marketing section).
63
+ * This pattern is commonly used for authentication pages where the form is prioritized on mobile.
64
+ *
65
+ * Layout specifications:
66
+ * - Mobile/Tablet: Stacked layout, only left section visible, content centered
67
+ * - LG (≥1024px): Side-by-side with 46px spacing on each side (92px total gap)
68
+ * - XL (≥1280px) and bigger: Side-by-side with 110px spacing on each side (220px total gap max)
69
+ * - Left section: Content aligned to right edge with responsive padding
70
+ * - Right section: Content aligned to left edge with responsive padding
71
+ * - Background colors extend full-width of viewport
72
+ * - Content within each section can be independently sized (e.g., using Card components)
73
+ */
74
+ const SplitLayout = React.forwardRef<HTMLDivElement, SplitLayoutProps>(
75
+ (
76
+ {
77
+ className,
78
+ dataHook,
79
+ trackingEl,
80
+ trackingLabel,
81
+ left,
82
+ right,
83
+ children,
84
+ ...props
85
+ },
86
+ ref
87
+ ) => {
88
+ return (
89
+ <div
90
+ ref={ref}
91
+ className={cn(splitLayoutVariants, className)}
92
+ data-hook={dataHook}
93
+ data-slot="split-layout"
94
+ data-tracking-el={trackingEl || "split-layout"}
95
+ data-tracking-label={trackingLabel}
96
+ {...props}
97
+ >
98
+ {left && (
99
+ <div
100
+ className={splitLayoutSectionVariants({ side: "left" })}
101
+ data-slot="split-layout-left"
102
+ >
103
+ {left}
104
+ </div>
105
+ )}
106
+ {right && (
107
+ <div
108
+ className={splitLayoutSectionVariants({ side: "right" })}
109
+ data-slot="split-layout-right"
110
+ >
111
+ {right}
112
+ </div>
113
+ )}
114
+ {children}
115
+ </div>
116
+ );
117
+ }
118
+ );
119
+
120
+ SplitLayout.displayName = "SplitLayout";
121
+
122
+ interface SplitLayoutSectionProps extends React.ComponentProps<"div"> {
123
+ /** Which side this section appears on */
124
+ side?: "left" | "right";
125
+ }
126
+
127
+ /**
128
+ * SplitLayoutSection - Individual section within a SplitLayout
129
+ *
130
+ * Use this for more granular control over layout sections
131
+ */
132
+ const SplitLayoutSection = React.forwardRef<
133
+ HTMLDivElement,
134
+ SplitLayoutSectionProps
135
+ >(({ className, side = "left", children, ...props }, ref) => {
136
+ return (
137
+ <div
138
+ ref={ref}
139
+ className={cn(splitLayoutSectionVariants({ side }), className)}
140
+ data-slot={`split-layout-${side}`}
141
+ {...props}
142
+ >
143
+ {children}
144
+ </div>
145
+ );
146
+ });
147
+
148
+ SplitLayoutSection.displayName = "SplitLayoutSection";
149
+
150
+ export {
151
+ SplitLayout,
152
+ SplitLayoutSection,
153
+ type SplitLayoutProps,
154
+ type SplitLayoutSectionProps,
155
+ };