@dust-tt/sparkle 0.2.270 → 0.2.272-rc-1

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 (132) hide show
  1. package/dist/cjs/index.js +8197 -8287
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/esm/components/AssistantPreview.d.ts.map +1 -1
  4. package/dist/esm/components/AssistantPreview.js +1 -1
  5. package/dist/esm/components/AssistantPreview.js.map +1 -1
  6. package/dist/esm/components/Banner.js +1 -1
  7. package/dist/esm/components/BarHeader.js +5 -5
  8. package/dist/esm/components/BarHeader.js.map +1 -1
  9. package/dist/esm/components/Button.d.ts +20 -24
  10. package/dist/esm/components/Button.d.ts.map +1 -1
  11. package/dist/esm/components/Button.js +72 -117
  12. package/dist/esm/components/Button.js.map +1 -1
  13. package/dist/esm/components/Checkbox.js +2 -2
  14. package/dist/esm/components/Checkbox.js.map +1 -1
  15. package/dist/esm/components/Citation.js +1 -1
  16. package/dist/esm/components/Citation.js.map +1 -1
  17. package/dist/esm/components/DataTable.js +2 -2
  18. package/dist/esm/components/DataTable.js.map +1 -1
  19. package/dist/esm/components/Dialog.d.ts +2 -2
  20. package/dist/esm/components/Dialog.d.ts.map +1 -1
  21. package/dist/esm/components/Dialog.js +2 -2
  22. package/dist/esm/components/Dialog.js.map +1 -1
  23. package/dist/esm/components/FilterChips.d.ts.map +1 -1
  24. package/dist/esm/components/FilterChips.js +1 -1
  25. package/dist/esm/components/FilterChips.js.map +1 -1
  26. package/dist/esm/components/IconButton.d.ts +4 -3
  27. package/dist/esm/components/IconButton.d.ts.map +1 -1
  28. package/dist/esm/components/IconButton.js +37 -65
  29. package/dist/esm/components/IconButton.js.map +1 -1
  30. package/dist/esm/components/Markdown.d.ts.map +1 -1
  31. package/dist/esm/components/Markdown.js +2 -2
  32. package/dist/esm/components/Markdown.js.map +1 -1
  33. package/dist/esm/components/Notification.js +1 -1
  34. package/dist/esm/components/Notification.js.map +1 -1
  35. package/dist/esm/components/Pagination.d.ts.map +1 -1
  36. package/dist/esm/components/Pagination.js +2 -2
  37. package/dist/esm/components/Pagination.js.map +1 -1
  38. package/dist/esm/components/Popup.js +1 -1
  39. package/dist/esm/components/RadioGroup.d.ts.map +1 -1
  40. package/dist/esm/components/RadioGroup.js +14 -6
  41. package/dist/esm/components/RadioGroup.js.map +1 -1
  42. package/dist/esm/components/Searchbar.js +1 -1
  43. package/dist/esm/components/Spinner.d.ts +6 -2
  44. package/dist/esm/components/Spinner.d.ts.map +1 -1
  45. package/dist/esm/components/Spinner.js +34 -47
  46. package/dist/esm/components/Spinner.js.map +1 -1
  47. package/dist/esm/components/TextArea.d.ts +6 -3
  48. package/dist/esm/components/TextArea.d.ts.map +1 -1
  49. package/dist/esm/components/TextArea.js +16 -6
  50. package/dist/esm/components/TextArea.js.map +1 -1
  51. package/dist/esm/components/Tree.d.ts +1 -2
  52. package/dist/esm/components/Tree.d.ts.map +1 -1
  53. package/dist/esm/components/Tree.js +16 -24
  54. package/dist/esm/components/Tree.js.map +1 -1
  55. package/dist/esm/components/ZoomableImageCitationWrapper.js +1 -1
  56. package/dist/esm/stories/Banner.stories.js +1 -1
  57. package/dist/esm/stories/Banner.stories.js.map +1 -1
  58. package/dist/esm/stories/Button.stories.d.ts +3 -16
  59. package/dist/esm/stories/Button.stories.d.ts.map +1 -1
  60. package/dist/esm/stories/Button.stories.js +53 -166
  61. package/dist/esm/stories/Button.stories.js.map +1 -1
  62. package/dist/esm/stories/CardButton.stories.js +1 -1
  63. package/dist/esm/stories/CardButton.stories.js.map +1 -1
  64. package/dist/esm/stories/ContextItem.stories.d.ts.map +1 -1
  65. package/dist/esm/stories/ContextItem.stories.js +5 -5
  66. package/dist/esm/stories/ContextItem.stories.js.map +1 -1
  67. package/dist/esm/stories/Dialog.stories.js +1 -1
  68. package/dist/esm/stories/Dialog.stories.js.map +1 -1
  69. package/dist/esm/stories/DropdownMenu.stories.d.ts.map +1 -1
  70. package/dist/esm/stories/DropdownMenu.stories.js +7 -7
  71. package/dist/esm/stories/DropdownMenu.stories.js.map +1 -1
  72. package/dist/esm/stories/IconButton.stories.js +4 -4
  73. package/dist/esm/stories/IconButton.stories.js.map +1 -1
  74. package/dist/esm/stories/Markdown.stories.d.ts +1 -2
  75. package/dist/esm/stories/Markdown.stories.d.ts.map +1 -1
  76. package/dist/esm/stories/Modal.stories.d.ts.map +1 -1
  77. package/dist/esm/stories/Modal.stories.js +1 -2
  78. package/dist/esm/stories/Modal.stories.js.map +1 -1
  79. package/dist/esm/stories/NewDropdown.stories.js +2 -2
  80. package/dist/esm/stories/NewDropdown.stories.js.map +1 -1
  81. package/dist/esm/stories/Page.stories.d.ts.map +1 -1
  82. package/dist/esm/stories/Page.stories.js +6 -6
  83. package/dist/esm/stories/Page.stories.js.map +1 -1
  84. package/dist/esm/stories/Popover.stories.js +1 -1
  85. package/dist/esm/stories/RadioGroup.stories.d.ts.map +1 -1
  86. package/dist/esm/stories/RadioGroup.stories.js +4 -4
  87. package/dist/esm/stories/RadioGroup.stories.js.map +1 -1
  88. package/dist/esm/stories/Searchbar.stories.js +3 -3
  89. package/dist/esm/stories/Searchbar.stories.js.map +1 -1
  90. package/dist/esm/stories/SliderToggle.stories.js +2 -2
  91. package/dist/esm/stories/SliderToggle.stories.js.map +1 -1
  92. package/dist/esm/stories/TextArea.stories.d.ts +1 -1
  93. package/dist/esm/stories/Tree.stories.d.ts.map +1 -1
  94. package/dist/esm/stories/Tree.stories.js +17 -17
  95. package/dist/esm/stories/Tree.stories.js.map +1 -1
  96. package/dist/sparkle.css +160 -269
  97. package/package.json +1 -1
  98. package/src/components/AssistantPreview.tsx +1 -5
  99. package/src/components/Banner.tsx +1 -1
  100. package/src/components/BarHeader.tsx +5 -9
  101. package/src/components/Button.tsx +164 -237
  102. package/src/components/Checkbox.tsx +3 -3
  103. package/src/components/Citation.tsx +1 -1
  104. package/src/components/DataTable.tsx +2 -2
  105. package/src/components/Dialog.tsx +5 -5
  106. package/src/components/FilterChips.tsx +1 -2
  107. package/src/components/IconButton.tsx +51 -87
  108. package/src/components/Markdown.tsx +1 -3
  109. package/src/components/Notification.tsx +1 -1
  110. package/src/components/Pagination.tsx +2 -8
  111. package/src/components/Popup.tsx +1 -1
  112. package/src/components/RadioGroup.tsx +22 -18
  113. package/src/components/Searchbar.tsx +1 -1
  114. package/src/components/Spinner.tsx +45 -68
  115. package/src/components/TextArea.tsx +45 -16
  116. package/src/components/Tree.tsx +18 -37
  117. package/src/components/ZoomableImageCitationWrapper.tsx +1 -1
  118. package/src/stories/Banner.stories.tsx +1 -1
  119. package/src/stories/Button.stories.tsx +60 -606
  120. package/src/stories/CardButton.stories.tsx +1 -1
  121. package/src/stories/ContextItem.stories.tsx +6 -11
  122. package/src/stories/Dialog.stories.tsx +1 -1
  123. package/src/stories/DropdownMenu.stories.tsx +8 -27
  124. package/src/stories/IconButton.stories.tsx +4 -4
  125. package/src/stories/Modal.stories.tsx +1 -2
  126. package/src/stories/NewDropdown.stories.tsx +2 -16
  127. package/src/stories/Page.stories.tsx +6 -9
  128. package/src/stories/Popover.stories.tsx +1 -1
  129. package/src/stories/RadioGroup.stories.tsx +5 -8
  130. package/src/stories/Searchbar.stories.tsx +3 -3
  131. package/src/stories/SliderToggle.stories.tsx +2 -2
  132. package/src/stories/Tree.stories.tsx +9 -22
