Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

adjust calendar styling and add calendar stories

Scott Wilson8807e27a38dc
diff --git a/frontend/src/components/v3/generic/Calendar/Calendar.stories.tsx b/frontend/src/components/v3/generic/Calendar/Calendar.stories.tsx
new file mode 100644
index 0000000000..3a98f4a7e2
--- /dev/null
+++ b/frontend/src/components/v3/generic/Calendar/Calendar.stories.tsx
@@ -0,0 +1,174 @@
+import { useState } from "react";
+import type { DateRange } from "react-day-picker";
+import type { Meta, StoryObj } from "@storybook/react-vite";
+
+import { Calendar } from "./Calendar";
+
+/**
+ * Calendars let the user pick a date, a set of dates, or a date range.
+ * This component is a thin wrapper around `react-day-picker` — the `mode` prop
+ * switches between `single`, `multiple`, and `range` selection, and `captionLayout`
+ * swaps the month header between a static label and dropdowns for month / year
+ * navigation.
+ */
+const meta = {
+ title: "Generic/Calendar",
+ component: Calendar,
+ parameters: {
+ layout: "centered"
+ },
+ tags: ["autodocs"],
+ argTypes: {
+ mode: {
+ control: "select",
+ options: ["single", "multiple", "range"]
+ },
+ captionLayout: {
+ control: "select",
+ options: ["label", "dropdown", "dropdown-months", "dropdown-years"]
+ },
+ numberOfMonths: {
+ control: { type: "number", min: 1, max: 3 }
+ },
+ showOutsideDays: {
+ control: "boolean"
+ },
+ buttonVariant: {
+ control: "select",
+ options: ["ghost", "outline", "neutral"]
+ }
+ }
+} satisfies Meta<typeof Calendar>;
+
+export default meta;
+type Story = StoryObj<typeof meta>;
+
+const SingleStory = () => {
+ const [selected, setSelected] = useState<Date | undefined>(new Date());
+ return <Calendar mode="single" selected={selected} onSelect={setSelected} />;
+};
+
+export const Single: Story = {
+ name: "Variant: Single",
+ parameters: {
+ docs: {
+ description: {
+ story:
+ 'Use `mode="single"` for a single-date picker. The selected day is highlighted with a filled foreground chip; today\'s date is outlined separately.'
+ }
+ }
+ },
+ render: () => <SingleStory />
+};
+
+const MultipleStory = () => {
+ const today = new Date();
+ const [selected, setSelected] = useState<Date[] | undefined>([
+ today,
+ new Date(today.getFullYear(), today.getMonth(), today.getDate() + 2),
+ new Date(today.getFullYear(), today.getMonth(), today.getDate() + 5)
+ ]);
+ return <Calendar mode="multiple" selected={selected} onSelect={setSelected} />;
+};
+
+export const Multiple: Story = {
+ name: "Variant: Multiple",
+ parameters: {
+ docs: {
+ description: {
+ story:
+ 'Use `mode="multiple"` when the user should pick an arbitrary set of discrete dates. Each selection toggles independently.'
+ }
+ }
+ },
+ render: () => <MultipleStory />
+};
+
+const RangeStory = () => {
+ const today = new Date();
+ const [selected, setSelected] = useState<DateRange | undefined>({
+ from: today,
+ to: new Date(today.getFullYear(), today.getMonth(), today.getDate() + 6)
+ });
+ return <Calendar mode="range" selected={selected} onSelect={setSelected} />;
+};
+
+export const Range: Story = {
+ name: "Variant: Range",
+ parameters: {
+ docs: {
+ description: {
+ story:
+ 'Use `mode="range"` to pick a start / end pair. The first click sets the start; the second sets the end. Days between the bounds render with a muted background — the pattern used by `DateRangeFilter`.'
+ }
+ }
+ },
+ render: () => <RangeStory />
+};
+
+const DropdownCaptionStory = () => {
+ const [selected, setSelected] = useState<Date | undefined>(new Date());
+ return (
+ <Calendar mode="single" captionLayout="dropdown" selected={selected} onSelect={setSelected} />
+ );
+};
+
+export const DropdownCaption: Story = {
+ name: "Example: Dropdown Caption",
+ parameters: {
+ docs: {
+ description: {
+ story:
+ 'Pass `captionLayout="dropdown"` to replace the month label with month + year dropdowns. Use when the user may need to jump across many years (e.g. birthdays, historic audit ranges).'
+ }
+ }
+ },
+ render: () => <DropdownCaptionStory />
+};
+
+const TwoMonthsStory = () => {
+ const today = new Date();
+ const [selected, setSelected] = useState<DateRange | undefined>({
+ from: new Date(today.getFullYear(), today.getMonth(), today.getDate() - 2),
+ to: new Date(today.getFullYear(), today.getMonth() + 1, today.getDate() + 3)
+ });
+ return <Calendar mode="range" numberOfMonths={2} selected={selected} onSelect={setSelected} />;
+};
+
+export const TwoMonths: Story = {
+ name: "Example: Two Months",
+ parameters: {
+ docs: {
+ description: {
+ story:
+ 'Set `numberOfMonths={2}` (or more) to show adjacent months side-by-side. Most useful with `mode="range"` so the user can drag a span across month boundaries without paging.'
+ }
+ }
+ },
+ render: () => <TwoMonthsStory />
+};
+
+const DisabledDatesStory = () => {
+ const [selected, setSelected] = useState<Date | undefined>();
+ return (
+ <Calendar
+ mode="single"
+ selected={selected}
+ onSelect={setSelected}
+ disabled={{ before: new Date() }}
+ />
+ );
+};
+
+export const DisabledDates: Story = {
+ name: "Example: Disabled Dates",
+ parameters: {
+ docs: {
+ description: {
+ story:
+ "Pass a matcher to `disabled` to grey out and block interaction for specific days. The `{ before: new Date() }` matcher here disables every past day — use for forward-only pickers like scheduled rotations or expirations."
+ }
+ }
+ },
+ render: () => <DisabledDatesStory />
+};
diff --git a/frontend/src/components/v3/generic/Calendar/Calendar.tsx b/frontend/src/components/v3/generic/Calendar/Calendar.tsx
index 6ed1316f10..1c97b5feb5 100644
--- a/frontend/src/components/v3/generic/Calendar/Calendar.tsx
+++ b/frontend/src/components/v3/generic/Calendar/Calendar.tsx
@@ -39,7 +39,7 @@ function CalendarDayButton({
data-range-end={modifiers.range_end}
data-range-middle={modifiers.range_middle}
className={cn(
- "relative isolate z-10 flex aspect-square size-auto w-full min-w-(--cell-size) flex-col gap-1 border-0 leading-none font-normal group-data-[focused=true]/day:relative group-data-[focused=true]/day:z-10 group-data-[focused=true]/day:border-ring group-data-[focused=true]/day:ring-[3px] group-data-[focused=true]/day:ring-ring/50 hover:text-foreground data-[range-end=true]:rounded-(--cell-radius) data-[range-end=true]:rounded-r-(--cell-radius) data-[range-end=true]:bg-foreground data-[range-end=true]:text-background data-[range-end=true]:hover:text-background data-[range-middle=true]:rounded-none data-[range-middle=true]:bg-muted data-[range-middle=true]:text-foreground data-[range-start=true]:rounded-(--cell-radius) data-[range-start=true]:rounded-l-(--cell-radius) data-[range-start=true]:bg-foreground data-[range-start=true]:text-background data-[range-start=true]:hover:text-background data-[selected-single=true]:bg-foreground data-[selected-single=true]:text-background data-[selected-single=true]:hover:text-background [&>span]:text-xs [&>span]:opacity-70",
+ "relative isolate z-10 flex aspect-square size-auto w-full min-w-(--cell-size) flex-col gap-1 border-0 leading-none font-normal group-data-[focused=true]/day:relative group-data-[focused=true]/day:z-10 group-data-[focused=true]/day:border-ring group-data-[focused=true]/day:ring-[3px] group-data-[focused=true]/day:ring-ring/50 hover:text-foreground data-[range-end=true]:rounded-(--cell-radius) data-[range-end=true]:rounded-r-(--cell-radius) data-[range-end=true]:bg-foreground data-[range-end=true]:text-background data-[range-end=true]:hover:text-background data-[range-middle=true]:rounded-none data-[range-middle=true]:bg-muted/[12%] data-[range-middle=true]:text-foreground data-[range-start=true]:rounded-(--cell-radius) data-[range-start=true]:rounded-l-(--cell-radius) data-[range-start=true]:bg-foreground data-[range-start=true]:text-background data-[range-start=true]:hover:text-background data-[selected-single=true]:bg-foreground data-[selected-single=true]:text-background data-[selected-single=true]:hover:text-background [&>span]:text-xs [&>span]:opacity-70",
defaultClassNames.day,
className
)}
@@ -67,7 +67,7 @@ function Calendar({
<DayPicker
showOutsideDays={showOutsideDays}
className={cn(
- "group/calendar bg-background p-2 [--cell-radius:var(--radius-md)] [--cell-size:--spacing(8)] in-data-[slot=card-content]:bg-transparent in-data-[slot=popover-content]:bg-transparent",
+ "group/calendar bg-background p-2 text-foreground [--cell-radius:var(--radius-md)] [--cell-size:--spacing(8)] in-data-[slot=card-content]:bg-transparent in-data-[slot=popover-content]:bg-transparent",
String.raw`rtl:**:[.rdp-button\_next>svg]:rotate-180`,
String.raw`rtl:**:[.rdp-button\_previous>svg]:rotate-180`,
className
@@ -136,12 +136,12 @@ function Calendar({
defaultClassNames.day
),
range_start: cn(
- "rounded-l-(--cell-radius) bg-muted relative after:bg-muted after:absolute after:inset-y-0 after:w-4 after:right-0 z-0 isolate",
+ "rounded-l-(--cell-radius) bg-muted/[12%] relative after:bg-muted/[12%] after:absolute after:inset-y-0 after:w-4 after:right-0 z-0 isolate",
defaultClassNames.range_start
),
range_middle: cn("rounded-none", defaultClassNames.range_middle),
range_end: cn(
- "rounded-r-(--cell-radius) bg-muted relative after:bg-muted after:absolute after:inset-y-0 after:w-4 after:left-0 z-0 isolate",
+ "rounded-r-(--cell-radius) bg-muted/[12%] relative after:bg-muted/[12%] after:absolute after:inset-y-0 after:w-4 after:left-0 z-0 isolate",
defaultClassNames.range_end
),
today: cn(
@@ -152,7 +152,7 @@ function Calendar({
"[&_button]:text-accent [&_button]:aria-selected:text-accent",
defaultClassNames.outside
),
- disabled: cn("[&_button]:text-accent opacity-50", defaultClassNames.disabled),
+ disabled: cn("[&_button]:text-accent", defaultClassNames.disabled),
hidden: cn("invisible", defaultClassNames.hidden),
...classNames
}}