@ginia/ui 0.1.24 → 0.1.25
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/AGENTS.md +4 -1
- package/dist/components/ui/button/button.cjs +1 -1
- package/dist/components/ui/button/button.cjs.map +1 -1
- package/dist/components/ui/button/button.js +1 -1
- package/dist/components/ui/button/button.js.map +1 -1
- package/dist/components/ui/calendar/calendar.cjs +4 -2
- package/dist/components/ui/calendar/calendar.cjs.map +1 -1
- package/dist/components/ui/calendar/calendar.d.cts +1 -1
- package/dist/components/ui/calendar/calendar.d.ts +1 -1
- package/dist/components/ui/calendar/calendar.js +4 -2
- package/dist/components/ui/calendar/calendar.js.map +1 -1
- package/dist/components/ui/date-picker/date-picker.cjs +173 -51
- package/dist/components/ui/date-picker/date-picker.cjs.map +1 -1
- package/dist/components/ui/date-picker/date-picker.d.cts +11 -1
- package/dist/components/ui/date-picker/date-picker.d.ts +11 -1
- package/dist/components/ui/date-picker/date-picker.js +180 -53
- package/dist/components/ui/date-picker/date-picker.js.map +1 -1
- package/dist/components/ui/date-picker/index.d.cts +1 -0
- package/dist/components/ui/date-picker/index.d.ts +1 -0
- package/dist/components/ui/index.d.cts +1 -0
- package/dist/components/ui/index.d.ts +1 -0
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/package.json +1 -1
package/AGENTS.md
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
- **Storybook (live)**: <https://ginia-ui.vercel.app>
|
|
9
9
|
- **Component index (machine-readable)**: <https://ginia-ui.vercel.app/llms.txt>
|
|
10
10
|
|
|
11
|
+
After changing stories or UI docs, run `pnpm build-storybook` locally to confirm the static build (Vercel runs it on deploy). Dev server: `pnpm storybook`.
|
|
12
|
+
|
|
11
13
|
---
|
|
12
14
|
|
|
13
15
|
## Setup (in a consumer project)
|
|
@@ -65,4 +67,5 @@ import { cn } from "@ginia/ui";
|
|
|
65
67
|
7. **Icons**: Icons are re-exported from `lucide-react` and should be imported from `@ginia/ui/icons`. For consistent sizing and accessibility, prefer using the `<Icon />` component from `@ginia/ui`.
|
|
66
68
|
8. **Typography**: Use `<Typography variant="…" />` for headings, body, lead, caption, and display styles. Pass `className` to merge extra Tailwind utilities. Each variant has a default HTML tag; override with `as` or `asChild` when you need a different element (e.g. a link styled as a heading).
|
|
67
69
|
9. **Brand lockup**: `<Wordmark />` combines the official `<Logo />` SVG with custom text (default “Ginia”). Use `className` on the root, `text` for the word, `size` (`sm` | `md` | `lg`), and optional `label` for screen readers (defaults to `text`).
|
|
68
|
-
10. **
|
|
70
|
+
10. **Dates**: `<Calendar />` (react-day-picker) defaults to Spanish via `locale={es}`. `<DatePicker />` uses month/year dropdowns and `locale` from `date-fns` (default `es`); pass `enUS` or another locale when needed. Optional `fromYear` / `toYear` bound the year list.
|
|
71
|
+
11. **No business logic** in components — they are purely presentational.
|
|
@@ -36,7 +36,7 @@ const buttonVariants = (0, import_class_variance_authority.cva)(
|
|
|
36
36
|
destructive: "bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90 focus-visible:ring-destructive/20",
|
|
37
37
|
outline: "bg-card text-primary border border-input hover:bg-primary hover:text-primary-foreground shadow-sm",
|
|
38
38
|
secondary: "bg-accent text-accent-foreground hover:bg-accent/90 shadow-sm",
|
|
39
|
-
ghost: "hover:bg-
|
|
39
|
+
ghost: "hover:bg-accent hover:text-accent-foreground",
|
|
40
40
|
link: "text-primary underline-offset-4 hover:underline",
|
|
41
41
|
success: "bg-success text-success-foreground shadow-sm hover:bg-success/90",
|
|
42
42
|
warning: "bg-warning text-warning-foreground shadow-sm hover:bg-warning/90"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/ui/button/button.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { Slot } from \"@radix-ui/react-slot\";\nimport { cva, type VariantProps } from \"class-variance-authority\";\n\nimport { cn } from \"../../../lib/utils\";\n\nconst buttonVariants = cva(\n \"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-lg text-sm font-medium transition-all duration-200 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:ring-2 focus-visible:ring-ring/20 focus-visible:ring-offset-2\",\n {\n variants: {\n variant: {\n default: \"bg-primary hover:bg-primary-dark text-primary-foreground shadow-sm\",\n destructive:\n \"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90 focus-visible:ring-destructive/20\",\n outline:\n \"bg-card text-primary border border-input hover:bg-primary hover:text-primary-foreground shadow-sm\",\n secondary: \"bg-accent text-accent-foreground hover:bg-accent/90 shadow-sm\",\n ghost: \"hover:bg-
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/ui/button/button.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { Slot } from \"@radix-ui/react-slot\";\nimport { cva, type VariantProps } from \"class-variance-authority\";\n\nimport { cn } from \"../../../lib/utils\";\n\nconst buttonVariants = cva(\n \"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-lg text-sm font-medium transition-all duration-200 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:ring-2 focus-visible:ring-ring/20 focus-visible:ring-offset-2\",\n {\n variants: {\n variant: {\n default: \"bg-primary hover:bg-primary-dark text-primary-foreground shadow-sm\",\n destructive:\n \"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90 focus-visible:ring-destructive/20\",\n outline:\n \"bg-card text-primary border border-input hover:bg-primary hover:text-primary-foreground shadow-sm\",\n secondary: \"bg-accent text-accent-foreground hover:bg-accent/90 shadow-sm\",\n ghost: \"hover:bg-accent hover:text-accent-foreground\",\n link: \"text-primary underline-offset-4 hover:underline\",\n success: \"bg-success text-success-foreground shadow-sm hover:bg-success/90\",\n warning: \"bg-warning text-warning-foreground shadow-sm hover:bg-warning/90\",\n },\n size: {\n default: \"px-4 py-2\",\n sm: \"px-3 py-1.5 text-sm\",\n lg: \"px-5 py-2.5 text-base\",\n icon: \"size-9 p-2\",\n },\n },\n defaultVariants: {\n variant: \"default\",\n size: \"default\",\n },\n },\n);\n\nfunction Button({\n className,\n variant,\n size,\n asChild = false,\n ...props\n}: React.ComponentProps<\"button\"> &\n VariantProps<typeof buttonVariants> & {\n asChild?: boolean;\n }) {\n const Comp = asChild ? Slot : \"button\";\n\n return (\n <Comp\n data-slot=\"button\"\n className={cn(buttonVariants({ variant, size, className }))}\n {...props}\n />\n );\n}\n\nexport { Button, buttonVariants };\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmDI;AAhDJ,wBAAqB;AACrB,sCAAuC;AAEvC,mBAAmB;AAEnB,MAAM,qBAAiB;AAAA,EACrB;AAAA,EACA;AAAA,IACE,UAAU;AAAA,MACR,SAAS;AAAA,QACP,SAAS;AAAA,QACT,aACE;AAAA,QACF,SACE;AAAA,QACF,WAAW;AAAA,QACX,OAAO;AAAA,QACP,MAAM;AAAA,QACN,SAAS;AAAA,QACT,SAAS;AAAA,MACX;AAAA,MACA,MAAM;AAAA,QACJ,SAAS;AAAA,QACT,IAAI;AAAA,QACJ,IAAI;AAAA,QACJ,MAAM;AAAA,MACR;AAAA,IACF;AAAA,IACA,iBAAiB;AAAA,MACf,SAAS;AAAA,MACT,MAAM;AAAA,IACR;AAAA,EACF;AACF;AAEA,SAAS,OAAO;AAAA,EACd;AAAA,EACA;AAAA,EACA;AAAA,EACA,UAAU;AAAA,EACV,GAAG;AACL,GAGK;AACH,QAAM,OAAO,UAAU,yBAAO;AAE9B,SACE;AAAA,IAAC;AAAA;AAAA,MACC,aAAU;AAAA,MACV,eAAW,iBAAG,eAAe,EAAE,SAAS,MAAM,UAAU,CAAC,CAAC;AAAA,MACzD,GAAG;AAAA;AAAA,EACN;AAEJ;","names":[]}
|
|
@@ -12,7 +12,7 @@ const buttonVariants = cva(
|
|
|
12
12
|
destructive: "bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90 focus-visible:ring-destructive/20",
|
|
13
13
|
outline: "bg-card text-primary border border-input hover:bg-primary hover:text-primary-foreground shadow-sm",
|
|
14
14
|
secondary: "bg-accent text-accent-foreground hover:bg-accent/90 shadow-sm",
|
|
15
|
-
ghost: "hover:bg-
|
|
15
|
+
ghost: "hover:bg-accent hover:text-accent-foreground",
|
|
16
16
|
link: "text-primary underline-offset-4 hover:underline",
|
|
17
17
|
success: "bg-success text-success-foreground shadow-sm hover:bg-success/90",
|
|
18
18
|
warning: "bg-warning text-warning-foreground shadow-sm hover:bg-warning/90"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/ui/button/button.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { Slot } from \"@radix-ui/react-slot\";\nimport { cva, type VariantProps } from \"class-variance-authority\";\n\nimport { cn } from \"../../../lib/utils\";\n\nconst buttonVariants = cva(\n \"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-lg text-sm font-medium transition-all duration-200 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:ring-2 focus-visible:ring-ring/20 focus-visible:ring-offset-2\",\n {\n variants: {\n variant: {\n default: \"bg-primary hover:bg-primary-dark text-primary-foreground shadow-sm\",\n destructive:\n \"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90 focus-visible:ring-destructive/20\",\n outline:\n \"bg-card text-primary border border-input hover:bg-primary hover:text-primary-foreground shadow-sm\",\n secondary: \"bg-accent text-accent-foreground hover:bg-accent/90 shadow-sm\",\n ghost: \"hover:bg-
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/ui/button/button.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { Slot } from \"@radix-ui/react-slot\";\nimport { cva, type VariantProps } from \"class-variance-authority\";\n\nimport { cn } from \"../../../lib/utils\";\n\nconst buttonVariants = cva(\n \"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-lg text-sm font-medium transition-all duration-200 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:ring-2 focus-visible:ring-ring/20 focus-visible:ring-offset-2\",\n {\n variants: {\n variant: {\n default: \"bg-primary hover:bg-primary-dark text-primary-foreground shadow-sm\",\n destructive:\n \"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90 focus-visible:ring-destructive/20\",\n outline:\n \"bg-card text-primary border border-input hover:bg-primary hover:text-primary-foreground shadow-sm\",\n secondary: \"bg-accent text-accent-foreground hover:bg-accent/90 shadow-sm\",\n ghost: \"hover:bg-accent hover:text-accent-foreground\",\n link: \"text-primary underline-offset-4 hover:underline\",\n success: \"bg-success text-success-foreground shadow-sm hover:bg-success/90\",\n warning: \"bg-warning text-warning-foreground shadow-sm hover:bg-warning/90\",\n },\n size: {\n default: \"px-4 py-2\",\n sm: \"px-3 py-1.5 text-sm\",\n lg: \"px-5 py-2.5 text-base\",\n icon: \"size-9 p-2\",\n },\n },\n defaultVariants: {\n variant: \"default\",\n size: \"default\",\n },\n },\n);\n\nfunction Button({\n className,\n variant,\n size,\n asChild = false,\n ...props\n}: React.ComponentProps<\"button\"> &\n VariantProps<typeof buttonVariants> & {\n asChild?: boolean;\n }) {\n const Comp = asChild ? Slot : \"button\";\n\n return (\n <Comp\n data-slot=\"button\"\n className={cn(buttonVariants({ variant, size, className }))}\n {...props}\n />\n );\n}\n\nexport { Button, buttonVariants };\n"],"mappings":";AAmDI;AAhDJ,SAAS,YAAY;AACrB,SAAS,WAA8B;AAEvC,SAAS,UAAU;AAEnB,MAAM,iBAAiB;AAAA,EACrB;AAAA,EACA;AAAA,IACE,UAAU;AAAA,MACR,SAAS;AAAA,QACP,SAAS;AAAA,QACT,aACE;AAAA,QACF,SACE;AAAA,QACF,WAAW;AAAA,QACX,OAAO;AAAA,QACP,MAAM;AAAA,QACN,SAAS;AAAA,QACT,SAAS;AAAA,MACX;AAAA,MACA,MAAM;AAAA,QACJ,SAAS;AAAA,QACT,IAAI;AAAA,QACJ,IAAI;AAAA,QACJ,MAAM;AAAA,MACR;AAAA,IACF;AAAA,IACA,iBAAiB;AAAA,MACf,SAAS;AAAA,MACT,MAAM;AAAA,IACR;AAAA,EACF;AACF;AAEA,SAAS,OAAO;AAAA,EACd;AAAA,EACA;AAAA,EACA;AAAA,EACA,UAAU;AAAA,EACV,GAAG;AACL,GAGK;AACH,QAAM,OAAO,UAAU,OAAO;AAE9B,SACE;AAAA,IAAC;AAAA;AAAA,MACC,aAAU;AAAA,MACV,WAAW,GAAG,eAAe,EAAE,SAAS,MAAM,UAAU,CAAC,CAAC;AAAA,MACzD,GAAG;AAAA;AAAA,EACN;AAEJ;","names":[]}
|
|
@@ -24,14 +24,16 @@ __export(calendar_exports, {
|
|
|
24
24
|
module.exports = __toCommonJS(calendar_exports);
|
|
25
25
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
26
26
|
var import_react_day_picker = require("react-day-picker");
|
|
27
|
+
var import_locale = require("date-fns/locale");
|
|
27
28
|
var import_utils = require("../../../lib/utils");
|
|
28
29
|
var import_button = require("../button");
|
|
29
|
-
function Calendar({ className, classNames, showOutsideDays = true, ...props }) {
|
|
30
|
+
function Calendar({ className, classNames, showOutsideDays = true, locale = import_locale.es, ...props }) {
|
|
30
31
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
31
32
|
import_react_day_picker.DayPicker,
|
|
32
33
|
{
|
|
33
34
|
showOutsideDays,
|
|
34
|
-
|
|
35
|
+
locale,
|
|
36
|
+
className: (0, import_utils.cn)("rounded-md bg-white p-3 dark:bg-card", className),
|
|
35
37
|
classNames: {
|
|
36
38
|
months: "flex flex-col sm:flex-row space-y-4 sm:space-x-4 sm:space-y-0",
|
|
37
39
|
month: "space-y-4",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/ui/calendar/calendar.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { DayPicker } from \"react-day-picker\";\n\nimport { cn } from \"../../../lib/utils\";\nimport { buttonVariants } from \"../button\";\n\nexport type CalendarProps = React.ComponentProps<typeof DayPicker>;\n\nfunction Calendar({ className, classNames, showOutsideDays = true, ...props }: CalendarProps) {\n return (\n <DayPicker\n showOutsideDays={showOutsideDays}\n className={cn(\"p-3\", className)}\n classNames={{\n months: \"flex flex-col sm:flex-row space-y-4 sm:space-x-4 sm:space-y-0\",\n month: \"space-y-4\",\n caption: \"flex justify-center pt-1 relative items-center\",\n caption_label: \"text-sm font-medium\",\n nav: \"space-x-1 flex items-center\",\n nav_button: cn(\n buttonVariants({ variant: \"outline\" }),\n \"h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100\",\n ),\n nav_button_previous: \"absolute left-1\",\n nav_button_next: \"absolute right-1\",\n table: \"w-full border-collapse space-y-1\",\n head_row: \"flex\",\n head_cell: \"text-muted-foreground rounded-md w-9 font-normal text-[0.8rem]\",\n row: \"flex w-full mt-2\",\n cell: \"h-9 w-9 text-center text-sm p-0 relative [&:has([aria-selected].day-range-end)]:rounded-r-md [&:has([aria-selected].day-outside)]:bg-accent/50 [&:has([aria-selected])]:bg-accent first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md focus-within:relative focus-within:z-20\",\n day: cn(\n buttonVariants({ variant: \"ghost\" }),\n \"h-9 w-9 p-0 font-normal aria-selected:opacity-100\",\n ),\n day_range_end: \"day-range-end\",\n day_selected:\n \"bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground focus:bg-primary focus:text-primary-foreground\",\n day_today: \"bg-accent text-accent-foreground\",\n day_outside:\n \"day-outside text-muted-foreground opacity-50 aria-selected:bg-accent/50 aria-selected:text-muted-foreground aria-selected:opacity-30\",\n day_disabled: \"text-muted-foreground opacity-50\",\n day_range_middle: \"aria-selected:bg-accent aria-selected:text-accent-foreground\",\n day_hidden: \"invisible\",\n ...classNames,\n }}\n {...props}\n />\n );\n}\n\nexport { Calendar };\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/ui/calendar/calendar.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { DayPicker } from \"react-day-picker\";\nimport { es } from \"date-fns/locale\";\n\nimport { cn } from \"../../../lib/utils\";\nimport { buttonVariants } from \"../button\";\n\nexport type CalendarProps = React.ComponentProps<typeof DayPicker>;\n\nfunction Calendar({ className, classNames, showOutsideDays = true, locale = es, ...props }: CalendarProps) {\n return (\n <DayPicker\n showOutsideDays={showOutsideDays}\n locale={locale}\n className={cn(\"rounded-md bg-white p-3 dark:bg-card\", className)}\n classNames={{\n months: \"flex flex-col sm:flex-row space-y-4 sm:space-x-4 sm:space-y-0\",\n month: \"space-y-4\",\n caption: \"flex justify-center pt-1 relative items-center\",\n caption_label: \"text-sm font-medium\",\n nav: \"space-x-1 flex items-center\",\n nav_button: cn(\n buttonVariants({ variant: \"outline\" }),\n \"h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100\",\n ),\n nav_button_previous: \"absolute left-1\",\n nav_button_next: \"absolute right-1\",\n table: \"w-full border-collapse space-y-1\",\n head_row: \"flex\",\n head_cell: \"text-muted-foreground rounded-md w-9 font-normal text-[0.8rem]\",\n row: \"flex w-full mt-2\",\n cell: \"h-9 w-9 text-center text-sm p-0 relative [&:has([aria-selected].day-range-end)]:rounded-r-md [&:has([aria-selected].day-outside)]:bg-accent/50 [&:has([aria-selected])]:bg-accent first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md focus-within:relative focus-within:z-20\",\n day: cn(\n buttonVariants({ variant: \"ghost\" }),\n \"h-9 w-9 p-0 font-normal aria-selected:opacity-100\",\n ),\n day_range_end: \"day-range-end\",\n day_selected:\n \"bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground focus:bg-primary focus:text-primary-foreground\",\n day_today: \"bg-accent text-accent-foreground\",\n day_outside:\n \"day-outside text-muted-foreground opacity-50 aria-selected:bg-accent/50 aria-selected:text-muted-foreground aria-selected:opacity-30\",\n day_disabled: \"text-muted-foreground opacity-50\",\n day_range_middle: \"aria-selected:bg-accent aria-selected:text-accent-foreground\",\n day_hidden: \"invisible\",\n ...classNames,\n }}\n {...props}\n />\n );\n}\n\nexport { Calendar };\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAaI;AAVJ,8BAA0B;AAC1B,oBAAmB;AAEnB,mBAAmB;AACnB,oBAA+B;AAI/B,SAAS,SAAS,EAAE,WAAW,YAAY,kBAAkB,MAAM,SAAS,kBAAI,GAAG,MAAM,GAAkB;AACzG,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA,eAAW,iBAAG,wCAAwC,SAAS;AAAA,MAC/D,YAAY;AAAA,QACV,QAAQ;AAAA,QACR,OAAO;AAAA,QACP,SAAS;AAAA,QACT,eAAe;AAAA,QACf,KAAK;AAAA,QACL,gBAAY;AAAA,cACV,8BAAe,EAAE,SAAS,UAAU,CAAC;AAAA,UACrC;AAAA,QACF;AAAA,QACA,qBAAqB;AAAA,QACrB,iBAAiB;AAAA,QACjB,OAAO;AAAA,QACP,UAAU;AAAA,QACV,WAAW;AAAA,QACX,KAAK;AAAA,QACL,MAAM;AAAA,QACN,SAAK;AAAA,cACH,8BAAe,EAAE,SAAS,QAAQ,CAAC;AAAA,UACnC;AAAA,QACF;AAAA,QACA,eAAe;AAAA,QACf,cACE;AAAA,QACF,WAAW;AAAA,QACX,aACE;AAAA,QACF,cAAc;AAAA,QACd,kBAAkB;AAAA,QAClB,YAAY;AAAA,QACZ,GAAG;AAAA,MACL;AAAA,MACC,GAAG;AAAA;AAAA,EACN;AAEJ;","names":[]}
|
|
@@ -3,6 +3,6 @@ import * as React from 'react';
|
|
|
3
3
|
import { DayPicker } from 'react-day-picker';
|
|
4
4
|
|
|
5
5
|
type CalendarProps = React.ComponentProps<typeof DayPicker>;
|
|
6
|
-
declare function Calendar({ className, classNames, showOutsideDays, ...props }: CalendarProps): react_jsx_runtime.JSX.Element;
|
|
6
|
+
declare function Calendar({ className, classNames, showOutsideDays, locale, ...props }: CalendarProps): react_jsx_runtime.JSX.Element;
|
|
7
7
|
|
|
8
8
|
export { Calendar, type CalendarProps };
|
|
@@ -3,6 +3,6 @@ import * as React from 'react';
|
|
|
3
3
|
import { DayPicker } from 'react-day-picker';
|
|
4
4
|
|
|
5
5
|
type CalendarProps = React.ComponentProps<typeof DayPicker>;
|
|
6
|
-
declare function Calendar({ className, classNames, showOutsideDays, ...props }: CalendarProps): react_jsx_runtime.JSX.Element;
|
|
6
|
+
declare function Calendar({ className, classNames, showOutsideDays, locale, ...props }: CalendarProps): react_jsx_runtime.JSX.Element;
|
|
7
7
|
|
|
8
8
|
export { Calendar, type CalendarProps };
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
3
|
import { DayPicker } from "react-day-picker";
|
|
4
|
+
import { es } from "date-fns/locale";
|
|
4
5
|
import { cn } from "../../../lib/utils";
|
|
5
6
|
import { buttonVariants } from "../button";
|
|
6
|
-
function Calendar({ className, classNames, showOutsideDays = true, ...props }) {
|
|
7
|
+
function Calendar({ className, classNames, showOutsideDays = true, locale = es, ...props }) {
|
|
7
8
|
return /* @__PURE__ */ jsx(
|
|
8
9
|
DayPicker,
|
|
9
10
|
{
|
|
10
11
|
showOutsideDays,
|
|
11
|
-
|
|
12
|
+
locale,
|
|
13
|
+
className: cn("rounded-md bg-white p-3 dark:bg-card", className),
|
|
12
14
|
classNames: {
|
|
13
15
|
months: "flex flex-col sm:flex-row space-y-4 sm:space-x-4 sm:space-y-0",
|
|
14
16
|
month: "space-y-4",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/ui/calendar/calendar.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { DayPicker } from \"react-day-picker\";\n\nimport { cn } from \"../../../lib/utils\";\nimport { buttonVariants } from \"../button\";\n\nexport type CalendarProps = React.ComponentProps<typeof DayPicker>;\n\nfunction Calendar({ className, classNames, showOutsideDays = true, ...props }: CalendarProps) {\n return (\n <DayPicker\n showOutsideDays={showOutsideDays}\n className={cn(\"p-3\", className)}\n classNames={{\n months: \"flex flex-col sm:flex-row space-y-4 sm:space-x-4 sm:space-y-0\",\n month: \"space-y-4\",\n caption: \"flex justify-center pt-1 relative items-center\",\n caption_label: \"text-sm font-medium\",\n nav: \"space-x-1 flex items-center\",\n nav_button: cn(\n buttonVariants({ variant: \"outline\" }),\n \"h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100\",\n ),\n nav_button_previous: \"absolute left-1\",\n nav_button_next: \"absolute right-1\",\n table: \"w-full border-collapse space-y-1\",\n head_row: \"flex\",\n head_cell: \"text-muted-foreground rounded-md w-9 font-normal text-[0.8rem]\",\n row: \"flex w-full mt-2\",\n cell: \"h-9 w-9 text-center text-sm p-0 relative [&:has([aria-selected].day-range-end)]:rounded-r-md [&:has([aria-selected].day-outside)]:bg-accent/50 [&:has([aria-selected])]:bg-accent first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md focus-within:relative focus-within:z-20\",\n day: cn(\n buttonVariants({ variant: \"ghost\" }),\n \"h-9 w-9 p-0 font-normal aria-selected:opacity-100\",\n ),\n day_range_end: \"day-range-end\",\n day_selected:\n \"bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground focus:bg-primary focus:text-primary-foreground\",\n day_today: \"bg-accent text-accent-foreground\",\n day_outside:\n \"day-outside text-muted-foreground opacity-50 aria-selected:bg-accent/50 aria-selected:text-muted-foreground aria-selected:opacity-30\",\n day_disabled: \"text-muted-foreground opacity-50\",\n day_range_middle: \"aria-selected:bg-accent aria-selected:text-accent-foreground\",\n day_hidden: \"invisible\",\n ...classNames,\n }}\n {...props}\n />\n );\n}\n\nexport { Calendar };\n"],"mappings":";
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/ui/calendar/calendar.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { DayPicker } from \"react-day-picker\";\nimport { es } from \"date-fns/locale\";\n\nimport { cn } from \"../../../lib/utils\";\nimport { buttonVariants } from \"../button\";\n\nexport type CalendarProps = React.ComponentProps<typeof DayPicker>;\n\nfunction Calendar({ className, classNames, showOutsideDays = true, locale = es, ...props }: CalendarProps) {\n return (\n <DayPicker\n showOutsideDays={showOutsideDays}\n locale={locale}\n className={cn(\"rounded-md bg-white p-3 dark:bg-card\", className)}\n classNames={{\n months: \"flex flex-col sm:flex-row space-y-4 sm:space-x-4 sm:space-y-0\",\n month: \"space-y-4\",\n caption: \"flex justify-center pt-1 relative items-center\",\n caption_label: \"text-sm font-medium\",\n nav: \"space-x-1 flex items-center\",\n nav_button: cn(\n buttonVariants({ variant: \"outline\" }),\n \"h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100\",\n ),\n nav_button_previous: \"absolute left-1\",\n nav_button_next: \"absolute right-1\",\n table: \"w-full border-collapse space-y-1\",\n head_row: \"flex\",\n head_cell: \"text-muted-foreground rounded-md w-9 font-normal text-[0.8rem]\",\n row: \"flex w-full mt-2\",\n cell: \"h-9 w-9 text-center text-sm p-0 relative [&:has([aria-selected].day-range-end)]:rounded-r-md [&:has([aria-selected].day-outside)]:bg-accent/50 [&:has([aria-selected])]:bg-accent first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md focus-within:relative focus-within:z-20\",\n day: cn(\n buttonVariants({ variant: \"ghost\" }),\n \"h-9 w-9 p-0 font-normal aria-selected:opacity-100\",\n ),\n day_range_end: \"day-range-end\",\n day_selected:\n \"bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground focus:bg-primary focus:text-primary-foreground\",\n day_today: \"bg-accent text-accent-foreground\",\n day_outside:\n \"day-outside text-muted-foreground opacity-50 aria-selected:bg-accent/50 aria-selected:text-muted-foreground aria-selected:opacity-30\",\n day_disabled: \"text-muted-foreground opacity-50\",\n day_range_middle: \"aria-selected:bg-accent aria-selected:text-accent-foreground\",\n day_hidden: \"invisible\",\n ...classNames,\n }}\n {...props}\n />\n );\n}\n\nexport { Calendar };\n"],"mappings":";AAaI;AAVJ,SAAS,iBAAiB;AAC1B,SAAS,UAAU;AAEnB,SAAS,UAAU;AACnB,SAAS,sBAAsB;AAI/B,SAAS,SAAS,EAAE,WAAW,YAAY,kBAAkB,MAAM,SAAS,IAAI,GAAG,MAAM,GAAkB;AACzG,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA,WAAW,GAAG,wCAAwC,SAAS;AAAA,MAC/D,YAAY;AAAA,QACV,QAAQ;AAAA,QACR,OAAO;AAAA,QACP,SAAS;AAAA,QACT,eAAe;AAAA,QACf,KAAK;AAAA,QACL,YAAY;AAAA,UACV,eAAe,EAAE,SAAS,UAAU,CAAC;AAAA,UACrC;AAAA,QACF;AAAA,QACA,qBAAqB;AAAA,QACrB,iBAAiB;AAAA,QACjB,OAAO;AAAA,QACP,UAAU;AAAA,QACV,WAAW;AAAA,QACX,KAAK;AAAA,QACL,MAAM;AAAA,QACN,KAAK;AAAA,UACH,eAAe,EAAE,SAAS,QAAQ,CAAC;AAAA,UACnC;AAAA,QACF;AAAA,QACA,eAAe;AAAA,QACf,cACE;AAAA,QACF,WAAW;AAAA,QACX,aACE;AAAA,QACF,cAAc;AAAA,QACd,kBAAkB;AAAA,QAClB,YAAY;AAAA,QACZ,GAAG;AAAA,MACL;AAAA,MACC,GAAG;AAAA;AAAA,EACN;AAEJ;","names":[]}
|
|
@@ -40,64 +40,140 @@ var import_lucide_react = require("lucide-react");
|
|
|
40
40
|
var import_utils = require("../../../lib/utils");
|
|
41
41
|
var import_button = require("../button");
|
|
42
42
|
var import_popover = require("../popover");
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
"
|
|
56
|
-
|
|
57
|
-
|
|
43
|
+
function getWeekStartsOn(locale) {
|
|
44
|
+
const w = locale.options?.weekStartsOn;
|
|
45
|
+
if (w === void 0) return 1;
|
|
46
|
+
return w;
|
|
47
|
+
}
|
|
48
|
+
function useMonthLabels(locale) {
|
|
49
|
+
return React.useMemo(
|
|
50
|
+
() => Array.from({ length: 12 }, (_, i) => (0, import_date_fns.format)(new Date(2024, i, 1), "LLL", { locale })),
|
|
51
|
+
[locale]
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
function weekdayTwoLetterLabel(abbrev) {
|
|
55
|
+
const graphemes = [...abbrev.normalize("NFC")];
|
|
56
|
+
if (graphemes.length <= 2) {
|
|
57
|
+
return abbrev;
|
|
58
|
+
}
|
|
59
|
+
return graphemes.slice(0, 2).join("");
|
|
60
|
+
}
|
|
61
|
+
function useWeekdayLabels(locale) {
|
|
62
|
+
return React.useMemo(() => {
|
|
63
|
+
const weekStartsOn = getWeekStartsOn(locale);
|
|
64
|
+
const start = (0, import_date_fns.startOfWeek)(new Date(2024, 0, 3), { weekStartsOn });
|
|
65
|
+
return Array.from({ length: 7 }, (_, i) => {
|
|
66
|
+
const abbrev = (0, import_date_fns.format)((0, import_date_fns.addDays)(start, i), "EEE", { locale });
|
|
67
|
+
return weekdayTwoLetterLabel(abbrev);
|
|
68
|
+
});
|
|
69
|
+
}, [locale]);
|
|
70
|
+
}
|
|
71
|
+
function getDaysInMonth(date, weekStartsOn) {
|
|
72
|
+
const year = date.getFullYear();
|
|
73
|
+
const month = date.getMonth();
|
|
74
|
+
const lastDay = new Date(year, month + 1, 0);
|
|
75
|
+
const daysInMonth = lastDay.getDate();
|
|
76
|
+
const firstDay = new Date(year, month, 1);
|
|
77
|
+
const startingDayOfWeek = firstDay.getDay();
|
|
78
|
+
const offset = (startingDayOfWeek - weekStartsOn + 7) % 7;
|
|
79
|
+
const days = [];
|
|
80
|
+
for (let i = 0; i < offset; i++) {
|
|
81
|
+
days.push(null);
|
|
82
|
+
}
|
|
83
|
+
for (let day = 1; day <= daysInMonth; day++) {
|
|
84
|
+
days.push(new Date(year, month, day));
|
|
85
|
+
}
|
|
86
|
+
return days;
|
|
87
|
+
}
|
|
88
|
+
function DatePickerSelect({
|
|
89
|
+
className,
|
|
90
|
+
wrapperClassName,
|
|
91
|
+
children,
|
|
92
|
+
...props
|
|
93
|
+
}) {
|
|
94
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: (0, import_utils.cn)("relative", wrapperClassName), children: [
|
|
95
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
96
|
+
"select",
|
|
97
|
+
{
|
|
98
|
+
...props,
|
|
99
|
+
className: (0, import_utils.cn)(
|
|
100
|
+
"h-9 w-full min-w-0 cursor-pointer appearance-none rounded-md border border-input bg-card py-0 pl-2 pr-9 text-left text-sm shadow-xs outline-none",
|
|
101
|
+
"focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50",
|
|
102
|
+
"disabled:cursor-not-allowed disabled:opacity-50",
|
|
103
|
+
className
|
|
104
|
+
),
|
|
105
|
+
children
|
|
106
|
+
}
|
|
107
|
+
),
|
|
108
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
109
|
+
import_lucide_react.ChevronDown,
|
|
110
|
+
{
|
|
111
|
+
className: "pointer-events-none absolute right-2 top-1/2 size-4 -translate-y-1/2 shrink-0 text-muted-foreground opacity-80",
|
|
112
|
+
"aria-hidden": true
|
|
113
|
+
}
|
|
114
|
+
)
|
|
115
|
+
] });
|
|
116
|
+
}
|
|
58
117
|
function DatePicker({
|
|
59
118
|
value,
|
|
60
119
|
onChange,
|
|
61
120
|
placeholder = "Seleccionar fecha",
|
|
62
121
|
disabled = false,
|
|
63
|
-
className
|
|
122
|
+
className,
|
|
123
|
+
locale = import_locale.es,
|
|
124
|
+
fromYear,
|
|
125
|
+
toYear
|
|
64
126
|
}) {
|
|
65
127
|
const [open, setOpen] = React.useState(false);
|
|
66
|
-
const [currentMonth, setCurrentMonth] = React.useState(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
days2.push(null);
|
|
128
|
+
const [currentMonth, setCurrentMonth] = React.useState(() => {
|
|
129
|
+
const base = value ?? /* @__PURE__ */ new Date();
|
|
130
|
+
return new Date(base.getFullYear(), base.getMonth(), 1);
|
|
131
|
+
});
|
|
132
|
+
const monthLabels = useMonthLabels(locale);
|
|
133
|
+
const weekdayLabels = useWeekdayLabels(locale);
|
|
134
|
+
const weekStartsOn = getWeekStartsOn(locale);
|
|
135
|
+
React.useEffect(() => {
|
|
136
|
+
if (value) {
|
|
137
|
+
setCurrentMonth(new Date(value.getFullYear(), value.getMonth(), 1));
|
|
77
138
|
}
|
|
78
|
-
|
|
79
|
-
|
|
139
|
+
}, [value]);
|
|
140
|
+
const days = React.useMemo(
|
|
141
|
+
() => getDaysInMonth(currentMonth, weekStartsOn),
|
|
142
|
+
[currentMonth, weekStartsOn]
|
|
143
|
+
);
|
|
144
|
+
const yearOptions = React.useMemo(() => {
|
|
145
|
+
const y = (/* @__PURE__ */ new Date()).getFullYear();
|
|
146
|
+
const from = fromYear ?? y - 100;
|
|
147
|
+
const to = toYear ?? y + 10;
|
|
148
|
+
const list = [];
|
|
149
|
+
for (let i = from; i <= to; i++) {
|
|
150
|
+
list.push(i);
|
|
80
151
|
}
|
|
81
|
-
return
|
|
82
|
-
};
|
|
83
|
-
const days = getDaysInMonth(currentMonth);
|
|
152
|
+
return list;
|
|
153
|
+
}, [fromYear, toYear]);
|
|
84
154
|
const handleDateSelect = (date) => {
|
|
85
155
|
onChange?.(date);
|
|
86
156
|
setOpen(false);
|
|
87
157
|
};
|
|
88
158
|
const goToPreviousMonth = () => {
|
|
89
|
-
setCurrentMonth(new Date(currentMonth.getFullYear(), currentMonth.getMonth() - 1));
|
|
159
|
+
setCurrentMonth(new Date(currentMonth.getFullYear(), currentMonth.getMonth() - 1, 1));
|
|
90
160
|
};
|
|
91
161
|
const goToNextMonth = () => {
|
|
92
|
-
setCurrentMonth(new Date(currentMonth.getFullYear(), currentMonth.getMonth() + 1));
|
|
162
|
+
setCurrentMonth(new Date(currentMonth.getFullYear(), currentMonth.getMonth() + 1, 1));
|
|
163
|
+
};
|
|
164
|
+
const setMonthFromSelect = (monthIndex) => {
|
|
165
|
+
setCurrentMonth(new Date(currentMonth.getFullYear(), monthIndex, 1));
|
|
166
|
+
};
|
|
167
|
+
const setYearFromSelect = (year) => {
|
|
168
|
+
setCurrentMonth(new Date(year, currentMonth.getMonth(), 1));
|
|
93
169
|
};
|
|
94
170
|
const isToday = (date) => {
|
|
95
171
|
const today = /* @__PURE__ */ new Date();
|
|
96
|
-
return date.
|
|
172
|
+
return date.getFullYear() === today.getFullYear() && date.getMonth() === today.getMonth() && date.getDate() === today.getDate();
|
|
97
173
|
};
|
|
98
174
|
const isSelected = (date) => {
|
|
99
175
|
if (!value) return false;
|
|
100
|
-
return date.
|
|
176
|
+
return date.getFullYear() === value.getFullYear() && date.getMonth() === value.getMonth() && date.getDate() === value.getDate();
|
|
101
177
|
};
|
|
102
178
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_popover.Popover, { open, onOpenChange: setOpen, children: [
|
|
103
179
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_popover.PopoverTrigger, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
@@ -112,32 +188,78 @@ function DatePicker({
|
|
|
112
188
|
),
|
|
113
189
|
disabled,
|
|
114
190
|
children: [
|
|
115
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.Calendar, { className: "mr-2 h-4 w-4" }),
|
|
116
|
-
value ? (0, import_date_fns.format)(value, "
|
|
191
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.Calendar, { className: "mr-2 h-4 w-4 shrink-0" }),
|
|
192
|
+
value ? (0, import_date_fns.format)(value, "P", { locale }) : placeholder
|
|
117
193
|
]
|
|
118
194
|
}
|
|
119
195
|
) }),
|
|
120
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_popover.PopoverContent, { className: "w-auto p-0", align: "start", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "p-3", children: [
|
|
121
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "mb-
|
|
122
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
196
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_popover.PopoverContent, { className: "w-auto bg-white p-0 dark:bg-card", align: "start", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "p-3", children: [
|
|
197
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "mb-3 flex flex-wrap items-center justify-center gap-1.5", children: [
|
|
198
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
199
|
+
import_button.Button,
|
|
200
|
+
{
|
|
201
|
+
type: "button",
|
|
202
|
+
variant: "outline",
|
|
203
|
+
size: "sm",
|
|
204
|
+
onClick: goToPreviousMonth,
|
|
205
|
+
className: "h-9 w-9 shrink-0 p-0",
|
|
206
|
+
"aria-label": locale.code?.startsWith("es") ? "Mes anterior" : "Previous month",
|
|
207
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.ChevronLeft, { className: "h-4 w-4" })
|
|
208
|
+
}
|
|
209
|
+
),
|
|
210
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
211
|
+
DatePickerSelect,
|
|
212
|
+
{
|
|
213
|
+
wrapperClassName: "w-[6.75rem] shrink-0",
|
|
214
|
+
value: currentMonth.getMonth(),
|
|
215
|
+
onChange: (e) => setMonthFromSelect(Number(e.target.value)),
|
|
216
|
+
"aria-label": locale.code?.startsWith("es") ? "Mes" : "Month",
|
|
217
|
+
children: monthLabels.map((label, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: i, children: label }, label))
|
|
218
|
+
}
|
|
219
|
+
),
|
|
220
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
221
|
+
DatePickerSelect,
|
|
222
|
+
{
|
|
223
|
+
wrapperClassName: "w-[5.5rem] shrink-0",
|
|
224
|
+
className: "tabular-nums text-center",
|
|
225
|
+
value: currentMonth.getFullYear(),
|
|
226
|
+
onChange: (e) => setYearFromSelect(Number(e.target.value)),
|
|
227
|
+
"aria-label": locale.code?.startsWith("es") ? "A\xF1o" : "Year",
|
|
228
|
+
children: yearOptions.map((y) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: y, children: y }, y))
|
|
229
|
+
}
|
|
230
|
+
),
|
|
231
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
232
|
+
import_button.Button,
|
|
233
|
+
{
|
|
234
|
+
type: "button",
|
|
235
|
+
variant: "outline",
|
|
236
|
+
size: "sm",
|
|
237
|
+
onClick: goToNextMonth,
|
|
238
|
+
className: "h-9 w-9 shrink-0 p-0",
|
|
239
|
+
"aria-label": locale.code?.startsWith("es") ? "Mes siguiente" : "Next month",
|
|
240
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.ChevronRight, { className: "h-4 w-4" })
|
|
241
|
+
}
|
|
242
|
+
)
|
|
129
243
|
] }),
|
|
130
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "mb-2 grid grid-cols-7 gap-1", children:
|
|
244
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "mb-2 grid grid-cols-7 gap-1", children: weekdayLabels.map((day, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
245
|
+
"div",
|
|
246
|
+
{
|
|
247
|
+
className: "px-0.5 py-2 text-center text-sm font-medium capitalize leading-tight text-muted-foreground",
|
|
248
|
+
children: day
|
|
249
|
+
},
|
|
250
|
+
i
|
|
251
|
+
)) }),
|
|
131
252
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "grid grid-cols-7 gap-1", children: days.map((day, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "flex h-9 w-9 items-center justify-center", children: day ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
132
253
|
import_button.Button,
|
|
133
254
|
{
|
|
255
|
+
type: "button",
|
|
134
256
|
variant: "ghost",
|
|
135
257
|
size: "sm",
|
|
136
258
|
className: (0, import_utils.cn)(
|
|
137
259
|
"h-9 w-9 p-0 font-normal",
|
|
138
|
-
isSelected(day) && "bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground",
|
|
139
|
-
isToday(day) && !isSelected(day) && "bg-accent text-accent-foreground",
|
|
140
|
-
"hover:bg-muted"
|
|
260
|
+
isSelected(day) && "bg-primary text-primary-foreground hover:bg-primary-dark hover:text-primary-foreground",
|
|
261
|
+
isToday(day) && !isSelected(day) && "bg-accent text-accent-foreground hover:bg-accent/80 hover:text-accent-foreground",
|
|
262
|
+
!isSelected(day) && !isToday(day) && "hover:bg-muted hover:text-foreground"
|
|
141
263
|
),
|
|
142
264
|
onClick: () => handleDateSelect(day),
|
|
143
265
|
children: day.getDate()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/ui/date-picker/date-picker.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { format } from \"date-fns\";\nimport { es } from \"date-fns/locale\";\nimport { Calendar as CalendarIcon, ChevronLeft, ChevronRight } from \"lucide-react\";\n\nimport { cn } from \"../../../lib/utils\";\nimport { Button } from \"../button\";\nimport { Popover, PopoverContent, PopoverTrigger } from \"../popover\";\n\nexport interface DatePickerProps {\n value?: Date;\n onChange?: (date: Date | undefined) => void;\n placeholder?: string;\n disabled?: boolean;\n className?: string;\n}\n\nconst monthNames = [\n \"Enero\",\n \"Febrero\",\n \"Marzo\",\n \"Abril\",\n \"Mayo\",\n \"Junio\",\n \"Julio\",\n \"Agosto\",\n \"Septiembre\",\n \"Octubre\",\n \"Noviembre\",\n \"Diciembre\",\n];\nconst dayNames = [\"Do\", \"Lu\", \"Ma\", \"Mi\", \"Ju\", \"Vi\", \"Sá\"];\n\nfunction DatePicker({\n value,\n onChange,\n placeholder = \"Seleccionar fecha\",\n disabled = false,\n className,\n}: DatePickerProps) {\n const [open, setOpen] = React.useState(false);\n const [currentMonth, setCurrentMonth] = React.useState(value || new Date());\n\n const getDaysInMonth = (date: Date) => {\n const year = date.getFullYear();\n const month = date.getMonth();\n const firstDay = new Date(year, month, 1);\n const lastDay = new Date(year, month + 1, 0);\n const daysInMonth = lastDay.getDate();\n const startingDayOfWeek = firstDay.getDay();\n\n const days: (Date | null)[] = [];\n\n for (let i = 0; i < startingDayOfWeek; i++) {\n days.push(null);\n }\n\n for (let day = 1; day <= daysInMonth; day++) {\n days.push(new Date(Date.UTC(year, month, day)));\n }\n\n return days;\n };\n\n const days = getDaysInMonth(currentMonth);\n\n const handleDateSelect = (date: Date) => {\n onChange?.(date);\n setOpen(false);\n };\n\n const goToPreviousMonth = () => {\n setCurrentMonth(new Date(currentMonth.getFullYear(), currentMonth.getMonth() - 1));\n };\n\n const goToNextMonth = () => {\n setCurrentMonth(new Date(currentMonth.getFullYear(), currentMonth.getMonth() + 1));\n };\n\n const isToday = (date: Date) => {\n const today = new Date();\n return (\n date.getUTCFullYear() === today.getFullYear() &&\n date.getUTCMonth() === today.getMonth() &&\n date.getUTCDate() === today.getDate()\n );\n };\n\n const isSelected = (date: Date) => {\n if (!value) return false;\n return (\n date.getUTCFullYear() === value.getFullYear() &&\n date.getUTCMonth() === value.getMonth() &&\n date.getUTCDate() === value.getDate()\n );\n };\n\n return (\n <Popover open={open} onOpenChange={setOpen}>\n <PopoverTrigger asChild>\n <Button\n variant=\"outline\"\n data-slot=\"date-picker\"\n className={cn(\n \"w-full justify-start text-left font-normal\",\n !value && \"text-muted-foreground\",\n className,\n )}\n disabled={disabled}\n >\n <CalendarIcon className=\"mr-2 h-4 w-4\" />\n {value ? format(value, \"dd/MM/yyyy\", { locale: es }) : placeholder}\n </Button>\n </PopoverTrigger>\n <PopoverContent className=\"w-auto p-0\" align=\"start\">\n <div className=\"p-3\">\n <div className=\"mb-4 flex items-center justify-between\">\n <Button variant=\"outline\" size=\"sm\" onClick={goToPreviousMonth} className=\"h-7 w-7 p-0\">\n <ChevronLeft className=\"h-4 w-4\" />\n </Button>\n <div className=\"text-sm font-medium\">\n {monthNames[currentMonth.getMonth()]} {currentMonth.getFullYear()}\n </div>\n <Button variant=\"outline\" size=\"sm\" onClick={goToNextMonth} className=\"h-7 w-7 p-0\">\n <ChevronRight className=\"h-4 w-4\" />\n </Button>\n </div>\n\n <div className=\"mb-2 grid grid-cols-7 gap-1\">\n {dayNames.map((day) => (\n <div key={day} className=\"py-2 text-center text-xs font-medium text-muted-foreground\">\n {day}\n </div>\n ))}\n </div>\n\n <div className=\"grid grid-cols-7 gap-1\">\n {days.map((day, index) => (\n <div key={index} className=\"flex h-9 w-9 items-center justify-center\">\n {day ? (\n <Button\n variant=\"ghost\"\n size=\"sm\"\n className={cn(\n \"h-9 w-9 p-0 font-normal\",\n isSelected(day) &&\n \"bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground\",\n isToday(day) && !isSelected(day) && \"bg-accent text-accent-foreground\",\n \"hover:bg-muted\",\n )}\n onClick={() => handleDateSelect(day)}\n >\n {day.getDate()}\n </Button>\n ) : (\n <div className=\"h-9 w-9\" />\n )}\n </div>\n ))}\n </div>\n </div>\n </PopoverContent>\n </Popover>\n );\n}\n\nexport { DatePicker };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAsGQ;AApGR,YAAuB;AACvB,sBAAuB;AACvB,oBAAmB;AACnB,0BAAoE;AAEpE,mBAAmB;AACnB,oBAAuB;AACvB,qBAAwD;AAUxD,MAAM,aAAa;AAAA,EACjB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AACA,MAAM,WAAW,CAAC,MAAM,MAAM,MAAM,MAAM,MAAM,MAAM,OAAI;AAE1D,SAAS,WAAW;AAAA,EAClB;AAAA,EACA;AAAA,EACA,cAAc;AAAA,EACd,WAAW;AAAA,EACX;AACF,GAAoB;AAClB,QAAM,CAAC,MAAM,OAAO,IAAI,MAAM,SAAS,KAAK;AAC5C,QAAM,CAAC,cAAc,eAAe,IAAI,MAAM,SAAS,SAAS,oBAAI,KAAK,CAAC;AAE1E,QAAM,iBAAiB,CAAC,SAAe;AACrC,UAAM,OAAO,KAAK,YAAY;AAC9B,UAAM,QAAQ,KAAK,SAAS;AAC5B,UAAM,WAAW,IAAI,KAAK,MAAM,OAAO,CAAC;AACxC,UAAM,UAAU,IAAI,KAAK,MAAM,QAAQ,GAAG,CAAC;AAC3C,UAAM,cAAc,QAAQ,QAAQ;AACpC,UAAM,oBAAoB,SAAS,OAAO;AAE1C,UAAMA,QAAwB,CAAC;AAE/B,aAAS,IAAI,GAAG,IAAI,mBAAmB,KAAK;AAC1C,MAAAA,MAAK,KAAK,IAAI;AAAA,IAChB;A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AA,IACzD,GACF;AAAA,IACA,4CAAC,iCAAe,WAAU,cAAa,OAAM,SAC3C,uDAAC,SAAI,WAAU,OACb;AAAA,mDAAC,SAAI,WAAU,0CACb;AAAA,oDAAC,wBAAO,SAAQ,WAAU,MAAK,MAAK,SAAS,mBAAmB,WAAU,eACxE,sDAAC,mCAAY,WAAU,WAAU,GACnC;AAAA,QACA,6CAAC,SAAI,WAAU,uBACZ;AAAA,qBAAW,aAAa,SAAS,CAAC;AAAA,UAAE;AAAA,UAAE,aAAa,YAAY;AAAA,WAClE;AAAA,QACA,4CAAC,wBAAO,SAAQ,WAAU,MAAK,MAAK,SAAS,eAAe,WAAU,eACpE,sDAAC,oCAAa,WAAU,WAAU,GACpC;AAAA,SACF;AAAA,MAEA,4CAAC,SAAI,WAAU,+BACZ,mBAAS,IAAI,CAAC,QACb,4CAAC,SAAc,WAAU,8DACtB,iBADO,GAEV,CACD,GACH;AAAA,MAEA,4CAAC,SAAI,WAAU,0BACZ,eAAK,IAAI,CAAC,KAAK,UACd,4CAAC,SAAgB,WAAU,4CACxB,gBACC;AAAA,QAAC;AAAA;AAAA,UACC,SAAQ;AAAA,UACR,MAAK;AAAA,UACL,eAAW;AAAA,YACT;AAAA,YACA,WAAW,GAAG,KACZ;AAAA,YACF,QAAQ,GAAG,KAAK,CAAC,WAAW,GAAG,KAAK;AAAA,YACpC;AAAA,UACF;AAAA,UACA,SAAS,MAAM,iBAAiB,GAAG;AAAA,UAElC,cAAI,QAAQ;AAAA;AAAA,MACf,IAEA,4CAAC,SAAI,WAAU,WAAU,KAjBnB,KAmBV,CACD,GACH;AAAA,OACF,GACF;AAAA,KACF;AAEJ;","names":["days","CalendarIcon"]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/ui/date-picker/date-picker.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { addDays, format, startOfWeek } from \"date-fns\";\nimport type { Locale } from \"date-fns\";\nimport { es } from \"date-fns/locale\";\nimport {\n Calendar as CalendarIcon,\n ChevronDown,\n ChevronLeft,\n ChevronRight,\n} from \"lucide-react\";\n\nimport { cn } from \"../../../lib/utils\";\nimport { Button } from \"../button\";\nimport { Popover, PopoverContent, PopoverTrigger } from \"../popover\";\n\nexport interface DatePickerProps {\n value?: Date;\n onChange?: (date: Date | undefined) => void;\n placeholder?: string;\n disabled?: boolean;\n className?: string;\n /**\n * Locale de `date-fns` para nombres de mes/día y formato de la fecha en el botón.\n * Por defecto español (`es`).\n */\n locale?: Locale;\n /** Año mínimo en el selector (inclusive). */\n fromYear?: number;\n /** Año máximo en el selector (inclusive). */\n toYear?: number;\n}\n\nfunction getWeekStartsOn(locale: Locale): 0 | 1 | 2 | 3 | 4 | 5 | 6 {\n const w = locale.options?.weekStartsOn;\n if (w === undefined) return 1;\n return w as 0 | 1 | 2 | 3 | 4 | 5 | 6;\n}\n\n/** Meses abreviados (`LLL`) para que el `<select>` sea compacto dentro del popover. */\nfunction useMonthLabels(locale: Locale) {\n return React.useMemo(\n () => Array.from({ length: 12 }, (_, i) => format(new Date(2024, i, 1), \"LLL\", { locale })),\n [locale],\n );\n}\n\n/** Abreviatura del día en exactamente dos caracteres visibles (p. ej. lun → lu, Wed → We). */\nfunction weekdayTwoLetterLabel(abbrev: string): string {\n const graphemes = [...abbrev.normalize(\"NFC\")];\n if (graphemes.length <= 2) {\n return abbrev;\n }\n return graphemes.slice(0, 2).join(\"\");\n}\n\nfunction useWeekdayLabels(locale: Locale) {\n return React.useMemo(() => {\n const weekStartsOn = getWeekStartsOn(locale);\n const start = startOfWeek(new Date(2024, 0, 3), { weekStartsOn });\n return Array.from({ length: 7 }, (_, i) => {\n const abbrev = format(addDays(start, i), \"EEE\", { locale });\n return weekdayTwoLetterLabel(abbrev);\n });\n }, [locale]);\n}\n\nfunction getDaysInMonth(date: Date, weekStartsOn: 0 | 1 | 2 | 3 | 4 | 5 | 6) {\n const year = date.getFullYear();\n const month = date.getMonth();\n const lastDay = new Date(year, month + 1, 0);\n const daysInMonth = lastDay.getDate();\n const firstDay = new Date(year, month, 1);\n const startingDayOfWeek = firstDay.getDay();\n const offset = (startingDayOfWeek - weekStartsOn + 7) % 7;\n\n const days: (Date | null)[] = [];\n for (let i = 0; i < offset; i++) {\n days.push(null);\n }\n for (let day = 1; day <= daysInMonth; day++) {\n days.push(new Date(year, month, day));\n }\n return days;\n}\n\n/** Select nativo sin flecha del sistema: el chevron es un icono con margen fijo (padding fiable en todos los navegadores). */\nfunction DatePickerSelect({\n className,\n wrapperClassName,\n children,\n ...props\n}: React.ComponentProps<\"select\"> & { wrapperClassName?: string }) {\n return (\n <div className={cn(\"relative\", wrapperClassName)}>\n <select\n {...props}\n className={cn(\n \"h-9 w-full min-w-0 cursor-pointer appearance-none rounded-md border border-input bg-card py-0 pl-2 pr-9 text-left text-sm shadow-xs outline-none\",\n \"focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50\",\n \"disabled:cursor-not-allowed disabled:opacity-50\",\n className,\n )}\n >\n {children}\n </select>\n <ChevronDown\n className=\"pointer-events-none absolute right-2 top-1/2 size-4 -translate-y-1/2 shrink-0 text-muted-foreground opacity-80\"\n aria-hidden\n />\n </div>\n );\n}\n\nfunction DatePicker({\n value,\n onChange,\n placeholder = \"Seleccionar fecha\",\n disabled = false,\n className,\n locale = es,\n fromYear,\n toYear,\n}: DatePickerProps) {\n const [open, setOpen] = React.useState(false);\n const [currentMonth, setCurrentMonth] = React.useState(() => {\n const base = value ?? new Date();\n return new Date(base.getFullYear(), base.getMonth(), 1);\n });\n\n const monthLabels = useMonthLabels(locale);\n const weekdayLabels = useWeekdayLabels(locale);\n const weekStartsOn = getWeekStartsOn(locale);\n\n React.useEffect(() => {\n if (value) {\n setCurrentMonth(new Date(value.getFullYear(), value.getMonth(), 1));\n }\n }, [value]);\n\n const days = React.useMemo(\n () => getDaysInMonth(currentMonth, weekStartsOn),\n [currentMonth, weekStartsOn],\n );\n\n const yearOptions = React.useMemo(() => {\n const y = new Date().getFullYear();\n const from = fromYear ?? y - 100;\n const to = toYear ?? y + 10;\n const list: number[] = [];\n for (let i = from; i <= to; i++) {\n list.push(i);\n }\n return list;\n }, [fromYear, toYear]);\n\n const handleDateSelect = (date: Date) => {\n onChange?.(date);\n setOpen(false);\n };\n\n const goToPreviousMonth = () => {\n setCurrentMonth(new Date(currentMonth.getFullYear(), currentMonth.getMonth() - 1, 1));\n };\n\n const goToNextMonth = () => {\n setCurrentMonth(new Date(currentMonth.getFullYear(), currentMonth.getMonth() + 1, 1));\n };\n\n const setMonthFromSelect = (monthIndex: number) => {\n setCurrentMonth(new Date(currentMonth.getFullYear(), monthIndex, 1));\n };\n\n const setYearFromSelect = (year: number) => {\n setCurrentMonth(new Date(year, currentMonth.getMonth(), 1));\n };\n\n const isToday = (date: Date) => {\n const today = new Date();\n return (\n date.getFullYear() === today.getFullYear() &&\n date.getMonth() === today.getMonth() &&\n date.getDate() === today.getDate()\n );\n };\n\n const isSelected = (date: Date) => {\n if (!value) return false;\n return (\n date.getFullYear() === value.getFullYear() &&\n date.getMonth() === value.getMonth() &&\n date.getDate() === value.getDate()\n );\n };\n\n return (\n <Popover open={open} onOpenChange={setOpen}>\n <PopoverTrigger asChild>\n <Button\n variant=\"outline\"\n data-slot=\"date-picker\"\n className={cn(\n \"w-full justify-start text-left font-normal\",\n !value && \"text-muted-foreground\",\n className,\n )}\n disabled={disabled}\n >\n <CalendarIcon className=\"mr-2 h-4 w-4 shrink-0\" />\n {value ? format(value, \"P\", { locale }) : placeholder}\n </Button>\n </PopoverTrigger>\n <PopoverContent className=\"w-auto bg-white p-0 dark:bg-card\" align=\"start\">\n <div className=\"p-3\">\n <div className=\"mb-3 flex flex-wrap items-center justify-center gap-1.5\">\n <Button\n type=\"button\"\n variant=\"outline\"\n size=\"sm\"\n onClick={goToPreviousMonth}\n className=\"h-9 w-9 shrink-0 p-0\"\n aria-label={locale.code?.startsWith(\"es\") ? \"Mes anterior\" : \"Previous month\"}\n >\n <ChevronLeft className=\"h-4 w-4\" />\n </Button>\n <DatePickerSelect\n wrapperClassName=\"w-[6.75rem] shrink-0\"\n value={currentMonth.getMonth()}\n onChange={(e) => setMonthFromSelect(Number(e.target.value))}\n aria-label={locale.code?.startsWith(\"es\") ? \"Mes\" : \"Month\"}\n >\n {monthLabels.map((label, i) => (\n <option key={label} value={i}>\n {label}\n </option>\n ))}\n </DatePickerSelect>\n <DatePickerSelect\n wrapperClassName=\"w-[5.5rem] shrink-0\"\n className=\"tabular-nums text-center\"\n value={currentMonth.getFullYear()}\n onChange={(e) => setYearFromSelect(Number(e.target.value))}\n aria-label={locale.code?.startsWith(\"es\") ? \"Año\" : \"Year\"}\n >\n {yearOptions.map((y) => (\n <option key={y} value={y}>\n {y}\n </option>\n ))}\n </DatePickerSelect>\n <Button\n type=\"button\"\n variant=\"outline\"\n size=\"sm\"\n onClick={goToNextMonth}\n className=\"h-9 w-9 shrink-0 p-0\"\n aria-label={locale.code?.startsWith(\"es\") ? \"Mes siguiente\" : \"Next month\"}\n >\n <ChevronRight className=\"h-4 w-4\" />\n </Button>\n </div>\n\n <div className=\"mb-2 grid grid-cols-7 gap-1\">\n {weekdayLabels.map((day, i) => (\n <div\n key={i}\n className=\"px-0.5 py-2 text-center text-sm font-medium capitalize leading-tight text-muted-foreground\"\n >\n {day}\n </div>\n ))}\n </div>\n\n <div className=\"grid grid-cols-7 gap-1\">\n {days.map((day, index) => (\n <div key={index} className=\"flex h-9 w-9 items-center justify-center\">\n {day ? (\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"sm\"\n className={cn(\n \"h-9 w-9 p-0 font-normal\",\n isSelected(day) &&\n \"bg-primary text-primary-foreground hover:bg-primary-dark hover:text-primary-foreground\",\n isToday(day) &&\n !isSelected(day) &&\n \"bg-accent text-accent-foreground hover:bg-accent/80 hover:text-accent-foreground\",\n !isSelected(day) && !isToday(day) && \"hover:bg-muted hover:text-foreground\",\n )}\n onClick={() => handleDateSelect(day)}\n >\n {day.getDate()}\n </Button>\n ) :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A,SAAS,MAAM,iBAAiB,GAAG;AAAA,UAElC,cAAI,QAAQ;AAAA;AAAA,MACf,IAEA,4CAAC,SAAI,WAAU,WAAU,KApBnB,KAsBV,CACD,GACH;AAAA,OACF,GACF;AAAA,KACF;AAEJ;","names":["CalendarIcon"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { Locale } from 'date-fns';
|
|
2
3
|
|
|
3
4
|
interface DatePickerProps {
|
|
4
5
|
value?: Date;
|
|
@@ -6,7 +7,16 @@ interface DatePickerProps {
|
|
|
6
7
|
placeholder?: string;
|
|
7
8
|
disabled?: boolean;
|
|
8
9
|
className?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Locale de `date-fns` para nombres de mes/día y formato de la fecha en el botón.
|
|
12
|
+
* Por defecto español (`es`).
|
|
13
|
+
*/
|
|
14
|
+
locale?: Locale;
|
|
15
|
+
/** Año mínimo en el selector (inclusive). */
|
|
16
|
+
fromYear?: number;
|
|
17
|
+
/** Año máximo en el selector (inclusive). */
|
|
18
|
+
toYear?: number;
|
|
9
19
|
}
|
|
10
|
-
declare function DatePicker({ value, onChange, placeholder, disabled, className, }: DatePickerProps): react_jsx_runtime.JSX.Element;
|
|
20
|
+
declare function DatePicker({ value, onChange, placeholder, disabled, className, locale, fromYear, toYear, }: DatePickerProps): react_jsx_runtime.JSX.Element;
|
|
11
21
|
|
|
12
22
|
export { DatePicker, type DatePickerProps };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { Locale } from 'date-fns';
|
|
2
3
|
|
|
3
4
|
interface DatePickerProps {
|
|
4
5
|
value?: Date;
|
|
@@ -6,7 +7,16 @@ interface DatePickerProps {
|
|
|
6
7
|
placeholder?: string;
|
|
7
8
|
disabled?: boolean;
|
|
8
9
|
className?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Locale de `date-fns` para nombres de mes/día y formato de la fecha en el botón.
|
|
12
|
+
* Por defecto español (`es`).
|
|
13
|
+
*/
|
|
14
|
+
locale?: Locale;
|
|
15
|
+
/** Año mínimo en el selector (inclusive). */
|
|
16
|
+
fromYear?: number;
|
|
17
|
+
/** Año máximo en el selector (inclusive). */
|
|
18
|
+
toYear?: number;
|
|
9
19
|
}
|
|
10
|
-
declare function DatePicker({ value, onChange, placeholder, disabled, className, }: DatePickerProps): react_jsx_runtime.JSX.Element;
|
|
20
|
+
declare function DatePicker({ value, onChange, placeholder, disabled, className, locale, fromYear, toYear, }: DatePickerProps): react_jsx_runtime.JSX.Element;
|
|
11
21
|
|
|
12
22
|
export { DatePicker, type DatePickerProps };
|
|
@@ -1,70 +1,151 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import * as React from "react";
|
|
4
|
-
import { format } from "date-fns";
|
|
4
|
+
import { addDays, format, startOfWeek } from "date-fns";
|
|
5
5
|
import { es } from "date-fns/locale";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
Calendar as CalendarIcon,
|
|
8
|
+
ChevronDown,
|
|
9
|
+
ChevronLeft,
|
|
10
|
+
ChevronRight
|
|
11
|
+
} from "lucide-react";
|
|
7
12
|
import { cn } from "../../../lib/utils";
|
|
8
13
|
import { Button } from "../button";
|
|
9
14
|
import { Popover, PopoverContent, PopoverTrigger } from "../popover";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
15
|
+
function getWeekStartsOn(locale) {
|
|
16
|
+
const w = locale.options?.weekStartsOn;
|
|
17
|
+
if (w === void 0) return 1;
|
|
18
|
+
return w;
|
|
19
|
+
}
|
|
20
|
+
function useMonthLabels(locale) {
|
|
21
|
+
return React.useMemo(
|
|
22
|
+
() => Array.from({ length: 12 }, (_, i) => format(new Date(2024, i, 1), "LLL", { locale })),
|
|
23
|
+
[locale]
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
function weekdayTwoLetterLabel(abbrev) {
|
|
27
|
+
const graphemes = [...abbrev.normalize("NFC")];
|
|
28
|
+
if (graphemes.length <= 2) {
|
|
29
|
+
return abbrev;
|
|
30
|
+
}
|
|
31
|
+
return graphemes.slice(0, 2).join("");
|
|
32
|
+
}
|
|
33
|
+
function useWeekdayLabels(locale) {
|
|
34
|
+
return React.useMemo(() => {
|
|
35
|
+
const weekStartsOn = getWeekStartsOn(locale);
|
|
36
|
+
const start = startOfWeek(new Date(2024, 0, 3), { weekStartsOn });
|
|
37
|
+
return Array.from({ length: 7 }, (_, i) => {
|
|
38
|
+
const abbrev = format(addDays(start, i), "EEE", { locale });
|
|
39
|
+
return weekdayTwoLetterLabel(abbrev);
|
|
40
|
+
});
|
|
41
|
+
}, [locale]);
|
|
42
|
+
}
|
|
43
|
+
function getDaysInMonth(date, weekStartsOn) {
|
|
44
|
+
const year = date.getFullYear();
|
|
45
|
+
const month = date.getMonth();
|
|
46
|
+
const lastDay = new Date(year, month + 1, 0);
|
|
47
|
+
const daysInMonth = lastDay.getDate();
|
|
48
|
+
const firstDay = new Date(year, month, 1);
|
|
49
|
+
const startingDayOfWeek = firstDay.getDay();
|
|
50
|
+
const offset = (startingDayOfWeek - weekStartsOn + 7) % 7;
|
|
51
|
+
const days = [];
|
|
52
|
+
for (let i = 0; i < offset; i++) {
|
|
53
|
+
days.push(null);
|
|
54
|
+
}
|
|
55
|
+
for (let day = 1; day <= daysInMonth; day++) {
|
|
56
|
+
days.push(new Date(year, month, day));
|
|
57
|
+
}
|
|
58
|
+
return days;
|
|
59
|
+
}
|
|
60
|
+
function DatePickerSelect({
|
|
61
|
+
className,
|
|
62
|
+
wrapperClassName,
|
|
63
|
+
children,
|
|
64
|
+
...props
|
|
65
|
+
}) {
|
|
66
|
+
return /* @__PURE__ */ jsxs("div", { className: cn("relative", wrapperClassName), children: [
|
|
67
|
+
/* @__PURE__ */ jsx(
|
|
68
|
+
"select",
|
|
69
|
+
{
|
|
70
|
+
...props,
|
|
71
|
+
className: cn(
|
|
72
|
+
"h-9 w-full min-w-0 cursor-pointer appearance-none rounded-md border border-input bg-card py-0 pl-2 pr-9 text-left text-sm shadow-xs outline-none",
|
|
73
|
+
"focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50",
|
|
74
|
+
"disabled:cursor-not-allowed disabled:opacity-50",
|
|
75
|
+
className
|
|
76
|
+
),
|
|
77
|
+
children
|
|
78
|
+
}
|
|
79
|
+
),
|
|
80
|
+
/* @__PURE__ */ jsx(
|
|
81
|
+
ChevronDown,
|
|
82
|
+
{
|
|
83
|
+
className: "pointer-events-none absolute right-2 top-1/2 size-4 -translate-y-1/2 shrink-0 text-muted-foreground opacity-80",
|
|
84
|
+
"aria-hidden": true
|
|
85
|
+
}
|
|
86
|
+
)
|
|
87
|
+
] });
|
|
88
|
+
}
|
|
25
89
|
function DatePicker({
|
|
26
90
|
value,
|
|
27
91
|
onChange,
|
|
28
92
|
placeholder = "Seleccionar fecha",
|
|
29
93
|
disabled = false,
|
|
30
|
-
className
|
|
94
|
+
className,
|
|
95
|
+
locale = es,
|
|
96
|
+
fromYear,
|
|
97
|
+
toYear
|
|
31
98
|
}) {
|
|
32
99
|
const [open, setOpen] = React.useState(false);
|
|
33
|
-
const [currentMonth, setCurrentMonth] = React.useState(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
days2.push(null);
|
|
100
|
+
const [currentMonth, setCurrentMonth] = React.useState(() => {
|
|
101
|
+
const base = value ?? /* @__PURE__ */ new Date();
|
|
102
|
+
return new Date(base.getFullYear(), base.getMonth(), 1);
|
|
103
|
+
});
|
|
104
|
+
const monthLabels = useMonthLabels(locale);
|
|
105
|
+
const weekdayLabels = useWeekdayLabels(locale);
|
|
106
|
+
const weekStartsOn = getWeekStartsOn(locale);
|
|
107
|
+
React.useEffect(() => {
|
|
108
|
+
if (value) {
|
|
109
|
+
setCurrentMonth(new Date(value.getFullYear(), value.getMonth(), 1));
|
|
44
110
|
}
|
|
45
|
-
|
|
46
|
-
|
|
111
|
+
}, [value]);
|
|
112
|
+
const days = React.useMemo(
|
|
113
|
+
() => getDaysInMonth(currentMonth, weekStartsOn),
|
|
114
|
+
[currentMonth, weekStartsOn]
|
|
115
|
+
);
|
|
116
|
+
const yearOptions = React.useMemo(() => {
|
|
117
|
+
const y = (/* @__PURE__ */ new Date()).getFullYear();
|
|
118
|
+
const from = fromYear ?? y - 100;
|
|
119
|
+
const to = toYear ?? y + 10;
|
|
120
|
+
const list = [];
|
|
121
|
+
for (let i = from; i <= to; i++) {
|
|
122
|
+
list.push(i);
|
|
47
123
|
}
|
|
48
|
-
return
|
|
49
|
-
};
|
|
50
|
-
const days = getDaysInMonth(currentMonth);
|
|
124
|
+
return list;
|
|
125
|
+
}, [fromYear, toYear]);
|
|
51
126
|
const handleDateSelect = (date) => {
|
|
52
127
|
onChange?.(date);
|
|
53
128
|
setOpen(false);
|
|
54
129
|
};
|
|
55
130
|
const goToPreviousMonth = () => {
|
|
56
|
-
setCurrentMonth(new Date(currentMonth.getFullYear(), currentMonth.getMonth() - 1));
|
|
131
|
+
setCurrentMonth(new Date(currentMonth.getFullYear(), currentMonth.getMonth() - 1, 1));
|
|
57
132
|
};
|
|
58
133
|
const goToNextMonth = () => {
|
|
59
|
-
setCurrentMonth(new Date(currentMonth.getFullYear(), currentMonth.getMonth() + 1));
|
|
134
|
+
setCurrentMonth(new Date(currentMonth.getFullYear(), currentMonth.getMonth() + 1, 1));
|
|
135
|
+
};
|
|
136
|
+
const setMonthFromSelect = (monthIndex) => {
|
|
137
|
+
setCurrentMonth(new Date(currentMonth.getFullYear(), monthIndex, 1));
|
|
138
|
+
};
|
|
139
|
+
const setYearFromSelect = (year) => {
|
|
140
|
+
setCurrentMonth(new Date(year, currentMonth.getMonth(), 1));
|
|
60
141
|
};
|
|
61
142
|
const isToday = (date) => {
|
|
62
143
|
const today = /* @__PURE__ */ new Date();
|
|
63
|
-
return date.
|
|
144
|
+
return date.getFullYear() === today.getFullYear() && date.getMonth() === today.getMonth() && date.getDate() === today.getDate();
|
|
64
145
|
};
|
|
65
146
|
const isSelected = (date) => {
|
|
66
147
|
if (!value) return false;
|
|
67
|
-
return date.
|
|
148
|
+
return date.getFullYear() === value.getFullYear() && date.getMonth() === value.getMonth() && date.getDate() === value.getDate();
|
|
68
149
|
};
|
|
69
150
|
return /* @__PURE__ */ jsxs(Popover, { open, onOpenChange: setOpen, children: [
|
|
70
151
|
/* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(
|
|
@@ -79,32 +160,78 @@ function DatePicker({
|
|
|
79
160
|
),
|
|
80
161
|
disabled,
|
|
81
162
|
children: [
|
|
82
|
-
/* @__PURE__ */ jsx(CalendarIcon, { className: "mr-2 h-4 w-4" }),
|
|
83
|
-
value ? format(value, "
|
|
163
|
+
/* @__PURE__ */ jsx(CalendarIcon, { className: "mr-2 h-4 w-4 shrink-0" }),
|
|
164
|
+
value ? format(value, "P", { locale }) : placeholder
|
|
84
165
|
]
|
|
85
166
|
}
|
|
86
167
|
) }),
|
|
87
|
-
/* @__PURE__ */ jsx(PopoverContent, { className: "w-auto p-0", align: "start", children: /* @__PURE__ */ jsxs("div", { className: "p-3", children: [
|
|
88
|
-
/* @__PURE__ */ jsxs("div", { className: "mb-
|
|
89
|
-
/* @__PURE__ */ jsx(
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
168
|
+
/* @__PURE__ */ jsx(PopoverContent, { className: "w-auto bg-white p-0 dark:bg-card", align: "start", children: /* @__PURE__ */ jsxs("div", { className: "p-3", children: [
|
|
169
|
+
/* @__PURE__ */ jsxs("div", { className: "mb-3 flex flex-wrap items-center justify-center gap-1.5", children: [
|
|
170
|
+
/* @__PURE__ */ jsx(
|
|
171
|
+
Button,
|
|
172
|
+
{
|
|
173
|
+
type: "button",
|
|
174
|
+
variant: "outline",
|
|
175
|
+
size: "sm",
|
|
176
|
+
onClick: goToPreviousMonth,
|
|
177
|
+
className: "h-9 w-9 shrink-0 p-0",
|
|
178
|
+
"aria-label": locale.code?.startsWith("es") ? "Mes anterior" : "Previous month",
|
|
179
|
+
children: /* @__PURE__ */ jsx(ChevronLeft, { className: "h-4 w-4" })
|
|
180
|
+
}
|
|
181
|
+
),
|
|
182
|
+
/* @__PURE__ */ jsx(
|
|
183
|
+
DatePickerSelect,
|
|
184
|
+
{
|
|
185
|
+
wrapperClassName: "w-[6.75rem] shrink-0",
|
|
186
|
+
value: currentMonth.getMonth(),
|
|
187
|
+
onChange: (e) => setMonthFromSelect(Number(e.target.value)),
|
|
188
|
+
"aria-label": locale.code?.startsWith("es") ? "Mes" : "Month",
|
|
189
|
+
children: monthLabels.map((label, i) => /* @__PURE__ */ jsx("option", { value: i, children: label }, label))
|
|
190
|
+
}
|
|
191
|
+
),
|
|
192
|
+
/* @__PURE__ */ jsx(
|
|
193
|
+
DatePickerSelect,
|
|
194
|
+
{
|
|
195
|
+
wrapperClassName: "w-[5.5rem] shrink-0",
|
|
196
|
+
className: "tabular-nums text-center",
|
|
197
|
+
value: currentMonth.getFullYear(),
|
|
198
|
+
onChange: (e) => setYearFromSelect(Number(e.target.value)),
|
|
199
|
+
"aria-label": locale.code?.startsWith("es") ? "A\xF1o" : "Year",
|
|
200
|
+
children: yearOptions.map((y) => /* @__PURE__ */ jsx("option", { value: y, children: y }, y))
|
|
201
|
+
}
|
|
202
|
+
),
|
|
203
|
+
/* @__PURE__ */ jsx(
|
|
204
|
+
Button,
|
|
205
|
+
{
|
|
206
|
+
type: "button",
|
|
207
|
+
variant: "outline",
|
|
208
|
+
size: "sm",
|
|
209
|
+
onClick: goToNextMonth,
|
|
210
|
+
className: "h-9 w-9 shrink-0 p-0",
|
|
211
|
+
"aria-label": locale.code?.startsWith("es") ? "Mes siguiente" : "Next month",
|
|
212
|
+
children: /* @__PURE__ */ jsx(ChevronRight, { className: "h-4 w-4" })
|
|
213
|
+
}
|
|
214
|
+
)
|
|
96
215
|
] }),
|
|
97
|
-
/* @__PURE__ */ jsx("div", { className: "mb-2 grid grid-cols-7 gap-1", children:
|
|
216
|
+
/* @__PURE__ */ jsx("div", { className: "mb-2 grid grid-cols-7 gap-1", children: weekdayLabels.map((day, i) => /* @__PURE__ */ jsx(
|
|
217
|
+
"div",
|
|
218
|
+
{
|
|
219
|
+
className: "px-0.5 py-2 text-center text-sm font-medium capitalize leading-tight text-muted-foreground",
|
|
220
|
+
children: day
|
|
221
|
+
},
|
|
222
|
+
i
|
|
223
|
+
)) }),
|
|
98
224
|
/* @__PURE__ */ jsx("div", { className: "grid grid-cols-7 gap-1", children: days.map((day, index) => /* @__PURE__ */ jsx("div", { className: "flex h-9 w-9 items-center justify-center", children: day ? /* @__PURE__ */ jsx(
|
|
99
225
|
Button,
|
|
100
226
|
{
|
|
227
|
+
type: "button",
|
|
101
228
|
variant: "ghost",
|
|
102
229
|
size: "sm",
|
|
103
230
|
className: cn(
|
|
104
231
|
"h-9 w-9 p-0 font-normal",
|
|
105
|
-
isSelected(day) && "bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground",
|
|
106
|
-
isToday(day) && !isSelected(day) && "bg-accent text-accent-foreground",
|
|
107
|
-
"hover:bg-muted"
|
|
232
|
+
isSelected(day) && "bg-primary text-primary-foreground hover:bg-primary-dark hover:text-primary-foreground",
|
|
233
|
+
isToday(day) && !isSelected(day) && "bg-accent text-accent-foreground hover:bg-accent/80 hover:text-accent-foreground",
|
|
234
|
+
!isSelected(day) && !isToday(day) && "hover:bg-muted hover:text-foreground"
|
|
108
235
|
),
|
|
109
236
|
onClick: () => handleDateSelect(day),
|
|
110
237
|
children: day.getDate()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/ui/date-picker/date-picker.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { format } from \"date-fns\";\nimport { es } from \"date-fns/locale\";\nimport { Calendar as CalendarIcon, ChevronLeft, ChevronRight } from \"lucide-react\";\n\nimport { cn } from \"../../../lib/utils\";\nimport { Button } from \"../button\";\nimport { Popover, PopoverContent, PopoverTrigger } from \"../popover\";\n\nexport interface DatePickerProps {\n value?: Date;\n onChange?: (date: Date | undefined) => void;\n placeholder?: string;\n disabled?: boolean;\n className?: string;\n}\n\nconst monthNames = [\n \"Enero\",\n \"Febrero\",\n \"Marzo\",\n \"Abril\",\n \"Mayo\",\n \"Junio\",\n \"Julio\",\n \"Agosto\",\n \"Septiembre\",\n \"Octubre\",\n \"Noviembre\",\n \"Diciembre\",\n];\nconst dayNames = [\"Do\", \"Lu\", \"Ma\", \"Mi\", \"Ju\", \"Vi\", \"Sá\"];\n\nfunction DatePicker({\n value,\n onChange,\n placeholder = \"Seleccionar fecha\",\n disabled = false,\n className,\n}: DatePickerProps) {\n const [open, setOpen] = React.useState(false);\n const [currentMonth, setCurrentMonth] = React.useState(value || new Date());\n\n const getDaysInMonth = (date: Date) => {\n const year = date.getFullYear();\n const month = date.getMonth();\n const firstDay = new Date(year, month, 1);\n const lastDay = new Date(year, month + 1, 0);\n const daysInMonth = lastDay.getDate();\n const startingDayOfWeek = firstDay.getDay();\n\n const days: (Date | null)[] = [];\n\n for (let i = 0; i < startingDayOfWeek; i++) {\n days.push(null);\n }\n\n for (let day = 1; day <= daysInMonth; day++) {\n days.push(new Date(Date.UTC(year, month, day)));\n }\n\n return days;\n };\n\n const days = getDaysInMonth(currentMonth);\n\n const handleDateSelect = (date: Date) => {\n onChange?.(date);\n setOpen(false);\n };\n\n const goToPreviousMonth = () => {\n setCurrentMonth(new Date(currentMonth.getFullYear(), currentMonth.getMonth() - 1));\n };\n\n const goToNextMonth = () => {\n setCurrentMonth(new Date(currentMonth.getFullYear(), currentMonth.getMonth() + 1));\n };\n\n const isToday = (date: Date) => {\n const today = new Date();\n return (\n date.getUTCFullYear() === today.getFullYear() &&\n date.getUTCMonth() === today.getMonth() &&\n date.getUTCDate() === today.getDate()\n );\n };\n\n const isSelected = (date: Date) => {\n if (!value) return false;\n return (\n date.getUTCFullYear() === value.getFullYear() &&\n date.getUTCMonth() === value.getMonth() &&\n date.getUTCDate() === value.getDate()\n );\n };\n\n return (\n <Popover open={open} onOpenChange={setOpen}>\n <PopoverTrigger asChild>\n <Button\n variant=\"outline\"\n data-slot=\"date-picker\"\n className={cn(\n \"w-full justify-start text-left font-normal\",\n !value && \"text-muted-foreground\",\n className,\n )}\n disabled={disabled}\n >\n <CalendarIcon className=\"mr-2 h-4 w-4\" />\n {value ? format(value, \"dd/MM/yyyy\", { locale: es }) : placeholder}\n </Button>\n </PopoverTrigger>\n <PopoverContent className=\"w-auto p-0\" align=\"start\">\n <div className=\"p-3\">\n <div className=\"mb-4 flex items-center justify-between\">\n <Button variant=\"outline\" size=\"sm\" onClick={goToPreviousMonth} className=\"h-7 w-7 p-0\">\n <ChevronLeft className=\"h-4 w-4\" />\n </Button>\n <div className=\"text-sm font-medium\">\n {monthNames[currentMonth.getMonth()]} {currentMonth.getFullYear()}\n </div>\n <Button variant=\"outline\" size=\"sm\" onClick={goToNextMonth} className=\"h-7 w-7 p-0\">\n <ChevronRight className=\"h-4 w-4\" />\n </Button>\n </div>\n\n <div className=\"mb-2 grid grid-cols-7 gap-1\">\n {dayNames.map((day) => (\n <div key={day} className=\"py-2 text-center text-xs font-medium text-muted-foreground\">\n {day}\n </div>\n ))}\n </div>\n\n <div className=\"grid grid-cols-7 gap-1\">\n {days.map((day, index) => (\n <div key={index} className=\"flex h-9 w-9 items-center justify-center\">\n {day ? (\n <Button\n variant=\"ghost\"\n size=\"sm\"\n className={cn(\n \"h-9 w-9 p-0 font-normal\",\n isSelected(day) &&\n \"bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground\",\n isToday(day) && !isSelected(day) && \"bg-accent text-accent-foreground\",\n \"hover:bg-muted\",\n )}\n onClick={() => handleDateSelect(day)}\n >\n {day.getDate()}\n </Button>\n ) : (\n <div className=\"h-9 w-9\" />\n )}\n </div>\n ))}\n </div>\n </div>\n </PopoverContent>\n </Popover>\n );\n}\n\nexport { DatePicker };\n"],"mappings":";AAsGQ,SAUE,KAVF;AApGR,YAAY,WAAW;AACvB,SAAS,cAAc;AACvB,SAAS,UAAU;AACnB,SAAS,YAAY,cAAc,aAAa,oBAAoB;AAEpE,SAAS,UAAU;AACnB,SAAS,cAAc;AACvB,SAAS,SAAS,gBAAgB,sBAAsB;AAUxD,MAAM,aAAa;AAAA,EACjB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AACA,MAAM,WAAW,CAAC,MAAM,MAAM,MAAM,MAAM,MAAM,MAAM,OAAI;AAE1D,SAAS,WAAW;AAAA,EAClB;AAAA,EACA;AAAA,EACA,cAAc;AAAA,EACd,WAAW;AAAA,EACX;AACF,GAAoB;AAClB,QAAM,CAAC,MAAM,OAAO,IAAI,MAAM,SAAS,KAAK;AAC5C,QAAM,CAAC,cAAc,eAAe,IAAI,MAAM,SAAS,SAAS,oBAAI,KAAK,CAAC;AAE1E,QAAM,iBAAiB,CAAC,SAAe;AACrC,UAAM,OAAO,KAAK,YAAY;AAC9B,UAAM,QAAQ,KAAK,SAAS;AAC5B,UAAM,WAAW,IAAI,KAAK,MAAM,OAAO,CAAC;AACxC,UAAM,UAAU,IAAI,KAAK,MAAM,QAAQ,GAAG,CAAC;AAC3C,UAAM,cAAc,QAAQ,QAAQ;AACpC,UAAM,oBAAoB,SAAS,OAAO;AAE1C,UAAMA,QAAwB,CAAC;AAE/B,aAAS,I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O,OAAO,cAAc,EAAE,QAAQ,GAAG,CAAC,IAAI;AAAA;AAAA;AAAA,IACzD,GACF;AAAA,IACA,oBAAC,kBAAe,WAAU,cAAa,OAAM,SAC3C,+BAAC,SAAI,WAAU,OACb;AAAA,2BAAC,SAAI,WAAU,0CACb;AAAA,4BAAC,UAAO,SAAQ,WAAU,MAAK,MAAK,SAAS,mBAAmB,WAAU,eACxE,8BAAC,eAAY,WAAU,WAAU,GACnC;AAAA,QACA,qBAAC,SAAI,WAAU,uBACZ;AAAA,qBAAW,aAAa,SAAS,CAAC;AAAA,UAAE;AAAA,UAAE,aAAa,YAAY;AAAA,WAClE;AAAA,QACA,oBAAC,UAAO,SAAQ,WAAU,MAAK,MAAK,SAAS,eAAe,WAAU,eACpE,8BAAC,gBAAa,WAAU,WAAU,GACpC;AAAA,SACF;AAAA,MAEA,oBAAC,SAAI,WAAU,+BACZ,mBAAS,IAAI,CAAC,QACb,oBAAC,SAAc,WAAU,8DACtB,iBADO,GAEV,CACD,GACH;AAAA,MAEA,oBAAC,SAAI,WAAU,0BACZ,eAAK,IAAI,CAAC,KAAK,UACd,oBAAC,SAAgB,WAAU,4CACxB,gBACC;AAAA,QAAC;AAAA;AAAA,UACC,SAAQ;AAAA,UACR,MAAK;AAAA,UACL,WAAW;AAAA,YACT;AAAA,YACA,WAAW,GAAG,KACZ;AAAA,YACF,QAAQ,GAAG,KAAK,CAAC,WAAW,GAAG,KAAK;AAAA,YACpC;AAAA,UACF;AAAA,UACA,SAAS,MAAM,iBAAiB,GAAG;AAAA,UAElC,cAAI,QAAQ;AAAA;AAAA,MACf,IAEA,oBAAC,SAAI,WAAU,WAAU,KAjBnB,KAmBV,CACD,GACH;AAAA,OACF,GACF;AAAA,KACF;AAEJ;","names":["days"]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/ui/date-picker/date-picker.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { addDays, format, startOfWeek } from \"date-fns\";\nimport type { Locale } from \"date-fns\";\nimport { es } from \"date-fns/locale\";\nimport {\n Calendar as CalendarIcon,\n ChevronDown,\n ChevronLeft,\n ChevronRight,\n} from \"lucide-react\";\n\nimport { cn } from \"../../../lib/utils\";\nimport { Button } from \"../button\";\nimport { Popover, PopoverContent, PopoverTrigger } from \"../popover\";\n\nexport interface DatePickerProps {\n value?: Date;\n onChange?: (date: Date | undefined) => void;\n placeholder?: string;\n disabled?: boolean;\n className?: string;\n /**\n * Locale de `date-fns` para nombres de mes/día y formato de la fecha en el botón.\n * Por defecto español (`es`).\n */\n locale?: Locale;\n /** Año mínimo en el selector (inclusive). */\n fromYear?: number;\n /** Año máximo en el selector (inclusive). */\n toYear?: number;\n}\n\nfunction getWeekStartsOn(locale: Locale): 0 | 1 | 2 | 3 | 4 | 5 | 6 {\n const w = locale.options?.weekStartsOn;\n if (w === undefined) return 1;\n return w as 0 | 1 | 2 | 3 | 4 | 5 | 6;\n}\n\n/** Meses abreviados (`LLL`) para que el `<select>` sea compacto dentro del popover. */\nfunction useMonthLabels(locale: Locale) {\n return React.useMemo(\n () => Array.from({ length: 12 }, (_, i) => format(new Date(2024, i, 1), \"LLL\", { locale })),\n [locale],\n );\n}\n\n/** Abreviatura del día en exactamente dos caracteres visibles (p. ej. lun → lu, Wed → We). */\nfunction weekdayTwoLetterLabel(abbrev: string): string {\n const graphemes = [...abbrev.normalize(\"NFC\")];\n if (graphemes.length <= 2) {\n return abbrev;\n }\n return graphemes.slice(0, 2).join(\"\");\n}\n\nfunction useWeekdayLabels(locale: Locale) {\n return React.useMemo(() => {\n const weekStartsOn = getWeekStartsOn(locale);\n const start = startOfWeek(new Date(2024, 0, 3), { weekStartsOn });\n return Array.from({ length: 7 }, (_, i) => {\n const abbrev = format(addDays(start, i), \"EEE\", { locale });\n return weekdayTwoLetterLabel(abbrev);\n });\n }, [locale]);\n}\n\nfunction getDaysInMonth(date: Date, weekStartsOn: 0 | 1 | 2 | 3 | 4 | 5 | 6) {\n const year = date.getFullYear();\n const month = date.getMonth();\n const lastDay = new Date(year, month + 1, 0);\n const daysInMonth = lastDay.getDate();\n const firstDay = new Date(year, month, 1);\n const startingDayOfWeek = firstDay.getDay();\n const offset = (startingDayOfWeek - weekStartsOn + 7) % 7;\n\n const days: (Date | null)[] = [];\n for (let i = 0; i < offset; i++) {\n days.push(null);\n }\n for (let day = 1; day <= daysInMonth; day++) {\n days.push(new Date(year, month, day));\n }\n return days;\n}\n\n/** Select nativo sin flecha del sistema: el chevron es un icono con margen fijo (padding fiable en todos los navegadores). */\nfunction DatePickerSelect({\n className,\n wrapperClassName,\n children,\n ...props\n}: React.ComponentProps<\"select\"> & { wrapperClassName?: string }) {\n return (\n <div className={cn(\"relative\", wrapperClassName)}>\n <select\n {...props}\n className={cn(\n \"h-9 w-full min-w-0 cursor-pointer appearance-none rounded-md border border-input bg-card py-0 pl-2 pr-9 text-left text-sm shadow-xs outline-none\",\n \"focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50\",\n \"disabled:cursor-not-allowed disabled:opacity-50\",\n className,\n )}\n >\n {children}\n </select>\n <ChevronDown\n className=\"pointer-events-none absolute right-2 top-1/2 size-4 -translate-y-1/2 shrink-0 text-muted-foreground opacity-80\"\n aria-hidden\n />\n </div>\n );\n}\n\nfunction DatePicker({\n value,\n onChange,\n placeholder = \"Seleccionar fecha\",\n disabled = false,\n className,\n locale = es,\n fromYear,\n toYear,\n}: DatePickerProps) {\n const [open, setOpen] = React.useState(false);\n const [currentMonth, setCurrentMonth] = React.useState(() => {\n const base = value ?? new Date();\n return new Date(base.getFullYear(), base.getMonth(), 1);\n });\n\n const monthLabels = useMonthLabels(locale);\n const weekdayLabels = useWeekdayLabels(locale);\n const weekStartsOn = getWeekStartsOn(locale);\n\n React.useEffect(() => {\n if (value) {\n setCurrentMonth(new Date(value.getFullYear(), value.getMonth(), 1));\n }\n }, [value]);\n\n const days = React.useMemo(\n () => getDaysInMonth(currentMonth, weekStartsOn),\n [currentMonth, weekStartsOn],\n );\n\n const yearOptions = React.useMemo(() => {\n const y = new Date().getFullYear();\n const from = fromYear ?? y - 100;\n const to = toYear ?? y + 10;\n const list: number[] = [];\n for (let i = from; i <= to; i++) {\n list.push(i);\n }\n return list;\n }, [fromYear, toYear]);\n\n const handleDateSelect = (date: Date) => {\n onChange?.(date);\n setOpen(false);\n };\n\n const goToPreviousMonth = () => {\n setCurrentMonth(new Date(currentMonth.getFullYear(), currentMonth.getMonth() - 1, 1));\n };\n\n const goToNextMonth = () => {\n setCurrentMonth(new Date(currentMonth.getFullYear(), currentMonth.getMonth() + 1, 1));\n };\n\n const setMonthFromSelect = (monthIndex: number) => {\n setCurrentMonth(new Date(currentMonth.getFullYear(), monthIndex, 1));\n };\n\n const setYearFromSelect = (year: number) => {\n setCurrentMonth(new Date(year, currentMonth.getMonth(), 1));\n };\n\n const isToday = (date: Date) => {\n const today = new Date();\n return (\n date.getFullYear() === today.getFullYear() &&\n date.getMonth() === today.getMonth() &&\n date.getDate() === today.getDate()\n );\n };\n\n const isSelected = (date: Date) => {\n if (!value) return false;\n return (\n date.getFullYear() === value.getFullYear() &&\n date.getMonth() === value.getMonth() &&\n date.getDate() === value.getDate()\n );\n };\n\n return (\n <Popover open={open} onOpenChange={setOpen}>\n <PopoverTrigger asChild>\n <Button\n variant=\"outline\"\n data-slot=\"date-picker\"\n className={cn(\n \"w-full justify-start text-left font-normal\",\n !value && \"text-muted-foreground\",\n className,\n )}\n disabled={disabled}\n >\n <CalendarIcon className=\"mr-2 h-4 w-4 shrink-0\" />\n {value ? format(value, \"P\", { locale }) : placeholder}\n </Button>\n </PopoverTrigger>\n <PopoverContent className=\"w-auto bg-white p-0 dark:bg-card\" align=\"start\">\n <div className=\"p-3\">\n <div className=\"mb-3 flex flex-wrap items-center justify-center gap-1.5\">\n <Button\n type=\"button\"\n variant=\"outline\"\n size=\"sm\"\n onClick={goToPreviousMonth}\n className=\"h-9 w-9 shrink-0 p-0\"\n aria-label={locale.code?.startsWith(\"es\") ? \"Mes anterior\" : \"Previous month\"}\n >\n <ChevronLeft className=\"h-4 w-4\" />\n </Button>\n <DatePickerSelect\n wrapperClassName=\"w-[6.75rem] shrink-0\"\n value={currentMonth.getMonth()}\n onChange={(e) => setMonthFromSelect(Number(e.target.value))}\n aria-label={locale.code?.startsWith(\"es\") ? \"Mes\" : \"Month\"}\n >\n {monthLabels.map((label, i) => (\n <option key={label} value={i}>\n {label}\n </option>\n ))}\n </DatePickerSelect>\n <DatePickerSelect\n wrapperClassName=\"w-[5.5rem] shrink-0\"\n className=\"tabular-nums text-center\"\n value={currentMonth.getFullYear()}\n onChange={(e) => setYearFromSelect(Number(e.target.value))}\n aria-label={locale.code?.startsWith(\"es\") ? \"Año\" : \"Year\"}\n >\n {yearOptions.map((y) => (\n <option key={y} value={y}>\n {y}\n </option>\n ))}\n </DatePickerSelect>\n <Button\n type=\"button\"\n variant=\"outline\"\n size=\"sm\"\n onClick={goToNextMonth}\n className=\"h-9 w-9 shrink-0 p-0\"\n aria-label={locale.code?.startsWith(\"es\") ? \"Mes siguiente\" : \"Next month\"}\n >\n <ChevronRight className=\"h-4 w-4\" />\n </Button>\n </div>\n\n <div className=\"mb-2 grid grid-cols-7 gap-1\">\n {weekdayLabels.map((day, i) => (\n <div\n key={i}\n className=\"px-0.5 py-2 text-center text-sm font-medium capitalize leading-tight text-muted-foreground\"\n >\n {day}\n </div>\n ))}\n </div>\n\n <div className=\"grid grid-cols-7 gap-1\">\n {days.map((day, index) => (\n <div key={index} className=\"flex h-9 w-9 items-center justify-center\">\n {day ? (\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"sm\"\n className={cn(\n \"h-9 w-9 p-0 font-normal\",\n isSelected(day) &&\n \"bg-primary text-primary-foreground hover:bg-primary-dark hover:text-primary-foreground\",\n isToday(day) &&\n !isSelected(day) &&\n \"bg-accent text-accent-foreground hover:bg-accent/80 hover:text-accent-foreground\",\n !isSelected(day) && !isToday(day) && \"hover:bg-muted hover:text-foreground\",\n )}\n onClick={() => handleDateSelect(day)}\n >\n {day.getDate()}\n </Button>\n ) : (\n <div className=\"h-9 w-9\" />\n )}\n </div>\n ))}\n </div>\n </div>\n </PopoverContent>\n </Popover>\n );\n}\n\nexport { DatePicker };\n"],"mappings":";AA+FI,SACE,KADF;AA7FJ,YAAY,WAAW;AACvB,SAAS,SAAS,QAAQ,mBAAmB;AAE7C,SAAS,UAAU;AACnB;AAAA,EACE,YAAY;AAAA,EACZ;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,UAAU;AACnB,SAAS,cAAc;AACvB,SAAS,SAAS,gBAAgB,sBAAsB;AAmBxD,SAAS,gBAAgB,QAA2C;AAClE,QAAM,IAAI,OAAO,SAAS;AAC1B,MAAI,MAAM,OAAW,QAAO;AAC5B,SAAO;AACT;AAGA,SAAS,eAAe,QAAgB;AACtC,SAAO,MAAM;AAAA,IACX,MAAM,MAAM,KAAK,EAAE,QAAQ,GAAG,GAAG,CAAC,GAAG,MAAM,OAAO,IAAI,KAAK,MAAM,GAAG,CAAC,GAAG,OAAO,EAAE,OAAO,CAAC,CAAC;AAAA,IAC1F,CAAC,MAAM;AAAA,EACT;AACF;AAGA,SAAS,sBAAsB,QAAwB;AACrD,QAAM,YAAY,CAAC,GAAG,OAAO,UAAU,KAAK,CAAC;AAC7C,MAAI,UAAU,UAAU,GAAG;AACzB,WAAO;AAAA,EACT;AACA,SAAO,UAAU,MAAM,GAAG,CAAC,EAAE,KAAK,EAAE;AACtC;AAEA,SAAS,iBAAiB,QAAgB;AACxC,SAAO,MAAM,QAAQ,MAAM;AACzB,UAAM,eAAe,gBAAgB,MAAM;AAC3C,UAAM,QAAQ,YAAY,IAAI,KAAK,MAAM,GAAG,CAAC,GAAG,EAAE,aAAa,CAAC;AAChE,WAAO,MAAM,KAAK,EAAE,QAAQ,EAAE,GAAG,CAAC,GAAG,MAAM;AACzC,YAAM,SAAS,OAAO,QAAQ,OAAO,CAAC,GAAG,OAAO,EAAE,OAAO,CAAC;AAC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