@@ -1,17 +1,18 @@
1
+ import { cva } from "class-variance-authority";
1
2
  import React, { ComponentType, MouseEventHandler } from "react";
2
3
 
3
- import { classNames } from "@sparkle/lib/utils";
4
+ import { Button, ButtonVariantType } from "@sparkle/components/Button";
4
5
 
5
- import { Icon, IconProps } from "./Icon";
6
+ import { Icon } from "./Icon";
6
7
  import { Tooltip } from "./Tooltip";
7
8
 
8
9
  type IconButtonProps = {
9
- variant?: "primary" | "warning" | "secondary" | "tertiary" | "white";
10
+ variant?: React.ComponentProps<typeof Button>["variant"];
10
11
  onClick?: MouseEventHandler<HTMLButtonElement>;
11
- size?: "xs" | "sm" | "md";
12
+ size?: React.ComponentProps<typeof Button>["size"];
12
13
  tooltip?: string;
13
14
  tooltipPosition?: React.ComponentProps<typeof Tooltip>["side"];
14
- icon?: ComponentType;
15
+ icon: ComponentType;
15
16
  className?: string;
16
17
  disabled?: boolean;
17
18
  };
@@ -19,100 +20,63 @@ type IconButtonProps = {
19
20
  const baseClasses =
20
21
  "s-transition-all s-ease-out s-duration-300 s-cursor-pointer hover:s-scale-110";
21
22
 
22
- const iconClasses = {
23
- primary: {
24
- base: "s-text-action-500",
25
- hover: "hover:s-text-action-400",
26
- active: "active:s-text-action-600",
27
- disabled: "s-text-element-500",
28
- dark: {
29
- base: "dark:s-text-action-500-dark",
30
- hover: "dark:hover:s-text-action-500-dark",
31
- active: "dark:active:s-text-action-600-dark",
32
- disabled: "dark:s-text-element-500-dark",
33
- },
34
- },
35
- warning: {
36
- base: "s-text-warning-500",
37
- hover: "hover:s-text-warning-400",
38
- active: "active:s-text-warning-600",
39
- disabled: "s-text-element-500",
40
- dark: {
41
- base: "dark:s-text-warning-500-dark",
42
- hover: "dark:hover:s-text-warning-500-dark",
43
- active: "dark:active:s-text-warning-600-dark",
44
- disabled: "dark:s-text-element-500-dark",
45
- },
46
- },
47
- secondary: {
48
- base: "s-text-element-900",
49
- hover: "hover:s-text-action-400",
50
- active: "active:s-text-action-600",
51
- disabled: "s-text-element-500",
52
- dark: {
53
- base: "dark:s-text-element-900-dark",
54
- hover: "dark:hover:s-text-action-500-dark",
55
- active: "dark:active:s-text-action-600-dark",
56
- disabled: "dark:s-text-element-500-dark",
57
- },
58
- },
59
- tertiary: {
60
- base: "s-text-element-700",
61
- hover: "hover:s-text-action-400",
62
- active: "active:s-text-action-600",
63
- disabled: "s-text-element-500",
64
- dark: {
65
- base: "dark:s-text-element-700-dark",
66
- hover: "dark:hover:s-text-action-500-dark",
67
- active: "dark:active:s-text-action-600-dark",
68
- disabled: "dark:s-text-element-500-dark",
23
+ const styleVariants: Record<ButtonVariantType, string> = {
24
+ primary:
25
+ "s-text-action-500 dark:s-text-action-500-dark" +
26
+ "hover:s-text-action-400 dark:hover:s-text-action-500-dark" +
27
+ "active:s-text-action-600 dark:active:s-text-action-600-dark" +
28
+ "s-text-element-500 dark:s-text-element-500-dark",
29
+ warning:
30
+ "s-text-warning-500 dark:s-text-warning-500-dark" +
31
+ "hover:s-text-warning-400 dark:hover:s-text-warning-500-dark" +
32
+ "active:s-text-warning-600 dark:active:s-text-warning-600-dark" +
33
+ "s-text-element-500 dark:s-text-element-500-dark",
34
+ highlight:
35
+ "s-text-element-900 dark:s-text-element-900-dark" +
36
+ "hover:s-text-action-400 dark:hover:s-text-action-500-dark" +
37
+ "active:s-text-action-600 dark:active:s-text-action-600-dark" +
38
+ "s-text-element-500 dark:s-text-element-500-dark",
39
+ outline:
40
+ "s-text-element-700 dark:s-text-element-700-dark" +
41
+ "hover:s-text-action-400 dark:hover:s-text-action-500-dark" +
42
+ "active:s-text-action-600 dark:active:s-text-action-600-dark" +
43
+ "s-text-element-500 dark:s-text-element-500-dark",
44
+ ghost:
45
+ "s-text-white s-text-white" +
46
+ "hover:s-text-slate-100 hover:s-text-slate-100" +
47
+ "active:s-text-slate-200 active:s-text-slate-200" +
48
+ "s-text-white/50 s-text-white/50",
49
+ };
50
+
51
+ const iconButtonVariants = cva(baseClasses, {
52
+ variants: {
53
+ variant: styleVariants,
54
+ disabled: {
55
+ true: "s-text-element-500 s-cursor-default hover:s-scale-100",
69
56
  },
70
57
  },
71
- white: {
72
- base: "s-text-white",
73
- hover: "hover:s-text-slate-100",
74
- active: "active:s-text-slate-200",
75
- disabled: "s-text-white/50",
76
- dark: {
77
- base: "s-text-white",
78
- hover: "hover:s-text-slate-100",
79
- active: "active:s-text-slate-200",
80
- disabled: "s-text-white/50",
81
- },
58
+ defaultVariants: {
59
+ variant: "outline",
60
+ disabled: false,
82
61
  },
83
- };
62
+ });
84
63
 
85
64
  export function IconButton({
86
- variant = "tertiary",
65
+ variant,
87
66
  onClick,
88
67
  disabled = false,
89
68
  tooltip,
90
- tooltipPosition = "top",
69
+ tooltipPosition,
91
70
  icon,
92
- className = "",
93
- size = "sm",
71
+ className,
72
+ size,
94
73
  }: IconButtonProps) {
95
- // Choose the correct group of classes based on 'type'
96
- const iconGroup = iconClasses[variant];
97
-
98
- const finalIconClasses = classNames(
99
- className,
100
- baseClasses,
101
- iconGroup.base,
102
- disabled ? iconGroup.disabled : iconGroup.hover,
103
- disabled ? "" : iconGroup.active,
104
- iconGroup.dark.base,
105
- disabled ? iconGroup.dark.disabled : iconGroup.dark.hover,
106
- disabled ? "" : iconGroup.dark.active
107
- );
74
+ const iconSize = size || "sm";
75
+ const buttonClasses = iconButtonVariants({ variant, disabled, className });
108
76
 
109
77
  const IconButtonContent = (
110
- <button
111
- className={finalIconClasses}
112
- onClick={disabled ? undefined : onClick}
113
- disabled={disabled}
114
- >
115
- {icon && <Icon visual={icon} size={size as IconProps["size"]} />}
78
+ <button className={buttonClasses} onClick={onClick} disabled={disabled}>
79
+ <Icon visual={icon} size={iconSize} />
116
80
  </button>
117
81
  );
118
82
 
@@ -146,13 +146,11 @@ export function Markdown({
146
146
  {childrenContent && (
147
147
  <Button
148
148
  size="xs"
149
- variant="tertiary"
149
+ variant="outline"
150
150
  onClick={async (e) => {
151
151
  e.preventDefault();
152
152
  await handleCopy();
153
153
  }}
154
- label="Copy"
155
- labelVisible={false}
156
154
  icon={isCopied ? ClipboardCheckIcon : ClipboardIcon}
157
155
  />
158
156
  )}
@@ -57,7 +57,7 @@ export function Notification({
57
57
  <IconButton
58
58
  icon={XMarkIcon}
59
59
  size="sm"
60
- variant="tertiary"
60
+ variant="outline"
61
61
  onClick={onClick}
62
62
  />
63
63
  </div>
@@ -75,11 +75,8 @@ export function Pagination({
75
75
  )}
76
76
  >
77
77
  <Button
78
- variant="tertiary"
78
+ variant="outline"
79
79
  size={size === "xs" ? "xs" : "sm"}
80
- label="previous"
81
- labelVisible={false}
82
- disabledTooltip={true}
83
80
  disabled={!canPreviousPage}
84
81
  icon={ChevronLeftIcon}
85
82
  onClick={previousPage}
@@ -96,11 +93,8 @@ export function Pagination({
96
93
  </div>
97
94
 
98
95
  <Button
99
- variant="tertiary"
96
+ variant="outline"
100
97
  size={size === "xs" ? "xs" : "sm"}
101
- label="next"
102
- labelVisible={false}
103
- disabledTooltip={true}
104
98
  disabled={!canNextPage}
105
99
  icon={ChevronRightIcon}
106
100
  onClick={nextPage}
@@ -51,7 +51,7 @@ export function Popup({
51
51
  <IconButton
52
52
  icon={XMarkIcon}
53
53
  onClick={onClose}
54
- variant="secondary"
54
+ variant="highlight"
55
55
  size="sm"
56
56
  />
57
57
  </div>
@@ -3,12 +3,11 @@ import { cva, VariantProps } from "class-variance-authority";
3
3
  import * as React from "react";
4
4
 
5
5
  import { Tooltip } from "@sparkle/components/Tooltip";
6
- import { CircleIcon } from "@sparkle/icons";
7
6
  import { cn } from "@sparkle/lib/utils";
8
7
 
9
8
  const radioStyles = cva(
10
9
  cn(
11
- "s-aspect-square s-h-4 s-w-4 s-rounded-full s-border s-text-foreground s-ring-offset-background",
10
+ "s-aspect-square s-rounded-full s-border s-border-border-darker s-text-foreground",
12
11
  "focus-visible:s-outline-none focus-visible:s-ring-2 focus-visible:s-ring-offset-2 focus-visible:s-ring-ring",
13
12
  "disabled:s-cursor-not-allowed disabled:s-opacity-50",
14
13
  "checked:s-ring-0 checked:s-bg-action-500"
@@ -26,6 +25,21 @@ const radioStyles = cva(
26
25
  }
27
26
  );
28
27
 
28
+ const radioIndicatorStyles = cva(
29
+ "s-bg-primary s-flex s-items-center s-justify-center s-rounded-full",
30
+ {
31
+ variants: {
32
+ size: {
33
+ xs: "s-h-2 s-w-2 s-ml-[3px]",
34
+ sm: "s-h-2.5 s-w-2.5 s-ml-1",
35
+ },
36
+ },
37
+ defaultVariants: {
38
+ size: "xs",
39
+ },
40
+ }
41
+ );
42
+
29
43
  const RadioGroup = React.forwardRef<
30
44
  React.ElementRef<typeof RadioGroupPrimitive.Root>,
31
45
  React.ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Root>
@@ -66,14 +80,9 @@ const RadioGroupItem = React.forwardRef<
66
80
  className={cn(radioStyles({ size }), className)}
67
81
  {...props}
68
82
  >
69
- <RadioGroupPrimitive.Indicator className="s-flex s-items-center s-justify-center">
70
- <CircleIcon
71
- className={cn(
72
- size === "xs" ? "s-h-2.5 s-w-2.5" : "s-h-3 s-w-3",
73
- "s-fill-current s-text-current focus:s-bg-action-50-dark"
74
- )}
75
- />
76
- </RadioGroupPrimitive.Indicator>
83
+ <RadioGroupPrimitive.Indicator
84
+ className={radioIndicatorStyles({ size })}
85
+ />
77
86
  </RadioGroupPrimitive.Item>
78
87
  }
79
88
  label={<span>{tooltipMessage}</span>}
@@ -84,14 +93,9 @@ const RadioGroupItem = React.forwardRef<
84
93
  className={cn(radioStyles({ size }), className)}
85
94
  {...props}
86
95
  >
87
- <RadioGroupPrimitive.Indicator className="s-flex s-items-center s-justify-center">
88
- <CircleIcon
89
- className={cn(
90
- size === "xs" ? "s-h-2.5 s-w-2.5" : "s-h-3 s-w-3",
91
- "s-fill-current s-text-current focus:s-bg-action-50-dark"
92
- )}
93
- />
94
- </RadioGroupPrimitive.Indicator>
96
+ <RadioGroupPrimitive.Indicator
97
+ className={radioIndicatorStyles({ size })}
98
+ />
95
99
  </RadioGroupPrimitive.Item>
96
100
  )}
97
101
  </div>
@@ -82,7 +82,7 @@ export const Searchbar = forwardRef<HTMLInputElement, SearchbarProps>(
82
82
  {value && onChange ? (
83
83
  <IconButton
84
84
  icon={XMarkIcon}
85
- variant="secondary"
85
+ variant="highlight"
86
86
  size={size}
87
87
  onClick={clearInputField}
88
88
  />
@@ -11,12 +11,27 @@ import animLightXS from "@sparkle/lottie/spinnerLight";
11
11
  import animLightLG from "@sparkle/lottie/spinnerLightLG";
12
12
  import animSimpleLight from "@sparkle/lottie/spinnerLightXS";
13
13
 
14
+ const SPINNER_SIZES = ["xs", "sm", "md", "lg", "xl", "xxl"] as const;
15
+
16
+ type SpinnerSizeType = (typeof SPINNER_SIZES)[number];
17
+
18
+ const SPINNER_VARIANTS = [
19
+ "color",
20
+ "light",
21
+ "dark",
22
+ "pink900",
23
+ "purple900",
24
+ "slate400",
25
+ ] as const;
26
+
27
+ type SpinnerVariantType = (typeof SPINNER_VARIANTS)[number];
28
+
14
29
  export interface SpinnerProps {
15
- size?: "xs" | "sm" | "md" | "lg" | "xl" | "xxl";
16
- variant?: "color" | "light" | "dark" | "pink900" | "purple900";
30
+ size?: SpinnerSizeType;
31
+ variant?: SpinnerVariantType;
17
32
  }
18
33
 
19
- const pxSizeClasses = {
34
+ const pxSizeClasses: Record<SpinnerSizeType, string> = {
20
35
  xs: "16",
21
36
  sm: "20",
22
37
  md: "24",
@@ -27,16 +42,12 @@ const pxSizeClasses = {
27
42
 
28
43
  type LottieColorType = [number, number, number, number];
29
44
 
30
- const colors: { [key: string]: LottieColorType } = {
31
- emerald900: [0.0235, 0.3059, 0.2314, 1], // #064E3B
32
- amber900: [0.5725, 0.251, 0.0549, 1], // #92400E
33
- slate900: [0.0588, 0.0902, 0.1647, 1], // #0F172A
45
+ const colors: Record<Exclude<SpinnerVariantType, "color">, LottieColorType> = {
46
+ light: [1, 1, 1, 1],
47
+ dark: [0.0588, 0.0902, 0.1647, 1],
34
48
  purple900: [0.298, 0.1137, 0.5843, 1], // #4C1D95
35
- sky900: [0.0471, 0.2902, 0.4314, 1], // #0C4A6E
36
49
  pink900: [0.5137, 0.0941, 0.2627, 1], // #831843
37
- red900: [0.498, 0.1137, 0.1137, 1], // #7F1D1D
38
- warning900: [0.498, 0.1137, 0.1137, 1], // #7F1D1D
39
- action900: [0.1176, 0.2275, 0.5412, 1], // #1E3A8A
50
+ slate400: [0.5647, 0.6314, 0.7176, 1], // #94a3b8
40
51
  };
41
52
 
42
53
  const isColorArray = (arr: unknown): arr is LottieColorType => {
@@ -75,73 +86,39 @@ const Spinner: React.FC<SpinnerProps> = ({
75
86
 
76
87
  switch (size) {
77
88
  case "xs":
78
- switch (variant) {
79
- case "light":
80
- anim = animSimpleLight;
81
- break;
82
-
83
- case "dark":
84
- anim = animDarkXS;
85
- break;
86
-
87
- default:
88
- anim = animColorXS;
89
- }
89
+ anim =
90
+ variant === "light"
91
+ ? animSimpleLight
92
+ : variant === "dark"
93
+ ? animDarkXS
94
+ : animColorXS;
90
95
  break;
91
-
92
96
  case "xl":
93
97
  case "xxl":
94
- switch (variant) {
95
- case "light":
96
- anim = animLightLG;
97
- break;
98
-
99
- case "dark":
100
- anim = animDarkLG;
101
- break;
102
-
103
- default:
104
- anim = animColorLG;
105
- }
98
+ anim =
99
+ variant === "light"
100
+ ? animLightLG
101
+ : variant === "dark"
102
+ ? animDarkLG
103
+ : animColorLG;
106
104
  break;
107
-
108
105
  default:
109
- switch (variant) {
110
- case "light":
111
- anim = animLightXS;
112
- break;
113
-
114
- case "dark":
115
- anim = animDark;
116
- break;
117
-
118
- default:
119
- anim = animColor;
120
- }
106
+ anim =
107
+ variant === "light"
108
+ ? animLightXS
109
+ : variant === "dark"
110
+ ? animDark
111
+ : animColor;
121
112
  }
122
113
 
123
- if (variant && variant in colors) {
124
- // Clone the animation data to modify it
125
- const animationData = JSON.parse(JSON.stringify(anim));
126
- const newColor = colors[variant];
127
-
128
- if (newColor) {
129
- replaceColors(animationData, newColor);
130
- }
131
-
132
- return (
133
- <Lottie
134
- animationData={animationData}
135
- style={{ width: `${fullSize}px`, height: `${fullSize}px` }}
136
- loop
137
- autoplay
138
- />
139
- );
140
- }
114
+ const animationData =
115
+ variant === "color"
116
+ ? anim
117
+ : replaceColors(JSON.parse(JSON.stringify(anim)), colors[variant]);
141
118
 
142
119
  return (
143
120
  <Lottie
144
- animationData={anim}
121
+ animationData={animationData}
145
122
  style={{ width: `${fullSize}px`, height: `${fullSize}px` }}
146
123
  loop
147
124
  autoplay
@@ -1,40 +1,66 @@
1
1
  import React from "react";
2
2
 
3
- import { classNames } from "@sparkle/lib/utils";
3
+ import { cn } from "@sparkle/lib/utils";
4
4
 
5
- export interface TextAreaProps
5
+ const RESIZE_DIRECTIONS = ["none", "vertical", "horizontal", "both"] as const;
6
+
7
+ type ResizeDirectionType = (typeof RESIZE_DIRECTIONS)[number];
8
+
9
+ export interface TextareaProps
6
10
  extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {
11
+ resize?: ResizeDirectionType;
7
12
  error?: string | null;
8
13
  showErrorLabel?: boolean;
9
14
  minRows?: number;
10
- className?: string;
11
15
  }
12
16
 
13
- export const TextArea = React.forwardRef<HTMLTextAreaElement, TextAreaProps>(
17
+ const textAreaStyles = cn(
18
+ "s-flex s-w-full s-px-3 s-py-2",
19
+ "s-transition s-duration-100",
20
+ "s-text-sm placeholder:s-text-muted-foreground s-text-foreground",
21
+ "s-ring-offset-background s-border s-border-border-dark s-bg-background s-rounded-xl",
22
+ "focus-visible:s-outline-none focus-visible:s-ring-2 focus-visible:s-ring-offset-2 ",
23
+ "disabled:s-cursor-not-allowed disabled:s-opacity-50 disabled:s-text-muted-foreground"
24
+ );
25
+
26
+ const TextArea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
14
27
  (
15
28
  {
16
- error,
17
- showErrorLabel = false,
18
29
  className,
30
+ resize = "both",
19
31
  minRows = 10,
32
+ error,
33
+ showErrorLabel,
20
34
  ...props
21
- }: TextAreaProps,
35
+ },
22
36
  ref
23
37
  ) => {
38
+ const resizeClass = {
39
+ none: "s-resize-none",
40
+ vertical: "s-resize-y",
41
+ horizontal: "s-resize-x",
42
+ both: "s-resize",
43
+ };
44
+
24
45
  return (
25
46
  <div className="s-flex s-flex-col s-gap-1 s-p-px">
26
47
  <textarea
27
- rows={minRows}
28
- ref={ref}
29
- className={classNames(
30
- "overflow-y-auto s-block s-w-full s-min-w-0 s-rounded-xl s-text-sm s-placeholder-element-700 s-transition-all s-scrollbar-hide s-duration-200",
48
+ className={cn(
49
+ textAreaStyles,
50
+ resizeClass[resize],
51
+ className,
31
52
  !error
32
- ? "s-border-structure-100 focus:s-border-action-300 focus:s-ring-action-300"
33
- : "s-border-red-500 focus:s-border-red-500 focus:s-ring-red-500",
34
- "s-border-structure-200 s-bg-structure-50",
35
- "s-resize-y",
36
- className ?? ""
53
+ ? cn(
54
+ "s-ring-structure-200 focus:s-ring-action-300",
55
+ "dark:s-ring-structure-300-dark dark:focus:s-ring-action-300-dark"
56
+ )
57
+ : cn(
58
+ "s-ring-warning-200 focus:s-ring-warning-300",
59
+ "dark:s-ring-warning-200-dark dark:focus:s-ring-warning-300-dark"
60
+ )
37
61
  )}
62
+ ref={ref}
63
+ rows={minRows}
38
64
  {...props}
39
65
  />
40
66
  {error && showErrorLabel && (
@@ -44,3 +70,6 @@ export const TextArea = React.forwardRef<HTMLTextAreaElement, TextAreaProps>(
44
70
  );
45
71
  }
46
72
  );
73
+ TextArea.displayName = "TextArea";
74
+
75
+ export { TextArea };