diff --git a/AGENTS.md b/AGENTS.md index 6e511fbc..c4c3ebce 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -75,6 +75,17 @@ headless/ solidtype-headless: the components Kobalte lacks, one and a header kept in view, rows reordered by a drag or the keys, and rows that hold rows, each row's cells and rows tokens it draws once read + calendar a month's grid of days to choose one date, several or + a range from, the locale's, moved through and paged + as React Stately's calendar is + date_field a date's segments, the locale's in its order and + calendar, each Kobalte's spin button, typed and stepped + as React Stately's date field edits them, of a date, a + date with a time or one in a zone, or two of them, a + range + date_picker a date field whose group's trigger opens a popover + of a calendar choosing its date or its range, a time + kept, as React Stately's pickers keep them color_picker one colour its parts share, as React Aria's: the colour components below read it, given no value of their own; it draws nothing diff --git a/CHANGES.md b/CHANGES.md index a5079816..3cafa844 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,11 +1,76 @@ # Changes -## Unreleased +## 0.13.0 (2026-11-22) - Breaking: the skill, `skills/solidtype`, is no longer installed. The documentation for an agent is `llms.txt` and every page in Markdown, in `$(opam var solidtype:doc)`, and the README's *With an agent* gives the line for a project's `AGENTS.md` that sends an agent there. +- `Time_field`'s clock is a provider's locale's, else `en-GB`'s, as a + `Date_field`'s is, never the browser's: a picker's time field and date + field now read one clock. +- HeroUI's `DateRangePicker`, `Date_range_picker`, composed as HeroUI's + is: a `Date_field.Group` of two `Date_field.Input`s given their `slot`, + `"start"` and `"end"`, a `Range_separator` between them, and a + `Range_calendar` in its `Popover`. Its range is told once both ends are + there, each end sent with a form by `start_name` and `end_name`, and it + is invalid with its end before its start. `Solidtype_headless.Date_field` + gains range roots, `Root_range` and its kinds, and + `Solidtype_headless.Date_picker` range pickers on them. +- HeroUI's `DatePicker`, `Date_picker`, composed as HeroUI's is: a + `Date_field.Group` whose `Date_picker.Trigger` opens a `Calendar` in a + `Date_picker.Popover`. Of a date, a date with a time, `Date_time`, or one + in a zone, `Zoned`; a day chosen keeps the value's time, and the + picker's state draws a time field in the popover. The calendar takes the + picker's date, range and state, and the focus as it opens. + `Solidtype_headless.Date_picker` is the picker itself, and a headless + `Calendar` inside one takes what it gives by `Calendar.Given`. +- HeroUI's `RangeCalendar`, `Range_calendar`, on Calendar's parts: a press + or Enter on a day begins a range, shown to the day hovered or focused, + and a second ends it; a drag chooses the days it crosses, and one from an + end of the range moves it; Escape lets a range begun go. A range begun + reaches no further than the nearest unavailable day unless + `allows_non_contiguous_ranges`, and `is_date_unavailable` is given its + first date. `Solidtype_headless.Calendar.Root_range` is the range itself. +- HeroUI's `Calendar`: a month's grid of days to choose a date from, + `Calendar.Multiple` for several, its locale's in its order, first day of + the week and calendar, day before month unless an `I18nProvider` names + another locale. The arrows move the focus, Page Up and Down a month, or a + year with Shift, Home and End to the week's or month's ends; Enter, Space + or a press choose. A month, `Weeks n` or `Days n` shown, several months + side by side by `offset`, a fixed `weeks_in_month`; `min_value`, + `max_value` and unavailable days, disabled, read-only and invalid; and + HeroUI's year picker. A press on a day it cannot choose focuses it, where + React's leaves its focus where it was. `Solidtype_headless.Calendar` is the + calendar itself, for another design system to dress. +- The headless `Date_field` and `Calendar` tell a reader in their locale's + words, React Aria's, unless `translations` are given. +- HeroUI's `Date_field`: a date's segments, its locale's in its order and + calendar -- `mm/dd/yyyy` in `en-US`, a Buddhist year in `th-TH` -- typed + into, stepped by the arrows, Page Up and Down, Home and End, and erased by + Backspace; told as soon as its segments make a date, a date that is none, + February 30, made one as focus leaves. A `CalendarDate`, or with + `Date_field.Date_time` a `CalendarDateTime` to a `granularity`, on a + 12- or 24-hour clock, or with `Date_field.Zoned` a `ZonedDateTime`, its + zone's name shown and its hour stepped by the zone's rules, each given back + as its kind and sent to a form whole. Invalid before `min_value`, after + `max_value` or on a day `is_date_unavailable` refuses, which a `Form` + refuses to submit; variants, prefix, suffix, an input container, disabled, + read-only and required. It is day before month, `dd/mm/yyyy`, whatever the + browser reads, unless an `I18nProvider` names another locale. + `Solidtype_headless.Date_field` is the field itself, for another design + system to dress, and `solidtype-headless` now depends on + `solidtype-internationalized-date`. +- `Types.ResolvedDateTimeFormatOptions`, in Kobalte's and + \@internationalized/date's bindings, reads what a formatter resolved to: its + calendar, its clock, each field's form. +- HeroUI's `Time_field.Group` and `Time_field.Input` are `aria-disabled` while + the field is disabled, as React Aria's group is. +- A virtualized table that resizes its columns, the headless `Table`'s, and so + HeroUI's `Table` and `Data_grid` given `allows_column_resize`, scrolls across + its columns itself and keeps its pinned columns in view, where it grew to its + columns' width, its container scrolled instead, and a pinned column scrolled + away with the rest. ## 0.12.0 (2026-11-20) diff --git a/agents/llms.txt b/agents/llms.txt index 1bd8758d..1cb7c288 100644 --- a/agents/llms.txt +++ b/agents/llms.txt @@ -107,6 +107,11 @@ Each component's page gives HeroUI's own examples in OCaml, and a table of its p - [Data Grid](pages/heroui/data-grid.md): A grid of records given as data, with sorting, selection, column resizing, pinned columns, drag and drop, virtualization and loading more, on HeroUI's Table. - [Table](pages/heroui/table.md): Tables display structured data in rows and columns with support for sorting, selection, column resizing, and infinite scrolling. - [TrendChip](pages/heroui/trend-chip.md): A chip that shows a change, its arrow and colour from its trend. +- [Calendar](pages/heroui/calendar.md): Composable date picker with month grid, navigation, and year picker support. +- [DateField](pages/heroui/date-field.md): Date input field with labels, descriptions, and validation. +- [DatePicker](pages/heroui/date-picker.md): Composable date picker built on React Aria DatePicker with DateField and Calendar composition parts. +- [DateRangePicker](pages/heroui/date-range-picker.md): Composable date range picker built on React Aria DateRangePicker with DateField and RangeCalendar composition parts. +- [RangeCalendar](pages/heroui/range-calendar.md): Composable date range picker with month grid, navigation, and year picker support. - [TimeField](pages/heroui/time-field.md): Time input field with labels, descriptions, and validation. - [Alert](pages/heroui/alert.md): Display important messages and notifications to users with status indicators. - [Meter](pages/heroui/meter.md): A meter represents a quantity within a known range, or a fractional value. diff --git a/agents/pages/heroui/calendar.md b/agents/pages/heroui/calendar.md new file mode 100644 index 00000000..ca54c98d --- /dev/null +++ b/agents/pages/heroui/calendar.md @@ -0,0 +1,1090 @@ +# Calendar + +Composable date picker with month grid, navigation, and year picker support. + +Its value is a `CalendarDate` of `solidtype-internationalized-date`, made by +`CalendarDate.make 2026 11 21`, `parse_date "2026-11-21"` or `today zone`; +several dates are `Calendar.Multiple`'s. + +Its weeks start on Monday and its days are written as `en-GB` writes them, +whatever the browser reads, unless an `I18n.I18nProvider` names another +locale. React's follows the browser. + +Original HeroUI documentation: [Calendar](https://heroui.com/en/docs/react/components/calendar). + +## Usage + +```ocaml title="calendar_usage.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar + +let make () = + + + + + + + + + (fun day -> + (Jsx.string (S.get day))) + + + (fun date -> ) + + + +``` + +## Parity + +The same HeroUI Calendar twice, under the same props: in solidtype on the +left, in React on the right. Below them, every attribute of the two calendars: +a marked row is one they disagree on. + +## Anatomy + +```ocaml + + + + + + + + + (fun day -> (Jsx.string (S.get day))) + + + (fun date -> ) + + + +``` + +## Examples + +### Disabled + +```ocaml title="calendar_disabled.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Description = Solidtype_heroui.Description + +let make () = +
+ + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + "Calendar is disabled" +
+``` + +### Read Only + +A press on a day of a read-only calendar focuses it, and the arrows move on +from it. + +```ocaml title="calendar_read_only.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Description = Solidtype_heroui.Description + +let make () = +
+ + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + "Calendar is read-only" +
+``` + +### Default Value + +```ocaml title="calendar_default_value.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate + +let make () = + + + + + + + + + (fun day -> + (Jsx.string (S.get day))) + + + (fun date -> ) + + + +``` + +### Year Picker + +`Calendar.Year_picker_trigger`, `Calendar.Year_picker_grid`, and their body +and cell parts provide an integrated year navigation pattern. + +```ocaml title="calendar_year_picker.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar + +let make () = + + + + + + + + + + + + (fun day -> + (Jsx.string (S.get day))) + + + (fun date -> ) + + + + + + +``` + +### Controlled + +Use controlled `value` and `focused_value` for external state coordination +and custom shortcuts. + +```ocaml title="calendar_controlled.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Button = Solidtype_heroui.Button +module Button_group = Solidtype_heroui.Button_group +module Calendar = Solidtype_heroui.Calendar +module Description = Solidtype_heroui.Description +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate + +let today () = D.today (D.get_local_time_zone ()) + +(* The start of the week holding [d], Monday first, as en-GB counts. *) +let start_of_week d = + Date.subtract d + (D.Types.DateDuration.make ~days:(D.get_day_of_week d "en-GB" ()) ()) + +let start_of_month d = Date.set d (D.Types.DateFields.make ~day:1 ()) + +let make () = + let value, set_value = S.create_signal None in + let focused, set_focused = S.create_signal (D.parse_date "2025-12-25") in + let choose d = + S.set set_value (Some d); + S.set set_focused d + in +
+ + + + + + S.set set_value (Some d)) + on_focus_change=(S.set set_focused)> + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + (Jsx.string + ("Selected date: " + ^ + match S.get value with + | Some d -> Date.to_string d () + | None -> "(none)")) + +
+ + + +
+
+``` + +### Min and Max Dates + +```ocaml title="calendar_min_max.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Description = Solidtype_heroui.Description + +let make () = + let now = D.today (D.get_local_time_zone ()) in + let max_date = Date.add now (D.Types.DateDuration.make ~months:3 ()) in +
+ + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + (Jsx.string + ("Select a date between today and " ^ Date.to_string max_date ())) + +
+``` + +### Unavailable Dates + +Use `is_date_unavailable` to block dates such as weekends, holidays, or +booked slots. A press on an unavailable day focuses it without choosing it. + +```ocaml title="calendar_unavailable.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Description = Solidtype_heroui.Description + +(* Saturdays and Sundays, as most of the world's weekend falls. *) +let is_date_unavailable date = D.is_weekend date "en-GB" + +let make () = +
+ + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + "Weekends are unavailable" +
+``` + +### Weeks in Month + +Set `weeks_in_month` to a fixed value, for example `6`, to keep the grid's +height as months change. + +```ocaml title="calendar_weeks_in_month.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module Description = Solidtype_heroui.Description + +let make () = +
+ + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + "Always shows 6 weeks per month to avoid layout shift when navigating" + +
+``` + +### Week View + +`` visible_duration=(Calendar.Weeks n) `` shows one or more weeks at a time, +and its buttons page by them; `` page_behavior=`single `` pages a week at a +time. Its grid is named by the days it shows. + +```ocaml title="calendar_week_view.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box +module Select = Solidtype_heroui.Select + +let options = + [| + ("1", "1 week"); + ("2", "2 weeks"); + ("3", "3 weeks"); + ("4", "4 weeks"); + ("5", "5 weeks"); + ("6", "6 weeks"); + ("8", "8 weeks"); + |] + +let make () = + let count, set_count = S.create_signal 1 in +
+ + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + +
+``` + +### Day View + +`` visible_duration=(Calendar.Days n) `` shows a run of days, and its buttons +page by them; `` page_behavior=`single `` pages a day at a time. + +```ocaml title="calendar_day_view.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box +module Select = Solidtype_heroui.Select + +let options = + [| + ("1", "1 day"); + ("5", "5 days"); + ("7", "7 days"); + ("8", "8 days"); + ("10", "10 days"); + ("14", "14 days"); + ("21", "21 days"); + |] + +let make () = + let count, set_count = S.create_signal 5 in +
+ + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + +
+``` + +### Multiple Selection + +`Calendar.Multiple` chooses several dates: its `value`, `default_value` and +`on_change` are arrays. + +```ocaml title="calendar_multiple.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Description = Solidtype_heroui.Description + +let make () = + let value, set_value = S.create_signal [||] in +
+ + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + (Jsx.string + (match Array.length (S.get value) with + | 0 -> "Select multiple dates" + | n -> string_of_int n ^ " date(s) selected")) + +
+``` + +### Focused Value + +`focused_value` and `on_focus_change` control which date is focused. + +```ocaml title="calendar_focused_value.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Description = Solidtype_heroui.Description +module Button = Solidtype_heroui.Button + +let make () = + let focused, set_focused = S.create_signal (D.parse_date "2025-06-15") in +
+ + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + (Jsx.string ("Focused: " ^ Date.to_string (S.get focused) ())) + +
+ + + +
+
+``` + +### Cell Indicators + +`Calendar.Cell`'s children are drawn of its state, and +`Calendar.Cell_indicator` marks a day. + +```ocaml title="calendar_indicators.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate + +let dates_with_events = [ 3; 7; 12; 15; 21; 28 ] + +let make () = + + + + + + + + + (fun day -> + (Jsx.string (S.get day))) + + + (fun date -> + + (fun (cell : Calendar.cell) -> + let d = S.get date in + Jsx.fragment + [| + Jsx.string (S.get cell.formatted_date); + (if + D.is_today d (D.get_local_time_zone ()) + || List.mem (Date.day d) dates_with_events + then + else Jsx.nothing); + |]) + ) + + + +``` + +### Custom Navigation Icons + +Children of `Calendar.Nav_button` replace the chevrons. + +```ocaml title="calendar_custom_icons.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar + +let make () = + + + + + + + + + + + + + + + + + (fun day -> + (Jsx.string (S.get day))) + + + (fun date -> ) + + + +``` + +### Multiple Months + +`visible_duration` and `offset` show several months side by side. + +```ocaml title="calendar_multiple_months.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar + +let make () = + +
+
+ + + +
+ + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + +
+
+ +
+ + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + +
+
+ +``` + +### Real-World Example + +```ocaml title="calendar_booking.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Button = Solidtype_heroui.Button + +let booked_dates = [ 5; 6; 12; 13; 14; 20 ] +let weekend date = D.is_weekend date "en-GB" + +let make () = + let selected, set_selected = S.create_signal None in + let is_date_unavailable date = + weekend date || List.mem (Date.day date) booked_dates + in +
+ S.set set_selected (Some d))> + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> + + (fun (cell : Calendar.cell) -> + let d = S.get date in + Jsx.fragment + [| + Jsx.string (S.get cell.formatted_date); + (if + (not (S.get cell.is_unavailable)) + && (not (weekend d)) + && List.mem (Date.day d) booked_dates + then + else Jsx.nothing); + |]) + ) + + + +
+
+ + "Has bookings" + + + "Weekend/Unavailable" + +
+ + (fun d -> + ) + +
+
+``` + +### International Calendars + +An `I18n.I18nProvider` locale with a calendar extension shows that calendar; +`on_change` gives a date in the calendar of the value given, else the +Gregorian. + +```ocaml title="calendar_international.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module I18n = Solidtype_kobalte.I18n + +let make () = + + + + + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + + + +``` + +## Customization + +### Tailwind CSS + +`class_` is added after HeroUI's classes. + +```ocaml title="calendar_tailwind.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar + +let make () = + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> + ) + + + +``` + +## Styling Reference + +HeroUI follows the [BEM](https://bem.info/en/methodology/) methodology to +ensure component variants and states are reusable and easy to customize. + +### CSS Classes + +- `.calendar` - Root container. +- `.calendar--week-view`, `.calendar--day-view` - A week's or a day's view. +- `.calendar__header` - Header row containing nav buttons and heading. +- `.calendar__heading` - Current month label. +- `.calendar__nav-button` - Previous/next navigation controls. +- `.calendar__grid` - Main day grid. +- `.calendar__grid-header` - Weekday header row wrapper. +- `.calendar__grid-body` - Date rows wrapper. +- `.calendar__header-cell` - Weekday header cell. +- `.calendar__cell` - Interactive day cell. +- `.calendar__cell-indicator` - Dot indicator inside a day cell. +- `.calendar-year-picker__trigger` - Year picker toggle button. +- `.calendar-year-picker__trigger-heading` - Heading text inside year picker trigger. +- `.calendar-year-picker__trigger-indicator` - Indicator icon inside year picker trigger. +- `.calendar-year-picker__year-grid` - Overlay grid of selectable years. +- `.calendar-year-picker__year-cell` - Individual year option. + +### Interactive States + +- **Selected**: `[data-selected="true"]` +- **Today**: `[data-today="true"]` +- **Unavailable**: `[data-unavailable="true"]` +- **Outside month**: `[data-outside-month="true"]` +- **Hovered**: `[data-hovered="true"]` +- **Pressed**: `[data-pressed="true"]` +- **Focus visible**: `[data-focus-visible="true"]` +- **Disabled**: `[data-disabled="true"]` + +## API Reference + +Each prop beside the name HeroUI's React component gives it. + +### Calendar + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `value` | `value` | `CalendarDate.t Js.Nullable.t` | | Controlled selected date; null controls it empty | +| `defaultValue` | `default_value` | `CalendarDate.t` | | Initial selected date (uncontrolled) | +| `onChange` | `on_change` | `CalendarDate.t -> unit` | | Called when a date is chosen | +| `selectionMode` | — | | | `Calendar.Multiple` chooses several dates | +| `focusedValue` | `focused_value` | `CalendarDate.t` | | Controlled focused date | +| `defaultFocusedValue` | `default_focused_value` | `CalendarDate.t` | its value, else today | Initial focused date | +| `onFocusChange` | `on_focus_change` | `CalendarDate.t -> unit` | | Called when focus moves to another date | +| `minValue` | `min_value` | `CalendarDate.t` | 1900-01-01 in its calendar | Earliest selectable date | +| `maxValue` | `max_value` | `CalendarDate.t` | 2099-12-31 in its calendar | Latest selectable date | +| `weeksInMonth` | `weeks_in_month` | `int` | the month's | The number of weeks in a month's grid | +| `isDateUnavailable` | `is_date_unavailable` | `CalendarDate.t -> bool` | | Marks dates as unavailable | +| `firstDayOfWeek` | `first_day_of_week` | `` [ `sun \| `mon \| `tue \| `wed \| `thu \| `fri \| `sat ] `` | the locale's | The first day of its weeks | +| `pageBehavior` | `page_behavior` | `` [ `visible \| `single ] `` | `` `visible `` | Whether paging moves by what is shown or by one unit | +| `selectionAlignment` | `selection_alignment` | `` [ `start \| `center \| `end_ ] `` | `` `center `` | Where the focused date stands in what is shown at first | +| `isDisabled` | `is_disabled` | `bool` | `false` | Disables interaction and selection | +| `isReadOnly` | `is_read_only` | `bool` | `false` | Days are focused but not chosen | +| `isInvalid` | `is_invalid` | `bool` | `false` | Marks the calendar as invalid | +| `visibleDuration` | `visible_duration` | `Calendar.duration` | `Months 1` | `Months n`, `Weeks n` or `Days n` | +| `defaultYearPickerOpen` | `default_year_picker_open` | `bool` | `false` | Initial open state of the year picker | +| `isYearPickerOpen` | `is_year_picker_open` | `bool` | | Controlled open state of the year picker | +| `onYearPickerOpenChange` | `on_year_picker_open_change` | `bool -> unit` | | Called when the year picker opens or closes | +| `aria-label` | `aria_label` | `string` | | Its name, beside the dates it shows | +| `className` | `class_` | `string` | | Added after HeroUI's classes | + +### Composition Parts + +| React | solidtype | Description | +|---|---|---| +| `Calendar.Header` | `Calendar.Header` | Header container for navigation and heading | +| `Calendar.Heading` | `Calendar.Heading` | The dates shown; `offset` and `format` | +| `Calendar.NavButton` | `Calendar.Nav_button` | `` slot=`previous `` or `` slot=`next `` | +| `Calendar.Grid` | `Calendar.Grid` | Day grid for one month; `offset` and `weekday_style` | +| `Calendar.GridHeader` | `Calendar.Grid_header` | Weekday header, a function of each day's name | +| `Calendar.GridBody` | `Calendar.Grid_body` | Date cells, a function of each date | +| `Calendar.HeaderCell` | `Calendar.Header_cell` | Weekday label cell | +| `Calendar.Cell` | `Calendar.Cell` | A day, its children drawn of its state | +| `Calendar.CellIndicator` | `Calendar.Cell_indicator` | A dot marking a day | +| `Calendar.YearPickerTrigger` | `Calendar.Year_picker_trigger` | Opens and closes the year picker | +| `Calendar.YearPickerTriggerHeading` | `Calendar.Year_picker_trigger_heading` | The month shown, in the trigger | +| `Calendar.YearPickerTriggerIndicator` | `Calendar.Year_picker_trigger_indicator` | The trigger's chevron | +| `Calendar.YearPickerGrid` | `Calendar.Year_picker_grid` | The years; `format` and `visible_years` | +| `Calendar.YearPickerGridBody` | `Calendar.Year_picker_grid_body` | The years' cells, or a function of each year | +| `Calendar.YearPickerCell` | `Calendar.Year_picker_cell` | A year | + +### Calendar.Cell's state + +| React | solidtype | Type | Description | +|---|---|---|---| +| `formattedDate` | `formatted_date` | `string S.accessor` | Its day of the month | +| `isSelected` | `is_selected` | `bool S.accessor` | Whether the date is chosen | +| `isUnavailable` | `is_unavailable` | `bool S.accessor` | Whether the date is unavailable | +| `isDisabled` | `is_disabled` | `bool S.accessor` | Whether the cell is disabled | +| `isOutsideMonth` | `is_outside_month` | `bool S.accessor` | Whether the date belongs to another month | +| `isToday` | `is_today` | `bool S.accessor` | Whether the date is today | diff --git a/agents/pages/heroui/coverage.md b/agents/pages/heroui/coverage.md index e4f444a6..b2d4463c 100644 --- a/agents/pages/heroui/coverage.md +++ b/agents/pages/heroui/coverage.md @@ -17,6 +17,7 @@ shows it beside the same component in React. | [Breadcrumbs](breadcrumbs.md) | ported: the last item the page, prerendered so too, disabled whole or an item at a time, a separator of its own, an item's press told by its id | | [Button](button.md) | ported: variants, sizes, full width, icon only, disabled | | [ButtonGroup](button-group.md) | ported: variants, sizes, orientations, full width, disabled, separator | +| [Calendar](calendar.md) | ported: one date or several, controlled or kept, the focused date controlled or kept, in the locale's order, first day and calendar; moved through by the keys and paged by its buttons, a page or a unit at a time; a month, weeks or days shown, several months side by side, a fixed number of weeks; min and max and unavailable days, disabled, read-only, invalid; its year picker; cell indicators, custom navigation icons | | [Card](card.md) | ported: variants, header, title, description, content, footer, as a surface | | [Checkbox](checkbox.md) | ported: variants, selected, indeterminate, disabled, invalid, interaction state | | [CheckboxGroup](checkbox-group.md) | ported: values controlled or kept, variants, disabled, invalid, read-only, required, its label and descriptions | @@ -29,6 +30,9 @@ shows it beside the same component in React. | [ColorSwatch](color-swatch.md) | ported: sizes, shapes, a colour less than opaque over a checkerboard, its name given or Kobalte's, style | | [ColorSwatchPicker](color-swatch-picker.md) | ported: a palette chosen from by a press or the keys, in a grid by where each swatch is or a stack, value controlled or kept, sizes, variants, layouts, disabled swatches, the checkmark or an indicator given, black over a light colour | | [ComboBox](combo-box.md) | ported: one or many chosen, controlled or kept, its text controlled or kept, filtered as typed or by a filter given, opened by focus, typing or only its trigger, custom values, its list a ListBox, sections, disabled options, its value listed, variants, full width, disabled, read-only, label, description and error, a form sent its ids or its text, its list's empty state while nothing matches | +| [DateField](date-field.md) | ported: a date, a date with a time and one in a zone, each given back as its kind, in the reader's locale's order and calendar; typed, stepped by the keys, erased, a date that is none made one as focus leaves; value controlled or kept, placeholder, granularity, hour cycle, leading zeros, its zone shown or hidden, min and max and unavailable days, variants, full width, prefix and suffix, disabled, read-only, required, invalid, label, description and error, a form sent its value whole | +| [DatePicker](date-picker.md) | ported: a date field whose trigger opens a calendar in a popover, of a date, a date with a time or one in a zone, the time kept as a day is chosen and drawn in the popover from its state; controlled or kept, open controlled or kept, closed on a day chosen unless not; disabled, read-only, required, invalid and validated in a form; a custom indicator, render functions, international calendars | +| [DateRangePicker](date-range-picker.md) | ported: a date field's group of a start and an end, whose trigger opens a range calendar in a popover, of dates, dates with times or ones in a zone, the times kept and drawn in the popover from its state; a range told once both ends are there, invalid with its end before its start; controlled or kept, open controlled or kept; disabled, read-only, required, invalid and validated in a form, each end sent by its name; a custom indicator, render functions, international calendars | | [Description](description.md) | ported: standalone, and a radio group's, a radio's or a text field's | | [Disclosure](disclosure.md) | ported: expanded controlled or kept, disabled, its own trigger or a button given its slot, indicator, content animated by its height and found by find in page | | [DisclosureGroup](disclosure-group.md) | ported: one or several expanded, controlled or kept, disabled with a disclosure's own, navigation by previous and next | @@ -53,6 +57,7 @@ shows it beside the same component in React. | [ProgressBar](progress-bar.md) | ported: value within a range, indeterminate, colors, sizes, output, format options | | [ProgressCircle](progress-circle.md) | ported: value within a range, indeterminate, colors, sizes, format options, a circle of any size its arc measured on its own radius | | [Radio Group](radio-group.md) | ported: variants, orientations, controlled, disabled, invalid, descriptions, interaction state | +| [RangeCalendar](range-calendar.md) | ported: a range begun by a press or Enter and shown to the day hovered or focused, ended by a second; chosen by a drag, an end moved by one; let go by Escape, and ended as `commit_behavior` says; reaching no further than an unavailable day unless non-contiguous, its predicate given the range's anchor; controlled or kept, min and max, disabled, read-only, invalid; weeks or days shown, several months side by side; its year picker; cell indicators | | [ScrollShadow](scroll-shadow.md) | ported: orientations, sizes, offset, visibility given or measured, hidden scrollbar | | [SearchField](search-field.md) | ported: query controlled or kept, cleared by Escape or its button, submitted by Enter, variants, disabled, invalid | | [Select](select.md) | ported: one or many chosen, controlled or kept, its list a ListBox, placeholder, value drawn as the option or by a function, clear button and Backspace, variants, full width, disabled, disabled options, sections, open controlled or kept, label, description and error, a form's errors; required, its error the application's to show, as a text field's | @@ -77,13 +82,13 @@ shows it beside the same component in React. ## Not yet ported -These 7 components of HeroUI 3.2 are not ported yet; each name links to +These 2 components of HeroUI 3.2 are not ported yet; each name links to HeroUI's own page. What a ported component does not do yet is in its row above and on its page. | Group | Components | |---|---| -| Not yet ported | [Calendar](https://heroui.com/en/docs/react/components/calendar), [DateField](https://heroui.com/en/docs/react/components/date-field), [DatePicker](https://heroui.com/en/docs/react/components/date-picker), [DateRangePicker](https://heroui.com/en/docs/react/components/date-range-picker), [InputOTP](https://heroui.com/en/docs/react/components/input-otp), [RangeCalendar](https://heroui.com/en/docs/react/components/range-calendar), [Toolbar](https://heroui.com/en/docs/react/components/toolbar) | +| Not yet ported | [InputOTP](https://heroui.com/en/docs/react/components/input-otp), [Toolbar](https://heroui.com/en/docs/react/components/toolbar) | ## Beyond HeroUI's set diff --git a/agents/pages/heroui/date-field.md b/agents/pages/heroui/date-field.md new file mode 100644 index 00000000..1149da38 --- /dev/null +++ b/agents/pages/heroui/date-field.md @@ -0,0 +1,819 @@ +# DateField + +Date input field with labels, descriptions, and validation. + +Its value is a `CalendarDate` of `solidtype-internationalized-date`, made by +`CalendarDate.make 2026 11 21`, `parse_date "2026-11-21"` or `today zone`; a +date with a time is `Date_field.Date_time`'s, and one in a zone +`Date_field.Zoned`'s. + +Its segments are day before month, `dd/mm/yyyy`, whatever the browser reads, +unless an `I18n.I18nProvider` names another locale: +`` gives `mm/dd/yyyy`. React's follows the +browser. + +Original HeroUI documentation: [DateField](https://heroui.com/en/docs/react/components/date-field). + +## Usage + +```ocaml title="date_field_usage.mlx" +module S = Solidtype.Solid +module Label = Solidtype_heroui.Label +module Date_field = Solidtype_heroui.Date_field + +let make () = + + + + + (fun segment -> ) + + + +``` + +## Parity + +The same HeroUI DateField twice, under the same props: in solidtype on the +left, in React on the right. Below them, every attribute of the two fields: a +marked row is one they disagree on. + +## Anatomy + +```ocaml + + +``` + +`Date_field` combines label, date input, description, and error into a single +accessible component. + +## Examples + +### With Icons + +Add prefix or suffix icons to enhance the date field. + +```ocaml title="date_field_prefix_icon.mlx" +module S = Solidtype.Solid +module Label = Solidtype_heroui.Label +module Date_field = Solidtype_heroui.Date_field +module Gravity = Solidtype_gravity_icons + +let make () = + + + + + + + + (fun segment -> ) + + + +``` + +```ocaml title="date_field_suffix_icon.mlx" +module S = Solidtype.Solid +module Label = Solidtype_heroui.Label +module Date_field = Solidtype_heroui.Date_field +module Gravity = Solidtype_gravity_icons + +let make () = + + + + + (fun segment -> ) + + + + + + +``` + +```ocaml title="date_field_prefix_suffix.mlx" +module S = Solidtype.Solid +module Description = Solidtype_heroui.Description +module Label = Solidtype_heroui.Label +module Date_field = Solidtype_heroui.Date_field +module Gravity = Solidtype_gravity_icons + +let make () = + + + + + + + + (fun segment -> ) + + + + + + "Enter a date" + +``` + +### Variants + +`Date_field.Group` takes two variants: `` `primary ``, the default, with a +shadow, and `` `secondary ``, a lower emphasis without one, for a surface. + +```ocaml title="date_field_variants.mlx" +module S = Solidtype.Solid +module Label = Solidtype_heroui.Label +module Date_field = Solidtype_heroui.Date_field + +let make () = +
+ + + + + (fun segment -> ) + + + + + + + + (fun segment -> ) + + + +
+``` + +### In Surface + +When used inside a [Surface](surface.md) component, use +`` variant=`secondary `` on `Date_field.Group` to apply the lower emphasis +variant suitable for surface backgrounds. + +```ocaml title="date_field_surface.mlx" +module S = Solidtype.Solid +module Description = Solidtype_heroui.Description +module Surface = Solidtype_heroui.Surface +module Label = Solidtype_heroui.Label +module Date_field = Solidtype_heroui.Date_field +module Gravity = Solidtype_gravity_icons + +let make () = + + + + + + (fun segment -> ) + + + "Enter a date" + + + + + + + + + (fun segment -> ) + + + "Enter a date for your appointment" + + +``` + +### With Description + +```ocaml title="date_field_description.mlx" +module S = Solidtype.Solid +module Description = Solidtype_heroui.Description +module Label = Solidtype_heroui.Label +module Date_field = Solidtype_heroui.Date_field + +let make () = +
+ + + + + (fun segment -> ) + + + "Enter your date of birth" + + + + + + (fun segment -> ) + + + "Enter a date for your appointment" + +
+``` + +### Required Field + +```ocaml title="date_field_required.mlx" +module S = Solidtype.Solid +module Description = Solidtype_heroui.Description +module Label = Solidtype_heroui.Label +module Date_field = Solidtype_heroui.Date_field + +let make () = +
+ + + + + (fun segment -> ) + + + + + + + + (fun segment -> ) + + + "Required field" + +
+``` + +### Disabled State + +```ocaml title="date_field_disabled.mlx" +module S = Solidtype.Solid +module Description = Solidtype_heroui.Description +module D = Solidtype_internationalized_date +module Label = Solidtype_heroui.Label +module Date_field = Solidtype_heroui.Date_field + +let make () = +
+ + + + + (fun segment -> ) + + + "This date field is disabled" + + + + + + (fun segment -> ) + + + "This date field is disabled" + +
+``` + +### Full Width + +```ocaml title="date_field_full_width.mlx" +module S = Solidtype.Solid +module Label = Solidtype_heroui.Label +module Date_field = Solidtype_heroui.Date_field +module Gravity = Solidtype_gravity_icons + +let make () = +
+ + + + + (fun segment -> ) + + + + + + + + + + + (fun segment -> ) + + + + + + +
+``` + +### Validation + +Use `is_invalid` together with `Field_error` to surface validation messages. + +```ocaml title="date_field_invalid.mlx" +module S = Solidtype.Solid +module Field_error = Solidtype_heroui.Field_error +module Label = Solidtype_heroui.Label +module Date_field = Solidtype_heroui.Date_field + +let make () = +
+ + + + + (fun segment -> ) + + + "Please enter a valid date" + + + + + + (fun segment -> ) + + + "Date must be in the future" + +
+``` + +### Granularity + +`granularity` is the smallest unit a field with a time shows, `` `minute `` by +default; `` `day `` shows the date alone. + +```ocaml title="date_field_granularity.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box +module Select = Solidtype_heroui.Select +module Tooltip = Solidtype_heroui.Tooltip +module Date_field = Solidtype_heroui.Date_field +module D = Solidtype_internationalized_date +module Gravity = Solidtype_gravity_icons + +let granularities = + [| + (`day, "day", "Day"); + (`hour, "hour", "Hour"); + (`minute, "minute", "Minute"); + (`second, "second", "Second"); + |] + +let make () = + let granularity, set_granularity = S.create_signal `day in + let id () = + match S.get granularity with + | `day -> "day" + | `hour -> "hour" + | `minute -> "minute" + | `second -> "second" + in +
+ + + + + (fun segment -> ) + + + +
+
+ + + + + + +

