@open-mercato/ui 0.8.1-develop.7215.1.60786cf836 → 0.8.1-develop.7219.1.f96cb57e70
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/.turbo/turbo-build.log +1 -1
- package/build.mjs +34 -7
- package/dist/backend/inputs/TimePicker.js +8 -3
- package/dist/backend/inputs/TimePicker.js.map +2 -2
- package/dist/primitives/calendar.js +5 -3
- package/dist/primitives/calendar.js.map +2 -2
- package/dist/primitives/date-locale.js +47 -0
- package/dist/primitives/date-locale.js.map +7 -0
- package/dist/primitives/date-picker.js +4 -1
- package/dist/primitives/date-picker.js.map +2 -2
- package/dist/primitives/time-picker.js.map +1 -1
- package/package.json +3 -3
- package/scripts/lucideRegistrySource.cjs +16 -1
- package/src/backend/__tests__/CrudForm.datetime.test.tsx +62 -0
- package/src/backend/icons/__tests__/lucideRegistryGenerator.test.ts +27 -1
- package/src/backend/inputs/TimePicker.tsx +17 -4
- package/src/backend/inputs/__tests__/DatePicker.test.tsx +1 -0
- package/src/backend/inputs/__tests__/TimePicker.test.tsx +31 -0
- package/src/primitives/__tests__/date-locale.test.ts +53 -0
- package/src/primitives/__tests__/date-picker.test.tsx +54 -2
- package/src/primitives/calendar.tsx +11 -3
- package/src/primitives/date-locale.ts +80 -0
- package/src/primitives/date-picker.tsx +16 -1
- package/src/primitives/time-picker.tsx +1 -1
package/.turbo/turbo-build.log
CHANGED
package/build.mjs
CHANGED
|
@@ -1,22 +1,49 @@
|
|
|
1
|
-
import { writeFileSync } from 'node:fs'
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from 'node:fs'
|
|
2
2
|
import { dirname, join } from 'node:path'
|
|
3
3
|
import { fileURLToPath } from 'node:url'
|
|
4
4
|
import { buildPackage } from '../../scripts/build-package.mjs'
|
|
5
5
|
import { discoverResolvedIcons } from './scripts/lucideIconDiscovery.cjs'
|
|
6
|
-
import { buildLucideRegistrySource } from './scripts/lucideRegistrySource.cjs'
|
|
6
|
+
import { buildLucideRegistrySource, checkLucideRegistryDrift } from './scripts/lucideRegistrySource.cjs'
|
|
7
7
|
|
|
8
8
|
const packageDir = dirname(fileURLToPath(import.meta.url))
|
|
9
|
+
// `--check` regenerates the lucide registry in memory and fails on drift
|
|
10
|
+
// without writing or building — the CI guard mode (`yarn ui:icons:check`).
|
|
11
|
+
const checkOnly = process.argv.includes('--check')
|
|
9
12
|
|
|
10
13
|
async function generateLucideRegistry() {
|
|
11
14
|
const repoRoot = join(packageDir, '..', '..')
|
|
12
15
|
const resolved = await discoverResolvedIcons(repoRoot)
|
|
13
16
|
|
|
14
17
|
const outPath = join(packageDir, 'src/backend/icons/lucideRegistry.generated.tsx')
|
|
15
|
-
|
|
18
|
+
const source = buildLucideRegistrySource(resolved)
|
|
19
|
+
|
|
20
|
+
// `--check` makes this a drift guard instead of a writer. The committed
|
|
21
|
+
// registry is a canonical mirror of a repo-wide scan, so nothing inside
|
|
22
|
+
// `packages/ui`'s own test suite can protect it: a PR that adds
|
|
23
|
+
// `icon: 'some-lucide-name'` in another package never selects `packages/ui`
|
|
24
|
+
// under turbo's `--filter=[base]...` (ui is a dependency of those packages,
|
|
25
|
+
// not a dependent), which is exactly how #4391 drifted unnoticed. CI calls
|
|
26
|
+
// this unfiltered, mirroring `ds:tokens:check`.
|
|
27
|
+
if (checkOnly) {
|
|
28
|
+
const committed = existsSync(outPath) ? readFileSync(outPath, 'utf8') : ''
|
|
29
|
+
const drift = checkLucideRegistryDrift(committed, source, outPath)
|
|
30
|
+
if (drift.drifted) {
|
|
31
|
+
console.error(drift.message)
|
|
32
|
+
process.exit(1)
|
|
33
|
+
}
|
|
34
|
+
console.log(`Lucide registry is in sync (${resolved.length} icons).`)
|
|
35
|
+
return
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
writeFileSync(outPath, source)
|
|
16
39
|
console.log(`Generated lucide registry with ${resolved.length} icons -> ${outPath}`)
|
|
17
40
|
}
|
|
18
41
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
42
|
+
if (checkOnly) {
|
|
43
|
+
await generateLucideRegistry()
|
|
44
|
+
} else {
|
|
45
|
+
await buildPackage(packageDir, {
|
|
46
|
+
name: 'ui',
|
|
47
|
+
beforeBuild: generateLucideRegistry,
|
|
48
|
+
})
|
|
49
|
+
}
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
TimePicker as TimePickerPrimitive,
|
|
9
9
|
formatTimePickerDisplay
|
|
10
10
|
} from "../../primitives/time-picker.js";
|
|
11
|
+
import { useTimeDisplayFormat } from "../../primitives/date-locale.js";
|
|
11
12
|
function currentHHMM() {
|
|
12
13
|
const now = /* @__PURE__ */ new Date();
|
|
13
14
|
const hour = String(now.getHours()).padStart(2, "0");
|
|
@@ -27,16 +28,19 @@ function TimePicker({
|
|
|
27
28
|
// button already exits the popover without committing, which is what users mean
|
|
28
29
|
// by "Clear" in most flows. Pass `showClearButton={true}` to opt back in when
|
|
29
30
|
// you need an explicit "set value to null" action distinct from "dismiss".
|
|
30
|
-
showClearButton = false
|
|
31
|
+
showClearButton = false,
|
|
32
|
+
format
|
|
31
33
|
}) {
|
|
32
34
|
const t = useT();
|
|
35
|
+
const localeFormat = useTimeDisplayFormat();
|
|
36
|
+
const timeFormat = format ?? localeFormat;
|
|
33
37
|
const [open, setOpen] = React.useState(false);
|
|
34
38
|
const placeholderText = placeholder ?? t("ui.timePicker.placeholder", "Pick a time");
|
|
35
39
|
const nowText = t("ui.timePicker.nowButton", "Now");
|
|
36
40
|
const clearText = t("ui.timePicker.clearButton", "Clear");
|
|
37
41
|
const isInteractive = !disabled && !readOnly;
|
|
38
42
|
const displayValue = value ? (() => {
|
|
39
|
-
const { main, suffix } = formatTimePickerDisplay(value,
|
|
43
|
+
const { main, suffix } = formatTimePickerDisplay(value, timeFormat);
|
|
40
44
|
return suffix ? `${main} ${suffix}` : main;
|
|
41
45
|
})() : null;
|
|
42
46
|
const triggerButton = /* @__PURE__ */ jsxs(
|
|
@@ -67,7 +71,7 @@ function TimePicker({
|
|
|
67
71
|
const pinnedTopActions = [];
|
|
68
72
|
if (showNowButton) {
|
|
69
73
|
const nowValue = currentHHMM();
|
|
70
|
-
const { main: nowMain, suffix: nowSuffix } = formatTimePickerDisplay(nowValue,
|
|
74
|
+
const { main: nowMain, suffix: nowSuffix } = formatTimePickerDisplay(nowValue, timeFormat);
|
|
71
75
|
pinnedTopActions.push({
|
|
72
76
|
label: nowText,
|
|
73
77
|
icon: /* @__PURE__ */ jsx(ClockIcon, { "aria-hidden": "true" }),
|
|
@@ -98,6 +102,7 @@ function TimePicker({
|
|
|
98
102
|
onChange(next);
|
|
99
103
|
},
|
|
100
104
|
intervalMinutes: Math.max(1, minuteStep),
|
|
105
|
+
format: timeFormat,
|
|
101
106
|
showHeader: false,
|
|
102
107
|
showFooter: true,
|
|
103
108
|
headerPlaceholder: placeholderText,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/backend/inputs/TimePicker.tsx"],
|
|
4
|
-
"sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport { ClockIcon } from 'lucide-react'\nimport { cn } from '@open-mercato/shared/lib/utils'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport {\n TimePicker as TimePickerPrimitive,\n formatTimePickerDisplay,\n} from '../../primitives/time-picker'\n\nexport type TimePickerProps = {\n value?: string | null\n onChange: (time: string | null) => void\n placeholder?: string\n disabled?: boolean\n readOnly?: boolean\n className?: string\n minuteStep?: number\n showNowButton?: boolean\n showClearButton?: boolean\n}\n\nfunction currentHHMM(): string {\n const now = new Date()\n const hour = String(now.getHours()).padStart(2, '0')\n const minute = String(now.getMinutes()).padStart(2, '0')\n return `${hour}:${minute}`\n}\n\n/**\n * Legacy popover-anchored time picker. Preserved for backward compatibility with\n * existing CrudForm `type: 'time'` consumers and DateTimePicker. Internally a shim\n * over the new `<TimePicker>` primitive from `@open-mercato/ui/primitives/time-picker`.\n *\n * `minuteStep` maps to `intervalMinutes` (default 30 for sane slot list size).\n * `showNowButton` / `showClearButton` render as `legacyFooterActions`.\n */\nexport function TimePicker({\n value,\n onChange,\n placeholder,\n disabled = false,\n readOnly = false,\n className,\n minuteStep = 30,\n showNowButton = true,\n // Default changed 2026-05-11 from `true` \u2192 `false`: the new primitive's Cancel\n // button already exits the popover without committing, which is what users mean\n // by \"Clear\" in most flows. Pass `showClearButton={true}` to opt back in when\n // you need an explicit \"set value to null\" action distinct from \"dismiss\".\n showClearButton = false,\n}: TimePickerProps) {\n const t = useT()\n const [open, setOpen] = React.useState(false)\n\n const placeholderText = placeholder ?? t('ui.timePicker.placeholder', 'Pick a time')\n const nowText = t('ui.timePicker.nowButton', 'Now')\n const clearText = t('ui.timePicker.clearButton', 'Clear')\n const isInteractive = !disabled && !readOnly\n\n // Render the trigger label in the same
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport { ClockIcon } from 'lucide-react'\nimport { cn } from '@open-mercato/shared/lib/utils'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport {\n TimePicker as TimePickerPrimitive,\n formatTimePickerDisplay,\n type TimeFormat,\n} from '../../primitives/time-picker'\nimport { useTimeDisplayFormat } from '../../primitives/date-locale'\n\nexport type TimePickerProps = {\n value?: string | null\n onChange: (time: string | null) => void\n placeholder?: string\n disabled?: boolean\n readOnly?: boolean\n className?: string\n minuteStep?: number\n showNowButton?: boolean\n showClearButton?: boolean\n /**\n * Clock convention for the trigger label and the slot list. Defaults to the one the active\n * locale writes time in \u2014 `12h` for English and Korean, `24h` for Polish, German and Spanish \u2014\n * so a tenant does not read an AM/PM clock its language never uses. Pass an explicit value to\n * pin one regardless of locale.\n */\n format?: TimeFormat\n}\n\nfunction currentHHMM(): string {\n const now = new Date()\n const hour = String(now.getHours()).padStart(2, '0')\n const minute = String(now.getMinutes()).padStart(2, '0')\n return `${hour}:${minute}`\n}\n\n/**\n * Legacy popover-anchored time picker. Preserved for backward compatibility with\n * existing CrudForm `type: 'time'` consumers and DateTimePicker. Internally a shim\n * over the new `<TimePicker>` primitive from `@open-mercato/ui/primitives/time-picker`.\n *\n * `minuteStep` maps to `intervalMinutes` (default 30 for sane slot list size).\n * `showNowButton` / `showClearButton` render as `legacyFooterActions`.\n */\nexport function TimePicker({\n value,\n onChange,\n placeholder,\n disabled = false,\n readOnly = false,\n className,\n minuteStep = 30,\n showNowButton = true,\n // Default changed 2026-05-11 from `true` \u2192 `false`: the new primitive's Cancel\n // button already exits the popover without committing, which is what users mean\n // by \"Clear\" in most flows. Pass `showClearButton={true}` to opt back in when\n // you need an explicit \"set value to null\" action distinct from \"dismiss\".\n showClearButton = false,\n format,\n}: TimePickerProps) {\n const t = useT()\n const localeFormat = useTimeDisplayFormat()\n const timeFormat = format ?? localeFormat\n const [open, setOpen] = React.useState(false)\n\n const placeholderText = placeholder ?? t('ui.timePicker.placeholder', 'Pick a time')\n const nowText = t('ui.timePicker.nowButton', 'Now')\n const clearText = t('ui.timePicker.clearButton', 'Clear')\n const isInteractive = !disabled && !readOnly\n\n // Render the trigger label in the same format as the slot list inside the popover\n // so users see one consistent representation.\n const displayValue = value\n ? (() => {\n const { main, suffix } = formatTimePickerDisplay(value, timeFormat)\n return suffix ? `${main} ${suffix}` : main\n })()\n : null\n\n const triggerButton = (\n <button\n type=\"button\"\n data-crud-focus-target=\"\"\n disabled={disabled}\n aria-haspopup=\"dialog\"\n className={cn(\n 'w-full h-10 flex items-center gap-2 rounded-md border bg-background px-3 text-sm text-left transition-colors',\n 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1',\n 'disabled:bg-muted disabled:text-muted-foreground disabled:cursor-not-allowed',\n readOnly && 'cursor-default opacity-70',\n !value && 'text-muted-foreground',\n className,\n )}\n onClick={!isInteractive ? (event) => event.preventDefault() : undefined}\n >\n <ClockIcon className=\"h-4 w-4 shrink-0 text-muted-foreground\" />\n <span className=\"flex-1 truncate\">{displayValue ?? placeholderText}</span>\n </button>\n )\n\n if (!isInteractive) {\n return triggerButton\n }\n\n const pinnedTopActions: Array<{\n label: string\n onClick: () => void\n icon?: React.ReactNode\n rightText?: string\n }> = []\n if (showNowButton) {\n const nowValue = currentHHMM()\n const { main: nowMain, suffix: nowSuffix } = formatTimePickerDisplay(nowValue, timeFormat)\n pinnedTopActions.push({\n label: nowText,\n icon: <ClockIcon aria-hidden=\"true\" />,\n rightText: nowSuffix ? `${nowMain} ${nowSuffix}` : nowMain,\n onClick: () => {\n onChange(nowValue)\n setOpen(false)\n },\n })\n }\n\n const legacyFooterActions: Array<{ label: string; onClick: () => void; variant: 'link' | 'muted' }> = []\n if (showClearButton) {\n legacyFooterActions.push({\n label: clearText,\n onClick: () => {\n onChange(null)\n setOpen(false)\n },\n variant: 'muted',\n })\n }\n\n return (\n <TimePickerPrimitive\n value={value ?? null}\n onChange={(next) => onChange(next)}\n onApply={(next) => {\n onChange(next)\n }}\n intervalMinutes={Math.max(1, minuteStep)}\n format={timeFormat}\n // Trigger button already displays current value \u2014 don't duplicate it\n // inside the popover header.\n showHeader={false}\n showFooter\n headerPlaceholder={placeholderText}\n pinnedTopActions={pinnedTopActions.length > 0 ? pinnedTopActions : undefined}\n legacyFooterActions={legacyFooterActions.length > 0 ? legacyFooterActions : undefined}\n trigger={triggerButton}\n open={open}\n onOpenChange={setOpen}\n disabled={disabled}\n />\n )\n}\n"],
|
|
5
|
+
"mappings": ";AAmFI,SAeE,KAfF;AAjFJ,YAAY,WAAW;AACvB,SAAS,iBAAiB;AAC1B,SAAS,UAAU;AACnB,SAAS,YAAY;AACrB;AAAA,EACE,cAAc;AAAA,EACd;AAAA,OAEK;AACP,SAAS,4BAA4B;AAqBrC,SAAS,cAAsB;AAC7B,QAAM,MAAM,oBAAI,KAAK;AACrB,QAAM,OAAO,OAAO,IAAI,SAAS,CAAC,EAAE,SAAS,GAAG,GA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mBAKD,CAAC;AACN,MAAI,eAAe;AACjB,UAAM,WAAW,YAAY;AAC7B,UAAM,EAAE,MAAM,SAAS,QAAQ,UAAU,IAAI,wBAAwB,UAAU,UAAU;AACzF,qBAAiB,KAAK;AAAA,MACpB,OAAO;AAAA,MACP,MAAM,oBAAC,aAAU,eAAY,QAAO;AAAA,MACpC,WAAW,YAAY,GAAG,OAAO,IAAI,SAAS,KAAK;AAAA,MACnD,SAAS,MAAM;AACb,iBAAS,QAAQ;AACjB,gBAAQ,KAAK;AAAA,MACf;AAAA,IACF,CAAC;AAAA,EACH;AAEA,QAAM,sBAAgG,CAAC;AACvG,MAAI,iBAAiB;AACnB,wBAAoB,KAAK;AAAA,MACvB,OAAO;AAAA,MACP,SAAS,MAAM;AACb,iBAAS,IAAI;AACb,gBAAQ,KAAK;AAAA,MACf;AAAA,MACA,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACC,OAAO,SAAS;AAAA,MAChB,UAAU,CAAC,SAAS,SAAS,IAAI;AAAA,MACjC,SAAS,CAAC,SAAS;AACjB,iBAAS,IAAI;AAAA,MACf;AAAA,MACA,iBAAiB,KAAK,IAAI,GAAG,UAAU;AAAA,MACvC,QAAQ;AAAA,MAGR,YAAY;AAAA,MACZ,YAAU;AAAA,MACV,mBAAmB;AAAA,MACnB,kBAAkB,iBAAiB,SAAS,IAAI,mBAAmB;AAAA,MACnE,qBAAqB,oBAAoB,SAAS,IAAI,sBAAsB;AAAA,MAC5E,SAAS;AAAA,MACT;AAAA,MACA,cAAc;AAAA,MACd;AAAA;AAAA,EACF;AAEJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -24,6 +24,8 @@ function CalendarMonthSelector({
|
|
|
24
24
|
onNextMonth ? /* @__PURE__ */ jsx(CompactButton, { appearance: "white", size: 24, className: "shadow-xs", onClick: onNextMonth, disabled: disabledNext, "aria-label": t("ui.calendar.nextMonth", "Next month"), children: /* @__PURE__ */ jsx(ChevronRight, { className: "size-5", "aria-hidden": "true" }) }) : /* @__PURE__ */ jsx("span", { className: "size-6 shrink-0", "aria-hidden": "true" })
|
|
25
25
|
] });
|
|
26
26
|
}
|
|
27
|
+
const STANDALONE_MONTH_YEAR = "LLLL yyyy";
|
|
28
|
+
const STANDALONE_MONTH_SHORT = "LLL";
|
|
27
29
|
const navButtonClassName = cn(
|
|
28
30
|
"h-9 w-9 inline-flex items-center justify-center rounded-md shrink-0",
|
|
29
31
|
"border border-border bg-background text-muted-foreground transition-colors",
|
|
@@ -38,7 +40,7 @@ function MonthNavButton({
|
|
|
38
40
|
const dayPicker = useDayPicker();
|
|
39
41
|
const target = direction === "prev" ? dayPicker.previousMonth : dayPicker.nextMonth;
|
|
40
42
|
const Icon = direction === "prev" ? ChevronLeft : ChevronRight;
|
|
41
|
-
const targetLabel = format(target ?? /* @__PURE__ */ new Date(),
|
|
43
|
+
const targetLabel = format(target ?? /* @__PURE__ */ new Date(), STANDALONE_MONTH_YEAR, locale ? { locale } : void 0);
|
|
42
44
|
const ariaLabel = `Go to ${direction === "prev" ? "previous" : "next"} month: ${targetLabel}`;
|
|
43
45
|
return /* @__PURE__ */ jsx(
|
|
44
46
|
"button",
|
|
@@ -59,7 +61,7 @@ function buildMonthCaption(locale, totalMonths, onOpenMonthGrid) {
|
|
|
59
61
|
calendarMonth,
|
|
60
62
|
displayIndex
|
|
61
63
|
}) {
|
|
62
|
-
const label = format(calendarMonth.date,
|
|
64
|
+
const label = format(calendarMonth.date, STANDALONE_MONTH_YEAR, locale ? { locale } : void 0);
|
|
63
65
|
const index = typeof displayIndex === "number" ? displayIndex : 0;
|
|
64
66
|
const showPrev = index === 0;
|
|
65
67
|
const showNext = index === totalMonths - 1;
|
|
@@ -103,7 +105,7 @@ function MonthGrid({
|
|
|
103
105
|
const monthLabels = React.useMemo(
|
|
104
106
|
() => Array.from(
|
|
105
107
|
{ length: 12 },
|
|
106
|
-
(_, monthIndex) => format(new Date(year, monthIndex, 1),
|
|
108
|
+
(_, monthIndex) => format(new Date(year, monthIndex, 1), STANDALONE_MONTH_SHORT, locale ? { locale } : void 0)
|
|
107
109
|
),
|
|
108
110
|
[year, locale]
|
|
109
111
|
);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/primitives/calendar.tsx"],
|
|
4
|
-
"sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport { DayPicker, useDayPicker } from 'react-day-picker'\nimport type { DayPickerProps, CalendarMonth } from 'react-day-picker'\nimport { ChevronLeft, ChevronRight } from 'lucide-react'\nimport { format } from 'date-fns/format'\nimport type { Locale } from 'date-fns/locale'\nimport { cn } from '@open-mercato/shared/lib/utils'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { CompactButton } from './compact-button'\n\nexport type CalendarProps = DayPickerProps & { daySize?: 36 | 40 }\n\nexport type CalendarMonthSelectorProps = React.HTMLAttributes<HTMLDivElement> & {\n month: Date\n locale?: Locale\n onPreviousMonth?: () => void\n onNextMonth?: () => void\n disabledPrevious?: boolean\n disabledNext?: boolean\n}\n\nexport function CalendarMonthSelector({\n month, locale, onPreviousMonth, onNextMonth, disabledPrevious, disabledNext, className, ...props\n}: CalendarMonthSelectorProps) {\n const t = useT()\n return (\n <div data-slot=\"calendar-month-selector\" className={cn('flex h-9 items-center gap-1.5 rounded-md bg-muted p-1.5', className)} {...props}>\n {onPreviousMonth\n ? <CompactButton appearance=\"white\" size={24} className=\"shadow-xs\" onClick={onPreviousMonth} disabled={disabledPrevious} aria-label={t('ui.calendar.previousMonth', 'Previous month')}><ChevronLeft className=\"size-5\" aria-hidden=\"true\" /></CompactButton>\n : <span className=\"size-6 shrink-0\" aria-hidden=\"true\" />}\n <span className=\"min-w-0 flex-1 text-center text-sm font-medium text-muted-foreground\" aria-live=\"polite\">{format(month, 'MMMM yyyy', locale ? { locale } : undefined)}</span>\n {onNextMonth\n ? <CompactButton appearance=\"white\" size={24} className=\"shadow-xs\" onClick={onNextMonth} disabled={disabledNext} aria-label={t('ui.calendar.nextMonth', 'Next month')}><ChevronRight className=\"size-5\" aria-hidden=\"true\" /></CompactButton>\n : <span className=\"size-6 shrink-0\" aria-hidden=\"true\" />}\n </div>\n )\n}\n\nconst navButtonClassName = cn(\n 'h-9 w-9 inline-flex items-center justify-center rounded-md shrink-0',\n 'border border-border bg-background text-muted-foreground transition-colors',\n 'hover:bg-accent hover:text-accent-foreground hover:border-input',\n 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2',\n 'disabled:opacity-30 disabled:pointer-events-none disabled:hover:bg-background',\n)\n\nfunction MonthNavButton({\n direction,\n locale,\n}: {\n direction: 'prev' | 'next'\n locale?: Locale\n}) {\n const dayPicker = useDayPicker() as unknown as {\n previousMonth?: Date\n nextMonth?: Date\n goToMonth?: (month: Date) => void\n }\n const target = direction === 'prev' ? dayPicker.previousMonth : dayPicker.nextMonth\n const Icon = direction === 'prev' ? ChevronLeft : ChevronRight\n const targetLabel = format(target ?? new Date(), 'MMMM yyyy', locale ? { locale } : undefined)\n const ariaLabel = `Go to ${direction === 'prev' ? 'previous' : 'next'} month: ${targetLabel}`\n return (\n <button\n type=\"button\"\n disabled={!target}\n aria-label={ariaLabel}\n onClick={() => {\n if (target && dayPicker.goToMonth) dayPicker.goToMonth(target)\n }}\n className={navButtonClassName}\n >\n <Icon className=\"h-4 w-4\" aria-hidden=\"true\" />\n </button>\n )\n}\n\nfunction buildMonthCaption(\n locale: Locale | undefined,\n totalMonths: number,\n onOpenMonthGrid: (() => void) | null,\n) {\n return function MonthCaption({\n calendarMonth,\n displayIndex,\n }: {\n calendarMonth: CalendarMonth\n displayIndex?: number\n }) {\n const label = format(calendarMonth.date, 'MMMM yyyy', locale ? { locale } : undefined)\n const index = typeof displayIndex === 'number' ? displayIndex : 0\n // For multi-month layouts (e.g. range pickers) only the leftmost month\n // exposes the previous-month chevron and only the rightmost exposes the\n // next-month chevron. Navigation is always global across all visible\n // months, so showing both arrows on every month is confusing.\n const showPrev = index === 0\n const showNext = index === totalMonths - 1\n // The month grid (fast navigation) is only offered on single-month\n // calendars; on the leftmost caption it owns the click target.\n const labelInteractive = onOpenMonthGrid !== null && index === 0\n return (\n <div className=\"flex items-center justify-between gap-2 mb-3\">\n {showPrev ? (\n <MonthNavButton direction=\"prev\" locale={locale} />\n ) : (\n <div className=\"h-9 w-9 shrink-0\" aria-hidden=\"true\" />\n )}\n {labelInteractive ? (\n <button\n type=\"button\"\n onClick={onOpenMonthGrid ?? undefined}\n aria-label={`${label} \u2013 open month and year navigation`}\n className={cn(\n 'flex-1 flex items-center justify-center h-9 rounded-md bg-muted px-3 text-sm font-medium',\n 'transition-colors hover:bg-accent hover:text-accent-foreground',\n 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2',\n )}\n >\n {label}\n </button>\n ) : (\n <div\n className=\"flex-1 flex items-center justify-center h-9 rounded-md bg-muted px-3 text-sm font-medium\"\n aria-live=\"polite\"\n >\n {label}\n </div>\n )}\n {showNext ? (\n <MonthNavButton direction=\"next\" locale={locale} />\n ) : (\n <div className=\"h-9 w-9 shrink-0\" aria-hidden=\"true\" />\n )}\n </div>\n )\n }\n}\n\nfunction MonthGrid({\n initialYear,\n selectedMonth,\n locale,\n onSelectMonth,\n onClose,\n}: {\n initialYear: number\n selectedMonth: Date\n locale?: Locale\n onSelectMonth: (month: Date) => void\n onClose: () => void\n}) {\n const [year, setYear] = React.useState(initialYear)\n const today = new Date()\n const monthLabels = React.useMemo(\n () =>\n Array.from({ length: 12 }, (_, monthIndex) =>\n format(new Date(year, monthIndex, 1), 'MMM', locale ? { locale } : undefined),\n ),\n [year, locale],\n )\n const yearLabel = format(new Date(year, 0, 1), 'yyyy', locale ? { locale } : undefined)\n return (\n <div\n className=\"absolute inset-0 z-10 flex flex-col rounded-md bg-popover p-3\"\n role=\"dialog\"\n aria-label=\"Select month and year\"\n >\n <div className=\"flex items-center justify-between gap-2 mb-3\">\n <button\n type=\"button\"\n aria-label={`Go to previous year: ${year - 1}`}\n onClick={() => setYear((current) => current - 1)}\n className={navButtonClassName}\n >\n <ChevronLeft className=\"h-4 w-4\" aria-hidden=\"true\" />\n </button>\n <button\n type=\"button\"\n onClick={onClose}\n aria-label={`${yearLabel} \u2013 back to day selection`}\n className={cn(\n 'flex-1 flex items-center justify-center h-9 rounded-md bg-muted px-3 text-sm font-medium',\n 'transition-colors hover:bg-accent hover:text-accent-foreground',\n 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2',\n )}\n >\n {yearLabel}\n </button>\n <button\n type=\"button\"\n aria-label={`Go to next year: ${year + 1}`}\n onClick={() => setYear((current) => current + 1)}\n className={navButtonClassName}\n >\n <ChevronRight className=\"h-4 w-4\" aria-hidden=\"true\" />\n </button>\n </div>\n <div className=\"grid grid-cols-3 gap-2\">\n {monthLabels.map((monthLabel, monthIndex) => {\n const isSelected =\n selectedMonth.getFullYear() === year && selectedMonth.getMonth() === monthIndex\n const isCurrentMonth =\n today.getFullYear() === year && today.getMonth() === monthIndex\n return (\n <button\n key={monthIndex}\n type=\"button\"\n aria-pressed={isSelected}\n onClick={() => onSelectMonth(new Date(year, monthIndex, 1))}\n className={cn(\n 'h-9 rounded-md text-sm font-normal transition-colors',\n 'inline-flex items-center justify-center',\n 'hover:bg-accent hover:text-accent-foreground',\n 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2',\n isCurrentMonth && !isSelected && 'font-semibold text-primary',\n isSelected && '!bg-primary !text-primary-foreground hover:!bg-primary',\n )}\n >\n {monthLabel}\n </button>\n )\n })}\n </div>\n </div>\n )\n}\n\nexport function Calendar({\n className,\n classNames,\n showOutsideDays = true,\n daySize = 36,\n fixedWeeks = true,\n locale,\n components,\n numberOfMonths = 1,\n pagedNavigation = true,\n month,\n defaultMonth,\n onMonthChange,\n ...props\n}: CalendarProps) {\n // The month/year grid (fast navigation) is only meaningful for single-month\n // calendars; multi-month layouts (range pickers) keep the static caption.\n const monthGridEnabled = numberOfMonths === 1\n const [displayMonth, setDisplayMonth] = React.useState<Date>(\n () => month ?? defaultMonth ?? new Date(),\n )\n const [showMonthGrid, setShowMonthGrid] = React.useState(false)\n\n // Honor a controlled `month` prop when consumers drive navigation externally.\n React.useEffect(() => {\n if (month) setDisplayMonth(month)\n }, [month])\n\n const handleMonthChange = React.useCallback(\n (next: Date) => {\n setDisplayMonth(next)\n onMonthChange?.(next)\n },\n [onMonthChange],\n )\n\n const handleSelectMonth = React.useCallback(\n (next: Date) => {\n handleMonthChange(next)\n setShowMonthGrid(false)\n },\n [handleMonthChange],\n )\n\n const monthCaption = React.useMemo(\n () =>\n buildMonthCaption(\n locale as Locale | undefined,\n numberOfMonths,\n monthGridEnabled ? () => setShowMonthGrid(true) : null,\n ),\n [locale, numberOfMonths, monthGridEnabled],\n )\n\n return (\n <div className={monthGridEnabled ? 'relative' : 'contents'}>\n <div\n className={monthGridEnabled && showMonthGrid ? 'pointer-events-none' : 'contents'}\n aria-hidden={monthGridEnabled && showMonthGrid ? true : undefined}\n >\n <DayPicker\n showOutsideDays={showOutsideDays}\n fixedWeeks={fixedWeeks}\n pagedNavigation={pagedNavigation}\n locale={locale}\n numberOfMonths={numberOfMonths}\n month={displayMonth}\n onMonthChange={handleMonthChange}\n className={cn('p-3', className)}\n classNames={{\n months: 'flex flex-col sm:flex-row gap-4',\n month: 'space-y-2',\n month_caption: '',\n caption_label: 'sr-only',\n nav: 'sr-only',\n month_grid: 'w-full border-collapse',\n weekdays: 'flex',\n weekday: cn('text-muted-foreground rounded-md font-normal text-xs', daySize === 40 ? 'w-10' : 'w-9'),\n weeks: 'w-full border-collapse',\n week: 'flex w-full mt-1',\n day: cn('text-center text-sm p-0 relative focus-within:relative focus-within:z-20', daySize === 40 ? 'size-10' : 'size-9'),\n day_button: cn(\n 'p-0 font-normal aria-selected:opacity-100',\n daySize === 40 ? 'size-10' : 'size-9',\n 'inline-flex items-center justify-center rounded-md text-sm',\n 'transition-colors focus:outline-none focus-visible:outline-none disabled:pointer-events-none',\n // Focus indicator is a soft accent fill instead of a ring overlay \u2014 keyboard\n // users get a visible cue, but mouse-click focus does not leave a stuck ring\n // on top of the selected cell.\n 'hover:bg-accent hover:text-accent-foreground',\n 'focus-visible:bg-accent focus-visible:text-accent-foreground',\n ),\n // React-day-picker v9 applies `classNames.selected` / `range_*` to the day\n // CELL (`<td>`) wrapper, not to the inner `<button>`. To keep the parent\n // fill visible through interaction, we (a) paint the cell with the desired\n // bg/text, and (b) force the inner button to render transparent \u2014 so the\n // button's own hover/focus-visible bg overrides cannot cover the cell fill.\n selected: cn(\n '!bg-primary !text-primary-foreground rounded-md',\n '[&_button]:!bg-transparent [&_button]:!text-primary-foreground',\n '[&_button:hover]:!bg-transparent [&_button:hover]:!text-primary-foreground',\n '[&_button:focus-visible]:!bg-transparent [&_button:focus-visible]:!text-primary-foreground',\n ),\n range_start: cn(\n '!bg-primary !text-primary-foreground rounded-l-md !rounded-r-none',\n '[&_button]:!bg-transparent [&_button]:!text-primary-foreground',\n '[&_button:hover]:!bg-transparent [&_button:hover]:!text-primary-foreground',\n '[&_button:focus-visible]:!bg-transparent [&_button:focus-visible]:!text-primary-foreground',\n ),\n range_end: cn(\n '!bg-primary !text-primary-foreground rounded-r-md !rounded-l-none',\n '[&_button]:!bg-transparent [&_button]:!text-primary-foreground',\n '[&_button:hover]:!bg-transparent [&_button:hover]:!text-primary-foreground',\n '[&_button:focus-visible]:!bg-transparent [&_button:focus-visible]:!text-primary-foreground',\n ),\n range_middle: cn(\n '!bg-accent !text-accent-foreground !rounded-none',\n '[&_button]:!bg-transparent [&_button]:!text-accent-foreground',\n '[&_button:hover]:!bg-transparent [&_button:hover]:!text-accent-foreground',\n '[&_button:focus-visible]:!bg-transparent [&_button:focus-visible]:!text-accent-foreground',\n ),\n today: 'font-semibold text-primary rounded-md',\n outside:\n 'day-outside text-muted-foreground opacity-40 aria-selected:bg-accent/50 aria-selected:text-muted-foreground aria-selected:opacity-30',\n disabled: 'text-muted-foreground opacity-50',\n hidden: 'invisible',\n ...classNames,\n }}\n components={{\n MonthCaption: monthCaption,\n ...components,\n }}\n {...props}\n />\n </div>\n {monthGridEnabled && showMonthGrid ? (\n <MonthGrid\n initialYear={displayMonth.getFullYear()}\n selectedMonth={displayMonth}\n locale={locale as Locale | undefined}\n onSelectMonth={handleSelectMonth}\n onClose={() => setShowMonthGrid(false)}\n />\n ) : null}\n </div>\n )\n}\n"],
|
|
5
|
-
"mappings": ";AA4BI,SAE4L,KAF5L;AA1BJ,YAAY,WAAW;AACvB,SAAS,WAAW,oBAAoB;AAExC,SAAS,aAAa,oBAAoB;AAC1C,SAAS,cAAc;AAEvB,SAAS,UAAU;AACnB,SAAS,YAAY;AACrB,SAAS,qBAAqB;AAavB,SAAS,sBAAsB;AAAA,EACpC;AAAA,EAAO;AAAA,EAAQ;AAAA,EAAiB;AAAA,EAAa;AAAA,EAAkB;AAAA,EAAc;AAAA,EAAW,GAAG;AAC7F,GAA+B;AAC7B,QAAM,IAAI,KAAK;AACf,SACE,qBAAC,SAAI,aAAU,2BAA0B,WAAW,GAAG,2DAA2D,SAAS,GAAI,GAAG,OAC/H;AAAA,sBACG,oBAAC,iBAAc,YAAW,SAAQ,MAAM,IAAI,WAAU,aAAY,SAAS,iBAAiB,UAAU,kBAAkB,cAAY,EAAE,6BAA6B,gBAAgB,GAAG,8BAAC,eAAY,WAAU,UAAS,eAAY,QAAO,GAAE,IAC3O,oBAAC,UAAK,WAAU,mBAAkB,eAAY,QAAO;AAAA,IACzD,oBAAC,UAAK,WAAU,wEAAuE,aAAU,UAAU,iBAAO,OAAO,aAAa,SAAS,EAAE,OAAO,IAAI,MAAS,GAAE;AAAA,IACtK,cACG,oBAAC,iBAAc,YAAW,SAAQ,MAAM,IAAI,WAAU,aAAY,SAAS,aAAa,UAAU,cAAc,cAAY,EAAE,yBAAyB,YAAY,GAAG,8BAAC,gBAAa,WAAU,UAAS,eAAY,QAAO,GAAE,IAC5N,oBAAC,UAAK,WAAU,mBAAkB,eAAY,QAAO;AAAA,KAC3D;AAEJ;
|
|
4
|
+
"sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport { DayPicker, useDayPicker } from 'react-day-picker'\nimport type { DayPickerProps, CalendarMonth } from 'react-day-picker'\nimport { ChevronLeft, ChevronRight } from 'lucide-react'\nimport { format } from 'date-fns/format'\nimport type { Locale } from 'date-fns/locale'\nimport { cn } from '@open-mercato/shared/lib/utils'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { CompactButton } from './compact-button'\n\nexport type CalendarProps = DayPickerProps & { daySize?: 36 | 40 }\n\nexport type CalendarMonthSelectorProps = React.HTMLAttributes<HTMLDivElement> & {\n month: Date\n locale?: Locale\n onPreviousMonth?: () => void\n onNextMonth?: () => void\n disabledPrevious?: boolean\n disabledNext?: boolean\n}\n\nexport function CalendarMonthSelector({\n month, locale, onPreviousMonth, onNextMonth, disabledPrevious, disabledNext, className, ...props\n}: CalendarMonthSelectorProps) {\n const t = useT()\n return (\n <div data-slot=\"calendar-month-selector\" className={cn('flex h-9 items-center gap-1.5 rounded-md bg-muted p-1.5', className)} {...props}>\n {onPreviousMonth\n ? <CompactButton appearance=\"white\" size={24} className=\"shadow-xs\" onClick={onPreviousMonth} disabled={disabledPrevious} aria-label={t('ui.calendar.previousMonth', 'Previous month')}><ChevronLeft className=\"size-5\" aria-hidden=\"true\" /></CompactButton>\n : <span className=\"size-6 shrink-0\" aria-hidden=\"true\" />}\n <span className=\"min-w-0 flex-1 text-center text-sm font-medium text-muted-foreground\" aria-live=\"polite\">{format(month, 'MMMM yyyy', locale ? { locale } : undefined)}</span>\n {onNextMonth\n ? <CompactButton appearance=\"white\" size={24} className=\"shadow-xs\" onClick={onNextMonth} disabled={disabledNext} aria-label={t('ui.calendar.nextMonth', 'Next month')}><ChevronRight className=\"size-5\" aria-hidden=\"true\" /></CompactButton>\n : <span className=\"size-6 shrink-0\" aria-hidden=\"true\" />}\n </div>\n )\n}\n\n// `LLLL`/`LLL`, not `MMMM`/`MMM`: these labels name a month on its own, and languages that\n// inflect month names \u2014 Polish among the five this repo ships \u2014 spell that differently from a\n// month inside a full date. `MMMM` is the inflected (genitive) form, so a Polish header read\n// \"stycznia\" (\"of January\") where it should read \"stycze\u0144\". The two tokens are identical in\n// English, which is why the bug was invisible until a non-English tenant opened a picker.\nconst STANDALONE_MONTH_YEAR = 'LLLL yyyy'\nconst STANDALONE_MONTH_SHORT = 'LLL'\n\nconst navButtonClassName = cn(\n 'h-9 w-9 inline-flex items-center justify-center rounded-md shrink-0',\n 'border border-border bg-background text-muted-foreground transition-colors',\n 'hover:bg-accent hover:text-accent-foreground hover:border-input',\n 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2',\n 'disabled:opacity-30 disabled:pointer-events-none disabled:hover:bg-background',\n)\n\nfunction MonthNavButton({\n direction,\n locale,\n}: {\n direction: 'prev' | 'next'\n locale?: Locale\n}) {\n const dayPicker = useDayPicker() as unknown as {\n previousMonth?: Date\n nextMonth?: Date\n goToMonth?: (month: Date) => void\n }\n const target = direction === 'prev' ? dayPicker.previousMonth : dayPicker.nextMonth\n const Icon = direction === 'prev' ? ChevronLeft : ChevronRight\n const targetLabel = format(target ?? new Date(), STANDALONE_MONTH_YEAR, locale ? { locale } : undefined)\n const ariaLabel = `Go to ${direction === 'prev' ? 'previous' : 'next'} month: ${targetLabel}`\n return (\n <button\n type=\"button\"\n disabled={!target}\n aria-label={ariaLabel}\n onClick={() => {\n if (target && dayPicker.goToMonth) dayPicker.goToMonth(target)\n }}\n className={navButtonClassName}\n >\n <Icon className=\"h-4 w-4\" aria-hidden=\"true\" />\n </button>\n )\n}\n\nfunction buildMonthCaption(\n locale: Locale | undefined,\n totalMonths: number,\n onOpenMonthGrid: (() => void) | null,\n) {\n return function MonthCaption({\n calendarMonth,\n displayIndex,\n }: {\n calendarMonth: CalendarMonth\n displayIndex?: number\n }) {\n const label = format(calendarMonth.date, STANDALONE_MONTH_YEAR, locale ? { locale } : undefined)\n const index = typeof displayIndex === 'number' ? displayIndex : 0\n // For multi-month layouts (e.g. range pickers) only the leftmost month\n // exposes the previous-month chevron and only the rightmost exposes the\n // next-month chevron. Navigation is always global across all visible\n // months, so showing both arrows on every month is confusing.\n const showPrev = index === 0\n const showNext = index === totalMonths - 1\n // The month grid (fast navigation) is only offered on single-month\n // calendars; on the leftmost caption it owns the click target.\n const labelInteractive = onOpenMonthGrid !== null && index === 0\n return (\n <div className=\"flex items-center justify-between gap-2 mb-3\">\n {showPrev ? (\n <MonthNavButton direction=\"prev\" locale={locale} />\n ) : (\n <div className=\"h-9 w-9 shrink-0\" aria-hidden=\"true\" />\n )}\n {labelInteractive ? (\n <button\n type=\"button\"\n onClick={onOpenMonthGrid ?? undefined}\n aria-label={`${label} \u2013 open month and year navigation`}\n className={cn(\n 'flex-1 flex items-center justify-center h-9 rounded-md bg-muted px-3 text-sm font-medium',\n 'transition-colors hover:bg-accent hover:text-accent-foreground',\n 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2',\n )}\n >\n {label}\n </button>\n ) : (\n <div\n className=\"flex-1 flex items-center justify-center h-9 rounded-md bg-muted px-3 text-sm font-medium\"\n aria-live=\"polite\"\n >\n {label}\n </div>\n )}\n {showNext ? (\n <MonthNavButton direction=\"next\" locale={locale} />\n ) : (\n <div className=\"h-9 w-9 shrink-0\" aria-hidden=\"true\" />\n )}\n </div>\n )\n }\n}\n\nfunction MonthGrid({\n initialYear,\n selectedMonth,\n locale,\n onSelectMonth,\n onClose,\n}: {\n initialYear: number\n selectedMonth: Date\n locale?: Locale\n onSelectMonth: (month: Date) => void\n onClose: () => void\n}) {\n const [year, setYear] = React.useState(initialYear)\n const today = new Date()\n const monthLabels = React.useMemo(\n () =>\n Array.from({ length: 12 }, (_, monthIndex) =>\n format(new Date(year, monthIndex, 1), STANDALONE_MONTH_SHORT, locale ? { locale } : undefined),\n ),\n [year, locale],\n )\n const yearLabel = format(new Date(year, 0, 1), 'yyyy', locale ? { locale } : undefined)\n return (\n <div\n className=\"absolute inset-0 z-10 flex flex-col rounded-md bg-popover p-3\"\n role=\"dialog\"\n aria-label=\"Select month and year\"\n >\n <div className=\"flex items-center justify-between gap-2 mb-3\">\n <button\n type=\"button\"\n aria-label={`Go to previous year: ${year - 1}`}\n onClick={() => setYear((current) => current - 1)}\n className={navButtonClassName}\n >\n <ChevronLeft className=\"h-4 w-4\" aria-hidden=\"true\" />\n </button>\n <button\n type=\"button\"\n onClick={onClose}\n aria-label={`${yearLabel} \u2013 back to day selection`}\n className={cn(\n 'flex-1 flex items-center justify-center h-9 rounded-md bg-muted px-3 text-sm font-medium',\n 'transition-colors hover:bg-accent hover:text-accent-foreground',\n 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2',\n )}\n >\n {yearLabel}\n </button>\n <button\n type=\"button\"\n aria-label={`Go to next year: ${year + 1}`}\n onClick={() => setYear((current) => current + 1)}\n className={navButtonClassName}\n >\n <ChevronRight className=\"h-4 w-4\" aria-hidden=\"true\" />\n </button>\n </div>\n <div className=\"grid grid-cols-3 gap-2\">\n {monthLabels.map((monthLabel, monthIndex) => {\n const isSelected =\n selectedMonth.getFullYear() === year && selectedMonth.getMonth() === monthIndex\n const isCurrentMonth =\n today.getFullYear() === year && today.getMonth() === monthIndex\n return (\n <button\n key={monthIndex}\n type=\"button\"\n aria-pressed={isSelected}\n onClick={() => onSelectMonth(new Date(year, monthIndex, 1))}\n className={cn(\n 'h-9 rounded-md text-sm font-normal transition-colors',\n 'inline-flex items-center justify-center',\n 'hover:bg-accent hover:text-accent-foreground',\n 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2',\n isCurrentMonth && !isSelected && 'font-semibold text-primary',\n isSelected && '!bg-primary !text-primary-foreground hover:!bg-primary',\n )}\n >\n {monthLabel}\n </button>\n )\n })}\n </div>\n </div>\n )\n}\n\nexport function Calendar({\n className,\n classNames,\n showOutsideDays = true,\n daySize = 36,\n fixedWeeks = true,\n locale,\n components,\n numberOfMonths = 1,\n pagedNavigation = true,\n month,\n defaultMonth,\n onMonthChange,\n ...props\n}: CalendarProps) {\n // The month/year grid (fast navigation) is only meaningful for single-month\n // calendars; multi-month layouts (range pickers) keep the static caption.\n const monthGridEnabled = numberOfMonths === 1\n const [displayMonth, setDisplayMonth] = React.useState<Date>(\n () => month ?? defaultMonth ?? new Date(),\n )\n const [showMonthGrid, setShowMonthGrid] = React.useState(false)\n\n // Honor a controlled `month` prop when consumers drive navigation externally.\n React.useEffect(() => {\n if (month) setDisplayMonth(month)\n }, [month])\n\n const handleMonthChange = React.useCallback(\n (next: Date) => {\n setDisplayMonth(next)\n onMonthChange?.(next)\n },\n [onMonthChange],\n )\n\n const handleSelectMonth = React.useCallback(\n (next: Date) => {\n handleMonthChange(next)\n setShowMonthGrid(false)\n },\n [handleMonthChange],\n )\n\n const monthCaption = React.useMemo(\n () =>\n buildMonthCaption(\n locale as Locale | undefined,\n numberOfMonths,\n monthGridEnabled ? () => setShowMonthGrid(true) : null,\n ),\n [locale, numberOfMonths, monthGridEnabled],\n )\n\n return (\n <div className={monthGridEnabled ? 'relative' : 'contents'}>\n <div\n className={monthGridEnabled && showMonthGrid ? 'pointer-events-none' : 'contents'}\n aria-hidden={monthGridEnabled && showMonthGrid ? true : undefined}\n >\n <DayPicker\n showOutsideDays={showOutsideDays}\n fixedWeeks={fixedWeeks}\n pagedNavigation={pagedNavigation}\n locale={locale}\n numberOfMonths={numberOfMonths}\n month={displayMonth}\n onMonthChange={handleMonthChange}\n className={cn('p-3', className)}\n classNames={{\n months: 'flex flex-col sm:flex-row gap-4',\n month: 'space-y-2',\n month_caption: '',\n caption_label: 'sr-only',\n nav: 'sr-only',\n month_grid: 'w-full border-collapse',\n weekdays: 'flex',\n weekday: cn('text-muted-foreground rounded-md font-normal text-xs', daySize === 40 ? 'w-10' : 'w-9'),\n weeks: 'w-full border-collapse',\n week: 'flex w-full mt-1',\n day: cn('text-center text-sm p-0 relative focus-within:relative focus-within:z-20', daySize === 40 ? 'size-10' : 'size-9'),\n day_button: cn(\n 'p-0 font-normal aria-selected:opacity-100',\n daySize === 40 ? 'size-10' : 'size-9',\n 'inline-flex items-center justify-center rounded-md text-sm',\n 'transition-colors focus:outline-none focus-visible:outline-none disabled:pointer-events-none',\n // Focus indicator is a soft accent fill instead of a ring overlay \u2014 keyboard\n // users get a visible cue, but mouse-click focus does not leave a stuck ring\n // on top of the selected cell.\n 'hover:bg-accent hover:text-accent-foreground',\n 'focus-visible:bg-accent focus-visible:text-accent-foreground',\n ),\n // React-day-picker v9 applies `classNames.selected` / `range_*` to the day\n // CELL (`<td>`) wrapper, not to the inner `<button>`. To keep the parent\n // fill visible through interaction, we (a) paint the cell with the desired\n // bg/text, and (b) force the inner button to render transparent \u2014 so the\n // button's own hover/focus-visible bg overrides cannot cover the cell fill.\n selected: cn(\n '!bg-primary !text-primary-foreground rounded-md',\n '[&_button]:!bg-transparent [&_button]:!text-primary-foreground',\n '[&_button:hover]:!bg-transparent [&_button:hover]:!text-primary-foreground',\n '[&_button:focus-visible]:!bg-transparent [&_button:focus-visible]:!text-primary-foreground',\n ),\n range_start: cn(\n '!bg-primary !text-primary-foreground rounded-l-md !rounded-r-none',\n '[&_button]:!bg-transparent [&_button]:!text-primary-foreground',\n '[&_button:hover]:!bg-transparent [&_button:hover]:!text-primary-foreground',\n '[&_button:focus-visible]:!bg-transparent [&_button:focus-visible]:!text-primary-foreground',\n ),\n range_end: cn(\n '!bg-primary !text-primary-foreground rounded-r-md !rounded-l-none',\n '[&_button]:!bg-transparent [&_button]:!text-primary-foreground',\n '[&_button:hover]:!bg-transparent [&_button:hover]:!text-primary-foreground',\n '[&_button:focus-visible]:!bg-transparent [&_button:focus-visible]:!text-primary-foreground',\n ),\n range_middle: cn(\n '!bg-accent !text-accent-foreground !rounded-none',\n '[&_button]:!bg-transparent [&_button]:!text-accent-foreground',\n '[&_button:hover]:!bg-transparent [&_button:hover]:!text-accent-foreground',\n '[&_button:focus-visible]:!bg-transparent [&_button:focus-visible]:!text-accent-foreground',\n ),\n today: 'font-semibold text-primary rounded-md',\n outside:\n 'day-outside text-muted-foreground opacity-40 aria-selected:bg-accent/50 aria-selected:text-muted-foreground aria-selected:opacity-30',\n disabled: 'text-muted-foreground opacity-50',\n hidden: 'invisible',\n ...classNames,\n }}\n components={{\n MonthCaption: monthCaption,\n ...components,\n }}\n {...props}\n />\n </div>\n {monthGridEnabled && showMonthGrid ? (\n <MonthGrid\n initialYear={displayMonth.getFullYear()}\n selectedMonth={displayMonth}\n locale={locale as Locale | undefined}\n onSelectMonth={handleSelectMonth}\n onClose={() => setShowMonthGrid(false)}\n />\n ) : null}\n </div>\n )\n}\n"],
|
|
5
|
+
"mappings": ";AA4BI,SAE4L,KAF5L;AA1BJ,YAAY,WAAW;AACvB,SAAS,WAAW,oBAAoB;AAExC,SAAS,aAAa,oBAAoB;AAC1C,SAAS,cAAc;AAEvB,SAAS,UAAU;AACnB,SAAS,YAAY;AACrB,SAAS,qBAAqB;AAavB,SAAS,sBAAsB;AAAA,EACpC;AAAA,EAAO;AAAA,EAAQ;AAAA,EAAiB;AAAA,EAAa;AAAA,EAAkB;AAAA,EAAc;AAAA,EAAW,GAAG;AAC7F,GAA+B;AAC7B,QAAM,IAAI,KAAK;AACf,SACE,qBAAC,SAAI,aAAU,2BAA0B,WAAW,GAAG,2DAA2D,SAAS,GAAI,GAAG,OAC/H;AAAA,sBACG,oBAAC,iBAAc,YAAW,SAAQ,MAAM,IAAI,WAAU,aAAY,SAAS,iBAAiB,UAAU,kBAAkB,cAAY,EAAE,6BAA6B,gBAAgB,GAAG,8BAAC,eAAY,WAAU,UAAS,eAAY,QAAO,GAAE,IAC3O,oBAAC,UAAK,WAAU,mBAAkB,eAAY,QAAO;AAAA,I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J;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { de } from "date-fns/locale/de";
|
|
3
|
+
import { enUS } from "date-fns/locale/en-US";
|
|
4
|
+
import { es } from "date-fns/locale/es";
|
|
5
|
+
import { ko } from "date-fns/locale/ko";
|
|
6
|
+
import { pl } from "date-fns/locale/pl";
|
|
7
|
+
import { useOptionalLocale } from "@open-mercato/shared/lib/i18n/context";
|
|
8
|
+
const DATE_FNS_LOCALES = {
|
|
9
|
+
de,
|
|
10
|
+
en: enUS,
|
|
11
|
+
es,
|
|
12
|
+
ko,
|
|
13
|
+
pl
|
|
14
|
+
};
|
|
15
|
+
function resolveDateFnsLocale(locale) {
|
|
16
|
+
const code = locale?.split("-")[0]?.toLowerCase();
|
|
17
|
+
return code ? DATE_FNS_LOCALES[code] : void 0;
|
|
18
|
+
}
|
|
19
|
+
function useDateFnsLocale() {
|
|
20
|
+
return resolveDateFnsLocale(useOptionalLocale());
|
|
21
|
+
}
|
|
22
|
+
const timeFormatCache = /* @__PURE__ */ new Map();
|
|
23
|
+
function deriveTimeDisplayFormat(locale) {
|
|
24
|
+
if (!locale) return "12h";
|
|
25
|
+
const cached = timeFormatCache.get(locale);
|
|
26
|
+
if (cached) return cached;
|
|
27
|
+
let resolved = "12h";
|
|
28
|
+
try {
|
|
29
|
+
if (new Intl.DateTimeFormat(locale, { hour: "numeric" }).resolvedOptions().hour12 === false) {
|
|
30
|
+
resolved = "24h";
|
|
31
|
+
}
|
|
32
|
+
} catch {
|
|
33
|
+
resolved = "12h";
|
|
34
|
+
}
|
|
35
|
+
timeFormatCache.set(locale, resolved);
|
|
36
|
+
return resolved;
|
|
37
|
+
}
|
|
38
|
+
function useTimeDisplayFormat() {
|
|
39
|
+
return deriveTimeDisplayFormat(useOptionalLocale());
|
|
40
|
+
}
|
|
41
|
+
export {
|
|
42
|
+
deriveTimeDisplayFormat,
|
|
43
|
+
resolveDateFnsLocale,
|
|
44
|
+
useDateFnsLocale,
|
|
45
|
+
useTimeDisplayFormat
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=date-locale.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/primitives/date-locale.ts"],
|
|
4
|
+
"sourcesContent": ["\"use client\"\n\nimport type { Locale as DateFnsLocale } from 'date-fns/locale'\nimport { de } from 'date-fns/locale/de'\nimport { enUS } from 'date-fns/locale/en-US'\nimport { es } from 'date-fns/locale/es'\nimport { ko } from 'date-fns/locale/ko'\nimport { pl } from 'date-fns/locale/pl'\nimport { useOptionalLocale } from '@open-mercato/shared/lib/i18n/context'\n\nexport type TimeDisplayFormat = '12h' | '24h'\n\n/**\n * The app locale is a bare language code (`'pl'`), but `react-day-picker` and every\n * date-fns formatter want a `Locale` object \u2014 the thing that knows month names and,\n * critically, `weekStartsOn`. Without one the picker falls back to the bundled `enUS`:\n * English month/weekday names and a Sunday-first week for every tenant.\n *\n * The five entries mirror `locales` in `@open-mercato/shared/lib/i18n/config`. They are\n * imported statically rather than loaded on demand because a picker renders its calendar\n * synchronously \u2014 an async locale would flash an English month header first.\n */\nconst DATE_FNS_LOCALES: Record<string, DateFnsLocale> = {\n de,\n en: enUS,\n es,\n ko,\n pl,\n}\n\n/**\n * The date-fns locale for an app locale code, or `undefined` when there is none to apply.\n *\n * `undefined` rather than `enUS` for an unknown code: the consumers pass this straight into\n * a `locale?: Locale` prop, and leaving it unset keeps their own documented default instead\n * of pinning English on a deployment that added a locale this map has not caught up with.\n */\nexport function resolveDateFnsLocale(locale?: string | null): DateFnsLocale | undefined {\n const code = locale?.split('-')[0]?.toLowerCase()\n return code ? DATE_FNS_LOCALES[code] : undefined\n}\n\n/** The date-fns locale for the active `I18nProvider` locale, or `undefined` outside a provider. */\nexport function useDateFnsLocale(): DateFnsLocale | undefined {\n return resolveDateFnsLocale(useOptionalLocale())\n}\n\n/**\n * Whether a locale writes the time of day on a 12- or 24-hour clock.\n *\n * Asked of `Intl` rather than a \"not English means 24h\" heuristic, because that heuristic is\n * wrong for two of the five locales this repo ships: Korean is a 12-hour locale (\uC624\uC804/\uC624\uD6C4), as\n * is English, while Polish, German and Spanish are not. `12h` is the fallback when `Intl` cannot\n * answer, matching the `TimePicker` primitive's own default.\n */\n// Constructing an `Intl.DateTimeFormat` costs ~40x using one, and this runs on every render of\n// every time picker \u2014 so the answer is kept per locale, exactly as `date-format.ts` caches its\n// formatters. The key space is the locales a deployment ships and the answer never changes.\nconst timeFormatCache = new Map<string, TimeDisplayFormat>()\n\nexport function deriveTimeDisplayFormat(locale?: string | null): TimeDisplayFormat {\n if (!locale) return '12h'\n const cached = timeFormatCache.get(locale)\n if (cached) return cached\n let resolved: TimeDisplayFormat = '12h'\n try {\n if (new Intl.DateTimeFormat(locale, { hour: 'numeric' }).resolvedOptions().hour12 === false) {\n resolved = '24h'\n }\n } catch {\n resolved = '12h'\n }\n timeFormatCache.set(locale, resolved)\n return resolved\n}\n\n/** The clock convention of the active `I18nProvider` locale; `12h` outside a provider. */\nexport function useTimeDisplayFormat(): TimeDisplayFormat {\n return deriveTimeDisplayFormat(useOptionalLocale())\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,UAAU;AACnB,SAAS,YAAY;AACrB,SAAS,UAAU;AACnB,SAAS,UAAU;AACnB,SAAS,UAAU;AACnB,SAAS,yBAAyB;AAclC,MAAM,mBAAkD;AAAA,EACtD;AAAA,EACA,IAAI;AAAA,EACJ;AAAA,EACA;AAAA,EACA;AACF;AASO,SAAS,qBAAqB,QAAmD;AACtF,QAAM,OAAO,QAAQ,MAAM,GAAG,EAAE,CAAC,GAAG,YAAY;AAChD,SAAO,OAAO,iBAAiB,IAAI,IAAI;AACzC;AAGO,SAAS,mBAA8C;AAC5D,SAAO,qBAAqB,kBAAkB,CAAC;AACjD;AAaA,MAAM,kBAAkB,oBAAI,IAA+B;AAEpD,SAAS,wBAAwB,QAA2C;AACjF,MAAI,CAAC,OAAQ,QAAO;AACpB,QAAM,SAAS,gBAAgB,IAAI,MAAM;AACzC,MAAI,OAAQ,QAAO;AACnB,MAAI,WAA8B;AAClC,MAAI;AACF,QAAI,IAAI,KAAK,eAAe,QAAQ,EAAE,MAAM,UAAU,CAAC,EAAE,gBAAgB,EAAE,WAAW,OAAO;AAC3F,iBAAW;AAAA,IACb;AAAA,EACF,QAAQ;AACN,eAAW;AAAA,EACb;AACA,kBAAgB,IAAI,QAAQ,QAAQ;AACpC,SAAO;AACT;AAGO,SAAS,uBAA0C;AACxD,SAAO,wBAAwB,kBAAkB,CAAC;AACpD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -10,6 +10,7 @@ import { Button } from "./button.js";
|
|
|
10
10
|
import { LinkButton } from "./link-button.js";
|
|
11
11
|
import { TimeInput } from "../backend/inputs/TimeInput.js";
|
|
12
12
|
import { formatWithPublicDateFormat, resolvePublicDateFormat, resolvePublicDateTimeFormat } from "./date-format.js";
|
|
13
|
+
import { useDateFnsLocale } from "./date-locale.js";
|
|
13
14
|
function extractTime(date) {
|
|
14
15
|
return `${String(date.getHours()).padStart(2, "0")}:${String(date.getMinutes()).padStart(2, "0")}`;
|
|
15
16
|
}
|
|
@@ -44,7 +45,7 @@ function DatePicker({
|
|
|
44
45
|
align = "start",
|
|
45
46
|
minDate,
|
|
46
47
|
maxDate,
|
|
47
|
-
locale,
|
|
48
|
+
locale: localeProp,
|
|
48
49
|
displayFormat,
|
|
49
50
|
className,
|
|
50
51
|
popoverClassName,
|
|
@@ -56,6 +57,8 @@ function DatePicker({
|
|
|
56
57
|
}) {
|
|
57
58
|
const resolvedCloseOnSelect = closeOnSelect ?? footer === "today-clear";
|
|
58
59
|
const t = useT();
|
|
60
|
+
const appLocale = useDateFnsLocale();
|
|
61
|
+
const locale = localeProp ?? appLocale;
|
|
59
62
|
const [uncontrolledOpen, setUncontrolledOpen] = React.useState(false);
|
|
60
63
|
const open = controlledOpen ?? uncontrolledOpen;
|
|
61
64
|
const setOpen = React.useCallback((next) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/primitives/date-picker.tsx"],
|
|
4
|
-
"sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport type { Locale } from 'date-fns/locale'\nimport { CalendarIcon } from 'lucide-react'\nimport { cn } from '@open-mercato/shared/lib/utils'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { Popover, PopoverContent, PopoverTrigger } from './popover'\nimport { Calendar } from './calendar'\nimport { Button } from './button'\nimport { LinkButton } from './link-button'\nimport { TimeInput } from '../backend/inputs/TimeInput'\nimport { formatWithPublicDateFormat, resolvePublicDateFormat, resolvePublicDateTimeFormat } from './date-format'\n\nexport type DatePickerFooter = 'apply-cancel' | 'today-clear' | 'none'\n\nexport type DatePickerProps = {\n value?: Date | null\n onChange: (value: Date | null) => void\n placeholder?: string\n size?: 'sm' | 'default'\n disabled?: boolean\n readOnly?: boolean\n /** Controlled open state of the popover. Omit for the default uncontrolled\n * behavior. Pair with `onOpenChange` to drive it externally (e.g. closing the\n * picker when a surrounding dialog scrolls). */\n open?: boolean\n onOpenChange?: (open: boolean) => void\n /**\n * Footer mode in the popover.\n * - `'apply-cancel'` (default, Figma-aligned): selecting a day stages a draft;\n * Apply commits and closes; Cancel reverts and closes.\n * - `'today-clear'`: legacy behavior \u2014 Today commits today, Clear sets null.\n * - `'none'`: no footer; selecting a day commits immediately and closes.\n */\n footer?: DatePickerFooter\n /**\n * Whether selecting a day commits the value and closes the popover.\n * - In `footer='apply-cancel'`: ignored (commit happens via Apply).\n * - In `footer='today-clear'`: default `true` for backward compatibility.\n * - In `footer='none'`: always `true` (popover always closes after selection).\n */\n closeOnSelect?: boolean\n /**\n * Whether to show the \"Today\" link in `footer='today-clear'` mode. Default `true`.\n * Only meaningful when `footer='today-clear'`.\n */\n showTodayButton?: boolean\n /**\n * Whether to show the \"Clear\" link in `footer='today-clear'` mode. Default `true`.\n * Only meaningful when `footer='today-clear'`.\n */\n showClearButton?: boolean\n withTime?: boolean\n minuteStep?: number\n align?: 'start' | 'center' | 'end'\n minDate?: Date\n maxDate?: Date\n locale?: Locale\n displayFormat?: string\n className?: string\n popoverClassName?: string\n id?: string\n name?: string\n required?: boolean\n 'aria-label'?: string\n 'aria-describedby'?: string\n}\n\nfunction extractTime(date: Date): string {\n return `${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}`\n}\n\nfunction applyTimeToDate(base: Date, time: string): Date {\n const [hourStr = '0', minuteStr = '0'] = time.split(':')\n const hour = parseInt(hourStr, 10)\n const minute = parseInt(minuteStr, 10)\n const next = new Date(base)\n next.setHours(isNaN(hour) ? 0 : hour, isNaN(minute) ? 0 : minute, 0, 0)\n return next\n}\n\nfunction startOfDay(date: Date): Date {\n const next = new Date(date)\n next.setHours(0, 0, 0, 0)\n return next\n}\n\nexport function DatePicker({\n value,\n onChange,\n placeholder,\n size = 'default',\n disabled = false,\n readOnly = false,\n open: controlledOpen,\n onOpenChange,\n footer = 'apply-cancel',\n closeOnSelect,\n showTodayButton = true,\n showClearButton = true,\n withTime = false,\n minuteStep = 1,\n align = 'start',\n minDate,\n maxDate,\n locale,\n displayFormat,\n className,\n popoverClassName,\n id,\n name,\n required,\n 'aria-label': ariaLabel,\n 'aria-describedby': ariaDescribedBy,\n}: DatePickerProps) {\n const resolvedCloseOnSelect = closeOnSelect ?? footer === 'today-clear'\n const t = useT()\n const [uncontrolledOpen, setUncontrolledOpen] = React.useState(false)\n const open = controlledOpen ?? uncontrolledOpen\n const setOpen = React.useCallback((next: boolean) => {\n if (controlledOpen === undefined) setUncontrolledOpen(next)\n onOpenChange?.(next)\n }, [controlledOpen, onOpenChange])\n const [draft, setDraft] = React.useState<Date | null>(value ?? null)\n\n const isInteractive = !disabled && !readOnly\n const useDraft = footer === 'apply-cancel'\n\n React.useEffect(() => {\n if (open) setDraft(value ?? null)\n }, [open, value])\n\n const resolvedFormat = withTime\n ? resolvePublicDateTimeFormat(locale, displayFormat)\n : resolvePublicDateFormat(locale, displayFormat)\n const placeholderText = placeholder ?? (\n withTime\n ? t('ui.dateTimePicker.placeholder', 'Pick date and time')\n : t('ui.datePicker.placeholder', 'Pick a date')\n )\n\n const formattedValue = React.useMemo(() => {\n if (!value) return null\n return formatWithPublicDateFormat(value, resolvedFormat, locale)\n }, [value, resolvedFormat, locale])\n\n const handleDaySelect = React.useCallback(\n (day: Date | undefined) => {\n if (!day || !isInteractive) return\n const reference = withTime ? (useDraft ? draft : value) : null\n const base = withTime\n ? applyTimeToDate(day, reference ? extractTime(reference) : '00:00')\n : startOfDay(day)\n if (useDraft) {\n setDraft(base)\n } else {\n onChange(base)\n if (footer === 'none' || resolvedCloseOnSelect) setOpen(false)\n }\n },\n [isInteractive, withTime, useDraft, draft, value, footer, resolvedCloseOnSelect, onChange, setOpen],\n )\n\n const handleTimeChange = React.useCallback(\n (time: string) => {\n const target = useDraft ? draft : value\n if (!target) return\n const next = applyTimeToDate(target, time)\n if (useDraft) setDraft(next)\n else onChange(next)\n },\n [useDraft, draft, value, onChange],\n )\n\n const handleApply = React.useCallback(() => {\n onChange(draft)\n setOpen(false)\n }, [draft, onChange, setOpen])\n\n const handleCancel = React.useCallback(() => {\n setDraft(value ?? null)\n setOpen(false)\n }, [value, setOpen])\n\n const handleToday = React.useCallback(() => {\n const today = withTime ? new Date() : startOfDay(new Date())\n onChange(today)\n setOpen(false)\n }, [withTime, onChange, setOpen])\n\n const handleClear = React.useCallback(() => {\n onChange(null)\n setOpen(false)\n }, [onChange, setOpen])\n\n const disabledMatcher = React.useMemo(() => {\n if (!minDate && !maxDate) return undefined\n const matchers: import('react-day-picker').Matcher[] = []\n if (minDate) matchers.push({ before: minDate })\n if (maxDate) matchers.push({ after: maxDate })\n return matchers\n }, [minDate, maxDate])\n\n const heightClass = size === 'sm' ? 'h-8 px-2.5 text-xs' : 'h-9 px-3 text-sm'\n const selectedDate = useDraft ? draft : value\n\n return (\n <Popover open={open} onOpenChange={isInteractive ? setOpen : undefined}>\n <PopoverTrigger asChild>\n <button\n type=\"button\"\n id={id}\n name={name}\n aria-label={ariaLabel}\n aria-describedby={ariaDescribedBy}\n aria-haspopup=\"dialog\"\n aria-required={required ? true : undefined}\n data-crud-focus-target=\"\"\n data-slot=\"date-picker-trigger\"\n disabled={disabled}\n className={cn(\n 'w-full inline-flex items-center gap-2 rounded-md border border-input bg-background shadow-xs transition-colors text-left',\n 'focus-visible:outline-none focus-visible:shadow-focus focus-visible:border-foreground',\n 'hover:bg-muted/40',\n 'disabled:bg-bg-disabled disabled:border-border-disabled disabled:shadow-none disabled:hover:bg-bg-disabled disabled:cursor-not-allowed',\n 'aria-invalid:border-destructive',\n heightClass,\n readOnly && 'cursor-default opacity-70',\n !formattedValue && 'text-muted-foreground',\n className,\n )}\n onClick={isInteractive ? undefined : (event) => event.preventDefault()}\n >\n <CalendarIcon className=\"h-4 w-4 shrink-0 text-muted-foreground\" aria-hidden=\"true\" />\n <span className=\"flex-1 truncate\">\n {formattedValue ?? placeholderText}\n </span>\n </button>\n </PopoverTrigger>\n <PopoverContent align={align} className={cn('w-auto p-0', popoverClassName)}>\n <Calendar\n mode=\"single\"\n selected={selectedDate ?? undefined}\n defaultMonth={selectedDate ?? undefined}\n onSelect={handleDaySelect}\n locale={locale}\n disabled={disabledMatcher}\n autoFocus\n />\n {withTime && (\n <div className=\"flex items-center gap-2 border-t px-3 py-2\">\n <span className=\"text-sm text-muted-foreground shrink-0\">\n {t('ui.datePicker.timeLabel', 'Time')}:\n </span>\n <TimeInput\n value={selectedDate ? extractTime(selectedDate) : undefined}\n onChange={handleTimeChange}\n minuteStep={minuteStep}\n disabled={!isInteractive || !selectedDate}\n />\n </div>\n )}\n {footer === 'apply-cancel' && (\n <div className=\"flex items-center justify-end gap-2 border-t px-3 py-2\">\n <Button type=\"button\" variant=\"outline\" size=\"sm\" onClick={handleCancel}>\n {t('ui.datePicker.cancelButton', 'Cancel')}\n </Button>\n <Button type=\"button\" size=\"sm\" onClick={handleApply}>\n {t('ui.datePicker.applyButton', 'Apply')}\n </Button>\n </div>\n )}\n {footer === 'today-clear' && (showTodayButton || showClearButton) && (\n <div className=\"flex items-center justify-between gap-2 border-t px-3 py-2\">\n {showTodayButton ? (\n <LinkButton type=\"button\" variant=\"primary\" onClick={handleToday}>\n {t('ui.datePicker.todayButton', 'Today')}\n </LinkButton>\n ) : null}\n {showClearButton ? (\n <LinkButton type=\"button\" variant=\"gray\" onClick={handleClear} className=\"ml-auto\">\n {t('ui.datePicker.clearButton', 'Clear')}\n </LinkButton>\n ) : null}\n </div>\n )}\n </PopoverContent>\n </Popover>\n )\n}\n"],
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport type { Locale } from 'date-fns/locale'\nimport { CalendarIcon } from 'lucide-react'\nimport { cn } from '@open-mercato/shared/lib/utils'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { Popover, PopoverContent, PopoverTrigger } from './popover'\nimport { Calendar } from './calendar'\nimport { Button } from './button'\nimport { LinkButton } from './link-button'\nimport { TimeInput } from '../backend/inputs/TimeInput'\nimport { formatWithPublicDateFormat, resolvePublicDateFormat, resolvePublicDateTimeFormat } from './date-format'\nimport { useDateFnsLocale } from './date-locale'\n\nexport type DatePickerFooter = 'apply-cancel' | 'today-clear' | 'none'\n\nexport type DatePickerProps = {\n value?: Date | null\n onChange: (value: Date | null) => void\n placeholder?: string\n size?: 'sm' | 'default'\n disabled?: boolean\n readOnly?: boolean\n /** Controlled open state of the popover. Omit for the default uncontrolled\n * behavior. Pair with `onOpenChange` to drive it externally (e.g. closing the\n * picker when a surrounding dialog scrolls). */\n open?: boolean\n onOpenChange?: (open: boolean) => void\n /**\n * Footer mode in the popover.\n * - `'apply-cancel'` (default, Figma-aligned): selecting a day stages a draft;\n * Apply commits and closes; Cancel reverts and closes.\n * - `'today-clear'`: legacy behavior \u2014 Today commits today, Clear sets null.\n * - `'none'`: no footer; selecting a day commits immediately and closes.\n */\n footer?: DatePickerFooter\n /**\n * Whether selecting a day commits the value and closes the popover.\n * - In `footer='apply-cancel'`: ignored (commit happens via Apply).\n * - In `footer='today-clear'`: default `true` for backward compatibility.\n * - In `footer='none'`: always `true` (popover always closes after selection).\n */\n closeOnSelect?: boolean\n /**\n * Whether to show the \"Today\" link in `footer='today-clear'` mode. Default `true`.\n * Only meaningful when `footer='today-clear'`.\n */\n showTodayButton?: boolean\n /**\n * Whether to show the \"Clear\" link in `footer='today-clear'` mode. Default `true`.\n * Only meaningful when `footer='today-clear'`.\n */\n showClearButton?: boolean\n withTime?: boolean\n minuteStep?: number\n align?: 'start' | 'center' | 'end'\n minDate?: Date\n maxDate?: Date\n /**\n * date-fns locale for month/weekday names and the first day of the week.\n * Defaults to the active `I18nProvider` locale (`undefined` outside a\n * provider, matching pre-existing behavior); pass one explicitly to pin it\n * regardless of the app locale.\n */\n locale?: Locale\n displayFormat?: string\n className?: string\n popoverClassName?: string\n id?: string\n name?: string\n required?: boolean\n 'aria-label'?: string\n 'aria-describedby'?: string\n}\n\nfunction extractTime(date: Date): string {\n return `${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}`\n}\n\nfunction applyTimeToDate(base: Date, time: string): Date {\n const [hourStr = '0', minuteStr = '0'] = time.split(':')\n const hour = parseInt(hourStr, 10)\n const minute = parseInt(minuteStr, 10)\n const next = new Date(base)\n next.setHours(isNaN(hour) ? 0 : hour, isNaN(minute) ? 0 : minute, 0, 0)\n return next\n}\n\nfunction startOfDay(date: Date): Date {\n const next = new Date(date)\n next.setHours(0, 0, 0, 0)\n return next\n}\n\nexport function DatePicker({\n value,\n onChange,\n placeholder,\n size = 'default',\n disabled = false,\n readOnly = false,\n open: controlledOpen,\n onOpenChange,\n footer = 'apply-cancel',\n closeOnSelect,\n showTodayButton = true,\n showClearButton = true,\n withTime = false,\n minuteStep = 1,\n align = 'start',\n minDate,\n maxDate,\n locale: localeProp,\n displayFormat,\n className,\n popoverClassName,\n id,\n name,\n required,\n 'aria-label': ariaLabel,\n 'aria-describedby': ariaDescribedBy,\n}: DatePickerProps) {\n const resolvedCloseOnSelect = closeOnSelect ?? footer === 'today-clear'\n const t = useT()\n // Callers may pin a locale explicitly (e.g. a field-level override); absent\n // that, fall back to the active app locale so every consumer of this\n // primitive \u2014 not just the ones that remember to thread a `locale` prop \u2014\n // renders a localized month/weekday grid instead of silently defaulting to\n // English. Outside an `I18nProvider` this resolves to `undefined`, same as\n // not passing a locale at all today.\n const appLocale = useDateFnsLocale()\n const locale = localeProp ?? appLocale\n const [uncontrolledOpen, setUncontrolledOpen] = React.useState(false)\n const open = controlledOpen ?? uncontrolledOpen\n const setOpen = React.useCallback((next: boolean) => {\n if (controlledOpen === undefined) setUncontrolledOpen(next)\n onOpenChange?.(next)\n }, [controlledOpen, onOpenChange])\n const [draft, setDraft] = React.useState<Date | null>(value ?? null)\n\n const isInteractive = !disabled && !readOnly\n const useDraft = footer === 'apply-cancel'\n\n React.useEffect(() => {\n if (open) setDraft(value ?? null)\n }, [open, value])\n\n const resolvedFormat = withTime\n ? resolvePublicDateTimeFormat(locale, displayFormat)\n : resolvePublicDateFormat(locale, displayFormat)\n const placeholderText = placeholder ?? (\n withTime\n ? t('ui.dateTimePicker.placeholder', 'Pick date and time')\n : t('ui.datePicker.placeholder', 'Pick a date')\n )\n\n const formattedValue = React.useMemo(() => {\n if (!value) return null\n return formatWithPublicDateFormat(value, resolvedFormat, locale)\n }, [value, resolvedFormat, locale])\n\n const handleDaySelect = React.useCallback(\n (day: Date | undefined) => {\n if (!day || !isInteractive) return\n const reference = withTime ? (useDraft ? draft : value) : null\n const base = withTime\n ? applyTimeToDate(day, reference ? extractTime(reference) : '00:00')\n : startOfDay(day)\n if (useDraft) {\n setDraft(base)\n } else {\n onChange(base)\n if (footer === 'none' || resolvedCloseOnSelect) setOpen(false)\n }\n },\n [isInteractive, withTime, useDraft, draft, value, footer, resolvedCloseOnSelect, onChange, setOpen],\n )\n\n const handleTimeChange = React.useCallback(\n (time: string) => {\n const target = useDraft ? draft : value\n if (!target) return\n const next = applyTimeToDate(target, time)\n if (useDraft) setDraft(next)\n else onChange(next)\n },\n [useDraft, draft, value, onChange],\n )\n\n const handleApply = React.useCallback(() => {\n onChange(draft)\n setOpen(false)\n }, [draft, onChange, setOpen])\n\n const handleCancel = React.useCallback(() => {\n setDraft(value ?? null)\n setOpen(false)\n }, [value, setOpen])\n\n const handleToday = React.useCallback(() => {\n const today = withTime ? new Date() : startOfDay(new Date())\n onChange(today)\n setOpen(false)\n }, [withTime, onChange, setOpen])\n\n const handleClear = React.useCallback(() => {\n onChange(null)\n setOpen(false)\n }, [onChange, setOpen])\n\n const disabledMatcher = React.useMemo(() => {\n if (!minDate && !maxDate) return undefined\n const matchers: import('react-day-picker').Matcher[] = []\n if (minDate) matchers.push({ before: minDate })\n if (maxDate) matchers.push({ after: maxDate })\n return matchers\n }, [minDate, maxDate])\n\n const heightClass = size === 'sm' ? 'h-8 px-2.5 text-xs' : 'h-9 px-3 text-sm'\n const selectedDate = useDraft ? draft : value\n\n return (\n <Popover open={open} onOpenChange={isInteractive ? setOpen : undefined}>\n <PopoverTrigger asChild>\n <button\n type=\"button\"\n id={id}\n name={name}\n aria-label={ariaLabel}\n aria-describedby={ariaDescribedBy}\n aria-haspopup=\"dialog\"\n aria-required={required ? true : undefined}\n data-crud-focus-target=\"\"\n data-slot=\"date-picker-trigger\"\n disabled={disabled}\n className={cn(\n 'w-full inline-flex items-center gap-2 rounded-md border border-input bg-background shadow-xs transition-colors text-left',\n 'focus-visible:outline-none focus-visible:shadow-focus focus-visible:border-foreground',\n 'hover:bg-muted/40',\n 'disabled:bg-bg-disabled disabled:border-border-disabled disabled:shadow-none disabled:hover:bg-bg-disabled disabled:cursor-not-allowed',\n 'aria-invalid:border-destructive',\n heightClass,\n readOnly && 'cursor-default opacity-70',\n !formattedValue && 'text-muted-foreground',\n className,\n )}\n onClick={isInteractive ? undefined : (event) => event.preventDefault()}\n >\n <CalendarIcon className=\"h-4 w-4 shrink-0 text-muted-foreground\" aria-hidden=\"true\" />\n <span className=\"flex-1 truncate\">\n {formattedValue ?? placeholderText}\n </span>\n </button>\n </PopoverTrigger>\n <PopoverContent align={align} className={cn('w-auto p-0', popoverClassName)}>\n <Calendar\n mode=\"single\"\n selected={selectedDate ?? undefined}\n defaultMonth={selectedDate ?? undefined}\n onSelect={handleDaySelect}\n locale={locale}\n disabled={disabledMatcher}\n autoFocus\n />\n {withTime && (\n <div className=\"flex items-center gap-2 border-t px-3 py-2\">\n <span className=\"text-sm text-muted-foreground shrink-0\">\n {t('ui.datePicker.timeLabel', 'Time')}:\n </span>\n <TimeInput\n value={selectedDate ? extractTime(selectedDate) : undefined}\n onChange={handleTimeChange}\n minuteStep={minuteStep}\n disabled={!isInteractive || !selectedDate}\n />\n </div>\n )}\n {footer === 'apply-cancel' && (\n <div className=\"flex items-center justify-end gap-2 border-t px-3 py-2\">\n <Button type=\"button\" variant=\"outline\" size=\"sm\" onClick={handleCancel}>\n {t('ui.datePicker.cancelButton', 'Cancel')}\n </Button>\n <Button type=\"button\" size=\"sm\" onClick={handleApply}>\n {t('ui.datePicker.applyButton', 'Apply')}\n </Button>\n </div>\n )}\n {footer === 'today-clear' && (showTodayButton || showClearButton) && (\n <div className=\"flex items-center justify-between gap-2 border-t px-3 py-2\">\n {showTodayButton ? (\n <LinkButton type=\"button\" variant=\"primary\" onClick={handleToday}>\n {t('ui.datePicker.todayButton', 'Today')}\n </LinkButton>\n ) : null}\n {showClearButton ? (\n <LinkButton type=\"button\" variant=\"gray\" onClick={handleClear} className=\"ml-auto\">\n {t('ui.datePicker.clearButton', 'Clear')}\n </LinkButton>\n ) : null}\n </div>\n )}\n </PopoverContent>\n </Popover>\n )\n}\n"],
|
|
5
|
+
"mappings": ";AAiOQ,SAwBE,KAxB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