@wheelhouse/ui 0.2.0 → 0.2.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.
Files changed (108) hide show
  1. package/dist/components/accordion/accordion.js +2 -2
  2. package/dist/components/alert/alert.stories.js +4 -4
  3. package/dist/components/alert-dialog/alert-dialog.stories.js +2 -2
  4. package/dist/components/breadcrumb/breadcrumb.d.ts.map +1 -1
  5. package/dist/components/breadcrumb/breadcrumb.js +3 -4
  6. package/dist/components/calendar/calendar.d.ts +34 -0
  7. package/dist/components/calendar/calendar.d.ts.map +1 -0
  8. package/dist/components/calendar/calendar.js +82 -0
  9. package/dist/components/calendar/calendar.stories.d.ts +16 -0
  10. package/dist/components/calendar/calendar.stories.d.ts.map +1 -0
  11. package/dist/components/calendar/calendar.stories.js +33 -0
  12. package/dist/components/calendar/index.d.ts +3 -0
  13. package/dist/components/calendar/index.d.ts.map +1 -0
  14. package/dist/components/calendar/index.js +1 -0
  15. package/dist/components/checkbox/checkbox.js +2 -2
  16. package/dist/components/collapsible/collapsible.stories.js +4 -4
  17. package/dist/components/combobox/combobox.d.ts.map +1 -1
  18. package/dist/components/combobox/combobox.js +5 -7
  19. package/dist/components/command/command.d.ts.map +1 -1
  20. package/dist/components/command/command.js +3 -4
  21. package/dist/components/context-menu/context-menu.d.ts.map +1 -1
  22. package/dist/components/context-menu/context-menu.js +4 -5
  23. package/dist/components/date-selector/date-selector-context.d.ts +6 -0
  24. package/dist/components/date-selector/date-selector-context.d.ts.map +1 -0
  25. package/dist/components/date-selector/date-selector-context.js +11 -0
  26. package/dist/components/date-selector/date-selector-parts.d.ts +68 -0
  27. package/dist/components/date-selector/date-selector-parts.d.ts.map +1 -0
  28. package/dist/components/date-selector/date-selector-parts.js +131 -0
  29. package/dist/components/date-selector/date-selector-types.d.ts +118 -0
  30. package/dist/components/date-selector/date-selector-types.d.ts.map +1 -0
  31. package/dist/components/date-selector/date-selector-types.js +32 -0
  32. package/dist/components/date-selector/date-selector-value.d.ts +47 -0
  33. package/dist/components/date-selector/date-selector-value.d.ts.map +1 -0
  34. package/dist/components/date-selector/date-selector-value.js +183 -0
  35. package/dist/components/date-selector/date-selector.d.ts +6 -0
  36. package/dist/components/date-selector/date-selector.d.ts.map +1 -0
  37. package/dist/components/date-selector/date-selector.js +144 -0
  38. package/dist/components/date-selector/date-selector.stories.d.ts +135 -0
  39. package/dist/components/date-selector/date-selector.stories.d.ts.map +1 -0
  40. package/dist/components/date-selector/date-selector.stories.js +144 -0
  41. package/dist/components/date-selector/index.d.ts +7 -0
  42. package/dist/components/date-selector/index.d.ts.map +1 -0
  43. package/dist/components/date-selector/index.js +5 -0
  44. package/dist/components/date-selector/use-date-selector.d.ts +50 -0
  45. package/dist/components/date-selector/use-date-selector.d.ts.map +1 -0
  46. package/dist/components/date-selector/use-date-selector.js +305 -0
  47. package/dist/components/dialog/dialog.js +2 -2
  48. package/dist/components/dropdown-menu/dropdown-menu.d.ts.map +1 -1
  49. package/dist/components/dropdown-menu/dropdown-menu.js +5 -6
  50. package/dist/components/empty/empty.stories.js +2 -2
  51. package/dist/components/filters/filters.js +4 -4
  52. package/dist/components/filters/filters.stories.js +3 -3
  53. package/dist/components/index.d.ts +5 -0
  54. package/dist/components/index.d.ts.map +1 -1
  55. package/dist/components/index.js +5 -0
  56. package/dist/components/input-group/input-group.stories.js +3 -3
  57. package/dist/components/item/item.stories.d.ts.map +1 -1
  58. package/dist/components/item/item.stories.js +5 -6
  59. package/dist/components/kbd/kbd.stories.js +2 -2
  60. package/dist/components/menubar/menubar.js +3 -3
  61. package/dist/components/native-select/native-select.js +2 -2
  62. package/dist/components/navigation-menu/navigation-menu.js +2 -2
  63. package/dist/components/navigation-pattern-1/index.d.ts +3 -0
  64. package/dist/components/navigation-pattern-1/index.d.ts.map +1 -0
  65. package/dist/components/navigation-pattern-1/index.js +1 -0
  66. package/dist/components/navigation-pattern-1/pattern-1.config.d.ts +47 -0
  67. package/dist/components/navigation-pattern-1/pattern-1.config.d.ts.map +1 -0
  68. package/dist/components/navigation-pattern-1/pattern-1.config.js +55 -0
  69. package/dist/components/navigation-pattern-1/pattern-1.d.ts +7 -0
  70. package/dist/components/navigation-pattern-1/pattern-1.d.ts.map +1 -0
  71. package/dist/components/navigation-pattern-1/pattern-1.js +83 -0
  72. package/dist/components/navigation-pattern-1/pattern-1.stories.d.ts +16 -0
  73. package/dist/components/navigation-pattern-1/pattern-1.stories.d.ts.map +1 -0
  74. package/dist/components/navigation-pattern-1/pattern-1.stories.js +20 -0
  75. package/dist/components/pagination/pagination.js +4 -4
  76. package/dist/components/select/select.js +5 -5
  77. package/dist/components/sheet/sheet.js +2 -2
  78. package/dist/components/sonner/sonner.d.ts +1 -1
  79. package/dist/components/sonner/sonner.js +7 -7
  80. package/dist/components/sortable/index.d.ts +3 -0
  81. package/dist/components/sortable/index.d.ts.map +1 -0
  82. package/dist/components/sortable/index.js +1 -0
  83. package/dist/components/sortable/sortable.d.ts +94 -0
  84. package/dist/components/sortable/sortable.d.ts.map +1 -0
  85. package/dist/components/sortable/sortable.js +210 -0
  86. package/dist/components/sortable/sortable.stories.d.ts +14 -0
  87. package/dist/components/sortable/sortable.stories.d.ts.map +1 -0
  88. package/dist/components/sortable/sortable.stories.js +38 -0
  89. package/dist/components/spinner/spinner.d.ts +3 -3
  90. package/dist/components/spinner/spinner.d.ts.map +1 -1
  91. package/dist/components/spinner/spinner.js +2 -2
  92. package/dist/components/status-indicator/index.d.ts +3 -0
  93. package/dist/components/status-indicator/index.d.ts.map +1 -0
  94. package/dist/components/status-indicator/index.js +1 -0
  95. package/dist/components/status-indicator/status-indicator.d.ts +51 -0
  96. package/dist/components/status-indicator/status-indicator.d.ts.map +1 -0
  97. package/dist/components/status-indicator/status-indicator.js +48 -0
  98. package/dist/components/status-indicator/status-indicator.stories.d.ts +20 -0
  99. package/dist/components/status-indicator/status-indicator.stories.d.ts.map +1 -0
  100. package/dist/components/status-indicator/status-indicator.stories.js +97 -0
  101. package/dist/components/text/text.js +1 -1
  102. package/dist/hooks/use-mobile.d.ts +2 -0
  103. package/dist/hooks/use-mobile.d.ts.map +1 -0
  104. package/dist/hooks/use-mobile.js +15 -0
  105. package/dist/tsconfig.tsbuildinfo +1 -1
  106. package/llms.txt +4 -4
  107. package/package.json +7 -4
  108. package/src/styles/globals.css +4 -12
