Motion calendars
Five calendars that differ only in how the month grid animates when you navigate: a directional slide, a cross-fade, a pop, a spring settle and a 3D morph. Each is self-contained (no date library), keeps the month and selection state outside the animated subtree, and starts from a fixed month so the output stays deterministic.
Installation
The styled layer is free and installs like any other ai2 component.
Run the following command
npx shadcn@latest add @ai2/calendar-motionDependencies, the @ai2/tokens theme and the component file are installed together.
Install dependencies
npm install motion lucide-reactCopy the source
components/ui/calendar-motion.tsx"use client"
import * as React from "react"
import type { TargetAndTransition, Transition } from "motion/react"
import { motion, useReducedMotion } from "motion/react"
import { ChevronLeft, ChevronRight } from "lucide-react"
import { cn } from "@/lib/utils"
/* Motion calendar family: 5 month grids that animate the month change in different ways. Determinism: the visible month derives from a FIXED constant (January 2026), NOT from the clock. The month state is held OUTSIDE the grid; only the grid is remounted on the month key, so prev and next always work. Motion is disabled with useReducedMotion(). Colour comes ONLY from semantic tokens. */
export type StyledSize = "sm" | "md" | "lg" | "xl"
const MONTHS = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
] as const
const WEEKDAYS = ["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"] as const
const FIXED_MONTH = new Date(2026, 0, 1)
function startOfMonth(d: Date) {
return new Date(d.getFullYear(), d.getMonth(), 1)
}
function addMonths(d: Date, n: number) {
return new Date(d.getFullYear(), d.getMonth() + n, 1)
}
function isSameDay(a: Date | null | undefined, b: Date | null | undefined) {
return (
!!a &&
!!b &&
a.getFullYear() === b.getFullYear() &&
a.getMonth() === b.getMonth() &&
a.getDate() === b.getDate()
)
}
function buildMonthGrid(month: Date): Date[] {
const first = startOfMonth(month)
const offset = (first.getDay() + 6) % 7
const start = new Date(first)
start.setDate(first.getDate() - offset)
const days: Date[] = []
for (let i = 0; i < 42; i++) {
const d = new Date(start)
d.setDate(start.getDate() + i)
days.push(d)
}
return days
}
function toWeeks(days: Date[]): Date[][] {
const weeks: Date[][] = []
for (let i = 0; i < days.length; i += 7) weeks.push(days.slice(i, i + 7))
return weeks
}
function ariaLabel(d: Date) {
return `${MONTHS[d.getMonth()]} ${d.getDate()}, ${d.getFullYear()}`
}
/* Ay + yon durumu. Animasyonlu alt agacin DISINDA yasar. */
function useVisibleMonth(defaultMonth?: Date) {
const [visible, setVisible] = React.useState<Date>(() =>
startOfMonth(defaultMonth ?? FIXED_MONTH)
)
const [dir, setDir] = React.useState(0)
const goPrev = React.useCallback(() => {
setDir(-1)
setVisible((m) => addMonths(m, -1))
}, [])
const goNext = React.useCallback(() => {
setDir(1)
setVisible((m) => addMonths(m, 1))
}, [])
return { visible, dir, goPrev, goNext }
}
/* Secili gun durumu da izgaranin disinda yasar; ay degisiminde kaybolmaz. */
function useSelected(defaultValue?: Date, onSelect?: (d: Date) => void) {
const [selected, setSelected] = React.useState<Date | undefined>(defaultValue)
const select = React.useCallback(
(d: Date) => {
setSelected(d)
onSelect?.(d)
},
[onSelect]
)
return { selected, select }
}
const cellSizes: Record<StyledSize, string> = {
sm: "size-8 text-xs",
md: "size-9 text-sm",
lg: "size-10 text-sm",
xl: "size-11 text-base",
}
const navButton =
"inline-flex size-7 items-center justify-center rounded-md text-muted-foreground outline-none transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:ring-[3px] focus-visible:ring-ring/50 [&_svg]:size-4 [&_svg]:shrink-0 [&_i]:text-base [&_i]:leading-none"
const dayBase =
"relative inline-flex items-center justify-center rounded-md font-normal text-foreground outline-none transition-colors duration-(--motion-fast) ease-(--motion-ease) hover:bg-accent hover:text-accent-foreground focus-visible:z-10 focus-visible:ring-[3px] focus-visible:ring-ring/50 motion-reduce:transition-none"
const daySelected =
"bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground"
const dayOutside = "text-muted-foreground/50"
interface MonthMotion {
initial: TargetAndTransition
animate: TargetAndTransition
transition: Transition
}
export interface MotionCalendarProps {
className?: string
size?: StyledSize
defaultMonth?: Date
defaultValue?: Date
onSelect?: (d: Date) => void
}
/* Shared body. buildMotion produces the month grid's entry animation from the direction; no animation at all is applied under reduced motion. */
function MotionCalendarBase({
props,
buildMotion,
perspective,
}: {
props: MotionCalendarProps
buildMotion: (dir: number) => MonthMotion
perspective?: boolean
}) {
const { className, size = "md", defaultMonth, defaultValue, onSelect } = props
const { visible, dir, goPrev, goNext } = useVisibleMonth(defaultMonth)
const { selected, select } = useSelected(defaultValue, onSelect)
const reduce = useReducedMotion()
const titleId = React.useId()
const weeks = toWeeks(buildMonthGrid(visible))
const monthKey = `${visible.getFullYear()}-${visible.getMonth()}`
const m = buildMotion(dir)
return (
<div
data-slot="styled-calendar"
role="grid"
aria-labelledby={titleId}
className={cn(
"inline-block rounded-xl border border-border bg-card p-3 text-card-foreground",
className
)}
>
<div className="mb-2 flex items-center justify-between gap-2 px-1">
<button type="button" onClick={goPrev} aria-label="Previous month" className={navButton}>
<ChevronLeft />
</button>
<div id={titleId} aria-live="polite" className="text-sm font-medium">
{MONTHS[visible.getMonth()]} {visible.getFullYear()}
</div>
<button type="button" onClick={goNext} aria-label="Next month" className={navButton}>
<ChevronRight />
</button>
</div>
<div role="row" className="grid grid-cols-7 gap-1">
{WEEKDAYS.map((w) => (
<div
key={w}
role="columnheader"
className="flex items-center justify-center py-1 text-xs font-medium text-muted-foreground"
>
{w}
</div>
))}
</div>
<div
className="relative overflow-hidden"
style={perspective && !reduce ? { perspective: "800px" } : undefined}
>
<motion.div
key={monthKey}
initial={reduce ? false : m.initial}
animate={reduce ? {} : m.animate}
transition={reduce ? { duration: 0 } : m.transition}
>
{weeks.map((week) => (
<div key={week[0].toISOString()} role="row" className="grid grid-cols-7 gap-1">
{week.map((d) => {
const outside = d.getMonth() !== visible.getMonth()
const isSelected = isSameDay(d, selected)
return (
<button
key={d.toISOString()}
type="button"
role="gridcell"
aria-label={ariaLabel(d)}
aria-selected={isSelected}
onClick={() => select(d)}
className={cn(
dayBase,
cellSizes[size],
outside && dayOutside,
isSelected && daySelected
)}
>
{d.getDate()}
</button>
)
})}
</div>
))}
</motion.div>
</div>
</div>
)
}
/* ---- 1. SlideCalendar: yon bilgisine gore yatay kayma ---- */
export function SlideCalendar(props: MotionCalendarProps) {
return (
<MotionCalendarBase
props={props}
buildMotion={(dir) => ({
initial: { x: dir >= 0 ? "20%" : "-20%", opacity: 0 },
animate: { x: 0, opacity: 1 },
transition: { duration: 0.24, ease: "easeOut" },
})}
/>
)
}
/* ---- 2. FadeCalendar: an opacity transition only ---- */
export function FadeCalendar(props: MotionCalendarProps) {
return (
<MotionCalendarBase
props={props}
buildMotion={() => ({
initial: { opacity: 0 },
animate: { opacity: 1 },
transition: { duration: 0.28, ease: "easeOut" },
})}
/>
)
}
/* ---- 3. PopCalendar: kucukten normale olcek + opaklik ---- */
export function PopCalendar(props: MotionCalendarProps) {
return (
<MotionCalendarBase
props={props}
buildMotion={() => ({
initial: { scale: 0.92, opacity: 0 },
animate: { scale: 1, opacity: 1 },
transition: { duration: 0.22, ease: "easeOut" },
})}
/>
)
}
/* ---- 4. SpringCalendar: yay fizigiyle dikey giris ---- */
export function SpringCalendar(props: MotionCalendarProps) {
return (
<MotionCalendarBase
props={props}
buildMotion={(dir) => ({
initial: { y: dir >= 0 ? 18 : -18, opacity: 0 },
animate: { y: 0, opacity: 1 },
transition: { type: "spring" as const, stiffness: 320, damping: 24, mass: 0.7 },
})}
/>
)
}
/* ---- 5. MorphCalendar: 3B egilme + olcek ile donusum ---- */
export function MorphCalendar(props: MotionCalendarProps) {
return (
<MotionCalendarBase
props={props}
perspective
buildMotion={(dir) => ({
initial: { rotateX: dir >= 0 ? -16 : 16, scale: 0.96, opacity: 0 },
animate: { rotateX: 0, scale: 1, opacity: 1 },
transition: { duration: 0.32, ease: "easeOut" },
})}
/>
)
}Manual installs skip the @ai2/tokens theme, so add the token CSS from the theming guide or the tone colors will be missing.
Variations
5 takes on the same idea. Each is its own export, and every one accepts a size prop (sm, md, lg, xl) aligned to the base Button scale.
Slide
The grid slides in from the direction you navigated.
import { SlideCalendar } from "@/components/ui/calendar-motion"
<SlideCalendar />Fade
The grid cross-fades with no movement.
import { FadeCalendar } from "@/components/ui/calendar-motion"
<FadeCalendar />Pop
The grid scales up from slightly small.
import { PopCalendar } from "@/components/ui/calendar-motion"
<PopCalendar />Spring
The grid settles in vertically with spring physics.
import { SpringCalendar } from "@/components/ui/calendar-motion"
<SpringCalendar />Morph
The grid tilts in 3D as the month changes.
import { MorphCalendar } from "@/components/ui/calendar-motion"
<MorphCalendar />ai2 Motion calendars: 5 styled variations on the token system
The ai2 Motion calendars are a set of 5 decorative button variations from the styled layer of the @ai2 design system, built around month-grid calendars that animate the month change. They are free and MIT licensed, and every color comes from a semantic token, so they theme with the rest of ai2 in light and dark.
Motion runs on framer-motion: framer-motion re-mounts the grid on every month change and animates it in. The styled layer is opt-in, so the dependency only lands if you use it; the base components stay lean. Under reduced motion, the month change is instant with no animation.
What is in the ai2 Motion calendars?
5 exports in one file: Slide, Fade, Pop, Spring and Morph. Each renders a native button and takes a size prop (sm, md, lg, xl) aligned to the base Button. They are separate from the base Button on purpose: the base keeps its clean variant, tone and size axes, while the styled layer carries the effects.
You own the file. Copy the one category file and you have all 5 variations, with no runtime dependency on ai2 itself.
Why use it
- On-system by construction: Every color resolves to an ai2 semantic token, so the buttons follow your theme in light and dark with no extra work.
- Effect without the sprawl: The decorations live in a dedicated styled file, so the base Button keeps its clean, predictable API.
- Accessible and honest: Each renders a real button element, keeps a visible focus ring, and respects prefers-reduced-motion.
Features
- Token-driven color: No hardcoded hex or oklch; the look recolors with your theme tokens.
- framer-motion: framer-motion re-mounts the grid on every month change and animates it in.
- Reduced-motion aware: Under prefers-reduced-motion, the month change is instant with no animation.
- Size aligned to the base: Every variation takes sm, md, lg and xl matching the base Button height scale, so styled and base buttons line up in a row.
Production tips
- Use it for emphasis, not everywhere: Styled buttons draw the eye. Reserve them for the one action you want people to take on a screen, and use the base Button for the rest.
- Keep labels as verbs: The decoration adds weight, so a clear action label keeps the button scannable.
- Pick one variation per surface: The variations share a family; using two different ones in the same view competes for attention.
Works with the rest of ai2
The Motion calendars sit alongside the base Button and the rest of the @ai2 registry. They share the same token file, so a styled action next to a base button or a badge stays visually consistent in both modes.