+ "Determines the smallest unit displayed in the date picker. By \ + default, this is \"day\" for dates, and \"minute\" for times." +

+
+
+
+ +
+
+``` + +### Controlled + +Control the value to synchronize with other components or state management. + +```ocaml title="date_field_controlled.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Button = Solidtype_heroui.Button +module Description = Solidtype_heroui.Description +module Label = Solidtype_heroui.Label +module Date_field = Solidtype_heroui.Date_field +module D = Solidtype_internationalized_date + +let make () = + let value, set_value = S.create_signal None in +
+ + + + + (fun segment -> ) + + + + (Jsx.string + ("Current value: " + ^ + match S.get value with + | Some d -> D.Types.CalendarDate.to_string d () + | None -> "(empty)")) + + +
+ + +
+
+``` + +### Times and Zones + +`Date_field.Date_time` and `Date_field.Zoned` edit a `CalendarDateTime` or a +`ZonedDateTime`, and give back the same kind. A zoned field needs a +`placeholder_value`, the zone a date typed while it is empty is in; it shows +the zone's name after the time, and its hour steps through an hour its clocks +repeat. The second field below is in Kyiv on the night its clocks go back. + +```ocaml title="date_field_zoned.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Description = Solidtype_heroui.Description +module Label = Solidtype_heroui.Label +module Date_field = Solidtype_heroui.Date_field +module D = Solidtype_internationalized_date + +let kyiv at = D.parse_zoned_date_time (at ^ "[Europe/Kyiv]") () + +let make () = + let meeting, set_meeting = S.create_signal (Some (kyiv "2026-10-25T02:30")) in +
+ + + + + (fun segment -> ) + + + + + + + + (fun segment -> ) + + + + (Jsx.string + (match S.get meeting with + | Some m -> D.Types.ZonedDateTime.to_string m () + | None -> "(empty)")) + + +
+``` + +### Form Example + +Complete form example with validation and submission handling. The button has +no pending state while the date is sent. + +```ocaml title="date_field_form.mlx" +module S = Solidtype.Solid +module Show = Solidtype.Show +module Button = Solidtype_heroui.Button +module Description = Solidtype_heroui.Description +module Field_error = Solidtype_heroui.Field_error +module Form = Solidtype_heroui.Form +module Label = Solidtype_heroui.Label +module Date_field = Solidtype_heroui.Date_field +module D = Solidtype_internationalized_date +module Gravity = Solidtype_gravity_icons + +external prevent_default : Dom.event -> unit = "preventDefault" [@@mel.send] + +let make () = + let value, set_value = S.create_signal None in + let is_submitting, set_is_submitting = S.create_signal false in + let today = D.today (D.get_local_time_zone ()) in + let is_invalid () = + match S.get value with + | Some d -> D.Types.CalendarDate.compare d today < 0. + | None -> false + in + let handle_submit e = + prevent_default e; + match S.get value with + | Some d when not (is_invalid ()) -> + S.set set_is_submitting true; + (* Simulate API call *) + ignore + (Js.Global.setTimeout + ~f:(fun () -> + Js.log2 "Date submitted:" d; + S.set set_value None; + S.set set_is_submitting false) + 1500 + : Js.Global.timeoutId) + | Some _ | None -> () + in +
+ + + + + + + + (fun segment -> ) + + + "Enter a date from today onwards")> + "Date must be today or in the future" + + + +
+``` + +### With Validation + +A field is invalid while its value is before `min_value`, after `max_value` or +a day `is_date_unavailable` refuses, and while the application says so by +`is_invalid`. + +```ocaml title="date_field_with_validation.mlx" +module S = Solidtype.Solid +module Show = Solidtype.Show +module Description = Solidtype_heroui.Description +module Field_error = Solidtype_heroui.Field_error +module Label = Solidtype_heroui.Label +module Date_field = Solidtype_heroui.Date_field +module D = Solidtype_internationalized_date + +let make () = + let value, set_value = S.create_signal None in + let today = D.today (D.get_local_time_zone ()) in + let is_invalid () = + match S.get value with + | Some d -> D.Types.CalendarDate.compare d today < 0. + | None -> false + in +
+ + + + + (fun segment -> ) + + + "Enter a date from today onwards")> + "Date must be today or in the future" + + +
+``` + +### Render Function + +`as_` overrides the default DOM element with a function of its props and its +state, as [Composition](composition.md#custom-dom-element) +shows. + +## Customization + +### Tailwind CSS + +`class_` is added after HeroUI's classes. + +```ocaml title="date_field_tailwind.mlx" +module S = Solidtype.Solid +module Label = Solidtype_heroui.Label +module Date_field = Solidtype_heroui.Date_field + +let make () = + + + + + (fun segment -> ) + + + +``` + +## Styling Reference + +HeroUI follows the [BEM](https://bem.info/en/methodology/) methodology to +ensure component variants and states are reusable and easy to customize. + +### CSS Classes + +- `.date-field` - Root container with minimal styling (`flex flex-col gap-1`) +- `.date-field--full-width` - Full width modifier +- `.date-input-group` - Root container styling of `Date_field.Group` +- `.date-input-group--primary`, `.date-input-group--secondary` - Variants +- `.date-input-group__input` - Input wrapper styling +- `.date-input-group__input-container` - Scrollable container for grouping + multiple inputs +- `.date-input-group__segment` - Individual date segment styling +- `.date-input-group__prefix` - Prefix element styling +- `.date-input-group__suffix` - Suffix element styling + +Child components ([Label](label.md), +[Description](description.md), +[FieldError](field-error.md)) have their own CSS classes and +styling. See their respective documentation for customization options. + +### Interactive States + +DateField automatically manages these data attributes based on its state: + +- **Invalid**: `[data-invalid="true"]` - Automatically hides the description + slot when invalid +- **Required**: `[data-required="true"]` - Applied when `is_required` is true +- **Disabled**: `[data-disabled="true"]` - Applied when `is_disabled` is true +- **Read-only**: `[data-readonly="true"]` - Applied when `is_read_only` is true + +`Date_field.Group`'s states: + +- **Hover**: `[data-hovered="true"]` +- **Focus Within**: `[data-focus-within="true"]` +- **Focus Visible**: `[data-focus-visible="true"]` +- **Invalid**: `[data-invalid="true"]` +- **Disabled**: `[data-disabled="true"]` +- **Segment Focus**: `[data-focused="true"]` on segment elements +- **Segment Placeholder**: `[data-placeholder="true"]` on segment elements +- **Segment Type**: `[data-type="literal"]`, and a zoned field's zone + `[data-type="timeZoneName"]` + +## API Reference + +Each prop beside the name HeroUI's React component gives it. + +### DateField + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `value` | `value` | `CalendarDate.t Js.Nullable.t` | | Current value (controlled); null controls it empty | +| `defaultValue` | `default_value` | `CalendarDate.t` | | Default value (uncontrolled) | +| `onChange` | `on_change` | `CalendarDate.t option -> unit` | | Called as soon as its segments make a date other than its value, and with `None` once every segment is erased | +| `placeholderValue` | `placeholder_value` | `CalendarDate.t` | today | What an arrow key steps an empty segment from | +| `minValue` | `min_value` | `CalendarDate.t` | | The earliest date it is valid at | +| `maxValue` | `max_value` | `CalendarDate.t` | | The latest date it is valid at | +| `isDateUnavailable` | `is_date_unavailable` | `CalendarDate.t -> bool` | | A day it is invalid at | +| `shouldForceLeadingZeros` | `should_force_leading_zeros` | `bool` | the locale's | Whether to always show leading zeros in the month, day and hour | +| `isRequired` | `is_required` | `bool` | `false` | Whether user input is required before form submission | +| `isInvalid` | `is_invalid` | `bool` | `false` | Whether the value is invalid | +| `isDisabled` | `is_disabled` | `bool` | `false` | Whether the input is disabled | +| `isReadOnly` | `is_read_only` | `bool` | `false` | Whether the input can be selected but not changed | +| `name` | `name` | `string` | | Its name in a form, which is sent its value as `@internationalized/date` writes it, `2026-11-21` | +| `autoFocus` | `auto_focus` | `bool` | `false` | Whether its first segment is focused as it is drawn | +| `aria-label` | `aria_label` | `string` | | Accessibility label when no visible label is present | +| `fullWidth` | `full_width` | `bool` | `false` | Whether the date field should take full width of its container | +| `className` | `class_` | `string` | | Added after HeroUI's classes | +| `onBlur` | `on_blur` | `Dom.focusEvent -> unit` | | Called once focus leaves it for an element outside it | +| `validate`, `validationBehavior` | — | | | A field validates nothing beyond its range: it is invalid as the application says, and out of its range at once | +| `granularity`, `hourCycle`, `hideTimeZone` | — | | | A date alone has no time: `Date_field.Date_time`'s and `Date_field.Zoned`'s | + +### DateField.Date_time, DateField.Zoned + +A DateField whose value is a `CalendarDateTime` or a `ZonedDateTime`. Each +takes DateField's props, its value and range of its own kind, and: + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `granularity` | `granularity` | `` [ `day \| `hour \| `minute \| `second ] `` | `` `minute `` | The smallest unit displayed, a time to the minute even while it is empty, where React's empty field with no placeholder shows a date alone | +| `hourCycle` | `hour_cycle` | `` [ `h12 \| `h24 ] `` | the locale's | Whether to display time in 12 or 24 hour format | +| `placeholderValue` | `placeholder_value` | `CalendarDateTime.t`, `ZonedDateTime.t` | today at midnight; required for a zoned field | What a date typed while it is empty is put on, a zoned one's zone too | +| `hideTimeZone` | `hide_time_zone` | `bool` | `false` | Whether a zoned field hides its zone's name | +| `name` | `name` | `string` | | Its name in a form, which is sent its value whole, `2026-11-21T09:30:00+02:00[Europe/Kyiv]` | + +### DateField.Group + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `variant` | `variant` | `` [ `primary \| `secondary ] `` | `` `primary `` | Visual variant of the component. `` `primary `` is the default style with shadow. `` `secondary `` is a lower emphasis variant without shadow, suitable for use in surfaces | +| `fullWidth` | `full_width` | `bool` | its field's | Whether it takes its container's width | +| `className` | `class_` | `string` | | Added after HeroUI's classes | + +### DateField.Input, DateField.Segment, DateField.InputContainer, DateField.Prefix, DateField.Suffix + +Each takes `class_`, added after HeroUI's class; the input, a function of each +segment, rendering it; a segment, the `segment` it is; an input container, a +prefix and a suffix, their `children`. diff --git a/agents/pages/heroui/date-picker.md b/agents/pages/heroui/date-picker.md new file mode 100644 index 00000000..d152a71e --- /dev/null +++ b/agents/pages/heroui/date-picker.md @@ -0,0 +1,917 @@ +# DatePicker + +Composable date picker built on React Aria DatePicker with DateField and Calendar composition parts. + +Its value is a `CalendarDate` of `solidtype-internationalized-date`, as a +[DateField](date-field.md)'s is; a date with a time is +`Date_picker.Date_time`'s, and one in a zone `Date_picker.Zoned`'s. The +[Calendar](calendar.md) in its popover takes its date, its +range and its state. + +Its segments are in `en-GB`'s order, day before month, whatever the browser +reads, unless an `I18n.I18nProvider` names another locale. React's follows +the browser. + +Original HeroUI documentation: [DatePicker](https://heroui.com/en/docs/react/components/date-picker). + +## Usage + +```ocaml title="date_picker_usage.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module Date_field = Solidtype_heroui.Date_field +module Date_picker = Solidtype_heroui.Date_picker +module Label = Solidtype_heroui.Label + +let make () = + + + + + (fun segment -> ) + + + + + + + + + + + + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + + + + +``` + +## Parity + +The same HeroUI DatePicker twice, under the same props: in solidtype on the +left, in React on the right. Below them, every attribute of the two pickers: +a marked row is one they disagree on. + +## Anatomy + +`Date_picker` is composed as HeroUI's is: a `Date_field.Group` of the field's +input, the trigger in its `Date_field.Suffix`, and a `Calendar` in the +popover. + +```ocaml + + +``` + +## Examples + +### Disabled + +```ocaml title="date_picker_disabled.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module Date_field = Solidtype_heroui.Date_field +module Date_picker = Solidtype_heroui.Date_picker +module Label = Solidtype_heroui.Label +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Description = Solidtype_heroui.Description + +let make () = + + + + + (fun segment -> ) + + + + + + + + "This date picker is disabled." + + + + + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + + + + +``` + +### Controlled + +```ocaml title="date_picker_controlled.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module Date_field = Solidtype_heroui.Date_field +module Date_picker = Solidtype_heroui.Date_picker +module Label = Solidtype_heroui.Label +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Description = Solidtype_heroui.Description +module Button = Solidtype_heroui.Button + +let make () = + let value, set_value = + S.create_signal (Some (D.today (D.get_local_time_zone ()))) + in +
+ + + + + (fun segment -> ) + + + + + + + + + + + + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + + + + + + (Jsx.string + ("Current value: " + ^ + match S.get value with + | Some d -> Date.to_string d () + | None -> "(empty)")) + +
+ + +
+
+``` + +### Validation + +```ocaml title="date_picker_validation.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module Date_field = Solidtype_heroui.Date_field +module Date_picker = Solidtype_heroui.Date_picker +module Label = Solidtype_heroui.Label +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Field_error = Solidtype_heroui.Field_error + +let make () = + let value, set_value = S.create_signal None in + let current = D.today (D.get_local_time_zone ()) in + let is_invalid () = + match S.get value with + | Some v -> Date.compare v current < 0. + | None -> false + in + + + + + (fun segment -> ) + + + + + + + + "Date must be today or in the future." + + + + + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + + + + +``` + +### Format Options + +Control how a picker's value is shown with `granularity`, `hour_cycle`, +`hide_time_zone` and `should_force_leading_zeros`. Its children may be a +function of its state, whose `state.time_value` and `state.set_time_value` +draw a `Time_field` in the popover. + +```ocaml title="date_picker_format_options.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module Date_field = Solidtype_heroui.Date_field +module Date_picker = Solidtype_heroui.Date_picker +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box +module Select = Solidtype_heroui.Select +module Switch = Solidtype_heroui.Switch +module Time_field = Solidtype_heroui.Time_field +module D = Solidtype_internationalized_date + +type granularity = [ `day | `hour | `minute | `second ] + +let granularities : (string * string * granularity) array = + [| + ("day", "Day", `day); + ("hour", "Hour", `hour); + ("minute", "Minute", `minute); + ("second", "Second", `second); + |] + +let hour_cycles = [| ("12", "12-hour", `h12); ("24", "24-hour", `h24) |] + +let calendar () = + + + + + + + + + + + + (fun day -> + (Jsx.string (S.get day))) + + + (fun date -> ) + + + + + + + +let group () = + + + (fun segment -> ) + + + + + + + + +let choice ~label ~options ~value ~on_change = + + +let switch ~on ~set text = + + + (Jsx.string text) + + + +let make () = + let granularity, set_granularity = S.create_signal (`minute : granularity) in + let hour_cycle, set_hour_cycle = S.create_signal `h12 in + let hide_time_zone, set_hide_time_zone = S.create_signal false in + let leading_zeros, set_leading_zeros = S.create_signal false in + let zone = D.get_local_time_zone () in + let at_time () = + D.parse_zoned_date_time ("2026-02-03T08:45:00[" ^ zone ^ "]") () + in + (* The time field's granularity: the picker's, which has a time. *) + let time_granularity () = + match S.get granularity with + | `day -> None + | (`hour | `minute | `second) as g -> Some g + in +
+ (match S.get granularity with + | `day -> + + + (group ()) + + (calendar ()) + + + | `hour | `minute | `second -> + + (fun (picker : D.Types.ZonedDateTime.t Date_picker.state) -> + Jsx.fragment + [| + ; + group (); + + (calendar ()) +
+ + + + + (fun segment -> + ) + + + +
+
; + |]) +
) +
+
+ (choice ~label:"Granularity" + ~options:(Array.map (fun (id, name, _) -> (id, name)) granularities) + ~value:(fun () -> + match S.get granularity with + | `day -> "day" + | `hour -> "hour" + | `minute -> "minute" + | `second -> "second") + ~on_change:(fun id -> + Array.iter + (fun (i, _, g) -> + if String.equal i id then S.set set_granularity g) + granularities)) +
+
+ (choice ~label:"Hour cycle" + ~options:(Array.map (fun (id, name, _) -> (id, name)) hour_cycles) + ~value:(fun () -> + match S.get hour_cycle with `h12 -> "12" | `h24 -> "24") + ~on_change:(fun id -> + Array.iter + (fun (i, _, c) -> + if String.equal i id then S.set set_hour_cycle c) + hour_cycles)) +
+
+
+ (switch + ~on:(fun () -> S.get hide_time_zone) + ~set:(S.set set_hide_time_zone) "Hide timezone") + (switch + ~on:(fun () -> S.get leading_zeros) + ~set:(S.set set_leading_zeros) "Force leading zeros") +
+
+``` + +### Form Example + +```ocaml title="date_picker_form.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module Date_field = Solidtype_heroui.Date_field +module Date_picker = Solidtype_heroui.Date_picker +module Label = Solidtype_heroui.Label +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Description = Solidtype_heroui.Description +module Button = Solidtype_heroui.Button +module Field_error = Solidtype_heroui.Field_error +module Form = Solidtype_heroui.Form + +external set_timeout : (unit -> unit) -> int -> unit = "setTimeout" +external prevent_default : Dom.event -> unit = "preventDefault" [@@mel.send] + +let make () = + let value, set_value = S.create_signal None in + let submitting, set_submitting = S.create_signal false in + let current = D.today (D.get_local_time_zone ()) in + let is_invalid () = + match S.get value with + | Some v -> Date.compare v current < 0. + | None -> false + in + let submit e = + prevent_default e; + if Option.is_some (S.get value) && not (is_invalid ()) then ( + S.set set_submitting true; + set_timeout + (fun () -> + S.set set_value None; + S.set set_submitting false) + 1200) + in +
+ + + + + (fun segment -> ) + + + + + + + + (if is_invalid () then + "Date must be today or in the future." + else "Choose a valid appointment date.") + + + + + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + + + + + +
+``` + +### Custom Indicator + +`Date_picker.Trigger_indicator` draws HeroUI's calendar icon unless given +children. + +```ocaml title="date_picker_custom_indicator.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module Date_field = Solidtype_heroui.Date_field +module Date_picker = Solidtype_heroui.Date_picker +module Label = Solidtype_heroui.Label +module Description = Solidtype_heroui.Description +module Icons = Solidtype_gravity_icons + +let make () = + + + + + (fun segment -> ) + + + + + + + + + + + "Replace the default calendar icon by passing custom children." + + + + + + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + + + + +``` + +### Render Function + +```ocaml title="date_picker_render_function.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module Date_field = Solidtype_heroui.Date_field +module Date_picker = Solidtype_heroui.Date_picker +module Label = Solidtype_heroui.Label + +let make () = +
)> + +
)> +
)> + (fun segment -> + ) + segment=(S.get segment) + />) + + + + +
+
+``` + +### Validation + +```ocaml title="date_range_picker_validation.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Date_field = Solidtype_heroui.Date_field +module Date_range_picker = Solidtype_heroui.Date_range_picker +module Label = Solidtype_heroui.Label +module Range_calendar = Solidtype_heroui.Range_calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Field_error = Solidtype_heroui.Field_error + +let make () = + let value, set_value = S.create_signal None in + let current = D.today (D.get_local_time_zone ()) in + let is_invalid () = + match S.get value with + | Some ({ start; end_ } : Date.t Date_range_picker.range) -> + Date.compare start current < 0. || Date.compare end_ start < 0. + | None -> false + in + + + + + (fun segment -> ) + + + + (fun segment -> ) + + + + + + + + "Select a valid range starting today or later." + + + + + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + + + + +``` + +### Format Options + +Control how a range is shown with `granularity`, `hour_cycle`, +`hide_time_zone` and `should_force_leading_zeros`. Its children may be a +function of its state, whose `state.time_range` and `state.set_time` draw a +time field for each end in the popover. + +```ocaml title="date_range_picker_format_options.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar +module Date_field = Solidtype_heroui.Date_field +module Date_range_picker = Solidtype_heroui.Date_range_picker +module Separator = Solidtype_heroui.Separator +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box +module Select = Solidtype_heroui.Select +module Switch = Solidtype_heroui.Switch +module Time_field = Solidtype_heroui.Time_field +module D = Solidtype_internationalized_date + +type granularity = [ `day | `hour | `minute | `second ] + +let granularities : (string * string * granularity) array = + [| + ("day", "Day", `day); + ("hour", "Hour", `hour); + ("minute", "Minute", `minute); + ("second", "Second", `second); + |] + +let hour_cycles = [| ("12", "12-hour", `h12); ("24", "24-hour", `h24) |] + +let calendar () = + + + + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + + + +let group () = + + + (fun segment -> ) + + + + (fun segment -> ) + + + + + + + + +let choice ~label ~options ~value ~on_change = + + +let switch ~on ~set text = + + + (Jsx.string text) + + + +(* The range as a short date range, its times left out. *) +let selected (r : D.Types.ZonedDateTime.t Date_range_picker.range option) = + match r with + | Some { start; end_ } -> + Js.String.concat + ~other: + (D.Types.DateFormatter.format_range + (D.Types.DateFormatter.make "en-GB" + ~options: + (D.Types.DateTimeFormatOptions.make ~day:"numeric" + ~month:"short" ~year:"numeric" ()) + ()) + (D.Types.ZonedDateTime.to_date start ()) + (D.Types.ZonedDateTime.to_date end_ ())) + "Selected: " + | None -> "Selected: No date selected" + +let make () = + let granularity, set_granularity = S.create_signal (`minute : granularity) in + let hour_cycle, set_hour_cycle = S.create_signal `h12 in + let hide_time_zone, set_hide_time_zone = S.create_signal false in + let leading_zeros, set_leading_zeros = S.create_signal false in + let zone = D.get_local_time_zone () in + let at time = D.parse_zoned_date_time (time ^ "[" ^ zone ^ "]") () in + let time_granularity () = + match S.get granularity with + | `day -> None + | (`hour | `minute | `second) as g -> Some g + in + let time_field ~label ~name ~value ~set = +
+ + + + + (fun segment -> ) + + + +
+ in +
+ (match S.get granularity with + | `day -> + + + (group ()) + + (calendar ()) + + + | `hour | `minute | `second -> + + (fun (picker : D.Types.ZonedDateTime.t Date_range_picker.state) -> + Jsx.fragment + [| + ; + group (); + + (calendar ()) +
+ (time_field ~label:"Start Time" ~name:"startTime" + ~value:(fun () -> fst (S.get picker.state.time_range)) + ~set:(picker.state.set_time `start)) + (time_field ~label:"End Time" ~name:"endTime" + ~value:(fun () -> snd (S.get picker.state.time_range)) + ~set:(picker.state.set_time `end_)) +
+ + (Jsx.string (selected (S.get picker.state.range))) + +
; + |]) +
) + + +
+
+ (choice ~label:"Granularity" + ~options:(Array.map (fun (id, name, _) -> (id, name)) granularities) + ~value:(fun () -> + match S.get granularity with + | `day -> "day" + | `hour -> "hour" + | `minute -> "minute" + | `second -> "second") + ~on_change:(fun id -> + Array.iter + (fun (i, _, g) -> + if String.equal i id then S.set set_granularity g) + granularities)) +
+
+ (choice ~label:"Hour cycle" + ~options:(Array.map (fun (id, name, _) -> (id, name)) hour_cycles) + ~value:(fun () -> + match S.get hour_cycle with `h12 -> "12" | `h24 -> "24") + ~on_change:(fun id -> + Array.iter + (fun (i, _, c) -> + if String.equal i id then S.set set_hour_cycle c) + hour_cycles)) +
+
+
+ (switch + ~on:(fun () -> S.get hide_time_zone) + ~set:(S.set set_hide_time_zone) "Hide timezone") + (switch + ~on:(fun () -> S.get leading_zeros) + ~set:(S.set set_leading_zeros) "Force leading zeros") +
+
+``` + +### Form Example + +```ocaml title="date_range_picker_form.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Date_field = Solidtype_heroui.Date_field +module Date_range_picker = Solidtype_heroui.Date_range_picker +module Label = Solidtype_heroui.Label +module Range_calendar = Solidtype_heroui.Range_calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Description = Solidtype_heroui.Description +module Button = Solidtype_heroui.Button +module Field_error = Solidtype_heroui.Field_error +module Form = Solidtype_heroui.Form + +external set_timeout : (unit -> unit) -> int -> unit = "setTimeout" +external prevent_default : Dom.event -> unit = "preventDefault" [@@mel.send] + +let make () = + let value, set_value = S.create_signal None in + let submitting, set_submitting = S.create_signal false in + let current = D.today (D.get_local_time_zone ()) in + let is_invalid () = + match S.get value with + | Some ({ start; end_ } : Date.t Date_range_picker.range) -> + Date.compare start current < 0. || Date.compare end_ start < 0. + | None -> false + in + let submit e = + prevent_default e; + if Option.is_some (S.get value) && not (is_invalid ()) then ( + S.set set_submitting true; + set_timeout + (fun () -> + S.set set_value None; + S.set set_submitting false) + 1200) + in +
+ + + + + (fun segment -> ) + + + + (fun segment -> ) + + + + + + + + (if is_invalid () then + "Please choose a valid range in the future." + else + "Select your check-in and check-out dates.") + + + + + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + + + + + +
+``` + +### Custom Indicator + +`Date_range_picker.Trigger_indicator` draws HeroUI's calendar icon unless +given children. + +```ocaml title="date_range_picker_custom_indicator.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Date_field = Solidtype_heroui.Date_field +module Date_range_picker = Solidtype_heroui.Date_range_picker +module Label = Solidtype_heroui.Label +module Range_calendar = Solidtype_heroui.Range_calendar +module Description = Solidtype_heroui.Description +module Icons = Solidtype_gravity_icons + +let make () = + + + + + (fun segment -> ) + + + + (fun segment -> ) + + + + + + + + + + + "Replace the default calendar icon by passing custom children." + + + + + + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + + + + +``` + +### Render Function + +```ocaml title="date_range_picker_render_function.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Date_field = Solidtype_heroui.Date_field +module Date_range_picker = Solidtype_heroui.Date_range_picker +module Label = Solidtype_heroui.Label +module Range_calendar = Solidtype_heroui.Range_calendar + +let make () = +
)> + + + + (fun segment -> ) + + + + (fun segment -> ) + + + + + + + + + + + + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + + + + +``` + +### International Calendar + +An `I18n.I18nProvider` locale with a calendar extension shows that calendar; +`on_change` gives dates in the calendar of the value given, else the +Gregorian. + +```ocaml title="date_range_picker_international.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Date_field = Solidtype_heroui.Date_field +module Date_range_picker = Solidtype_heroui.Date_range_picker +module Label = Solidtype_heroui.Label +module Range_calendar = Solidtype_heroui.Range_calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module I18n = Solidtype_kobalte.I18n + +let days n = D.Types.DateDuration.make ~days:n () + +let from_today n = + let start = D.today (D.get_local_time_zone ()) in + { Date_range_picker.start; end_ = Date.add start (days n) } + +let make () = + + + + + + (fun segment -> ) + + + + (fun segment -> ) + + + + + + + + + + + + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + + + + + +``` + +## Customization + +### Tailwind CSS + +```ocaml title="date_range_picker_tailwind.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Date_field = Solidtype_heroui.Date_field +module Date_range_picker = Solidtype_heroui.Date_range_picker +module Label = Solidtype_heroui.Label +module Range_calendar = Solidtype_heroui.Range_calendar + +let make () = + + + + + (fun segment -> ) + + + + (fun segment -> ) + + + + + + + + + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + +``` + +## Styling Reference + +HeroUI follows the [BEM](https://bem.info/en/methodology/) methodology to +ensure component variants and states are reusable and easy to customize. + +### CSS Classes + +- `.date-range-picker` - Root wrapper. +- `.date-range-picker__trigger` - Trigger part that opens the popover. +- `.date-range-picker__trigger-indicator` - Default or custom indicator slot. +- `.date-range-picker__range-separator` - Separator between the start and end inputs. +- `.date-range-picker__popover` - Popover content wrapper. + +### Interactive States + +- **Open**: `[data-pressed="true"]` on the trigger, `[data-open="true"]` on the root. +- **Disabled**: `[data-disabled="true"]` on the trigger. +- **Focus visible**: `[data-focus-visible="true"]` on the trigger. +- **Hover**: `[data-hovered="true"]` on the trigger. + +## API Reference + +Each prop beside the name HeroUI's React component gives it. + +### Date_range_picker + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `value` | `value` | `CalendarDate.t range Js.Nullable.t` | | Controlled selected range; null controls it empty | +| `defaultValue` | `default_value` | `CalendarDate.t range` | | Default selected range in uncontrolled mode | +| `onChange` | `on_change` | `CalendarDate.t range option -> unit` | | Called when the selected range changes | +| `isOpen` | `is_open` | `bool` | | Controlled popover open state | +| `defaultOpen` | `default_open` | `bool` | `false` | Initial popover open state | +| `onOpenChange` | `on_open_change` | `bool -> unit` | | Called when the popover opens or closes | +| `shouldCloseOnSelect` | `should_close_on_select` | `bool` | `true` | Whether choosing a range closes the popover | +| `isDisabled` | `is_disabled` | `bool` | `false` | Disables range selection and the trigger | +| `isInvalid` | `is_invalid` | `bool` | `false` | Marks the field as invalid | +| `minValue` | `min_value` | `CalendarDate.t` | | Minimum selectable date | +| `maxValue` | `max_value` | `CalendarDate.t` | | Maximum selectable date | +| `startName` | `start_name` | `string` | | Name of the start date in form submission | +| `endName` | `end_name` | `string` | | Name of the end date in form submission | +| `children` | children | elements, or `state -> Jsx.element` | | Composed content or a function of its state | +| `render` | `as_` | `Html.Div.props -> state -> Jsx.element` | | Draws the root as another element | + +### Composition Parts + +| React | solidtype | Description | +|---|---|---| +| `DateRangePicker.Root` | `Date_range_picker` | Root date range picker container and state owner | +| `DateRangePicker.Trigger` | `Date_range_picker.Trigger` | Trigger button, usually inside `Date_field.Suffix` | +| `DateRangePicker.TriggerIndicator` | `Date_range_picker.Trigger_indicator` | Indicator slot with the default calendar icon | +| `DateRangePicker.RangeSeparator` | `Date_range_picker.Range_separator` | Separator between the start and end inputs | +| `DateRangePicker.Popover` | `Date_range_picker.Popover` | Popover wrapper for `Range_calendar` content | diff --git a/agents/pages/heroui/range-calendar.md b/agents/pages/heroui/range-calendar.md new file mode 100644 index 00000000..5f46003f --- /dev/null +++ b/agents/pages/heroui/range-calendar.md @@ -0,0 +1,1239 @@ +# RangeCalendar + +Composable date range picker with month grid, navigation, and year picker support. + +Its value is a `Range_calendar.range`, `{ start; end_ }`, of +`CalendarDate`s of `solidtype-internationalized-date`. `on_change` is told +the range chosen, or `None` where `` commit_behavior=`clear `` clears it. + +Its weeks start on Monday and its days are written as `en-GB` writes them, +whatever the browser reads, unless an `I18n.I18nProvider` names another +locale. React's follows the browser. + +Original HeroUI documentation: [RangeCalendar](https://heroui.com/en/docs/react/components/range-calendar). + +## Usage + +```ocaml title="range_calendar_usage.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar + +let make () = + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + +``` + +## Parity + +The same HeroUI RangeCalendar twice, under the same props: in solidtype on +the left, in React on the right. Below them, every attribute of the two +calendars: a marked row is one they disagree on. + +## Anatomy + +```ocaml + + + + + + + + + (fun day -> + (Jsx.string (S.get day))) + + + (fun date -> ) + + + +``` + +A press on a day begins a range, and the days shown run to the one hovered +or focused until a second press ends it. A drag chooses the days it crosses, +and a drag from an end of the range chosen moves that end. Enter begins and +ends a range by the keys, and Escape lets a range begun go. + +## Examples + +### Disabled + +```ocaml title="range_calendar_disabled.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar +module Description = Solidtype_heroui.Description + +let make () = +
+ + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + "Range calendar is disabled" +
+``` + +### Year Picker + +`Range_calendar.Year_picker_trigger`, `Range_calendar.Year_picker_grid`, and +their body and cell parts provide an integrated year navigation pattern. + +```ocaml title="range_calendar_year_picker.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar + +let make () = + + + + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + + +``` + +### Default Value + +```ocaml title="range_calendar_default_value.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate + +let make () = + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + +``` + +### Controlled + +Use controlled `value` and `focused_value` for external state coordination +and custom shortcuts. + +```ocaml title="range_calendar_controlled.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Description = Solidtype_heroui.Description +module Button = Solidtype_heroui.Button +module Button_group = Solidtype_heroui.Button_group + +let today () = D.today (D.get_local_time_zone ()) + +(* The start of the week holding [d], Monday first, as en-GB counts. *) +let start_of_week d = + Date.subtract d + (D.Types.DateDuration.make ~days:(D.get_day_of_week d "en-GB" ()) ()) + +let start_of_month d = Date.set d (D.Types.DateFields.make ~day:1 ()) + +let make () = + let value, set_value = S.create_signal None in + let focused, set_focused = S.create_signal (D.parse_date "2025-12-25") in + let set_range start end_ = + S.set set_value (Some { Range_calendar.start; end_ }); + S.set set_focused start + in +
+ + + + + + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + (Jsx.string + ("Selected range: " + ^ + match S.get value with + | Some r -> + Date.to_string r.start () ^ " -> " ^ Date.to_string r.end_ () + | None -> "(none)")) + +
+ + + +
+
+``` + +### Min and Max Dates + +```ocaml title="range_calendar_min_max.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Description = Solidtype_heroui.Description + +let make () = + let now = D.today (D.get_local_time_zone ()) in + let max_date = Date.add now (D.Types.DateDuration.make ~months:3 ()) in +
+ + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + (Jsx.string + ("Select a date between today and " ^ Date.to_string max_date ())) + +
+``` + +### Unavailable Dates + +Use `is_date_unavailable` to block dates such as weekends, holidays, or +booked slots. A range begun reaches no further than the nearest unavailable +day. + +```ocaml title="range_calendar_unavailable.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Description = Solidtype_heroui.Description + +let now () = D.today (D.get_local_time_zone ()) +let days n = D.Types.DateDuration.make ~days:n () + +(* Days two to five from today, and twelve and thirteen, are booked. *) +let is_date_unavailable d _ = + let n = now () in + List.exists + (fun (a, b) -> + Date.compare d (Date.add n (days a)) >= 0. + && Date.compare d (Date.add n (days b)) <= 0.) + [ (2, 5); (12, 13) ] + +let make () = +
+ + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + "Some days are unavailable" +
+``` + +### Anchor-Based Unavailable Dates + +While a range is begun, `is_date_unavailable` is given its first date beside +each date, `Some anchor`, else `None`. Use it to limit which end dates are +valid, for example within 7 days of the start. + +```ocaml title="range_calendar_anchor_unavailable.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Description = Solidtype_heroui.Description + +(* Once a start is chosen, only the days within a week of it may end the + range. *) +let is_date_unavailable d anchor = + match anchor with + | Some a -> abs_float (Date.compare d a) > 7. + | None -> false + +let make () = +
+ + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + "After selecting a start date, only dates within 7 days are available" + +
+``` + +### Weeks in Month + +Set `weeks_in_month` to a fixed value, for example `6`, to keep the grid's +height as months change. + +```ocaml title="range_calendar_weeks_in_month.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar +module Description = Solidtype_heroui.Description + +let make () = +
+ + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + "Always shows 6 weeks per month to avoid layout shift when navigating" + +
+``` + +### Week View + +`` visible_duration=(Range_calendar.Weeks n) `` shows one or more weeks at a +time, and its buttons page by them; `` page_behavior=`single `` pages a week +at a time. Its grid is named by the days it shows. + +```ocaml title="range_calendar_week_view.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box +module Select = Solidtype_heroui.Select + +let options = + [| + ("1", "1 week"); + ("2", "2 weeks"); + ("3", "3 weeks"); + ("4", "4 weeks"); + ("5", "5 weeks"); + ("6", "6 weeks"); + ("8", "8 weeks"); + |] + +let make () = + let count, set_count = S.create_signal 1 in +
+ + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + +
+``` + +### Day View + +`` visible_duration=(Range_calendar.Days n) `` shows a run of days, and its +buttons page by them; `` page_behavior=`single `` pages a day at a time. + +```ocaml title="range_calendar_day_view.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box +module Select = Solidtype_heroui.Select + +let options = + [| + ("1", "1 day"); + ("5", "5 days"); + ("7", "7 days"); + ("8", "8 days"); + ("10", "10 days"); + ("14", "14 days"); + ("21", "21 days"); + |] + +let make () = + let count, set_count = S.create_signal 5 in +
+ + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + +
+``` + +### Allows Non-Contiguous Ranges + +`allows_non_contiguous_ranges` lets a range cross unavailable dates. + +```ocaml title="range_calendar_non_contiguous.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Description = Solidtype_heroui.Description + +let now () = D.today (D.get_local_time_zone ()) +let days n = D.Types.DateDuration.make ~days:n () + +(* Days two to five from today, and twelve and thirteen, are booked. *) +let is_date_unavailable d _ = + let n = now () in + List.exists + (fun (a, b) -> + Date.compare d (Date.add n (days a)) >= 0. + && Date.compare d (Date.add n (days b)) <= 0.) + [ (2, 5); (12, 13) ] + +let make () = +
+ + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + "Non-contiguous ranges are allowed across unavailable dates" + +
+``` + +### Read Only + +```ocaml title="range_calendar_read_only.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Description = Solidtype_heroui.Description + +let make () = +
+ + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + "Range calendar is read-only" + +
+``` + +### Invalid + +```ocaml title="range_calendar_invalid.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Description = Solidtype_heroui.Description + +let make () = + let now = D.today (D.get_local_time_zone ()) in + let after n = Date.add now (D.Types.DateDuration.make ~days:n ()) in + let value, set_value = + S.create_signal { Range_calendar.start = after 6; end_ = after 14 } + in + let too_long () = + let r = S.get value in + Date.compare r.end_ r.start > 7. + in +
+ + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + (if too_long () then +

"Maximum stay duration is 1 week"

+ else + + "Select a stay of up to 7 days" + ) +
+``` + +### Focused Value + +`focused_value` and `on_focus_change` control which date is focused. + +```ocaml title="range_calendar_focused_value.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Description = Solidtype_heroui.Description +module Button = Solidtype_heroui.Button + +let make () = + let focused, set_focused = S.create_signal (D.parse_date "2025-06-15") in +
+ + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + (Jsx.string ("Focused: " ^ Date.to_string (S.get focused) ())) + +
+ + + +
+
+``` + +### Cell Indicators + +`Range_calendar.Cell`'s children are drawn of its state, and +`Range_calendar.Cell_indicator` marks a day. + +```ocaml title="range_calendar_indicators.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate + +let dates_with_events = [ 3; 7; 12; 15; 21; 28 ] + +let make () = + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> + + (fun (cell : Range_calendar.cell) -> + let d = S.get date in + Jsx.fragment + [| + Jsx.string (S.get cell.formatted_date); + (if + D.is_today d (D.get_local_time_zone ()) + || List.mem (Date.day d) dates_with_events + then + else Jsx.nothing); + |]) + ) + + + +``` + +### Real-World Example + +```ocaml title="range_calendar_booking.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Button = Solidtype_heroui.Button + +let blocked_dates = [ 5; 6; 12; 13; 14; 20 ] +let weekend date = D.is_weekend date "en-GB" + +let make () = + let selected, set_selected = S.create_signal None in + let is_date_unavailable date _ = + weekend date || List.mem (Date.day date) blocked_dates + in +
+ + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> + + (fun (cell : Range_calendar.cell) -> + let d = S.get date in + Jsx.fragment + [| + Jsx.string (S.get cell.formatted_date); + (if + (not (S.get cell.is_unavailable)) + && (not (weekend d)) + && List.mem (Date.day d) blocked_dates + then + else Jsx.nothing); + |]) + ) + + + +
+
+ + "Blocked dates" + + + "Weekend/Unavailable" + +
+ + (fun r -> + ) + +
+
+``` + +### Multiple Months + +`visible_duration` and `offset` show several months side by side. + +```ocaml title="range_calendar_multiple_months.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar + +let make () = + +
+
+ + + +
+ + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + +
+
+ +
+ + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + +
+
+ +``` + +### International Calendars + +An `I18n.I18nProvider` locale with a calendar extension shows that calendar; +`on_change` gives dates in the calendar of the value given, else the +Gregorian. + +```ocaml title="range_calendar_international.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar +module I18n = Solidtype_kobalte.I18n + +let make () = + + + + + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + + + +``` + +## Customization + +### Tailwind CSS + +`class_` is added after HeroUI's classes. + +```ocaml title="range_calendar_tailwind.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar +module D = Solidtype_internationalized_date + +let cell_class = + String.concat " " + [ + "rounded-md"; + "**:data-[slot=range-calendar-cell-button]:rounded-md"; + "data-[outside-month=true]:text-muted \ + data-[outside-month=true]:opacity-50"; + "data-[hovered=true]:not-data-[selected=true]:**:data-[slot=range-calendar-cell-button]:bg-default"; + "data-[today=true]:**:data-[slot=range-calendar-cell-button]:bg-success-soft"; + "data-[today=true]:**:data-[slot=range-calendar-cell-button]:text-success-soft-foreground"; + "data-[today=true]:data-[hovered=true]:not-data-[selected=true]:**:data-[slot=range-calendar-cell-button]:bg-success-soft-hover"; + "data-[selected=true]:rounded-none data-[selected=true]:bg-success-soft"; + "data-[outside-month=true]:data-[selected=true]:bg-default/20"; + "data-[selection-start=true]:rounded-tl-md \ + data-[selection-start=true]:rounded-bl-md"; + "data-[selection-end=true]:rounded-tr-md \ + data-[selection-end=true]:rounded-br-md"; + "data-[selection-start=true]:**:data-[slot=range-calendar-cell-button]:bg-success"; + "data-[selection-start=true]:**:data-[slot=range-calendar-cell-button]:text-success-foreground"; + "data-[selection-start=true]:data-[pressed=true]:**:data-[slot=range-calendar-cell-button]:bg-success-hover"; + "data-[selection-end=true]:**:data-[slot=range-calendar-cell-button]:bg-success"; + "data-[selection-end=true]:**:data-[slot=range-calendar-cell-button]:text-success-foreground"; + "data-[selection-end=true]:data-[pressed=true]:**:data-[slot=range-calendar-cell-button]:bg-success-hover"; + ] + +let make () = + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> + ) + + + +``` + +## Styling Reference + +HeroUI follows the [BEM](https://bem.info/en/methodology/) methodology to +ensure component variants and states are reusable and easy to customize. + +### CSS Classes + +- `.range-calendar` - Root container. +- `.range-calendar--week-view`, `.range-calendar--day-view` - A week's or a day's view. +- `.range-calendar__header` - Header row containing nav buttons and heading. +- `.range-calendar__heading` - Current month label. +- `.range-calendar__nav-button` - Previous/next navigation controls. +- `.range-calendar__grid` - Main day grid. +- `.range-calendar__grid-header` - Weekday header row wrapper. +- `.range-calendar__grid-body` - Date rows wrapper. +- `.range-calendar__header-cell` - Weekday header cell. +- `.range-calendar__cell` - Interactive day cell. +- `.range-calendar__cell-button` - A day's content, chosen at the range's ends. +- `.range-calendar__cell-indicator` - Dot indicator inside a day cell. +- `.calendar-year-picker__trigger` - Year picker toggle button. +- `.calendar-year-picker__year-grid` - Overlay grid of selectable years. +- `.calendar-year-picker__year-cell` - Individual year option. + +### Interactive States + +- **Selected**: `[data-selected="true"]` +- **Selection start**: `[data-selection-start="true"]` +- **Selection end**: `[data-selection-end="true"]` +- **Today**: `[data-today="true"]` +- **Unavailable**: `[data-unavailable="true"]` +- **Outside month**: `[data-outside-month="true"]` +- **Hovered**: `[data-hovered="true"]` +- **Pressed**: `[data-pressed="true"]` +- **Focus visible**: `[data-focus-visible="true"]` +- **Disabled**: `[data-disabled="true"]` + +## API Reference + +Each prop beside the name HeroUI's React component gives it. + +### Range_calendar + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `value` | `value` | `range Js.Nullable.t` | | Controlled selected range; null controls it empty | +| `defaultValue` | `default_value` | `range` | | Initial selected range (uncontrolled) | +| `onChange` | `on_change` | `range option -> unit` | | Called when a range is chosen, or cleared | +| `allowsNonContiguousRanges` | `allows_non_contiguous_ranges` | `bool` | `false` | Allows ranges that span unavailable dates | +| `commitBehavior` | `commit_behavior` | `` [ `select \| `reset \| `clear ] `` | `` `select `` | What a range begun becomes as the pointer is let go outside the days, or the focus leaves | +| `focusedValue` | `focused_value` | `CalendarDate.t` | | Controlled focused date | +| `defaultFocusedValue` | `default_focused_value` | `CalendarDate.t` | its start, else today | Initial focused date | +| `onFocusChange` | `on_focus_change` | `CalendarDate.t -> unit` | | Called when focus moves to another date | +| `minValue` | `min_value` | `CalendarDate.t` | 1900-01-01 in its calendar | Earliest selectable date | +| `maxValue` | `max_value` | `CalendarDate.t` | 2099-12-31 in its calendar | Latest selectable date | +| `weeksInMonth` | `weeks_in_month` | `int` | the month's | The number of weeks in a month's grid | +| `isDateUnavailable` | `is_date_unavailable` | `CalendarDate.t -> CalendarDate.t option -> bool` | | Marks dates as unavailable, given a range begun's first date | +| `firstDayOfWeek` | `first_day_of_week` | `` [ `sun \| `mon \| `tue \| `wed \| `thu \| `fri \| `sat ] `` | the locale's | The first day of its weeks | +| `pageBehavior` | `page_behavior` | `` [ `visible \| `single ] `` | `` `visible `` | Whether paging moves by what is shown or by one unit | +| `selectionAlignment` | `selection_alignment` | `` [ `start \| `center \| `end_ ] `` | `` `center ``, or `` `start `` for a range longer than a view | Where the range stands in what is shown at first | +| `isDisabled` | `is_disabled` | `bool` | `false` | Disables interaction and selection | +| `isReadOnly` | `is_read_only` | `bool` | `false` | Days are focused but not chosen | +| `isInvalid` | `is_invalid` | `bool` | `false` | Marks the calendar as invalid | +| `visibleDuration` | `visible_duration` | `Range_calendar.duration` | `Months 1` | `Months n`, `Weeks n` or `Days n` | +| `defaultYearPickerOpen` | `default_year_picker_open` | `bool` | `false` | Initial open state of the year picker | +| `isYearPickerOpen` | `is_year_picker_open` | `bool` | | Controlled open state of the year picker | +| `onYearPickerOpenChange` | `on_year_picker_open_change` | `bool -> unit` | | Called when the year picker opens or closes | +| `aria-label` | `aria_label` | `string` | | Its name, beside the dates it shows | +| `className` | `class_` | `string` | | Added after HeroUI's classes | + +### Composition Parts + +They are [Calendar](calendar.md)'s parts, drawn in the +range's look. + +| React | solidtype | Description | +|---|---|---| +| `RangeCalendar.Header` | `Range_calendar.Header` | Header container for navigation and heading | +| `RangeCalendar.Heading` | `Range_calendar.Heading` | The dates shown; `offset` and `format` | +| `RangeCalendar.NavButton` | `Range_calendar.Nav_button` | `` slot=`previous `` or `` slot=`next `` | +| `RangeCalendar.Grid` | `Range_calendar.Grid` | Day grid for one month; `offset` and `weekday_style` | +| `RangeCalendar.GridHeader` | `Range_calendar.Grid_header` | Weekday header, a function of each day's name | +| `RangeCalendar.GridBody` | `Range_calendar.Grid_body` | Date cells, a function of each date | +| `RangeCalendar.HeaderCell` | `Range_calendar.Header_cell` | Weekday label cell | +| `RangeCalendar.Cell` | `Range_calendar.Cell` | A day, its children drawn of its state | +| `RangeCalendar.CellIndicator` | `Range_calendar.Cell_indicator` | A dot marking a day | +| `RangeCalendar.YearPickerTrigger` | `Range_calendar.Year_picker_trigger` | Opens and closes the year picker | +| `RangeCalendar.YearPickerTriggerHeading` | `Range_calendar.Year_picker_trigger_heading` | The month shown, in the trigger | +| `RangeCalendar.YearPickerTriggerIndicator` | `Range_calendar.Year_picker_trigger_indicator` | The trigger's chevron | +| `RangeCalendar.YearPickerGrid` | `Range_calendar.Year_picker_grid` | The years; `format` and `visible_years` | +| `RangeCalendar.YearPickerGridBody` | `Range_calendar.Year_picker_grid_body` | The years' cells, or a function of each year | +| `RangeCalendar.YearPickerCell` | `Range_calendar.Year_picker_cell` | A year | + +### Range_calendar.Cell's state + +| React | solidtype | Type | Description | +|---|---|---|---| +| `formattedDate` | `formatted_date` | `string S.accessor` | Its day of the month | +| `isSelected` | `is_selected` | `bool S.accessor` | Whether the date is in the range shown | +| `isSelectionStart` | `is_selection_start` | `bool S.accessor` | Whether the date starts the range shown | +| `isSelectionEnd` | `is_selection_end` | `bool S.accessor` | Whether the date ends the range shown | +| `isUnavailable` | `is_unavailable` | `bool S.accessor` | Whether the date is unavailable | +| `isDisabled` | `is_disabled` | `bool S.accessor` | Whether the cell is disabled | +| `isOutsideMonth` | `is_outside_month` | `bool S.accessor` | Whether the date belongs to another month | diff --git a/agents/pages/heroui/time-field.md b/agents/pages/heroui/time-field.md index b35a582e..431215c1 100644 --- a/agents/pages/heroui/time-field.md +++ b/agents/pages/heroui/time-field.md @@ -6,6 +6,10 @@ Its value is a `Time` of `solidtype-internationalized-date`, made by `Time.make ~hour:14 ~minute:30 ()` or `parse_time "14:30"`; a time on a date is `Time_field.Date_time`'s, and a time in a zone `Time_field.Zoned`'s. +Its clock is `en-GB`'s, 24 hours, whatever the browser reads, unless an +`I18n.I18nProvider` names another locale: `` +gives a 12-hour clock. React's follows the browser. + Original HeroUI documentation: [TimeField](https://heroui.com/en/docs/react/components/time-field). ## Usage diff --git a/agents/pages/index.md b/agents/pages/index.md index 7d8a5825..ada195e7 100644 --- a/agents/pages/index.md +++ b/agents/pages/index.md @@ -70,7 +70,7 @@ GitHub release: "solid-js": "~1.9.17", "vite": "^8.3.0", "vite-plugin-solid": "^2.11.14", - "vite-plugin-solidtype": "https://github.com/hyphatech/solidtype/releases/download/0.12.0/vite-plugin-solidtype-0.12.0.tgz" + "vite-plugin-solidtype": "https://github.com/hyphatech/solidtype/releases/download/0.13.0/vite-plugin-solidtype-0.13.0.tgz" } } ``` diff --git a/agents/pages/reference.md b/agents/pages/reference.md index fb3cb7d1..d13cc6c3 100644 --- a/agents/pages/reference.md +++ b/agents/pages/reference.md @@ -58,9 +58,16 @@ bun add $(opam show solidtype-rhp --field x-npm-depends) - [`Solidtype_headless`](https://hyphatech.github.io/solidtype/reference/solidtype-headless/Solidtype_headless/index.html) -- the components Kobalte lacks, one module each: - [`Table`](https://hyphatech.github.io/solidtype/reference/solidtype-headless/Solidtype_headless/Table/index.html), + [`Calendar`](https://hyphatech.github.io/solidtype/reference/solidtype-headless/Solidtype_headless/Calendar/index.html), + [`Color_picker`](https://hyphatech.github.io/solidtype/reference/solidtype-headless/Solidtype_headless/Color_picker/index.html), [`Color_swatch_picker`](https://hyphatech.github.io/solidtype/reference/solidtype-headless/Solidtype_headless/Color_swatch_picker/index.html), + [`Data_grid`](https://hyphatech.github.io/solidtype/reference/solidtype-headless/Solidtype_headless/Data_grid/index.html), + [`Date_field`](https://hyphatech.github.io/solidtype/reference/solidtype-headless/Solidtype_headless/Date_field/index.html), + [`Date_picker`](https://hyphatech.github.io/solidtype/reference/solidtype-headless/Solidtype_headless/Date_picker/index.html), [`Load_more_sentinel`](https://hyphatech.github.io/solidtype/reference/solidtype-headless/Solidtype_headless/Load_more_sentinel/index.html), + [`Table`](https://hyphatech.github.io/solidtype/reference/solidtype-headless/Solidtype_headless/Table/index.html), + [`Tag_group`](https://hyphatech.github.io/solidtype/reference/solidtype-headless/Solidtype_headless/Tag_group/index.html), + [`Top_layer`](https://hyphatech.github.io/solidtype/reference/solidtype-headless/Solidtype_headless/Top_layer/index.html), [`Virtualizer`](https://hyphatech.github.io/solidtype/reference/solidtype-headless/Solidtype_headless/Virtualizer/index.html); and Kobalte's own, fixed: [`Color_area`](https://hyphatech.github.io/solidtype/reference/solidtype-headless/Solidtype_headless/Color_area/index.html), diff --git a/docs/astro.config.mjs b/docs/astro.config.mjs index 86b1bb47..0ad1ec80 100644 --- a/docs/astro.config.mjs +++ b/docs/astro.config.mjs @@ -100,7 +100,7 @@ export default defineConfig({ { label: "Colors", items: ["heroui/color-area", "heroui/color-field", "heroui/color-picker", "heroui/color-slider", "heroui/color-swatch", "heroui/color-swatch-picker"] }, { label: "Controls", items: ["heroui/slider", "heroui/switch"] }, { label: "Data Display", items: ["heroui/badge", "heroui/chip", "heroui/data-grid", "heroui/table", "heroui/trend-chip"] }, - { label: "Date and Time", items: ["heroui/time-field"] }, + { label: "Date and Time", items: ["heroui/calendar", "heroui/date-field", "heroui/date-picker", "heroui/date-range-picker", "heroui/range-calendar", "heroui/time-field"] }, { label: "Feedback", items: ["heroui/alert", "heroui/meter", "heroui/progress-bar", "heroui/progress-circle", "heroui/skeleton", "heroui/spinner", "heroui/text-shimmer"] }, { label: "Forms", items: ["heroui/checkbox", "heroui/checkbox-group", "heroui/description", "heroui/error-message", "heroui/field-error", "heroui/fieldset", "heroui/form", "heroui/input", "heroui/input-group", "heroui/label", "heroui/number-field", "heroui/number-stepper", "heroui/radio-group", "heroui/search-field", "heroui/text-area", "heroui/text-field"] }, { label: "Layout", items: ["heroui/card", "heroui/separator", "heroui/surface"] }, @@ -157,14 +157,18 @@ export default defineConfig({ codeSplitting: { groups: [ { name: "react", test: /\/node_modules\/(react|react-dom|scheduler)\// }, - // React Aria's components carry their hooks, past a chunk alone: - // a module each, split in two by name, for size. + // React Aria's hooks and the state and dates under them, before + // the components that import them, which would otherwise take + // them into their own chunks; the hooks split in two by area, + // for size. + { name: "internationalized", test: /\/node_modules\/@internationalized\// }, + { name: "react-stately", test: /\/node_modules\/(@react-stately|react-stately|@react-types)\// }, + { name: "react-aria-a", test: /\/node_modules\/react-aria\/dist\/[a-z]+\/[a-l]/ }, + { name: "react-aria", test: /\/node_modules\/(@react-aria|react-aria)\// }, + // React Aria's components, a module each, split in two by name, + // for size. { name: "react-aria-components-a", test: /\/node_modules\/react-aria-components\/dist\/[a-z]+\/[A-La-l]/ }, { name: "react-aria-components", test: /\/node_modules\/react-aria-components\// }, - { - name: "react-aria", - test: /\/node_modules\/(@react-aria|@react-stately|@react-types|react-aria|react-stately|@internationalized)\//, - }, { name: "heroui-react", test: /\/node_modules\/@heroui\/react\// }, ], }, diff --git a/docs/islands/calendar_booking.mlx b/docs/islands/calendar_booking.mlx new file mode 100644 index 00000000..da42df67 --- /dev/null +++ b/docs/islands/calendar_booking.mlx @@ -0,0 +1,70 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Button = Solidtype_heroui.Button + +let booked_dates = [ 5; 6; 12; 13; 14; 20 ] +let weekend date = D.is_weekend date "en-GB" + +let make () = + let selected, set_selected = S.create_signal None in + let is_date_unavailable date = + weekend date || List.mem (Date.day date) booked_dates + in +
+ S.set set_selected (Some d))> + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> + + (fun (cell : Calendar.cell) -> + let d = S.get date in + Jsx.fragment + [| + Jsx.string (S.get cell.formatted_date); + (if + (not (S.get cell.is_unavailable)) + && (not (weekend d)) + && List.mem (Date.day d) booked_dates + then + else Jsx.nothing); + |]) + ) + + + +
+
+ + "Has bookings" + + + "Weekend/Unavailable" + +
+ + (fun d -> + ) + +
+
diff --git a/docs/islands/calendar_controlled.mlx b/docs/islands/calendar_controlled.mlx new file mode 100644 index 00000000..eb8f9a8a --- /dev/null +++ b/docs/islands/calendar_controlled.mlx @@ -0,0 +1,82 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Button = Solidtype_heroui.Button +module Button_group = Solidtype_heroui.Button_group +module Calendar = Solidtype_heroui.Calendar +module Description = Solidtype_heroui.Description +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate + +let today () = D.today (D.get_local_time_zone ()) + +(* The start of the week holding [d], Monday first, as en-GB counts. *) +let start_of_week d = + Date.subtract d + (D.Types.DateDuration.make ~days:(D.get_day_of_week d "en-GB" ()) ()) + +let start_of_month d = Date.set d (D.Types.DateFields.make ~day:1 ()) + +let make () = + let value, set_value = S.create_signal None in + let focused, set_focused = S.create_signal (D.parse_date "2025-12-25") in + let choose d = + S.set set_value (Some d); + S.set set_focused d + in +
+ + + + + + S.set set_value (Some d)) + on_focus_change=(S.set set_focused)> + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + (Jsx.string + ("Selected date: " + ^ + match S.get value with + | Some d -> Date.to_string d () + | None -> "(none)")) + +
+ + + +
+
diff --git a/docs/islands/calendar_custom_icons.mlx b/docs/islands/calendar_custom_icons.mlx new file mode 100644 index 00000000..6689f2e0 --- /dev/null +++ b/docs/islands/calendar_custom_icons.mlx @@ -0,0 +1,43 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar + +let make () = + + + + + + + + + + + + + + + + + (fun day -> + (Jsx.string (S.get day))) + + + (fun date -> ) + + + diff --git a/docs/islands/calendar_day_view.mlx b/docs/islands/calendar_day_view.mlx new file mode 100644 index 00000000..85cb3ecc --- /dev/null +++ b/docs/islands/calendar_day_view.mlx @@ -0,0 +1,62 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box +module Select = Solidtype_heroui.Select + +let options = + [| + ("1", "1 day"); + ("5", "5 days"); + ("7", "7 days"); + ("8", "8 days"); + ("10", "10 days"); + ("14", "14 days"); + ("21", "21 days"); + |] + +let make () = + let count, set_count = S.create_signal 5 in +
+ + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + +
diff --git a/docs/islands/calendar_default_value.mlx b/docs/islands/calendar_default_value.mlx new file mode 100644 index 00000000..b9ff9293 --- /dev/null +++ b/docs/islands/calendar_default_value.mlx @@ -0,0 +1,23 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate + +let make () = + + + + + + + + + (fun day -> + (Jsx.string (S.get day))) + + + (fun date -> ) + + + diff --git a/docs/islands/calendar_demo.mlx b/docs/islands/calendar_demo.mlx new file mode 100644 index 00000000..51e9d07c --- /dev/null +++ b/docs/islands/calendar_demo.mlx @@ -0,0 +1,45 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module I18n = Solidtype_kobalte.I18n +module Toggle = Controls.Toggle +module D = Solidtype_internationalized_date + +let make () = + let disabled, set_disabled = S.create_signal false in +
+
+ +
+ + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + ) + react=(fun host -> + Heroui_react.calendar host + (Heroui_react.calendar_props ~is_disabled:(S.get disabled) ())) + /> +
diff --git a/docs/islands/calendar_disabled.mlx b/docs/islands/calendar_disabled.mlx new file mode 100644 index 00000000..70323e2d --- /dev/null +++ b/docs/islands/calendar_disabled.mlx @@ -0,0 +1,32 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Description = Solidtype_heroui.Description + +let make () = +
+ + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + "Calendar is disabled" +
diff --git a/docs/islands/calendar_focused_value.mlx b/docs/islands/calendar_focused_value.mlx new file mode 100644 index 00000000..5bfbdd44 --- /dev/null +++ b/docs/islands/calendar_focused_value.mlx @@ -0,0 +1,56 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Description = Solidtype_heroui.Description +module Button = Solidtype_heroui.Button + +let make () = + let focused, set_focused = S.create_signal (D.parse_date "2025-06-15") in +
+ + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + (Jsx.string ("Focused: " ^ Date.to_string (S.get focused) ())) + +
+ + + +
+
diff --git a/docs/islands/calendar_indicators.mlx b/docs/islands/calendar_indicators.mlx new file mode 100644 index 00000000..331d647d --- /dev/null +++ b/docs/islands/calendar_indicators.mlx @@ -0,0 +1,38 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate + +let dates_with_events = [ 3; 7; 12; 15; 21; 28 ] + +let make () = + + + + + + + + + (fun day -> + (Jsx.string (S.get day))) + + + (fun date -> + + (fun (cell : Calendar.cell) -> + let d = S.get date in + Jsx.fragment + [| + Jsx.string (S.get cell.formatted_date); + (if + D.is_today d (D.get_local_time_zone ()) + || List.mem (Date.day d) dates_with_events + then + else Jsx.nothing); + |]) + ) + + + diff --git a/docs/islands/calendar_international.mlx b/docs/islands/calendar_international.mlx new file mode 100644 index 00000000..07314f6c --- /dev/null +++ b/docs/islands/calendar_international.mlx @@ -0,0 +1,35 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module I18n = Solidtype_kobalte.I18n + +let make () = + + + + + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + + + diff --git a/docs/islands/calendar_min_max.mlx b/docs/islands/calendar_min_max.mlx new file mode 100644 index 00000000..31bb87ee --- /dev/null +++ b/docs/islands/calendar_min_max.mlx @@ -0,0 +1,34 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Description = Solidtype_heroui.Description + +let make () = + let now = D.today (D.get_local_time_zone ()) in + let max_date = Date.add now (D.Types.DateDuration.make ~months:3 ()) in +
+ + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + (Jsx.string + ("Select a date between today and " ^ Date.to_string max_date ())) + +
diff --git a/docs/islands/calendar_multiple.mlx b/docs/islands/calendar_multiple.mlx new file mode 100644 index 00000000..b1571741 --- /dev/null +++ b/docs/islands/calendar_multiple.mlx @@ -0,0 +1,36 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Description = Solidtype_heroui.Description + +let make () = + let value, set_value = S.create_signal [||] in +
+ + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + (Jsx.string + (match Array.length (S.get value) with + | 0 -> "Select multiple dates" + | n -> string_of_int n ^ " date(s) selected")) + +
diff --git a/docs/islands/calendar_multiple_months.mlx b/docs/islands/calendar_multiple_months.mlx new file mode 100644 index 00000000..26c9056a --- /dev/null +++ b/docs/islands/calendar_multiple_months.mlx @@ -0,0 +1,48 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar + +let make () = + +
+
+ + + +
+ + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + +
+
+ +
+ + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + +
+
+ diff --git a/docs/islands/calendar_read_only.mlx b/docs/islands/calendar_read_only.mlx new file mode 100644 index 00000000..dfcb6613 --- /dev/null +++ b/docs/islands/calendar_read_only.mlx @@ -0,0 +1,32 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Description = Solidtype_heroui.Description + +let make () = +
+ + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + "Calendar is read-only" +
diff --git a/docs/islands/calendar_tailwind.mlx b/docs/islands/calendar_tailwind.mlx new file mode 100644 index 00000000..9fb0b5cf --- /dev/null +++ b/docs/islands/calendar_tailwind.mlx @@ -0,0 +1,52 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar + +let make () = + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> + ) + + + diff --git a/docs/islands/calendar_unavailable.mlx b/docs/islands/calendar_unavailable.mlx new file mode 100644 index 00000000..49360354 --- /dev/null +++ b/docs/islands/calendar_unavailable.mlx @@ -0,0 +1,32 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Description = Solidtype_heroui.Description + +(* Saturdays and Sundays, as most of the world's weekend falls. *) +let is_date_unavailable date = D.is_weekend date "en-GB" + +let make () = +
+ + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + "Weekends are unavailable" +
diff --git a/docs/islands/calendar_usage.mlx b/docs/islands/calendar_usage.mlx new file mode 100644 index 00000000..38a2c796 --- /dev/null +++ b/docs/islands/calendar_usage.mlx @@ -0,0 +1,21 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar + +let make () = + + + + + + + + + (fun day -> + (Jsx.string (S.get day))) + + + (fun date -> ) + + + diff --git a/docs/islands/calendar_week_view.mlx b/docs/islands/calendar_week_view.mlx new file mode 100644 index 00000000..221324a4 --- /dev/null +++ b/docs/islands/calendar_week_view.mlx @@ -0,0 +1,62 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box +module Select = Solidtype_heroui.Select + +let options = + [| + ("1", "1 week"); + ("2", "2 weeks"); + ("3", "3 weeks"); + ("4", "4 weeks"); + ("5", "5 weeks"); + ("6", "6 weeks"); + ("8", "8 weeks"); + |] + +let make () = + let count, set_count = S.create_signal 1 in +
+ + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + +
diff --git a/docs/islands/calendar_weeks_in_month.mlx b/docs/islands/calendar_weeks_in_month.mlx new file mode 100644 index 00000000..c0846549 --- /dev/null +++ b/docs/islands/calendar_weeks_in_month.mlx @@ -0,0 +1,29 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module Description = Solidtype_heroui.Description + +let make () = +
+ + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + "Always shows 6 weeks per month to avoid layout shift when navigating" + +
diff --git a/docs/islands/calendar_year_picker.mlx b/docs/islands/calendar_year_picker.mlx new file mode 100644 index 00000000..2259670f --- /dev/null +++ b/docs/islands/calendar_year_picker.mlx @@ -0,0 +1,27 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar + +let make () = + + + + + + + + + + + + (fun day -> + (Jsx.string (S.get day))) + + + (fun date -> ) + + + + + + diff --git a/docs/islands/date_field_controlled.mlx b/docs/islands/date_field_controlled.mlx new file mode 100644 index 00000000..2a6c241b --- /dev/null +++ b/docs/islands/date_field_controlled.mlx @@ -0,0 +1,43 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Button = Solidtype_heroui.Button +module Description = Solidtype_heroui.Description +module Label = Solidtype_heroui.Label +module Date_field = Solidtype_heroui.Date_field +module D = Solidtype_internationalized_date + +let make () = + let value, set_value = S.create_signal None in +
+ + + + + (fun segment -> ) + + + + (Jsx.string + ("Current value: " + ^ + match S.get value with + | Some d -> D.Types.CalendarDate.to_string d () + | None -> "(empty)")) + + +
+ + +
+
diff --git a/docs/islands/date_field_demo.mlx b/docs/islands/date_field_demo.mlx new file mode 100644 index 00000000..53e036a6 --- /dev/null +++ b/docs/islands/date_field_demo.mlx @@ -0,0 +1,43 @@ +module S = Solidtype.Solid +module Label = Solidtype_heroui.Label +module Date_field = Solidtype_heroui.Date_field +module Select = Controls.Select +module Toggle = Controls.Toggle + +(* Each choice with the name HeroUI's React component takes for it. *) +let variants = [| (`primary, "primary"); (`secondary, "secondary") |] + +let make () = + let variant, set_variant = S.create_signal (`primary, "primary") in + let disabled, set_disabled = S.create_signal false in +
+
+ + match + Array.find_opt + (fun (_, id, _) -> Array.exists (String.equal id) ids) + granularities + with + | Some (g, _, _) -> S.set set_granularity g + | None -> ())> + + + + + (fun (_, id, label) _ -> + + (Jsx.string label) + ) + + + + +
+
diff --git a/docs/islands/date_field_invalid.mlx b/docs/islands/date_field_invalid.mlx new file mode 100644 index 00000000..fc7b0d3f --- /dev/null +++ b/docs/islands/date_field_invalid.mlx @@ -0,0 +1,26 @@ +module S = Solidtype.Solid +module Field_error = Solidtype_heroui.Field_error +module Label = Solidtype_heroui.Label +module Date_field = Solidtype_heroui.Date_field + +let make () = +
+ + + + + (fun segment -> ) + + + "Please enter a valid date" + + + + + + (fun segment -> ) + + + "Date must be in the future" + +
diff --git a/docs/islands/date_field_prefix_icon.mlx b/docs/islands/date_field_prefix_icon.mlx new file mode 100644 index 00000000..9f4f1f4d --- /dev/null +++ b/docs/islands/date_field_prefix_icon.mlx @@ -0,0 +1,17 @@ +module S = Solidtype.Solid +module Label = Solidtype_heroui.Label +module Date_field = Solidtype_heroui.Date_field +module Gravity = Solidtype_gravity_icons + +let make () = + + + + + + + + (fun segment -> ) + + + diff --git a/docs/islands/date_field_prefix_suffix.mlx b/docs/islands/date_field_prefix_suffix.mlx new file mode 100644 index 00000000..fd7b89e8 --- /dev/null +++ b/docs/islands/date_field_prefix_suffix.mlx @@ -0,0 +1,22 @@ +module S = Solidtype.Solid +module Description = Solidtype_heroui.Description +module Label = Solidtype_heroui.Label +module Date_field = Solidtype_heroui.Date_field +module Gravity = Solidtype_gravity_icons + +let make () = + + + + + + + + (fun segment -> ) + + + + + + "Enter a date" + diff --git a/docs/islands/date_field_required.mlx b/docs/islands/date_field_required.mlx new file mode 100644 index 00000000..13c9d09c --- /dev/null +++ b/docs/islands/date_field_required.mlx @@ -0,0 +1,25 @@ +module S = Solidtype.Solid +module Description = Solidtype_heroui.Description +module Label = Solidtype_heroui.Label +module Date_field = Solidtype_heroui.Date_field + +let make () = +
+ + + + + (fun segment -> ) + + + + + + + + (fun segment -> ) + + + "Required field" + +
diff --git a/docs/islands/date_field_suffix_icon.mlx b/docs/islands/date_field_suffix_icon.mlx new file mode 100644 index 00000000..798bc6fd --- /dev/null +++ b/docs/islands/date_field_suffix_icon.mlx @@ -0,0 +1,17 @@ +module S = Solidtype.Solid +module Label = Solidtype_heroui.Label +module Date_field = Solidtype_heroui.Date_field +module Gravity = Solidtype_gravity_icons + +let make () = + + + + + (fun segment -> ) + + + + + + diff --git a/docs/islands/date_field_surface.mlx b/docs/islands/date_field_surface.mlx new file mode 100644 index 00000000..de052f96 --- /dev/null +++ b/docs/islands/date_field_surface.mlx @@ -0,0 +1,31 @@ +module S = Solidtype.Solid +module Description = Solidtype_heroui.Description +module Surface = Solidtype_heroui.Surface +module Label = Solidtype_heroui.Label +module Date_field = Solidtype_heroui.Date_field +module Gravity = Solidtype_gravity_icons + +let make () = + + + + + + (fun segment -> ) + + + "Enter a date" + + + + + + + + + (fun segment -> ) + + + "Enter a date for your appointment" + + diff --git a/docs/islands/date_field_tailwind.mlx b/docs/islands/date_field_tailwind.mlx new file mode 100644 index 00000000..b72daf84 --- /dev/null +++ b/docs/islands/date_field_tailwind.mlx @@ -0,0 +1,15 @@ +module S = Solidtype.Solid +module Label = Solidtype_heroui.Label +module Date_field = Solidtype_heroui.Date_field + +let make () = + + + + + (fun segment -> ) + + + diff --git a/docs/islands/date_field_usage.mlx b/docs/islands/date_field_usage.mlx new file mode 100644 index 00000000..373e52a8 --- /dev/null +++ b/docs/islands/date_field_usage.mlx @@ -0,0 +1,13 @@ +module S = Solidtype.Solid +module Label = Solidtype_heroui.Label +module Date_field = Solidtype_heroui.Date_field + +let make () = + + + + + (fun segment -> ) + + + diff --git a/docs/islands/date_field_variants.mlx b/docs/islands/date_field_variants.mlx new file mode 100644 index 00000000..a5dab981 --- /dev/null +++ b/docs/islands/date_field_variants.mlx @@ -0,0 +1,23 @@ +module S = Solidtype.Solid +module Label = Solidtype_heroui.Label +module Date_field = Solidtype_heroui.Date_field + +let make () = +
+ + + + + (fun segment -> ) + + + + + + + + (fun segment -> ) + + + +
diff --git a/docs/islands/date_field_with_validation.mlx b/docs/islands/date_field_with_validation.mlx new file mode 100644 index 00000000..c482ffd9 --- /dev/null +++ b/docs/islands/date_field_with_validation.mlx @@ -0,0 +1,38 @@ +module S = Solidtype.Solid +module Show = Solidtype.Show +module Description = Solidtype_heroui.Description +module Field_error = Solidtype_heroui.Field_error +module Label = Solidtype_heroui.Label +module Date_field = Solidtype_heroui.Date_field +module D = Solidtype_internationalized_date + +let make () = + let value, set_value = S.create_signal None in + let today = D.today (D.get_local_time_zone ()) in + let is_invalid () = + match S.get value with + | Some d -> D.Types.CalendarDate.compare d today < 0. + | None -> false + in +
+ + + + + (fun segment -> ) + + + "Enter a date from today onwards")> + "Date must be today or in the future" + + +
diff --git a/docs/islands/date_field_zoned.mlx b/docs/islands/date_field_zoned.mlx new file mode 100644 index 00000000..5eb6c7db --- /dev/null +++ b/docs/islands/date_field_zoned.mlx @@ -0,0 +1,44 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Description = Solidtype_heroui.Description +module Label = Solidtype_heroui.Label +module Date_field = Solidtype_heroui.Date_field +module D = Solidtype_internationalized_date + +let kyiv at = D.parse_zoned_date_time (at ^ "[Europe/Kyiv]") () + +let make () = + let meeting, set_meeting = S.create_signal (Some (kyiv "2026-10-25T02:30")) in +
+ + + + + (fun segment -> ) + + + + + + + + (fun segment -> ) + + + + (Jsx.string + (match S.get meeting with + | Some m -> D.Types.ZonedDateTime.to_string m () + | None -> "(empty)")) + + +
diff --git a/docs/islands/date_picker_controlled.mlx b/docs/islands/date_picker_controlled.mlx new file mode 100644 index 00000000..203e4351 --- /dev/null +++ b/docs/islands/date_picker_controlled.mlx @@ -0,0 +1,78 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module Date_field = Solidtype_heroui.Date_field +module Date_picker = Solidtype_heroui.Date_picker +module Label = Solidtype_heroui.Label +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Description = Solidtype_heroui.Description +module Button = Solidtype_heroui.Button + +let make () = + let value, set_value = + S.create_signal (Some (D.today (D.get_local_time_zone ()))) + in +
+ + + + + (fun segment -> ) + + + + + + + + + + + + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + + + + + + (Jsx.string + ("Current value: " + ^ + match S.get value with + | Some d -> Date.to_string d () + | None -> "(empty)")) + +
+ + +
+
diff --git a/docs/islands/date_picker_custom_indicator.mlx b/docs/islands/date_picker_custom_indicator.mlx new file mode 100644 index 00000000..01ed99b1 --- /dev/null +++ b/docs/islands/date_picker_custom_indicator.mlx @@ -0,0 +1,54 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module Date_field = Solidtype_heroui.Date_field +module Date_picker = Solidtype_heroui.Date_picker +module Label = Solidtype_heroui.Label +module Description = Solidtype_heroui.Description +module Icons = Solidtype_gravity_icons + +let make () = + + + + + (fun segment -> ) + + + + + + + + + + + "Replace the default calendar icon by passing custom children." + + + + + + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + + + + diff --git a/docs/islands/date_picker_demo.mlx b/docs/islands/date_picker_demo.mlx new file mode 100644 index 00000000..6f53c58a --- /dev/null +++ b/docs/islands/date_picker_demo.mlx @@ -0,0 +1,65 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module Date_field = Solidtype_heroui.Date_field +module Date_picker = Solidtype_heroui.Date_picker +module Label = Solidtype_heroui.Label +module I18n = Solidtype_kobalte.I18n +module Toggle = Controls.Toggle +module D = Solidtype_internationalized_date + +let make () = + let disabled, set_disabled = S.create_signal false in +
+
+ +
+ + + + + + (fun segment -> + ) + + + + + + + + + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + + ) + react=(fun host -> + Heroui_react.date_picker host + (Heroui_react.date_picker_props ~is_disabled:(S.get disabled) ())) + /> +
diff --git a/docs/islands/date_picker_disabled.mlx b/docs/islands/date_picker_disabled.mlx new file mode 100644 index 00000000..8e2e2836 --- /dev/null +++ b/docs/islands/date_picker_disabled.mlx @@ -0,0 +1,55 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module Date_field = Solidtype_heroui.Date_field +module Date_picker = Solidtype_heroui.Date_picker +module Label = Solidtype_heroui.Label +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Description = Solidtype_heroui.Description + +let make () = + + + + + (fun segment -> ) + + + + + + + + "This date picker is disabled." + + + + + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + + + + diff --git a/docs/islands/date_picker_form.mlx b/docs/islands/date_picker_form.mlx new file mode 100644 index 00000000..dbfdbb70 --- /dev/null +++ b/docs/islands/date_picker_form.mlx @@ -0,0 +1,92 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module Date_field = Solidtype_heroui.Date_field +module Date_picker = Solidtype_heroui.Date_picker +module Label = Solidtype_heroui.Label +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Description = Solidtype_heroui.Description +module Button = Solidtype_heroui.Button +module Field_error = Solidtype_heroui.Field_error +module Form = Solidtype_heroui.Form + +external set_timeout : (unit -> unit) -> int -> unit = "setTimeout" +external prevent_default : Dom.event -> unit = "preventDefault" [@@mel.send] + +let make () = + let value, set_value = S.create_signal None in + let submitting, set_submitting = S.create_signal false in + let current = D.today (D.get_local_time_zone ()) in + let is_invalid () = + match S.get value with + | Some v -> Date.compare v current < 0. + | None -> false + in + let submit e = + prevent_default e; + if Option.is_some (S.get value) && not (is_invalid ()) then ( + S.set set_submitting true; + set_timeout + (fun () -> + S.set set_value None; + S.set set_submitting false) + 1200) + in +
+ + + + + (fun segment -> ) + + + + + + + + (if is_invalid () then + "Date must be today or in the future." + else "Choose a valid appointment date.") + + + + + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + + + + + +
diff --git a/docs/islands/date_picker_format_options.mlx b/docs/islands/date_picker_format_options.mlx new file mode 100644 index 00000000..4b98eb6a --- /dev/null +++ b/docs/islands/date_picker_format_options.mlx @@ -0,0 +1,194 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module Date_field = Solidtype_heroui.Date_field +module Date_picker = Solidtype_heroui.Date_picker +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box +module Select = Solidtype_heroui.Select +module Switch = Solidtype_heroui.Switch +module Time_field = Solidtype_heroui.Time_field +module D = Solidtype_internationalized_date + +type granularity = [ `day | `hour | `minute | `second ] + +let granularities : (string * string * granularity) array = + [| + ("day", "Day", `day); + ("hour", "Hour", `hour); + ("minute", "Minute", `minute); + ("second", "Second", `second); + |] + +let hour_cycles = [| ("12", "12-hour", `h12); ("24", "24-hour", `h24) |] + +let calendar () = + + + + + + + + + + + + (fun day -> + (Jsx.string (S.get day))) + + + (fun date -> ) + + + + + + + +let group () = + + + (fun segment -> ) + + + + + + + + +let choice ~label ~options ~value ~on_change = + + +let switch ~on ~set text = + + + (Jsx.string text) + + + +let make () = + let granularity, set_granularity = S.create_signal (`minute : granularity) in + let hour_cycle, set_hour_cycle = S.create_signal `h12 in + let hide_time_zone, set_hide_time_zone = S.create_signal false in + let leading_zeros, set_leading_zeros = S.create_signal false in + let zone = D.get_local_time_zone () in + let at_time () = + D.parse_zoned_date_time ("2026-02-03T08:45:00[" ^ zone ^ "]") () + in + (* The time field's granularity: the picker's, which has a time. *) + let time_granularity () = + match S.get granularity with + | `day -> None + | (`hour | `minute | `second) as g -> Some g + in +
+ (match S.get granularity with + | `day -> + + + (group ()) + + (calendar ()) + + + | `hour | `minute | `second -> + + (fun (picker : D.Types.ZonedDateTime.t Date_picker.state) -> + Jsx.fragment + [| + ; + group (); + + (calendar ()) +
+ + + + + (fun segment -> + ) + + + +
+
; + |]) +
) +
+
+ (choice ~label:"Granularity" + ~options:(Array.map (fun (id, name, _) -> (id, name)) granularities) + ~value:(fun () -> + match S.get granularity with + | `day -> "day" + | `hour -> "hour" + | `minute -> "minute" + | `second -> "second") + ~on_change:(fun id -> + Array.iter + (fun (i, _, g) -> + if String.equal i id then S.set set_granularity g) + granularities)) +
+
+ (choice ~label:"Hour cycle" + ~options:(Array.map (fun (id, name, _) -> (id, name)) hour_cycles) + ~value:(fun () -> + match S.get hour_cycle with `h12 -> "12" | `h24 -> "24") + ~on_change:(fun id -> + Array.iter + (fun (i, _, c) -> + if String.equal i id then S.set set_hour_cycle c) + hour_cycles)) +
+
+
+ (switch + ~on:(fun () -> S.get hide_time_zone) + ~set:(S.set set_hide_time_zone) "Hide timezone") + (switch + ~on:(fun () -> S.get leading_zeros) + ~set:(S.set set_leading_zeros) "Force leading zeros") +
+
diff --git a/docs/islands/date_picker_international.mlx b/docs/islands/date_picker_international.mlx new file mode 100644 index 00000000..ea2677c2 --- /dev/null +++ b/docs/islands/date_picker_international.mlx @@ -0,0 +1,55 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module Date_field = Solidtype_heroui.Date_field +module Date_picker = Solidtype_heroui.Date_picker +module Label = Solidtype_heroui.Label +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module I18n = Solidtype_kobalte.I18n + +let make () = + + + + + + (fun segment -> ) + + + + + + + + + + + + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + + + + + diff --git a/docs/islands/date_picker_render_function.mlx b/docs/islands/date_picker_render_function.mlx new file mode 100644 index 00000000..7a9f7d3a --- /dev/null +++ b/docs/islands/date_picker_render_function.mlx @@ -0,0 +1,60 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Calendar = Solidtype_heroui.Calendar +module Date_field = Solidtype_heroui.Date_field +module Date_picker = Solidtype_heroui.Date_picker +module Label = Solidtype_heroui.Label + +let make () = +
)> + +
)> +
)> + (fun segment -> + ) + segment=(S.get segment) + />) + + + + +
+
diff --git a/docs/islands/date_range_picker_custom_indicator.mlx b/docs/islands/date_range_picker_custom_indicator.mlx new file mode 100644 index 00000000..dfccd9bc --- /dev/null +++ b/docs/islands/date_range_picker_custom_indicator.mlx @@ -0,0 +1,58 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Date_field = Solidtype_heroui.Date_field +module Date_range_picker = Solidtype_heroui.Date_range_picker +module Label = Solidtype_heroui.Label +module Range_calendar = Solidtype_heroui.Range_calendar +module Description = Solidtype_heroui.Description +module Icons = Solidtype_gravity_icons + +let make () = + + + + + (fun segment -> ) + + + + (fun segment -> ) + + + + + + + + + + + "Replace the default calendar icon by passing custom children." + + + + + + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + + + + diff --git a/docs/islands/date_range_picker_demo.mlx b/docs/islands/date_range_picker_demo.mlx new file mode 100644 index 00000000..7dbfc147 --- /dev/null +++ b/docs/islands/date_range_picker_demo.mlx @@ -0,0 +1,76 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar +module Date_field = Solidtype_heroui.Date_field +module Date_range_picker = Solidtype_heroui.Date_range_picker +module Label = Solidtype_heroui.Label +module I18n = Solidtype_kobalte.I18n +module Toggle = Controls.Toggle +module D = Solidtype_internationalized_date + +let make () = + let disabled, set_disabled = S.create_signal false in +
+
+ +
+ + + + + + (fun segment -> + ) + + + + (fun segment -> + ) + + + + + + + + + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> + ) + + + + + + ) + react=(fun host -> + Heroui_react.date_range_picker host + (Heroui_react.date_range_picker_props + ~is_disabled:(S.get disabled) ())) + /> +
diff --git a/docs/islands/date_range_picker_disabled.mlx b/docs/islands/date_range_picker_disabled.mlx new file mode 100644 index 00000000..51c06ee4 --- /dev/null +++ b/docs/islands/date_range_picker_disabled.mlx @@ -0,0 +1,66 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Date_field = Solidtype_heroui.Date_field +module Date_range_picker = Solidtype_heroui.Date_range_picker +module Label = Solidtype_heroui.Label +module Range_calendar = Solidtype_heroui.Range_calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Description = Solidtype_heroui.Description + +let days n = D.Types.DateDuration.make ~days:n () + +let from_today n = + let start = D.today (D.get_local_time_zone ()) in + { Date_range_picker.start; end_ = Date.add start (days n) } + +let make () = + + + + + (fun segment -> ) + + + + (fun segment -> ) + + + + + + + + "This date range picker is disabled." + + + + + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + + + + diff --git a/docs/islands/date_range_picker_form.mlx b/docs/islands/date_range_picker_form.mlx new file mode 100644 index 00000000..269a3a6c --- /dev/null +++ b/docs/islands/date_range_picker_form.mlx @@ -0,0 +1,99 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Date_field = Solidtype_heroui.Date_field +module Date_range_picker = Solidtype_heroui.Date_range_picker +module Label = Solidtype_heroui.Label +module Range_calendar = Solidtype_heroui.Range_calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Description = Solidtype_heroui.Description +module Button = Solidtype_heroui.Button +module Field_error = Solidtype_heroui.Field_error +module Form = Solidtype_heroui.Form + +external set_timeout : (unit -> unit) -> int -> unit = "setTimeout" +external prevent_default : Dom.event -> unit = "preventDefault" [@@mel.send] + +let make () = + let value, set_value = S.create_signal None in + let submitting, set_submitting = S.create_signal false in + let current = D.today (D.get_local_time_zone ()) in + let is_invalid () = + match S.get value with + | Some ({ start; end_ } : Date.t Date_range_picker.range) -> + Date.compare start current < 0. || Date.compare end_ start < 0. + | None -> false + in + let submit e = + prevent_default e; + if Option.is_some (S.get value) && not (is_invalid ()) then ( + S.set set_submitting true; + set_timeout + (fun () -> + S.set set_value None; + S.set set_submitting false) + 1200) + in +
+ + + + + (fun segment -> ) + + + + (fun segment -> ) + + + + + + + + (if is_invalid () then + "Please choose a valid range in the future." + else + "Select your check-in and check-out dates.") + + + + + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + + + + + +
diff --git a/docs/islands/date_range_picker_format_options.mlx b/docs/islands/date_range_picker_format_options.mlx new file mode 100644 index 00000000..ac33d650 --- /dev/null +++ b/docs/islands/date_range_picker_format_options.mlx @@ -0,0 +1,238 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar +module Date_field = Solidtype_heroui.Date_field +module Date_range_picker = Solidtype_heroui.Date_range_picker +module Separator = Solidtype_heroui.Separator +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box +module Select = Solidtype_heroui.Select +module Switch = Solidtype_heroui.Switch +module Time_field = Solidtype_heroui.Time_field +module D = Solidtype_internationalized_date + +type granularity = [ `day | `hour | `minute | `second ] + +let granularities : (string * string * granularity) array = + [| + ("day", "Day", `day); + ("hour", "Hour", `hour); + ("minute", "Minute", `minute); + ("second", "Second", `second); + |] + +let hour_cycles = [| ("12", "12-hour", `h12); ("24", "24-hour", `h24) |] + +let calendar () = + + + + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + + + +let group () = + + + (fun segment -> ) + + + + (fun segment -> ) + + + + + + + + +let choice ~label ~options ~value ~on_change = + + +let switch ~on ~set text = + + + (Jsx.string text) + + + +(* The range as a short date range, its times left out. *) +let selected (r : D.Types.ZonedDateTime.t Date_range_picker.range option) = + match r with + | Some { start; end_ } -> + Js.String.concat + ~other: + (D.Types.DateFormatter.format_range + (D.Types.DateFormatter.make "en-GB" + ~options: + (D.Types.DateTimeFormatOptions.make ~day:"numeric" + ~month:"short" ~year:"numeric" ()) + ()) + (D.Types.ZonedDateTime.to_date start ()) + (D.Types.ZonedDateTime.to_date end_ ())) + "Selected: " + | None -> "Selected: No date selected" + +let make () = + let granularity, set_granularity = S.create_signal (`minute : granularity) in + let hour_cycle, set_hour_cycle = S.create_signal `h12 in + let hide_time_zone, set_hide_time_zone = S.create_signal false in + let leading_zeros, set_leading_zeros = S.create_signal false in + let zone = D.get_local_time_zone () in + let at time = D.parse_zoned_date_time (time ^ "[" ^ zone ^ "]") () in + let time_granularity () = + match S.get granularity with + | `day -> None + | (`hour | `minute | `second) as g -> Some g + in + let time_field ~label ~name ~value ~set = +
+ + + + + (fun segment -> ) + + + +
+ in +
+ (match S.get granularity with + | `day -> + + + (group ()) + + (calendar ()) + + + | `hour | `minute | `second -> + + (fun (picker : D.Types.ZonedDateTime.t Date_range_picker.state) -> + Jsx.fragment + [| + ; + group (); + + (calendar ()) +
+ (time_field ~label:"Start Time" ~name:"startTime" + ~value:(fun () -> fst (S.get picker.state.time_range)) + ~set:(picker.state.set_time `start)) + (time_field ~label:"End Time" ~name:"endTime" + ~value:(fun () -> snd (S.get picker.state.time_range)) + ~set:(picker.state.set_time `end_)) +
+ + (Jsx.string (selected (S.get picker.state.range))) + +
; + |]) +
) + + +
+
+ (choice ~label:"Granularity" + ~options:(Array.map (fun (id, name, _) -> (id, name)) granularities) + ~value:(fun () -> + match S.get granularity with + | `day -> "day" + | `hour -> "hour" + | `minute -> "minute" + | `second -> "second") + ~on_change:(fun id -> + Array.iter + (fun (i, _, g) -> + if String.equal i id then S.set set_granularity g) + granularities)) +
+
+ (choice ~label:"Hour cycle" + ~options:(Array.map (fun (id, name, _) -> (id, name)) hour_cycles) + ~value:(fun () -> + match S.get hour_cycle with `h12 -> "12" | `h24 -> "24") + ~on_change:(fun id -> + Array.iter + (fun (i, _, c) -> + if String.equal i id then S.set set_hour_cycle c) + hour_cycles)) +
+
+
+ (switch + ~on:(fun () -> S.get hide_time_zone) + ~set:(S.set set_hide_time_zone) "Hide timezone") + (switch + ~on:(fun () -> S.get leading_zeros) + ~set:(S.set set_leading_zeros) "Force leading zeros") +
+
diff --git a/docs/islands/date_range_picker_international.mlx b/docs/islands/date_range_picker_international.mlx new file mode 100644 index 00000000..2988a21a --- /dev/null +++ b/docs/islands/date_range_picker_international.mlx @@ -0,0 +1,66 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Date_field = Solidtype_heroui.Date_field +module Date_range_picker = Solidtype_heroui.Date_range_picker +module Label = Solidtype_heroui.Label +module Range_calendar = Solidtype_heroui.Range_calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module I18n = Solidtype_kobalte.I18n + +let days n = D.Types.DateDuration.make ~days:n () + +let from_today n = + let start = D.today (D.get_local_time_zone ()) in + { Date_range_picker.start; end_ = Date.add start (days n) } + +let make () = + + + + + + (fun segment -> ) + + + + (fun segment -> ) + + + + + + + + + + + + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + + + + + diff --git a/docs/islands/date_range_picker_render_function.mlx b/docs/islands/date_range_picker_render_function.mlx new file mode 100644 index 00000000..883d55c1 --- /dev/null +++ b/docs/islands/date_range_picker_render_function.mlx @@ -0,0 +1,55 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Date_field = Solidtype_heroui.Date_field +module Date_range_picker = Solidtype_heroui.Date_range_picker +module Label = Solidtype_heroui.Label +module Range_calendar = Solidtype_heroui.Range_calendar + +let make () = +
)> + + + + (fun segment -> ) + + + + (fun segment -> ) + + + + + + + + + + + + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + + + + diff --git a/docs/islands/date_range_picker_tailwind.mlx b/docs/islands/date_range_picker_tailwind.mlx new file mode 100644 index 00000000..91497c70 --- /dev/null +++ b/docs/islands/date_range_picker_tailwind.mlx @@ -0,0 +1,53 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Date_field = Solidtype_heroui.Date_field +module Date_range_picker = Solidtype_heroui.Date_range_picker +module Label = Solidtype_heroui.Label +module Range_calendar = Solidtype_heroui.Range_calendar + +let make () = + + + + + (fun segment -> ) + + + + (fun segment -> ) + + + + + + + + + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + diff --git a/docs/islands/date_range_picker_usage.mlx b/docs/islands/date_range_picker_usage.mlx new file mode 100644 index 00000000..ef267d7c --- /dev/null +++ b/docs/islands/date_range_picker_usage.mlx @@ -0,0 +1,51 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Date_field = Solidtype_heroui.Date_field +module Date_range_picker = Solidtype_heroui.Date_range_picker +module Label = Solidtype_heroui.Label +module Range_calendar = Solidtype_heroui.Range_calendar + +let make () = + + + + + (fun segment -> ) + + + + (fun segment -> ) + + + + + + + + + + + + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + + + + diff --git a/docs/islands/date_range_picker_validation.mlx b/docs/islands/date_range_picker_validation.mlx new file mode 100644 index 00000000..2ac6981f --- /dev/null +++ b/docs/islands/date_range_picker_validation.mlx @@ -0,0 +1,71 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Date_field = Solidtype_heroui.Date_field +module Date_range_picker = Solidtype_heroui.Date_range_picker +module Label = Solidtype_heroui.Label +module Range_calendar = Solidtype_heroui.Range_calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Field_error = Solidtype_heroui.Field_error + +let make () = + let value, set_value = S.create_signal None in + let current = D.today (D.get_local_time_zone ()) in + let is_invalid () = + match S.get value with + | Some ({ start; end_ } : Date.t Date_range_picker.range) -> + Date.compare start current < 0. || Date.compare end_ start < 0. + | None -> false + in + + + + + (fun segment -> ) + + + + (fun segment -> ) + + + + + + + + "Select a valid range starting today or later." + + + + + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + + + + diff --git a/docs/islands/heroui_react.ml b/docs/islands/heroui_react.ml index c862a7b7..360cf77b 100644 --- a/docs/islands/heroui_react.ml +++ b/docs/islands/heroui_react.ml @@ -366,6 +366,53 @@ external time_field : Dom.htmlDivElement -> time_field_props -> unit = "timeField" [@@mel.module "./react/heroui.tsx"] +type date_field_props + +external date_field_props : + variant:string -> is_disabled:bool -> unit -> date_field_props = "" +[@@mel.obj] + +external date_field : Dom.htmlDivElement -> date_field_props -> unit + = "dateField" +[@@mel.module "./react/heroui.tsx"] + +type date_picker_props + +external date_picker_props : is_disabled:bool -> unit -> date_picker_props = "" +[@@mel.obj] + +external date_picker : Dom.htmlDivElement -> date_picker_props -> unit + = "datePicker" +[@@mel.module "./react/heroui.tsx"] + +type date_range_picker_props + +external date_range_picker_props : + is_disabled:bool -> unit -> date_range_picker_props = "" +[@@mel.obj] + +external date_range_picker : + Dom.htmlDivElement -> date_range_picker_props -> unit = "dateRangePicker" +[@@mel.module "./react/heroui.tsx"] + +type range_calendar_props + +external range_calendar_props : is_disabled:bool -> unit -> range_calendar_props + = "" +[@@mel.obj] + +external range_calendar : Dom.htmlDivElement -> range_calendar_props -> unit + = "rangeCalendar" +[@@mel.module "./react/heroui.tsx"] + +type calendar_props + +external calendar_props : is_disabled:bool -> unit -> calendar_props = "" +[@@mel.obj] + +external calendar : Dom.htmlDivElement -> calendar_props -> unit = "calendar" +[@@mel.module "./react/heroui.tsx"] + type progress_circle_props external progress_circle_props : diff --git a/docs/islands/range_calendar_anchor_unavailable.mlx b/docs/islands/range_calendar_anchor_unavailable.mlx new file mode 100644 index 00000000..aa6dbadd --- /dev/null +++ b/docs/islands/range_calendar_anchor_unavailable.mlx @@ -0,0 +1,41 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Description = Solidtype_heroui.Description + +(* Once a start is chosen, only the days within a week of it may end the + range. *) +let is_date_unavailable d anchor = + match anchor with + | Some a -> abs_float (Date.compare d a) > 7. + | None -> false + +let make () = +
+ + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + "After selecting a start date, only dates within 7 days are available" + +
diff --git a/docs/islands/range_calendar_booking.mlx b/docs/islands/range_calendar_booking.mlx new file mode 100644 index 00000000..0d13ad86 --- /dev/null +++ b/docs/islands/range_calendar_booking.mlx @@ -0,0 +1,74 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Button = Solidtype_heroui.Button + +let blocked_dates = [ 5; 6; 12; 13; 14; 20 ] +let weekend date = D.is_weekend date "en-GB" + +let make () = + let selected, set_selected = S.create_signal None in + let is_date_unavailable date _ = + weekend date || List.mem (Date.day date) blocked_dates + in +
+ + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> + + (fun (cell : Range_calendar.cell) -> + let d = S.get date in + Jsx.fragment + [| + Jsx.string (S.get cell.formatted_date); + (if + (not (S.get cell.is_unavailable)) + && (not (weekend d)) + && List.mem (Date.day d) blocked_dates + then + else Jsx.nothing); + |]) + ) + + + +
+
+ + "Blocked dates" + + + "Weekend/Unavailable" + +
+ + (fun r -> + ) + +
+
diff --git a/docs/islands/range_calendar_controlled.mlx b/docs/islands/range_calendar_controlled.mlx new file mode 100644 index 00000000..c8b19070 --- /dev/null +++ b/docs/islands/range_calendar_controlled.mlx @@ -0,0 +1,105 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Description = Solidtype_heroui.Description +module Button = Solidtype_heroui.Button +module Button_group = Solidtype_heroui.Button_group + +let today () = D.today (D.get_local_time_zone ()) + +(* The start of the week holding [d], Monday first, as en-GB counts. *) +let start_of_week d = + Date.subtract d + (D.Types.DateDuration.make ~days:(D.get_day_of_week d "en-GB" ()) ()) + +let start_of_month d = Date.set d (D.Types.DateFields.make ~day:1 ()) + +let make () = + let value, set_value = S.create_signal None in + let focused, set_focused = S.create_signal (D.parse_date "2025-12-25") in + let set_range start end_ = + S.set set_value (Some { Range_calendar.start; end_ }); + S.set set_focused start + in +
+ + + + + + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + (Jsx.string + ("Selected range: " + ^ + match S.get value with + | Some r -> + Date.to_string r.start () ^ " -> " ^ Date.to_string r.end_ () + | None -> "(none)")) + +
+ + + +
+
diff --git a/docs/islands/range_calendar_day_view.mlx b/docs/islands/range_calendar_day_view.mlx new file mode 100644 index 00000000..d2a57275 --- /dev/null +++ b/docs/islands/range_calendar_day_view.mlx @@ -0,0 +1,62 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box +module Select = Solidtype_heroui.Select + +let options = + [| + ("1", "1 day"); + ("5", "5 days"); + ("7", "7 days"); + ("8", "8 days"); + ("10", "10 days"); + ("14", "14 days"); + ("21", "21 days"); + |] + +let make () = + let count, set_count = S.create_signal 5 in +
+ + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + +
diff --git a/docs/islands/range_calendar_default_value.mlx b/docs/islands/range_calendar_default_value.mlx new file mode 100644 index 00000000..f4e43226 --- /dev/null +++ b/docs/islands/range_calendar_default_value.mlx @@ -0,0 +1,30 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate + +let make () = + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + diff --git a/docs/islands/range_calendar_demo.mlx b/docs/islands/range_calendar_demo.mlx new file mode 100644 index 00000000..5842a7a8 --- /dev/null +++ b/docs/islands/range_calendar_demo.mlx @@ -0,0 +1,50 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar +module I18n = Solidtype_kobalte.I18n +module Toggle = Controls.Toggle +module D = Solidtype_internationalized_date + +let make () = + let disabled, set_disabled = S.create_signal false in +
+
+ +
+ + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + ) + react=(fun host -> + Heroui_react.range_calendar host + (Heroui_react.range_calendar_props ~is_disabled:(S.get disabled) + ())) + /> +
diff --git a/docs/islands/range_calendar_disabled.mlx b/docs/islands/range_calendar_disabled.mlx new file mode 100644 index 00000000..235c4b0c --- /dev/null +++ b/docs/islands/range_calendar_disabled.mlx @@ -0,0 +1,27 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar +module Description = Solidtype_heroui.Description + +let make () = +
+ + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + "Range calendar is disabled" +
diff --git a/docs/islands/range_calendar_focused_value.mlx b/docs/islands/range_calendar_focused_value.mlx new file mode 100644 index 00000000..acb13633 --- /dev/null +++ b/docs/islands/range_calendar_focused_value.mlx @@ -0,0 +1,56 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Description = Solidtype_heroui.Description +module Button = Solidtype_heroui.Button + +let make () = + let focused, set_focused = S.create_signal (D.parse_date "2025-06-15") in +
+ + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + (Jsx.string ("Focused: " ^ Date.to_string (S.get focused) ())) + +
+ + + +
+
diff --git a/docs/islands/range_calendar_indicators.mlx b/docs/islands/range_calendar_indicators.mlx new file mode 100644 index 00000000..b4b37215 --- /dev/null +++ b/docs/islands/range_calendar_indicators.mlx @@ -0,0 +1,40 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate + +let dates_with_events = [ 3; 7; 12; 15; 21; 28 ] + +let make () = + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> + + (fun (cell : Range_calendar.cell) -> + let d = S.get date in + Jsx.fragment + [| + Jsx.string (S.get cell.formatted_date); + (if + D.is_today d (D.get_local_time_zone ()) + || List.mem (Date.day d) dates_with_events + then + else Jsx.nothing); + |]) + ) + + + diff --git a/docs/islands/range_calendar_international.mlx b/docs/islands/range_calendar_international.mlx new file mode 100644 index 00000000..bf065be2 --- /dev/null +++ b/docs/islands/range_calendar_international.mlx @@ -0,0 +1,32 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar +module I18n = Solidtype_kobalte.I18n + +let make () = + + + + + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + + + diff --git a/docs/islands/range_calendar_invalid.mlx b/docs/islands/range_calendar_invalid.mlx new file mode 100644 index 00000000..d923531d --- /dev/null +++ b/docs/islands/range_calendar_invalid.mlx @@ -0,0 +1,48 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Description = Solidtype_heroui.Description + +let make () = + let now = D.today (D.get_local_time_zone ()) in + let after n = Date.add now (D.Types.DateDuration.make ~days:n ()) in + let value, set_value = + S.create_signal { Range_calendar.start = after 6; end_ = after 14 } + in + let too_long () = + let r = S.get value in + Date.compare r.end_ r.start > 7. + in +
+ + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + (if too_long () then +

"Maximum stay duration is 1 week"

+ else + + "Select a stay of up to 7 days" + ) +
diff --git a/docs/islands/range_calendar_min_max.mlx b/docs/islands/range_calendar_min_max.mlx new file mode 100644 index 00000000..a6ef3f48 --- /dev/null +++ b/docs/islands/range_calendar_min_max.mlx @@ -0,0 +1,35 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Description = Solidtype_heroui.Description + +let make () = + let now = D.today (D.get_local_time_zone ()) in + let max_date = Date.add now (D.Types.DateDuration.make ~months:3 ()) in +
+ + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + (Jsx.string + ("Select a date between today and " ^ Date.to_string max_date ())) + +
diff --git a/docs/islands/range_calendar_multiple_months.mlx b/docs/islands/range_calendar_multiple_months.mlx new file mode 100644 index 00000000..0a7c5265 --- /dev/null +++ b/docs/islands/range_calendar_multiple_months.mlx @@ -0,0 +1,50 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar + +let make () = + +
+
+ + + +
+ + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + +
+
+ +
+ + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + +
+
+ diff --git a/docs/islands/range_calendar_non_contiguous.mlx b/docs/islands/range_calendar_non_contiguous.mlx new file mode 100644 index 00000000..5cee4002 --- /dev/null +++ b/docs/islands/range_calendar_non_contiguous.mlx @@ -0,0 +1,51 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Description = Solidtype_heroui.Description + +let now () = D.today (D.get_local_time_zone ()) +let days n = D.Types.DateDuration.make ~days:n () + +(* Days two to five from today, and twelve and thirteen, are booked. *) +let is_date_unavailable d _ = + let n = now () in + List.exists + (fun (a, b) -> + Date.compare d (Date.add n (days a)) >= 0. + && Date.compare d (Date.add n (days b)) <= 0.) + [ (2, 5); (12, 13) ] + +let make () = +
+ + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + "Non-contiguous ranges are allowed across unavailable dates" + +
diff --git a/docs/islands/range_calendar_read_only.mlx b/docs/islands/range_calendar_read_only.mlx new file mode 100644 index 00000000..29a47234 --- /dev/null +++ b/docs/islands/range_calendar_read_only.mlx @@ -0,0 +1,39 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Description = Solidtype_heroui.Description + +let make () = +
+ + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + "Range calendar is read-only" + +
diff --git a/docs/islands/range_calendar_tailwind.mlx b/docs/islands/range_calendar_tailwind.mlx new file mode 100644 index 00000000..a1a52d53 --- /dev/null +++ b/docs/islands/range_calendar_tailwind.mlx @@ -0,0 +1,65 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar +module D = Solidtype_internationalized_date + +let cell_class = + String.concat " " + [ + "rounded-md"; + "**:data-[slot=range-calendar-cell-button]:rounded-md"; + "data-[outside-month=true]:text-muted \ + data-[outside-month=true]:opacity-50"; + "data-[hovered=true]:not-data-[selected=true]:**:data-[slot=range-calendar-cell-button]:bg-default"; + "data-[today=true]:**:data-[slot=range-calendar-cell-button]:bg-success-soft"; + "data-[today=true]:**:data-[slot=range-calendar-cell-button]:text-success-soft-foreground"; + "data-[today=true]:data-[hovered=true]:not-data-[selected=true]:**:data-[slot=range-calendar-cell-button]:bg-success-soft-hover"; + "data-[selected=true]:rounded-none data-[selected=true]:bg-success-soft"; + "data-[outside-month=true]:data-[selected=true]:bg-default/20"; + "data-[selection-start=true]:rounded-tl-md \ + data-[selection-start=true]:rounded-bl-md"; + "data-[selection-end=true]:rounded-tr-md \ + data-[selection-end=true]:rounded-br-md"; + "data-[selection-start=true]:**:data-[slot=range-calendar-cell-button]:bg-success"; + "data-[selection-start=true]:**:data-[slot=range-calendar-cell-button]:text-success-foreground"; + "data-[selection-start=true]:data-[pressed=true]:**:data-[slot=range-calendar-cell-button]:bg-success-hover"; + "data-[selection-end=true]:**:data-[slot=range-calendar-cell-button]:bg-success"; + "data-[selection-end=true]:**:data-[slot=range-calendar-cell-button]:text-success-foreground"; + "data-[selection-end=true]:data-[pressed=true]:**:data-[slot=range-calendar-cell-button]:bg-success-hover"; + ] + +let make () = + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> + ) + + + diff --git a/docs/islands/range_calendar_unavailable.mlx b/docs/islands/range_calendar_unavailable.mlx new file mode 100644 index 00000000..546f64c7 --- /dev/null +++ b/docs/islands/range_calendar_unavailable.mlx @@ -0,0 +1,48 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar +module D = Solidtype_internationalized_date +module Date = D.Types.CalendarDate +module Description = Solidtype_heroui.Description + +let now () = D.today (D.get_local_time_zone ()) +let days n = D.Types.DateDuration.make ~days:n () + +(* Days two to five from today, and twelve and thirteen, are booked. *) +let is_date_unavailable d _ = + let n = now () in + List.exists + (fun (a, b) -> + Date.compare d (Date.add n (days a)) >= 0. + && Date.compare d (Date.add n (days b)) <= 0.) + [ (2, 5); (12, 13) ] + +let make () = +
+ + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + "Some days are unavailable" +
diff --git a/docs/islands/range_calendar_usage.mlx b/docs/islands/range_calendar_usage.mlx new file mode 100644 index 00000000..d2152bb4 --- /dev/null +++ b/docs/islands/range_calendar_usage.mlx @@ -0,0 +1,23 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar + +let make () = + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + diff --git a/docs/islands/range_calendar_week_view.mlx b/docs/islands/range_calendar_week_view.mlx new file mode 100644 index 00000000..446e9d19 --- /dev/null +++ b/docs/islands/range_calendar_week_view.mlx @@ -0,0 +1,63 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box +module Select = Solidtype_heroui.Select + +let options = + [| + ("1", "1 week"); + ("2", "2 weeks"); + ("3", "3 weeks"); + ("4", "4 weeks"); + ("5", "5 weeks"); + ("6", "6 weeks"); + ("8", "8 weeks"); + |] + +let make () = + let count, set_count = S.create_signal 1 in +
+ + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + +
diff --git a/docs/islands/range_calendar_weeks_in_month.mlx b/docs/islands/range_calendar_weeks_in_month.mlx new file mode 100644 index 00000000..dee6a9e8 --- /dev/null +++ b/docs/islands/range_calendar_weeks_in_month.mlx @@ -0,0 +1,29 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar +module Description = Solidtype_heroui.Description + +let make () = +
+ + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + "Always shows 6 weeks per month to avoid layout shift when navigating" + +
diff --git a/docs/islands/range_calendar_year_picker.mlx b/docs/islands/range_calendar_year_picker.mlx new file mode 100644 index 00000000..b7491ab9 --- /dev/null +++ b/docs/islands/range_calendar_year_picker.mlx @@ -0,0 +1,29 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Range_calendar = Solidtype_heroui.Range_calendar + +let make () = + + + + + + + + + + + + (fun day -> + + (Jsx.string (S.get day)) + ) + + + (fun date -> ) + + + + + + diff --git a/docs/islands/react/heroui.tsx b/docs/islands/react/heroui.tsx index 15855bca..b512cfe7 100644 --- a/docs/islands/react/heroui.tsx +++ b/docs/islands/react/heroui.tsx @@ -2,7 +2,9 @@ // OCaml page owns, beside each port: the one place React runs. Each render // is flushed at once, so the page reads the result in the same effect. -import { Accordion, Alert, AlertDialog, Autocomplete, Avatar, AvatarGroup, Badge, Breadcrumbs, Button, ButtonGroup, Card, Checkbox, CheckboxGroup, Chip, CloseButton, ColorArea, ColorField, ColorPicker, ColorSlider, ColorSwatch, ColorSwatchPicker, ComboBox, Description, Disclosure, DisclosureGroup, Drawer, Dropdown, FieldError, Fieldset, Input, InputGroup, Kbd, Label, Link, ListBox, Meter, Modal, NumberField, Pagination, Popover, ProgressBar, ProgressCircle, Radio, RadioGroup, ScrollShadow, SearchField, Select, Separator, Skeleton, Slider, Spinner, Surface, Switch, Table, Tabs, Tag, TagGroup, TextField, TimeField, ToggleButton, ToggleButtonGroup, Tooltip, Typography, useFilter } from "@heroui/react"; +import { CalendarDate } from "@internationalized/date"; +import { I18nProvider } from "react-aria-components"; +import { Accordion, Alert, AlertDialog, Autocomplete, Avatar, AvatarGroup, Badge, Breadcrumbs, Button, ButtonGroup, Calendar, Card, Checkbox, CheckboxGroup, Chip, CloseButton, ColorArea, ColorField, ColorPicker, ColorSlider, ColorSwatch, ColorSwatchPicker, ComboBox, DateField, DatePicker, DateRangePicker, Description, Disclosure, DisclosureGroup, Drawer, Dropdown, FieldError, Fieldset, Input, InputGroup, Kbd, Label, Link, ListBox, Meter, Modal, NumberField, Pagination, Popover, ProgressBar, ProgressCircle, Radio, RangeCalendar, RadioGroup, ScrollShadow, SearchField, Select, Separator, Skeleton, Slider, Spinner, Surface, Switch, Table, Tabs, Tag, TagGroup, TextField, TimeField, ToggleButton, ToggleButtonGroup, Tooltip, Typography, useFilter } from "@heroui/react"; import { useState } from "react"; import { flushSync } from "react-dom"; import { createRoot, type Root } from "react-dom/client"; @@ -526,6 +528,150 @@ export function timeField(host: HTMLElement, { variant, is_disabled }: TimeField ); } +type DateFieldProps = { + variant: "primary" | "secondary"; + is_disabled: boolean; +}; + +export function dateField(host: HTMLElement, { variant, is_disabled }: DateFieldProps): void { + flushSync(() => + rootOf(host).render( + + + + {(segment) => } + + , + ), + ); +} + +type DatePickerProps = { is_disabled: boolean }; + +export function datePicker(host: HTMLElement, { is_disabled }: DatePickerProps): void { + flushSync(() => + rootOf(host).render( + + + + + {(segment) => } + + + + + + + + + + + + + + + {(day) => {day}} + {(date) => } + + + + + , + ), + ); +} + +type DateRangePickerProps = { is_disabled: boolean }; + +export function dateRangePicker(host: HTMLElement, { is_disabled }: DateRangePickerProps): void { + flushSync(() => + rootOf(host).render( + + + + + {(segment) => } + + {(segment) => } + + + + + + + + + + + + + + + {(day) => {day}} + {(date) => } + + + + + , + ), + ); +} + +type RangeCalendarProps = { is_disabled: boolean }; + +export function rangeCalendar(host: HTMLElement, { is_disabled }: RangeCalendarProps): void { + flushSync(() => + rootOf(host).render( + + + + + + + + + {(day) => {day}} + {(date) => } + + + , + ), + ); +} + +type CalendarProps = { is_disabled: boolean }; + +export function calendar(host: HTMLElement, { is_disabled }: CalendarProps): void { + flushSync(() => + rootOf(host).render( + + + + + + + + + {(day) => {day}} + {(date) => } + + + , + ), + ); +} + type ProgressCircleProps = { color: "default" | "accent" | "success" | "warning" | "danger"; size: "sm" | "md" | "lg"; diff --git a/docs/src/content/docs/heroui/calendar.mdx b/docs/src/content/docs/heroui/calendar.mdx new file mode 100644 index 00000000..2645a1e2 --- /dev/null +++ b/docs/src/content/docs/heroui/calendar.mdx @@ -0,0 +1,303 @@ +--- +title: Calendar +description: Composable date picker with month grid, navigation, and year picker support. +--- + +import Example from "@components/Example.astro"; +import * as ExUsage from "@islands/calendar_usage.jsx"; +import ExUsageCode from "@islands/calendar_usage.mlx?raw"; +import * as ExDisabled from "@islands/calendar_disabled.jsx"; +import ExDisabledCode from "@islands/calendar_disabled.mlx?raw"; +import * as ExReadOnly from "@islands/calendar_read_only.jsx"; +import ExReadOnlyCode from "@islands/calendar_read_only.mlx?raw"; +import * as ExDefaultValue from "@islands/calendar_default_value.jsx"; +import ExDefaultValueCode from "@islands/calendar_default_value.mlx?raw"; +import * as ExYearPicker from "@islands/calendar_year_picker.jsx"; +import ExYearPickerCode from "@islands/calendar_year_picker.mlx?raw"; +import * as ExControlled from "@islands/calendar_controlled.jsx"; +import ExControlledCode from "@islands/calendar_controlled.mlx?raw"; +import * as ExMinMax from "@islands/calendar_min_max.jsx"; +import ExMinMaxCode from "@islands/calendar_min_max.mlx?raw"; +import * as ExUnavailable from "@islands/calendar_unavailable.jsx"; +import ExUnavailableCode from "@islands/calendar_unavailable.mlx?raw"; +import * as ExWeeksInMonth from "@islands/calendar_weeks_in_month.jsx"; +import ExWeeksInMonthCode from "@islands/calendar_weeks_in_month.mlx?raw"; +import * as ExWeekView from "@islands/calendar_week_view.jsx"; +import ExWeekViewCode from "@islands/calendar_week_view.mlx?raw"; +import * as ExDayView from "@islands/calendar_day_view.jsx"; +import ExDayViewCode from "@islands/calendar_day_view.mlx?raw"; +import * as ExMultiple from "@islands/calendar_multiple.jsx"; +import ExMultipleCode from "@islands/calendar_multiple.mlx?raw"; +import * as ExFocusedValue from "@islands/calendar_focused_value.jsx"; +import ExFocusedValueCode from "@islands/calendar_focused_value.mlx?raw"; +import * as ExIndicators from "@islands/calendar_indicators.jsx"; +import ExIndicatorsCode from "@islands/calendar_indicators.mlx?raw"; +import * as ExCustomIcons from "@islands/calendar_custom_icons.jsx"; +import ExCustomIconsCode from "@islands/calendar_custom_icons.mlx?raw"; +import * as ExMultipleMonths from "@islands/calendar_multiple_months.jsx"; +import ExMultipleMonthsCode from "@islands/calendar_multiple_months.mlx?raw"; +import * as ExBooking from "@islands/calendar_booking.jsx"; +import ExBookingCode from "@islands/calendar_booking.mlx?raw"; +import * as ExInternational from "@islands/calendar_international.jsx"; +import ExInternationalCode from "@islands/calendar_international.mlx?raw"; +import * as ExTailwind from "@islands/calendar_tailwind.jsx"; +import ExTailwindCode from "@islands/calendar_tailwind.mlx?raw"; +import * as Demo from "@islands/calendar_demo.jsx"; + +Its value is a `CalendarDate` of `solidtype-internationalized-date`, made by +`CalendarDate.make 2026 11 21`, `parse_date "2026-11-21"` or `today zone`; +several dates are `Calendar.Multiple`'s. + +Its weeks start on Monday and its days are written as `en-GB` writes them, +whatever the browser reads, unless an `I18n.I18nProvider` names another +locale. React's follows the browser. + +Original HeroUI documentation: [Calendar](https://heroui.com/en/docs/react/components/calendar). + +## Usage + + + +## Parity + +The same HeroUI Calendar twice, under the same props: in solidtype on the +left, in React on the right. Below them, every attribute of the two calendars: +a marked row is one they disagree on. + +
+ +
+ +## Anatomy + +```ocaml + + + + + + + + + (fun day -> (Jsx.string (S.get day))) + + + (fun date -> ) + + + +``` + +## Examples + +### Disabled + + + +### Read Only + +A press on a day of a read-only calendar focuses it, and the arrows move on +from it. + + + +### Default Value + + + +### Year Picker + +`Calendar.Year_picker_trigger`, `Calendar.Year_picker_grid`, and their body +and cell parts provide an integrated year navigation pattern. + + + +### Controlled + +Use controlled `value` and `focused_value` for external state coordination +and custom shortcuts. + + + +### Min and Max Dates + + + +### Unavailable Dates + +Use `is_date_unavailable` to block dates such as weekends, holidays, or +booked slots. A press on an unavailable day focuses it without choosing it. + + + +### Weeks in Month + +Set `weeks_in_month` to a fixed value, for example `6`, to keep the grid's +height as months change. + + + +### Week View + +`` visible_duration=(Calendar.Weeks n) `` shows one or more weeks at a time, +and its buttons page by them; `` page_behavior=`single `` pages a week at a +time. Its grid is named by the days it shows. + + + +### Day View + +`` visible_duration=(Calendar.Days n) `` shows a run of days, and its buttons +page by them; `` page_behavior=`single `` pages a day at a time. + + + +### Multiple Selection + +`Calendar.Multiple` chooses several dates: its `value`, `default_value` and +`on_change` are arrays. + + + +### Focused Value + +`focused_value` and `on_focus_change` control which date is focused. + + + +### Cell Indicators + +`Calendar.Cell`'s children are drawn of its state, and +`Calendar.Cell_indicator` marks a day. + + + +### Custom Navigation Icons + +Children of `Calendar.Nav_button` replace the chevrons. + + + +### Multiple Months + +`visible_duration` and `offset` show several months side by side. + + + +### Real-World Example + + + +### International Calendars + +An `I18n.I18nProvider` locale with a calendar extension shows that calendar; +`on_change` gives a date in the calendar of the value given, else the +Gregorian. + + + +## Customization + +### Tailwind CSS + +`class_` is added after HeroUI's classes. + + + +## Styling Reference + +HeroUI follows the [BEM](https://bem.info/en/methodology/) methodology to +ensure component variants and states are reusable and easy to customize. + +### CSS Classes + +- `.calendar` - Root container. +- `.calendar--week-view`, `.calendar--day-view` - A week's or a day's view. +- `.calendar__header` - Header row containing nav buttons and heading. +- `.calendar__heading` - Current month label. +- `.calendar__nav-button` - Previous/next navigation controls. +- `.calendar__grid` - Main day grid. +- `.calendar__grid-header` - Weekday header row wrapper. +- `.calendar__grid-body` - Date rows wrapper. +- `.calendar__header-cell` - Weekday header cell. +- `.calendar__cell` - Interactive day cell. +- `.calendar__cell-indicator` - Dot indicator inside a day cell. +- `.calendar-year-picker__trigger` - Year picker toggle button. +- `.calendar-year-picker__trigger-heading` - Heading text inside year picker trigger. +- `.calendar-year-picker__trigger-indicator` - Indicator icon inside year picker trigger. +- `.calendar-year-picker__year-grid` - Overlay grid of selectable years. +- `.calendar-year-picker__year-cell` - Individual year option. + +### Interactive States + +- **Selected**: `[data-selected="true"]` +- **Today**: `[data-today="true"]` +- **Unavailable**: `[data-unavailable="true"]` +- **Outside month**: `[data-outside-month="true"]` +- **Hovered**: `[data-hovered="true"]` +- **Pressed**: `[data-pressed="true"]` +- **Focus visible**: `[data-focus-visible="true"]` +- **Disabled**: `[data-disabled="true"]` + +## API Reference + +Each prop beside the name HeroUI's React component gives it. + +### Calendar + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `value` | `value` | `CalendarDate.t Js.Nullable.t` | | Controlled selected date; null controls it empty | +| `defaultValue` | `default_value` | `CalendarDate.t` | | Initial selected date (uncontrolled) | +| `onChange` | `on_change` | `CalendarDate.t -> unit` | | Called when a date is chosen | +| `selectionMode` | — | | | `Calendar.Multiple` chooses several dates | +| `focusedValue` | `focused_value` | `CalendarDate.t` | | Controlled focused date | +| `defaultFocusedValue` | `default_focused_value` | `CalendarDate.t` | its value, else today | Initial focused date | +| `onFocusChange` | `on_focus_change` | `CalendarDate.t -> unit` | | Called when focus moves to another date | +| `minValue` | `min_value` | `CalendarDate.t` | 1900-01-01 in its calendar | Earliest selectable date | +| `maxValue` | `max_value` | `CalendarDate.t` | 2099-12-31 in its calendar | Latest selectable date | +| `weeksInMonth` | `weeks_in_month` | `int` | the month's | The number of weeks in a month's grid | +| `isDateUnavailable` | `is_date_unavailable` | `CalendarDate.t -> bool` | | Marks dates as unavailable | +| `firstDayOfWeek` | `first_day_of_week` | `` [ `sun \| `mon \| `tue \| `wed \| `thu \| `fri \| `sat ] `` | the locale's | The first day of its weeks | +| `pageBehavior` | `page_behavior` | `` [ `visible \| `single ] `` | `` `visible `` | Whether paging moves by what is shown or by one unit | +| `selectionAlignment` | `selection_alignment` | `` [ `start \| `center \| `end_ ] `` | `` `center `` | Where the focused date stands in what is shown at first | +| `isDisabled` | `is_disabled` | `bool` | `false` | Disables interaction and selection | +| `isReadOnly` | `is_read_only` | `bool` | `false` | Days are focused but not chosen | +| `isInvalid` | `is_invalid` | `bool` | `false` | Marks the calendar as invalid | +| `visibleDuration` | `visible_duration` | `Calendar.duration` | `Months 1` | `Months n`, `Weeks n` or `Days n` | +| `defaultYearPickerOpen` | `default_year_picker_open` | `bool` | `false` | Initial open state of the year picker | +| `isYearPickerOpen` | `is_year_picker_open` | `bool` | | Controlled open state of the year picker | +| `onYearPickerOpenChange` | `on_year_picker_open_change` | `bool -> unit` | | Called when the year picker opens or closes | +| `aria-label` | `aria_label` | `string` | | Its name, beside the dates it shows | +| `className` | `class_` | `string` | | Added after HeroUI's classes | + +### Composition Parts + +| React | solidtype | Description | +|---|---|---| +| `Calendar.Header` | `Calendar.Header` | Header container for navigation and heading | +| `Calendar.Heading` | `Calendar.Heading` | The dates shown; `offset` and `format` | +| `Calendar.NavButton` | `Calendar.Nav_button` | `` slot=`previous `` or `` slot=`next `` | +| `Calendar.Grid` | `Calendar.Grid` | Day grid for one month; `offset` and `weekday_style` | +| `Calendar.GridHeader` | `Calendar.Grid_header` | Weekday header, a function of each day's name | +| `Calendar.GridBody` | `Calendar.Grid_body` | Date cells, a function of each date | +| `Calendar.HeaderCell` | `Calendar.Header_cell` | Weekday label cell | +| `Calendar.Cell` | `Calendar.Cell` | A day, its children drawn of its state | +| `Calendar.CellIndicator` | `Calendar.Cell_indicator` | A dot marking a day | +| `Calendar.YearPickerTrigger` | `Calendar.Year_picker_trigger` | Opens and closes the year picker | +| `Calendar.YearPickerTriggerHeading` | `Calendar.Year_picker_trigger_heading` | The month shown, in the trigger | +| `Calendar.YearPickerTriggerIndicator` | `Calendar.Year_picker_trigger_indicator` | The trigger's chevron | +| `Calendar.YearPickerGrid` | `Calendar.Year_picker_grid` | The years; `format` and `visible_years` | +| `Calendar.YearPickerGridBody` | `Calendar.Year_picker_grid_body` | The years' cells, or a function of each year | +| `Calendar.YearPickerCell` | `Calendar.Year_picker_cell` | A year | + +### Calendar.Cell's state + +| React | solidtype | Type | Description | +|---|---|---|---| +| `formattedDate` | `formatted_date` | `string S.accessor` | Its day of the month | +| `isSelected` | `is_selected` | `bool S.accessor` | Whether the date is chosen | +| `isUnavailable` | `is_unavailable` | `bool S.accessor` | Whether the date is unavailable | +| `isDisabled` | `is_disabled` | `bool S.accessor` | Whether the cell is disabled | +| `isOutsideMonth` | `is_outside_month` | `bool S.accessor` | Whether the date belongs to another month | +| `isToday` | `is_today` | `bool S.accessor` | Whether the date is today | diff --git a/docs/src/content/docs/heroui/coverage.mdx b/docs/src/content/docs/heroui/coverage.mdx index 1cf7327a..52f76754 100644 --- a/docs/src/content/docs/heroui/coverage.mdx +++ b/docs/src/content/docs/heroui/coverage.mdx @@ -18,6 +18,7 @@ shows it beside the same component in React. | [Breadcrumbs](/solidtype/heroui/breadcrumbs/) | ported: the last item the page, prerendered so too, disabled whole or an item at a time, a separator of its own, an item's press told by its id | | [Button](/solidtype/heroui/button/) | ported: variants, sizes, full width, icon only, disabled | | [ButtonGroup](/solidtype/heroui/button-group/) | ported: variants, sizes, orientations, full width, disabled, separator | +| [Calendar](/solidtype/heroui/calendar/) | ported: one date or several, controlled or kept, the focused date controlled or kept, in the locale's order, first day and calendar; moved through by the keys and paged by its buttons, a page or a unit at a time; a month, weeks or days shown, several months side by side, a fixed number of weeks; min and max and unavailable days, disabled, read-only, invalid; its year picker; cell indicators, custom navigation icons | | [Card](/solidtype/heroui/card/) | ported: variants, header, title, description, content, footer, as a surface | | [Checkbox](/solidtype/heroui/checkbox/) | ported: variants, selected, indeterminate, disabled, invalid, interaction state | | [CheckboxGroup](/solidtype/heroui/checkbox-group/) | ported: values controlled or kept, variants, disabled, invalid, read-only, required, its label and descriptions | @@ -30,6 +31,9 @@ shows it beside the same component in React. | [ColorSwatch](/solidtype/heroui/color-swatch/) | ported: sizes, shapes, a colour less than opaque over a checkerboard, its name given or Kobalte's, style | | [ColorSwatchPicker](/solidtype/heroui/color-swatch-picker/) | ported: a palette chosen from by a press or the keys, in a grid by where each swatch is or a stack, value controlled or kept, sizes, variants, layouts, disabled swatches, the checkmark or an indicator given, black over a light colour | | [ComboBox](/solidtype/heroui/combo-box/) | ported: one or many chosen, controlled or kept, its text controlled or kept, filtered as typed or by a filter given, opened by focus, typing or only its trigger, custom values, its list a ListBox, sections, disabled options, its value listed, variants, full width, disabled, read-only, label, description and error, a form sent its ids or its text, its list's empty state while nothing matches | +| [DateField](/solidtype/heroui/date-field/) | ported: a date, a date with a time and one in a zone, each given back as its kind, in the reader's locale's order and calendar; typed, stepped by the keys, erased, a date that is none made one as focus leaves; value controlled or kept, placeholder, granularity, hour cycle, leading zeros, its zone shown or hidden, min and max and unavailable days, variants, full width, prefix and suffix, disabled, read-only, required, invalid, label, description and error, a form sent its value whole | +| [DatePicker](/solidtype/heroui/date-picker/) | ported: a date field whose trigger opens a calendar in a popover, of a date, a date with a time or one in a zone, the time kept as a day is chosen and drawn in the popover from its state; controlled or kept, open controlled or kept, closed on a day chosen unless not; disabled, read-only, required, invalid and validated in a form; a custom indicator, render functions, international calendars | +| [DateRangePicker](/solidtype/heroui/date-range-picker/) | ported: a date field's group of a start and an end, whose trigger opens a range calendar in a popover, of dates, dates with times or ones in a zone, the times kept and drawn in the popover from its state; a range told once both ends are there, invalid with its end before its start; controlled or kept, open controlled or kept; disabled, read-only, required, invalid and validated in a form, each end sent by its name; a custom indicator, render functions, international calendars | | [Description](/solidtype/heroui/description/) | ported: standalone, and a radio group's, a radio's or a text field's | | [Disclosure](/solidtype/heroui/disclosure/) | ported: expanded controlled or kept, disabled, its own trigger or a button given its slot, indicator, content animated by its height and found by find in page | | [DisclosureGroup](/solidtype/heroui/disclosure-group/) | ported: one or several expanded, controlled or kept, disabled with a disclosure's own, navigation by previous and next | @@ -54,6 +58,7 @@ shows it beside the same component in React. | [ProgressBar](/solidtype/heroui/progress-bar/) | ported: value within a range, indeterminate, colors, sizes, output, format options | | [ProgressCircle](/solidtype/heroui/progress-circle/) | ported: value within a range, indeterminate, colors, sizes, format options, a circle of any size its arc measured on its own radius | | [Radio Group](/solidtype/heroui/radio-group/) | ported: variants, orientations, controlled, disabled, invalid, descriptions, interaction state | +| [RangeCalendar](/solidtype/heroui/range-calendar/) | ported: a range begun by a press or Enter and shown to the day hovered or focused, ended by a second; chosen by a drag, an end moved by one; let go by Escape, and ended as `commit_behavior` says; reaching no further than an unavailable day unless non-contiguous, its predicate given the range's anchor; controlled or kept, min and max, disabled, read-only, invalid; weeks or days shown, several months side by side; its year picker; cell indicators | | [ScrollShadow](/solidtype/heroui/scroll-shadow/) | ported: orientations, sizes, offset, visibility given or measured, hidden scrollbar | | [SearchField](/solidtype/heroui/search-field/) | ported: query controlled or kept, cleared by Escape or its button, submitted by Enter, variants, disabled, invalid | | [Select](/solidtype/heroui/select/) | ported: one or many chosen, controlled or kept, its list a ListBox, placeholder, value drawn as the option or by a function, clear button and Backspace, variants, full width, disabled, disabled options, sections, open controlled or kept, label, description and error, a form's errors; required, its error the application's to show, as a text field's | @@ -78,13 +83,13 @@ shows it beside the same component in React. ## Not yet ported -These 7 components of HeroUI 3.2 are not ported yet; each name links to +These 2 components of HeroUI 3.2 are not ported yet; each name links to HeroUI's own page. What a ported component does not do yet is in its row above and on its page. | Group | Components | |---|---| -| Not yet ported | [Calendar](https://heroui.com/en/docs/react/components/calendar), [DateField](https://heroui.com/en/docs/react/components/date-field), [DatePicker](https://heroui.com/en/docs/react/components/date-picker), [DateRangePicker](https://heroui.com/en/docs/react/components/date-range-picker), [InputOTP](https://heroui.com/en/docs/react/components/input-otp), [RangeCalendar](https://heroui.com/en/docs/react/components/range-calendar), [Toolbar](https://heroui.com/en/docs/react/components/toolbar) | +| Not yet ported | [InputOTP](https://heroui.com/en/docs/react/components/input-otp), [Toolbar](https://heroui.com/en/docs/react/components/toolbar) | ## Beyond HeroUI's set diff --git a/docs/src/content/docs/heroui/date-field.mdx b/docs/src/content/docs/heroui/date-field.mdx new file mode 100644 index 00000000..ad52b9bf --- /dev/null +++ b/docs/src/content/docs/heroui/date-field.mdx @@ -0,0 +1,287 @@ +--- +title: DateField +description: Date input field with labels, descriptions, and validation. +--- + +import Example from "@components/Example.astro"; +import * as ExUsage from "@islands/date_field_usage.jsx"; +import ExUsageCode from "@islands/date_field_usage.mlx?raw"; +import * as ExPrefixIcon from "@islands/date_field_prefix_icon.jsx"; +import ExPrefixIconCode from "@islands/date_field_prefix_icon.mlx?raw"; +import * as ExSuffixIcon from "@islands/date_field_suffix_icon.jsx"; +import ExSuffixIconCode from "@islands/date_field_suffix_icon.mlx?raw"; +import * as ExPrefixSuffix from "@islands/date_field_prefix_suffix.jsx"; +import ExPrefixSuffixCode from "@islands/date_field_prefix_suffix.mlx?raw"; +import * as ExVariants from "@islands/date_field_variants.jsx"; +import ExVariantsCode from "@islands/date_field_variants.mlx?raw"; +import * as ExSurface from "@islands/date_field_surface.jsx"; +import ExSurfaceCode from "@islands/date_field_surface.mlx?raw"; +import * as ExDescription from "@islands/date_field_description.jsx"; +import ExDescriptionCode from "@islands/date_field_description.mlx?raw"; +import * as ExRequired from "@islands/date_field_required.jsx"; +import ExRequiredCode from "@islands/date_field_required.mlx?raw"; +import * as ExDisabled from "@islands/date_field_disabled.jsx"; +import ExDisabledCode from "@islands/date_field_disabled.mlx?raw"; +import * as ExFullWidth from "@islands/date_field_full_width.jsx"; +import ExFullWidthCode from "@islands/date_field_full_width.mlx?raw"; +import * as ExInvalid from "@islands/date_field_invalid.jsx"; +import ExInvalidCode from "@islands/date_field_invalid.mlx?raw"; +import * as ExGranularity from "@islands/date_field_granularity.jsx"; +import ExGranularityCode from "@islands/date_field_granularity.mlx?raw"; +import * as ExControlled from "@islands/date_field_controlled.jsx"; +import ExControlledCode from "@islands/date_field_controlled.mlx?raw"; +import * as ExZoned from "@islands/date_field_zoned.jsx"; +import ExZonedCode from "@islands/date_field_zoned.mlx?raw"; +import * as ExForm from "@islands/date_field_form.jsx"; +import ExFormCode from "@islands/date_field_form.mlx?raw"; +import * as ExWithValidation from "@islands/date_field_with_validation.jsx"; +import ExWithValidationCode from "@islands/date_field_with_validation.mlx?raw"; +import * as ExTailwind from "@islands/date_field_tailwind.jsx"; +import ExTailwindCode from "@islands/date_field_tailwind.mlx?raw"; +import * as Demo from "@islands/date_field_demo.jsx"; + +Its value is a `CalendarDate` of `solidtype-internationalized-date`, made by +`CalendarDate.make 2026 11 21`, `parse_date "2026-11-21"` or `today zone`; a +date with a time is `Date_field.Date_time`'s, and one in a zone +`Date_field.Zoned`'s. + +Its segments are day before month, `dd/mm/yyyy`, whatever the browser reads, +unless an `I18n.I18nProvider` names another locale: +`` gives `mm/dd/yyyy`. React's follows the +browser. + +Original HeroUI documentation: [DateField](https://heroui.com/en/docs/react/components/date-field). + +## Usage + + + +## Parity + +The same HeroUI DateField twice, under the same props: in solidtype on the +left, in React on the right. Below them, every attribute of the two fields: a +marked row is one they disagree on. + +
+ +
+ +## Anatomy + +```ocaml + + +``` + +`Date_field` combines label, date input, description, and error into a single +accessible component. + +## Examples + +### With Icons + +Add prefix or suffix icons to enhance the date field. + + + + + + + +### Variants + +`Date_field.Group` takes two variants: `` `primary ``, the default, with a +shadow, and `` `secondary ``, a lower emphasis without one, for a surface. + + + +### In Surface + +When used inside a [Surface](/solidtype/heroui/surface/) component, use +`` variant=`secondary `` on `Date_field.Group` to apply the lower emphasis +variant suitable for surface backgrounds. + + + +### With Description + + + +### Required Field + + + +### Disabled State + + + +### Full Width + + + +### Validation + +Use `is_invalid` together with `Field_error` to surface validation messages. + + + +### Granularity + +`granularity` is the smallest unit a field with a time shows, `` `minute `` by +default; `` `day `` shows the date alone. + + + +### Controlled + +Control the value to synchronize with other components or state management. + + + +### Times and Zones + +`Date_field.Date_time` and `Date_field.Zoned` edit a `CalendarDateTime` or a +`ZonedDateTime`, and give back the same kind. A zoned field needs a +`placeholder_value`, the zone a date typed while it is empty is in; it shows +the zone's name after the time, and its hour steps through an hour its clocks +repeat. The second field below is in Kyiv on the night its clocks go back. + + + +### Form Example + +Complete form example with validation and submission handling. The button has +no pending state while the date is sent. + + + +### With Validation + +A field is invalid while its value is before `min_value`, after `max_value` or +a day `is_date_unavailable` refuses, and while the application says so by +`is_invalid`. + + + +### Render Function + +`as_` overrides the default DOM element with a function of its props and its +state, as [Composition](/solidtype/heroui/composition/#custom-dom-element) +shows. + +## Customization + +### Tailwind CSS + +`class_` is added after HeroUI's classes. + + + +## Styling Reference + +HeroUI follows the [BEM](https://bem.info/en/methodology/) methodology to +ensure component variants and states are reusable and easy to customize. + +### CSS Classes + +- `.date-field` - Root container with minimal styling (`flex flex-col gap-1`) +- `.date-field--full-width` - Full width modifier +- `.date-input-group` - Root container styling of `Date_field.Group` +- `.date-input-group--primary`, `.date-input-group--secondary` - Variants +- `.date-input-group__input` - Input wrapper styling +- `.date-input-group__input-container` - Scrollable container for grouping + multiple inputs +- `.date-input-group__segment` - Individual date segment styling +- `.date-input-group__prefix` - Prefix element styling +- `.date-input-group__suffix` - Suffix element styling + +Child components ([Label](/solidtype/heroui/label/), +[Description](/solidtype/heroui/description/), +[FieldError](/solidtype/heroui/field-error/)) have their own CSS classes and +styling. See their respective documentation for customization options. + +### Interactive States + +DateField automatically manages these data attributes based on its state: + +- **Invalid**: `[data-invalid="true"]` - Automatically hides the description + slot when invalid +- **Required**: `[data-required="true"]` - Applied when `is_required` is true +- **Disabled**: `[data-disabled="true"]` - Applied when `is_disabled` is true +- **Read-only**: `[data-readonly="true"]` - Applied when `is_read_only` is true + +`Date_field.Group`'s states: + +- **Hover**: `[data-hovered="true"]` +- **Focus Within**: `[data-focus-within="true"]` +- **Focus Visible**: `[data-focus-visible="true"]` +- **Invalid**: `[data-invalid="true"]` +- **Disabled**: `[data-disabled="true"]` +- **Segment Focus**: `[data-focused="true"]` on segment elements +- **Segment Placeholder**: `[data-placeholder="true"]` on segment elements +- **Segment Type**: `[data-type="literal"]`, and a zoned field's zone + `[data-type="timeZoneName"]` + +## API Reference + +Each prop beside the name HeroUI's React component gives it. + +### DateField + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `value` | `value` | `CalendarDate.t Js.Nullable.t` | | Current value (controlled); null controls it empty | +| `defaultValue` | `default_value` | `CalendarDate.t` | | Default value (uncontrolled) | +| `onChange` | `on_change` | `CalendarDate.t option -> unit` | | Called as soon as its segments make a date other than its value, and with `None` once every segment is erased | +| `placeholderValue` | `placeholder_value` | `CalendarDate.t` | today | What an arrow key steps an empty segment from | +| `minValue` | `min_value` | `CalendarDate.t` | | The earliest date it is valid at | +| `maxValue` | `max_value` | `CalendarDate.t` | | The latest date it is valid at | +| `isDateUnavailable` | `is_date_unavailable` | `CalendarDate.t -> bool` | | A day it is invalid at | +| `shouldForceLeadingZeros` | `should_force_leading_zeros` | `bool` | the locale's | Whether to always show leading zeros in the month, day and hour | +| `isRequired` | `is_required` | `bool` | `false` | Whether user input is required before form submission | +| `isInvalid` | `is_invalid` | `bool` | `false` | Whether the value is invalid | +| `isDisabled` | `is_disabled` | `bool` | `false` | Whether the input is disabled | +| `isReadOnly` | `is_read_only` | `bool` | `false` | Whether the input can be selected but not changed | +| `name` | `name` | `string` | | Its name in a form, which is sent its value as `@internationalized/date` writes it, `2026-11-21` | +| `autoFocus` | `auto_focus` | `bool` | `false` | Whether its first segment is focused as it is drawn | +| `aria-label` | `aria_label` | `string` | | Accessibility label when no visible label is present | +| `fullWidth` | `full_width` | `bool` | `false` | Whether the date field should take full width of its container | +| `className` | `class_` | `string` | | Added after HeroUI's classes | +| `onBlur` | `on_blur` | `Dom.focusEvent -> unit` | | Called once focus leaves it for an element outside it | +| `validate`, `validationBehavior` | — | | | A field validates nothing beyond its range: it is invalid as the application says, and out of its range at once | +| `granularity`, `hourCycle`, `hideTimeZone` | — | | | A date alone has no time: `Date_field.Date_time`'s and `Date_field.Zoned`'s | + +### DateField.Date_time, DateField.Zoned + +A DateField whose value is a `CalendarDateTime` or a `ZonedDateTime`. Each +takes DateField's props, its value and range of its own kind, and: + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `granularity` | `granularity` | `` [ `day \| `hour \| `minute \| `second ] `` | `` `minute `` | The smallest unit displayed, a time to the minute even while it is empty, where React's empty field with no placeholder shows a date alone | +| `hourCycle` | `hour_cycle` | `` [ `h12 \| `h24 ] `` | the locale's | Whether to display time in 12 or 24 hour format | +| `placeholderValue` | `placeholder_value` | `CalendarDateTime.t`, `ZonedDateTime.t` | today at midnight; required for a zoned field | What a date typed while it is empty is put on, a zoned one's zone too | +| `hideTimeZone` | `hide_time_zone` | `bool` | `false` | Whether a zoned field hides its zone's name | +| `name` | `name` | `string` | | Its name in a form, which is sent its value whole, `2026-11-21T09:30:00+02:00[Europe/Kyiv]` | + +### DateField.Group + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `variant` | `variant` | `` [ `primary \| `secondary ] `` | `` `primary `` | Visual variant of the component. `` `primary `` is the default style with shadow. `` `secondary `` is a lower emphasis variant without shadow, suitable for use in surfaces | +| `fullWidth` | `full_width` | `bool` | its field's | Whether it takes its container's width | +| `className` | `class_` | `string` | | Added after HeroUI's classes | + +### DateField.Input, DateField.Segment, DateField.InputContainer, DateField.Prefix, DateField.Suffix + +Each takes `class_`, added after HeroUI's class; the input, a function of each +segment, rendering it; a segment, the `segment` it is; an input container, a +prefix and a suffix, their `children`. diff --git a/docs/src/content/docs/heroui/date-picker.mdx b/docs/src/content/docs/heroui/date-picker.mdx new file mode 100644 index 00000000..6e2a2e5e --- /dev/null +++ b/docs/src/content/docs/heroui/date-picker.mdx @@ -0,0 +1,183 @@ +--- +title: DatePicker +description: Composable date picker built on React Aria DatePicker with DateField and Calendar composition parts. +--- + +import Example from "@components/Example.astro"; +import * as ExUsage from "@islands/date_picker_usage.jsx"; +import ExUsageCode from "@islands/date_picker_usage.mlx?raw"; +import * as ExDisabled from "@islands/date_picker_disabled.jsx"; +import ExDisabledCode from "@islands/date_picker_disabled.mlx?raw"; +import * as ExControlled from "@islands/date_picker_controlled.jsx"; +import ExControlledCode from "@islands/date_picker_controlled.mlx?raw"; +import * as ExValidation from "@islands/date_picker_validation.jsx"; +import ExValidationCode from "@islands/date_picker_validation.mlx?raw"; +import * as ExFormatOptions from "@islands/date_picker_format_options.jsx"; +import ExFormatOptionsCode from "@islands/date_picker_format_options.mlx?raw"; +import * as ExForm from "@islands/date_picker_form.jsx"; +import ExFormCode from "@islands/date_picker_form.mlx?raw"; +import * as ExCustomIndicator from "@islands/date_picker_custom_indicator.jsx"; +import ExCustomIndicatorCode from "@islands/date_picker_custom_indicator.mlx?raw"; +import * as ExRenderFunction from "@islands/date_picker_render_function.jsx"; +import ExRenderFunctionCode from "@islands/date_picker_render_function.mlx?raw"; +import * as ExInternational from "@islands/date_picker_international.jsx"; +import ExInternationalCode from "@islands/date_picker_international.mlx?raw"; +import * as ExTailwind from "@islands/date_picker_tailwind.jsx"; +import ExTailwindCode from "@islands/date_picker_tailwind.mlx?raw"; +import * as Demo from "@islands/date_picker_demo.jsx"; + +Its value is a `CalendarDate` of `solidtype-internationalized-date`, as a +[DateField](/solidtype/heroui/date-field/)'s is; a date with a time is +`Date_picker.Date_time`'s, and one in a zone `Date_picker.Zoned`'s. The +[Calendar](/solidtype/heroui/calendar/) in its popover takes its date, its +range and its state. + +Its segments are in `en-GB`'s order, day before month, whatever the browser +reads, unless an `I18n.I18nProvider` names another locale. React's follows +the browser. + +Original HeroUI documentation: [DatePicker](https://heroui.com/en/docs/react/components/date-picker). + +## Usage + + + +## Parity + +The same HeroUI DatePicker twice, under the same props: in solidtype on the +left, in React on the right. Below them, every attribute of the two pickers: +a marked row is one they disagree on. + +
+ +
+ +## Anatomy + +`Date_picker` is composed as HeroUI's is: a `Date_field.Group` of the field's +input, the trigger in its `Date_field.Suffix`, and a `Calendar` in the +popover. + +```ocaml + + +``` + +## Examples + +### Disabled + + + +### Controlled + + + +### Validation + + + +### Format Options + +Control how a picker's value is shown with `granularity`, `hour_cycle`, +`hide_time_zone` and `should_force_leading_zeros`. Its children may be a +function of its state, whose `state.time_value` and `state.set_time_value` +draw a `Time_field` in the popover. + + + +### Form Example + + + +### Custom Indicator + +`Date_picker.Trigger_indicator` draws HeroUI's calendar icon unless given +children. + + + +### Render Function + + + +### International Calendar + +An `I18n.I18nProvider` locale with a calendar extension shows that calendar; +`on_change` gives a date in the calendar of the value given, else the +Gregorian. + + + +## Customization + +### Tailwind CSS + + + +## Styling Reference + +HeroUI follows [BEM](https://bem.info/en/methodology/) naming for reusable +customization. + +### CSS Classes + +- `.date-picker` - Root wrapper. +- `.date-picker__trigger` - Trigger part that opens the popover. +- `.date-picker__trigger-indicator` - Default or custom indicator slot. +- `.date-picker__popover` - Popover content wrapper. + +### Interactive States + +- **Open**: `[data-pressed="true"]` on the trigger, `[data-open="true"]` on the root. +- **Disabled**: `[data-disabled="true"]` on the trigger. +- **Focus visible**: `[data-focus-visible="true"]` on the trigger. +- **Hover**: `[data-hovered="true"]` on the trigger. + +## API Reference + +Each prop beside the name HeroUI's React component gives it. + +### Date_picker + +It takes every prop a [DateField](/solidtype/heroui/date-field/) takes, and: + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `value` | `value` | `CalendarDate.t Js.Nullable.t` | | Controlled selected date; null controls it empty | +| `defaultValue` | `default_value` | `CalendarDate.t` | | Default selected value in uncontrolled mode | +| `onChange` | `on_change` | `CalendarDate.t option -> unit` | | Called when the selected date changes | +| `isOpen` | `is_open` | `bool` | | Controlled popover open state | +| `defaultOpen` | `default_open` | `bool` | `false` | Initial popover open state | +| `onOpenChange` | `on_open_change` | `bool -> unit` | | Called when the popover opens or closes | +| `shouldCloseOnSelect` | `should_close_on_select` | `bool` | `true` | Whether choosing a day closes the popover | +| `firstDayOfWeek` | `first_day_of_week` | `` [ `sun \| `mon \| ... ] `` | the locale's | The calendar's first day of the week | +| `pageBehavior` | `page_behavior` | `` [ `visible \| `single ] `` | `` `visible `` | How the calendar pages | +| `isDisabled` | `is_disabled` | `bool` | `false` | Disables date selection and the trigger | +| `isInvalid` | `is_invalid` | `bool` | `false` | Marks the field as invalid | +| `minValue` | `min_value` | `CalendarDate.t` | | Minimum selectable date | +| `maxValue` | `max_value` | `CalendarDate.t` | | Maximum selectable date | +| `name` | `name` | `string` | | Name used for form submission | +| `children` | children | elements, or `state -> Jsx.element` | | Composed content or a function of its state | +| `render` | `as_` | `Html.Div.props -> state -> Jsx.element` | | Draws the root as another element | + +### Composition Parts + +| React | solidtype | Description | +|---|---|---| +| `DatePicker.Root` | `Date_picker` | Root date picker container and state owner | +| `DatePicker.Trigger` | `Date_picker.Trigger` | Trigger button, usually inside `Date_field.Suffix` | +| `DatePicker.TriggerIndicator` | `Date_picker.Trigger_indicator` | Indicator slot with the default calendar icon | +| `DatePicker.Popover` | `Date_picker.Popover` | Popover wrapper for `Calendar` content; `placement` and `offset` | diff --git a/docs/src/content/docs/heroui/date-range-picker.mdx b/docs/src/content/docs/heroui/date-range-picker.mdx new file mode 100644 index 00000000..98d91069 --- /dev/null +++ b/docs/src/content/docs/heroui/date-range-picker.mdx @@ -0,0 +1,191 @@ +--- +title: DateRangePicker +description: Composable date range picker built on React Aria DateRangePicker with DateField and RangeCalendar composition parts. +--- + +import Example from "@components/Example.astro"; +import * as ExUsage from "@islands/date_range_picker_usage.jsx"; +import ExUsageCode from "@islands/date_range_picker_usage.mlx?raw"; +import * as ExDisabled from "@islands/date_range_picker_disabled.jsx"; +import ExDisabledCode from "@islands/date_range_picker_disabled.mlx?raw"; +import * as ExControlled from "@islands/date_range_picker_controlled.jsx"; +import ExControlledCode from "@islands/date_range_picker_controlled.mlx?raw"; +import * as ExValidation from "@islands/date_range_picker_validation.jsx"; +import ExValidationCode from "@islands/date_range_picker_validation.mlx?raw"; +import * as ExFormatOptions from "@islands/date_range_picker_format_options.jsx"; +import ExFormatOptionsCode from "@islands/date_range_picker_format_options.mlx?raw"; +import * as ExForm from "@islands/date_range_picker_form.jsx"; +import ExFormCode from "@islands/date_range_picker_form.mlx?raw"; +import * as ExCustomIndicator from "@islands/date_range_picker_custom_indicator.jsx"; +import ExCustomIndicatorCode from "@islands/date_range_picker_custom_indicator.mlx?raw"; +import * as ExRenderFunction from "@islands/date_range_picker_render_function.jsx"; +import ExRenderFunctionCode from "@islands/date_range_picker_render_function.mlx?raw"; +import * as ExInternational from "@islands/date_range_picker_international.jsx"; +import ExInternationalCode from "@islands/date_range_picker_international.mlx?raw"; +import * as ExTailwind from "@islands/date_range_picker_tailwind.jsx"; +import ExTailwindCode from "@islands/date_range_picker_tailwind.mlx?raw"; +import * as Demo from "@islands/date_range_picker_demo.jsx"; + +Its value is a `Date_range_picker.range`, `{ start; end_ }`, of +`CalendarDate`s of `solidtype-internationalized-date`, told once both ends +are there, and `None` as one is erased; a range of dates with times is +`Date_range_picker.Date_time`'s, and one in a zone `Date_range_picker.Zoned`'s. +The [RangeCalendar](/solidtype/heroui/range-calendar/) in its popover takes +its range and chooses it. + +Its segments are in `en-GB`'s order, day before month, whatever the browser +reads, unless an `I18n.I18nProvider` names another locale. React's follows +the browser. A range whose end is before its start is invalid at once, where +React's shows it so only once a value is committed. + +Original HeroUI documentation: [DateRangePicker](https://heroui.com/en/docs/react/components/date-range-picker). + +## Usage + + + +## Parity + +The same HeroUI DateRangePicker twice, under the same props: in solidtype on +the left, in React on the right. Below them, every attribute of the two +pickers: a marked row is one they disagree on. + +
+ +
+ +## Anatomy + +`Date_range_picker` is composed as HeroUI's is: a `Date_field.Group` of two +`Date_field.Input`s given their `slot`, `"start"` and `"end"`, a +`Date_range_picker.Range_separator` between them, the trigger in its +`Date_field.Suffix`, and a `Range_calendar` in the popover. + +```ocaml + + +``` + +## Examples + +### Disabled + + + +### Controlled + + + +### Validation + + + +### Format Options + +Control how a range is shown with `granularity`, `hour_cycle`, +`hide_time_zone` and `should_force_leading_zeros`. Its children may be a +function of its state, whose `state.time_range` and `state.set_time` draw a +time field for each end in the popover. + + + +### Form Example + + + +### Custom Indicator + +`Date_range_picker.Trigger_indicator` draws HeroUI's calendar icon unless +given children. + + + +### Render Function + + + +### International Calendar + +An `I18n.I18nProvider` locale with a calendar extension shows that calendar; +`on_change` gives dates in the calendar of the value given, else the +Gregorian. + + + +## Customization + +### Tailwind CSS + + + +## Styling Reference + +HeroUI follows the [BEM](https://bem.info/en/methodology/) methodology to +ensure component variants and states are reusable and easy to customize. + +### CSS Classes + +- `.date-range-picker` - Root wrapper. +- `.date-range-picker__trigger` - Trigger part that opens the popover. +- `.date-range-picker__trigger-indicator` - Default or custom indicator slot. +- `.date-range-picker__range-separator` - Separator between the start and end inputs. +- `.date-range-picker__popover` - Popover content wrapper. + +### Interactive States + +- **Open**: `[data-pressed="true"]` on the trigger, `[data-open="true"]` on the root. +- **Disabled**: `[data-disabled="true"]` on the trigger. +- **Focus visible**: `[data-focus-visible="true"]` on the trigger. +- **Hover**: `[data-hovered="true"]` on the trigger. + +## API Reference + +Each prop beside the name HeroUI's React component gives it. + +### Date_range_picker + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `value` | `value` | `CalendarDate.t range Js.Nullable.t` | | Controlled selected range; null controls it empty | +| `defaultValue` | `default_value` | `CalendarDate.t range` | | Default selected range in uncontrolled mode | +| `onChange` | `on_change` | `CalendarDate.t range option -> unit` | | Called when the selected range changes | +| `isOpen` | `is_open` | `bool` | | Controlled popover open state | +| `defaultOpen` | `default_open` | `bool` | `false` | Initial popover open state | +| `onOpenChange` | `on_open_change` | `bool -> unit` | | Called when the popover opens or closes | +| `shouldCloseOnSelect` | `should_close_on_select` | `bool` | `true` | Whether choosing a range closes the popover | +| `isDisabled` | `is_disabled` | `bool` | `false` | Disables range selection and the trigger | +| `isInvalid` | `is_invalid` | `bool` | `false` | Marks the field as invalid | +| `minValue` | `min_value` | `CalendarDate.t` | | Minimum selectable date | +| `maxValue` | `max_value` | `CalendarDate.t` | | Maximum selectable date | +| `startName` | `start_name` | `string` | | Name of the start date in form submission | +| `endName` | `end_name` | `string` | | Name of the end date in form submission | +| `children` | children | elements, or `state -> Jsx.element` | | Composed content or a function of its state | +| `render` | `as_` | `Html.Div.props -> state -> Jsx.element` | | Draws the root as another element | + +### Composition Parts + +| React | solidtype | Description | +|---|---|---| +| `DateRangePicker.Root` | `Date_range_picker` | Root date range picker container and state owner | +| `DateRangePicker.Trigger` | `Date_range_picker.Trigger` | Trigger button, usually inside `Date_field.Suffix` | +| `DateRangePicker.TriggerIndicator` | `Date_range_picker.Trigger_indicator` | Indicator slot with the default calendar icon | +| `DateRangePicker.RangeSeparator` | `Date_range_picker.Range_separator` | Separator between the start and end inputs | +| `DateRangePicker.Popover` | `Date_range_picker.Popover` | Popover wrapper for `Range_calendar` content | diff --git a/docs/src/content/docs/heroui/range-calendar.mdx b/docs/src/content/docs/heroui/range-calendar.mdx new file mode 100644 index 00000000..753003e9 --- /dev/null +++ b/docs/src/content/docs/heroui/range-calendar.mdx @@ -0,0 +1,320 @@ +--- +title: RangeCalendar +description: Composable date range picker with month grid, navigation, and year picker support. +--- + +import Example from "@components/Example.astro"; +import * as ExUsage from "@islands/range_calendar_usage.jsx"; +import ExUsageCode from "@islands/range_calendar_usage.mlx?raw"; +import * as ExDisabled from "@islands/range_calendar_disabled.jsx"; +import ExDisabledCode from "@islands/range_calendar_disabled.mlx?raw"; +import * as ExYearPicker from "@islands/range_calendar_year_picker.jsx"; +import ExYearPickerCode from "@islands/range_calendar_year_picker.mlx?raw"; +import * as ExDefaultValue from "@islands/range_calendar_default_value.jsx"; +import ExDefaultValueCode from "@islands/range_calendar_default_value.mlx?raw"; +import * as ExControlled from "@islands/range_calendar_controlled.jsx"; +import ExControlledCode from "@islands/range_calendar_controlled.mlx?raw"; +import * as ExMinMax from "@islands/range_calendar_min_max.jsx"; +import ExMinMaxCode from "@islands/range_calendar_min_max.mlx?raw"; +import * as ExUnavailable from "@islands/range_calendar_unavailable.jsx"; +import ExUnavailableCode from "@islands/range_calendar_unavailable.mlx?raw"; +import * as ExAnchorUnavailable from "@islands/range_calendar_anchor_unavailable.jsx"; +import ExAnchorUnavailableCode from "@islands/range_calendar_anchor_unavailable.mlx?raw"; +import * as ExWeeksInMonth from "@islands/range_calendar_weeks_in_month.jsx"; +import ExWeeksInMonthCode from "@islands/range_calendar_weeks_in_month.mlx?raw"; +import * as ExWeekView from "@islands/range_calendar_week_view.jsx"; +import ExWeekViewCode from "@islands/range_calendar_week_view.mlx?raw"; +import * as ExDayView from "@islands/range_calendar_day_view.jsx"; +import ExDayViewCode from "@islands/range_calendar_day_view.mlx?raw"; +import * as ExNonContiguous from "@islands/range_calendar_non_contiguous.jsx"; +import ExNonContiguousCode from "@islands/range_calendar_non_contiguous.mlx?raw"; +import * as ExReadOnly from "@islands/range_calendar_read_only.jsx"; +import ExReadOnlyCode from "@islands/range_calendar_read_only.mlx?raw"; +import * as ExInvalid from "@islands/range_calendar_invalid.jsx"; +import ExInvalidCode from "@islands/range_calendar_invalid.mlx?raw"; +import * as ExFocusedValue from "@islands/range_calendar_focused_value.jsx"; +import ExFocusedValueCode from "@islands/range_calendar_focused_value.mlx?raw"; +import * as ExIndicators from "@islands/range_calendar_indicators.jsx"; +import ExIndicatorsCode from "@islands/range_calendar_indicators.mlx?raw"; +import * as ExBooking from "@islands/range_calendar_booking.jsx"; +import ExBookingCode from "@islands/range_calendar_booking.mlx?raw"; +import * as ExMultipleMonths from "@islands/range_calendar_multiple_months.jsx"; +import ExMultipleMonthsCode from "@islands/range_calendar_multiple_months.mlx?raw"; +import * as ExInternational from "@islands/range_calendar_international.jsx"; +import ExInternationalCode from "@islands/range_calendar_international.mlx?raw"; +import * as ExTailwind from "@islands/range_calendar_tailwind.jsx"; +import ExTailwindCode from "@islands/range_calendar_tailwind.mlx?raw"; +import * as Demo from "@islands/range_calendar_demo.jsx"; + +Its value is a `Range_calendar.range`, `{ start; end_ }`, of +`CalendarDate`s of `solidtype-internationalized-date`. `on_change` is told +the range chosen, or `None` where `` commit_behavior=`clear `` clears it. + +Its weeks start on Monday and its days are written as `en-GB` writes them, +whatever the browser reads, unless an `I18n.I18nProvider` names another +locale. React's follows the browser. + +Original HeroUI documentation: [RangeCalendar](https://heroui.com/en/docs/react/components/range-calendar). + +## Usage + + + +## Parity + +The same HeroUI RangeCalendar twice, under the same props: in solidtype on +the left, in React on the right. Below them, every attribute of the two +calendars: a marked row is one they disagree on. + +
+ +
+ +## Anatomy + +```ocaml + + + + + + + + + (fun day -> + (Jsx.string (S.get day))) + + + (fun date -> ) + + + +``` + +A press on a day begins a range, and the days shown run to the one hovered +or focused until a second press ends it. A drag chooses the days it crosses, +and a drag from an end of the range chosen moves that end. Enter begins and +ends a range by the keys, and Escape lets a range begun go. + +## Examples + +### Disabled + + + +### Year Picker + +`Range_calendar.Year_picker_trigger`, `Range_calendar.Year_picker_grid`, and +their body and cell parts provide an integrated year navigation pattern. + + + +### Default Value + + + +### Controlled + +Use controlled `value` and `focused_value` for external state coordination +and custom shortcuts. + + + +### Min and Max Dates + + + +### Unavailable Dates + +Use `is_date_unavailable` to block dates such as weekends, holidays, or +booked slots. A range begun reaches no further than the nearest unavailable +day. + + + +### Anchor-Based Unavailable Dates + +While a range is begun, `is_date_unavailable` is given its first date beside +each date, `Some anchor`, else `None`. Use it to limit which end dates are +valid, for example within 7 days of the start. + + + +### Weeks in Month + +Set `weeks_in_month` to a fixed value, for example `6`, to keep the grid's +height as months change. + + + +### Week View + +`` visible_duration=(Range_calendar.Weeks n) `` shows one or more weeks at a +time, and its buttons page by them; `` page_behavior=`single `` pages a week +at a time. Its grid is named by the days it shows. + + + +### Day View + +`` visible_duration=(Range_calendar.Days n) `` shows a run of days, and its +buttons page by them; `` page_behavior=`single `` pages a day at a time. + + + +### Allows Non-Contiguous Ranges + +`allows_non_contiguous_ranges` lets a range cross unavailable dates. + + + +### Read Only + + + +### Invalid + + + +### Focused Value + +`focused_value` and `on_focus_change` control which date is focused. + + + +### Cell Indicators + +`Range_calendar.Cell`'s children are drawn of its state, and +`Range_calendar.Cell_indicator` marks a day. + + + +### Real-World Example + + + +### Multiple Months + +`visible_duration` and `offset` show several months side by side. + + + +### International Calendars + +An `I18n.I18nProvider` locale with a calendar extension shows that calendar; +`on_change` gives dates in the calendar of the value given, else the +Gregorian. + + + +## Customization + +### Tailwind CSS + +`class_` is added after HeroUI's classes. + + + +## Styling Reference + +HeroUI follows the [BEM](https://bem.info/en/methodology/) methodology to +ensure component variants and states are reusable and easy to customize. + +### CSS Classes + +- `.range-calendar` - Root container. +- `.range-calendar--week-view`, `.range-calendar--day-view` - A week's or a day's view. +- `.range-calendar__header` - Header row containing nav buttons and heading. +- `.range-calendar__heading` - Current month label. +- `.range-calendar__nav-button` - Previous/next navigation controls. +- `.range-calendar__grid` - Main day grid. +- `.range-calendar__grid-header` - Weekday header row wrapper. +- `.range-calendar__grid-body` - Date rows wrapper. +- `.range-calendar__header-cell` - Weekday header cell. +- `.range-calendar__cell` - Interactive day cell. +- `.range-calendar__cell-button` - A day's content, chosen at the range's ends. +- `.range-calendar__cell-indicator` - Dot indicator inside a day cell. +- `.calendar-year-picker__trigger` - Year picker toggle button. +- `.calendar-year-picker__year-grid` - Overlay grid of selectable years. +- `.calendar-year-picker__year-cell` - Individual year option. + +### Interactive States + +- **Selected**: `[data-selected="true"]` +- **Selection start**: `[data-selection-start="true"]` +- **Selection end**: `[data-selection-end="true"]` +- **Today**: `[data-today="true"]` +- **Unavailable**: `[data-unavailable="true"]` +- **Outside month**: `[data-outside-month="true"]` +- **Hovered**: `[data-hovered="true"]` +- **Pressed**: `[data-pressed="true"]` +- **Focus visible**: `[data-focus-visible="true"]` +- **Disabled**: `[data-disabled="true"]` + +## API Reference + +Each prop beside the name HeroUI's React component gives it. + +### Range_calendar + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `value` | `value` | `range Js.Nullable.t` | | Controlled selected range; null controls it empty | +| `defaultValue` | `default_value` | `range` | | Initial selected range (uncontrolled) | +| `onChange` | `on_change` | `range option -> unit` | | Called when a range is chosen, or cleared | +| `allowsNonContiguousRanges` | `allows_non_contiguous_ranges` | `bool` | `false` | Allows ranges that span unavailable dates | +| `commitBehavior` | `commit_behavior` | `` [ `select \| `reset \| `clear ] `` | `` `select `` | What a range begun becomes as the pointer is let go outside the days, or the focus leaves | +| `focusedValue` | `focused_value` | `CalendarDate.t` | | Controlled focused date | +| `defaultFocusedValue` | `default_focused_value` | `CalendarDate.t` | its start, else today | Initial focused date | +| `onFocusChange` | `on_focus_change` | `CalendarDate.t -> unit` | | Called when focus moves to another date | +| `minValue` | `min_value` | `CalendarDate.t` | 1900-01-01 in its calendar | Earliest selectable date | +| `maxValue` | `max_value` | `CalendarDate.t` | 2099-12-31 in its calendar | Latest selectable date | +| `weeksInMonth` | `weeks_in_month` | `int` | the month's | The number of weeks in a month's grid | +| `isDateUnavailable` | `is_date_unavailable` | `CalendarDate.t -> CalendarDate.t option -> bool` | | Marks dates as unavailable, given a range begun's first date | +| `firstDayOfWeek` | `first_day_of_week` | `` [ `sun \| `mon \| `tue \| `wed \| `thu \| `fri \| `sat ] `` | the locale's | The first day of its weeks | +| `pageBehavior` | `page_behavior` | `` [ `visible \| `single ] `` | `` `visible `` | Whether paging moves by what is shown or by one unit | +| `selectionAlignment` | `selection_alignment` | `` [ `start \| `center \| `end_ ] `` | `` `center ``, or `` `start `` for a range longer than a view | Where the range stands in what is shown at first | +| `isDisabled` | `is_disabled` | `bool` | `false` | Disables interaction and selection | +| `isReadOnly` | `is_read_only` | `bool` | `false` | Days are focused but not chosen | +| `isInvalid` | `is_invalid` | `bool` | `false` | Marks the calendar as invalid | +| `visibleDuration` | `visible_duration` | `Range_calendar.duration` | `Months 1` | `Months n`, `Weeks n` or `Days n` | +| `defaultYearPickerOpen` | `default_year_picker_open` | `bool` | `false` | Initial open state of the year picker | +| `isYearPickerOpen` | `is_year_picker_open` | `bool` | | Controlled open state of the year picker | +| `onYearPickerOpenChange` | `on_year_picker_open_change` | `bool -> unit` | | Called when the year picker opens or closes | +| `aria-label` | `aria_label` | `string` | | Its name, beside the dates it shows | +| `className` | `class_` | `string` | | Added after HeroUI's classes | + +### Composition Parts + +They are [Calendar](/solidtype/heroui/calendar/)'s parts, drawn in the +range's look. + +| React | solidtype | Description | +|---|---|---| +| `RangeCalendar.Header` | `Range_calendar.Header` | Header container for navigation and heading | +| `RangeCalendar.Heading` | `Range_calendar.Heading` | The dates shown; `offset` and `format` | +| `RangeCalendar.NavButton` | `Range_calendar.Nav_button` | `` slot=`previous `` or `` slot=`next `` | +| `RangeCalendar.Grid` | `Range_calendar.Grid` | Day grid for one month; `offset` and `weekday_style` | +| `RangeCalendar.GridHeader` | `Range_calendar.Grid_header` | Weekday header, a function of each day's name | +| `RangeCalendar.GridBody` | `Range_calendar.Grid_body` | Date cells, a function of each date | +| `RangeCalendar.HeaderCell` | `Range_calendar.Header_cell` | Weekday label cell | +| `RangeCalendar.Cell` | `Range_calendar.Cell` | A day, its children drawn of its state | +| `RangeCalendar.CellIndicator` | `Range_calendar.Cell_indicator` | A dot marking a day | +| `RangeCalendar.YearPickerTrigger` | `Range_calendar.Year_picker_trigger` | Opens and closes the year picker | +| `RangeCalendar.YearPickerTriggerHeading` | `Range_calendar.Year_picker_trigger_heading` | The month shown, in the trigger | +| `RangeCalendar.YearPickerTriggerIndicator` | `Range_calendar.Year_picker_trigger_indicator` | The trigger's chevron | +| `RangeCalendar.YearPickerGrid` | `Range_calendar.Year_picker_grid` | The years; `format` and `visible_years` | +| `RangeCalendar.YearPickerGridBody` | `Range_calendar.Year_picker_grid_body` | The years' cells, or a function of each year | +| `RangeCalendar.YearPickerCell` | `Range_calendar.Year_picker_cell` | A year | + +### Range_calendar.Cell's state + +| React | solidtype | Type | Description | +|---|---|---|---| +| `formattedDate` | `formatted_date` | `string S.accessor` | Its day of the month | +| `isSelected` | `is_selected` | `bool S.accessor` | Whether the date is in the range shown | +| `isSelectionStart` | `is_selection_start` | `bool S.accessor` | Whether the date starts the range shown | +| `isSelectionEnd` | `is_selection_end` | `bool S.accessor` | Whether the date ends the range shown | +| `isUnavailable` | `is_unavailable` | `bool S.accessor` | Whether the date is unavailable | +| `isDisabled` | `is_disabled` | `bool S.accessor` | Whether the cell is disabled | +| `isOutsideMonth` | `is_outside_month` | `bool S.accessor` | Whether the date belongs to another month | diff --git a/docs/src/content/docs/heroui/time-field.mdx b/docs/src/content/docs/heroui/time-field.mdx index e1167e6b..de2336e9 100644 --- a/docs/src/content/docs/heroui/time-field.mdx +++ b/docs/src/content/docs/heroui/time-field.mdx @@ -40,6 +40,10 @@ Its value is a `Time` of `solidtype-internationalized-date`, made by `Time.make ~hour:14 ~minute:30 ()` or `parse_time "14:30"`; a time on a date is `Time_field.Date_time`'s, and a time in a zone `Time_field.Zoned`'s. +Its clock is `en-GB`'s, 24 hours, whatever the browser reads, unless an +`I18n.I18nProvider` names another locale: `` +gives a 12-hour clock. React's follows the browser. + Original HeroUI documentation: [TimeField](https://heroui.com/en/docs/react/components/time-field). ## Usage diff --git a/docs/src/content/docs/index.mdx b/docs/src/content/docs/index.mdx index 30ee319b..3292fbe1 100644 --- a/docs/src/content/docs/index.mdx +++ b/docs/src/content/docs/index.mdx @@ -65,7 +65,7 @@ GitHub release: "solid-js": "~1.9.17", "vite": "^8.3.0", "vite-plugin-solid": "^2.11.14", - "vite-plugin-solidtype": "https://github.com/hyphatech/solidtype/releases/download/0.12.0/vite-plugin-solidtype-0.12.0.tgz" + "vite-plugin-solidtype": "https://github.com/hyphatech/solidtype/releases/download/0.13.0/vite-plugin-solidtype-0.13.0.tgz" } } ``` diff --git a/docs/src/content/docs/reference.md b/docs/src/content/docs/reference.md index 6cd13d1c..44f372e0 100644 --- a/docs/src/content/docs/reference.md +++ b/docs/src/content/docs/reference.md @@ -59,9 +59,16 @@ bun add $(opam show solidtype-rhp --field x-npm-depends) - [`Solidtype_headless`](/solidtype/reference/solidtype-headless/Solidtype_headless/index.html) -- the components Kobalte lacks, one module each: - [`Table`](/solidtype/reference/solidtype-headless/Solidtype_headless/Table/index.html), + [`Calendar`](/solidtype/reference/solidtype-headless/Solidtype_headless/Calendar/index.html), + [`Color_picker`](/solidtype/reference/solidtype-headless/Solidtype_headless/Color_picker/index.html), [`Color_swatch_picker`](/solidtype/reference/solidtype-headless/Solidtype_headless/Color_swatch_picker/index.html), + [`Data_grid`](/solidtype/reference/solidtype-headless/Solidtype_headless/Data_grid/index.html), + [`Date_field`](/solidtype/reference/solidtype-headless/Solidtype_headless/Date_field/index.html), + [`Date_picker`](/solidtype/reference/solidtype-headless/Solidtype_headless/Date_picker/index.html), [`Load_more_sentinel`](/solidtype/reference/solidtype-headless/Solidtype_headless/Load_more_sentinel/index.html), + [`Table`](/solidtype/reference/solidtype-headless/Solidtype_headless/Table/index.html), + [`Tag_group`](/solidtype/reference/solidtype-headless/Solidtype_headless/Tag_group/index.html), + [`Top_layer`](/solidtype/reference/solidtype-headless/Solidtype_headless/Top_layer/index.html), [`Virtualizer`](/solidtype/reference/solidtype-headless/Solidtype_headless/Virtualizer/index.html); and Kobalte's own, fixed: [`Color_area`](/solidtype/reference/solidtype-headless/Solidtype_headless/Color_area/index.html), diff --git a/docs/src/styles/heroui.css b/docs/src/styles/heroui.css index cbe894a0..bb9f5dde 100644 --- a/docs/src/styles/heroui.css +++ b/docs/src/styles/heroui.css @@ -57,6 +57,12 @@ @import "@heroui/styles/components/textfield.css" layer(components); @import "@heroui/styles/components/search-field.css" layer(components); @import "@heroui/styles/components/textarea.css" layer(components); +@import "@heroui/styles/components/calendar.css" layer(components); +@import "@heroui/styles/components/calendar-year-picker.css" layer(components); +@import "@heroui/styles/components/date-field.css" layer(components); +@import "@heroui/styles/components/date-picker.css" layer(components); +@import "@heroui/styles/components/date-range-picker.css" layer(components); +@import "@heroui/styles/components/range-calendar.css" layer(components); @import "@heroui/styles/components/time-field.css" layer(components); @import "@heroui/styles/components/date-input-group.css" layer(components); @import "@heroui/styles/components/card.css" layer(components); diff --git a/dune-project b/dune-project index d4f6b5c6..1b0e3215 100644 --- a/dune-project +++ b/dune-project @@ -157,6 +157,8 @@ (solidtype (= :version)) (solidtype-kobalte + (= :version)) + (solidtype-internationalized-date (= :version)))) (package diff --git a/example/test/fetch.ts b/example/test/fetch.ts index c1e0b535..083cdba2 100644 --- a/example/test/fetch.ts +++ b/example/test/fetch.ts @@ -1,3 +1,5 @@ +import { configure } from "@solidjs/testing-library"; + // The board fetches the page's own origin, /api/tasks, as a browser // resolves it. jsdom's fetch is Node's, which resolves nothing against the // page, so a relative URL is resolved here against the page's, the @@ -5,3 +7,8 @@ const fetched = globalThis.fetch; globalThis.fetch = (input, init) => fetched(typeof input === "string" ? new URL(input, location.href) : input, init); + +// A query that waits for what the server sends waits as long as a run of +// every test file at once can take to send it: Testing Library's second is a +// quiet machine's, and a loaded one answers later. +configure({ asyncUtilTimeout: 5000 }); diff --git a/generate/binding.ts b/generate/binding.ts index 167adeab..31179193 100644 --- a/generate/binding.ts +++ b/generate/binding.ts @@ -176,6 +176,7 @@ function anonymousModule(type: ts.Type, where: string): Named { const readable = new Set([ "File", "DateTimeFormatOptions", "NumberFormatOptions", "CollatorOptions", "Collator", "NumberFormat", "DateTimeFormat", "DateTimeFormatPart", + "ResolvedDateTimeFormatOptions", ]); const opaques = new Set(); function opaque(name: string): string { diff --git a/headless/calendar.mli b/headless/calendar.mli new file mode 100644 index 00000000..8c40580d --- /dev/null +++ b/headless/calendar.mli @@ -0,0 +1,463 @@ +(** A calendar, as Kobalte would make one: a month's grid of days to choose a + date from, its locale's in its order, its first day of the week and its + calendar, moved through by the keys and paged by its {!Previous} and {!Next} + buttons. Its value is \@internationalized/date's + {!Solidtype_internationalized_date.Types.CalendarDate}: one with {!Root}, + several with {!Root_multiple}. It draws no style: each part is the element + it names, its roles and state as attributes, and takes every attribute its + element does, which it passes on. + + {[ + + + "<" + ">" + + + (fun day -> (Jsx.string (S.get day))) + + + (fun date -> ) + + + + ]} + + Its locale is the one an [I18nProvider] names, else [en-GB], whatever the + browser reads. It shows [visible_duration], a month by default, around the + focused date, which is [focused_value] while it is given one, else the one + it keeps: [default_focused_value] at first, else its value, else today, + within [min_value] and [max_value]. The arrows move the focus a day, or a + week up and down; Page Up and Page Down a month, or a year with Shift; Home + and End to the start and end of the week, or of the month in a month's view; + Enter and Space choose the focused day, as a press does. A day before + [min_value] or after [max_value] is disabled; one [is_date_unavailable] + refuses is focused but never chosen. A chosen date is told in the calendar + of the value given, else the Gregorian. A reader is told each day's name, + whether it is today and whether it is chosen, and the month shown as it + changes. A part is used inside a root: elsewhere it raises + [Invalid_argument] as it is made. *) + +module S := Solidtype.Solid +module Jsx := Solidtype.Jsx +module D := Solidtype_internationalized_date + +type duration = + | Months of int + | Weeks of int + | Days of int (** How much a calendar shows, and pages by. *) + +type day_of_week = [ `sun | `mon | `tue | `wed | `thu | `fri | `sat ] + +type range = { start : D.Types.CalendarDate.t; end_ : D.Types.CalendarDate.t } +(** A range of dates, its ends included, [start] never after [end_]. *) + +type translations = { + previous : string; + next : string; + selected_date_description : string -> string; + today_date : string -> string; + today_date_selected : string -> string; + date_selected : string -> string; + minimum_date : string; + maximum_date : string; + date_range : string -> string -> string; + selected_range_description : string -> string; + start_range_selection_prompt : string; + finish_range_selection_prompt : string; +} +(** What the calendar tells a reader, in its locale's words where none are + given, React Aria's, else English. *) + +val english : translations +(** React Aria's English: [Previous], + [Today, Saturday, November 21, 2026 selected], [First available date]. *) + +type calendar = { + focused_date : D.Types.CalendarDate.t S.accessor; + set_focused_date : D.Types.CalendarDate.t -> unit; + (** Focuses a date, within the calendar's range, and shows it. *) + visible_start : D.Types.CalendarDate.t S.accessor; + visible_end : D.Types.CalendarDate.t S.accessor; + visible_duration : duration S.accessor; + min_value : D.Types.CalendarDate.t option S.accessor; + max_value : D.Types.CalendarDate.t option S.accessor; + locale : string S.accessor; + time_zone : string S.accessor; + is_disabled : bool S.accessor; + is_read_only : bool S.accessor; + is_invalid : bool S.accessor; + is_focused : bool S.accessor; (** Whether focus is in its grid. *) + is_previous_disabled : bool S.accessor; + is_next_disabled : bool S.accessor; + (** Whether its {!Previous} and {!Next} buttons are disabled. *) + focus : unit -> unit; (** Focuses its focused date's cell. *) +} +(** What a part inside a root reads of it, and a style's attribute on it. *) + +module Context : sig + val use : unit -> calendar + (** The calendar above; outside a root it raises [Invalid_argument]. *) +end + +type cell = { + date : D.Types.CalendarDate.t S.accessor; + formatted_date : string S.accessor; (** Its day of the month, [21]. *) + is_selected : bool S.accessor; + is_focused : bool S.accessor; + is_disabled : bool S.accessor; + is_unavailable : bool S.accessor; + is_outside_month : bool S.accessor; + is_outside_visible_range : bool S.accessor; + is_today : bool S.accessor; + is_invalid : bool S.accessor; + is_selection_start : bool S.accessor; + is_selection_end : bool S.accessor; +} +(** What a {!Cell}'s children are drawn of, given as a function. *) + +(** What a picker around a calendar gives it: its date, or its range, and the + dates it may choose. A root inside a {!Given.Provider} takes each where it + is given none of its own, and the focus as it is drawn, as React Aria's + calendar takes its date picker's; a date chosen is told to both. *) +module Given : sig + type value = + | Single of + D.Types.CalendarDate.t option S.accessor + * (D.Types.CalendarDate.t -> unit) + | Range of range option S.accessor * (range -> unit) + + type t = { + value : value; + min_value : D.Types.CalendarDate.t option S.accessor; + max_value : D.Types.CalendarDate.t option S.accessor; + is_date_unavailable : (D.Types.CalendarDate.t -> bool) option S.accessor; + is_disabled : bool S.accessor; + is_read_only : bool S.accessor; + is_invalid : bool S.accessor; + default_focused_value : D.Types.CalendarDate.t option S.accessor; + first_day_of_week : day_of_week option S.accessor; + page_behavior : [ `visible | `single ] option S.accessor; + } + + module Provider : sig + module Props : sig + val check : + value:t Solidtype.Check.value -> + ?children:('f, [ `elements ]) Solidtype.Check.children -> + unit -> + unit + end + + val component : unit Jsx.component + end + + val use : unit -> t option +end + +(** A calendar of one date, a [
] named by [aria_label], + else [aria_labelledby], and the dates it shows. Its value is [value] while + it is given one -- [Js.Nullable.null] keeps it empty -- else the one it + keeps, [default_value] at first; each date chosen calls [on_change]. Paging + moves by [visible_duration], or a single month, week or day with + [page_behavior] [`single]; [selection_alignment] places the focused date at + the start, the centre or the end of what is shown. Its weeks start on + [first_day_of_week], else the locale's, and a month's grid has + [weeks_in_month] rows, else as many as the month needs. While [is_disabled] + nothing is focused or chosen, and while [is_read_only] days are focused but + not chosen; it is invalid while [is_invalid] or while its value is out of + its range or unavailable. *) +module Root : sig + module Props : sig + type t + + val check : + ?value:D.Types.CalendarDate.t Js.Nullable.t Solidtype.Check.value -> + ?default_value:D.Types.CalendarDate.t Solidtype.Check.value -> + ?on_change:(D.Types.CalendarDate.t -> unit) -> + ?focused_value:D.Types.CalendarDate.t Solidtype.Check.value -> + ?default_focused_value:D.Types.CalendarDate.t Solidtype.Check.value -> + ?on_focus_change:(D.Types.CalendarDate.t -> unit) -> + ?min_value:D.Types.CalendarDate.t Solidtype.Check.value -> + ?max_value:D.Types.CalendarDate.t Solidtype.Check.value -> + ?is_date_unavailable:(D.Types.CalendarDate.t -> bool) -> + ?visible_duration:duration Solidtype.Check.value -> + ?page_behavior:[ `visible | `single ] Solidtype.Check.value -> + ?selection_alignment:[ `start | `center | `end_ ] Solidtype.Check.value -> + ?first_day_of_week:day_of_week Solidtype.Check.value -> + ?weeks_in_month:int Solidtype.Check.value -> + ?is_disabled:bool Solidtype.Check.value -> + ?is_read_only:bool Solidtype.Check.value -> + ?is_invalid:bool Solidtype.Check.value -> + ?auto_focus:bool Solidtype.Check.value -> + ?aria_label:string Solidtype.Check.value -> + ?aria_labelledby:string Solidtype.Check.value -> + ?aria_describedby:string Solidtype.Check.value -> + ?translations:translations Solidtype.Check.value -> + ?as_:(Solidtype.Html.Div.props -> Jsx.element) -> + ?props:'spread S.rest -> + (?children:('f, [ `elements ]) Solidtype.Check.children -> unit -> unit) + Solidtype.Html.Div.check + end + + val make : Props.t -> Jsx.element + val component : Props.t Jsx.component +end + +(** A calendar of several dates, as {!Root} is: a date chosen joins its value, + and one chosen again leaves it, each change telling [on_change] the dates in + the order they were chosen. Its grid is [aria-multiselectable]. *) +module Root_multiple : sig + module Props : sig + type t + + val check : + ?value:D.Types.CalendarDate.t array Solidtype.Check.value -> + ?default_value:D.Types.CalendarDate.t array Solidtype.Check.value -> + ?on_change:(D.Types.CalendarDate.t array -> unit) -> + ?focused_value:D.Types.CalendarDate.t Solidtype.Check.value -> + ?default_focused_value:D.Types.CalendarDate.t Solidtype.Check.value -> + ?on_focus_change:(D.Types.CalendarDate.t -> unit) -> + ?min_value:D.Types.CalendarDate.t Solidtype.Check.value -> + ?max_value:D.Types.CalendarDate.t Solidtype.Check.value -> + ?is_date_unavailable:(D.Types.CalendarDate.t -> bool) -> + ?visible_duration:duration Solidtype.Check.value -> + ?page_behavior:[ `visible | `single ] Solidtype.Check.value -> + ?selection_alignment:[ `start | `center | `end_ ] Solidtype.Check.value -> + ?first_day_of_week:day_of_week Solidtype.Check.value -> + ?weeks_in_month:int Solidtype.Check.value -> + ?is_disabled:bool Solidtype.Check.value -> + ?is_read_only:bool Solidtype.Check.value -> + ?is_invalid:bool Solidtype.Check.value -> + ?auto_focus:bool Solidtype.Check.value -> + ?aria_label:string Solidtype.Check.value -> + ?aria_labelledby:string Solidtype.Check.value -> + ?aria_describedby:string Solidtype.Check.value -> + ?translations:translations Solidtype.Check.value -> + ?as_:(Solidtype.Html.Div.props -> Jsx.element) -> + ?props:'spread S.rest -> + (?children:('f, [ `elements ]) Solidtype.Check.children -> unit -> unit) + Solidtype.Html.Div.check + end + + val make : Props.t -> Jsx.element + val component : Props.t Jsx.component +end + +(** A calendar of a range of dates: a press, or Enter, on a day begins it, and + the range shown runs from that day to the one hovered or focused, until a + second press ends it; a drag from a day chooses the days it crosses, and one + from an end of the range chosen moves that end. While a range is begun it + reaches no further than the nearest unavailable day, unless + [allows_non_contiguous_ranges]; Escape lets it go, and a pointer let go of + outside the days, or the focus leaving, ends it as [commit_behavior] says: + [`select] the focused day, [`reset] the range begun let go, [`clear] the + value too, [on_change] told [None]. Its cells are [data-selection-start] and + [data-selection-end] at the range's ends. [is_date_unavailable] is given the + range's first date beside each, while one is begun, so the days a range may + end on can turn on where it starts. *) +module Root_range : sig + module Props : sig + type t + + val check : + ?value:range Js.Nullable.t Solidtype.Check.value -> + ?default_value:range Solidtype.Check.value -> + ?on_change:(range option -> unit) -> + ?allows_non_contiguous_ranges:bool Solidtype.Check.value -> + ?commit_behavior:[ `clear | `reset | `select ] Solidtype.Check.value -> + ?focused_value:D.Types.CalendarDate.t Solidtype.Check.value -> + ?default_focused_value:D.Types.CalendarDate.t Solidtype.Check.value -> + ?on_focus_change:(D.Types.CalendarDate.t -> unit) -> + ?min_value:D.Types.CalendarDate.t Solidtype.Check.value -> + ?max_value:D.Types.CalendarDate.t Solidtype.Check.value -> + ?is_date_unavailable: + (D.Types.CalendarDate.t -> D.Types.CalendarDate.t option -> bool) -> + ?visible_duration:duration Solidtype.Check.value -> + ?page_behavior:[ `visible | `single ] Solidtype.Check.value -> + ?selection_alignment:[ `start | `center | `end_ ] Solidtype.Check.value -> + ?first_day_of_week:day_of_week Solidtype.Check.value -> + ?weeks_in_month:int Solidtype.Check.value -> + ?is_disabled:bool Solidtype.Check.value -> + ?is_read_only:bool Solidtype.Check.value -> + ?is_invalid:bool Solidtype.Check.value -> + ?auto_focus:bool Solidtype.Check.value -> + ?aria_label:string Solidtype.Check.value -> + ?aria_labelledby:string Solidtype.Check.value -> + ?aria_describedby:string Solidtype.Check.value -> + ?translations:translations Solidtype.Check.value -> + ?as_:(Solidtype.Html.Div.props -> Jsx.element) -> + ?props:'spread S.rest -> + (?children:('f, [ `elements ]) Solidtype.Check.children -> unit -> unit) + Solidtype.Html.Div.check + end + + val make : Props.t -> Jsx.element + val component : Props.t Jsx.component +end + +(** What the calendar shows, an [

] a reader skips, since the calendar is + named by it: the month and year, [November 2026], or the days of a week's or + a day's view, [November 16 – 22, 2026]. Given [offset], the month that far + from the first shown, for a calendar of several months; given [format], the + parts of the date it writes. *) +module Heading : sig + module Props : sig + type t + + val check : + ?offset:duration Solidtype.Check.value -> + ?format:D.Types.DateTimeFormatOptions.t Solidtype.Check.value -> + ?as_:(Solidtype.Html.H2.props -> Jsx.element) -> + ?props:'spread S.rest -> + (?children:('f, [ `elements ]) Solidtype.Check.children -> unit -> unit) + Solidtype.Html.H2.check + end + + val make : Props.t -> Jsx.element + val component : Props.t Jsx.component +end + +(** What shows the page before, a [