Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

style: add size variants to date range picker

Brad Barbinf0ea9b9fb7c4
diff --git a/apps/erp/app/routes/x+/sales+/_index.tsx b/apps/erp/app/routes/x+/sales+/_index.tsx
index ab47300abb..92b7b35557 100644
--- a/apps/erp/app/routes/x+/sales+/_index.tsx
+++ b/apps/erp/app/routes/x+/sales+/_index.tsx
@@ -1,6 +1,35 @@
-import { Button, Card, HStack } from "@carbon/react";
-import { LuArrowUpRight } from "react-icons/lu";
-import { RiProgress2Line, RiProgress4Line } from "react-icons/ri";
+import {
+ Button,
+ Card,
+ CardAction,
+ CardContent,
+ CardDescription,
+ CardHeader,
+ CardTitle,
+ DateRangePicker,
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuRadioGroup,
+ DropdownMenuRadioItem,
+ DropdownMenuTrigger,
+ HStack,
+ IconButton,
+} from "@carbon/react";
+import {
+ ChartContainer,
+ ChartTooltip,
+ ChartTooltipContent,
+ type ChartConfig,
+} from "@carbon/react/Chart";
+import type { DateRange } from "@react-types/datepicker";
+import { useState } from "react";
+import { LuArrowUpRight, LuChevronDown, LuMoreVertical } from "react-icons/lu";
+import {
+ RiProgress2Line,
+ RiProgress4Line,
+ RiProgress8Line,
+} from "react-icons/ri";
+import { Bar, BarChart, CartesianGrid, XAxis } from "recharts";
const chartData = [
{ month: "January", desktop: 186, mobile: 80 },
@@ -11,9 +40,63 @@ const chartData = [
{ month: "June", desktop: 214, mobile: 140 },
];
+const KPIS = [
+ {
+ key: "salesOrderRevenue",
+ label: "Sales Order Revenue",
+ },
+ {
+ key: "quoteRevenue",
+ label: "Quote Revenue",
+ },
+ {
+ key: "salesOrderCount",
+ label: "Sales Order Count",
+ },
+ {
+ key: "quoteCount",
+ label: "Quote Count",
+ },
+ {
+ key: "rfqCount",
+ label: "RFQ Count",
+ },
+ {
+ key: "turnaroundTime",
+ label: "Turnaround Time",
+ },
+];
+
+const CHART_INTERVALS = [
+ { key: "week", label: "Week" },
+ { key: "month", label: "Month" },
+ { key: "quarter", label: "Quarter" },
+ { key: "year", label: "Year" },
+ { key: "custom", label: "Custom" },
+];
+
+const chartConfig = {
+ desktop: {
+ label: "Desktop",
+ color: "hsl(var(--primary))", // Primary color
+ },
+ mobile: {
+ label: "Mobile",
+ color: "hsl(var(--chart-1))", // Lighter primary
+ },
+} satisfies ChartConfig;
+
export default function SalesDashboard() {
+ const [interval, setInterval] = useState("month");
+ const [selectedKpi, setSelectedKpi] = useState("salesOrderRevenue");
+ const [dateRange, setDateRange] = useState<DateRange | null>(null);
+
+ const selectedInterval =
+ CHART_INTERVALS.find((i) => i.key === interval) || CHART_INTERVALS[1];
+ const selectedKpiData = KPIS.find((k) => k.key === selectedKpi) || KPIS[0];
+
return (
- <div className="flex flex-col gap-4 w-full p-4">
+ <div className="flex flex-col gap-4 w-full p-4 h-[calc(100dvh-var(--header-height))] overflow-y-auto scrollbar-thin scrollbar-thumb-rounded-full scrollbar-thumb-muted-foreground">
<div className="grid w-full gap-4 grid-cols-1 lg:grid-cols-3">
<Card className="p-4 rounded-xl items-start justify-start gap-y-4">
<HStack className="justify-between w-full items-start mb-4">
@@ -60,7 +143,7 @@ export default function SalesDashboard() {
<Card className="p-4 items-start justify-start gap-y-4">
<HStack className="justify-between w-full items-start mb-4">
<div className="bg-muted/80 border border-border rounded-xl p-2 text-foreground shadow-md">
- <RiProgress4Line className="size-5" />
+ <RiProgress8Line className="size-5" />
</div>
<Button
size="sm"
@@ -79,7 +162,121 @@ export default function SalesDashboard() {
</Card>
</div>
- <div className="grid w-full gap-4 grid-cols-1 lg:grid-cols-2"></div>
+ <div className="grid w-full gap-4 grid-cols-1 lg:grid-cols-3">
+ <Card className="col-span-2 p-0">
+ <HStack className="justify-between items-start">
+ <CardHeader className="px-4">
+ <div className="flex w-full justify-start items-center gap-2">
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <Button
+ variant="secondary"
+ rightIcon={<LuChevronDown />}
+ className="hover:bg-background/80"
+ >
+ <span>{selectedKpiData.label}</span>
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent side="bottom" align="start">
+ <DropdownMenuRadioGroup
+ value={selectedKpi}
+ onValueChange={setSelectedKpi}
+ >
+ {KPIS.map((kpi) => (
+ <DropdownMenuRadioItem key={kpi.key} value={kpi.key}>
+ {kpi.label}
+ </DropdownMenuRadioItem>
+ ))}
+ </DropdownMenuRadioGroup>
+ </DropdownMenuContent>
+ </DropdownMenu>
+
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <Button
+ variant="secondary"
+ rightIcon={<LuChevronDown />}
+ className="hover:bg-background/80"
+ >
+ <span>{selectedInterval.label}</span>
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent side="bottom" align="start">
+ <DropdownMenuRadioGroup
+ value={interval}
+ onValueChange={setInterval}
+ >
+ {CHART_INTERVALS.map((i) => (
+ <DropdownMenuRadioItem key={i.key} value={i.key}>
+ {i.label}
+ </DropdownMenuRadioItem>
+ ))}
+ </DropdownMenuRadioGroup>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ {interval === "custom" && (
+ <DateRangePicker
+ size="md"
+ value={dateRange}
+ onChange={setDateRange}
+ />
+ )}
+ </div>
+ </CardHeader>
+ <CardAction className="py-6 px-4">
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <IconButton
+ variant="secondary"
+ size="sm"
+ icon={<LuMoreVertical />}
+ aria-label="More"
+ />
+ </DropdownMenuTrigger>
+ </DropdownMenu>
+ </CardAction>
+ </HStack>
+ <CardContent className="p-4">
+ <ChartContainer
+ config={chartConfig}
+ className="min-h-[200px] w-full"
+ >
+ <BarChart accessibilityLayer data={chartData}>
+ <CartesianGrid vertical={false} />
+ <XAxis
+ dataKey="month"
+ tickLine={false}
+ tickMargin={10}
+ axisLine={false}
+ tickFormatter={(value) => value.slice(0, 3)}
+ />
+ <ChartTooltip content={<ChartTooltipContent />} />
+ <Bar dataKey="desktop" fill="var(--color-desktop)" radius={4} />
+ <Bar dataKey="mobile" fill="var(--color-mobile)" radius={4} />
+ </BarChart>
+ </ChartContainer>
+ </CardContent>
+ </Card>
+
+ <Card className="p-0">
+ <CardHeader className="px-4">
+ <CardTitle>Recent Activity</CardTitle>
+ <CardDescription className="text-sm">
+ Newly created sales documents
+ </CardDescription>
+ </CardHeader>
+ </Card>
+ </div>
+
+ <Card className="p-0">
+ <CardHeader className="px-4">
+ <CardTitle>Assigned to Me</CardTitle>
+ <CardDescription className="text-sm">
+ Sales documents currently assigned to me
+ </CardDescription>
+ </CardHeader>
+ <CardContent className="p-4 min-h-[200px]"></CardContent>
+ </Card>
</div>
);
}
diff --git a/packages/react/src/Date/DateRangePicker.tsx b/packages/react/src/Date/DateRangePicker.tsx
index e9c0cf51ce..c3a90f85d3 100644
--- a/packages/react/src/Date/DateRangePicker.tsx
+++ b/packages/react/src/Date/DateRangePicker.tsx
@@ -1,17 +1,48 @@
import { useDateRangePicker } from "@react-aria/datepicker";
import { useDateRangePickerState } from "@react-stately/datepicker";
import type { DateRangePickerProps, DateValue } from "@react-types/datepicker";
+import { cva } from "class-variance-authority";
import { useRef } from "react";
import { LuBan } from "react-icons/lu";
import { HStack } from "../HStack";
import { InputGroup } from "../Input";
-import TimeField from "./TimePicker";
import { FieldButton } from "./components/Button";
import DateField from "./components/DateField";
import { Popover } from "./components/Popover";
import { RangeCalendar } from "./components/RangeCalendar";
-const DateRangePicker = (props: DateRangePickerProps<DateValue>) => {
+const iconVariants = cva("", {
+ variants: {
+ size: {
+ sm: "h-3 w-3",
+ md: "h-4 w-4",
+ lg: "h-5 w-5",
+ },
+ },
+ defaultVariants: {
+ size: "md",
+ },
+});
+
+const fieldVariants = cva("flex w-full", {
+ variants: {
+ size: {
+ sm: "px-2 py-1",
+ md: "px-4 py-2",
+ lg: "px-6 py-3",
+ },
+ },
+ defaultVariants: {
+ size: "md",
+ },
+});
+
+const DateRangePicker = ({
+ size = "md",
+ ...props
+}: DateRangePickerProps<DateValue> & {
+ size?: "sm" | "md" | "lg";
+}) => {
const state = useDateRangePickerState({
...props,
shouldCloseOnSelect: false,
@@ -32,21 +63,26 @@ const DateRangePicker = (props: DateRangePickerProps<DateValue>) => {
<InputGroup
{...groupProps}
ref={ref}
+ size={size}
className="w-full inline-flex rounded-r-none"
>
- <div className="flex w-full px-4 py-2">
- <DateField {...startFieldProps} />
+ <div className={fieldVariants({ size })}>
+ <DateField {...startFieldProps} size={size} />
<span aria-hidden="true" className="px-2">
–
</span>
- <DateField {...endFieldProps} />
+ <DateField {...endFieldProps} size={size} />
{state.isInvalid && (
- <LuBan className="text-destructive-foreground absolute right-[12px]" />
+ <LuBan
+ className={`text-destructive-foreground absolute right-[12px] ${iconVariants(
+ { size }
+ )}`}
+ />
)}
</div>
</InputGroup>
- <FieldButton {...buttonProps} isPressed={state.isOpen} />
+ <FieldButton {...buttonProps} isPressed={state.isOpen} size={size} />
</HStack>
{state.isOpen && (
<Popover
@@ -55,18 +91,6 @@ const DateRangePicker = (props: DateRangePickerProps<DateValue>) => {
onClose={() => state.setOpen(false)}
>
<RangeCalendar {...calendarProps} />
- <div className="flex gap-2">
- <TimeField
- label="Start time"
- value={state.timeRange?.start || null}
- onChange={(v) => state.setTime("start", v)}
- />
- <TimeField
- label="End time"
- value={state.timeRange?.end || null}
- onChange={(v) => state.setTime("end", v)}
- />
- </div>
</Popover>
)}
</div>
diff --git a/packages/react/src/Date/components/Button.tsx b/packages/react/src/Date/components/Button.tsx
index 4889994c76..44a3b02cad 100644
--- a/packages/react/src/Date/components/Button.tsx
+++ b/packages/react/src/Date/components/Button.tsx
@@ -22,20 +22,28 @@ export const CalendarButton = (props: AriaButtonProps & IconButtonProps) => {
export interface FieldButtonProps extends AriaButtonProps {
isPressed: boolean;
className?: string;
+ size?: "sm" | "md" | "lg";
}
-export const FieldButton = (props: FieldButtonProps) => {
+export const FieldButton = ({ size = "md", ...props }: FieldButtonProps) => {
const ref = useRef<HTMLButtonElement>(null);
const { buttonProps } = useButton(props, ref);
+
+ const sizeClasses = {
+ sm: "h-8 w-8 px-2",
+ md: "h-10 w-10 px-3",
+ lg: "h-12 w-12 px-4",
+ };
+
return (
<IconButton
{...buttonProps}
ref={ref}
aria-label="Toggle"
- className="flex-shrink-0 h-10 w-10 px-3 rounded-l-none border-l-0 shadow-sm"
+ className={`flex-shrink-0 ${sizeClasses[size]} rounded-l-none border-l-0 shadow-sm`}
icon={<LuCalendar />}
variant="secondary"
- size="md"
+ size={size}
/>
);
};
diff --git a/packages/react/src/Date/components/CalendarGrid.tsx b/packages/react/src/Date/components/CalendarGrid.tsx
index 344417d1b4..748b228605 100644
--- a/packages/react/src/Date/components/CalendarGrid.tsx
+++ b/packages/react/src/Date/components/CalendarGrid.tsx
@@ -6,15 +6,17 @@ import type {
CalendarState,
RangeCalendarState,
} from "@react-stately/calendar";
-import { Table, Tbody, Td, Th, Thead, Tr } from "../../Table";
import { CalendarCell } from "./CalendarCell";
+import { CalendarRangeCell } from "./CalendarRangeCell";
export const CalendarGrid = ({
state,
offset = {},
+ isRangeCalendar = false,
}: {
state: CalendarState | RangeCalendarState;
offset?: DateDuration;
+ isRangeCalendar?: boolean;
}) => {
const { locale } = useLocale();
const startDate = state.visibleRange.start.add(offset);
@@ -31,39 +33,53 @@ export const CalendarGrid = ({
const weeksInMonth = getWeeksInMonth(state.visibleRange.start, locale);
return (
- <Table {...gridProps}>
- <Thead {...headerProps}>
- <Tr>
+ <table
+ {...gridProps}
+ className="w-full border-collapse space-y-1"
+ cellPadding={isRangeCalendar ? "0" : undefined}
+ >
+ <thead {...headerProps}>
+ <tr>
{weekDays.map((day, index) => (
- <Th
+ <th
+ className="text-muted-foreground rounded-md w-8 font-normal text-[0.8rem]"
key={index}
- className="text-muted-foreground text-sm text-center px-0"
>
{day}
- </Th>
+ </th>
))}
- </Tr>
- </Thead>
- <Tbody>
+ </tr>
+ </thead>
+ <tbody>
{[...new Array(weeksInMonth).keys()].map((weekIndex) => (
- <Tr key={weekIndex} className="border-none">
+ <tr key={weekIndex} className="h-9">
{state
.getDatesInWeek(weekIndex, startDate)
.map((date, i) =>
date ? (
- <CalendarCell
- key={i}
- state={state}
- date={date}
- currentMonth={startDate}
- />
+ isRangeCalendar ? (
+ <CalendarRangeCell
+ key={i}
+ state={state as RangeCalendarState}
+ date={date}
+ currentMonth={startDate}
+ locale={locale}
+ />
+ ) : (
+ <CalendarCell
+ key={i}
+ state={state as CalendarState}
+ date={date}
+ currentMonth={startDate}
+ />
+ )
) : (
- <Td key={i} />
+ <td key={i} />
)
)}
- </Tr>
+ </tr>
))}
- </Tbody>
- </Table>
+ </tbody>
+ </table>
);
};
diff --git a/packages/react/src/Date/components/CalendarRangeCell.tsx b/packages/react/src/Date/components/CalendarRangeCell.tsx
new file mode 100644
index 0000000000..c996a25f41
--- /dev/null
+++ b/packages/react/src/Date/components/CalendarRangeCell.tsx
@@ -0,0 +1,92 @@
+import type { CalendarDate } from "@internationalized/date";
+import {
+ getLocalTimeZone,
+ isToday as isDateToday,
+ isSameDay,
+ isSameMonth,
+} from "@internationalized/date";
+import { useCalendarCell } from "@react-aria/calendar";
+import type { RangeCalendarState } from "@react-stately/calendar";
+import clsx from "clsx";
+import { useRef } from "react";
+
+import { Button } from "../../Button";
+
+export function CalendarRangeCell({
+ state,
+ date,
+ currentMonth,
+ ...props
+}: {
+ state: RangeCalendarState;
+ date: CalendarDate;
+ currentMonth: CalendarDate;
+ isRangeCalendar?: boolean;
+ locale?: string;
+}) {
+ const ref = useRef<HTMLButtonElement>(null);
+ const {
+ cellProps,
+ buttonProps,
+ isSelected,
+ isInvalid,
+ isDisabled,
+ isUnavailable,
+ isFocused,
+ formattedDate,
+ } = useCalendarCell({ date }, state, ref);
+
+ const isOutsideMonth = !isSameMonth(currentMonth, date);
+ const isToday = isDateToday(date, getLocalTimeZone());
+
+ const isSelectionStart = state.highlightedRange
+ ? isSameDay(date, state.highlightedRange.start)
+ : isSelected;
+ const isSelectionEnd = state.highlightedRange
+ ? isSameDay(date, state.highlightedRange.end)
+ : isSelected;
+
+ const isRoundedLeft = isSelected && isSelectionStart;
+ const isRoundedRight = isSelected && isSelectionEnd;
+
+ return (
+ <td className="text-center relative" {...cellProps}>
+ <Button
+ {...buttonProps}
+ ref={ref}
+ size="sm"
+ variant={isSelected ? "primary" : "ghost"}
+ className={clsx(
+ "p-0 w-8 h-8 shadow-none font-normal hover:primary/10",
+ {
+ "bg-primary/50": isFocused,
+ "bg-primary text-card hover:bg-primary": isSelected,
+ "opacity-50 hover:bg-card focus:bg-card":
+ isInvalid || isDisabled || isUnavailable,
+ "hover:rounded-full": !isSelected,
+ hidden: isOutsideMonth,
+ "rounded-none": isSelected && !isRoundedLeft && !isRoundedRight,
+ "!rounded-l-full !rounded-r-none": isRoundedLeft,
+ "!rounded-r-full !rounded-l-none": isRoundedRight,
+ "!rounded-full":
+ (isFocused && !isSelected) ||
+ (isSelected && isRoundedLeft && isRoundedRight),
+ }
+ )}
+ >
+ {formattedDate}
+ </Button>
+ {isToday && (
+ <span
+ className={clsx(
+ "absolute w-1 h-1 bottom-1 rounded-full left-1/2 transform -translate-x-1/2",
+ {
+ "bg-card": isSelected,
+ "bg-primary ": !isSelected,
+ }
+ )}
+ />
+ )}
+ </td>
+ );
+}
diff --git a/packages/react/src/Date/components/DateField.tsx b/packages/react/src/Date/components/DateField.tsx
index 081dbe15ca..b491d5f688 100644
--- a/packages/react/src/Date/components/DateField.tsx
+++ b/packages/react/src/Date/components/DateField.tsx
@@ -7,7 +7,11 @@ import { useDateFieldState } from "@react-stately/datepicker";
import { useRef } from "react";
import { DateSegment } from "./DateSegment";
-const DateField = (props: AriaDateFieldProps<DateValue>) => {
+interface DateFieldProps extends AriaDateFieldProps<DateValue> {
+ size?: "sm" | "md" | "lg";
+}
+
+const DateField = ({ size, ...props }: DateFieldProps) => {
const { locale } = useLocale();
const state = useDateFieldState({
...props,
@@ -19,9 +23,9 @@ const DateField = (props: AriaDateFieldProps<DateValue>) => {
const { fieldProps } = useDateField(props, state, ref);
return (
- <div className="flex" {...fieldProps} ref={ref}>
+ <div className="flex items-center" {...fieldProps} ref={ref}>
{state.segments.map((segment, i) => (
- <DateSegment key={i} segment={segment} state={state} />
+ <DateSegment key={i} segment={segment} state={state} size={size} />
))}
</div>
);
diff --git a/packages/react/src/Date/components/DateSegment.tsx b/packages/react/src/Date/components/DateSegment.tsx
index 79d83f693f..e86f5271d4 100644
--- a/packages/react/src/Date/components/DateSegment.tsx
+++ b/packages/react/src/Date/components/DateSegment.tsx
@@ -6,13 +6,23 @@ import type {
import clsx from "clsx";
import { useId, useRef } from "react";
+const segmentSizeVariants = {
+ sm: "text-xs",
+ md: "text-sm",
+ lg: "text-base",
+} as const;
+
+interface DateSegmentProps {
+ segment: DateSegmentType;
+ state: ReturnType<typeof useDateFieldState>;
+ size?: keyof typeof segmentSizeVariants;
+}
+
export const DateSegment = ({
segment,
state,
-}: {
- segment: DateSegmentType;
- state: ReturnType<typeof useDateFieldState>;
-}) => {
+ size = "md",
+}: DateSegmentProps) => {
const instanceId = useId();
const ref = useRef<HTMLDivElement>(null);
const { segmentProps } = useDateSegment(segment, state, ref);
@@ -28,7 +38,10 @@ export const DateSegment = ({
<div
{...segmentProps}
ref={ref}
- className="box-content text-sm tabular-nums text-right outline-none rounded-sm group focus:bg-primary focus:text-primary-foreground"
+ className={clsx(
+ "box-content tabular-nums text-right outline-none rounded-sm group focus:bg-primary focus:text-primary-foreground",
+ segmentSizeVariants[size]
+ )}
>
<span
aria-hidden="true"
diff --git a/packages/react/src/Date/components/RangeCalendar.tsx b/packages/react/src/Date/components/RangeCalendar.tsx
index 3308b60cdf..1f2bec9f1f 100644
--- a/packages/react/src/Date/components/RangeCalendar.tsx
+++ b/packages/react/src/Date/components/RangeCalendar.tsx
@@ -1,17 +1,29 @@
-import type { DateValue } from "@internationalized/date";
+import type { CalendarDate, DateValue } from "@internationalized/date";
import { createCalendar } from "@internationalized/date";
import type { RangeCalendarProps } from "@react-aria/calendar";
import { useRangeCalendar } from "@react-aria/calendar";
import { useLocale } from "@react-aria/i18n";
import { useRangeCalendarState } from "@react-stately/calendar";
-import { useRef } from "react";
-import { FaAngleLeft, FaAngleRight } from "react-icons/fa";
-import { Heading } from "../../Heading";
+import { useEffect, useMemo, useRef } from "react";
+import clsx from "clsx";
+import {
+ LuChevronLeft,
+ LuChevronRight,
+ LuChevronsLeft,
+ LuChevronsRight,
+} from "react-icons/lu";
import { CalendarButton } from "./Button";
import { CalendarGrid } from "./CalendarGrid";
-export function RangeCalendar(props: RangeCalendarProps<DateValue>) {
+export function RangeCalendar({
+ bordered = false,
+ ...props
+}: RangeCalendarProps<DateValue> & {
+ locale?: string;
+ bordered?: boolean;
+ className?: string;
+}) {
const { locale } = useLocale();
const state = useRangeCalendarState({
...props,
@@ -20,34 +32,123 @@ export function RangeCalendar(props: RangeCalendarProps<DateValue>) {
createCalendar,
});
+ useEffect(() => {
+ if (!props.value?.start) return;
+ state.setFocusedDate(props.value.start as CalendarDate);
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [props.value]);
+
const ref = useRef<HTMLDivElement>(null);
- const { calendarProps, prevButtonProps, nextButtonProps, title } =
- useRangeCalendar(props, state, ref);
+ const { calendarProps, prevButtonProps, nextButtonProps } = useRangeCalendar(
+ props,
+ state,
+ ref
+ );
+
+ const startTitle = useLocalizedTitle(
+ state.visibleRange.start,
+ state.timeZone,
+ locale
+ );
+ const endTitle = useLocalizedTitle(
+ state.visibleRange.end,
+ state.timeZone,
+ locale
+ );
+
+ // Note that in some calendar systems, such as the Hebrew,
+ // the number of months may differ between years.
+ const numMonths = state.focusedDate.calendar.getMonthsInYear(
+ state.focusedDate
+ );
+
+ const handlePrevYear = () => {
+ state.setFocusedDate(
+ state.visibleRange.start.subtract({ months: numMonths - 1 })
+ );
+ };
+
+ const handleNextYear = () => {
+ state.setFocusedDate(state.visibleRange.start.add({ years: 1 }));
+ };
return (
- <div {...calendarProps} ref={ref}>
- <div className="flex items-center pb-4">
- <CalendarButton
- aria-label="Previous Month"
- icon={<FaAngleLeft />}
- {...prevButtonProps}
- className="w-6 h-6"
- />
-
- <Heading as="h2" size="h3" className="flex-1 text-center">
- {title}
- </Heading>
- <CalendarButton
- aria-label="Next Month"
- icon={<FaAngleRight />}
- {...nextButtonProps}
- className="w-6 h-6"
- />
+ <div {...calendarProps} ref={ref} className="flex">
+ <div
+ className={clsx("p-4 border-r border-border", {
+ "rounded-md border shadow": bordered,
+ })}
+ >
+ <div className="flex items-center pb-4">
+ <CalendarButton
+ onClick={handlePrevYear}
+ aria-label="Previous Year"
+ className="rounded-full"
+ icon={<LuChevronsLeft />}
+ size="sm"
+ variant="ghost"
+ />
+ <CalendarButton
+ {...prevButtonProps}
+ aria-label="Previous Month"
+ className="rounded-full"
+ icon={<LuChevronLeft />}
+ size="sm"
+ variant="ghost"
+ />
+ <div className="font-semibold text-left text-base flex-1 pl-2">
+ {startTitle}
+ </div>
+ </div>
+ <div className="flex gap-8">
+ <CalendarGrid state={state} isRangeCalendar />
+ </div>
</div>
- <div className="flex gap-8">
- <CalendarGrid state={state} />
- <CalendarGrid state={state} offset={{ months: 1 }} />
+ <div
+ className={clsx("p-4 ", {
+ "rounded-md border shadow": bordered,
+ })}
+ >
+ <div className="flex items-center pb-4">
+ <div className="font-semibold text-right text-base flex-1 pr-2">
+ {endTitle}
+ </div>
+ <CalendarButton
+ {...nextButtonProps}
+ aria-label="Next Month"
+ className="rounded-full"
+ icon={<LuChevronRight />}
+ size="sm"
+ variant="ghost"
+ />
+ <CalendarButton
+ onClick={handleNextYear}
+ aria-label="Next Year"
+ className="rounded-full"
+ icon={<LuChevronsRight />}
+ size="sm"
+ variant="ghost"
+ />
+ </div>
+ <div className="flex gap-8">
+ <CalendarGrid state={state} offset={{ months: 1 }} isRangeCalendar />
+ </div>
</div>
</div>
);
}
+
+function useLocalizedTitle(
+ date: CalendarDate,
+ timeZone: string,
+ locale: string
+) {
+ const dateFormatter = useMemo(() => {
+ return new Intl.DateTimeFormat(locale, {
+ month: "long",
+ year: "numeric",
+ });
+ }, [locale]);
+
+ return dateFormatter.format(date.toDate(timeZone));
+}