@@ -0,0 +1,144 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ /**
4
+ * Rich date / period filter: day through year granularity, filter operators (is / before / after / between), optional free-text input,
5
+ * and shared state via {@link useDateSelector}. Built on `Calendar`, tabs, and `ScrollArea`.
6
+ *
7
+ * Implementation is split across `date-selector-types`, `date-selector-value`, `use-date-selector`, `date-selector-context`,
8
+ * and `date-selector-parts` for maintainability.
9
+ */
10
+ import { useCallback, useMemo, useState } from 'react';
11
+ import { parse } from 'date-fns';
12
+ import { cn } from '../../lib/utils';
13
+ import { Button } from '../button';
14
+ import { Input } from '../input';
15
+ import { ScrollArea } from '../scroll-area';
16
+ import { Tabs, TabsList, TabsTrigger } from '../tabs';
17
+ import { X } from 'lucide-react';
18
+ import { DateSelectorContext } from './date-selector-context';
19
+ import { DateSelectorDayPicker, DateSelectorFilterToggle, DateSelectorPeriodGrid, DateSelectorPeriodTabs, DateSelectorYearList } from './date-selector-parts';
20
+ import { DATE_SELECTOR_ROLLING_DAY_OPTIONS, DEFAULT_DATE_SELECTOR_I18N } from './date-selector-types';
21
+ import { formatDateValue } from './date-selector-value';
22
+ import { useDateSelector } from './use-date-selector';
23
+ /**
24
+ * Composite filter control for dates and calendar periods. Root element sets `data-slot="date-selector"`.
25
+ */
26
+ export function DateSelector({ value, onChange, allowRange = true, periodTypes, defaultPeriodType = 'day', defaultFilterType = 'is', presetMode, showInput = true, showOperators = true, showTwoMonths = false, label, className, yearRange = 5, baseYear, minYear = 2024, maxYear = 2028, yearOptions, i18n: i18nOverride, inputHint, dayDateFormat = 'MM/dd/yyyy', dayDateFormats, weekStartsOn, showRollingPresets = false, rollingDayOptions = DATE_SELECTOR_ROLLING_DAY_OPTIONS, }) {
27
+ const mergedI18n = useMemo(() => ({ ...DEFAULT_DATE_SELECTOR_I18N, ...i18nOverride }), [i18nOverride]);
28
+ const selector = useDateSelector({
29
+ value,
30
+ onChange,
31
+ defaultPeriodType,
32
+ defaultFilterType,
33
+ presetMode,
34
+ allowRange,
35
+ yearRange,
36
+ baseYear,
37
+ minYear,
38
+ maxYear,
39
+ yearOptions,
40
+ periodTypes,
41
+ });
42
+ const { periodType, filterType, selectedDate, selectedEndDate, calendarMonth, selectedYear, selectedMonth, selectedQuarter, rangeStart, rangeEnd, hoverDate, years, currentValue, setPeriodType, setFilterType, setCalendarMonth, setHoverDate, clearSelection, handleDayClick, handlePeriodSelect, handleYearSelect, isInRange, isYearInRange, selectionMode, rollingDays, applyRollingPreset, enterCustomRange, syncInternalFromParsedValue, } = selector;
43
+ const defaultRollingDay = useMemo(() => {
44
+ if (rollingDays !== undefined && rollingDayOptions.includes(rollingDays))
45
+ return rollingDays;
46
+ return rollingDayOptions[0];
47
+ }, [rollingDays, rollingDayOptions]);
48
+ const hideOperatorsForRolling = showRollingPresets && periodType === 'day' && (selectionMode === 'rolling-next' || selectionMode === 'rolling-last');
49
+ const showDayCalendar = periodType === 'day' && selectionMode === 'custom';
50
+ const displayValue = formatDateValue(currentValue, mergedI18n, dayDateFormat);
51
+ const [draftInput, setDraftInput] = useState('');
52
+ const [isInputFocused, setIsInputFocused] = useState(false);
53
+ const summaryInputValue = inputHint ? (isInputFocused ? draftInput : displayValue) : displayValue;
54
+ const dateFormats = useMemo(() => {
55
+ if (dayDateFormats && dayDateFormats.length > 0) {
56
+ const formats = [...dayDateFormats];
57
+ if (!formats.includes(dayDateFormat)) {
58
+ formats.unshift(dayDateFormat);
59
+ }
60
+ return formats;
61
+ }
62
+ const defaultFormats = [dayDateFormat, 'dd/MM/yyyy', 'yyyy-MM-dd', 'MM-dd-yyyy', 'dd-MM-yyyy'];
63
+ return Array.from(new Set(defaultFormats));
64
+ }, [dayDateFormat, dayDateFormats]);
65
+ const parseInputValue = useCallback((text) => {
66
+ if (!text.trim())
67
+ return null;
68
+ const trimmed = text.trim();
69
+ const yearMatch = trimmed.match(/^\d{4}$/);
70
+ if (yearMatch) {
71
+ const year = parseInt(yearMatch[0]);
72
+ if (year >= 1900 && year <= 2100) {
73
+ return {
74
+ period: 'year',
75
+ operator: presetMode ?? filterType,
76
+ year,
77
+ };
78
+ }
79
+ }
80
+ const quarterMatch = trimmed.match(/^Q([1-4])(?:\s+(\d{4}))?$/i);
81
+ if (quarterMatch) {
82
+ const quarter = parseInt(quarterMatch[1]) - 1;
83
+ const year = quarterMatch[2] ? parseInt(quarterMatch[2]) : new Date().getFullYear();
84
+ if (year >= 1900 && year <= 2100) {
85
+ return {
86
+ period: 'quarter',
87
+ operator: presetMode ?? filterType,
88
+ year,
89
+ quarter,
90
+ };
91
+ }
92
+ }
93
+ for (const dateFormat of dateFormats) {
94
+ try {
95
+ const parsed = parse(trimmed, dateFormat, new Date());
96
+ if (!isNaN(parsed.getTime())) {
97
+ return {
98
+ period: 'day',
99
+ operator: presetMode ?? filterType,
100
+ startDate: parsed,
101
+ };
102
+ }
103
+ }
104
+ catch {
105
+ // Continue to next format
106
+ }
107
+ }
108
+ return null;
109
+ }, [filterType, presetMode, dateFormats]);
110
+ const handleInputChange = useCallback((e) => {
111
+ const newValue = e.target.value;
112
+ setDraftInput(newValue);
113
+ const parsed = parseInputValue(newValue);
114
+ if (parsed) {
115
+ onChange?.(parsed);
116
+ if (value === undefined) {
117
+ syncInternalFromParsedValue(parsed);
118
+ }
119
+ }
120
+ }, [onChange, parseInputValue, syncInternalFromParsedValue, value]);
121
+ const handleInputBlur = useCallback(() => {
122
+ setIsInputFocused(false);
123
+ if (!parseInputValue(draftInput)) {
124
+ setDraftInput(displayValue);
125
+ }
126
+ }, [draftInput, displayValue, parseInputValue]);
127
+ const summaryInput = showInput ? (_jsxs("div", { className: "relative", "data-slot": "date-selector-summary-input", children: [_jsx(Input, { type: "text", value: summaryInputValue, readOnly: !inputHint, placeholder: isInputFocused && inputHint ? inputHint : mergedI18n.placeholder, onFocus: () => {
128
+ setIsInputFocused(true);
129
+ setDraftInput(displayValue);
130
+ }, onBlur: handleInputBlur, onChange: handleInputChange }), summaryInputValue && (_jsx("button", { type: "button", onClick: clearSelection, className: cn('absolute end-2.5 top-1/2 size-4 -translate-y-1/2 cursor-pointer rounded-xs', 'opacity-70 transition-opacity hover:opacity-100', 'ring-offset-background focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:outline-none'), children: _jsx(X, { className: "size-4" }) }))] })) : null;
131
+ return (_jsx(DateSelectorContext.Provider, { value: { i18n: mergedI18n, variant: 'outline', size: 'default' }, children: _jsxs("div", { "data-slot": "date-selector", className: cn('w-full max-w-[20rem] space-y-4', className), children: [label && (_jsx("h3", { className: "text-sm font-medium", "data-slot": "data-selector-label", children: label })), showRollingPresets && (_jsxs("div", { className: "space-y-2", "data-slot": "date-selector-rolling", children: [_jsx(Tabs, { className: "w-full", value: selectionMode === 'rolling-next' ? 'rolling-next' : selectionMode === 'rolling-last' ? 'rolling-last' : 'custom', onValueChange: (newValue) => {
132
+ if (!newValue)
133
+ return;
134
+ if (newValue === 'rolling-next')
135
+ applyRollingPreset('rolling-next', defaultRollingDay);
136
+ else if (newValue === 'rolling-last')
137
+ applyRollingPreset('rolling-last', defaultRollingDay);
138
+ else if (newValue === 'custom')
139
+ enterCustomRange();
140
+ }, children: _jsxs(TabsList, { className: "flex h-9 w-full min-w-0 gap-1 bg-muted/80 p-[3px]", children: [_jsx(TabsTrigger, { value: "rolling-next", "aria-label": mergedI18n.rollingWindowTabs.next, className: "min-w-0 flex-1 px-2 py-1 text-center font-normal", children: mergedI18n.rollingWindowTabs.next }), _jsx(TabsTrigger, { value: "rolling-last", "aria-label": mergedI18n.rollingWindowTabs.last, className: "min-w-0 flex-1 px-2 py-1 text-center font-normal", children: mergedI18n.rollingWindowTabs.last }), _jsx(TabsTrigger, { value: "custom", "aria-label": mergedI18n.rollingWindowTabs.custom, className: "min-w-0 flex-1 px-2 py-1 text-center font-normal", children: mergedI18n.rollingWindowTabs.custom })] }) }), showInput && summaryInput, (selectionMode === 'rolling-next' || selectionMode === 'rolling-last') && (_jsx("div", { className: "grid grid-cols-3 gap-2", "data-slot": "date-selector-rolling-value", children: rollingDayOptions.map((d) => {
141
+ const chipLabel = mergedI18n.rollingDaysChip.replace('{{count}}', String(d));
142
+ return (_jsx(Button, { type: "button", size: "sm", className: "w-full min-w-0", variant: rollingDays === d ? 'default' : 'outline', onClick: () => applyRollingPreset(selectionMode === 'rolling-last' ? 'rolling-last' : 'rolling-next', d), children: chipLabel }, d));
143
+ }) }))] })), showOperators && !hideOperatorsForRolling && (_jsx(DateSelectorFilterToggle, { value: filterType, onChange: setFilterType, showBetween: allowRange, presetMode: presetMode })), showInput && !showRollingPresets && summaryInput, (!showRollingPresets || selectionMode === 'custom') && (_jsx(DateSelectorPeriodTabs, { value: periodType, onChange: setPeriodType, periodTypes: periodTypes })), periodType === 'day' && showDayCalendar && (_jsx("div", { className: "w-full pb-1", children: _jsx(DateSelectorDayPicker, { currentMonth: calendarMonth, selectedDate: selectedDate, selectedEndDate: selectedEndDate, onDayClick: handleDayClick, isRange: filterType === 'between' && allowRange, onDayHover: setHoverDate, hoverDate: hoverDate, showTwoMonths: showTwoMonths, weekStartsOn: weekStartsOn, onMonthChange: setCalendarMonth }) })), periodType !== 'day' && (_jsx("div", { className: "-mr-3 w-full", children: _jsxs(ScrollArea, { className: "h-[200px] w-full pe-3", children: [periodType === 'month' && (_jsx(DateSelectorPeriodGrid, { years: years, items: mergedI18n.monthsShort, selectedYear: selectedYear, selectedValue: selectedMonth, rangeStart: rangeStart, rangeEnd: rangeEnd, isInRange: isInRange, onSelect: handlePeriodSelect, columns: 3 })), periodType === 'quarter' && (_jsx(DateSelectorPeriodGrid, { className: "space-y-3", years: years, items: mergedI18n.quarters, selectedYear: selectedYear, selectedValue: selectedQuarter, rangeStart: rangeStart, rangeEnd: rangeEnd, isInRange: isInRange, onSelect: handlePeriodSelect, columns: 4 })), periodType === 'year' && (_jsx(DateSelectorYearList, { years: years, selectedYear: selectedYear, rangeStart: rangeStart, rangeEnd: rangeEnd, isYearInRange: isYearInRange, onSelect: handleYearSelect }))] }, periodType) }))] }) }));
144
+ }
@@ -0,0 +1,135 @@
1
+ import type { StoryObj } from '@storybook/react';
2
+ import type { DateSelectorFilterType, DateSelectorProps } from '.';
3
+ declare const PERIOD_TYPE_PRESETS: {
4
+ readonly all: undefined;
5
+ readonly day: ["day"];
6
+ readonly 'day-month': ["day", "month"];
7
+ readonly month: ["month"];
8
+ readonly quarter: ["quarter"];
9
+ readonly year: ["year"];
10
+ };
11
+ type PeriodTypesPreset = keyof typeof PERIOD_TYPE_PRESETS;
12
+ /** Story-only controls; mapped to {@link DateSelectorProps} in {@link storyArgsToProps}. */
13
+ type DateSelectorStoryArgs = Omit<Partial<DateSelectorProps>, 'value' | 'onChange' | 'periodTypes' | 'presetMode' | 'weekStartsOn'> & {
14
+ periodTypesPreset?: PeriodTypesPreset;
15
+ presetMode?: DateSelectorFilterType | 'unset';
16
+ weekStartsOn?: 'unset' | NonNullable<DateSelectorProps['weekStartsOn']>;
17
+ };
18
+ /** Storybook-only shell: maps story args to {@link DateSelector} and wires controlled state. */
19
+ declare function DateSelectorStorybook(args: DateSelectorStoryArgs): import("react/jsx-runtime").JSX.Element;
20
+ declare const meta: {
21
+ title: string;
22
+ component: typeof DateSelectorStorybook;
23
+ tags: string[];
24
+ parameters: {
25
+ layout: string;
26
+ docs: {
27
+ story: {
28
+ height: string;
29
+ };
30
+ };
31
+ };
32
+ args: {
33
+ label: string;
34
+ showInput: true;
35
+ showOperators: true;
36
+ showTwoMonths: false;
37
+ allowRange: true;
38
+ showRollingPresets: false;
39
+ defaultPeriodType: "day";
40
+ defaultFilterType: "is";
41
+ presetMode: "unset";
42
+ periodTypesPreset: "all";
43
+ minYear: number;
44
+ maxYear: number;
45
+ yearRange: number;
46
+ weekStartsOn: "unset";
47
+ inputHint: string;
48
+ dayDateFormat: string;
49
+ };
50
+ argTypes: {
51
+ label: {
52
+ control: "text";
53
+ };
54
+ showInput: {
55
+ control: "boolean";
56
+ };
57
+ showOperators: {
58
+ control: "boolean";
59
+ };
60
+ showTwoMonths: {
61
+ control: "boolean";
62
+ };
63
+ allowRange: {
64
+ control: "boolean";
65
+ };
66
+ showRollingPresets: {
67
+ control: "boolean";
68
+ };
69
+ defaultPeriodType: {
70
+ control: "select";
71
+ options: string[];
72
+ };
73
+ defaultFilterType: {
74
+ control: "select";
75
+ options: string[];
76
+ };
77
+ presetMode: {
78
+ control: "select";
79
+ options: string[];
80
+ description: string;
81
+ };
82
+ periodTypesPreset: {
83
+ control: "select";
84
+ options: PeriodTypesPreset[];
85
+ description: string;
86
+ };
87
+ minYear: {
88
+ control: "number";
89
+ };
90
+ maxYear: {
91
+ control: "number";
92
+ };
93
+ yearRange: {
94
+ control: "number";
95
+ };
96
+ baseYear: {
97
+ control: "number";
98
+ };
99
+ weekStartsOn: {
100
+ control: "select";
101
+ options: (string | number)[];
102
+ description: string;
103
+ };
104
+ inputHint: {
105
+ control: "text";
106
+ };
107
+ dayDateFormat: {
108
+ control: "text";
109
+ };
110
+ className: {
111
+ control: false;
112
+ };
113
+ i18n: {
114
+ control: false;
115
+ };
116
+ yearOptions: {
117
+ control: false;
118
+ };
119
+ dayDateFormats: {
120
+ control: false;
121
+ };
122
+ rollingDayOptions: {
123
+ control: false;
124
+ };
125
+ };
126
+ };
127
+ export default meta;
128
+ type Story = StoryObj<typeof meta>;
129
+ export declare const Default: Story;
130
+ export declare const DayOnly: Story;
131
+ export declare const PresetBetween: Story;
132
+ export declare const NoInput: Story;
133
+ export declare const NoOperators: Story;
134
+ export declare const RollingPresets: Story;
135
+ //# sourceMappingURL=date-selector.stories.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"date-selector.stories.d.ts","sourceRoot":"","sources":["../../../src/components/date-selector/date-selector.stories.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAQ,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAGvD,OAAO,KAAK,EAAE,sBAAsB,EAA0B,iBAAiB,EAAqB,MAAM,GAAG,CAAC;AAG9G,QAAA,MAAM,mBAAmB;;;;;;;CAOgD,CAAC;AAE1E,KAAK,iBAAiB,GAAG,MAAM,OAAO,mBAAmB,CAAC;AAE1D,4FAA4F;AAC5F,KAAK,qBAAqB,GAAG,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,EAAE,OAAO,GAAG,UAAU,GAAG,aAAa,GAAG,YAAY,GAAG,cAAc,CAAC,GAAG;IAClI,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC,UAAU,CAAC,EAAE,sBAAsB,GAAG,OAAO,CAAC;IAC9C,YAAY,CAAC,EAAE,OAAO,GAAG,WAAW,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAAC,CAAC;CAC3E,CAAC;AAYF,gGAAgG;AAChG,iBAAS,qBAAqB,CAAC,IAAI,EAAE,qBAAqB,2CAIzD;AAED,QAAA,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAoD+C,iBAAiB,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoB9B,CAAC;AAE/C,eAAe,IAAI,CAAC;AACpB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC;AAEnC,eAAO,MAAM,OAAO,EAAE,KAAU,CAAC;AAEjC,eAAO,MAAM,OAAO,EAAE,KAerB,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,KAM3B,CAAC;AAEF,eAAO,MAAM,OAAO,EAAE,KAKrB,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,KAMzB,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,KAM5B,CAAC"}
@@ -0,0 +1,144 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useState } from 'react';
3
+ import { DateSelector } from '.';
4
+ const PERIOD_TYPE_PRESETS = {
5
+ all: undefined,
6
+ day: ['day'],
7
+ 'day-month': ['day', 'month'],
8
+ month: ['month'],
9
+ quarter: ['quarter'],
10
+ year: ['year'],
11
+ };
12
+ function storyArgsToProps(args) {
13
+ const { periodTypesPreset = 'all', presetMode, weekStartsOn, ...rest } = args;
14
+ return {
15
+ ...rest,
16
+ periodTypes: PERIOD_TYPE_PRESETS[periodTypesPreset],
17
+ presetMode: presetMode === 'unset' ? undefined : presetMode,
18
+ weekStartsOn: weekStartsOn === 'unset' ? undefined : weekStartsOn,
19
+ };
20
+ }
21
+ /** Storybook-only shell: maps story args to {@link DateSelector} and wires controlled state. */
22
+ function DateSelectorStorybook(args) {
23
+ const [value, setValue] = useState();
24
+ const props = storyArgsToProps(args);
25
+ return _jsx(DateSelector, { ...props, value: value, onChange: setValue });
26
+ }
27
+ const meta = {
28
+ title: 'UI/DateSelector',
29
+ component: DateSelectorStorybook,
30
+ tags: ['autodocs'],
31
+ parameters: {
32
+ layout: 'padded',
33
+ docs: {
34
+ story: {
35
+ height: '720px',
36
+ },
37
+ },
38
+ },
39
+ args: {
40
+ label: '',
41
+ showInput: true,
42
+ showOperators: true,
43
+ showTwoMonths: false,
44
+ allowRange: true,
45
+ showRollingPresets: false,
46
+ defaultPeriodType: 'day',
47
+ defaultFilterType: 'is',
48
+ presetMode: 'unset',
49
+ periodTypesPreset: 'all',
50
+ minYear: 2024,
51
+ maxYear: 2028,
52
+ yearRange: 10,
53
+ weekStartsOn: 'unset',
54
+ inputHint: '',
55
+ dayDateFormat: 'MM/dd/yyyy',
56
+ },
57
+ argTypes: {
58
+ label: { control: 'text' },
59
+ showInput: { control: 'boolean' },
60
+ showOperators: { control: 'boolean' },
61
+ showTwoMonths: { control: 'boolean' },
62
+ allowRange: { control: 'boolean' },
63
+ showRollingPresets: { control: 'boolean' },
64
+ defaultPeriodType: {
65
+ control: 'select',
66
+ options: ['day', 'month', 'quarter', 'year'],
67
+ },
68
+ defaultFilterType: {
69
+ control: 'select',
70
+ options: ['is', 'before', 'after', 'between'],
71
+ },
72
+ presetMode: {
73
+ control: 'select',
74
+ options: ['unset', 'is', 'before', 'after', 'between'],
75
+ description: 'Use “unset” to clear (same as leaving `presetMode` undefined).',
76
+ },
77
+ periodTypesPreset: {
78
+ control: 'select',
79
+ options: Object.keys(PERIOD_TYPE_PRESETS),
80
+ description: 'Maps to the `periodTypes` prop (which tabs are enabled).',
81
+ },
82
+ minYear: { control: 'number' },
83
+ maxYear: { control: 'number' },
84
+ yearRange: { control: 'number' },
85
+ baseYear: { control: 'number' },
86
+ weekStartsOn: {
87
+ control: 'select',
88
+ options: ['unset', 0, 1, 2, 3, 4, 5, 6],
89
+ description: 'Use “unset” for the default (Sunday in most locales).',
90
+ },
91
+ inputHint: { control: 'text' },
92
+ dayDateFormat: { control: 'text' },
93
+ className: { control: false },
94
+ i18n: { control: false },
95
+ yearOptions: { control: false },
96
+ dayDateFormats: { control: false },
97
+ rollingDayOptions: { control: false },
98
+ },
99
+ };
100
+ export default meta;
101
+ export const Default = {};
102
+ export const DayOnly = {
103
+ args: {
104
+ label: 'Date',
105
+ periodTypesPreset: 'day',
106
+ defaultPeriodType: 'day',
107
+ },
108
+ render: function DayOnlyStory(args) {
109
+ const [value, setValue] = useState({
110
+ period: 'day',
111
+ operator: 'is',
112
+ startDate: new Date(2026, 3, 13),
113
+ });
114
+ const props = storyArgsToProps(args);
115
+ return _jsx(DateSelector, { ...props, value: value, onChange: setValue });
116
+ },
117
+ };
118
+ export const PresetBetween = {
119
+ args: {
120
+ label: 'In range',
121
+ presetMode: 'between',
122
+ defaultFilterType: 'between',
123
+ },
124
+ };
125
+ export const NoInput = {
126
+ args: {
127
+ label: 'Pick in calendar',
128
+ showInput: false,
129
+ },
130
+ };
131
+ export const NoOperators = {
132
+ args: {
133
+ label: 'Period only (operator fixed to is)',
134
+ showOperators: false,
135
+ defaultFilterType: 'is',
136
+ },
137
+ };
138
+ export const RollingPresets = {
139
+ args: {
140
+ label: 'Rolling window',
141
+ showRollingPresets: true,
142
+ defaultFilterType: 'between',
143
+ },
144
+ };
@@ -0,0 +1,7 @@
1
+ export { computeRollingDateRange, formatDateValue } from './date-selector-value';
2
+ export { DATE_SELECTOR_ROLLING_DAY_OPTIONS, DEFAULT_DATE_SELECTOR_I18N } from './date-selector-types';
3
+ export { DateSelector } from './date-selector';
4
+ export { useDateSelector } from './use-date-selector';
5
+ export { useDateSelectorContext } from './date-selector-context';
6
+ export type { DateSelectorContextValue, DateSelectorFilterType, DateSelectorI18nConfig, DateSelectorPeriodType, DateSelectorProps, DateSelectorRollingDays, DateSelectorSelectionMode, DateSelectorValue, UseDateSelectorOptions, } from './date-selector-types';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/date-selector/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACjF,OAAO,EAAE,iCAAiC,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AACtG,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,YAAY,EACR,wBAAwB,EACxB,sBAAsB,EACtB,sBAAsB,EACtB,sBAAsB,EACtB,iBAAiB,EACjB,uBAAuB,EACvB,yBAAyB,EACzB,iBAAiB,EACjB,sBAAsB,GACzB,MAAM,uBAAuB,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { computeRollingDateRange, formatDateValue } from './date-selector-value';
2
+ export { DATE_SELECTOR_ROLLING_DAY_OPTIONS, DEFAULT_DATE_SELECTOR_I18N } from './date-selector-types';
3
+ export { DateSelector } from './date-selector';
4
+ export { useDateSelector } from './use-date-selector';
5
+ export { useDateSelectorContext } from './date-selector-context';
@@ -0,0 +1,50 @@
1
+ import { type SetStateAction } from 'react';
2
+ import type { DateSelectorFilterType, DateSelectorPeriodType, DateSelectorRollingDays, DateSelectorValue, UseDateSelectorOptions } from './date-selector-types';
3
+ /**
4
+ * Headless state and handlers for the date selector: period, filter operator, selected dates/ranges, and year lists.
5
+ * Use when building a custom layout; otherwise prefer {@link DateSelector}.
6
+ *
7
+ * **`syncInternalFromParsedValue`:** When the UI parses free text into a {@link DateSelectorValue} and `value` is
8
+ * undefined (uncontrolled), call this so internal state matches the parsed value. Controlled flows should rely on
9
+ * `value` + `onChange` only.
10
+ */
11
+ export declare function useDateSelector({ value, onChange, defaultPeriodType, defaultFilterType, presetMode, allowRange, yearRange, baseYear, minYear, maxYear, yearOptions, periodTypes, }: UseDateSelectorOptions): {
12
+ periodType: DateSelectorPeriodType;
13
+ filterType: DateSelectorFilterType;
14
+ selectedDate: Date | undefined;
15
+ selectedEndDate: Date | undefined;
16
+ calendarMonth: Date;
17
+ selectedYear: number | undefined;
18
+ selectedMonth: number | undefined;
19
+ selectedQuarter: number | undefined;
20
+ rangeStart: {
21
+ year: number;
22
+ value: number;
23
+ } | undefined;
24
+ rangeEnd: {
25
+ year: number;
26
+ value: number;
27
+ } | undefined;
28
+ hoverDate: Date | undefined;
29
+ years: number[];
30
+ currentValue: DateSelectorValue;
31
+ allowRange: boolean;
32
+ selectionMode: import("./date-selector-types").DateSelectorSelectionMode;
33
+ rollingDays: 3 | 7 | 14 | 30 | 60 | 90 | 180 | 365 | undefined;
34
+ setPeriodType: (type: DateSelectorPeriodType) => void;
35
+ setFilterType: (type: DateSelectorFilterType) => void;
36
+ setSelectedDate: (action: SetStateAction<Date | undefined>) => void;
37
+ setSelectedEndDate: (action: SetStateAction<Date | undefined>) => void;
38
+ setCalendarMonth: (action: SetStateAction<Date>) => void;
39
+ setHoverDate: (action: SetStateAction<Date | undefined>) => void;
40
+ clearSelection: () => void;
41
+ handleDayClick: (day: Date) => void;
42
+ handlePeriodSelect: (year: number, periodValue: number) => void;
43
+ handleYearSelect: (year: number) => void;
44
+ isInRange: (year: number, periodValue: number) => boolean;
45
+ isYearInRange: (year: number) => boolean;
46
+ applyRollingPreset: (mode: "rolling-next" | "rolling-last", days: DateSelectorRollingDays) => void;
47
+ enterCustomRange: () => void;
48
+ syncInternalFromParsedValue: (parsed: DateSelectorValue) => void;
49
+ };
50
+ //# sourceMappingURL=use-date-selector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-date-selector.d.ts","sourceRoot":"","sources":["../../../src/components/date-selector/use-date-selector.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,cAAc,EAAkC,MAAM,OAAO,CAAC;AAG5E,OAAO,KAAK,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAUhK;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,EAC5B,KAAK,EACL,QAAQ,EACR,iBAAyB,EACzB,iBAAwB,EACxB,UAAU,EACV,UAAiB,EACjB,SAAc,EACd,QAAQ,EACR,OAAO,EACP,OAAO,EACP,WAAW,EACX,WAAW,GACd,EAAE,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;0BA4PV,sBAAsB;0BAmBtB,sBAAsB;8BAjMpB,cAAc,CAAC,IAAI,GAAG,SAAS,CAAC;iCAUhC,cAAc,CAAC,IAAI,GAAG,SAAS,CAAC;+BA/BC,cAAc,CAAC,IAAI,CAAC;2BAUxB,cAAc,CAAC,IAAI,GAAG,SAAS,CAAC;;0BA4EhE,IAAI;+BA+BH,MAAM,eAAe,MAAM;6BA0C3B,MAAM;sBA2EN,MAAM,eAAe,MAAM;0BAW3B,MAAM;+BAjLN,cAAc,GAAG,cAAc,QAAQ,uBAAuB;;0CA9E5D,iBAAiB;EA2SjC"}