diff --git a/CHANGES.md b/CHANGES.md index 39ecbe6..cf6f200 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,53 @@ # Changes +## 0.15.1 (2026-11-23) + +- `List_view`, a list of rows in HeroUI's look, on a headless + `Solidtype_headless.Grid_list` made of Kobalte's selection hooks: rows + chosen by a checkbox, the keys or a press, toggle or replace, actions and + links, disabled rows, an empty state, primary and secondary, and + `virtualized`, drawing only the rows in view, each `row_height` high. Its + look is `list-view.css`. +- `Rating`, Kobalte's rating in HeroUI's look: chosen by a press or the + keys, previewed under the pointer, three sizes, its colours by CSS + variables, an icon for every item or per item, a render function, + disabled, and read only with a fractional value filled in part. Its look + is `rating.css`. +- `Action_bar`, a `Toolbar` that floats at the foot of the page while open, + for what can be done with what is chosen, sliding in and out. Its look is + `action-bar.css`. +- `Toolbar`, HeroUI's, on a headless `Solidtype_headless.Toolbar`: the + arrows of its orientation move between its stops, what Tab reaches in it, + so a toggle group is one stop that keeps its own arrows. A `Separator` + inside it runs across it, a `Button_group` or `Toggle_button_group` along + it, unless either gives its own orientation. +- `Inline_select`, a select drawn as text with no field around it, for a + choice made in a sentence, a toolbar or a cell: its trigger muted until + hovered, chevrons up and down or an icon given, its list at the trigger's + bottom end. Its look is `inline-select.css`, in the plugin's + `heroui-extras.css`. +- `Select.Popover` takes every placement React Aria names, `` `bottom_end ``, + `` `top_start ``, `` `left_top `` and the rest, as `Dropdown.Popover` does, + where it took a side alone. +- A virtualized `Table`'s header, and so a virtualized `Data_grid`'s, hides + the rows that scroll beneath it, where they showed through it. +- A virtualized `Table` prerendered on the server tells a reader its rows + and columns, `aria-rowcount` and `aria-colcount`, where it said one row and + no column, and kept saying so once hydrated. +- A `Field_error` inside a `Checkbox_group` or a `Radio_group` shows while + the group is invalid and describes the group and each control in it, after + its description, where it raised. +- A press on a control inside an `Autocomplete`'s trigger, a tag's remove + button in its value, is the control's: the list no longer opens with it. +- `Switch.Icon`, an icon in the switch's thumb, which now takes children, as + HeroUI's does. +- A press inside a `Table`'s or `Data_grid`'s cell is the control's + wherever it lands: an `Autocomplete`'s value, a date field's segments, a + tab, a slider or any group of controls no longer runs the row's action. +- A virtualized or resizable `Data_grid` draws its checkbox and handle + columns 40px and 32px wide, header and cells alike, where its layout gave + them 75px and its header kept 40px. + ## 0.15.0 (2026-11-23) - Breaking: what Kobalte types `any` is no longer a type its reader diff --git a/agents/llms.txt b/agents/llms.txt index 1efc645..326274a 100644 --- a/agents/llms.txt +++ b/agents/llms.txt @@ -102,9 +102,11 @@ Each component's page gives HeroUI's own examples in OCaml, and a table of its p - [ColorSwatchPicker](pages/heroui/color-swatch-picker.md): A list of color swatches that allows users to select a color from a predefined palette. - [Slider](pages/heroui/slider.md): A slider allows a user to select one or more values within a range. - [Switch](pages/heroui/switch.md): A toggle switch component for boolean states. +- [Action Bar](pages/heroui/action-bar.md): A floating toolbar for what can be done with what is chosen. - [Badge](pages/heroui/badge.md): Displays a small indicator positioned relative to another element, commonly used for notification counts, status dots, and labels. - [Chip](pages/heroui/chip.md): Small informational badges for displaying labels, statuses, and categories. - [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. +- [List View](pages/heroui/list-view.md): A one-column list of rows, chosen and acted on by the keys and the pointer. - [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. @@ -133,12 +135,14 @@ Each component's page gives HeroUI's own examples in OCaml, and a table of its p - [NumberField](pages/heroui/number-field.md): Number input fields with increment/decrement buttons, validation, and internationalized formatting. - [NumberStepper](pages/heroui/number-stepper.md): A number between two round buttons, which rolls to each new value. - [Radio Group](pages/heroui/radio-group.md): Radio group for selecting a single option from a list. +- [Rating](pages/heroui/rating.md): A star rating, chosen by a press or the arrow keys, or shown read only as a fraction. - [SearchField](pages/heroui/search-field.md): Search input field with clear button and search icon. - [TextArea](pages/heroui/text-area.md): Primitive multiline text input component that accepts standard HTML attributes. - [TextField](pages/heroui/text-field.md): Composition-friendly text fields with labels, descriptions, and inline validation. - [Card](pages/heroui/card.md): Flexible container component for grouping related content and actions. - [Separator](pages/heroui/separator.md): Visually divide content sections. - [Surface](pages/heroui/surface.md): Container component that provides surface-level styling and context for child components. +- [Toolbar](pages/heroui/toolbar.md): A container for interactive controls with arrow key navigation. - [Avatar](pages/heroui/avatar.md): Display user profile images with customizable fallback content. - [AvatarGroup](pages/heroui/avatar-group.md): Display a stacked or grid group of avatars with overflow counting. - [Accordion](pages/heroui/accordion.md): A collapsible content panel for organizing information in a compact space. @@ -157,6 +161,7 @@ Each component's page gives HeroUI's own examples in OCaml, and a table of its p - [Tooltip](pages/heroui/tooltip.md): Displays informative text when users hover over or focus on an element. - [Autocomplete](pages/heroui/autocomplete.md): An autocomplete combines a select with filtering, allowing users to search and select from a list of options. - [ComboBox](pages/heroui/combo-box.md): A combo box combines a text input with a listbox, allowing users to filter a list of options to items matching a query. +- [Inline Select](pages/heroui/inline-select.md): A select drawn as text, for a choice made in a sentence, a toolbar or a cell. - [Select](pages/heroui/select.md): A select displays a collapsible list of options and allows a user to select one of them. - [Kbd](pages/heroui/kbd.md): Display keyboard shortcuts and key combinations. - [Typography](pages/heroui/typography.md): A semantic typography primitive for headings, body copy, and inline code. diff --git a/agents/pages/heroui.md b/agents/pages/heroui.md index 0c1b4e7..b33930c 100644 --- a/agents/pages/heroui.md +++ b/agents/pages/heroui.md @@ -69,8 +69,8 @@ let make () = ## How far it goes -65 of HeroUI 3.2's components are ported; -[Coverage](heroui/coverage.md) lists each, what it does, and the 9 +66 of HeroUI 3.2's components are ported; +[Coverage](heroui/coverage.md) lists each, what it does, and the one still to come. Every component has its page in this section, with HeroUI's own examples written in OCaml. diff --git a/agents/pages/heroui/action-bar.md b/agents/pages/heroui/action-bar.md new file mode 100644 index 0000000..9de937a --- /dev/null +++ b/agents/pages/heroui/action-bar.md @@ -0,0 +1,308 @@ +# Action Bar + +A floating toolbar for what can be done with what is chosen. + +A [Toolbar](toolbar.md) that floats at the foot of the page +while `is_open`, sliding in and out. Its look is a stylesheet the library +ships, imported as [Theming](theming.md#setup) shows. + +## Usage + +Choose rows to see it. + +```ocaml title="action_bar_usage.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Action_bar = Solidtype_heroui.Action_bar +module Button = Solidtype_heroui.Button +module Chip = Solidtype_heroui.Chip +module List_view = Solidtype_heroui.List_view +module Separator = Solidtype_heroui.Separator +module Gravity = Solidtype_gravity_icons + +let files = + [| + ("proposal", "Project proposal.pdf"); + ("report", "Q4 financial report.xlsx"); + ("brand", "Brand guidelines.fig"); + ("photo", "Team photo.jpg"); + ("notes", "Meeting notes.md"); + ("api", "API documentation.pdf"); + |] + +let make () = + let chosen, set_chosen = S.create_signal [||] in +
+ S.set set_chosen keys)> + + (fun (id, name) _ -> + + + (Jsx.string name) + + ) + + + 0)> + + + (Jsx.int (Array.length (S.get chosen))) + + + + + + + + + + + + + + + +
+``` + +## With Data Grid + +```ocaml title="data_grid_bulk_actions.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Action_bar = Solidtype_heroui.Action_bar +module Avatar = Solidtype_heroui.Avatar +module Button = Solidtype_heroui.Button +module Chip = Solidtype_heroui.Chip +module Data_grid = Solidtype_heroui.Data_grid +module Separator = Solidtype_heroui.Separator +module Gravity = Solidtype_gravity_icons +module I18n = Solidtype_kobalte.I18n +module Types = Solidtype_kobalte.Types + +type status = Active | Pending | Inactive + +type employee = { + id : string; + name : string; + email : string; + department : string; + status : status; + joined : string; + avatar : int; +} + +let employee id name email department status joined avatar = + { id; name; email; department; status; joined; avatar } + +let employees = + [| + employee "1" "Amara Okafor" "amara.okafor@company.com" "Support" Pending + "2024-06-27" 25; + employee "2" "Elena Rodriguez" "elena.rodriguez@company.com" "HR" Active + "2024-01-28" 20; + employee "3" "James O'Brien" "james.o.brien@company.com" "Finance" Active + "2024-04-14" 23; + employee "4" "Luca Bianchi" "luca.bianchi@company.com" "Engineering" Active + "2024-07-25" 21; + employee "5" "Marcus Chen" "marcus.chen@company.com" "Design" Pending + "2024-02-03" 22; + employee "6" "Priya Patel" "priya.patel@company.com" "HR" Active + "2024-03-04" 24; + employee "7" "Yuki Tanaka" "yuki.tanaka@company.com" "Product" Inactive + "2024-05-08" 26; + |] + +let status_name = function + | Active -> "Active" + | Pending -> "Pending" + | Inactive -> "Inactive" + +let status_color = function + | Active -> `success + | Pending -> `warning + | Inactive -> `danger + +let columns day = + [| + Data_grid.column ~id:"name" ~header:(Text "Employee") ~is_row_header:true + ~sort:(By_text (fun e -> e.name)) + (fun e -> +
+ + + +
+ + (Jsx.string (S.get e).name) + + + (Jsx.string (S.get e).email) + +
+
); + Data_grid.column ~id:"department" ~header:(Text "Department") + ~sort:(By_text (fun e -> e.department)) + (fun e -> Jsx.string (S.get e).department); + Data_grid.column ~id:"status" ~header:(Text "Status") + ~sort:(By_text (fun e -> status_name e.status)) + (fun e -> + + + (Jsx.string (status_name (S.get e).status)) + ); + Data_grid.column ~id:"joined" ~header:(Text "Joined") + ~sort:(By (fun a b -> String.compare a.joined b.joined)) + (fun e -> + + (Jsx.string + (Types.DateTimeFormat.format (S.get day) + ~date:(Types.Either.right (Js.Date.fromString (S.get e).joined)) + ())) + ); + |] + +let make () = + let chosen, set_chosen = S.create_signal [||] in + let day = + I18n.create_date_formatter + (Types.Either.left + (Types.DateTimeFormatOptions.make ~year:"numeric" ~month:"short" + ~day:"numeric" ~time_zone:"UTC" ())) + in +
+ e.id) + columns=(columns day) + selection_mode=`multiple + show_selection_checkboxes=true + selected_keys=(S.get chosen) + on_selection_change=(fun keys -> S.set set_chosen keys) + default_sort_descriptor={ column = "name"; direction = `ascending } + content_class="min-w-[640px]" + /> + 0) aria_label="Bulk actions"> + + + (Jsx.int (Array.length (S.get chosen))) + + + + + + + + + + + + + + +
+``` + +## Anatomy + +```ocaml + + ... + + ... + + ... + +``` + +Each section is optional; a `Separator` between them runs across the bar. + +## Responsive Labels + +Text of the class `action-bar__label` is read but not shown below 640 pixels, +so a button there shows its icon alone. + +## Styling Reference + +### CSS Classes + +- `.action-bar` - Fixed at the foot of the page, centred; `[data-entering]` + and `[data-exiting]` while it slides +- `.action-bar__wrapper` - The bar itself, its toolbar +- `.action-bar__prefix` - Its leading section +- `.action-bar__content` - Its actions +- `.action-bar__suffix` - Its trailing section +- `.action-bar__label` - Text hidden below 640 pixels + +## API Reference + +### Action_bar + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `isOpen` | `is_open` | `bool` | | Whether it is shown | +| `aria-label` | `aria_label` | `string` | `"Actions"` | Its name | +| `isAttached` | `is_attached` | `bool` | `true` | Whether its toolbar has a surface, fully rounded | +| `orientation` | `orientation` | `` [ `horizontal \| `vertical ] `` | `` `horizontal `` | Its toolbar's orientation | +| `className` | `class_` | `string` | | Added after its toolbar's classes | + +### Action_bar.Prefix, Content, Suffix + +| React | solidtype | Type | Description | +|---|---|---|---| +| `className` | `class_` | `string` | Added after its own class | +| `children` | `children` | elements | What it holds | diff --git a/agents/pages/heroui/autocomplete.md b/agents/pages/heroui/autocomplete.md index 396fec7..723b455 100644 --- a/agents/pages/heroui/autocomplete.md +++ b/agents/pages/heroui/autocomplete.md @@ -6,22 +6,62 @@ Original HeroUI documentation: [Autocomplete](https://heroui.com/en/docs/react/c ## Usage -HeroUI's example draws the states chosen as tags, with a TagGroup, which is -not ported yet; here they are listed as the value draws them. - ```ocaml title="autocomplete_usage.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For module Autocomplete = Solidtype_heroui.Autocomplete module Empty_state = Solidtype_heroui.Empty_state module Label = Solidtype_heroui.Label module List_box = Solidtype_heroui.List_box module Search_field = Solidtype_heroui.Search_field +module Tag = Solidtype_heroui.Tag +module Tag_group = Solidtype_heroui.Tag_group + +let states = + [| + ("florida", "Florida"); + ("delaware", "Delaware"); + ("california", "California"); + ("texas", "Texas"); + ("new-york", "New York"); + ("washington", "Washington"); + |] + +let name_of id = + match Array.find_opt (fun (k, _) -> String.equal k id) states with + | Some (_, name) -> name + | None -> id let make () = + let chosen, set_chosen = S.create_signal [||] in + let remove keys = + S.set set_chosen + (Js.Array.filter (S.get chosen) ~f:(fun k -> + not (Array.exists (String.equal k) keys))) + in + class_="w-[256px]" + placeholder="Select states" + selection_mode=`multiple + value=(S.get chosen) + on_change=(fun keys -> S.set set_chosen keys)> - + + (fun value -> + + + + (fun id _ -> + + (Jsx.string (name_of id)) + ) + + + ) + + @@ -37,24 +77,12 @@ let make () = render_empty_state=(fun _ -> "No results found") selection_mode=`multiple> - - "Florida" - - - "Delaware" - - - "California" - - - "Texas" - - - "New York" - - - "Washington" - + + (fun (id, name) _ -> + + (Jsx.string name) + ) + @@ -1434,6 +1462,150 @@ let make () = ``` +### User Selection Multiple + +```ocaml title="autocomplete_user_selection_multiple.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Avatar = Solidtype_heroui.Avatar +module Description = Solidtype_heroui.Description +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box +module Autocomplete = Solidtype_heroui.Autocomplete +module Empty_state = Solidtype_heroui.Empty_state +module Search_field = Solidtype_heroui.Search_field +module Tag = Solidtype_heroui.Tag +module Tag_group = Solidtype_heroui.Tag_group + +type user = { + avatar_url : string; + email : string; + fallback : string; + id : string; + name : string; +} + +let users = + [| + { + avatar_url = + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/blue.jpg"; + email = "bob@heroui.com"; + fallback = "B"; + id = "1"; + name = "Bob"; + }; + { + avatar_url = + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/green.jpg"; + email = "fred@heroui.com"; + fallback = "F"; + id = "2"; + name = "Fred"; + }; + { + avatar_url = + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/purple.jpg"; + email = "martha@heroui.com"; + fallback = "M"; + id = "3"; + name = "Martha"; + }; + { + avatar_url = + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/red.jpg"; + email = "john@heroui.com"; + fallback = "J"; + id = "4"; + name = "John"; + }; + { + avatar_url = + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/orange.jpg"; + email = "jane@heroui.com"; + fallback = "J"; + id = "5"; + name = "Jane"; + }; + |] + +let make () = + let chosen, set_chosen = S.create_signal [||] in + let remove keys = + S.set set_chosen + (Js.Array.filter (S.get chosen) ~f:(fun k -> + not (Array.exists (String.equal k) keys))) + in + let user_of id = + Array.find_opt (fun (u : user) -> String.equal u.id id) users + in + S.set set_chosen keys)> + + + + (fun value -> + + + + (fun id _ -> + match user_of id with + | Some user -> + + + + + (Jsx.string user.fallback) + + + (Jsx.string user.name) + + | None -> Jsx.nothing) + + + ) + + + + + + + + + + + + + + + "No results found") + selection_mode=`multiple> + + (fun (user : user) _ -> + + + + (Jsx.string user.fallback) + +
+ + (Jsx.string user.email) +
+ +
) +
+
+
+
+
+``` + ### Location Search ```ocaml title="autocomplete_location_search.mlx" @@ -1533,18 +1705,298 @@ let make () = ``` -### User Selection Multiple, Tag Group Selection, Email Recipients +### Tag Group Selection -These draw the options chosen as tags, with HeroUI's TagGroup, which is not -ported yet. +```ocaml title="autocomplete_tag_group_selection.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Autocomplete = Solidtype_heroui.Autocomplete +module Empty_state = Solidtype_heroui.Empty_state +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box +module Search_field = Solidtype_heroui.Search_field +module Tag = Solidtype_heroui.Tag +module Tag_group = Solidtype_heroui.Tag_group + +let tags = + [| + ("react", "React"); + ("typescript", "TypeScript"); + ("javascript", "JavaScript"); + ("nodejs", "Node.js"); + ("python", "Python"); + ("vue", "Vue"); + ("angular", "Angular"); + ("nextjs", "Next.js"); + |] + +let name_of id = + match Array.find_opt (fun (k, _) -> String.equal k id) tags with + | Some (_, name) -> name + | None -> id + +let make () = + let chosen, set_chosen = S.create_signal [||] in + let remove keys = + S.set set_chosen + (Js.Array.filter (S.get chosen) ~f:(fun k -> + not (Array.exists (String.equal k) keys))) + in + S.set set_chosen keys)> + + + + (fun value -> + + + + (fun id _ -> + + (Jsx.string (name_of id)) + ) + + + ) + + + + + + + + + + + + + + + "No tags found") + selection_mode=`multiple> + + (fun (id, name) _ -> + + (Jsx.string name) + ) + + + + + +``` + +### Email Recipients + +```ocaml title="autocomplete_email_recipients.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Autocomplete = Solidtype_heroui.Autocomplete +module Description = Solidtype_heroui.Description +module Empty_state = Solidtype_heroui.Empty_state +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box +module Search_field = Solidtype_heroui.Search_field +module Tag = Solidtype_heroui.Tag +module Tag_group = Solidtype_heroui.Tag_group + +let people = + [| + ("alice@example.com", "Alice Johnson"); + ("bob@example.com", "Bob Smith"); + ("charlie@example.com", "Charlie Brown"); + ("diana@example.com", "Diana Prince"); + ("eve@example.com", "Eve Wilson"); + |] + +let make () = + let chosen, set_chosen = S.create_signal [||] in + let remove keys = + S.set set_chosen + (Js.Array.filter (S.get chosen) ~f:(fun k -> + not (Array.exists (String.equal k) keys))) + in + S.set set_chosen keys)> + + + + (fun value -> + + + + (fun email _ -> + (Jsx.string email)) + + + ) + + + + + + + + + + + + + + + "No recipients found") + selection_mode=`multiple> + + (fun (email, name) _ -> + +
+ + (Jsx.string email) +
+ +
) +
+
+
+
+
+``` ## Customization ### Tailwind CSS -HeroUI's Tailwind example draws the people chosen as tags, with a TagGroup, -which is not ported yet; `class_` is added after HeroUI's classes on every -part, as the examples above show. +`class_` is added after HeroUI's classes on every part. + +```ocaml title="autocomplete_custom_styles.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Autocomplete = Solidtype_heroui.Autocomplete +module Description = Solidtype_heroui.Description +module Empty_state = Solidtype_heroui.Empty_state +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box +module Search_field = Solidtype_heroui.Search_field +module Tag = Solidtype_heroui.Tag +module Tag_group = Solidtype_heroui.Tag_group + +let teammates = + [| + ("sarah", "Sarah Chen", "Product Design"); + ("marcus", "Marcus Lee", "Engineering"); + ("priya", "Priya Patel", "Data Science"); + ("jordan", "Jordan Kim", "Customer Success"); + ("alex", "Alex Rivera", "Marketing"); + |] + +let name_of id = + match Array.find_opt (fun (k, _, _) -> String.equal k id) teammates with + | Some (_, name, _) -> name + | None -> id + +let make () = + let chosen, set_chosen = S.create_signal [||] in + let remove keys = + S.set set_chosen + (Js.Array.filter (S.get chosen) ~f:(fun k -> + not (Array.exists (String.equal k) keys))) + in +
+ S.set set_chosen keys)> + + + "People who will be notified when this task updates." + + + + (fun value -> + + + + (fun id _ -> + + (Jsx.string (name_of id)) + ) + + + ) + + + + + + + + + + + + + + + "No teammates found") + selection_mode=`multiple> + + (fun (id, name, role) _ -> + +
+ + (Jsx.string name) + + (Jsx.string role) +
+ +
) +
+
+
+
+
+
+``` ### Global CSS diff --git a/agents/pages/heroui/checkbox-group.md b/agents/pages/heroui/checkbox-group.md index ce6cda1..ce5f032 100644 --- a/agents/pages/heroui/checkbox-group.md +++ b/agents/pages/heroui/checkbox-group.md @@ -172,10 +172,74 @@ let make () = ``` -### Not yet +### Validation -HeroUI's Validation example validates the group as its form is submitted, -which is not ported yet; `is_invalid` marks it invalid. +A group validates nothing itself, as no field here does: it is invalid as +`is_invalid` says, here once a submit finds nothing chosen, and its +`Field_error` shows while it is. + +```ocaml title="checkbox_group_validation.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Show = Solidtype.Show +module Button = Solidtype_heroui.Button +module Checkbox = Solidtype_heroui.Checkbox +module Checkbox_group = Solidtype_heroui.Checkbox_group +module Field_error = Solidtype_heroui.Field_error +module Form = Solidtype_heroui.Form +module Label = Solidtype_heroui.Label + +external prevent_default : Dom.event -> unit = "preventDefault" [@@mel.send] + +let make () = + let chosen, set_chosen = S.create_signal [] in + let tried, set_tried = S.create_signal false in + let sent, set_sent = S.create_signal None in +
+ prevent_default e; + S.set set_tried true; + S.set set_sent + (match S.get chosen with + | [] -> None + | values -> + Some ("Selected preferences: " ^ String.concat ", " values)))> + + + + + + "Email notifications" + + + + + + "SMS notifications" + + + + + + "Push notifications" + + + + "Please select at least one notification method." + + + + + (fun m ->

(Jsx.string (S.get m))

) +
+
+``` ## Styling Reference diff --git a/agents/pages/heroui/coverage.md b/agents/pages/heroui/coverage.md index 8788f7c..7b09271 100644 --- a/agents/pages/heroui/coverage.md +++ b/agents/pages/heroui/coverage.md @@ -10,7 +10,7 @@ shows it beside the same component in React. | [Accordion](accordion.md) | ported: one or several expanded, controlled or kept, disabled with an item's own, surface, no separator, its own icon, a button given its slot, panels animated by their height and found by find in page, focus moved by the arrows, a trigger's own `on_press` and `is_disabled` | | [Alert](alert.md) | ported: statuses and their icons, indicator, title, description, as a surface | | [AlertDialog](alert-dialog.md) | ported: as Modal, its dialog an `alertdialog` that only its buttons close unless its backdrop says otherwise; statuses and their icons, placements, sizes, a custom portal container | -| [Autocomplete](autocomplete.md) | ported: one or many chosen, controlled or kept, its search a SearchField filtering its ListBox, a filter given, its search's text controlled, an empty state, open controlled or kept, empty collection, clear button, variants, full width, disabled, disabled options, sections, label, description and error, a form's errors; a value drawn as tags not yet | +| [Autocomplete](autocomplete.md) | ported: one or many chosen, controlled or kept, its search a SearchField filtering its ListBox, a filter given, its search's text controlled, an empty state, open controlled or kept, empty collection, clear button, variants, full width, disabled, disabled options, sections, label, description and error, a form's errors, a value drawn as removable tags | | [Avatar](avatar.md) | ported: sizes, colors, variants, image once loaded, fallback | | [AvatarGroup](avatar-group.md) | ported: sizes, colors, variants, max and its count, grid, overlaps | | [Badge](badge.md) | ported: colors, placements, sizes, variants, anchor, label | @@ -60,13 +60,13 @@ shows it beside the same component in React. | [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 | +| [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, its list placed on any side and end, label, description and error, a form's errors; required, its error the application's to show, as a text field's | | [Separator](separator.md) | ported: orientations, variants | | [Skeleton](skeleton.md) | ported: animation types, and the page's `--skeleton-animation` | | [Slider](slider.md) | ported: one value or a range, controlled or kept, step and range, vertical, disabled, output, format options | | [Spinner](spinner.md) | ported: colors, sizes, its icon's gradients unique per spinner | | [Surface](surface.md) | ported: variants, and the variant it gives what is inside it | -| [Switch](switch.md) | ported: sizes, selected, disabled, invalid, interaction state, with HeroUI's Label | +| [Switch](switch.md) | ported: sizes, selected, disabled, invalid, interaction state, with HeroUI's Label, an icon in its thumb, a description, a form's values | | [SwitchGroup](switch.md#group) | ported: orientations | | [Table](table.md) | ported: variants, static rows or rows of data, columns of data, row headers, an empty state, a footer, rows and cells moved through by the keys, rows selected one or many, by a press, the keys or a checkbox, all by the header's, disabled rows, sorted by a column pressed or keyed, its sortable header's chevron, more rows loaded as its end scrolls into view, columns resized by a drag or the keys, columns pinned to either side, a header kept in view, rows reordered by a drag or the keys, rows that hold rows expanded by a chevron or the keys, virtualized, only the rows in view drawn; a tree virtualized not yet | | [Tabs](tabs.md) | ported: selection controlled or kept, horizontal or vertical, primary or secondary, aligned, disabled, manual activation, separators, an indicator that slides between tabs, a list that scrolls by its chevrons, a tab as a link, `href` | @@ -77,18 +77,19 @@ shows it beside the same component in React. | [Toast](toast.md) | ported: provider, placements, the stack collapsed and expanded, its hotkey, variants, indicators, action, loading, custom rendering, queues of its own, update, promise, pause and resume | | [ToggleButton](toggle-button.md) | ported: variants, sizes, icon only, selected controlled or kept, disabled, interaction state | | [ToggleButtonGroup](toggle-button-group.md) | ported: single or multiple selection controlled or kept, empty selection disallowed, sizes, orientations, detached, full width, disabled with a button's own override, separator | +| [Toolbar](toolbar.md) | ported: horizontal and vertical, attached, the arrows of its orientation between its controls and Tab out and back, the separators, button groups and toggle groups inside it turned to it | | [Tooltip](tooltip.md) | ported: on a button or a trigger of its own, placements, arrow, offset, flip, delays of its own or the page's, hover or focus, disabled, open controlled or kept, enter and exit animations | | [Typography](typography.md) | ported: every type and its element, alignments, colors, weights, truncation, primitives, prose | ## Not yet ported -These 2 components of HeroUI 3.2 are not ported yet; each name links to +This component of HeroUI 3.2 is not ported yet; its 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 | [InputOTP](https://heroui.com/en/docs/react/components/input-otp), [Toolbar](https://heroui.com/en/docs/react/components/toolbar) | +| Not yet ported | [InputOTP](https://heroui.com/en/docs/react/components/input-otp) | ## Beyond HeroUI's set @@ -97,9 +98,13 @@ imported as [Theming](theming.md#setup) shows. | Component | Status | |---|---| +| [ActionBar](action-bar.md) | made: a toolbar that floats at the foot of the page while open, sliding in and out, a prefix, content and suffix, labels hidden on small screens | | [Command](command.md) | made: a search that filters a menu of commands in a dialog, kept or controlled, by its text or a filter given, the focus kept in the search while the keys move through the commands shown, groups, separators, an empty state, a header and a footer, sizes, backdrops | -| [Data Grid](data-grid.md) | made: rows as data and columns as definitions, sorted in the browser by text in the page's order or a comparison, or by the application, selection checkboxes, columns resized, pinned to either side and aligned, a header kept in view, rows dragged by a handle and the keys, cells of any control, an empty state, loading more, virtualized, a footer | +| [Data Grid](data-grid.md) | made: rows as data and columns as definitions, sorted in the browser by text in the page's order or a comparison, or by the application, selection checkboxes and an action bar for the rows chosen, columns resized, pinned to either side and aligned, a header kept in view, rows dragged by a handle and the keys, cells of any control, an empty state, loading more, virtualized, a footer | +| [InlineSelect](inline-select.md) | made: a select drawn as text, one option or many, kept or controlled, a trigger of any content, a custom indicator, its list placed on any side and end | +| [ListView](list-view.md) | made: rows chosen one or many by a checkbox, the keys or a press, kept or controlled, toggle or replace, primary and secondary, disabled rows, actions and links, an empty state, a title, a description and an action per row | | [NumberStepper](number-stepper.md) | made: a number field's value, range, step, format and keys, sizes, a value that rolls, a custom value, custom icons and buttons, reversed, disabled | +| [Rating](rating.md) | made: Kobalte's rating, chosen by a press or the keys, previewed under the pointer, kept or controlled, sizes, colours, an icon for all or per item, a render function, disabled, read only with fractional values, in a form | | [Segment](segment.md) | made: one option always selected, controlled or kept, default and ghost, sizes, disabled whole or by option, separators, icons, options that show their label only while selected, an indicator that slides between options | | [TextShimmer](text-shimmer.md) | made: its text's colour, still under reduced motion | | [TrendChip](trend-chip.md) | made: trends, sizes, variants, prefix and suffix, a custom indicator, tabular figures | diff --git a/agents/pages/heroui/data-grid.md b/agents/pages/heroui/data-grid.md index 746bb2b..15b8ea8 100644 --- a/agents/pages/heroui/data-grid.md +++ b/agents/pages/heroui/data-grid.md @@ -30,6 +30,11 @@ type payment = { email : string; status : status; amount : float; + fee : float; + method_ : string; + region : string; + description : string; + date : string; } let payments = @@ -40,20 +45,35 @@ let payments = email = "emma@example.com"; status = Succeeded; amount = 2450.; + fee = 73.5; + method_ = {js|Visa •••• 4242|js}; + region = "North America"; + description = {js|Annual subscription — Enterprise plan|js}; + date = "2025-12-07"; }; { id = "pay_1N3x9M"; customer = "Isabella Nguyen"; email = "isabella@example.com"; status = Succeeded; - amount = 899.; + amount = 299.; + fee = 8.97; + method_ = {js|Visa •••• 1234|js}; + region = "Asia Pacific"; + description = {js|Quarterly subscription — Team plan|js}; + date = "2025-12-03"; }; { id = "pay_1N3x8L"; customer = "Jackson Lee"; email = "jackson@example.com"; status = Processing; - amount = 320.; + amount = 39.; + fee = 1.43; + method_ = {js|Mastercard •••• 5555|js}; + region = "North America"; + description = {js|Monthly add-on — Extra seats|js}; + date = "2025-12-02"; }; { id = "pay_1N3xCQ"; @@ -61,6 +81,11 @@ let payments = email = "liam@example.com"; status = Refunded; amount = 150.; + fee = 4.5; + method_ = {js|Mastercard •••• 6789|js}; + region = "Europe"; + description = {js|Monthly subscription — Pro plan|js}; + date = "2025-12-06"; }; { id = "pay_1N3x7K"; @@ -68,6 +93,23 @@ let payments = email = "olivia@example.com"; status = Succeeded; amount = 1999.; + fee = 59.97; + method_ = {js|Visa •••• 4242|js}; + region = "North America"; + description = {js|Annual subscription — Pro plan|js}; + date = "2025-12-01"; + }; + { + id = "pay_1N3xBP"; + customer = "Sofia Davis"; + email = "sofia@example.com"; + status = Succeeded; + amount = 450.; + fee = 13.5; + method_ = {js|Visa •••• 9012|js}; + region = "Europe"; + description = {js|One-time purchase — Enterprise setup|js}; + date = "2025-12-05"; }; { id = "pay_1N3xAN"; @@ -75,6 +117,11 @@ let payments = email = "will@example.com"; status = Failed; amount = 99.; + fee = 3.17; + method_ = {js|Amex •••• 3782|js}; + region = "Asia Pacific"; + description = {js|Monthly subscription — Starter plan|js}; + date = "2025-12-04"; }; |] @@ -121,20 +168,29 @@ let actions p = -let columns money = +let columns ~money ~day = + let amount ~class_ value = + + (Jsx.string (Types.NumberFormat.format (S.get money) value)) + + in [| Data_grid.column ~id:"customer" ~header:(Text "Customer") - ~is_row_header:true + ~is_row_header:true ~default_width:(Pixels 240.) ~allows_resizing:true ~sort:(By_text (fun p -> p.customer)) (fun p ->
- (Jsx.string (S.get p).customer) + + (Jsx.string (S.get p).customer) + (Jsx.string (S.get p).email)
); Data_grid.column ~id:"id" ~header:(Text "Transaction ID") + ~default_width:(Pixels 130.) ~allows_resizing:true ~cell_class:"font-mono text-xs text-muted" (fun p -> Jsx.string (S.get p).id); Data_grid.column ~id:"status" ~header:(Text "Status") + ~default_width:(Pixels 120.) ~allows_resizing:true ~sort:(By_text (fun p -> status_name p.status)) (fun p -> ); Data_grid.column ~id:"amount" ~header:(Text "Amount") ~align:`end_ + ~default_width:(Pixels 110.) ~allows_resizing:true ~sort:(By (fun a b -> Float.compare a.amount b.amount)) - ~cell_class:"tabular-nums" + (fun p -> amount ~class_:"font-medium tabular-nums" (S.get p).amount); + Data_grid.column ~id:"fee" ~header:(Text "Fee") ~align:`end_ + ~default_width:(Pixels 90.) ~allows_resizing:true + ~sort:(By (fun a b -> Float.compare a.fee b.fee)) + (fun p -> amount ~class_:"text-muted tabular-nums" (S.get p).fee); + Data_grid.column ~id:"net" ~header:(Text "Net") ~align:`end_ + ~default_width:(Pixels 110.) ~allows_resizing:true + ~sort: + (By (fun a b -> Float.compare (a.amount -. a.fee) (b.amount -. b.fee))) + (fun p -> + amount ~class_:"font-medium tabular-nums" + ((S.get p).amount -. (S.get p).fee)); + Data_grid.column ~id:"method" ~header:(Text "Payment Method") + ~default_width:(Pixels 170.) ~allows_resizing:true (fun p -> + Jsx.string (S.get p).method_); + Data_grid.column ~id:"region" ~header:(Text "Region") + ~default_width:(Pixels 130.) ~allows_resizing:true + ~sort:(By_text (fun p -> p.region)) + (fun p -> Jsx.string (S.get p).region); + Data_grid.column ~id:"description" ~header:(Text "Description") + ~default_width:(Pixels 240.) ~allows_resizing:true + ~cell_class:"text-muted" (fun p -> Jsx.string (S.get p).description); + Data_grid.column ~id:"date" ~header:(Text "Date") + ~default_width:(Pixels 120.) ~allows_resizing:true + ~sort:(By (fun a b -> String.compare a.date b.date)) (fun p -> - Jsx.string (Types.NumberFormat.format (S.get money) (S.get p).amount)); + + (Jsx.string + (Types.DateTimeFormat.format (S.get day) + ~date:(Types.Either.right (Js.Date.fromString (S.get p).date)) + ())) + ); Data_grid.column ~id:"actions" ~header:(Element (fun () -> "Actions")) ~align:`end_ ~pinned:`end_ ~width:(Pixels 72.) actions; @@ -161,15 +247,22 @@ let make () = (Types.Either.left (Types.NumberFormatOptions.make ~style:`currency ~currency:"USD" ())) in + let day = + I18n.create_date_formatter + (Types.Either.left + (Types.DateTimeFormatOptions.make ~year:"numeric" ~month:"short" + ~day:"numeric" ~time_zone:"UTC" ())) + in p.id) - columns=(columns money) + columns=(columns ~money ~day) selection_mode=`multiple show_selection_checkboxes=true default_sort_descriptor={ column = "customer"; direction = `ascending } - content_class="min-w-[720px]" + allows_column_resize=true + content_class="min-w-[1400px]" /> ``` @@ -611,21 +704,34 @@ let make () = ## Editable Cells -A cell draws any control: a `Select`, a +A cell draws any control: an input, an +[`Inline_select`](inline-select.md), a [`Number_stepper`](number-stepper.md), a `Switch`. Every key of a field is its own, and the arrows from a button move between cells. ```ocaml title="data_grid_editable_cells.mlx" module S = Solidtype.Solid module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Show = Solidtype.Show +module Button = Solidtype_heroui.Button module Chip = Solidtype_heroui.Chip module Data_grid = Solidtype_heroui.Data_grid +module Inline_select = Solidtype_heroui.Inline_select +module Input = Solidtype_heroui.Input module List_box = Solidtype_heroui.List_box module Number_stepper = Solidtype_heroui.Number_stepper -module Select = Solidtype_heroui.Select module Switch = Solidtype_heroui.Switch +module Gravity = Solidtype_gravity_icons + +external target : Dom.inputEvent -> Dom.htmlInputElement = "target" [@@mel.get] +external value_of : Dom.htmlInputElement -> string = "value" [@@mel.get] +external key : Dom.keyboardEvent -> string = "key" [@@mel.get] +external focus : Dom.htmlInputElement -> unit = "focus" [@@mel.send] +external focus_button : Dom.htmlButtonElement -> unit = "focus" [@@mel.send] +external select_text : Dom.htmlInputElement -> unit = "select" [@@mel.send] -type priority = Low | Medium | High +type priority = High | Medium | Low type flag = { id : string; @@ -635,64 +741,126 @@ type flag = { enabled : bool; } +let flag id feature priority points enabled = + { id; feature; priority; points; enabled } + let flags = [| - { - id = "1"; - feature = "Dark mode"; - priority = High; - points = 8.; - enabled = true; - }; - { - id = "2"; - feature = "CSV export"; - priority = Medium; - points = 6.; - enabled = true; - }; - { - id = "3"; - feature = "Keyboard shortcuts"; - priority = Low; - points = 5.; - enabled = false; - }; - { - id = "4"; - feature = "Two-factor auth"; - priority = Medium; - points = 16.; - enabled = true; - }; - { - id = "5"; - feature = "Bulk import"; - priority = Medium; - points = 8.; - enabled = false; - }; - { - id = "6"; - feature = "Audit log"; - priority = High; - points = 5.; - enabled = true; - }; + flag "1" "Dark mode" High 8. true; + flag "2" "CSV export" Medium 3. true; + flag "3" "Keyboard shortcuts" Low 5. false; + flag "4" "Two-factor auth" High 13. true; + flag "5" "Bulk import" Medium 8. false; + flag "6" "Audit log" High 5. true; + flag "7" "Webhooks" Low 3. false; + flag "8" "Custom branding" Medium 8. true; |] -let priority_key = function Low -> "low" | Medium -> "medium" | High -> "high" -let priority_of = function "high" -> High | "medium" -> Medium | _ -> Low +let priorities = [| High; Medium; Low |] +let priority_key = function High -> "high" | Medium -> "medium" | Low -> "low" let priority_name = function - | Low -> "Low" - | Medium -> "Medium" | High -> "High" + | Medium -> "Medium" + | Low -> "Low" let priority_color = function - | Low -> `default - | Medium -> `warning | High -> `danger + | Medium -> `warning + | Low -> `default + +let priority_chip p = + + (Jsx.string (priority_name p)) + + +(* The title as an input, its text chosen as it opens: Enter or Save keeps + it, Escape or Cancel leaves the title as it was. *) +let title_editor ~title ~save ~cancel = + let draft, set_draft = S.create_signal title in + let field = ref None in + S.on_mount (fun () -> + Option.iter + (fun e -> + focus e; + select_text e) + !field); + let keep () = + match String.trim (S.get draft) with "" -> cancel () | t -> save t + in +
+ field := Some e) + on_input=(fun e -> S.set set_draft (value_of (target e))) + on_key_down=(fun e -> + match key e with + | "Enter" -> keep () + | "Escape" -> cancel () + | _ -> ()) + /> + + +
+ +(* Shown while its row is hovered, or reached by the keys. *) +let edit_button ~ref ~on_click = + + +(* The title, and its button, which takes the focus back as editing ends, + since the input that had it is gone. *) +let title_cell ~title ~rename = + let editing, set_editing = S.create_signal false in + let button = ref None in + let finish () = + S.set set_editing false; + Option.iter focus_button !button + in + + + (Jsx.string (S.get title)) + + (edit_button + ~ref:(fun b -> button := Some b) + ~on_click:(fun () -> S.set set_editing true)) + )> + (title_editor ~title:(S.get title) + ~save:(fun t -> + rename t; + finish ()) + ~cancel:finish) + + +let summary = + "Edit titles, change priorities, adjust story points, and toggle features \ + inline." let make () = let rows, set_rows = S.create_signal flags in @@ -705,50 +873,46 @@ let make () = let columns = [| Data_grid.column ~id:"feature" ~header:(Text "Feature") - ~is_row_header:true ~cell_class:"font-medium" (fun row -> - Jsx.string (S.get row).feature); + ~is_row_header:true ~width:(Pixels 300.) (fun row -> + title_cell + ~title:(S.accessor (fun () -> (S.get row).feature)) + ~rename:(fun feature -> + change (S.get row).id (fun r -> { r with feature }))); Data_grid.column ~id:"priority" ~header:(Text "Priority") - ~width:(Pixels 200.) (fun row -> - ); - Data_grid.column ~id:"points" ~header:(Text "Story points") ~align:`center - ~width:(Pixels 160.) (fun row -> + + ); + Data_grid.column ~id:"points" ~header:(Text "Story Points") ~align:`center + ~width:(Pixels 167.) (fun row -> ); Data_grid.column ~id:"enabled" ~header:(Text "Enabled") ~align:`center - ~width:(Pixels 100.) (fun row -> + ~width:(Pixels 117.) (fun row -> change (S.get row).id (fun r -> { r with enabled }))> @@ -780,26 +944,31 @@ let make () = let effort () = Array.fold_left (fun sum r -> sum +. r.points) 0. (S.get rows) in - r.id) - columns - content_class="min-w-[640px]" - footer=( - - (Jsx.string - (string_of_int (enabled ()) - ^ " of " - ^ string_of_int (Array.length (S.get rows)) - ^ " enabled")) - - - (Jsx.string - ("Total effort: " ^ Js.Float.toString (effort ()) ^ " pts")) - - ) - /> +
+
+

"Feature Flags"

+

(Jsx.string summary)

+
+ r.id) + columns + content_class="min-w-[640px]" + /> +
+ + (Jsx.string + (string_of_int (enabled ()) + ^ " of " + ^ string_of_int (Array.length (S.get rows)) + ^ " enabled")) + + + (Jsx.string ("Total effort: " ^ Js.Float.toString (effort ()) ^ " pts")) + +
+
``` ## Empty State @@ -916,56 +1085,732 @@ let make () = ## Sticky Header `sticky_header` keeps the header at the top of the scroll container, which -`scroll_container_class` gives a height or a maximum height; the grid above -keeps its header so. +`scroll_container_class` gives a height or a maximum height. Rows keep their +own heights, and selection, sorting, pinned columns and resizing work as in any +grid. + +```ocaml title="data_grid_sticky_header.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Button = Solidtype_heroui.Button +module Chip = Solidtype_heroui.Chip +module Data_grid = Solidtype_heroui.Data_grid +module Dropdown = Solidtype_heroui.Dropdown +module Label = Solidtype_heroui.Label +module Gravity = Solidtype_gravity_icons +module I18n = Solidtype_kobalte.I18n +module Types = Solidtype_kobalte.Types + +type status = Succeeded | Processing | Refunded | Failed + +type payment = { + id : string; + customer : string; + email : string; + status : status; + amount : float; + fee : float; + method_ : string; + region : string; + description : string; + date : string; +} + +let payments = + [| + { + id = "pay_1N3xDR"; + customer = "Emma Wilson"; + email = "emma@example.com"; + status = Succeeded; + amount = 2450.; + fee = 73.5; + method_ = {js|Visa •••• 4242|js}; + region = "North America"; + description = {js|Annual subscription — Enterprise plan|js}; + date = "2025-12-07"; + }; + { + id = "pay_1N3x9M"; + customer = "Isabella Nguyen"; + email = "isabella@example.com"; + status = Succeeded; + amount = 299.; + fee = 8.97; + method_ = {js|Visa •••• 1234|js}; + region = "Asia Pacific"; + description = {js|Quarterly subscription — Team plan|js}; + date = "2025-12-03"; + }; + { + id = "pay_1N3x8L"; + customer = "Jackson Lee"; + email = "jackson@example.com"; + status = Processing; + amount = 39.; + fee = 1.43; + method_ = {js|Mastercard •••• 5555|js}; + region = "North America"; + description = {js|Monthly add-on — Extra seats|js}; + date = "2025-12-02"; + }; + { + id = "pay_1N3xCQ"; + customer = "Liam Johnson"; + email = "liam@example.com"; + status = Refunded; + amount = 150.; + fee = 4.5; + method_ = {js|Mastercard •••• 6789|js}; + region = "Europe"; + description = {js|Monthly subscription — Pro plan|js}; + date = "2025-12-06"; + }; + { + id = "pay_1N3x7K"; + customer = "Olivia Martin"; + email = "olivia@example.com"; + status = Succeeded; + amount = 1999.; + fee = 59.97; + method_ = {js|Visa •••• 4242|js}; + region = "North America"; + description = {js|Annual subscription — Pro plan|js}; + date = "2025-12-01"; + }; + { + id = "pay_1N3xBP"; + customer = "Sofia Davis"; + email = "sofia@example.com"; + status = Succeeded; + amount = 450.; + fee = 13.5; + method_ = {js|Visa •••• 9012|js}; + region = "Europe"; + description = {js|One-time purchase — Enterprise setup|js}; + date = "2025-12-05"; + }; + { + id = "pay_1N3xAN"; + customer = "William Kim"; + email = "will@example.com"; + status = Failed; + amount = 99.; + fee = 3.17; + method_ = {js|Amex •••• 3782|js}; + region = "Asia Pacific"; + description = {js|Monthly subscription — Starter plan|js}; + date = "2025-12-04"; + }; + |] + +let status_name = function + | Succeeded -> "Succeeded" + | Processing -> "Processing" + | Refunded -> "Refunded" + | Failed -> "Failed" + +let status_color = function + | Succeeded -> `success + | Processing -> `warning + | Refunded -> `default + | Failed -> `danger + +let actions p = + + + + ())> + + + + + + + + + + + + + + + + + + + + +let columns ~money ~day = + let amount ~class_ value = + + (Jsx.string (Types.NumberFormat.format (S.get money) value)) + + in + [| + Data_grid.column ~id:"customer" ~header:(Text "Customer") + ~is_row_header:true ~default_width:(Pixels 240.) ~allows_resizing:true + ~sort:(By_text (fun p -> p.customer)) + (fun p -> +
+ + (Jsx.string (S.get p).customer) + + (Jsx.string (S.get p).email) +
); + Data_grid.column ~id:"id" ~header:(Text "Transaction ID") + ~default_width:(Pixels 130.) ~allows_resizing:true + ~cell_class:"font-mono text-xs text-muted" (fun p -> + Jsx.string (S.get p).id); + Data_grid.column ~id:"status" ~header:(Text "Status") + ~default_width:(Pixels 120.) ~allows_resizing:true + ~sort:(By_text (fun p -> status_name p.status)) + (fun p -> + + + (Jsx.string (status_name (S.get p).status)) + ); + Data_grid.column ~id:"amount" ~header:(Text "Amount") ~align:`end_ + ~default_width:(Pixels 110.) ~allows_resizing:true + ~sort:(By (fun a b -> Float.compare a.amount b.amount)) + (fun p -> amount ~class_:"font-medium tabular-nums" (S.get p).amount); + Data_grid.column ~id:"fee" ~header:(Text "Fee") ~align:`end_ + ~default_width:(Pixels 90.) ~allows_resizing:true + ~sort:(By (fun a b -> Float.compare a.fee b.fee)) + (fun p -> amount ~class_:"text-muted tabular-nums" (S.get p).fee); + Data_grid.column ~id:"net" ~header:(Text "Net") ~align:`end_ + ~default_width:(Pixels 110.) ~allows_resizing:true + ~sort: + (By (fun a b -> Float.compare (a.amount -. a.fee) (b.amount -. b.fee))) + (fun p -> + amount ~class_:"font-medium tabular-nums" + ((S.get p).amount -. (S.get p).fee)); + Data_grid.column ~id:"method" ~header:(Text "Payment Method") + ~default_width:(Pixels 170.) ~allows_resizing:true (fun p -> + Jsx.string (S.get p).method_); + Data_grid.column ~id:"region" ~header:(Text "Region") + ~default_width:(Pixels 130.) ~allows_resizing:true + ~sort:(By_text (fun p -> p.region)) + (fun p -> Jsx.string (S.get p).region); + Data_grid.column ~id:"description" ~header:(Text "Description") + ~default_width:(Pixels 240.) ~allows_resizing:true + ~cell_class:"text-muted" (fun p -> Jsx.string (S.get p).description); + Data_grid.column ~id:"date" ~header:(Text "Date") + ~default_width:(Pixels 120.) ~allows_resizing:true + ~sort:(By (fun a b -> String.compare a.date b.date)) + (fun p -> + + (Jsx.string + (Types.DateTimeFormat.format (S.get day) + ~date:(Types.Either.right (Js.Date.fromString (S.get p).date)) + ())) + ); + Data_grid.column ~id:"actions" + ~header:(Element (fun () -> "Actions")) + ~align:`end_ ~pinned:`end_ ~width:(Pixels 72.) actions; + |] + +let make () = + let money = + I18n.create_number_formatter + (Types.Either.left + (Types.NumberFormatOptions.make ~style:`currency ~currency:"USD" ())) + in + let day = + I18n.create_date_formatter + (Types.Either.left + (Types.DateTimeFormatOptions.make ~year:"numeric" ~month:"short" + ~day:"numeric" ~time_zone:"UTC" ())) + in + p.id) + columns=(columns ~money ~day) + selection_mode=`multiple + show_selection_checkboxes=true + default_sort_descriptor={ column = "customer"; direction = `ascending } + allows_column_resize=true + sticky_header=true + scroll_container_class="max-h-[320px]" + content_class="min-w-[1400px]" + /> +``` ## Virtualization `virtualized` draws only the rows in view, each `row_height` high below a -header `heading_height` high. The table is what scrolls: give it a height by -`content_class`. The keys reach every row. +header `heading_height` high, for a thousand rows or more. The table is what +scrolls: give it a height by `content_class`. The keys reach every row. ```ocaml title="data_grid_virtualization.mlx" module S = Solidtype.Solid module Jsx = Solidtype.Jsx +module Chip = Solidtype_heroui.Chip module Data_grid = Solidtype_heroui.Data_grid +module Search_field = Solidtype_heroui.Search_field +module Rating = Solidtype_heroui.Rating +module Segment = Solidtype_heroui.Segment +module Gravity = Solidtype_gravity_icons +module I18n = Solidtype_kobalte.I18n +module Types = Solidtype_kobalte.Types + +type stock = In_stock | Low_stock | Out_of_stock + +type product = { + id : string; + name : string; + sku : string; + units : int; + price : float; + cost : float; + rating : float; + sales : int; +} -type entry = { id : string; name : string; email : string; city : string } +let brands = + [| + "ZenCore"; + "EchoLink"; + "TechFlow"; + "PrimeByte"; + "NovaPeak"; + "PixelForge"; + "SwiftEdge"; + |] -let cities = [| "Berlin"; "Lisbon"; "Oslo"; "Tokyo"; "Toronto"; "Nairobi" |] +let grades = + [| + "Turbo"; + "Advanced"; + "Deluxe"; + "Ultra"; + "Slim"; + "Elite"; + "Eco"; + "Compact"; + "Portable"; + "Wireless"; + |] -let entries = +let kinds = + [| + "Sensor"; + "Mouse"; + "Drive"; + "Tablet"; + "Cable"; + "Headphones"; + "Controller"; + "Charger"; + "Speaker"; + "Keyboard"; + "Monitor"; + |] + +let lines = [| "LGT"; "AUD"; "KEY"; "SPK"; "MON"; "FRN"; "CAM"; "ACC" |] + +(* The same thousand products on every visit: each field a number drawn from + the product's index, never from a random source. *) +let drawn i salt n = (((i + 1) * 7919) + (salt * 104729)) mod n +let one_of i salt names = names.(drawn i salt (Array.length names)) + +let products = Array.init 1000 (fun i -> + let price = float_of_int (50 + drawn i 4 1950) in { id = string_of_int (i + 1); - name = "Person " ^ string_of_int (i + 1); - email = "person" ^ string_of_int (i + 1) ^ "@example.com"; - city = cities.(i mod Array.length cities); + name = + one_of i 1 brands ^ " " ^ one_of i 2 grades ^ " " ^ one_of i 3 kinds; + sku = one_of i 5 lines ^ "-" ^ string_of_int (1000 + drawn i 6 9000); + units = + (match drawn i 7 10 with + | 0 | 1 -> 0 + | 2 | 3 -> 1 + drawn i 8 5 + | _ -> 6 + drawn i 8 195); + price; + cost = Float.round (price *. float_of_int (30 + drawn i 9 40) /. 100.); + rating = 3. +. (float_of_int (drawn i 10 5) /. 2.); + sales = drawn i 11 1000; }) +let stock p = + if p.units = 0 then Out_of_stock + else if p.units <= 5 then Low_stock + else In_stock + +let stock_key = function + | In_stock -> "in-stock" + | Low_stock -> "low-stock" + | Out_of_stock -> "out-of-stock" + +let stock_chip p = + match stock p with + | In_stock -> + + "In Stock" + + | Low_stock -> + + "Low Stock" + + | Out_of_stock -> + + "Out of Stock" + + +let stars rating = + + + + + + + + +let columns money = + let price ~class_ value = + + (Jsx.string (Types.NumberFormat.format (S.get money) value)) + + in + [| + Data_grid.column ~id:"name" ~header:(Text "Product") ~is_row_header:true + ~width:(Pixels 280.) (fun p -> +
+ (S.get + (Jsx.string (S.get p).name) +
); + Data_grid.column ~id:"sku" ~header:(Text "SKU") ~min_width:100. + ~cell_class:"font-mono text-xs text-muted" (fun p -> + Jsx.string (S.get p).sku); + Data_grid.column ~id:"status" ~header:(Text "Status") ~width:(Pixels 140.) + (fun p -> stock_chip (S.get p)); + Data_grid.column ~id:"stock" ~header:(Text "Stock") ~align:`center (fun p -> + Jsx.int (S.get p).units); + Data_grid.column ~id:"price" ~header:(Text "Price") ~align:`end_ (fun p -> + price ~class_:"tabular-nums" (S.get p).price); + Data_grid.column ~id:"cost" ~header:(Text "Cost") ~align:`end_ + ~cell_class:"text-muted" (fun p -> + price ~class_:"tabular-nums" (S.get p).cost); + Data_grid.column ~id:"rating" ~header:(Text "Rating") (fun p -> + stars (S.get p).rating); + Data_grid.column ~id:"sales" ~header:(Text "Sales") ~align:`end_ (fun p -> + (Jsx.int (S.get p).sales)); + |] + +let make () = + let money = + I18n.create_number_formatter + (Types.Either.left + (Types.NumberFormatOptions.make ~style:`currency ~currency:"USD" + ~maximum_fraction_digits:0. ())) + in + let shown, set_shown = S.create_signal "all" in + let query, set_query = S.create_signal "" in + let rows = + S.create_memo (fun () -> + let shown = S.get shown in + let query = String.lowercase_ascii (String.trim (S.get query)) in + let matches text = + Js.String.includes ~search:query (String.lowercase_ascii text) + in + Js.Array.filter products ~f:(fun p -> + (String.equal shown "all" + || String.equal shown (stock_key (stock p))) + && (String.equal query "" || matches p.name || matches p.sku))) + in +
+
+ S.set set_shown key)> + "All" + "In Stock" + "Out of Stock" + "Low Stock" + + S.set set_query text)> + + + + + + +
+ p.id) + columns=(columns money) + selection_mode=`multiple + show_selection_checkboxes=true + virtualized=true + row_height=58. + heading_height=37. + content_class="h-[600px] min-w-[900px] overflow-auto" + /> +
+``` + +## Bulk Actions + +An [Action Bar](action-bar.md) for the rows chosen. + +```ocaml title="data_grid_bulk_actions.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Action_bar = Solidtype_heroui.Action_bar +module Avatar = Solidtype_heroui.Avatar +module Button = Solidtype_heroui.Button +module Chip = Solidtype_heroui.Chip +module Data_grid = Solidtype_heroui.Data_grid +module Separator = Solidtype_heroui.Separator +module Gravity = Solidtype_gravity_icons +module I18n = Solidtype_kobalte.I18n +module Types = Solidtype_kobalte.Types + +type status = Active | Pending | Inactive + +type employee = { + id : string; + name : string; + email : string; + department : string; + status : status; + joined : string; + avatar : int; +} + +let employee id name email department status joined avatar = + { id; name; email; department; status; joined; avatar } + +let employees = + [| + employee "1" "Amara Okafor" "amara.okafor@company.com" "Support" Pending + "2024-06-27" 25; + employee "2" "Elena Rodriguez" "elena.rodriguez@company.com" "HR" Active + "2024-01-28" 20; + employee "3" "James O'Brien" "james.o.brien@company.com" "Finance" Active + "2024-04-14" 23; + employee "4" "Luca Bianchi" "luca.bianchi@company.com" "Engineering" Active + "2024-07-25" 21; + employee "5" "Marcus Chen" "marcus.chen@company.com" "Design" Pending + "2024-02-03" 22; + employee "6" "Priya Patel" "priya.patel@company.com" "HR" Active + "2024-03-04" 24; + employee "7" "Yuki Tanaka" "yuki.tanaka@company.com" "Product" Inactive + "2024-05-08" 26; + |] + +let status_name = function + | Active -> "Active" + | Pending -> "Pending" + | Inactive -> "Inactive" + +let status_color = function + | Active -> `success + | Pending -> `warning + | Inactive -> `danger + +let columns day = + [| + Data_grid.column ~id:"name" ~header:(Text "Employee") ~is_row_header:true + ~sort:(By_text (fun e -> e.name)) + (fun e -> +
+ + + +
+ + (Jsx.string (S.get e).name) + + + (Jsx.string (S.get e).email) + +
+
); + Data_grid.column ~id:"department" ~header:(Text "Department") + ~sort:(By_text (fun e -> e.department)) + (fun e -> Jsx.string (S.get e).department); + Data_grid.column ~id:"status" ~header:(Text "Status") + ~sort:(By_text (fun e -> status_name e.status)) + (fun e -> + + + (Jsx.string (status_name (S.get e).status)) + ); + Data_grid.column ~id:"joined" ~header:(Text "Joined") + ~sort:(By (fun a b -> String.compare a.joined b.joined)) + (fun e -> + + (Jsx.string + (Types.DateTimeFormat.format (S.get day) + ~date:(Types.Either.right (Js.Date.fromString (S.get e).joined)) + ())) + ); + |] + +let make () = + let chosen, set_chosen = S.create_signal [||] in + let day = + I18n.create_date_formatter + (Types.Either.left + (Types.DateTimeFormatOptions.make ~year:"numeric" ~month:"short" + ~day:"numeric" ~time_zone:"UTC" ())) + in +
+ e.id) + columns=(columns day) + selection_mode=`multiple + show_selection_checkboxes=true + selected_keys=(S.get chosen) + on_selection_change=(fun keys -> S.set set_chosen keys) + default_sort_descriptor={ column = "name"; direction = `ascending } + content_class="min-w-[640px]" + /> + 0) aria_label="Bulk actions"> + + + (Jsx.int (Array.length (S.get chosen))) + + + + + + + + + + + + + + +
+``` + +## Users + +```ocaml title="data_grid_users.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Button = Solidtype_heroui.Button +module Data_grid = Solidtype_heroui.Data_grid +module Link = Solidtype_heroui.Link + +type user = { name : string; title : string; email : string; role : string } + +let user name title email role = { name; title; email; role } + +let users = + [| + user "Lindsay Walton" "Front-end Developer" "lindsay.walton@example.com" + "Member"; + user "Courtney Henry" "Designer" "courtney.henry@example.com" "Admin"; + user "Tom Cook" "Director of Product" "tom.cook@example.com" "Member"; + user "Whitney Francis" "Copywriter" "whitney.francis@example.com" "Admin"; + user "Leonard Krasner" "Senior Designer" "leonard.krasner@example.com" + "Owner"; + user "Floyd Miles" "Principal Designer" "floyd.miles@example.com" "Member"; + |] + let columns = [| Data_grid.column ~id:"name" ~header:(Text "Name") ~is_row_header:true - ~sort:(By_text (fun e -> e.name)) - (fun e -> Jsx.string (S.get e).name); - Data_grid.column ~id:"email" ~header:(Text "Email") (fun e -> - Jsx.string (S.get e).email); - Data_grid.column ~id:"city" ~header:(Text "City") - ~sort:(By_text (fun e -> e.city)) - (fun e -> Jsx.string (S.get e).city); + ~cell_class:"font-medium" (fun u -> Jsx.string (S.get u).name); + Data_grid.column ~id:"title" ~header:(Text "Title") (fun u -> + Jsx.string (S.get u).title); + Data_grid.column ~id:"email" ~header:(Text "Email") (fun u -> + Jsx.string (S.get u).email); + Data_grid.column ~id:"role" ~header:(Text "Role") (fun u -> + Jsx.string (S.get u).role); + Data_grid.column ~id:"actions" + ~header:(Element (fun () -> "Actions")) + ~align:`end_ + (fun u -> + "Edit"); |] let make () = - e.id) - columns - virtualized=true - row_height=48. - heading_height=36. - content_class="h-[400px] min-w-[640px] overflow-auto" - /> +
+
+
+

