torch-glare 1.0.2
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.
- package/LICENSE +21 -0
- package/README.md +207 -0
- package/cli/bin/addComponent.js +278 -0
- package/cli/bin/addHooks.js +75 -0
- package/cli/bin/addLayout.js +71 -0
- package/cli/bin/addProvider.js +71 -0
- package/cli/bin/addUtils.js +74 -0
- package/cli/bin/cli.js +73 -0
- package/cli/bin/init/init.js +15 -0
- package/cli/bin/init/tailwindInit.js +174 -0
- package/cli/bin/update.js +147 -0
- package/lib/components/ActionButton.tsx +63 -0
- package/lib/components/ActionsGroup.tsx +34 -0
- package/lib/components/AlertDialog.tsx +211 -0
- package/lib/components/Badge.tsx +116 -0
- package/lib/components/BadgeField.tsx +192 -0
- package/lib/components/Button.tsx +277 -0
- package/lib/components/Card.tsx +63 -0
- package/lib/components/Checkbox.tsx +122 -0
- package/lib/components/CountBadge.tsx +54 -0
- package/lib/components/DatePicker.tsx +464 -0
- package/lib/components/Drawer.tsx +118 -0
- package/lib/components/DropdownMenu.tsx +399 -0
- package/lib/components/FieldHint.tsx +76 -0
- package/lib/components/ImageAttachment.tsx +180 -0
- package/lib/components/InnerLabelField.tsx +155 -0
- package/lib/components/Input.tsx +179 -0
- package/lib/components/InputField.tsx +147 -0
- package/lib/components/Label.tsx +107 -0
- package/lib/components/LabelField.tsx +75 -0
- package/lib/components/LabeledCheckBox.tsx +65 -0
- package/lib/components/LabeledRadio.tsx +45 -0
- package/lib/components/LinkButton.tsx +94 -0
- package/lib/components/LoginButton.tsx +56 -0
- package/lib/components/PasswordLevel.tsx +58 -0
- package/lib/components/Popover.tsx +274 -0
- package/lib/components/ProfileMenu.tsx +90 -0
- package/lib/components/Radio.tsx +77 -0
- package/lib/components/RadioCard.tsx +72 -0
- package/lib/components/RingLoading.tsx +190 -0
- package/lib/components/SearchField.tsx +49 -0
- package/lib/components/Select.tsx +417 -0
- package/lib/components/SlideDatePicker.tsx +120 -0
- package/lib/components/SpinLoading.tsx +190 -0
- package/lib/components/Switcher.tsx +56 -0
- package/lib/components/TabFormItem.tsx +158 -0
- package/lib/components/Table.tsx +395 -0
- package/lib/components/Textarea.tsx +108 -0
- package/lib/components/Tooltip.tsx +111 -0
- package/lib/components/TransparentLabel.tsx +72 -0
- package/lib/components/TreeDropDown.tsx +69 -0
- package/lib/hooks/MobileSlidePicker/components/Picker.tsx +218 -0
- package/lib/hooks/MobileSlidePicker/components/PickerColumn.tsx +238 -0
- package/lib/hooks/MobileSlidePicker/components/PickerItem.tsx +64 -0
- package/lib/hooks/MobileSlidePicker/index.ts +10 -0
- package/lib/hooks/useActiveTreeItem.tsx +61 -0
- package/lib/hooks/useClickOutside.tsx +20 -0
- package/lib/hooks/useResize.tsx +78 -0
- package/lib/layouts/CLayout.tsx +326 -0
- package/lib/layouts/FieldSection.tsx +64 -0
- package/lib/layouts/TreeSubLayout.tsx +187 -0
- package/lib/providers/ThemeProvider.tsx +99 -0
- package/lib/utils/cn.ts +6 -0
- package/lib/utils/convertImageFileToDataUrl.ts +17 -0
- package/lib/utils/resize.ts +35 -0
- package/lib/utils/types.ts +12 -0
- package/package.json +28 -0
- package/torch-glare.js +24 -0
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import * as SelectPrimitive from "@radix-ui/react-select";
|
|
4
|
+
import { cn } from "../utils/cn";
|
|
5
|
+
import { cva, VariantProps } from "class-variance-authority";
|
|
6
|
+
import { Button } from "./Button";
|
|
7
|
+
import { Tooltip } from "./Tooltip";
|
|
8
|
+
import { Themes } from "../utils/types";
|
|
9
|
+
|
|
10
|
+
// NOTE: radix select as DropDownButton
|
|
11
|
+
|
|
12
|
+
export const SelectContentStyles = cva(
|
|
13
|
+
[
|
|
14
|
+
"p-1",
|
|
15
|
+
"rounded-[8px]",
|
|
16
|
+
"border",
|
|
17
|
+
"max-h-[200px]",
|
|
18
|
+
"min-w-[240px]",
|
|
19
|
+
"outline-none",
|
|
20
|
+
"overflow-scroll",
|
|
21
|
+
"data-[state=open]:animate-in",
|
|
22
|
+
"data-[state=closed]:animate-out",
|
|
23
|
+
"data-[state=closed]:fade-out-0",
|
|
24
|
+
"data-[state=open]:fade-in-0",
|
|
25
|
+
"overflow-x-hidden",
|
|
26
|
+
"scrollbar-hide",
|
|
27
|
+
],
|
|
28
|
+
{
|
|
29
|
+
variants: {
|
|
30
|
+
variant: {
|
|
31
|
+
SystemStyle: [
|
|
32
|
+
"border-border-system-global-secondary",
|
|
33
|
+
"bg-background-system-body-primary",
|
|
34
|
+
"shadow-[0px_0px_18px_0px_rgba(0,0,0,0.75)]",
|
|
35
|
+
],
|
|
36
|
+
PresentationStyle: [
|
|
37
|
+
"border-border-presentation-global-primary",
|
|
38
|
+
"bg-background-presentation-form-base",
|
|
39
|
+
"shadow-[0px_0px_10px_0px_rgba(0,0,0,0.4),0px_4px_4px_0px_rgba(0,0,0,0.2)]",
|
|
40
|
+
],
|
|
41
|
+
},
|
|
42
|
+
defaultVariants: {
|
|
43
|
+
variant: "PresentationStyle",
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
}
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
export const MenuItemStyles = cva(
|
|
50
|
+
[
|
|
51
|
+
"text-content-presentation-action-light-primary",
|
|
52
|
+
"outline-none",
|
|
53
|
+
"border",
|
|
54
|
+
"border-transparent",
|
|
55
|
+
"flex",
|
|
56
|
+
"gap-[8px]",
|
|
57
|
+
"items-center",
|
|
58
|
+
"justify-start",
|
|
59
|
+
"text-overflow",
|
|
60
|
+
"overflow-hidden",
|
|
61
|
+
"px-[12px]",
|
|
62
|
+
"rounded-[4px]",
|
|
63
|
+
"transition-all",
|
|
64
|
+
"ease-in-out",
|
|
65
|
+
"duration-300",
|
|
66
|
+
],
|
|
67
|
+
{
|
|
68
|
+
variants: {
|
|
69
|
+
variant: {
|
|
70
|
+
Default: [
|
|
71
|
+
"text-content-presentation-action-light-primary",
|
|
72
|
+
"bg-background-presentation-action-dropdown-primary",
|
|
73
|
+
"hover:bg-background-presentation-action-hover",
|
|
74
|
+
"hover:text-content-presentation-action-hover",
|
|
75
|
+
"focus:bg-background-presentation-action-selected",
|
|
76
|
+
"focus:text-content-presentation-action-light-primary",
|
|
77
|
+
"active:border-border-presentation-action-disabled",
|
|
78
|
+
"active:bg-background-presentation-action-selected",
|
|
79
|
+
"active:text-content-presentation-action-light-primary",
|
|
80
|
+
"active:border-border-presentation-action-disabled",
|
|
81
|
+
"disabled:text-content-presentation-state-disabled",
|
|
82
|
+
"disabled:bg-white-00",
|
|
83
|
+
],
|
|
84
|
+
Warning: [
|
|
85
|
+
"bg-background-presentation-action-dropdown-primary",
|
|
86
|
+
"text-content-presentation-state-information",
|
|
87
|
+
"hover:bg-background-presentation-state-information-primary",
|
|
88
|
+
"hover:text-content-presentation-action-hover",
|
|
89
|
+
],
|
|
90
|
+
Negative: [
|
|
91
|
+
"bg-background-presentation-action-dropdown-primary",
|
|
92
|
+
"text-content-presentation-state-negative",
|
|
93
|
+
"hover:bg-background-presentation-state-negative-primary",
|
|
94
|
+
"hover:!text-content-presentation-action-hover",
|
|
95
|
+
"focus:text-content-presentation-state-negative",
|
|
96
|
+
"active:text-content-presentation-state-negative",
|
|
97
|
+
],
|
|
98
|
+
SystemStyle: [
|
|
99
|
+
"bg-background-system-body-primary",
|
|
100
|
+
"text-content-system-global-primary",
|
|
101
|
+
"hover:!bg-background-system-action-secondary-hover",
|
|
102
|
+
"hover:!text-content-system-action-primary-hover",
|
|
103
|
+
"hover:!border-border-system-action-primary-hover",
|
|
104
|
+
"focus:bg-background-System-Action-Primary-Selected",
|
|
105
|
+
"focus:border-transparent",
|
|
106
|
+
"active:border-transparent",
|
|
107
|
+
"active:bg-background-System-Action-Primary-Selected",
|
|
108
|
+
"disabled:bg-background-system-body-secondary",
|
|
109
|
+
"disabled:text-content-system-global-disabled",
|
|
110
|
+
],
|
|
111
|
+
},
|
|
112
|
+
size: {
|
|
113
|
+
S: ["typography-body-small-regular", "h-[24px]"],
|
|
114
|
+
M: ["typography-body-medium-regular", "h-[32px]"],
|
|
115
|
+
},
|
|
116
|
+
|
|
117
|
+
disabled: {
|
|
118
|
+
true: [
|
|
119
|
+
"text-content-presentation-state-disabled",
|
|
120
|
+
"bg-white-00",
|
|
121
|
+
],
|
|
122
|
+
},
|
|
123
|
+
|
|
124
|
+
active: {
|
|
125
|
+
true: [
|
|
126
|
+
"bg-background-presentation-action-selected",
|
|
127
|
+
"text-content-presentation-action-light-primary",
|
|
128
|
+
],
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
defaultVariants: {
|
|
132
|
+
variant: "SystemStyle",
|
|
133
|
+
size: "M",
|
|
134
|
+
active: false,
|
|
135
|
+
disabled: false,
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
compoundVariants: [
|
|
139
|
+
{
|
|
140
|
+
active: true,
|
|
141
|
+
variant: "Warning",
|
|
142
|
+
className: ["text-content-presentation-state-negative"],
|
|
143
|
+
},
|
|
144
|
+
],
|
|
145
|
+
}
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
export const dropdownTriggerStyles = cva(
|
|
149
|
+
[
|
|
150
|
+
"flex flex-row rounded-[4px] justify-between items-center outline-none",
|
|
151
|
+
"rounded-[4px]",
|
|
152
|
+
"[&_span]:text-content-presentation-action-light-primary",
|
|
153
|
+
"typography-body-small-regular",
|
|
154
|
+
"[&_p]:px-[10px] [&_p]:whitespace-nowrap",
|
|
155
|
+
"group",
|
|
156
|
+
"w-fit",
|
|
157
|
+
"border",
|
|
158
|
+
"transition-all duration-200 ease-in-out",
|
|
159
|
+
"hover:shadow-[0px_1px_6px_0px_rgba(0,0,0,0.30)]",
|
|
160
|
+
],
|
|
161
|
+
{
|
|
162
|
+
variants: {
|
|
163
|
+
variant: {
|
|
164
|
+
PresentationStyle: [
|
|
165
|
+
"bg-background-presentation-form-field-primary",
|
|
166
|
+
"hover:bg-background-presentation-form-field-hover",
|
|
167
|
+
"border-none",
|
|
168
|
+
],
|
|
169
|
+
SystemStyle: [
|
|
170
|
+
"bg-black-alpha-20",
|
|
171
|
+
"text-white",
|
|
172
|
+
"border-[#2C2D2E]",
|
|
173
|
+
"hover:border-[#9748FF]",
|
|
174
|
+
"hover:bg-purple-alpha-10",
|
|
175
|
+
],
|
|
176
|
+
},
|
|
177
|
+
error: {
|
|
178
|
+
true: [
|
|
179
|
+
"border-border-presentation-state-negative",
|
|
180
|
+
"caret-border-presentation-state-negative",
|
|
181
|
+
"hover:border-border-presentation-state-negative",
|
|
182
|
+
"hover:caret-border-presentation-state-negative",
|
|
183
|
+
],
|
|
184
|
+
},
|
|
185
|
+
size: {
|
|
186
|
+
S: [
|
|
187
|
+
"[&_span]:h-[22px] [&_span]:w-[22px] [&_p]:typography-body-small-medium",
|
|
188
|
+
],
|
|
189
|
+
M: [
|
|
190
|
+
"[&_span]:h-[26px] [&_span]:w-[26px] [&_p]:typography-body-medium-medium",
|
|
191
|
+
],
|
|
192
|
+
L: [
|
|
193
|
+
"[&_span]:h-[28px] [&_span]:w-[28px] [&_p]:typography-body-large-medium",
|
|
194
|
+
],
|
|
195
|
+
XL: [
|
|
196
|
+
"h-[40px] p-[4px] rounded-[6px] [&_span]:h-[32px] [&_span]:w-[32px] [&_p]:typography-body-small-regular [&_p]:px-[4px]",
|
|
197
|
+
],
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
defaultVariants: {
|
|
201
|
+
size: "M",
|
|
202
|
+
},
|
|
203
|
+
}
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
const Select = SelectPrimitive.Root;
|
|
207
|
+
|
|
208
|
+
const SelectGroup = SelectPrimitive.Group;
|
|
209
|
+
|
|
210
|
+
const SelectValue = SelectPrimitive.Value;
|
|
211
|
+
|
|
212
|
+
const SelectTrigger = React.forwardRef<
|
|
213
|
+
React.ElementRef<typeof SelectPrimitive.Trigger>,
|
|
214
|
+
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger> &
|
|
215
|
+
VariantProps<typeof dropdownTriggerStyles> & {
|
|
216
|
+
errors?: string;
|
|
217
|
+
icon?: string
|
|
218
|
+
theme?: Themes
|
|
219
|
+
}
|
|
220
|
+
>(
|
|
221
|
+
(
|
|
222
|
+
{
|
|
223
|
+
className,
|
|
224
|
+
children,
|
|
225
|
+
size = "M",
|
|
226
|
+
variant = "PresentationStyle",
|
|
227
|
+
errors,
|
|
228
|
+
theme,
|
|
229
|
+
icon,
|
|
230
|
+
...props
|
|
231
|
+
},
|
|
232
|
+
ref
|
|
233
|
+
) => {
|
|
234
|
+
return (
|
|
235
|
+
<Tooltip toolTipSide={"top"} open={errors !== undefined} text={errors}>
|
|
236
|
+
<SelectPrimitive.Trigger
|
|
237
|
+
data-theme={theme}
|
|
238
|
+
ref={ref}
|
|
239
|
+
className={cn(
|
|
240
|
+
dropdownTriggerStyles({
|
|
241
|
+
size,
|
|
242
|
+
variant,
|
|
243
|
+
error: errors !== undefined,
|
|
244
|
+
}),
|
|
245
|
+
className
|
|
246
|
+
)}
|
|
247
|
+
{...props}
|
|
248
|
+
>
|
|
249
|
+
<p className={cn({
|
|
250
|
+
"[&_span]:text-[#A0A0A0]": !props.value
|
|
251
|
+
})}>{children}</p>
|
|
252
|
+
|
|
253
|
+
<Button
|
|
254
|
+
as={"span"}
|
|
255
|
+
buttonType="icon"
|
|
256
|
+
className={cn(
|
|
257
|
+
[
|
|
258
|
+
"group-aria-expanded:bg-background-presentation-action-hover",
|
|
259
|
+
"group-aria-expanded:text-white",
|
|
260
|
+
]
|
|
261
|
+
)}
|
|
262
|
+
>
|
|
263
|
+
<i
|
|
264
|
+
className={cn(
|
|
265
|
+
"ri-arrow-down-s-line transition-all duration-100 ease-in-out group-aria-expanded:rotate-180",
|
|
266
|
+
{ "!text-[12px]": size === "S" },
|
|
267
|
+
{ "!text-[16px]": size === "M" },
|
|
268
|
+
{ "!text-[18px]": size === "L" },
|
|
269
|
+
{ "!text-[26px]": size === "XL" },
|
|
270
|
+
{ icon: icon }
|
|
271
|
+
)}
|
|
272
|
+
/>
|
|
273
|
+
</Button>
|
|
274
|
+
</SelectPrimitive.Trigger>
|
|
275
|
+
</Tooltip>
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
);
|
|
279
|
+
SelectTrigger.displayName = "SelectTrigger";
|
|
280
|
+
|
|
281
|
+
const SelectScrollUpButton = React.forwardRef<
|
|
282
|
+
React.ElementRef<typeof SelectPrimitive.ScrollUpButton>,
|
|
283
|
+
React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollUpButton>
|
|
284
|
+
>(({ className, ...props }, ref) => (
|
|
285
|
+
<SelectPrimitive.ScrollUpButton
|
|
286
|
+
ref={ref}
|
|
287
|
+
className={cn(
|
|
288
|
+
"flex cursor-default items-center justify-center py-1 ",
|
|
289
|
+
className
|
|
290
|
+
)}
|
|
291
|
+
{...props}
|
|
292
|
+
>
|
|
293
|
+
<i
|
|
294
|
+
className="h-4 w-4 ri-arrow-up-s-line"
|
|
295
|
+
color={"var(--content-presentation-action-light-primary)"}
|
|
296
|
+
/>
|
|
297
|
+
</SelectPrimitive.ScrollUpButton>
|
|
298
|
+
));
|
|
299
|
+
SelectScrollUpButton.displayName = "SelectScrollUpButton";
|
|
300
|
+
|
|
301
|
+
const SelectScrollDownButton = React.forwardRef<
|
|
302
|
+
React.ElementRef<typeof SelectPrimitive.ScrollDownButton>,
|
|
303
|
+
React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollDownButton>
|
|
304
|
+
>(({ className, ...props }, ref) => (
|
|
305
|
+
<SelectPrimitive.ScrollDownButton
|
|
306
|
+
ref={ref}
|
|
307
|
+
className={cn(
|
|
308
|
+
"flex cursor-default items-center justify-center py-1",
|
|
309
|
+
className
|
|
310
|
+
)}
|
|
311
|
+
{...props}
|
|
312
|
+
>
|
|
313
|
+
<i
|
|
314
|
+
color={"var(--content-presentation-action-light-primary)"}
|
|
315
|
+
className="h-4 w-4 ri-arrow-down-s-line"
|
|
316
|
+
/>
|
|
317
|
+
</SelectPrimitive.ScrollDownButton>
|
|
318
|
+
));
|
|
319
|
+
SelectScrollDownButton.displayName = "SelectScrollDownButton";
|
|
320
|
+
|
|
321
|
+
const SelectContent = React.forwardRef<
|
|
322
|
+
React.ElementRef<typeof SelectPrimitive.Content>,
|
|
323
|
+
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Content> &
|
|
324
|
+
VariantProps<typeof SelectContentStyles> & {
|
|
325
|
+
theme?: Themes
|
|
326
|
+
}
|
|
327
|
+
>(
|
|
328
|
+
(
|
|
329
|
+
{
|
|
330
|
+
className,
|
|
331
|
+
children,
|
|
332
|
+
variant = "PresentationStyle",
|
|
333
|
+
position = "popper",
|
|
334
|
+
theme,
|
|
335
|
+
...props
|
|
336
|
+
},
|
|
337
|
+
ref
|
|
338
|
+
) => (
|
|
339
|
+
<SelectPrimitive.Portal>
|
|
340
|
+
<SelectPrimitive.Content
|
|
341
|
+
data-theme={theme}
|
|
342
|
+
ref={ref}
|
|
343
|
+
className={cn(SelectContentStyles({ variant }), className)}
|
|
344
|
+
position={position}
|
|
345
|
+
{...props}
|
|
346
|
+
>
|
|
347
|
+
<SelectPrimitive.Viewport>{children}</SelectPrimitive.Viewport>
|
|
348
|
+
</SelectPrimitive.Content>
|
|
349
|
+
</SelectPrimitive.Portal>
|
|
350
|
+
)
|
|
351
|
+
);
|
|
352
|
+
SelectContent.displayName = "SelectContent";
|
|
353
|
+
|
|
354
|
+
const SelectLabel = React.forwardRef<
|
|
355
|
+
React.ElementRef<typeof SelectPrimitive.Label>,
|
|
356
|
+
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Label>
|
|
357
|
+
>(({ className, ...props }, ref) => (
|
|
358
|
+
<SelectPrimitive.Label
|
|
359
|
+
ref={ref}
|
|
360
|
+
className={cn("px-2 py-1.5 text-sm font-semibold", className)}
|
|
361
|
+
{...props}
|
|
362
|
+
/>
|
|
363
|
+
));
|
|
364
|
+
SelectLabel.displayName = "SelectLabel";
|
|
365
|
+
|
|
366
|
+
const SelectItem = React.forwardRef<
|
|
367
|
+
React.ElementRef<typeof SelectPrimitive.Item>,
|
|
368
|
+
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Item> &
|
|
369
|
+
VariantProps<typeof MenuItemStyles>
|
|
370
|
+
>(
|
|
371
|
+
(
|
|
372
|
+
{ className, children, size = "M", variant = "Default", active, ...props },
|
|
373
|
+
ref
|
|
374
|
+
) => (
|
|
375
|
+
<SelectPrimitive.Item
|
|
376
|
+
ref={ref}
|
|
377
|
+
className={cn(
|
|
378
|
+
MenuItemStyles({
|
|
379
|
+
variant,
|
|
380
|
+
active,
|
|
381
|
+
size,
|
|
382
|
+
}),
|
|
383
|
+
className
|
|
384
|
+
)}
|
|
385
|
+
{...props}
|
|
386
|
+
>
|
|
387
|
+
<SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
|
|
388
|
+
</SelectPrimitive.Item>
|
|
389
|
+
)
|
|
390
|
+
);
|
|
391
|
+
|
|
392
|
+
SelectItem.displayName = "SelectItem";
|
|
393
|
+
|
|
394
|
+
const SelectSeparator = React.forwardRef<
|
|
395
|
+
React.ElementRef<typeof SelectPrimitive.Separator>,
|
|
396
|
+
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Separator>
|
|
397
|
+
>(({ className, ...props }, ref) => (
|
|
398
|
+
<SelectPrimitive.Separator
|
|
399
|
+
ref={ref}
|
|
400
|
+
className={cn("-mx-1 my-1 h-px bg-muted", className)}
|
|
401
|
+
{...props}
|
|
402
|
+
/>
|
|
403
|
+
));
|
|
404
|
+
SelectSeparator.displayName = "SelectSeparator";
|
|
405
|
+
|
|
406
|
+
export {
|
|
407
|
+
Select,
|
|
408
|
+
SelectGroup,
|
|
409
|
+
SelectValue,
|
|
410
|
+
SelectTrigger,
|
|
411
|
+
SelectContent,
|
|
412
|
+
SelectLabel,
|
|
413
|
+
SelectItem,
|
|
414
|
+
SelectSeparator,
|
|
415
|
+
SelectScrollUpButton,
|
|
416
|
+
SelectScrollDownButton,
|
|
417
|
+
};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { ComponentProps, forwardRef, useState } from 'react';
|
|
2
|
+
import { getDaysInMonth } from 'date-fns';
|
|
3
|
+
import Picker, { PickerValue } from '../hooks/MobileSlidePicker';
|
|
4
|
+
import { Popover, PopoverContent, PopoverTrigger } from './Popover';
|
|
5
|
+
import { InputField } from './InputField';
|
|
6
|
+
|
|
7
|
+
function getDayArray(year: number, month: number): string[] {
|
|
8
|
+
const dayCount = getDaysInMonth(new Date(year, month - 1));
|
|
9
|
+
return Array.from({ length: dayCount }, (_, i) => String(i + 1).padStart(2, '0'));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface SlideDatePickerProps extends Omit<ComponentProps<typeof InputField>, 'onChange'> {
|
|
13
|
+
onChange?: (e: Date) => void;
|
|
14
|
+
theme?: "dark" | "light" | "default";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const SlideDatePicker = forwardRef<HTMLInputElement, SlideDatePickerProps>(({ theme = "dark", onChange, ...props }, forwardedRef) => {
|
|
18
|
+
const today = new Date();
|
|
19
|
+
const pickerValueData = {
|
|
20
|
+
year: String(today.getFullYear()),
|
|
21
|
+
month: String(today.getMonth() + 1).padStart(2, '0'),
|
|
22
|
+
day: String(today.getDate()).padStart(2, '0'),
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const [pickerValue, setPickerValue] = useState<PickerValue>(pickerValueData);
|
|
26
|
+
|
|
27
|
+
const currentYear = new Date().getFullYear();
|
|
28
|
+
const years = Array.from({ length: 200 }, (_, i) => `${currentYear - 100 + i}`);
|
|
29
|
+
const months = Array.from({ length: 12 }, (_, i) => String(i + 1).padStart(2, ''));
|
|
30
|
+
const days = getDayArray(Number(pickerValue.year), Number(pickerValue.month));
|
|
31
|
+
const monthsNames = [
|
|
32
|
+
"January", "February", "March", "April", "May", "June",
|
|
33
|
+
"July", "August", "September", "October", "November", "December",
|
|
34
|
+
];
|
|
35
|
+
const handlePickerChange = (newValue: PickerValue, key: string) => {
|
|
36
|
+
let { year, month, day } = newValue;
|
|
37
|
+
|
|
38
|
+
if (key === 'year' || key === 'month') {
|
|
39
|
+
const newDayArray = getDayArray(Number(year), Number(month));
|
|
40
|
+
day = newDayArray.includes(day as string) ? day : newDayArray[newDayArray.length - 1];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const updatedValue = { year, month, day };
|
|
44
|
+
setPickerValue(updatedValue);
|
|
45
|
+
|
|
46
|
+
// Create a Date object from the updated value
|
|
47
|
+
const newDate = new Date(`${updatedValue.year}-${updatedValue.month}-${updatedValue.day}`);
|
|
48
|
+
|
|
49
|
+
// Call the onChange callback with the Date object
|
|
50
|
+
if (onChange) {
|
|
51
|
+
onChange(newDate);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<Popover>
|
|
57
|
+
<PopoverTrigger data-theme={theme} className='w-full flex-1' >
|
|
58
|
+
<InputField theme={theme} {...props} ref={forwardedRef} value={`${pickerValue.year}/${pickerValue.month}/${pickerValue.day}`} readOnly />
|
|
59
|
+
</PopoverTrigger>
|
|
60
|
+
<PopoverContent data-theme={theme} dir="ltr" variant={props.variant} className="overflow-hidden w-[285px] flex justify-center items-center p-[6px] pt-[30px]">
|
|
61
|
+
<div className="flex justify-evenly items-center w-full absolute top-0 py-[6px]">
|
|
62
|
+
<p className="text-content-system-global-secondary typography-headers-medium-regular">Year</p>
|
|
63
|
+
<div className="flex justify-center items-center self-center">
|
|
64
|
+
<span className="h-[13px] w-[1px] bg-border-system-global-secondary rounded-[3px]"></span>
|
|
65
|
+
<p className="text-content-system-global-secondary typography-headers-medium-regular px-[18px]">Month</p>
|
|
66
|
+
<span className="h-[13px] w-[1px] bg-border-system-global-secondary rounded-[3px]"></span>
|
|
67
|
+
</div>
|
|
68
|
+
<p className="text-content-system-global-secondary typography-headers-medium-regular">Day</p>
|
|
69
|
+
</div>
|
|
70
|
+
<Picker
|
|
71
|
+
className="flex-1"
|
|
72
|
+
selectContainerClassName="bg-background-system-body-tertiary z-[-1] rounded-[8px]"
|
|
73
|
+
value={pickerValue}
|
|
74
|
+
onChange={handlePickerChange}
|
|
75
|
+
wheelMode="natural"
|
|
76
|
+
>
|
|
77
|
+
<Picker.Column name="year" >
|
|
78
|
+
{years.map((year) => (
|
|
79
|
+
<Picker.Item key={year} value={year}>
|
|
80
|
+
<div className="typography-display-small-semibold text-content-presentation-action-light-primary">{year}</div>
|
|
81
|
+
</Picker.Item>
|
|
82
|
+
))}
|
|
83
|
+
</Picker.Column>
|
|
84
|
+
<Picker.Column name="month">
|
|
85
|
+
{months.map((month, i) => (
|
|
86
|
+
<Picker.Item key={month} value={month}>
|
|
87
|
+
<div className="typography-display-small-semibold flex gap-1 whitespace-nowrap text-content-presentation-action-light-primary"> <p className='text-content-presentation-action-light-secondary'>{monthsNames[i].substring(0, 3)} - </p>{month}</div>
|
|
88
|
+
</Picker.Item>
|
|
89
|
+
))}
|
|
90
|
+
</Picker.Column>
|
|
91
|
+
<Picker.Column name="day">
|
|
92
|
+
{days.map((day) => (
|
|
93
|
+
<Picker.Item key={day} value={day}>
|
|
94
|
+
<div className="typography-display-small-semibold text-content-presentation-action-light-primary">{day}</div>
|
|
95
|
+
</Picker.Item>
|
|
96
|
+
))}
|
|
97
|
+
</Picker.Column>
|
|
98
|
+
</Picker>
|
|
99
|
+
</PopoverContent>
|
|
100
|
+
</Popover>
|
|
101
|
+
);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
// using with react hook form lib
|
|
106
|
+
/*
|
|
107
|
+
<form onSubmit={handleSubmit(onSubmit)}>
|
|
108
|
+
<Controller
|
|
109
|
+
name="date"
|
|
110
|
+
control={control}
|
|
111
|
+
render={({ field }) => (
|
|
112
|
+
<SlideDatePicker
|
|
113
|
+
{...field}
|
|
114
|
+
onChange={(value: Date) => field.onChange(value)}
|
|
115
|
+
/>
|
|
116
|
+
)}
|
|
117
|
+
/>
|
|
118
|
+
<button>submit</button>
|
|
119
|
+
</form>
|
|
120
|
+
*/
|