The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Migrate DatePicker to twenty-ui (#28636)
Raphaël Bosi8c1a920d7c6e
diff --git a/packages/twenty-docs/snippets/ui/generated/components/input/date-picker.mdx b/packages/twenty-docs/snippets/ui/generated/components/input/date-picker.mdxnew file mode 100644index 00000000000..814bc5f7f78--- /dev/null+++ b/packages/twenty-docs/snippets/ui/generated/components/input/date-picker.mdx@@ -0,0 +1,128 @@+{/*+ * _____ _+ *|_ _|_ _____ _ __ | |_ _ _+ * | | \ \ /\ / / _ \ '_ \| __| | | | Auto-generated file+ * | | \ V V / __/ | | | |_| |_| | DO NOT EDIT - changes will be overwritten+ * |_| \_/\_/ \___|_| |_|\__|\__, | Generated by: npx nx generate:ui twenty-docs+ * |___/+ *+ * This file is generated from the documentation data in packages/twenty-ui/generated.+ * To update it, edit the component prop types or design tokens in twenty-ui and run:+ * npx nx generate:ui twenty-docs+ */}++<ParamField body="aria-label" type="string">+ Accessible name of the calendar group.+</ParamField>++<ParamField body="aria-labelledby" type="string">+ ID of the element that labels the calendar group.+</ParamField>++<ParamField body="className" type="string">+ CSS class applied to the root element.+</ParamField>++<ParamField body="disabled" type="boolean" default="false">+ Disables date selection and the default header controls.+</ParamField>++<ParamField body="highlightedRange" type="{ start: string; end: string; }">+ Inclusive YYYY-MM-DD start and end dates to highlight. The application computes the range independently from the selected date.+</ParamField>++<ParamField body="isDateUnavailable" type="((date: string) => boolean)">+ Returns whether a canonical YYYY-MM-DD date cannot be selected. The calendar engine handles unavailable-date presentation and navigation.+</ParamField>++<ParamField body="isGridHidden" type="boolean" default="false">+ Hides weekday and date rows while retaining the header for a month-only navigator.+</ParamField>++<ParamField body="isKeyboardNavigationDisabled" type="boolean" default="false">+ Disables keyboard date navigation in the calendar engine for compatibility with existing input wrappers. Header controls retain their native keyboard behavior.+</ParamField>++<ParamField body="loadingFallback" type="ReactNode" default="300px-high Skeleton">+ Custom Suspense fallback while the calendar engine loads. Defaults to a 300px-high Skeleton.+</ParamField>++<ParamField body="locale" type="string" required>+ Locale for the default month/year header and custom weekday titles. Engine day labels retain their existing locale behavior; values remain Gregorian date-only strings.+</ParamField>++<ParamField body="monthLabel" type="string" required>+ Accessible name of the default month selector.+</ParamField>++<ParamField body="nextMonthLabel" type="string" required>+ Accessible name of the default next-month button.+</ParamField>++<ParamField body="onNavigationOpenChange" type="((args: { open: boolean; control: "month" | "year"; }) => void)">+ Reports { open, control } when a default month or year popup starts opening, and when it finishes closing or its selector unmounts. Header arrow actions do not call this callback.+</ParamField>++<ParamField body="onValueChange" type="(date: string) => void" required>+ Called when choosing an available day changes the selected date. Month and year browsing does not select another date.+</ParamField>++<ParamField body="onValueSelect" type="((date: string) => void)">+ Called with the selected YYYY-MM-DD date after choosing an available day, including the already-selected day. Use it to commit or close a product picker.+</ParamField>++<ParamField body="onViewedMonthChange" type="(month: string) => void" required>+ Requests the month shown by calendar navigation without changing the selected date.+</ParamField>++<ParamField body="portalContainer" type="HTMLElement | ShadowRoot | RefObject<HTMLElement | ShadowRoot | null> | null">+ Mount container for the default month and year selector popups. Accepts the shared Select portal container contract.+</ParamField>++<ParamField body="previousMonthLabel" type="string" required>+ Accessible name of the default previous-month button.+</ParamField>++<ParamField body="readOnly" type="boolean" default="false">+ Prevents date selection while allowing month and year browsing and displaying the selected date or highlighted range.+</ParamField>++<ParamField body="ref" type="Ref<HTMLDivElement>">+ Ref to the root element.+</ParamField>++<ParamField body="render" type="ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, {}>">+ Composes the root element while preserving its props and contents.+</ParamField>++<ParamField body="renderHeader" type="((props: DatePickerHeaderProps) => ReactNode)">+ Renders a product header with the viewed month, previous/next actions, month numbers from 1 through 12, year change actions, and navigation-disabled states. Header actions only browse months.+</ParamField>++<ParamField body="role" type="AriaRole" default="group">+ Root semantics. Defaults to a group; the caller supplies its accessible name.+</ParamField>++<ParamField body="style" type="CSSProperties">+ Inline styles applied to the root element.+</ParamField>++<ParamField body="value" type="string | null" required>+ Controlled selected Gregorian date in YYYY-MM-DD form, or null for no selection.+</ParamField>++<ParamField body="viewedMonth" type="string" required>+ Controlled Gregorian month in YYYY-MM form. It is independent from the selected date.+</ParamField>++<ParamField body="weekdayLabels" type="readonly [string, string, string, string, string, string, string]">+ Optional short weekday labels in Sunday-first order. The calendar engine supplies weekday names when omitted.+</ParamField>++<ParamField body="weekStart" type="0 | 1 | 2 | 3 | 4 | 5 | 6" required>+ First weekday column: 0 for Sunday through 6 for Saturday.+</ParamField>++<ParamField body="yearLabel" type="string" required>+ Accessible name of the default year selector.+</ParamField>diff --git a/packages/twenty-docs/ui/components/input/date-picker.mdx b/packages/twenty-docs/ui/components/input/date-picker.mdxnew file mode 100644index 00000000000..f865233712b--- /dev/null+++ b/packages/twenty-docs/ui/components/input/date-picker.mdx@@ -0,0 +1,156 @@+---+title: DatePicker+description: Share the existing calendar engine while browsing months independently from the selected date.+---++import { StoryEmbed } from '/snippets/ui/StoryEmbed.mdx';+import DatePickerReference from '/snippets/ui/generated/components/input/date-picker.mdx';++`DatePicker` shares the `react-datepicker` calendar engine used by Twenty's date and date-time inputs. It provides date-only values and independent control over the selected date and viewed month.++<StoryEmbed+ storyId="ui-components-datepicker--display"+ title="DatePicker example"+ height={330}+/>++## Usage++```tsx+import { useState } from 'react';+import { DatePicker } from 'twenty-ui/components/input';++export const ChooseDate = () => {+ const [value, setValue] = useState<string | null>('2026-10-07');+ const [viewedMonth, setViewedMonth] = useState('2026-10');++ return (+ <DatePicker+ aria-label="Choose a date"+ value={value}+ onValueChange={setValue}+ viewedMonth={viewedMonth}+ onViewedMonthChange={setViewedMonth}+ weekStart={1}+ weekdayLabels={['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa']}+ locale="en-US"+ previousMonthLabel="Previous month"+ nextMonthLabel="Next month"+ monthLabel="Month"+ yearLabel="Year"+ />+ );+};+```++## Selection and browsing++Changing the month or year calls `onViewedMonthChange` and leaves `value` unchanged. Choosing an available day calls `onValueChange` when the selected date changes.++Use `onValueSelect` to commit a date or close a product picker. It receives the canonical `YYYY-MM-DD` date even when the user chooses the already-selected day. Keep closing behavior in the application adapter.++Update each controlled prop in its matching callback. Prop changes do not select a replacement date. The default header provides month and year selectors and previous and next buttons; its year selector lists up to 100 years before and after the viewed year.++## Date values and localization++Pass canonical Gregorian date-only strings: `YYYY-MM-DD` for `value` and highlighted range bounds, and `YYYY-MM` for `viewedMonth`. Set `value={null}` for no selection. These values contain no time or timezone. Supported years are 0001 through 9999.++`locale` formats the default month/year header and full weekday titles when custom `weekdayLabels` are supplied. Day labels and the underlying calendar retain the existing `react-datepicker` locale behavior.++`weekStart` sets the first column, using 0 for Sunday through 6 for Saturday. Use `weekdayLabels` for seven short visible labels in Sunday-first order, regardless of `weekStart`. The calendar engine supplies weekday names when this prop is omitted.++Current-day presentation follows the calendar engine's browser-clock behavior. Product adapters own timezone conversion, initial date fallbacks, member preferences, and scheduling data.++## Existing calendar behavior++Day rendering, accessibility markup, keyboard date navigation, and unavailable-date handling use `react-datepicker`. Visible days from neighboring months remain selectable when available.++Set `isDateUnavailable` to prevent selection of dates according to your application's policy. The callback receives a canonical `YYYY-MM-DD` string. Set `disabled` to disable date selection and the default header controls.++`isKeyboardNavigationDisabled` defaults to `false`. Existing product input adapters can set it to preserve their keyboard behavior. Header controls keep their native keyboard interaction.++## Highlighted ranges and read-only views++Pass `highlightedRange={{ start: '2026-10-05', end: '2026-10-11' }}` to highlight an inclusive date range. The application computes the range; highlighting does not select multiple dates or change `value`.++Use `readOnly` to display a computed range or selected date while allowing month and year browsing. Use `isGridHidden` for a month-only navigator that retains the same header.++## Custom headers++Use `renderHeader` to compose an existing product header with date inputs, time inputs, or application-specific controls. Its `DatePickerHeaderProps` argument provides these values and actions:++| Property | Purpose |+| --- | --- |+| `viewedMonth` | Current `YYYY-MM` month. |+| `onPreviousMonth`, `onNextMonth` | Browse to the adjacent month. |+| `onMonthChange` | Browse to a month number from 1 through 12. |+| `onYearChange` | Browse to the supplied year. |+| `isPreviousMonthDisabled`, `isNextMonthDisabled` | Whether each adjacent-month action is unavailable. |++These header actions change the viewed month and leave the selected date unchanged.++```tsx+import { useState } from 'react';+import { DatePicker } from 'twenty-ui/components/input';+import { Button } from 'twenty-ui/primitives/input';+import { Text } from 'twenty-ui/primitives/typography';+import { themeCssVariables } from 'twenty-ui/theme';++export const CalendarWithProductHeader = () => {+ const [value, setValue] = useState<string | null>('2026-10-07');+ const [viewedMonth, setViewedMonth] = useState('2026-10');++ return (+ <DatePicker+ aria-label="Choose a date"+ value={value}+ onValueChange={setValue}+ viewedMonth={viewedMonth}+ onViewedMonthChange={setViewedMonth}+ weekStart={1}+ locale="en-US"+ previousMonthLabel="Previous month"+ nextMonthLabel="Next month"+ monthLabel="Month"+ yearLabel="Year"+ renderHeader={({+ viewedMonth: month,+ onPreviousMonth,+ onNextMonth,+ isPreviousMonthDisabled,+ isNextMonthDisabled,+ }) => (+ <Text+ style={{+ display: 'flex',+ alignItems: 'center',+ gap: themeCssVariables.spacing[2],+ }}+ >+ <Button size="sm" disabled={isPreviousMonthDisabled} onClick={onPreviousMonth}>+ Previous month+ </Button>+ <Text>{month}</Text>+ <Button size="sm" disabled={isNextMonthDisabled} onClick={onNextMonth}>+ Next month+ </Button>+ </Text>+ )}+ />+ );+};+```++## Composition and product adapters++Supply a group name with `aria-label` or `aria-labelledby`. Native attributes, `className`, `style`, and `ref` apply to the root. Use `render` to compose a different root while preserving the supplied props and ref.++Pass `loadingFallback` to preserve a product loading surface while the calendar engine loads. The default fallback is a 300px-high `Skeleton`.++For the default header, `portalContainer` mounts selector popups in a host-provided container. `onNavigationOpenChange` receives `{ open, control }` for `month` or `year`, with `open: true` when opening starts and `open: false` after closing completes. Hosts can retain their popup and focus handling through dismissal. Custom headers own their popup integration.++Keep product headers, text inputs, time editing, timezone conversion, clear actions, and relative-filter computation in `twenty-front`. Date, date-time, and month-only adapters can compose this shared calendar engine with `highlightedRange`, `readOnly`, and `isGridHidden` as needed.++## Props++<DatePickerReference />diff --git a/packages/twenty-ui/.size-limit.json b/packages/twenty-ui/.size-limit.jsonindex fad71533081..d5c16f3f503 100644--- a/packages/twenty-ui/.size-limit.json+++ b/packages/twenty-ui/.size-limit.json@@ -13,7 +13,7 @@{"name": "components","path": "dist/components.mjs",- "limit": "166 kB"+ "limit": "215 kB"},{"name": "components/code-editor",@@ -45,6 +45,12 @@"path": "dist/primitives/input.mjs","limit": "230 kB"},+ {+ "name": "components (DatePicker)",+ "path": "dist/components.mjs",+ "limit": "150 kB",+ "import": "{ DatePicker }"+ },{"name": "components (JsonTree)","path": "dist/components.mjs",diff --git a/packages/twenty-ui/docs/components.ts b/packages/twenty-ui/docs/components.tsindex ddf8e61c385..64316336911 100644--- a/packages/twenty-ui/docs/components.ts+++ b/packages/twenty-ui/docs/components.ts@@ -30,6 +30,7 @@ import { RADIO_GROUP_PROP_DESCRIPTIONS } from './radioGroupPropDescriptions';import { PHONE_COUNTRY_PICKER_PART_PROP_DESCRIPTIONS } from './phoneCountryPickerPartPropDescriptions';import { PHONE_COUNTRY_PICKER_PROP_DESCRIPTIONS } from './phoneCountryPickerPropDescriptions';import { SEARCH_INPUT_PROP_DESCRIPTIONS } from './searchInputPropDescriptions';+import { DATE_PICKER_PROP_DESCRIPTIONS } from './datePickerPropDescriptions';import { NUMBER_STEPPER_PROP_DESCRIPTIONS } from './numberStepperPropDescriptions';import { NUMBER_FIELD_PART_PROP_DESCRIPTIONS } from './numberFieldPartPropDescriptions';import { IMAGE_INPUT_PROP_DESCRIPTIONS } from './imageInputPropDescriptions';@@ -1086,6 +1087,21 @@ export const DOCUMENTED_COMPONENTS = [slug: 'components/input/image-input',propDescriptions: IMAGE_INPUT_PROP_DESCRIPTIONS,},+ {+ name: 'DatePicker',+ source: 'components/input/DatePicker/DatePicker.tsx',+ entryPoint: 'twenty-ui/components/input',+ slug: 'components/input/date-picker',+ propDescriptions: DATE_PICKER_PROP_DESCRIPTIONS,+ propDefaults: {+ isKeyboardNavigationDisabled: 'false',+ loadingFallback: '300px-high Skeleton',+ disabled: 'false',+ readOnly: 'false',+ isGridHidden: 'false',+ role: 'group',+ },+ },{name: 'SearchInput',source: 'components/input/SearchInput/SearchInput.tsx',diff --git a/packages/twenty-ui/docs/datePickerPropDescriptions.ts b/packages/twenty-ui/docs/datePickerPropDescriptions.tsnew file mode 100644index 00000000000..b177e3347b8--- /dev/null+++ b/packages/twenty-ui/docs/datePickerPropDescriptions.ts@@ -0,0 +1,49 @@+import { type DatePickerProps } from '../src/components/input/DatePicker/types/DatePickerProps';++export const DATE_PICKER_PROP_DESCRIPTIONS = {+ value:+ 'Controlled selected Gregorian date in YYYY-MM-DD form, or null for no selection.',+ onValueChange:+ 'Called when choosing an available day changes the selected date. Month and year browsing does not select another date.',+ onValueSelect:+ 'Called with the selected YYYY-MM-DD date after choosing an available day, including the already-selected day. Use it to commit or close a product picker.',+ viewedMonth:+ 'Controlled Gregorian month in YYYY-MM form. It is independent from the selected date.',+ onViewedMonthChange:+ 'Requests the month shown by calendar navigation without changing the selected date.',+ weekStart: 'First weekday column: 0 for Sunday through 6 for Saturday.',+ weekdayLabels:+ 'Optional short weekday labels in Sunday-first order. The calendar engine supplies weekday names when omitted.',+ locale:+ 'Locale for the default month/year header and custom weekday titles. Engine day labels retain their existing locale behavior; values remain Gregorian date-only strings.',+ previousMonthLabel: 'Accessible name of the default previous-month button.',+ nextMonthLabel: 'Accessible name of the default next-month button.',+ monthLabel: 'Accessible name of the default month selector.',+ yearLabel: 'Accessible name of the default year selector.',+ isDateUnavailable:+ 'Returns whether a canonical YYYY-MM-DD date cannot be selected. The calendar engine handles unavailable-date presentation and navigation.',+ highlightedRange:+ 'Inclusive YYYY-MM-DD start and end dates to highlight. The application computes the range independently from the selected date.',+ readOnly:+ 'Prevents date selection while allowing month and year browsing and displaying the selected date or highlighted range.',+ isGridHidden:+ 'Hides weekday and date rows while retaining the header for a month-only navigator.',+ isKeyboardNavigationDisabled:+ 'Disables keyboard date navigation in the calendar engine for compatibility with existing input wrappers. Header controls retain their native keyboard behavior.',+ loadingFallback:+ 'Custom Suspense fallback while the calendar engine loads. Defaults to a 300px-high Skeleton.',+ renderHeader:+ 'Renders a product header with the viewed month, previous/next actions, month numbers from 1 through 12, year change actions, and navigation-disabled states. Header actions only browse months.',+ portalContainer:+ 'Mount container for the default month and year selector popups. Accepts the shared Select portal container contract.',+ onNavigationOpenChange:+ 'Reports { open, control } when a default month or year popup starts opening, and when it finishes closing or its selector unmounts. Header arrow actions do not call this callback.',+ disabled: 'Disables date selection and the default header controls.',+ render: 'Composes the root element while preserving its props and contents.',+ ref: 'Ref to the root element.',+ className: 'CSS class applied to the root element.',+ style: 'Inline styles applied to the root element.',+ role: 'Root semantics. Defaults to a group; the caller supplies its accessible name.',+ 'aria-label': 'Accessible name of the calendar group.',+ 'aria-labelledby': 'ID of the element that labels the calendar group.',+} satisfies Partial<Record<keyof DatePickerProps, string>>;diff --git a/packages/twenty-ui/docs/label-ownership.md b/packages/twenty-ui/docs/label-ownership.mdindex 3be15a87128..8b457c0e6cf 100644--- a/packages/twenty-ui/docs/label-ownership.md+++ b/packages/twenty-ui/docs/label-ownership.md@@ -13,6 +13,7 @@ This covers production exports under components, primitives, and icons, includin| IconButton and LightIconButton | Caller-supplied accessible label and optional tooltip. Native `aria-labelledby` remains available and takes precedence. || CountPager | Caller-owned `positionText`, `previousLabel`, `nextLabel`, and native group names. Position text is announced politely when it changes. The caller formats counts, supplies empty-state text, and owns translations. || ReactionButton | Caller-supplied emoji, count formatting, accessible name, and optional native title or composed Tooltip content. The emoji and count are decorative; `pressed` supplies the accessible selection state. |+| DatePicker | Caller-owned group name, default month/year selector labels, previous/next labels, default-header locale, and optional weekday labels. The shared react-datepicker engine owns calendar markup, day labels, and current-day behavior. Product adapters own selected values, viewed months, custom headers, timezone conversion, relative-range computation, and popup/focus coordination. || SearchInput | Caller-owned placeholder, native accessible name and action labels. Referenced labels take precedence over explicit labels and placeholder fallback. || CountrySelect | Root owns caller-supplied country labels and `noCountryLabel` (default `No country`). Trigger accepts `label`, native accessible names, and custom children. Options owns `searchLabel` (default `Search`) and `noResultsLabel` (default `No results`). The shorthand exposes the same labels. Applications own translations, stable identifiers, and persistence conversions. || PhoneCountryPicker | Callers supply country labels and the trigger name. The selected label describes the trigger; the popup uses its trigger name unless named explicitly. Options defaults are `Search` (`searchLabel`), `Countries` (`listLabel`) and `No results` (`emptyLabel`), also available through shorthand `optionsProps`. Calling codes omit the plus sign in caller data and display with LTR isolation. |diff --git a/packages/twenty-ui/docs/module-ownership.json b/packages/twenty-ui/docs/module-ownership.jsonindex 0fa7b418844..895629b7a07 100644--- a/packages/twenty-ui/docs/module-ownership.json+++ b/packages/twenty-ui/docs/module-ownership.json@@ -55,6 +55,7 @@"CountPager","CountrySelect","CurrencyPicker",+ "DatePicker","DetailsRow","Dropdown","EmojiPicker",diff --git a/packages/twenty-ui/docs/public-exports.json b/packages/twenty-ui/docs/public-exports.jsonindex 849d31b1c2c..d9132e14440 100644--- a/packages/twenty-ui/docs/public-exports.json+++ b/packages/twenty-ui/docs/public-exports.json@@ -92,6 +92,7 @@"values": {"CountrySelect": "components/input/CountrySelect/CountrySelect","CurrencyPicker": "components/input/CurrencyPicker/CurrencyPicker",+ "DatePicker": "components/input/DatePicker/DatePicker","EmojiPicker": "components/input/EmojiPicker/EmojiPicker","FormFieldRow": "components/input/FormFieldRow/FormFieldRow","IconButton": "components/input/IconButton/IconButton",@@ -119,6 +120,8 @@"CurrencyPickerRootProps": "components/input/CurrencyPicker/types/CurrencyPickerRootProps","CurrencyPickerState": "components/input/CurrencyPicker/types/CurrencyPickerState","CurrencyPickerTriggerProps": "components/input/CurrencyPicker/types/CurrencyPickerTriggerProps",+ "DatePickerHeaderProps": "components/input/DatePicker/types/DatePickerHeaderProps",+ "DatePickerProps": "components/input/DatePicker/types/DatePickerProps","EmojiPickerProps": "components/input/EmojiPicker/types/EmojiPickerProps","FormFieldRowProps": "components/input/FormFieldRow/types/FormFieldRowProps","IconButtonProps": "components/input/IconButton/types/IconButtonProps",diff --git a/packages/twenty-ui/generated/components.docs.json b/packages/twenty-ui/generated/components.docs.jsonindex 6d1db6b4bb0..03350e10c44 100644--- a/packages/twenty-ui/generated/components.docs.json+++ b/packages/twenty-ui/generated/components.docs.json@@ -15168,6 +15168,216 @@}]},+ {+ "name": "DatePicker",+ "entryPoint": "twenty-ui/components/input",+ "slug": "components/input/date-picker",+ "props": [+ {+ "name": "aria-label",+ "type": "string",+ "required": false,+ "defaultValue": null,+ "description": "Accessible name of the calendar group."+ },+ {+ "name": "aria-labelledby",+ "type": "string",+ "required": false,+ "defaultValue": null,+ "description": "ID of the element that labels the calendar group."+ },+ {+ "name": "className",+ "type": "string",+ "required": false,+ "defaultValue": null,+ "description": "CSS class applied to the root element."+ },+ {+ "name": "disabled",+ "type": "boolean",+ "required": false,+ "defaultValue": "false",+ "description": "Disables date selection and the default header controls."+ },+ {+ "name": "highlightedRange",+ "type": "{ start: string; end: string; }",+ "required": false,+ "defaultValue": null,+ "description": "Inclusive YYYY-MM-DD start and end dates to highlight. The application computes the range independently from the selected date."+ },+ {+ "name": "isDateUnavailable",+ "type": "((date: string) => boolean)",+ "required": false,+ "defaultValue": null,+ "description": "Returns whether a canonical YYYY-MM-DD date cannot be selected. The calendar engine handles unavailable-date presentation and navigation."+ },+ {+ "name": "isGridHidden",+ "type": "boolean",+ "required": false,+ "defaultValue": "false",+ "description": "Hides weekday and date rows while retaining the header for a month-only navigator."+ },+ {+ "name": "isKeyboardNavigationDisabled",+ "type": "boolean",+ "required": false,+ "defaultValue": "false",+ "description": "Disables keyboard date navigation in the calendar engine for compatibility with existing input wrappers. Header controls retain their native keyboard behavior."+ },+ {+ "name": "loadingFallback",+ "type": "ReactNode",+ "required": false,+ "defaultValue": "300px-high Skeleton",+ "description": "Custom Suspense fallback while the calendar engine loads. Defaults to a 300px-high Skeleton."+ },+ {+ "name": "locale",+ "type": "string",+ "required": true,+ "defaultValue": null,+ "description": "Locale for the default month/year header and custom weekday titles. Engine day labels retain their existing locale behavior; values remain Gregorian date-only strings."+ },+ {+ "name": "monthLabel",+ "type": "string",+ "required": true,+ "defaultValue": null,+ "description": "Accessible name of the default month selector."+ },+ {+ "name": "nextMonthLabel",+ "type": "string",+ "required": true,+ "defaultValue": null,+ "description": "Accessible name of the default next-month button."+ },+ {+ "name": "onNavigationOpenChange",+ "type": "((args: { open: boolean; control: \"month\" | \"year\"; }) => void)",+ "required": false,+ "defaultValue": null,+ "description": "Reports { open, control } when a default month or year popup starts opening, and when it finishes closing or its selector unmounts. Header arrow actions do not call this callback."+ },+ {+ "name": "onValueChange",+ "type": "(date: string) => void",+ "required": true,+ "defaultValue": null,+ "description": "Called when choosing an available day changes the selected date. Month and year browsing does not select another date."+ },+ {+ "name": "onValueSelect",+ "type": "((date: string) => void)",+ "required": false,+ "defaultValue": null,+ "description": "Called with the selected YYYY-MM-DD date after choosing an available day, including the already-selected day. Use it to commit or close a product picker."+ },+ {+ "name": "onViewedMonthChange",+ "type": "(month: string) => void",+ "required": true,+ "defaultValue": null,+ "description": "Requests the month shown by calendar navigation without changing the selected date."+ },+ {+ "name": "portalContainer",+ "type": "HTMLElement | ShadowRoot | RefObject<HTMLElement | ShadowRoot | null> | null",+ "required": false,+ "defaultValue": null,+ "description": "Mount container for the default month and year selector popups. Accepts the shared Select portal container contract."+ },+ {+ "name": "previousMonthLabel",+ "type": "string",+ "required": true,+ "defaultValue": null,+ "description": "Accessible name of the default previous-month button."+ },+ {+ "name": "readOnly",+ "type": "boolean",+ "required": false,+ "defaultValue": "false",+ "description": "Prevents date selection while allowing month and year browsing and displaying the selected date or highlighted range."+ },+ {+ "name": "ref",+ "type": "Ref<HTMLDivElement>",+ "required": false,+ "defaultValue": null,+ "description": "Ref to the root element."+ },+ {+ "name": "render",+ "type": "ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, {}>",+ "required": false,+ "defaultValue": null,+ "description": "Composes the root element while preserving its props and contents."+ },+ {+ "name": "renderHeader",+ "type": "((props: DatePickerHeaderProps) => ReactNode)",+ "required": false,+ "defaultValue": null,+ "description": "Renders a product header with the viewed month, previous/next actions, month numbers from 1 through 12, year change actions, and navigation-disabled states. Header actions only browse months."+ },+ {+ "name": "role",+ "type": "AriaRole",+ "required": false,+ "defaultValue": "group",+ "description": "Root semantics. Defaults to a group; the caller supplies its accessible name."+ },+ {+ "name": "style",+ "type": "CSSProperties",+ "required": false,+ "defaultValue": null,+ "description": "Inline styles applied to the root element."+ },+ {+ "name": "value",+ "type": "string | null",+ "required": true,+ "defaultValue": null,+ "description": "Controlled selected Gregorian date in YYYY-MM-DD form, or null for no selection."+ },+ {+ "name": "viewedMonth",+ "type": "string",+ "required": true,+ "defaultValue": null,+ "description": "Controlled Gregorian month in YYYY-MM form. It is independent from the selected date."+ },+ {+ "name": "weekdayLabels",+ "type": "readonly [string, string, string, string, string, string, string]",+ "required": false,+ "defaultValue": null,+ "description": "Optional short weekday labels in Sunday-first order. The calendar engine supplies weekday names when omitted."+ },+ {+ "name": "weekStart",+ "type": "0 | 1 | 2 | 3 | 4 | 5 | 6",+ "required": true,+ "defaultValue": null,+ "description": "First weekday column: 0 for Sunday through 6 for Saturday."+ },+ {+ "name": "yearLabel",+ "type": "string",+ "required": true,+ "defaultValue": null,+ "description": "Accessible name of the default year selector."+ }+ ]+ },{"name": "SearchInput","entryPoint": "twenty-ui/components/input",diff --git a/packages/twenty-ui/package.json b/packages/twenty-ui/package.jsonindex 46a9b7b6c6e..4c19d6b1931 100644--- a/packages/twenty-ui/package.json+++ b/packages/twenty-ui/package.json@@ -81,6 +81,7 @@"@sniptt/guards": "^0.2.0","@tabler/icons-react": "^3.31.0","clsx": "^2.1.1",+ "react-datepicker": "^9.1.0","type-fest": "^4.10.1","zod": "^4.1.11"},diff --git a/packages/twenty-ui/src/components/input/DatePicker/DatePicker.module.scss b/packages/twenty-ui/src/components/input/DatePicker/DatePicker.module.scssnew file mode 100644index 00000000000..8f891e8a224--- /dev/null+++ b/packages/twenty-ui/src/components/input/DatePicker/DatePicker.module.scss@@ -0,0 +1,114 @@+.calendar {+ --calendar-day-size: calc(var(--t-spacing-8) + var(--t-spacing-0_5));++ box-sizing: border-box;+ font-family: var(--t-font-family);+ inline-size: calc(7 * var(--t-spacing-10));+ max-inline-size: 100%;+}++.header {+ align-items: center;+ display: flex;+ gap: var(--t-spacing-1);+ min-inline-size: 0;+ padding: var(--t-spacing-2);+ padding-block-end: 0;+}++.monthSelect {+ flex: 1.3;+ min-inline-size: 0;+}+.yearSelect {+ flex: 1;+ min-inline-size: 0;+}+.navigation {+ display: flex;+ gap: var(--t-spacing-1);+}+.chevron:dir(rtl) {+ transform: scaleX(-1);+}++.calendar :global(.react-datepicker) {+ background: transparent;+ border: none;+ display: block;+ font-family: var(--t-font-family);+ font-size: var(--t-font-size-md);+ font-weight: var(--t-font-weight-regular);+}++.calendar :global(.react-datepicker-popper) {+ position: relative !important;+ inset: auto !important;+ transform: none !important;+ padding: 0 !important;+}++.calendar :global(.react-datepicker__triangle),+.calendar :global(.react-datepicker-wrapper),+.calendar :global(.react-datepicker__current-month) {+ display: none;+}++.calendar :global(.react-datepicker__header) {+ background: transparent;+ border: none;+ padding: 0;+}++.calendar :global(.react-datepicker__month-container) {+ float: none;+}+.calendar :global(.react-datepicker__month) {+ margin: 0;+}++.calendar[data-readonly] :global(.react-datepicker__month) {+ pointer-events: none;+ opacity: 0.5;+}++.calendar[data-hide-grid] :global(.react-datepicker__month),+.calendar[data-hide-grid] :global(.react-datepicker__day-names) {+ display: none;+}++.calendar :global(.react-datepicker__day-name) {+ color: var(--t-font-color-secondary);+ width: var(--calendar-day-size);+ height: var(--t-spacing-10);+ line-height: var(--t-spacing-10);+ margin: var(--t-spacing-0_5);+}++.calendar :global(.react-datepicker__day) {+ width: var(--calendar-day-size);+ height: var(--calendar-day-size);+ line-height: var(--calendar-day-size);+ margin: var(--t-spacing-0_5);+ color: var(--t-font-color-primary);+}++.calendar :global(.react-datepicker__day--keyboard-selected) {+ background-color: inherit;+}++.calendar :global(.react-datepicker__day--outside-month),+.calendar :global(.react-datepicker__day:hover) {+ color: var(--t-font-color-secondary);+}++.calendar :global(.react-datepicker__day--selected),+.calendar :global(.react-datepicker__day--in-range),+.calendar :global(.react-datepicker__day--range-start),+.calendar :global(.react-datepicker__day--range-end) {+ background-color: var(--t-color-blue);+ color: var(--t-background-primary);+ &:hover {+ color: var(--t-background-primary);+ }+}diff --git a/packages/twenty-ui/src/components/input/DatePicker/DatePicker.tsx b/packages/twenty-ui/src/components/input/DatePicker/DatePicker.tsxnew file mode 100644index 00000000000..bc030ef9e7f--- /dev/null+++ b/packages/twenty-ui/src/components/input/DatePicker/DatePicker.tsx@@ -0,0 +1,229 @@+import { useDirection } from '@base-ui/react/direction-provider';+import { useRender } from '@base-ui/react/use-render';+import { clsx } from 'clsx';+import { Suspense, useRef, type MouseEvent as ReactMouseEvent } from 'react';+import {+ type default as ReactDatePicker,+ type ReactDatePickerCustomHeaderProps,+} from 'react-datepicker';+import 'react-datepicker/dist/react-datepicker.css';++import { Skeleton } from '@ui/primitives/feedback/Skeleton/Skeleton';+import { isDefined } from '@ui/utilities/utils/isDefined';++import styles from './DatePicker.module.scss';+import { DatePickerHeader } from './internal/DatePickerHeader';+import { DatePickerViewedMonthEffect } from './internal/DatePickerViewedMonthEffect';+import { formatDatePickerLocalDate } from './internal/formatDatePickerLocalDate';+import { parseDatePickerLocalDateOrThrow } from './internal/parseDatePickerLocalDateOrThrow';+import { ReactDatePickerLibrary } from './internal/ReactDatePickerLibrary';+import { validateDatePickerHighlightedRangeOrThrow } from './internal/validateDatePickerHighlightedRangeOrThrow';+import { type DatePickerProps } from './types/DatePickerProps';++const DATE_PICKER_LOADING_HEIGHT = 300;++export const DatePicker = ({+ value,+ onValueChange,+ onValueSelect,+ viewedMonth,+ onViewedMonthChange,+ highlightedRange,+ readOnly = false,+ isGridHidden = false,+ weekStart,+ locale,+ weekdayLabels,+ previousMonthLabel,+ nextMonthLabel,+ monthLabel,+ yearLabel,+ portalContainer,+ onNavigationOpenChange,+ isDateUnavailable,+ disabled = false,+ isKeyboardNavigationDisabled = false,+ renderHeader,+ loadingFallback,+ dir,+ render,+ ref,+ className,+ ...props+}: DatePickerProps) => {+ const calendarRef = useRef<ReactDatePicker>(null);+ const internalMouseDownRef = useRef<MouseEvent | null>(null);+ const engineViewedMonthRef = useRef(value?.slice(0, 7) ?? viewedMonth);+ const providedDirection = useDirection();+ const direction = dir === 'rtl' || dir === 'ltr' ? dir : providedDirection;++ if (isDefined(highlightedRange)) {+ validateDatePickerHighlightedRangeOrThrow(highlightedRange);+ }++ const handleViewedMonthChange = (date: Date) => {+ const nextMonth = formatDatePickerLocalDate(date).slice(0, 7);+ engineViewedMonthRef.current = nextMonth;++ if (nextMonth !== viewedMonth) {+ onViewedMonthChange(nextMonth);+ }+ };++ const handleDateChange = (date: Date | null) => {+ if (readOnly || disabled || !isDefined(date)) {+ return;+ }++ onValueChange(formatDatePickerLocalDate(date));+ };++ const calendarProps = {+ ref: calendarRef,+ open: true,+ onClickOutside: (event: MouseEvent) => {+ if (internalMouseDownRef.current === event) {+ event.preventDefault();+ }+ },+ minDate: parseDatePickerLocalDateOrThrow('0001-01-01'),+ maxDate: parseDatePickerLocalDateOrThrow('9999-12-31'),+ disabled,+ disabledKeyboardNavigation: isKeyboardNavigationDisabled,+ openToDate: parseDatePickerLocalDateOrThrow(`${viewedMonth}-01`),+ calendarStartDay: weekStart,+ onMonthChange: handleViewedMonthChange,+ onYearChange: handleViewedMonthChange,+ filterDate: (date: Date) =>+ !isDateUnavailable?.(formatDatePickerLocalDate(date)),+ onSelect: (date: Date | null) => {+ if (readOnly || disabled || !isDefined(date)) {+ return;+ }++ const nextValue = formatDatePickerLocalDate(date);++ if (isDefined(highlightedRange) && nextValue !== value) {+ onValueChange(nextValue);+ }++ onValueSelect?.(nextValue);+ },+ renderCustomDayName: isDefined(weekdayLabels)+ ? ({ day }: { day: Date }) => (+ <span+ title={new Intl.DateTimeFormat(locale, { weekday: 'long' }).format(+ day,+ )}+ >+ {weekdayLabels[day.getDay()]}+ </span>+ )+ : undefined,+ renderCustomHeader: ({+ monthDate,+ decreaseMonth,+ increaseMonth,+ changeMonth,+ changeYear,+ prevMonthButtonDisabled,+ nextMonthButtonDisabled,+ }: ReactDatePickerCustomHeaderProps) => {+ const navigationProps = {+ viewedMonth: formatDatePickerLocalDate(monthDate).slice(0, 7),+ onPreviousMonth: decreaseMonth,+ onNextMonth: increaseMonth,+ onMonthChange: (month: number) => changeMonth(month - 1),+ onYearChange: (year: number) => {+ const nextDate = new Date(monthDate);+ nextDate.setFullYear(year);+ const hasMonthOverflow = nextDate.getMonth() !== monthDate.getMonth();++ if (!hasMonthOverflow) {+ changeYear(year);+ return;+ }++ nextDate.setDate(0);+ calendarRef.current?.setPreSelection(nextDate);+ },+ isPreviousMonthDisabled: disabled || prevMonthButtonDisabled,+ isNextMonthDisabled: disabled || nextMonthButtonDisabled,+ };++ return isDefined(renderHeader) ? (+ <>{renderHeader(navigationProps)}</>+ ) : (+ <DatePickerHeader+ // oxlint-disable-next-line react/jsx-props-no-spreading+ {...navigationProps}+ locale={locale}+ previousMonthLabel={previousMonthLabel}+ nextMonthLabel={nextMonthLabel}+ monthLabel={monthLabel}+ yearLabel={yearLabel}+ portalContainer={portalContainer}+ onNavigationOpenChange={onNavigationOpenChange}+ disabled={disabled}+ />+ );+ },+ };++ const renderCalendar = () => {+ if (isDefined(highlightedRange)) {+ return (+ <ReactDatePickerLibrary+ // oxlint-disable-next-line react/jsx-props-no-spreading+ {...calendarProps}+ selectsRange+ startDate={parseDatePickerLocalDateOrThrow(highlightedRange.start)}+ endDate={parseDatePickerLocalDateOrThrow(highlightedRange.end)}+ onChange={() => undefined}+ />+ );+ }++ return (+ <ReactDatePickerLibrary+ // oxlint-disable-next-line react/jsx-props-no-spreading+ {...calendarProps}+ selected={+ isDefined(value) ? parseDatePickerLocalDateOrThrow(value) : null+ }+ onChange={handleDateChange}+ />+ );+ };++ return useRender({+ render,+ ref,+ props: {+ role: 'group',+ ...props,+ dir: direction,+ onMouseDownCapture: (event: ReactMouseEvent<HTMLDivElement>) => {+ props.onMouseDownCapture?.(event);+ internalMouseDownRef.current = event.nativeEvent;+ },+ className: clsx(styles.calendar, className),+ 'data-readonly': readOnly || undefined,+ 'data-hide-grid': isGridHidden || undefined,+ children: (+ <Suspense+ fallback={+ loadingFallback ?? <Skeleton height={DATE_PICKER_LOADING_HEIGHT} />+ }+ >+ <DatePickerViewedMonthEffect+ calendarRef={calendarRef}+ engineViewedMonthRef={engineViewedMonthRef}+ viewedMonth={viewedMonth}+ />+ {renderCalendar()}+ </Suspense>+ ),+ },+ });+};diff --git a/packages/twenty-ui/src/components/input/DatePicker/__stories__/DatePicker.interactions.stories.tsx b/packages/twenty-ui/src/components/input/DatePicker/__stories__/DatePicker.interactions.stories.tsxnew file mode 100644index 00000000000..4892a26cd65--- /dev/null+++ b/packages/twenty-ui/src/components/input/DatePicker/__stories__/DatePicker.interactions.stories.tsx@@ -0,0 +1,442 @@+import { type Meta, type StoryObj } from '@storybook/react-vite';+import { expect, fn, userEvent, waitFor, within } from 'storybook/test';++import { DirectionProvider } from '@ui/primitives/layout/DirectionProvider/DirectionProvider';+import { ComponentDecorator } from '@ui/testing';+import { THEME_COMMON } from '@ui/theme/constants/ThemeCommon';++import { DatePicker } from '../DatePicker';+import { DATE_PICKER_WEEKDAY_LABELS } from './datePickerWeekdayLabels';+import { DatePickerExample } from './DatePickerExample';+import { DatePickerCssVariableThemeExample } from './DatePickerCssVariableThemeExample';+import { DatePickerExternalMonthExample } from './DatePickerExternalMonthExample';+import { DatePickerNavigationUnmountExample } from './DatePickerNavigationUnmountExample';++const meta: Meta<typeof DatePicker> = {+ id: 'ui-components-datepicker-interactions',+ title: 'UI/Components/Input/DatePicker/Interactions',+ component: DatePicker,+ decorators: [ComponentDecorator],+ parameters: { container: { width: 312 } },+ args: {+ 'aria-label': 'Choose a date',+ value: '2026-10-07',+ viewedMonth: '2026-10',+ weekStart: 1,+ locale: 'en-US',+ weekdayLabels: DATE_PICKER_WEEKDAY_LABELS,+ previousMonthLabel: 'Previous month',+ nextMonthLabel: 'Next month',+ monthLabel: 'Month',+ yearLabel: 'Year',+ onValueChange: fn(),+ onValueSelect: fn(),+ onViewedMonthChange: fn(),+ onNavigationOpenChange: fn(),+ },+};++export default meta;+type Story = StoryObj<typeof DatePicker>;++const NEXT_YEAR_OPTION_LABEL = /^2027$/;+const LEAP_YEAR_OPTION_LABEL = /^2024$/;+const NON_LEAP_YEAR_OPTION_LABEL = /^2025$/;++export const DayKeyboardNavigation: Story = {+ render: ({ onValueChange, onValueSelect, onViewedMonthChange }) => (+ <DatePickerExample+ onValueChange={onValueChange}+ onValueSelect={onValueSelect}+ onViewedMonthChange={onViewedMonthChange}+ />+ ),+ play: async ({ canvasElement, args }) => {+ const canvas = within(canvasElement);+ const selected = await canvas.findByRole('gridcell', {+ name: 'Choose Wednesday, October 7th, 2026',+ });++ await expect(canvas.getAllByRole('columnheader')[0]).toHaveTextContent(+ 'Mo',+ );+ await expect(selected).toHaveAttribute('aria-selected', 'true');+ selected.focus();+ await userEvent.keyboard('{ArrowDown}');+ await expect(+ canvas.getByRole('gridcell', {+ name: 'Choose Wednesday, October 14th, 2026',+ }),+ ).toHaveFocus();+ await expect(args.onValueChange).not.toHaveBeenCalled();+ await userEvent.keyboard('{Enter}');+ await expect(args.onValueChange).toHaveBeenLastCalledWith('2026-10-14');+ await expect(args.onValueSelect).toHaveBeenLastCalledWith('2026-10-14');+ },+};++export const MonthAndYearControls: Story = {+ render: ({ onValueChange, onViewedMonthChange, onNavigationOpenChange }) => (+ <DatePickerExample+ onValueChange={onValueChange}+ onViewedMonthChange={onViewedMonthChange}+ onNavigationOpenChange={onNavigationOpenChange}+ />+ ),+ play: async ({ canvasElement, args }) => {+ const canvas = within(canvasElement);+ const body = within(canvasElement.ownerDocument.body);+ const nextMonth = await canvas.findByRole('button', { name: 'Next month' });++ await userEvent.click(nextMonth);+ await expect(+ canvas.getByRole('combobox', { name: 'Month' }),+ ).toHaveTextContent('November');+ await expect(nextMonth).toHaveFocus();+ await expect(+ canvas.getAllByRole('gridcell').filter((day) => day.tabIndex === 0),+ ).toHaveLength(1);+ await expect(args.onViewedMonthChange).toHaveBeenLastCalledWith('2026-11');+ await userEvent.click(canvas.getByRole('combobox', { name: 'Month' }));+ await userEvent.click(+ await body.findByRole('option', { name: 'December' }),+ );+ await expect(+ canvas.getByRole('combobox', { name: 'Month' }),+ ).toHaveTextContent('December');+ await expect(args.onViewedMonthChange).toHaveBeenLastCalledWith('2026-12');+ await userEvent.click(canvas.getByRole('combobox', { name: 'Year' }));+ await userEvent.click(+ await body.findByRole('option', { name: NEXT_YEAR_OPTION_LABEL }),+ );+ await expect(+ canvas.getByRole('combobox', { name: 'Year' }),+ ).toHaveTextContent('2027');+ await expect(args.onViewedMonthChange).toHaveBeenLastCalledWith('2027-12');+ await waitFor(() =>+ expect(args.onNavigationOpenChange).toHaveBeenLastCalledWith({+ open: false,+ control: 'year',+ }),+ );+ await expect(args.onNavigationOpenChange).toHaveBeenCalledTimes(4);+ await expect(args.onValueChange).not.toHaveBeenCalled();+ },+};++export const NavigationUnmount: Story = {+ render: ({ onNavigationOpenChange }) => (+ <DatePickerNavigationUnmountExample+ onNavigationOpenChange={onNavigationOpenChange}+ />+ ),+ play: async ({ canvasElement, args }) => {+ const canvas = within(canvasElement);+ const body = within(canvasElement.ownerDocument.body);+ await userEvent.click(+ await canvas.findByRole('combobox', { name: 'Month' }),+ );+ await expect(args.onNavigationOpenChange).toHaveBeenLastCalledWith({+ open: true,+ control: 'month',+ });+ await userEvent.click(+ await body.findByRole('option', { name: 'November' }),+ );+ await expect(canvas.getByText('Calendar hidden')).toBeVisible();+ await expect(args.onNavigationOpenChange).toHaveBeenLastCalledWith({+ open: false,+ control: 'month',+ });+ },+};++export const UnavailableDates: Story = {+ render: ({ onValueChange, onViewedMonthChange }) => (+ <DatePickerExample+ onValueChange={onValueChange}+ onViewedMonthChange={onViewedMonthChange}+ isDateUnavailable={(date) => date === '2026-10-08'}+ />+ ),+ play: async ({ canvasElement, args }) => {+ const canvas = within(canvasElement);+ const selected = await canvas.findByRole('gridcell', {+ name: 'Choose Wednesday, October 7th, 2026',+ });+ const unavailable = canvas.getByRole('gridcell', {+ name: 'Not available Thursday, October 8th, 2026',+ });++ await expect(unavailable).toHaveAttribute('aria-disabled', 'true');+ await userEvent.click(unavailable);+ await expect(args.onValueChange).not.toHaveBeenCalled();+ selected.focus();+ await userEvent.keyboard('{ArrowRight}');+ await expect(+ canvas.getByRole('gridcell', {+ name: 'Choose Friday, October 9th, 2026',+ }),+ ).toHaveFocus();+ await userEvent.keyboard('{Enter}');+ await expect(args.onValueChange).toHaveBeenLastCalledWith('2026-10-09');+ },+};++export const MonthBoundaryAndLeapYear: Story = {+ render: ({ onValueChange, onViewedMonthChange }) => (+ <DatePickerExample+ initialValue="2024-01-31"+ initialViewedMonth="2024-01"+ onValueChange={onValueChange}+ onViewedMonthChange={onViewedMonthChange}+ />+ ),+ play: async ({ canvasElement, args }) => {+ const canvas = within(canvasElement);+ (+ await canvas.findByRole('gridcell', {+ name: 'Choose Wednesday, January 31st, 2024',+ })+ ).focus();+ await userEvent.keyboard('{PageDown}');+ await waitFor(() =>+ expect(+ canvas.getByRole('gridcell', {+ name: 'Choose Thursday, February 29th, 2024',+ }),+ ).toHaveFocus(),+ );+ await userEvent.keyboard('{Shift>}{PageDown}{/Shift}');+ await waitFor(() =>+ expect(+ canvas.getByRole('gridcell', {+ name: 'Choose Friday, February 28th, 2025',+ }),+ ).toHaveFocus(),+ );+ await expect(args.onValueChange).not.toHaveBeenCalled();+ const body = within(canvasElement.ownerDocument.body);+ await userEvent.click(canvas.getByRole('combobox', { name: 'Year' }));+ await userEvent.click(+ await body.findByRole('option', { name: LEAP_YEAR_OPTION_LABEL }),+ );+ await userEvent.click(+ canvas.getByRole('gridcell', {+ name: 'Choose Thursday, February 29th, 2024',+ }),+ );+ await expect(args.onValueChange).toHaveBeenLastCalledWith('2024-02-29');+ await userEvent.click(canvas.getByRole('combobox', { name: 'Year' }));+ await userEvent.click(+ await body.findByRole('option', { name: NON_LEAP_YEAR_OPTION_LABEL }),+ );+ await expect(+ canvas.getByRole('combobox', { name: 'Month' }),+ ).toHaveTextContent('February');+ await expect(args.onViewedMonthChange).toHaveBeenLastCalledWith('2025-02');+ await expect(+ canvas.getByRole('gridcell', {+ name: 'Choose Friday, February 28th, 2025',+ }),+ ).toHaveAttribute('tabindex', '0');+ await expect(args.onValueChange).toHaveBeenCalledTimes(1);+ },+};++export const ExternalMonthChange: Story = {+ render: ({ onValueChange, onViewedMonthChange }) => (+ <DatePickerExternalMonthExample+ onValueChange={onValueChange}+ onViewedMonthChange={onViewedMonthChange}+ />+ ),+ play: async ({ canvasElement, args }) => {+ const canvas = within(canvasElement);+ const externalControl = await canvas.findByRole('button', {+ name: 'Show November',+ });++ await userEvent.click(externalControl);+ await expect(+ await canvas.findByRole('gridcell', {+ name: 'Choose Sunday, November 15th, 2026',+ }),+ ).toBeVisible();+ await expect(externalControl).toHaveFocus();+ await expect(+ canvas.getAllByRole('gridcell').filter((day) => day.tabIndex === 0),+ ).toHaveLength(1);+ await expect(args.onViewedMonthChange).not.toHaveBeenCalled();+ await expect(args.onValueChange).not.toHaveBeenCalled();+ },+};++export const RightToLeft: Story = {+ render: () => (+ <DirectionProvider direction="rtl">+ <DatePickerExample />+ </DirectionProvider>+ ),+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);+ const selected = await canvas.findByRole('gridcell', {+ name: 'Choose Wednesday, October 7th, 2026',+ });+ const nextDate = canvas.getByRole('gridcell', {+ name: 'Choose Thursday, October 8th, 2026',+ });++ await expect(+ canvas.getByRole('group', { name: 'Choose a date' }),+ ).toHaveAttribute('dir', 'rtl');+ await expect(nextDate.getBoundingClientRect().left).toBeLessThan(+ selected.getBoundingClientRect().left,+ );+ },+};++export const Disabled: Story = {+ args: { disabled: true },+ play: async ({ canvasElement, args }) => {+ const canvas = within(canvasElement);+ const next = await canvas.findByRole('button', { name: 'Next month' });+ const date = canvas.getByRole('gridcell', {+ name: 'Not available Wednesday, October 7th, 2026',+ });++ await expect(next).toBeDisabled();+ await expect(date).toHaveAttribute('aria-disabled', 'true');+ await expect(+ canvas.getByRole('combobox', { name: 'Month' }),+ ).toBeDisabled();+ await userEvent.click(date);+ await expect(args.onValueChange).not.toHaveBeenCalled();+ },+};++export const SundayStart: Story = {+ args: { weekStart: 0 },+ play: async ({ canvasElement }) => {+ const headers = await within(canvasElement).findAllByRole('columnheader');+ await expect(headers.map((header) => header.textContent)).toEqual(+ DATE_PICKER_WEEKDAY_LABELS,+ );+ },+};++export const RangeReadOnlyNavigation: Story = {+ render: ({ onValueChange, onViewedMonthChange }) => (+ <DatePickerExample+ initialValue={null}+ highlightedRange={{ start: '2026-10-07', end: '2026-10-09' }}+ readOnly+ onValueChange={onValueChange}+ onViewedMonthChange={onViewedMonthChange}+ />+ ),+ play: async ({ canvasElement, args }) => {+ const canvas = within(canvasElement);+ const middleDate = await canvas.findByRole('gridcell', {+ name: 'Choose Thursday, October 8th, 2026',+ });++ await expect(middleDate).toHaveAttribute('aria-selected', 'true');+ await expect(+ canvas.getAllByRole('gridcell', { selected: true }),+ ).toHaveLength(3);+ await expect(middleDate.parentElement?.parentElement).toHaveStyle({+ pointerEvents: 'none',+ opacity: '0.5',+ });+ await userEvent.click(canvas.getByRole('button', { name: 'Next month' }));+ await expect(+ canvas.getByRole('combobox', { name: 'Month' }),+ ).toHaveTextContent('November');+ await expect(args.onValueChange).not.toHaveBeenCalled();+ },+};++export const HeaderOnly: Story = {+ render: ({ onValueChange, onViewedMonthChange }) => (+ <DatePickerExample+ isGridHidden+ onValueChange={onValueChange}+ onViewedMonthChange={onViewedMonthChange}+ />+ ),+ play: async ({ canvasElement, args }) => {+ const canvas = within(canvasElement);+ await expect(+ await canvas.findByRole('combobox', { name: 'Month' }),+ ).toBeVisible();+ await expect(canvas.queryByRole('gridcell')).not.toBeInTheDocument();+ await userEvent.click(canvas.getByRole('button', { name: 'Next month' }));+ await expect(args.onViewedMonthChange).toHaveBeenLastCalledWith('2026-11');+ await expect(args.onValueChange).not.toHaveBeenCalled();+ },+};++export const SameAndAdjacentDates: Story = {+ render: ({ onValueChange, onValueSelect }) => (+ <DatePickerExample+ onValueChange={onValueChange}+ onValueSelect={onValueSelect}+ />+ ),+ play: async ({ canvasElement, args }) => {+ const canvas = within(canvasElement);+ await userEvent.click(+ await canvas.findByRole('gridcell', {+ name: 'Choose Wednesday, October 7th, 2026',+ }),+ );+ await expect(args.onValueChange).not.toHaveBeenCalled();+ await expect(args.onValueSelect).toHaveBeenLastCalledWith('2026-10-07');+ await userEvent.click(+ canvas.getByRole('gridcell', {+ name: 'Choose Wednesday, September 30th, 2026',+ }),+ );+ await expect(args.onValueChange).toHaveBeenLastCalledWith('2026-09-30');+ await expect(args.onValueSelect).toHaveBeenLastCalledWith('2026-09-30');+ },+};++export const SupportedYearBoundaries: Story = {+ args: { value: '0001-01-01', viewedMonth: '0001-01' },+ play: async ({ canvasElement, args }) => {+ const canvas = within(canvasElement);+ const previous = await canvas.findByRole('button', {+ name: 'Previous month',+ });+ await expect(previous).toBeDisabled();+ await userEvent.click(previous);+ await expect(args.onViewedMonthChange).not.toHaveBeenCalled();+ },+};++export const CssVariableSpacing: Story = {+ render: () => <DatePickerCssVariableThemeExample />,+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);+ const body = within(canvasElement.ownerDocument.body);+ const monthTrigger = await canvas.findByRole('combobox', {+ name: 'Month',+ });++ await userEvent.click(monthTrigger);+ const popup = await body.findByRole('listbox');++ await waitFor(() =>+ expect(+ popup.getBoundingClientRect().top -+ monthTrigger.getBoundingClientRect().bottom,+ ).toBeCloseTo(THEME_COMMON.spacingMultiplicator, 0),+ );+ await userEvent.click(+ within(popup).getByRole('option', { name: 'November' }),+ );+ await expect(monthTrigger).toHaveTextContent('November');+ },+};diff --git a/packages/twenty-ui/src/components/input/DatePicker/__stories__/DatePicker.stories.module.scss b/packages/twenty-ui/src/components/input/DatePicker/__stories__/DatePicker.stories.module.scssnew file mode 100644index 00000000000..3712522413d--- /dev/null+++ b/packages/twenty-ui/src/components/input/DatePicker/__stories__/DatePicker.stories.module.scss@@ -0,0 +1,5 @@+.externalExample {+ display: grid;+ justify-items: start;+ gap: var(--t-spacing-3);+}diff --git a/packages/twenty-ui/src/components/input/DatePicker/__stories__/DatePicker.stories.tsx b/packages/twenty-ui/src/components/input/DatePicker/__stories__/DatePicker.stories.tsxnew file mode 100644index 00000000000..5ac03132086--- /dev/null+++ b/packages/twenty-ui/src/components/input/DatePicker/__stories__/DatePicker.stories.tsx@@ -0,0 +1,101 @@+import { type Meta, type StoryObj } from '@storybook/react-vite';+import { fn } from 'storybook/test';++import { Text } from '@ui/primitives/typography/Text/Text';+import { ComponentDecorator, GroupedCatalog } from '@ui/testing';++import { DatePicker } from '../DatePicker';+import { DATE_PICKER_WEEKDAY_LABELS } from './datePickerWeekdayLabels';+import { type DatePickerProps } from '../types/DatePickerProps';+import { DatePickerExample } from './DatePickerExample';++const meta: Meta<typeof DatePicker> = {+ id: 'ui-components-datepicker',+ title: 'UI/Components/Input/DatePicker',+ component: DatePicker,+ decorators: [ComponentDecorator],+ parameters: { container: { width: 312 } },+ args: {+ 'aria-label': 'Choose a date',+ value: '2026-10-07',+ viewedMonth: '2026-10',+ weekStart: 1,+ locale: 'en-US',+ weekdayLabels: DATE_PICKER_WEEKDAY_LABELS,+ previousMonthLabel: 'Previous month',+ nextMonthLabel: 'Next month',+ monthLabel: 'Month',+ yearLabel: 'Year',+ onValueChange: fn(),+ onViewedMonthChange: fn(),+ },+};++export default meta;+type Story = StoryObj<typeof DatePicker>;++export const Display: Story = {+ argTypes: {+ value: { control: false },+ viewedMonth: { control: false },+ weekStart: { control: false },+ locale: { control: false },+ weekdayLabels: { control: false },+ previousMonthLabel: { control: false },+ nextMonthLabel: { control: false },+ monthLabel: { control: false },+ yearLabel: { control: false },+ 'aria-label': { control: false },+ },+ render: ({ disabled, highlightedRange, readOnly, isGridHidden }) => (+ <DatePickerExample+ disabled={disabled}+ highlightedRange={highlightedRange}+ readOnly={readOnly}+ isGridHidden={isGridHidden}+ />+ ),+};++const CALENDAR_EXAMPLES: {+ label: string;+ props: Partial<+ Pick<DatePickerProps, 'value' | 'disabled' | 'isDateUnavailable'>+ >;+}[] = [+ { label: 'Selected date and today', props: {} },+ { label: 'No selection', props: { value: null } },+ {+ label: 'Unavailable date',+ props: { isDateUnavailable: (date) => date === '2026-10-08' },+ },+ { label: 'Disabled', props: { disabled: true } },+];++export const Catalog: Story = {+ parameters: { container: { width: 680 } },+ render: (args) => (+ <GroupedCatalog+ groups={[+ { label: 'Selection and availability', examples: CALENDAR_EXAMPLES },+ ]}+ renderExample={({ label, props }) => (+ <>+ <Text>{label}</Text>+ <DatePicker+ // oxlint-disable-next-line react/jsx-props-no-spreading+ {...args}+ // oxlint-disable-next-line react/jsx-props-no-spreading+ {...props}+ aria-label={label}+ />+ </>+ )}+ />+ ),+};++export const DisplayDark: Story = {+ ...Display,+ globals: { colorScheme: 'dark' },+};diff --git a/packages/twenty-ui/src/components/input/DatePicker/__stories__/DatePickerCssVariableThemeExample.tsx b/packages/twenty-ui/src/components/input/DatePicker/__stories__/DatePickerCssVariableThemeExample.tsxnew file mode 100644index 00000000000..e123ccb2982--- /dev/null+++ b/packages/twenty-ui/src/components/input/DatePicker/__stories__/DatePickerCssVariableThemeExample.tsx@@ -0,0 +1,20 @@+import { THEME_LIGHT } from '@ui/theme/constants/ThemeLight';+import { getThemeContext } from '@ui/theme/internal/getThemeContext';+import { themeCssVariables } from '@ui/theme/themeCssVariables';++import { DatePickerExample } from './DatePickerExample';++export const DatePickerCssVariableThemeExample = () => {+ const ThemeContext = getThemeContext();++ return (+ <ThemeContext.Provider+ value={{+ theme: { ...THEME_LIGHT, spacing: themeCssVariables.spacing },+ colorScheme: 'light',+ }}+ >+ <DatePickerExample />+ </ThemeContext.Provider>+ );+};diff --git a/packages/twenty-ui/src/components/input/DatePicker/__stories__/DatePickerExample.tsx b/packages/twenty-ui/src/components/input/DatePicker/__stories__/DatePickerExample.tsxnew file mode 100644index 00000000000..4ddffc52a35--- /dev/null+++ b/packages/twenty-ui/src/components/input/DatePicker/__stories__/DatePickerExample.tsx@@ -0,0 +1,68 @@+import { useState } from 'react';++import { DatePicker } from '../DatePicker';+import { DATE_PICKER_WEEKDAY_LABELS } from './datePickerWeekdayLabels';+import { type DatePickerProps } from '../types/DatePickerProps';++export const DatePickerExample = ({+ initialValue = '2026-10-07',+ initialViewedMonth = '2026-10',+ highlightedRange,+ readOnly,+ isGridHidden,+ disabled,+ isDateUnavailable,+ onValueChange,+ onValueSelect,+ onViewedMonthChange,+ onNavigationOpenChange,+}: Partial<+ Pick<+ DatePickerProps,+ | 'highlightedRange'+ | 'readOnly'+ | 'isGridHidden'+ | 'disabled'+ | 'isDateUnavailable'+ | 'onValueChange'+ | 'onValueSelect'+ | 'onViewedMonthChange'+ | 'onNavigationOpenChange'+ >+> & {+ initialValue?: string | null;+ initialViewedMonth?: string;+}) => {+ const [value, setValue] = useState(initialValue);+ const [viewedMonth, setViewedMonth] = useState(initialViewedMonth);++ return (+ <DatePicker+ aria-label="Choose a date"+ value={value}+ onValueChange={(date) => {+ setValue(date);+ onValueChange?.(date);+ }}+ onValueSelect={onValueSelect}+ onNavigationOpenChange={onNavigationOpenChange}+ viewedMonth={viewedMonth}+ onViewedMonthChange={(month) => {+ setViewedMonth(month);+ onViewedMonthChange?.(month);+ }}+ highlightedRange={highlightedRange}+ readOnly={readOnly}+ isGridHidden={isGridHidden}+ weekStart={1}+ locale="en-US"+ weekdayLabels={DATE_PICKER_WEEKDAY_LABELS}+ previousMonthLabel="Previous month"+ nextMonthLabel="Next month"+ monthLabel="Month"+ yearLabel="Year"+ disabled={disabled}+ isDateUnavailable={isDateUnavailable}+ />+ );+};diff --git a/packages/twenty-ui/src/components/input/DatePicker/__stories__/DatePickerExternalMonthExample.tsx b/packages/twenty-ui/src/components/input/DatePicker/__stories__/DatePickerExternalMonthExample.tsxnew file mode 100644index 00000000000..6e97f5bf675--- /dev/null+++ b/packages/twenty-ui/src/components/input/DatePicker/__stories__/DatePickerExternalMonthExample.tsx@@ -0,0 +1,42 @@+import { useState } from 'react';++import { Button } from '@ui/primitives/input/Button/Button';+import styles from './DatePicker.stories.module.scss';++import { DatePicker } from '../DatePicker';+import { DATE_PICKER_WEEKDAY_LABELS } from './datePickerWeekdayLabels';++export const DatePickerExternalMonthExample = ({+ onValueChange,+ onViewedMonthChange,+}: {+ onValueChange: (date: string) => void;+ onViewedMonthChange: (month: string) => void;+}) => {+ const [viewedMonth, setViewedMonth] = useState('2026-10');++ return (+ <div className={styles.externalExample}>+ <DatePicker+ aria-label="Choose a date"+ value="2026-10-07"+ onValueChange={onValueChange}+ viewedMonth={viewedMonth}+ onViewedMonthChange={(month) => {+ setViewedMonth(month);+ onViewedMonthChange(month);+ }}+ weekStart={1}+ locale="en-US"+ weekdayLabels={DATE_PICKER_WEEKDAY_LABELS}+ previousMonthLabel="Previous month"+ nextMonthLabel="Next month"+ monthLabel="Month"+ yearLabel="Year"+ />+ <Button size="sm" onClick={() => setViewedMonth('2026-11')}>+ Show November+ </Button>+ </div>+ );+};diff --git a/packages/twenty-ui/src/components/input/DatePicker/__stories__/DatePickerNavigationUnmountExample.tsx b/packages/twenty-ui/src/components/input/DatePicker/__stories__/DatePickerNavigationUnmountExample.tsxnew file mode 100644index 00000000000..053e73f0468--- /dev/null+++ b/packages/twenty-ui/src/components/input/DatePicker/__stories__/DatePickerNavigationUnmountExample.tsx@@ -0,0 +1,23 @@+import { useState } from 'react';++import { Text } from '@ui/primitives/typography/Text/Text';++import { type DatePickerProps } from '../types/DatePickerProps';+import { DatePickerExample } from './DatePickerExample';++export const DatePickerNavigationUnmountExample = ({+ onNavigationOpenChange,+}: Pick<DatePickerProps, 'onNavigationOpenChange'>) => {+ const [isCalendarVisible, setIsCalendarVisible] = useState(true);++ if (!isCalendarVisible) {+ return <Text>Calendar hidden</Text>;+ }++ return (+ <DatePickerExample+ onNavigationOpenChange={onNavigationOpenChange}+ onViewedMonthChange={() => setIsCalendarVisible(false)}+ />+ );+};diff --git a/packages/twenty-ui/src/components/input/DatePicker/__stories__/datePickerWeekdayLabels.ts b/packages/twenty-ui/src/components/input/DatePicker/__stories__/datePickerWeekdayLabels.tsnew file mode 100644index 00000000000..134d157b364--- /dev/null+++ b/packages/twenty-ui/src/components/input/DatePicker/__stories__/datePickerWeekdayLabels.ts@@ -0,0 +1,9 @@+export const DATE_PICKER_WEEKDAY_LABELS = [+ 'Su',+ 'Mo',+ 'Tu',+ 'We',+ 'Th',+ 'Fr',+ 'Sa',+] as const;diff --git a/packages/twenty-ui/src/components/input/DatePicker/__tests__/DatePicker.test.tsx b/packages/twenty-ui/src/components/input/DatePicker/__tests__/DatePicker.test.tsxnew file mode 100644index 00000000000..a11f13b1e6b--- /dev/null+++ b/packages/twenty-ui/src/components/input/DatePicker/__tests__/DatePicker.test.tsx@@ -0,0 +1,26 @@+import { vi } from 'vitest';++import { runComponentConformance } from '@test-utilities/conformance/runComponentConformance';++import { DatePicker } from '../DatePicker';+import styles from '../DatePicker.module.scss';++runComponentConformance({+ name: 'DatePicker',+ element: (+ <DatePicker+ value="2026-10-07"+ onValueChange={vi.fn()}+ viewedMonth="2026-10"+ onViewedMonthChange={vi.fn()}+ weekStart={1}+ locale="en-US"+ previousMonthLabel="Previous month"+ nextMonthLabel="Next month"+ monthLabel="Month"+ yearLabel="Year"+ />+ ),+ refInstanceOf: HTMLDivElement,+ ownClassName: styles.calendar,+});diff --git a/packages/twenty-ui/src/components/input/DatePicker/internal/DatePickerException.ts b/packages/twenty-ui/src/components/input/DatePicker/internal/DatePickerException.tsnew file mode 100644index 00000000000..4d4a31ba551--- /dev/null+++ b/packages/twenty-ui/src/components/input/DatePicker/internal/DatePickerException.ts@@ -0,0 +1,8 @@+import { doNotTranslate } from '@ui/utilities/internal/doNotTranslate';++export class DatePickerException extends RangeError {+ constructor({ message }: { message: string }) {+ super(message);+ this.name = doNotTranslate('DatePickerException');+ }+}diff --git a/packages/twenty-ui/src/components/input/DatePicker/internal/DatePickerHeader.tsx b/packages/twenty-ui/src/components/input/DatePicker/internal/DatePickerHeader.tsxnew file mode 100644index 00000000000..868f8d49da1--- /dev/null+++ b/packages/twenty-ui/src/components/input/DatePicker/internal/DatePickerHeader.tsx@@ -0,0 +1,118 @@+import { LightIconButton } from '@ui/components/input/LightIconButton/LightIconButton';+import { IconChevronLeft, IconChevronRight } from '@ui/icon';+import { doNotTranslate } from '@ui/utilities/internal/doNotTranslate';++import styles from '../DatePicker.module.scss';+import { type DatePickerProps } from '../types/DatePickerProps';+import { type DatePickerHeaderProps } from '../types/DatePickerHeaderProps';+import { DATE_PICKER_CONSTANTS } from './datePickerConstants';+import { DatePickerSelect } from './DatePickerSelect';+import { parseDatePickerDateOrThrow } from './parseDatePickerDateOrThrow';++const YEAR_WINDOW = 100;++export const DatePickerHeader = ({+ viewedMonth,+ onPreviousMonth,+ onNextMonth,+ onMonthChange,+ onYearChange,+ isPreviousMonthDisabled,+ isNextMonthDisabled,+ locale,+ previousMonthLabel,+ nextMonthLabel,+ monthLabel,+ yearLabel,+ portalContainer,+ onNavigationOpenChange,+ disabled,+}: DatePickerHeaderProps &+ Pick<+ DatePickerProps,+ | 'locale'+ | 'previousMonthLabel'+ | 'nextMonthLabel'+ | 'monthLabel'+ | 'yearLabel'+ | 'portalContainer'+ | 'onNavigationOpenChange'+ | 'disabled'+ >) => {+ const monthDate = parseDatePickerDateOrThrow(`${viewedMonth}-01`);+ const year = monthDate.getUTCFullYear();+ const month = monthDate.getUTCMonth() + 1;+ const monthFormatter = new Intl.DateTimeFormat(locale, {+ month: 'long',+ calendar: 'gregory',+ timeZone: doNotTranslate('UTC'),+ });+ const yearFormatter = new Intl.NumberFormat(locale, { useGrouping: false });+ const months = [];++ for (let index = 1; index <= DATE_PICKER_CONSTANTS.MONTHS_PER_YEAR; index++) {+ const date = new Date(monthDate);+ date.setUTCMonth(index - 1);+ months.push({ value: index, label: monthFormatter.format(date) });+ }++ const years = [];+ const firstYear = Math.max(+ DATE_PICKER_CONSTANTS.MIN_YEAR,+ year - YEAR_WINDOW,+ );+ const lastYear = Math.min(DATE_PICKER_CONSTANTS.MAX_YEAR, year + YEAR_WINDOW);++ for (let optionYear = firstYear; optionYear <= lastYear; optionYear++) {+ years.push({ value: optionYear, label: yearFormatter.format(optionYear) });+ }++ return (+ <div className={styles.header}>+ <div className={styles.monthSelect}>+ <DatePickerSelect+ value={month}+ items={months}+ disabled={disabled}+ label={monthLabel}+ portalContainer={portalContainer}+ onOpenChange={(open) =>+ onNavigationOpenChange?.({ open, control: 'month' })+ }+ onValueChange={onMonthChange}+ />+ </div>+ <div className={styles.yearSelect}>+ <DatePickerSelect+ value={year}+ items={years}+ disabled={disabled}+ label={yearLabel}+ portalContainer={portalContainer}+ onOpenChange={(open) =>+ onNavigationOpenChange?.({ open, control: 'year' })+ }+ onValueChange={onYearChange}+ />+ </div>+ <div className={styles.navigation}>+ <LightIconButton+ size="md"+ disabled={disabled || isPreviousMonthDisabled}+ aria-label={previousMonthLabel}+ onClick={onPreviousMonth}+ >+ <IconChevronLeft className={styles.chevron} />+ </LightIconButton>+ <LightIconButton+ size="md"+ disabled={disabled || isNextMonthDisabled}+ aria-label={nextMonthLabel}+ onClick={onNextMonth}+ >+ <IconChevronRight className={styles.chevron} />+ </LightIconButton>+ </div>+ </div>+ );+};diff --git a/packages/twenty-ui/src/components/input/DatePicker/internal/DatePickerSelect.tsx b/packages/twenty-ui/src/components/input/DatePicker/internal/DatePickerSelect.tsxnew file mode 100644index 00000000000..a0162470772--- /dev/null+++ b/packages/twenty-ui/src/components/input/DatePicker/internal/DatePickerSelect.tsx@@ -0,0 +1,81 @@+import { isNumber } from '@sniptt/guards';+import { useRef } from 'react';++import { Select } from '@ui/primitives/input/Select/Select';+import { THEME_COMMON } from '@ui/theme/constants/ThemeCommon';++import { type DatePickerProps } from '../types/DatePickerProps';+import { DatePickerSelectLifecycleEffect } from './DatePickerSelectLifecycleEffect';++type DatePickerSelectProps = {+ value: number;+ items: { value: number; label: string }[];+ onValueChange: (value: number) => void;+ label: string;+ disabled?: boolean;+ portalContainer?: DatePickerProps['portalContainer'];+ onOpenChange?: (open: boolean) => void;+};++export const DatePickerSelect = ({+ value,+ items,+ onValueChange,+ label,+ disabled,+ portalContainer,+ onOpenChange,+}: DatePickerSelectProps) => {+ const isOpenRef = useRef(false);++ return (+ <Select.Root+ value={value}+ items={items}+ disabled={disabled}+ onOpenChange={(open) => {+ if (open) {+ isOpenRef.current = true;+ onOpenChange?.(true);+ }+ }}+ onOpenChangeComplete={(open) => {+ if (!open && isOpenRef.current) {+ isOpenRef.current = false;+ onOpenChange?.(false);+ }+ }}+ onValueChange={(nextValue) => {+ if (!isNumber(nextValue)) {+ return;+ }++ onValueChange(nextValue);+ }}+ >+ <DatePickerSelectLifecycleEffect+ isOpenRef={isOpenRef}+ onOpenChange={onOpenChange}+ />+ <Select.Trigger aria-label={label}>+ <Select.Value />+ <Select.Icon />+ </Select.Trigger>+ <Select.Portal container={portalContainer}>+ <Select.Positioner+ sideOffset={THEME_COMMON.spacingMultiplicator}+ alignItemWithTrigger={false}+ >+ <Select.Popup>+ {items.map(({ value: itemValue, label: itemLabel }) => (+ <Select.Item key={itemValue} value={itemValue}>+ <Select.ItemText>{itemLabel}</Select.ItemText>+ <Select.ItemIndicator />+ </Select.Item>+ ))}+ </Select.Popup>+ </Select.Positioner>+ </Select.Portal>+ </Select.Root>+ );+};diff --git a/packages/twenty-ui/src/components/input/DatePicker/internal/DatePickerSelectLifecycleEffect.tsx b/packages/twenty-ui/src/components/input/DatePicker/internal/DatePickerSelectLifecycleEffect.tsxnew file mode 100644index 00000000000..e6044285b13--- /dev/null+++ b/packages/twenty-ui/src/components/input/DatePicker/internal/DatePickerSelectLifecycleEffect.tsx@@ -0,0 +1,27 @@+import { useStableCallback } from '@base-ui/utils/useStableCallback';+import { useEffect, type RefObject } from 'react';++type DatePickerSelectLifecycleEffectProps = {+ isOpenRef: RefObject<boolean>;+ onOpenChange?: (open: boolean) => void;+};++export const DatePickerSelectLifecycleEffect = ({+ isOpenRef,+ onOpenChange,+}: DatePickerSelectLifecycleEffectProps) => {+ const changeOpen = useStableCallback(onOpenChange);++ useEffect(() => {+ return () => {+ if (!isOpenRef.current) {+ return;+ }++ isOpenRef.current = false;+ changeOpen(false);+ };+ }, [isOpenRef, changeOpen]);++ return null;+};diff --git a/packages/twenty-ui/src/components/input/DatePicker/internal/DatePickerViewedMonthEffect.tsx b/packages/twenty-ui/src/components/input/DatePicker/internal/DatePickerViewedMonthEffect.tsxnew file mode 100644index 00000000000..f44bbaaae17--- /dev/null+++ b/packages/twenty-ui/src/components/input/DatePicker/internal/DatePickerViewedMonthEffect.tsx@@ -0,0 +1,29 @@+import { useEffect, type RefObject } from 'react';+import { type default as ReactDatePicker } from 'react-datepicker';++import { parseDatePickerLocalDateOrThrow } from './parseDatePickerLocalDateOrThrow';++type DatePickerViewedMonthEffectProps = {+ calendarRef: RefObject<ReactDatePicker | null>;+ engineViewedMonthRef: RefObject<string>;+ viewedMonth: string;+};++export const DatePickerViewedMonthEffect = ({+ calendarRef,+ engineViewedMonthRef,+ viewedMonth,+}: DatePickerViewedMonthEffectProps) => {+ useEffect(() => {+ if (engineViewedMonthRef.current === viewedMonth) {+ return;+ }++ calendarRef.current?.setPreSelection(+ parseDatePickerLocalDateOrThrow(`${viewedMonth}-01`),+ );+ engineViewedMonthRef.current = viewedMonth;+ }, [calendarRef, engineViewedMonthRef, viewedMonth]);++ return null;+};diff --git a/packages/twenty-ui/src/components/input/DatePicker/internal/ReactDatePickerLibrary.tsx b/packages/twenty-ui/src/components/input/DatePicker/internal/ReactDatePickerLibrary.tsxnew file mode 100644index 00000000000..dfda43ca787--- /dev/null+++ b/packages/twenty-ui/src/components/input/DatePicker/internal/ReactDatePickerLibrary.tsx@@ -0,0 +1,13 @@+import { lazy } from 'react';+import { type default as ReactDatePicker } from 'react-datepicker';++export const ReactDatePickerLibrary = lazy<typeof ReactDatePicker>(async () => {+ const datePickerModule: {+ default: typeof ReactDatePicker | { default: typeof ReactDatePicker };+ } = await import('react-datepicker');+ const datePicker = datePickerModule.default;++ return {+ default: 'default' in datePicker ? datePicker.default : datePicker,+ };+});diff --git a/packages/twenty-ui/src/components/input/DatePicker/internal/__tests__/parseDatePickerDateOrThrow.test.ts b/packages/twenty-ui/src/components/input/DatePicker/internal/__tests__/parseDatePickerDateOrThrow.test.tsnew file mode 100644index 00000000000..e9f680062a2--- /dev/null+++ b/packages/twenty-ui/src/components/input/DatePicker/internal/__tests__/parseDatePickerDateOrThrow.test.ts@@ -0,0 +1,32 @@+import { describe, expect, it } from 'vitest';++import { DatePickerException } from '../DatePickerException';++import { parseDatePickerDateOrThrow } from '../parseDatePickerDateOrThrow';++describe('parseDatePickerDateOrThrow', () => {+ it.each(['0001-01-01', '0051-06-15', '2000-02-29', '9999-12-31'])(+ 'parses %s as UTC midnight, including years below 100',+ (value) => {+ expect(parseDatePickerDateOrThrow(value).toISOString()).toBe(+ `${value}T00:00:00.000Z`,+ );+ },+ );++ it.each([+ '2026-2-01',+ '2026-02-01T00:00:00Z',+ '2026-02-01\n',+ '2100-02-29',+ '2026-04-31',+ '2026-00-01',+ '2026-01-00',+ '0000-01-01',+ '10000-01-01',+ ])('rejects the invalid or noncanonical date %s', (value) => {+ expect(() => parseDatePickerDateOrThrow(value)).toThrow(+ DatePickerException,+ );+ });+});diff --git a/packages/twenty-ui/src/components/input/DatePicker/internal/__tests__/validateDatePickerHighlightedRangeOrThrow.test.ts b/packages/twenty-ui/src/components/input/DatePicker/internal/__tests__/validateDatePickerHighlightedRangeOrThrow.test.tsnew file mode 100644index 00000000000..f240133d26f--- /dev/null+++ b/packages/twenty-ui/src/components/input/DatePicker/internal/__tests__/validateDatePickerHighlightedRangeOrThrow.test.ts@@ -0,0 +1,27 @@+import { describe, expect, it } from 'vitest';++import { DatePickerException } from '../DatePickerException';++import { validateDatePickerHighlightedRangeOrThrow } from '../validateDatePickerHighlightedRangeOrThrow';++describe('validateDatePickerHighlightedRangeOrThrow', () => {+ it.each([+ { start: '2026-10-07', end: '2026-10-09' },+ { start: '2026-10-07', end: '2026-10-07' },+ { start: '2026-12-31', end: '2027-01-01' },+ ])('accepts the inclusive range from $start to $end', (range) => {+ expect(() =>+ validateDatePickerHighlightedRangeOrThrow(range),+ ).not.toThrow();+ });++ it.each([+ { start: '2026-10-09', end: '2026-10-07' },+ { start: '2026-2-01', end: '2026-10-07' },+ { start: '2026-10-07', end: '2026-02-30' },+ ])('rejects the invalid range from $start to $end', (range) => {+ expect(() => validateDatePickerHighlightedRangeOrThrow(range)).toThrow(+ DatePickerException,+ );+ });+});diff --git a/packages/twenty-ui/src/components/input/DatePicker/internal/datePickerConstants.ts b/packages/twenty-ui/src/components/input/DatePicker/internal/datePickerConstants.tsnew file mode 100644index 00000000000..34bb6fcf8df--- /dev/null+++ b/packages/twenty-ui/src/components/input/DatePicker/internal/datePickerConstants.ts@@ -0,0 +1,6 @@+export const DATE_PICKER_CONSTANTS = {+ MIN_YEAR: 1,+ MAX_YEAR: 9999,+ DAYS_PER_WEEK: 7,+ MONTHS_PER_YEAR: 12,+} as const;diff --git a/packages/twenty-ui/src/components/input/DatePicker/internal/formatDatePickerLocalDate.ts b/packages/twenty-ui/src/components/input/DatePicker/internal/formatDatePickerLocalDate.tsnew file mode 100644index 00000000000..02b55f44b44--- /dev/null+++ b/packages/twenty-ui/src/components/input/DatePicker/internal/formatDatePickerLocalDate.ts@@ -0,0 +1,6 @@+export const formatDatePickerLocalDate = (date: Date): string =>+ [+ date.getFullYear().toString().padStart(4, '0'),+ (date.getMonth() + 1).toString().padStart(2, '0'),+ date.getDate().toString().padStart(2, '0'),+ ].join('-');diff --git a/packages/twenty-ui/src/components/input/DatePicker/internal/parseDatePickerDateOrThrow.ts b/packages/twenty-ui/src/components/input/DatePicker/internal/parseDatePickerDateOrThrow.tsnew file mode 100644index 00000000000..facb15f0622--- /dev/null+++ b/packages/twenty-ui/src/components/input/DatePicker/internal/parseDatePickerDateOrThrow.ts@@ -0,0 +1,47 @@+import { isDefined } from '@ui/utilities/utils/isDefined';+import { doNotTranslate } from '@ui/utilities/internal/doNotTranslate';++import { DatePickerException } from './DatePickerException';++import { DATE_PICKER_CONSTANTS } from './datePickerConstants';++const DATE_PICKER_DATE_PATTERN = /^(\d{4})-(\d{2})-(\d{2})$/;+const DATE_PICKER_DATE_STRING_LENGTH = 10;++export const parseDatePickerDateOrThrow = (value: string): Date => {+ const dateParts = value.match(DATE_PICKER_DATE_PATTERN);++ if (+ !isDefined(dateParts) ||+ value.length !== DATE_PICKER_DATE_STRING_LENGTH+ ) {+ throw new DatePickerException({+ message: doNotTranslate('Calendar dates must use the YYYY-MM-DD format.'),+ });+ }++ const [, yearString, monthString, dayString] = dateParts;+ const year = Number(yearString);+ const month = Number(monthString);+ const day = Number(dayString);+ const date = new Date(0);++ date.setUTCFullYear(year, month - 1, day);++ const isSupportedDate =+ year >= DATE_PICKER_CONSTANTS.MIN_YEAR &&+ year <= DATE_PICKER_CONSTANTS.MAX_YEAR &&+ date.getUTCFullYear() === year &&+ date.getUTCMonth() === month - 1 &&+ date.getUTCDate() === day;++ if (!isSupportedDate) {+ throw new DatePickerException({+ message: doNotTranslate(+ 'Calendar dates must be valid dates in years 0001 through 9999.',+ ),+ });+ }++ return date;+};diff --git a/packages/twenty-ui/src/components/input/DatePicker/internal/parseDatePickerLocalDateOrThrow.ts b/packages/twenty-ui/src/components/input/DatePicker/internal/parseDatePickerLocalDateOrThrow.tsnew file mode 100644index 00000000000..dd0765769e3--- /dev/null+++ b/packages/twenty-ui/src/components/input/DatePicker/internal/parseDatePickerLocalDateOrThrow.ts@@ -0,0 +1,14 @@+import { parseDatePickerDateOrThrow } from './parseDatePickerDateOrThrow';++export const parseDatePickerLocalDateOrThrow = (value: string): Date => {+ const parsedDate = parseDatePickerDateOrThrow(value);+ const localDate = new Date(0);+ localDate.setFullYear(+ parsedDate.getUTCFullYear(),+ parsedDate.getUTCMonth(),+ parsedDate.getUTCDate(),+ );+ localDate.setHours(0, 0, 0, 0);++ return localDate;+};diff --git a/packages/twenty-ui/src/components/input/DatePicker/internal/validateDatePickerHighlightedRangeOrThrow.ts b/packages/twenty-ui/src/components/input/DatePicker/internal/validateDatePickerHighlightedRangeOrThrow.tsnew file mode 100644index 00000000000..23f7baefe05--- /dev/null+++ b/packages/twenty-ui/src/components/input/DatePicker/internal/validateDatePickerHighlightedRangeOrThrow.ts@@ -0,0 +1,24 @@+import { doNotTranslate } from '@ui/utilities/internal/doNotTranslate';++import { DatePickerException } from './DatePickerException';++import { parseDatePickerDateOrThrow } from './parseDatePickerDateOrThrow';++export const validateDatePickerHighlightedRangeOrThrow = ({+ start,+ end,+}: {+ start: string;+ end: string;+}): void => {+ parseDatePickerDateOrThrow(start);+ parseDatePickerDateOrThrow(end);++ if (start > end) {+ throw new DatePickerException({+ message: doNotTranslate(+ 'Calendar highlighted ranges must end on or after their start date.',+ ),+ });+ }+};diff --git a/packages/twenty-ui/src/components/input/DatePicker/types/DatePickerHeaderProps.ts b/packages/twenty-ui/src/components/input/DatePicker/types/DatePickerHeaderProps.tsnew file mode 100644index 00000000000..62369d26dca--- /dev/null+++ b/packages/twenty-ui/src/components/input/DatePicker/types/DatePickerHeaderProps.ts@@ -0,0 +1,9 @@+export type DatePickerHeaderProps = {+ viewedMonth: string;+ onPreviousMonth: () => void;+ onNextMonth: () => void;+ onMonthChange: (month: number) => void;+ onYearChange: (year: number) => void;+ isPreviousMonthDisabled: boolean;+ isNextMonthDisabled: boolean;+};diff --git a/packages/twenty-ui/src/components/input/DatePicker/types/DatePickerProps.ts b/packages/twenty-ui/src/components/input/DatePicker/types/DatePickerProps.tsnew file mode 100644index 00000000000..1d40a294725--- /dev/null+++ b/packages/twenty-ui/src/components/input/DatePicker/types/DatePickerProps.ts@@ -0,0 +1,45 @@+import { type useRender } from '@base-ui/react/use-render';+import { type ReactNode } from 'react';++import { type DatePickerHeaderProps } from './DatePickerHeaderProps';++import { type SelectPortalProps } from '@ui/primitives/input/Select/types/SelectPortalProps';++export type DatePickerProps = Omit<+ useRender.ComponentProps<'div'>,+ 'children' | 'onChange' | 'defaultValue'+> & {+ value: string | null;+ onValueChange: (date: string) => void;+ onValueSelect?: (date: string) => void;+ viewedMonth: string;+ onViewedMonthChange: (month: string) => void;+ highlightedRange?: { start: string; end: string };+ readOnly?: boolean;+ isGridHidden?: boolean;+ weekStart: 0 | 1 | 2 | 3 | 4 | 5 | 6;+ locale: string;+ weekdayLabels?: readonly [+ string,+ string,+ string,+ string,+ string,+ string,+ string,+ ];+ previousMonthLabel: string;+ nextMonthLabel: string;+ monthLabel: string;+ yearLabel: string;+ portalContainer?: SelectPortalProps['container'];+ onNavigationOpenChange?: (args: {+ open: boolean;+ control: 'month' | 'year';+ }) => void;+ isDateUnavailable?: (date: string) => boolean;+ disabled?: boolean;+ isKeyboardNavigationDisabled?: boolean;+ loadingFallback?: ReactNode;+ renderHeader?: (props: DatePickerHeaderProps) => ReactNode;+};diff --git a/packages/twenty-ui/src/components/input/index.ts b/packages/twenty-ui/src/components/input/index.tsindex 43f28c8f5fc..133eeda572a 100644--- a/packages/twenty-ui/src/components/input/index.ts+++ b/packages/twenty-ui/src/components/input/index.ts@@ -22,6 +22,9 @@ export type { CurrencyPickerProps } from './CurrencyPicker/types/CurrencyPickerPexport type { CurrencyPickerRootProps } from './CurrencyPicker/types/CurrencyPickerRootProps';export type { CurrencyPickerState } from './CurrencyPicker/types/CurrencyPickerState';export type { CurrencyPickerTriggerProps } from './CurrencyPicker/types/CurrencyPickerTriggerProps';+export { DatePicker } from './DatePicker/DatePicker';+export type { DatePickerHeaderProps } from './DatePicker/types/DatePickerHeaderProps';+export type { DatePickerProps } from './DatePicker/types/DatePickerProps';export { EmojiPicker } from './EmojiPicker/EmojiPicker';export type { EmojiPickerProps } from './EmojiPicker/types/EmojiPickerProps';export { FormFieldRow } from './FormFieldRow/FormFieldRow';diff --git a/packages/twenty-ui/vite.config.ts b/packages/twenty-ui/vite.config.tsindex 076ab3e9f5d..ad7559c9832 100644--- a/packages/twenty-ui/vite.config.ts+++ b/packages/twenty-ui/vite.config.ts@@ -93,6 +93,7 @@ export default defineConfig(({ command }) => {// optimized chunk hash and 404s in-flight dynamic imports (vite 8 / rolldown).include: ['@base-ui/utils/store',+ 'react-datepicker','react','react-dom','react-dom/client',@@ -145,6 +146,7 @@ export default defineConfig(({ command }) => {},rollupOptions: {external: (id: string) =>+ id !== 'react-datepicker/dist/react-datepicker.css' &&externalDeps.some((dep) => id === dep || id.startsWith(dep + '/')),output: [{diff --git a/yarn.lock b/yarn.lockindex 4c5dd688b2e..f463cfeb018 100644--- a/yarn.lock+++ b/yarn.lock@@ -51398,6 +51398,7 @@ __metadata:postcss: "npm:^8.5.15"prettier: "npm:^3.1.1"react: "npm:^19.2.0"+ react-datepicker: "npm:^9.1.0"react-docgen-typescript: "npm:^2.2.2"react-dom: "npm:^19.2.0"sass: "npm:^1.83.0"