"Users"

+

+ "A list of all the users in your account including their name, \ + title, email and role." +

+
+ +
+ u.email) + columns + content_class="min-w-[640px]" + /> +
``` ## Team Members @@ -1450,6 +2295,126 @@ let make () = /> ``` +## Footer + +`footer` is drawn below the grid, here a [Pagination](pagination.md). + +```ocaml title="data_grid_footer.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Chip = Solidtype_heroui.Chip +module Data_grid = Solidtype_heroui.Data_grid +module Pagination = Solidtype_heroui.Pagination + +type status = Paid | Pending | Overdue + +type invoice = { + id : string; + customer : string; + date : string; + status : status; + amount : string; +} + +let invoice id customer date status amount = + { id; customer; date; status; amount } + +let invoices = + [| + invoice "INV-001" "Acme Corp" "2024-03-01" Paid "$1,250"; + invoice "INV-002" "Globex" "2024-03-04" Paid "$890"; + invoice "INV-003" "Initech" "2024-03-07" Pending "$2,340"; + invoice "INV-004" "Umbrella Co" "2024-03-09" Overdue "$560"; + invoice "INV-005" "Stark Industries" "2024-03-12" Paid "$1,780"; + invoice "INV-006" "Wayne Enterprises" "2024-03-15" Pending "$430"; + invoice "INV-007" "Cyberdyne" "2024-03-18" Paid "$3,120"; + invoice "INV-008" "Soylent Corp" "2024-03-21" Overdue "$975"; + invoice "INV-009" "Massive Dynamic" "2024-03-24" Paid "$1,640"; + invoice "INV-010" "Hooli" "2024-03-27" Pending "$720"; + invoice "INV-011" "Vehement Capital" "2024-03-29" Paid "$2,050"; + invoice "INV-012" "Bluth Company" "2024-03-31" Overdue "$385"; + |] + +let per_page = 4 +let pages = (Array.length invoices + per_page - 1) / per_page + +let status_name = function + | Paid -> "paid" + | Pending -> "pending" + | Overdue -> "overdue" + +let status_color = function + | Paid -> `success + | Pending -> `warning + | Overdue -> `danger + +let columns = + [| + Data_grid.column ~id:"id" ~header:(Text "Invoice") ~is_row_header:true + ~cell_class:"font-medium" (fun i -> Jsx.string (S.get i).id); + Data_grid.column ~id:"customer" ~header:(Text "Customer") (fun i -> + Jsx.string (S.get i).customer); + Data_grid.column ~id:"date" ~header:(Text "Date") (fun i -> + Jsx.string (S.get i).date); + Data_grid.column ~id:"status" ~header:(Text "Status") (fun i -> + + (Jsx.string (status_name (S.get i).status)) + ); + Data_grid.column ~id:"amount" ~header:(Text "Amount") ~align:`end_ (fun i -> + (Jsx.string (S.get i).amount)); + |] + +let make () = + let page, set_page = S.create_signal 1 in + let shown () = Array.sub invoices ((S.get page - 1) * per_page) per_page in + i.id) + columns + content_class="min-w-[640px]" + footer=( + + (Jsx.string + (string_of_int (((S.get page - 1) * per_page) + 1) + ^ " to " + ^ string_of_int + (min (S.get page * per_page) (Array.length invoices)) + ^ " of " + ^ string_of_int (Array.length invoices) + ^ " invoices")) + + + + S.update set_page pred)> + + + + + (fun p _ -> + + S.set set_page p)> + (Jsx.int p) + + ) + + + S.update set_page succ)> + + + + + ) + /> +``` + ## Styling Reference ### CSS Classes @@ -1464,6 +2429,9 @@ let make () = - `.data-grid__empty-state` - What is drawn with no rows - `.data-grid__footer` - The footer, with HeroUI's `.table__footer` +A virtualized or resizable grid places its own two columns itself, at 40px +and 32px, whatever the variables say. + ### Interactive States - **Alignment**: `[data-align="start"]`, `"center"` or `"end"` on a column's diff --git a/agents/pages/heroui/inline-select.md b/agents/pages/heroui/inline-select.md new file mode 100644 index 0000000..5cb79a9 --- /dev/null +++ b/agents/pages/heroui/inline-select.md @@ -0,0 +1,317 @@ +# Inline Select + +A select drawn as text, for a choice made in a sentence, a toolbar or a cell. + +A [Select](select.md) drawn as text, with no field around it. +Its choice, keys and list are the select's. Its look is a stylesheet the +library ships, imported as [Theming](theming.md#setup) shows. + +## Usage + +```ocaml title="inline_select_usage.mlx" +module Inline_select = Solidtype_heroui.Inline_select +module List_box = Solidtype_heroui.List_box + +let make () = + + + + + + + + "English" + + + "Spanish" + + + "French" + + + "Japanese" + + + + +``` + +## Anatomy + +```ocaml + + + + + + + "English" + + + +``` + +## Team Switcher + +The trigger draws whatever it is given, here the team chosen. + +```ocaml title="inline_select_team_switcher.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Inline_select = Solidtype_heroui.Inline_select +module List_box = Solidtype_heroui.List_box +module Gravity = Solidtype_gravity_icons + +type team = { id : string; name : string; color : string } + +let teams = + [| + { id = "northwind"; name = "Northwind Labs"; color = "bg-violet-700" }; + { id = "acme"; name = "Acme Corp"; color = "bg-blue-600" }; + { id = "maple"; name = "Maple Studio"; color = "bg-amber-600" }; + |] + +let mark team = +
+ + (Jsx.string (String.sub team.name 0 1)) + +
+ +let make () = + let chosen, set_chosen = S.create_signal teams.(0) in +
+ + "/" + + match Array.find_opt (fun t -> Array.mem t.id keys) teams with + | Some t -> S.set set_chosen t + | None -> ())> + + (mark (S.get chosen)) + + (Jsx.string (S.get chosen).name) + + + + + + + (fun team _ -> + + (mark team) (Jsx.string team.name) + ) + + + + +
+``` + +## Custom Indicator + +`Inline_select.Indicator` draws the icon it is given in place of its chevrons. + +```ocaml title="inline_select_custom_indicator.mlx" +module Inline_select = Solidtype_heroui.Inline_select +module List_box = Solidtype_heroui.List_box +module Gravity = Solidtype_gravity_icons + +let make () = + + + + + + + + + + + "Viewer" + + + "Editor" + + + "Admin" + + + + +``` + +## Multi Select + +With `selection_mode=` `` `multiple ``, the value lists every option chosen. + +```ocaml title="inline_select_multi_select.mlx" +module Inline_select = Solidtype_heroui.Inline_select +module List_box = Solidtype_heroui.List_box + +let make () = + + + + + + + + "Email" + + + "WhatsApp" + + + "Push Notification" + + + + +``` + +## Placements + +`Inline_select.Popover` takes a `placement`, `` `bottom_end `` by default. + +```ocaml title="inline_select_placements.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Inline_select = Solidtype_heroui.Inline_select +module List_box = Solidtype_heroui.List_box + +let placements = + [| + ("bottom", `bottom, "bottom"); + ("bottom-start", `bottom_start, "bottom start"); + ("bottom-end", `bottom_end, "bottom end (default)"); + ("top", `top, "top"); + ("top-start", `top_start, "top start"); + ("top-end", `top_end, "top end"); + ("left", `left, "left"); + ("left-top", `left_top, "left top"); + ("left-bottom", `left_bottom, "left bottom"); + ("right", `right, "right"); + ("right-top", `right_top, "right top"); + ("right-bottom", `right_bottom, "right bottom"); + |] + +let make () = + let chosen, set_chosen = S.create_signal "bottom-end" in + let placement () = + match + Array.find_opt + (fun (id, _, _) -> String.equal id (S.get chosen)) + placements + with + | Some (_, p, _) -> p + | None -> `bottom_end + in +
+ + match keys with [| k |] -> S.set set_chosen k | _ -> ())> + + + + + + + (fun (id, _, name) _ -> + + (Jsx.string name) + ) + + + + +
+``` + +## Styling Reference + +### CSS Classes + +- `.inline-select`, beside the select's `.select` +- `.inline-select__trigger`, beside `.select__trigger` +- `.inline-select__value`, beside `.select__value` +- `.inline-select__indicator`, beside `.select__indicator` +- `.inline-select__popover`, beside `.select__popover` + +### Interactive States + +On `.inline-select__trigger`: + +- **Hovered**: `[data-hovered="true"]` +- **Focus visible**: `[data-focus-visible="true"]` +- **Disabled**: `[data-disabled="true"]` + +And on `.inline-select__indicator`, `[data-open="true"]` while the list is open. + +### CSS Variables + +| Variable | Default | Description | +|---|---|---| +| `--inline-select-value-max-width` | `12rem` | The widest the value is drawn before it is cut short | +| `--inline-select-indicator-size` | `0.75rem` | The indicator's width and height | + +## API Reference + +Each prop beside its name in React's convention. + +### Inline_select + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `selectionMode` | `selection_mode` | `` [ `single \| `multiple ] `` | `` `single `` | One option or many | +| `value` | `value` | `string array` | | The options chosen (controlled) | +| `defaultValue` | `default_value` | `string array` | | The options chosen at first (uncontrolled) | +| `onChange` | `on_change` | `string array -> unit` | | Called with the options chosen | +| `placeholder` | `placeholder` | `string` | `"Select an item"` | Shown while nothing is chosen | +| `disabledKeys` | `disabled_keys` | `string array` | | Options that cannot be chosen | +| `isOpen` | `is_open` | `bool` | | Whether the list is open (controlled) | +| `defaultOpen` | `default_open` | `bool` | | Whether the list is open at first | +| `onOpenChange` | `on_open_change` | `bool -> unit` | | Called as the list opens and closes | +| `isDisabled` | `is_disabled` | `bool` | `false` | Whether it is disabled | +| `isRequired` | `is_required` | `bool` | `false` | Whether a form requires a choice | +| `isInvalid` | `is_invalid` | `bool` | `false` | Whether its choice is invalid | +| `name` | `name` | `string` | | Its name in a form | +| `className` | `class_` | `string` | | Added after its own classes | +| `children` | `children` | elements | | Its trigger and popover | + +### Inline_select.Trigger + +| React | solidtype | Type | Description | +|---|---|---|---| +| `aria-label` | `aria_label` | `string` | Its name | +| `className` | `class_` | `string` | Added after its own classes | +| `children` | `children` | elements, or a function of its state | Its value and indicator, or anything else | + +### Inline_select.Value + +| React | solidtype | Type | Description | +|---|---|---|---| +| `className` | `class_` | `string` | Added after its own classes | +| `children` | `children` | elements, or a function of its state | Drawn while an option is chosen, in place of the option | + +### Inline_select.Indicator + +| React | solidtype | Type | Description | +|---|---|---|---| +| `className` | `class_` | `string` | Added after its own classes | +| `children` | `children` | elements | An icon in place of its chevrons | + +### Inline_select.Popover + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `placement` | `placement` | `Select.placement` | `` `bottom_end `` | Where the list sits beside the trigger | +| `className` | `class_` | `string` | | Added after its own classes | +| `children` | `children` | elements | | Its `List_box` | diff --git a/agents/pages/heroui/list-view.md b/agents/pages/heroui/list-view.md new file mode 100644 index 0000000..0f44e06 --- /dev/null +++ b/agents/pages/heroui/list-view.md @@ -0,0 +1,469 @@ +# List View + +A one-column list of rows, chosen and acted on by the keys and the pointer. + +A list of rows, each its content and an action, chosen by a checkbox where the +list chooses. Its look is a stylesheet the library ships, imported as +[Theming](theming.md#setup) shows. + +## Usage + +```ocaml title="list_view_usage.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module List_view = Solidtype_heroui.List_view +module Gravity = Solidtype_gravity_icons + +let files = + [| + ("documents", "Documents", "2 days ago", true); + ("photos", "Photos", "1 week ago", true); + ("readme", "README.md", "3 hours ago", false); + ("package", "package.json", "Yesterday", false); + ("src", "src", "Just now", true); + ("gitignore", ".gitignore", "2 weeks ago", false); + |] + +let make () = +
+ + + (fun (id, name, updated, folder) _ -> + + + (if folder then else ) +
+ (Jsx.string name) + + (Jsx.string ("Updated " ^ updated)) + +
+
+
) +
+
+
+``` + +## Anatomy + +```ocaml + + + + "README.md" + "Updated 3 hours ago" + + ... + + +``` + +## Keys + +Up and Down move between rows, never past either end, a disabled row passed +over; Home and End reach the first and the last, and typing the start of a +row's name the next row of that name. Space chooses a row. Right moves into +the controls of a row, and Left back out. Where the list has an `on_action`, a +press or Enter runs it while nothing is chosen. + +## Selection Modes + +`` `none ``, `` `single `` or `` `multiple ``; a list that chooses draws a +checkbox in each row. + +```ocaml title="list_view_selection_modes.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module List_view = Solidtype_heroui.List_view +module Gravity = Solidtype_gravity_icons + +let files = + [| + ("documents", "Documents", "2 days ago", true); + ("photos", "Photos", "1 week ago", true); + ("readme", "README.md", "3 hours ago", false); + ("package", "package.json", "Yesterday", false); + ("src", "src", "Just now", true); + |] + +let name_of id = + match Array.find_opt (fun (k, _, _, _) -> String.equal k id) files with + | Some (_, name, _, _) -> name + | None -> id + +let chosen_text = function + | [||] -> "None selected" + | [| one |] -> name_of one + | many -> string_of_int (Array.length many) ^ " selected" + +let column ~title ~mode = + let chosen, set_chosen = S.create_signal [||] in +
+
+ (Jsx.string title) + (match mode with + | `none -> Jsx.string "" + | `single | `multiple -> + + (Jsx.string (chosen_text (S.get chosen))) + ) +
+ S.set set_chosen keys)> + + (fun (id, name, updated, folder) _ -> + + + (if folder then else ) +
+ (Jsx.string name) + + (Jsx.string ("Updated " ^ updated)) + +
+
+
) +
+
+
+ +let make () = +
+ (column ~title:"None" ~mode:`none) + (column ~title:"Single" ~mode:`single) + (column ~title:"Multiple" ~mode:`multiple) +
+``` + +## Variants + +### Primary + +A grey card of white rows, the default. + +```ocaml title="list_view_usage.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module List_view = Solidtype_heroui.List_view +module Gravity = Solidtype_gravity_icons + +let files = + [| + ("documents", "Documents", "2 days ago", true); + ("photos", "Photos", "1 week ago", true); + ("readme", "README.md", "3 hours ago", false); + ("package", "package.json", "Yesterday", false); + ("src", "src", "Just now", true); + ("gitignore", ".gitignore", "2 weeks ago", false); + |] + +let make () = +
+ + + (fun (id, name, updated, folder) _ -> + + + (if folder then else ) +
+ (Jsx.string name) + + (Jsx.string ("Updated " ^ updated)) + +
+
+
) +
+
+
+``` + +### Secondary + +Rows on the page's own background, a line between each. + +```ocaml title="list_view_secondary.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module List_view = Solidtype_heroui.List_view +module Gravity = Solidtype_gravity_icons + +let files = + [| + ("documents", "Documents", "2 days ago", true); + ("photos", "Photos", "1 week ago", true); + ("readme", "README.md", "3 hours ago", false); + ("package", "package.json", "Yesterday", false); + ("src", "src", "Just now", true); + |] + +let make () = +
+ + + (fun (id, name, updated, folder) _ -> + + + (if folder then else ) +
+ (Jsx.string name) + + (Jsx.string ("Updated " ^ updated)) + +
+
+
) +
+
+
+``` + +## Disabled Items + +`disabled_keys` names rows that cannot be chosen, focused or acted on. + +```ocaml title="list_view_disabled_items.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module List_view = Solidtype_heroui.List_view +module Gravity = Solidtype_gravity_icons + +let files = + [| + ("documents", "Documents", true); + ("budget", "Budget.xlsx", false); + ("archived", "Archived.zip", false); + ("photos", "Photos", true); + ("backup", "Old backup.tar", false); + ("readme", "README.md", false); + |] + +let locked = [| "archived"; "backup" |] + +let make () = +
+ + + (fun (id, name, folder) _ -> + + + (if folder then else ) + (Jsx.string name) + + (if Array.exists (String.equal id) locked then + + + + else Jsx.string "") + ) + + +
+``` + +## With Action Bar + +An [Action Bar](action-bar.md) for what is chosen. + +```ocaml title="list_view_with_action_bar.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Action_bar = Solidtype_heroui.Action_bar +module Button = Solidtype_heroui.Button +module Chip = Solidtype_heroui.Chip +module List_view = Solidtype_heroui.List_view +module Separator = Solidtype_heroui.Separator +module Gravity = Solidtype_gravity_icons + +let files = + [| + ("design", "Design System", "2 days ago", true); + ("photos", "Photos", "1 week ago", true); + ("readme", "README.md", "3 hours ago", false); + ("package", "package.json", "Yesterday", false); + ("src", "src", "Just now", true); + ("gitignore", ".gitignore", "2 weeks ago", false); + ("tsconfig", "tsconfig.json", "3 days ago", false); + ("modules", "node_modules", "1 day ago", true); + |] + +let make () = + let chosen, set_chosen = S.create_signal [||] in +
+ S.set set_chosen keys)> + + (fun (id, name, updated, folder) _ -> + + + (if folder then else ) +
+ (Jsx.string name) + + (Jsx.string ("Updated " ^ updated)) + +
+
+
) +
+
+ 0) aria_label="File actions"> + + + (Jsx.int (Array.length (S.get chosen))) + + + + + + + + + + + + + + + +
+``` + +## Virtualization + +`virtualized` draws only the rows in view, each `row_height` high, of a list +given a height, which scrolls them. + +```ocaml title="list_view_virtualization.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module List_view = Solidtype_heroui.List_view +module Gravity = Solidtype_gravity_icons + +let files = + Array.init 1000 (fun i -> + let n = string_of_int (i + 1) in + (n, "report-" ^ n ^ ".pdf", string_of_int ((i * 37 mod 900) + 12) ^ " KB")) + +let make () = +
+ + + (fun (id, name, size) _ -> + + + +
+ (Jsx.string name) + (Jsx.string size) +
+
+
) +
+
+
+``` + +## Styling Reference + +### CSS Classes + +- `.list-view` - The list +- `.list-view--primary`, `.list-view--secondary` - Its variants +- `.list-view__item` - A row +- `.list-view__selection-cell` - A row's checkbox +- `.list-view__item-content` - A row's icon and text +- `.list-view__title` - A row's name +- `.list-view__description` - The line under it +- `.list-view__item-action` - What a row ends with +- `.list-view__empty-state` - What a list with no rows draws + +### Interactive States + +On `.list-view__item`: + +- **Selected**: `[data-selected="true"]` +- **Hovered**: `[data-hovered="true"]` +- **Pressed**: `[data-pressed="true"]` +- **Focus visible**: `[data-focus-visible="true"]` +- **Disabled**: `[aria-disabled="true"]` + +## API Reference + +Each prop beside its name in React's convention. + +### List_view + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `aria-label` | `aria_label` | `string` | | Its name | +| `variant` | `variant` | `` [ `primary \| `secondary ] `` | `` `primary `` | Its look | +| `selectionMode` | `selection_mode` | `` [ `none \| `single \| `multiple ] `` | `` `none `` | How many rows it chooses | +| `selectionBehavior` | `selection_behavior` | `` [ `toggle \| `replace ] `` | `` `toggle `` | Whether a press adds to the choice or replaces it | +| `selectedKeys` | `selected_keys` | `string array` | | The rows chosen (controlled) | +| `defaultSelectedKeys` | `default_selected_keys` | `string array` | | The rows chosen at first | +| `onSelectionChange` | `on_selection_change` | `string array -> unit` | | Called with the rows chosen | +| `disabledKeys` | `disabled_keys` | `string array` | | Rows that cannot be chosen or acted on | +| `disallowEmptySelection` | `disallow_empty_selection` | `bool` | | Whether the last row chosen stays chosen | +| `onAction` | `on_action` | `string -> unit` | | Called with a row's key as it is acted on | +| `renderEmptyState` | `render_empty_state` | `unit -> element` | | Drawn while it has no row | +| `virtualized` | `virtualized` | `bool` | `false` | Whether it draws only the rows in view | +| `rowHeight` | `row_height` | `float` | `48.` | Each row's height while virtualized | +| `className` | `class_` | `string` | | Added after its own classes | + +### List_view.Item + +| React | solidtype | Type | Description | +|---|---|---|---| +| `id` | `id` | `string` | Its key | +| `textValue` | `text_value` | `string` | Its name, which typing finds | +| `isDisabled` | `is_disabled` | `bool` | Whether it is disabled | +| `href` | `href` | `string` | The page its action opens | +| `className` | `class_` | `string` | Added after its own classes | +| `children` | `children` | elements, or a function of its state | Its content and action | + +### List_view.Item_content, Title, Description, Item_action + +| React | solidtype | Type | Description | +|---|---|---|---| +| `className` | `class_` | `string` | Added after its own class | +| `children` | `children` | elements | What it holds | diff --git a/agents/pages/heroui/radio-group.md b/agents/pages/heroui/radio-group.md index ab0289c..bb9b167 100644 --- a/agents/pages/heroui/radio-group.md +++ b/agents/pages/heroui/radio-group.md @@ -164,6 +164,46 @@ let make () = ``` +### In Surface + +On a [Surface](surface.md), `variant=` `` `secondary `` is +the quieter look meant for its background. + +```ocaml title="radio_group_in_surface.mlx" +module Description = Solidtype_heroui.Description +module Label = Solidtype_heroui.Label +module Radio = Solidtype_heroui.Radio +module Radio_group = Solidtype_heroui.Radio_group +module Surface = Solidtype_heroui.Surface + +let make () = + + + + "Choose the plan that suits you best" + + + "Basic Plan" + + "Includes 100 messages per month" + + + + "Premium Plan" + + "Includes 200 messages per month" + + + + "Business Plan" + + "Unlimited messages" + + + +``` + ### Disabled ```ocaml title="radio_group_disabled.mlx" @@ -285,6 +325,166 @@ let make () = ``` +### Validation + +The group is invalid as `is_invalid` says, here once a submit finds no plan +chosen, and its `Field_error` shows while it is. + +```ocaml title="radio_group_validation.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +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 Radio = Solidtype_heroui.Radio +module Radio_group = Solidtype_heroui.Radio_group + +external prevent_default : Dom.event -> unit = "preventDefault" [@@mel.send] + +let make () = + let plan, set_plan = S.create_signal None in + let tried, set_tried = S.create_signal false in + let message, set_message = S.create_signal None in +
+ prevent_default e; + S.set set_tried true; + S.set set_message + (Option.map + (fun p -> "Your chosen plan is: " ^ p) + (S.get plan)))> + S.set set_plan (Some p))> + + + + "Starter" + + "For side projects and small teams" + + + + "Pro" + + "Advanced reporting and analytics" + + + + "Teams" + + "Share access with up to 10 teammates" + + "Choose a subscription before continuing." + + + + (fun m ->

(Jsx.string (S.get m))

) +
+
+``` + +### Delivery & Payment + +Each `Radio.Content` drawn as a card, its state read by `data-selected`. + +```ocaml title="radio_group_delivery_and_payment.mlx" +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Description = Solidtype_heroui.Description +module Label = Solidtype_heroui.Label +module Radio = Solidtype_heroui.Radio +module Radio_group = Solidtype_heroui.Radio_group +module Gravity = Solidtype_gravity_icons + +let deliveries = + [| + ("standard", "Standard", "4-10 business days", "$5.00"); + ("express", "Express", "2-5 business days", "$16.00"); + ("super-fast", "Super Fast", "1 business day", "$25.00"); + |] + +let payments = + [| + ("mastercard", "**** 8304", "Exp. on 01/2026"); + ("visa", "**** 0123", "Exp. on 01/2026"); + ("paypal", "PayPal", "Pay with PayPal"); + |] + +let accent = + "--accent: #006FEE; --accent-foreground: #fff; --accent-hover: #006FEE; \ + --border-width: 2px; --border-width-field: 2px; --focus: #006FEE;" + +let make () = +
+
+ + +
+ + (fun (value, title, description, price) _ -> + + + + + +
+ (Jsx.string title) + (Jsx.string description) +
+ (Jsx.string price) +
+
) +
+
+
+
+
+ +
+ +
+
+ + (fun (value, title, description) _ -> + + + + + + (if String.equal value "paypal" then + + else ) +
+ (Jsx.string title) + (Jsx.string description) +
+
+
) +
+
+
+
+
+``` + ### Custom Indicator ```ocaml title="radio_group_custom_indicator.mlx" @@ -322,10 +522,9 @@ let make () = ``` -### Not yet +### Render Function -HeroUI's In Surface, until Surface is ported; Validation and Delivery & -Payment, which need a form and `FieldError`. `as_` draws another element in a part's place, as [Composition](composition.md#custom-dom-element) shows. +`as_` draws another element in a part's place, as [Composition](composition.md#custom-dom-element) shows. ## Customization diff --git a/agents/pages/heroui/rating.md b/agents/pages/heroui/rating.md new file mode 100644 index 0000000..6bd5710 --- /dev/null +++ b/agents/pages/heroui/rating.md @@ -0,0 +1,391 @@ +# Rating + +A star rating, chosen by a press or the arrow keys, or shown read only as a fraction. + +Kobalte's rating, a radio group of stars, in HeroUI's look: chosen by a press +or the arrow keys, the stars under the pointer previewed as it moves. Read +only, its value may be a fraction. Its look is a stylesheet the library ships, +imported as [Theming](theming.md#setup) shows. + +## Usage + +```ocaml title="rating_usage.mlx" +module Rating = Solidtype_heroui.Rating + +let make () = + + + + + + + +``` + +## Anatomy + +```ocaml + + + +``` + +## Controlled + +```ocaml title="rating_controlled.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Rating = Solidtype_heroui.Rating + +let make () = + let value, set_value = S.create_signal 3. in +
+ S.set set_value v)> + + + + + + + + (Jsx.string (Js.Float.toString (S.get value) ^ " stars")) + +
+``` + +## Custom Color + +`--rating-active-color` colours the active stars. + +```ocaml title="rating_custom_color.mlx" +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Rating = Solidtype_heroui.Rating + +let colors = + [| ("accent", "Accent"); ("danger", "Danger"); ("success", "Success") |] + +let make () = +
+ + (fun (color, name) _ -> +
+ + + + + + + + (Jsx.string name) +
) +
+
+``` + +## Custom Icon Heart + +`icon` is every item's icon. + +```ocaml title="rating_custom_icon_heart.mlx" +module Rating = Solidtype_heroui.Rating +module Gravity = Solidtype_gravity_icons + +let make () = + )> + + + + + + +``` + +## Custom Icon Per Item + +An item's children are its own icon. + +```ocaml title="rating_custom_icon_per_item.mlx" +module For = Solidtype.For +module Rating = Solidtype_heroui.Rating +module Gravity = Solidtype_gravity_icons + +let make () = + + + (fun value _ -> ) + + +``` + +## Disabled + +```ocaml title="rating_disabled.mlx" +module Rating = Solidtype_heroui.Rating + +let make () = + + + + + + + +``` + +## Product Review + +```ocaml title="rating_product_review.mlx" +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Rating = Solidtype_heroui.Rating + +let scores = + [| + ("Quality", 4.5); + ("Value for money", 3.7); + ("Design", 5.); + ("Durability", 2.3); + |] + +let make () = +
+ + (fun (name, score) _ -> +
+ (Jsx.string name) +
+ + + + + + + + + (Jsx.string (Js.Float.toString score)) + +
+
) +
+
+``` + +## Read Only + +```ocaml title="rating_read_only.mlx" +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Rating = Solidtype_heroui.Rating + +let values = [| 1.5; 2.3; 3.7; 4.2; 4.8 |] + +let make () = +
+ + (fun value _ -> +
+ + + + + + + + + (Jsx.string (Js.Float.toString value)) + +
) +
+
+``` + +## Read Only Fractional + +A value read only may be a fraction: the stars up to its whole part are active, and the next filled as far as the fraction goes. + +```ocaml title="rating_read_only_fractional.mlx" +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Rating = Solidtype_heroui.Rating + +let values = [| 1.5; 2.3; 3.7; 4.2; 4.8 |] + +let make () = +
+ + (fun value _ -> +
+ + + + + + + + + (Jsx.string (Js.Float.toString value)) + +
) +
+
+``` + +## Render Function + +A function child draws the whole item of its state: `is_active`, `is_partial` and `partial_percent`. + +```ocaml title="rating_render_function.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Rating = Solidtype_heroui.Rating +module Gravity = Solidtype_gravity_icons + +let make () = + let value, set_value = S.create_signal 0. in +
+ S.set set_value v)> + + (fun value _ -> + + (fun state -> + + + ) + ) + + + + (Jsx.string + (match S.get value with + | 0. -> "No rating" + | 1. -> "1 star" + | v -> Js.Float.toString v ^ " stars")) + +
+``` + +## Sizes + +```ocaml title="rating_sizes.mlx" +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Rating = Solidtype_heroui.Rating + +let sizes = [| (`sm, "sm"); (`md, "md"); (`lg, "lg") |] + +let make () = +
+ + (fun (size, name) _ -> +
+ + + + + + + + (Jsx.string name) +
) +
+
+``` + +## With Label + +```ocaml title="rating_with_label.mlx" +module Rating = Solidtype_heroui.Rating +module Label = Solidtype_heroui.Label + +let make () = +
+ + + + + + + + +
+``` + +## Styling Reference + +### CSS Classes + +- `.rating`, and its sizes `.rating--sm`, `.rating--md`, `.rating--lg` +- `.rating__item`, and `.rating__item--sm`, `--md`, `--lg` +- `.rating__icon` - An item's icon +- `.rating__icon-partial` - The part of an icon a fraction fills + +### Interactive States + +- **Active**: `[data-active="true"]` on `.rating__icon` +- **Read only**: `[data-readonly="true"]` on `.rating` and `.rating__item` +- **Focus visible**: `[data-focus-visible="true"]` on `.rating__item` +- **Pressed**: `[data-pressed="true"]` on `.rating__item` +- **Disabled**: `[data-disabled="true"]` on `.rating` + +### CSS Variables + +| Variable | Default | Description | +|---|---|---| +| `--rating-active-color` | `var(--color-warning)` | The active stars' colour | +| `--rating-inactive-color` | `var(--color-surface-tertiary)` | The other stars' colour | +| `--rating-partial` | | How far a fraction fills its star, written by the rating | + +## API Reference + +Each prop beside its name in React's convention. + +### Rating + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `size` | `size` | `` [ `sm \| `md \| `lg ] `` | `` `md `` | Its size | +| `value` | `value` | `float` | | The value (controlled) | +| `defaultValue` | `default_value` | `float` | `0.` | The value at first (uncontrolled) | +| `onValueChange` | `on_value_change` | `float -> unit` | | Called with each value chosen | +| `icon` | `icon` | element | a star | Every item's icon | +| `isDisabled` | `is_disabled` | `bool` | `false` | Whether it is disabled | +| `isReadOnly` | `is_read_only` | `bool` | `false` | Whether it only shows its value | +| `isRequired` | `is_required` | `bool` | `false` | Whether a form requires a value | +| `name` | `name` | `string` | | Its name in a form | +| `aria-label` | `aria_label` | `string` | | Its name | +| `className` | `class_` | `string` | | Added after its own classes | + +### Rating.Item + +| React | solidtype | Type | Description | +|---|---|---|---| +| `value` | `value` | `float` | Its place, from 1 | +| `children` | `children` | elements, or a function of its state | Its icon, or the whole item | +| `className` | `class_` | `string` | Added after its own classes | diff --git a/agents/pages/heroui/select.md b/agents/pages/heroui/select.md index 85bffe7..8790fd6 100644 --- a/agents/pages/heroui/select.md +++ b/agents/pages/heroui/select.md @@ -1213,7 +1213,7 @@ Each prop beside the name HeroUI's React component gives it. | React | solidtype | Type | Description | |---|---|---|---| -| `placement` | `placement` | `` `top `` \| `` `bottom `` \| `` `left `` \| `` `right `` | Placement of the popover relative to the trigger, `` `bottom `` by default | +| `placement` | `placement` | `` `bottom ``, and React Aria's others: `` `bottom_end ``, `` `top_start ``, `` `start ``... | Placement of the popover relative to the trigger, `` `bottom `` by default | | `className` | `class_` | `string` | Added after HeroUI's classes | | `children` | `children` | elements | What it holds | diff --git a/agents/pages/heroui/surface.md b/agents/pages/heroui/surface.md index 504b839..30c7c7e 100644 --- a/agents/pages/heroui/surface.md +++ b/agents/pages/heroui/surface.md @@ -111,10 +111,31 @@ let on_surface () = match surface with Some variant -> S.get variant | None -> `default ``` -### Not yet +### With Form Components -HeroUI's With Form Components example needs Input and TextArea, which are not -ported yet. +A field on a surface takes `variant=` `` `secondary ``, the quieter look +meant for a surface's background. + +```ocaml title="surface_with_form_components.mlx" +module Input = Solidtype_heroui.Input +module Surface = Solidtype_heroui.Surface +module Text_area = Solidtype_heroui.Text_area + +let make () = + + + + +``` ## Customization diff --git a/agents/pages/heroui/switch.md b/agents/pages/heroui/switch.md index 7836276..b64aa7c 100644 --- a/agents/pages/heroui/switch.md +++ b/agents/pages/heroui/switch.md @@ -90,6 +90,67 @@ let make () = ``` +### With Icons + +A `Switch.Icon` in the thumb, drawn of the switch's state. + +```ocaml title="switch_with_icons.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Switch = Solidtype_heroui.Switch +module Gravity = Solidtype_gravity_icons + +type icon = Jsx.element + +let switches : (string * (unit -> icon) * (unit -> icon) * string) array = + [| + ( "check", + (fun () -> ), + (fun () -> ), + "bg-green-500/80" ); + ( "darkMode", + (fun () -> ), + (fun () -> ), + "" ); + ( "microphone", + (fun () -> + ), + (fun () -> ), + "bg-red-500/80" ); + ( "notification", + (fun () -> ), + (fun () -> ), + "bg-purple-500/80" ); + ( "volume", + (fun () -> + ), + (fun () -> + ), + "bg-blue-500/80" ); + |] + +let make () = +
+ + (fun (name, on, off, selected_class) _ -> + + (fun s -> + + + + + (if S.get s.is_selected then on () else off ()) + + + + ) + ) + +
+``` + ### Disabled ```ocaml title="switch_disabled.mlx" @@ -156,6 +217,23 @@ let make () =
``` +### With Description + +```ocaml title="switch_with_description.mlx" +module Description = Solidtype_heroui.Description +module Switch = Solidtype_heroui.Switch + +let make () = +
+ + + "Public profile" + + "Allow others to see your profile information" + +
+``` + ### Label Position ```ocaml title="switch_label_position.mlx" @@ -233,6 +311,79 @@ let make () = ``` +### Form Integration + +A switch's `name` and `value` are its form's while it is on. + +```ocaml title="switch_form_integration.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Show = Solidtype.Show +module Button = Solidtype_heroui.Button +module Form = Solidtype_heroui.Form +module Switch = Solidtype_heroui.Switch +module Switch_group = Solidtype_heroui.Switch_group + +external prevent_default : Dom.event -> unit = "preventDefault" [@@mel.send] + +external current_target : Dom.event -> Dom.htmlFormElement = "currentTarget" +[@@mel.get] + +type form_data + +external form_data : Dom.htmlFormElement -> form_data = "FormData" [@@mel.new] + +type entries + +external entries : form_data -> entries = "entries" [@@mel.send] + +(* Each entry a pair, its name and its value, as JavaScript gives it. *) +external listed : entries -> (string * string) array = "from" +[@@mel.scope "Array"] + +let make () = + let sent, set_sent = S.create_signal None in +
+ prevent_default e; + let fields = + listed (entries (form_data (current_target e))) + |> Array.map (fun (key, value) -> key ^ ": " ^ value) + in + S.set set_sent + (Some + ("Form submitted with: " + ^ String.concat ", " (Array.to_list fields))))> + + + + + "Enable notifications" + + + + + + "Subscribe to newsletter" + + + + + + "Receive marketing updates" + + + + + + (fun m ->

(Jsx.string (S.get m))

) +
+
+``` + ### Render Props A function child is given the switch's state. @@ -254,10 +405,9 @@ let make () = ``` -### Not yet +### Render Function -HeroUI's With Icons, With Description and Form Integration, until their parts -are ported. `as_` draws another element in a part's place, as [Composition](composition.md#custom-dom-element) shows. +`as_` draws another element in a part's place, as [Composition](composition.md#custom-dom-element) shows. ## Customization @@ -287,6 +437,7 @@ ensure component variants and states are reusable and easy to customize. - `.switch__content` - Content container - `.switch__control` - Switch control track - `.switch__thumb` - Switch thumb that moves +- `.switch__icon` - An icon in the thumb - `.switch--sm` - Small size variant - `.switch--md` - Medium size variant (default) - `.switch--lg` - Large size variant @@ -334,12 +485,12 @@ Each prop beside the name HeroUI's React component gives it. | `aria-label` | `aria_label` | `string` | | Its name where no label names it | | `isInvalid` | `is_invalid` | `bool` | `false` | Whether the switch is invalid | -### Switch.Content, Switch.Control and Switch.Thumb +### Switch.Content, Switch.Control, Switch.Thumb and Switch.Icon | React | solidtype | Type | Description | |---|---|---|---| | `className` | `class_` | `string` | Added after HeroUI's class | -| `children` | `children` | elements | What it holds; not the thumb's | +| `children` | `children` | elements | What it holds: the thumb an icon, the icon what it draws | ### SwitchGroup diff --git a/agents/pages/heroui/toolbar.md b/agents/pages/heroui/toolbar.md new file mode 100644 index 0000000..eedb873 --- /dev/null +++ b/agents/pages/heroui/toolbar.md @@ -0,0 +1,252 @@ +# Toolbar + +A container for interactive controls with arrow key navigation. + +Original HeroUI documentation: [Toolbar](https://heroui.com/en/docs/react/components/toolbar). + +## Usage + +```ocaml title="toolbar_usage.mlx" +module Button = Solidtype_heroui.Button +module Button_group = Solidtype_heroui.Button_group +module Separator = Solidtype_heroui.Separator +module Toggle_button = Solidtype_heroui.Toggle_button +module Toggle_button_group = Solidtype_heroui.Toggle_button_group +module Toolbar = Solidtype_heroui.Toolbar +module Gravity = Solidtype_gravity_icons + +let make () = + + + + + + + + + + + + + + + + + + +``` + +## Parity + +The same HeroUI Toolbar twice, under the same props: in solidtype on the left, +in React on the right. Below them, every attribute of the two toolbars: a +marked row is one they disagree on, and a dimmed row is a framework's own, +which no style reads. + +## Keys + +The arrows of its orientation move the focus between its stops, what Tab +reaches inside it, the page's direction read for the horizontal ones, never +past either end. A toggle group is one stop, whose own arrows move among its +buttons. A `Separator` inside the toolbar runs across it, and a +`Button_group` or `Toggle_button_group` along it, unless either gives its +own orientation. + +## Examples + +### Vertical + +```ocaml title="toolbar_vertical.mlx" +module Button = Solidtype_heroui.Button +module Button_group = Solidtype_heroui.Button_group +module Separator = Solidtype_heroui.Separator +module Toggle_button = Solidtype_heroui.Toggle_button +module Toggle_button_group = Solidtype_heroui.Toggle_button_group +module Toolbar = Solidtype_heroui.Toolbar +module Gravity = Solidtype_gravity_icons + +let make () = + + + + + + + + + + + + + + + + + + +``` + +### Attached + +```ocaml title="toolbar_attached.mlx" +module Button = Solidtype_heroui.Button +module Button_group = Solidtype_heroui.Button_group +module Separator = Solidtype_heroui.Separator +module Toggle_button = Solidtype_heroui.Toggle_button +module Toggle_button_group = Solidtype_heroui.Toggle_button_group +module Toolbar = Solidtype_heroui.Toolbar +module Gravity = Solidtype_gravity_icons + +let make () = + + + + + + + + + + + + + + + + + + +``` + +### With ButtonGroup + +```ocaml title="toolbar_with_button_group.mlx" +module Button = Solidtype_heroui.Button +module Button_group = Solidtype_heroui.Button_group +module Separator = Solidtype_heroui.Separator +module Toggle_button = Solidtype_heroui.Toggle_button +module Toggle_button_group = Solidtype_heroui.Toggle_button_group +module Toolbar = Solidtype_heroui.Toolbar +module Gravity = Solidtype_gravity_icons + +let make () = + + + + + + + + + + + + + + + + + + + + + + + + +``` + +## Customization + +### Tailwind CSS + +```ocaml title="toolbar_tailwind.mlx" +module Toggle_button = Solidtype_heroui.Toggle_button +module Toggle_button_group = Solidtype_heroui.Toggle_button_group +module Toolbar = Solidtype_heroui.Toolbar +module Gravity = Solidtype_gravity_icons + +let toggle_class = + "rounded-lg data-[selected=true]:bg-accent \ + data-[selected=true]:text-accent-foreground" + +let make () = + + + + + + + + + + + + + +``` + +### Global CSS + +```css +@layer components { + .toolbar { + @apply gap-4 rounded-lg bg-surface p-3; + } +} +``` + +## Styling Reference + +### CSS Classes + +- `.toolbar` - Base container +- `.toolbar--horizontal` - Horizontal orientation (default) +- `.toolbar--vertical` - Vertical orientation +- `.toolbar--attached` - Attached variant with surface background and full rounding + +## API Reference + +Each prop beside the name HeroUI's React component gives it. + +### Toolbar + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `isAttached` | `is_attached` | `bool` | `false` | Whether the toolbar has a surface background with full rounding | +| `orientation` | `orientation` | `` [ `horizontal \| `vertical ] `` | `` `horizontal `` | The orientation of the toolbar | +| `aria-label` | `aria_label` | `string` | | An accessible label for the toolbar | +| `aria-labelledby` | `aria_labelledby` | `string` | | The id of an element that labels the toolbar | +| `children` | `children` | elements, or a function of its state | | Its controls | +| `className` | `class_` | `string` | | Added after HeroUI's classes | + +### Render Props + +| React | solidtype | Type | Description | +|---|---|---|---| +| `orientation` | `orientation` | `` [ `horizontal \| `vertical ] S.accessor `` | The current orientation of the toolbar | diff --git a/agents/pages/index.md b/agents/pages/index.md index 820df7f..db33cac 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.15.0/vite-plugin-solidtype-0.15.0.tgz" + "vite-plugin-solidtype": "https://github.com/hyphatech/solidtype/releases/download/0.15.1/vite-plugin-solidtype-0.15.1.tgz" } } ``` diff --git a/docs/astro.config.mjs b/docs/astro.config.mjs index 437c782..6e1066c 100644 --- a/docs/astro.config.mjs +++ b/docs/astro.config.mjs @@ -99,15 +99,15 @@ export default defineConfig({ { label: "Collections", items: ["heroui/dropdown", "heroui/empty-state", "heroui/list-box", "heroui/tag-group"] }, { 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: "Data Display", items: ["heroui/action-bar", "heroui/badge", "heroui/chip", "heroui/data-grid", "heroui/list-view", "heroui/table", "heroui/trend-chip"] }, { 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"] }, + { 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/rating", "heroui/search-field", "heroui/text-area", "heroui/text-field"] }, + { label: "Layout", items: ["heroui/card", "heroui/separator", "heroui/surface", "heroui/toolbar"] }, { label: "Media", items: ["heroui/avatar", "heroui/avatar-group"] }, { label: "Navigation", items: ["heroui/accordion", "heroui/breadcrumbs", "heroui/command", "heroui/disclosure", "heroui/disclosure-group", "heroui/link", "heroui/pagination", "heroui/tabs"] }, { label: "Overlays", items: ["heroui/alert-dialog", "heroui/drawer", "heroui/modal", "heroui/popover", "heroui/toast", "heroui/tooltip"] }, - { label: "Pickers", items: ["heroui/autocomplete", "heroui/combo-box", "heroui/select"] }, + { label: "Pickers", items: ["heroui/autocomplete", "heroui/combo-box", "heroui/inline-select", "heroui/select"] }, { label: "Typography", items: ["heroui/kbd", "heroui/typography"] }, { label: "Utilities", items: ["heroui/scroll-shadow"] }, ], diff --git a/docs/islands/action_bar_usage.mlx b/docs/islands/action_bar_usage.mlx new file mode 100644 index 0000000..6d132c0 --- /dev/null +++ b/docs/islands/action_bar_usage.mlx @@ -0,0 +1,77 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Action_bar = Solidtype_heroui.Action_bar +module Button = Solidtype_heroui.Button +module Chip = Solidtype_heroui.Chip +module List_view = Solidtype_heroui.List_view +module Separator = Solidtype_heroui.Separator +module Gravity = Solidtype_gravity_icons + +let files = + [| + ("proposal", "Project proposal.pdf"); + ("report", "Q4 financial report.xlsx"); + ("brand", "Brand guidelines.fig"); + ("photo", "Team photo.jpg"); + ("notes", "Meeting notes.md"); + ("api", "API documentation.pdf"); + |] + +let make () = + let chosen, set_chosen = S.create_signal [||] in +
+ S.set set_chosen keys)> + + (fun (id, name) _ -> + + + (Jsx.string name) + + ) + + + 0)> + + + (Jsx.int (Array.length (S.get chosen))) + + + + + + + + + + + + + + + +
diff --git a/docs/islands/autocomplete_custom_styles.mlx b/docs/islands/autocomplete_custom_styles.mlx new file mode 100644 index 0000000..75c94b4 --- /dev/null +++ b/docs/islands/autocomplete_custom_styles.mlx @@ -0,0 +1,114 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Autocomplete = Solidtype_heroui.Autocomplete +module Description = Solidtype_heroui.Description +module Empty_state = Solidtype_heroui.Empty_state +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box +module Search_field = Solidtype_heroui.Search_field +module Tag = Solidtype_heroui.Tag +module Tag_group = Solidtype_heroui.Tag_group + +let teammates = + [| + ("sarah", "Sarah Chen", "Product Design"); + ("marcus", "Marcus Lee", "Engineering"); + ("priya", "Priya Patel", "Data Science"); + ("jordan", "Jordan Kim", "Customer Success"); + ("alex", "Alex Rivera", "Marketing"); + |] + +let name_of id = + match Array.find_opt (fun (k, _, _) -> String.equal k id) teammates with + | Some (_, name, _) -> name + | None -> id + +let make () = + let chosen, set_chosen = S.create_signal [||] in + let remove keys = + S.set set_chosen + (Js.Array.filter (S.get chosen) ~f:(fun k -> + not (Array.exists (String.equal k) keys))) + in +
+ S.set set_chosen keys)> + + + "People who will be notified when this task updates." + + + + (fun value -> + + + + (fun id _ -> + + (Jsx.string (name_of id)) + ) + + + ) + + + + + + + + + + + + + + + "No teammates found") + selection_mode=`multiple> + + (fun (id, name, role) _ -> + +
+ + (Jsx.string name) + + (Jsx.string role) +
+ +
) +
+
+
+
+
+
diff --git a/docs/islands/autocomplete_email_recipients.mlx b/docs/islands/autocomplete_email_recipients.mlx new file mode 100644 index 0000000..f1c629e --- /dev/null +++ b/docs/islands/autocomplete_email_recipients.mlx @@ -0,0 +1,78 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Autocomplete = Solidtype_heroui.Autocomplete +module Description = Solidtype_heroui.Description +module Empty_state = Solidtype_heroui.Empty_state +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box +module Search_field = Solidtype_heroui.Search_field +module Tag = Solidtype_heroui.Tag +module Tag_group = Solidtype_heroui.Tag_group + +let people = + [| + ("alice@example.com", "Alice Johnson"); + ("bob@example.com", "Bob Smith"); + ("charlie@example.com", "Charlie Brown"); + ("diana@example.com", "Diana Prince"); + ("eve@example.com", "Eve Wilson"); + |] + +let make () = + let chosen, set_chosen = S.create_signal [||] in + let remove keys = + S.set set_chosen + (Js.Array.filter (S.get chosen) ~f:(fun k -> + not (Array.exists (String.equal k) keys))) + in + S.set set_chosen keys)> + + + + (fun value -> + + + + (fun email _ -> + (Jsx.string email)) + + + ) + + + + + + + + + + + + + + + "No recipients found") + selection_mode=`multiple> + + (fun (email, name) _ -> + +
+ + (Jsx.string email) +
+ +
) +
+
+
+
+
diff --git a/docs/islands/autocomplete_tag_group_selection.mlx b/docs/islands/autocomplete_tag_group_selection.mlx new file mode 100644 index 0000000..a82a3e3 --- /dev/null +++ b/docs/islands/autocomplete_tag_group_selection.mlx @@ -0,0 +1,82 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Autocomplete = Solidtype_heroui.Autocomplete +module Empty_state = Solidtype_heroui.Empty_state +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box +module Search_field = Solidtype_heroui.Search_field +module Tag = Solidtype_heroui.Tag +module Tag_group = Solidtype_heroui.Tag_group + +let tags = + [| + ("react", "React"); + ("typescript", "TypeScript"); + ("javascript", "JavaScript"); + ("nodejs", "Node.js"); + ("python", "Python"); + ("vue", "Vue"); + ("angular", "Angular"); + ("nextjs", "Next.js"); + |] + +let name_of id = + match Array.find_opt (fun (k, _) -> String.equal k id) tags with + | Some (_, name) -> name + | None -> id + +let make () = + let chosen, set_chosen = S.create_signal [||] in + let remove keys = + S.set set_chosen + (Js.Array.filter (S.get chosen) ~f:(fun k -> + not (Array.exists (String.equal k) keys))) + in + S.set set_chosen keys)> + + + + (fun value -> + + + + (fun id _ -> + + (Jsx.string (name_of id)) + ) + + + ) + + + + + + + + + + + + + + + "No tags found") + selection_mode=`multiple> + + (fun (id, name) _ -> + + (Jsx.string name) + ) + + + + + diff --git a/docs/islands/autocomplete_usage.mlx b/docs/islands/autocomplete_usage.mlx index 05ca8d1..71330d7 100644 --- a/docs/islands/autocomplete_usage.mlx +++ b/docs/islands/autocomplete_usage.mlx @@ -1,15 +1,58 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For module Autocomplete = Solidtype_heroui.Autocomplete module Empty_state = Solidtype_heroui.Empty_state module Label = Solidtype_heroui.Label module List_box = Solidtype_heroui.List_box module Search_field = Solidtype_heroui.Search_field +module Tag = Solidtype_heroui.Tag +module Tag_group = Solidtype_heroui.Tag_group + +let states = + [| + ("florida", "Florida"); + ("delaware", "Delaware"); + ("california", "California"); + ("texas", "Texas"); + ("new-york", "New York"); + ("washington", "Washington"); + |] + +let name_of id = + match Array.find_opt (fun (k, _) -> String.equal k id) states with + | Some (_, name) -> name + | None -> id let make () = + let chosen, set_chosen = S.create_signal [||] in + let remove keys = + S.set set_chosen + (Js.Array.filter (S.get chosen) ~f:(fun k -> + not (Array.exists (String.equal k) keys))) + in + class_="w-[256px]" + placeholder="Select states" + selection_mode=`multiple + value=(S.get chosen) + on_change=(fun keys -> S.set set_chosen keys)> - + + (fun value -> + + + + (fun id _ -> + + (Jsx.string (name_of id)) + ) + + + ) + + @@ -25,24 +68,12 @@ let make () = render_empty_state=(fun _ -> "No results found") selection_mode=`multiple> - - "Florida" - - - "Delaware" - - - "California" - - - "Texas" - - - "New York" - - - "Washington" - + + (fun (id, name) _ -> + + (Jsx.string name) + ) + diff --git a/docs/islands/autocomplete_user_selection_multiple.mlx b/docs/islands/autocomplete_user_selection_multiple.mlx new file mode 100644 index 0000000..ced17da --- /dev/null +++ b/docs/islands/autocomplete_user_selection_multiple.mlx @@ -0,0 +1,139 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Avatar = Solidtype_heroui.Avatar +module Description = Solidtype_heroui.Description +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box +module Autocomplete = Solidtype_heroui.Autocomplete +module Empty_state = Solidtype_heroui.Empty_state +module Search_field = Solidtype_heroui.Search_field +module Tag = Solidtype_heroui.Tag +module Tag_group = Solidtype_heroui.Tag_group + +type user = { + avatar_url : string; + email : string; + fallback : string; + id : string; + name : string; +} + +let users = + [| + { + avatar_url = + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/blue.jpg"; + email = "bob@heroui.com"; + fallback = "B"; + id = "1"; + name = "Bob"; + }; + { + avatar_url = + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/green.jpg"; + email = "fred@heroui.com"; + fallback = "F"; + id = "2"; + name = "Fred"; + }; + { + avatar_url = + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/purple.jpg"; + email = "martha@heroui.com"; + fallback = "M"; + id = "3"; + name = "Martha"; + }; + { + avatar_url = + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/red.jpg"; + email = "john@heroui.com"; + fallback = "J"; + id = "4"; + name = "John"; + }; + { + avatar_url = + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/orange.jpg"; + email = "jane@heroui.com"; + fallback = "J"; + id = "5"; + name = "Jane"; + }; + |] + +let make () = + let chosen, set_chosen = S.create_signal [||] in + let remove keys = + S.set set_chosen + (Js.Array.filter (S.get chosen) ~f:(fun k -> + not (Array.exists (String.equal k) keys))) + in + let user_of id = + Array.find_opt (fun (u : user) -> String.equal u.id id) users + in + S.set set_chosen keys)> + + + + (fun value -> + + + + (fun id _ -> + match user_of id with + | Some user -> + + + + + (Jsx.string user.fallback) + + + (Jsx.string user.name) + + | None -> Jsx.nothing) + + + ) + + + + + + + + + + + + + + + "No results found") + selection_mode=`multiple> + + (fun (user : user) _ -> + + + + (Jsx.string user.fallback) + +
+ + (Jsx.string user.email) +
+ +
) +
+
+
+
+
diff --git a/docs/islands/checkbox_group_validation.mlx b/docs/islands/checkbox_group_validation.mlx new file mode 100644 index 0000000..526007c --- /dev/null +++ b/docs/islands/checkbox_group_validation.mlx @@ -0,0 +1,60 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Show = Solidtype.Show +module Button = Solidtype_heroui.Button +module Checkbox = Solidtype_heroui.Checkbox +module Checkbox_group = Solidtype_heroui.Checkbox_group +module Field_error = Solidtype_heroui.Field_error +module Form = Solidtype_heroui.Form +module Label = Solidtype_heroui.Label + +external prevent_default : Dom.event -> unit = "preventDefault" [@@mel.send] + +let make () = + let chosen, set_chosen = S.create_signal [] in + let tried, set_tried = S.create_signal false in + let sent, set_sent = S.create_signal None in +
+ prevent_default e; + S.set set_tried true; + S.set set_sent + (match S.get chosen with + | [] -> None + | values -> + Some ("Selected preferences: " ^ String.concat ", " values)))> + + + + + + "Email notifications" + + + + + + "SMS notifications" + + + + + + "Push notifications" + + + + "Please select at least one notification method." + + + + + (fun m ->

(Jsx.string (S.get m))

) +
+
diff --git a/docs/islands/data_grid_bulk_actions.mlx b/docs/islands/data_grid_bulk_actions.mlx new file mode 100644 index 0000000..dd03ce4 --- /dev/null +++ b/docs/islands/data_grid_bulk_actions.mlx @@ -0,0 +1,162 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Action_bar = Solidtype_heroui.Action_bar +module Avatar = Solidtype_heroui.Avatar +module Button = Solidtype_heroui.Button +module Chip = Solidtype_heroui.Chip +module Data_grid = Solidtype_heroui.Data_grid +module Separator = Solidtype_heroui.Separator +module Gravity = Solidtype_gravity_icons +module I18n = Solidtype_kobalte.I18n +module Types = Solidtype_kobalte.Types + +type status = Active | Pending | Inactive + +type employee = { + id : string; + name : string; + email : string; + department : string; + status : status; + joined : string; + avatar : int; +} + +let employee id name email department status joined avatar = + { id; name; email; department; status; joined; avatar } + +let employees = + [| + employee "1" "Amara Okafor" "amara.okafor@company.com" "Support" Pending + "2024-06-27" 25; + employee "2" "Elena Rodriguez" "elena.rodriguez@company.com" "HR" Active + "2024-01-28" 20; + employee "3" "James O'Brien" "james.o.brien@company.com" "Finance" Active + "2024-04-14" 23; + employee "4" "Luca Bianchi" "luca.bianchi@company.com" "Engineering" Active + "2024-07-25" 21; + employee "5" "Marcus Chen" "marcus.chen@company.com" "Design" Pending + "2024-02-03" 22; + employee "6" "Priya Patel" "priya.patel@company.com" "HR" Active + "2024-03-04" 24; + employee "7" "Yuki Tanaka" "yuki.tanaka@company.com" "Product" Inactive + "2024-05-08" 26; + |] + +let status_name = function + | Active -> "Active" + | Pending -> "Pending" + | Inactive -> "Inactive" + +let status_color = function + | Active -> `success + | Pending -> `warning + | Inactive -> `danger + +let columns day = + [| + Data_grid.column ~id:"name" ~header:(Text "Employee") ~is_row_header:true + ~sort:(By_text (fun e -> e.name)) + (fun e -> +
+ + + +
+ + (Jsx.string (S.get e).name) + + + (Jsx.string (S.get e).email) + +
+
); + Data_grid.column ~id:"department" ~header:(Text "Department") + ~sort:(By_text (fun e -> e.department)) + (fun e -> Jsx.string (S.get e).department); + Data_grid.column ~id:"status" ~header:(Text "Status") + ~sort:(By_text (fun e -> status_name e.status)) + (fun e -> + + + (Jsx.string (status_name (S.get e).status)) + ); + Data_grid.column ~id:"joined" ~header:(Text "Joined") + ~sort:(By (fun a b -> String.compare a.joined b.joined)) + (fun e -> + + (Jsx.string + (Types.DateTimeFormat.format (S.get day) + ~date:(Types.Either.right (Js.Date.fromString (S.get e).joined)) + ())) + ); + |] + +let make () = + let chosen, set_chosen = S.create_signal [||] in + let day = + I18n.create_date_formatter + (Types.Either.left + (Types.DateTimeFormatOptions.make ~year:"numeric" ~month:"short" + ~day:"numeric" ~time_zone:"UTC" ())) + in +
+ e.id) + columns=(columns day) + selection_mode=`multiple + show_selection_checkboxes=true + selected_keys=(S.get chosen) + on_selection_change=(fun keys -> S.set set_chosen keys) + default_sort_descriptor={ column = "name"; direction = `ascending } + content_class="min-w-[640px]" + /> + 0) aria_label="Bulk actions"> + + + (Jsx.int (Array.length (S.get chosen))) + + + + + + + + + + + + + + +
diff --git a/docs/islands/data_grid_editable_cells.mlx b/docs/islands/data_grid_editable_cells.mlx index 7132ad9..a6a1086 100644 --- a/docs/islands/data_grid_editable_cells.mlx +++ b/docs/islands/data_grid_editable_cells.mlx @@ -1,13 +1,25 @@ module S = Solidtype.Solid module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Show = Solidtype.Show +module Button = Solidtype_heroui.Button module Chip = Solidtype_heroui.Chip module Data_grid = Solidtype_heroui.Data_grid +module Inline_select = Solidtype_heroui.Inline_select +module Input = Solidtype_heroui.Input module List_box = Solidtype_heroui.List_box module Number_stepper = Solidtype_heroui.Number_stepper -module Select = Solidtype_heroui.Select module Switch = Solidtype_heroui.Switch +module Gravity = Solidtype_gravity_icons -type priority = Low | Medium | High +external target : Dom.inputEvent -> Dom.htmlInputElement = "target" [@@mel.get] +external value_of : Dom.htmlInputElement -> string = "value" [@@mel.get] +external key : Dom.keyboardEvent -> string = "key" [@@mel.get] +external focus : Dom.htmlInputElement -> unit = "focus" [@@mel.send] +external focus_button : Dom.htmlButtonElement -> unit = "focus" [@@mel.send] +external select_text : Dom.htmlInputElement -> unit = "select" [@@mel.send] + +type priority = High | Medium | Low type flag = { id : string; @@ -17,64 +29,126 @@ type flag = { enabled : bool; } +let flag id feature priority points enabled = + { id; feature; priority; points; enabled } + let flags = [| - { - id = "1"; - feature = "Dark mode"; - priority = High; - points = 8.; - enabled = true; - }; - { - id = "2"; - feature = "CSV export"; - priority = Medium; - points = 6.; - enabled = true; - }; - { - id = "3"; - feature = "Keyboard shortcuts"; - priority = Low; - points = 5.; - enabled = false; - }; - { - id = "4"; - feature = "Two-factor auth"; - priority = Medium; - points = 16.; - enabled = true; - }; - { - id = "5"; - feature = "Bulk import"; - priority = Medium; - points = 8.; - enabled = false; - }; - { - id = "6"; - feature = "Audit log"; - priority = High; - points = 5.; - enabled = true; - }; + flag "1" "Dark mode" High 8. true; + flag "2" "CSV export" Medium 3. true; + flag "3" "Keyboard shortcuts" Low 5. false; + flag "4" "Two-factor auth" High 13. true; + flag "5" "Bulk import" Medium 8. false; + flag "6" "Audit log" High 5. true; + flag "7" "Webhooks" Low 3. false; + flag "8" "Custom branding" Medium 8. true; |] -let priority_key = function Low -> "low" | Medium -> "medium" | High -> "high" -let priority_of = function "high" -> High | "medium" -> Medium | _ -> Low +let priorities = [| High; Medium; Low |] +let priority_key = function High -> "high" | Medium -> "medium" | Low -> "low" let priority_name = function - | Low -> "Low" - | Medium -> "Medium" | High -> "High" + | Medium -> "Medium" + | Low -> "Low" let priority_color = function - | Low -> `default - | Medium -> `warning | High -> `danger + | Medium -> `warning + | Low -> `default + +let priority_chip p = + + (Jsx.string (priority_name p)) + + +(* The title as an input, its text chosen as it opens: Enter or Save keeps + it, Escape or Cancel leaves the title as it was. *) +let title_editor ~title ~save ~cancel = + let draft, set_draft = S.create_signal title in + let field = ref None in + S.on_mount (fun () -> + Option.iter + (fun e -> + focus e; + select_text e) + !field); + let keep () = + match String.trim (S.get draft) with "" -> cancel () | t -> save t + in +
+ field := Some e) + on_input=(fun e -> S.set set_draft (value_of (target e))) + on_key_down=(fun e -> + match key e with + | "Enter" -> keep () + | "Escape" -> cancel () + | _ -> ()) + /> + + +
+ +(* Shown while its row is hovered, or reached by the keys. *) +let edit_button ~ref ~on_click = + + +(* The title, and its button, which takes the focus back as editing ends, + since the input that had it is gone. *) +let title_cell ~title ~rename = + let editing, set_editing = S.create_signal false in + let button = ref None in + let finish () = + S.set set_editing false; + Option.iter focus_button !button + in + + + (Jsx.string (S.get title)) + + (edit_button + ~ref:(fun b -> button := Some b) + ~on_click:(fun () -> S.set set_editing true)) + )> + (title_editor ~title:(S.get title) + ~save:(fun t -> + rename t; + finish ()) + ~cancel:finish) + + +let summary = + "Edit titles, change priorities, adjust story points, and toggle features \ + inline." let make () = let rows, set_rows = S.create_signal flags in @@ -87,50 +161,46 @@ let make () = let columns = [| Data_grid.column ~id:"feature" ~header:(Text "Feature") - ~is_row_header:true ~cell_class:"font-medium" (fun row -> - Jsx.string (S.get row).feature); + ~is_row_header:true ~width:(Pixels 300.) (fun row -> + title_cell + ~title:(S.accessor (fun () -> (S.get row).feature)) + ~rename:(fun feature -> + change (S.get row).id (fun r -> { r with feature }))); Data_grid.column ~id:"priority" ~header:(Text "Priority") - ~width:(Pixels 200.) (fun row -> - ); - Data_grid.column ~id:"points" ~header:(Text "Story points") ~align:`center - ~width:(Pixels 160.) (fun row -> + + ); + Data_grid.column ~id:"points" ~header:(Text "Story Points") ~align:`center + ~width:(Pixels 167.) (fun row -> ); Data_grid.column ~id:"enabled" ~header:(Text "Enabled") ~align:`center - ~width:(Pixels 100.) (fun row -> + ~width:(Pixels 117.) (fun row -> change (S.get row).id (fun r -> { r with enabled }))> @@ -162,23 +232,28 @@ let make () = let effort () = Array.fold_left (fun sum r -> sum +. r.points) 0. (S.get rows) in - r.id) - columns - content_class="min-w-[640px]" - footer=( - - (Jsx.string - (string_of_int (enabled ()) - ^ " of " - ^ string_of_int (Array.length (S.get rows)) - ^ " enabled")) - - - (Jsx.string - ("Total effort: " ^ Js.Float.toString (effort ()) ^ " pts")) - - ) - /> +
+
+

"Feature Flags"

+

(Jsx.string summary)

+
+ r.id) + columns + content_class="min-w-[640px]" + /> +
+ + (Jsx.string + (string_of_int (enabled ()) + ^ " of " + ^ string_of_int (Array.length (S.get rows)) + ^ " enabled")) + + + (Jsx.string ("Total effort: " ^ Js.Float.toString (effort ()) ^ " pts")) + +
+
diff --git a/docs/islands/data_grid_footer.mlx b/docs/islands/data_grid_footer.mlx new file mode 100644 index 0000000..fdea0ab --- /dev/null +++ b/docs/islands/data_grid_footer.mlx @@ -0,0 +1,113 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Chip = Solidtype_heroui.Chip +module Data_grid = Solidtype_heroui.Data_grid +module Pagination = Solidtype_heroui.Pagination + +type status = Paid | Pending | Overdue + +type invoice = { + id : string; + customer : string; + date : string; + status : status; + amount : string; +} + +let invoice id customer date status amount = + { id; customer; date; status; amount } + +let invoices = + [| + invoice "INV-001" "Acme Corp" "2024-03-01" Paid "$1,250"; + invoice "INV-002" "Globex" "2024-03-04" Paid "$890"; + invoice "INV-003" "Initech" "2024-03-07" Pending "$2,340"; + invoice "INV-004" "Umbrella Co" "2024-03-09" Overdue "$560"; + invoice "INV-005" "Stark Industries" "2024-03-12" Paid "$1,780"; + invoice "INV-006" "Wayne Enterprises" "2024-03-15" Pending "$430"; + invoice "INV-007" "Cyberdyne" "2024-03-18" Paid "$3,120"; + invoice "INV-008" "Soylent Corp" "2024-03-21" Overdue "$975"; + invoice "INV-009" "Massive Dynamic" "2024-03-24" Paid "$1,640"; + invoice "INV-010" "Hooli" "2024-03-27" Pending "$720"; + invoice "INV-011" "Vehement Capital" "2024-03-29" Paid "$2,050"; + invoice "INV-012" "Bluth Company" "2024-03-31" Overdue "$385"; + |] + +let per_page = 4 +let pages = (Array.length invoices + per_page - 1) / per_page + +let status_name = function + | Paid -> "paid" + | Pending -> "pending" + | Overdue -> "overdue" + +let status_color = function + | Paid -> `success + | Pending -> `warning + | Overdue -> `danger + +let columns = + [| + Data_grid.column ~id:"id" ~header:(Text "Invoice") ~is_row_header:true + ~cell_class:"font-medium" (fun i -> Jsx.string (S.get i).id); + Data_grid.column ~id:"customer" ~header:(Text "Customer") (fun i -> + Jsx.string (S.get i).customer); + Data_grid.column ~id:"date" ~header:(Text "Date") (fun i -> + Jsx.string (S.get i).date); + Data_grid.column ~id:"status" ~header:(Text "Status") (fun i -> + + (Jsx.string (status_name (S.get i).status)) + ); + Data_grid.column ~id:"amount" ~header:(Text "Amount") ~align:`end_ (fun i -> + (Jsx.string (S.get i).amount)); + |] + +let make () = + let page, set_page = S.create_signal 1 in + let shown () = Array.sub invoices ((S.get page - 1) * per_page) per_page in + i.id) + columns + content_class="min-w-[640px]" + footer=( + + (Jsx.string + (string_of_int (((S.get page - 1) * per_page) + 1) + ^ " to " + ^ string_of_int + (min (S.get page * per_page) (Array.length invoices)) + ^ " of " + ^ string_of_int (Array.length invoices) + ^ " invoices")) + + + + S.update set_page pred)> + + + + + (fun p _ -> + + S.set set_page p)> + (Jsx.int p) + + ) + + + S.update set_page succ)> + + + + + ) + /> diff --git a/docs/islands/data_grid_sticky_header.mlx b/docs/islands/data_grid_sticky_header.mlx new file mode 100644 index 0000000..5652c2b --- /dev/null +++ b/docs/islands/data_grid_sticky_header.mlx @@ -0,0 +1,255 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Button = Solidtype_heroui.Button +module Chip = Solidtype_heroui.Chip +module Data_grid = Solidtype_heroui.Data_grid +module Dropdown = Solidtype_heroui.Dropdown +module Label = Solidtype_heroui.Label +module Gravity = Solidtype_gravity_icons +module I18n = Solidtype_kobalte.I18n +module Types = Solidtype_kobalte.Types + +type status = Succeeded | Processing | Refunded | Failed + +type payment = { + id : string; + customer : string; + email : string; + status : status; + amount : float; + fee : float; + method_ : string; + region : string; + description : string; + date : string; +} + +let payments = + [| + { + id = "pay_1N3xDR"; + customer = "Emma Wilson"; + email = "emma@example.com"; + status = Succeeded; + amount = 2450.; + fee = 73.5; + method_ = {js|Visa •••• 4242|js}; + region = "North America"; + description = {js|Annual subscription — Enterprise plan|js}; + date = "2025-12-07"; + }; + { + id = "pay_1N3x9M"; + customer = "Isabella Nguyen"; + email = "isabella@example.com"; + status = Succeeded; + amount = 299.; + fee = 8.97; + method_ = {js|Visa •••• 1234|js}; + region = "Asia Pacific"; + description = {js|Quarterly subscription — Team plan|js}; + date = "2025-12-03"; + }; + { + id = "pay_1N3x8L"; + customer = "Jackson Lee"; + email = "jackson@example.com"; + status = Processing; + amount = 39.; + fee = 1.43; + method_ = {js|Mastercard •••• 5555|js}; + region = "North America"; + description = {js|Monthly add-on — Extra seats|js}; + date = "2025-12-02"; + }; + { + id = "pay_1N3xCQ"; + customer = "Liam Johnson"; + email = "liam@example.com"; + status = Refunded; + amount = 150.; + fee = 4.5; + method_ = {js|Mastercard •••• 6789|js}; + region = "Europe"; + description = {js|Monthly subscription — Pro plan|js}; + date = "2025-12-06"; + }; + { + id = "pay_1N3x7K"; + customer = "Olivia Martin"; + email = "olivia@example.com"; + status = Succeeded; + amount = 1999.; + fee = 59.97; + method_ = {js|Visa •••• 4242|js}; + region = "North America"; + description = {js|Annual subscription — Pro plan|js}; + date = "2025-12-01"; + }; + { + id = "pay_1N3xBP"; + customer = "Sofia Davis"; + email = "sofia@example.com"; + status = Succeeded; + amount = 450.; + fee = 13.5; + method_ = {js|Visa •••• 9012|js}; + region = "Europe"; + description = {js|One-time purchase — Enterprise setup|js}; + date = "2025-12-05"; + }; + { + id = "pay_1N3xAN"; + customer = "William Kim"; + email = "will@example.com"; + status = Failed; + amount = 99.; + fee = 3.17; + method_ = {js|Amex •••• 3782|js}; + region = "Asia Pacific"; + description = {js|Monthly subscription — Starter plan|js}; + date = "2025-12-04"; + }; + |] + +let status_name = function + | Succeeded -> "Succeeded" + | Processing -> "Processing" + | Refunded -> "Refunded" + | Failed -> "Failed" + +let status_color = function + | Succeeded -> `success + | Processing -> `warning + | Refunded -> `default + | Failed -> `danger + +let actions p = + + + + ())> + + + + + + + + + + + + + + + + + + + + +let columns ~money ~day = + let amount ~class_ value = + + (Jsx.string (Types.NumberFormat.format (S.get money) value)) + + in + [| + Data_grid.column ~id:"customer" ~header:(Text "Customer") + ~is_row_header:true ~default_width:(Pixels 240.) ~allows_resizing:true + ~sort:(By_text (fun p -> p.customer)) + (fun p -> +
+ + (Jsx.string (S.get p).customer) + + (Jsx.string (S.get p).email) +
); + Data_grid.column ~id:"id" ~header:(Text "Transaction ID") + ~default_width:(Pixels 130.) ~allows_resizing:true + ~cell_class:"font-mono text-xs text-muted" (fun p -> + Jsx.string (S.get p).id); + Data_grid.column ~id:"status" ~header:(Text "Status") + ~default_width:(Pixels 120.) ~allows_resizing:true + ~sort:(By_text (fun p -> status_name p.status)) + (fun p -> + + + (Jsx.string (status_name (S.get p).status)) + ); + Data_grid.column ~id:"amount" ~header:(Text "Amount") ~align:`end_ + ~default_width:(Pixels 110.) ~allows_resizing:true + ~sort:(By (fun a b -> Float.compare a.amount b.amount)) + (fun p -> amount ~class_:"font-medium tabular-nums" (S.get p).amount); + Data_grid.column ~id:"fee" ~header:(Text "Fee") ~align:`end_ + ~default_width:(Pixels 90.) ~allows_resizing:true + ~sort:(By (fun a b -> Float.compare a.fee b.fee)) + (fun p -> amount ~class_:"text-muted tabular-nums" (S.get p).fee); + Data_grid.column ~id:"net" ~header:(Text "Net") ~align:`end_ + ~default_width:(Pixels 110.) ~allows_resizing:true + ~sort: + (By (fun a b -> Float.compare (a.amount -. a.fee) (b.amount -. b.fee))) + (fun p -> + amount ~class_:"font-medium tabular-nums" + ((S.get p).amount -. (S.get p).fee)); + Data_grid.column ~id:"method" ~header:(Text "Payment Method") + ~default_width:(Pixels 170.) ~allows_resizing:true (fun p -> + Jsx.string (S.get p).method_); + Data_grid.column ~id:"region" ~header:(Text "Region") + ~default_width:(Pixels 130.) ~allows_resizing:true + ~sort:(By_text (fun p -> p.region)) + (fun p -> Jsx.string (S.get p).region); + Data_grid.column ~id:"description" ~header:(Text "Description") + ~default_width:(Pixels 240.) ~allows_resizing:true + ~cell_class:"text-muted" (fun p -> Jsx.string (S.get p).description); + Data_grid.column ~id:"date" ~header:(Text "Date") + ~default_width:(Pixels 120.) ~allows_resizing:true + ~sort:(By (fun a b -> String.compare a.date b.date)) + (fun p -> + + (Jsx.string + (Types.DateTimeFormat.format (S.get day) + ~date:(Types.Either.right (Js.Date.fromString (S.get p).date)) + ())) + ); + Data_grid.column ~id:"actions" + ~header:(Element (fun () -> "Actions")) + ~align:`end_ ~pinned:`end_ ~width:(Pixels 72.) actions; + |] + +let make () = + let money = + I18n.create_number_formatter + (Types.Either.left + (Types.NumberFormatOptions.make ~style:`currency ~currency:"USD" ())) + in + let day = + I18n.create_date_formatter + (Types.Either.left + (Types.DateTimeFormatOptions.make ~year:"numeric" ~month:"short" + ~day:"numeric" ~time_zone:"UTC" ())) + in + p.id) + columns=(columns ~money ~day) + selection_mode=`multiple + show_selection_checkboxes=true + default_sort_descriptor={ column = "customer"; direction = `ascending } + allows_column_resize=true + sticky_header=true + scroll_container_class="max-h-[320px]" + content_class="min-w-[1400px]" + /> diff --git a/docs/islands/data_grid_usage.mlx b/docs/islands/data_grid_usage.mlx index e9ce0f1..9bbba2a 100644 --- a/docs/islands/data_grid_usage.mlx +++ b/docs/islands/data_grid_usage.mlx @@ -17,6 +17,11 @@ type payment = { email : string; status : status; amount : float; + fee : float; + method_ : string; + region : string; + description : string; + date : string; } let payments = @@ -27,20 +32,35 @@ let payments = email = "emma@example.com"; status = Succeeded; amount = 2450.; + fee = 73.5; + method_ = {js|Visa •••• 4242|js}; + region = "North America"; + description = {js|Annual subscription — Enterprise plan|js}; + date = "2025-12-07"; }; { id = "pay_1N3x9M"; customer = "Isabella Nguyen"; email = "isabella@example.com"; status = Succeeded; - amount = 899.; + amount = 299.; + fee = 8.97; + method_ = {js|Visa •••• 1234|js}; + region = "Asia Pacific"; + description = {js|Quarterly subscription — Team plan|js}; + date = "2025-12-03"; }; { id = "pay_1N3x8L"; customer = "Jackson Lee"; email = "jackson@example.com"; status = Processing; - amount = 320.; + amount = 39.; + fee = 1.43; + method_ = {js|Mastercard •••• 5555|js}; + region = "North America"; + description = {js|Monthly add-on — Extra seats|js}; + date = "2025-12-02"; }; { id = "pay_1N3xCQ"; @@ -48,6 +68,11 @@ let payments = email = "liam@example.com"; status = Refunded; amount = 150.; + fee = 4.5; + method_ = {js|Mastercard •••• 6789|js}; + region = "Europe"; + description = {js|Monthly subscription — Pro plan|js}; + date = "2025-12-06"; }; { id = "pay_1N3x7K"; @@ -55,6 +80,23 @@ let payments = email = "olivia@example.com"; status = Succeeded; amount = 1999.; + fee = 59.97; + method_ = {js|Visa •••• 4242|js}; + region = "North America"; + description = {js|Annual subscription — Pro plan|js}; + date = "2025-12-01"; + }; + { + id = "pay_1N3xBP"; + customer = "Sofia Davis"; + email = "sofia@example.com"; + status = Succeeded; + amount = 450.; + fee = 13.5; + method_ = {js|Visa •••• 9012|js}; + region = "Europe"; + description = {js|One-time purchase — Enterprise setup|js}; + date = "2025-12-05"; }; { id = "pay_1N3xAN"; @@ -62,6 +104,11 @@ let payments = email = "will@example.com"; status = Failed; amount = 99.; + fee = 3.17; + method_ = {js|Amex •••• 3782|js}; + region = "Asia Pacific"; + description = {js|Monthly subscription — Starter plan|js}; + date = "2025-12-04"; }; |] @@ -108,20 +155,29 @@ let actions p = -let columns money = +let columns ~money ~day = + let amount ~class_ value = + + (Jsx.string (Types.NumberFormat.format (S.get money) value)) + + in [| Data_grid.column ~id:"customer" ~header:(Text "Customer") - ~is_row_header:true + ~is_row_header:true ~default_width:(Pixels 240.) ~allows_resizing:true ~sort:(By_text (fun p -> p.customer)) (fun p ->
- (Jsx.string (S.get p).customer) + + (Jsx.string (S.get p).customer) + (Jsx.string (S.get p).email)
); Data_grid.column ~id:"id" ~header:(Text "Transaction ID") + ~default_width:(Pixels 130.) ~allows_resizing:true ~cell_class:"font-mono text-xs text-muted" (fun p -> Jsx.string (S.get p).id); Data_grid.column ~id:"status" ~header:(Text "Status") + ~default_width:(Pixels 120.) ~allows_resizing:true ~sort:(By_text (fun p -> status_name p.status)) (fun p -> ); Data_grid.column ~id:"amount" ~header:(Text "Amount") ~align:`end_ + ~default_width:(Pixels 110.) ~allows_resizing:true ~sort:(By (fun a b -> Float.compare a.amount b.amount)) - ~cell_class:"tabular-nums" + (fun p -> amount ~class_:"font-medium tabular-nums" (S.get p).amount); + Data_grid.column ~id:"fee" ~header:(Text "Fee") ~align:`end_ + ~default_width:(Pixels 90.) ~allows_resizing:true + ~sort:(By (fun a b -> Float.compare a.fee b.fee)) + (fun p -> amount ~class_:"text-muted tabular-nums" (S.get p).fee); + Data_grid.column ~id:"net" ~header:(Text "Net") ~align:`end_ + ~default_width:(Pixels 110.) ~allows_resizing:true + ~sort: + (By (fun a b -> Float.compare (a.amount -. a.fee) (b.amount -. b.fee))) (fun p -> - Jsx.string (Types.NumberFormat.format (S.get money) (S.get p).amount)); + amount ~class_:"font-medium tabular-nums" + ((S.get p).amount -. (S.get p).fee)); + Data_grid.column ~id:"method" ~header:(Text "Payment Method") + ~default_width:(Pixels 170.) ~allows_resizing:true (fun p -> + Jsx.string (S.get p).method_); + Data_grid.column ~id:"region" ~header:(Text "Region") + ~default_width:(Pixels 130.) ~allows_resizing:true + ~sort:(By_text (fun p -> p.region)) + (fun p -> Jsx.string (S.get p).region); + Data_grid.column ~id:"description" ~header:(Text "Description") + ~default_width:(Pixels 240.) ~allows_resizing:true + ~cell_class:"text-muted" (fun p -> Jsx.string (S.get p).description); + Data_grid.column ~id:"date" ~header:(Text "Date") + ~default_width:(Pixels 120.) ~allows_resizing:true + ~sort:(By (fun a b -> String.compare a.date b.date)) + (fun p -> + + (Jsx.string + (Types.DateTimeFormat.format (S.get day) + ~date:(Types.Either.right (Js.Date.fromString (S.get p).date)) + ())) + ); Data_grid.column ~id:"actions" ~header:(Element (fun () -> "Actions")) ~align:`end_ ~pinned:`end_ ~width:(Pixels 72.) actions; @@ -148,13 +234,20 @@ let make () = (Types.Either.left (Types.NumberFormatOptions.make ~style:`currency ~currency:"USD" ())) in + let day = + I18n.create_date_formatter + (Types.Either.left + (Types.DateTimeFormatOptions.make ~year:"numeric" ~month:"short" + ~day:"numeric" ~time_zone:"UTC" ())) + in p.id) - columns=(columns money) + columns=(columns ~money ~day) selection_mode=`multiple show_selection_checkboxes=true default_sort_descriptor={ column = "customer"; direction = `ascending } - content_class="min-w-[720px]" + allows_column_resize=true + content_class="min-w-[1400px]" /> diff --git a/docs/islands/data_grid_users.mlx b/docs/islands/data_grid_users.mlx new file mode 100644 index 0000000..c1ad2d5 --- /dev/null +++ b/docs/islands/data_grid_users.mlx @@ -0,0 +1,60 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Button = Solidtype_heroui.Button +module Data_grid = Solidtype_heroui.Data_grid +module Link = Solidtype_heroui.Link + +type user = { name : string; title : string; email : string; role : string } + +let user name title email role = { name; title; email; role } + +let users = + [| + user "Lindsay Walton" "Front-end Developer" "lindsay.walton@example.com" + "Member"; + user "Courtney Henry" "Designer" "courtney.henry@example.com" "Admin"; + user "Tom Cook" "Director of Product" "tom.cook@example.com" "Member"; + user "Whitney Francis" "Copywriter" "whitney.francis@example.com" "Admin"; + user "Leonard Krasner" "Senior Designer" "leonard.krasner@example.com" + "Owner"; + user "Floyd Miles" "Principal Designer" "floyd.miles@example.com" "Member"; + |] + +let columns = + [| + Data_grid.column ~id:"name" ~header:(Text "Name") ~is_row_header:true + ~cell_class:"font-medium" (fun u -> Jsx.string (S.get u).name); + Data_grid.column ~id:"title" ~header:(Text "Title") (fun u -> + Jsx.string (S.get u).title); + Data_grid.column ~id:"email" ~header:(Text "Email") (fun u -> + Jsx.string (S.get u).email); + Data_grid.column ~id:"role" ~header:(Text "Role") (fun u -> + Jsx.string (S.get u).role); + Data_grid.column ~id:"actions" + ~header:(Element (fun () -> "Actions")) + ~align:`end_ + (fun u -> + "Edit"); + |] + +let make () = +
+
+
+

"Users"

+

+ "A list of all the users in your account including their name, \ + title, email and role." +

+
+ +
+ u.email) + columns + content_class="min-w-[640px]" + /> +
diff --git a/docs/islands/data_grid_virtualization.mlx b/docs/islands/data_grid_virtualization.mlx index e72fe5e..4eacaed 100644 --- a/docs/islands/data_grid_virtualization.mlx +++ b/docs/islands/data_grid_virtualization.mlx @@ -1,40 +1,223 @@ module S = Solidtype.Solid module Jsx = Solidtype.Jsx +module Chip = Solidtype_heroui.Chip module Data_grid = Solidtype_heroui.Data_grid +module Search_field = Solidtype_heroui.Search_field +module Rating = Solidtype_heroui.Rating +module Segment = Solidtype_heroui.Segment +module Gravity = Solidtype_gravity_icons +module I18n = Solidtype_kobalte.I18n +module Types = Solidtype_kobalte.Types -type entry = { id : string; name : string; email : string; city : string } +type stock = In_stock | Low_stock | Out_of_stock -let cities = [| "Berlin"; "Lisbon"; "Oslo"; "Tokyo"; "Toronto"; "Nairobi" |] +type product = { + id : string; + name : string; + sku : string; + units : int; + price : float; + cost : float; + rating : float; + sales : int; +} -let entries = +let brands = + [| + "ZenCore"; + "EchoLink"; + "TechFlow"; + "PrimeByte"; + "NovaPeak"; + "PixelForge"; + "SwiftEdge"; + |] + +let grades = + [| + "Turbo"; + "Advanced"; + "Deluxe"; + "Ultra"; + "Slim"; + "Elite"; + "Eco"; + "Compact"; + "Portable"; + "Wireless"; + |] + +let kinds = + [| + "Sensor"; + "Mouse"; + "Drive"; + "Tablet"; + "Cable"; + "Headphones"; + "Controller"; + "Charger"; + "Speaker"; + "Keyboard"; + "Monitor"; + |] + +let lines = [| "LGT"; "AUD"; "KEY"; "SPK"; "MON"; "FRN"; "CAM"; "ACC" |] + +(* The same thousand products on every visit: each field a number drawn from + the product's index, never from a random source. *) +let drawn i salt n = (((i + 1) * 7919) + (salt * 104729)) mod n +let one_of i salt names = names.(drawn i salt (Array.length names)) + +let products = Array.init 1000 (fun i -> + let price = float_of_int (50 + drawn i 4 1950) in { id = string_of_int (i + 1); - name = "Person " ^ string_of_int (i + 1); - email = "person" ^ string_of_int (i + 1) ^ "@example.com"; - city = cities.(i mod Array.length cities); + name = + one_of i 1 brands ^ " " ^ one_of i 2 grades ^ " " ^ one_of i 3 kinds; + sku = one_of i 5 lines ^ "-" ^ string_of_int (1000 + drawn i 6 9000); + units = + (match drawn i 7 10 with + | 0 | 1 -> 0 + | 2 | 3 -> 1 + drawn i 8 5 + | _ -> 6 + drawn i 8 195); + price; + cost = Float.round (price *. float_of_int (30 + drawn i 9 40) /. 100.); + rating = 3. +. (float_of_int (drawn i 10 5) /. 2.); + sales = drawn i 11 1000; }) -let columns = +let stock p = + if p.units = 0 then Out_of_stock + else if p.units <= 5 then Low_stock + else In_stock + +let stock_key = function + | In_stock -> "in-stock" + | Low_stock -> "low-stock" + | Out_of_stock -> "out-of-stock" + +let stock_chip p = + match stock p with + | In_stock -> + + "In Stock" + + | Low_stock -> + + "Low Stock" + + | Out_of_stock -> + + "Out of Stock" + + +let stars rating = + + + + + + + + +let columns money = + let price ~class_ value = + + (Jsx.string (Types.NumberFormat.format (S.get money) value)) + + in [| - Data_grid.column ~id:"name" ~header:(Text "Name") ~is_row_header:true - ~sort:(By_text (fun e -> e.name)) - (fun e -> Jsx.string (S.get e).name); - Data_grid.column ~id:"email" ~header:(Text "Email") (fun e -> - Jsx.string (S.get e).email); - Data_grid.column ~id:"city" ~header:(Text "City") - ~sort:(By_text (fun e -> e.city)) - (fun e -> Jsx.string (S.get e).city); + Data_grid.column ~id:"name" ~header:(Text "Product") ~is_row_header:true + ~width:(Pixels 280.) (fun p -> +
+ (S.get + (Jsx.string (S.get p).name) +
); + Data_grid.column ~id:"sku" ~header:(Text "SKU") ~min_width:100. + ~cell_class:"font-mono text-xs text-muted" (fun p -> + Jsx.string (S.get p).sku); + Data_grid.column ~id:"status" ~header:(Text "Status") ~width:(Pixels 140.) + (fun p -> stock_chip (S.get p)); + Data_grid.column ~id:"stock" ~header:(Text "Stock") ~align:`center (fun p -> + Jsx.int (S.get p).units); + Data_grid.column ~id:"price" ~header:(Text "Price") ~align:`end_ (fun p -> + price ~class_:"tabular-nums" (S.get p).price); + Data_grid.column ~id:"cost" ~header:(Text "Cost") ~align:`end_ + ~cell_class:"text-muted" (fun p -> + price ~class_:"tabular-nums" (S.get p).cost); + Data_grid.column ~id:"rating" ~header:(Text "Rating") (fun p -> + stars (S.get p).rating); + Data_grid.column ~id:"sales" ~header:(Text "Sales") ~align:`end_ (fun p -> + (Jsx.int (S.get p).sales)); |] let make () = - e.id) - columns - virtualized=true - row_height=48. - heading_height=36. - content_class="h-[400px] min-w-[640px] overflow-auto" - /> + let money = + I18n.create_number_formatter + (Types.Either.left + (Types.NumberFormatOptions.make ~style:`currency ~currency:"USD" + ~maximum_fraction_digits:0. ())) + in + let shown, set_shown = S.create_signal "all" in + let query, set_query = S.create_signal "" in + let rows = + S.create_memo (fun () -> + let shown = S.get shown in + let query = String.lowercase_ascii (String.trim (S.get query)) in + let matches text = + Js.String.includes ~search:query (String.lowercase_ascii text) + in + Js.Array.filter products ~f:(fun p -> + (String.equal shown "all" + || String.equal shown (stock_key (stock p))) + && (String.equal query "" || matches p.name || matches p.sku))) + in +
+
+ S.set set_shown key)> + "All" + "In Stock" + "Out of Stock" + "Low Stock" + + S.set set_query text)> + + + + + + +
+ p.id) + columns=(columns money) + selection_mode=`multiple + show_selection_checkboxes=true + virtualized=true + row_height=58. + heading_height=37. + content_class="h-[600px] min-w-[900px] overflow-auto" + /> +
diff --git a/docs/islands/heroui_react.ml b/docs/islands/heroui_react.ml index 360cf77..6f9edfd 100644 --- a/docs/islands/heroui_react.ml +++ b/docs/islands/heroui_react.ml @@ -758,3 +758,15 @@ external tag_group_props : external tag_group : Dom.htmlDivElement -> tag_group_props -> unit = "tagGroup" [@@mel.module "./react/heroui.tsx"] + +type toolbar_props + +external toolbar_props : + orientation:string -> + is_attached:(bool[@mel.as "isAttached"]) -> + unit -> + toolbar_props = "" +[@@mel.obj] + +external toolbar : Dom.htmlDivElement -> toolbar_props -> unit = "toolbar" +[@@mel.module "./react/heroui.tsx"] diff --git a/docs/islands/inline_select_custom_indicator.mlx b/docs/islands/inline_select_custom_indicator.mlx new file mode 100644 index 0000000..7a32b02 --- /dev/null +++ b/docs/islands/inline_select_custom_indicator.mlx @@ -0,0 +1,26 @@ +module Inline_select = Solidtype_heroui.Inline_select +module List_box = Solidtype_heroui.List_box +module Gravity = Solidtype_gravity_icons + +let make () = + + + + + + + + + + + "Viewer" + + + "Editor" + + + "Admin" + + + + diff --git a/docs/islands/inline_select_multi_select.mlx b/docs/islands/inline_select_multi_select.mlx new file mode 100644 index 0000000..1cd436c --- /dev/null +++ b/docs/islands/inline_select_multi_select.mlx @@ -0,0 +1,22 @@ +module Inline_select = Solidtype_heroui.Inline_select +module List_box = Solidtype_heroui.List_box + +let make () = + + + + + + + + "Email" + + + "WhatsApp" + + + "Push Notification" + + + + diff --git a/docs/islands/inline_select_placements.mlx b/docs/islands/inline_select_placements.mlx new file mode 100644 index 0000000..8e372fd --- /dev/null +++ b/docs/islands/inline_select_placements.mlx @@ -0,0 +1,53 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Inline_select = Solidtype_heroui.Inline_select +module List_box = Solidtype_heroui.List_box + +let placements = + [| + ("bottom", `bottom, "bottom"); + ("bottom-start", `bottom_start, "bottom start"); + ("bottom-end", `bottom_end, "bottom end (default)"); + ("top", `top, "top"); + ("top-start", `top_start, "top start"); + ("top-end", `top_end, "top end"); + ("left", `left, "left"); + ("left-top", `left_top, "left top"); + ("left-bottom", `left_bottom, "left bottom"); + ("right", `right, "right"); + ("right-top", `right_top, "right top"); + ("right-bottom", `right_bottom, "right bottom"); + |] + +let make () = + let chosen, set_chosen = S.create_signal "bottom-end" in + let placement () = + match + Array.find_opt + (fun (id, _, _) -> String.equal id (S.get chosen)) + placements + with + | Some (_, p, _) -> p + | None -> `bottom_end + in +
+ + match keys with [| k |] -> S.set set_chosen k | _ -> ())> + + + + + + + (fun (id, _, name) _ -> + + (Jsx.string name) + ) + + + + +
diff --git a/docs/islands/inline_select_team_switcher.mlx b/docs/islands/inline_select_team_switcher.mlx new file mode 100644 index 0000000..8714275 --- /dev/null +++ b/docs/islands/inline_select_team_switcher.mlx @@ -0,0 +1,55 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Inline_select = Solidtype_heroui.Inline_select +module List_box = Solidtype_heroui.List_box +module Gravity = Solidtype_gravity_icons + +type team = { id : string; name : string; color : string } + +let teams = + [| + { id = "northwind"; name = "Northwind Labs"; color = "bg-violet-700" }; + { id = "acme"; name = "Acme Corp"; color = "bg-blue-600" }; + { id = "maple"; name = "Maple Studio"; color = "bg-amber-600" }; + |] + +let mark team = +
+ + (Jsx.string (String.sub team.name 0 1)) + +
+ +let make () = + let chosen, set_chosen = S.create_signal teams.(0) in +
+ + "/" + + match Array.find_opt (fun t -> Array.mem t.id keys) teams with + | Some t -> S.set set_chosen t + | None -> ())> + + (mark (S.get chosen)) + + (Jsx.string (S.get chosen).name) + + + + + + + (fun team _ -> + + (mark team) (Jsx.string team.name) + ) + + + + +
diff --git a/docs/islands/inline_select_usage.mlx b/docs/islands/inline_select_usage.mlx new file mode 100644 index 0000000..43ea9ae --- /dev/null +++ b/docs/islands/inline_select_usage.mlx @@ -0,0 +1,25 @@ +module Inline_select = Solidtype_heroui.Inline_select +module List_box = Solidtype_heroui.List_box + +let make () = + + + + + + + + "English" + + + "Spanish" + + + "French" + + + "Japanese" + + + + diff --git a/docs/islands/list_view_disabled_items.mlx b/docs/islands/list_view_disabled_items.mlx new file mode 100644 index 0000000..4369f8c --- /dev/null +++ b/docs/islands/list_view_disabled_items.mlx @@ -0,0 +1,37 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module List_view = Solidtype_heroui.List_view +module Gravity = Solidtype_gravity_icons + +let files = + [| + ("documents", "Documents", true); + ("budget", "Budget.xlsx", false); + ("archived", "Archived.zip", false); + ("photos", "Photos", true); + ("backup", "Old backup.tar", false); + ("readme", "README.md", false); + |] + +let locked = [| "archived"; "backup" |] + +let make () = +
+ + + (fun (id, name, folder) _ -> + + + (if folder then else ) + (Jsx.string name) + + (if Array.exists (String.equal id) locked then + + + + else Jsx.string "") + ) + + +
diff --git a/docs/islands/list_view_secondary.mlx b/docs/islands/list_view_secondary.mlx new file mode 100644 index 0000000..1a0463d --- /dev/null +++ b/docs/islands/list_view_secondary.mlx @@ -0,0 +1,34 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module List_view = Solidtype_heroui.List_view +module Gravity = Solidtype_gravity_icons + +let files = + [| + ("documents", "Documents", "2 days ago", true); + ("photos", "Photos", "1 week ago", true); + ("readme", "README.md", "3 hours ago", false); + ("package", "package.json", "Yesterday", false); + ("src", "src", "Just now", true); + |] + +let make () = +
+ + + (fun (id, name, updated, folder) _ -> + + + (if folder then else ) +
+ (Jsx.string name) + + (Jsx.string ("Updated " ^ updated)) + +
+
+
) +
+
+
diff --git a/docs/islands/list_view_selection_modes.mlx b/docs/islands/list_view_selection_modes.mlx new file mode 100644 index 0000000..c8ff603 --- /dev/null +++ b/docs/islands/list_view_selection_modes.mlx @@ -0,0 +1,64 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module List_view = Solidtype_heroui.List_view +module Gravity = Solidtype_gravity_icons + +let files = + [| + ("documents", "Documents", "2 days ago", true); + ("photos", "Photos", "1 week ago", true); + ("readme", "README.md", "3 hours ago", false); + ("package", "package.json", "Yesterday", false); + ("src", "src", "Just now", true); + |] + +let name_of id = + match Array.find_opt (fun (k, _, _, _) -> String.equal k id) files with + | Some (_, name, _, _) -> name + | None -> id + +let chosen_text = function + | [||] -> "None selected" + | [| one |] -> name_of one + | many -> string_of_int (Array.length many) ^ " selected" + +let column ~title ~mode = + let chosen, set_chosen = S.create_signal [||] in +
+
+ (Jsx.string title) + (match mode with + | `none -> Jsx.string "" + | `single | `multiple -> + + (Jsx.string (chosen_text (S.get chosen))) + ) +
+ S.set set_chosen keys)> + + (fun (id, name, updated, folder) _ -> + + + (if folder then else ) +
+ (Jsx.string name) + + (Jsx.string ("Updated " ^ updated)) + +
+
+
) +
+
+
+ +let make () = +
+ (column ~title:"None" ~mode:`none) + (column ~title:"Single" ~mode:`single) + (column ~title:"Multiple" ~mode:`multiple) +
diff --git a/docs/islands/list_view_usage.mlx b/docs/islands/list_view_usage.mlx new file mode 100644 index 0000000..48074e1 --- /dev/null +++ b/docs/islands/list_view_usage.mlx @@ -0,0 +1,35 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module List_view = Solidtype_heroui.List_view +module Gravity = Solidtype_gravity_icons + +let files = + [| + ("documents", "Documents", "2 days ago", true); + ("photos", "Photos", "1 week ago", true); + ("readme", "README.md", "3 hours ago", false); + ("package", "package.json", "Yesterday", false); + ("src", "src", "Just now", true); + ("gitignore", ".gitignore", "2 weeks ago", false); + |] + +let make () = +
+ + + (fun (id, name, updated, folder) _ -> + + + (if folder then else ) +
+ (Jsx.string name) + + (Jsx.string ("Updated " ^ updated)) + +
+
+
) +
+
+
diff --git a/docs/islands/list_view_virtualization.mlx b/docs/islands/list_view_virtualization.mlx new file mode 100644 index 0000000..00004b0 --- /dev/null +++ b/docs/islands/list_view_virtualization.mlx @@ -0,0 +1,33 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module List_view = Solidtype_heroui.List_view +module Gravity = Solidtype_gravity_icons + +let files = + Array.init 1000 (fun i -> + let n = string_of_int (i + 1) in + (n, "report-" ^ n ^ ".pdf", string_of_int ((i * 37 mod 900) + 12) ^ " KB")) + +let make () = +
+ + + (fun (id, name, size) _ -> + + + +
+ (Jsx.string name) + (Jsx.string size) +
+
+
) +
+
+
diff --git a/docs/islands/list_view_with_action_bar.mlx b/docs/islands/list_view_with_action_bar.mlx new file mode 100644 index 0000000..66d5b48 --- /dev/null +++ b/docs/islands/list_view_with_action_bar.mlx @@ -0,0 +1,86 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Action_bar = Solidtype_heroui.Action_bar +module Button = Solidtype_heroui.Button +module Chip = Solidtype_heroui.Chip +module List_view = Solidtype_heroui.List_view +module Separator = Solidtype_heroui.Separator +module Gravity = Solidtype_gravity_icons + +let files = + [| + ("design", "Design System", "2 days ago", true); + ("photos", "Photos", "1 week ago", true); + ("readme", "README.md", "3 hours ago", false); + ("package", "package.json", "Yesterday", false); + ("src", "src", "Just now", true); + ("gitignore", ".gitignore", "2 weeks ago", false); + ("tsconfig", "tsconfig.json", "3 days ago", false); + ("modules", "node_modules", "1 day ago", true); + |] + +let make () = + let chosen, set_chosen = S.create_signal [||] in +
+ S.set set_chosen keys)> + + (fun (id, name, updated, folder) _ -> + + + (if folder then else ) +
+ (Jsx.string name) + + (Jsx.string ("Updated " ^ updated)) + +
+
+
) +
+
+ 0) aria_label="File actions"> + + + (Jsx.int (Array.length (S.get chosen))) + + + + + + + + + + + + + + + +
diff --git a/docs/islands/radio_group_delivery_and_payment.mlx b/docs/islands/radio_group_delivery_and_payment.mlx new file mode 100644 index 0000000..fc9c355 --- /dev/null +++ b/docs/islands/radio_group_delivery_and_payment.mlx @@ -0,0 +1,88 @@ +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Description = Solidtype_heroui.Description +module Label = Solidtype_heroui.Label +module Radio = Solidtype_heroui.Radio +module Radio_group = Solidtype_heroui.Radio_group +module Gravity = Solidtype_gravity_icons + +let deliveries = + [| + ("standard", "Standard", "4-10 business days", "$5.00"); + ("express", "Express", "2-5 business days", "$16.00"); + ("super-fast", "Super Fast", "1 business day", "$25.00"); + |] + +let payments = + [| + ("mastercard", "**** 8304", "Exp. on 01/2026"); + ("visa", "**** 0123", "Exp. on 01/2026"); + ("paypal", "PayPal", "Pay with PayPal"); + |] + +let accent = + "--accent: #006FEE; --accent-foreground: #fff; --accent-hover: #006FEE; \ + --border-width: 2px; --border-width-field: 2px; --focus: #006FEE;" + +let make () = +
+
+ + +
+ + (fun (value, title, description, price) _ -> + + + + + +
+ (Jsx.string title) + (Jsx.string description) +
+ (Jsx.string price) +
+
) +
+
+
+
+
+ +
+ +
+
+ + (fun (value, title, description) _ -> + + + + + + (if String.equal value "paypal" then + + else ) +
+ (Jsx.string title) + (Jsx.string description) +
+
+
) +
+
+
+
+
diff --git a/docs/islands/radio_group_in_surface.mlx b/docs/islands/radio_group_in_surface.mlx new file mode 100644 index 0000000..a77c6ce --- /dev/null +++ b/docs/islands/radio_group_in_surface.mlx @@ -0,0 +1,32 @@ +module Description = Solidtype_heroui.Description +module Label = Solidtype_heroui.Label +module Radio = Solidtype_heroui.Radio +module Radio_group = Solidtype_heroui.Radio_group +module Surface = Solidtype_heroui.Surface + +let make () = + + + + "Choose the plan that suits you best" + + + "Basic Plan" + + "Includes 100 messages per month" + + + + "Premium Plan" + + "Includes 200 messages per month" + + + + "Business Plan" + + "Unlimited messages" + + + diff --git a/docs/islands/radio_group_validation.mlx b/docs/islands/radio_group_validation.mlx new file mode 100644 index 0000000..c4e60c3 --- /dev/null +++ b/docs/islands/radio_group_validation.mlx @@ -0,0 +1,57 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +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 Radio = Solidtype_heroui.Radio +module Radio_group = Solidtype_heroui.Radio_group + +external prevent_default : Dom.event -> unit = "preventDefault" [@@mel.send] + +let make () = + let plan, set_plan = S.create_signal None in + let tried, set_tried = S.create_signal false in + let message, set_message = S.create_signal None in +
+ prevent_default e; + S.set set_tried true; + S.set set_message + (Option.map + (fun p -> "Your chosen plan is: " ^ p) + (S.get plan)))> + S.set set_plan (Some p))> + + + + "Starter" + + "For side projects and small teams" + + + + "Pro" + + "Advanced reporting and analytics" + + + + "Teams" + + "Share access with up to 10 teammates" + + "Choose a subscription before continuing." + + + + (fun m ->

(Jsx.string (S.get m))

) +
+
diff --git a/docs/islands/rating_controlled.mlx b/docs/islands/rating_controlled.mlx new file mode 100644 index 0000000..c8f9b1c --- /dev/null +++ b/docs/islands/rating_controlled.mlx @@ -0,0 +1,21 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Rating = Solidtype_heroui.Rating + +let make () = + let value, set_value = S.create_signal 3. in +
+ S.set set_value v)> + + + + + + + + (Jsx.string (Js.Float.toString (S.get value) ^ " stars")) + +
diff --git a/docs/islands/rating_custom_color.mlx b/docs/islands/rating_custom_color.mlx new file mode 100644 index 0000000..05e30ad --- /dev/null +++ b/docs/islands/rating_custom_color.mlx @@ -0,0 +1,26 @@ +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Rating = Solidtype_heroui.Rating + +let colors = + [| ("accent", "Accent"); ("danger", "Danger"); ("success", "Success") |] + +let make () = +
+ + (fun (color, name) _ -> +
+ + + + + + + + (Jsx.string name) +
) +
+
diff --git a/docs/islands/rating_custom_icon_heart.mlx b/docs/islands/rating_custom_icon_heart.mlx new file mode 100644 index 0000000..ce67d7b --- /dev/null +++ b/docs/islands/rating_custom_icon_heart.mlx @@ -0,0 +1,11 @@ +module Rating = Solidtype_heroui.Rating +module Gravity = Solidtype_gravity_icons + +let make () = + )> + + + + + + diff --git a/docs/islands/rating_custom_icon_per_item.mlx b/docs/islands/rating_custom_icon_per_item.mlx new file mode 100644 index 0000000..0dd853b --- /dev/null +++ b/docs/islands/rating_custom_icon_per_item.mlx @@ -0,0 +1,13 @@ +module For = Solidtype.For +module Rating = Solidtype_heroui.Rating +module Gravity = Solidtype_gravity_icons + +let make () = + + + (fun value _ -> ) + + diff --git a/docs/islands/rating_disabled.mlx b/docs/islands/rating_disabled.mlx new file mode 100644 index 0000000..bc3268b --- /dev/null +++ b/docs/islands/rating_disabled.mlx @@ -0,0 +1,10 @@ +module Rating = Solidtype_heroui.Rating + +let make () = + + + + + + + diff --git a/docs/islands/rating_product_review.mlx b/docs/islands/rating_product_review.mlx new file mode 100644 index 0000000..f6d8fc6 --- /dev/null +++ b/docs/islands/rating_product_review.mlx @@ -0,0 +1,37 @@ +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Rating = Solidtype_heroui.Rating + +let scores = + [| + ("Quality", 4.5); + ("Value for money", 3.7); + ("Design", 5.); + ("Durability", 2.3); + |] + +let make () = +
+ + (fun (name, score) _ -> +
+ (Jsx.string name) +
+ + + + + + + + + (Jsx.string (Js.Float.toString score)) + +
+
) +
+
diff --git a/docs/islands/rating_read_only.mlx b/docs/islands/rating_read_only.mlx new file mode 100644 index 0000000..0d3a90b --- /dev/null +++ b/docs/islands/rating_read_only.mlx @@ -0,0 +1,27 @@ +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Rating = Solidtype_heroui.Rating + +let values = [| 1.5; 2.3; 3.7; 4.2; 4.8 |] + +let make () = +
+ + (fun value _ -> +
+ + + + + + + + + (Jsx.string (Js.Float.toString value)) + +
) +
+
diff --git a/docs/islands/rating_read_only_fractional.mlx b/docs/islands/rating_read_only_fractional.mlx new file mode 100644 index 0000000..0d3a90b --- /dev/null +++ b/docs/islands/rating_read_only_fractional.mlx @@ -0,0 +1,27 @@ +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Rating = Solidtype_heroui.Rating + +let values = [| 1.5; 2.3; 3.7; 4.2; 4.8 |] + +let make () = +
+ + (fun value _ -> +
+ + + + + + + + + (Jsx.string (Js.Float.toString value)) + +
) +
+
diff --git a/docs/islands/rating_render_function.mlx b/docs/islands/rating_render_function.mlx new file mode 100644 index 0000000..3fcbbab --- /dev/null +++ b/docs/islands/rating_render_function.mlx @@ -0,0 +1,34 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Rating = Solidtype_heroui.Rating +module Gravity = Solidtype_gravity_icons + +let make () = + let value, set_value = S.create_signal 0. in +
+ S.set set_value v)> + + (fun value _ -> + + (fun state -> + + + ) + ) + + + + (Jsx.string + (match S.get value with + | 0. -> "No rating" + | 1. -> "1 star" + | v -> Js.Float.toString v ^ " stars")) + +
diff --git a/docs/islands/rating_sizes.mlx b/docs/islands/rating_sizes.mlx new file mode 100644 index 0000000..2b29191 --- /dev/null +++ b/docs/islands/rating_sizes.mlx @@ -0,0 +1,22 @@ +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Rating = Solidtype_heroui.Rating + +let sizes = [| (`sm, "sm"); (`md, "md"); (`lg, "lg") |] + +let make () = +
+ + (fun (size, name) _ -> +
+ + + + + + + + (Jsx.string name) +
) +
+
diff --git a/docs/islands/rating_usage.mlx b/docs/islands/rating_usage.mlx new file mode 100644 index 0000000..4c4de8c --- /dev/null +++ b/docs/islands/rating_usage.mlx @@ -0,0 +1,10 @@ +module Rating = Solidtype_heroui.Rating + +let make () = + + + + + + + diff --git a/docs/islands/rating_with_label.mlx b/docs/islands/rating_with_label.mlx new file mode 100644 index 0000000..72d1aaa --- /dev/null +++ b/docs/islands/rating_with_label.mlx @@ -0,0 +1,14 @@ +module Rating = Solidtype_heroui.Rating +module Label = Solidtype_heroui.Label + +let make () = +
+ + + + + + + + +
diff --git a/docs/islands/react/heroui.tsx b/docs/islands/react/heroui.tsx index b512cfe..1f98178 100644 --- a/docs/islands/react/heroui.tsx +++ b/docs/islands/react/heroui.tsx @@ -4,7 +4,7 @@ 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 { 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, Toolbar, Tooltip, Typography, useFilter } from "@heroui/react"; import { useState } from "react"; import { flushSync } from "react-dom"; import { createRoot, type Root } from "react-dom/client"; @@ -1437,3 +1437,32 @@ function TagGroupDemo(props: TagGroupProps) { export function tagGroup(host: HTMLElement, props: TagGroupProps): void { flushSync(() => rootOf(host).render()); } + +type ToolbarProps = { orientation: "horizontal" | "vertical"; isAttached: boolean }; + +// A text style group and two buttons, as the port's demo draws them. +export function toolbar(host: HTMLElement, props: ToolbarProps): void { + flushSync(() => + rootOf(host).render( + + + + B + + + I + + + + + + + + , + ), + ); +} diff --git a/docs/islands/surface_with_form_components.mlx b/docs/islands/surface_with_form_components.mlx new file mode 100644 index 0000000..a5d607c --- /dev/null +++ b/docs/islands/surface_with_form_components.mlx @@ -0,0 +1,18 @@ +module Input = Solidtype_heroui.Input +module Surface = Solidtype_heroui.Surface +module Text_area = Solidtype_heroui.Text_area + +let make () = + + + + diff --git a/docs/islands/switch_form_integration.mlx b/docs/islands/switch_form_integration.mlx new file mode 100644 index 0000000..5df6367 --- /dev/null +++ b/docs/islands/switch_form_integration.mlx @@ -0,0 +1,66 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Show = Solidtype.Show +module Button = Solidtype_heroui.Button +module Form = Solidtype_heroui.Form +module Switch = Solidtype_heroui.Switch +module Switch_group = Solidtype_heroui.Switch_group + +external prevent_default : Dom.event -> unit = "preventDefault" [@@mel.send] + +external current_target : Dom.event -> Dom.htmlFormElement = "currentTarget" +[@@mel.get] + +type form_data + +external form_data : Dom.htmlFormElement -> form_data = "FormData" [@@mel.new] + +type entries + +external entries : form_data -> entries = "entries" [@@mel.send] + +(* Each entry a pair, its name and its value, as JavaScript gives it. *) +external listed : entries -> (string * string) array = "from" +[@@mel.scope "Array"] + +let make () = + let sent, set_sent = S.create_signal None in +
+ prevent_default e; + let fields = + listed (entries (form_data (current_target e))) + |> Array.map (fun (key, value) -> key ^ ": " ^ value) + in + S.set set_sent + (Some + ("Form submitted with: " + ^ String.concat ", " (Array.to_list fields))))> + + + + + "Enable notifications" + + + + + + "Subscribe to newsletter" + + + + + + "Receive marketing updates" + + + + + + (fun m ->

(Jsx.string (S.get m))

) +
+
diff --git a/docs/islands/switch_with_description.mlx b/docs/islands/switch_with_description.mlx new file mode 100644 index 0000000..b73e402 --- /dev/null +++ b/docs/islands/switch_with_description.mlx @@ -0,0 +1,12 @@ +module Description = Solidtype_heroui.Description +module Switch = Solidtype_heroui.Switch + +let make () = +
+ + + "Public profile" + + "Allow others to see your profile information" + +
diff --git a/docs/islands/switch_with_icons.mlx b/docs/islands/switch_with_icons.mlx new file mode 100644 index 0000000..26ce661 --- /dev/null +++ b/docs/islands/switch_with_icons.mlx @@ -0,0 +1,54 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Switch = Solidtype_heroui.Switch +module Gravity = Solidtype_gravity_icons + +type icon = Jsx.element + +let switches : (string * (unit -> icon) * (unit -> icon) * string) array = + [| + ( "check", + (fun () -> ), + (fun () -> ), + "bg-green-500/80" ); + ( "darkMode", + (fun () -> ), + (fun () -> ), + "" ); + ( "microphone", + (fun () -> + ), + (fun () -> ), + "bg-red-500/80" ); + ( "notification", + (fun () -> ), + (fun () -> ), + "bg-purple-500/80" ); + ( "volume", + (fun () -> + ), + (fun () -> + ), + "bg-blue-500/80" ); + |] + +let make () = +
+ + (fun (name, on, off, selected_class) _ -> + + (fun s -> + + + + + (if S.get s.is_selected then on () else off ()) + + + + ) + ) + +
diff --git a/docs/islands/toolbar_attached.mlx b/docs/islands/toolbar_attached.mlx new file mode 100644 index 0000000..3bcc85e --- /dev/null +++ b/docs/islands/toolbar_attached.mlx @@ -0,0 +1,29 @@ +module Button = Solidtype_heroui.Button +module Button_group = Solidtype_heroui.Button_group +module Separator = Solidtype_heroui.Separator +module Toggle_button = Solidtype_heroui.Toggle_button +module Toggle_button_group = Solidtype_heroui.Toggle_button_group +module Toolbar = Solidtype_heroui.Toolbar +module Gravity = Solidtype_gravity_icons + +let make () = + + + + + + + + + + + + + + + + + + diff --git a/docs/islands/toolbar_demo.mlx b/docs/islands/toolbar_demo.mlx new file mode 100644 index 0000000..f24250b --- /dev/null +++ b/docs/islands/toolbar_demo.mlx @@ -0,0 +1,61 @@ +module S = Solidtype.Solid +module Button = Solidtype_heroui.Button +module Button_group = Solidtype_heroui.Button_group +module Separator = Solidtype_heroui.Separator +module Toggle_button = Solidtype_heroui.Toggle_button +module Toggle_button_group = Solidtype_heroui.Toggle_button_group +module Toolbar = Solidtype_heroui.Toolbar +module Select = Controls.Select +module Toggle = Controls.Toggle + +(* Each choice with the name HeroUI's React component takes for it. *) +let orientations = [| (`horizontal, "horizontal"); (`vertical, "vertical") |] + +let make () = + let orientation, set_orientation = + S.create_signal (`horizontal, "horizontal") + in + let attached, set_attached = S.create_signal false in +
+
+ ignore (on_change keys : unit option)) + ?disabled_keys=(S.get disabled_keys) + ?is_open=(S.get is_open) + ?default_open=(S.get default_open) + on_open_change=(fun o -> ignore (on_open_change o : unit option)) + ?is_disabled=(S.get is_disabled) + ?is_required=(S.get is_required) + ?is_invalid=(S.get is_invalid) + ?name=(S.get name) + class_=(after "inline-select" (S.get class_)) + data_slot="inline-select" + ref=(fun e -> ignore (given_ref e : unit option)) + on_focus_out=(fun e -> ignore (on_focus_out e : unit option)) + ?as_=(S.get as_) + props=(Props.others props)> + (S.get children) + +[@@element div] diff --git a/heroui/list-view.css b/heroui/list-view.css new file mode 100644 index 0000000..80bdfc2 --- /dev/null +++ b/heroui/list-view.css @@ -0,0 +1,124 @@ +/* List_view, in HeroUI's look, which ships no stylesheet for it: Tailwind on + HeroUI's tokens, written as HeroUI writes its components' CSS, so an + application restyles a part by a rule for its class. */ + +.list-view { + @apply relative min-h-0 w-full outline-none; +} + +/* A grey card of white rows. */ +.list-view--primary { + @apply rounded-[calc(var(--radius)*2.5)] bg-surface-secondary p-1; +} + +.list-view__item { + @apply flex cursor-(--cursor-interactive) items-center gap-3 px-4 py-3 text-sm outline-none; + -webkit-tap-highlight-color: transparent; + + &:focus-visible, + &[data-focus-visible="true"] { + box-shadow: inset 0 0 0 2px var(--color-focus); + } + + &[aria-disabled="true"] { + @apply status-disabled; + } + + &[data-dragging="true"] { + @apply opacity-50; + } +} + +/* A virtualized list scrolls its own rows, as high as a caller makes it, + each as high as the frame its row_height gives it. */ +.list-view[data-virtualized="true"] { + @apply overflow-y-auto; + + & .list-view__item { + @apply h-full; + } +} + +.list-view--primary .list-view__item { + @apply border-b bg-surface; + border-color: color-mix(in oklab, var(--separator-tertiary) 50%, transparent); + + @media (hover: hover) { + &:hover, + &[data-hovered="true"] { + @apply bg-surface/40; + } + } + + &[data-selected="true"] { + @apply bg-surface/10; + } +} + +/* The first and last rows of a list that draws them all, siblings; a + virtualized list draws each in a frame of its own. */ +.list-view--primary:not([data-virtualized="true"]) .list-view__item { + &:first-child { + @apply rounded-t-[calc(var(--radius)*2)]; + } + + &:last-child { + @apply rounded-b-[calc(var(--radius)*2)] border-b-0; + } +} + +/* Rows on the page's background, a line between each. */ +.list-view--secondary .list-view__item { + @apply border-b bg-transparent; + border-color: color-mix(in oklab, var(--separator-tertiary) 50%, transparent); + + @media (hover: hover) { + &:hover, + &[data-hovered="true"] { + @apply bg-default/50; + } + } + + &[data-selected="true"] { + @apply bg-accent-soft; + + @media (hover: hover) { + &:hover, + &[data-hovered="true"] { + background-color: var(--accent-soft-hover); + } + } + } +} + +.list-view--secondary:not([data-virtualized="true"]) .list-view__item:last-child { + @apply border-b-0; +} + +.list-view__selection-cell { + @apply flex shrink-0 items-center; +} + +.list-view__item-content { + @apply flex min-w-0 flex-1 items-center gap-3; + + & svg { + @apply size-4 shrink-0 text-muted; + } +} + +.list-view__title { + @apply truncate text-sm font-medium text-foreground; +} + +.list-view__description { + @apply mt-0.5 truncate text-xs text-muted; +} + +.list-view__item-action { + @apply ms-auto shrink-0 ps-2; +} + +.list-view__empty-state { + @apply flex items-center justify-center px-4 py-8; +} diff --git a/heroui/list_view.mli b/heroui/list_view.mli new file mode 100644 index 0000000..da95509 --- /dev/null +++ b/heroui/list_view.mli @@ -0,0 +1,170 @@ +(** A list of rows, in HeroUI's look, which ships no stylesheet for it: a + {!Solidtype_headless.Grid_list} of items, each its content and an action, + chosen by a checkbox where the list chooses, acted on by [on_action] or an + item's [href]. Its look is a stylesheet, [list-view.css], in the + [components] layer, rules for its classes. + + Its page, with its examples: + [$(opam var solidtype:doc)/pages/heroui/list-view.md]. + + {[ + + + + "README.md" + "Updated 3 hours ago" + + + + ]} + + Its keys, selection and actions are {!Solidtype_headless.Grid_list}'s. A + part is used inside a [List_view]: elsewhere it raises [Invalid_argument] as + it is made. *) + +module S := Solidtype.Solid +module Jsx := Solidtype.Jsx + +type variant = [ `primary | `secondary ] + +(** The content of an item, its icon and its text: a + [
]. *) +module Item_content : sig + module Props : sig + type t + + val check : + ?class_:string Solidtype.Check.value -> + children:(_, [ `elements ]) Solidtype.Check.children -> + ?as_:(Solidtype.Html.Div.props -> Jsx.element) -> + ?props:t S.rest -> + (unit -> unit) Solidtype.Html.Div.check + end + + val make : Props.t -> Jsx.element + val component : Props.t Jsx.component +end + +(** An item's name, cut short to its width: a []. +*) +module Title : sig + module Props : sig + type t + + val check : + ?class_:string Solidtype.Check.value -> + children:(_, [ `elements ]) Solidtype.Check.children -> + ?as_:(Solidtype.Html.Span.props -> Jsx.element) -> + ?props:t S.rest -> + (unit -> unit) Solidtype.Html.Span.check + end + + val make : Props.t -> Jsx.element + val component : Props.t Jsx.component +end + +(** A line under an item's name, muted: a + []. *) +module Description : sig + module Props : sig + type t + + val check : + ?class_:string Solidtype.Check.value -> + children:(_, [ `elements ]) Solidtype.Check.children -> + ?as_:(Solidtype.Html.Span.props -> Jsx.element) -> + ?props:t S.rest -> + (unit -> unit) Solidtype.Html.Span.check + end + + val make : Props.t -> Jsx.element + val component : Props.t Jsx.component +end + +(** What an item ends with, its buttons or its menu, at its far side: a + [
]. *) +module Item_action : sig + module Props : sig + type t + + val check : + ?class_:string Solidtype.Check.value -> + children:(_, [ `elements ]) Solidtype.Check.children -> + ?as_:(Solidtype.Html.Div.props -> Jsx.element) -> + ?props:t S.rest -> + (unit -> unit) Solidtype.Html.Div.check + end + + val make : Props.t -> Jsx.element + val component : Props.t Jsx.component +end + +(** An item: a [
], React Aria's state on + it as ["true"] -- [data-selected], [data-hovered], [data-pressed], + [data-focus-visible], [data-disabled] -- and [data-selection-mode]; where + the list chooses, a checkbox first that stands for its selection. *) +module Item : sig + type state = { + is_selected : bool S.accessor; + is_disabled : bool S.accessor; + is_hovered : bool S.accessor; + is_pressed : bool S.accessor; + is_focused : bool S.accessor; + is_focus_visible : bool S.accessor; + selection_mode : [ `none | `single | `multiple ] S.accessor; + } + (** What its children are drawn of, given as a function. *) + + module Props : sig + type t + + val check : + ?id:string Solidtype.Check.value -> + ?text_value:string Solidtype.Check.value -> + ?is_disabled:bool Solidtype.Check.value -> + ?href:string Solidtype.Check.value -> + ?class_:string Solidtype.Check.value -> + ?ref:(Dom.htmlDivElement -> unit) -> + children: + (state -> Jsx.element, [ `elements | `render ]) Solidtype.Check.children -> + ?as_:(Solidtype.Html.Div.props -> state -> Jsx.element) -> + ?props:t S.rest -> + (unit -> unit) Solidtype.Html.Div.check + end + + val make : Props.t -> Jsx.element + val component : Props.t Jsx.component +end + +module Props : sig + type t + + val check : + ?variant:variant Solidtype.Check.value -> + ?selection_mode:[ `none | `single | `multiple ] Solidtype.Check.value -> + ?selection_behavior:[ `toggle | `replace ] Solidtype.Check.value -> + ?selected_keys:string array Solidtype.Check.value -> + ?default_selected_keys:string array Solidtype.Check.value -> + ?on_selection_change:(string array -> unit) -> + ?disabled_keys:string array Solidtype.Check.value -> + ?disallow_empty_selection:bool Solidtype.Check.value -> + ?on_action:(string -> unit) -> + ?render_empty_state:(unit -> Jsx.element) -> + ?virtualized:bool Solidtype.Check.value -> + ?row_height:float Solidtype.Check.value -> + ?class_:string Solidtype.Check.value -> + ?ref:(Dom.htmlDivElement -> unit) -> + children:(_, [ `elements ]) Solidtype.Check.children -> + ?as_:(Solidtype.Html.Div.props -> Jsx.element) -> + ?props:t S.rest -> + (unit -> unit) Solidtype.Html.Div.check +end + +val make : Props.t -> Jsx.element +(** The list: a [
], or + [--secondary], [`primary] by default: a grey card of white rows, or rows on + the page's own background with a line between each. With [virtualized], + [data-virtualized], it draws only the rows in view, each [row_height] high, + 48 by default, and scrolls them: give it a height. *) + +val component : Props.t Jsx.component diff --git a/heroui/list_view.mlx b/heroui/list_view.mlx new file mode 100644 index 0000000..6f9376d --- /dev/null +++ b/heroui/list_view.mlx @@ -0,0 +1,242 @@ +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Headless = Solidtype_headless.Grid_list + +let after own = function Some c -> own ^ " " ^ c | None -> own + +type variant = [ `primary | `secondary ] + +(* Whether a list was given [on_action], read of its props as given, which + its own parameter, a call that does nothing where none was, cannot tell: + only a list given one runs an item's action on a press. *) +type handler + +external action_given : 'props -> handler Js.Undefined.t = "onAction" +[@@mel.get] + +external empty_state_given : 'props -> handler Js.Undefined.t + = "renderEmptyState" +[@@mel.get] + +module Variant = Solidtype.Context.Make (struct + type t = variant S.accessor + + let default = S.accessor (fun () -> `primary) +end) + +(* A part drawn as a [
] or a [] of a class of its own, its + children what it holds. *) +module Item_content = struct + let%component make ?(class_ : string option) ~(children : Jsx.element) () = +
+ (S.get children) +
+ [@@element div] +end + +module Title = struct + let%component make ?(class_ : string option) ~(children : Jsx.element) () = + + (S.get children) + + [@@element span] +end + +module Description = struct + let%component make ?(class_ : string option) ~(children : Jsx.element) () = + + (S.get children) + + [@@element span] +end + +module Item_action = struct + let%component make ?(class_ : string option) ~(children : Jsx.element) () = +
+ (S.get children) +
+ [@@element div] +end + +module Item = struct + type state = { + is_selected : bool S.accessor; + is_disabled : bool S.accessor; + is_hovered : bool S.accessor; + is_pressed : bool S.accessor; + is_focused : bool S.accessor; + is_focus_visible : bool S.accessor; + selection_mode : [ `none | `single | `multiple ] S.accessor; + } + + let%component make ?(id : string option) ?(text_value : string option) + ?(is_disabled : bool option) ?(href : string option) + ?(class_ : string option) + ?ref:(given_ref : (Dom.htmlDivElement -> unit) option) + ~(children : state Jsx.children) + ?(as_ : + (Solidtype.Html.Div.props -> state -> Solidtype.Jsx.element) option) () + = + let h = Headless.Context.use () in + let variant = Variant.use () in + let key = + match S.untrack (fun () -> S.get id) with + | Some k -> k + | None -> S.create_unique_id () + in + let disabled () = + Option.value (S.get is_disabled) ~default:false || h.is_disabled key + in + let selected () = h.is_selected key in + let i = Interaction.create ~disabled:(fun () -> disabled ()) () in + let state () = + { + is_selected = S.accessor (fun () -> selected ()); + is_disabled = S.accessor (fun () -> disabled ()); + is_hovered = S.accessor (fun () -> Interaction.hovered i); + is_pressed = S.accessor (fun () -> Interaction.pressed i); + is_focused = S.accessor (fun () -> Interaction.focused i); + is_focus_visible = S.accessor (fun () -> Interaction.focus_visible i); + selection_mode = h.selection_mode; + } + in + (* A checkbox stands for the item's selection while it can be selected, + as React Aria's selection checkbox does. *) + let checkbox = + { + Checkbox.selected = S.accessor (fun () -> selected ()); + indeterminate = S.accessor (fun () -> false); + set = + (fun now -> + if not (Bool.equal now (selected ())) then h.toggle_selection key); + disabled = S.accessor (fun () -> disabled ()); + } + in + + ignore (given_ref e : unit option); + Interaction.watch i e) + class_=(after "list-view__item" (S.get class_)) + data_slot="list-view-item" + data_selected=(Jsx.flag (selected ())) + data_disabled=(Jsx.flag (disabled ())) + data_hovered=(Jsx.flag (Interaction.hovered i)) + data_pressed=(Jsx.flag (Interaction.pressed i)) + data_focused=(Jsx.flag (Interaction.focused i)) + data_focus_visible=(Jsx.flag (Interaction.focus_visible i)) + data_selection_mode=(match S.get h.selection_mode with + | `none -> Jsx.flag false + | `single -> Jsx.data "single" + | `multiple -> Jsx.data "multiple") + ?as_=(Option.map (fun f p -> f p (state ())) (S.get as_)) + props=(Props.others props)> + (match S.get h.selection_mode with + | `none -> Jsx.string "" + | `single | `multiple -> +
+ + `secondary + | `secondary -> `primary)> + + + + + +
) + (Jsx.draw (S.get children) (state ())) +
+ [@@element div] +end + +let%component make ?(variant : variant = `primary) + ?(selection_mode : [ `none | `single | `multiple ] = `none) + ?(selection_behavior : [ `toggle | `replace ] option) + ?(selected_keys : string array option) + ?(default_selected_keys : string array option) + ?(on_selection_change : (string array -> unit) option) + ?(disabled_keys : string array option) + ?(disallow_empty_selection : bool option) + ?(on_action : (string -> unit) option) + ?(render_empty_state : (unit -> Jsx.element) option) + ?(virtualized : bool = false) ?(row_height : float = 48.) + ?(class_ : string option) + ?ref:(given_ref : (Dom.htmlDivElement -> unit) option) + ~(children : Jsx.element) () = + let shown_variant = S.accessor (fun () -> S.get variant) in + let given_action = + Option.is_some (Js.Undefined.toOption (action_given props)) + in + let given_empty_state = + Option.is_some (Js.Undefined.toOption (empty_state_given props)) + in + + (let list () = + + ignore (on_selection_change keys : unit option)) + ?disabled_keys=(S.get disabled_keys) + ?disallow_empty_selection=(S.get disallow_empty_selection) + ?on_action=(if given_action then + Some (fun k -> ignore (on_action k : unit option)) + else None) + ?render_empty_state=(if given_empty_state then + Some + (fun () -> +
+ (Option.value (render_empty_state ()) + ~default:Jsx.nothing) +
) + else None) + class_=(after + ("list-view list-view--" + ^ + match S.get variant with + | `primary -> "primary" + | `secondary -> "secondary") + (S.get class_)) + data_slot="list-view" + data_virtualized=(Jsx.flag (S.get virtualized)) + data_layout="stack" + data_orientation="vertical" + ref=(fun e -> ignore (given_ref e : unit option)) + props=(Props.others props)> + (S.get children) +
+ in + (* A long list draws only the rows in view, each [row_height] high. *) + if S.untrack (fun () -> S.get virtualized) then + + (list ()) + + else list ()) +
+[@@element div] diff --git a/heroui/radio_group.mlx b/heroui/radio_group.mlx index e68dcdf..d82981a 100644 --- a/heroui/radio_group.mlx +++ b/heroui/radio_group.mlx @@ -97,6 +97,24 @@ let description : Description.slot = (children ()) +module Kobalte_error = Field.As_span (struct + let component = Kobalte.ErrorMessage.component +end) + +(* An error in a group is the group's: Kobalte's, shown while it is invalid + and describing it. *) +let error : Field_error.slot = + fun classes others children -> + + (children ()) + + (* What its children are drawn of: React Aria's render props for a radio group. *) type state = { @@ -207,7 +225,9 @@ let%component make ?(variant : [ `primary | `secondary ] = `primary) props=(Props.others props)> - (Jsx.draw (S.get children) (state ())) + + (Jsx.draw (S.get children) (state ())) + diff --git a/heroui/rating.css b/heroui/rating.css new file mode 100644 index 0000000..5f77515 --- /dev/null +++ b/heroui/rating.css @@ -0,0 +1,98 @@ +/* Rating, in HeroUI's look, which ships no stylesheet for it: Tailwind on + HeroUI's tokens, written as HeroUI writes its components' CSS, so an + application restyles a part by a rule for its class. */ + +.rating { + --rating-active-color: var(--color-warning); + --rating-inactive-color: var(--color-surface-tertiary); + @apply flex items-center outline-none; + + &[data-focus-visible="true"] { + @apply status-focused; + } + + &[data-disabled="true"] { + @apply status-disabled; + } + + &[data-readonly="true"] { + @apply pointer-events-none; + } +} + +/* Kobalte's control around the items lays nothing out itself. */ +.rating__control { + @apply contents; +} + +.rating--sm { + gap: 4px; +} + +.rating--md { + gap: 5px; +} + +.rating--lg { + gap: 8px; +} + +.rating__item { + @apply relative flex cursor-(--cursor-interactive) items-center justify-center outline-none transition-transform duration-150 motion-reduce:transition-none; + -webkit-tap-highlight-color: transparent; + + &[data-focus-visible="true"] { + @apply status-focused rounded-[calc(var(--radius)*0.5)]; + } + + &[aria-disabled="true"] { + @apply status-disabled; + } + + &[data-pressed="true"]:not([data-readonly="true"]) { + @apply scale-80; + } + + &[data-readonly="true"] { + @apply pointer-events-none cursor-default; + } +} + +.rating__icon { + @apply relative flex items-center justify-center transition-colors duration-100 ease-out motion-reduce:transition-none; + color: var(--rating-inactive-color); + + & svg { + @apply size-full; + } + + &[data-active="true"] { + color: var(--rating-active-color); + } +} + +/* An item a fractional value fills in part, as far as the fraction goes. */ +.rating__icon-partial { + @apply absolute inset-y-0 start-0 flex items-center overflow-hidden; + width: var(--rating-partial); + color: var(--rating-active-color); + + & svg { + @apply shrink-0; + } +} + +.rating__item--sm .rating__icon, +.rating__item--sm .rating__icon-partial svg { + @apply size-4; +} + +.rating__item--md .rating__icon, +.rating__item--md .rating__icon-partial svg { + @apply size-5; +} + +.rating__item--lg .rating__icon, +.rating__item--lg .rating__icon-partial svg { + @apply size-7; +} diff --git a/heroui/rating.mli b/heroui/rating.mli new file mode 100644 index 0000000..bf40a74 --- /dev/null +++ b/heroui/rating.mli @@ -0,0 +1,90 @@ +(** A rating, in HeroUI's look, which ships no stylesheet for it: Kobalte's + [Rating], a radio group of items, each a star or the icon given, chosen by a + press or the arrow keys, the items under the pointer previewed as it moves. + Read only, its value may be a fraction, 3.7, the next item filled as far as + the fraction goes. Its look is a stylesheet, [rating.css], in the + [components] layer, rules for its classes. + + Its page, with its examples: + [$(opam var solidtype:doc)/pages/heroui/rating.md]. + + {[ + + + + + + ]} + + A part is used inside a [Rating]: elsewhere it raises [Invalid_argument] as + it is made. *) + +module S := Solidtype.Solid +module Jsx := Solidtype.Jsx + +type size = [ `sm | `md | `lg ] + +(** An item: Kobalte's [Rating.Item], a + [