@brightlocal/ui-components 0.1.2 → 0.1.3
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/dist/accordion.cjs +1 -1
- package/dist/accordion.d.ts +74 -4
- package/dist/accordion.d.ts.map +1 -1
- package/dist/accordion.js +100 -105
- package/dist/alert-dialog.cjs +1 -1
- package/dist/alert-dialog.d.ts +30 -10
- package/dist/alert-dialog.d.ts.map +1 -1
- package/dist/alert-dialog.js +129 -132
- package/dist/alert.d.ts +22 -1
- package/dist/alert.d.ts.map +1 -1
- package/dist/aspect-ratio.cjs +1 -1
- package/dist/aspect-ratio.d.ts +11 -1
- package/dist/aspect-ratio.d.ts.map +1 -1
- package/dist/aspect-ratio.js +16 -20
- package/dist/avatar.cjs +1 -1
- package/dist/avatar.d.ts +43 -3
- package/dist/avatar.d.ts.map +1 -1
- package/dist/avatar.js +18 -16
- package/dist/badge.cjs +1 -1
- package/dist/badge.d.ts +24 -9
- package/dist/badge.d.ts.map +1 -1
- package/dist/badge.js +34 -32
- package/dist/blocks/data-table.cjs +1 -1
- package/dist/blocks/data-table.d.ts.map +1 -1
- package/dist/blocks/data-table.js +177 -170
- package/dist/blocks/sidebar.cjs +1 -1
- package/dist/blocks/sidebar.d.ts +1 -1
- package/dist/blocks/sidebar.d.ts.map +1 -1
- package/dist/blocks/sidebar.js +154 -154
- package/dist/breadcrumb.cjs +1 -1
- package/dist/breadcrumb.d.ts +63 -8
- package/dist/breadcrumb.d.ts.map +1 -1
- package/dist/breadcrumb.js +97 -93
- package/dist/button.cjs +1 -1
- package/dist/button.d.ts +17 -45
- package/dist/button.d.ts.map +1 -1
- package/dist/button.js +49 -50
- package/dist/calendar.cjs +1 -1
- package/dist/calendar.d.ts +12 -0
- package/dist/calendar.d.ts.map +1 -1
- package/dist/calendar.js +10 -8
- package/dist/card.cjs +1 -1
- package/dist/card.d.ts +58 -18
- package/dist/card.d.ts.map +1 -1
- package/dist/card.js +60 -51
- package/dist/carousel.cjs +1 -1
- package/dist/carousel.d.ts +99 -9
- package/dist/carousel.d.ts.map +1 -1
- package/dist/carousel.js +142 -128
- package/dist/centred-layout.cjs +1 -1
- package/dist/centred-layout.d.ts +18 -2
- package/dist/centred-layout.d.ts.map +1 -1
- package/dist/centred-layout.js +46 -33
- package/dist/chart.cjs +4 -4
- package/dist/chart.d.ts +70 -7
- package/dist/chart.d.ts.map +1 -1
- package/dist/chart.js +71 -66
- package/dist/checkbox.cjs +1 -1
- package/dist/checkbox.d.ts +9 -5
- package/dist/checkbox.d.ts.map +1 -1
- package/dist/checkbox.js +61 -82
- package/dist/collapsible.cjs +1 -1
- package/dist/collapsible.d.ts +65 -8
- package/dist/collapsible.d.ts.map +1 -1
- package/dist/collapsible.js +41 -55
- package/dist/combobox.cjs +1 -1
- package/dist/combobox.d.ts +29 -11
- package/dist/combobox.d.ts.map +1 -1
- package/dist/combobox.js +193 -159
- package/dist/command.cjs +1 -1
- package/dist/command.d.ts +115 -9
- package/dist/command.d.ts.map +1 -1
- package/dist/command.js +176 -152
- package/dist/context-menu.cjs +1 -1
- package/dist/context-menu.d.ts +188 -20
- package/dist/context-menu.d.ts.map +1 -1
- package/dist/context-menu.js +119 -121
- package/dist/date-picker.cjs +1 -1
- package/dist/date-picker.d.ts +75 -9
- package/dist/date-picker.d.ts.map +1 -1
- package/dist/date-picker.js +220 -81
- package/dist/description.cjs +1 -0
- package/dist/description.d.ts +37 -0
- package/dist/description.d.ts.map +1 -0
- package/dist/description.js +25 -0
- package/dist/dialog.cjs +1 -1
- package/dist/dialog.d.ts +73 -9
- package/dist/dialog.d.ts.map +1 -1
- package/dist/dialog.js +103 -112
- package/dist/drawer.cjs +1 -1
- package/dist/drawer.d.ts +92 -0
- package/dist/drawer.d.ts.map +1 -1
- package/dist/drawer.js +67 -52
- package/dist/dropdown-menu.cjs +1 -1
- package/dist/dropdown-menu.d.ts +95 -11
- package/dist/dropdown-menu.d.ts.map +1 -1
- package/dist/dropdown-menu.js +146 -106
- package/dist/field.cjs +1 -1
- package/dist/field.d.ts +23 -6
- package/dist/field.d.ts.map +1 -1
- package/dist/field.js +54 -53
- package/dist/global-layout.cjs +1 -1
- package/dist/global-layout.d.ts +27 -17
- package/dist/global-layout.d.ts.map +1 -1
- package/dist/global-layout.js +86 -79
- package/dist/hover-card.cjs +1 -1
- package/dist/hover-card.d.ts +36 -6
- package/dist/hover-card.d.ts.map +1 -1
- package/dist/hover-card.js +44 -42
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +383 -387
- package/dist/input-group.cjs +1 -1
- package/dist/input-group.d.ts +21 -2
- package/dist/input-group.d.ts.map +1 -1
- package/dist/input-group.js +51 -41
- package/dist/input-password.cjs +1 -1
- package/dist/input-password.d.ts.map +1 -1
- package/dist/input-password.js +24 -25
- package/dist/input.cjs +1 -1
- package/dist/input.d.ts +38 -24
- package/dist/input.d.ts.map +1 -1
- package/dist/input.js +68 -136
- package/dist/label.cjs +1 -1
- package/dist/label.d.ts +20 -1
- package/dist/label.d.ts.map +1 -1
- package/dist/label.js +31 -18
- package/dist/logo.cjs +1 -1
- package/dist/logo.d.ts +3 -0
- package/dist/logo.d.ts.map +1 -1
- package/dist/logo.js +12 -10
- package/dist/menubar.cjs +1 -1
- package/dist/menubar.d.ts +40 -6
- package/dist/menubar.d.ts.map +1 -1
- package/dist/menubar.js +97 -76
- package/dist/popover.cjs +1 -1
- package/dist/popover.d.ts +59 -4
- package/dist/popover.d.ts.map +1 -1
- package/dist/popover.js +42 -34
- package/dist/progress.cjs +1 -1
- package/dist/progress.d.ts +9 -2
- package/dist/progress.d.ts.map +1 -1
- package/dist/progress.js +71 -59
- package/dist/radio-group.d.ts +40 -0
- package/dist/radio-group.d.ts.map +1 -1
- package/dist/rating.d.ts +4 -0
- package/dist/rating.d.ts.map +1 -1
- package/dist/resizable.cjs +1 -1
- package/dist/resizable.d.ts +65 -4
- package/dist/resizable.d.ts.map +1 -1
- package/dist/resizable.js +53 -36
- package/dist/scroll-area.cjs +1 -1
- package/dist/scroll-area.d.ts +46 -5
- package/dist/scroll-area.d.ts.map +1 -1
- package/dist/scroll-area.js +42 -38
- package/dist/select.cjs +1 -1
- package/dist/select.d.ts +30 -0
- package/dist/select.d.ts.map +1 -1
- package/dist/select.js +64 -54
- package/dist/separator.cjs +1 -1
- package/dist/separator.d.ts +49 -2
- package/dist/separator.d.ts.map +1 -1
- package/dist/separator.js +48 -36
- package/dist/sheet.cjs +1 -1
- package/dist/sheet.d.ts +80 -9
- package/dist/sheet.d.ts.map +1 -1
- package/dist/sheet.js +117 -113
- package/dist/skeleton.cjs +1 -1
- package/dist/skeleton.d.ts +24 -2
- package/dist/skeleton.d.ts.map +1 -1
- package/dist/skeleton.js +15 -9
- package/dist/slider.cjs +1 -1
- package/dist/slider.d.ts +18 -4
- package/dist/slider.d.ts.map +1 -1
- package/dist/slider.js +72 -66
- package/dist/sonner.cjs +1 -1
- package/dist/sonner.d.ts +4 -2
- package/dist/sonner.d.ts.map +1 -1
- package/dist/sonner.js +29 -28
- package/dist/split-layout.d.ts +4 -1
- package/dist/split-layout.d.ts.map +1 -1
- package/package.json +8 -2
- package/src/blocks/data-table.tsx +42 -32
- package/src/blocks/sidebar.tsx +4 -12
- package/src/components/accordion.tsx +163 -77
- package/src/components/alert-dialog.tsx +156 -111
- package/src/components/alert.tsx +26 -13
- package/src/components/aspect-ratio.tsx +25 -16
- package/src/components/avatar.tsx +56 -8
- package/src/components/badge.tsx +65 -42
- package/src/components/breadcrumb.tsx +158 -82
- package/src/components/button.tsx +41 -62
- package/src/components/calendar.tsx +16 -2
- package/src/components/card.tsx +92 -40
- package/src/components/carousel.tsx +240 -115
- package/src/components/centred-layout.tsx +67 -35
- package/src/components/chart.tsx +118 -47
- package/src/components/checkbox.tsx +42 -78
- package/src/components/collapsible.tsx +95 -26
- package/src/components/combobox.tsx +242 -144
- package/src/components/command.tsx +295 -121
- package/src/components/context-menu.tsx +278 -81
- package/src/components/date-picker.tsx +281 -30
- package/src/components/description.tsx +60 -0
- package/src/components/dialog.tsx +162 -86
- package/src/components/drawer.tsx +76 -2
- package/src/components/dropdown-menu.tsx +143 -37
- package/src/components/field.tsx +36 -11
- package/src/components/global-layout.tsx +116 -77
- package/src/components/hover-card.tsx +54 -14
- package/src/components/input-group.tsx +56 -18
- package/src/components/input-password.tsx +3 -4
- package/src/components/input.tsx +93 -186
- package/src/components/label.tsx +56 -15
- package/src/components/logo.tsx +3 -0
- package/src/components/menubar.tsx +58 -4
- package/src/components/popover.tsx +103 -20
- package/src/components/progress.tsx +82 -60
- package/src/components/radio-group.tsx +40 -0
- package/src/components/rating.tsx +4 -0
- package/src/components/resizable.tsx +119 -31
- package/src/components/scroll-area.tsx +123 -56
- package/src/components/select.tsx +21 -1
- package/src/components/separator.tsx +97 -20
- package/src/components/sheet.tsx +180 -79
- package/src/components/skeleton.tsx +40 -10
- package/src/components/slider.tsx +83 -57
- package/src/components/sonner.tsx +10 -7
- package/src/components/split-layout.tsx +4 -1
- package/src/index.ts +1 -1
- package/dist/input-base.cjs +0 -1
- package/dist/input-base.d.ts +0 -28
- package/dist/input-base.d.ts.map +0 -1
- package/dist/input-base.js +0 -56
- package/src/components/input-base.tsx +0 -86
|
@@ -3,15 +3,37 @@
|
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
import { format } from "date-fns";
|
|
5
5
|
import { Calendar as CalendarIcon } from "lucide-react";
|
|
6
|
+
import type { DateRange } from "react-day-picker";
|
|
6
7
|
|
|
7
8
|
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
8
|
-
import { inputVariants } from "
|
|
9
|
+
import { inputVariants } from "./input";
|
|
9
10
|
import { Calendar } from "@brightlocal/ui-components/calendar";
|
|
10
11
|
import {
|
|
11
12
|
Popover,
|
|
12
13
|
PopoverContent,
|
|
13
14
|
PopoverTrigger,
|
|
14
15
|
} from "@brightlocal/ui-components/popover";
|
|
16
|
+
import {
|
|
17
|
+
Select,
|
|
18
|
+
SelectContent,
|
|
19
|
+
SelectItem,
|
|
20
|
+
SelectTrigger,
|
|
21
|
+
SelectValue,
|
|
22
|
+
} from "@brightlocal/ui-components/select";
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Preset configuration for DatePicker
|
|
26
|
+
*/
|
|
27
|
+
export interface DatePreset {
|
|
28
|
+
/**
|
|
29
|
+
* Label text for the preset option
|
|
30
|
+
*/
|
|
31
|
+
label: string;
|
|
32
|
+
/**
|
|
33
|
+
* Function that returns the date for this preset
|
|
34
|
+
*/
|
|
35
|
+
date: () => Date;
|
|
36
|
+
}
|
|
15
37
|
|
|
16
38
|
export interface DatePickerProps extends Omit<
|
|
17
39
|
React.ComponentProps<"div">,
|
|
@@ -40,10 +62,6 @@ export interface DatePickerProps extends Omit<
|
|
|
40
62
|
* Callback fired when date selection changes
|
|
41
63
|
*/
|
|
42
64
|
onDateChange?: (date: Date | undefined) => void;
|
|
43
|
-
/**
|
|
44
|
-
* Label text displayed above the date picker
|
|
45
|
-
*/
|
|
46
|
-
label?: string;
|
|
47
65
|
/**
|
|
48
66
|
* Placeholder text when no date is selected
|
|
49
67
|
* @default "Pick a date"
|
|
@@ -53,10 +71,6 @@ export interface DatePickerProps extends Omit<
|
|
|
53
71
|
* Disabled state
|
|
54
72
|
*/
|
|
55
73
|
disabled?: boolean;
|
|
56
|
-
/**
|
|
57
|
-
* Accessible label for screen readers
|
|
58
|
-
*/
|
|
59
|
-
ariaLabel?: string;
|
|
60
74
|
/**
|
|
61
75
|
* Format string for displaying selected date
|
|
62
76
|
* Uses date-fns format tokens
|
|
@@ -65,6 +79,11 @@ export interface DatePickerProps extends Omit<
|
|
|
65
79
|
* @example "PPP" → "December 31st, 2024"
|
|
66
80
|
*/
|
|
67
81
|
dateFormat?: string;
|
|
82
|
+
/**
|
|
83
|
+
* Optional array of preset date options
|
|
84
|
+
* When provided, shows a Select dropdown above the calendar
|
|
85
|
+
*/
|
|
86
|
+
presets?: DatePreset[];
|
|
68
87
|
}
|
|
69
88
|
|
|
70
89
|
const DatePicker = React.forwardRef<HTMLDivElement, DatePickerProps>(
|
|
@@ -76,17 +95,37 @@ const DatePicker = React.forwardRef<HTMLDivElement, DatePickerProps>(
|
|
|
76
95
|
trackingLabel,
|
|
77
96
|
date,
|
|
78
97
|
onDateChange,
|
|
79
|
-
label,
|
|
80
98
|
placeholder = "Pick a date",
|
|
81
99
|
disabled,
|
|
82
|
-
ariaLabel,
|
|
83
100
|
dateFormat = "PPP",
|
|
101
|
+
presets,
|
|
102
|
+
id,
|
|
84
103
|
...props
|
|
85
104
|
},
|
|
86
105
|
ref
|
|
87
106
|
) => {
|
|
88
107
|
const [open, setOpen] = React.useState(false);
|
|
89
108
|
|
|
109
|
+
const calendarElement = (
|
|
110
|
+
<Calendar
|
|
111
|
+
captionLayout="dropdown"
|
|
112
|
+
className={cn(
|
|
113
|
+
"border-0 shadow-none",
|
|
114
|
+
presets && "border-border rounded-lg border"
|
|
115
|
+
)}
|
|
116
|
+
dataHook={`${dataHook}-calendar`}
|
|
117
|
+
disabled={disabled}
|
|
118
|
+
endMonth={new Date(2100, 11, 31)}
|
|
119
|
+
mode="single"
|
|
120
|
+
selected={date}
|
|
121
|
+
startMonth={new Date(1900, 0, 1)}
|
|
122
|
+
onSelect={(selectedDate) => {
|
|
123
|
+
onDateChange?.(selectedDate);
|
|
124
|
+
setOpen(false);
|
|
125
|
+
}}
|
|
126
|
+
/>
|
|
127
|
+
);
|
|
128
|
+
|
|
90
129
|
return (
|
|
91
130
|
<div
|
|
92
131
|
ref={ref}
|
|
@@ -97,14 +136,6 @@ const DatePicker = React.forwardRef<HTMLDivElement, DatePickerProps>(
|
|
|
97
136
|
data-tracking-label={trackingLabel}
|
|
98
137
|
{...props}
|
|
99
138
|
>
|
|
100
|
-
{label && (
|
|
101
|
-
<label
|
|
102
|
-
className="text-foreground text-sm leading-none font-medium"
|
|
103
|
-
data-slot="date-picker-label"
|
|
104
|
-
>
|
|
105
|
-
{label}
|
|
106
|
-
</label>
|
|
107
|
-
)}
|
|
108
139
|
<Popover open={open} onOpenChange={setOpen}>
|
|
109
140
|
<PopoverTrigger asChild>
|
|
110
141
|
<div className="relative flex w-full items-center">
|
|
@@ -116,7 +147,7 @@ const DatePicker = React.forwardRef<HTMLDivElement, DatePickerProps>(
|
|
|
116
147
|
data-slot="calendar-icon"
|
|
117
148
|
/>
|
|
118
149
|
<button
|
|
119
|
-
aria-label={
|
|
150
|
+
aria-label={props["aria-label"] ?? "Select date"}
|
|
120
151
|
className={cn(
|
|
121
152
|
inputVariants({ hasIcon: true }),
|
|
122
153
|
"cursor-pointer justify-start text-left",
|
|
@@ -125,23 +156,243 @@ const DatePicker = React.forwardRef<HTMLDivElement, DatePickerProps>(
|
|
|
125
156
|
data-hook={`${dataHook}-trigger`}
|
|
126
157
|
data-slot="date-picker-trigger"
|
|
127
158
|
disabled={disabled}
|
|
159
|
+
id={id}
|
|
128
160
|
type="button"
|
|
129
161
|
>
|
|
130
162
|
{date ? format(date, dateFormat) : <span>{placeholder}</span>}
|
|
131
163
|
</button>
|
|
132
164
|
</div>
|
|
133
165
|
</PopoverTrigger>
|
|
134
|
-
<PopoverContent align="start" className="w-auto p-0">
|
|
166
|
+
<PopoverContent align="start" className="w-auto rounded-lg p-0">
|
|
167
|
+
{presets ? (
|
|
168
|
+
<div className="flex flex-col gap-2 p-2">
|
|
169
|
+
<Select
|
|
170
|
+
disabled={disabled}
|
|
171
|
+
value={
|
|
172
|
+
date
|
|
173
|
+
? presets.find(
|
|
174
|
+
(p) => p.date().toDateString() === date.toDateString()
|
|
175
|
+
)?.label
|
|
176
|
+
: undefined
|
|
177
|
+
}
|
|
178
|
+
onValueChange={(value) => {
|
|
179
|
+
const preset = presets.find((p) => p.label === value);
|
|
180
|
+
if (preset) {
|
|
181
|
+
onDateChange?.(preset.date());
|
|
182
|
+
}
|
|
183
|
+
}}
|
|
184
|
+
>
|
|
185
|
+
<SelectTrigger
|
|
186
|
+
className="w-full"
|
|
187
|
+
dataHook={`${dataHook}-preset-select`}
|
|
188
|
+
>
|
|
189
|
+
<SelectValue placeholder={placeholder} />
|
|
190
|
+
</SelectTrigger>
|
|
191
|
+
<SelectContent>
|
|
192
|
+
{presets.map((preset) => (
|
|
193
|
+
<SelectItem
|
|
194
|
+
key={preset.label}
|
|
195
|
+
data-hook={`${dataHook}-preset-${preset.label.toLowerCase().replace(/\s+/g, "-")}`}
|
|
196
|
+
value={preset.label}
|
|
197
|
+
>
|
|
198
|
+
{preset.label}
|
|
199
|
+
</SelectItem>
|
|
200
|
+
))}
|
|
201
|
+
</SelectContent>
|
|
202
|
+
</Select>
|
|
203
|
+
{calendarElement}
|
|
204
|
+
</div>
|
|
205
|
+
) : (
|
|
206
|
+
calendarElement
|
|
207
|
+
)}
|
|
208
|
+
</PopoverContent>
|
|
209
|
+
</Popover>
|
|
210
|
+
</div>
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
DatePicker.displayName = "DatePicker";
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Default presets for DatePickerPreset
|
|
219
|
+
*/
|
|
220
|
+
const DEFAULT_PRESETS: DatePreset[] = [
|
|
221
|
+
{
|
|
222
|
+
label: "Today",
|
|
223
|
+
date: () => new Date(),
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
label: "Tomorrow",
|
|
227
|
+
date: () => {
|
|
228
|
+
const d = new Date();
|
|
229
|
+
d.setDate(d.getDate() + 1);
|
|
230
|
+
return d;
|
|
231
|
+
},
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
label: "In 3 days",
|
|
235
|
+
date: () => {
|
|
236
|
+
const d = new Date();
|
|
237
|
+
d.setDate(d.getDate() + 3);
|
|
238
|
+
return d;
|
|
239
|
+
},
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
label: "In a week",
|
|
243
|
+
date: () => {
|
|
244
|
+
const d = new Date();
|
|
245
|
+
d.setDate(d.getDate() + 7);
|
|
246
|
+
return d;
|
|
247
|
+
},
|
|
248
|
+
},
|
|
249
|
+
];
|
|
250
|
+
|
|
251
|
+
export interface DatePickerPresetProps extends Omit<
|
|
252
|
+
DatePickerProps,
|
|
253
|
+
"presets"
|
|
254
|
+
> {
|
|
255
|
+
/**
|
|
256
|
+
* Custom presets to override the defaults
|
|
257
|
+
* @default Default presets: Today, Tomorrow, In 3 days, In a week
|
|
258
|
+
*/
|
|
259
|
+
presets?: DatePreset[];
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* DatePickerPreset - A DatePicker with built-in preset options.
|
|
264
|
+
* Comes with sensible defaults (Today, Tomorrow, In 3 days, In a week)
|
|
265
|
+
* that can be overridden with custom presets.
|
|
266
|
+
*/
|
|
267
|
+
const DatePickerPreset = React.forwardRef<
|
|
268
|
+
HTMLDivElement,
|
|
269
|
+
DatePickerPresetProps
|
|
270
|
+
>(({ presets = DEFAULT_PRESETS, ...props }, ref) => {
|
|
271
|
+
return <DatePicker ref={ref} presets={presets} {...props} />;
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
DatePickerPreset.displayName = "DatePickerPreset";
|
|
275
|
+
|
|
276
|
+
export interface DatePickerRangeProps extends Omit<
|
|
277
|
+
React.ComponentProps<"div">,
|
|
278
|
+
"onSelect"
|
|
279
|
+
> {
|
|
280
|
+
/**
|
|
281
|
+
* Data hook for automated testing (REQUIRED)
|
|
282
|
+
*/
|
|
283
|
+
dataHook: string;
|
|
284
|
+
/**
|
|
285
|
+
* Tracking element identifier for analytics
|
|
286
|
+
*/
|
|
287
|
+
trackingEl?: string;
|
|
288
|
+
/**
|
|
289
|
+
* Tracking label for analytics context
|
|
290
|
+
*/
|
|
291
|
+
trackingLabel?: string;
|
|
292
|
+
/**
|
|
293
|
+
* Selected date range value
|
|
294
|
+
*/
|
|
295
|
+
dateRange?: DateRange;
|
|
296
|
+
/**
|
|
297
|
+
* Callback fired when date range selection changes
|
|
298
|
+
*/
|
|
299
|
+
onDateRangeChange?: (dateRange: DateRange | undefined) => void;
|
|
300
|
+
/**
|
|
301
|
+
* Placeholder text when no date is selected
|
|
302
|
+
* @default "Pick a date range"
|
|
303
|
+
*/
|
|
304
|
+
placeholder?: string;
|
|
305
|
+
/**
|
|
306
|
+
* Disabled state
|
|
307
|
+
*/
|
|
308
|
+
disabled?: boolean;
|
|
309
|
+
/**
|
|
310
|
+
* Format string for displaying selected dates
|
|
311
|
+
* @default "PP"
|
|
312
|
+
*/
|
|
313
|
+
dateFormat?: string;
|
|
314
|
+
/**
|
|
315
|
+
* Number of months to display
|
|
316
|
+
* @default 2
|
|
317
|
+
*/
|
|
318
|
+
numberOfMonths?: 1 | 2 | 3;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const DatePickerRange = React.forwardRef<HTMLDivElement, DatePickerRangeProps>(
|
|
322
|
+
(
|
|
323
|
+
{
|
|
324
|
+
className,
|
|
325
|
+
dataHook,
|
|
326
|
+
trackingEl,
|
|
327
|
+
trackingLabel,
|
|
328
|
+
dateRange,
|
|
329
|
+
onDateRangeChange,
|
|
330
|
+
placeholder = "Pick a date range",
|
|
331
|
+
disabled,
|
|
332
|
+
dateFormat = "PP",
|
|
333
|
+
numberOfMonths = 2,
|
|
334
|
+
id,
|
|
335
|
+
...props
|
|
336
|
+
},
|
|
337
|
+
ref
|
|
338
|
+
) => {
|
|
339
|
+
const [open, setOpen] = React.useState(false);
|
|
340
|
+
|
|
341
|
+
const formatDateRange = () => {
|
|
342
|
+
if (!dateRange?.from) return null;
|
|
343
|
+
if (!dateRange.to) return format(dateRange.from, dateFormat);
|
|
344
|
+
return `${format(dateRange.from, dateFormat)} - ${format(dateRange.to, dateFormat)}`;
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
return (
|
|
348
|
+
<div
|
|
349
|
+
ref={ref}
|
|
350
|
+
className={cn("flex w-full flex-col gap-2", className)}
|
|
351
|
+
data-hook={dataHook}
|
|
352
|
+
data-slot="date-picker-range"
|
|
353
|
+
data-tracking-el={trackingEl || "date-picker-range"}
|
|
354
|
+
data-tracking-label={trackingLabel}
|
|
355
|
+
{...props}
|
|
356
|
+
>
|
|
357
|
+
<Popover open={open} onOpenChange={setOpen}>
|
|
358
|
+
<PopoverTrigger asChild>
|
|
359
|
+
<div className="relative flex w-full items-center">
|
|
360
|
+
<CalendarIcon
|
|
361
|
+
className={cn(
|
|
362
|
+
"text-muted-foreground pointer-events-none absolute left-3 flex size-4 items-center",
|
|
363
|
+
disabled && "opacity-50"
|
|
364
|
+
)}
|
|
365
|
+
data-slot="calendar-icon"
|
|
366
|
+
/>
|
|
367
|
+
<button
|
|
368
|
+
aria-label={props["aria-label"] ?? "Select date range"}
|
|
369
|
+
className={cn(
|
|
370
|
+
inputVariants({ hasIcon: true }),
|
|
371
|
+
"cursor-pointer justify-start text-left",
|
|
372
|
+
!dateRange?.from && "text-muted-foreground"
|
|
373
|
+
)}
|
|
374
|
+
data-hook={`${dataHook}-trigger`}
|
|
375
|
+
data-slot="date-picker-trigger"
|
|
376
|
+
disabled={disabled}
|
|
377
|
+
id={id}
|
|
378
|
+
type="button"
|
|
379
|
+
>
|
|
380
|
+
{formatDateRange() || <span>{placeholder}</span>}
|
|
381
|
+
</button>
|
|
382
|
+
</div>
|
|
383
|
+
</PopoverTrigger>
|
|
384
|
+
<PopoverContent align="start" className="w-auto rounded-lg p-0">
|
|
135
385
|
<Calendar
|
|
136
|
-
|
|
386
|
+
captionLayout="dropdown"
|
|
387
|
+
className="border-0 shadow-none"
|
|
137
388
|
dataHook={`${dataHook}-calendar`}
|
|
138
389
|
disabled={disabled}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
390
|
+
endMonth={new Date(2100, 11, 31)}
|
|
391
|
+
mode="range"
|
|
392
|
+
numberOfMonths={numberOfMonths}
|
|
393
|
+
selected={dateRange}
|
|
394
|
+
startMonth={new Date(1900, 0, 1)}
|
|
395
|
+
onSelect={onDateRangeChange}
|
|
145
396
|
/>
|
|
146
397
|
</PopoverContent>
|
|
147
398
|
</Popover>
|
|
@@ -150,6 +401,6 @@ const DatePicker = React.forwardRef<HTMLDivElement, DatePickerProps>(
|
|
|
150
401
|
}
|
|
151
402
|
);
|
|
152
403
|
|
|
153
|
-
|
|
404
|
+
DatePickerRange.displayName = "DatePickerRange";
|
|
154
405
|
|
|
155
|
-
export { DatePicker };
|
|
406
|
+
export { DatePicker, DatePickerPreset, DatePickerRange };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Props for the Description component
|
|
6
|
+
*/
|
|
7
|
+
interface DescriptionProps extends React.ComponentProps<"p"> {
|
|
8
|
+
/**
|
|
9
|
+
* Data hook for automated testing
|
|
10
|
+
* Used to identify component in tests and E2E automation
|
|
11
|
+
*/
|
|
12
|
+
dataHook?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Tracking element identifier for analytics
|
|
15
|
+
* Defaults to "description" if not provided
|
|
16
|
+
*/
|
|
17
|
+
trackingEl?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Tracking label for analytics context
|
|
20
|
+
* Additional context for tracking events
|
|
21
|
+
*/
|
|
22
|
+
trackingLabel?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Base description component for displaying helper text
|
|
27
|
+
*
|
|
28
|
+
* Use this for simple descriptive text. For form fields,
|
|
29
|
+
* use FieldDescription which adds form-specific styles.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```tsx
|
|
33
|
+
* <Description dataHook="help-text">
|
|
34
|
+
* This is a helpful description
|
|
35
|
+
* </Description>
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
const Description = React.forwardRef<HTMLParagraphElement, DescriptionProps>(
|
|
39
|
+
({ className, dataHook, trackingEl, trackingLabel, ...props }, ref) => {
|
|
40
|
+
return (
|
|
41
|
+
<p
|
|
42
|
+
ref={ref}
|
|
43
|
+
className={cn(
|
|
44
|
+
"text-muted-foreground text-left text-sm",
|
|
45
|
+
"[&>a:hover]:text-primary [&>a]:underline [&>a]:underline-offset-4",
|
|
46
|
+
className
|
|
47
|
+
)}
|
|
48
|
+
data-hook={dataHook}
|
|
49
|
+
data-slot="description"
|
|
50
|
+
data-tracking-el={trackingEl || "description"}
|
|
51
|
+
data-tracking-label={trackingLabel}
|
|
52
|
+
{...props}
|
|
53
|
+
/>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
Description.displayName = "Description";
|
|
59
|
+
|
|
60
|
+
export { Description, type DescriptionProps };
|