@sybilion/uilib 1.4.21 → 1.4.22
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/assets/globals.css +3 -0
- package/dist/agent-glossary/workspace.generated.ts +2 -0
- package/dist/agent-glossary/workspace.index.md +2 -0
- package/dist/agent-glossary/workspace.md +2 -0
- package/dist/esm/components/ui/Checkbox/Checkbox.js +2 -2
- package/dist/esm/components/ui/Checkbox/Checkbox.styl.js +2 -2
- package/dist/esm/components/ui/DatePicker/Calendar.js +72 -0
- package/dist/esm/components/ui/DatePicker/DatePicker.js +81 -0
- package/dist/esm/components/ui/DatePicker/DatePicker.styl.js +7 -0
- package/dist/esm/components/ui/DatePicker/DatePickerInput.js +70 -0
- package/dist/esm/components/ui/DatePicker/DateRangePickerInput.js +130 -0
- package/dist/esm/components/ui/DatePicker/dateUtils.js +137 -0
- package/dist/esm/components/ui/RadioGroup/RadioGroup.helpers.js +6 -0
- package/dist/esm/components/ui/RadioGroup/RadioGroup.js +18 -0
- package/dist/esm/components/ui/RadioGroup/RadioGroup.styl.js +7 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/types/src/components/ui/Checkbox/Checkbox.d.ts +1 -1
- package/dist/esm/types/src/components/ui/Checkbox/Checkbox.types.d.ts +2 -0
- package/dist/esm/types/src/components/ui/Checkbox/index.d.ts +1 -1
- package/dist/esm/types/src/components/ui/DatePicker/Calendar.d.ts +2 -0
- package/dist/esm/types/src/components/ui/DatePicker/DatePicker.d.ts +2 -0
- package/dist/esm/types/src/components/ui/DatePicker/DatePicker.types.d.ts +60 -0
- package/dist/esm/types/src/components/ui/DatePicker/DatePickerInput.d.ts +2 -0
- package/dist/esm/types/src/components/ui/DatePicker/DateRangePickerInput.d.ts +2 -0
- package/dist/esm/types/src/components/ui/DatePicker/dateUtils.d.ts +30 -0
- package/dist/esm/types/src/components/ui/DatePicker/index.d.ts +6 -0
- package/dist/esm/types/src/components/ui/RadioGroup/RadioGroup.d.ts +4 -0
- package/dist/esm/types/src/components/ui/RadioGroup/RadioGroup.example.d.ts +1 -0
- package/dist/esm/types/src/components/ui/RadioGroup/RadioGroup.helpers.d.ts +3 -0
- package/dist/esm/types/src/components/ui/RadioGroup/RadioGroup.types.d.ts +11 -0
- package/dist/esm/types/src/components/ui/RadioGroup/index.d.ts +2 -0
- package/dist/esm/types/src/docs/pages/DatePickerPage.d.ts +1 -0
- package/dist/esm/types/src/docs/pages/RadioGroupPage.d.ts +1 -0
- package/dist/esm/types/src/index.d.ts +2 -0
- package/package.json +2 -1
- package/src/components/ui/Checkbox/AGENT.md +1 -0
- package/src/components/ui/Checkbox/Checkbox.styl +26 -2
- package/src/components/ui/Checkbox/Checkbox.styl.d.ts +4 -0
- package/src/components/ui/Checkbox/Checkbox.tsx +3 -3
- package/src/components/ui/Checkbox/Checkbox.types.ts +5 -1
- package/src/components/ui/Checkbox/index.ts +1 -1
- package/src/components/ui/DatePicker/AGENT.md +45 -0
- package/src/components/ui/DatePicker/Calendar.tsx +160 -0
- package/src/components/ui/DatePicker/DatePicker.styl +219 -0
- package/src/components/ui/DatePicker/DatePicker.styl.d.ts +39 -0
- package/src/components/ui/DatePicker/DatePicker.tsx +160 -0
- package/src/components/ui/DatePicker/DatePicker.types.ts +91 -0
- package/src/components/ui/DatePicker/DatePickerInput.tsx +169 -0
- package/src/components/ui/DatePicker/DateRangePickerInput.tsx +276 -0
- package/src/components/ui/DatePicker/dateUtils.ts +199 -0
- package/src/components/ui/DatePicker/index.ts +13 -0
- package/src/components/ui/RadioGroup/AGENT.md +24 -0
- package/src/components/ui/RadioGroup/RadioGroup.example.tsx +136 -0
- package/src/components/ui/RadioGroup/RadioGroup.helpers.ts +11 -0
- package/src/components/ui/RadioGroup/RadioGroup.styl +70 -0
- package/src/components/ui/RadioGroup/RadioGroup.styl.d.ts +13 -0
- package/src/components/ui/RadioGroup/RadioGroup.tsx +58 -0
- package/src/components/ui/RadioGroup/RadioGroup.types.ts +19 -0
- package/src/components/ui/RadioGroup/index.ts +6 -0
- package/src/docs/pages/CheckboxPage.tsx +129 -18
- package/src/docs/pages/DatePickerPage.tsx +183 -0
- package/src/docs/pages/FormsOverviewPage.tsx +131 -0
- package/src/docs/pages/RadioGroupPage.tsx +21 -0
- package/src/docs/registry.ts +12 -0
- package/src/index.ts +2 -0
package/assets/globals.css
CHANGED
|
@@ -24,6 +24,7 @@ Entry point for \`@sybilion/uilib\`. Open linked AGENT.md before using a compone
|
|
|
24
24
|
- [Checkbox](src/components/ui/Checkbox/AGENT.md) — Checkbox is a binary control for selecting or deselecting an option. Pair it with a Label linked via htmlFor so the t…
|
|
25
25
|
- [Chip](src/components/ui/Chip/AGENT.md) — Chips are compact capsules for filters, status labels, version tags, and quantitative delta indicators. Use the defau…
|
|
26
26
|
- [Confirm](src/components/ui/Confirm/AGENT.md) — Confirm is a focused confirmation dialog built on Dialog, with a title, body, and paired confirm and cancel actions. …
|
|
27
|
+
- [DatePicker](src/components/ui/DatePicker/AGENT.md) — DatePickerInput is the primary date field for forms: a text input with a calendar icon that opens a month grid for si…
|
|
27
28
|
- [Dialog](src/components/ui/Dialog/AGENT.md) — Dialog presents content in a modal layer above the page, with a trigger, title, optional subtitle, body content, and …
|
|
28
29
|
- [DonutChart](src/components/ui/DonutChart/AGENT.md) — DonutChart shows how a small number of categories make up a whole. Each datum carries a key, value, and optional labe…
|
|
29
30
|
- [Drawer](src/components/ui/Drawer/AGENT.md) — Drawer is a panel that slides in from the edge of the screen, built on Vaul for touch-friendly drag-to-dismiss behavi…
|
|
@@ -51,6 +52,7 @@ Entry point for \`@sybilion/uilib\`. Open linked AGENT.md before using a compone
|
|
|
51
52
|
- [NumberControl](src/components/ui/NumberControl/AGENT.md) — NumberControl is a numeric stepper with minus and plus buttons for adjusting a value within a bounded range. Configur…
|
|
52
53
|
- [Progress](src/components/ui/Progress/AGENT.md) — Progress is a horizontal bar that communicates how much of a process has completed. Pass a value between 0 and 100 to…
|
|
53
54
|
- [PullQuote](src/components/ui/PullQuote/AGENT.md) — PullQuote presents an editorial quote with a 2px accent rule on the left, display-face body text, and a small Manrope…
|
|
55
|
+
- [RadioGroup](src/components/ui/RadioGroup/AGENT.md) — RadioGroup is a single-choice control for selecting one option from a short list. Pair each RadioGroupItem with a Lab…
|
|
54
56
|
- [RegionCoords](src/components/ui/RegionCoords/AGENT.md) — RegionSelector lets the user pick a named region from a map of geographic coordinates. Pass a record of region names …
|
|
55
57
|
- [Renamer](src/components/ui/Renamer/AGENT.md) — Renamer wraps a displayed name with an inline rename affordance: a pencil control switches the text into an editable …
|
|
56
58
|
- [Select](src/components/ui/Select/AGENT.md) — Select is a Radix-based dropdown for choosing a single option from a list. Compose it from Select, SelectTrigger, Sel…
|
|
@@ -23,6 +23,7 @@ Entry point for `@sybilion/uilib`. Open linked AGENT.md before using a component
|
|
|
23
23
|
- [Checkbox](src/components/ui/Checkbox/AGENT.md) — Checkbox is a binary control for selecting or deselecting an option. Pair it with a Label linked via htmlFor so the t…
|
|
24
24
|
- [Chip](src/components/ui/Chip/AGENT.md) — Chips are compact capsules for filters, status labels, version tags, and quantitative delta indicators. Use the defau…
|
|
25
25
|
- [Confirm](src/components/ui/Confirm/AGENT.md) — Confirm is a focused confirmation dialog built on Dialog, with a title, body, and paired confirm and cancel actions. …
|
|
26
|
+
- [DatePicker](src/components/ui/DatePicker/AGENT.md) — DatePickerInput is the primary date field for forms: a text input with a calendar icon that opens a month grid for si…
|
|
26
27
|
- [Dialog](src/components/ui/Dialog/AGENT.md) — Dialog presents content in a modal layer above the page, with a trigger, title, optional subtitle, body content, and …
|
|
27
28
|
- [DonutChart](src/components/ui/DonutChart/AGENT.md) — DonutChart shows how a small number of categories make up a whole. Each datum carries a key, value, and optional labe…
|
|
28
29
|
- [Drawer](src/components/ui/Drawer/AGENT.md) — Drawer is a panel that slides in from the edge of the screen, built on Vaul for touch-friendly drag-to-dismiss behavi…
|
|
@@ -50,6 +51,7 @@ Entry point for `@sybilion/uilib`. Open linked AGENT.md before using a component
|
|
|
50
51
|
- [NumberControl](src/components/ui/NumberControl/AGENT.md) — NumberControl is a numeric stepper with minus and plus buttons for adjusting a value within a bounded range. Configur…
|
|
51
52
|
- [Progress](src/components/ui/Progress/AGENT.md) — Progress is a horizontal bar that communicates how much of a process has completed. Pass a value between 0 and 100 to…
|
|
52
53
|
- [PullQuote](src/components/ui/PullQuote/AGENT.md) — PullQuote presents an editorial quote with a 2px accent rule on the left, display-face body text, and a small Manrope…
|
|
54
|
+
- [RadioGroup](src/components/ui/RadioGroup/AGENT.md) — RadioGroup is a single-choice control for selecting one option from a short list. Pair each RadioGroupItem with a Lab…
|
|
53
55
|
- [RegionCoords](src/components/ui/RegionCoords/AGENT.md) — RegionSelector lets the user pick a named region from a map of geographic coordinates. Pass a record of region names …
|
|
54
56
|
- [Renamer](src/components/ui/Renamer/AGENT.md) — Renamer wraps a displayed name with an inline rename affordance: a pencil control switches the text into an editable …
|
|
55
57
|
- [Select](src/components/ui/Select/AGENT.md) — Select is a Radix-based dropdown for choosing a single option from a list. Compose it from Select, SelectTrigger, Sel…
|
|
@@ -23,6 +23,7 @@ Entry point for `@sybilion/uilib`. Open linked AGENT.md before using a component
|
|
|
23
23
|
- [Checkbox](src/components/ui/Checkbox/AGENT.md) — Checkbox is a binary control for selecting or deselecting an option. Pair it with a Label linked via htmlFor so the t…
|
|
24
24
|
- [Chip](src/components/ui/Chip/AGENT.md) — Chips are compact capsules for filters, status labels, version tags, and quantitative delta indicators. Use the defau…
|
|
25
25
|
- [Confirm](src/components/ui/Confirm/AGENT.md) — Confirm is a focused confirmation dialog built on Dialog, with a title, body, and paired confirm and cancel actions. …
|
|
26
|
+
- [DatePicker](src/components/ui/DatePicker/AGENT.md) — DatePickerInput is the primary date field for forms: a text input with a calendar icon that opens a month grid for si…
|
|
26
27
|
- [Dialog](src/components/ui/Dialog/AGENT.md) — Dialog presents content in a modal layer above the page, with a trigger, title, optional subtitle, body content, and …
|
|
27
28
|
- [DonutChart](src/components/ui/DonutChart/AGENT.md) — DonutChart shows how a small number of categories make up a whole. Each datum carries a key, value, and optional labe…
|
|
28
29
|
- [Drawer](src/components/ui/Drawer/AGENT.md) — Drawer is a panel that slides in from the edge of the screen, built on Vaul for touch-friendly drag-to-dismiss behavi…
|
|
@@ -50,6 +51,7 @@ Entry point for `@sybilion/uilib`. Open linked AGENT.md before using a component
|
|
|
50
51
|
- [NumberControl](src/components/ui/NumberControl/AGENT.md) — NumberControl is a numeric stepper with minus and plus buttons for adjusting a value within a bounded range. Configur…
|
|
51
52
|
- [Progress](src/components/ui/Progress/AGENT.md) — Progress is a horizontal bar that communicates how much of a process has completed. Pass a value between 0 and 100 to…
|
|
52
53
|
- [PullQuote](src/components/ui/PullQuote/AGENT.md) — PullQuote presents an editorial quote with a 2px accent rule on the left, display-face body text, and a small Manrope…
|
|
54
|
+
- [RadioGroup](src/components/ui/RadioGroup/AGENT.md) — RadioGroup is a single-choice control for selecting one option from a short list. Pair each RadioGroupItem with a Lab…
|
|
53
55
|
- [RegionCoords](src/components/ui/RegionCoords/AGENT.md) — RegionSelector lets the user pick a named region from a map of geographic coordinates. Pass a record of region names …
|
|
54
56
|
- [Renamer](src/components/ui/Renamer/AGENT.md) — Renamer wraps a displayed name with an inline rename affordance: a pencil control switches the text into an editable …
|
|
55
57
|
- [Select](src/components/ui/Select/AGENT.md) — Select is a Radix-based dropdown for choosing a single option from a list. Compose it from Select, SelectTrigger, Sel…
|
|
@@ -4,8 +4,8 @@ import { CheckIcon } from '@phosphor-icons/react';
|
|
|
4
4
|
import * as CheckboxPrimitive from '@radix-ui/react-checkbox';
|
|
5
5
|
import S from './Checkbox.styl.js';
|
|
6
6
|
|
|
7
|
-
function Checkbox({ className, ...props }) {
|
|
8
|
-
return (jsx(CheckboxPrimitive.Root, { "data-slot": "checkbox", className: cn(S.checkboxRoot, className), ...props, children: jsx(CheckboxPrimitive.Indicator, { "data-slot": "checkbox-indicator", className: S.checkboxIndicator, children: jsx(CheckIcon, { className:
|
|
7
|
+
function Checkbox({ className, size = 'md', ...props }) {
|
|
8
|
+
return (jsx(CheckboxPrimitive.Root, { "data-slot": "checkbox", className: cn(S.checkboxRoot, S[`size-${size}`], className), ...props, children: jsx(CheckboxPrimitive.Indicator, { "data-slot": "checkbox-indicator", className: S.checkboxIndicator, children: jsx(CheckIcon, { className: S.checkIcon }) }) }));
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export { Checkbox };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import styleInject from 'style-inject';
|
|
2
2
|
|
|
3
|
-
var css_248z = ".Checkbox_checkboxRoot__r1zFW{background:transparent;border:1px solid var(--input);border-radius:var(--radius-2);box-shadow:0 1px 2px 0 rgba(0,0,0,.05);cursor:pointer;flex-shrink:0;
|
|
4
|
-
var S = {"checkboxRoot":"Checkbox_checkboxRoot__r1zFW","dark":"Checkbox_dark__l-gfs","checkboxIndicator":"Checkbox_checkboxIndicator__4fmLx"};
|
|
3
|
+
var css_248z = ".Checkbox_checkboxRoot__r1zFW{background:transparent;border:1px solid var(--input);border-radius:var(--radius-2);box-shadow:0 1px 2px 0 rgba(0,0,0,.05);cursor:pointer;flex-shrink:0;outline:none;transition:box-shadow .15s ease-in-out}.Checkbox_dark__l-gfs .Checkbox_checkboxRoot__r1zFW{background-color:var(--input-30)}.Checkbox_checkboxRoot__r1zFW[data-state=checked]{background-color:var(--primary);border-color:var(--primary);color:var(--primary-foreground)}.Checkbox_dark__l-gfs .Checkbox_checkboxRoot__r1zFW[data-state=checked]{background-color:var(--primary)}.Checkbox_checkboxRoot__r1zFW:focus-visible{border-color:var(--ring);box-shadow:0 0 0 3px var(--ring-50)}.Checkbox_checkboxRoot__r1zFW[aria-invalid=true]{border-color:var(--destructive);box-shadow:0 0 0 3px var(--destructive-200)}.Checkbox_dark__l-gfs .Checkbox_checkboxRoot__r1zFW[aria-invalid=true]{box-shadow:0 0 0 3px var(--destructive-400)}.Checkbox_checkboxRoot__r1zFW:disabled{cursor:not-allowed;opacity:.5}.Checkbox_size-sm__Exhtm{height:var(--icon-size-sm);width:var(--icon-size-sm)}.Checkbox_size-sm__Exhtm .Checkbox_checkIcon__4XHoy{height:10px;width:10px}.Checkbox_size-md__Zj0Aq{height:var(--icon-size-md);width:var(--icon-size-md)}.Checkbox_size-md__Zj0Aq .Checkbox_checkIcon__4XHoy{height:12px;width:12px}.Checkbox_size-lg__NTUdV{height:var(--icon-size-lg);width:var(--icon-size-lg)}.Checkbox_size-lg__NTUdV .Checkbox_checkIcon__4XHoy{height:var(--icon-size-sm);width:var(--icon-size-sm)}.Checkbox_checkboxIndicator__4fmLx{align-items:center;color:currentColor;display:flex;justify-content:center;transition:none}.Checkbox_checkIcon__4XHoy{flex-shrink:0}";
|
|
4
|
+
var S = {"checkboxRoot":"Checkbox_checkboxRoot__r1zFW","dark":"Checkbox_dark__l-gfs","size-sm":"Checkbox_size-sm__Exhtm","checkIcon":"Checkbox_checkIcon__4XHoy","size-md":"Checkbox_size-md__Zj0Aq","size-lg":"Checkbox_size-lg__NTUdV","checkboxIndicator":"Checkbox_checkboxIndicator__4fmLx"};
|
|
5
5
|
styleInject(css_248z);
|
|
6
6
|
|
|
7
7
|
export { S as default };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import cn from 'classnames';
|
|
3
|
+
import { useMemo } from 'react';
|
|
4
|
+
import { Button } from '../Button/Button.js';
|
|
5
|
+
import S from './DatePicker.styl.js';
|
|
6
|
+
import { parseDateString, getTodayParts, normalizeDateRange, formatDateString, getMonthMatrix, getWeekdayLabels, isSameDate, isDateDisabled, isBetweenDates } from './dateUtils.js';
|
|
7
|
+
|
|
8
|
+
function Calendar({ className, mode = 'single', value, rangeStart, rangeEnd, rangeHover, viewMonth, onViewMonthChange, onSelect, onDayHover, startOfWeek = 0, minDate, maxDate, disabledDate, size = 'md', }) {
|
|
9
|
+
const selected = parseDateString(value);
|
|
10
|
+
const today = getTodayParts();
|
|
11
|
+
const visibleMonth = viewMonth ?? {
|
|
12
|
+
year: selected?.year ?? today.year,
|
|
13
|
+
month: selected?.month ?? today.month,
|
|
14
|
+
};
|
|
15
|
+
const rangeBounds = useMemo(() => {
|
|
16
|
+
if (mode !== 'range') {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
const start = parseDateString(rangeStart);
|
|
20
|
+
const tentativeEnd = parseDateString(rangeEnd ?? rangeHover);
|
|
21
|
+
if (!start || !tentativeEnd) {
|
|
22
|
+
if (start) {
|
|
23
|
+
return { start, end: start };
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
const normalized = normalizeDateRange(formatDateString(start), formatDateString(tentativeEnd));
|
|
28
|
+
const end = parseDateString(normalized.end);
|
|
29
|
+
return end ? { start: parseDateString(normalized.start), end } : null;
|
|
30
|
+
}, [mode, rangeEnd, rangeHover, rangeStart]);
|
|
31
|
+
const days = useMemo(() => getMonthMatrix(visibleMonth.year, visibleMonth.month, startOfWeek), [visibleMonth.month, visibleMonth.year, startOfWeek]);
|
|
32
|
+
const weekdayLabels = useMemo(() => getWeekdayLabels(startOfWeek), [startOfWeek]);
|
|
33
|
+
const isSelectingRange = mode === 'range' && rangeStart && !rangeEnd;
|
|
34
|
+
return (jsxs("div", { className: cn(S.calendar, S[`calendarSize-${size}`], className), "data-slot": "calendar", "data-mode": mode, onMouseLeave: () => onDayHover?.(undefined), children: [jsx("div", { className: S.weekdayRow, role: "row", children: weekdayLabels.map(label => (jsx("div", { className: S.weekdayCell, role: "columnheader", children: label }, label))) }), jsx("div", { className: S.dayGrid, role: "grid", children: days.map(day => {
|
|
35
|
+
const inCurrentMonth = day.month === visibleMonth.month;
|
|
36
|
+
const isSelected = mode === 'single' && selected ? isSameDate(day, selected) : false;
|
|
37
|
+
const isToday = isSameDate(day, today);
|
|
38
|
+
const disabled = isDateDisabled(day, {
|
|
39
|
+
minDate,
|
|
40
|
+
maxDate,
|
|
41
|
+
disabledDate,
|
|
42
|
+
});
|
|
43
|
+
const dateValue = formatDateString(day);
|
|
44
|
+
const isRangeStart = rangeBounds && isSameDate(day, rangeBounds.start);
|
|
45
|
+
const isRangeEnd = rangeBounds && isSameDate(day, rangeBounds.end);
|
|
46
|
+
const isInRange = rangeBounds &&
|
|
47
|
+
isBetweenDates(day, rangeBounds.start, rangeBounds.end) &&
|
|
48
|
+
!isRangeStart &&
|
|
49
|
+
!isRangeEnd;
|
|
50
|
+
const isPreview = isSelectingRange &&
|
|
51
|
+
isInRange &&
|
|
52
|
+
rangeHover &&
|
|
53
|
+
!parseDateString(rangeEnd);
|
|
54
|
+
return (jsx(Button, { size: size, type: "button", role: "gridcell", "aria-selected": isSelected || isRangeStart || isRangeEnd, "aria-current": isToday ? 'date' : undefined, "aria-disabled": disabled || undefined, disabled: disabled, className: cn(S.dayCell, !inCurrentMonth && S.dayOutsideMonth, isSelected && S.daySelected, isToday && S.dayToday, isInRange && S.dayInRange, isPreview && S.dayInRangePreview, isRangeStart && S.dayRangeStart, isRangeEnd && S.dayRangeEnd), onMouseEnter: () => {
|
|
55
|
+
if (disabled || mode !== 'range') {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
onDayHover?.(dateValue);
|
|
59
|
+
}, onClick: () => {
|
|
60
|
+
if (disabled) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
onSelect?.(dateValue);
|
|
64
|
+
if (day.month !== visibleMonth.month ||
|
|
65
|
+
day.year !== visibleMonth.year) {
|
|
66
|
+
onViewMonthChange?.({ year: day.year, month: day.month });
|
|
67
|
+
}
|
|
68
|
+
}, children: day.day }, dateValue));
|
|
69
|
+
}) })] }));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export { Calendar };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import cn from 'classnames';
|
|
3
|
+
import { useState, useEffect, useMemo, useCallback } from 'react';
|
|
4
|
+
import { CaretLeft, CaretRight } from '@phosphor-icons/react';
|
|
5
|
+
import { Button } from '../Button/Button.js';
|
|
6
|
+
import { Calendar } from './Calendar.js';
|
|
7
|
+
import S from './DatePicker.styl.js';
|
|
8
|
+
import { parseDateString, getTodayParts, formatMonthYear, addMonths, normalizeDateRange } from './dateUtils.js';
|
|
9
|
+
|
|
10
|
+
function DatePicker({ className, mode = 'single', value, onChange, rangeValue, onRangeChange, size = 'md', calendarProps, }) {
|
|
11
|
+
const selected = parseDateString(value);
|
|
12
|
+
const rangeStartParsed = parseDateString(rangeValue?.start);
|
|
13
|
+
const today = getTodayParts();
|
|
14
|
+
const [viewMonth, setViewMonth] = useState(() => ({
|
|
15
|
+
year: selected?.year ??
|
|
16
|
+
rangeStartParsed?.year ??
|
|
17
|
+
parseDateString(rangeValue?.end)?.year ??
|
|
18
|
+
today.year,
|
|
19
|
+
month: selected?.month ??
|
|
20
|
+
rangeStartParsed?.month ??
|
|
21
|
+
parseDateString(rangeValue?.end)?.month ??
|
|
22
|
+
today.month,
|
|
23
|
+
}));
|
|
24
|
+
const [pendingStart, setPendingStart] = useState();
|
|
25
|
+
const [rangeHover, setRangeHover] = useState();
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
const parsed = parseDateString(value);
|
|
28
|
+
if (parsed) {
|
|
29
|
+
setViewMonth({ year: parsed.year, month: parsed.month });
|
|
30
|
+
}
|
|
31
|
+
}, [value]);
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
const parsed = parseDateString(rangeValue?.start) ?? parseDateString(rangeValue?.end);
|
|
34
|
+
if (parsed) {
|
|
35
|
+
setViewMonth({ year: parsed.year, month: parsed.month });
|
|
36
|
+
}
|
|
37
|
+
}, [rangeValue?.end, rangeValue?.start]);
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (rangeValue?.start && rangeValue?.end) {
|
|
40
|
+
setPendingStart(undefined);
|
|
41
|
+
setRangeHover(undefined);
|
|
42
|
+
}
|
|
43
|
+
}, [rangeValue?.end, rangeValue?.start]);
|
|
44
|
+
const monthLabel = useMemo(() => formatMonthYear(viewMonth.year, viewMonth.month), [viewMonth.month, viewMonth.year]);
|
|
45
|
+
const handlePrevMonth = useCallback(() => {
|
|
46
|
+
setViewMonth(current => addMonths(current, -1));
|
|
47
|
+
}, []);
|
|
48
|
+
const handleNextMonth = useCallback(() => {
|
|
49
|
+
setViewMonth(current => addMonths(current, 1));
|
|
50
|
+
}, []);
|
|
51
|
+
const handleSelect = useCallback((nextValue) => {
|
|
52
|
+
if (mode === 'single') {
|
|
53
|
+
onChange?.(nextValue);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const hasCompleteRange = Boolean(rangeValue?.start && rangeValue?.end);
|
|
57
|
+
const activeStart = pendingStart ?? rangeValue?.start;
|
|
58
|
+
if (!activeStart || hasCompleteRange) {
|
|
59
|
+
setPendingStart(nextValue);
|
|
60
|
+
setRangeHover(undefined);
|
|
61
|
+
onRangeChange?.({ start: nextValue, end: '' });
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const normalized = normalizeDateRange(activeStart, nextValue);
|
|
65
|
+
setPendingStart(undefined);
|
|
66
|
+
setRangeHover(undefined);
|
|
67
|
+
onRangeChange?.(normalized);
|
|
68
|
+
}, [
|
|
69
|
+
mode,
|
|
70
|
+
onChange,
|
|
71
|
+
onRangeChange,
|
|
72
|
+
pendingStart,
|
|
73
|
+
rangeValue?.end,
|
|
74
|
+
rangeValue?.start,
|
|
75
|
+
]);
|
|
76
|
+
const activeRangeStart = pendingStart ?? rangeValue?.start;
|
|
77
|
+
const activeRangeEnd = rangeValue?.end;
|
|
78
|
+
return (jsxs("div", { className: cn(S.picker, S[`pickerSize-${size}`], className), "data-slot": "date-picker", "data-mode": mode, children: [jsxs("div", { className: S.pickerHeader, children: [jsx(Button, { type: "button", variant: "ghost", size: size, icon: true, "aria-label": "Previous month", onClick: handlePrevMonth, children: jsx(CaretLeft, { size: 16 }) }), jsx("div", { className: S.pickerMonthLabel, children: monthLabel }), jsx(Button, { type: "button", variant: "ghost", size: size, icon: true, "aria-label": "Next month", onClick: handleNextMonth, children: jsx(CaretRight, { size: 16 }) })] }), jsx(Calendar, { mode: mode, value: value, rangeStart: activeRangeStart, rangeEnd: activeRangeEnd, rangeHover: rangeHover, onDayHover: setRangeHover, viewMonth: viewMonth, onViewMonthChange: setViewMonth, onSelect: handleSelect, size: size, ...calendarProps })] }));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export { DatePicker };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import styleInject from 'style-inject';
|
|
2
|
+
|
|
3
|
+
var css_248z = "@media (max-width:768px){:root{--page-x-padding:var(--p-6);--page-y-padding:var(--p-6)}}.DatePicker_inputRoot__I05aT{align-items:stretch;display:flex;position:relative;width:100%}.DatePicker_inputField__9gMsb{padding-right:2.5rem}.DatePicker_calendarTrigger__kV-on{color:var(--muted-foreground);position:absolute;right:.25rem;top:50%;transform:translateY(-50%)}.DatePicker_calendarTrigger__kV-on:hover{color:var(--foreground)}.DatePicker_popupContent__80qAa{min-width:17.5rem;padding:var(--p-2)}.DatePicker_popupContent-sm__bNSi0{min-width:auto;width:-moz-fit-content;width:fit-content}.DatePicker_picker__N7DuK{display:flex;flex-direction:column;gap:var(--p-2)}.DatePicker_pickerHeader__acx36{align-items:center;display:flex;gap:var(--p-1);justify-content:space-between;width:100%}.DatePicker_pickerMonthLabel__750w0{color:var(--foreground);flex:1;font-size:var(--text-sm);font-weight:600;text-align:center}.DatePicker_calendar__cjaLN{display:flex;flex-direction:column;gap:var(--p-1)}.DatePicker_weekdayRow__FREkB{display:grid;grid-template-columns:repeat(7,1fr);grid-gap:0;gap:0}.DatePicker_weekdayCell__2LXNH{align-items:center;color:var(--muted-foreground);display:flex;font-size:var(--text-xs);font-weight:500;height:2rem;justify-content:center}.DatePicker_dayGrid__glrxi{display:grid;grid-template-columns:repeat(7,1fr);grid-gap:0;gap:0}.DatePicker_dayCell__hK6cT{align-items:center;background-color:transparent;border:none;color:var(--foreground);cursor:pointer;display:flex;justify-content:center;transition:background-color .15s,color .15s}.DatePicker_dayCell__hK6cT:hover:not(:disabled){background-color:var(--accent);color:var(--accent-foreground)}.DatePicker_dayCell__hK6cT:focus-visible{outline:2px solid var(--ring);outline-offset:1px}.DatePicker_dayCell__hK6cT:disabled{cursor:not-allowed;opacity:.35}.DatePicker_dayOutsideMonth__DLU5u{color:var(--muted-foreground)}.DatePicker_daySelected__Bklm8,.DatePicker_daySelected__Bklm8:hover:not(:disabled){background-color:var(--primary);color:var(--primary-foreground)}.DatePicker_dayToday__0m3Eg:not(.DatePicker_daySelected__Bklm8):not(.DatePicker_dayRangeStart__NqI7O):not(.DatePicker_dayRangeEnd__3zChr){box-shadow:inset 0 0 0 1px var(--ring)}.DatePicker_dayInRange__28EU5{border-radius:0}.DatePicker_dayInRange__28EU5,.DatePicker_dayInRange__28EU5:hover:not(:disabled){background-color:var(--accent);color:var(--accent-foreground)}.DatePicker_dayInRangePreview__ruAB9{background-color:color-mix(in srgb,var(--accent) 70%,transparent)}.DatePicker_dayRangeStart__NqI7O{border-bottom-right-radius:0;border-top-right-radius:0}.DatePicker_dayRangeEnd__3zChr,.DatePicker_dayRangeStart__NqI7O,.DatePicker_dayRangeStart__NqI7O:hover:not(:disabled){background-color:var(--primary);color:var(--primary-foreground)}.DatePicker_dayRangeEnd__3zChr{border-bottom-left-radius:0;border-top-left-radius:0}.DatePicker_dayRangeEnd__3zChr:hover:not(:disabled){background-color:var(--primary);color:var(--primary-foreground)}.DatePicker_dayRangeStart__NqI7O.DatePicker_dayRangeEnd__3zChr{border-radius:var(--radius-input)}.DatePicker_rangeInputRoot__I5JQB{align-items:stretch;display:flex;position:relative;width:100%}.DatePicker_rangeInputField__C9xYd{flex:1;min-width:0}.DatePicker_rangeInputFieldActive__s-sn2{box-shadow:inset 0 0 0 2px var(--brand-color-400)!important}.DatePicker_rangeSeparator__u-ma7{align-items:center;color:var(--muted-foreground);display:flex;padding:0 var(--p-1);-webkit-user-select:none;-moz-user-select:none;user-select:none}.DatePicker_rangeCalendarTrigger__i6QC7{color:var(--muted-foreground);position:absolute;right:.25rem;top:50%;transform:translateY(-50%)}.DatePicker_rangeCalendarTrigger__i6QC7:hover{color:var(--foreground)}.DatePicker_rangeInputRoot__I5JQB .DatePicker_rangeInputField__C9xYd:last-of-type{padding-right:2.5rem}.DatePicker_calendarSize-sm__8Rz-S .DatePicker_dayCell__hK6cT,.DatePicker_inputSize-sm__JZ7yq .DatePicker_dayCell__hK6cT,.DatePicker_pickerSize-sm__r4J2Y .DatePicker_dayCell__hK6cT{font-size:var(--text-xs);height:var(--p-6);width:var(--p-6)}.DatePicker_pickerSize-sm__r4J2Y{align-items:center}.DatePicker_calendarSize-sm__8Rz-S{width:-moz-fit-content;width:fit-content}.DatePicker_calendarSize-sm__8Rz-S .DatePicker_dayGrid__glrxi,.DatePicker_calendarSize-sm__8Rz-S .DatePicker_weekdayRow__FREkB{grid-template-columns:repeat(7,var(--p-6));width:-moz-fit-content;width:fit-content}.DatePicker_calendarSize-md__NR1IS .DatePicker_dayCell__hK6cT,.DatePicker_inputSize-md__IB5B2 .DatePicker_dayCell__hK6cT{font-size:var(--text-sm);height:var(--p-10);width:var(--p-10)}.DatePicker_calendarSize-lg__erHC- .DatePicker_dayCell__hK6cT,.DatePicker_pickerSize-lg__Typ1j .DatePicker_dayCell__hK6cT{font-size:var(--text-base);height:var(--p-10);width:var(--p-10)}.DatePicker_srOnly__XfGTn{height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;width:1px;clip:rect(0,0,0,0);border:0;white-space:nowrap}";
|
|
4
|
+
var S = {"inputRoot":"DatePicker_inputRoot__I05aT","inputField":"DatePicker_inputField__9gMsb","calendarTrigger":"DatePicker_calendarTrigger__kV-on","popupContent":"DatePicker_popupContent__80qAa","popupContent-sm":"DatePicker_popupContent-sm__bNSi0","picker":"DatePicker_picker__N7DuK","pickerHeader":"DatePicker_pickerHeader__acx36","pickerMonthLabel":"DatePicker_pickerMonthLabel__750w0","calendar":"DatePicker_calendar__cjaLN","weekdayRow":"DatePicker_weekdayRow__FREkB","weekdayCell":"DatePicker_weekdayCell__2LXNH","dayGrid":"DatePicker_dayGrid__glrxi","dayCell":"DatePicker_dayCell__hK6cT","dayOutsideMonth":"DatePicker_dayOutsideMonth__DLU5u","daySelected":"DatePicker_daySelected__Bklm8","dayToday":"DatePicker_dayToday__0m3Eg","dayRangeStart":"DatePicker_dayRangeStart__NqI7O","dayRangeEnd":"DatePicker_dayRangeEnd__3zChr","dayInRange":"DatePicker_dayInRange__28EU5","dayInRangePreview":"DatePicker_dayInRangePreview__ruAB9","rangeInputRoot":"DatePicker_rangeInputRoot__I5JQB","rangeInputField":"DatePicker_rangeInputField__C9xYd","rangeInputFieldActive":"DatePicker_rangeInputFieldActive__s-sn2","rangeSeparator":"DatePicker_rangeSeparator__u-ma7","rangeCalendarTrigger":"DatePicker_rangeCalendarTrigger__i6QC7","inputSize-sm":"DatePicker_inputSize-sm__JZ7yq","pickerSize-sm":"DatePicker_pickerSize-sm__r4J2Y","calendarSize-sm":"DatePicker_calendarSize-sm__8Rz-S","inputSize-md":"DatePicker_inputSize-md__IB5B2","calendarSize-md":"DatePicker_calendarSize-md__NR1IS","pickerSize-lg":"DatePicker_pickerSize-lg__Typ1j","calendarSize-lg":"DatePicker_calendarSize-lg__erHC-","srOnly":"DatePicker_srOnly__XfGTn"};
|
|
5
|
+
styleInject(css_248z);
|
|
6
|
+
|
|
7
|
+
export { S as default };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import cn from 'classnames';
|
|
3
|
+
import { useId, useState, useCallback } from 'react';
|
|
4
|
+
import { CalendarBlank } from '@phosphor-icons/react';
|
|
5
|
+
import { Button } from '../Button/Button.js';
|
|
6
|
+
import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent } from '../DropdownMenu/DropdownMenu.js';
|
|
7
|
+
import { Input } from '../Input/Input.js';
|
|
8
|
+
import { DatePicker } from './DatePicker.js';
|
|
9
|
+
import S from './DatePicker.styl.js';
|
|
10
|
+
import { parseDateString, formatDateString, formatDisplayDate } from './dateUtils.js';
|
|
11
|
+
|
|
12
|
+
function DatePickerInput({ className, value: controlledValue, defaultValue, onChange, size = 'md', placeholder = 'YYYY-MM-DD', disabled, minDate, maxDate, disabledDate, calendarProps, open: controlledOpen, onOpenChange, id: idProp, displayFormat: _displayFormat, variant = 'default', ...inputProps }) {
|
|
13
|
+
const generatedId = useId();
|
|
14
|
+
const inputId = idProp ?? generatedId;
|
|
15
|
+
const [uncontrolledValue, setUncontrolledValue] = useState(defaultValue);
|
|
16
|
+
const [uncontrolledOpen, setUncontrolledOpen] = useState(false);
|
|
17
|
+
const [draftValue, setDraftValue] = useState();
|
|
18
|
+
const value = controlledValue ?? uncontrolledValue;
|
|
19
|
+
const open = controlledOpen ?? uncontrolledOpen;
|
|
20
|
+
const setOpen = useCallback((nextOpen) => {
|
|
21
|
+
if (controlledOpen === undefined) {
|
|
22
|
+
setUncontrolledOpen(nextOpen);
|
|
23
|
+
}
|
|
24
|
+
onOpenChange?.(nextOpen);
|
|
25
|
+
}, [controlledOpen, onOpenChange]);
|
|
26
|
+
const commitValue = useCallback((nextValue) => {
|
|
27
|
+
if (controlledValue === undefined) {
|
|
28
|
+
setUncontrolledValue(nextValue);
|
|
29
|
+
}
|
|
30
|
+
onChange?.(nextValue);
|
|
31
|
+
}, [controlledValue, onChange]);
|
|
32
|
+
const handleInputChange = useCallback((event) => {
|
|
33
|
+
const nextValue = event.target.value;
|
|
34
|
+
setDraftValue(nextValue);
|
|
35
|
+
if (!nextValue) {
|
|
36
|
+
commitValue(undefined);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (parseDateString(nextValue)) {
|
|
40
|
+
commitValue(nextValue);
|
|
41
|
+
}
|
|
42
|
+
}, [commitValue]);
|
|
43
|
+
const handleInputBlur = useCallback(() => {
|
|
44
|
+
if (draftValue === undefined) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const parsed = parseDateString(draftValue);
|
|
48
|
+
if (parsed) {
|
|
49
|
+
commitValue(formatDateString(parsed));
|
|
50
|
+
}
|
|
51
|
+
else if (!draftValue) {
|
|
52
|
+
commitValue(undefined);
|
|
53
|
+
}
|
|
54
|
+
setDraftValue(undefined);
|
|
55
|
+
}, [commitValue, draftValue]);
|
|
56
|
+
const handleDateSelect = useCallback((nextValue) => {
|
|
57
|
+
commitValue(nextValue);
|
|
58
|
+
setDraftValue(undefined);
|
|
59
|
+
setOpen(false);
|
|
60
|
+
}, [commitValue, setOpen]);
|
|
61
|
+
const displayValue = draftValue !== undefined ? draftValue : (value ?? '');
|
|
62
|
+
return (jsxs("div", { className: cn(S.inputRoot, S[`inputSize-${size}`], className), "data-slot": "date-picker-input", children: [jsx(Input, { ...inputProps, type: "text", variant: variant, id: inputId, size: size, value: displayValue, placeholder: placeholder, disabled: disabled, onChange: handleInputChange, onBlur: handleInputBlur, onFocus: () => setOpen(true), className: S.inputField, autoComplete: "off", inputMode: "numeric" }), jsxs(DropdownMenu, { open: open, onOpenChange: setOpen, modal: false, children: [jsx(DropdownMenuTrigger, { asChild: true, children: jsx(Button, { type: "button", variant: "ghost", size: "sm", icon: true, disabled: disabled, className: S.calendarTrigger, "aria-label": "Open calendar", onClick: () => setOpen(true), children: jsx(CalendarBlank, { size: 16 }) }) }), jsx(DropdownMenuContent, { align: "end", sideOffset: 4, className: cn(S.popupContent, size === 'sm' && S['popupContent-sm']), onCloseAutoFocus: event => event.preventDefault(), children: jsx(DatePicker, { value: value, onChange: handleDateSelect, size: size, calendarProps: {
|
|
63
|
+
minDate,
|
|
64
|
+
maxDate,
|
|
65
|
+
disabledDate,
|
|
66
|
+
...calendarProps,
|
|
67
|
+
} }) })] }), jsx("span", { className: S.srOnly, "aria-live": "polite", children: value ? formatDisplayDate(value) : '' })] }));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export { DatePickerInput };
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import cn from 'classnames';
|
|
3
|
+
import { useId, useState, useCallback } from 'react';
|
|
4
|
+
import { CalendarBlank } from '@phosphor-icons/react';
|
|
5
|
+
import { Button } from '../Button/Button.js';
|
|
6
|
+
import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent } from '../DropdownMenu/DropdownMenu.js';
|
|
7
|
+
import { Input } from '../Input/Input.js';
|
|
8
|
+
import { DatePicker } from './DatePicker.js';
|
|
9
|
+
import S from './DatePicker.styl.js';
|
|
10
|
+
import { parseDateString, formatDateString, formatDisplayDateRange, normalizeDateRange } from './dateUtils.js';
|
|
11
|
+
|
|
12
|
+
function commitRangeField(current, field, nextValue) {
|
|
13
|
+
const next = {
|
|
14
|
+
start: current?.start ?? '',
|
|
15
|
+
end: current?.end ?? '',
|
|
16
|
+
[field]: nextValue ?? '',
|
|
17
|
+
};
|
|
18
|
+
if (!next.start && !next.end) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
if (next.start && next.end) {
|
|
22
|
+
return normalizeDateRange(next.start, next.end);
|
|
23
|
+
}
|
|
24
|
+
return next;
|
|
25
|
+
}
|
|
26
|
+
function DateRangePickerInput({ className, value: controlledValue, defaultValue, onChange, size = 'md', startPlaceholder = 'Start date', endPlaceholder = 'End date', disabled, minDate, maxDate, disabledDate, calendarProps, open: controlledOpen, onOpenChange, id: idProp, variant = 'default', ...inputProps }) {
|
|
27
|
+
const generatedId = useId();
|
|
28
|
+
const startId = idProp ?? `${generatedId}-start`;
|
|
29
|
+
const endId = `${startId}-end`;
|
|
30
|
+
const [uncontrolledValue, setUncontrolledValue] = useState(defaultValue);
|
|
31
|
+
const [uncontrolledOpen, setUncontrolledOpen] = useState(false);
|
|
32
|
+
const [draftStart, setDraftStart] = useState();
|
|
33
|
+
const [draftEnd, setDraftEnd] = useState();
|
|
34
|
+
const [focusedField, setFocusedField] = useState(null);
|
|
35
|
+
const value = controlledValue ?? uncontrolledValue;
|
|
36
|
+
const open = controlledOpen ?? uncontrolledOpen;
|
|
37
|
+
// Calendar picks end once start is set; otherwise start (Carbon-style).
|
|
38
|
+
const calendarActiveField = value?.start && !value?.end ? 'end' : 'start';
|
|
39
|
+
const activeField = focusedField ?? (open ? calendarActiveField : null);
|
|
40
|
+
const setOpen = useCallback((nextOpen) => {
|
|
41
|
+
if (controlledOpen === undefined) {
|
|
42
|
+
setUncontrolledOpen(nextOpen);
|
|
43
|
+
}
|
|
44
|
+
onOpenChange?.(nextOpen);
|
|
45
|
+
}, [controlledOpen, onOpenChange]);
|
|
46
|
+
const commitValue = useCallback((nextValue) => {
|
|
47
|
+
if (controlledValue === undefined) {
|
|
48
|
+
setUncontrolledValue(nextValue);
|
|
49
|
+
}
|
|
50
|
+
onChange?.(nextValue);
|
|
51
|
+
}, [controlledValue, onChange]);
|
|
52
|
+
const handleStartChange = useCallback((event) => {
|
|
53
|
+
const nextValue = event.target.value;
|
|
54
|
+
setDraftStart(nextValue);
|
|
55
|
+
if (!nextValue) {
|
|
56
|
+
commitValue(commitRangeField(value, 'start', undefined));
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (parseDateString(nextValue)) {
|
|
60
|
+
commitValue(commitRangeField(value, 'start', nextValue));
|
|
61
|
+
}
|
|
62
|
+
}, [commitValue, value]);
|
|
63
|
+
const handleEndChange = useCallback((event) => {
|
|
64
|
+
const nextValue = event.target.value;
|
|
65
|
+
setDraftEnd(nextValue);
|
|
66
|
+
if (!nextValue) {
|
|
67
|
+
commitValue(commitRangeField(value, 'end', undefined));
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (parseDateString(nextValue)) {
|
|
71
|
+
commitValue(commitRangeField(value, 'end', nextValue));
|
|
72
|
+
}
|
|
73
|
+
}, [commitValue, value]);
|
|
74
|
+
const handleStartBlur = useCallback(() => {
|
|
75
|
+
if (draftStart === undefined) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const parsed = parseDateString(draftStart);
|
|
79
|
+
if (parsed) {
|
|
80
|
+
commitValue(commitRangeField(value, 'start', formatDateString(parsed)));
|
|
81
|
+
}
|
|
82
|
+
else if (!draftStart) {
|
|
83
|
+
commitValue(commitRangeField(value, 'start', undefined));
|
|
84
|
+
}
|
|
85
|
+
setDraftStart(undefined);
|
|
86
|
+
}, [commitValue, draftStart, value]);
|
|
87
|
+
const handleEndBlur = useCallback(() => {
|
|
88
|
+
if (draftEnd === undefined) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const parsed = parseDateString(draftEnd);
|
|
92
|
+
if (parsed) {
|
|
93
|
+
commitValue(commitRangeField(value, 'end', formatDateString(parsed)));
|
|
94
|
+
}
|
|
95
|
+
else if (!draftEnd) {
|
|
96
|
+
commitValue(commitRangeField(value, 'end', undefined));
|
|
97
|
+
}
|
|
98
|
+
setDraftEnd(undefined);
|
|
99
|
+
}, [commitValue, draftEnd, value]);
|
|
100
|
+
const handleRangeSelect = useCallback((nextValue) => {
|
|
101
|
+
commitValue(nextValue);
|
|
102
|
+
if (nextValue?.start && nextValue?.end) {
|
|
103
|
+
setDraftStart(undefined);
|
|
104
|
+
setDraftEnd(undefined);
|
|
105
|
+
setOpen(false);
|
|
106
|
+
}
|
|
107
|
+
}, [commitValue, setOpen]);
|
|
108
|
+
const startDisplay = draftStart !== undefined ? draftStart : (value?.start ?? '');
|
|
109
|
+
const endDisplay = draftEnd !== undefined ? draftEnd : (value?.end ?? '');
|
|
110
|
+
return (jsxs("div", { className: cn(S.rangeInputRoot, S[`inputSize-${size}`], className), "data-slot": "date-range-picker-input", children: [jsx(Input, { ...inputProps, type: "text", variant: variant, id: startId, size: size, value: startDisplay, placeholder: startPlaceholder, disabled: disabled, onChange: handleStartChange, onBlur: () => {
|
|
111
|
+
handleStartBlur();
|
|
112
|
+
setFocusedField(current => (current === 'start' ? null : current));
|
|
113
|
+
}, onFocus: () => {
|
|
114
|
+
setFocusedField('start');
|
|
115
|
+
setOpen(true);
|
|
116
|
+
}, className: cn(S.inputField, S.rangeInputField, activeField === 'start' && S.rangeInputFieldActive), autoComplete: "off", inputMode: "numeric", "aria-label": "Start date" }), jsx("span", { className: S.rangeSeparator, "aria-hidden": "true", children: "\u2013" }), jsx(Input, { ...inputProps, type: "text", variant: variant, id: endId, size: size, value: endDisplay, placeholder: endPlaceholder, disabled: disabled, onChange: handleEndChange, onBlur: () => {
|
|
117
|
+
handleEndBlur();
|
|
118
|
+
setFocusedField(current => (current === 'end' ? null : current));
|
|
119
|
+
}, onFocus: () => {
|
|
120
|
+
setFocusedField('end');
|
|
121
|
+
setOpen(true);
|
|
122
|
+
}, className: cn(S.inputField, S.rangeInputField, activeField === 'end' && S.rangeInputFieldActive), autoComplete: "off", inputMode: "numeric", "aria-label": "End date" }), jsxs(DropdownMenu, { open: open, onOpenChange: setOpen, modal: false, children: [jsx(DropdownMenuTrigger, { asChild: true, children: jsx(Button, { type: "button", variant: "ghost", size: "sm", icon: true, disabled: disabled, className: S.rangeCalendarTrigger, "aria-label": "Open calendar", onClick: () => setOpen(true), children: jsx(CalendarBlank, { size: 16 }) }) }), jsx(DropdownMenuContent, { align: "end", sideOffset: 4, className: cn(S.popupContent, size === 'sm' && S['popupContent-sm']), onCloseAutoFocus: event => event.preventDefault(), children: jsx(DatePicker, { mode: "range", rangeValue: value, onRangeChange: handleRangeSelect, size: size, calendarProps: {
|
|
123
|
+
minDate,
|
|
124
|
+
maxDate,
|
|
125
|
+
disabledDate,
|
|
126
|
+
...calendarProps,
|
|
127
|
+
} }) })] }), jsx("span", { className: S.srOnly, "aria-live": "polite", children: formatDisplayDateRange(value) })] }));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export { DateRangePickerInput };
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
const ISO_DATE_RE = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
2
|
+
function parseDateString(value) {
|
|
3
|
+
if (!value) {
|
|
4
|
+
return null;
|
|
5
|
+
}
|
|
6
|
+
const match = ISO_DATE_RE.exec(value.trim());
|
|
7
|
+
if (!match) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
const year = Number(match[1]);
|
|
11
|
+
const month = Number(match[2]);
|
|
12
|
+
const day = Number(match[3]);
|
|
13
|
+
const date = new Date(Date.UTC(year, month - 1, day));
|
|
14
|
+
if (date.getUTCFullYear() !== year ||
|
|
15
|
+
date.getUTCMonth() !== month - 1 ||
|
|
16
|
+
date.getUTCDate() !== day) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
return { year, month, day };
|
|
20
|
+
}
|
|
21
|
+
function formatDateString(parts) {
|
|
22
|
+
const month = String(parts.month).padStart(2, '0');
|
|
23
|
+
const day = String(parts.day).padStart(2, '0');
|
|
24
|
+
return `${parts.year}-${month}-${day}`;
|
|
25
|
+
}
|
|
26
|
+
function toUtcTimestamp(parts) {
|
|
27
|
+
return Date.UTC(parts.year, parts.month - 1, parts.day);
|
|
28
|
+
}
|
|
29
|
+
function isSameDate(a, b) {
|
|
30
|
+
return a.year === b.year && a.month === b.month && a.day === b.day;
|
|
31
|
+
}
|
|
32
|
+
function isBeforeDate(a, b) {
|
|
33
|
+
return toUtcTimestamp(a) < toUtcTimestamp(b);
|
|
34
|
+
}
|
|
35
|
+
function isAfterDate(a, b) {
|
|
36
|
+
return toUtcTimestamp(a) > toUtcTimestamp(b);
|
|
37
|
+
}
|
|
38
|
+
function addMonths(parts, delta) {
|
|
39
|
+
const date = new Date(Date.UTC(parts.year, parts.month - 1 + delta, 1));
|
|
40
|
+
return {
|
|
41
|
+
year: date.getUTCFullYear(),
|
|
42
|
+
month: date.getUTCMonth() + 1,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function getTodayParts() {
|
|
46
|
+
const now = new Date();
|
|
47
|
+
return {
|
|
48
|
+
year: now.getFullYear(),
|
|
49
|
+
month: now.getMonth() + 1,
|
|
50
|
+
day: now.getDate(),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function getMonthMatrix(year, month, startOfWeek) {
|
|
54
|
+
const firstOfMonth = new Date(Date.UTC(year, month - 1, 1));
|
|
55
|
+
const firstWeekday = firstOfMonth.getUTCDay();
|
|
56
|
+
const offset = (firstWeekday - startOfWeek + 7) % 7;
|
|
57
|
+
const start = new Date(Date.UTC(year, month - 1, 1 - offset));
|
|
58
|
+
const days = [];
|
|
59
|
+
for (let i = 0; i < 42; i += 1) {
|
|
60
|
+
const date = new Date(start.getTime() + i * 86_400_000);
|
|
61
|
+
days.push({
|
|
62
|
+
year: date.getUTCFullYear(),
|
|
63
|
+
month: date.getUTCMonth() + 1,
|
|
64
|
+
day: date.getUTCDate(),
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return days;
|
|
68
|
+
}
|
|
69
|
+
function formatDisplayDate(value, locale = 'en-US') {
|
|
70
|
+
const parts = parseDateString(value);
|
|
71
|
+
if (!parts) {
|
|
72
|
+
return '';
|
|
73
|
+
}
|
|
74
|
+
return new Intl.DateTimeFormat(locale, {
|
|
75
|
+
year: 'numeric',
|
|
76
|
+
month: 'short',
|
|
77
|
+
day: 'numeric',
|
|
78
|
+
}).format(new Date(parts.year, parts.month - 1, parts.day));
|
|
79
|
+
}
|
|
80
|
+
function formatMonthYear(year, month, locale = 'en-US') {
|
|
81
|
+
return new Intl.DateTimeFormat(locale, {
|
|
82
|
+
month: 'long',
|
|
83
|
+
year: 'numeric',
|
|
84
|
+
}).format(new Date(year, month - 1, 1));
|
|
85
|
+
}
|
|
86
|
+
function getWeekdayLabels(startOfWeek, locale = 'en-US') {
|
|
87
|
+
const formatter = new Intl.DateTimeFormat(locale, { weekday: 'narrow' });
|
|
88
|
+
const baseSunday = new Date(2024, 0, 7);
|
|
89
|
+
const labels = [];
|
|
90
|
+
for (let i = 0; i < 7; i += 1) {
|
|
91
|
+
const weekday = (startOfWeek + i) % 7;
|
|
92
|
+
const date = new Date(baseSunday);
|
|
93
|
+
date.setDate(baseSunday.getDate() + weekday);
|
|
94
|
+
labels.push(formatter.format(date));
|
|
95
|
+
}
|
|
96
|
+
return labels;
|
|
97
|
+
}
|
|
98
|
+
function normalizeDateRange(start, end) {
|
|
99
|
+
const startParts = parseDateString(start);
|
|
100
|
+
const endParts = parseDateString(end);
|
|
101
|
+
if (!startParts || !endParts) {
|
|
102
|
+
return { start, end };
|
|
103
|
+
}
|
|
104
|
+
if (isAfterDate(startParts, endParts)) {
|
|
105
|
+
return { start: end, end: start };
|
|
106
|
+
}
|
|
107
|
+
return { start, end };
|
|
108
|
+
}
|
|
109
|
+
function isBetweenDates(parts, start, end) {
|
|
110
|
+
const timestamp = toUtcTimestamp(parts);
|
|
111
|
+
return timestamp >= toUtcTimestamp(start) && timestamp <= toUtcTimestamp(end);
|
|
112
|
+
}
|
|
113
|
+
function formatDisplayDateRange(value, locale = 'en-US') {
|
|
114
|
+
if (!value?.start || !value?.end) {
|
|
115
|
+
return '';
|
|
116
|
+
}
|
|
117
|
+
const start = formatDisplayDate(value.start, locale);
|
|
118
|
+
const end = formatDisplayDate(value.end, locale);
|
|
119
|
+
return `${start} – ${end}`;
|
|
120
|
+
}
|
|
121
|
+
function isDateDisabled(parts, options) {
|
|
122
|
+
const { minDate, maxDate, disabledDate } = options;
|
|
123
|
+
const min = parseDateString(minDate);
|
|
124
|
+
const max = parseDateString(maxDate);
|
|
125
|
+
if (min && isBeforeDate(parts, min)) {
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
if (max && isAfterDate(parts, max)) {
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
if (disabledDate?.(formatDateString(parts))) {
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export { addMonths, formatDateString, formatDisplayDate, formatDisplayDateRange, formatMonthYear, getMonthMatrix, getTodayParts, getWeekdayLabels, isAfterDate, isBeforeDate, isBetweenDates, isDateDisabled, isSameDate, normalizeDateRange, parseDateString, toUtcTimestamp };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import cn from 'classnames';
|
|
3
|
+
import { createContext, useContext } from 'react';
|
|
4
|
+
import * as RadioGroupPrimitive from '@radix-ui/react-radio-group';
|
|
5
|
+
import { getDefaultRadioGroupContextValues, getRadioGroupContextValues } from './RadioGroup.helpers.js';
|
|
6
|
+
import S from './RadioGroup.styl.js';
|
|
7
|
+
|
|
8
|
+
const RadioGroupContext = createContext(getDefaultRadioGroupContextValues());
|
|
9
|
+
function RadioGroup({ className, size = 'md', children, ...props }) {
|
|
10
|
+
return (jsx(RadioGroupContext.Provider, { value: { size }, children: jsx(RadioGroupPrimitive.Root, { "data-slot": "radio-group", className: cn(S.groupRoot, className), ...props, children: children }) }));
|
|
11
|
+
}
|
|
12
|
+
function RadioGroupItem({ className, size, ...props }) {
|
|
13
|
+
const context = useContext(RadioGroupContext);
|
|
14
|
+
const resolvedSize = getRadioGroupContextValues(context, size);
|
|
15
|
+
return (jsx(RadioGroupPrimitive.Item, { "data-slot": "radio-group-item", className: cn(S.radioRoot, S[`size-${resolvedSize}`], className), ...props, children: jsx(RadioGroupPrimitive.Indicator, { "data-slot": "radio-group-indicator", className: S.radioIndicator }) }));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { RadioGroup, RadioGroupItem };
|