Report Period Header
Analytics report header with a date range: preset periods or a custom range recompute visits, page views, conversions and conversion rate from sample data.
"use client"
import { useId, useState } from "react"
import {
eachDayOfInterval,
endOfDay,
format,
isSameDay,
isWithinInterval,
startOfDay,
subDays,
} from "date-fns"
import type { DateRange } from "react-day-picker"
import { DateRangePicker } from "@/components/controls/date-range-picker"
import {
Stat,
StatLabel,
StatValue,
} from "@/components/stats/stats"
import {
Card,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from "@/components/ui/card"
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"
// The sample "today". It is a fixed date so the server and the browser
// render the same days; every other date here counts from it. In your app,
// read the real date where you load the data.
const TODAY = new Date(2026, 10, 17)
// The copy: change text here, not in the markup.
const COPY = {
title: "Website performance",
description: "A clear view of the period you choose.",
period: "Period",
placeholder: "All available dates",
presets: "Report period presets",
preset: (days: number) => `Last ${days} days`,
visits: "Visits",
views: "Page views",
conversions: "Conversions",
rate: "Conversion rate",
days: (count: number, first: string, last: string) =>
`${count} ${count === 1 ? "day" : "days"} with data · ${first} – ${last}`,
empty: "No sample data for this period. Choose another range.",
sample: (first: string, last: string) =>
`Sample data available ${first} – ${last}.`,
} as const
const PRESETS = [7, 30, 90] as const
// 180 days of sample traffic, ending today.
const REPORT_DAYS = eachDayOfInterval({
start: subDays(TODAY, 179),
end: TODAY,
}).map((date, index) => {
const weekend = date.getDay() === 0 || date.getDay() === 6
const visits = 180 + ((index * 37) % 190) + (weekend ? -60 : 55)
return {
date,
visits,
views: Math.round(visits * (2.1 + (index % 5) * 0.16)),
conversions: Math.round(visits * (0.022 + (index % 7) * 0.002)),
}
})
function lastDays(days: number): DateRange {
return { from: subDays(TODAY, days - 1), to: TODAY }
}
/**
* A report card whose date range recomputes its four figures: pick a preset
* period or an exact range, and visits, page views, conversions and the
* conversion rate follow from the sample data.
*
* The layout follows the card's own width, not the screen's (a container
* query on the Card), so it also fits a sidebar, a dialog or half a page.
*
* The words live in `COPY`, the presets in `PRESETS` and the data in
* `REPORT_DAYS`.
*/
export default function ReportPeriod01() {
const id = useId()
const [range, setRange] = useState<DateRange | undefined>(() => lastDays(30))
const days = range?.from
? REPORT_DAYS.filter((day) =>
isWithinInterval(day.date, {
start: startOfDay(range.from!),
end: endOfDay(range.to ?? range.from!),
})
)
: REPORT_DAYS
const totals = days.reduce(
(sum, day) => ({
visits: sum.visits + day.visits,
views: sum.views + day.views,
conversions: sum.conversions + day.conversions,
}),
{ visits: 0, views: 0, conversions: 0 }
)
const metrics = [
{ label: COPY.visits, value: totals.visits.toLocaleString("en-US") },
{ label: COPY.views, value: totals.views.toLocaleString("en-US") },
{
label: COPY.conversions,
value: totals.conversions.toLocaleString("en-US"),
},
{
label: COPY.rate,
value: `${totals.visits ? ((totals.conversions / totals.visits) * 100).toFixed(2) : "0.00"}%`,
},
]
const first = days[0]?.date
const last = days.at(-1)?.date
// The preset the range matches, if any, so its toggle shows as pressed.
const preset = PRESETS.find((length) => {
const match = lastDays(length)
return (
range?.from &&
range.to &&
isSameDay(range.from, match.from!) &&
isSameDay(range.to, match.to!)
)
})
return (
<Card
role="region"
aria-labelledby={`${id}-title`}
className="@container/report mx-auto w-full max-w-3xl"
>
<CardHeader>
<CardTitle>
<h2 id={`${id}-title`}>{COPY.title}</h2>
</CardTitle>
<CardDescription>{COPY.description}</CardDescription>
</CardHeader>
<CardContent className="flex flex-col gap-6">
<div className="flex flex-wrap items-end justify-between gap-4">
<DateRangePicker
label={COPY.period}
value={range}
onValueChange={setRange}
placeholder={COPY.placeholder}
className="w-auto"
/>
<ToggleGroup
aria-label={COPY.presets}
variant="outline"
className="flex-wrap"
value={preset ? [String(preset)] : []}
onValueChange={(next) => {
const length = Number(next[0])
if (length) setRange(lastDays(length))
}}
>
{PRESETS.map((length) => (
<ToggleGroupItem key={length} value={String(length)}>
{COPY.preset(length)}
</ToggleGroupItem>
))}
</ToggleGroup>
</div>
{/* Laid out here, not with StatGroup: that part's columns follow
the screen, and these follow the card. */}
<ul
role="list"
className="grid gap-6 @xs/report:grid-cols-2 @2xl/report:grid-cols-4"
>
{metrics.map((metric) => (
<Stat key={metric.label}>
<StatValue className="tabular-nums">{metric.value}</StatValue>
<StatLabel>{metric.label}</StatLabel>
</Stat>
))}
</ul>
</CardContent>
<CardFooter className="flex-col items-start gap-1 border-t text-xs text-muted-foreground">
<span role="status">
{first && last
? COPY.days(
days.length,
format(first, "MMM d"),
format(last, "MMM d, yyyy")
)
: COPY.empty}
</span>
<span>
{COPY.sample(
format(REPORT_DAYS[0].date, "MMM d"),
format(TODAY, "MMM d, yyyy")
)}
</span>
</CardFooter>
</Card>
)
}
"use client"
import { useId, useState, type ComponentProps, type ReactNode } from "react"
import { zodResolver } from "@hookform/resolvers/zod"
import { CalendarBlankIcon } from "@phosphor-icons/react"
import { cn } from "cn"
import { format, isValid, parse } from "date-fns"
import { type DateRange } from "react-day-picker"
import { Controller, useForm, useWatch } from "react-hook-form"
import { z } from "zod"
import { Button } from "@/components/ui/button"
import { Calendar } from "@/components/ui/calendar"
import { Field, FieldError, FieldLabel } from "@/components/ui/field"
import { Input } from "@/components/ui/input"
import { Kbd } from "@/components/ui/kbd"
import {
Popover,
PopoverContent,
PopoverTitle,
PopoverTrigger,
} from "@/components/ui/popover"
type DateRangePickerProps = Omit<
ComponentProps<typeof Field>,
"children" | "defaultValue"
> & {
/** The field's label, tied to the button that opens the calendar. It also names the popup. */
label: ReactNode
/** The button's text before any range is applied. */
placeholder: ReactNode
/** Controlled with value + onValueChange, or seeded with defaultValue. */
value?: DateRange
/**
* The range applied at first, when the picker keeps the value itself.
* Make the dates in a client file: a Date passed down from a Server
* Component arrives as a fixed instant, and can read as the day before
* or after in the reader's time zone.
*/
defaultValue?: DateRange
/** Called with the range each time one is applied, and with `undefined` when it is cleared. */
onValueChange?: (range: DateRange | undefined) => void
/**
* date-fns pattern for the button's text. By default the date, and with
* `time` the date and the time.
*/
dateFormat?: string
/** How many months the calendar shows side by side; 1 by default. */
numberOfMonths?: number
/**
* Adds a start and an end time field, read in the reader's own time zone.
* Off by default: the range is then two days, each at midnight.
*/
time?: boolean
/** Opens the calendar on first render. */
defaultOpen?: boolean
}
// What the fields hold while a range is being chosen: text, as typed.
type Draft = {
startDate: string
startTime: string
endDate: string
endTime: string
}
// How the fields write a value, and the other forms they accept when typed.
const DATE_TEXT = "MMM dd, yyyy"
const TIME_TEXT = "hh:mm a"
const DATE_FORMATS = [
"MMM d, yyyy",
"MMM d yyyy",
"MMMM d, yyyy",
"M/d/yyyy",
"yyyy-MM-dd",
]
const TIME_FORMATS = ["h:mm a", "h:mma", "h a", "ha", "H:mm"]
// The picker's own words: change or translate them here.
const COPY = {
start: "Start",
end: "End",
startTime: "Start time",
endTime: "End time",
datePlaceholder: "Jan 05, 2026",
timePlaceholder: "1:00 PM",
clear: "Clear",
apply: "Apply",
errors: {
date: "Enter a date like Jan 5, 2026.",
time: "Enter a time like 1:00 PM.",
gap: "That time does not exist on this day.",
order: "The end is before the start.",
},
} as const
// A fixed day with no clock change, for reading a time by itself.
const PLAIN_DAY = new Date(2001, 0, 1)
/**
* The day a typed date names, at midnight; `undefined` when it is not a
* date. Only a four-digit year is taken: a year still being typed
* ("Jan 5, 2") and one with a digit too many ("Jan 5, 20266") both read as
* real years otherwise.
*/
function readDate(text: string) {
for (const pattern of DATE_FORMATS) {
const date = parse(text.trim(), pattern, PLAIN_DAY)
const year = date.getFullYear()
if (isValid(date) && year >= 1000 && year <= 9999) return date
}
return undefined
}
/** The hour and minute a typed time names; `undefined` when it is not a time. */
function readTime(text: string) {
for (const pattern of TIME_FORMATS) {
const date = parse(text.trim(), pattern, PLAIN_DAY)
if (isValid(date))
return { hours: date.getHours(), minutes: date.getMinutes() }
}
return undefined
}
/**
* A day at a time of day, in the reader's own zone; `undefined` when the
* clock skips that time on that day, as it does when daylight saving
* starts. When the clock repeats an hour, this is its first occurrence.
*/
function at(day: Date, clock: { hours: number; minutes: number }) {
const date = new Date(
day.getFullYear(),
day.getMonth(),
day.getDate(),
clock.hours,
clock.minutes
)
return date.getHours() === clock.hours && date.getMinutes() === clock.minutes
? date
: undefined
}
type Problem = { field: keyof Draft; message: string }
/**
* Reads the four fields into a range, or into the list of what is wrong
* with them. The schema and Apply both use it, so what validates is exactly
* what is applied.
*/
function readDraft(draft: Draft, time: boolean) {
const problems: Problem[] = []
const startDay = readDate(draft.startDate)
const endDay = readDate(draft.endDate)
if (!startDay)
problems.push({ field: "startDate", message: COPY.errors.date })
if (!endDay) problems.push({ field: "endDate", message: COPY.errors.date })
let from = startDay
let to = endDay
if (time) {
const startClock = readTime(draft.startTime)
const endClock = readTime(draft.endTime)
if (!startClock)
problems.push({ field: "startTime", message: COPY.errors.time })
if (!endClock)
problems.push({ field: "endTime", message: COPY.errors.time })
if (startDay && startClock) {
from = at(startDay, startClock)
if (!from) problems.push({ field: "startTime", message: COPY.errors.gap })
}
if (endDay && endClock) {
to = at(endDay, endClock)
if (!to) problems.push({ field: "endTime", message: COPY.errors.gap })
}
}
if (from && to && to < from)
problems.push({ field: "endDate", message: COPY.errors.order })
return problems.length || !from || !to
? { problems, range: undefined }
: { problems, range: { from, to } satisfies DateRange }
}
/** The fields' text for an applied range; empty when there is none. */
function toDraft(range: DateRange | undefined, time: boolean): Draft {
return {
startDate: range?.from ? format(range.from, DATE_TEXT) : "",
startTime: range?.from && time ? format(range.from, TIME_TEXT) : "",
endDate: range?.to ? format(range.to, DATE_TEXT) : "",
endTime: range?.to && time ? format(range.to, TIME_TEXT) : "",
}
}
/** The form's schema: every problem `readDraft` finds, on its own field. */
const draftSchema = (time: boolean) =>
z
.object({
startDate: z.string(),
startTime: z.string(),
endDate: z.string(),
endTime: z.string(),
})
.superRefine((draft, context) => {
for (const problem of readDraft(draft, time).problems) {
context.addIssue({
code: "custom",
path: [problem.field],
message: problem.message,
})
}
})
/**
* A labelled button that opens a date range picker in a popover and shows
* the applied range. Pick two days in the calendar, or type the start and
* end dates in the fields under it. Nothing changes until Apply, which
* Enter also triggers; a field that cannot be read says so and blocks
* Apply. Clear empties the range.
*
* With `time`, each end also has a time field, read in the reader's own
* time zone; without it the range is two days at midnight. With one month
* the popover is 280px wide, or as wide as the screen allows, and the
* calendar and the fields share that width. The picker's own words
* (Start, End, Clear, Apply and the error messages) live in `COPY`. Other
* props go to the Field.
*/
function DateRangePicker(pickerProps: DateRangePickerProps) {
const {
label,
placeholder,
value,
defaultValue,
onValueChange,
numberOfMonths = 1,
time = false,
dateFormat = time ? "LLL dd, y h:mm a" : "LLL dd, y",
defaultOpen = false,
className,
...props
} = pickerProps
const id = useId()
const [uncontrolled, setUncontrolled] = useState(defaultValue)
const controlled = Object.hasOwn(pickerProps, "value")
const range = controlled ? value : uncontrolled
const [open, setOpen] = useState(defaultOpen)
const [month, setMonth] = useState(range?.from ?? new Date())
const form = useForm<Draft>({
resolver: zodResolver(draftSchema(time)),
defaultValues: toDraft(range, time),
})
const draft = useWatch({ control: form.control })
// The days the calendar marks: whatever the two date fields read as now.
const shownFrom = readDate(draft.startDate ?? "")
const typedTo = readDate(draft.endDate ?? "")
// An end typed before the start is not drawn: the calendar would take its
// next pick from a range that runs backwards.
const shownTo =
shownFrom && typedTo && typedTo >= shownFrom ? typedTo : undefined
const anyText = Object.values(draft).some(Boolean)
// A time field's error counts only while the time fields are shown.
const { errors } = form.formState
const startErrors = [errors.startDate, time ? errors.startTime : undefined]
const endErrors = [errors.endDate, time ? errors.endTime : undefined]
const startWrong = startErrors.some(Boolean)
const endWrong = endErrors.some(Boolean)
// Once Apply has been tried, every change checks all four fields again:
// fixing the start also settles "the end is before the start".
function recheck() {
if (form.formState.isSubmitted) void form.trigger()
}
function write(field: keyof Draft, text: string) {
form.setValue(field, text, { shouldDirty: true })
}
// The calendar writes the days it is given into the two date fields. With
// `time`, an empty time field gets the start or the end of the day, once
// its own date is picked: a time with no date would look half-filled.
function pickDays(next: DateRange | undefined) {
write("startDate", next?.from ? format(next.from, DATE_TEXT) : "")
write("endDate", next?.to ? format(next.to, DATE_TEXT) : "")
if (time) {
if (next?.from && !form.getValues("startTime"))
write("startTime", "12:00 AM")
if (next?.to && !form.getValues("endTime")) write("endTime", "11:59 PM")
}
recheck()
}
function apply(values: Draft) {
const next = readDraft(values, time).range
if (!next) return
if (!controlled) setUncontrolled(next)
onValueChange?.(next)
setOpen(false)
}
// Clear empties the range straight away, with no Apply.
function clear() {
form.reset(toDraft(undefined, time))
if (!controlled) setUncontrolled(undefined)
onValueChange?.(undefined)
setOpen(false)
}
return (
<Field data-slot="date-range-picker" className={className} {...props}>
<FieldLabel htmlFor={id}>{label}</FieldLabel>
<Popover
open={open}
onOpenChange={(next) => {
// Opening starts again from the applied range.
if (next) {
form.reset(toDraft(range, time))
setMonth(range?.from ?? new Date())
}
setOpen(next)
}}
>
<PopoverTrigger
render={
<Button
variant="outline"
id={id}
className="justify-start px-2.5 font-normal"
/>
}
>
<CalendarBlankIcon data-icon="inline-start" />
{range?.from ? (
range.to ? (
<>
{format(range.from, dateFormat)} -{" "}
{format(range.to, dateFormat)}
</>
) : (
format(range.from, dateFormat)
)
) : (
<span>{placeholder}</span>
)}
</PopoverTrigger>
{/* 280px for one month, or the room the screen has: the popup
scrolls inside that, so nothing runs off a phone. More months
set their own width. */}
<PopoverContent
className={cn(
"max-h-(--available-height) max-w-(--available-width) overflow-y-auto",
numberOfMonths === 1 ? "w-70" : "w-auto"
)}
align="start"
>
<PopoverTitle className="sr-only">{label}</PopoverTitle>
{/* The calendar takes the popup's width, as the fields below do. */}
<Calendar
mode="range"
month={month}
onMonthChange={setMonth}
selected={shownFrom ? { from: shownFrom, to: shownTo } : undefined}
onSelect={pickDays}
numberOfMonths={numberOfMonths}
className="p-0"
classNames={{ root: "w-full" }}
/>
<form
className="grid gap-3"
noValidate
onSubmit={(event) => {
// The popup is a portal, so React would pass this submit on to
// a form the picker sits in. It ends here.
event.stopPropagation()
void form.handleSubmit(apply)(event)
}}
>
<Field data-invalid={startWrong}>
<FieldLabel htmlFor={`${id}-start`}>{COPY.start}</FieldLabel>
<div className="flex gap-2">
<Controller
control={form.control}
name="startDate"
render={({ field, fieldState }) => (
<Input
{...field}
id={`${id}-start`}
placeholder={COPY.datePlaceholder}
autoComplete="off"
spellCheck={false}
aria-invalid={fieldState.invalid}
aria-describedby={
startWrong ? `${id}-start-error` : undefined
}
onChange={(event) => {
field.onChange(event)
recheck()
// The calendar follows a date as soon as it reads.
const day = readDate(event.target.value)
if (day) setMonth(day)
}}
/>
)}
/>
{time ? (
<Controller
control={form.control}
name="startTime"
render={({ field, fieldState }) => (
<Input
{...field}
onChange={(event) => {
field.onChange(event)
recheck()
}}
aria-label={COPY.startTime}
placeholder={COPY.timePlaceholder}
autoComplete="off"
spellCheck={false}
aria-invalid={fieldState.invalid}
aria-describedby={
startWrong ? `${id}-start-error` : undefined
}
className="w-36"
/>
)}
/>
) : null}
</div>
<FieldError id={`${id}-start-error`} errors={startErrors} />
</Field>
<Field data-invalid={endWrong}>
<FieldLabel htmlFor={`${id}-end`}>{COPY.end}</FieldLabel>
<div className="flex gap-2">
<Controller
control={form.control}
name="endDate"
render={({ field, fieldState }) => (
<Input
{...field}
id={`${id}-end`}
onChange={(event) => {
field.onChange(event)
recheck()
}}
placeholder={COPY.datePlaceholder}
autoComplete="off"
spellCheck={false}
aria-invalid={fieldState.invalid}
aria-describedby={
endWrong ? `${id}-end-error` : undefined
}
/>
)}
/>
{time ? (
<Controller
control={form.control}
name="endTime"
render={({ field, fieldState }) => (
<Input
{...field}
onChange={(event) => {
field.onChange(event)
recheck()
}}
aria-label={COPY.endTime}
placeholder={COPY.timePlaceholder}
autoComplete="off"
spellCheck={false}
aria-invalid={fieldState.invalid}
aria-describedby={
endWrong ? `${id}-end-error` : undefined
}
className="w-36"
/>
)}
/>
) : null}
</div>
<FieldError id={`${id}-end-error`} errors={endErrors} />
</Field>
<div className="flex gap-2">
<Button
type="button"
variant="ghost"
disabled={!range?.from && !anyText}
onClick={clear}
>
{COPY.clear}
</Button>
<Button type="submit" variant="outline" className="flex-1">
{COPY.apply}
<Kbd aria-hidden="true">↵</Kbd>
</Button>
</div>
</form>
</PopoverContent>
</Popover>
</Field>
)
}
export { DateRangePicker }
import type { ComponentProps } from "react"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "cn"
import { Grid, type GridProps } from "@/components/grid/grid"
/**
* A list of `Stat` items laid out by `Grid`, rendered as a `ul`. It defaults
* to 3 columns and the large gap. Like `Grid`, its columns follow the width
* it is given, so size its parent to narrow it. `className` lands on the
* list.
*/
function StatGroup({
cols = 3,
gap = "lg",
...props
}: ComponentProps<"ul"> & {
/**
* The most columns, 3 by default. They step up as the list's space
* widens, the way `Grid`'s do.
*/
cols?: GridProps["cols"]
/**
* Space between stats: `xs` 8px, `sm` 16px, `md` 24px, `lg` 40px, `xl` 64px, `px` 1px, `none` 0. `lg`
* is the default.
*/
gap?: GridProps["gap"]
}) {
return (
<Grid
data-slot="stat-group"
render={<ul role="list" />}
cols={cols}
gap={gap}
// Grid's props are typed for its default div; this group renders a list.
{...(props as Omit<GridProps, "cols" | "gap">)}
/>
)
}
// card sets the stat on a filled panel; rule sets a line down its left side.
const statVariants = cva("grid content-start gap-2", {
variants: {
/**
* The stat style. `default` (the default) adds nothing. `card` sets it
* on a `rounded-xl` panel with 32px padding, filled with `muted`, or
* with `card` and `card-foreground` text in dark mode. `rule` draws a
* 1px line in `border` down its left side, 24px from the text.
*/
variant: {
default: "",
card: "rounded-xl bg-muted p-8 dark:bg-card dark:text-card-foreground",
rule: "border-l border-border pl-6",
},
},
defaultVariants: { variant: "default" },
})
/**
* One figure and its label, as an `li` inside `StatGroup`. Holds a
* `StatValue` and a `StatLabel`, stacked with 8px gaps.
*
* `card` sets it on a filled, rounded panel with 32px padding. `rule` draws a
* line down its left side.
*/
function Stat({
className,
variant = "default",
...props
}: ComponentProps<"li"> & VariantProps<typeof statVariants>) {
return (
<li
data-slot="stat"
data-variant={variant}
className={cn(statVariants({ variant }), className)}
{...props}
/>
)
}
/** The figure itself, such as a number or a percentage, at 32px in the body font. */
function StatValue({ className, ...props }: ComponentProps<"p">) {
return (
<p
data-slot="stat-value"
className={cn("text-[2rem]/10 tracking-tight", className)}
{...props}
/>
)
}
/**
* The caption under the figure: what it measures, in a few words. Small
* muted text, 14px on a 20px line, so the number carries the weight. Longer
* explanation belongs in the section's lead or a note, not here.
*/
function StatLabel({ className, ...props }: ComponentProps<"p">) {
return (
<p
data-slot="stat-label"
className={cn("text-sm/5 text-pretty text-muted-foreground", className)}
{...props}
/>
)
}
export { StatGroup, Stat, StatValue, StatLabel }
import { mergeProps } from "@base-ui/react/merge-props"
import { useRender } from "@base-ui/react/use-render"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "cn"
const GRID_DEFAULTS = { cols: 3, gap: "lg" } as const
const containerGridVariants = cva("grid w-full grid-cols-1", {
variants: {
/**
* The most columns. Below 40rem of screen width the grid is one
* column (two for `6`); it steps up at 40rem and 48rem: `2` is two
* columns from 40rem, `3` two then three, `4` two then four, `5` three
* then five, and `6` three, then four, then six from 64rem. The default
* is 3.
*/
cols: {
1: "",
2: "sm:grid-cols-2",
3: "sm:grid-cols-2 md:grid-cols-3",
4: "sm:grid-cols-2 md:grid-cols-4",
5: "sm:grid-cols-3 md:grid-cols-5",
6: "grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-6",
},
/**
* Space between items: `xs` 8px, `sm` 16px, `md` 24px, `lg` 40px, `xl` 64px, `px` 1px, `none` 0. `lg`
* is the default. The sizes are the `--gap-*` values in globals.css.
*/
gap: {
xs: "gap-(--gap-xs)",
sm: "gap-(--gap-sm)",
md: "gap-(--gap-md)",
lg: "gap-(--gap-lg)",
xl: "gap-(--gap-xl)",
px: "gap-px",
none: "gap-0",
},
},
defaultVariants: GRID_DEFAULTS,
})
type GridState = { slot: "grid" } & VariantProps<typeof containerGridVariants>
type GridProps = useRender.ComponentProps<"div", GridState> &
VariantProps<typeof containerGridVariants>
/**
* Columns follow the screen, stepping at 40rem and 48rem (and 64rem for six).
* Gap sizes read the shared `--gap-*` values in globals.css. The grid fills
* its parent's width: without that, a grid given `mx-auto` or set inside a
* centering parent shrinks to fit its content, and a part built on it that
* is a container collapses to nothing.
*
* className, render and every other prop go to the grid. To narrow a Grid, pass
* a `max-w-*` class or size its parent.
*/
function Grid({
className,
cols = GRID_DEFAULTS.cols,
gap = GRID_DEFAULTS.gap,
render,
...props
}: GridProps) {
const grid = useRender({
defaultTagName: "div",
render,
state: { slot: "grid", cols, gap },
props: mergeProps<"div">(
{ className: cn(containerGridVariants({ cols, gap }), className) },
props
),
})
return grid
}
export { Grid, type GridProps }
Installation
npx shadcn@latest add @01orbital/report-period-01Make it yours
- Its words are in
COPYat the top ofcomponents/blocks/controls/report-period-01/index.tsx: change them there, not in the markup. TODAY,PRESETSandREPORT_DAYS, also at the top of the file, hold its lists and settings.
Built from
npm: date-fns, react-day-picker. The CLI installs them for you.
Built from these parts. The CLI adds each one that is missing and won't replace a file you already have unless you choose to:
The shadcn parts here are their Base UI versions, and this piece uses Base UI's API. A Radix version you already have won't work with it.
Last updated on