laif-ds
Version:
Design System di Laif con componenti React basati su principi di Atomic Design
245 lines (244 loc) • 8.74 kB
JavaScript
"use client";
import { jsx as a, jsxs as h } from "react/jsx-runtime";
import { l as z } from "../../_virtual/lodash.js";
import * as y from "react";
import { AppSelect as b } from "./app-select.js";
import { buttonVariants as w, Button as x } from "./button.js";
import { cn as e } from "../../lib/utils.js";
import { getDefaultClassNames as v } from "../../node_modules/react-day-picker/dist/esm/helpers/getDefaultClassNames.js";
import { DayPicker as C } from "../../node_modules/react-day-picker/dist/esm/DayPicker.js";
import _ from "../../node_modules/lucide-react/dist/esm/icons/chevron-left.js";
import N from "../../node_modules/lucide-react/dist/esm/icons/chevron-right.js";
import D from "../../node_modules/lucide-react/dist/esm/icons/chevron-down.js";
import { useDayPicker as k } from "../../node_modules/react-day-picker/dist/esm/useDayPicker.js";
import { formatDate as M } from "../../node_modules/date-fns/format.js";
function W({
className: p,
classNames: g,
showOutsideDays: r = !0,
buttonVariant: d = "ghost",
formatters: u,
components: s,
locale: c,
...f
}) {
const t = v();
return /* @__PURE__ */ a(
C,
{
showOutsideDays: r,
endMonth: new Date((/* @__PURE__ */ new Date()).getFullYear() + 100, 11, 31),
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`,
p
),
formatters: {
formatMonthDropdown: (n) => n.toLocaleString("default", { month: "short" }),
...u
},
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(
w({ variant: d }),
"size-(--cell-size) aria-disabled:opacity-50 p-0 select-none",
t.button_previous
),
button_next: e(
w({ variant: d }),
"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 data-[selected=true]:rounded-none",
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),
...g
},
components: {
Root: ({ className: n, rootRef: l, ...i }) => /* @__PURE__ */ a(
"div",
{
"data-slot": "calendar",
ref: l,
className: e(n),
...i
}
),
Chevron: ({ className: n, orientation: l, ...i }) => l === "left" ? /* @__PURE__ */ a(_, { className: e("size-4", n), ...i }) : l === "right" ? /* @__PURE__ */ a(
N,
{
className: e("size-4", n),
...i
}
) : /* @__PURE__ */ a(D, { className: e("size-4", n), ...i }),
DayButton: L,
WeekNumber: ({ children: n, ...l }) => /* @__PURE__ */ a("td", { ...l, children: /* @__PURE__ */ a("div", { className: "flex size-(--cell-size) items-center justify-center text-center", children: n }) }),
MonthCaption: (n) => /* @__PURE__ */ a(P, { ...n, locale: c }),
...s
},
locale: c,
...f
}
);
}
function L({
className: p,
day: g,
modifiers: r,
...d
}) {
const u = v(), s = y.useRef(null);
return y.useEffect(() => {
r.focused && s.current?.focus();
}, [r.focused]), /* @__PURE__ */ h(
x,
{
ref: s,
variant: "ghost",
size: "icon",
"data-day": g.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",
u.day,
p
),
...d,
children: [
d.children,
r.today && /* @__PURE__ */ a("span", { className: "bg-d-primary absolute bottom-1 left-1/2 h-1 w-1 -translate-x-1/2 rounded-full" })
]
}
);
}
function P({
calendarMonth: p,
locale: g
}) {
const r = k(), { goToMonth: d, nextMonth: u, previousMonth: s } = r, c = p.date, f = Array.from({ length: 12 }, (m, o) => ({
value: o,
label: z.upperFirst(
g ? M(new Date(2e3, o), "LLLL", { locale: g }) : new Date(2e3, o).toLocaleString("default", { month: "long" })
)
})), t = (/* @__PURE__ */ new Date()).getFullYear(), n = Array.from({ length: 201 }, (m, o) => ({
value: t - 100 + o,
label: String(t - 100 + o)
})), l = (m) => {
if (m === void 0) return;
const o = new Date(c);
o.setMonth(Number(m)), d(o);
}, i = (m) => {
if (m === void 0) return;
const o = new Date(c);
o.setFullYear(Number(m)), d(o);
};
return /* @__PURE__ */ h("div", { className: "flex items-center justify-center gap-1", children: [
/* @__PURE__ */ a(
x,
{
variant: "ghost",
size: "icon",
className: "h-6 w-6 p-0",
disabled: !s,
onClick: () => s && d(s),
children: /* @__PURE__ */ a(_, { className: "size-3 opacity-50 hover:opacity-100" })
}
),
/* @__PURE__ */ h("div", { className: "flex items-center gap-1", children: [
/* @__PURE__ */ a(
b,
{
searchable: !0,
searchPlaceholder: "",
emptyPlaceholder: "",
options: f,
value: c.getMonth(),
onValueChange: l,
size: "sm",
className: "h-7 w-[105px] text-xs"
}
),
/* @__PURE__ */ a(
b,
{
searchable: !0,
searchPlaceholder: "",
emptyPlaceholder: "",
options: n,
value: c.getFullYear(),
onValueChange: i,
size: "sm",
className: "h-7 w-[75px] text-xs"
}
)
] }),
/* @__PURE__ */ a(
x,
{
variant: "ghost",
size: "icon",
className: "h-6 w-6 p-0",
disabled: !u,
onClick: () => u && d(u),
children: /* @__PURE__ */ a(N, { className: "size-3 opacity-50 hover:opacity-100" })
}
)
] });
}
export {
W as Calendar,
L as CalendarDayButton
};