An open source design system that's fully customizable and agent ready
TypeScript
docs(useCalendarDays): add hook docs and a month grid example block (#9905)
Parman Mohammadalizadeha4dd70eb1aa9
diff --git a/.changeset/hook-doc-use-calendar-days.md b/.changeset/hook-doc-use-calendar-days.mdnew file mode 100644index 0000000000..6ccd30392d--- /dev/null+++ b/.changeset/hook-doc-use-calendar-days.md@@ -0,0 +1,8 @@+---+'@astryxdesign/core': patch+'@astryxdesign/cli': patch+---++[docs] Hook docs for `useCalendarDays`, so `astryx hook useCalendarDays` and `astryx search` return it, and a `useCalendarDays — Month Grid` example block: a compact month table built from the hook's `weeks` and `dayNames`, with the previous and next months' days dimmed and a Week starts on control (Sunday or Monday) that reorders both the header and the grid. Copy it with `astryx template useCalendarDaysHookUsage <path>`.++@MannXodiff --git a/apps/sandbox/scripts/next-export-routes.json b/apps/sandbox/scripts/next-export-routes.jsonindex 7ace7e0f97..56c128827e 100644--- a/apps/sandbox/scripts/next-export-routes.json+++ b/apps/sandbox/scripts/next-export-routes.json@@ -789,6 +789,7 @@"/templates/table/","/templates/theme-showcase/","/templates/useAnnounceHookUsage/",+ "/templates/useCalendarDaysHookUsage/","/templates/useClickableContainerHookUsage/","/templates/useClipboardHookUsage/","/templates/useCollatorHookUsage/",diff --git a/internal/shadcn-registry/routes.lock.json b/internal/shadcn-registry/routes.lock.jsonindex c286206ed1..a64f540b41 100644--- a/internal/shadcn-registry/routes.lock.json+++ b/internal/shadcn-registry/routes.lock.json@@ -3666,6 +3666,11 @@"path": "examples/use-app-shell-mobile/custom-mobile-trigger","aliases": []},+ {+ "name": "example-use-calendar-days-month-grid",+ "path": "examples/use-calendar-days/month-grid",+ "aliases": []+ },{"name": "example-use-clickable-container-clickable-project-card","path": "examples/use-clickable-container/clickable-project-card",@@ -3936,6 +3941,11 @@"path": "hooks/use-app-shell-mobile","aliases": []},+ {+ "name": "hook-use-calendar-days",+ "path": "hooks/use-calendar-days",+ "aliases": []+ },{"name": "hook-use-clickable-container","path": "hooks/use-clickable-container",diff --git a/packages/cli/api/component/__fixtures__/resolutions/modules.txt b/packages/cli/api/component/__fixtures__/resolutions/modules.txtindex 5106cf14d6..e3130e7a53 100644--- a/packages/cli/api/component/__fixtures__/resolutions/modules.txt+++ b/packages/cli/api/component/__fixtures__/resolutions/modules.txt@@ -249,7 +249,7 @@ useBackdropPress useBackdropPress Layer/Layer.doc.mjs Layer/useBackdropPress.tsuseBaseTablePlugins useBaseTablePlugins Table/Table.doc.mjs Table/useBaseTablePlugins.tsuseBusyAnnouncement useBusyAnnouncement hooks/useAnimatedLayout.doc.mjs hooks/useBusyAnnouncement.tsuseCalendarConstraints useCalendarConstraints Calendar/Calendar.doc.mjs Calendar/hooks/useCalendarConstraints.ts-useCalendarDays useCalendarDays Calendar/Calendar.doc.mjs Calendar/hooks/useCalendarDays.ts+useCalendarDays useCalendarDays Calendar/useCalendarDays.doc.mjs Calendar/hooks/useCalendarDays.tsuseCalendarNavigation useCalendarNavigation Calendar/Calendar.doc.mjs Calendar/hooks/useCalendarNavigation.tsuseChatComposerTokens useChatComposerTokens Chat/Chat.doc.mjs Chat/useChatComposerTokens.tsuseChatDictation useChatDictation Chat/Chat.doc.mjs Chat/useChatDictation.tsdiff --git a/packages/cli/api/template/use-calendar-days-hook-usage.test.tsx b/packages/cli/api/template/use-calendar-days-hook-usage.test.tsxnew file mode 100644index 0000000000..b7160e4ccd--- /dev/null+++ b/packages/cli/api/template/use-calendar-days-hook-usage.test.tsx@@ -0,0 +1,86 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.+// @vitest-environment jsdom++/**+ * The useCalendarDays example is a December 2026 month table built from the+ * hook's weeks and dayNames. Days outside the month are dimmed, and the Week+ * starts on control reorders the header and the grid.+ */++import {act} from 'react';+import {createRoot, type Root} from 'react-dom/client';+import {afterEach, beforeEach, describe, expect, it} from 'vitest';+import UseCalendarDaysHookUsage from '../../assets/templates/blocks/components/Calendar/useCalendarDaysHookUsage';++(globalThis as {IS_REACT_ACT_ENVIRONMENT?: boolean}).IS_REACT_ACT_ENVIRONMENT =+ true;++let root: Root | null = null;+let container: HTMLElement;++function header(): string[] {+ return Array.from(container.querySelectorAll('thead th')).map(+ cell => cell.textContent ?? '',+ );+}++function rows(): string[][] {+ return Array.from(container.querySelectorAll('tbody tr')).map(row =>+ Array.from(row.querySelectorAll('td')).map(cell => cell.textContent ?? ''),+ );+}++function dayClass(row: number, column: number): string {+ const cells = container.querySelectorAll('tbody tr')[row].children;+ return cells[column].firstElementChild?.className ?? '';+}++function startOn(label: string): void {+ const option = Array.from(container.querySelectorAll('button, label')).find(+ candidate => candidate.textContent === label,+ );+ act(() => (option as HTMLElement | undefined)?.click());+}++beforeEach(() => {+ container = document.createElement('div');+ document.body.appendChild(container);+ act(() => {+ root = createRoot(container);+ root.render(<UseCalendarDaysHookUsage />);+ });+});++afterEach(() => {+ act(() => root?.unmount());+ root = null;+ container.remove();+});++describe('useCalendarDays example', () => {+ it('lays out December 2026 from Sunday, with only the rows it needs', () => {+ expect(header()).toEqual(['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']);+ expect(rows()).toEqual([+ ['29', '30', '1', '2', '3', '4', '5'],+ ['6', '7', '8', '9', '10', '11', '12'],+ ['13', '14', '15', '16', '17', '18', '19'],+ ['20', '21', '22', '23', '24', '25', '26'],+ ['27', '28', '29', '30', '31', '1', '2'],+ ]);+ });++ it('dims the days from November and January', () => {+ const inside = dayClass(0, 2);+ expect(dayClass(0, 0)).not.toBe(inside);+ expect(dayClass(0, 1)).toBe(dayClass(0, 0));+ expect(dayClass(4, 5)).toBe(dayClass(0, 0));+ expect(dayClass(4, 4)).toBe(inside);+ });++ it('reorders the header and the grid when the week starts on Monday', () => {+ startOn('Monday');+ expect(header()).toEqual(['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']);+ expect(rows()[0]).toEqual(['30', '1', '2', '3', '4', '5', '6']);+ expect(rows().at(-1)).toEqual(['28', '29', '30', '31', '1', '2', '3']);+ });+});diff --git a/packages/cli/assets/templates/blocks/components/Calendar/useCalendarDaysHookUsage.doc.mjs b/packages/cli/assets/templates/blocks/components/Calendar/useCalendarDaysHookUsage.doc.mjsnew file mode 100644index 0000000000..ad867862a4--- /dev/null+++ b/packages/cli/assets/templates/blocks/components/Calendar/useCalendarDaysHookUsage.doc.mjs@@ -0,0 +1,14 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/** @type {import('@astryxdesign/cli/authoring').TemplateDoc} */+export const doc = {+ type: 'block',+ exampleFor: 'useCalendarDays',+ name: 'useCalendarDays — Month Grid',+ displayName: 'useCalendarDays — Month Grid',+ description:+ 'A compact custom month view: a seven-column table built from the weeks and dayNames that useCalendarDays returns, with only as many rows as the month needs. Days from the previous and next months are dimmed, and a Week starts on control (Sunday or Monday) reorders both the header and the grid.',+ isReady: true,+ aspectRatio: 4 / 3,+ componentsUsed: ['SegmentedControl', 'Layout', 'Text'],+};diff --git a/packages/cli/assets/templates/blocks/components/Calendar/useCalendarDaysHookUsage.tsx b/packages/cli/assets/templates/blocks/components/Calendar/useCalendarDaysHookUsage.tsxnew file mode 100644index 0000000000..ea64469e28--- /dev/null+++ b/packages/cli/assets/templates/blocks/components/Calendar/useCalendarDaysHookUsage.tsx@@ -0,0 +1,71 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++'use client';++import {useState} from 'react';+import {useCalendarDays} from '@astryxdesign/core/Calendar';+import {HStack, VStack} from '@astryxdesign/core/Layout';+import {+ SegmentedControl,+ SegmentedControlItem,+} from '@astryxdesign/core/SegmentedControl';+import {Text} from '@astryxdesign/core/Text';++export default function UseCalendarDaysHookUsage() {+ const [weekStartsOn, setWeekStartsOn] = useState<0 | 1>(0);+ const {weeks, dayNames} = useCalendarDays({+ year: 2026,+ month: 12,+ weekStartsOn,+ hasVariableRowCount: true,+ });++ return (+ <VStack gap={3}>+ <HStack gap={2} vAlign="center">+ <Text type="body">Week starts on</Text>+ <SegmentedControl+ label="Week starts on"+ value={String(weekStartsOn)}+ onChange={value => setWeekStartsOn(value === '1' ? 1 : 0)}+ size="sm">+ <SegmentedControlItem value="0" label="Sunday" />+ <SegmentedControlItem value="1" label="Monday" />+ </SegmentedControl>+ </HStack>+ <table style={{tableLayout: 'fixed', width: 280}}>+ <caption>+ <Text type="body" weight="bold">+ December 2026+ </Text>+ </caption>+ <thead>+ <tr>+ {dayNames.map((name, column) => (+ <th key={(weekStartsOn + column) % 7} scope="col">+ <Text type="supporting" color="secondary">+ {name}+ </Text>+ </th>+ ))}+ </tr>+ </thead>+ <tbody>+ {weeks.map(week => (+ <tr key={week[0].iso}>+ {week.map(day => (+ <td key={day.iso} align="center">+ <Text+ type="body"+ color={day.isOutside ? 'secondary' : 'primary'}>+ {day.dayNumber}+ </Text>+ </td>+ ))}+ </tr>+ ))}+ </tbody>+ </table>+ </VStack>+ );+}diff --git a/packages/core/src/Calendar/useCalendarDays.doc.mjs b/packages/core/src/Calendar/useCalendarDays.doc.mjsnew file mode 100644index 0000000000..795b3634f1--- /dev/null+++ b/packages/core/src/Calendar/useCalendarDays.doc.mjs@@ -0,0 +1,158 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/** @type {import('@astryxdesign/cli/authoring').HookDoc} */+export const docs = {+ name: 'useCalendarDays',+ displayName: 'useCalendarDays',+ group: 'Calendar',+ keywords: [+ 'calendar',+ 'month',+ 'grid',+ 'weeks',+ 'days',+ 'weekday names',+ 'week start',+ 'date picker',+ ],+ params: [+ {+ name: 'options',+ type: 'UseCalendarDaysOptions',+ description: 'The month to lay out and how.',+ required: true,+ },+ {+ name: 'options.year',+ type: 'number',+ description:+ 'Year of the month to lay out, as options.calendar numbers it.',+ required: true,+ },+ {+ name: 'options.month',+ type: 'number',+ description:+ "The month's position in its year under options.calendar, 1-based. In the Gregorian calendar 1 is January and 12 is December; other calendars number months as Temporal.PlainDate does, so a Hebrew leap year runs from 1 to 13.",+ required: true,+ },+ {+ name: 'options.weekStartsOn',+ type: 'DayOfWeek',+ description:+ 'First day of the week, from 0 (Sunday) to 6 (Saturday). It sets the first column of both the grid and dayNames.',+ default: '0',+ required: false,+ },+ {+ name: 'options.hasVariableRowCount',+ type: 'boolean',+ description:+ 'Use only as many week rows as the month needs instead of a fixed 6-row grid. That is 4 to 6 for a Gregorian month, and 1 or 2 for the short thirteenth month of the Coptic and Ethiopic calendars.',+ default: 'false',+ required: false,+ },+ {+ name: 'options.calendar',+ type: 'CalendarSystem',+ description:+ "The calendar system that numbers year, month and each day's dayNumber. Every day keeps its Gregorian date and iso. The hook never reads the InternationalizationProvider calendar. Calendars other than gregory, iso8601, buddhist, roc and japanese need Temporal; without it the hook uses Gregorian numbers and warns once in development.",+ default: "'gregory'",+ required: false,+ },+ ],+ returns: [+ {+ name: 'days',+ type: 'CalendarDay[]',+ description:+ 'Every cell of the grid in order, including the days from the previous and next months that fill the first and last weeks. Each day has date (a PlainDate), iso (YYYY-MM-DD), isOutside (true for a day outside the month) and dayNumber (its day of the calendar month).',+ },+ {+ name: 'weeks',+ type: 'CalendarDay[][]',+ description: 'The same days grouped into rows of seven.',+ },+ {+ name: 'dayNames',+ type: 'string[]',+ description:+ "Weekday header names for the current locale (from InternationalizationProvider), starting at weekStartsOn. Abbreviated where every name fits the column, otherwise the locale's narrow names.",+ },+ {+ name: 'totalCells',+ type: 'number',+ description:+ 'Number of cells in the grid: 42 for the fixed grid, otherwise rows times seven.',+ },+ ],+ usage: {+ description:+ "Builds the day grid for one month: every date to show, including the previous and next months' days that fill the first and last weeks, grouped into weeks, plus localized weekday header names that start on weekStartsOn. It is the layout Calendar uses, for a custom month view such as a compact availability grid or a mini calendar. It returns data only: rendering, selection, keyboard navigation and the grid's accessibility semantics are the caller's.",+ bestPractices: [+ {+ guidance: true,+ description:+ 'Render dayNames as the header row so the header follows weekStartsOn and the locale together with the grid.',+ },+ {+ guidance: true,+ description:+ 'Style days with isOutside differently, for example dimmed, so the filler days read as part of the next or previous month.',+ },+ {+ guidance: false,+ description:+ 'Use it to build a date picker that people choose from; use Calendar, which adds selection, keyboard navigation and grid semantics.',+ },+ ],+ },+ relatedComponents: ['Calendar'],+ relatedHooks: ['useLocale'],+ importPath: '@astryxdesign/core/Calendar',+ category: 'utilities',+};++/** @type {import('@astryxdesign/cli/authoring').HookTranslationDoc} */+export const docsDense = {+ description:+ "Builds one month's day grid: every date incl. previous/next month filler days, grouped into weeks, + localized weekday names starting at weekStartsOn. Calendar's layout, for custom month views. Data only: rendering, selection, keyboard nav, a11y semantics are the caller's.",+ paramDescriptions: {+ options: 'month to lay out + how.',+ 'options.year': 'year of the month, numbered by options.calendar.',+ 'options.month':+ "month's position in its options.calendar year, 1-based (gregory 1 = January; Hebrew leap year 1-13).",+ 'options.weekStartsOn':+ 'first day of week, 0 (Sunday) to 6 (Saturday); first column of grid + dayNames.',+ 'options.hasVariableRowCount':+ 'only as many week rows as needed (Gregorian 4-6, Coptic/Ethiopic 13th month 1-2) vs fixed 6 rows.',+ 'options.calendar':+ "calendar system numbering year, month, dayNumber; default 'gregory'. Dates stay Gregorian; provider calendar ignored. Non-Gregorian-aligned systems need Temporal.",+ },+ returnDescriptions: {+ days: 'every grid cell in order incl. filler days; each has date (PlainDate), iso, isOutside, dayNumber (day of the calendar month).',+ weeks: 'days grouped into rows of 7.',+ dayNames:+ 'locale weekday header names starting at weekStartsOn; abbreviated where all fit, else narrow.',+ totalCells: 'cell count: 42 fixed, else rows x 7.',+ },+ usage: {+ description:+ "Month day grid (filler days, weeks, localized weekday names from weekStartsOn). Calendar's layout, for custom month views. Data only; rendering, selection, keyboard nav + a11y semantics are the caller's.",+ bestPractices: [+ {+ guidance: true,+ description:+ 'Render dayNames as the header row so it follows weekStartsOn + locale.',+ },+ {+ guidance: true,+ description: 'Style isOutside days differently (e.g. dimmed).',+ },+ {+ guidance: false,+ description: 'Build a selectable date picker with it; use Calendar.',+ },+ ],+ },+};