@usefragments/ui 1.3.0 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -11
- package/dist/assets/ui.css +1093 -0
- package/dist/chart.cjs +1 -0
- package/dist/chart.js +1 -0
- package/dist/codeblock.cjs +1 -0
- package/dist/codeblock.js +1 -0
- package/dist/colorpicker.cjs +1 -0
- package/dist/colorpicker.js +1 -0
- package/dist/components/Accordion/index.cjs +1 -0
- package/dist/components/Accordion/index.js +1 -0
- package/dist/components/Alert/index.cjs +1 -0
- package/dist/components/Alert/index.js +1 -0
- package/dist/components/AppShell/index.cjs +1 -0
- package/dist/components/AppShell/index.js +1 -0
- package/dist/components/Avatar/index.cjs +1 -0
- package/dist/components/Avatar/index.js +1 -0
- package/dist/components/Badge/index.cjs +1 -0
- package/dist/components/Badge/index.js +1 -0
- package/dist/components/Breadcrumbs/index.cjs +1 -0
- package/dist/components/Breadcrumbs/index.js +1 -0
- package/dist/components/Button/index.cjs +1 -0
- package/dist/components/Button/index.js +1 -0
- package/dist/components/Card/index.cjs +1 -0
- package/dist/components/Card/index.js +1 -0
- package/dist/components/Checkbox/index.cjs +1 -0
- package/dist/components/Checkbox/index.js +1 -0
- package/dist/components/Chip/index.cjs +1 -0
- package/dist/components/Chip/index.js +1 -0
- package/dist/components/Collapsible/index.cjs +1 -0
- package/dist/components/Collapsible/index.js +1 -0
- package/dist/components/Combobox/index.cjs +1 -0
- package/dist/components/Combobox/index.js +1 -0
- package/dist/components/Command/index.cjs +1 -0
- package/dist/components/Command/index.js +1 -0
- package/dist/components/ComponentDefaults/index.cjs +1 -0
- package/dist/components/ComponentDefaults/index.js +1 -0
- package/dist/components/ConversationList/index.cjs +1 -0
- package/dist/components/ConversationList/index.js +1 -0
- package/dist/components/DatePicker/index.d.ts +1 -1
- package/dist/components/DatePicker/index.d.ts.map +1 -1
- package/dist/components/Dialog/index.cjs +1 -0
- package/dist/components/Dialog/index.js +1 -0
- package/dist/components/Drawer/index.cjs +1 -0
- package/dist/components/Drawer/index.js +1 -0
- package/dist/components/EmptyState/index.cjs +1 -0
- package/dist/components/EmptyState/index.js +1 -0
- package/dist/components/Field/index.cjs +1 -0
- package/dist/components/Field/index.js +1 -0
- package/dist/components/Fieldset/index.cjs +1 -0
- package/dist/components/Fieldset/index.js +1 -0
- package/dist/components/Form/index.cjs +1 -0
- package/dist/components/Form/index.js +1 -0
- package/dist/components/Header/index.cjs +1 -0
- package/dist/components/Header/index.js +1 -0
- package/dist/components/Icon/index.cjs +1 -0
- package/dist/components/Icon/index.js +1 -0
- package/dist/components/IconButton/index.cjs +1 -0
- package/dist/components/IconButton/index.js +1 -0
- package/dist/components/Image/index.cjs +1 -0
- package/dist/components/Image/index.js +1 -0
- package/dist/components/Input/index.cjs +1 -0
- package/dist/components/Input/index.js +1 -0
- package/dist/components/List/index.cjs +1 -0
- package/dist/components/List/index.js +1 -0
- package/dist/components/Listbox/index.cjs +1 -0
- package/dist/components/Listbox/index.js +1 -0
- package/dist/components/Loading/index.cjs +1 -0
- package/dist/components/Loading/index.js +1 -0
- package/dist/components/Menu/index.cjs +1 -0
- package/dist/components/Menu/index.js +1 -0
- package/dist/components/Message/index.cjs +1 -0
- package/dist/components/Message/index.js +1 -0
- package/dist/components/NavigationMenu/NavigationMenuContext.cjs +1 -0
- package/dist/components/NavigationMenu/NavigationMenuContext.js +1 -0
- package/dist/components/NavigationMenu/index.cjs +1 -0
- package/dist/components/NavigationMenu/index.js +1 -0
- package/dist/components/NavigationMenu/useNavigationMenu.cjs +1 -0
- package/dist/components/NavigationMenu/useNavigationMenu.js +1 -0
- package/dist/components/Pagination/index.cjs +1 -0
- package/dist/components/Pagination/index.js +1 -0
- package/dist/components/Popover/index.cjs +1 -0
- package/dist/components/Popover/index.js +1 -0
- package/dist/components/Progress/index.cjs +1 -0
- package/dist/components/Progress/index.js +1 -0
- package/dist/components/Prompt/index.cjs +1 -0
- package/dist/components/Prompt/index.js +1 -0
- package/dist/components/RadioGroup/index.cjs +1 -0
- package/dist/components/RadioGroup/index.js +1 -0
- package/dist/components/ScrollArea/index.cjs +1 -0
- package/dist/components/ScrollArea/index.js +1 -0
- package/dist/components/Select/index.cjs +1 -0
- package/dist/components/Select/index.js +1 -0
- package/dist/components/Separator/index.cjs +1 -0
- package/dist/components/Separator/index.js +1 -0
- package/dist/components/Sidebar/index.cjs +1 -0
- package/dist/components/Sidebar/index.js +1 -0
- package/dist/components/Slider/index.cjs +1 -0
- package/dist/components/Slider/index.js +1 -0
- package/dist/components/TableOfContents/index.cjs +1 -0
- package/dist/components/TableOfContents/index.js +1 -0
- package/dist/components/Tabs/index.cjs +1 -0
- package/dist/components/Tabs/index.js +1 -0
- package/dist/components/Theme/index.cjs +1 -0
- package/dist/components/Theme/index.js +1 -0
- package/dist/components/ThinkingIndicator/index.cjs +1 -0
- package/dist/components/ThinkingIndicator/index.js +1 -0
- package/dist/components/Toast/index.cjs +1 -0
- package/dist/components/Toast/index.js +1 -0
- package/dist/components/Toggle/index.cjs +1 -0
- package/dist/components/Toggle/index.js +1 -0
- package/dist/components/ToggleGroup/index.cjs +1 -0
- package/dist/components/ToggleGroup/index.js +1 -0
- package/dist/components/Tooltip/index.cjs +1 -0
- package/dist/components/Tooltip/index.js +1 -0
- package/dist/data-table-virtual.cjs +1 -0
- package/dist/data-table-virtual.js +1 -0
- package/dist/data-table.cjs +1 -0
- package/dist/data-table.js +1 -0
- package/dist/datepicker.cjs +69 -32
- package/dist/datepicker.js +42 -5
- package/dist/editor.cjs +1 -0
- package/dist/editor.js +1 -0
- package/dist/markdown.cjs +1 -0
- package/dist/markdown.js +1 -0
- package/dist/table.cjs +1 -0
- package/dist/table.js +1 -0
- package/dist/utils/a11y.cjs +1 -0
- package/dist/utils/a11y.js +1 -0
- package/dist/utils/keyboard-shortcuts.cjs +1 -0
- package/dist/utils/keyboard-shortcuts.js +1 -0
- package/package.json +3 -2
- package/src/components/DatePicker/index.tsx +64 -5
package/dist/data-table.cjs
CHANGED
package/dist/data-table.js
CHANGED
package/dist/datepicker.cjs
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
+
"use client";
|
|
1
2
|
"use strict";
|
|
2
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
4
|
const jsxRuntime = require("react/jsx-runtime");
|
|
4
5
|
const React = require("react");
|
|
5
6
|
const popover = require("@base-ui/react/popover");
|
|
6
|
-
const reactDayPicker = require("react-day-picker");
|
|
7
|
-
const dateFns = require("date-fns");
|
|
8
7
|
const aria = require("./utils/aria.cjs");
|
|
9
8
|
const index = require("./components/ComponentDefaults/index.cjs");
|
|
10
9
|
const DatePicker_module = require("./components/DatePicker/DatePicker.module.scss.cjs");
|
|
@@ -92,13 +91,23 @@ function useDatePickerContext() {
|
|
|
92
91
|
}
|
|
93
92
|
return context;
|
|
94
93
|
}
|
|
94
|
+
const longDateFormatter = new Intl.DateTimeFormat("en-US", {
|
|
95
|
+
month: "long",
|
|
96
|
+
day: "numeric",
|
|
97
|
+
year: "numeric"
|
|
98
|
+
});
|
|
99
|
+
const mediumDateFormatter = new Intl.DateTimeFormat("en-US", {
|
|
100
|
+
month: "short",
|
|
101
|
+
day: "2-digit",
|
|
102
|
+
year: "numeric"
|
|
103
|
+
});
|
|
95
104
|
function defaultFormatDate(date) {
|
|
96
|
-
return
|
|
105
|
+
return longDateFormatter.format(date);
|
|
97
106
|
}
|
|
98
107
|
function defaultFormatRange(range) {
|
|
99
108
|
if (!range.from) return "";
|
|
100
|
-
if (!range.to) return
|
|
101
|
-
return `${
|
|
109
|
+
if (!range.to) return mediumDateFormatter.format(range.from);
|
|
110
|
+
return `${mediumDateFormatter.format(range.from)} - ${mediumDateFormatter.format(range.to)}`;
|
|
102
111
|
}
|
|
103
112
|
function formatDateForHiddenInput(date) {
|
|
104
113
|
if (!date) return "";
|
|
@@ -107,32 +116,54 @@ function formatDateForHiddenInput(date) {
|
|
|
107
116
|
const day = String(date.getDate()).padStart(2, "0");
|
|
108
117
|
return `${year}-${month}-${day}`;
|
|
109
118
|
}
|
|
119
|
+
let _DayPicker = null;
|
|
120
|
+
let _UI = null;
|
|
121
|
+
let _SelectionState = null;
|
|
122
|
+
let _DayFlag = null;
|
|
123
|
+
let _rdpLoaded = false;
|
|
124
|
+
let _rdpFailed = false;
|
|
125
|
+
function loadDayPickerDeps() {
|
|
126
|
+
if (_rdpLoaded) return;
|
|
127
|
+
_rdpLoaded = true;
|
|
128
|
+
try {
|
|
129
|
+
const rdp = require("react-day-picker");
|
|
130
|
+
_DayPicker = rdp.DayPicker;
|
|
131
|
+
_UI = rdp.UI;
|
|
132
|
+
_SelectionState = rdp.SelectionState;
|
|
133
|
+
_DayFlag = rdp.DayFlag;
|
|
134
|
+
} catch {
|
|
135
|
+
_rdpFailed = true;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
110
138
|
function getCalendarClassNames() {
|
|
139
|
+
const UI = _UI;
|
|
140
|
+
const SelectionState = _SelectionState;
|
|
141
|
+
const DayFlag = _DayFlag;
|
|
111
142
|
return {
|
|
112
|
-
[
|
|
113
|
-
[
|
|
114
|
-
[
|
|
115
|
-
[
|
|
116
|
-
[
|
|
117
|
-
[
|
|
118
|
-
[
|
|
119
|
-
[
|
|
120
|
-
[
|
|
121
|
-
[
|
|
122
|
-
[
|
|
123
|
-
[
|
|
124
|
-
[
|
|
125
|
-
[
|
|
126
|
-
[
|
|
127
|
-
[
|
|
128
|
-
[
|
|
129
|
-
[
|
|
130
|
-
[
|
|
131
|
-
[
|
|
132
|
-
[
|
|
133
|
-
[
|
|
134
|
-
[
|
|
135
|
-
[
|
|
143
|
+
[UI.Root]: DatePicker_module.default.calendar,
|
|
144
|
+
[UI.Months]: DatePicker_module.default.months,
|
|
145
|
+
[UI.Month]: DatePicker_module.default.month,
|
|
146
|
+
[UI.MonthCaption]: DatePicker_module.default.monthCaption,
|
|
147
|
+
[UI.CaptionLabel]: DatePicker_module.default.captionLabel,
|
|
148
|
+
[UI.Nav]: DatePicker_module.default.nav,
|
|
149
|
+
[UI.PreviousMonthButton]: DatePicker_module.default.navButton,
|
|
150
|
+
[UI.NextMonthButton]: DatePicker_module.default.navButton,
|
|
151
|
+
[UI.MonthGrid]: DatePicker_module.default.monthGrid,
|
|
152
|
+
[UI.Weekdays]: DatePicker_module.default.weekdays,
|
|
153
|
+
[UI.Weekday]: DatePicker_module.default.weekday,
|
|
154
|
+
[UI.Weeks]: DatePicker_module.default.weeks,
|
|
155
|
+
[UI.Week]: DatePicker_module.default.week,
|
|
156
|
+
[UI.Day]: DatePicker_module.default.day,
|
|
157
|
+
[UI.DayButton]: DatePicker_module.default.dayButton,
|
|
158
|
+
[UI.Chevron]: DatePicker_module.default.chevron,
|
|
159
|
+
[SelectionState.selected]: DatePicker_module.default.selected,
|
|
160
|
+
[SelectionState.range_start]: DatePicker_module.default.rangeStart,
|
|
161
|
+
[SelectionState.range_middle]: DatePicker_module.default.rangeMiddle,
|
|
162
|
+
[SelectionState.range_end]: DatePicker_module.default.rangeEnd,
|
|
163
|
+
[DayFlag.today]: DatePicker_module.default.today,
|
|
164
|
+
[DayFlag.outside]: DatePicker_module.default.outside,
|
|
165
|
+
[DayFlag.disabled]: DatePicker_module.default.disabled,
|
|
166
|
+
[DayFlag.focused]: DatePicker_module.default.focused
|
|
136
167
|
};
|
|
137
168
|
}
|
|
138
169
|
const DatePickerRoot = React__namespace.forwardRef(function DatePickerRoot2({
|
|
@@ -339,12 +370,18 @@ function DatePickerCalendar({
|
|
|
339
370
|
}),
|
|
340
371
|
[]
|
|
341
372
|
);
|
|
373
|
+
loadDayPickerDeps();
|
|
374
|
+
if (_rdpFailed || !_DayPicker || !_UI) {
|
|
375
|
+
return null;
|
|
376
|
+
}
|
|
377
|
+
const DayPicker = _DayPicker;
|
|
378
|
+
const UI = _UI;
|
|
342
379
|
const calendarClassNames = getCalendarClassNames();
|
|
343
|
-
const calendarClasses = className ? { ...calendarClassNames, [
|
|
380
|
+
const calendarClasses = className ? { ...calendarClassNames, [UI.Root]: [DatePicker_module.default.calendar, className].join(" ") } : calendarClassNames;
|
|
344
381
|
if (ctx.mode === "range") {
|
|
345
382
|
const rangeSelected = ctx.selectedRange ? { from: ctx.selectedRange.from ?? void 0, to: ctx.selectedRange.to ?? void 0 } : void 0;
|
|
346
383
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
347
|
-
|
|
384
|
+
DayPicker,
|
|
348
385
|
{
|
|
349
386
|
mode: "range",
|
|
350
387
|
selected: rangeSelected,
|
|
@@ -364,7 +401,7 @@ function DatePickerCalendar({
|
|
|
364
401
|
);
|
|
365
402
|
}
|
|
366
403
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
367
|
-
|
|
404
|
+
DayPicker,
|
|
368
405
|
{
|
|
369
406
|
mode: "single",
|
|
370
407
|
selected: ctx.selected ?? void 0,
|
package/dist/datepicker.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
+
"use client";
|
|
1
2
|
import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
2
3
|
import * as React from "react";
|
|
3
4
|
import { Popover } from "@base-ui/react/popover";
|
|
4
|
-
import { UI, DayPicker, DayFlag, SelectionState } from "react-day-picker";
|
|
5
|
-
import { format } from "date-fns";
|
|
6
5
|
import { useFormFieldIds } from "./utils/aria.js";
|
|
7
6
|
import { useResolvedControlSize } from "./components/ComponentDefaults/index.js";
|
|
8
7
|
import styles from "./components/DatePicker/DatePicker.module.scss.js";
|
|
@@ -73,13 +72,23 @@ function useDatePickerContext() {
|
|
|
73
72
|
}
|
|
74
73
|
return context;
|
|
75
74
|
}
|
|
75
|
+
const longDateFormatter = new Intl.DateTimeFormat("en-US", {
|
|
76
|
+
month: "long",
|
|
77
|
+
day: "numeric",
|
|
78
|
+
year: "numeric"
|
|
79
|
+
});
|
|
80
|
+
const mediumDateFormatter = new Intl.DateTimeFormat("en-US", {
|
|
81
|
+
month: "short",
|
|
82
|
+
day: "2-digit",
|
|
83
|
+
year: "numeric"
|
|
84
|
+
});
|
|
76
85
|
function defaultFormatDate(date) {
|
|
77
|
-
return format(date
|
|
86
|
+
return longDateFormatter.format(date);
|
|
78
87
|
}
|
|
79
88
|
function defaultFormatRange(range) {
|
|
80
89
|
if (!range.from) return "";
|
|
81
|
-
if (!range.to) return format(range.from
|
|
82
|
-
return `${format(range.from
|
|
90
|
+
if (!range.to) return mediumDateFormatter.format(range.from);
|
|
91
|
+
return `${mediumDateFormatter.format(range.from)} - ${mediumDateFormatter.format(range.to)}`;
|
|
83
92
|
}
|
|
84
93
|
function formatDateForHiddenInput(date) {
|
|
85
94
|
if (!date) return "";
|
|
@@ -88,7 +97,29 @@ function formatDateForHiddenInput(date) {
|
|
|
88
97
|
const day = String(date.getDate()).padStart(2, "0");
|
|
89
98
|
return `${year}-${month}-${day}`;
|
|
90
99
|
}
|
|
100
|
+
let _DayPicker = null;
|
|
101
|
+
let _UI = null;
|
|
102
|
+
let _SelectionState = null;
|
|
103
|
+
let _DayFlag = null;
|
|
104
|
+
let _rdpLoaded = false;
|
|
105
|
+
let _rdpFailed = false;
|
|
106
|
+
function loadDayPickerDeps() {
|
|
107
|
+
if (_rdpLoaded) return;
|
|
108
|
+
_rdpLoaded = true;
|
|
109
|
+
try {
|
|
110
|
+
const rdp = require("react-day-picker");
|
|
111
|
+
_DayPicker = rdp.DayPicker;
|
|
112
|
+
_UI = rdp.UI;
|
|
113
|
+
_SelectionState = rdp.SelectionState;
|
|
114
|
+
_DayFlag = rdp.DayFlag;
|
|
115
|
+
} catch {
|
|
116
|
+
_rdpFailed = true;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
91
119
|
function getCalendarClassNames() {
|
|
120
|
+
const UI = _UI;
|
|
121
|
+
const SelectionState = _SelectionState;
|
|
122
|
+
const DayFlag = _DayFlag;
|
|
92
123
|
return {
|
|
93
124
|
[UI.Root]: styles.calendar,
|
|
94
125
|
[UI.Months]: styles.months,
|
|
@@ -320,6 +351,12 @@ function DatePickerCalendar({
|
|
|
320
351
|
}),
|
|
321
352
|
[]
|
|
322
353
|
);
|
|
354
|
+
loadDayPickerDeps();
|
|
355
|
+
if (_rdpFailed || !_DayPicker || !_UI) {
|
|
356
|
+
return null;
|
|
357
|
+
}
|
|
358
|
+
const DayPicker = _DayPicker;
|
|
359
|
+
const UI = _UI;
|
|
323
360
|
const calendarClassNames = getCalendarClassNames();
|
|
324
361
|
const calendarClasses = className ? { ...calendarClassNames, [UI.Root]: [styles.calendar, className].join(" ") } : calendarClassNames;
|
|
325
362
|
if (ctx.mode === "range") {
|
package/dist/editor.cjs
CHANGED
package/dist/editor.js
CHANGED
package/dist/markdown.cjs
CHANGED
package/dist/markdown.js
CHANGED
package/dist/table.cjs
CHANGED
package/dist/table.js
CHANGED
package/dist/utils/a11y.cjs
CHANGED
package/dist/utils/a11y.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usefragments/ui",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Customizable UI components built on Base UI headless primitives",
|
|
6
6
|
"author": "Conan McNicholl",
|
|
@@ -233,6 +233,7 @@
|
|
|
233
233
|
"react-colorful": "^5.6.1",
|
|
234
234
|
"react-day-picker": "^9.0.0",
|
|
235
235
|
"react-dom": "^19.0.0",
|
|
236
|
+
"rollup-plugin-preserve-directives": "0.4.0",
|
|
236
237
|
"sass": "^1.83.0",
|
|
237
238
|
"shiki": "^3.0.0",
|
|
238
239
|
"storybook": "^8",
|
|
@@ -261,7 +262,7 @@
|
|
|
261
262
|
],
|
|
262
263
|
"scripts": {
|
|
263
264
|
"dev": "storybook dev -p 6006",
|
|
264
|
-
"build": "vite build && tsc -p tsconfig.build.json",
|
|
265
|
+
"build": "vite build && node ./scripts/emit-complete-styles.mjs && tsc -p tsconfig.build.json",
|
|
265
266
|
"lint": "eslint src",
|
|
266
267
|
"test": "vitest run",
|
|
267
268
|
"build-storybook": "storybook build",
|
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
import { Popover as BasePopover } from "@base-ui/react/popover";
|
|
5
|
-
import { DayFlag, DayPicker, SelectionState, UI } from "react-day-picker";
|
|
6
|
-
import { format as formatDateWithPattern } from "date-fns";
|
|
7
5
|
import { useFormFieldIds, type FormFieldProps } from "../../utils/aria";
|
|
8
6
|
import { useResolvedControlSize } from "../ComponentDefaults";
|
|
9
7
|
import styles from "./DatePicker.module.scss";
|
|
@@ -186,15 +184,30 @@ function useDatePickerContext() {
|
|
|
186
184
|
// ============================================
|
|
187
185
|
// Default formatters
|
|
188
186
|
// ============================================
|
|
187
|
+
//
|
|
188
|
+
// Zero-dependency `Intl.DateTimeFormat` so the default trigger label needs no
|
|
189
|
+
// optional peer. `date-fns` remains an optional peer only for consumers who pass
|
|
190
|
+
// their own `formatDate`/`formatRange`; the default path never imports it, so a
|
|
191
|
+
// bundler that pulls DatePicker into the graph does not fail on a missing peer.
|
|
192
|
+
const longDateFormatter = new Intl.DateTimeFormat("en-US", {
|
|
193
|
+
month: "long",
|
|
194
|
+
day: "numeric",
|
|
195
|
+
year: "numeric",
|
|
196
|
+
});
|
|
197
|
+
const mediumDateFormatter = new Intl.DateTimeFormat("en-US", {
|
|
198
|
+
month: "short",
|
|
199
|
+
day: "2-digit",
|
|
200
|
+
year: "numeric",
|
|
201
|
+
});
|
|
189
202
|
|
|
190
203
|
function defaultFormatDate(date: Date): string {
|
|
191
|
-
return
|
|
204
|
+
return longDateFormatter.format(date);
|
|
192
205
|
}
|
|
193
206
|
|
|
194
207
|
function defaultFormatRange(range: DateRange): string {
|
|
195
208
|
if (!range.from) return "";
|
|
196
|
-
if (!range.to) return
|
|
197
|
-
return `${
|
|
209
|
+
if (!range.to) return mediumDateFormatter.format(range.from);
|
|
210
|
+
return `${mediumDateFormatter.format(range.from)} - ${mediumDateFormatter.format(range.to)}`;
|
|
198
211
|
}
|
|
199
212
|
|
|
200
213
|
function formatDateForHiddenInput(date?: Date): string {
|
|
@@ -205,11 +218,48 @@ function formatDateForHiddenInput(date?: Date): string {
|
|
|
205
218
|
return `${year}-${month}-${day}`;
|
|
206
219
|
}
|
|
207
220
|
|
|
221
|
+
// ============================================
|
|
222
|
+
// Lazy-loaded dependency (react-day-picker)
|
|
223
|
+
// ============================================
|
|
224
|
+
//
|
|
225
|
+
// Loaded on demand via require() so the barrel never statically references the
|
|
226
|
+
// optional `react-day-picker` peer. Importing anything else from
|
|
227
|
+
// @usefragments/ui must not drag the calendar (or its transitive `date-fns`
|
|
228
|
+
// dependency) into a consumer's build graph. Mirrors the Chart/recharts pattern.
|
|
229
|
+
|
|
230
|
+
type DayPickerComponent = React.ComponentType<Record<string, unknown>>;
|
|
231
|
+
type RdpEnum = Record<string, string>;
|
|
232
|
+
|
|
233
|
+
let _DayPicker: DayPickerComponent | null = null;
|
|
234
|
+
let _UI: RdpEnum | null = null;
|
|
235
|
+
let _SelectionState: RdpEnum | null = null;
|
|
236
|
+
let _DayFlag: RdpEnum | null = null;
|
|
237
|
+
let _rdpLoaded = false;
|
|
238
|
+
let _rdpFailed = false;
|
|
239
|
+
|
|
240
|
+
function loadDayPickerDeps(): void {
|
|
241
|
+
if (_rdpLoaded) return;
|
|
242
|
+
_rdpLoaded = true;
|
|
243
|
+
try {
|
|
244
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
245
|
+
const rdp = require("react-day-picker");
|
|
246
|
+
_DayPicker = rdp.DayPicker as DayPickerComponent;
|
|
247
|
+
_UI = rdp.UI as RdpEnum;
|
|
248
|
+
_SelectionState = rdp.SelectionState as RdpEnum;
|
|
249
|
+
_DayFlag = rdp.DayFlag as RdpEnum;
|
|
250
|
+
} catch {
|
|
251
|
+
_rdpFailed = true;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
208
255
|
// ============================================
|
|
209
256
|
// ClassNames mapping (built lazily)
|
|
210
257
|
// ============================================
|
|
211
258
|
|
|
212
259
|
function getCalendarClassNames() {
|
|
260
|
+
const UI = _UI!;
|
|
261
|
+
const SelectionState = _SelectionState!;
|
|
262
|
+
const DayFlag = _DayFlag!;
|
|
213
263
|
return {
|
|
214
264
|
[UI.Root]: styles.calendar,
|
|
215
265
|
[UI.Months]: styles.months,
|
|
@@ -517,6 +567,15 @@ function DatePickerCalendar({
|
|
|
517
567
|
[]
|
|
518
568
|
);
|
|
519
569
|
|
|
570
|
+
loadDayPickerDeps();
|
|
571
|
+
if (_rdpFailed || !_DayPicker || !_UI) {
|
|
572
|
+
// react-day-picker is an optional peer: render nothing rather than crash
|
|
573
|
+
// when a consumer mounts <DatePicker> without installing the calendar dep.
|
|
574
|
+
return null;
|
|
575
|
+
}
|
|
576
|
+
const DayPicker = _DayPicker;
|
|
577
|
+
const UI = _UI;
|
|
578
|
+
|
|
520
579
|
const calendarClassNames = getCalendarClassNames();
|
|
521
580
|
|
|
522
581
|
const calendarClasses = className
|