torch-glare 2.0.0 → 2.1.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.
@@ -3,73 +3,182 @@ import { cva, VariantProps } from "class-variance-authority";
3
3
  import { cn } from "../utils/cn";
4
4
  import { Themes } from "../utils/types";
5
5
 
6
- export const badgeBase = cva(
6
+ const SOLID_TEXT =
7
+ "text-content-presentation-global-primary-light [&_i]:text-content-presentation-global-primary-light";
8
+
9
+ const solidCompoundVariants = [
10
+ {
11
+ badgeStyle: "solid" as const,
12
+ color: "gray" as const,
13
+ className: `bg-background-presentation-badge-gray-solid ${SOLID_TEXT}`,
14
+ },
15
+ {
16
+ badgeStyle: "solid" as const,
17
+ color: "slate" as const,
18
+ className: `bg-background-presentation-badge-slate-solid ${SOLID_TEXT}`,
19
+ },
20
+ {
21
+ badgeStyle: "solid" as const,
22
+ color: "red" as const,
23
+ className: `bg-background-presentation-badge-red-solid ${SOLID_TEXT}`,
24
+ },
25
+ {
26
+ badgeStyle: "solid" as const,
27
+ color: "orange" as const,
28
+ className: `bg-background-presentation-badge-orange-solid ${SOLID_TEXT}`,
29
+ },
30
+ {
31
+ badgeStyle: "solid" as const,
32
+ color: "yellow" as const,
33
+ className: `bg-background-presentation-badge-yellow-solid ${SOLID_TEXT}`,
34
+ },
35
+ {
36
+ badgeStyle: "solid" as const,
37
+ color: "green" as const,
38
+ className: `bg-background-presentation-badge-green-solid ${SOLID_TEXT}`,
39
+ },
40
+ {
41
+ badgeStyle: "solid" as const,
42
+ color: "ocean" as const,
43
+ className: `bg-background-presentation-badge-ocean-solid ${SOLID_TEXT}`,
44
+ },
45
+ {
46
+ badgeStyle: "solid" as const,
47
+ color: "blue" as const,
48
+ className: `bg-background-presentation-badge-blue-solid ${SOLID_TEXT}`,
49
+ },
50
+ {
51
+ badgeStyle: "solid" as const,
52
+ color: "purple" as const,
53
+ className: `bg-background-presentation-badge-purple-solid ${SOLID_TEXT}`,
54
+ },
55
+ {
56
+ badgeStyle: "solid" as const,
57
+ color: "rose" as const,
58
+ className: `bg-background-presentation-badge-rose-solid ${SOLID_TEXT}`,
59
+ },
60
+ ];
61
+
62
+ const SUBTLE_TEXT =
63
+ "text-content-presentation-global-subtle [&>div]:mix-blend-luminosity [&_i]:text-content-presentation-global-subtle [&_i]:mix-blend-luminosity [&>button]:mix-blend-luminosity";
64
+
65
+ const subtleCompoundVariants = [
66
+ {
67
+ badgeStyle: "subtle" as const,
68
+ color: "gray" as const,
69
+ className: `bg-background-presentation-badge-gray-subtle ${SUBTLE_TEXT}`,
70
+ },
71
+ {
72
+ badgeStyle: "subtle" as const,
73
+ color: "slate" as const,
74
+ className: `bg-background-presentation-badge-slate-subtle ${SUBTLE_TEXT}`,
75
+ },
76
+ {
77
+ badgeStyle: "subtle" as const,
78
+ color: "red" as const,
79
+ className: `bg-background-presentation-badge-red-subtle ${SUBTLE_TEXT}`,
80
+ },
81
+ {
82
+ badgeStyle: "subtle" as const,
83
+ color: "orange" as const,
84
+ className: `bg-background-presentation-badge-orange-subtle ${SUBTLE_TEXT}`,
85
+ },
86
+ {
87
+ badgeStyle: "subtle" as const,
88
+ color: "yellow" as const,
89
+ className: `bg-background-presentation-badge-yellow-subtle ${SUBTLE_TEXT}`,
90
+ },
91
+ {
92
+ badgeStyle: "subtle" as const,
93
+ color: "green" as const,
94
+ className: `bg-background-presentation-badge-green-subtle ${SUBTLE_TEXT}`,
95
+ },
96
+ {
97
+ badgeStyle: "subtle" as const,
98
+ color: "ocean" as const,
99
+ className: `bg-background-presentation-badge-ocean-subtle ${SUBTLE_TEXT}`,
100
+ },
101
+ {
102
+ badgeStyle: "subtle" as const,
103
+ color: "blue" as const,
104
+ className: `bg-background-presentation-badge-blue-subtle ${SUBTLE_TEXT}`,
105
+ },
106
+ {
107
+ badgeStyle: "subtle" as const,
108
+ color: "purple" as const,
109
+ className: `bg-background-presentation-badge-purple-subtle ${SUBTLE_TEXT}`,
110
+ },
111
+ {
112
+ badgeStyle: "subtle" as const,
113
+ color: "rose" as const,
114
+ className: `bg-background-presentation-badge-rose-subtle ${SUBTLE_TEXT}`,
115
+ },
116
+ ];
117
+
118
+ export const badgeStyles = cva(
7
119
  [
8
- "px-[6px]",
9
- "[&_div]:text-content-presentation-action-light-primary",
10
- "[&_i]:!leading-none",
11
- "flex",
12
- "justify-center",
13
- "items-center",
14
- "border",
120
+ "inline-flex items-center justify-center w-fit",
15
121
  "rounded-[6px]",
16
- "transition-all",
17
- "duration-300",
18
- "ease-in-out",
19
- "w-fit",
20
- "cursor-pointer",
21
- "[&_i]:leading-0",
122
+ "transition-all duration-200 ease-in-out",
123
+ "whitespace-nowrap",
124
+ "[&_i]:!leading-none",
22
125
  ],
23
126
  {
24
127
  variants: {
25
- size: {
26
- XS: "h-[18px] [&_i]:text-[12px] [&_div]:typography-body-small-medium",
27
- S: "h-[22px] [&_i]:text-[12px] [&_div]:typography-body-small-medium",
28
- M: "h-[26px] [&_i]:text-[16px] [&_div]:typography-body-medium-medium",
128
+ badgeStyle: {
129
+ solid: "",
130
+ subtle: "",
29
131
  },
30
- variant: {
31
- highlight: ["h-[20px] [&_i]:text-[12px] [&_div]:typography-body-small-medium",
32
- "bg-background-presentation-badge-gray border-transparent px-[3px]"
33
- ],
34
- green: "border-border-presentation-badge-green bg-background-presentation-badge-green [&_i]:text-content-presentation-badge-green",
35
- greenLight: "border-border-presentation-badge-green-light bg-background-presentation-badge-green-light [&_i]:text-content-presentation-badge-green-light",
36
- cocktailGreen: "border-border-presentation-badge-cocktail-green bg-background-presentation-badge-cocktail-green [&_i]:text-content-presentation-badge-cocktail-green",
37
- yellow: "border-border-presentation-badge-yellow bg-background-presentation-badge-yellow [&_i]:text-content-presentation-badge-yellow",
38
- redOrange: "border-border-presentation-badge-red-orange bg-background-presentation-badge-red-orange [&_i]:text-content-presentation-badge-red-orange",
39
- redLight: "border-border-presentation-badge-red bg-background-presentation-badge-red [&_i]:text-content-presentation-badge-red",
40
- rose: "border-border-presentation-badge-rose bg-background-presentation-badge-rose [&_i]:text-content-presentation-badge-rose",
41
- purple: "border-border-presentation-badge-purple bg-background-presentation-badge-purple [&_i]:text-content-presentation-badge-purple",
42
- bluePurple: "border-border-presentation-badge-blue-purple bg-background-presentation-badge-blue-purple [&_i]:text-content-presentation-badge-blue-purple",
43
- blue: "border-border-presentation-badge-blue bg-background-presentation-badge-blue [&_i]:text-content-presentation-badge-blue",
44
- navy: "border-border-presentation-badge-navy bg-background-presentation-badge-navy [&_i]:text-content-presentation-badge-navy",
45
- gray: "border-border-presentation-badge-gray bg-background-presentation-badge-gray [&_i]:text-content-presentation-badge-gray",
132
+ color: {
133
+ gray: "",
134
+ slate: "",
135
+ red: "",
136
+ orange: "",
137
+ yellow: "",
138
+ green: "",
139
+ ocean: "",
140
+ blue: "",
141
+ purple: "",
142
+ rose: "",
143
+ },
144
+ size: {
145
+ XS: "h-[18px] px-[6px] py-0 [&_i]:text-[12px] [&>div]:typography-body-small-medium",
146
+ S: "h-[22px] px-[6px] py-[2px] [&_i]:text-[12px] [&>div]:typography-body-small-medium",
147
+ M: "h-[26px] px-[8px] py-[2px] [&_i]:text-[16px] [&>div]:typography-body-medium-medium",
46
148
  },
47
149
  },
150
+ compoundVariants: [...solidCompoundVariants, ...subtleCompoundVariants],
48
151
  defaultVariants: {
152
+ badgeStyle: "subtle",
153
+ color: "gray",
49
154
  size: "S",
50
- variant: "green",
51
155
  },
52
- }
156
+ },
53
157
  );
54
158
 
55
- interface BadgeProps extends HTMLAttributes<HTMLButtonElement>,
56
- VariantProps<typeof badgeBase> {
159
+ interface BadgeProps
160
+ extends
161
+ Omit<HTMLAttributes<HTMLSpanElement>, "color">,
162
+ VariantProps<typeof badgeStyles> {
57
163
  label?: string;
58
- onUnselect?: () => void;
59
- isSelected?: boolean;
60
164
  badgeIcon?: ReactNode;
165
+ showIcon?: boolean;
166
+ isClosable?: boolean;
167
+ onClose?: () => void;
168
+ theme?: Themes;
61
169
  className?: string;
62
- theme?: Themes
63
170
  }
64
171
 
65
172
  export const Badge: React.FC<BadgeProps> = ({
66
173
  label,
67
- onUnselect,
68
- isSelected,
69
174
  badgeIcon,
175
+ showIcon = true,
176
+ isClosable,
177
+ onClose,
70
178
  theme,
71
- size = "S",
72
- variant = "green",
179
+ badgeStyle,
180
+ color,
181
+ size,
73
182
  className,
74
183
  ...props
75
184
  }) => {
@@ -78,37 +187,55 @@ export const Badge: React.FC<BadgeProps> = ({
78
187
  {...props}
79
188
  data-theme={theme}
80
189
  className={cn(
81
- badgeBase({ size, variant }),
82
- {
83
- "cursor-default": isSelected,
84
- },
85
- className
190
+ badgeStyles({ badgeStyle, color, size }),
191
+ { "cursor-default": isClosable },
192
+ className,
86
193
  )}
87
194
  >
88
- <div className={"flex justify-center items-center"}>
89
- {!badgeIcon ? (
90
- <i className={cn("ri-circle-fill !text-[8px]", { "hidden": variant === "highlight" })}></i>
91
- ) : (
92
- badgeIcon
93
- )}
94
- </div>
195
+ {showIcon && (
196
+ <div className="flex items-center justify-center">
197
+ {badgeIcon ?? <i className="ri-circle-fill !text-[8px]" />}
198
+ </div>
199
+ )}
200
+
201
+ {label && <div className="px-[3px]">{label}</div>}
95
202
 
96
- <div className="px-[3px] whitespace-nowrap">{label}</div>
97
- {isSelected && (
203
+ {isClosable && (
98
204
  <button
99
- onClick={onUnselect}
100
- className="rounded-[2px] flex justify-center items-center cursor-pointer"
101
- tabIndex={0}
102
- role="button"
103
- aria-label="Remove badge"
205
+ type="button"
206
+ onClick={onClose}
104
207
  onKeyDown={(e) => {
105
- if (e.key === 'Enter' || e.key === ' ') {
208
+ if (e.key === "Enter" || e.key === " ") {
106
209
  e.preventDefault();
107
- onUnselect?.();
210
+ onClose?.();
108
211
  }
109
212
  }}
213
+ className={cn(
214
+ "rounded-[4px]",
215
+ "flex items-center justify-center cursor-pointer",
216
+ "hover:bg-background-presentation-action-secondary",
217
+ "transition-colors duration-150",
218
+ size === "M"
219
+ ? "w-[16px] h-[16px]"
220
+ : size === "S"
221
+ ? "w-[14px] h-[14px]"
222
+ : "w-[12px] h-[12px]",
223
+ )}
224
+ aria-label="Remove badge"
110
225
  >
111
- <i className="ri-close-line !text-content-presentation-action-light-primary"></i>
226
+ <svg
227
+ xmlns="http://www.w3.org/2000/svg"
228
+ width="100%"
229
+ height="100%"
230
+ viewBox="0 0 12 12"
231
+ fill="none"
232
+ aria-hidden="true"
233
+ >
234
+ <path
235
+ d="M6.00002 5.33336L8.33334 3L9 3.66667L6.66668 6.00002L9 8.33334L8.33334 9L6.00002 6.66668L3.66667 9L3 8.33334L5.33336 6.00002L3 3.66667L3.66667 3L6.00002 5.33336Z"
236
+ fill="currentColor"
237
+ />
238
+ </svg>
112
239
  </button>
113
240
  )}
114
241
  </span>
@@ -124,10 +124,10 @@ export const BadgeField = forwardRef<HTMLInputElement, Props>(
124
124
  <Badge
125
125
  key={tag.id}
126
126
  size={size}
127
- variant={tag.variant as any}
127
+ color={tag.variant as any}
128
128
  label={tag.name}
129
- isSelected={true}
130
- onUnselect={() => handleUnselectTag(tag.id)}
129
+ isClosable={true}
130
+ onClose={() => handleUnselectTag(tag.id)}
131
131
  className={
132
132
  focusedTagIndex === index ? "ring-2 ring-blue-500" : ""
133
133
  }
@@ -179,7 +179,7 @@ export const BadgeField = forwardRef<HTMLInputElement, Props>(
179
179
  <Badge
180
180
  key={tag.id}
181
181
  size={size}
182
- variant={tag.variant as any}
182
+ color={tag.variant as any}
183
183
  label={tag.name}
184
184
  onClick={() => handleSelectTag(tag.id)}
185
185
  className={`outline-none ${focusedPopoverIndex === index ? "ring-2 ring-blue-500" : ""