@wheelhouse/ui 0.2.1 → 0.2.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/blocks/columns/columns-types.d.ts +40 -0
- package/dist/blocks/columns/columns-types.d.ts.map +1 -0
- package/dist/blocks/columns/columns-types.js +10 -0
- package/dist/blocks/columns/columns-utils.d.ts +13 -0
- package/dist/blocks/columns/columns-utils.d.ts.map +1 -0
- package/dist/blocks/columns/columns-utils.js +85 -0
- package/dist/blocks/columns/columns.d.ts +3 -0
- package/dist/blocks/columns/columns.d.ts.map +1 -0
- package/dist/blocks/columns/columns.js +79 -0
- package/dist/blocks/columns/columns.stories.d.ts +12 -0
- package/dist/blocks/columns/columns.stories.d.ts.map +1 -0
- package/dist/blocks/columns/columns.stories.js +67 -0
- package/dist/blocks/columns/index.d.ts +6 -0
- package/dist/blocks/columns/index.d.ts.map +1 -0
- package/dist/blocks/columns/index.js +3 -0
- package/dist/blocks/date-selector/date-selector-context.d.ts.map +1 -0
- package/dist/blocks/date-selector/date-selector-default-i18n.d.ts +10 -0
- package/dist/blocks/date-selector/date-selector-default-i18n.d.ts.map +1 -0
- package/dist/blocks/date-selector/date-selector-default-i18n.js +29 -0
- package/dist/blocks/date-selector/date-selector-i18n-resources.d.ts +11 -0
- package/dist/blocks/date-selector/date-selector-i18n-resources.d.ts.map +1 -0
- package/dist/blocks/date-selector/date-selector-i18n-resources.js +248 -0
- package/dist/blocks/date-selector/date-selector-i18n.shared.d.ts +12 -0
- package/dist/blocks/date-selector/date-selector-i18n.shared.d.ts.map +1 -0
- package/dist/blocks/date-selector/date-selector-i18n.shared.js +84 -0
- package/dist/{components → blocks}/date-selector/date-selector-parts.d.ts +9 -0
- package/dist/blocks/date-selector/date-selector-parts.d.ts.map +1 -0
- package/dist/{components → blocks}/date-selector/date-selector-parts.js +21 -6
- package/dist/{components → blocks}/date-selector/date-selector-types.d.ts +70 -0
- package/dist/blocks/date-selector/date-selector-types.d.ts.map +1 -0
- package/dist/{components → blocks}/date-selector/date-selector-types.js +22 -0
- package/dist/blocks/date-selector/date-selector-value.d.ts +81 -0
- package/dist/blocks/date-selector/date-selector-value.d.ts.map +1 -0
- package/dist/blocks/date-selector/date-selector-value.js +423 -0
- package/dist/{components → blocks}/date-selector/date-selector.d.ts +1 -1
- package/dist/blocks/date-selector/date-selector.d.ts.map +1 -0
- package/dist/blocks/date-selector/date-selector.js +191 -0
- package/dist/{components → blocks}/date-selector/date-selector.stories.d.ts +14 -0
- package/dist/blocks/date-selector/date-selector.stories.d.ts.map +1 -0
- package/dist/blocks/date-selector/date-selector.stories.js +299 -0
- package/dist/blocks/date-selector/index.d.ts +11 -0
- package/dist/blocks/date-selector/index.d.ts.map +1 -0
- package/dist/blocks/date-selector/index.js +8 -0
- package/dist/{components → blocks}/date-selector/use-date-selector.d.ts +4 -3
- package/dist/blocks/date-selector/use-date-selector.d.ts.map +1 -0
- package/dist/{components → blocks}/date-selector/use-date-selector.js +14 -8
- package/dist/blocks/index.d.ts +2 -0
- package/dist/blocks/index.d.ts.map +1 -1
- package/dist/blocks/index.js +2 -0
- package/dist/blocks/navigation/index.d.ts +4 -1
- package/dist/blocks/navigation/index.d.ts.map +1 -1
- package/dist/blocks/navigation/index.js +2 -1
- package/dist/blocks/navigation/navigation-types.d.ts +60 -0
- package/dist/blocks/navigation/navigation-types.d.ts.map +1 -0
- package/dist/blocks/navigation/navigation-types.js +1 -0
- package/dist/blocks/navigation/navigation.d.ts +9 -0
- package/dist/blocks/navigation/navigation.d.ts.map +1 -0
- package/dist/blocks/navigation/navigation.demo.d.ts +4 -0
- package/dist/blocks/navigation/navigation.demo.d.ts.map +1 -0
- package/dist/blocks/navigation/navigation.demo.js +46 -0
- package/dist/blocks/navigation/navigation.js +98 -0
- package/dist/blocks/navigation/navigation.stories.d.ts +14 -0
- package/dist/blocks/navigation/navigation.stories.d.ts.map +1 -0
- package/dist/blocks/navigation/navigation.stories.js +16 -0
- package/dist/components/accordion/accordion.stories.js +1 -1
- package/dist/components/alert/alert.stories.js +1 -1
- package/dist/components/alert-dialog/alert-dialog.stories.js +1 -1
- package/dist/components/aspect-ratio/aspect-ratio.stories.js +1 -1
- package/dist/components/avatar/avatar.stories.js +1 -1
- package/dist/components/badge/badge.d.ts +1 -1
- package/dist/components/badge/badge.stories.js +1 -1
- package/dist/components/breadcrumb/breadcrumb.stories.js +1 -1
- package/dist/components/button/button.d.ts +2 -2
- package/dist/components/button/button.stories.js +1 -1
- package/dist/components/button-group/button-group.d.ts +10 -4
- package/dist/components/button-group/button-group.d.ts.map +1 -1
- package/dist/components/button-group/button-group.js +15 -3
- package/dist/components/button-group/button-group.stories.js +1 -1
- package/dist/components/button-group/index.d.ts +2 -2
- package/dist/components/button-group/index.d.ts.map +1 -1
- package/dist/components/button-group/index.js +1 -1
- package/dist/components/calendar/calendar.stories.js +1 -1
- package/dist/components/card/card.stories.js +1 -1
- package/dist/components/checkbox/checkbox.stories.js +1 -1
- package/dist/components/collapsible/collapsible.stories.js +1 -1
- package/dist/components/combobox/combobox.stories.js +1 -1
- package/dist/components/command/command.stories.js +1 -1
- package/dist/components/context-menu/context-menu.stories.js +1 -1
- package/dist/components/dialog/dialog.stories.js +1 -1
- package/dist/components/direction/direction.stories.js +1 -1
- package/dist/components/drawer/drawer.stories.js +1 -1
- package/dist/components/dropdown-menu/dropdown-menu.d.ts +9 -2
- package/dist/components/dropdown-menu/dropdown-menu.d.ts.map +1 -1
- package/dist/components/dropdown-menu/dropdown-menu.js +4 -1
- package/dist/components/dropdown-menu/dropdown-menu.stories.js +1 -1
- package/dist/components/dropdown-menu/index.d.ts +2 -2
- package/dist/components/dropdown-menu/index.d.ts.map +1 -1
- package/dist/components/dropdown-menu/index.js +1 -1
- package/dist/components/empty/empty.stories.js +1 -1
- package/dist/components/field/field.stories.js +1 -1
- package/dist/components/filters/filter-date-metric-value.d.ts +32 -0
- package/dist/components/filters/filter-date-metric-value.d.ts.map +1 -0
- package/dist/components/filters/filter-date-metric-value.js +331 -0
- package/dist/components/filters/filters-defaults.d.ts +4 -0
- package/dist/components/filters/filters-defaults.d.ts.map +1 -1
- package/dist/components/filters/filters-defaults.js +59 -1
- package/dist/components/filters/filters-i18n-resources.d.ts +277 -0
- package/dist/components/filters/filters-i18n-resources.d.ts.map +1 -0
- package/dist/components/filters/filters-i18n-resources.js +276 -0
- package/dist/components/filters/filters-i18n.shared.d.ts +16 -0
- package/dist/components/filters/filters-i18n.shared.d.ts.map +1 -0
- package/dist/components/filters/filters-i18n.shared.js +111 -0
- package/dist/components/filters/filters-types.d.ts +33 -1
- package/dist/components/filters/filters-types.d.ts.map +1 -1
- package/dist/components/filters/filters-utils.d.ts +28 -1
- package/dist/components/filters/filters-utils.d.ts.map +1 -1
- package/dist/components/filters/filters-utils.js +102 -0
- package/dist/components/filters/filters.d.ts +21 -3
- package/dist/components/filters/filters.d.ts.map +1 -1
- package/dist/components/filters/filters.js +493 -290
- package/dist/components/filters/filters.stories.d.ts +107 -2
- package/dist/components/filters/filters.stories.d.ts.map +1 -1
- package/dist/components/filters/filters.stories.js +364 -29
- package/dist/components/filters/index.d.ts +3 -1
- package/dist/components/filters/index.d.ts.map +1 -1
- package/dist/components/filters/index.js +3 -1
- package/dist/components/frame/frame.d.ts +1 -1
- package/dist/components/frame/frame.stories.js +1 -1
- package/dist/components/hover-card/hover-card.stories.js +1 -1
- package/dist/components/index.d.ts +0 -1
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +0 -1
- package/dist/components/input/input.stories.js +1 -1
- package/dist/components/input-group/input-group.d.ts +2 -2
- package/dist/components/input-group/input-group.stories.js +1 -1
- package/dist/components/item/item.d.ts +2 -2
- package/dist/components/item/item.stories.js +1 -1
- package/dist/components/kbd/kbd.stories.js +1 -1
- package/dist/components/label/label.stories.js +1 -1
- package/dist/components/menubar/menubar.stories.js +1 -1
- package/dist/components/native-select/native-select.stories.js +1 -1
- package/dist/components/navigation-menu/navigation-menu.stories.js +1 -1
- package/dist/components/pagination/pagination.stories.js +1 -1
- package/dist/components/popover/popover.stories.js +1 -1
- package/dist/components/progress/progress.stories.js +1 -1
- package/dist/components/radio-group/radio-group.stories.js +1 -1
- package/dist/components/resizable/resizable.stories.js +1 -1
- package/dist/components/scroll-area/scroll-area.stories.js +1 -1
- package/dist/components/select/select.stories.js +1 -1
- package/dist/components/separator/separator.stories.js +1 -1
- package/dist/components/sheet/sheet.stories.js +1 -1
- package/dist/components/slider/slider.stories.js +1 -1
- package/dist/components/sonner/sonner.stories.js +1 -1
- package/dist/components/sortable/sortable.stories.js +1 -1
- package/dist/components/spinner/spinner.stories.js +1 -1
- package/dist/components/status-indicator/status-indicator.stories.js +1 -1
- package/dist/components/switch/switch.stories.js +1 -1
- package/dist/components/tabs/tabs.d.ts +1 -1
- package/dist/components/tabs/tabs.stories.js +1 -1
- package/dist/components/text/text.d.ts +1 -1
- package/dist/components/text/text.stories.js +1 -1
- package/dist/components/textarea/textarea.stories.js +1 -1
- package/dist/components/toggle/toggle.stories.js +1 -1
- package/dist/components/toggle-group/toggle-group.stories.js +1 -1
- package/dist/components/tooltip/tooltip.stories.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/llms.txt +8 -10
- package/package.json +6 -2
- package/dist/blocks/navigation/pattern-1/index.d.ts +0 -3
- package/dist/blocks/navigation/pattern-1/index.d.ts.map +0 -1
- package/dist/blocks/navigation/pattern-1/index.js +0 -1
- package/dist/blocks/navigation/pattern-1/pattern-1.config.d.ts +0 -47
- package/dist/blocks/navigation/pattern-1/pattern-1.config.d.ts.map +0 -1
- package/dist/blocks/navigation/pattern-1/pattern-1.config.js +0 -55
- package/dist/blocks/navigation/pattern-1/pattern-1.d.ts +0 -7
- package/dist/blocks/navigation/pattern-1/pattern-1.d.ts.map +0 -1
- package/dist/blocks/navigation/pattern-1/pattern-1.js +0 -50
- package/dist/blocks/navigation/pattern-1/pattern-1.stories.d.ts +0 -16
- package/dist/blocks/navigation/pattern-1/pattern-1.stories.d.ts.map +0 -1
- package/dist/blocks/navigation/pattern-1/pattern-1.stories.js +0 -20
- package/dist/components/date-selector/date-selector-context.d.ts.map +0 -1
- package/dist/components/date-selector/date-selector-parts.d.ts.map +0 -1
- package/dist/components/date-selector/date-selector-types.d.ts.map +0 -1
- package/dist/components/date-selector/date-selector-value.d.ts +0 -47
- package/dist/components/date-selector/date-selector-value.d.ts.map +0 -1
- package/dist/components/date-selector/date-selector-value.js +0 -183
- package/dist/components/date-selector/date-selector.d.ts.map +0 -1
- package/dist/components/date-selector/date-selector.js +0 -144
- package/dist/components/date-selector/date-selector.stories.d.ts.map +0 -1
- package/dist/components/date-selector/date-selector.stories.js +0 -144
- package/dist/components/date-selector/index.d.ts +0 -7
- package/dist/components/date-selector/index.d.ts.map +0 -1
- package/dist/components/date-selector/index.js +0 -5
- package/dist/components/date-selector/use-date-selector.d.ts.map +0 -1
- /package/dist/{components → blocks}/date-selector/date-selector-context.d.ts +0 -0
- /package/dist/{components → blocks}/date-selector/date-selector-context.js +0 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { type DateSelectorFilterType, type DateSelectorI18nConfig, type DateSelectorPeriodType, type DateSelectorRollingUnit, type DateSelectorSelectionMode, type DateSelectorValue, type FormatDateValueOptions } from './date-selector-types';
|
|
2
|
+
/** Compact US-style day display (`4/18/26`): rolling day spans, tooltips, and dense UIs such as the date-metric filter bar. */
|
|
3
|
+
export declare const DATE_SELECTOR_COMPACT_DAY_FORMAT = "M/d/yy";
|
|
4
|
+
export declare function resolveRollingCount(value: DateSelectorValue): number | undefined;
|
|
5
|
+
export declare function resolveRollingUnit(value: DateSelectorValue): DateSelectorRollingUnit;
|
|
6
|
+
/**
|
|
7
|
+
* Short rolling label only (no calendar parenthetical, no day span) for compact bars when detail is shown in a tooltip.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getRollingBarShortLabel(value: DateSelectorValue, i18n?: DateSelectorI18nConfig): string | null;
|
|
10
|
+
/**
|
|
11
|
+
* Human-readable rolling preset title for compact summaries. **Rolling year** presets with bounds use
|
|
12
|
+
* `Next Year (2027)` / `Last Year (2025)`; **rolling month** inner text uses calendar-relative months, e.g.
|
|
13
|
+
* `Next Month (May 2026)`, `Last Month (March 2026)`; multi-month uses a span, e.g. `Next 6 Months (May 2026 - Oct 2026)`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getRollingSummaryLabel(value: DateSelectorValue, i18n?: DateSelectorI18nConfig): string | null;
|
|
16
|
+
/**
|
|
17
|
+
* Inclusive calendar bounds for rolling presets. **Days:** “next N” / “last N” are the N calendar days **after** today /
|
|
18
|
+
* **before** today (today excluded). **Months** use month boundaries (last span can include today through end of day).
|
|
19
|
+
* **Years:** “last” / “next” use **full calendar years**
|
|
20
|
+
* adjacent to the current year (`last` → prior year(s), `next` → following year(s)), not partial ranges from today.
|
|
21
|
+
* **Quarters:** same pattern using calendar quarters adjacent to the current quarter.
|
|
22
|
+
*/
|
|
23
|
+
export declare function computeRollingPresetRange(mode: 'rolling-next' | 'rolling-last', unit: DateSelectorRollingUnit, count: number, now?: Date): {
|
|
24
|
+
startDate: Date;
|
|
25
|
+
endDate: Date;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Computes inclusive calendar date bounds for rolling day windows. “Next N” is the N days **after** today (exclusive of
|
|
29
|
+
* today). “Last N” is the N days **before** today (exclusive of today).
|
|
30
|
+
*/
|
|
31
|
+
export declare function computeRollingDateRange(mode: 'rolling-next' | 'rolling-last', days: number, now?: Date): {
|
|
32
|
+
startDate: Date;
|
|
33
|
+
endDate: Date;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Calendar detail for any rolling preset — for tooltips when the bar uses {@link getRollingBarShortLabel} only.
|
|
37
|
+
* Uses `value` bounds when present, otherwise {@link computeRollingPresetRange}.
|
|
38
|
+
* Rolling **day** spans always use compact `M/d/yy` (e.g. `4/18/26`); the `dayDateFormat` argument is reserved for API compatibility and ignored for that unit.
|
|
39
|
+
*/
|
|
40
|
+
export declare function formatRollingRangeTooltipDetail(value: DateSelectorValue, i18n?: DateSelectorI18nConfig,
|
|
41
|
+
/** @deprecated Ignored for rolling days; day tooltips use compact `M/d/yy`. Kept for call-site compatibility. */
|
|
42
|
+
_dayDateFormat?: string): string | null;
|
|
43
|
+
/**
|
|
44
|
+
* Formats a {@link DateSelectorValue} for display using the same rules as the selector’s summary text.
|
|
45
|
+
*/
|
|
46
|
+
export declare function formatDateValue(value: DateSelectorValue, i18n?: DateSelectorI18nConfig, dayDateFormat?: string, options?: FormatDateValueOptions): string;
|
|
47
|
+
/** Stable fingerprint for a {@link DateSelectorValue} (for sync keys and onChange deduplication). */
|
|
48
|
+
export declare function dateSelectorDataKey(value: DateSelectorValue | undefined): string;
|
|
49
|
+
export declare function computeStateSyncKey(value: DateSelectorValue | undefined, presetMode: DateSelectorFilterType | undefined, defaultFilterType: DateSelectorFilterType, validDefaultPeriodType: DateSelectorPeriodType): string;
|
|
50
|
+
/** Full local UI state for {@link useDateSelector} (calendar month / hover are not part of {@link DateSelectorValue}). */
|
|
51
|
+
export interface DateSelectorInternalState {
|
|
52
|
+
periodType: DateSelectorPeriodType;
|
|
53
|
+
filterType: DateSelectorFilterType;
|
|
54
|
+
selectedDate: Date | undefined;
|
|
55
|
+
selectedEndDate: Date | undefined;
|
|
56
|
+
calendarMonth: Date;
|
|
57
|
+
selectedYear: number | undefined;
|
|
58
|
+
selectedMonth: number | undefined;
|
|
59
|
+
selectedQuarter: number | undefined;
|
|
60
|
+
rangeStart: {
|
|
61
|
+
year: number;
|
|
62
|
+
value: number;
|
|
63
|
+
} | undefined;
|
|
64
|
+
rangeEnd: {
|
|
65
|
+
year: number;
|
|
66
|
+
value: number;
|
|
67
|
+
} | undefined;
|
|
68
|
+
hoverDate: Date | undefined;
|
|
69
|
+
selectionMode: DateSelectorSelectionMode;
|
|
70
|
+
rollingUnit: DateSelectorRollingUnit;
|
|
71
|
+
rollingCount: number | undefined;
|
|
72
|
+
}
|
|
73
|
+
export declare function createInitialInternalState(value: DateSelectorValue | undefined, validDefaultPeriodType: DateSelectorPeriodType, defaultFilterType: DateSelectorFilterType, presetMode: DateSelectorFilterType | undefined): DateSelectorInternalState;
|
|
74
|
+
export declare function buildRollingValueFromState(selectionMode: DateSelectorSelectionMode, rollingUnit: DateSelectorRollingUnit, rollingCount: number | undefined): DateSelectorValue | undefined;
|
|
75
|
+
export declare function buildCurrentValueFromInternal(s: DateSelectorInternalState, presetMode: DateSelectorFilterType | undefined): DateSelectorValue;
|
|
76
|
+
/** Combined UI state + last emitted value fingerprint for `onChange` deduplication. */
|
|
77
|
+
export interface DateSelectorHookState {
|
|
78
|
+
internal: DateSelectorInternalState;
|
|
79
|
+
lastEmittedDataKey: string;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=date-selector-value.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date-selector-value.d.ts","sourceRoot":"","sources":["../../../src/blocks/date-selector/date-selector-value.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
import { addDays, addMonths, addQuarters, addYears, endOfDay, endOfMonth, endOfQuarter, endOfYear, format, getQuarter, startOfDay, startOfMonth, startOfQuarter, startOfYear, subDays, subMonths, subQuarters, subYears, } from 'date-fns';
|
|
2
|
+
import { DATE_SELECTOR_ROLLING_DAY_OPTIONS, DEFAULT_DATE_SELECTOR_I18N, } from './date-selector-types';
|
|
3
|
+
/** Compact US-style day display (`4/18/26`): rolling day spans, tooltips, and dense UIs such as the date-metric filter bar. */
|
|
4
|
+
export const DATE_SELECTOR_COMPACT_DAY_FORMAT = 'M/d/yy';
|
|
5
|
+
export function resolveRollingCount(value) {
|
|
6
|
+
return value.rollingCount ?? value.rollingDays;
|
|
7
|
+
}
|
|
8
|
+
export function resolveRollingUnit(value) {
|
|
9
|
+
return value.rollingUnit ?? 'day';
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Inner text for rolling month chips. Count 1: the single target calendar month. Multiple months: `May 2026 - Oct 2026`
|
|
13
|
+
* style range (first–last month in the preset, {@link monthsShort}).
|
|
14
|
+
*/
|
|
15
|
+
function formatRollingMonthInnerLabel(startDate, endDate, mode, count, i18n) {
|
|
16
|
+
const full = (d) => `${i18n.months[d.getMonth()]} ${d.getFullYear()}`;
|
|
17
|
+
const short = (d) => `${i18n.monthsShort[d.getMonth()]} ${d.getFullYear()}`;
|
|
18
|
+
if (count === 1) {
|
|
19
|
+
if (mode === 'rolling-last') {
|
|
20
|
+
return full(subMonths(startOfMonth(endDate), 1));
|
|
21
|
+
}
|
|
22
|
+
return full(addMonths(startOfMonth(startDate), 1));
|
|
23
|
+
}
|
|
24
|
+
if (mode === 'rolling-next') {
|
|
25
|
+
const anchor = startOfMonth(startDate);
|
|
26
|
+
const first = addMonths(anchor, 1);
|
|
27
|
+
const last = addMonths(anchor, count);
|
|
28
|
+
return `${short(first)} - ${short(last)}`;
|
|
29
|
+
}
|
|
30
|
+
const anchorLast = startOfMonth(endDate);
|
|
31
|
+
const first = subMonths(anchorLast, count);
|
|
32
|
+
const last = subMonths(anchorLast, 1);
|
|
33
|
+
return `${short(first)} - ${short(last)}`;
|
|
34
|
+
}
|
|
35
|
+
function formatRollingQuarterSpan(startDate, endDate, i18n) {
|
|
36
|
+
const qLabel = (d) => `${i18n.quarters[getQuarter(d) - 1]} ${d.getFullYear()}`;
|
|
37
|
+
if (getQuarter(startDate) === getQuarter(endDate) && startDate.getFullYear() === endDate.getFullYear()) {
|
|
38
|
+
return qLabel(startDate);
|
|
39
|
+
}
|
|
40
|
+
return `${qLabel(startDate)} - ${qLabel(endDate)}`;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Short rolling label only (no calendar parenthetical, no day span) for compact bars when detail is shown in a tooltip.
|
|
44
|
+
*/
|
|
45
|
+
export function getRollingBarShortLabel(value, i18n = DEFAULT_DATE_SELECTOR_I18N) {
|
|
46
|
+
const { selectionMode } = value;
|
|
47
|
+
const count = resolveRollingCount(value);
|
|
48
|
+
if ((selectionMode !== 'rolling-next' && selectionMode !== 'rolling-last') || count === undefined)
|
|
49
|
+
return null;
|
|
50
|
+
const unit = resolveRollingUnit(value);
|
|
51
|
+
const isNext = selectionMode === 'rolling-next';
|
|
52
|
+
if (unit === 'month') {
|
|
53
|
+
if (count === 1)
|
|
54
|
+
return isNext ? i18n.rollingSummaryNextSingleMonth : i18n.rollingSummaryLastSingleMonth;
|
|
55
|
+
return (isNext ? i18n.rollingSummaryNextMonths : i18n.rollingSummaryLastMonths).replace('{{count}}', String(count));
|
|
56
|
+
}
|
|
57
|
+
if (unit === 'year') {
|
|
58
|
+
if (count === 1)
|
|
59
|
+
return isNext ? i18n.rollingSummaryNextYear : i18n.rollingSummaryLastYear;
|
|
60
|
+
return (isNext ? i18n.rollingSummaryNextYears : i18n.rollingSummaryLastYears).replace('{{count}}', String(count));
|
|
61
|
+
}
|
|
62
|
+
if (unit === 'quarter') {
|
|
63
|
+
if (count === 1)
|
|
64
|
+
return isNext ? i18n.rollingSummaryNextQuarter : i18n.rollingSummaryLastQuarter;
|
|
65
|
+
return (isNext ? i18n.rollingSummaryNextQuarters : i18n.rollingSummaryLastQuarters).replace('{{count}}', String(count));
|
|
66
|
+
}
|
|
67
|
+
return (isNext ? i18n.rollingSummaryNext : i18n.rollingSummaryLast).replace('{{count}}', String(count));
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Human-readable rolling preset title for compact summaries. **Rolling year** presets with bounds use
|
|
71
|
+
* `Next Year (2027)` / `Last Year (2025)`; **rolling month** inner text uses calendar-relative months, e.g.
|
|
72
|
+
* `Next Month (May 2026)`, `Last Month (March 2026)`; multi-month uses a span, e.g. `Next 6 Months (May 2026 - Oct 2026)`.
|
|
73
|
+
*/
|
|
74
|
+
export function getRollingSummaryLabel(value, i18n = DEFAULT_DATE_SELECTOR_I18N) {
|
|
75
|
+
const { selectionMode } = value;
|
|
76
|
+
const count = resolveRollingCount(value);
|
|
77
|
+
if ((selectionMode !== 'rolling-next' && selectionMode !== 'rolling-last') || count === undefined)
|
|
78
|
+
return null;
|
|
79
|
+
const unit = resolveRollingUnit(value);
|
|
80
|
+
const isNext = selectionMode === 'rolling-next';
|
|
81
|
+
if (unit === 'month') {
|
|
82
|
+
const phraseForMonthRange = (inner) => {
|
|
83
|
+
if (count === 1) {
|
|
84
|
+
return `${isNext ? i18n.rollingSummaryNextSingleMonth : i18n.rollingSummaryLastSingleMonth} (${inner})`;
|
|
85
|
+
}
|
|
86
|
+
const head = (isNext ? i18n.rollingSummaryNextMonths : i18n.rollingSummaryLastMonths).replace('{{count}}', String(count));
|
|
87
|
+
return `${head} (${inner})`;
|
|
88
|
+
};
|
|
89
|
+
if (value.startDate && value.endDate) {
|
|
90
|
+
return phraseForMonthRange(formatRollingMonthInnerLabel(value.startDate, value.endDate, selectionMode, count, i18n));
|
|
91
|
+
}
|
|
92
|
+
const { startDate, endDate } = computeRollingPresetRange(selectionMode, 'month', count, new Date());
|
|
93
|
+
return phraseForMonthRange(formatRollingMonthInnerLabel(startDate, endDate, selectionMode, count, i18n));
|
|
94
|
+
}
|
|
95
|
+
if (unit === 'year') {
|
|
96
|
+
const phraseForYearRange = (inner) => {
|
|
97
|
+
if (count === 1) {
|
|
98
|
+
return `${isNext ? i18n.rollingSummaryNextYear : i18n.rollingSummaryLastYear} (${inner})`;
|
|
99
|
+
}
|
|
100
|
+
const head = (isNext ? i18n.rollingSummaryNextYears : i18n.rollingSummaryLastYears).replace('{{count}}', String(count));
|
|
101
|
+
return `${head} (${inner})`;
|
|
102
|
+
};
|
|
103
|
+
if (value.startDate && value.endDate) {
|
|
104
|
+
const y1 = value.startDate.getFullYear();
|
|
105
|
+
const y2 = value.endDate.getFullYear();
|
|
106
|
+
const inner = y1 === y2 ? String(y1) : `${y1}–${y2}`;
|
|
107
|
+
return phraseForYearRange(inner);
|
|
108
|
+
}
|
|
109
|
+
if (count === undefined || count === 1)
|
|
110
|
+
return null;
|
|
111
|
+
const { startDate, endDate } = computeRollingPresetRange(selectionMode, 'year', count, new Date());
|
|
112
|
+
const y1 = startDate.getFullYear();
|
|
113
|
+
const y2 = endDate.getFullYear();
|
|
114
|
+
const inner = y1 === y2 ? String(y1) : `${y1}–${y2}`;
|
|
115
|
+
return phraseForYearRange(inner);
|
|
116
|
+
}
|
|
117
|
+
if (unit === 'quarter') {
|
|
118
|
+
const phraseForQuarterRange = (inner) => {
|
|
119
|
+
if (count === 1) {
|
|
120
|
+
return `${isNext ? i18n.rollingSummaryNextQuarter : i18n.rollingSummaryLastQuarter} (${inner})`;
|
|
121
|
+
}
|
|
122
|
+
const head = (isNext ? i18n.rollingSummaryNextQuarters : i18n.rollingSummaryLastQuarters).replace('{{count}}', String(count));
|
|
123
|
+
return `${head} (${inner})`;
|
|
124
|
+
};
|
|
125
|
+
if (value.startDate && value.endDate) {
|
|
126
|
+
return phraseForQuarterRange(formatRollingQuarterSpan(value.startDate, value.endDate, i18n));
|
|
127
|
+
}
|
|
128
|
+
if (count === undefined || count === 1)
|
|
129
|
+
return null;
|
|
130
|
+
const { startDate, endDate } = computeRollingPresetRange(selectionMode, 'quarter', count, new Date());
|
|
131
|
+
return phraseForQuarterRange(formatRollingQuarterSpan(startDate, endDate, i18n));
|
|
132
|
+
}
|
|
133
|
+
return (isNext ? i18n.rollingSummaryNext : i18n.rollingSummaryLast).replace('{{count}}', String(count));
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Inclusive calendar bounds for rolling presets. **Days:** “next N” / “last N” are the N calendar days **after** today /
|
|
137
|
+
* **before** today (today excluded). **Months** use month boundaries (last span can include today through end of day).
|
|
138
|
+
* **Years:** “last” / “next” use **full calendar years**
|
|
139
|
+
* adjacent to the current year (`last` → prior year(s), `next` → following year(s)), not partial ranges from today.
|
|
140
|
+
* **Quarters:** same pattern using calendar quarters adjacent to the current quarter.
|
|
141
|
+
*/
|
|
142
|
+
export function computeRollingPresetRange(mode, unit, count, now = new Date()) {
|
|
143
|
+
const today = startOfDay(now);
|
|
144
|
+
if (unit === 'day') {
|
|
145
|
+
if (mode === 'rolling-next') {
|
|
146
|
+
return {
|
|
147
|
+
startDate: startOfDay(addDays(today, 1)),
|
|
148
|
+
endDate: startOfDay(addDays(today, count)),
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
return {
|
|
152
|
+
startDate: startOfDay(subDays(today, count)),
|
|
153
|
+
endDate: startOfDay(subDays(today, 1)),
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
if (unit === 'month') {
|
|
157
|
+
if (mode === 'rolling-last') {
|
|
158
|
+
return {
|
|
159
|
+
startDate: startOfMonth(subMonths(today, count - 1)),
|
|
160
|
+
endDate: endOfDay(today),
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
const monthStart = startOfMonth(today);
|
|
164
|
+
return {
|
|
165
|
+
startDate: today,
|
|
166
|
+
endDate: endOfMonth(addMonths(monthStart, count - 1)),
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
if (unit === 'year') {
|
|
170
|
+
const yearStart = startOfYear(today);
|
|
171
|
+
if (mode === 'rolling-last') {
|
|
172
|
+
return {
|
|
173
|
+
startDate: startOfYear(subYears(yearStart, count)),
|
|
174
|
+
endDate: endOfYear(subYears(yearStart, 1)),
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
startDate: startOfYear(addYears(yearStart, 1)),
|
|
179
|
+
endDate: endOfYear(addYears(yearStart, count)),
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
if (unit === 'quarter') {
|
|
183
|
+
const quarterStart = startOfQuarter(today);
|
|
184
|
+
if (mode === 'rolling-last') {
|
|
185
|
+
return {
|
|
186
|
+
startDate: startOfQuarter(subQuarters(quarterStart, count)),
|
|
187
|
+
endDate: endOfQuarter(subQuarters(quarterStart, 1)),
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
return {
|
|
191
|
+
startDate: startOfQuarter(addQuarters(quarterStart, 1)),
|
|
192
|
+
endDate: endOfQuarter(addQuarters(quarterStart, count)),
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
const _unreachable = unit;
|
|
196
|
+
return _unreachable;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Computes inclusive calendar date bounds for rolling day windows. “Next N” is the N days **after** today (exclusive of
|
|
200
|
+
* today). “Last N” is the N days **before** today (exclusive of today).
|
|
201
|
+
*/
|
|
202
|
+
export function computeRollingDateRange(mode, days, now = new Date()) {
|
|
203
|
+
return computeRollingPresetRange(mode, 'day', days, now);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Calendar detail for any rolling preset — for tooltips when the bar uses {@link getRollingBarShortLabel} only.
|
|
207
|
+
* Uses `value` bounds when present, otherwise {@link computeRollingPresetRange}.
|
|
208
|
+
* Rolling **day** spans always use compact `M/d/yy` (e.g. `4/18/26`); the `dayDateFormat` argument is reserved for API compatibility and ignored for that unit.
|
|
209
|
+
*/
|
|
210
|
+
export function formatRollingRangeTooltipDetail(value, i18n = DEFAULT_DATE_SELECTOR_I18N,
|
|
211
|
+
/** @deprecated Ignored for rolling days; day tooltips use compact `M/d/yy`. Kept for call-site compatibility. */
|
|
212
|
+
_dayDateFormat = 'MM/dd/yyyy') {
|
|
213
|
+
if (value.selectionMode !== 'rolling-next' && value.selectionMode !== 'rolling-last')
|
|
214
|
+
return null;
|
|
215
|
+
const count = resolveRollingCount(value);
|
|
216
|
+
if (count === undefined)
|
|
217
|
+
return null;
|
|
218
|
+
const unit = resolveRollingUnit(value);
|
|
219
|
+
const mode = value.selectionMode;
|
|
220
|
+
const rangeOrCompute = (u) => value.startDate && value.endDate ? { startDate: value.startDate, endDate: value.endDate } : computeRollingPresetRange(mode, u, count);
|
|
221
|
+
if (unit === 'day') {
|
|
222
|
+
const { startDate, endDate } = rangeOrCompute('day');
|
|
223
|
+
return `${format(startDate, DATE_SELECTOR_COMPACT_DAY_FORMAT)} – ${format(endDate, DATE_SELECTOR_COMPACT_DAY_FORMAT)}`;
|
|
224
|
+
}
|
|
225
|
+
if (unit === 'month') {
|
|
226
|
+
const { startDate, endDate } = rangeOrCompute('month');
|
|
227
|
+
return formatRollingMonthInnerLabel(startDate, endDate, mode, count, i18n);
|
|
228
|
+
}
|
|
229
|
+
if (unit === 'quarter') {
|
|
230
|
+
const { startDate, endDate } = rangeOrCompute('quarter');
|
|
231
|
+
return formatRollingQuarterSpan(startDate, endDate, i18n);
|
|
232
|
+
}
|
|
233
|
+
if (unit === 'year') {
|
|
234
|
+
const { startDate, endDate } = rangeOrCompute('year');
|
|
235
|
+
const y1 = startDate.getFullYear();
|
|
236
|
+
const y2 = endDate.getFullYear();
|
|
237
|
+
return y1 === y2 ? String(y1) : `${y1}–${y2}`;
|
|
238
|
+
}
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Formats a {@link DateSelectorValue} for display using the same rules as the selector’s summary text.
|
|
243
|
+
*/
|
|
244
|
+
export function formatDateValue(value, i18n = DEFAULT_DATE_SELECTOR_I18N, dayDateFormat = 'MM/dd/yyyy', options) {
|
|
245
|
+
const { period, startDate, endDate, year, month, quarter, rangeStart, rangeEnd } = value;
|
|
246
|
+
const includeRollingDetail = options?.includeRollingRangeDetailInLabel !== false;
|
|
247
|
+
const rollingLabel = getRollingSummaryLabel(value, i18n);
|
|
248
|
+
if (rollingLabel !== null) {
|
|
249
|
+
if (!includeRollingDetail) {
|
|
250
|
+
const short = getRollingBarShortLabel(value, i18n);
|
|
251
|
+
return short ?? rollingLabel;
|
|
252
|
+
}
|
|
253
|
+
const ru = resolveRollingUnit(value);
|
|
254
|
+
if (ru === 'year' || ru === 'month' || ru === 'quarter') {
|
|
255
|
+
return rollingLabel;
|
|
256
|
+
}
|
|
257
|
+
if (startDate && endDate) {
|
|
258
|
+
return `${rollingLabel} (${format(startDate, DATE_SELECTOR_COMPACT_DAY_FORMAT)} – ${format(endDate, DATE_SELECTOR_COMPACT_DAY_FORMAT)})`;
|
|
259
|
+
}
|
|
260
|
+
return rollingLabel;
|
|
261
|
+
}
|
|
262
|
+
if (period === 'day') {
|
|
263
|
+
if (startDate && endDate) {
|
|
264
|
+
return `${format(startDate, dayDateFormat)} - ${format(endDate, dayDateFormat)}`;
|
|
265
|
+
}
|
|
266
|
+
if (startDate) {
|
|
267
|
+
return format(startDate, dayDateFormat);
|
|
268
|
+
}
|
|
269
|
+
return '';
|
|
270
|
+
}
|
|
271
|
+
if (period === 'month') {
|
|
272
|
+
if (rangeStart && rangeEnd) {
|
|
273
|
+
return `${i18n.monthsShort[rangeStart.value]} ${rangeStart.year} - ${i18n.monthsShort[rangeEnd.value]} ${rangeEnd.year}`;
|
|
274
|
+
}
|
|
275
|
+
if (year !== undefined && month !== undefined) {
|
|
276
|
+
return `${i18n.monthsShort[month]} ${year}`;
|
|
277
|
+
}
|
|
278
|
+
return '';
|
|
279
|
+
}
|
|
280
|
+
if (period === 'quarter') {
|
|
281
|
+
if (rangeStart && rangeEnd) {
|
|
282
|
+
return `${i18n.quarters[rangeStart.value]} ${rangeStart.year} - ${i18n.quarters[rangeEnd.value]} ${rangeEnd.year}`;
|
|
283
|
+
}
|
|
284
|
+
if (year !== undefined && quarter !== undefined) {
|
|
285
|
+
return `${i18n.quarters[quarter]} ${year}`;
|
|
286
|
+
}
|
|
287
|
+
return '';
|
|
288
|
+
}
|
|
289
|
+
if (period === 'year') {
|
|
290
|
+
if (rangeStart && rangeEnd) {
|
|
291
|
+
return `${rangeStart.year} - ${rangeEnd.year}`;
|
|
292
|
+
}
|
|
293
|
+
if (year !== undefined) {
|
|
294
|
+
return `${year}`;
|
|
295
|
+
}
|
|
296
|
+
return '';
|
|
297
|
+
}
|
|
298
|
+
return '';
|
|
299
|
+
}
|
|
300
|
+
/** Stable fingerprint for a {@link DateSelectorValue} (for sync keys and onChange deduplication). */
|
|
301
|
+
export function dateSelectorDataKey(value) {
|
|
302
|
+
if (value === undefined)
|
|
303
|
+
return '__uc__';
|
|
304
|
+
const v = value;
|
|
305
|
+
return [
|
|
306
|
+
v.period,
|
|
307
|
+
v.operator,
|
|
308
|
+
v.selectionMode ?? '',
|
|
309
|
+
v.rollingUnit ?? (v.rollingDays != null ? 'day' : ''),
|
|
310
|
+
v.rollingCount ?? v.rollingDays ?? '',
|
|
311
|
+
v.year ?? '',
|
|
312
|
+
v.month ?? '',
|
|
313
|
+
v.quarter ?? '',
|
|
314
|
+
v.startDate?.getTime() ?? '',
|
|
315
|
+
v.endDate?.getTime() ?? '',
|
|
316
|
+
v.rangeStart ? `${v.rangeStart.year}-${v.rangeStart.value}` : '',
|
|
317
|
+
v.rangeEnd ? `${v.rangeEnd.year}-${v.rangeEnd.value}` : '',
|
|
318
|
+
].join('|');
|
|
319
|
+
}
|
|
320
|
+
export function computeStateSyncKey(value, presetMode, defaultFilterType, validDefaultPeriodType) {
|
|
321
|
+
return `${dateSelectorDataKey(value)}|${presetMode ?? ''}|${defaultFilterType}|${validDefaultPeriodType}`;
|
|
322
|
+
}
|
|
323
|
+
export function createInitialInternalState(value, validDefaultPeriodType, defaultFilterType, presetMode) {
|
|
324
|
+
const calendarMonth = value?.startDate ?? new Date();
|
|
325
|
+
if (!value) {
|
|
326
|
+
return {
|
|
327
|
+
periodType: validDefaultPeriodType,
|
|
328
|
+
filterType: presetMode ?? defaultFilterType,
|
|
329
|
+
selectedDate: undefined,
|
|
330
|
+
selectedEndDate: undefined,
|
|
331
|
+
calendarMonth,
|
|
332
|
+
selectedYear: undefined,
|
|
333
|
+
selectedMonth: undefined,
|
|
334
|
+
selectedQuarter: undefined,
|
|
335
|
+
rangeStart: undefined,
|
|
336
|
+
rangeEnd: undefined,
|
|
337
|
+
hoverDate: undefined,
|
|
338
|
+
selectionMode: 'custom',
|
|
339
|
+
rollingUnit: 'day',
|
|
340
|
+
rollingCount: undefined,
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
const filterType = presetMode ?? value.operator ?? defaultFilterType;
|
|
344
|
+
if (value.selectionMode === 'rolling-next' || value.selectionMode === 'rolling-last') {
|
|
345
|
+
const rollingUnit = resolveRollingUnit(value);
|
|
346
|
+
const rollingCount = resolveRollingCount(value);
|
|
347
|
+
return {
|
|
348
|
+
periodType: value.period || validDefaultPeriodType,
|
|
349
|
+
filterType,
|
|
350
|
+
selectedDate: undefined,
|
|
351
|
+
selectedEndDate: undefined,
|
|
352
|
+
calendarMonth,
|
|
353
|
+
selectedYear: value.year,
|
|
354
|
+
selectedMonth: value.month,
|
|
355
|
+
selectedQuarter: value.quarter,
|
|
356
|
+
rangeStart: value.rangeStart,
|
|
357
|
+
rangeEnd: value.rangeEnd,
|
|
358
|
+
hoverDate: undefined,
|
|
359
|
+
selectionMode: value.selectionMode,
|
|
360
|
+
rollingUnit,
|
|
361
|
+
rollingCount,
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
return {
|
|
365
|
+
periodType: value.period || validDefaultPeriodType,
|
|
366
|
+
filterType,
|
|
367
|
+
selectedYear: value.year,
|
|
368
|
+
selectedMonth: value.month,
|
|
369
|
+
selectedQuarter: value.quarter,
|
|
370
|
+
rangeStart: value.rangeStart,
|
|
371
|
+
rangeEnd: value.rangeEnd,
|
|
372
|
+
hoverDate: undefined,
|
|
373
|
+
selectionMode: 'custom',
|
|
374
|
+
rollingUnit: 'day',
|
|
375
|
+
rollingCount: undefined,
|
|
376
|
+
selectedDate: value.startDate,
|
|
377
|
+
selectedEndDate: value.endDate,
|
|
378
|
+
calendarMonth,
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
export function buildRollingValueFromState(selectionMode, rollingUnit, rollingCount) {
|
|
382
|
+
if (selectionMode !== 'rolling-next' && selectionMode !== 'rolling-last') {
|
|
383
|
+
return undefined;
|
|
384
|
+
}
|
|
385
|
+
if (rollingCount === undefined) {
|
|
386
|
+
return {
|
|
387
|
+
period: 'day',
|
|
388
|
+
operator: 'between',
|
|
389
|
+
selectionMode,
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
const mode = selectionMode === 'rolling-next' ? 'rolling-next' : 'rolling-last';
|
|
393
|
+
const { startDate: rs, endDate: re } = computeRollingPresetRange(mode, rollingUnit, rollingCount, new Date());
|
|
394
|
+
const out = {
|
|
395
|
+
period: 'day',
|
|
396
|
+
operator: 'between',
|
|
397
|
+
selectionMode,
|
|
398
|
+
rollingUnit,
|
|
399
|
+
rollingCount,
|
|
400
|
+
startDate: rs,
|
|
401
|
+
endDate: re,
|
|
402
|
+
};
|
|
403
|
+
if (rollingUnit === 'day' && DATE_SELECTOR_ROLLING_DAY_OPTIONS.includes(rollingCount)) {
|
|
404
|
+
out.rollingDays = rollingCount;
|
|
405
|
+
}
|
|
406
|
+
return out;
|
|
407
|
+
}
|
|
408
|
+
export function buildCurrentValueFromInternal(s, presetMode) {
|
|
409
|
+
const rolling = buildRollingValueFromState(s.selectionMode, s.rollingUnit, s.rollingCount);
|
|
410
|
+
if (rolling)
|
|
411
|
+
return rolling;
|
|
412
|
+
return {
|
|
413
|
+
period: s.periodType,
|
|
414
|
+
operator: presetMode ?? s.filterType,
|
|
415
|
+
startDate: s.selectedDate,
|
|
416
|
+
endDate: s.selectedEndDate,
|
|
417
|
+
year: s.selectedYear,
|
|
418
|
+
month: s.selectedMonth,
|
|
419
|
+
quarter: s.selectedQuarter,
|
|
420
|
+
rangeStart: s.rangeStart,
|
|
421
|
+
rangeEnd: s.rangeEnd,
|
|
422
|
+
};
|
|
423
|
+
}
|
|
@@ -2,5 +2,5 @@ import { type DateSelectorProps } from './date-selector-types';
|
|
|
2
2
|
/**
|
|
3
3
|
* Composite filter control for dates and calendar periods. Root element sets `data-slot="date-selector"`.
|
|
4
4
|
*/
|
|
5
|
-
export declare function DateSelector({ value, onChange, allowRange, periodTypes, defaultPeriodType, defaultFilterType, presetMode, showInput, showOperators, showTwoMonths, label, className, yearRange, baseYear, minYear, maxYear, yearOptions, i18n: i18nOverride, inputHint, dayDateFormat, dayDateFormats, weekStartsOn, showRollingPresets, rollingDayOptions, }: DateSelectorProps): import("react/jsx-runtime").JSX.Element;
|
|
5
|
+
export declare function DateSelector({ value, onChange, allowRange, periodTypes, defaultPeriodType, defaultFilterType, presetMode, showInput, showOperators, showTwoMonths, label, className, yearRange, baseYear, minYear, maxYear, yearOptions, i18n: i18nOverride, i18nInstance: i18nInstanceProp, inputHint, dayDateFormat, dayDateFormats, weekStartsOn, showRollingPresets, rollingDayOptions, rollingMonthOptions, rollingQuarterOptions, rollingYearOptions, fillHeight, separateDayPeriod, }: DateSelectorProps): import("react/jsx-runtime").JSX.Element;
|
|
6
6
|
//# sourceMappingURL=date-selector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date-selector.d.ts","sourceRoot":"","sources":["../../../src/blocks/date-selector/date-selector.tsx"],"names":[],"mappings":"AAiCA,OAAO,EAKH,KAAK,iBAAiB,EAGzB,MAAM,uBAAuB,CAAC;AAI/B;;GAEG;AACH,wBAAgB,YAAY,CAAC,EACzB,KAAK,EACL,QAAQ,EACR,UAAiB,EACjB,WAAW,EACX,iBAAyB,EACzB,iBAAwB,EACxB,UAAU,EACV,SAAgB,EAChB,aAAoB,EACpB,aAAqB,EACrB,KAAK,EACL,SAAS,EACT,SAAa,EACb,QAAQ,EACR,OAAc,EACd,OAAc,EACd,WAAW,EACX,IAAI,EAAE,YAAY,EAClB,YAAY,EAAE,gBAAgB,EAC9B,SAAS,EACT,aAA4B,EAC5B,cAAc,EACd,YAAY,EACZ,kBAA0B,EAC1B,iBAAqD,EACrD,mBAAyD,EACzD,qBAA6D,EAC7D,kBAAuD,EACvD,UAAkB,EAClB,iBAAyB,GAC5B,EAAE,iBAAiB,2CAianB"}
|