UNPKG

laif-ds

Version:

Design System di Laif con componenti React basati su principi di Atomic Design

275 lines (274 loc) 9.54 kB
"use client"; import { jsx as d, jsxs as v } from "react/jsx-runtime"; import { l as A } from "../../_virtual/lodash.js"; import * as _ from "react"; import { AppSelect as z } from "./app-select.js"; import { buttonVariants as C, Button as N } from "./button.js"; import { cn as e } from "../../lib/utils.js"; import { getDefaultClassNames as k } from "../../node_modules/react-day-picker/dist/esm/helpers/getDefaultClassNames.js"; import { DayPicker as P } from "../../node_modules/react-day-picker/dist/esm/DayPicker.js"; import Y from "../../node_modules/lucide-react/dist/esm/icons/chevron-left.js"; import M from "../../node_modules/lucide-react/dist/esm/icons/chevron-right.js"; import S from "../../node_modules/lucide-react/dist/esm/icons/chevron-down.js"; import { useDayPicker as R } from "../../node_modules/react-day-picker/dist/esm/useDayPicker.js"; import { formatDate as j } from "../../node_modules/date-fns/format.js"; const w = 50; function Q({ className: h, classNames: m, showOutsideDays: r = !0, buttonVariant: o = "ghost", formatters: y, components: l, locale: p, minDate: u, maxDate: s, disabled: g, ...x }) { const t = k(), b = _.useMemo(() => { const a = []; return u && a.push({ before: u }), s && a.push({ after: s }), g && (Array.isArray(g) ? a.push(...g) : a.push(g)), a.length > 0 ? a : void 0; }, [u, s, g]); return /* @__PURE__ */ d( P, { showOutsideDays: r, startMonth: u ?? new Date((/* @__PURE__ */ new Date()).getFullYear() - w, 0, 1), endMonth: s ?? new Date((/* @__PURE__ */ new Date()).getFullYear() + w, 11, 31), disabled: b, className: e( "bg-d-background group/calendar p-3 [--cell-size:--spacing(7)] [[data-slot=card-content]_&]:bg-transparent [[data-slot=popover-content]_&]:bg-transparent", String.raw`rtl:**:[.rdp-button\_next>svg]:rotate-180`, String.raw`rtl:**:[.rdp-button\_previous>svg]:rotate-180`, h ), formatters: { formatMonthDropdown: (a) => a.toLocaleString("default", { month: "short" }), ...y }, classNames: { root: e("w-fit", t.root), months: e( "flex gap-4 flex-col md:flex-row relative", t.months ), month: e("flex flex-col w-full gap-4", t.month), nav: e("hidden", t.nav), button_previous: e( C({ variant: o }), "size-(--cell-size) aria-disabled:opacity-50 p-0 select-none", t.button_previous ), button_next: e( C({ variant: o }), "size-(--cell-size) aria-disabled:opacity-50 p-0 select-none", t.button_next ), month_caption: e( "flex items-center justify-center pt-1 relative", t.month_caption ), caption_label: e( "select-none font-medium text-sm", t.caption_label ), table: "w-full border-collapse space-y-1", weekdays: e("flex", t.weekdays), weekday: e( "text-d-muted-foreground rounded-md flex-1 font-normal text-[0.8rem] select-none", t.weekday ), week: e("flex w-full mt-2", t.week), week_number_header: e( "select-none w-(--cell-size)", t.week_number_header ), week_number: e( "text-[0.8rem] select-none text-d-muted-foreground", t.week_number ), day: e( "relative w-full h-full p-0 text-center [&:first-child[data-selected=true]_button]:rounded-l-md [&:last-child[data-selected=true]_button]:rounded-r-md group/day aspect-square select-none", t.day ), range_start: e( "rounded-l-md bg-d-accent", t.range_start ), range_middle: e("rounded-none", t.range_middle), range_end: e("rounded-r-md bg-d-accent", t.range_end), today: e( "bg-d-accent text-d-accent-foreground rounded-md", t.today ), outside: e( "text-d-muted-foreground aria-selected:text-d-muted-foreground", t.outside ), disabled: e( "text-d-muted-foreground opacity-50", t.disabled ), hidden: e("invisible", t.hidden), ...m }, components: { Root: ({ className: a, rootRef: i, ...f }) => /* @__PURE__ */ d( "div", { "data-slot": "calendar", ref: i, className: e(a), ...f } ), Chevron: ({ className: a, orientation: i, ...f }) => i === "left" ? /* @__PURE__ */ d(Y, { className: e("size-4", a), ...f }) : i === "right" ? /* @__PURE__ */ d( M, { className: e("size-4", a), ...f } ) : /* @__PURE__ */ d(S, { className: e("size-4", a), ...f }), DayButton: E, WeekNumber: ({ children: a, ...i }) => /* @__PURE__ */ d("td", { ...i, children: /* @__PURE__ */ d("div", { className: "flex size-(--cell-size) items-center justify-center text-center", children: a }) }), MonthCaption: (a) => /* @__PURE__ */ d( B, { ...a, locale: p, minDate: u, maxDate: s } ), ...l }, locale: p, ...x } ); } function E({ className: h, day: m, modifiers: r, ...o }) { const y = k(), l = _.useRef(null); return _.useEffect(() => { r.focused && l.current?.focus(); }, [r.focused]), /* @__PURE__ */ v( N, { ref: l, variant: "ghost", size: "icon", "data-day": m.date.toLocaleDateString(), "data-selected-single": r.selected && !r.range_start && !r.range_end && !r.range_middle, "data-range-start": r.range_start, "data-range-end": r.range_end, "data-range-middle": r.range_middle, className: e( "data-[selected-single=true]:bg-d-primary data-[selected-single=true]:text-d-primary-foreground data-[range-middle=true]:bg-d-accent data-[range-middle=true]:text-d-accent-foreground data-[range-start=true]:bg-d-primary data-[range-start=true]:text-d-primary-foreground data-[range-end=true]:bg-d-primary data-[range-end=true]:text-d-primary-foreground group-data-[focused=true]/day:border-ring group-data-[focused=true]/day:ring-d-ring/50 flex aspect-square size-auto w-full min-w-(--cell-size) flex-col gap-1 leading-none font-normal group-data-[focused=true]/day:relative group-data-[focused=true]/day:z-10 group-data-[focused=true]/day:ring-[1px] data-[range-end=true]:rounded-md data-[range-end=true]:rounded-r-md data-[range-middle=true]:rounded-none data-[range-start=true]:rounded-md data-[range-start=true]:rounded-l-md [&>span]:text-xs [&>span]:opacity-70", y.day, h ), ...o, children: [ o.children, r.today && /* @__PURE__ */ d("span", { className: "bg-d-primary absolute bottom-1 left-1/2 h-1 w-1 -translate-x-1/2 rounded-full" }) ] } ); } function B({ calendarMonth: h, locale: m, minDate: r, maxDate: o }) { const y = R(), { goToMonth: l, nextMonth: p, previousMonth: u } = y, s = h.date, g = s.getFullYear(), x = (c) => { if (!r && !o) return !1; const n = new Date(g, c, 1); return !!(r && n < r || o && n > o); }, t = Array.from( { length: 12 }, (c, n) => ({ value: n, label: A.upperFirst( m ? j(new Date(2e3, n), "LLLL", { locale: m }) : new Date(2e3, n).toLocaleString("default", { month: "long" }) ), disabled: x(n) }) ), b = (/* @__PURE__ */ new Date()).getFullYear(), a = r ? r.getFullYear() : b - w, i = o ? o.getFullYear() : b + w, f = Array.from( { length: i - a + 1 }, (c, n) => ({ value: a + n, label: String(a + n) }) ), F = (c) => { if (c === void 0) return; const n = new Date(s); n.setMonth(Number(c)), !(r && n < r) && (o && n > o || l(n)); }, L = (c) => { if (c === void 0) return; const n = new Date(s); n.setFullYear(Number(c)), !(r && n < r) && (o && n > o || l(n)); }; return /* @__PURE__ */ v("div", { className: "flex items-center justify-center gap-1", children: [ /* @__PURE__ */ d( N, { variant: "ghost", size: "icon", className: "h-6 w-6 p-0", disabled: !u, onClick: () => u && l(u), children: /* @__PURE__ */ d(Y, { className: "size-3 opacity-50 hover:opacity-100" }) } ), /* @__PURE__ */ v("div", { className: "flex items-center gap-1", children: [ /* @__PURE__ */ d( z, { searchable: !0, searchPlaceholder: "", emptyPlaceholder: "", options: t, value: s.getMonth(), onValueChange: F, size: "sm", className: "h-7 w-[105px] text-xs" } ), /* @__PURE__ */ d( z, { searchable: !0, searchPlaceholder: "", emptyPlaceholder: "", options: f, value: s.getFullYear(), onValueChange: L, size: "sm", className: "h-7 w-[75px] text-xs" } ) ] }), /* @__PURE__ */ d( N, { variant: "ghost", size: "icon", className: "h-6 w-6 p-0", disabled: !p, onClick: () => p && l(p), children: /* @__PURE__ */ d(M, { className: "size-3 opacity-50 hover:opacity-100" }) } ) ] }); } export { Q as Calendar, E as CalendarDayButton };