@cerberus-design/react
Version:
The Cerberus Design React component library.
39 lines (36 loc) • 1.95 kB
JavaScript
'use client';
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
import { DatePickerParts } from './parts.js';
import { DatePickerViewControlGroup } from './view-control-group.js';
function DatePickerDayView(props) {
function isToday(date) {
const today = /* @__PURE__ */ new Date();
const formatted = today.toISOString().split("T")[0];
const arkDate = `${date.year}-${String(date.month).padStart(2, "0")}-${String(date.day).padStart(2, "0")}`;
return formatted === arkDate;
}
function isPastDay(date) {
const today = /* @__PURE__ */ new Date();
const arkDate = `${date.year}-${String(date.month).padStart(2, "0")}-${String(date.day).padStart(2, "0")}`;
return new Date(arkDate) < today;
}
function getDayValue(date) {
if (isToday(date)) return "today";
if (isPastDay(date)) return "past";
return "future";
}
return /* @__PURE__ */ jsx(DatePickerParts.View, { ...props, view: "day", children: /* @__PURE__ */ jsx(DatePickerParts.Context, { children: (datePickerData) => /* @__PURE__ */ jsxs(Fragment, { children: [
/* @__PURE__ */ jsx(DatePickerViewControlGroup, {}),
/* @__PURE__ */ jsxs(DatePickerParts.Table, { children: [
/* @__PURE__ */ jsx(DatePickerParts.TableHead, { children: /* @__PURE__ */ jsx(DatePickerParts.TableRow, { children: datePickerData.weekDays.map((weekDay, id) => /* @__PURE__ */ jsx(DatePickerParts.TableHeader, { children: weekDay.narrow }, id)) }) }),
/* @__PURE__ */ jsx(DatePickerParts.TableBody, { children: datePickerData.weeks.map((week, id) => /* @__PURE__ */ jsx(DatePickerParts.TableRow, { children: week.map((day, id2) => /* @__PURE__ */ jsx(DatePickerParts.TableCell, { value: day, children: /* @__PURE__ */ jsx(
DatePickerParts.TableCellTrigger,
{
"data-date": getDayValue(day),
children: day.day
}
) }, id2)) }, id)) })
] })
] }) }) });
}
export { DatePickerDayView };