From 43cda3c3dea99086bd0ff973bf153a89a1cbc764 Mon Sep 17 00:00:00 2001 From: Roman Zaiev Date: Fri, 20 Nov 2026 19:35:03 +0000 Subject: [PATCH] Release 0.12.0: a data grid, overlays on top, docs for agents An application listing records, a CRM's above all, needs a grid drawn from data: rows given as an array, columns as definitions, sorted in the browser or by the server, columns pinned to a side, a header kept in view, rows dragged to a new place. solidtype had only the Table's parts. Behaviour goes where a component Kobalte lacks keeps it, in the headless Table, and the grid's model is plain functions any design system's grid can draw; HeroUI's draws it on the Table port, its look a stylesheet of its own. A cell's story points step with a number stepper, a number field in HeroUI's look whose digits roll as Number Flow's do, sharing the field's value, range and form rather than copying them. Building them found bugs, each fixed with a test: keys typed in a cell's field went to the rows, a menu in a cell closed as it opened because a function child was drawn where its parent read it, Kobalte replaced a number input's key handlers with a caller's, a number field named only by aria-label left its input unnamed, and a resizable table prerendered on the server laid every column out at no width. A popover, a menu, a select's list and a tooltip were drawn under any element the page stacks, a virtualized table's sticky header among them, since Kobalte copies its content's z-index, which HeroUI's styles leave to React Aria. Every overlay is now drawn in the browser's top layer, the toasts kept above them all. Kobalte's portals take a ref, which breaks the types of SegmentedControl's. An agent building on solidtype hand-rolled what solidtype-heroui has, since an installed package carried no pages. Each package now installs the documentation for a user's agent, written by starlight-theme-hypha from the site's pages, with a skill that sends an agent to it. --- AGENTS.md | 50 +- CHANGES.md | 96 + Makefile | 14 +- README.md | 34 +- agents/llms.txt | 186 ++ agents/pages/heroui.md | 116 ++ agents/pages/heroui/accordion.md | 707 +++++++ agents/pages/heroui/alert-dialog.md | 1198 +++++++++++ agents/pages/heroui/alert.md | 183 ++ agents/pages/heroui/autocomplete.md | 1661 ++++++++++++++++ agents/pages/heroui/avatar-group.md | 479 +++++ agents/pages/heroui/avatar.md | 402 ++++ agents/pages/heroui/badge.md | 338 ++++ agents/pages/heroui/breadcrumbs.md | 210 ++ agents/pages/heroui/button-group.md | 504 +++++ agents/pages/heroui/button.md | 259 +++ agents/pages/heroui/card.md | 549 +++++ agents/pages/heroui/checkbox-group.md | 211 ++ agents/pages/heroui/checkbox.md | 523 +++++ agents/pages/heroui/chip.md | 266 +++ agents/pages/heroui/close-button.md | 132 ++ agents/pages/heroui/color-area.md | 322 +++ agents/pages/heroui/color-field.md | 651 ++++++ agents/pages/heroui/color-picker.md | 514 +++++ agents/pages/heroui/color-slider.md | 361 ++++ agents/pages/heroui/color-swatch-picker.md | 391 ++++ agents/pages/heroui/color-swatch.md | 202 ++ agents/pages/heroui/combo-box.md | 1507 ++++++++++++++ agents/pages/heroui/composition.md | 164 ++ agents/pages/heroui/coverage.md | 99 + agents/pages/heroui/data-grid.md | 1533 ++++++++++++++ agents/pages/heroui/description.md | 78 + agents/pages/heroui/disclosure-group.md | 287 +++ agents/pages/heroui/disclosure.md | 204 ++ agents/pages/heroui/drawer.md | 639 ++++++ agents/pages/heroui/dropdown.md | 1167 +++++++++++ agents/pages/heroui/empty-state.md | 32 + agents/pages/heroui/error-message.md | 109 + agents/pages/heroui/field-error.md | 92 + agents/pages/heroui/fieldset.md | 221 +++ agents/pages/heroui/form.md | 435 ++++ agents/pages/heroui/input-group.md | 762 +++++++ agents/pages/heroui/input.md | 128 ++ agents/pages/heroui/kbd.md | 289 +++ agents/pages/heroui/label.md | 107 + agents/pages/heroui/link.md | 233 +++ agents/pages/heroui/list-box.md | 737 +++++++ agents/pages/heroui/meter.md | 197 ++ agents/pages/heroui/modal.md | 1226 ++++++++++++ agents/pages/heroui/number-field.md | 778 ++++++++ agents/pages/heroui/number-stepper.md | 431 ++++ agents/pages/heroui/pagination.md | 634 ++++++ agents/pages/heroui/popover.md | 367 ++++ agents/pages/heroui/progress-bar.md | 216 ++ agents/pages/heroui/progress-circle.md | 227 +++ agents/pages/heroui/radio-group.md | 493 +++++ agents/pages/heroui/scroll-shadow.md | 438 ++++ agents/pages/heroui/search-field.md | 660 ++++++ agents/pages/heroui/segment.md | 303 +++ agents/pages/heroui/select.md | 1255 ++++++++++++ agents/pages/heroui/separator.md | 223 +++ agents/pages/heroui/skeleton.md | 285 +++ agents/pages/heroui/slider.md | 261 +++ agents/pages/heroui/spinner.md | 178 ++ agents/pages/heroui/styling.md | 177 ++ agents/pages/heroui/surface.md | 186 ++ agents/pages/heroui/switch.md | 350 ++++ agents/pages/heroui/table.md | 1768 +++++++++++++++++ agents/pages/heroui/tabs.md | 585 ++++++ agents/pages/heroui/tag-group.md | 635 ++++++ agents/pages/heroui/text-area.md | 87 + agents/pages/heroui/text-field.md | 366 ++++ agents/pages/heroui/text-shimmer.md | 45 + agents/pages/heroui/theming.md | 213 ++ agents/pages/heroui/time-field.md | 715 +++++++ agents/pages/heroui/toast.md | 873 ++++++++ agents/pages/heroui/toggle-button-group.md | 474 +++++ agents/pages/heroui/toggle-button.md | 245 +++ agents/pages/heroui/tooltip.md | 322 +++ agents/pages/heroui/trend-chip.md | 179 ++ agents/pages/heroui/typography.md | 317 +++ agents/pages/index.md | 150 ++ agents/pages/kobalte.md | 95 + agents/pages/kobalte/binding.md | 127 ++ agents/pages/kobalte/headless.md | 361 ++++ agents/pages/kobalte/usage.md | 248 +++ agents/pages/reference.md | 107 + agents/pages/rhp.md | 86 + agents/pages/rhp/area.md | 78 + agents/pages/rhp/bar.md | 77 + agents/pages/rhp/cell.md | 68 + agents/pages/rhp/chart.md | 172 ++ agents/pages/rhp/dot.md | 71 + agents/pages/rhp/gallery.md | 975 +++++++++ agents/pages/rhp/helpers.md | 257 +++ agents/pages/rhp/label.md | 74 + agents/pages/rhp/line.md | 82 + agents/pages/rhp/many-dots.md | 228 +++ agents/pages/rhp/place.md | 69 + agents/pages/rhp/plot.md | 207 ++ agents/pages/rhp/poster.md | 66 + agents/pages/rhp/scale.md | 101 + agents/pages/rhp/slat.md | 115 ++ agents/pages/rhp/theme.md | 71 + agents/pages/rhp/tick.md | 62 + agents/pages/solid.md | 122 ++ agents/pages/solid/async.md | 75 + agents/pages/solid/components.md | 245 +++ agents/pages/solid/control-flow.md | 149 ++ agents/pages/solid/reactivity.md | 132 ++ agents/pages/solid/rendering.md | 64 + agents/pages/solid/state.md | 105 + agents/pages/start/astro.md | 261 +++ agents/pages/start/conventions.md | 128 ++ agents/pages/start/how-it-works.md | 224 +++ agents/pages/start/melange.md | 117 ++ agents/pages/start/ocaml-over-typescript.md | 237 +++ agents/pages/start/vite.md | 109 + agents/skills/solidtype/SKILL.md | 18 + bun.lock | 34 +- docs/agents.md | 45 + docs/astro.config.mjs | 27 +- docs/dune | 4 +- docs/islands/data_grid_async_loading.mlx | 53 + docs/islands/data_grid_column_resizing.mlx | 76 + docs/islands/data_grid_drag_and_drop.mlx | 60 + docs/islands/data_grid_editable_cells.mlx | 184 ++ docs/islands/data_grid_empty_state.mlx | 42 + docs/islands/data_grid_pinned_columns.mlx | 160 ++ docs/islands/data_grid_servers.mlx | 163 ++ docs/islands/data_grid_sorting.mlx | 77 + docs/islands/data_grid_team_members.mlx | 302 +++ docs/islands/data_grid_usage.mlx | 160 ++ docs/islands/data_grid_virtualization.mlx | 40 + docs/islands/number_stepper_controlled.mlx | 21 + docs/islands/number_stepper_custom_icons.mlx | 20 + docs/islands/number_stepper_custom_value.mlx | 17 + docs/islands/number_stepper_disabled.mlx | 10 + docs/islands/number_stepper_guest_picker.mlx | 39 + docs/islands/number_stepper_min_max.mlx | 21 + .../number_stepper_reversed_layout.mlx | 10 + docs/islands/number_stepper_sizes.mlx | 19 + docs/islands/number_stepper_usage.mlx | 10 + .../number_stepper_with_custom_buttons.mlx | 39 + .../number_stepper_with_format_options.mlx | 27 + docs/islands/number_stepper_with_label.mlx | 18 + docs/islands/number_stepper_with_step.mlx | 23 + docs/islands/table_drag_and_drop.mlx | 52 + docs/package.json | 2 +- docs/public/llms.txt | 190 -- docs/src/content/docs/heroui/button.mdx | 2 +- docs/src/content/docs/heroui/coverage.mdx | 6 +- docs/src/content/docs/heroui/data-grid.mdx | 230 +++ .../content/docs/heroui/number-stepper.mdx | 173 ++ docs/src/content/docs/heroui/table.mdx | 19 + docs/src/content/docs/heroui/theming.mdx | 3 +- docs/src/content/docs/index.mdx | 2 +- docs/src/content/docs/kobalte/headless.mdx | 55 +- docs/src/content/docs/reference.md | 1 + .../docs/start/ocaml-over-typescript.mdx | 2 +- dune | 59 + example/README.md | 6 +- example/src/app.mlx | 59 +- example/src/board.css | 6 +- example/src/task_list.mlx | 63 + example/test/board_test.mlx | 22 + example/test/testing.ml | 5 + generate/binding.ts | 18 +- generate/rhp.ts | 15 +- headless/color_channel_field.mlx | 6 +- headless/data_grid.ml | 90 + headless/data_grid.mli | 86 + headless/number_field.mli | 24 +- headless/number_field.mlx | 47 +- headless/table.mli | 115 +- headless/table.mlx | 1155 ++++++++++- headless/top_layer.ml | 54 + headless/top_layer.mli | 35 + heroui/accordion.mli | 3 + heroui/alert.mli | 3 + heroui/alert_dialog.mli | 3 + heroui/autocomplete.mli | 3 + heroui/autocomplete.mlx | 2 +- heroui/avatar.mli | 3 + heroui/avatar_group.mli | 3 + heroui/badge.mli | 3 + heroui/breadcrumbs.mli | 3 + heroui/button.mli | 74 +- heroui/button.mlx | 141 +- heroui/button_group.mli | 3 + heroui/card.mli | 3 + heroui/checkbox.mli | 3 + heroui/checkbox_group.mli | 3 + heroui/chip.mli | 3 + heroui/close_button.mli | 3 + heroui/color_area.mli | 3 + heroui/color_field.mli | 3 + heroui/color_picker.mli | 3 + heroui/color_picker.mlx | 2 +- heroui/color_slider.mli | 3 + heroui/color_swatch.mli | 3 + heroui/color_swatch_picker.mli | 3 + heroui/combo_box.mli | 3 + heroui/combo_box.mlx | 2 +- heroui/data-grid.css | 77 + heroui/data_grid.mli | 172 ++ heroui/data_grid.mlx | 399 ++++ heroui/description.mli | 3 + heroui/dialog_frame.mlx | 5 +- heroui/disclosure.mli | 3 + heroui/disclosure_group.mli | 3 + heroui/drawer.mli | 3 + heroui/dropdown.mli | 3 + heroui/dropdown.mlx | 4 +- heroui/empty_state.mli | 3 + heroui/error_message.mli | 3 + heroui/extras.css | 3 + heroui/field_error.mli | 3 + heroui/fieldset.mli | 3 + heroui/form.mli | 3 + heroui/input.mli | 3 + heroui/input_group.mli | 3 + heroui/kbd.mli | 3 + heroui/label.mli | 3 + heroui/link.mli | 3 + heroui/list_box.mli | 3 + heroui/meter.mli | 3 + heroui/modal.mli | 3 + heroui/number-stepper.css | 210 ++ heroui/number_field.mli | 48 + heroui/number_field.mlx | 174 +- heroui/number_stepper.mli | 126 ++ heroui/number_stepper.mlx | 413 ++++ heroui/pagination.mli | 3 + heroui/popover.mli | 3 + heroui/popover.mlx | 2 +- heroui/progress_bar.mli | 3 + heroui/progress_circle.mli | 3 + heroui/radio_group.mli | 3 + heroui/scroll_shadow.mli | 3 + heroui/search_field.mli | 3 + heroui/segment.mli | 3 + heroui/select.mli | 3 + heroui/select.mlx | 2 +- heroui/separator.mli | 3 + heroui/skeleton.mli | 3 + heroui/slider.mli | 3 + heroui/spinner.mli | 3 + heroui/surface.mli | 3 + heroui/switch.mli | 3 + heroui/table.css | 161 ++ heroui/table.mli | 43 +- heroui/table.mlx | 51 +- heroui/tabs.mli | 3 + heroui/tag_group.mli | 3 + heroui/text_area.mli | 3 + heroui/text_field.mli | 3 + heroui/text_shimmer.mli | 3 + heroui/time_field.mli | 3 + heroui/toast.mli | 3 + heroui/toast.mlx | 85 +- heroui/toggle_button.mli | 5 +- heroui/toggle_button_group.mli | 5 +- heroui/tooltip.mli | 3 + heroui/tooltip.mlx | 2 +- heroui/trend_chip.mli | 3 + heroui/typography.mli | 3 + kobalte/solidtype_kobalte.ml | 14 +- kobalte/solidtype_kobalte.mli | 14 +- kobalte/types.ml | 12 +- kobalte/types.mli | 12 +- rhp/helpers.mli | 3 + rhp/many_dots.mli | 3 + rhp/plot.mli | 2 + rhp/scale.mli | 2 + rhp/slat.mli | 2 + rhp/solidtype_rhp.ml | 31 +- rhp/solidtype_rhp.mli | 31 +- src/jsx.ml | 9 +- src/jsx.mli | 4 +- test/dune | 6 +- test/headless/data_grid_test.ml | 95 + test/headless/kobalte_fixes_test.mlx | 89 + test/headless/table_controls_test.mlx | 151 ++ test/headless/table_pinned_test.mlx | 234 +++ test/headless/table_reorder_test.mlx | 292 +++ test/headless/table_test.mlx | 55 + test/headless/top_layer_test.mlx | 61 + test/heroui/attributes_test.mlx | 20 + test/heroui/data_grid_test.mlx | 320 +++ test/heroui/number_field_test.mlx | 125 ++ test/heroui/number_stepper_test.mlx | 243 +++ test/heroui/table_reorder_test.mlx | 137 ++ test/heroui/top_layer_test.mlx | 111 ++ test/heroui/twins/NumberField.tsx | 41 +- test/heroui/twins/TableReorder.tsx | 65 + test/jsdom.ts | 54 + test/server/table_layout_test.mlx | 82 + test/test_docs.ml | 48 - vite-plugin/src/rewrite.ts | 20 +- vite-plugin/test/rewrite.test.ts | 16 + 301 files changed, 49583 insertions(+), 548 deletions(-) create mode 100644 agents/llms.txt create mode 100644 agents/pages/heroui.md create mode 100644 agents/pages/heroui/accordion.md create mode 100644 agents/pages/heroui/alert-dialog.md create mode 100644 agents/pages/heroui/alert.md create mode 100644 agents/pages/heroui/autocomplete.md create mode 100644 agents/pages/heroui/avatar-group.md create mode 100644 agents/pages/heroui/avatar.md create mode 100644 agents/pages/heroui/badge.md create mode 100644 agents/pages/heroui/breadcrumbs.md create mode 100644 agents/pages/heroui/button-group.md create mode 100644 agents/pages/heroui/button.md create mode 100644 agents/pages/heroui/card.md create mode 100644 agents/pages/heroui/checkbox-group.md create mode 100644 agents/pages/heroui/checkbox.md create mode 100644 agents/pages/heroui/chip.md create mode 100644 agents/pages/heroui/close-button.md create mode 100644 agents/pages/heroui/color-area.md create mode 100644 agents/pages/heroui/color-field.md create mode 100644 agents/pages/heroui/color-picker.md create mode 100644 agents/pages/heroui/color-slider.md create mode 100644 agents/pages/heroui/color-swatch-picker.md create mode 100644 agents/pages/heroui/color-swatch.md create mode 100644 agents/pages/heroui/combo-box.md create mode 100644 agents/pages/heroui/composition.md create mode 100644 agents/pages/heroui/coverage.md create mode 100644 agents/pages/heroui/data-grid.md create mode 100644 agents/pages/heroui/description.md create mode 100644 agents/pages/heroui/disclosure-group.md create mode 100644 agents/pages/heroui/disclosure.md create mode 100644 agents/pages/heroui/drawer.md create mode 100644 agents/pages/heroui/dropdown.md create mode 100644 agents/pages/heroui/empty-state.md create mode 100644 agents/pages/heroui/error-message.md create mode 100644 agents/pages/heroui/field-error.md create mode 100644 agents/pages/heroui/fieldset.md create mode 100644 agents/pages/heroui/form.md create mode 100644 agents/pages/heroui/input-group.md create mode 100644 agents/pages/heroui/input.md create mode 100644 agents/pages/heroui/kbd.md create mode 100644 agents/pages/heroui/label.md create mode 100644 agents/pages/heroui/link.md create mode 100644 agents/pages/heroui/list-box.md create mode 100644 agents/pages/heroui/meter.md create mode 100644 agents/pages/heroui/modal.md create mode 100644 agents/pages/heroui/number-field.md create mode 100644 agents/pages/heroui/number-stepper.md create mode 100644 agents/pages/heroui/pagination.md create mode 100644 agents/pages/heroui/popover.md create mode 100644 agents/pages/heroui/progress-bar.md create mode 100644 agents/pages/heroui/progress-circle.md create mode 100644 agents/pages/heroui/radio-group.md create mode 100644 agents/pages/heroui/scroll-shadow.md create mode 100644 agents/pages/heroui/search-field.md create mode 100644 agents/pages/heroui/segment.md create mode 100644 agents/pages/heroui/select.md create mode 100644 agents/pages/heroui/separator.md create mode 100644 agents/pages/heroui/skeleton.md create mode 100644 agents/pages/heroui/slider.md create mode 100644 agents/pages/heroui/spinner.md create mode 100644 agents/pages/heroui/styling.md create mode 100644 agents/pages/heroui/surface.md create mode 100644 agents/pages/heroui/switch.md create mode 100644 agents/pages/heroui/table.md create mode 100644 agents/pages/heroui/tabs.md create mode 100644 agents/pages/heroui/tag-group.md create mode 100644 agents/pages/heroui/text-area.md create mode 100644 agents/pages/heroui/text-field.md create mode 100644 agents/pages/heroui/text-shimmer.md create mode 100644 agents/pages/heroui/theming.md create mode 100644 agents/pages/heroui/time-field.md create mode 100644 agents/pages/heroui/toast.md create mode 100644 agents/pages/heroui/toggle-button-group.md create mode 100644 agents/pages/heroui/toggle-button.md create mode 100644 agents/pages/heroui/tooltip.md create mode 100644 agents/pages/heroui/trend-chip.md create mode 100644 agents/pages/heroui/typography.md create mode 100644 agents/pages/index.md create mode 100644 agents/pages/kobalte.md create mode 100644 agents/pages/kobalte/binding.md create mode 100644 agents/pages/kobalte/headless.md create mode 100644 agents/pages/kobalte/usage.md create mode 100644 agents/pages/reference.md create mode 100644 agents/pages/rhp.md create mode 100644 agents/pages/rhp/area.md create mode 100644 agents/pages/rhp/bar.md create mode 100644 agents/pages/rhp/cell.md create mode 100644 agents/pages/rhp/chart.md create mode 100644 agents/pages/rhp/dot.md create mode 100644 agents/pages/rhp/gallery.md create mode 100644 agents/pages/rhp/helpers.md create mode 100644 agents/pages/rhp/label.md create mode 100644 agents/pages/rhp/line.md create mode 100644 agents/pages/rhp/many-dots.md create mode 100644 agents/pages/rhp/place.md create mode 100644 agents/pages/rhp/plot.md create mode 100644 agents/pages/rhp/poster.md create mode 100644 agents/pages/rhp/scale.md create mode 100644 agents/pages/rhp/slat.md create mode 100644 agents/pages/rhp/theme.md create mode 100644 agents/pages/rhp/tick.md create mode 100644 agents/pages/solid.md create mode 100644 agents/pages/solid/async.md create mode 100644 agents/pages/solid/components.md create mode 100644 agents/pages/solid/control-flow.md create mode 100644 agents/pages/solid/reactivity.md create mode 100644 agents/pages/solid/rendering.md create mode 100644 agents/pages/solid/state.md create mode 100644 agents/pages/start/astro.md create mode 100644 agents/pages/start/conventions.md create mode 100644 agents/pages/start/how-it-works.md create mode 100644 agents/pages/start/melange.md create mode 100644 agents/pages/start/ocaml-over-typescript.md create mode 100644 agents/pages/start/vite.md create mode 100644 agents/skills/solidtype/SKILL.md create mode 100644 docs/agents.md create mode 100644 docs/islands/data_grid_async_loading.mlx create mode 100644 docs/islands/data_grid_column_resizing.mlx create mode 100644 docs/islands/data_grid_drag_and_drop.mlx create mode 100644 docs/islands/data_grid_editable_cells.mlx create mode 100644 docs/islands/data_grid_empty_state.mlx create mode 100644 docs/islands/data_grid_pinned_columns.mlx create mode 100644 docs/islands/data_grid_servers.mlx create mode 100644 docs/islands/data_grid_sorting.mlx create mode 100644 docs/islands/data_grid_team_members.mlx create mode 100644 docs/islands/data_grid_usage.mlx create mode 100644 docs/islands/data_grid_virtualization.mlx create mode 100644 docs/islands/number_stepper_controlled.mlx create mode 100644 docs/islands/number_stepper_custom_icons.mlx create mode 100644 docs/islands/number_stepper_custom_value.mlx create mode 100644 docs/islands/number_stepper_disabled.mlx create mode 100644 docs/islands/number_stepper_guest_picker.mlx create mode 100644 docs/islands/number_stepper_min_max.mlx create mode 100644 docs/islands/number_stepper_reversed_layout.mlx create mode 100644 docs/islands/number_stepper_sizes.mlx create mode 100644 docs/islands/number_stepper_usage.mlx create mode 100644 docs/islands/number_stepper_with_custom_buttons.mlx create mode 100644 docs/islands/number_stepper_with_format_options.mlx create mode 100644 docs/islands/number_stepper_with_label.mlx create mode 100644 docs/islands/number_stepper_with_step.mlx create mode 100644 docs/islands/table_drag_and_drop.mlx delete mode 100644 docs/public/llms.txt create mode 100644 docs/src/content/docs/heroui/data-grid.mdx create mode 100644 docs/src/content/docs/heroui/number-stepper.mdx create mode 100644 example/src/task_list.mlx create mode 100644 headless/data_grid.ml create mode 100644 headless/data_grid.mli create mode 100644 headless/top_layer.ml create mode 100644 headless/top_layer.mli create mode 100644 heroui/data-grid.css create mode 100644 heroui/data_grid.mli create mode 100644 heroui/data_grid.mlx create mode 100644 heroui/number-stepper.css create mode 100644 heroui/number_stepper.mli create mode 100644 heroui/number_stepper.mlx create mode 100644 heroui/table.css create mode 100644 test/headless/data_grid_test.ml create mode 100644 test/headless/table_controls_test.mlx create mode 100644 test/headless/table_pinned_test.mlx create mode 100644 test/headless/table_reorder_test.mlx create mode 100644 test/headless/top_layer_test.mlx create mode 100644 test/heroui/data_grid_test.mlx create mode 100644 test/heroui/number_stepper_test.mlx create mode 100644 test/heroui/table_reorder_test.mlx create mode 100644 test/heroui/top_layer_test.mlx create mode 100644 test/heroui/twins/TableReorder.tsx create mode 100644 test/server/table_layout_test.mlx diff --git a/AGENTS.md b/AGENTS.md index 1047f8de..ec523063 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -23,7 +23,8 @@ make setup # once: the switch solidtype, all dependencies, and make test # the ppx's lowering, the plugin's rewrite, the # libraries' tests and the example's make lint # formatting, the plugin's and the generators' types, - # litany, the release build, and the generated bindings + # litany, the release build, the generated bindings, and + # agents/ against the pages make fmt # format in place make example # the board, built by Vite into _build/example-dist, and # its Astro page, into _build/example-astro @@ -34,6 +35,7 @@ make docs # the documentation site, odoc's reference copied into # as .github/workflows/docs.yml publishes it from main make docs-serve # the documentation site built, served on DOCS_PORT with # search +make agents # agents/ written from the documentation's pages make release VERSION=1.2.3 # tag and release ``` @@ -65,10 +67,14 @@ headless/ solidtype-headless: the components Kobalte lacks, one taken and passed on; and Kobalte's own where they need a fix, each fixed part Kobalte's beneath, the others Kobalte's as they are + data_grid a data grid's model, whoever dresses it: its columns, + its rows sorted, and reordered by a drop table a grid of rows and cells: Kobalte's list of rows, their selection, the keys through their cells, a row that loads more, columns laid out and resized as - React Stately lays them out, and rows that hold rows, + React Stately lays them out, columns pinned to a side + and a header kept in view, rows reordered by a drag or + the keys, and rows that hold rows, each row's cells and rows tokens it draws once read color_picker one colour its parts share, as React Aria's: the colour components below read it, given no value of their own; @@ -81,6 +87,9 @@ headless/ solidtype-headless: the components Kobalte lacks, one with a wrap, removed by a button or the keys and the focus moved on load_more_sentinel what asks a list for more as its end comes into view + top_layer the browser's top layer: an overlay drawn above the + page and every overlay opened before it, and one + kept above those opened after virtualizer React Aria's Virtualizer: a collection draws the entries in view, each placed by a layout color_swatch Kobalte's, a colour less than opaque one a browser @@ -131,9 +140,15 @@ heroui/ solidtype-heroui: HeroUI's components ported onto selection_indicator what a tab's and a segment's indicator share: drawn in the selected item, it starts where the last one was - segment trend_chip text_shimmer + segment trend_chip text_shimmer number_stepper components HeroUI ships no stylesheet for, made as every port is: their look a stylesheet each + table.css what HeroUI's table stylesheet does not draw: a column + pinned, a header kept in view, where a dragged row + would land + data_grid a grid of rows given as data and columns as + definitions, drawn on the Table port, its look + data-grid.css extras.css those stylesheets in the components layer, which the plugin's tarball ships as heroui-extras.css docs/ the documentation, a Starlight site in Hypha's look, @@ -166,13 +181,23 @@ docs/ the documentation, a Starlight site in Hypha's look, the packages, and a link to each module's odoc page, which `make docs` copies into public/reference/, ignored, since Starlight serves public/ as it is - public/llms.txt the site's index for a model, written by hand: what - solidtype is, how it is written, every page; amended - with each page added or changed + agents.md what an agent knows before any page -- the packages + and how solidtype is written -- which the theme puts + at the head of llms.txt; each group's note, and the + skill's description and the parts agents have been + seen writing by hand instead, are in astro.config.mjs src/pages/demo/ the Astro page's demo, pages of Astro's own outside Starlight: a route per tea, its islands given props, under a basket the client router keeps; the page imports their sources as @demo/?raw +agents/ the documentation for a user's agent, generated by + starlight-theme-hypha from the pages, `make agents`: + llms.txt, the catalogue; pages/, each page as + Markdown, its examples written in; skills/solidtype/, + the skill that sends an agent there; installed by the + root dune into $(opam var solidtype:doc), and llms.txt + alone, its links to solidtype's pages, into every other + package's doc/ prds/ the PRDs of work being decided and built, and which document owns each kind of fact once it lands generate/ what writes the generated bindings from Solid's, @@ -275,8 +300,8 @@ test/internationalized_date/ test/ppx/ what the ppx writes for each JSX form test/test_docs.ml every island of docs/islands on some page, or a part of other islands, every rhp page linked to rhp's, every - page in llms.txt, and the plugin a page installs the - newest release's in CHANGES.md + port's to HeroUI's before its usage, and the plugin a + page installs the newest release's in CHANGES.md test/does_not_compile.t each mistake the types refuse, built against the installed library, with the error a user reads @@ -680,6 +705,15 @@ break. `_ Jsx.component`, never a function type, and an OCaml component is `Jsx.component make`. Why: Melange wraps an external function used as a value in a closure, which no JSX tag can name. +- **`agents/` is generated, never edited.** starlight-theme-hypha writes it + from the documentation's pages, `docs/agents.md` and the `agents` options + in `docs/astro.config.mjs`: a page changed is `make agents` run in the + same commit. A module with a page of its own names the page's installed + path, `$(opam var solidtype:doc)/pages/.md`, in its `.mli`'s opening + comment, and `generate/rhp.ts` writes it for rhp's generated components. + Why: a user's agent reads what the release installs, offline, and a page + it reads must be the release's. Test: `make lint` runs `HYPHA_AGENTS=check + astro sync`, which fails on each file that differs from the pages. - **Tests of what runs in a browser are OCaml, run by vitest.** Alcotest does not build for Melange; `melange-jest` reaches the globals vitest shares with Jest. The ppx, native, is tested by its expectations. Why: diff --git a/CHANGES.md b/CHANGES.md index d56b0075..b217508c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,101 @@ # Changes +## 0.12.0 (2026-11-20) + +- HeroUI's `Data_grid`: rows given as data, each known by its `row_id`, and + columns as definitions, `Data_grid.column`, drawn on HeroUI's `Table`. A + column sorts exactly when it is given a `sort`, by a row's text in the + page's order or a comparison, the grid keeping its own sort or drawing the + application's; a cell is given its row as an accessor, so a control in it + keeps its focus as the row is given again. Selection checkboxes, columns + resized, pinned and aligned, a header kept in view, rows dragged to a new + place and told with every row, an empty state, a footer, loading more and + virtualization. Its look is `heroui/data-grid.css`, in the plugin's + `heroui-extras.css`. `Solidtype_headless.Data_grid` is its model, for + another design system's grid. +- HeroUI's `Table` takes `pinned` on a `Table.Column` and `sticky_header` on + its `Table.Content`, drawn by the plugin's `heroui-extras.css`; a pinned + cell at a corner of the body fills what lies outside its curve, so nothing + scrolling beneath shows there. +- The headless `Table` reorders its rows, given `on_reorder`: a + `Table.Drag_handle` grabs its row by Enter or Space, the arrows move it + among the rows of its parent and Enter drops it, Escape lets it go, and a + pointer drags it; each step is told to a reader in React Aria's words, a + selected row is dragged with the others selected, and `on_reorder` is + given the rows moved and the row they land beside. A pointer's drag leaves + the row in its place, `data-dragging`, and draws a copy of it that follows + the pointer, `data-drag-preview`. HeroUI's `Table` does so by a `Button` of + `` slot=`drag ``, its dragged row dimmed, its copy lifted, and a line in the + accent where it would land. +- The headless `Table` pins a column to its start or its end, `pinned=`start` + on its `Table.Column`: its header and cells stay in view as the others + scroll beneath them, each beside the columns pinned there before it, the + last of each side `data-pinned-edge`, and the table + `data-pinned-start-detached` and `data-pinned-end-detached` while content + passes beneath them; virtualized too. `sticky_header=true` on its + `Table.Root` keeps the columns' headers at the top of what scrolls it. +- A key pressed in a control inside the headless `Table`'s cell, and so the + HeroUI `Table`'s, is the control's: a field keeps every key, where the + arrows moved focus to another row, a letter could find one, Space selected + it and Tab left the table; a key a control handles is its own; and the + arrows, Home and End from a button move from its cell. +- The headless `Table`, and so the HeroUI `Table`, keeps a resizable + table's layout and its columns' widths beside a `style` given to its + `Table.Root` or a `Table.Column`, which replaced them. +- A resizable table prerendered on the server lays its columns out as they + ask, where every column was 0 pixels wide: the server computes + a memo once, before the columns had registered, and hydration never wrote + the widths again. +- A letter typed on the headless `Table`'s row, and so the HeroUI + `Table`'s, moves to the next row whose text starts with what was typed, + as its interface said; it found none, since each row's text was taken to + be its key. +- HeroUI's `Number_stepper`: a `Number_field` drawn as two round buttons + around its value, whose digits roll to each new number the way it moved, + up as it rises and down as it falls, in sizes; its + value, range, step, format, form and keys are the field's, its input out of + sight in the page's order until text is typed in it. Its look is + `heroui/number-stepper.css`, in the plugin's `heroui-extras.css`. A + component built on a number field draws it in its own classes by + `Number_field.Look`, and reads its value by `Number_field.Shown`. +- A HeroUI `Button` given `` slot=`increment `` or `` slot=`decrement `` steps + the `Number_field` or `Number_stepper` it is in, as React Aria's slots do. +- HeroUI's `Number_field` given `aria_label` and no `Label` names its input + by it, and its buttons "Increase" and "Decrease" followed by it, as React + Aria's; its input was unnamed and its buttons named by a label that was not + there. +- A caller's `on_key_down`, `on_focus` and `on_blur` on the headless + `Number_field`'s and `Color_channel_field`'s input are called beside + Kobalte's own, which they replaced, so the arrows no longer stepped it. +- A component's function child drawn by `Jsx.draw` is drawn where Solid + inserts it, so what it reads draws only it again: a menu opened by a button + in a HeroUI `Table`'s cell stays open, where the cell drew its content anew + and closed it. +- A press that begins on a control in the headless `Table`'s cell leaves the + focus where the control puts it, rather than on the cell. +- Every overlay of HeroUI's ports is drawn in the browser's top layer, by + `Solidtype_headless.Top_layer`: above anything the page stacks, a + virtualized table's sticky header among them, and above every overlay + opened before it, the toasts kept above them all. A popover, a menu, a + select's list and a tooltip were drawn under such a header, since Kobalte + copies its content's `z-index`, which HeroUI's styles leave to React Aria. +- A Kobalte part's `ref` is the function Solid calls with its element, of + the element it declares: every portal's, which the binding left out, is + `?ref:(Dom.element -> unit)`, since a portal draws a `
` or a ``. + Breaking: `SegmentedControl`'s root takes `Dom.htmlElement -> unit`, not + an element or a function; the `Types` modules written for a portal's + ref's element, `AlertDialog_Portal_Ref` and the like, are gone. +- `vite-plugin-solidtype` writes a `ref` given by name as a function that + calls it, so a module's function given as an element's `ref`, + `ref=Top_layer.place`, is called with the element, where Solid's compiler + would assign the element to it, an import, and the build failed. +- Each package installs the documentation for a user's agent: `solidtype` + its catalogue, `llms.txt`, every page in Markdown with its examples, and + a skill, `skills/solidtype`, in `$(opam var solidtype:doc)`; every other + package the catalogue, its links reaching those pages. The README's *With + an agent* says how to give an agent the skill, and a module with a page + names the page's installed path in its `.mli`. + ## 0.11.1 (2026-11-16) - The code `ppx_solidtype` writes around a component's tag, the `if false` diff --git a/Makefile b/Makefile index b515656a..9decb42a 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ DOCS_PORT ?= 4321 REFERENCE = solidtype solidtype-kobalte solidtype-headless solidtype-heroui solidtype-rhp solidtype-internationalized-date solidtype-gravity-icons ppx_solidtype odoc.support .DEFAULT_GOAL := help -.PHONY: help setup build test lint fmt example example-serve docs docs-serve generate release +.PHONY: help setup build test lint fmt example example-serve docs docs-serve agents generate release help: ## list targets @grep -hE '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \ @@ -30,8 +30,10 @@ test: build node_modules ## run the tests $(OPAM) dune test --force $(OPAM) bun run test -# Release is the profile opam installs with. -lint: node_modules ## check formatting, types, litany, the release build and bindings +# Release is the profile opam installs with. agents/ is checked from docs/, +# where Astro finds its config, by reading the pages without building the +# site. +lint: node_modules ## check formatting, types, litany, the release build, bindings and agents/ $(OPAM) dune build @all @fmt $(OPAM) dune build --profile release @all $(OPAM) litany check @@ -43,6 +45,7 @@ lint: node_modules ## check formatting, types, litany, the release build and bin $(OPAM) bun generate/rhp.ts --check $(OPAM) bun generate/internationalized_date.ts --check $(OPAM) bun generate/gravity_icons.ts --check + cd docs && HYPHA_AGENTS=check bunx astro sync fmt: ## format the code $(OPAM) dune fmt @@ -74,6 +77,11 @@ docs: build node_modules ## build the documentation site docs-serve: docs ## serve the built documentation site cd docs && bun --bun astro preview --open --port $(DOCS_PORT) +# Each page as Markdown, llms.txt and the skill, from the documentation's +# pages, for the solidtype package to install. +agents: node_modules ## write agents/ from the documentation's pages + cd docs && HYPHA_AGENTS=write bunx astro sync + generate: node_modules ## write the generated bindings $(OPAM) bun generate/html.ts $(OPAM) bun generate/kobalte.ts diff --git a/README.md b/README.md index 98cdc17a..2510247b 100644 --- a/README.md +++ b/README.md @@ -16,23 +16,51 @@ rhp's charts and @internationalized/date's dates included. ```sh opam repo add open-opam https://github.com/open-opam/opam-repository.git -opam install solidtype +opam install solidtype solidtype-heroui +bun add $(opam show solidtype-heroui --field x-npm-depends) ``` ```ocaml module Jsx = Solidtype.Jsx module Solid = Solidtype.Solid +module Button = Solidtype_heroui.Button let make () = let count, set_count = Solid.create_signal 0 in - + ``` Setting up dune and Vite to build it: [Getting Started](https://hyphatech.github.io/solidtype/). +## With an agent + +Each release installs its documentation for an agent with it: `llms.txt`, +every page in Markdown, and a skill that sends the agent there before it +writes code with solidtype. With opam alone, copy the skill into your +project, into `.agents/skills/` for Codex, Cursor and most agents or +`.claude/skills/` for Claude Code: + +```sh +mkdir -p .agents/skills +cp -r $(opam var solidtype:doc)/skills/solidtype .agents/skills/ +``` + +With Node or Bun: + +```sh +npx skills add hyphatech/solidtype +``` + +An agent that reads no skills is told in your project's `AGENTS.md`: + +```md +Before writing code with solidtype, read `$(opam var solidtype:doc)/llms.txt` +and the page of each part the work needs; build from its parts. +``` + ## Licence MIT, copyright Hypha Technologies Ltd. See [LICENSE](LICENSE). diff --git a/agents/llms.txt b/agents/llms.txt new file mode 100644 index 00000000..1bd8758d --- /dev/null +++ b/agents/llms.txt @@ -0,0 +1,186 @@ +# solidtype + +> SolidJS for modern OCaml. + +Solid, typed, for OCaml front ends on SolidJS and Kobalte, compiled by Melange. A component is written in OCaml's JSX (`.mlx`) and reaches the browser as the code Solid's own compiler emits for the same JSX. HeroUI's components are ported onto Kobalte, and rhp's charts are bound. + +A signal given where its value belongs does not compile, and neither does a prop left out, an attribute an element does not take, or a `match` in a `Switch` that misses a case. Solid's, Kobalte's and HeroUI's own documentation stays the reference for what a component does; these pages say how it is written in OCaml. + +## Packages + +- `solidtype`: Solid 1.9 bound whole, for Melange: signals, resources, stores, its components, its renderer, server rendering included. +- `ppx_solidtype`: rewrites the JSX of `.mlx` files into calls Melange compiles. +- `vite-plugin-solidtype`: turns those calls back into JSX for Solid's compiler. It is not on npm: it is the asset `vite-plugin-solidtype-.tgz` of each release at https://github.com/hyphatech/solidtype/releases, at the version of the opam packages. +- `solidtype-kobalte`: Kobalte 0.13 bound whole, generated from its declarations. +- `solidtype-headless`: the components Kobalte lacks, with no style, and Kobalte's own where they need a fix. +- `solidtype-heroui`: HeroUI 3's components, ported onto Kobalte. Their look is `@import "@heroui/styles";` after Tailwind's, and for Segment, TrendChip and TextShimmer, which HeroUI has no styles for, `@import "vite-plugin-solidtype/heroui-extras.css";`. +- `solidtype-rhp`: rhp 2.2's charts. +- `solidtype-internationalized-date`: @internationalized/date, the values HeroUI's date components take. +- `solidtype-gravity-icons`: every icon of Gravity UI, the set HeroUI's examples draw: `ChevronDown` is `Solidtype_gravity_icons.Chevron_down`. It imports nothing from npm; `solidtype-heroui` depends on it and draws its own icons from it. + +The opam packages come from open-opam: `opam repo add open-opam https://github.com/open-opam/opam-repository.git`. Each names the npm packages it imports in its opam field `x-npm-depends`: `bun add $(opam show solidtype-heroui --field x-npm-depends)`. In Vite, `solidtype()` goes before `solid()`. + +## Writing it + +- Every name is snake case, by one rule from the name in Solid's, Kobalte's or HeroUI's documentation: `onClick` is `on_click`, `aria-label` is `aria_label`, `isDisabled` is `is_disabled`; a keyword takes a trailing underscore, `class_`, `type_`. A module keeps its JavaScript name: `Solidtype_kobalte.Switch.Root`, `Solidtype_heroui.Button`. +- In JSX a value is written as itself, and Solid keeps it current. A literal or a name is given as it is; any other expression is read again as what it reads changes, as Solid's compiler makes an expression in JSX a getter: `title=(S.get note)` is `title={note()}`, a child `(Jsx.int (S.get count))` is `{count()}`. What changes is read by `S.get` (a signal, a prop, a part's state). Outside JSX a value that changes is `fun () -> e`, as Solid's own API takes `() => e`; state a component derives for its children is `S.accessor (fun () -> e)`. Nothing but a binding writes `[@u]`. +- A function is a function wherever it is given, `on_close=(fun () -> hide ())`, and one given where a value belongs is refused by its type. +- An optional prop is given as OCaml gives an optional argument: a value, `count=3`, or an option, `?title=label_opt`, `?title=(S.get note)`, absent while `None`. +- What JSX holds is one type, `Jsx.element`, as Solid's `JSX.Element` is: a node, `Jsx.string s`, `Jsx.int n`. A child given by its name or an expression is one, `let icon = in `. +- A function child is written in place as the child, `(fun item _ -> ...)`, or given by its name as `render=f`. +- A component is `let%component make ~(name : string) () = ...`, and reads a prop as a signal is read, `S.get name`; its tag is the module, ``. A root mounted by a page is a plain `let make () = ...`. +- A spread, TSX's `{...props}`, is the attribute `props`; no prop is named `props`. +- A `data-` attribute is a `Jsx.data`: `data_selected=(Jsx.flag (S.get on))`. +- A namespace wraps the value: `on:click={f}` is `on_click=(Jsx.native f)`. +- A part draws another element by `as_`, HeroUI's `render`. + +A page is built from the library's parts, as this counter is from HeroUI's Button: a raw element is written only where no part draws it. + +```ocaml +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Button = Solidtype_heroui.Button + +let make () = + let count, set_count = S.create_signal 0 in + +``` + +## Start here + +- [Getting Started](pages/index.md): SolidJS for modern OCaml. +- [OCaml over TypeScript](pages/start/ocaml-over-typescript.md): Safe, readable and predictable, and still Solid underneath. +- [How it works](pages/start/how-it-works.md): One component, from OCaml's JSX to the code Solid's compiler emits. +- [Melange and dune](pages/start/melange.md): How components are built by dune, compiled by Melange, and why the libraries are shaped as they are. +- [Vite](pages/start/vite.md): The plugin in Vite, under Astro, and under vitest. +- [Astro](pages/start/astro.md): Build a site with Astro, its interactive parts written as OCaml islands. +- [Conventions](pages/start/conventions.md): How a name, a namespace, a data attribute, an optional prop and a spread from Solid's documentation are written in OCaml. + +## Solid + +- [Solid](pages/solid.md): Zero-cost bindings to Solid. +- [Components](pages/solid/components.md): A component in OCaml's JSX, its props, its children, and how the compiler checks them. +- [Reactivity](pages/solid/reactivity.md): Signals, derived values and effects, and where a reactive read is tracked. +- [Control flow](pages/solid/control-flow.md): Show, For, Index, Switch and Match, ErrorBoundary and Portal, with OCaml's options and matches. +- [Stores and context](pages/solid/state.md): State tracked field by field, and a value given to every component below a provider. +- [Async](pages/solid/async.md): Resources, Suspense and transitions, with OCaml's options and results. +- [Rendering](pages/solid/rendering.md): Mounting in the browser, rendering on the server, and hydrating what the server rendered. + +## Kobalte + +- [Kobalte](pages/kobalte.md): Zero-cost bindings to Kobalte, generated from its own types. +- [The binding](pages/kobalte/binding.md): How solidtype-kobalte is generated from Kobalte's own declarations, and how Kobalte's types become OCaml's. +- [Using Kobalte](pages/kobalte/usage.md): Kobalte's components in OCaml's JSX, styled by their own data attributes. +- [Headless components](pages/kobalte/headless.md): Components Kobalte lacks, made as Kobalte makes its own, of its hooks, and Kobalte's own, fixed. + +## HeroUI + +Each component's page gives HeroUI's own examples in OCaml, and a table of its props with the name HeroUI's React component gives each. + +- [HeroUI](pages/heroui.md): A maintained port of HeroUI's design system to solidtype. +- [Coverage](pages/heroui/coverage.md): Which of HeroUI's components solidtype has ported. +- [Theming](pages/heroui/theming.md): Customize HeroUI's design system with CSS variables and global styles. +- [Styling](pages/heroui/styling.md): Style HeroUI components with CSS or Tailwind. +- [Composition](pages/heroui/composition.md): Build flexible UI with component composition patterns. +- [Button](pages/heroui/button.md): A clickable button component with multiple variants and states. +- [ButtonGroup](pages/heroui/button-group.md): Group related buttons together with consistent styling and spacing. +- [CloseButton](pages/heroui/close-button.md): Button component for closing dialogs, modals, or dismissing content. +- [Segment](pages/heroui/segment.md): A segmented control, for a few options of which one is selected. +- [ToggleButton](pages/heroui/toggle-button.md): An interactive toggle control for on/off or selected/unselected states. +- [ToggleButtonGroup](pages/heroui/toggle-button-group.md): Groups multiple ToggleButtons into a unified control, allowing users to select one or multiple options. +- [Dropdown](pages/heroui/dropdown.md): A dropdown displays a list of actions or options that a user can choose. +- [EmptyState](pages/heroui/empty-state.md): What a list shows where it has nothing to show. +- [ListBox](pages/heroui/list-box.md): A listbox displays a list of options and allows a user to select one or more of them. +- [TagGroup](pages/heroui/tag-group.md): A focusable list of tags with support for keyboard navigation, selection, and removal. +- [ColorArea](pages/heroui/color-area.md): A 2D color picker that allows users to select colors from a gradient area. +- [ColorField](pages/heroui/color-field.md): Color input field with labels, descriptions, and validation. +- [ColorPicker](pages/heroui/color-picker.md): A composable color picker that synchronizes color value between multiple color components. +- [ColorSlider](pages/heroui/color-slider.md): A color slider allows users to adjust an individual channel of a color value. +- [ColorSwatch](pages/heroui/color-swatch.md): A visual preview of a color value with accessibility support. +- [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. +- [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. +- [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. +- [TimeField](pages/heroui/time-field.md): Time input field with labels, descriptions, and validation. +- [Alert](pages/heroui/alert.md): Display important messages and notifications to users with status indicators. +- [Meter](pages/heroui/meter.md): A meter represents a quantity within a known range, or a fractional value. +- [ProgressBar](pages/heroui/progress-bar.md): A progress bar shows either determinate or indeterminate progress of an operation over time. +- [ProgressCircle](pages/heroui/progress-circle.md): A circular progress indicator that shows determinate or indeterminate progress. +- [Skeleton](pages/heroui/skeleton.md): Skeleton is a placeholder to show a loading state and the expected shape of a component. +- [Spinner](pages/heroui/spinner.md): A loading indicator component to show pending states. +- [TextShimmer](pages/heroui/text-shimmer.md): Text with a highlight sweeping across it, for a label of work under way. +- [Checkbox](pages/heroui/checkbox.md): Checkboxes allow users to select multiple items from a list of individual items, or to mark one individual item as selected. +- [CheckboxGroup](pages/heroui/checkbox-group.md): A checkbox group component for managing multiple checkbox selections. +- [Description](pages/heroui/description.md): Provides supplementary text for form fields and other components. +- [ErrorMessage](pages/heroui/error-message.md): An error message for non-form components such as a TagGroup. +- [FieldError](pages/heroui/field-error.md): Displays validation error messages for form fields. +- [Fieldset](pages/heroui/fieldset.md): Group related form controls with legends, descriptions, and actions. +- [Form](pages/heroui/form.md): Wrapper component for form validation and submission handling. +- [Input](pages/heroui/input.md): Primitive single-line text input component that accepts standard HTML attributes. +- [InputGroup](pages/heroui/input-group.md): Group related input controls with prefix and suffix elements for enhanced form fields. +- [Label](pages/heroui/label.md): Renders an accessible label associated with form controls. +- [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. +- [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. +- [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. +- [Breadcrumbs](pages/heroui/breadcrumbs.md): Navigation breadcrumbs showing the current page's location within a hierarchy. +- [Disclosure](pages/heroui/disclosure.md): A disclosure is a collapsible section with a header containing a heading and a trigger button, and a panel that wraps the content. +- [DisclosureGroup](pages/heroui/disclosure-group.md): Container that manages multiple Disclosure items with coordinated expanded states. +- [Link](pages/heroui/link.md): A styled anchor component for navigation with built-in icon support. +- [Pagination](pages/heroui/pagination.md): Page navigation with composable page links, previous/next buttons, and ellipsis indicators. +- [Tabs](pages/heroui/tabs.md): Tabs organize content into multiple sections and allow users to navigate between them. +- [AlertDialog](pages/heroui/alert-dialog.md): Modal dialog for critical confirmations requiring user attention and explicit action. +- [Drawer](pages/heroui/drawer.md): Slide-out panel for supplementary content and actions. +- [Modal](pages/heroui/modal.md): Dialog overlay for focused user interactions and important content. +- [Popover](pages/heroui/popover.md): Displays rich content in a portal triggered by a button or any custom element. +- [Toast](pages/heroui/toast.md): Display temporary notifications and messages to users with automatic dismissal and customizable placement. +- [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. +- [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. +- [ScrollShadow](pages/heroui/scroll-shadow.md): Apply visual shadows to indicate scrollable content overflow with automatic detection of scroll position. + +## Charts + +Each page links to the page of rhp's documentation it follows. + +- [Charts](pages/rhp.md): Zero-cost bindings to rhp, Solid's reactive charts made of HTML. +- [Gallery](pages/rhp/gallery.md): rhp's gallery charts in OCaml: a waterfall, a pie, a heatmap, a Gantt chart and candlesticks. +- [Theme](pages/rhp/theme.md): The colours and font of every chart inside it. +- [Chart](pages/rhp/chart.md): The frame of a chart -- its scale, its axis and its orientation. +- [Plot](pages/rhp/plot.md): A slat for each row, stacked in the chart's band, each in its place as the rows change. +- [Scale](pages/rhp/scale.md): An axis drawn as a plot of its ticks, from blocks. +- [Slat](pages/rhp/slat.md): The template for one row, with the CSS and layout every slat of its type shares. +- [Many dots](pages/rhp/many-dots.md): Many points at once, without a slat or a computation for each. +- [Poster](pages/rhp/poster.md): A panel around a chart, as a magazine sets one: kicker, headline, dek and note. +- [Helpers](pages/rhp/helpers.md): The functions of data rhp gives: stacks, running totals, bins, summaries, densities. +- [Bar](pages/rhp/bar.md): A bar along the value axis, from one value to another. +- [Dot](pages/rhp/dot.md): A round point at a value, or at a value on each of two scales. +- [Tick](pages/rhp/tick.md): A short line across the band at a value: a goal, a median, a mark. +- [Label](pages/rhp/label.md): Text placed on the chart's scale, or outside it at an edge. +- [Cell](pages/rhp/cell.md): A cell of the band, coloured by its value on the scale. +- [Place](pages/rhp/place.md): A place on the scale, which draws nothing, for whatever is put in it. +- [Line](pages/rhp/line.md): A line through points: a sparkline in a slat, or a line chart on a second scale. +- [Area](pages/rhp/area.md): A filled outline across the band: ridgelines, or violins drawn both ways. + +## Reference + +Each module's interface, its `.mli`, is its contract: what each function does, refuses and defaults to. + +- [Reference](pages/reference.md): The packages, and a link to each module's odoc page. diff --git a/agents/pages/heroui.md b/agents/pages/heroui.md new file mode 100644 index 00000000..0c1b4e7e --- /dev/null +++ b/agents/pages/heroui.md @@ -0,0 +1,116 @@ +# HeroUI + +A maintained port of HeroUI's design system to solidtype. + +[HeroUI](https://heroui.com)'s look and feel, reimplemented on Kobalte. The +port follows each HeroUI release, and every component is tested against +HeroUI's own React one. + +```ocaml title="card_form.mlx" +module Button = Solidtype_heroui.Button +module Card = Solidtype_heroui.Card +module Form = Solidtype_heroui.Form +module Input = Solidtype_heroui.Input +module Label = Solidtype_heroui.Label +module Link = Solidtype_heroui.Link +module Text_field = Solidtype_heroui.Text_field + +external prevent_default : Dom.event -> unit = "preventDefault" [@@mel.send] +external alert : string -> unit = "alert" + +let make () = + + + "Login" + + "Enter your credentials to access your account" + + +
+ prevent_default e; + alert "Form submitted successfully!")> + +
+ + + + + + + + +
+
+ + + "Forgot password?" + +
+
+``` + +## What you get + +- **HeroUI's look.** Each component carries HeroUI's own classes from + `@heroui/styles`, so HeroUI's themes and stylesheets restyle it as they do + in React. +- **Kobalte's behaviour.** Keyboard, focus and ARIA are Kobalte's, with + HeroUI's parts and props on top, and what HeroUI does beyond Kobalte. +- **HeroUI's state attributes.** `data-hovered`, `data-pressed`, + `data-selected` and the rest are on each element, prerendered pages + included, so HeroUI's selectors work. +- **Parity with HeroUI in React.** Each component's page shows it beside + HeroUI's own React component. + +## 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 +still to come. Every component has its page in this section, with HeroUI's +own examples written in OCaml. + +## Install + +```sh +opam install solidtype-heroui +bun add @heroui/styles @kobalte/core tailwindcss +``` + +```lisp +(libraries solidtype solidtype-kobalte solidtype-heroui melange.dom) +``` + +Import HeroUI's styles, as HeroUI's own installation does: + +```css +@import "tailwindcss"; +@import "@heroui/styles"; +``` + +## Icons + +HeroUI's components and examples draw [Gravity UI's icons](https://gravity-ui.com/icons). +`solidtype-gravity-icons` has every one, named by the one rule: +`ChevronDown` is `Gravity.Chevron_down`. It imports nothing from npm, and +comes with `solidtype-heroui`, whose components draw their icons from it. + +```sh +opam install solidtype-gravity-icons +``` + +```lisp +(libraries solidtype solidtype-gravity-icons melange.dom) +``` + +```ocaml +module Gravity = Solidtype_gravity_icons + +let icon = +``` + +An icon takes every attribute an `` does. diff --git a/agents/pages/heroui/accordion.md b/agents/pages/heroui/accordion.md new file mode 100644 index 00000000..a54e39b7 --- /dev/null +++ b/agents/pages/heroui/accordion.md @@ -0,0 +1,707 @@ +# Accordion + +A collapsible content panel for organizing information in a compact space. + +Original HeroUI documentation: [Accordion](https://heroui.com/en/docs/react/components/accordion). + +## Usage + +HeroUI's examples, with HeroUI's icons from [`solidtype-gravity-icons`](../heroui.md#icons). + +```ocaml title="accordion_usage.mlx" +module Accordion = Solidtype_heroui.Accordion +module Gravity = Solidtype_gravity_icons + +let items = + [| + ( (fun () -> ), + "How do I place an order?", + "Browse our products, add items to your cart, and proceed to checkout. \ + You'll need to provide shipping and payment information to complete \ + your purchase." ); + ( (fun () -> ), + "Can I modify or cancel my order?", + "Yes, you can modify or cancel your order before it's shipped. Once your \ + order is processed, you can't make changes." ); + ( (fun () -> ), + "What payment methods do you accept?", + "We accept all major credit cards, including Visa, Mastercard, and \ + American Express." ); + ( (fun () -> ), + "How much does shipping cost?", + "Shipping costs vary based on your location and the size of your order. \ + We offer free shipping for orders over $50." ); + ( (fun () -> ), + "Do you ship internationally?", + "Yes, we ship to most countries. Please check our shipping rates and \ + policies for more information." ); + ( (fun () -> ), + "How do I request a refund?", + "If you're not satisfied with your purchase, you can request a refund \ + within 30 days of purchase. Please contact our customer support team \ + for assistance." ); + |] + +let make () = + + + (fun (icon, title, content) _ -> + + + + (icon ()) + (Solidtype.Jsx.string title) + + + + + + + (Solidtype.Jsx.string content) + + ) + + +``` + +## Parity + +The same HeroUI Accordion twice, under the same props: in solidtype on the +left, in React on the right. Below them, every attribute of the two +accordions: a marked row is one they disagree on, and a dimmed row is a +framework's own, which no style reads. Each trigger's `aria-controls` names +its own panel by the id its framework made. Kobalte's panel is a region of the +page its trigger controls, where React Aria's is a group its trigger names; +both are accessible, and the port keeps Kobalte's. + +## Anatomy + +```ocaml + + + + + + + + + + +``` + +A [`Button`](button.md) given `` slot=`trigger `` inside a +heading is its item's trigger, in HeroUI's look. + +## Examples + +### Surface + +`` variant=`surface `` lays the accordion on a surface, which the components +inside it read as a [`Surface`](surface.md)'s. + +```ocaml title="accordion_surface.mlx" +module Accordion = Solidtype_heroui.Accordion +module Gravity = Solidtype_gravity_icons + +let items = + [| + ( (fun () -> ), + "How do I place an order?", + "Browse our products, add items to your cart, and proceed to checkout. \ + You'll need to provide shipping and payment information to complete \ + your purchase." ); + ( (fun () -> ), + "Can I modify or cancel my order?", + "Yes, you can modify or cancel your order before it's shipped. Once your \ + order is processed, you can't make changes." ); + ( (fun () -> ), + "What payment methods do you accept?", + "We accept all major credit cards, including Visa, Mastercard, and \ + American Express." ); + ( (fun () -> ), + "How much does shipping cost?", + "Shipping costs vary based on your location and the size of your order. \ + We offer free shipping for orders over $50." ); + ( (fun () -> ), + "Do you ship internationally?", + "Yes, we ship to most countries. Please check our shipping rates and \ + policies for more information." ); + ( (fun () -> ), + "How do I request a refund?", + "If you're not satisfied with your purchase, you can request a refund \ + within 30 days of purchase. Please contact our customer support team \ + for assistance." ); + |] + +let make () = + + + (fun (icon, title, content) _ -> + + + + (icon ()) + (Solidtype.Jsx.string title) + + + + + + + (Solidtype.Jsx.string content) + + ) + + +``` + +### Without Separator + +```ocaml title="accordion_without_separator.mlx" +module Accordion = Solidtype_heroui.Accordion +module Gravity = Solidtype_gravity_icons + +let items = + [| + ( (fun () -> ), + "How do I place an order?", + "Browse our products, add items to your cart, and proceed to checkout. \ + You'll need to provide shipping and payment information to complete \ + your purchase." ); + ( (fun () -> ), + "Can I modify or cancel my order?", + "Yes, you can modify or cancel your order before it's shipped. Once your \ + order is processed, you can't make changes." ); + ( (fun () -> ), + "What payment methods do you accept?", + "We accept all major credit cards, including Visa, Mastercard, and \ + American Express." ); + |] + +let make () = + + + (fun (icon, title, content) _ -> + + + + (icon ()) + (Solidtype.Jsx.string title) + + + + + + + (Solidtype.Jsx.string content) + + ) + + +``` + +### Multiple Expanded + +```ocaml title="accordion_multiple.mlx" +module Accordion = Solidtype_heroui.Accordion + +let items = + [| + ( "Getting Started", + "Learn the basics of HeroUI and how to integrate it into your React \ + project. This section covers installation, setup, and your first \ + component." ); + ( "Core Concepts", + "Understand the fundamental concepts behind HeroUI, including the \ + compound component pattern, styling with Tailwind CSS, and \ + accessibility features." ); + ( "Advanced Usage", + "Explore advanced features like custom variants, theme customization, \ + and integration with other libraries in your React ecosystem." ); + ( "Best Practices", + "Follow our recommended best practices for building performant, \ + accessible, and maintainable applications with HeroUI components." ); + |] + +let make () = + + + (fun (title, content) _ -> + + + + (Solidtype.Jsx.string title) + + + + (Solidtype.Jsx.string content) + + ) + + +``` + +### Disabled State + +An item is disabled while it or the accordion is. + +```ocaml title="accordion_disabled.mlx" +module Accordion = Solidtype_heroui.Accordion + +let item ?is_disabled ~title ~content () = + + + + (Solidtype.Jsx.string title) + + + + (Solidtype.Jsx.string content) + + + +let make () = +
+
+

+ "Entire accordion disabled" +

+ + (item ~title:"Disabled Item 1" + ~content: + "This content cannot be accessed when the accordion is disabled." + ()) + (item ~title:"Disabled Item 2" + ~content: + "This content cannot be accessed when the accordion is disabled." + ()) + +
+
+

+ "Individual items disabled" +

+ + (item ~title:"Active Item" + ~content:"This item is active and can be toggled normally." ()) + (item ~is_disabled:true ~title:"Disabled Item" + ~content:"This content cannot be accessed when the item is disabled." + ()) + (item ~title:"Another Active Item" + ~content:"This item is also active and can be toggled." ()) + +
+
+``` + +### Controlled + +`expanded_keys` gives the expanded items' ids, and `on_expanded_change` is +called with them all, then the pressed item's with its own state. [`Disclosure_group.navigation`](disclosure-group.md#navigation), +HeroUI's `useDisclosureGroupNavigation`, gives previous and next buttons over +the items. + +```ocaml title="accordion_controlled.mlx" +module S = Solidtype.Solid +module Accordion = Solidtype_heroui.Accordion +module Button = Solidtype_heroui.Button +module Disclosure_group = Solidtype_heroui.Disclosure_group +module Gravity = Solidtype_gravity_icons + +let items = + [| + ( "getting-started", + "Getting Started", + "Learn the basics of HeroUI and how to integrate it into your React \ + project. This section covers installation, setup, and your first \ + component." ); + ( "core-concepts", + "Core Concepts", + "Understand the fundamental concepts behind HeroUI, including the \ + compound component pattern, styling with Tailwind CSS, and \ + accessibility features." ); + ( "advanced-usage", + "Advanced Usage", + "Explore advanced features like custom variants, theme customization, \ + and integration with other libraries in your React ecosystem." ); + |] + +let make () = + let expanded, set_expanded = S.create_signal [| "getting-started" |] in + let n = + Disclosure_group.navigation + ~expanded_keys:(fun () -> S.get expanded) + ~item_ids:(Array.map (fun (id, _, _) -> id) items) + ~on_expanded_change:(S.set set_expanded) () + in +
+
+

+ "Expanded: " + + (match S.get expanded with + | [||] -> Solidtype.Jsx.string "none" + | keys -> Solidtype.Jsx.string (Js.Array.join ~sep:", " keys)) + +

+
+ + +
+
+ + + (fun (id, title, content) _ -> + + + + (Solidtype.Jsx.string title) + + + + (Solidtype.Jsx.string content) + + ) + + +
+``` + +### Custom Indicator + +An icon given to `Accordion.Indicator` takes the chevron's place and turns +over as its item expands. + +```ocaml title="accordion_custom_indicator.mlx" +module S = Solidtype.Solid +module Accordion = Solidtype_heroui.Accordion +module Gravity = Solidtype_gravity_icons + +let make () = + let expanded, set_expanded = S.create_signal [| "" |] in + + + + + "Using Plus/Minus Icon" + + (if Array.exists (String.equal "1") (S.get expanded) then + + else ) + + + + + + "This accordion uses a plus icon that transforms when expanded. The \ + icon automatically rotates 45 degrees to form an X." + + + + + + + "Using Caret Icon" + + + + + + + + "This item uses a caret icon for the indicator. The rotation \ + animation is applied automatically." + + + + + + + "Using Arrow Icon" + + + + + + "This item uses an arrow icon. Any icon you pass will receive the \ + rotation animation when the item expands." + + + + +``` + +### FAQ Layout + +```ocaml title="accordion_faq.mlx" +module Accordion = Solidtype_heroui.Accordion +module Gravity = Solidtype_gravity_icons + +let categories = + [| + ( "General", + [| + ( "How do I place an order?", + "Browse our products, add items to your cart, and proceed to \ + checkout. You'll need to provide shipping and payment information \ + to complete your purchase." ); + ( "Can I modify or cancel my order?", + "Yes, you can modify or cancel your order before it's shipped. Once \ + your order is processed, you can't make changes." ); + |] ); + ( "Licensing", + [| + ( "How do I purchase a license?", + "You can purchase a license directly from our website. Select the \ + license type that fits your needs and proceed to checkout." ); + ( "What is the difference between a standard and a pro license?", + "A standard license is for personal use or small projects, while a \ + pro license includes commercial use rights and priority support." ); + |] ); + ( "Support", + [| + ( "How do I get support?", + "You can reach our support team through the contact form on our \ + website, or email us directly at support@example.com." ); + |] ); + |] + +let make () = +
+
+

"Frequently Asked Questions"

+

+ "Everything you need to know about licensing and usage." +

+
+ + (fun (category, items) _ -> +
+

+ (Solidtype.Jsx.string category) +

+ + + (fun (title, content) _ -> + + + + (Solidtype.Jsx.string title) + + + + + + + + (Solidtype.Jsx.string content) + + + ) + + +
) +
+
+``` + +## Customization + +### Tailwind CSS + +`class_` is added after HeroUI's classes, on every part. + +```ocaml title="accordion_tailwind.mlx" +module Accordion = Solidtype_heroui.Accordion +module Gravity = Solidtype_gravity_icons + +let assets = + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/docs/3dicons/" + +let items = + [| + ( "Set Up Notifications", + "Receive account activity updates", + assets ^ "bell-small.png", + "Stay informed about your account activity with real-time notifications." + ); + ( "Set up Browser Extension", + "Connect your browser to your account", + assets ^ "compass-small.png", + "Enhance your browsing experience by installing our official browser \ + extension" ); + ( "Mint Collectible", + "Create your first collectible", + assets ^ "mint-collective-small.png", + "Begin your journey into the world of digital collectibles by creating \ + your first NFT. " ); + |] + +let make () = + + + (fun (title, subtitle, icon, content) _ -> + + + + title +
+ + (Solidtype.Jsx.string title) + + + (Solidtype.Jsx.string subtitle) + +
+ + + +
+
+ + + (Solidtype.Jsx.string content) + + +
) +
+
+``` + +### Global CSS + +HeroUI's classes are global, so a stylesheet restyles every accordion, as with +HeroUI in React: + +```css +@layer components { + .accordion { + @apply rounded-xl bg-gray-50; + } + + .accordion__trigger { + @apply text-lg font-semibold; + } +} +``` + +## Styling Reference + +### CSS Classes + +- `.accordion` - Base accordion container +- `.accordion--surface` - Surface variant +- `.accordion__item` - Individual accordion item +- `.accordion__heading` - Heading wrapper +- `.accordion__trigger` - Clickable trigger button +- `.accordion__indicator` - Expand/collapse indicator icon +- `.accordion__panel` - Collapsible panel container +- `.accordion__body`, `.accordion__body-inner` - Content body container + +### Interactive States + +- **Expanded**: `[aria-expanded="true"]` on the trigger, and + `[data-expanded="true"]` on the item, the indicator and the panel +- **Hover**: `:hover` or `[data-hovered="true"]` on the trigger +- **Focus**: `:focus-visible` or `[data-focus-visible="true"]` on the trigger +- **Disabled**: `:disabled` or `[data-disabled="true"]` on the trigger, the + item and the root +- **No separator**: `[data-hide-separator="true"]` on each item +- **Hidden**: `[aria-hidden="true"]` and `hidden="until-found"` on the panel + while collapsed + +## API Reference + +Each prop beside the name HeroUI's React component gives it. + +### Accordion + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `expandedKeys` | `expanded_keys` | `string array` | | The controlled expanded keys | +| `defaultExpandedKeys` | `default_expanded_keys` | `string array` | `[\|\|]` | The initial expanded keys | +| `onExpandedChange` | `on_expanded_change` | `string array -> unit` | | Handler called when expanded keys change | +| `allowsMultipleExpanded` | `allows_multiple_expanded` | `bool` | `false` | Whether multiple items can be expanded at once | +| `isDisabled` | `is_disabled` | `bool` | `false` | Whether the entire accordion is disabled | +| `variant` | `variant` | `` [ `default \| `surface ] `` | `` `default `` | The visual variant of the accordion | +| `hideSeparator` | `hide_separator` | `bool` | `false` | Hide separator lines between accordion items | +| `className` | `class_` | `string` | | Added after HeroUI's classes | +| `children` | `children` | elements | | The accordion items | +| `render` | `as_` | a function of its props and state | | Draws another element in its place | + +### Accordion.Item + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `id` | `id` | `string` | a unique id | Unique identifier for the item | +| `isDisabled` | `is_disabled` | `bool` | `false` | Whether this item is disabled | +| `onExpandedChange` | `on_expanded_change` | `bool -> unit` | | Called with its new state as its trigger is pressed, after the accordion's | +| `isExpanded`, `defaultExpanded` | — | | | An item is expanded as the accordion's keys say: HeroUI's reads neither inside an accordion, and here they are refused | +| `className` | `class_` | `string` | | Added after HeroUI's classes | +| `children` | `children` | elements | | The item content | +| `render` | `as_` | a function of its props and state | | Draws another element in its place | + +### Accordion.Trigger + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `onPress` | `on_press` | `unit -> unit` | | Called as it is pressed, by a pointer, Enter or Space, after its item's state has changed | +| `isDisabled` | `is_disabled` | `bool` | `false` | Whether it is disabled, as it is while its item is; the arrows pass it by | +| `className` | `class_` | `string` | | Added after HeroUI's classes | +| `children` | `children` | elements | | Trigger content | +| `render` | `as_` | a function of its props and state | | Draws another element in its place | + +### Accordion.Heading, Accordion.Panel, Accordion.Body + +| React | solidtype | Type | Description | +|---|---|---|---| +| `className` | `class_` | `string` | Added after HeroUI's classes | +| `children` | `children` | elements | Its content | +| `render` | `as_` | a function of its props and state | Draws another element in its place | + +### Accordion.Indicator + +| React | solidtype | Type | Description | +|---|---|---|---| +| `className` | `class_` | `string` | Added after HeroUI's classes | +| `children` | `children` | elements | Custom indicator icon | + +## Accessibility + +- The up and down arrows move focus between triggers, round from the last to + the first, and Home and End to the first and the last, skipping a disabled + item +- A collapsed panel stays on the page: the browser's find in page searches + it, and expands its item on a match diff --git a/agents/pages/heroui/alert-dialog.md b/agents/pages/heroui/alert-dialog.md new file mode 100644 index 00000000..baa8152b --- /dev/null +++ b/agents/pages/heroui/alert-dialog.md @@ -0,0 +1,1198 @@ +# AlertDialog + +Modal dialog for critical confirmations requiring user attention and explicit action. + +Original HeroUI documentation: [AlertDialog](https://heroui.com/en/docs/react/components/alert-dialog). + +## Usage + +```ocaml title="alert_dialog_usage.mlx" +module Button = Solidtype_heroui.Button +module Alert_dialog = Solidtype_heroui.Alert_dialog + +let make () = + + + + + + + + + + "Delete project permanently?" + + + +

+ "This will permanently delete " + "My Awesome Project" + " and all of its data. This action cannot be undone." +

+
+ + + + +
+
+
+
+``` + +## Parity + +The same HeroUI AlertDialog twice, under the same props: in solidtype on the +left, in React on the right. Below them, every attribute of each trigger: a +marked row is one they disagree on, and a dimmed row is a framework's own, +which no style reads. + +The marked row is Kobalte's: its trigger tells a reader it opens a dialog, `aria-haspopup="dialog"`, which React Aria's leaves out. + +## Anatomy + +```ocaml + + + + + + + + + ... + + ... + ... + + + + +``` + +`Alert_dialog.Close_trigger` and `Alert_dialog.Icon` are optional. A +`Button` given `` slot=`close `` inside the dialog closes it. + +## Examples + +### Statuses + +```ocaml title="alert_dialog_statuses.mlx" +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Button = Solidtype_heroui.Button +module Alert_dialog = Solidtype_heroui.Alert_dialog + +type example = { + cancel : string; + confirm : string; + body : string; + classes : string; + header : string; + status : Solidtype_heroui.Status_icon.status; + trigger : string; +} + +let examples = + [| + { + cancel = "Stay Signed In"; + confirm = "Sign Out"; + body = + "You'll need to sign in again to access your account. Any unsaved \ + changes will be lost."; + classes = "bg-accent-soft text-accent-soft-foreground"; + header = "Sign out of your account?"; + status = `accent; + trigger = "Sign Out"; + }; + { + cancel = "Not Yet"; + confirm = "Mark Complete"; + body = + "This will mark the task as complete and notify all team members. The \ + task will be moved to your completed list."; + classes = "bg-success-soft text-success-soft-foreground"; + header = "Complete this task?"; + status = `success; + trigger = "Complete Task"; + }; + { + cancel = "Keep Editing"; + confirm = "Discard"; + body = + "You have unsaved changes that will be permanently lost. Are you sure \ + you want to discard them?"; + classes = "bg-warning-soft text-warning-soft-foreground"; + header = "Discard unsaved changes?"; + status = `warning; + trigger = "Discard Changes"; + }; + { + cancel = "Cancel"; + confirm = "Delete Account"; + body = + "This will permanently delete your account and remove all your data \ + from our servers. This action is irreversible."; + classes = "bg-danger-soft text-danger-soft-foreground"; + header = "Delete your account?"; + status = `danger; + trigger = "Delete Account"; + }; + |] + +let make () = +
+ + (fun (e : example) _ -> + + + + + + + + + + (Jsx.string e.header) + + + +

(Jsx.string e.body)

+
+ + + + +
+
+
+
) +
+
+``` + +### Placements + +```ocaml title="alert_dialog_placements.mlx" +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Button = Solidtype_heroui.Button +module Alert_dialog = Solidtype_heroui.Alert_dialog + +let placements = + [| (`auto, "auto"); (`top, "top"); (`center, "center"); (`bottom, "bottom") |] + +let make () = +
+ + (fun (placement, name) _ -> + + + + + + + + + + (Jsx.string + (match placement with + | `auto -> "Auto Placement" + | `top | `center | `bottom -> + String.capitalize_ascii name ^ " Position")) + + + +

+ (Jsx.string + (match placement with + | `auto -> + "Automatically positions at the bottom on mobile \ + and center on desktop for optimal user experience." + | `top | `center | `bottom -> + "This dialog is positioned at the " ^ name + ^ " of the viewport. Critical confirmations are \ + typically centered for maximum attention.")) +

+
+ + + + +
+
+
+
) +
+
+``` + +### Sizes + +```ocaml title="alert_dialog_sizes.mlx" +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Button = Solidtype_heroui.Button +module Alert_dialog = Solidtype_heroui.Alert_dialog +module Gravity = Solidtype_gravity_icons + +let sizes = + [| (`xs, "xs"); (`sm, "sm"); (`md, "md"); (`lg, "lg"); (`cover, "cover") |] + +let make () = +
+ + (fun (size, name) _ -> + + + + + + + + + + + + "Size: " (Jsx.string (String.capitalize_ascii name)) + + + +

+ "This alert dialog uses the " + (Jsx.string name) + (Jsx.string + (match size with + | `cover -> + " size variant. It spans the full screen with \ + margins: 16px on mobile and 40px on desktop. \ + Maintains rounded corners and standard padding. \ + Perfect for critical confirmations that need \ + maximum width while preserving alert dialog \ + aesthetics." + | `xs | `sm | `md | `lg -> + " size variant. On mobile devices, all sizes adapt \ + to near full-width for optimal viewing. On \ + desktop, each size provides a different maximum \ + width to suit various content needs.")) +

+
+ + + + +
+
+
+
) +
+
+``` + +### Controlled State + +Keep the open state in a signal, given as `is_open` with `on_open_change`. + +```ocaml title="alert_dialog_controlled.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Button = Solidtype_heroui.Button +module Alert_dialog = Solidtype_heroui.Alert_dialog + +(* HeroUI shows React's useState and its own useOverlayState; a signal is + Solid's state, so both halves keep the dialog's in one. *) +let make () = + let is_open, set_open = S.create_signal false in + let state_open, set_state_open = S.create_signal false in +
+
+

"With a signal"

+

+ "Control the alert dialog using Solid's " + "signal" + " for simple state management. Perfect for basic use cases." +

+
+
+

+ "Status: " + + (Jsx.string (if S.get is_open then "open" else "closed")) + +

+
+
+ + +
+
+ + + + + + + + "Controlled with a signal" + + + +

+ "This alert dialog is controlled by Solid's " + "signal" + ". Pass " + "is_open" + " and " + "on_open_change" + " props to manage the dialog state externally." +

+
+ + + + +
+
+
+
+
+

+ "With a signal's setter" +

+

+ "Use the " + "signal" + "'s setter for a cleaner API with convenient calls like " + "S.set set_open true" + ", " + "S.set set_open false" + ", and " + "S.update set_open not" + "." +

+
+
+

+ "Status: " + + (Jsx.string (if S.get state_open then "open" else "closed")) + +

+
+
+ + +
+
+ + + + + + + + "Controlled with a signal's setter" + + + +

+ "The " + "signal" + {js|'s setter covers the common operations. No need to manually create callbacks—just use |js} + "S.set set_open true" + ", " + "S.set set_open false" + ", or " + "S.update set_open not" + "." +

+
+ + + + +
+
+
+
+
+``` + +### Custom Icon + +```ocaml title="alert_dialog_custom_icon.mlx" +module Button = Solidtype_heroui.Button +module Alert_dialog = Solidtype_heroui.Alert_dialog +module Gravity = Solidtype_gravity_icons + +let make () = + + + + + + + + + + + "Reset your password?" + + +

+ "We'll send a password reset link to your email address. You'll \ + need to create a new password to regain access to your account." +

+
+ + + + +
+
+
+
+``` + +### Custom Trigger + +```ocaml title="alert_dialog_custom_trigger.mlx" +module Button = Solidtype_heroui.Button +module Alert_dialog = Solidtype_heroui.Alert_dialog +module Gravity = Solidtype_gravity_icons + +let make () = + + +
+ +
+
+

"Delete Item"

+

"Permanently remove this item"

+
+
+ + + + + + + + + "Delete this item?" + + +

+ "Use " + "Alert_dialog.Trigger" + " to create custom trigger elements beyond standard buttons. \ + This example shows a card-style trigger with icons and \ + descriptive text." +

+
+ + + + +
+
+
+
+``` + +### Backdrop Variants + +```ocaml title="alert_dialog_backdrop_variants.mlx" +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Button = Solidtype_heroui.Button +module Alert_dialog = Solidtype_heroui.Alert_dialog + +let variants = + [| (`opaque, "opaque"); (`blur, "blur"); (`transparent, "transparent") |] + +let make () = +
+ + (fun (variant, name) _ -> + + + + + + + + + + "Backdrop: " (Jsx.string (String.capitalize_ascii name)) + + + +

+ (Jsx.string + (match variant with + | `opaque -> + "An opaque dark backdrop that completely obscures \ + the background, providing maximum focus on the \ + dialog." + | `blur -> + "A blurred backdrop that softly obscures the \ + background while maintaining visual context." + | `transparent -> + "A transparent backdrop that keeps the background \ + fully visible, useful for less critical \ + confirmations.")) +

+
+ + + + +
+
+
+
) +
+
+``` + +### Custom Backdrop + +```ocaml title="alert_dialog_custom_backdrop.mlx" +module Button = Solidtype_heroui.Button +module Alert_dialog = Solidtype_heroui.Alert_dialog +module Gravity = Solidtype_gravity_icons + +let make () = + + + + + + + + + + + + "Permanently delete your account?" + + + +

+ "This action cannot be undone. All your data, settings, and \ + content will be permanently removed from our servers. The \ + dramatic red backdrop emphasizes the severity and \ + irreversibility of this decision." +

+
+ + + + +
+
+
+
+``` + +### Dismiss Behavior + +```ocaml title="alert_dialog_dismiss.mlx" +module Button = Solidtype_heroui.Button +module Alert_dialog = Solidtype_heroui.Alert_dialog +module Gravity = Solidtype_gravity_icons + +let make () = +
+
+

"is_dismissable"

+

+ "Controls whether the alert dialog can be dismissed by clicking the \ + overlay backdrop. Alert dialogs typically require explicit action, so \ + this defaults to " + "false" + ". Set to " + "true" + " for less critical confirmations." +

+ + + + + + + + + + + + "is_dismissable = false" + +

+ "Clicking the backdrop won't close this alert dialog" +

+
+ +

+ "Try clicking outside this alert dialog on the overlay - it \ + won't close. You must use the action buttons to dismiss it." +

+
+ + + + +
+
+
+
+
+
+

"is_keyboard_dismiss_disabled"

+

+ "Controls whether the ESC key can dismiss the alert dialog. Alert \ + dialogs typically require explicit action, so this defaults to " + "true" + ". When set to " + "false" + ", the ESC key will be enabled." +

+ + + + + + + + + + + + "is_keyboard_dismiss_disabled = true" + +

+ "ESC key is disabled" +

+
+ +

+ "Press ESC - nothing happens. You must use the action \ + buttons to dismiss this alert dialog." +

+
+ + + + +
+
+
+
+
+
+``` + +### Close Methods + +A dialog's function child is given `close`, which closes it. + +```ocaml title="alert_dialog_close_methods.mlx" +module S = Solidtype.Solid +module Button = Solidtype_heroui.Button +module Alert_dialog = Solidtype_heroui.Alert_dialog + +(* HeroUI's second dialog closes itself through its render prop's close; here + the page keeps the dialog's state, which the buttons set. *) +let make () = + let is_open, set_open = S.create_signal false in +
+
+

"Using slot=`close"

+

+ "The simplest way to close a dialog. Add " + "slot=`close" + " to any Button component within the dialog. When clicked, it will \ + automatically close the dialog." +

+ + + + + + + + "Using slot=`close" + + +

+ "Click either button below - both have " + "slot=`close" + " and will close the dialog automatically." +

+
+ + + + +
+
+
+
+
+
+

"Using the dialog's state"

+

+ "Keep the dialog's state in a " + "signal" + " and set it to " + "false" + ". This gives you full control over when and how to close the dialog, \ + allowing you to add custom logic before closing." +

+ + + + + + + + + "Using the dialog's state" + + + +

+ "The buttons below set the " + "signal" + " to " + "false" + ". You can add validation or other logic before calling " + "S.set set_open false" + "." +

+
+ + + + +
+
+
+
+
+
+``` + +### Custom Animations + +```ocaml title="alert_dialog_custom_animations.mlx" +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Button = Solidtype_heroui.Button +module Alert_dialog = Solidtype_heroui.Alert_dialog +module Gravity = Solidtype_gravity_icons + +type animation = { + backdrop : string; + container : string; + description : string; + icon : [ `sparkles | `arrow_up_from_line ]; + name : string; +} + +let animations = + [| + { + backdrop = + String.concat " " + [ + "data-[entering]:duration-400"; + "data-[entering]:ease-[cubic-bezier(0.16,1,0.3,1)]"; + "data-[exiting]:duration-200"; + "data-[exiting]:ease-[cubic-bezier(0.7,0,0.84,0)]"; + ]; + container = + String.concat " " + [ + "data-[entering]:animate-in"; + "data-[entering]:fade-in-0"; + "data-[entering]:zoom-in-95"; + "data-[entering]:duration-400"; + "data-[entering]:ease-[cubic-bezier(0.16,1,0.3,1)]"; + "data-[exiting]:animate-out"; + "data-[exiting]:fade-out-0"; + "data-[exiting]:zoom-out-95"; + "data-[exiting]:duration-200"; + "data-[exiting]:ease-[cubic-bezier(0.7,0,0.84,0)]"; + ]; + description = + "Physics-based elastic scaling. Simulates a high-damping spring system \ + with fast transient response and prolonged settling time. Ideal for \ + Alert Dialogs and Modals."; + icon = `sparkles; + name = "Kinematic Scale"; + }; + { + backdrop = + String.concat " " + [ + "data-[entering]:duration-500"; + "data-[entering]:ease-[cubic-bezier(0.25,1,0.5,1)]"; + "data-[exiting]:duration-200"; + "data-[exiting]:ease-[cubic-bezier(0.5,0,0.75,0)]"; + ]; + container = + String.concat " " + [ + "data-[entering]:animate-in"; + "data-[entering]:fade-in-0"; + "data-[entering]:slide-in-from-bottom-4"; + "data-[entering]:duration-500"; + "data-[entering]:ease-[cubic-bezier(0.25,1,0.5,1)]"; + "data-[exiting]:animate-out"; + "data-[exiting]:fade-out-0"; + "data-[exiting]:slide-out-to-bottom-2"; + "data-[exiting]:duration-200"; + "data-[exiting]:ease-[cubic-bezier(0.5,0,0.75,0)]"; + ]; + description = + "Simulates movement through a medium with fluid resistance. Eliminates \ + mechanical linearity for a natural, grounded feel. Perfect for Bottom \ + Sheets or Toasts."; + icon = `arrow_up_from_line; + name = "Fluid Slide"; + }; + |] + +let make () = +
+ + (fun (a : animation) _ -> + + + + + + + + + (match a.icon with + | `sparkles -> + | `arrow_up_from_line -> + ) + + + (Jsx.string a.name) " Animation" + + + +

(Jsx.string a.description)

+
+ + + + +
+
+
+
) +
+
+``` + +### Custom Portal + +The backdrop's `portal_container` draws it inside an element of the page +instead of at the end of its body. Any element a `ref` gives is taken. + +```ocaml title="alert_dialog_custom_portal.mlx" +module S = Solidtype.Solid +module Button = Solidtype_heroui.Button +module Alert_dialog = Solidtype_heroui.Alert_dialog + +let make () = + (* The box is known once it is on the page, as React's ref and state know + it; the modal is made after the page hydrates, as the server, with no + box, never made it. *) + let box = ref None in + let container, set_container = S.create_signal None in + S.on_mount (fun () -> S.set set_container !box); +
+
+

+ "Render alert dialogs inside a custom container instead of " + "document.body" +

+

+ "Apply " + + "transform: translateZ(0)" + + " to the container to create a new stacking context." +

+
+
box := Some e) + class_="relative flex h-[380px] items-center justify-center \ + overflow-hidden rounded bg-muted/20" + style="transform: translate(0);"> + + (fun element -> + + + + + + + + + "Custom Portal" + + +

+ "Lorem ipsum dolor sit amet, consectetur adipiscing \ + elit. Sed do eiusmod tempor incididunt ut labore et \ + dolore magna aliqua. Ut enim ad minim veniam, quis \ + nostrud exercitation ullamco laboris nisi ut aliquip ex \ + ea commodo consequat." +

+

+ "Lorem ipsum dolor sit amet, consectetur adipiscing \ + elit. Sed do eiusmod tempor incididunt ut labore et \ + dolore magna aliqua. Ut enim ad minim veniam, quis \ + nostrud exercitation ullamco laboris nisi ut aliquip ex \ + ea commodo consequat." +

+

+ "Lorem ipsum dolor sit amet, consectetur adipiscing \ + elit. Sed do eiusmod tempor incididunt ut labore et \ + dolore magna aliqua. Ut enim ad minim veniam, quis \ + nostrud exercitation ullamco laboris nisi ut aliquip ex \ + ea commodo consequat." +

+
+ + + + +
+
+
+
) +
+
+
+``` + +## Customization + +### Tailwind CSS + +`class_` is added after HeroUI's classes. + +```ocaml title="alert_dialog_tailwind.mlx" +module Button = Solidtype_heroui.Button +module Alert_dialog = Solidtype_heroui.Alert_dialog + +let make () = + + + + + +
+
+ + + + "Sign out of your account?" + + + +

+ "You will be signed out on this device. Unsaved work in " + "Acme Workspace" + " may be lost unless it was saved to the cloud." +

+
+ + + + + + + + +``` + +### Global CSS + +HeroUI's classes are global, so a stylesheet restyles every one, as with +HeroUI in React: + +```css +@layer components { + .alert-dialog__dialog { + @apply rounded-2xl; + } + + .alert-dialog__heading { + @apply text-lg font-semibold; + } +} +``` + +## Styling Reference + +### CSS Classes + +- `.alert-dialog__trigger` - Trigger element that opens the alert dialog +- `.alert-dialog__backdrop` - Overlay backdrop behind the dialog +- `.alert-dialog__container` - Positioning wrapper with placement support +- `.alert-dialog__dialog` - Dialog content container +- `.alert-dialog__header` - Header section for icon and title +- `.alert-dialog__heading` - Heading text styles +- `.alert-dialog__body` - Main content area +- `.alert-dialog__footer` - Footer section for actions +- `.alert-dialog__icon` - Icon container with status colors +- `.alert-dialog__close-trigger` - Close button element +- `.alert-dialog__backdrop--opaque` - Opaque colored backdrop (default) +- `.alert-dialog__backdrop--blur` - Blurred backdrop with glass effect +- `.alert-dialog__backdrop--transparent` - Transparent backdrop (no overlay) +- `.alert-dialog__dialog--xs`, `--sm`, `--md`, `--lg`, `--cover` - Sizes +- `.alert-dialog__icon--default` - Default gray status +- `.alert-dialog__icon--accent` - Accent blue status +- `.alert-dialog__icon--success` - Success green status +- `.alert-dialog__icon--warning` - Warning orange status +- `.alert-dialog__icon--danger` - Danger red status + +### Interactive States + +- **Entering**: `[data-entering="true"]` on the backdrop and the container +- **Exiting**: `[data-exiting="true"]` on the backdrop and the container +- **Placement**: `[data-placement="auto"]`, and the others, on the container + and the dialog + +## API Reference + +Each prop beside the name HeroUI's React component gives it. + +### AlertDialog + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `isOpen` | `is_open` | `bool` | | Whether it is open, controlled | +| `defaultOpen` | `default_open` | `bool` | `false` | Whether it starts open | +| `onOpenChange` | `on_open_change` | `bool -> unit` | | Told as it opens or closes | + +### AlertDialog.Backdrop + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `variant` | `variant` | `` `opaque `` \| `` `blur `` \| `` `transparent `` | `` `opaque `` | Backdrop overlay style | +| `isDismissable` | `is_dismissable` | `bool` | `false` | Close on backdrop click | +| `isKeyboardDismissDisabled` | `is_keyboard_dismiss_disabled` | `bool` | `true` | Disable Escape key to close | +| `isOpen` | `is_open` | `bool` | | With no `Alert_dialog` around it, whether it is open | +| `onOpenChange` | `on_open_change` | `bool -> unit` | | With no `Alert_dialog` around it, told as it opens or closes | +| `UNSTABLE_portalContainer` | `portal_container` | `_ Dom.element_like` | the page's body | Custom portal container | +| `className` | `class_` | `string` | | Added after HeroUI's classes | + +### AlertDialog.Container + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `placement` | `placement` | `` `auto `` \| `` `center `` \| `` `top `` \| `` `bottom `` | `` `auto `` | Dialog position on screen | +| `size` | `size` | `` `xs `` \| `` `sm `` \| `` `md `` \| `` `lg `` \| `` `cover `` | `` `md `` | Alert Dialog size variant | +| `className` | `class_` | `string` | | Added after HeroUI's classes | + +### AlertDialog.Icon + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `status` | `status` | `` `default `` \| `` `accent `` \| `` `success `` \| `` `warning `` \| `` `danger `` | `` `danger `` | Status color variant | +| `className` | `class_` | `string` | | Added after HeroUI's classes | +| `children` | `children` | elements | | Custom icon element | + +### AlertDialog.Dialog, Header, Body, Footer, Heading, CloseTrigger, Trigger + +As [Modal's](modal.md#api-reference). + +## Accessibility + +Implements the [WAI-ARIA AlertDialog pattern](https://www.w3.org/WAI/ARIA/apg/patterns/alertdialog/): + +- **Focus trap**: Focus locked within alert dialog +- **Keyboard**: Escape closes (when enabled), Tab cycles elements +- **Screen readers**: `role="alertdialog"`, named by its heading +- **Scroll lock**: Body scroll disabled when open +- **Required action**: Defaults to requiring explicit user action (no + backdrop or Escape dismiss) diff --git a/agents/pages/heroui/alert.md b/agents/pages/heroui/alert.md new file mode 100644 index 00000000..afaec998 --- /dev/null +++ b/agents/pages/heroui/alert.md @@ -0,0 +1,183 @@ +# Alert + +Display important messages and notifications to users with status indicators. + +Original HeroUI documentation: [Alert](https://heroui.com/en/docs/react/components/alert). + +## Usage + +```ocaml title="alert_usage.mlx" +module Alert = Solidtype_heroui.Alert +module Button = Solidtype_heroui.Button +module Close_button = Solidtype_heroui.Close_button +module Spinner = Solidtype_heroui.Spinner + +let make () = +
+ + + + "New features available" + + "Check out our latest updates including dark mode support and \ + improved accessibility features." + + + + + + + "Update available" + + "A new version of the application is available. Please refresh to \ + get the latest features and bug fixes." + + + + + + + + + "Unable to connect to server" + + "We're experiencing connection issues. Please try the following:" +
    +
  • "Check your internet connection"
  • +
  • "Refresh the page"
  • +
  • "Clear your browser cache"
  • +
+
+ +
+ +
+ + + + "Profile updated successfully" + + + + + + + "Processing your request" + + "Please wait while we sync your data. This may take a few moments." + + + + + + + "Scheduled maintenance" + + "Our services will be unavailable on Sunday, March 15th from 2:00 AM \ + to 6:00 AM UTC for scheduled maintenance." + + + +
+``` + +## Parity + +The same HeroUI Alert twice, under the same props: in solidtype on the left, +in React on the right. Below them, every attribute of the two: a marked row is +one they disagree on. + +## Anatomy + +```ocaml + + + + "Title" + "Description" + + +``` + +## Examples + +### Announced + +`` role=`alert `` has a reader announce the alert as it appears. + +```ocaml title="alert_announced.mlx" +module Alert = Solidtype_heroui.Alert + +let make () = + + + + "Payment failed" + "Your card was declined." + + +``` + +## Customization + +### Global CSS + +HeroUI's classes are global, so a stylesheet restyles every alert, as with +HeroUI in React: + +```css +@layer components { + .alert { + @apply rounded-2xl shadow-lg; + } + + .alert__title { + @apply font-bold; + } +} +``` + +## Styling Reference + +### CSS Classes + +- `.alert` - Base alert container +- `.alert__indicator` - Icon/indicator container +- `.alert__content` - Content wrapper for title and description +- `.alert__title` - Alert title text +- `.alert__description` - Alert description text +- `.alert--default` - Default gray status +- `.alert--accent` - Accent blue status +- `.alert--success` - Success green status +- `.alert--warning` - Warning yellow/orange status +- `.alert--danger` - Danger red status + +### Interactive States + +The alert is informational and has no interactive states of its own. It can +contain interactive elements like buttons or close buttons. + +## API Reference + +Each prop beside the name HeroUI's React component gives it. + +### Alert + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `status` | `status` | `` [ `default \| `accent \| `success \| `warning \| `danger ] `` | `` `default `` | The visual status of the alert | +| `role` | `role` | `Solidtype.Html.Div.role` | | `` `alert `` to be announced | +| `className` | `class_` | `string` | | Added after HeroUI's classes | +| `children` | `children` | elements | | The alert content | + +### Alert.Indicator, Content, Title, Description + +Each takes `class_`, added after HeroUI's class, and its children. The +indicator's children are a custom indicator icon, which defaults to the status +icon. diff --git a/agents/pages/heroui/autocomplete.md b/agents/pages/heroui/autocomplete.md new file mode 100644 index 00000000..396fec73 --- /dev/null +++ b/agents/pages/heroui/autocomplete.md @@ -0,0 +1,1661 @@ +# Autocomplete + +An autocomplete combines a select with filtering, allowing users to search and select from a list of options. + +Original HeroUI documentation: [Autocomplete](https://heroui.com/en/docs/react/components/autocomplete). + +## 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 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 + +let make () = + + + + + + + + + + + + + + + + "No results found") + selection_mode=`multiple> + + "Florida" + + + "Delaware" + + + "California" + + + "Texas" + + + "New York" + + + "Washington" + + + + + +``` + +## Parity + +The same HeroUI Autocomplete twice, under the same props: in solidtype on +the left, in React on the right. Below them, every attribute of each button: +a marked row is one they disagree on, and a dimmed row is a framework's own, +which no style reads. + +## Anatomy + +```ocaml + + + + + + + + ... + + + + + + + + + + ... + + + + +``` + +A `Label` inside it names its trigger, a `Description` describes it, and a +`Field_error` shows while it is invalid. The `Search_field` inside its +`Autocomplete.Filter` is its search, and the `List_box` beside it its list. + +## Examples + +### Variants + +The Autocomplete component supports two visual variants: + +- **`` `primary ``** (default) - Standard styling with shadow, suitable for + most use cases +- **`` `secondary ``** - Lower emphasis variant without shadow, suitable for + use in Surface components + +```ocaml title="autocomplete_variants.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +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 + +let items = + [| + ("option1", "Option 1"); + ("option2", "Option 2"); + ("option3", "Option 3"); + ("option4", "Option 4"); + |] + +let variant ~label ~variant ~mode = + let selected, set_selected = S.create_signal [||] in + "Select one" + | `multiple -> "Select options") + selection_mode=mode + value=(S.get selected) + variant + on_change=(S.set set_selected)> + + + + + + + + + + + + + + + + + "No results found") + selection_mode=(mode :> List_box.selection_mode)> + + (fun (id, name) _ -> + + (Jsx.string name) + ) + + + + + + +let make () = +
+
+

"Single Select Variants"

+
+ (variant ~label:"Primary variant" ~variant:`primary ~mode:`single) + (variant ~label:"Secondary variant" ~variant:`secondary ~mode:`single) +
+
+
+

"Multiple Select Variants"

+
+ (variant ~label:"Primary variant" ~variant:`primary ~mode:`multiple) + (variant ~label:"Secondary variant" ~variant:`secondary ~mode:`multiple) +
+
+
+``` + +### Full Width + +```ocaml title="autocomplete_full_width.mlx" +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 + +let make () = +
+ + + + + + + + + + + + + + + + + + "No results found")> + + "Florida" + + + "Delaware" + + + "California" + + + "Texas" + + + "New York" + + + "Washington" + + + + + +
+``` + +### With Description + +```ocaml title="autocomplete_with_description.mlx" +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 Description = Solidtype_heroui.Description + +let make () = + + + + + + + + "Select your state of residence" + + + + + + + + + + + "No results found")> + + "Florida" + + + "Delaware" + + + "California" + + + "Texas" + + + "New York" + + + "Washington" + + + + + +``` + +### Required + +A `Form` does not check a required autocomplete itself: the example marks it +invalid once a submit finds it empty. + +```ocaml title="autocomplete_required.mlx" +module S = Solidtype.Solid +module Autocomplete = Solidtype_heroui.Autocomplete +module Button = Solidtype_heroui.Button +module Empty_state = Solidtype_heroui.Empty_state +module Field_error = Solidtype_heroui.Field_error +module Form = Solidtype_heroui.Form +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box +module Search_field = Solidtype_heroui.Search_field + +external prevent_default : Dom.event -> unit = "preventDefault" [@@mel.send] +external alert : string -> unit = "alert" [@@mel.scope "window"] + +let make () = + let state, set_state = S.create_signal [||] in + (* A required autocomplete shows its error once a submit has been tried, as + the browser's validation React Aria reads does. *) + let tried, set_tried = S.create_signal false in + let missing () = S.get tried && Array.length (S.get state) = 0 in +
+ prevent_default e; + S.set set_tried true; + if Array.length (S.get state) > 0 then + alert "Form submitted successfully!")> + + + + + + + + + + + + + + + + + + "No results found")> + + "Florida" + + + "Delaware" + + + "California" + + + "Texas" + + + "New York" + + + "Washington" + + + + + "Please select an item in the list." + + +
+``` + +### Disabled + +```ocaml title="autocomplete_disabled.mlx" +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 + +let make () = + + + + + + + + + + + + + + + + + + "No results found")> + + "Florida" + + + "Delaware" + + + "California" + + + "Texas" + + + "New York" + + + "Washington" + + + + + +``` + +### With Disabled Options + +```ocaml title="autocomplete_with_disabled_options.mlx" +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 + +let make () = + + + + + + + + + + + + + + + + + + "No results found")> + + "Dog" + + + "Cat" + + + "Bird" + + + "Kangaroo" + + + "Elephant" + + + "Tiger" + + + + + +``` + +### Allows Empty Collection + +`allows_empty_collection` lets the list open even when the search shows no +option, as when the list is empty at first or every option is filtered out. + +```ocaml title="autocomplete_allows_empty_collection.mlx" +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 + +let make () = + + + + + + + + + + + + + + + + + + "No results found") + /> + + + +``` + +### With Sections + +```ocaml title="autocomplete_with_sections.mlx" +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 Header = Solidtype_heroui.Header +module Separator = Solidtype_heroui.Separator + +let make () = + + + + + + + + + + + + + + + + + + "No results found")> + +
"North America"
+ + "United States" + + + "Canada" + + + "Mexico" + +
+ + +
"Europe"
+ + "United Kingdom" + + + "France" + + + "Germany" + + + "Spain" + + + "Italy" + +
+ + +
"Asia"
+ + "Japan" + + + "China" + + + "India" + + + "South Korea" + +
+
+
+
+
+``` + +### Multiple Select + +```ocaml title="autocomplete_multiple_select.mlx" +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 + +let make () = + + + + + + + + + + + + + + + + + + "No results found") + selection_mode=`multiple> + + "Florida" + + + "Delaware" + + + "California" + + + "Texas" + + + "New York" + + + "Washington" + + + + + +``` + +### Controlled + +The ids chosen are `value`, an array, as a select's are. + +```ocaml title="autocomplete_controlled.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +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 + +let states = + [| + ("california", "California"); + ("texas", "Texas"); + ("florida", "Florida"); + ("new-york", "New York"); + ("illinois", "Illinois"); + ("pennsylvania", "Pennsylvania"); + |] + +let make () = + let state, set_state = S.create_signal [| "california" |] in + let name () = + match S.get state with + | [| key |] -> ( + match Array.find_opt (fun (id, _) -> String.equal id key) states with + | Some (_, name) -> name + | None -> "None") + | _ -> "None" + in +
+ + + + + + + + + + + + + + + + + + "No results found")> + + (fun (id, name) _ -> + + (Jsx.string name) + ) + + + + + +

(Jsx.string ("Selected: " ^ name ()))

+
+``` + +### Controlled Multiple + +```ocaml title="autocomplete_controlled_multiple.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +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 + +let states = + [| + ("california", "California"); + ("texas", "Texas"); + ("florida", "Florida"); + ("new-york", "New York"); + ("illinois", "Illinois"); + ("pennsylvania", "Pennsylvania"); + |] + +let make () = + let selected, set_selected = S.create_signal [| "california"; "texas" |] in + let names () = + S.get selected |> Array.to_list + |> List.filter_map (fun key -> + Option.map snd + (Array.find_opt (fun (id, _) -> String.equal id key) states)) + in +
+ + + + + + + + + + + + + + + + + + "No results found") + selection_mode=`multiple> + + (fun (id, name) _ -> + + (Jsx.string name) + ) + + + + + +

+ (Jsx.string + ("Selected: " + ^ + match names () with + | [] -> "None" + | names -> String.concat ", " names)) +

+
+``` + +### Controlled Open State + +```ocaml title="autocomplete_controlled_open_state.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Autocomplete = Solidtype_heroui.Autocomplete +module Button = Solidtype_heroui.Button +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 + +let states = + [| + ("florida", "Florida"); + ("delaware", "Delaware"); + ("california", "California"); + ("texas", "Texas"); + ("new-york", "New York"); + ("washington", "Washington"); + |] + +let make () = + let is_open, set_open = S.create_signal false in +
+ + + + + + + + + + + + + + + + + + "No results found")> + + (fun (id, name) _ -> + + (Jsx.string name) + ) + + + + + + +

+ (Jsx.string + ("Autocomplete is " ^ if S.get is_open then "open" else "closed")) +

+
+``` + +### Asynchronous Filtering + +HeroUI's example searches a server for each text typed; here the same names +are searched after the same wait. The filter's `input_value` and +`on_input_change` hold the search's text. + +```ocaml title="autocomplete_asynchronous_filtering.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +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 + +(* The first two pages of https://swapi.py4e.com/api/people/, which HeroUI's + example searches, here searched after the same wait. *) +let characters = + [| + "Luke Skywalker"; + "C-3PO"; + "R2-D2"; + "Darth Vader"; + "Leia Organa"; + "Owen Lars"; + "Beru Whitesun lars"; + "R5-D4"; + "Biggs Darklighter"; + "Obi-Wan Kenobi"; + "Anakin Skywalker"; + "Wilhuff Tarkin"; + "Chewbacca"; + "Han Solo"; + "Greedo"; + "Jabba Desilijic Tiure"; + "Wedge Antilles"; + "Jek Tono Porkins"; + "Yoda"; + "Palpatine"; + |] + +(* How long the fetch it stands in for takes. *) +let load_ms = 400 + +(* Whether [part] is in [name], whatever their case, as the search finds it. *) +let holds ~part name = + let name = String.lowercase_ascii name + and part = String.lowercase_ascii part in + let n = String.length part in + let rec from i = + i + n <= String.length name + && (String.equal (String.sub name i n) part || from (i + 1)) + in + from 0 + +let make () = + let filter_text, set_filter_text = S.create_signal "" in + let found, set_found = S.create_signal characters in + let search text = + S.set set_filter_text text; + let timer = + Js.Global.setTimeout + ~f:(fun () -> + S.set set_found + (Array.of_list + (List.filter + (fun name -> holds ~part:text name) + (Array.to_list characters)))) + load_ms + in + S.on_cleanup (fun () -> Js.Global.clearTimeout timer) + in + + + + + + + + + + + + + + + + + + "No results found")> + + (fun name _ -> + + (Jsx.string name) + ) + + + + + +``` + +### Custom Indicator + +```ocaml title="autocomplete_custom_indicator.mlx" +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 Gravity = Solidtype_gravity_icons + +let make () = + + + + + + + + + + + + + + + + + + + + "No results found")> + + "Florida" + + + "Delaware" + + + "California" + + + "Texas" + + + "New York" + + + "Washington" + + + + + +``` + +### Custom Value + +`Autocomplete.Value`'s children are a function of the ids chosen, drawn +while one is; the autocomplete draws its placeholder while none is. + +```ocaml title="autocomplete_custom_value.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +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 + +type currency = { code : string; id : string; name : string; symbol : string } + +let currencies = + [| + { code = "USD"; id = "usd"; name = "US Dollar"; symbol = "$" }; + { code = "EUR"; id = "eur"; name = "Euro"; symbol = {js|€|js} }; + { code = "GBP"; id = "gbp"; name = "British Pound"; symbol = {js|£|js} }; + { code = "JPY"; id = "jpy"; name = "Japanese Yen"; symbol = {js|¥|js} }; + { code = "CHF"; id = "chf"; name = "Swiss Franc"; symbol = {js|₣|js} }; + |] + +let make () = + + + + + (fun s -> + + (match S.get s.selected_keys with + | [| key |] -> ( + match + Array.find_opt (fun c -> String.equal c.id key) currencies + with + | Some c -> + + (Jsx.string c.symbol) + (Jsx.string c.code) + + (Jsx.string c.name) + + + | None -> Jsx.nothing) + | _ -> Jsx.nothing) + ) + + + + + + + + + + + + + + "No results found")> + + (fun c _ -> + +
+ + (Jsx.string c.name) +
+ +
) +
+
+
+
+
+``` + +### In Surface + +Inside a [`Surface`](surface.md), use `` variant=`secondary `` +for the lower emphasis variant suitable for surface backgrounds. + +```ocaml title="autocomplete_in_surface.mlx" +module S = Solidtype.Solid +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 Surface = Solidtype_heroui.Surface + +let make () = + let selected, set_selected = S.create_signal [||] in + + + + + + + + + + + + + + + + + + + "No results found")> + + "Florida" + + + "Delaware" + + + "California" + + + "Texas" + + + "New York" + + + "Washington" + + + + + + +``` + +### Virtualization + +Autocomplete supports virtualization through a +[`Virtualizer`](list-box.md#virtualizer) around its list, +drawing only the options in view of the popover. The option the keys move to +is scrolled into view. + +```ocaml title="autocomplete_virtualization.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +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 Virtualizer = Solidtype_heroui.Virtualizer +module Users = List_box_virtualization + +(* Whether [part] is in [text], whatever their case, as the search finds it. *) +let holds ~part text = + let text = String.lowercase_ascii text + and part = String.lowercase_ascii part in + let n = String.length part in + let rec from i = + i + n <= String.length text + && (String.equal (String.sub text i n) part || from (i + 1)) + in + from 0 + +let make () = + let selected, set_selected = S.create_signal [||] in + let search, set_search = S.create_signal "" in + let all_users = Users.generate_users 1000 in + let found () = + let part = S.get search in + if String.equal part "" then all_users + else + Js.Array.filter all_users ~f:(fun (u : Users.user) -> + holds ~part u.name || holds ~part u.email) + in + + + + + + + + + + + + + + + + + + + "No results found")> + + (fun (user : Users.user) _ -> + +
+ + (Jsx.string user.email) +
+ +
) +
+
+
+
+
+
+``` + +## Advanced Examples + +### User Selection + +```ocaml title="autocomplete_user_selection.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 + +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 () = + + + + + (fun s -> + + (match S.get s.selected_keys with + | [| key |] -> ( + match + Array.find_opt + (fun (user : user) -> String.equal user.id key) + users + with + | Some user -> +
+ + + + (Jsx.string user.fallback) + + + (Jsx.string user.name) +
+ | None -> Jsx.nothing) + | keys -> + Jsx.string + (string_of_int (Array.length keys) ^ " users selected")) +
) +
+ + +
+ + + + + + + + + + + "No results found")> + + (fun (user : user) _ -> + + + + (Jsx.string user.fallback) + +
+ + (Jsx.string user.email) +
+ +
) +
+
+
+
+
+``` + +### Location Search + +```ocaml title="autocomplete_location_search.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +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 + +type city = { name : string; country : string } + +let cities = + [| + { country = "USA"; name = "New York" }; + { country = "USA"; name = "Los Angeles" }; + { country = "USA"; name = "Chicago" }; + { country = "UK"; name = "London" }; + { country = "France"; name = "Paris" }; + { country = "Japan"; name = "Tokyo" }; + { country = "Australia"; name = "Sydney" }; + { country = "Canada"; name = "Toronto" }; + { country = "Germany"; name = "Berlin" }; + { country = "Spain"; name = "Madrid" }; + |] + +(* How long the search it stands in for takes. *) +let search_ms = 300 + +(* Whether [part] is in [text], whatever their case. *) +let holds ~part text = + let text = String.lowercase_ascii text + and part = String.lowercase_ascii part in + let n = String.length part in + let rec from i = + i + n <= String.length text + && (String.equal (String.sub text i n) part || from (i + 1)) + in + from 0 + +let make () = + let selected, set_selected = S.create_signal [||] in + let loading, set_loading = S.create_signal false in + (* HeroUI's example stands in for a search that takes a while. *) + let filter text typed = + String.equal typed "" + || + (S.set set_loading true; + let (_ : Js.Global.timeoutId) = + Js.Global.setTimeout ~f:(fun () -> S.set set_loading false) search_ms + in + holds ~part:typed text) + in + + + + + + + + + + + + + + + + + + + (Jsx.string + (if S.get loading then "Searching..." + else "No cities found")) + )> + + (fun city _ -> + +
+ + (Jsx.string city.country) +
+ +
) +
+
+
+
+
+``` + +### User Selection Multiple, Tag Group Selection, Email Recipients + +These draw the options chosen as tags, with HeroUI's TagGroup, which is not +ported yet. + +## 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. + +### Global CSS + +HeroUI's classes are global, so a stylesheet restyles every one, as with +HeroUI in React: + +```css +@layer components { + .autocomplete__trigger { + @apply rounded-lg border border-border bg-surface; + } + + .autocomplete__popover { + @apply rounded-xl; + } +} +``` + +## Styling Reference + +### CSS Classes + +- `.autocomplete` - Base autocomplete container +- `.autocomplete__trigger` - The button that triggers the autocomplete +- `.autocomplete__value` - The displayed value or placeholder +- `.autocomplete__clear-button` - The clear button that removes the selected + value +- `.autocomplete__indicator` - The dropdown indicator icon +- `.autocomplete__popover` - The popover container +- `.autocomplete--primary` - Primary variant with shadow (default) +- `.autocomplete--secondary` - Secondary variant without shadow, suitable for + use in surfaces +- `.autocomplete--full-width` - Full width modifier + +### Interactive States + +- **Open**: `[data-open="true"]` on the autocomplete and its indicator +- **Focus**: `[data-focused="true"]` on the autocomplete while its button has + the focus; `[data-focus-within="true"]` on its trigger +- **Hover**: `[data-hovered="true"]` on the trigger +- **Placeholder**: `[data-placeholder="true"]` on the value +- **Empty**: `[data-empty="true"]` on the clear button +- **Invalid**, **Disabled**, **Required**: `[data-invalid="true"]`, + `[data-disabled="true"]`, `[data-required="true"]` on the autocomplete +- **Entering** and **Exiting**: `[data-entering="true"]`, + `[data-exiting="true"]` on the popover + +## API Reference + +Each prop beside the name HeroUI's React component gives it. + +### Autocomplete + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `placeholder` | `placeholder` | `string` | `"Select an item"` | Temporary text that occupies the autocomplete when it is empty | +| `selectionMode` | `selection_mode` | `` `single `` \| `` `multiple `` | `` `single `` | Whether single or multiple selection is enabled, read as it is made | +| `value` | `value` | `string array` | | Current value (controlled) | +| `defaultValue` | `default_value` | `string array` | | Default value (uncontrolled) | +| `onChange` | `on_change` | `string array -> unit` | | Handler called when the value changes | +| `onClear` | `on_clear` | `unit -> unit` | | Told as it is cleared | +| `disabledKeys` | `disabled_keys` | `string array` | | Keys of disabled items | +| `isOpen` | `is_open` | `bool` | | Sets the open state of the popover (controlled) | +| `defaultOpen` | `default_open` | `bool` | `false` | Sets the default open state of the popover (uncontrolled) | +| `onOpenChange` | `on_open_change` | `bool -> unit` | | Handler called when the open state changes | +| `allowsEmptyCollection` | `allows_empty_collection` | `bool` | `false` | Whether the autocomplete allows an empty collection. When true, the list opens even with no items. | +| `isDisabled` | `is_disabled` | `bool` | `false` | Whether the autocomplete is disabled | +| `isRequired` | `is_required` | `bool` | `false` | Whether user input is required | +| `isInvalid` | `is_invalid` | `bool` | `false` | Whether the autocomplete value is invalid | +| `name` | `name` | `string` | | The name of the input, used when submitting an HTML form | +| `fullWidth` | `full_width` | `bool` | `false` | Whether the autocomplete should take full width of its container | +| `variant` | `variant` | `` `primary `` \| `` `secondary `` | `` `primary `` | Visual variant of the component. `` `primary `` is the default style with shadow. `` `secondary `` is a lower emphasis variant without shadow, suitable for use in surfaces. | +| `className` | `class_` | `string` | | Added after HeroUI's classes | +| `children` | `children` | elements | | Its label, trigger, description and popover | + +### Autocomplete.Filter + +| React | solidtype | Type | Description | +|---|---|---|---| +| `filter` | `filter` | `string -> string -> bool` | Custom filter function, given an option's text and the search's; by default, whether the option's text contains the search's, whatever its case or accents | +| `inputValue` | `input_value` | `string` | Controlled input value | +| `onInputChange` | `on_input_change` | `string -> unit` | Handler called when input value changes | +| `children` | `children` | elements | Filter content (`Search_field` and `List_box`) | + +### Autocomplete.Trigger, Autocomplete.Popover, Autocomplete.Indicator, Autocomplete.Clear_button + +| React | solidtype | Type | Description | +|---|---|---|---| +| `placement` | `placement` | `` `top `` \| `` `bottom `` \| `` `left `` \| `` `right `` | 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; the indicator's own icon | +| `onClick` | `on_click` | `Dom.mouseEvent -> unit` | The clear button's, called after it clears | + +### Autocomplete.Value + +| React | solidtype | Type | Description | +|---|---|---|---| +| `className` | `class_` | `string` | Added after HeroUI's classes | +| `children` | `children` | `string array accessor -> element` | What it draws while something is chosen, given the ids chosen | + +## Accessibility + +The Autocomplete implements the ARIA combobox pattern with a filtered list and +provides: + +- Full keyboard navigation support: a press on the trigger, or Enter, Space or + an arrow on its indicator, opens the list and focuses the search; the arrows + move through the options while the focus stays in the search +- Proper focus management: in a choice of one, choosing closes the list and + returns the focus to the indicator +- Support for disabled states +- Search functionality with filtering, whatever the text's case or accents, + or by the filter given; the search starts empty each time the list opens +- HTML form integration through `name` diff --git a/agents/pages/heroui/avatar-group.md b/agents/pages/heroui/avatar-group.md new file mode 100644 index 00000000..e497c47b --- /dev/null +++ b/agents/pages/heroui/avatar-group.md @@ -0,0 +1,479 @@ +# AvatarGroup + +Display a stacked or grid group of avatars with overflow counting. + +Original HeroUI documentation: [AvatarGroup](https://heroui.com/en/docs/react/components/avatar-group). + +## Usage + +```ocaml title="avatar_group_usage.mlx" +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Avatar = Solidtype_heroui.Avatar +module Avatar_group = Solidtype_heroui.Avatar_group + +let users = + [| + ( "John Doe", + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/blue.jpg" + ); + ( "Kate Wilson", + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/green.jpg" + ); + ( "Emily Chen", + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/purple.jpg" + ); + ( "Michael Brown", + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/orange.jpg" + ); + ( "Olivia Davis", + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/red.jpg" ); + |] + +(* "John Doe" is "JD". *) +let initials name = + String.split_on_char ' ' name + |> List.filter_map (fun word -> + if String.length word > 0 then Some (String.make 1 word.[0]) else None) + |> String.concat "" + +let make () = + + + (fun (name, image) _ -> + + + (Jsx.string (initials name)) + ) + + +``` + +## Parity + +The same HeroUI AvatarGroup twice, under the same props: in solidtype on the +left, in React on the right. Below them, every attribute of the two groups: a +marked row is one they disagree on. + +## Anatomy + +```ocaml + + + + "AL" + + "+3" + +``` + +`Avatar_group.Count` is an optional explicit child. + +## Examples + +### Max + +`max` shows the first avatars and counts the rest. + +```ocaml title="avatar_group_max.mlx" +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Avatar = Solidtype_heroui.Avatar +module Avatar_group = Solidtype_heroui.Avatar_group + +let users = + [| + ( "John Doe", + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/blue.jpg" + ); + ( "Kate Wilson", + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/green.jpg" + ); + ( "Emily Chen", + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/purple.jpg" + ); + ( "Michael Brown", + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/orange.jpg" + ); + ( "Olivia Davis", + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/red.jpg" ); + |] + +(* "John Doe" is "JD". *) +let initials name = + String.split_on_char ' ' name + |> List.filter_map (fun word -> + if String.length word > 0 then Some (String.make 1 word.[0]) else None) + |> String.concat "" + +let make () = + + + (fun (name, image) _ -> + + + (Jsx.string (initials name)) + ) + + +``` + +### With Count + +For a total the page knows, an `Avatar_group.Count` of its own: the group +counts none itself, and shows it whatever its `max`. + +```ocaml title="avatar_group_count.mlx" +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Avatar = Solidtype_heroui.Avatar +module Avatar_group = Solidtype_heroui.Avatar_group + +let users = + [| + ( "John Doe", + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/blue.jpg" + ); + ( "Kate Wilson", + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/green.jpg" + ); + ( "Emily Chen", + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/purple.jpg" + ); + ( "Michael Brown", + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/orange.jpg" + ); + ( "Olivia Davis", + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/red.jpg" ); + |] + +(* "John Doe" is "JD". *) +let initials name = + String.split_on_char ' ' name + |> List.filter_map (fun word -> + if String.length word > 0 then Some (String.make 1 word.[0]) else None) + |> String.concat "" + +let make () = + let total = 12 in + + + (fun (name, image) _ -> + + + (Jsx.string (initials name)) + ) + + + (Jsx.string ("+" ^ string_of_int (total - 3))) + + +``` + +### Sizes + +```ocaml title="avatar_group_sizes.mlx" +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Avatar = Solidtype_heroui.Avatar +module Avatar_group = Solidtype_heroui.Avatar_group + +let users = + [| + ( "John Doe", + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/blue.jpg" + ); + ( "Kate Wilson", + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/green.jpg" + ); + ( "Emily Chen", + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/purple.jpg" + ); + ( "Michael Brown", + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/orange.jpg" + ); + ( "Olivia Davis", + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/red.jpg" ); + |] + +(* "John Doe" is "JD". *) +let initials name = + String.split_on_char ' ' name + |> List.filter_map (fun word -> + if String.length word > 0 then Some (String.make 1 word.[0]) else None) + |> String.concat "" + +let make () = +
+
+

"Small"

+ + + (fun (name, image) _ -> + + + (Jsx.string (initials name)) + ) + + +
+
+

"Medium (default)"

+ + + (fun (name, image) _ -> + + + (Jsx.string (initials name)) + ) + + +
+
+

"Large"

+ + + (fun (name, image) _ -> + + + (Jsx.string (initials name)) + ) + + +
+
+``` + +### Grid + +```ocaml title="avatar_group_grid.mlx" +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Avatar = Solidtype_heroui.Avatar +module Avatar_group = Solidtype_heroui.Avatar_group + +let users = + [| + ( "John Doe", + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/blue.jpg" + ); + ( "Kate Wilson", + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/green.jpg" + ); + ( "Emily Chen", + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/purple.jpg" + ); + ( "Michael Brown", + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/orange.jpg" + ); + ( "Olivia Davis", + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/red.jpg" ); + |] + +(* "John Doe" is "JD". *) +let initials name = + String.split_on_char ' ' name + |> List.filter_map (fun word -> + if String.length word > 0 then Some (String.make 1 word.[0]) else None) + |> String.concat "" + +let make () = + + + (fun (name, image) _ -> + + + (Jsx.string (initials name)) + ) + + +``` + +### Overlap + +`` `clip ``, the default, leaves a crescent seam between avatars, and +`` `ring `` a solid outline; neither applies to a grid. + +```ocaml title="avatar_group_overlap.mlx" +module Avatar = Solidtype_heroui.Avatar +module Avatar_group = Solidtype_heroui.Avatar_group + +let group overlap = + + + + "JD" + + "AB" + + + "EC" + + "SM" + "+2" + + +(* A striped backdrop, which shows the seam each overlap leaves. *) +let backdrop child = +
+
+
child
+
+ +let make () = +
+
+

"clip"

(backdrop (group `clip)) +
+
+

"ring"

(backdrop (group `ring)) +
+
+``` + +## Counting + +Avatars are counted in the order they were made: an avatar a `For` adds later +is counted after the others, wherever it is shown. + +## Customization + +### Tailwind CSS + +`class_` is added after HeroUI's classes; a group that means something, as +assignees do, takes a role and a name. + +```ocaml title="avatar_group_tailwind.mlx" +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Avatar = Solidtype_heroui.Avatar +module Avatar_group = Solidtype_heroui.Avatar_group + +let users = + [| + ( "John Doe", + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/blue.jpg" + ); + ( "Kate Wilson", + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/green.jpg" + ); + ( "Emily Chen", + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/purple.jpg" + ); + ( "Michael Brown", + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/orange.jpg" + ); + ( "Olivia Davis", + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/red.jpg" ); + |] + +(* "John Doe" is "JD". *) +let initials name = + String.split_on_char ' ' name + |> List.filter_map (fun word -> + if String.length word > 0 then Some (String.make 1 word.[0]) else None) + |> String.concat "" + +let make () = +
+ + + (fun (name, image) _ -> + + + (Jsx.string (initials name)) + ) + + + "3 assignees" +
+``` + +### Global CSS + +HeroUI's classes are global, so a stylesheet restyles every group, as with +HeroUI in React. The overlap is `--avatar-group-overlap`, `0.5rem` by +default, and the seam `--avatar-group-seam`. + +## Styling Reference + +### CSS Classes + +- `.avatar-group` - Base avatar group container +- `.avatar-group--grid` - Grid layout modifier (no overlap) +- `.avatar-group--clip` - Transparent seam tracing the next avatar's outline + (default stacked overlap) +- `.avatar-group--ring` - Solid box-shadow outline via `--background` +- `.avatar-group__count` - Overflow count avatar + +Stacked layout uses negative margin between siblings +(`--avatar-group-overlap`, default `0.5rem`). Clip mode masks overlapped +avatars (not the last child or the count); the seam follows the avatar's own +`--avatar-radius`, so a themed `--radius` reshapes avatars and seams together. +Ring mode uses a thin box-shadow outline via `--background`. + +## API Reference + +Each prop beside the name HeroUI's React component gives it. + +### AvatarGroup + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `size` | `size` | `` [ `sm \| `md \| `lg ] `` | `` `md `` | Size applied to child avatars (and the overflow count) when they omit `size` | +| `color` | `color` | `` [ `default \| `accent \| `success \| `warning \| `danger ] `` | | Color applied to child avatars (and the overflow count) when they omit `color` | +| `variant` | `variant` | `` [ `default \| `soft ] `` | | Variant applied to child avatars (and the overflow count) when they omit `variant` | +| `max` | `max` | `int` | | Maximum number of avatar children to render; omit to show all | +| `isGrid` | `is_grid` | `bool` | `false` | Whether to use a wrapping grid layout without overlap | +| `overlap` | `overlap` | `` [ `clip \| `ring ] `` | `` `clip `` | Stacked overlap style: transparent seam (default) or box-shadow ring; ignored when `is_grid` | +| `role` | `role` | `Solidtype.Html.Div.role` | | Its role, `` `group `` where it means something | +| `aria-label` | `aria_label` | `string` | | Its name | +| `aria-labelledby` | `aria_labelledby` | `string` | | The id of what names it | +| `className` | `class_` | `string` | | Added after HeroUI's classes | +| `children` | `children` | elements | | Avatar components (and optional `Avatar_group.Count`) to group together | + +### AvatarGroup.Count + +The overflow indicator, an avatar with a fallback. Not truncated by `max`. + +| React | solidtype | Type | Description | +|---|---|---|---| +| `size` | `size` | `` [ `sm \| `md \| `lg ] `` | Override size from the group | +| `color` | `color` | `` [ `default \| `accent \| `success \| `warning \| `danger ] `` | Override color from the group | +| `variant` | `variant` | `` [ `default \| `soft ] `` | Override variant from the group | +| `className` | `class_` | `string` | Added after HeroUI's classes | +| `children` | `children` | elements | Count content (e.g. `"+3"`) | + +## Note + +- `Avatar_group` passes `size`, `color` and `variant` to every `Avatar` inside + it that sets none itself +- `max` truncates visible avatars when set and auto-counts the rest; omit it + to show all +- For a known total (e.g. from the server), add an explicit + `Avatar_group.Count`: it is not truncated by `max` and suppresses the auto + count +- `is_grid` disables overlap and uses a wrapping grid layout instead +- `overlap` defaults to `` `clip `` (transparent seam); use `` `ring `` for the + solid outline; no effect with `is_grid` +- No role by default: when the stack is meaningful (assignees, viewers), pass + `` role=`group `` with `aria_label` or `aria_labelledby` diff --git a/agents/pages/heroui/avatar.md b/agents/pages/heroui/avatar.md new file mode 100644 index 00000000..29ccc311 --- /dev/null +++ b/agents/pages/heroui/avatar.md @@ -0,0 +1,402 @@ +# Avatar + +Display user profile images with customizable fallback content. + +Original HeroUI documentation: [Avatar](https://heroui.com/en/docs/react/components/avatar). + +## Usage + +```ocaml title="avatar_usage.mlx" +module Avatar = Solidtype_heroui.Avatar + +let make () = +
+ + + "JD" + + + + "B" + + "JR" +
+``` + +## Parity + +The same HeroUI Avatar twice, under the same props: in solidtype on the left, +in React on the right. Below them, every attribute of the two avatars: a +marked row is one they disagree on. + +## Anatomy + +```ocaml + + + "AL" + +``` + +`Avatar.Image` shows once its image has loaded, and `Avatar.Fallback` until +then, or where it fails to load. + +## Examples + +### Sizes + +```ocaml title="avatar_sizes.mlx" +module Avatar = Solidtype_heroui.Avatar + +let make () = +
+ + + "SM" + + + + "MD" + + + + "LG" + +
+``` + +### Colors + +```ocaml title="avatar_colors.mlx" +module Avatar = Solidtype_heroui.Avatar + +let make () = +
+ "DF" + "AC" + "SC" + "WR" + "DG" +
+``` + +### Variants + +```ocaml title="avatar_variants.mlx" +module Avatar = Solidtype_heroui.Avatar +module Separator = Solidtype_heroui.Separator +module Gravity = Solidtype_gravity_icons + +let make () = +
+
+
+
+ "accent" +
+
+ "default" +
+
+ "success" +
+
+ "warning" +
+
+ "danger" +
+
+ +
+
"letter"
+
+ "AG" +
+
+ "AG" +
+
+ "AG" +
+
+ "AG" +
+
+ "AG" +
+
+
+
"letter soft"
+
+ + "AG" + +
+
+ + "AG" + +
+
+ + "AG" + +
+
+ + "AG" + +
+
+ + "AG" + +
+
+
+
"icon"
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+
+
"icon soft"
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+
+
"img"
+
+ + + "A" + +
+
+ + + "D" + +
+
+ + + "S" + +
+
+ + + "W" + +
+
+ + + "D" + +
+
+
+``` + +### Fallback Content + +The avatar's `fallback_delay`, in milliseconds, delays the fallback to prevent +a flash while the image loads. + +```ocaml title="avatar_fallback.mlx" +module Avatar = Solidtype_heroui.Avatar +module Gravity = Solidtype_gravity_icons + +let make () = +
+ "JD" + + + + "NA" + + + + "GB" + + +
+``` + +### Not yet + +HeroUI's Custom Image Component example composes a custom image component; +here `Avatar.Image` takes `as_`, as +[Composition](composition.md#custom-dom-element) shows. + +## Customization + +### Tailwind CSS + +`class_` is added after HeroUI's classes, on the avatar and on each part. + +```ocaml title="avatar_tailwind.mlx" +module Avatar = Solidtype_heroui.Avatar + +let make () = + + + "JD" + +``` + +### Global CSS + +HeroUI's classes are global, so a stylesheet restyles every avatar, as with +HeroUI in React: + +```css +@layer components { + .avatar { + @apply size-16 border-2 border-accent; + } + + .avatar__fallback { + @apply bg-gradient-to-br from-purple-500 to-pink-500; + } +} +``` + +## Styling Reference + +### CSS Classes + +- `.avatar` - Base container with default size (size-10) +- `.avatar__image` - Image element with aspect-square sizing +- `.avatar__fallback` - Fallback container with centered content +- `.avatar--sm` - Small avatar (size-8) +- `.avatar--md` - Medium avatar (default, no additional styles) +- `.avatar--lg` - Large avatar (size-12) +- `.avatar--soft` - Soft variant with lighter background +- `.avatar__fallback--default` - Default text color +- `.avatar__fallback--accent` - Accent text color +- `.avatar__fallback--success` - Success text color +- `.avatar__fallback--warning` - Warning text color +- `.avatar__fallback--danger` - Danger text color + +## API Reference + +Each prop beside the name HeroUI's React component gives it. + +### Avatar + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `size` | `size` | `` [ `sm \| `md \| `lg ] `` | `` `md `` | Avatar size | +| `color` | `color` | `` [ `default \| `accent \| `success \| `warning \| `danger ] `` | `` `default `` | Fallback color theme | +| `variant` | `variant` | `` [ `default \| `soft ] `` | `` `default `` | Visual style variant | +| `Avatar.Fallback`'s `delayMs` | `fallback_delay` | `float` | | Delay before showing fallback (prevents flash) | +| `className` | `class_` | `string` | | Added after HeroUI's classes | +| `children` | `children` | elements | | Its image and fallback | + +### Avatar.Image + +| React | solidtype | Type | Description | +|---|---|---|---| +| `src` | `src` | `string` | Image source URL | +| `alt` | `alt` | `string` | Alternative text for the image | +| `srcSet` | `srcset` | `string` | The image `srcset` attribute for responsive images | +| `sizes` | `sizes` | `string` | The image `sizes` attribute for responsive images | +| `crossOrigin` | `crossorigin` | `` [ `anonymous \| `use_credentials ] `` | CORS setting for the image request | +| `loading` | `loading` | `string` | Native lazy loading attribute, `"lazy"` or `"eager"` | +| `className` | `class_` | `string` | Added after HeroUI's class | +| `onLoad`, `onError` | — | | Not yet | +| `asChild` | `as_` | a function of its props | Draws another element in its place | + +### Avatar.Fallback + +| React | solidtype | Type | Description | +|---|---|---|---| +| `color` | `color` | `` [ `default \| `accent \| `success \| `warning \| `danger ] `` | Override color from parent | +| `className` | `class_` | `string` | Added after HeroUI's class | +| `children` | `children` | elements | Initials or an icon | diff --git a/agents/pages/heroui/badge.md b/agents/pages/heroui/badge.md new file mode 100644 index 00000000..71cf9de3 --- /dev/null +++ b/agents/pages/heroui/badge.md @@ -0,0 +1,338 @@ +# Badge + +Displays a small indicator positioned relative to another element, commonly used for notification counts, status dots, and labels. + +Original HeroUI documentation: [Badge](https://heroui.com/en/docs/react/components/badge). + +## Usage + +```ocaml title="badge_usage.mlx" +module Avatar = Solidtype_heroui.Avatar +module Badge = Solidtype_heroui.Badge + +let avatars = "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/" + +let make () = +
+ + + + "JD" + + "5" + + + + + "AB" + + "New" + + + + + "CD" + + + +
+``` + +## Parity + +The same HeroUI Badge twice, under the same props: in solidtype on the left, +in React on the right. Below them, every attribute of the two badges: a +marked row is one they disagree on, and a dimmed row is a framework's own, +which no style reads. + +## Anatomy + +```ocaml + + + "5" + +``` + +Badge is designed to be positioned relative to another element using +`Badge.Anchor`. Plain-text children are automatically wrapped in +`Badge.Label`. + +For standalone label usage, use the [Chip](chip.md) component +instead. + +## Examples + +### Variants + +```ocaml title="badge_variants.mlx" +module Avatar = Solidtype_heroui.Avatar +module Badge = Solidtype_heroui.Badge +module Separator = Solidtype_heroui.Separator + +let avatar = + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/green.jpg" + +let colors = [| `accent; `default; `success; `warning; `danger |] + +let row ~name ~variant = +
+

+ (Solidtype.Jsx.string name) +

+
+ + (fun color _ -> + + + + "JD" + + "5" + ) + +
+
+ +let make () = +
+ (row ~name:"primary" ~variant:`primary) + + (row ~name:"secondary" ~variant:`secondary) + + (row ~name:"soft" ~variant:`soft) +
+``` + +### Sizes + +```ocaml title="badge_sizes.mlx" +module Avatar = Solidtype_heroui.Avatar +module Badge = Solidtype_heroui.Badge + +let avatar = + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/green.jpg" + +let make () = +
+ + (fun size _ -> + + + "JD" + + "5" + ) + +
+``` + +### Colors + +```ocaml title="badge_colors.mlx" +module Avatar = Solidtype_heroui.Avatar +module Badge = Solidtype_heroui.Badge + +let avatar = + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/green.jpg" + +let make () = +
+ + (fun color _ -> + + + "JD" + + + ) + +
+``` + +### Placements + +```ocaml title="badge_placements.mlx" +module Avatar = Solidtype_heroui.Avatar +module Badge = Solidtype_heroui.Badge + +let avatar = + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/green.jpg" + +let placements = + [| + (`top_right, "top-right"); + (`top_left, "top-left"); + (`bottom_right, "bottom-right"); + (`bottom_left, "bottom-left"); + |] + +let make () = +
+ + (fun (placement, name) _ -> +
+ + + + "JD" + + + + (Solidtype.Jsx.string name) +
) +
+
+``` + +### Dot Badge + +Empty badges act as status indicators, useful for online/offline states or +activity signals. + +```ocaml title="badge_dot.mlx" +module Avatar = Solidtype_heroui.Avatar +module Badge = Solidtype_heroui.Badge + +let avatar = + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/green.jpg" + +let make () = +
+ + (fun color _ -> + + + "JD" + + + ) + +
+``` + +### With Content + +Badge supports text, numbers, and icons as content. When no children are +provided, it renders as a dot indicator. + +```ocaml title="badge_with_content.mlx" +module Avatar = Solidtype_heroui.Avatar +module Badge = Solidtype_heroui.Badge +module Gravity = Solidtype_gravity_icons + +let avatar = + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/green.jpg" + +let anchored badge = + + + "JD" + + (badge ()) + + +let make () = +
+ (anchored (fun () -> "5")) + (anchored (fun () -> "New")) + (anchored (fun () -> "99+")) + (anchored (fun () -> + + + )) +
+``` + +## Customization + +### Tailwind CSS + +`class_` is added after HeroUI's classes. + +```ocaml title="badge_tailwind.mlx" +module Avatar = Solidtype_heroui.Avatar +module Badge = Solidtype_heroui.Badge + +let make () = + + + + "KW" + + + "5" + + +``` + +### Global CSS + +HeroUI's classes are global, so a stylesheet restyles every one, as with +HeroUI in React: + +```css +@layer components { + .badge { + @apply font-bold; + } +} +``` + +## Styling Reference + +### CSS Classes + +- `.badge` - Base badge container styles +- `.badge__label` - Label text slot styles +- `.badge-anchor` - Positioning wrapper for the anchored element +- `.badge--accent` - Accent color variant +- `.badge--danger` - Danger color variant +- `.badge--default` - Default color variant +- `.badge--success` - Success color variant +- `.badge--warning` - Warning color variant +- `.badge--primary` - Primary variant with filled background +- `.badge--secondary` - Secondary variant with default background +- `.badge--soft` - Soft variant with lighter background +- `.badge--sm` - Small size +- `.badge--md` - Medium size (default) +- `.badge--lg` - Large size +- `.badge--top-right` - Position at top-right corner (default) +- `.badge--top-left` - Position at top-left corner +- `.badge--bottom-right` - Position at bottom-right corner +- `.badge--bottom-left` - Position at bottom-left corner + +Badges combine variant and color classes (e.g. `.badge--primary.badge--accent` +or `.badge--soft.badge--danger`): each `primary` and `soft` combination has +default styles defined. + +## API Reference + +Each prop beside the name HeroUI's React component gives it. A tag is the +string React takes, a hyphen written as an underscore: `` `top_right `` is +`"top-right"`. + +### Badge + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `color` | `color` | `` [ `accent \| `default \| `success \| `warning \| `danger ] `` | `` `default `` | Color variant of the badge | +| `variant` | `variant` | `` [ `primary \| `secondary \| `soft ] `` | `` `primary `` | Visual style variant | +| `size` | `size` | `` [ `sm \| `md \| `lg ] `` | `` `md `` | Size of the badge | +| `placement` | `placement` | `` [ `top_right \| `top_left \| `bottom_right \| `bottom_left ] `` | `` `top_right `` | Position of the badge relative to its anchor | +| `className` | `class_` | `string` | | Added after HeroUI's classes | +| `children` | `children` | elements | | Content to display inside the badge (text, number, or icon); text becomes a `Badge.Label`. When omitted, renders as a dot. | + +### Badge.Anchor and Badge.Label + +| React | solidtype | Type | Description | +|---|---|---|---| +| `className` | `class_` | `string` | Added after HeroUI's class | +| `children` | `children` | elements | The anchor's: the element to anchor the badge to, plus the badge itself. The label's: label text content | diff --git a/agents/pages/heroui/breadcrumbs.md b/agents/pages/heroui/breadcrumbs.md new file mode 100644 index 00000000..13ce608d --- /dev/null +++ b/agents/pages/heroui/breadcrumbs.md @@ -0,0 +1,210 @@ +# Breadcrumbs + +Navigation breadcrumbs showing the current page's location within a hierarchy. + +Original HeroUI documentation: [Breadcrumbs](https://heroui.com/en/docs/react/components/breadcrumbs). + +## Usage + +```ocaml title="breadcrumbs_usage.mlx" +module Breadcrumbs = Solidtype_heroui.Breadcrumbs + +let make () = + + "Home" + "Products" + "Electronics" + "Laptop" + +``` + +## Parity + +The same HeroUI Breadcrumbs twice, under the same props: in solidtype on the +left, in React on the right. Below them, every attribute of the first link of +each: a marked row is one they disagree on, and a dimmed row is a framework's +own, which no style reads. + +## Anatomy + +```ocaml + + "Home" + "Category" + "Current Page" + +``` + +## Examples + +### Navigation Levels + +```ocaml title="breadcrumbs_level2.mlx" +module Breadcrumbs = Solidtype_heroui.Breadcrumbs + +let make () = + + "Home" + "Current Page" + +``` + +```ocaml title="breadcrumbs_level3.mlx" +module Breadcrumbs = Solidtype_heroui.Breadcrumbs + +let make () = + + "Home" + "Category" + "Current Page" + +``` + +### Disabled State + +```ocaml title="breadcrumbs_disabled.mlx" +module Breadcrumbs = Solidtype_heroui.Breadcrumbs + +let make () = + + "Home" + "Products" + "Electronics" + "Laptop" + +``` + +### Custom Separator + +`separator` is drawn between items in place of the chevron, in a 12-pixel +square hidden from a reader. An icon fills it with `size-full`. + +```ocaml title="breadcrumbs_custom_separator.mlx" +module Breadcrumbs = Solidtype_heroui.Breadcrumbs + +let make () = + + + )> + "Home" + "Products" + "Electronics" + "Laptop" + +``` + +### Render Function + +HeroUI's `render` is `as_`, on the trail and on each item, as +[Composition](composition.md#custom-dom-element) shows. + +## Customization + +### Tailwind CSS + +`class_` is added after HeroUI's classes: the trail's on its list, an item's +on its `
  • `. + +```ocaml title="breadcrumbs_tailwind.mlx" +module Breadcrumbs = Solidtype_heroui.Breadcrumbs + +let make () = + + + "Home" + + + "Products" + + + "Laptop" + + +``` + +### Global CSS + +HeroUI's classes are global, so a stylesheet restyles every one, as with +HeroUI in React: + +```css +@layer components { + .breadcrumbs { + @apply gap-4 text-lg; + } + + .breadcrumbs__link { + @apply font-semibold; + } + + .breadcrumbs__separator { + @apply text-blue-500; + } +} +``` + +## Styling Reference + +### CSS Classes + +- `.breadcrumbs` - Base breadcrumbs container +- `.breadcrumbs__item` - Individual breadcrumb item wrapper +- `.breadcrumbs__link` - Breadcrumb link element +- `.breadcrumbs__separator` - Separator icon between items + +### Interactive States + +- **Current**: `[data-current="true"]` on the link and its item +- **Hover**: `:hover` or `[data-hovered="true"]` on a link +- **Focus**: `[data-focus-visible="true"]` on a link +- **Disabled**: `[aria-disabled="true"]` on a link + +## API Reference + +Each prop beside the name HeroUI's React component gives it. + +### Breadcrumbs + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `separator` | `separator` | element | HeroUI's chevron | Custom separator between breadcrumb items | +| `isDisabled` | `is_disabled` | `bool` | `false` | Whether all breadcrumb links are disabled | +| `onAction` | `on_action` | `string -> unit` | | Told the `id` of an item whose link is pressed | +| `className` | `class_` | `string` | | Added after HeroUI's classes | +| `children` | `children` | elements | | The breadcrumb items | + +### Breadcrumbs.Item + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `id` | `id` | `string` | | What `on_action` is told | +| `href` | `href` | `string` | | The URL to link to (omit for current page) | +| `isDisabled` | `is_disabled` | `bool` | `false` | Whether its link is disabled | +| `className` | `class_` | `string` | | Added after HeroUI's classes | +| `children` | `children` | elements | | Item content | + +## Accessibility + +Breadcrumbs provides: + +- A navigation landmark named "Breadcrumbs" +- Current page indication via `aria-current="page"` +- Keyboard navigation support: each link but the current page's is reached by + Tab + +The last breadcrumb item automatically becomes the current page indicator, +on the server too; an item added later by a `For` becomes it if it is last. + +## Note + +- A context given between `Breadcrumbs` and an item does not reach the + item's children +- An item without an `id` tells `on_action` nothing diff --git a/agents/pages/heroui/button-group.md b/agents/pages/heroui/button-group.md new file mode 100644 index 00000000..d9f62752 --- /dev/null +++ b/agents/pages/heroui/button-group.md @@ -0,0 +1,504 @@ +# ButtonGroup + +Group related buttons together with consistent styling and spacing. + +Original HeroUI documentation: [ButtonGroup](https://heroui.com/en/docs/react/components/button-group). + +## Usage + +HeroUI's examples, with HeroUI's icons from [`solidtype-gravity-icons`](../heroui.md#icons). + +```ocaml title="button_group_usage.mlx" +module Button = Solidtype_heroui.Button +module Button_group = Solidtype_heroui.Button_group +module Chip = Solidtype_heroui.Chip +module Description = Solidtype_heroui.Description +module Dropdown = Solidtype_heroui.Dropdown +module Label = Solidtype_heroui.Label +module Gravity = Solidtype_gravity_icons + +let make () = +
    +
    + + + + + + + + + + "All commits from this branch will be added to the base \ + branch" + + + + + + "The 14 commits from this branch will be combined into one \ + commit in the base branch" + + + + + + "The 14 commits from this branch will be rebased and added \ + to the base branch" + + + + + + +
    +
    +
    + + + + + + + + + + + + + + + + + + + + +
    +
    +
    + + + + +
    +
    + + + + + +
    +
    + + + + + +
    +
    + + + + + + +
    +
    +``` + +## Parity + +The same HeroUI ButtonGroup twice, under the same props: in solidtype on the +left, in React on the right. Below them, every attribute of the two groups: +a marked row is one they disagree on, and a dimmed row is a framework's own -- +Solid's hydration key, React Aria's markers and the id it generates -- which no +style reads. + +## Anatomy + +```ocaml + + + + + +``` + +`Button_group` wraps several `Button`s together, applying consistent +styling, spacing and automatic border radius handling. It passes `size`, +`variant`, `is_disabled` and `full_width` to every button inside it. + +## Examples + +### Variants + +```ocaml title="button_group_variants.mlx" +module Button = Solidtype_heroui.Button +module Button_group = Solidtype_heroui.Button_group + +let group ~label ~variant = +
    +

    (Solidtype.Jsx.string label)

    + + + + + +
    + +let make () = +
    + (group ~label:"Primary" ~variant:`primary) + (group ~label:"Secondary" ~variant:`secondary) + (group ~label:"Tertiary" ~variant:`tertiary) + (group ~label:"Outline" ~variant:`outline) + (group ~label:"Ghost" ~variant:`ghost) + (group ~label:"Danger" ~variant:`danger) +
    +``` + +### Sizes + +```ocaml title="button_group_sizes.mlx" +module Button = Solidtype_heroui.Button +module Button_group = Solidtype_heroui.Button_group + +let group ~label ~size = +
    +

    (Solidtype.Jsx.string label)

    + + + + + +
    + +let make () = +
    + (group ~label:"Small" ~size:`sm) + (group ~label:"Medium (default)" ~size:`md) + (group ~label:"Large" ~size:`lg) +
    +``` + +### Orientation + +`orientation` arranges the buttons horizontally or vertically. + +```ocaml title="button_group_orientation.mlx" +module Button = Solidtype_heroui.Button +module Button_group = Solidtype_heroui.Button_group +module Gravity = Solidtype_gravity_icons + +let group ~label ~orientation = +
    + (Solidtype.Jsx.string label) + + + + + + +
    + +let make () = +
    + (group ~label:"Horizontal" ~orientation:`horizontal) + (group ~label:"Vertical" ~orientation:`vertical) +
    +``` + +### With Icons + +```ocaml title="button_group_icons.mlx" +module Button = Solidtype_heroui.Button +module Button_group = Solidtype_heroui.Button_group +module Gravity = Solidtype_gravity_icons + +let make () = +
    +
    +

    "With icons"

    + + + + + +
    +
    +

    "Icon only buttons"

    + + + + + +
    +
    +``` + +### Full Width + +```ocaml title="button_group_full_width.mlx" +module Button = Solidtype_heroui.Button +module Button_group = Solidtype_heroui.Button_group +module Gravity = Solidtype_gravity_icons + +let make () = +
    + + + + + + + + + + +
    +``` + +### Disabled State + +A button's own `is_disabled` overrides its group's. + +```ocaml title="button_group_disabled.mlx" +module Button = Solidtype_heroui.Button +module Button_group = Solidtype_heroui.Button_group + +let make () = +
    +
    +

    "All buttons disabled"

    + + + + + +
    +
    +

    + "Group disabled, but one button overrides" +

    + + + + + +
    +
    +``` + +### Without Separator + +A button without a `Button_group.Separator` draws no line before it. + +```ocaml title="button_group_without_separator.mlx" +module Button = Solidtype_heroui.Button +module Button_group = Solidtype_heroui.Button_group + +let make () = + + + +``` + +## Customization + +### Tailwind CSS + +`class_` is added after HeroUI's classes, on the group and on each button. + +```ocaml title="button_group_tailwind.mlx" +module Button = Solidtype_heroui.Button +module Button_group = Solidtype_heroui.Button_group +module Description = Solidtype_heroui.Description +module Dropdown = Solidtype_heroui.Dropdown +module Label = Solidtype_heroui.Label +module Gravity = Solidtype_gravity_icons + +let make () = + + + + + + + + + + "All commits from this branch will be added to the base branch" + + + + + + "The 14 commits from this branch will be combined into one \ + commit in the base branch" + + + + + + "The 14 commits from this branch will be rebased and added to \ + the base branch" + + + + + + +``` + +### Global CSS + +HeroUI's classes are global, so a stylesheet restyles every group, as with +HeroUI in React: + +```css +@layer components { + .button-group { + @apply gap-2 rounded-lg; + } + + .button-group__separator { + @apply opacity-25; + } +} +``` + +## Styling Reference + +### CSS Classes + +- `.button-group` - Base button group container +- `.button-group--horizontal`, `.button-group--vertical` - Orientations +- `.button-group--full-width` - Full width modifier +- `.button-group__separator` - Separator element between buttons + +The group applies border radius to its buttons: + +- The first button gets a rounded start edge +- The last button gets a rounded end edge +- Middle buttons have no border radius +- A single button gets full border radius on all edges + +### Interactive States + +- **Disabled**: `[data-disabled="true"]` on the group, while it is disabled + +Each button shows its own state, as `Solidtype_heroui.Button` does. + +## API Reference + +Each prop beside the name HeroUI's React component gives it. + +### ButtonGroup + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `variant` | `variant` | `` [ `primary \| `secondary \| `tertiary \| `outline \| `ghost \| `danger \| `danger_soft ] `` | | Visual style variant applied to all buttons in the group | +| `size` | `size` | `` [ `sm \| `md \| `lg ] `` | | Size applied to all buttons in the group | +| `orientation` | `orientation` | `` [ `horizontal \| `vertical ] `` | `` `horizontal `` | The orientation of the button group | +| `fullWidth` | `full_width` | `bool` | `false` | Whether the button group should take full width of its container | +| `isDisabled` | `is_disabled` | `bool` | `false` | Whether all buttons in the group are disabled (can be overridden on individual buttons) | +| `className` | `class_` | `string` | | Added after HeroUI's classes | +| `children` | `children` | elements | | Button components to group together | + +### ButtonGroup.Separator + +| React | solidtype | Type | Description | +|---|---|---|---| +| `className` | `class_` | `string` | Added after HeroUI's class | + +## Note + +- Every `Button` inside the group takes its `size`, `variant`, `is_disabled` + and `full_width`, a Dropdown's trigger too +- A button's own prop overrides the group's: `is_disabled=false` keeps it + enabled in a disabled group +- Add `` inside each button but the first to show + dividers between buttons +- Buttons in a group have their pressed scale removed for a more cohesive + appearance diff --git a/agents/pages/heroui/button.md b/agents/pages/heroui/button.md new file mode 100644 index 00000000..3f82fee9 --- /dev/null +++ b/agents/pages/heroui/button.md @@ -0,0 +1,259 @@ +# Button + +A clickable button component with multiple variants and states. + +Original HeroUI documentation: [Button](https://heroui.com/en/docs/react/components/button). + +## Usage + +```ocaml title="button_usage.mlx" +module Button = Solidtype_heroui.Button + +let make () = +``` + +## Parity + +The same HeroUI Button twice, under the same props: in solidtype on the +left, in React on the right. Below them, every attribute of the two elements: +a marked row is one they disagree on, and a dimmed row is a framework's own -- +Solid's hydration key, React Aria's markers and the id it generates -- which no +style reads. Hover, focus and press them to see the state each sets. + +## Examples + +### Variants + +```ocaml title="button_variants.mlx" +module Button = Solidtype_heroui.Button + +let make () = +
    + + + + + + + +
    +``` + +### Sizes + +```ocaml title="button_sizes.mlx" +module Button = Solidtype_heroui.Button + +let make () = +
    + + + +
    +``` + +### With Icons + +```ocaml title="button_icons.mlx" +module Gravity = Solidtype_gravity_icons +module Button = Solidtype_heroui.Button + +let make () = +
    + + + +
    +``` + +### Icon Only + +An icon-only button is named by its `aria_label`. + +```ocaml title="button_icon_only.mlx" +module Button = Solidtype_heroui.Button +module Gravity = Solidtype_gravity_icons + +let make () = +
    + + + +
    +``` + +### Loading + +A pending button keeps its focus but takes no press: its click reaches +nothing, a submit button submits nothing, and it is `aria-disabled`. A reader +is told as it starts or stops pending while it has the focus. A function child +is given `is_pending` with the rest of its state. + +```ocaml title="button_loading.mlx" +module Button = Solidtype_heroui.Button +module Spinner = Solidtype_heroui.Spinner + +let make () = + +``` + +### Loading State + +```ocaml title="button_loading_state.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Button = Solidtype_heroui.Button +module Spinner = Solidtype_heroui.Spinner +module Gravity = Solidtype_gravity_icons + +let make () = + let loading, set_loading = S.create_signal false in + let press _ = + S.set set_loading true; + ignore + (Js.Global.setTimeout ~f:(fun () -> S.set set_loading false) 2000 + : Js.Global.timeoutId) + in + +``` + +### Full Width + +```ocaml title="button_full_width.mlx" +module Button = Solidtype_heroui.Button + +let make () = +
    + + +
    +``` + +### Disabled State + +```ocaml title="button_disabled.mlx" +module Button = Solidtype_heroui.Button + +let make () = +
    + + + +
    +``` + +### Render Function + +```ocaml title="button_render_function.mlx" +module Button = Solidtype_heroui.Button +module S = Solidtype.Solid + +let make () = + +``` + +An animated element takes a button's place the same way: see [Composition](composition.md#custom-dom-element). + +## Customization + +### Tailwind CSS + +`class_` is added after HeroUI's classes. + +```ocaml title="button_tailwind.mlx" +module Button = Solidtype_heroui.Button + +let make () = + +``` + +### Global CSS + +HeroUI's classes are global, so a stylesheet restyles every button, as with +HeroUI in React: + +```css +@layer components { + .button { + @apply font-semibold uppercase; + } + + .button--primary { + @apply bg-indigo-600 hover:bg-indigo-700; + } +} +``` + +## Styling Reference + +### CSS Classes + +- `.button` - Base button styles +- `.button--sm` - Small size variant +- `.button--md` - Medium size variant +- `.button--lg` - Large size variant +- `.button--primary`, `.button--secondary`, `.button--tertiary`, + `.button--outline`, `.button--ghost`, `.button--danger`, + `.button--danger-soft` - Variants +- `.button--icon-only`, with `.button--sm` and `.button--lg` - Icon-only + modifier +- `.button--full-width` - Full width modifier + +### Interactive States + +The button supports both CSS pseudo-classes and data attributes for +flexibility: + +- **Hover**: `:hover` or `[data-hovered="true"]`, by a mouse but never a touch +- **Active/Pressed**: `:active` or `[data-pressed="true"]`, by a pointer or by + Enter and Space (includes scale transform) +- **Focus**: `:focus-visible` or `[data-focus-visible="true"]`, only after a + key (shows focus ring) +- **Disabled**: `:disabled` or `[data-disabled="true"]` (reduced opacity, no + pointer events) +- **Pending**: `[data-pending="true"]` (no pointer events during loading) + +## API Reference + +Each prop beside the name HeroUI's React component gives it. A tag is the +string React takes, a hyphen written as an underscore: `` `danger_soft `` is +`"danger-soft"`. + +### Button + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `variant` | `variant` | `` [ `primary \| `secondary \| `tertiary \| `outline \| `ghost \| `danger \| `danger_soft ] `` | `` `primary `` | Visual style variant | +| `size` | `size` | `` [ `sm \| `md \| `lg ] `` | `` `md `` | Size of the button | +| `fullWidth` | `full_width` | `bool` | `false` | Whether the button should take full width of its container | +| `isIconOnly` | `is_icon_only` | `bool` | `false` | Whether the button contains only an icon | +| `isDisabled` | `is_disabled` | `bool` | `false` | Whether the button is disabled | +| `isPending` | `is_pending` | `bool` | `false` | Whether the button is in a loading state: focusable, pressed by nothing, `aria-disabled` | +| `id` | `id` | `string` | | Its id, which names it with its spinner while it is pending | +| `slot` | `slot` | `` [ `trigger \| `close \| `chevron \| `drag \| `increment \| `decrement ] `` | | Makes it a part of what it is in: the trigger of a [`Disclosure.Heading`](disclosure.md), what closes a [Modal](modal.md)'s dialog, what expands or drags a [Table](table.md)'s row, what steps a [NumberField](number-field.md) or [NumberStepper](number-stepper.md) | +| `type` | `type_` | `` [ `button \| `submit \| `reset \| `menu ] `` | `` `button `` | The button's type in a form | +| `aria-label` | `aria_label` | `string` | | Its name where it shows an icon alone | +| `onPress` | `on_click` | `Dom.mouseEvent -> unit` | | Handler called when the button is pressed, by mouse, touch or keyboard | +| `className` | `class_` | `string` | | Added after HeroUI's classes | +| `children` | `children` | elements, or a function of `state` | | Button content or render prop | +| `render` | `as_` | a function of its props and `state` | | Draws another element in its place | diff --git a/agents/pages/heroui/card.md b/agents/pages/heroui/card.md new file mode 100644 index 00000000..b7e04372 --- /dev/null +++ b/agents/pages/heroui/card.md @@ -0,0 +1,549 @@ +# Card + +Flexible container component for grouping related content and actions. + +Original HeroUI documentation: [Card](https://heroui.com/en/docs/react/components/card). + +## Usage + +HeroUI's examples, with HeroUI's icons from [`solidtype-gravity-icons`](../heroui.md#icons). + +```ocaml title="card_usage.mlx" +module Card = Solidtype_heroui.Card +module Link = Solidtype_heroui.Link +module Gravity = Solidtype_gravity_icons + +let make () = + + + + "Become an Acme Creator!" + + "Visit the Acme Creator Hub to sign up today and start earning credits \ + from your fans and followers." + + + + "Creator Hub" + + +``` + +## Parity + +The same HeroUI Card twice, under the same props: in solidtype on the left, in +React on the right. Below them, every attribute of the two cards: a marked row +is one they disagree on. + +## Anatomy + +```ocaml + + + "Title" + "Description" + + "Content" + "Footer" + +``` + +## Examples + +### Variants + +Cards come in semantic variants that describe their prominence level rather +than specific visual styles. This allows themes to interpret them +differently: + +- **`` `transparent ``** - Minimal prominence, transparent background (great + for nested cards) +- **`` `default ``** - Standard card for most use cases (surface-secondary) +- **`` `secondary ``** - Medium prominence to draw moderate attention + (surface-tertiary) +- **`` `tertiary ``** - Higher prominence for important content + (surface-tertiary) + +A card but a transparent one is a [`Surface`](surface.md) to +the components inside it. + +```ocaml title="card_variants.mlx" +module Card = Solidtype_heroui.Card + +let make () = +
    + + + "Transparent" + + "Minimal prominence with transparent background" + + + +

    "Use for less important content or nested cards"

    +
    +
    + + + "Default" + + "Standard card appearance (bg-surface)" + + + +

    "The default card variant for most use cases"

    +
    +
    + + + "Secondary" + + "Medium prominence (bg-surface-secondary)" + + +

    "Use to draw moderate attention"

    +
    + + + "Tertiary" + + "Higher prominence (bg-surface-tertiary)" + + +

    "Use for primary or featured content"

    +
    +
    +``` + +### Horizontal Layout + +```ocaml title="card_horizontal.mlx" +module Button = Solidtype_heroui.Button +module Card = Solidtype_heroui.Card +module Close_button = Solidtype_heroui.Close_button + +let make () = + +
    + Cherries +
    +
    + + "Become an ACME Creator!" + + "Lorem ipsum dolor sit amet consectetur. Sed arcu donec id aliquam \ + dolor sed amet faucibus etiam." + + + + +
    + + "Only 10 spots" + + "Submission ends Oct 10." +
    + +
    +
    +
    +``` + +### With Avatar + +```ocaml title="card_avatar.mlx" +module Avatar = Solidtype_heroui.Avatar +module Card = Solidtype_heroui.Card + +let assets = "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/" + +let community ~image ~alt ~title ~members ~avatar ~avatar_alt ~fallback ~by = + + + + (Solidtype.Jsx.string title) + (Solidtype.Jsx.string members) + + + + + + (Solidtype.Jsx.string fallback) + + + (Solidtype.Jsx.string by) + + + +let make () = +
    + (community ~image:"docs/demo1.jpg" ~alt:"Indie Hackers community" + ~title:"Indie Hackers" ~members:"148 members" ~avatar:"avatars/red.jpg" + ~avatar_alt:"Martha's avatar" ~fallback:"IH" ~by:"By Martha") + (community ~image:"docs/demo2.jpg" ~alt:"AI Builders community" + ~title:"AI Builders" ~members:"362 members" ~avatar:"avatars/blue.jpg" + ~avatar_alt:"John's avatar - blue themed" ~fallback:"B" ~by:"By John") +
    +``` + +### With Images + +```ocaml title="card_images.mlx" +module Avatar = Solidtype_heroui.Avatar +module Button = Solidtype_heroui.Button +module Card = Solidtype_heroui.Card +module Close_button = Solidtype_heroui.Close_button +module Link = Solidtype_heroui.Link +module Gravity = Solidtype_gravity_icons + +let assets = "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/" + +let community ~image ~alt ~fallback ~title ~members ~avatar ~by = + + + + + (Solidtype.Jsx.string fallback) + + + +

    (Solidtype.Jsx.string title)

    +

    (Solidtype.Jsx.string members)

    +
    + + + + (Solidtype.Jsx.string fallback) + +

    (Solidtype.Jsx.string by)

    +
    +
    + +let make () = +
    +
    + +
    + Cherries +
    +
    + + "Become an ACME Creator!" + + "Lorem ipsum dolor sit amet consectetur. Sed arcu donec id \ + aliquam dolor sed amet faucibus etiam." + + + + +
    + + "Only 10 spots" + + "Submission ends Oct 10." +
    + +
    +
    +
    +
    +
    + +
    + +
    + + +
    + + "PAYMENT" + + + "You can now withdraw on crypto" + + + "Add your wallet in settings to withdraw" + +
    +
    + + "Go to settings" + +
    +
    + (community ~image:"docs/demo1.jpg" ~alt:"Demo 1" ~fallback:"JK" + ~title:"Indie Hackers" ~members:"148 members" + ~avatar:"avatars/red.jpg" ~by:"By John") + (community ~image:"docs/demo2.jpg" ~alt:"Demo 2" ~fallback:"AB" + ~title:"AI Builders" ~members:"362 members" + ~avatar:"avatars/blue.jpg" ~by:"By Martha") +
    +
    + + NEO Home Robot + + + "NEO" + + + "Home Robot" + + + +
    +
    + "Available soon" +
    +
    "Get notified"
    +
    + +
    +
    +
    +
    +
    +``` + +### With Form + +```ocaml title="card_form.mlx" +module Button = Solidtype_heroui.Button +module Card = Solidtype_heroui.Card +module Form = Solidtype_heroui.Form +module Input = Solidtype_heroui.Input +module Label = Solidtype_heroui.Label +module Link = Solidtype_heroui.Link +module Text_field = Solidtype_heroui.Text_field + +external prevent_default : Dom.event -> unit = "preventDefault" [@@mel.send] +external alert : string -> unit = "alert" + +let make () = + + + "Login" + + "Enter your credentials to access your account" + + +
    + prevent_default e; + alert "Form submitted successfully!")> + +
    + + + + + + + + +
    +
    + + + "Forgot password?" + +
    +
    +``` + +## Customization + +### Tailwind CSS + +`class_` is added after HeroUI's classes. + +```ocaml title="card_tailwind.mlx" +module Button = Solidtype_heroui.Button +module Card = Solidtype_heroui.Card +module Gravity = Solidtype_gravity_icons + +let make () = + +
    +
    + + + "Recommended" + +
    +
    + +
    +
    + "Upgrade to Pro" + + "Unlock team workflows and insights built for growing products." + +
    +
    +
    + +
      +
    • + + "Unlimited projects and collaborators" +
    • +
    • + + "Priority support with 24h response" +
    • +
    • + + "Advanced analytics and exports" +
    • +
    +
    + + + + + +``` + +### Global CSS + +HeroUI's classes are global, so a stylesheet restyles every card, as with +HeroUI in React: + +```css +@layer components { + .card--secondary { + @apply bg-gradient-to-br from-blue-50 to-purple-50; + } + + .card__title { + @apply text-xl font-bold; + } +} +``` + +## Styling Reference + +### CSS Classes + +- `.card` - Base container with padding and border +- `.card__header` - Header section container +- `.card__title` - Title with base font size and weight +- `.card__description` - Muted description text +- `.card__content` - Flexible content container +- `.card__footer` - Footer with row layout +- `.card--transparent` - Minimal prominence, transparent background +- `.card--default` - Standard appearance with surface-secondary (default) +- `.card--secondary` - Medium prominence with surface-tertiary +- `.card--tertiary` - Higher prominence with surface-tertiary + +## Accessibility + +For semantic markup, a card that stands for an article takes its role and the +title that names it: + +```ocaml + + + "Article Title" + + +``` + +## API Reference + +Each prop beside the name HeroUI's React component gives it. + +### Card + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `variant` | `variant` | `` [ `default \| `secondary \| `tertiary \| `transparent ] `` | `` `default `` | Semantic variant indicating prominence level | +| `role` | `role` | `Solidtype.Html.Div.role` | | Its role, `` `article `` for an article | +| `aria-labelledby` | `aria_labelledby` | `string` | | The id of what names it | +| `className` | `class_` | `string` | | Added after HeroUI's classes | +| `children` | `children` | elements | | Card content | + +### Card.Header, Card.Description, Card.Content, Card.Footer + +| React | solidtype | Type | Description | +|---|---|---|---| +| `className` | `class_` | `string` | Added after HeroUI's class | +| `children` | `children` | elements | Its content: header, description (a `

    `), main or footer content | + +### Card.Title + +| React | solidtype | Type | Description | +|---|---|---|---| +| `id` | `id` | `string` | Its id, for a card it names | +| `className` | `class_` | `string` | Added after HeroUI's class | +| `children` | `children` | elements | Title content (renders as `

    `) | diff --git a/agents/pages/heroui/checkbox-group.md b/agents/pages/heroui/checkbox-group.md new file mode 100644 index 00000000..ce6cda12 --- /dev/null +++ b/agents/pages/heroui/checkbox-group.md @@ -0,0 +1,211 @@ +# CheckboxGroup + +A checkbox group component for managing multiple checkbox selections. + +Original HeroUI documentation: [CheckboxGroup](https://heroui.com/en/docs/react/components/checkbox-group). + +## Usage + +```ocaml title="checkbox_group_usage.mlx" +module Checkbox = Solidtype_heroui.Checkbox +module Checkbox_group = Solidtype_heroui.Checkbox_group +module Description = Solidtype_heroui.Description +module Label = Solidtype_heroui.Label + +let make () = + + + "Choose all that apply" + + + "Coding" + + "Love building software" + + + + "Design" + + "Enjoy creating beautiful interfaces" + + + + "Writing" + + "Passionate about content creation" + + +``` + +## Parity + +The same HeroUI CheckboxGroup twice, under the same props: in solidtype on the +left, in React on the right. Below them, every attribute of the two groups: a +marked row is one they disagree on. + +## Anatomy + +```ocaml + + + "Optional" + + + "Label" + + "Optional per-checkbox help text" + + +``` + +The group's `Label` names it, and its `Description` describes it and each +checkbox. A checkbox's own `Description` describes that checkbox alone. Plain +text in `Checkbox.Content` is the checkbox's clickable label. + +## Examples + +### In Surface + +When used inside a [`Surface`](surface.md), use +`` variant=`secondary `` to apply the lower emphasis variant suitable for +surface backgrounds. Each checkbox takes it. + +```ocaml title="checkbox_group_surface.mlx" +module Checkbox = Solidtype_heroui.Checkbox +module Checkbox_group = Solidtype_heroui.Checkbox_group +module Description = Solidtype_heroui.Description +module Label = Solidtype_heroui.Label +module Surface = Solidtype_heroui.Surface + +let make () = + + + + + + "Email" + + + + + "SMS" + + + + + + "Push notifications" + + + + +``` + +### Disabled + +```ocaml title="checkbox_group_disabled.mlx" +module Checkbox = Solidtype_heroui.Checkbox +module Checkbox_group = Solidtype_heroui.Checkbox_group +module Description = Solidtype_heroui.Description +module Label = Solidtype_heroui.Label + +let make () = + + + "Feature selection is temporarily disabled" + + + "Feature 1" + + "This feature is coming soon" + + + + "Feature 2" + + "This feature is coming soon" + + +``` + +### Controlled + +```ocaml title="checkbox_group_controlled.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Checkbox = Solidtype_heroui.Checkbox +module Checkbox_group = Solidtype_heroui.Checkbox_group +module Description = Solidtype_heroui.Description +module Label = Solidtype_heroui.Label + +let make () = + let selected, set_selected = S.create_signal [ "coding"; "design" ] in + + + + + "Coding" + + + + + "Design" + + + + + "Writing" + + + + +``` + +### Not yet + +HeroUI's Validation example validates the group as its form is submitted, +which is not ported yet; `is_invalid` marks it invalid. + +## Styling Reference + +### CSS Classes + +- `.checkbox-group` - Base checkbox group container +- `.checkbox-group--primary`, `.checkbox-group--secondary` - Variants + +### Interactive States + +- **Disabled**: `[data-disabled="true"]` +- **Invalid**: `[data-invalid="true"]` + +## API Reference + +Each prop beside the name HeroUI's React component gives it. + +### CheckboxGroup + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `variant` | `variant` | `` [ `primary \| `secondary ] `` | `` `primary `` | Its checkboxes' variant, where they set none | +| `value` | `value` | `string list` | | The current selected values (controlled) | +| `defaultValue` | `default_value` | `string list` | `[]` | The default selected values (uncontrolled) | +| `onChange` | `on_change` | `string list -> unit` | | Handler called when the selected values change | +| `isDisabled` | `is_disabled` | `bool` | | Whether the checkbox group is disabled, else as its fieldset is | +| `isInvalid` | `is_invalid` | `bool` | `false` | Whether the checkbox group is in an invalid state | +| `isReadOnly` | `is_read_only` | `bool` | `false` | Whether the checkbox group is read only | +| `isRequired` | `is_required` | `bool` | `false` | Whether the checkbox group is required | +| `name` | `name` | `string` | | The name of the checkbox group, used when submitting an HTML form | +| `className` | `class_` | `string` | | Added after HeroUI's classes | +| `onBlur` | `on_blur` | `Dom.focusEvent -> unit` | | Called once focus leaves it for an element outside it | +| `children` | `children` | elements | | Checkbox group content | diff --git a/agents/pages/heroui/checkbox.md b/agents/pages/heroui/checkbox.md new file mode 100644 index 00000000..51920da9 --- /dev/null +++ b/agents/pages/heroui/checkbox.md @@ -0,0 +1,523 @@ +# Checkbox + +Checkboxes allow users to select multiple items from a list of individual items, or to mark one individual item as selected. + +Original HeroUI documentation: [Checkbox](https://heroui.com/en/docs/react/components/checkbox). + +## Usage + +HeroUI's examples. + +```ocaml title="checkbox_usage.mlx" +module Checkbox = Solidtype_heroui.Checkbox + +let make () = + + + + "Accept terms and conditions" + + +``` + +## Parity + +The same HeroUI Checkbox twice, under the same props: in solidtype on the left, +in React on the right. Below them, every attribute of the two contents: a +marked row is one they disagree on, and a dimmed row is a framework's own, +which no style reads. + +## Anatomy + +```ocaml + + + + "Label" + + "Optional field-level help text" + "Optional validation message" + +``` + +Plain text in `Checkbox.Content` is the clickable label and the checkbox's +accessible name. `Description` and `Field_error` are optional. + +## Examples + +### Variants + +The Checkbox component supports two visual variants: + +- **`` `primary ``** (default) - Standard styling with default background, + suitable for most use cases +- **`` `secondary ``** - Lower emphasis variant, suitable for use in Surface + components + +```ocaml title="checkbox_variants.mlx" +module Checkbox = Solidtype_heroui.Checkbox +module Description = Solidtype_heroui.Description + +let make () = +
    +
    +

    "Primary variant"

    + + + + "Primary checkbox" + + "Standard styling with default background" + +
    +
    +

    "Secondary variant"

    + + + + "Secondary checkbox" + + "Lower emphasis variant for use in surfaces" + +
    +
    +``` + +### Full Rounded + +```ocaml title="checkbox_rounded.mlx" +module Checkbox = Solidtype_heroui.Checkbox +module Label = Solidtype_heroui.Label + +let make () = +
    +
    + + + + + + + "Small size" + + +
    +
    + + + + + + "Default size" + + +
    +
    + + + + + + "Large size" + + +
    +
    + + + + + + "Extra large size" + + +
    +
    +``` + +### Disabled + +```ocaml title="checkbox_disabled.mlx" +module Checkbox = Solidtype_heroui.Checkbox +module Description = Solidtype_heroui.Description + +let make () = + + + + "Premium Feature" + + "This feature is coming soon" + +``` + +### External Label + +The checkbox does not take an `id` yet, so a `Label` outside it cannot name +it: here its `aria_label` says what the label says. + +```ocaml title="checkbox_external_label.mlx" +module Checkbox = Solidtype_heroui.Checkbox +module Label = Solidtype_heroui.Label + +(* HeroUI's label names the checkbox by its id, which the port's checkbox + does not take yet: it is named as the label is. *) +let make () = +
    + + + + + + +
    +``` + +### With Description + +```ocaml title="checkbox_description.mlx" +module Checkbox = Solidtype_heroui.Checkbox +module Description = Solidtype_heroui.Description + +let make () = + + + + "Email notifications" + + + "Get notified when someone mentions you in a comment" + + +``` + +### Default Selected + +```ocaml title="checkbox_default_selected.mlx" +module Checkbox = Solidtype_heroui.Checkbox + +let make () = + + + + "Enable email notifications" + + +``` + +### Invalid + +```ocaml title="checkbox_invalid.mlx" +module Checkbox = Solidtype_heroui.Checkbox +module Field_error = Solidtype_heroui.Field_error + +let make () = + + + + "I agree to the terms" + + "You must accept the terms to continue" + +``` + +### Controlled + +```ocaml title="checkbox_controlled.mlx" +module Checkbox = Solidtype_heroui.Checkbox +module S = Solidtype.Solid + +let make () = + let selected, set_selected = S.create_signal true in +
    + + + + "Email notifications" + + +

    + "Status: " + + (Solidtype.Jsx.string + (if S.get selected then "Enabled" else "Disabled")) + +

    +
    +``` + +### Indeterminate + +```ocaml title="checkbox_indeterminate.mlx" +module Checkbox = Solidtype_heroui.Checkbox +module S = Solidtype.Solid +module Description = Solidtype_heroui.Description + +let make () = + let indeterminate, set_indeterminate = S.create_signal true in + let selected, set_selected = S.create_signal false in + + S.set set_selected v; + S.set set_indeterminate false)> + + "Select all" + + "Shows indeterminate state (dash icon)" + +``` + +### Form Integration + +```ocaml title="checkbox_form.mlx" +module Button = Solidtype_heroui.Button +module Checkbox = Solidtype_heroui.Checkbox + +type form_data + +external prevent_default : Dom.event -> unit = "preventDefault" [@@mel.send] +external target : Dom.event -> Dom.element = "target" [@@mel.get] +external form_data : Dom.element -> form_data = "FormData" [@@mel.new] + +external entries : form_data -> (string * string) array = "from" +[@@mel.scope "Array"] + +external alert : string -> unit = "alert" + +let submit e = + prevent_default e; + let lines = + form_data (target e) + |> entries + |> Array.map (fun (key, value) -> key ^ ": " ^ value) + |> Array.to_list |> String.concat "\n" + in + alert ("Form submitted with:\n" ^ lines) + +let item ?(selected = false) ~name ~text () = + + + + (Solidtype.Jsx.string text) + + + +let make () = +
    +
    + (item ~name:"notifications" ~text:"Enable notifications" ()) + (item ~selected:true ~name:"newsletter" ~text:"Subscribe to newsletter" ()) + (item ~name:"marketing" ~text:"Receive marketing updates" ()) +
    + +
    +``` + +### Render Props + +A function child is given the checkbox's state. + +```ocaml title="checkbox_render_props.mlx" +module Checkbox = Solidtype_heroui.Checkbox +module S = Solidtype.Solid +module Description = Solidtype_heroui.Description + +let make () = + + (fun s -> + Solidtype.Jsx.fragment + [| + + + (Solidtype.Jsx.string + (if S.get s.is_selected then "Terms accepted" else "Accept terms")) + ; + + (Solidtype.Jsx.string + (if S.get s.is_selected then "Thank you for accepting" + else "Please read and accept the terms")) + ; + |]) + +``` + +### Render Function + +`as_` draws another element in its place, given its props and its state, as [Composition](composition.md#custom-dom-element) shows. + +### Custom Indicator + +An icon given to `Checkbox.Indicator` shows only while the box is checked. + +```ocaml title="checkbox_custom_indicator.mlx" +module Checkbox = Solidtype_heroui.Checkbox + +(* HeroUI draws each icon only while the box is checked, by a render prop; + HeroUI's styles show an indicator's content only then, so it is given as it + is. *) +let make () = +
    + + + + + + + + + + "Heart" + + + + + + + + + + + + + "Plus" + + + + + + + + + + + + "Indeterminate" + + +
    +``` + +## Customization + +### Tailwind CSS + +`class_` is added after HeroUI's classes. + +```ocaml title="checkbox_tailwind.mlx" +module Checkbox = Solidtype_heroui.Checkbox + +let make () = + + + + + + "Custom styled checkbox" + + +``` + +### Global CSS + +HeroUI's classes are global, so a stylesheet restyles every one, as with +HeroUI in React: + +```css +@layer components { + .checkbox__control { + @apply rounded-full; + } +} +``` + +## Styling Reference + +### CSS Classes + +- `.checkbox` - Base checkbox container (the field) +- `.checkbox__content` - Clickable label wrapping the control and label text +- `.checkbox__control` - Checkbox control box +- `.checkbox__indicator` - Checkbox checkmark indicator +- `.checkbox--primary`, `.checkbox--secondary` - Variants + +### Interactive States + +The checkbox supports both CSS pseudo-classes and data attributes for +flexibility: + +- **Selected**: `[data-selected="true"]` or `[aria-checked="true"]` (shows + checkmark and background color change) +- **Indeterminate**: `[data-indeterminate="true"]` (shows indeterminate state + with dash) +- **Invalid**: `[data-invalid="true"]` or `[aria-invalid="true"]` (shows error + state with danger colors) +- **Hover**: `:hover` or `[data-hovered="true"]` +- **Focus**: `:focus-visible` or `[data-focus-visible="true"]` (shows focus + ring on control) +- **Disabled**: `[data-disabled="true"]` (reduced opacity, including help + text) +- **Pressed**: `:active` or `[data-pressed="true"]` + +## API Reference + +Each prop beside the name HeroUI's React component gives it. + +### Checkbox + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `variant` | `variant` | `` [ `primary \| `secondary ] `` | `` `primary `` | Visual variant of the component. `` `secondary `` is a lower emphasis variant, suitable for use in surfaces. | +| `isSelected` | `is_selected` | `bool` | | Whether the checkbox is checked (controlled) | +| `defaultSelected` | `default_selected` | `bool` | `false` | Whether the checkbox is checked by default (uncontrolled) | +| `isIndeterminate` | `is_indeterminate` | `bool` | `false` | Whether the checkbox is in an indeterminate state | +| `onChange` | `on_change` | `bool -> unit` | | Handler called when the checkbox value changes | +| `isDisabled` | `is_disabled` | `bool` | `false` | Whether the checkbox is disabled | +| `isInvalid` | `is_invalid` | `bool` | `false` | Whether the checkbox is invalid | +| `className` | `class_` | `string` | | Added after HeroUI's classes | +| `onBlur` | `on_blur` | `Dom.focusEvent -> unit` | | Called once focus leaves it for an element outside it | +| `children` | `children` | elements | | Checkbox content, or a function of its state | +| `isReadOnly` | `is_read_only` | `bool` | `false` | Whether the checkbox is read only | +| `isRequired` | `is_required` | `bool` | `false` | Whether the checkbox must be selected | +| `name` | `name` | `string` | | The name of the input element, used when submitting an HTML form | +| `value` | `value` | `string` | | The value of the input element, used when submitting an HTML form | +| `aria-label` | `aria_label` | `string` | | Its name where no label names it | +| `slot` | `slot` | `` [ `selection ] `` | | The checkbox of the part above it: a table row's, or all of a table's rows in its header | + +### Checkbox.Content, Checkbox.Control and Checkbox.Indicator + +`Checkbox.Content` is the clickable label that wraps the control and label +text. Keep `Description` and `Field_error` as siblings of `Checkbox.Content`. +For a checkbox with no label, pass an `aria_label` on `Checkbox`. + +| React | solidtype | Type | Description | +|---|---|---|---| +| `className` | `class_` | `string` | Added after HeroUI's class | +| `children` | `children` | elements | What it holds; the indicator's own mark when given | diff --git a/agents/pages/heroui/chip.md b/agents/pages/heroui/chip.md new file mode 100644 index 00000000..bde3bc9a --- /dev/null +++ b/agents/pages/heroui/chip.md @@ -0,0 +1,266 @@ +# Chip + +Small informational badges for displaying labels, statuses, and categories. + +Original HeroUI documentation: [Chip](https://heroui.com/en/docs/react/components/chip). + +## Usage + +HeroUI's examples, with HeroUI's icons from [`solidtype-gravity-icons`](../heroui.md#icons). + +```ocaml title="chip_usage.mlx" +module Chip = Solidtype_heroui.Chip + +let make () = +
    + "Default" + "Accent" + "Success" + "Warning" + "Danger" +
    +``` + +## Parity + +The same HeroUI Chip twice, under the same props: in solidtype on the left, +in React on the right. Below them, every attribute of the two chips: a +marked row is one they disagree on, and a dimmed row is a framework's own, +which no style reads. + +## Anatomy + +```ocaml +"Label text" +``` + +Plain-text children are automatically wrapped in `Chip.Label`. + +## Examples + +### Variants + +```ocaml title="chip_variants.mlx" +module Chip = Solidtype_heroui.Chip +module Separator = Solidtype_heroui.Separator +module Gravity = Solidtype_gravity_icons + +let variants = + [| + (`primary, "primary"); + (`secondary, "secondary"); + (`tertiary, "tertiary"); + (`soft, "soft"); + |] + +let colors = + [| + (`accent, "accent"); + (`default, "default"); + (`success, "success"); + (`warning, "warning"); + (`danger, "danger"); + |] + +let cell children = +
    + (children ()) +
    + +let size_block (size, name) = +
    +

    + (Solidtype.Jsx.string name) +

    +
    +
    + + (fun (_, color) _ -> + cell (fun () -> + + (Solidtype.Jsx.string color) + )) + +
    +
    + + (fun (variant, vname) _ -> +
    +
    + (Solidtype.Jsx.string vname) +
    + + (fun (color, _) _ -> + cell (fun () -> + + + "Label" + + )) + +
    ) +
    +
    +
    + +let make () = +
    + (size_block (`lg, "lg")) + + (size_block (`md, "md")) + + (size_block (`sm, "sm")) +
    +``` + +### Statuses + +```ocaml title="chip_statuses.mlx" +module Chip = Solidtype_heroui.Chip +module Gravity = Solidtype_gravity_icons + +let make () = +
    +
    + + "Default" + + + "Active" + + + "Pending" + + + "Inactive" + +
    +
    + + + "New Feature" + + + "Available" + + + + "Beta" + + + "Deprecated" + +
    +
    +``` + +### With Icons + +```ocaml title="chip_icons.mlx" +module Chip = Solidtype_heroui.Chip +module Gravity = Solidtype_gravity_icons + +let make () = +
    + + "Information" + + + + "Completed" + + + "Pending" + + + "Failed" + + + "Label" + +
    +``` + +## Customization + +### Tailwind CSS + +`class_` is added after HeroUI's classes. + +```ocaml title="chip_tailwind.mlx" +module Chip = Solidtype_heroui.Chip + +let make () = +
    + + "Draft" + + + "In review" + + + "Published" + +
    +``` + +### Global CSS + +HeroUI's classes are global, so a stylesheet restyles every one, as with +HeroUI in React: + +```css +@layer components { + .chip { + @apply rounded-md; + } +} +``` + +## Styling Reference + +### CSS Classes + +- `.chip` - Base chip container styles +- `.chip__label` - Label text slot styles +- `.chip--accent` - Accent color variant +- `.chip--danger` - Danger color variant +- `.chip--default` - Default color variant +- `.chip--success` - Success color variant +- `.chip--warning` - Warning color variant +- `.chip--primary` - Primary variant with filled background +- `.chip--secondary` - Secondary variant with border +- `.chip--tertiary` - Tertiary variant with transparent background +- `.chip--soft` - Soft variant with lighter background +- `.chip--sm` - Small size +- `.chip--md` - Medium size +- `.chip--lg` - Large size + +Chips combine variant and color classes (e.g. `.chip--secondary.chip--accent`). +The `primary` and `soft` variants have default styles defined with the +`accent`, `success`, `warning` and `danger` colors; any other combination can +be styled with the `@layer components` directive. + +## API Reference + +Each prop beside the name HeroUI's React component gives it. + +### Chip + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `color` | `color` | `` [ `accent \| `default \| `success \| `warning \| `danger ] `` | `` `default `` | Color variant of the chip | +| `variant` | `variant` | `` [ `primary \| `secondary \| `tertiary \| `soft ] `` | `` `secondary `` | Visual style variant | +| `size` | `size` | `` [ `sm \| `md \| `lg ] `` | none | Size of the chip; none adds no size class | +| `className` | `class_` | `string` | | Added after HeroUI's classes | +| `children` | `children` | elements | | Content to display inside the chip; text becomes a `Chip.Label` | + +### Chip.Label + +| React | solidtype | Type | Description | +|---|---|---|---| +| `className` | `class_` | `string` | Added after HeroUI's class | +| `children` | `children` | elements | Label text content | diff --git a/agents/pages/heroui/close-button.md b/agents/pages/heroui/close-button.md new file mode 100644 index 00000000..7b68f357 --- /dev/null +++ b/agents/pages/heroui/close-button.md @@ -0,0 +1,132 @@ +# CloseButton + +Button component for closing dialogs, modals, or dismissing content. + +Original HeroUI documentation: [CloseButton](https://heroui.com/en/docs/react/components/close-button). + +## Usage + +```ocaml title="close_button_usage.mlx" +module Close_button = Solidtype_heroui.Close_button + +let make () = +``` + +## Parity + +The same HeroUI CloseButton twice, under the same props: in solidtype on the +left, in React on the right. Below them, every attribute of the two elements: +a marked row is one they disagree on, and a dimmed row is a framework's own -- +Solid's hydration key, React Aria's markers and the id it generates -- which no +style reads. Hover, focus and press them to see the state each sets. + +## Examples + +### Interactive + +```ocaml title="close_button_interactive.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Close_button = Solidtype_heroui.Close_button + +let make () = + let count, set_count = S.create_signal 0 in + let times () = string_of_int (S.get count) ^ " times" in +
    + S.set set_count (S.get count + 1)) + /> + + (Jsx.string ("Clicked: " ^ times ())) + +
    +``` + +### With Custom Icon + +Its children take the place of the default close icon. + +```ocaml title="close_button_custom_icon.mlx" +module Close_button = Solidtype_heroui.Close_button +module Gravity = Solidtype_gravity_icons + +let make () = +
    +
    + + "Custom Icon" +
    +
    + + "Alternative Icon" +
    +
    +``` + +## Customization + +### Tailwind CSS + +`class_` is added after HeroUI's classes. + +```ocaml title="close_button_tailwind.mlx" +module Close_button = Solidtype_heroui.Close_button + +let make () = + +``` + +### Global CSS + +HeroUI's classes are global, so a stylesheet restyles every close button, as +with HeroUI in React: + +```css +@layer components { + .close-button { + @apply bg-red-100 text-red-800 hover:bg-red-200; + } + + .close-button--custom { + @apply rounded-full border-2 border-red-300; + } +} +``` + +## Styling Reference + +### CSS Classes + +- `.close-button` - Base component styles +- `.close-button--default` - Default variant + +### Interactive States + +The component supports both CSS pseudo-classes and data attributes for +flexibility, set as a [`Button`](button.md#interactive-states)'s +are: + +- **Hover**: `:hover` or `[data-hovered="true"]` +- **Active/Pressed**: `:active` or `[data-pressed="true"]` +- **Focus**: `:focus-visible` or `[data-focus-visible="true"]` +- **Disabled**: `:disabled` or `[data-disabled="true"]` + +## API Reference + +Each prop beside the name HeroUI's React component gives it. + +### CloseButton + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `variant` | `variant` | `` [ `default ] `` | `` `default `` | Visual variant of the button | +| `isDisabled` | `is_disabled` | `bool` | `false` | Whether the button is disabled | +| `aria-label` | `aria_label` | `string` | `"Close"` | Accessible label for screen readers | +| `onPress` | `on_click` | `Dom.mouseEvent -> unit` | | Handler called when the button is pressed, by mouse, touch or keyboard | +| `className` | `class_` | `string` | | Added after HeroUI's classes | +| `children` | `children` | elements, or a function of `state` | the close icon | Content to display (defaults to close icon) | diff --git a/agents/pages/heroui/color-area.md b/agents/pages/heroui/color-area.md new file mode 100644 index 00000000..db5a6bec --- /dev/null +++ b/agents/pages/heroui/color-area.md @@ -0,0 +1,322 @@ +# ColorArea + +A 2D color picker that allows users to select colors from a gradient area. + +Its value is a `Types.Color.t`, read from any CSS colour by +`Solidtype_kobalte.Colors.parse_color`. + +Original HeroUI documentation: [ColorArea](https://heroui.com/en/docs/react/components/color-area). + +## Usage + +HeroUI's examples. + +```ocaml title="color_area_usage.mlx" +module Color_area = Solidtype_heroui.Color_area +module Colors = Solidtype_kobalte.Colors + +let make () = + + + +``` + +## Parity + +The same HeroUI ColorArea twice, under the same props: in solidtype on the +left, in React on the right. Below them, every attribute of the two areas: a +marked row is one they disagree on. + +The marked row is where each draws the gradient: Kobalte on a part of its own inside the area, React Aria in the area's own `style`, with its place. The gradient is the same. + +## Anatomy + +```ocaml + + + +``` + +## Examples + +### With Dots + +```ocaml title="color_area_with_dots.mlx" +module Color_area = Solidtype_heroui.Color_area +module Colors = Solidtype_kobalte.Colors + +let make () = + + + +``` + +### Color Space & Channels + +Use `color_space` to set the color space (RGB, HSL, HSB) and +`x_channel`/`y_channel` to customize which color channels are displayed on +each axis. + +```ocaml title="color_area_space_and_channels.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Color_area = Solidtype_heroui.Color_area +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box +module Select = Solidtype_heroui.Select +module Colors = Solidtype_kobalte.Colors +module Color = Solidtype_kobalte.Types.Color + +type 'a option_ = { id : string; name : string; value : 'a } + +let color_spaces = + [| + { id = "rgb"; name = "RGB"; value = `rgb }; + { id = "hsl"; name = "HSL"; value = `hsl }; + { id = "hsb"; name = "HSB"; value = `hsb }; + |] + +let channels_by_space = function + | `hsb -> + [| + { id = "hue"; name = "Hue"; value = `hue }; + { id = "saturation"; name = "Saturation"; value = `saturation }; + { id = "brightness"; name = "Brightness"; value = `brightness }; + |] + | `hsl -> + [| + { id = "hue"; name = "Hue"; value = `hue }; + { id = "saturation"; name = "Saturation"; value = `saturation }; + { id = "lightness"; name = "Lightness"; value = `lightness }; + |] + | `rgb -> + [| + { id = "red"; name = "Red"; value = `red }; + { id = "green"; name = "Green"; value = `green }; + { id = "blue"; name = "Blue"; value = `blue }; + |] + +(* The channels across and up a space starts with. *) +let defaults = function + | `rgb -> ("blue", "green") + | `hsl -> ("saturation", "lightness") + | `hsb -> ("saturation", "brightness") + +let space_id = function `rgb -> "rgb" | `hsl -> "hsl" | `hsb -> "hsb" + +(* The colour as its space writes it. *) +let written color = function + | `rgb -> Color.to_string color ~format:`rgb () + | `hsl -> Color.to_string color ~format:`hsl () + | `hsb -> Color.to_string color ~format:`hsb () + +let find id options = Array.find_opt (fun o -> String.equal o.id id) options + +(* A Select of [options], [picked] its one value. *) +module Picker = struct + let%component make ~(class_ : string) ~(label : string) + ~(options : 'a option_ array) ~(picked : string) + ~(on_pick : string -> unit) () = + +end + +let make () = + let space, set_space = S.create_signal `hsb in + let color, set_color = + S.create_signal (Colors.parse_color "hsb(219, 58%, 93%)") + in + let x, set_x = S.create_signal "saturation" in + let y, set_y = S.create_signal "brightness" in + let channels () = channels_by_space (S.get space) in + let channel id = Option.map (fun o -> o.value) (find id (channels ())) in + let pick_space id = + Option.iter + (fun o -> + S.set set_space o.value; + (* Each channel goes back to the new space's own. *) + let x', y' = defaults o.value in + S.set set_x x'; + S.set set_y y') + (find id color_spaces) + in + (* No channel is on both axes. *) + let other than = + Array.of_list + (List.filter + (fun o -> not (String.equal o.id than)) + (Array.to_list (channels ()))) + in +
    +
    + + + +
    + + + +
    +
    + + (Jsx.string (written (S.get color) (S.get space))) + +
    +
    +``` + +### Disabled + +```ocaml title="color_area_disabled.mlx" +module Color_area = Solidtype_heroui.Color_area +module Colors = Solidtype_kobalte.Colors + +let make () = + + + +``` + +### Controlled + +```ocaml title="color_area_controlled.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Color_area = Solidtype_heroui.Color_area +module Color_swatch = Solidtype_heroui.Color_swatch +module Colors = Solidtype_kobalte.Colors +module Color = Solidtype_kobalte.Types.Color + +let make () = + let color, set_color = S.create_signal (Colors.parse_color "#9B80FF") in +
    + + + +
    + +

    + "Current color: " + + (Jsx.string (Color.to_string (S.get color) ~format:`hex ())) + +

    +
    +
    +``` + +### Render Function + +`as_` draws another element in its place, given its props and its state, as [Composition](composition.md#custom-dom-element) shows. + +## Customization + +### Tailwind CSS + +`class_` is added after HeroUI's classes, on the area and on its thumb. + +```ocaml title="color_area_custom_styles.mlx" +module Color_area = Solidtype_heroui.Color_area +module Colors = Solidtype_kobalte.Colors + +let make () = + + + +``` + +## Styling Reference + +### CSS Classes + +- `.color-area` - Base styles with gradient background and inner shadow +- `.color-area--show-dots` - Adds dot grid overlay for precision picking +- `.color-area__thumb` - Draggable thumb indicator, its colour + `--color-area-thumb-color` + +### Interactive States + +- **Disabled**: `[data-disabled="true"]`, on the area and its thumb +- **Focus**: `[data-focus-visible="true"]` (thumb only) +- **Dragging**: `[data-dragging="true"]` (thumb only) + +## API Reference + +Each prop beside the name HeroUI's React component gives it. + +### ColorArea + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `value` | `value` | `Types.Color.t` | | The current color value (controlled) | +| `defaultValue` | `default_value` | `Types.Color.t` | Kobalte's red | The default color value (uncontrolled) | +| `onChange` | `on_change` | `Types.Color.t -> unit` | | Handler called when the color changes while dragging | +| `onChangeEnd` | `on_change_end` | `Types.Color.t -> unit` | | Handler called when the user stops dragging | +| `xChannel` | `x_channel` | `Color_area.channel` | its space's | Color channel for the horizontal axis | +| `yChannel` | `y_channel` | `Color_area.channel` | its space's | Color channel for the vertical axis | +| `colorSpace` | `color_space` | `` [ `rgb \| `hsl \| `hsb ] `` | its value's | The color space for the channels | +| `xName`, `yName` | `x_name`, `y_name` | `string` | | Each channel's name in a form | +| `isDisabled` | `is_disabled` | `bool` | `false` | Whether the color area is disabled | +| `showDots` | `show_dots` | `bool` | `false` | Whether to show the dot grid overlay | +| `className` | `class_` | `string` | | Added after HeroUI's classes | +| `render` | `as_` | a function of its props and state | | Draws another element in its place | + +### ColorArea.Thumb + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `className` | `class_` | `string` | | Added after HeroUI's class | +| `style` | `style` | `string` | | Inline styles, added after its colour; a function of its state in React | +| `render` | `as_` | a function of its props and state | | Draws another element in its place | diff --git a/agents/pages/heroui/color-field.md b/agents/pages/heroui/color-field.md new file mode 100644 index 00000000..70a95ab6 --- /dev/null +++ b/agents/pages/heroui/color-field.md @@ -0,0 +1,651 @@ +# ColorField + +Color input field with labels, descriptions, and validation. + +Its value is a `Types.Color.t`, read from any CSS colour by +`Solidtype_kobalte.Colors.parse_color`, or none. What is typed is committed +as focus leaves the input and by Enter. The arrow keys, Page Up and Page Down, +Home and End, and the wheel while the input has the focus, step its value. + +Original HeroUI documentation: [ColorField](https://heroui.com/en/docs/react/components/color-field). + +## Usage + +HeroUI's examples. + +```ocaml title="color_field_usage.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Color_field = Solidtype_heroui.Color_field +module Color_swatch = Solidtype_heroui.Color_swatch +module Description = Solidtype_heroui.Description +module Field_error = Solidtype_heroui.Field_error +module Label = Solidtype_heroui.Label +module Colors = Solidtype_kobalte.Colors +module Color = Solidtype_kobalte.Types.Color + +(* A swatch of no colour, where HeroUI's is given none. *) +let shown c = Option.value c ~default:(Colors.parse_color "rgba(0, 0, 0, 0)") + +let make () = + let color, set_color = + S.create_signal (Some (Colors.parse_color "#0485F7")) + in + + + + + + + + + +``` + +## Parity + +The same HeroUI ColorField twice, under the same props: in solidtype on the +left, in React on the right. Below them, every attribute of the two fields: +a marked row is one they disagree on. + +The marked row is Kobalte's: its field is a `group` its label names, where React Aria's has no role. + +## Anatomy + +```ocaml + + + + + + + + "..." + + "..." + "..." + +``` + +`Color_field` combines label, color input, description, and error into a +single accessible component. + +## Examples + +### Variants + +`Color_field.Group` supports two visual variants: + +- `` `primary `` (default) - Standard styling with shadow, suitable for most + use cases +- `` `secondary `` - Lower emphasis variant without shadow, suitable for use + in `Surface` components + +```ocaml title="color_field_variants.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Color_field = Solidtype_heroui.Color_field +module Color_swatch = Solidtype_heroui.Color_swatch +module Description = Solidtype_heroui.Description +module Field_error = Solidtype_heroui.Field_error +module Label = Solidtype_heroui.Label +module Colors = Solidtype_kobalte.Colors +module Color = Solidtype_kobalte.Types.Color + +let make () = +
    + + + + + + + + + + + + +
    +``` + +### On Surface + +When used inside a [Surface](surface.md) component, use +``variant=`secondary`` on `Color_field.Group` to apply the lower emphasis +variant suitable for surface backgrounds. + +```ocaml title="color_field_on_surface.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Color_field = Solidtype_heroui.Color_field +module Color_swatch = Solidtype_heroui.Color_swatch +module Description = Solidtype_heroui.Description +module Field_error = Solidtype_heroui.Field_error +module Label = Solidtype_heroui.Label +module Colors = Solidtype_kobalte.Colors +module Color = Solidtype_kobalte.Types.Color +module Surface = Solidtype_heroui.Surface + +let make () = + + + + + + + "Select your theme color" + + +``` + +### With Description + +```ocaml title="color_field_with_description.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Color_field = Solidtype_heroui.Color_field +module Color_swatch = Solidtype_heroui.Color_swatch +module Description = Solidtype_heroui.Description +module Field_error = Solidtype_heroui.Field_error +module Label = Solidtype_heroui.Label +module Colors = Solidtype_kobalte.Colors +module Color = Solidtype_kobalte.Types.Color + +let make () = +
    + + + + "Enter your brand's primary color" + + + + + "Used for highlights and CTAs" + +
    +``` + +### Required Field + +```ocaml title="color_field_required.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Color_field = Solidtype_heroui.Color_field +module Color_swatch = Solidtype_heroui.Color_swatch +module Description = Solidtype_heroui.Description +module Field_error = Solidtype_heroui.Field_error +module Label = Solidtype_heroui.Label +module Colors = Solidtype_kobalte.Colors +module Color = Solidtype_kobalte.Types.Color + +let make () = +
    + + + + + + + + + + + + "Required field" + +
    +``` + +### Disabled State + +```ocaml title="color_field_disabled.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Color_field = Solidtype_heroui.Color_field +module Color_swatch = Solidtype_heroui.Color_swatch +module Description = Solidtype_heroui.Description +module Field_error = Solidtype_heroui.Field_error +module Label = Solidtype_heroui.Label +module Colors = Solidtype_kobalte.Colors +module Color = Solidtype_kobalte.Types.Color + +let make () = +
    + + + + "This color field is disabled" + + + + + + + "This color field is disabled" + +
    +``` + +### Full Width + +```ocaml title="color_field_full_width.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Color_field = Solidtype_heroui.Color_field +module Color_swatch = Solidtype_heroui.Color_swatch +module Description = Solidtype_heroui.Description +module Field_error = Solidtype_heroui.Field_error +module Label = Solidtype_heroui.Label +module Colors = Solidtype_kobalte.Colors +module Color = Solidtype_kobalte.Types.Color + +let make () = +
    + + + + + + + + +
    +``` + +### Validation + +Use `is_invalid` together with `Field_error` to surface validation messages. + +```ocaml title="color_field_validation.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Color_field = Solidtype_heroui.Color_field +module Color_swatch = Solidtype_heroui.Color_swatch +module Description = Solidtype_heroui.Description +module Field_error = Solidtype_heroui.Field_error +module Label = Solidtype_heroui.Label +module Colors = Solidtype_kobalte.Colors +module Color = Solidtype_kobalte.Types.Color + +let make () = +
    + + + + + + "Please enter a valid hex color" + + + + + "Invalid color format. Use hex (e.g., #FF5733)" + +
    +``` + +### Channel Editing + +`Color_field` supports editing individual color channels (hue, saturation, +lightness, red, green, blue, alpha) by setting the `color_space` and `channel` +props. Each input here takes `min-w-0`, so the `%` after it fits. + +```ocaml title="color_field_channel_editing.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Color_field = Solidtype_heroui.Color_field +module Color_swatch = Solidtype_heroui.Color_swatch +module Description = Solidtype_heroui.Description +module Field_error = Solidtype_heroui.Field_error +module Label = Solidtype_heroui.Label +module Colors = Solidtype_kobalte.Colors +module Color = Solidtype_kobalte.Types.Color + +let make () = + let color, set_color = + S.create_signal (Some (Colors.parse_color "#7F007F")) + in + let channel ~channel ~name ~label ~suffix = + + + + + (if suffix then + + "%" + + else Jsx.string "") + + + in +
    +

    "Edit individual HSL channels:"

    +
    + (channel ~channel:`hue ~name:"hue" ~label:"Hue" ~suffix:false) + (channel ~channel:`saturation ~name:"saturation" ~label:"Saturation" + ~suffix:true) + (channel ~channel:`lightness ~name:"lightness" ~label:"Lightness" + ~suffix:true) +
    +
    + + + "Current: " + (Jsx.string + (match S.get color with + | Some c -> Color.to_string c ~format:`hex () + | None -> "(empty)")) + +
    +
    +``` + +### Controlled + +Control the value to synchronize with other components or state management. + +```ocaml title="color_field_controlled.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Color_field = Solidtype_heroui.Color_field +module Color_swatch = Solidtype_heroui.Color_swatch +module Description = Solidtype_heroui.Description +module Field_error = Solidtype_heroui.Field_error +module Label = Solidtype_heroui.Label +module Colors = Solidtype_kobalte.Colors +module Color = Solidtype_kobalte.Types.Color +module Button = Solidtype_heroui.Button + +(* A swatch of no colour, where HeroUI's is given none. *) +let shown c = Option.value c ~default:(Colors.parse_color "rgba(0, 0, 0, 0)") + +let make () = + let value, set_value = + S.create_signal (Some (Colors.parse_color "#0485F7")) + in +
    + + + + + + + + + + "Current value: " + (Jsx.string + (match S.get value with + | Some c -> Color.to_string c ~format:`hex () + | None -> "(empty)")) + + +
    + + + +
    +
    +``` + +### Form Example + +Complete form example with validation and submission handling. + +```ocaml title="color_field_form.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Color_field = Solidtype_heroui.Color_field +module Color_swatch = Solidtype_heroui.Color_swatch +module Description = Solidtype_heroui.Description +module Field_error = Solidtype_heroui.Field_error +module Label = Solidtype_heroui.Label +module Colors = Solidtype_kobalte.Colors +module Color = Solidtype_kobalte.Types.Color +module Button = Solidtype_heroui.Button +module Form = Solidtype_heroui.Form + +external prevent_default : Dom.event -> unit = "preventDefault" [@@mel.send] + +(* A swatch of no colour, where HeroUI's is given none. *) +let shown c = Option.value c ~default:(Colors.parse_color "rgba(0, 0, 0, 0)") + +(* How long the save it stands in for takes. *) +let save_ms = 1500 + +let make () = + let value, set_value = S.create_signal None in + let submitting, set_submitting = S.create_signal false in + let timer = ref None in + S.on_cleanup (fun () -> Option.iter Js.Global.clearTimeout !timer); +
    + prevent_default e; + match S.get value with + | None -> () + | Some _ -> + S.set set_submitting true; + timer := + Some + (Js.Global.setTimeout + ~f:(fun () -> + S.set set_value None; + S.set set_submitting false) + save_ms))> + + + + + + + + + "Choose your brand's primary color" + + +
    +``` + +### Render Function + +`as_` draws another element in its place, given its props and its state, as [Composition](composition.md#custom-dom-element) shows. + +## Customization + +### Tailwind CSS + +`class_` is added after HeroUI's classes, on each part. + +```ocaml title="color_field_custom_styles.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Color_field = Solidtype_heroui.Color_field +module Color_swatch = Solidtype_heroui.Color_swatch +module Description = Solidtype_heroui.Description +module Field_error = Solidtype_heroui.Field_error +module Label = Solidtype_heroui.Label +module Colors = Solidtype_kobalte.Colors +module Color = Solidtype_kobalte.Types.Color + +(* A swatch of no colour, where HeroUI's is given none. *) +let shown c = Option.value c ~default:(Colors.parse_color "rgba(0, 0, 0, 0)") + +let make () = + let color, set_color = + S.create_signal (Some (Colors.parse_color "#6366F1")) + in + + + "Applied to buttons, links, and focus rings." + + + + + + + +``` + +## Styling Reference + +### CSS Classes + +- `.color-field` - Root container with minimal styling (`flex flex-col gap-1`) +- `.color-field--full-width` - Full width modifier +- `.color-input-group` - Group root container styling +- `.color-input-group--primary`, `.color-input-group--secondary` - Group + variants +- `.color-input-group--full-width` - Group full width modifier +- `.color-input-group__input` - Input wrapper styling +- `.color-input-group__prefix` - Prefix element styling +- `.color-input-group__suffix` - Suffix element styling + +Child components ([Label](label.md), +[Description](description.md), +[FieldError](field-error.md)) have their own CSS classes and +styling. See their respective documentation for customization options. + +### Interactive States + +The field manages these data attributes based on its state: + +- **Channel**: `[data-channel]` - The channel it edits, or `hex` +- **Invalid**: `[data-invalid="true"]` - Applied while it is invalid +- **Required**: `[data-required="true"]` - Applied when `is_required` is true +- **Disabled**: `[data-disabled="true"]` - Applied when `is_disabled` is true +- **Read Only**: `[data-readonly="true"]` - Applied when `is_read_only` is + true + +The group: + +- **Hover**: `[data-hovered="true"]` +- **Focus Within**: `[data-focus-within="true"]`, and + `[data-focus-visible="true"]` from the keyboard +- **Invalid**: `[data-invalid="true"]` +- **Disabled**: `[data-disabled="true"]` + +The input: `[data-hovered="true"]`, `[data-focused="true"]`, +`[data-focus-visible="true"]`, `[data-invalid="true"]`, +`[data-disabled="true"]`. + +## API Reference + +Each prop beside the name HeroUI's React component gives it. + +### ColorField + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `value` | `value` | `Types.Color.t Js.Nullable.t` | | Current value (controlled), null for none | +| `defaultValue` | `default_value` | `Types.Color.t` | | Default value (uncontrolled) | +| `onChange` | `on_change` | `Types.Color.t option -> unit` | | Handler called when the value changes, `None` for none | +| `channel` | `channel` | `Color_field.channel` | | The color channel to edit, fixed as it is made. If not provided, edits hex value | +| `colorSpace` | `color_space` | `` [ `rgb \| `hsl \| `hsb ] `` | its value's | The color space that the color field operates in when `channel` is provided | +| `fullWidth` | `full_width` | `bool` | `false` | Whether the color field should take full width of its container | +| `isRequired` | `is_required` | `bool` | `false` | Whether user input is required before form submission | +| `isInvalid` | `is_invalid` | `bool` | `false` | Whether the value is invalid; so too while a form's error names it | +| `validate`, `validationBehavior` | — | | | A field validates nothing itself: it is invalid as the application says | +| `isDisabled` | `is_disabled` | `bool` | its fieldset's | Whether the input is disabled | +| `isReadOnly` | `is_read_only` | `bool` | `false` | Whether the input can be selected but not changed | +| `isWheelDisabled` | `is_wheel_disabled` | `bool` | `false` | Whether to disable changing the value with scroll | +| `name` | `name` | `string` | | Name of the input element, for HTML form submission: the hex or the channel's value | +| `autoFocus` | — | | | The input's own `autofocus` | +| `aria-label` | `aria_label` | `string` | | Accessibility label when no visible label is present | +| `onBlur` | `on_blur` | `Dom.focusEvent -> unit` | | Called as focus leaves it | +| `className` | `class_` | `string` | | Added after HeroUI's class | +| `render` | `as_` | a function of its props and state | | Draws another element in its place | + +Any other attribute, `id` or `aria_describedby`, is the field's element's. + +### ColorField.Group + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `variant` | `variant` | `` [ `primary \| `secondary ] `` | `` `primary `` | Visual variant of the component. `` `primary `` is the default style with shadow. `` `secondary `` is a lower emphasis variant without shadow, suitable for use in surfaces | +| `fullWidth` | `full_width` | `bool` | `false` | Whether the color input group should take full width of its container | +| `className` | `class_` | `string` | | Added after HeroUI's class | + +A press on the group but on its input gives the input the focus. + +### ColorField.Input, ColorField.Prefix, ColorField.Suffix + +Each takes `class_`, added after HeroUI's class, and every attribute of its +element; the input its `placeholder`, shown while it is empty, the prefix and +the suffix their `children`. diff --git a/agents/pages/heroui/color-picker.md b/agents/pages/heroui/color-picker.md new file mode 100644 index 00000000..8abc57b8 --- /dev/null +++ b/agents/pages/heroui/color-picker.md @@ -0,0 +1,514 @@ +# ColorPicker + +A composable color picker that synchronizes color value between multiple color components. + +A `Color_area`, `Color_slider`, `Color_field`, `Color_swatch` or +`Color_swatch_picker` inside it, given no value, shows its colour and moves it. +A part's own value wins, and its own `on_change` is called too. Its value is a `Types.Color.t`, read from any CSS colour by +`Solidtype_kobalte.Colors.parse_color`. + +Original HeroUI documentation: [ColorPicker](https://heroui.com/en/docs/react/components/color-picker). + +## Usage + +HeroUI's examples. + +```ocaml title="color_picker_usage.mlx" +module Color_area = Solidtype_heroui.Color_area +module Color_picker = Solidtype_heroui.Color_picker +module Color_slider = Solidtype_heroui.Color_slider +module Color_swatch = Solidtype_heroui.Color_swatch +module Label = Solidtype_heroui.Label +module Colors = Solidtype_kobalte.Colors + +let make () = + + + + + + + + + + + + + + + +``` + +## Parity + +The same picker twice, each keeping its own colour: in solidtype on the left, in +React on the right. Below them, every attribute of the two triggers: a marked +row is one they disagree on: `aria-haspopup="dialog"` is Kobalte's, which says +what the trigger opens, where React Aria's trigger says nothing. + +## Anatomy + +`Color_picker` is a composable component that combines multiple color +components: + +```ocaml + + + + + + + + + + + + + +``` + +## Examples + +### Controlled + +```ocaml title="color_picker_controlled.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Button = Solidtype_heroui.Button +module Color_field = Solidtype_heroui.Color_field +module Color_swatch_picker = Solidtype_heroui.Color_swatch_picker +module Color = Solidtype_kobalte.Types.Color +module Color_area = Solidtype_heroui.Color_area +module Color_picker = Solidtype_heroui.Color_picker +module Color_slider = Solidtype_heroui.Color_slider +module Color_swatch = Solidtype_heroui.Color_swatch +module Label = Solidtype_heroui.Label +module Colors = Solidtype_kobalte.Colors +module Gravity = Solidtype_gravity_icons + +let presets = + [| + "#ef4444"; + "#f97316"; + "#eab308"; + "#22c55e"; + "#06b6d4"; + "#3b82f6"; + "#8b5cf6"; + "#ec4899"; + "#f43f5e"; + |] + +let random_colour () = + let hue = Js.Math.random_int 0 360 + and saturation = Js.Math.random_int 50 100 + and lightness = Js.Math.random_int 40 70 in + Colors.parse_color + ("hsl(" ^ string_of_int hue ^ ", " ^ string_of_int saturation ^ "%, " + ^ string_of_int lightness ^ "%)") + +let make () = + let color, set_color = S.create_signal (Colors.parse_color "#325578") in +
    + + + + + + + + (fun preset _ -> + + + ) + + + + + +
    + + + + +
    + + + + + + +
    +
    +

    + "Selected: " + + (Jsx.string (Color.to_string (S.get color) ~format:`hex ())) + +

    +
    +``` + +### With Swatches + +```ocaml title="color_picker_with_swatches.mlx" +module For = Solidtype.For +module Color_swatch_picker = Solidtype_heroui.Color_swatch_picker +module Color_area = Solidtype_heroui.Color_area +module Color_picker = Solidtype_heroui.Color_picker +module Color_slider = Solidtype_heroui.Color_slider +module Color_swatch = Solidtype_heroui.Color_swatch +module Label = Solidtype_heroui.Label +module Colors = Solidtype_kobalte.Colors + +let presets = + [| + "#ef4444"; + "#f97316"; + "#eab308"; + "#22c55e"; + "#06b6d4"; + "#3b82f6"; + "#8b5cf6"; + "#ec4899"; + "#f43f5e"; + |] + +let make () = + + + + + + + + + + + + + + + + (fun preset _ -> + + + ) + + + + +``` + +### With Fields + +Use `Color_field` to allow users to edit individual color channel values with +a `Select` to switch between color spaces. + +```ocaml title="color_picker_with_fields.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Color_field = Solidtype_heroui.Color_field +module List_box = Solidtype_heroui.List_box +module Select = Solidtype_heroui.Select +module Color_area = Solidtype_heroui.Color_area +module Color_picker = Solidtype_heroui.Color_picker +module Color_slider = Solidtype_heroui.Color_slider +module Color_swatch = Solidtype_heroui.Color_swatch +module Label = Solidtype_heroui.Label +module Colors = Solidtype_kobalte.Colors + +(* A colour space, by the name its option has. *) +let spaces = [| ("hsb", `hsb); ("hsl", `hsl); ("rgb", `rgb) |] + +let picked_space id = + Array.find_map + (fun (name, space) -> if String.equal name id then Some space else None) + spaces + +let channels = function + | `hsb -> [| `hue; `saturation; `brightness |] + | `hsl -> [| `hue; `saturation; `lightness |] + | `rgb -> [| `red; `green; `blue |] + +let name_of = function + | `hue -> "hue" + | `saturation -> "saturation" + | `brightness -> "brightness" + | `lightness -> "lightness" + | `red -> "red" + | `green -> "green" + | `blue -> "blue" + | `alpha -> "alpha" + +let make () = + let space_name, set_space_name = S.create_signal "hsl" in + let space () = Option.value (picked_space (S.get space_name)) ~default:`hsl in + + + + + + + + + + + + + + +
    + + (fun channel _ -> + + + + + ) + +
    +
    +
    +``` + +### With Sliders + +Use multiple `Color_slider` components to adjust each channel of a color +value. + +```ocaml title="color_picker_with_sliders.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module List_box = Solidtype_heroui.List_box +module Select = Solidtype_heroui.Select +module Color_area = Solidtype_heroui.Color_area +module Color_picker = Solidtype_heroui.Color_picker +module Color_slider = Solidtype_heroui.Color_slider +module Color_swatch = Solidtype_heroui.Color_swatch +module Label = Solidtype_heroui.Label +module Colors = Solidtype_kobalte.Colors + +(* A colour space, by the name its option has. *) +let spaces = [| ("hsb", `hsb); ("hsl", `hsl); ("rgb", `rgb) |] + +let picked_space id = + Array.find_map + (fun (name, space) -> if String.equal name id then Some space else None) + spaces + +let channels = function + | `hsb -> [| `hue; `saturation; `brightness; `alpha |] + | `hsl -> [| `hue; `saturation; `lightness; `alpha |] + | `rgb -> [| `red; `green; `blue; `alpha |] + +let name_of = function + | `hue -> "hue" + | `saturation -> "saturation" + | `brightness -> "brightness" + | `lightness -> "lightness" + | `red -> "red" + | `green -> "green" + | `blue -> "blue" + | `alpha -> "alpha" + +let make () = + let space_name, set_space_name = S.create_signal "hsl" in + let space () = Option.value (picked_space (S.get space_name)) ~default:`hsl in + + + + + + +
    + + (fun channel _ -> + + + + + ) + +
    +
    +
    +``` + +### Render Function + +`as_` draws another element in its place, given its props and its state, as [Composition](composition.md#custom-dom-element) shows. + +## Customization + +### Tailwind CSS + +`class_` is added after HeroUI's classes, on each part. + +```ocaml title="color_picker_custom_styles.mlx" +module Color_area = Solidtype_heroui.Color_area +module Color_picker = Solidtype_heroui.Color_picker +module Color_slider = Solidtype_heroui.Color_slider +module Color_swatch = Solidtype_heroui.Color_swatch +module Label = Solidtype_heroui.Label +module Colors = Solidtype_kobalte.Colors + +let make () = + + + + + + + + + + + + + + + + +``` + +## Styling Reference + +### CSS Classes + +- `.color-picker` - Base container +- `.color-picker__trigger` - Trigger button +- `.color-picker__popover` - Popover container + +### Interactive States + +The trigger: + +- **Focus**: `:focus-visible` or `[data-focus-visible="true"]`, and + `[data-focused="true"]` +- **Disabled**: `:disabled` or `[data-disabled="true"]` +- **Hover**: `[data-hovered="true"]` +- **Pressed**: `[data-pressed="true"]` + +The popover: `[data-placement]`, `[data-entering="true"]`, +`[data-exiting="true"]`. + +## API Reference + +Each prop beside the name HeroUI's React component gives it. + +### ColorPicker + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `value` | `value` | `Types.Color.t` | | The current color value (controlled) | +| `defaultValue` | `default_value` | `Types.Color.t` | black | The default color value (uncontrolled) | +| `onChange` | `on_change` | `Types.Color.t -> unit` | | Handler called when the color changes | +| `className` | `class_` | `string` | | Added after HeroUI's class | +| `render` | `as_` | a function of its props | | Draws another element in its place | + +### ColorPicker.Trigger + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `isDisabled` | `is_disabled` | `bool` | `false` | Whether it can be pressed | +| `className` | `class_` | `string` | | Added after HeroUI's class | +| `children` | `children` | elements, or a function of its state | required | Trigger content or render prop | +| `render` | `as_` | a function of its props and state | | Draws another element in its place | + +### ColorPicker.Popover + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `isOpen` | `is_open` | `bool` | | Whether it is open, controlled | +| `defaultOpen` | `default_open` | `bool` | `false` | Whether it is open at first | +| `onOpenChange` | `on_open_change` | `bool -> unit` | | Called as it opens and closes | +| `placement` | `placement` | `` `bottom_left ``, and React Aria's others | `` `bottom_left `` | Placement of the popover | +| `offset` | `offset` | `float` | `8.` | Pixels from its trigger | +| `shouldFlip` | `should_flip` | `bool` | `true` | To the other side where there is no room | +| `className` | `class_` | `string` | | Added after HeroUI's class | +| `style` | `style` | `string` | | Added after its own | +| `render` | `as_` | a function of its props | | Draws another element in its place | diff --git a/agents/pages/heroui/color-slider.md b/agents/pages/heroui/color-slider.md new file mode 100644 index 00000000..b65f5b8d --- /dev/null +++ b/agents/pages/heroui/color-slider.md @@ -0,0 +1,361 @@ +# ColorSlider + +A color slider allows users to adjust an individual channel of a color value. + +Its value is a `Types.Color.t`, read from any CSS colour by +`Solidtype_kobalte.Colors.parse_color`. A channel asked of a space that has +none of it -- red in HSL, hue in RGB -- is read in the space it is in. + +Original HeroUI documentation: [ColorSlider](https://heroui.com/en/docs/react/components/color-slider). + +## Usage + +HeroUI's examples. + +```ocaml title="color_slider_usage.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Color_slider = Solidtype_heroui.Color_slider +module Color_swatch = Solidtype_heroui.Color_swatch +module Label = Solidtype_heroui.Label +module Colors = Solidtype_kobalte.Colors +module Color = Solidtype_kobalte.Types.Color + +let make () = + + + + + +``` + +## Parity + +The same HeroUI ColorSlider twice, under the same props: in solidtype on the +left, in React on the right. Below them, every attribute of the two sliders: +a marked row is one they disagree on. + +The marked row is Kobalte's: its slider is a `group` its label names, where React Aria's has no role. + +## Anatomy + +```ocaml + + + + + + + +``` + +## Examples + +### Disabled + +```ocaml title="color_slider_disabled.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Color_slider = Solidtype_heroui.Color_slider +module Color_swatch = Solidtype_heroui.Color_swatch +module Label = Solidtype_heroui.Label +module Colors = Solidtype_kobalte.Colors +module Color = Solidtype_kobalte.Types.Color + +let make () = + + + + + +``` + +### Vertical + +```ocaml title="color_slider_vertical.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Color_slider = Solidtype_heroui.Color_slider +module Color_swatch = Solidtype_heroui.Color_swatch +module Label = Solidtype_heroui.Label +module Colors = Solidtype_kobalte.Colors +module Color = Solidtype_kobalte.Types.Color + +let make () = +
    + + + + + + + + + +
    +``` + +### Controlled + +```ocaml title="color_slider_controlled.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Color_slider = Solidtype_heroui.Color_slider +module Color_swatch = Solidtype_heroui.Color_swatch +module Label = Solidtype_heroui.Label +module Colors = Solidtype_kobalte.Colors +module Color = Solidtype_kobalte.Types.Color + +let make () = + let color, set_color = + S.create_signal (Colors.parse_color "hsl(200, 100%, 50%)") + in +
    + + + + + +
    + +

    + "Current color: " + + (Jsx.string (Color.to_string (S.get color) ~format:`hsl ())) + +

    +
    +
    +``` + +### HSL Channels + +Use multiple `Color_slider`s to control different channels of a color value. +The sliders can share the same color value to create a complete color picker. + +```ocaml title="color_slider_hsl_channels.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Color_slider = Solidtype_heroui.Color_slider +module Color_swatch = Solidtype_heroui.Color_swatch +module Label = Solidtype_heroui.Label +module Colors = Solidtype_kobalte.Colors +module Color = Solidtype_kobalte.Types.Color + +let make () = + let color, set_color = + S.create_signal (Colors.parse_color "hsl(0, 100%, 50%)") + in +
    + + + + + + + + + + + + + + + +
    + +

    + "Current color: " + + (Jsx.string (Color.to_string (S.get color) ~format:`hsl ())) + +

    +
    +
    +``` + +### Alpha Channel + +The alpha channel slider shows a transparency checkerboard pattern to help +visualize the transparency level. + +```ocaml title="color_slider_alpha_channel.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Color_slider = Solidtype_heroui.Color_slider +module Color_swatch = Solidtype_heroui.Color_swatch +module Label = Solidtype_heroui.Label +module Colors = Solidtype_kobalte.Colors +module Color = Solidtype_kobalte.Types.Color + +let make () = + + + + + +``` + +### RGB Channels + +You can also use the RGB color space with red, green, and blue channels. + +```ocaml title="color_slider_rgb_channels.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Color_slider = Solidtype_heroui.Color_slider +module Color_swatch = Solidtype_heroui.Color_swatch +module Label = Solidtype_heroui.Label +module Colors = Solidtype_kobalte.Colors +module Color = Solidtype_kobalte.Types.Color + +let make () = + let color, set_color = + S.create_signal (Colors.parse_color "rgb(255, 100, 50)") + in +
    + + + + + + + + + + + + + + + +
    + +

    + "Current color: " + + (Jsx.string (Color.to_string (S.get color) ~format:`rgb ())) + +

    +
    +
    +``` + +### Render Function + +`as_` draws another element in its place, given its props and its state, as [Composition](composition.md#custom-dom-element) shows. + +## Customization + +### Tailwind CSS + +`class_` is added after HeroUI's classes, on each part. + +```ocaml title="color_slider_custom_styles.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Color_slider = Solidtype_heroui.Color_slider +module Color_swatch = Solidtype_heroui.Color_swatch +module Label = Solidtype_heroui.Label +module Colors = Solidtype_kobalte.Colors +module Color = Solidtype_kobalte.Types.Color + +let make () = + + + + + + + +``` + +## Styling Reference + +### CSS Classes + +- `.color-slider` - Base slider container +- `.color-slider__output` - Output element displaying current value +- `.color-slider__track` - Track element with color gradient, its ends + `--track-start-color` and `--track-end-color` +- `.color-slider__thumb` - Thumb element showing current color + +### Interactive States + +- **Hover**: `[data-hovered="true"]` on thumb +- **Focus**: `[data-focus-visible="true"]` on thumb +- **Dragging**: `[data-dragging="true"]` on thumb +- **Disabled**: `[data-disabled="true"]` on slider or thumb +- **Orientation**: `[data-orientation]` on slider + +## API Reference + +Each prop beside the name HeroUI's React component gives it. + +### ColorSlider + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `channel` | `channel` | `Color_slider.channel` | | The color channel that the slider manipulates (hue, saturation, lightness, brightness, alpha, red, green, blue) | +| `colorSpace` | `color_space` | `` [ `rgb \| `hsl \| `hsb ] `` | its value's | The color space (hsl, hsb, rgb). Defaults to the color space of the value | +| `value` | `value` | `Types.Color.t` | | The current color value (controlled) | +| `defaultValue` | `default_value` | `Types.Color.t` | | The default color value (uncontrolled) | +| `onChange` | `on_change` | `Types.Color.t -> unit` | | Handler called when the value changes during dragging, with each colour other than its own | +| `onChangeEnd` | `on_change_end` | `Types.Color.t -> unit` | | Handler called when dragging ends | +| `orientation` | `orientation` | `` [ `horizontal \| `vertical ] `` | `` `horizontal `` | The orientation of the slider | +| `isDisabled` | `is_disabled` | `bool` | its fieldset's | Whether the slider is disabled | +| `name` | `name` | `string` | | The name of the input element for form submission | +| `aria-label` | `aria_label` | `string` | | Accessibility label for the slider | +| `onBlur` | `on_blur` | `Dom.focusEvent -> unit` | | Called as focus leaves it | +| `className` | `class_` | `string` | | Added after HeroUI's class | +| `render` | `as_` | a function of its props and state | | Draws another element in its place | + +### ColorSlider.Output, ColorSlider.Track, ColorSlider.Thumb + +Each takes `class_`, added after HeroUI's class; the track and the thumb +`style`, after their own, a function of their state in React; the output and +the thumb their `children`, the output's in place of the channel's value. + +## Accessibility + +`Color_slider` implements the ARIA slider pattern and provides: + +- Full keyboard navigation support (arrow keys, Home, End, Page Up and Page + Down) +- Screen reader announcements for value changes, such as `0°, red` +- Proper focus management +- Support for disabled states +- HTML form integration via a hidden input element diff --git a/agents/pages/heroui/color-swatch-picker.md b/agents/pages/heroui/color-swatch-picker.md new file mode 100644 index 00000000..1c4d2943 --- /dev/null +++ b/agents/pages/heroui/color-swatch-picker.md @@ -0,0 +1,391 @@ +# ColorSwatchPicker + +A list of color swatches that allows users to select a color from a predefined palette. + +Its colours are `Types.Color.t`s, read from any CSS colour by +`Solidtype_kobalte.Colors.parse_color`. A value is its swatch's when the two +are one colour, however each is written: `rgb(139, 92, 246)` chooses +`#8B5CF6`. + +Original HeroUI documentation: [ColorSwatchPicker](https://heroui.com/en/docs/react/components/color-swatch-picker). + +## Usage + +HeroUI's examples. + +```ocaml title="color_swatch_picker_usage.mlx" +module For = Solidtype.For +module Color_swatch_picker = Solidtype_heroui.Color_swatch_picker +module Colors = Solidtype_kobalte.Colors + +let colors = + [| + "#F43F5E"; "#D946EF"; "#8B5CF6"; "#3B82F6"; "#06B6D4"; "#10B981"; "#84CC16"; + |] + +let make () = + + + (fun c _ -> + + + ) + + +``` + +## Parity + +The same HeroUI ColorSwatchPicker twice, under the same props: in solidtype +on the left, in React on the right. Below them, every attribute of the two +pickers: a marked row is one they disagree on. + +## Anatomy + +```ocaml + + + + + + +``` + +## Examples + +### Variants + +```ocaml title="color_swatch_picker_variants.mlx" +module For = Solidtype.For +module Color_swatch_picker = Solidtype_heroui.Color_swatch_picker +module Colors = Solidtype_kobalte.Colors + +let colors = + [| + "#F43F5E"; "#D946EF"; "#8B5CF6"; "#3B82F6"; "#06B6D4"; "#10B981"; "#84CC16"; + |] + +let make () = +
    +
    + "Circle (default)" + + + (fun c _ -> + + + ) + + +
    +
    + "Square" + + + (fun c _ -> + + + ) + + +
    +
    +``` + +### Sizes + +```ocaml title="color_swatch_picker_sizes.mlx" +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Color_swatch_picker = Solidtype_heroui.Color_swatch_picker +module Colors = Solidtype_kobalte.Colors + +let colors = + [| + "#F43F5E"; "#D946EF"; "#8B5CF6"; "#3B82F6"; "#06B6D4"; "#10B981"; "#84CC16"; + |] + +let sizes = + [| (`xs, "xs"); (`sm, "sm"); (`md, "md"); (`lg, "lg"); (`xl, "xl") |] + +let make () = +
    + + (fun (size, name) _ -> +
    + (Jsx.string name) + + + (fun c _ -> + + + + ) + + +
    ) +
    +
    +``` + +### Disabled + +```ocaml title="color_swatch_picker_disabled.mlx" +module For = Solidtype.For +module Color_swatch_picker = Solidtype_heroui.Color_swatch_picker +module Colors = Solidtype_kobalte.Colors + +let colors = + [| + "#F43F5E"; "#D946EF"; "#8B5CF6"; "#3B82F6"; "#06B6D4"; "#10B981"; "#84CC16"; + |] + +let make () = + + + (fun c _ -> + + + ) + + +``` + +### Stack Layout + +A stack is a list the keys walk by Up and Down. + +```ocaml title="color_swatch_picker_stack.mlx" +module For = Solidtype.For +module Color_swatch_picker = Solidtype_heroui.Color_swatch_picker +module Colors = Solidtype_kobalte.Colors + +let colors = + [| + "#F43F5E"; "#D946EF"; "#8B5CF6"; "#3B82F6"; "#06B6D4"; "#10B981"; "#84CC16"; + |] + +let make () = + + + (fun c _ -> + + + ) + + +``` + +### Default Value + +```ocaml title="color_swatch_picker_default_value.mlx" +module For = Solidtype.For +module Color_swatch_picker = Solidtype_heroui.Color_swatch_picker +module Colors = Solidtype_kobalte.Colors + +let colors = + [| + "#F43F5E"; "#D946EF"; "#8B5CF6"; "#3B82F6"; "#06B6D4"; "#10B981"; "#84CC16"; + |] + +let make () = + + + (fun c _ -> + + + ) + + +``` + +### Controlled + +```ocaml title="color_swatch_picker_controlled.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Color_swatch_picker = Solidtype_heroui.Color_swatch_picker +module Colors = Solidtype_kobalte.Colors +module Color = Solidtype_kobalte.Types.Color + +let colors = + [| + "#F43F5E"; "#D946EF"; "#8B5CF6"; "#3B82F6"; "#06B6D4"; "#10B981"; "#84CC16"; + |] + +let make () = + let value, set_value = S.create_signal (Colors.parse_color "#F43F5E") in +
    + + + (fun c _ -> + + + ) + + +

    + "Selected: " + + (Jsx.string (Color.to_string (S.get value) ~format:`hex ())) + +

    +
    +``` + +### Custom Indicator + +`Color_swatch_picker.Indicator` takes its children in place of the +checkmark. Inside an item, `Solidtype_headless.Color_swatch_picker.Item.Context.use` +reads its colour and whether it is chosen or disabled. + +```ocaml title="color_swatch_picker_custom_indicator.mlx" +module For = Solidtype.For +module Color_swatch_picker = Solidtype_heroui.Color_swatch_picker +module Colors = Solidtype_kobalte.Colors +module Gravity = Solidtype_gravity_icons + +let colors = + [| + "#F43F5E"; "#D946EF"; "#8B5CF6"; "#3B82F6"; "#06B6D4"; "#10B981"; "#84CC16"; + |] + +let make () = + + + (fun c _ -> + + + + + + ) + + +``` + +### Render Function + +`as_` draws another element in its place, given its props and its state, as [Composition](composition.md#custom-dom-element) shows. + +## Customization + +### Tailwind CSS + +`class_` is added after HeroUI's classes, on each part, and an item's `style` +after its colour. + +```ocaml title="color_swatch_picker_custom_styles.mlx" +module For = Solidtype.For +module Color_swatch_picker = Solidtype_heroui.Color_swatch_picker +module Colors = Solidtype_kobalte.Colors + +let colors = + [| + "#F43F5E"; "#D946EF"; "#8B5CF6"; "#3B82F6"; "#06B6D4"; "#10B981"; "#84CC16"; + |] + +let make () = + + + (fun c _ -> + + + ) + + +``` + +## Styling Reference + +### CSS Classes + +- `.color-swatch-picker` - Base container (flex layout) +- `.color-swatch-picker__item` - Individual swatch item wrapper +- `.color-swatch-picker__swatch` - The color swatch visual element +- `.color-swatch-picker__indicator` - The checkmark over a chosen swatch +- `.color-swatch-picker--xs` - Extra small (16px) +- `.color-swatch-picker--sm` - Small (24px) +- `.color-swatch-picker--md` - Medium (32px, default) +- `.color-swatch-picker--lg` - Large (36px) +- `.color-swatch-picker--xl` - Extra large (40px) +- `.color-swatch-picker--circle` - Circle shape (default) +- `.color-swatch-picker--square` - Square shape with rounded corners +- `.color-swatch-picker--grid` - Horizontal wrapping layout (default) +- `.color-swatch-picker--stack` - Vertical stacked layout + +### Interactive States + +Each item: + +- **Hover**: `[data-hovered="true"]` - Scale up to 1.1 (only when not + selected) +- **Focus**: `[data-focus-visible="true"]` - Focus ring, and + `[data-focused="true"]` +- **Pressed**: `[data-pressed="true"]` +- **Selected**: `[data-selected="true"]` - Inner border with same color as + swatch +- **Disabled**: `[data-disabled="true"]` - Reduced opacity + +An item's colour is `--color-swatch-current`. The list declares +`[data-layout]`, `grid` or `stack`. The indicator declares +`[data-light-color="true"]` over a light colour, which draws its checkmark +black. + +## API Reference + +Each prop beside the name HeroUI's React component gives it. + +### ColorSwatchPicker + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `value` | `value` | `Types.Color.t` | | The current selected color (controlled) | +| `defaultValue` | `default_value` | `Types.Color.t` | | The default selected color (uncontrolled) | +| `onChange` | `on_change` | `Types.Color.t -> unit` | | Handler called when selection changes | +| `size` | `size` | `` [ `xs \| `sm \| `md \| `lg \| `xl ] `` | `` `md `` | Size of the swatches | +| `variant` | `variant` | `` [ `circle \| `square ] `` | `` `circle `` | Shape of the swatches | +| `layout` | `layout` | `` [ `grid \| `stack ] `` | `` `grid `` | Layout direction: wrapped in rows, or one above another | +| `aria-label` | `aria_label` | `string` | "Color swatches" | Its name | +| `aria-labelledby` | `aria_labelledby` | `string` | | The id of what names it | +| `className` | `class_` | `string` | | Added after HeroUI's classes | +| `render` | `as_` | a function of its props and state | | Draws another element in its place | + +### ColorSwatchPicker.Item + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `color` | `color` | `Types.Color.t` | required | The color of the swatch | +| `isDisabled` | `is_disabled` | `bool` | `false` | Whether the item is disabled | +| `className` | `class_` | `string` | | Added after HeroUI's class | +| `style` | `style` | `string` | | Added after its colour | +| `render` | `as_` | a function of its props and state | | Draws another element in its place | + +### ColorSwatchPicker.Swatch + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `colorName` | `color_name` | `string` | Kobalte's | The colour's name, which names its item | +| `className` | `class_` | `string` | | Added after HeroUI's class | + +### ColorSwatchPicker.Indicator + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `children` | `children` | nodes | a checkmark | What it shows once its item is chosen | +| `className` | `class_` | `string` | | Added after HeroUI's class | + +## Accessibility + +- Tab reaches the chosen swatch, or the first. +- In a grid, Left and Right move to the swatch before and after, as the page's + direction reads them, and Up and Down to the one above and below; in a + stack, Up and Down move to the one before and after. +- Home and End reach the ends, Page Up and Page Down too unless the list + scrolls, and typing the start of a colour's name reaches its swatch. +- A disabled swatch is passed over. A press, Space or Enter chooses a swatch. diff --git a/agents/pages/heroui/color-swatch.md b/agents/pages/heroui/color-swatch.md new file mode 100644 index 00000000..68d9e14c --- /dev/null +++ b/agents/pages/heroui/color-swatch.md @@ -0,0 +1,202 @@ +# ColorSwatch + +A visual preview of a color value with accessibility support. + +Its colour is a `Types.Color.t`, read from any CSS colour by +`Solidtype_kobalte.Colors.parse_color`. + +Original HeroUI documentation: [ColorSwatch](https://heroui.com/en/docs/react/components/color-swatch). + +## Usage + +HeroUI's examples. + +```ocaml title="color_swatch_usage.mlx" +module Color_swatch = Solidtype_heroui.Color_swatch +module Colors = Solidtype_kobalte.Colors + +let make () = +
    + + + + + +
    +``` + +## Parity + +The same HeroUI ColorSwatch twice, under the same props: in solidtype on the +left, in React on the right. Below them, every attribute of the two swatches: +a marked row is one they disagree on. + +## Examples + +### Sizes + +```ocaml title="color_swatch_sizes.mlx" +module Color_swatch = Solidtype_heroui.Color_swatch +module Colors = Solidtype_kobalte.Colors + +let make () = +
    + + + + + +
    +``` + +### Shapes + +```ocaml title="color_swatch_shapes.mlx" +module Color_swatch = Solidtype_heroui.Color_swatch +module Colors = Solidtype_kobalte.Colors + +let make () = +
    + + +
    +``` + +### Transparency + +```ocaml title="color_swatch_transparency.mlx" +module Color_swatch = Solidtype_heroui.Color_swatch +module Colors = Solidtype_kobalte.Colors + +let make () = +
    + + + + + +
    +``` + +### Render Function + +`as_` draws another element in its place, given its props and its state, as [Composition](composition.md#custom-dom-element) shows. + +### Accessibility + +Use `color_name` to provide a custom accessible name for the color, and +`aria_label` to add context about how the color is used. + +```ocaml title="color_swatch_accessibility.mlx" +module Color_swatch = Solidtype_heroui.Color_swatch +module Colors = Solidtype_kobalte.Colors + +let make () = +
    + + + +
    +``` + +## Customization + +### Tailwind CSS + +`class_` is added after HeroUI's classes, and `style` after the swatch's +colour, which it may paint over. + +```ocaml title="color_swatch_custom_styles.mlx" +module Color_swatch = Solidtype_heroui.Color_swatch +module Colors = Solidtype_kobalte.Colors +module For = Solidtype.For + +let colors = [| "#0485F7"; "#EF4444"; "#F59E0B"; "#10B981"; "#D946EF" |] + +let make () = +
    +
    + "Glow Effect" +
    + + (fun color _ -> + ) + +
    +
    +
    + "Gradient" +
    + + (fun color _ -> + ) + +
    +
    +
    +``` + +## Styling Reference + +### CSS Classes + +- `.color-swatch` - Base swatch styles with checkered background for + transparency, its colour `--color-swatch-current` +- `.color-swatch--circle` - Circular shape (default) +- `.color-swatch--square` - Square shape with rounded corners +- `.color-swatch--xs` - Extra small (16px) +- `.color-swatch--sm` - Small (24px) +- `.color-swatch--md` - Medium (32px, default) +- `.color-swatch--lg` - Large (36px) +- `.color-swatch--xl` - Extra large (40px) + +## API Reference + +Each prop beside the name HeroUI's React component gives it. + +### ColorSwatch + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `color` | `color` | `Types.Color.t` | its picker's, else transparent | The color value to display | +| `colorName` | `color_name` | `string` | Kobalte's | Accessible name for the color (overrides auto-generated description) | +| `aria-label` | `aria_label` | `string` | | Accessible label for the swatch, told after the colour's name | +| `shape` | `shape` | `` [ `circle \| `square ] `` | `` `circle `` | Shape of the swatch | +| `size` | `size` | `` [ `xs \| `sm \| `md \| `lg \| `xl ] `` | `` `md `` | Size of the swatch | +| `className` | `class_` | `string` | | Added after HeroUI's classes | +| `style` | `style` | `string` | | Inline styles, added after its colour; a function of the colour in React | +| `render` | `as_` | a function of its props and state | | Draws another element in its place | diff --git a/agents/pages/heroui/combo-box.md b/agents/pages/heroui/combo-box.md new file mode 100644 index 00000000..0bc0f0f0 --- /dev/null +++ b/agents/pages/heroui/combo-box.md @@ -0,0 +1,1507 @@ +# ComboBox + +A combo box combines a text input with a listbox, allowing users to filter a list of options to items matching a query. + +Original HeroUI documentation: [ComboBox](https://heroui.com/en/docs/react/components/combo-box). + +## Usage + +```ocaml title="combo_box_usage.mlx" +module Combo_box = Solidtype_heroui.Combo_box +module Input = Solidtype_heroui.Input +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box + +let make () = + + + + + + + + + "Aardvark" + + + "Cat" + + + "Dog" + + + "Kangaroo" + + + "Panda" + + + "Snake" + + + + +``` + +## Parity + +The same HeroUI ComboBox twice, under the same props: in solidtype on the +left, in React on the right. Below them, every attribute of each input: a +marked row is one they disagree on, and a dimmed row is a framework's own, +which no style reads. + +The marked row is Kobalte's: its input says it opens a list, `aria-haspopup="listbox"`, which a combo box means without it and React Aria leaves out. + +## Anatomy + +```ocaml + + + + + + + + ... + + + ... + + + +``` + +`Combo_box.Value` displays the selected values, primarily used for multiple +selection. + +## Examples + +### Full Width + +```ocaml title="combo_box_full_width.mlx" +module Combo_box = Solidtype_heroui.Combo_box +module Input = Solidtype_heroui.Input +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box + +let make () = +
    + + + + + + + + + "Aardvark" + + + "Cat" + + + "Dog" + + + "Kangaroo" + + + "Panda" + + + "Snake" + + + + +
    +``` + +### With Description + +```ocaml title="combo_box_with_description.mlx" +module Combo_box = Solidtype_heroui.Combo_box +module Input = Solidtype_heroui.Input +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box +module Description = Solidtype_heroui.Description + +let make () = + + + + + + + + + "Aardvark" + + + "Cat" + + + "Dog" + + + "Kangaroo" + + + "Panda" + + + "Snake" + + + + "Search and select your favorite animal" + +``` + +### Required + +A `Form` checks nothing itself: the example marks the combo box invalid once +a submit finds it empty. + +```ocaml title="combo_box_required.mlx" +module S = Solidtype.Solid +module Button = Solidtype_heroui.Button +module Combo_box = Solidtype_heroui.Combo_box +module Field_error = Solidtype_heroui.Field_error +module Form = Solidtype_heroui.Form +module Input = Solidtype_heroui.Input +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box + +external prevent_default : Dom.event -> unit = "preventDefault" [@@mel.send] +external alert : string -> unit = "alert" [@@mel.scope "window"] + +let make () = + let animal, set_animal = S.create_signal [||] in + (* A required combo box shows its error once a submit has been tried, as + the browser's validation React Aria reads does. *) + let tried, set_tried = S.create_signal false in + let missing () = S.get tried && Array.length (S.get animal) = 0 in +
    + prevent_default e; + S.set set_tried true; + if Array.length (S.get animal) > 0 then + alert "Form submitted successfully!")> + + + + + + + + + "Aardvark" + + + "Cat" + + + "Dog" + + + "Kangaroo" + + + "Panda" + + + "Snake" + + + + "Please select an item in the list." + + +
    +``` + +### Disabled + +```ocaml title="combo_box_disabled.mlx" +module Combo_box = Solidtype_heroui.Combo_box +module Input = Solidtype_heroui.Input +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box + +let make () = + + + + + + + + + "Aardvark" + + + "Cat" + + + "Dog" + + + "Kangaroo" + + + "Panda" + + + "Snake" + + + + +``` + +### With Disabled Options + +```ocaml title="combo_box_with_disabled_options.mlx" +module Combo_box = Solidtype_heroui.Combo_box +module Input = Solidtype_heroui.Input +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box + +let make () = + + + + + + + + + "Dog" + + + "Cat" + + + "Bird" + + + "Kangaroo" + + + "Elephant" + + + "Tiger" + + + + +``` + +### With Sections + +A section the input's text leaves empty is not drawn, its header with it. + +```ocaml title="combo_box_with_sections.mlx" +module Combo_box = Solidtype_heroui.Combo_box +module Input = Solidtype_heroui.Input +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box +module Header = Solidtype_heroui.Header +module Separator = Solidtype_heroui.Separator + +let make () = + + + + + + + + +
    "North America"
    + + "United States" + + + "Canada" + + + "Mexico" + +
    + + +
    "Europe"
    + + "United Kingdom" + + + "France" + + + "Germany" + + + "Spain" + + + "Italy" + +
    + + +
    "Asia"
    + + "Japan" + + + "China" + + + "India" + + + "South Korea" + +
    +
    +
    +
    +``` + +### Controlled + +The ids chosen are `value`, an array: one at most in a choice of one. + +```ocaml title="combo_box_controlled.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Combo_box = Solidtype_heroui.Combo_box +module Input = Solidtype_heroui.Input +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box + +type animal = { id : string; name : string } + +let animals = + [| + { id = "cat"; name = "Cat" }; + { id = "dog"; name = "Dog" }; + { id = "bird"; name = "Bird" }; + { id = "fish"; name = "Fish" }; + { id = "hamster"; name = "Hamster" }; + |] + +let make () = + let selected, set_selected = S.create_signal [| "cat" |] in + let selected_animal () = + match S.get selected with + | [| key |] -> Array.find_opt (fun a -> String.equal a.id key) animals + | _ -> None + in +
    + + + + + + + + + (fun animal _ -> + + (Jsx.string animal.name) + ) + + + + +

    + (Jsx.string + ("Selected: " + ^ match selected_animal () with Some a -> a.name | None -> "None")) +

    +
    +``` + +### Controlled Input Value + +```ocaml title="combo_box_controlled_input_value.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Combo_box = Solidtype_heroui.Combo_box +module Input = Solidtype_heroui.Input +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box + +let make () = + let input_value, set_input_value = S.create_signal "" in +
    + + + + + + + + + "Aardvark" + + + "Cat" + + + "Dog" + + + "Kangaroo" + + + "Panda" + + + "Snake" + + + + +

    + (Jsx.string + ("Input value: " + ^ match S.get input_value with "" -> "(empty)" | text -> text)) +

    +
    +``` + +### Asynchronous Loading + +The names are searched and loaded a part at a time. +`List_box.Load_more_item` asks for more as the list scrolls to its end, and +the list's `render_empty_state` draws an `Empty_state` while no name holds the +text typed. + +```ocaml title="combo_box_asynchronous_loading.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Combo_box = Solidtype_heroui.Combo_box +module Empty_state = Solidtype_heroui.Empty_state +module Input = Solidtype_heroui.Input +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box +module Spinner = Solidtype_heroui.Spinner + +(* The first two pages of https://swapi.py4e.com/api/people/, which HeroUI's + example searches, here searched and loaded a part at a time. *) +let characters = + [| + "Luke Skywalker"; + "C-3PO"; + "R2-D2"; + "Darth Vader"; + "Leia Organa"; + "Owen Lars"; + "Beru Whitesun lars"; + "R5-D4"; + "Biggs Darklighter"; + "Obi-Wan Kenobi"; + "Anakin Skywalker"; + "Wilhuff Tarkin"; + "Chewbacca"; + "Han Solo"; + "Greedo"; + "Jabba Desilijic Tiure"; + "Wedge Antilles"; + "Jek Tono Porkins"; + "Yoda"; + "Palpatine"; + |] + +(* How long the fetch it stands in for takes, and how many each brings. *) +let load_ms = 600 +let page = 10 + +(* Whether [part] is in [name], whatever their case, as the search finds it. *) +let holds ~part name = + let name = String.lowercase_ascii name + and part = String.lowercase_ascii part in + let n = String.length part in + let rec from i = + i + n <= String.length name + && (String.equal (String.sub name i n) part || from (i + 1)) + in + from 0 + +let make () = + let filter_text, set_filter_text = S.create_signal "" in + let loaded, set_loaded = S.create_signal 0 in + let loading, set_loading = S.create_signal false in + let found () = + Array.of_list + (List.filter + (fun name -> holds ~part:(S.get filter_text) name) + (Array.to_list characters)) + in + let load_more () = + let now = S.get loaded in + if (not (S.get loading)) && now < Array.length (found ()) then ( + S.set set_loading true; + let timer = + Js.Global.setTimeout + ~f:(fun () -> + S.set set_loaded (now + page); + S.set set_loading false) + load_ms + in + S.on_cleanup (fun () -> Js.Global.clearTimeout timer)) + in + let search text = + S.set set_filter_text text; + S.set set_loaded 0; + load_more () + in + S.on_mount load_more; + + + + + + + )> + + (fun name _ -> + + (Jsx.string name) + ) + + +
    + + "Loading more..." +
    +
    +
    +
    +
    +``` + +### Default Selected Key + +```ocaml title="combo_box_default_selected_key.mlx" +module Combo_box = Solidtype_heroui.Combo_box +module Input = Solidtype_heroui.Input +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box + +let make () = + + + + + + + + + "Aardvark" + + + "Cat" + + + "Dog" + + + "Kangaroo" + + + "Panda" + + + "Snake" + + + + +``` + +### Allows Custom Value + +```ocaml title="combo_box_allows_custom_value.mlx" +module Combo_box = Solidtype_heroui.Combo_box +module Input = Solidtype_heroui.Input +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box +module Description = Solidtype_heroui.Description + +let make () = + + + + + + + + + "Aardvark" + + + "Cat" + + + "Dog" + + + "Kangaroo" + + + "Panda" + + + "Snake" + + + + + "You can type any animal name, even if it's not in the list" + + +``` + +### Custom Indicator + +```ocaml title="combo_box_custom_indicator.mlx" +module Combo_box = Solidtype_heroui.Combo_box +module Input = Solidtype_heroui.Input +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box +module Gravity = Solidtype_gravity_icons + +let make () = + + + + + + + + + + + + "Aardvark" + + + "Cat" + + + "Dog" + + + "Kangaroo" + + + "Panda" + + + "Snake" + + + + +``` + +### Custom Value + +```ocaml title="combo_box_custom_value.mlx" +module Jsx = Solidtype.Jsx +module Avatar = Solidtype_heroui.Avatar +module Combo_box = Solidtype_heroui.Combo_box +module Description = Solidtype_heroui.Description +module Input = Solidtype_heroui.Input +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box + +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 () = + + + + + + + + + (fun (user : user) _ -> + + + + (Jsx.string user.fallback) + +
    + + (Jsx.string user.email) +
    + +
    ) +
    +
    +
    +
    +``` + +### Custom Filtering + +`default_filter` is given an option's text and the input's, and keeps the +options it answers `true` for. + +```ocaml title="combo_box_custom_filtering.mlx" +module Jsx = Solidtype.Jsx +module Combo_box = Solidtype_heroui.Combo_box +module Input = Solidtype_heroui.Input +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box + +type animal = { id : string; name : string } + +let animals = + [| + { id = "cat"; name = "Cat" }; + { id = "dog"; name = "Dog" }; + { id = "bird"; name = "Bird" }; + { id = "fish"; name = "Fish" }; + { id = "hamster"; name = "Hamster" }; + |] + +(* Whether [part] is in [text], whatever their case. *) +let holds ~part text = + let text = String.lowercase_ascii text + and part = String.lowercase_ascii part in + let n = String.length part in + let rec from i = + i + n <= String.length text + && (String.equal (String.sub text i n) part || from (i + 1)) + in + from 0 + +let make () = + + String.equal typed "" || holds ~part:typed text)> + + + + + + + + (fun animal _ -> + + (Jsx.string animal.name) + ) + + + + +``` + +### Render Function + +`as_` draws another element in its place, given its props and its state, as [Composition](composition.md#custom-dom-element) shows. + +### Menu Trigger + +Use the `menu_trigger` prop to control when the popover opens: + +- `` `focus `` (default): popover opens when the user focuses the input +- `` `input ``: popover opens when the user edits the input text +- `` `manual ``: popover only opens when the user presses the trigger button + or uses the arrow keys + +```ocaml title="combo_box_menu_trigger.mlx" +module Combo_box = Solidtype_heroui.Combo_box +module Input = Solidtype_heroui.Input +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box +module Description = Solidtype_heroui.Description + +let make () = +
    +
    +

    "Focus (default)"

    + + + + + + + + + "Aardvark" + + + "Cat" + + + "Dog" + + + "Kangaroo" + + + "Panda" + + + "Snake" + + + + "Popover opens when the input is focused" + +
    +
    +

    "Input"

    + + + + + + + + + "Aardvark" + + + "Cat" + + + "Dog" + + + "Kangaroo" + + + "Panda" + + + "Snake" + + + + + "Popover opens when the user edits the input text" + + +
    +
    +

    "Manual"

    + + + + + + + + + "Aardvark" + + + "Cat" + + + "Dog" + + + "Kangaroo" + + + "Panda" + + + "Snake" + + + + + "Popover only opens when the trigger button is pressed or arrow keys \ + are used" + + +
    +
    +``` + +### Form Value + +Use the `form_value` prop to control whether the selected item's key or text +is submitted in forms. `` `key `` is the default. When `allows_custom_value` +is true, the text is always submitted. + +```ocaml title="combo_box_form_value.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Button = Solidtype_heroui.Button +module Combo_box = Solidtype_heroui.Combo_box +module Description = Solidtype_heroui.Description +module Field_error = Solidtype_heroui.Field_error +module Form = Solidtype_heroui.Form +module Input = Solidtype_heroui.Input +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box + +external prevent_default : Dom.event -> unit = "preventDefault" [@@mel.send] +external current_target : Dom.event -> Dom.element = "currentTarget" [@@mel.get] + +type form_data + +external form_data : Dom.element -> form_data = "FormData" [@@mel.new] +external get : form_data -> string -> string Js.null = "get" [@@mel.send] + +type animal = { id : string; name : string } + +let animals = + [| + { id = "aardvark"; name = "Aardvark" }; + { id = "cat"; name = "Cat" }; + { id = "dog"; name = "Dog" }; + { id = "kangaroo"; name = "Kangaroo" }; + { id = "panda"; name = "Panda" }; + { id = "snake"; name = "Snake" }; + |] + +let list () = + + + (fun animal _ -> + + (Jsx.string animal.name) + ) + + + +let make () = + let message, set_message = S.create_signal None in + let sent data name = + Option.value (Js.Null.toOption (get data name)) ~default:"null" + in +
    + prevent_default e; + let data = form_data (current_target e) in + S.set set_message + (Some + ("Key: " ^ sent data "animal" ^ ". Text: " + ^ sent data "animal-text" ^ ".")))> + + + + + + (list ()) + "Submits the selected key" + + + + + + + + (list ()) + "Submits the selected text" + + + + (match S.get message with + | Some m ->

    (Jsx.string m)

    + | None -> Jsx.nothing) +
    +``` + +### Validation Behavior + +There is no `validation_behavior`: a field is invalid while `is_invalid` says +so, whenever the application decides, as the [Form](form.md) +page shows. + +### Custom Validation + +There is no `validate`: read the value the application keeps, and set +`is_invalid` from it. + +```ocaml title="combo_box_custom_validation.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Button = Solidtype_heroui.Button +module Combo_box = Solidtype_heroui.Combo_box +module Field_error = Solidtype_heroui.Field_error +module Form = Solidtype_heroui.Form +module Input = Solidtype_heroui.Input +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box + +external prevent_default : Dom.event -> unit = "preventDefault" [@@mel.send] +external alert : string -> unit = "alert" [@@mel.scope "window"] + +type animal = { id : string; name : string } + +let animals = + [| + { id = "aardvark"; name = "Aardvark" }; + { id = "cat"; name = "Cat" }; + { id = "dog"; name = "Dog" }; + { id = "kangaroo"; name = "Kangaroo" }; + { id = "panda"; name = "Panda" }; + { id = "snake"; name = "Snake" }; + |] + +(* The rule HeroUI's example gives its validate, here a reading of the value + the application keeps. *) +let problem = function + | [||] -> Some "Please select an animal" + | [| "snake" |] -> Some "Snakes are not allowed" + | _ -> None + +let make () = + let animal, set_animal = S.create_signal [||] in + let tried, set_tried = S.create_signal false in + let error () = if S.get tried then problem (S.get animal) else None in +
    + prevent_default e; + S.set set_tried true; + if Option.is_none (problem (S.get animal)) then + alert "Form submitted successfully!")> + + + + + + + + + (fun animal _ -> + + (Jsx.string animal.name) + ) + + + + + (Jsx.string (Option.value (error ()) ~default:"")) + + + +
    +``` + +### Read Only + +Use the `is_read_only` prop to make the combo box read-only. The selected +value can be focused, but it cannot be changed. + +```ocaml title="combo_box_read_only.mlx" +module Combo_box = Solidtype_heroui.Combo_box +module Input = Solidtype_heroui.Input +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box + +let make () = + + + + + + + + + "Aardvark" + + + "Cat" + + + "Dog" + + + "Kangaroo" + + + "Panda" + + + "Snake" + + + + +``` + +### Multiple Selection + +Set ``selection_mode=`multiple`` to allow selecting more than one option. In +multiple selection mode, use `Combo_box.Value` to display the selected items +and pass ``selection_mode=`multiple`` to the inner `List_box` as well. +Selection is controlled with the `value` / `default_value` (`string array`) +props and the `on_change` handler. + +```ocaml title="combo_box_multiple_selection.mlx" +module Combo_box = Solidtype_heroui.Combo_box +module Input = Solidtype_heroui.Input +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box + +let make () = + + + + + + + + + + "Aardvark" + + + "Cat" + + + "Dog" + + + "Kangaroo" + + + "Panda" + + + "Snake" + + + + +``` + +### In Surface + +When used inside a [Surface](surface.md) component, use +``variant=`secondary`` to apply the lower emphasis variant suitable for +surface backgrounds. + +```ocaml title="combo_box_in_surface.mlx" +module S = Solidtype.Solid +module Button = Solidtype_heroui.Button +module Combo_box = Solidtype_heroui.Combo_box +module Field_error = Solidtype_heroui.Field_error +module Form = Solidtype_heroui.Form +module Input = Solidtype_heroui.Input +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box +module Surface = Solidtype_heroui.Surface + +external prevent_default : Dom.event -> unit = "preventDefault" [@@mel.send] +external alert : string -> unit = "alert" [@@mel.scope "window"] + +let make () = + let animal, set_animal = S.create_signal [||] in + (* A required combo box shows its error once a submit has been tried, as + the browser's validation React Aria reads does. *) + let tried, set_tried = S.create_signal false in + let missing () = S.get tried && Array.length (S.get animal) = 0 in + +
    + prevent_default e; + S.set set_tried true; + if Array.length (S.get animal) > 0 then + alert "Form submitted successfully!")> + + + + + + + + + "Aardvark" + + + "Cat" + + + "Dog" + + + "Kangaroo" + + + "Panda" + + + "Snake" + + + + "Please select an item in the list." + + +
    +
    +``` + +## Customization + +### Tailwind CSS + +`class_` is added after HeroUI's classes. + +```ocaml title="combo_box_tailwind.mlx" +module Combo_box = Solidtype_heroui.Combo_box +module Input = Solidtype_heroui.Input +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box + +let item_class = + "rounded-lg data-[focused=true]:bg-muted/70 data-[selected=true]:font-medium \ + data-[selected=true]:text-foreground" + +let make () = + + + + + + + + + + "React" + + + "Vue" + + + "Svelte" + + + + +``` + +### Global CSS + +To customize the ComboBox component classes, you can use the +`@layer components` directive. +[Learn more](https://tailwindcss.com/docs/adding-custom-styles#adding-component-classes). + +```css +@layer components { + .combo-box { + @apply flex flex-col gap-1; + } + + .combo-box__input-group { + @apply relative inline-flex items-center; + } + + .combo-box__trigger { + @apply absolute right-0 text-muted; + } + + .combo-box__popover { + @apply rounded-lg border border-border bg-surface p-2; + } +} +``` + +## Styling Reference + +### CSS Classes + +- `.combo-box` - Base ComboBox container +- `.combo-box--full-width` - Full width modifier +- `.combo-box__input-group` - Container for the input and trigger button +- `.combo-box__input-group--full-width` - Full width input group +- `.combo-box__value` - The selected value display (used in multiple + selection) +- `.combo-box__trigger` - The button that triggers the popover +- `.combo-box__popover` - The popover container + +### Interactive States + +- **Open**: `[data-open="true"]` on the combo box and its trigger +- **Focus**: `[data-focused="true"]` on the combo box and its input, and + `[data-focus-visible="true"]` on its input and trigger +- **Hover** and **Pressed**: `[data-hovered="true"]`, `[data-pressed="true"]` + on the trigger, pressed while the list is open +- **Placeholder**: `[data-placeholder="true"]` on the value +- **Invalid**, **Disabled**, **Read-only**, **Required**: + `[data-invalid="true"]`, `[data-disabled="true"]`, `[data-readonly="true"]`, + `[data-required="true"]` on the combo box +- **Entering** and **Exiting**: `[data-entering="true"]`, + `[data-exiting="true"]` on the popover + +## API Reference + +Each prop beside the name HeroUI's React component gives it. + +### ComboBox + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `selectionMode` | `selection_mode` | `` `single `` \| `` `multiple `` | `` `single `` | Whether single or multiple selection is enabled, read as it is made | +| `value`, `selectedKey` | `value` | `string array` | | The currently selected keys (controlled) | +| `defaultValue`, `defaultSelectedKey` | `default_value` | `string array` | | The initial selected keys (uncontrolled) | +| `onChange`, `onSelectionChange` | `on_change` | `string array -> unit` | | Handler called when the selection changes | +| `inputValue` | `input_value` | `string` | | Current input value (controlled) | +| `defaultInputValue` | `default_input_value` | `string` | | Default input value (uncontrolled) | +| `onInputChange` | `on_input_change` | `string -> unit` | | Handler called when the input value changes | +| `onOpenChange` | `on_open_change` | `bool -> unit` | | Told as the list opens or closes | +| `disabledKeys` | `disabled_keys` | `string array` | | Keys of disabled items | +| `defaultFilter` | `default_filter` | `string -> string -> bool` | contains | Custom filter function for filtering items, given an option's text and the input's | +| `menuTrigger` | `menu_trigger` | `` `focus `` \| `` `input `` \| `` `manual `` | `` `focus `` | The interaction required to display the ComboBox menu | +| `allowsCustomValue` | `allows_custom_value` | `bool` | `false` | Whether the ComboBox allows custom values not in the list | +| `allowsEmptyCollection` | `allows_empty_collection` | `bool` | `false` | Whether the ComboBox allows an empty collection | +| `shouldFocusWrap` | `should_focus_wrap` | `bool` | `false` | Whether keyboard navigation is circular | +| `isDisabled` | `is_disabled` | `bool` | `false` | Whether the ComboBox is disabled | +| `isReadOnly` | `is_read_only` | `bool` | `false` | Whether the input can be selected but not changed by the user | +| `isRequired` | `is_required` | `bool` | `false` | Whether user input is required | +| `isInvalid` | `is_invalid` | `bool` | `false` | Whether the ComboBox value is invalid | +| `name` | `name` | `string` | | The name of the input, used when submitting an HTML form | +| `formValue` | `form_value` | `` `key `` \| `` `text `` | `` `key `` | Whether the text or key of the selected item is submitted as part of an HTML form. When `allows_custom_value` is true, the text is always submitted | +| `onBlur` | `on_blur` | `Dom.focusEvent -> unit` | | Told as the focus leaves it | +| `fullWidth` | `full_width` | `bool` | `false` | Whether the ComboBox should take full width of its container | +| `variant` | `variant` | `` `primary `` \| `` `secondary `` | `` `primary `` | Visual variant of the component. `` `primary `` is the default style with shadow. `` `secondary `` is a lower emphasis variant without shadow, suitable for use in surfaces | +| `className` | `class_` | `string` | | Added after HeroUI's classes | +| `children` | `children` | elements | | Its label, input group, value, description and popover | + +### ComboBox.InputGroup, ComboBox.Trigger, ComboBox.Popover + +| React | solidtype | Type | Description | +|---|---|---|---| +| `placement` | `placement` | `` `top `` \| `` `bottom `` \| `` `left `` \| `` `right `` | 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; the trigger's own icon | + +### ComboBox.Value + +Renders the selected values of a combo box, or a placeholder if no value is +selected. By default the selected items are rendered as a list in the +reader's language, "Cat, Dog, and Panda". Use the render function to customize this (for example, to display +tags). + +| React | solidtype | Type | Description | +|---|---|---|---| +| `placeholder` | `placeholder` | `string` | A value to display when no items are selected | +| `className` | `class_` | `string` | Added after HeroUI's classes | +| `children` | `children` | `string array accessor -> element` | Custom render function for the selected values, given the ids chosen | + +## Accessibility + +`Combo_box` implements the ARIA combobox pattern and provides: + +- Full keyboard navigation support: the arrows move through the options while + the focus stays in the input, Enter or a press chooses one, and Escape + closes the list +- Filtering by the input's text, whatever its case or accents +- Proper focus management +- Support for disabled states +- HTML form integration: a form is sent the ids chosen, or the input's text + where it is the value +- Support for custom values: Escape on a closed list, or leaving the input, + puts back the text of the option chosen, unless custom values are allowed + +While the list is open, the rest of the page stays reachable by a screen +reader. diff --git a/agents/pages/heroui/composition.md b/agents/pages/heroui/composition.md new file mode 100644 index 00000000..14a4c100 --- /dev/null +++ b/agents/pages/heroui/composition.md @@ -0,0 +1,164 @@ +# Composition + +Build flexible UI with component composition patterns. + +HeroUI uses composition patterns to create flexible, customizable components. +Change the rendered element, compose components together, and maintain full +control over markup. + +Original HeroUI documentation: [Composition](https://heroui.com/docs/react/getting-started/composition). + +## Parts + +HeroUI components are built as compound components: they export multiple +parts that work together. A component is a module and its parts are modules +inside it: `` is HeroUI's `` or ``, and +`` its ``. + +```ocaml +module Alert = Solidtype_heroui.Alert + +let saved () = + + + + "Saved" + "Your changes have been saved." + + +``` + +## HeroUI's look on any element + +Apply HeroUI styles to any element using variant functions or BEM classes. +`Solidtype_heroui.Styles` holds HeroUI's variant functions, one module each: +`buttonVariants` is `Styles.Button`, its variants the optional arguments of +`options`, and `classes` the class string; a component of several parts has +`slots`, and a function per part. HeroUI's BEM classes work as they are: + +```ocaml title="composition_link.mlx" +module Styles = Solidtype_heroui.Styles + +(* A button's look on a link: HeroUI's variant function, or its classes as + they are. *) +let make () = + let primary = + Styles.Button.classes (Styles.Button.options ~variant:`primary ()) + in + +``` + +Such an element has HeroUI's look at rest and its `:hover` and `:active` +rules, but none of the state a port declares. `Solidtype_heroui.Interaction` +gives any element the hover, press and focus state HeroUI's styles read: + +```ocaml title="composition_state.mlx" +module Jsx = Solidtype.Jsx +module Interaction = Solidtype_heroui.Interaction + +(* An element no port renders, given HeroUI's classes and the state its styles + read, as a port declares it. *) +let make () = + let i = Interaction.create () in + Interaction.watch i e) + data_hovered=(Jsx.flag (Interaction.hovered i)) + data_pressed=(Jsx.flag (Interaction.pressed i)) + data_focus_visible=(Jsx.flag (Interaction.focus_visible i))> + "A link, pressed as a button" + +``` + +## Custom variants + +Create custom variants by wrapping a port in a component of your own that +gives it classes. They come after HeroUI's, and a utility wins over HeroUI's +classes, which are in Tailwind's `components` layer: + +```ocaml title="composition_variants.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Button = Solidtype_heroui.Button + +(* A button of one's own: a variant HeroUI's has not, as classes given to + HeroUI's, which its own variant function merges over its own. *) +module Pill_button = struct + let%component make ?(radius : [ `full | `sm ] = `full) + ~(children : Jsx.element) () = + +end + +let make () = +
    + "Full" + "Small" +
    +``` + +## Custom DOM Element + +Use the `as_` prop, HeroUI's `render`, on a part that draws an element to +render a custom component in place of the default DOM element. It is a +function of the part's props and, where the part has one, its state. + +For example, you can render a [Motion](https://motion.dev/) button and use the +state to drive an animation. + +```ocaml title="composition_motion.mlx" +module Button = Solidtype_heroui.Button +module S = Solidtype.Solid + +(* solid-motionone's button, bound by what this page uses of it. *) +module Motion_button = struct + type keyframes + + external keyframes : scale:float -> keyframes = "" [@@mel.obj] + + module Props = struct + external check : + animate:keyframes Solidtype.Check.value -> + ?props:'spread Solidtype.Solid.rest -> + (?children:('f, [ `elements ]) Solidtype.Check.children -> unit -> unit) + Solidtype.Html.Button.check = "check" + [@@mel.module "vite-plugin-solidtype/markers"] + end + + external component : unit Solidtype.Jsx.component = "button" + [@@mel.module "solid-motionone"] [@@mel.scope "Motion"] +end + +let make () = + +``` + +Follow these rules to avoid breaking the behavior and accessibility of the +component: + +- Always render the expected element type (e.g. if ` + + ())> + + + + + + + + + + + + + + + + + + + + +let columns money = + [| + Data_grid.column ~id:"customer" ~header:(Text "Customer") + ~is_row_header: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") + ~cell_class:"font-mono text-xs text-muted" (fun p -> + Jsx.string (S.get p).id); + Data_grid.column ~id:"status" ~header:(Text "Status") + ~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_ + ~sort:(By (fun a b -> Float.compare a.amount b.amount)) + ~cell_class:"tabular-nums" + (fun p -> + Jsx.string (Types.NumberFormat.format (S.get money) (S.get p).amount)); + 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 + p.id) + columns=(columns money) + selection_mode=`multiple + show_selection_checkboxes=true + default_sort_descriptor={ column = "customer"; direction = `ascending } + content_class="min-w-[720px]" + /> +``` + +## Anatomy + +```ocaml + p.id) columns /> +``` + +## Column Definitions + +`Data_grid.column ~id ~header cell` makes a column: `cell` draws a cell from +its row, and `header` is `Text`, `Element` of a function drawn where the +header is, or `Sorted`, drawn from the column's sort direction. A column is +sortable exactly when it has a `sort`, `By_text` of a row's text, in the +order of the page's language, or `By` a comparison of two rows. `align`, +`width`, `min_width`, `max_width`, `pinned`, `header_class` and `cell_class` +lay it out. + +## Sorting + +A grid given no `sort_descriptor` keeps its own sort, `default_sort_descriptor` +at first, and orders its rows as a header is pressed. Given one, the sort is +the application's: the grid draws its rows as given and tells +`on_sort_change`, as a server sorts them. A `By` comparison orders rows by +anything, here priorities by their rank. + +```ocaml title="data_grid_sorting.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Chip = Solidtype_heroui.Chip +module Data_grid = Solidtype_heroui.Data_grid + +type priority = Low | Medium | High | Urgent +type task = { id : string; title : string; priority : priority; due : string } + +let tasks = + [| + { + id = "1"; + title = "Renew the SSL certificate"; + priority = Urgent; + due = "2026-11-21"; + }; + { id = "2"; title = "Plan the offsite"; priority = Low; due = "2026-12-10" }; + { + id = "3"; + title = "Review the Q4 budget"; + priority = High; + due = "2026-11-28"; + }; + { + id = "4"; + title = "Update the onboarding guide"; + priority = Medium; + due = "2026-12-02"; + }; + { + id = "5"; + title = "Fix the export timeout"; + priority = High; + due = "2026-11-24"; + }; + |] + +let rank = function Low -> 0 | Medium -> 1 | High -> 2 | Urgent -> 3 + +let priority_name = function + | Low -> "Low" + | Medium -> "Medium" + | High -> "High" + | Urgent -> "Urgent" + +let priority_color = function + | Low -> `default + | Medium -> `accent + | High -> `warning + | Urgent -> `danger + +let columns = + [| + Data_grid.column ~id:"title" ~header:(Text "Task") ~is_row_header:true + ~sort:(By_text (fun t -> t.title)) + (fun t -> Jsx.string (S.get t).title); + (* Priorities in their own order, never their names'. *) + Data_grid.column ~id:"priority" ~header:(Text "Priority") + ~sort:(By (fun a b -> Int.compare (rank a.priority) (rank b.priority))) + (fun t -> + + (Jsx.string (priority_name (S.get t).priority)) + ); + Data_grid.column ~id:"due" ~header:(Text "Due") ~align:`end_ + ~sort:(By_text (fun t -> t.due)) + ~cell_class:"tabular-nums text-muted" + (fun t -> Jsx.string (S.get t).due); + |] + +let make () = + t.id) + columns + default_sort_descriptor={ column = "priority"; direction = `descending } + /> +``` + +## Row Selection + +`selection_mode` with `show_selection_checkboxes` adds a column of +checkboxes, the header's choosing every row. The selection is +`selected_keys`, or `default_selected_keys`, and `on_selection_change`. + +## Column Resizing + +`allows_column_resize` on the grid, and `allows_resizing` on a column, let a +column be resized by a drag or the keys, within its `min_width` and +`max_width`; `on_column_resize` is told each step and `on_column_resize_end` +the last. A column needs no width of its own to be resized. + +```ocaml title="data_grid_column_resizing.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Data_grid = Solidtype_heroui.Data_grid +module Table = Solidtype_heroui.Table + +type member = { id : string; name : string; role : string; email : string } + +let members = + [| + { + id = "1"; + name = "Kate Moore"; + role = "Chief Executive Officer"; + email = "kate@acme.com"; + }; + { + id = "2"; + name = "John Smith"; + role = "Chief Technology Officer"; + email = "john@acme.com"; + }; + { + id = "3"; + name = "Sara Johnson"; + role = "Chief Marketing Officer"; + email = "sara@acme.com"; + }; + { + id = "4"; + name = "Michael Brown"; + role = "Chief Financial Officer"; + email = "michael@acme.com"; + }; + |] + +let columns = + [| + Data_grid.column ~id:"name" ~header:(Text "Name") ~is_row_header:true + ~allows_resizing:true ~default_width:(Pixels 180.) ~min_width:120. + (fun m -> Jsx.string (S.get m).name); + Data_grid.column ~id:"role" ~header:(Text "Role") ~allows_resizing:true + ~default_width:(Fraction 1.) ~min_width:160. (fun m -> + Jsx.string (S.get m).role); + Data_grid.column ~id:"email" ~header:(Text "Email") ~allows_resizing:true + ~default_width:(Fraction 1.) ~min_width:160. (fun m -> + Jsx.string (S.get m).email); + |] + +let size_name : Table.column_size -> string = function + | Pixels p -> Js.Float.toString p ^ "px" + | Percent p -> Js.Float.toString p ^ "%" + | Fraction f -> Js.Float.toString f ^ "fr" + +let make () = + let widths, set_widths = S.create_signal "" in +
    + m.id) + columns + allows_column_resize=true + on_column_resize_end=(fun sizes -> + S.set set_widths + (String.concat ", " + (Array.to_list + (Array.map + (fun (id, size) -> + id ^ " " ^ size_name size) + sizes)))) + /> +

    + "Widths: " + (Jsx.string (match S.get widths with "" -> "as given" | w -> w)) +

    +
    +``` + +## Pinned Columns + +A column `pinned` to `` `start `` or `` `end_ `` stays in view as the others +scroll sideways, a line at its edge while content passes beneath it. It needs +no width of its own: its place is measured. The checkbox and handle columns +stay with the columns pinned to the start. + +```ocaml title="data_grid_pinned_columns.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 Gravity = Solidtype_gravity_icons + +type strength = Very_strong | Strong | Weak | Very_weak | No_communication + +type company = { + id : string; + name : string; + dot : string; + industries : string array; + linkedin : string; + last_interaction : string; + strength : strength; +} + +let companies = + [| + { + id = "1"; + name = "LVMH"; + dot = "bg-warning"; + industries = [| "Luxury"; "E-commerce" |]; + linkedin = "lvmh"; + last_interaction = "No contact"; + strength = No_communication; + }; + { + id = "2"; + name = "Disney"; + dot = "bg-success"; + industries = [| "Media" |]; + linkedin = "disney-music-group"; + last_interaction = "No contact"; + strength = No_communication; + }; + { + id = "3"; + name = "PayPal"; + dot = "bg-accent"; + industries = [| "Financial Services"; "Payments" |]; + linkedin = "paypal"; + last_interaction = "No contact"; + strength = No_communication; + }; + { + id = "4"; + name = "sweetgreen"; + dot = "bg-success"; + industries = [| "Food"; "Retail" |]; + linkedin = "sweetgreen"; + last_interaction = "about 2 hours ago"; + strength = Very_strong; + }; + { + id = "5"; + name = "OpenPhone"; + dot = "bg-accent"; + industries = [| "Telecom" |]; + linkedin = "openphone"; + last_interaction = "2 days ago"; + strength = Weak; + }; + { + id = "6"; + name = "Attio"; + dot = "bg-accent"; + industries = [| "Enterprise"; "CRM" |]; + linkedin = "attio"; + last_interaction = "about 3 hours ago"; + strength = Very_weak; + }; + { + id = "7"; + name = "Opera"; + dot = "bg-danger"; + industries = [| "Software"; "Browsers"; "AI" |]; + linkedin = "opera-software"; + last_interaction = "14 days ago"; + strength = Very_weak; + }; + { + id = "8"; + name = "Google"; + dot = "bg-accent"; + industries = [| "Hosting"; "Search" |]; + linkedin = "google"; + last_interaction = "9 days ago"; + strength = Weak; + }; + |] + +let strength_name = function + | Very_strong -> "Very strong" + | Strong -> "Strong" + | Weak -> "Weak" + | Very_weak -> "Very weak" + | No_communication -> "No communication" + +let strength_class = function + | Very_strong | Strong -> "text-success" + | Weak -> "text-warning" + | Very_weak -> "text-danger" + | No_communication -> "text-muted" + +let columns = + [| + Data_grid.column ~id:"company" ~header:(Text "Company") ~is_row_header:true + ~pinned:`start ~width:(Pixels 160.) + ~sort:(By_text (fun c -> c.name)) + (fun c -> + + + (Jsx.string (S.get c).name) + ); + Data_grid.column ~id:"industries" ~header:(Text "Industries") + ~width:(Pixels 220.) (fun c -> + + + (Jsx.string (S.get c).industries.(0)) + + (match Array.length (S.get c).industries with + | 1 -> Jsx.fragment [||] + | n -> + + (Jsx.string ("+" ^ string_of_int (n - 1))) + ) + ); + Data_grid.column ~id:"linkedin" ~header:(Text "LinkedIn") + ~width:(Pixels 200.) (fun c -> + + (Jsx.string (S.get c).linkedin) + ); + Data_grid.column ~id:"last" ~header:(Text "Last interaction") + ~width:(Pixels 180.) (fun c -> Jsx.string (S.get c).last_interaction); + Data_grid.column ~id:"strength" ~header:(Text "Connection strength") + ~width:(Pixels 200.) (fun c -> + + + (Jsx.string (strength_name (S.get c).strength)) + ); + |] + +let make () = + c.id) + columns + selection_mode=`multiple + show_selection_checkboxes=true + footer=( + (Jsx.string (string_of_int (Array.length companies) ^ " count")) + ) + /> +``` + +## Drag and Drop + +Given `on_reorder`, each row has a handle: Enter grabs the row, the arrows +move it, Enter drops it and Escape lets it go, and a pointer drags it. +`on_reorder` is told the rows moved, where they landed, and `rows`, every row +in its new order. Selected rows are dragged together. + +```ocaml title="data_grid_drag_and_drop.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Chip = Solidtype_heroui.Chip +module Data_grid = Solidtype_heroui.Data_grid + +type task = { id : string; title : string; assignee : string; points : int } + +let tasks = + [| + { + id = "task-1"; + title = "Design system audit"; + assignee = "Kate Moore"; + points = 5; + }; + { + id = "task-2"; + title = "Billing page redesign"; + assignee = "John Smith"; + points = 8; + }; + { + id = "task-3"; + title = "Onboarding emails"; + assignee = "Sara Johnson"; + points = 3; + }; + { + id = "task-4"; + title = "API rate limits"; + assignee = "Michael Brown"; + points = 5; + }; + { + id = "task-5"; + title = "Dark mode polish"; + assignee = "Kate Moore"; + points = 2; + }; + |] + +let columns = + [| + Data_grid.column ~id:"title" ~header:(Text "Task") ~is_row_header:true + (fun t -> Jsx.string (S.get t).title); + Data_grid.column ~id:"assignee" ~header:(Text "Assignee") + ~cell_class:"text-muted" (fun t -> Jsx.string (S.get t).assignee); + Data_grid.column ~id:"points" ~header:(Text "Points") ~align:`end_ (fun t -> + (Jsx.int (S.get t).points)); + |] + +let make () = + let rows, set_rows = S.create_signal tasks in + t.id) + columns + on_reorder=(fun r -> S.set set_rows r.rows) + /> +``` + +## Editable Cells + +A cell draws any control: a `Select`, 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 Chip = Solidtype_heroui.Chip +module Data_grid = Solidtype_heroui.Data_grid +module List_box = Solidtype_heroui.List_box +module Number_stepper = Solidtype_heroui.Number_stepper +module Select = Solidtype_heroui.Select +module Switch = Solidtype_heroui.Switch + +type priority = Low | Medium | High + +type flag = { + id : string; + feature : string; + priority : priority; + points : float; + enabled : bool; +} + +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; + }; + |] + +let priority_key = function Low -> "low" | Medium -> "medium" | High -> "high" +let priority_of = function "high" -> High | "medium" -> Medium | _ -> Low + +let priority_name = function + | Low -> "Low" + | Medium -> "Medium" + | High -> "High" + +let priority_color = function + | Low -> `default + | Medium -> `warning + | High -> `danger + +let make () = + let rows, set_rows = S.create_signal flags in + let change id f = + S.set set_rows + (Array.map + (fun r -> if String.equal r.id id then f r else r) + (S.get rows)) + in + 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); + 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 -> + + change (S.get row).id (fun r -> { r with points }))> + + + + + + ); + Data_grid.column ~id:"enabled" ~header:(Text "Enabled") ~align:`center + ~width:(Pixels 100.) (fun row -> + + change (S.get row).id (fun r -> { r with enabled }))> + + + + ); + |] + in + let enabled () = + Array.length (Js.Array.filter ~f:(fun r -> r.enabled) (S.get rows)) + in + 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")) + + ) + /> +``` + +## Empty State + +`empty_state` is drawn across every column while there are no rows. + +```ocaml title="data_grid_empty_state.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Button = Solidtype_heroui.Button +module Data_grid = Solidtype_heroui.Data_grid +module Empty_state = Solidtype_heroui.Empty_state +module Gravity = Solidtype_gravity_icons + +type project = { id : string; name : string; owner : string; files : int } + +let columns = + [| + Data_grid.column ~id:"project" ~header:(Text "Project") ~is_row_header:true + (fun p -> Jsx.string (S.get p).name); + Data_grid.column ~id:"owner" ~header:(Text "Owner") (fun p -> + Jsx.string (S.get p).owner); + Data_grid.column ~id:"files" ~header:(Text "Files") ~align:`end_ (fun p -> + Jsx.int (S.get p).files); + |] + +let make () = + p.id) + columns + empty_state=( + + + + + "No projects yet" + + + "Get started by creating your first project." + + + ) + /> +``` + +## Async Loading + +Given `on_load_more`, the grid asks for more rows as its end comes into view, +`load_more_content` drawn while `is_loading_more`. Give the scroll container +a height by `scroll_container_class`. + +```ocaml title="data_grid_async_loading.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Data_grid = Solidtype_heroui.Data_grid +module Spinner = Solidtype_heroui.Spinner + +type order = { id : string; customer : string; total : string } + +let page n = + Array.init 20 (fun i -> + let k = (n * 20) + i + 1 in + { + id = string_of_int k; + customer = "Customer " ^ string_of_int k; + total = "$" ^ string_of_int ((k * 37 mod 900) + 100) ^ ".00"; + }) + +let columns = + [| + Data_grid.column ~id:"id" ~header:(Text "Order") ~is_row_header:true + ~cell_class:"tabular-nums" (fun o -> Jsx.string ("#" ^ (S.get o).id)); + Data_grid.column ~id:"customer" ~header:(Text "Customer") (fun o -> + Jsx.string (S.get o).customer); + Data_grid.column ~id:"total" ~header:(Text "Total") ~align:`end_ + ~cell_class:"tabular-nums" (fun o -> Jsx.string (S.get o).total); + |] + +let make () = + let rows, set_rows = S.create_signal (page 0) in + let loading, set_loading = S.create_signal false in + let more () = Array.length (S.get rows) < 100 in + o.id) + columns + scroll_container_class="max-h-[400px] overflow-y-auto" + sticky_header=true + is_loading_more=(S.get loading) + on_load_more=(fun () -> + if more () && not (S.get loading) then begin + S.set set_loading true; + ignore + (Js.Global.setTimeout + ~f:(fun () -> + S.set set_rows + (Array.append (S.get rows) + (page (Array.length (S.get rows) / 20))); + S.set set_loading false) + 800 + : Js.Global.timeoutId) + end) + load_more_content=() + /> +``` + +## 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. + +## 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. + +```ocaml title="data_grid_virtualization.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Data_grid = Solidtype_heroui.Data_grid + +type entry = { id : string; name : string; email : string; city : string } + +let cities = [| "Berlin"; "Lisbon"; "Oslo"; "Tokyo"; "Toronto"; "Nairobi" |] + +let entries = + Array.init 1000 (fun i -> + { + 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); + }) + +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); + |] + +let make () = + e.id) + columns + virtualized=true + row_height=48. + heading_height=36. + content_class="h-[400px] min-w-[640px] overflow-auto" + /> +``` + +## Team Members + +Search, a status filter and the columns shown are the application's: it +filters `rows` and `columns` before giving them. Rows paged in the `footer`, +a header kept in view, a column pinned to each side. + +```ocaml title="data_grid_team_members.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Avatar = Solidtype_heroui.Avatar +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 Pagination = Solidtype_heroui.Pagination +module Search_field = Solidtype_heroui.Search_field +module Gravity = Solidtype_gravity_icons + +type status = Active | Vacation | Inactive + +type member = { + id : string; + name : string; + email : string; + kind : string; + status : status; + start : string; + team : string; +} + +let first_names = + [| "Aaron"; "Alice"; "Bella"; "Bob"; "Carla"; "David"; "Emma"; "Felix" |] + +let last_names = [| "Carter"; "Johnson"; "Brown"; "Smith"; "Lopez"; "Kim" |] +let teams = [| "Design"; "Product"; "Engineering"; "Sales"; "Other" |] +let two n = (if n < 10 then "0" else "") ^ string_of_int n + +let members = + Array.init 48 (fun i -> + let first = first_names.(i mod Array.length first_names) in + let last = last_names.(i mod Array.length last_names) in + { + id = string_of_int (i + 1); + name = first ^ " " ^ last; + email = + String.lowercase_ascii first + ^ "." + ^ String.lowercase_ascii last + ^ "@example.com"; + kind = (if i mod 3 = 0 then "Contractor" else "Employee"); + status = + (match i mod 4 with 0 -> Inactive | 1 -> Vacation | _ -> Active); + start = "2025-" ^ two ((i mod 12) + 1) ^ "-" ^ two ((i mod 27) + 1); + team = teams.(i mod Array.length teams); + }) + +let status_name = function + | Active -> "Active" + | Vacation -> "Vacation" + | Inactive -> "Inactive" + +let status_key = function + | Active -> "active" + | Vacation -> "vacation" + | Inactive -> "inactive" + +let status_color = function + | Active -> `success + | Vacation -> `warning + | Inactive -> `danger + +let initials name = + String.concat "" + (List.map + (fun w -> String.sub w 0 1) + (List.filter + (fun w -> not (String.equal w "")) + (String.split_on_char ' ' name))) + +let all_columns = + [| + Data_grid.column ~id:"member" ~header:(Text "Member") ~is_row_header:true + ~pinned:`start ~width:(Pixels 260.) + ~sort:(By_text (fun m -> m.name)) + (fun m -> + + + + (Jsx.string (initials (S.get m).name)) + + + + (Jsx.string (S.get m).name) + + (Jsx.string (S.get m).email) + + + ); + Data_grid.column ~id:"kind" ~header:(Text "Worker type") + ~width:(Pixels 140.) + ~sort:(By_text (fun m -> m.kind)) + (fun m -> Jsx.string (S.get m).kind); + Data_grid.column ~id:"status" ~header:(Text "Status") ~width:(Pixels 130.) + ~sort:(By_text (fun m -> status_name m.status)) + (fun m -> + + + (Jsx.string (status_name (S.get m).status)) + ); + Data_grid.column ~id:"start" ~header:(Text "Start date") + ~width:(Pixels 160.) + ~sort:(By_text (fun m -> m.start)) + (fun m -> + + + (Jsx.string (S.get m).start) + ); + Data_grid.column ~id:"team" ~header:(Text "Team") ~width:(Pixels 140.) + (fun m -> + (Jsx.string (S.get m).team)); + Data_grid.column ~id:"actions" + ~header:(Element (fun () -> "Actions")) + ~align:`end_ ~pinned:`end_ ~width:(Pixels 64.) + (fun m -> + + + + ())> + + + + + + + + + ); + |] + +let per_page = 10 + +let make () = + let query, set_query = S.create_signal "" in + let statuses, set_statuses = + S.create_signal [| "active"; "vacation"; "inactive" |] + in + let shown_columns, set_shown_columns = + S.create_signal + (Array.map (fun (c : member Data_grid.column) -> c.id) all_columns) + in + let page, set_page = S.create_signal 1 in + let selected, set_selected = S.create_signal [||] in + let matching () = + let q = String.lowercase_ascii (S.get query) in + Js.Array.filter + ~f:(fun m -> + Array.exists (String.equal (status_key m.status)) (S.get statuses) + && (String.equal q "" + || Js.String.includes ~search:q (String.lowercase_ascii m.name) + || Js.String.includes ~search:q m.email)) + members + in + let pages () = + max 1 ((Array.length (matching ()) + per_page - 1) / per_page) + in + let shown () = + let all = matching () in + let start = (min (S.get page) (pages ()) - 1) * per_page in + Array.sub all start (min per_page (Array.length all - start)) + in + let columns () = + Js.Array.filter + ~f:(fun (c : member Data_grid.column) -> + Array.exists (String.equal c.id) (S.get shown_columns)) + all_columns + in +
    +
    + + S.set set_query q; + S.set set_page 1)> + + + + + + + + + + + S.set set_statuses keys; + S.set set_page 1)> + + + + + + + + + + + + + + + + + + (fun (c : member Data_grid.column) _ -> + + + + ) + + + + +
    + m.id) + columns=(columns ()) + selection_mode=`multiple + show_selection_checkboxes=true + selected_keys=(S.get selected) + on_selection_change=(S.set set_selected) + sticky_header=true + scroll_container_class="max-h-[440px] overflow-auto" + content_class="min-w-[900px]" + footer=(
    + + (Jsx.string + (string_of_int (Array.length (S.get selected)) + ^ " of " + ^ string_of_int (Array.length (matching ())) + ^ " selected")) + + + + + + S.update set_page (fun p -> max 1 (p - 1)))> + "Previous" + + + i + 1))> + (fun p _ -> + + S.set set_page p)> + (Jsx.int p) + + ) + + + = pages ()) + on_press=(fun () -> + S.update set_page (fun p -> + min (pages ()) (p + 1)))> + "Next" + + + + +
    ) + /> +
    +``` + +## Servers + +A sparkline in a cell is an [rhp](../rhp/line.md) `Line` in a chart of +one row; a capacity a `Progress_circle`. + +```ocaml title="data_grid_servers.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 Progress_circle = Solidtype_heroui.Progress_circle +module Gravity = Solidtype_gravity_icons +module Chart = Solidtype_rhp.Chart +module Line = Solidtype_rhp.Line +module Plot = Solidtype_rhp.Plot +module Row = Solidtype_rhp.Row +module Slat = Solidtype_rhp.Slat +module Ticks = Solidtype_rhp.Ticks + +type server = { + id : string; + instances : int; + active : bool; + region : string; + capacity : float; + cost : float; + requests : float array; +} + +let servers = + [| + { + id = "4586930"; + instances = 25; + active = true; + region = "US-West 1"; + capacity = 20.01; + cost = 830.04; + requests = [| 4.; 6.; 5.; 3.; 4.; 5.; 6.; 5.; 7.; 8.; 7.; 9. |]; + }; + { + id = "4586931"; + instances = 13; + active = true; + region = "US-East 2"; + capacity = 7.36; + cost = 752.72; + requests = [| 6.; 6.; 7.; 7.; 6.; 6.; 5.; 6.; 7.; 6.; 6.; 7. |]; + }; + { + id = "4586932"; + instances = 27; + active = false; + region = "EU-Central 1"; + capacity = 48.25; + cost = 517.6; + requests = [| 5.; 5.; 6.; 5.; 5.; 6.; 6.; 7.; 6.; 6.; 5.; 5. |]; + }; + { + id = "4586934"; + instances = 6; + active = true; + region = "US-West 2"; + capacity = 73.12; + cost = 412.71; + requests = [| 8.; 9.; 8.; 7.; 8.; 6.; 7.; 6.; 5.; 5.; 4.; 5. |]; + }; + { + id = "4586935"; + instances = 19; + active = true; + region = "EU-West 1"; + capacity = 72.65; + cost = 354.06; + requests = [| 6.; 7.; 6.; 7.; 6.; 7.; 6.; 7.; 6.; 7.; 6.; 7. |]; + }; + { + id = "4586937"; + instances = 27; + active = true; + region = "AP-Northeast 1"; + capacity = 11.35; + cost = 146.05; + requests = [| 4.; 5.; 6.; 6.; 7.; 6.; 7.; 8.; 7.; 6.; 7.; 6. |]; + }; + |] + +(* A point for each hour, its number along the value axis, its requests + across the band. *) +let points requests = + Array.mapi (fun i r -> Some (Some (float_of_int i), Some r)) requests + +let spark = + Slat.make ~thickness:(Slat.number 32.) + ~room:(Slat.room ~start:(Slat.px 0.) ~end_:(Slat.px 0.) ()) + (fun d -> + ) + +let capacity s = + let warn = (S.get s).capacity >= 70. in + + + + + + + (Jsx.string (Js.Float.toFixed ~digits:2 (S.get s).capacity ^ "%")) + + +let columns = + [| + Data_grid.column ~id:"id" ~header:(Text "Cluster ID") ~is_row_header:true + ~sort:(By_text (fun s -> s.id)) + (fun s -> + + (Jsx.string (S.get s).id) + + ); + Data_grid.column ~id:"instances" ~header:(Text "Instances") ~align:`center + ~sort:(By (fun a b -> Int.compare a.instances b.instances)) + (fun s -> Jsx.int (S.get s).instances); + Data_grid.column ~id:"status" ~header:(Text "Status") (fun s -> + + (Jsx.string (if (S.get s).active then "Active" else "Inactive")) + ); + Data_grid.column ~id:"region" ~header:(Text "Region") (fun s -> + Jsx.string (S.get s).region); + Data_grid.column ~id:"capacity" ~header:(Text "Capacity") + ~sort:(By (fun a b -> Float.compare a.capacity b.capacity)) + capacity; + Data_grid.column ~id:"cost" ~header:(Text "Cost") ~align:`end_ + ~sort:(By (fun a b -> Float.compare a.cost b.cost)) + ~cell_class:"tabular-nums" + (fun s -> Jsx.string ("$" ^ Js.Float.toFixed ~digits:2 (S.get s).cost)); + Data_grid.column ~id:"requests" ~header:(Text "Requests") + ~width:(Pixels 140.) (fun s -> + + + ); + |] + +let make () = + s.id) + columns + content_class="min-w-[880px]" + /> +``` + +## Styling Reference + +### CSS Classes + +- `.data-grid` - The root, with HeroUI's `.table-root` +- `.data-grid__selection-column`, `.data-grid__selection-cell` - The + checkbox column, `--data-grid-selection-column-width` wide, 40px +- `.data-grid__drag-handle-column`, `.data-grid__drag-handle-cell` - The + handle column, `--data-grid-drag-handle-column-width` wide, 32px +- `.data-grid__drag-handle` - A row's handle +- `.data-grid__sort-icon` - A sorted column's chevron, turned for descending +- `.data-grid__empty-state` - What is drawn with no rows +- `.data-grid__footer` - The footer, with HeroUI's `.table__footer` + +### Interactive States + +- **Alignment**: `[data-align="start"]`, `"center"` or `"end"` on a column's + header and cells +- **Vertical alignment**: `[data-vertical-align]` on the root, `top`, + `middle` or `bottom` +- **Pinned**: `[data-pinned="start"]` or `"end"` on a header and its cells, + `[data-pinned-edge]` on the last of each side, and + `[data-pinned-start-detached]`, `[data-pinned-end-detached]` on the table + while content passes beneath +- **Sticky header**: `[data-sticky-header]` on the table +- **Handle**: `[data-hovered="true"]`, `[data-pressed="true"]`, + `[data-focus-visible="true"]`, `[data-dragging="true"]` +- **Rows**: HeroUI's Table's, and `[data-dragging="true"]`, + `[data-drop-position]` + +## API Reference + +### Data_grid + +| Prop | Type | Default | Description | +|---|---|---|---| +| `rows` | `'row array` | | The rows | +| `row_id` | `'row -> string` | | Each row's key | +| `columns` | `'row Data_grid.column array` | | Its columns, from `Data_grid.column` | +| `aria_label` | `string` | | What names it | +| `variant` | `` [ `primary \| `secondary ] `` | `` `primary `` | The Table's variant | +| `class_`, `content_class`, `scroll_container_class` | `string` | | Added to the root, the `` and the scroll container | +| `sticky_header` | `bool` | `false` | The header kept in view | +| `vertical_align` | `` [ `top \| `middle \| `bottom ] `` | `` `middle `` | Where cells' content sits | +| `selection_mode` | `` [ `none \| `single \| `multiple ] `` | `` `none `` | How many rows may be selected | +| `selection_behavior` | `` [ `toggle \| `replace ] `` | `` `toggle `` | Whether a press toggles a row or chooses it alone | +| `selected_keys`, `default_selected_keys` | `string array` | | The rows selected, controlled or at first | +| `on_selection_change` | `string array -> unit` | | Told each change | +| `show_selection_checkboxes` | `bool` | `false` | A checkbox column first | +| `disabled_keys` | `string array` | | Rows never selected | +| `sort_descriptor` | `Table.sort_descriptor` | | The application's sort, rows drawn as given | +| `default_sort_descriptor` | `Table.sort_descriptor` | | The grid's own sort at first | +| `on_sort_change` | `Table.sort_descriptor -> unit` | | Told each sort | +| `allows_column_resize` | `bool` | `false` | Columns that allow it resized | +| `on_column_resize`, `on_column_resize_end` | `(string * Table.column_size) array -> unit` | | Every column's size, at each step and at the end | +| `on_reorder` | `'row Data_grid.reorder -> unit` | | Rows dragged by their handles, told where they landed | +| `reorder_messages` | `Table.reorder_messages` | React Aria's | What a drag tells a reader | +| `on_row_action` | `string -> unit` | | A row's action, given its key | +| `empty_state` | `Jsx.element` | | Drawn with no rows | +| `footer`, `footer_class` | `Jsx.element`, `string` | | Below the table | +| `on_load_more` | `unit -> unit` | | Asked as its end comes into view | +| `is_loading_more` | `bool` | `false` | Whether more are loading | +| `load_more_content` | `Jsx.element` | | Shown while loading more | +| `virtualized` | `bool` | `false` | Only the rows in view drawn | +| `row_height`, `heading_height` | `float` | `42.`, `36.` | A virtualized grid's rows and header, in pixels | + +### Data_grid.column + +| Argument | Type | Default | Description | +|---|---|---|---| +| `~id` | `string` | | What a sort names it by | +| `~header` | `Data_grid.header` | | `Text`, `Element` or `Sorted` | +| `?sort` | `'row Data_grid.sort` | | `By_text` or `By`; sortable only with one | +| `?is_row_header` | `bool` | `false` | Its cells name their rows | +| `?width`, `?default_width` | `Table.column_size` | | Its width, controlled or at first | +| `?min_width`, `?max_width` | `float` | | Its bounds when resized | +| `?allows_resizing` | `bool` | `false` | Resizable in a grid that `allows_column_resize` | +| `?align` | `` [ `start \| `center \| `end_ ] `` | `` `start `` | Its header's and cells' alignment | +| `?pinned` | `` [ `start \| `end_ ] `` | | The side it stays in view at | +| `?header_class`, `?cell_class` | `string` | | Added to its header and cells | +| cell | `'row -> Jsx.element` | | Draws a cell from its row | diff --git a/agents/pages/heroui/description.md b/agents/pages/heroui/description.md new file mode 100644 index 00000000..31614a11 --- /dev/null +++ b/agents/pages/heroui/description.md @@ -0,0 +1,78 @@ +# Description + +Provides supplementary text for form fields and other components. + +Original HeroUI documentation: [Description](https://heroui.com/en/docs/react/components/description). + +## Usage + +```ocaml title="description_usage.mlx" +module Description = Solidtype_heroui.Description +module Input = Solidtype_heroui.Input +module Label = Solidtype_heroui.Label + +let make () = +
    + + + + "We'll never share your email with anyone else." + +
    +``` + +## Customization + +### Tailwind CSS + +`class_` is added after HeroUI's classes. + +```ocaml title="description_tailwind.mlx" +module Description = Solidtype_heroui.Description +module Input = Solidtype_heroui.Input +module Label = Solidtype_heroui.Label + +let make () = +
    + + + + "Lowercase letters and hyphens only. Used in app.heroui.com/acme" + +
    +``` + +## Styling Reference + +### CSS Classes + +- `.description` - Base description styles with `muted` text color + +## API Reference + +| React | solidtype | Type | Description | +|---|---|---|---| +| `className` | `class_` | `string` | Added after HeroUI's classes | +| `children` | `children` | elements | The content of the description | + +### Description.Slot + +How a description renders inside a part, given its classes and its +children. + +## Accessibility + +The Description component enhances accessibility by: + +- Describing what it is in: inside a [TextField](text-field.md) + the field's input, inside a [RadioGroup](radio-group.md) the + group, and inside a radio the radio's input +- Providing the `data-slot="description"` attribute +- Supporting proper text contrast ratios diff --git a/agents/pages/heroui/disclosure-group.md b/agents/pages/heroui/disclosure-group.md new file mode 100644 index 00000000..55b6cceb --- /dev/null +++ b/agents/pages/heroui/disclosure-group.md @@ -0,0 +1,287 @@ +# DisclosureGroup + +Container that manages multiple Disclosure items with coordinated expanded states. + +It holds the [`Disclosure`](disclosure.md)s inside it, each +by its `id`: one expanded at a time, or several. + +Original HeroUI documentation: [DisclosureGroup](https://heroui.com/en/docs/react/components/disclosure-group). + +## Usage + +HeroUI's examples, with HeroUI's icons from [`solidtype-gravity-icons`](../heroui.md#icons) and Iconify. + +```ocaml title="disclosure_group_usage.mlx" +module S = Solidtype.Solid +module Button = Solidtype_heroui.Button +module Disclosure = Solidtype_heroui.Disclosure +module Disclosure_group = Solidtype_heroui.Disclosure_group +module Separator = Solidtype_heroui.Separator +module Gravity = Solidtype_gravity_icons + +(* A disclosure whose trigger is secondary while it is expanded, and + transparent while it is not. *) +let item ~expanded ~id ~icon ~title ~body = + let open_ () = Array.exists (String.equal id) (S.get expanded) in + + + + + + + (body ()) + + + + +let qr_code = + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/images/qr-code-native.png" + +let preview () = + Solidtype.Jsx.fragment + [| +

    + "Scan this QR code with your camera app to preview the HeroUI native \ + components." +

    ; + Expo Go QR Code; +

    + "Expo must be installed on your device." +

    ; + ; + |] + +let download () = + Solidtype.Jsx.fragment + [| +

    + "Download the HeroUI native app to explore our mobile components \ + directly on your device." +

    ; + App Store QR Code; +

    "Available on iOS and Android devices."

    ; + ; + |] + +let make () = + let expanded, set_expanded = S.create_signal [| "preview" |] in +
    +
    + + (item ~expanded ~id:"preview" + ~icon:(fun () -> ) + ~title:"Preview HeroUI Native" ~body:preview) + + (item ~expanded ~id:"download" + ~icon:(fun () -> ) + ~title:"Download App" ~body:download) + +
    +
    +``` + +## Parity + +The same HeroUI DisclosureGroup twice, under the same props: in solidtype on +the left, in React on the right. Below them, every attribute of the two +groups: a marked row is one they disagree on, and a dimmed row is a +framework's own, which no style reads. + +## Anatomy + +```ocaml + + + + + + + + +``` + +## Examples + +### Controlled + +You can control which disclosures are expanded with external navigation +controls using the `expanded_keys` and `on_expanded_change` props. +`Disclosure_group.navigation`, HeroUI's `useDisclosureGroupNavigation`, gives +previous and next buttons over the group's disclosures. Where several may be +expanded, next expands the one after the last expanded and previous the one +before the first. + +```ocaml title="disclosure_group_controlled.mlx" +module S = Solidtype.Solid +module Button = Solidtype_heroui.Button +module Disclosure_group = Solidtype_heroui.Disclosure_group +module Separator = Solidtype_heroui.Separator +module Usage = Disclosure_group_usage +module Gravity = Solidtype_gravity_icons + +let make () = + let expanded, set_expanded = S.create_signal [| "preview" |] in + let n = + Disclosure_group.navigation + ~expanded_keys:(fun () -> S.get expanded) + ~item_ids:[| "preview"; "download" |] + ~on_expanded_change:(S.set set_expanded) () + in +
    +
    +
    +

    "HeroUI Native"

    +
    + + +
    +
    + + (Usage.item ~expanded ~id:"preview" + ~icon:(fun () -> ) + ~title:"Preview HeroUI Native" ~body:Usage.preview) + + (Usage.item ~expanded ~id:"download" + ~icon:(fun () -> ) + ~title:"Download App" ~body:Usage.download) + +
    +
    +``` + +## Customization + +### Tailwind CSS + +`class_` is added after HeroUI's class. + +```ocaml title="disclosure_group_tailwind.mlx" +module Button = Solidtype_heroui.Button +module Disclosure = Solidtype_heroui.Disclosure +module Disclosure_group = Solidtype_heroui.Disclosure_group +module Separator = Solidtype_heroui.Separator + +let make () = + + + + + + + + "Invoices are issued on the first of each month." + + + + + + + + + + + "Reach us at help@heroui.com. Typical response time is under one \ + business day." + + + + +``` + +### Global CSS + +To customize the DisclosureGroup component classes, you can use the +`@layer components` directive. +[Learn more](https://tailwindcss.com/docs/adding-custom-styles#adding-component-classes). + +```css +@layer components { + .disclosure-group { + @apply w-full; + } +} +``` + +## Styling Reference + +### CSS Classes + +- `.disclosure-group` - Base container styles with layout containment + +### Interactive States + +- **Disabled**: `[data-disabled="true"]` on entire group, and on each + disclosure disabled with it +- **Expanded Management**: Automatically manages `[data-expanded="true"]` + states on child Disclosure items + +## API Reference + +Each prop beside the name HeroUI's React component gives it. + +### DisclosureGroup + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `expandedKeys` | `expanded_keys` | `string array` | | The currently expanded items (controlled) | +| `defaultExpandedKeys` | `default_expanded_keys` | `string array` | `[\|\|]` | The initially expanded items (uncontrolled) | +| `onExpandedChange` | `on_expanded_change` | `string array -> unit` | | Handler called when expanded items change | +| `allowsMultipleExpanded` | `allows_multiple_expanded` | `bool` | `false` | Whether multiple items can be expanded simultaneously | +| `isDisabled` | `is_disabled` | `bool` | `false` | Whether all disclosures in the group are disabled | +| `className` | `class_` | `string` | | Added after HeroUI's class | +| `children` | `children` | elements, or a function of `state` | | Disclosure items to render | + +### navigation + +| React | solidtype | Type | Description | +|---|---|---|---| +| `expandedKeys` | `expanded_keys` | `unit -> string array` | The expanded ids, read as they change | +| `itemIds` | `item_ids` | `string array` | The disclosures' ids, in order | +| `onExpandedChange` | `on_expanded_change` | `string array -> unit` | Sets the expanded ids | +| `allowsMultipleExpanded` | `allows_multiple_expanded` | `bool` | Whether a step expands one beside those expanded | +| `currentIndex` | `current_index` | `unit -> int` | The first expanded's index | +| `isPrevDisabled`, `isNextDisabled` | `is_prev_disabled`, `is_next_disabled` | `unit -> bool` | Whether a step has nowhere to go | +| `onPrevious`, `onNext` | `on_previous`, `on_next` | `unit -> unit` | Steps | diff --git a/agents/pages/heroui/disclosure.md b/agents/pages/heroui/disclosure.md new file mode 100644 index 00000000..864e8ac5 --- /dev/null +++ b/agents/pages/heroui/disclosure.md @@ -0,0 +1,204 @@ +# Disclosure + +A disclosure is a collapsible section with a header containing a heading and a trigger button, and a panel that wraps the content. + +A [`Button`](button.md) given `` slot=`trigger `` inside its +heading is its trigger too. Its content stays on the page while collapsed, and +the browser's find in page expands it to reach a word in it. + +Original HeroUI documentation: [Disclosure](https://heroui.com/en/docs/react/components/disclosure). + +## Usage + +HeroUI's examples, with HeroUI's icons from [`solidtype-gravity-icons`](../heroui.md#icons) and Iconify. + +```ocaml title="disclosure_usage.mlx" +module S = Solidtype.Solid +module Button = Solidtype_heroui.Button +module Disclosure = Solidtype_heroui.Disclosure +module Gravity = Solidtype_gravity_icons + +let make () = + let expanded, set_expanded = S.create_signal true in +
    + + + + + + +

    + "Scan this QR code with your camera app to preview the HeroUI \ + native components." +

    + Expo Go QR Code +

    + "Expo must be installed on your device." +

    + +
    +
    +
    +
    +``` + +## Parity + +The same HeroUI Disclosure twice, under the same props: in solidtype on the +left, in React on the right. Below them, every attribute of the two triggers: +a marked row is one they disagree on, and a dimmed row is a framework's own, +which no style reads. Each trigger's `aria-controls` names its own content by +the id its framework made; Kobalte marks the trigger expanded or closed, and +disabled, with empty attributes, which no style of HeroUI's reads. + +## Anatomy + +```ocaml + + + + + + +``` + +## Examples + +### Render Function + +`as_` draws another element in its place, given its props and its state, as [Composition](composition.md#custom-dom-element) shows. + +## Customization + +### Tailwind CSS + +`class_` is added after HeroUI's classes; on `Disclosure.Body` it is the +inner element's, as in React. + +```ocaml title="disclosure_tailwind.mlx" +module S = Solidtype.Solid +module Button = Solidtype_heroui.Button +module Disclosure = Solidtype_heroui.Disclosure +module Gravity = Solidtype_gravity_icons + +let make () = + let expanded, set_expanded = S.create_signal false in +
    + + + + + + + {js|Orders ship within 2 business days. Standard delivery takes 3–5 days; express is available at checkout.|js} + + + +
    +``` + +### Global CSS + +To customize the Disclosure component classes, you can use the +`@layer components` directive. +[Learn more](https://tailwindcss.com/docs/adding-custom-styles#adding-component-classes). + +```css +@layer components { + .disclosure { + @apply relative; + } + + .disclosure__trigger { + @apply cursor-pointer; + } + + .disclosure__indicator { + @apply transition-transform duration-300; + } + + .disclosure__content { + @apply overflow-hidden transition-all; + } +} +``` + +## Styling Reference + +### CSS Classes + +- `.disclosure` - Base container styles +- `.disclosure__heading` - Heading wrapper +- `.disclosure__trigger` - Trigger button styles +- `.disclosure__indicator` - Chevron indicator styles +- `.disclosure__content` - Content container with animations, its height + `--disclosure-panel-height` +- `.disclosure__body`, `.disclosure__body-inner` - The body inside the content + +### Interactive States + +- **Expanded**: `[data-expanded="true"]` on indicator for rotation, and on + the root and the content +- **Focus**: `:focus-visible` or `[data-focus-visible="true"]` on the trigger +- **Disabled**: `:disabled` or `[data-disabled="true"]` on the trigger and the + root +- **Hidden**: `[aria-hidden="true"]` and `hidden="until-found"` on the content + while collapsed + +## API Reference + +Each prop beside the name HeroUI's React component gives it. + +### Disclosure + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `id` | `id` | `string` | | Its key in a [`Disclosure_group`](disclosure-group.md) | +| `isExpanded` | `is_expanded` | `bool` | | Controls the expanded state | +| `defaultExpanded` | `default_expanded` | `bool` | `false` | Whether it is expanded at first (uncontrolled) | +| `onExpandedChange` | `on_expanded_change` | `bool -> unit` | | Callback when expanded state changes | +| `isDisabled` | `is_disabled` | `bool` | `false` | Whether the disclosure is disabled | +| `className` | `class_` | `string` | | Added after HeroUI's classes | +| `children` | `children` | elements | | Content to render, or a function of its state | +| `render` | `as_` | a function of its props and state | | Draws another element in its place | + +### Disclosure.Heading, Disclosure.Trigger, Disclosure.Content, Disclosure.Body + +| React | solidtype | Type | Description | +|---|---|---|---| +| `className` | `class_` | `string` | Added after HeroUI's classes | +| `children` | `children` | elements | Its content | + +### Disclosure.Indicator + +| React | solidtype | Type | Description | +|---|---|---|---| +| `className` | `class_` | `string` | Added after HeroUI's classes | +| `children` | — | | Not yet: HeroUI's chevron is always drawn | diff --git a/agents/pages/heroui/drawer.md b/agents/pages/heroui/drawer.md new file mode 100644 index 00000000..71d4f744 --- /dev/null +++ b/agents/pages/heroui/drawer.md @@ -0,0 +1,639 @@ +# Drawer + +Slide-out panel for supplementary content and actions. + +It is a [Modal](modal.md) that slides in from the edge its +`placement` names, and is dragged toward that edge to close. + +Original HeroUI documentation: [Drawer](https://heroui.com/en/docs/react/components/drawer). + +## Usage + +```ocaml title="drawer_usage.mlx" +module Button = Solidtype_heroui.Button +module Drawer = Solidtype_heroui.Drawer + +let make () = + + + + + + + "Drawer Title" + + +

    + "This is a bottom drawer built with React Aria's Modal \ + component. It slides up from the bottom of the screen with a \ + smooth CSS transition." +

    +
    + + + + +
    +
    +
    +
    +``` + +## Parity + +The same HeroUI Drawer twice, under the same props: in solidtype on the left, +in React on the right. Below them, every attribute of each trigger: a marked +row is one they disagree on, and a dimmed row is a framework's own, which no +style reads. + +The marked row is Kobalte's: its trigger tells a reader it opens a dialog, `aria-haspopup="dialog"`, which React Aria's leaves out. + +## Anatomy + +```ocaml + + + + + + (* Optional: drag handle *) + (* Optional: close button *) + + ... + + ... + ... + + + + +``` + +## Examples + +### Placement + +```ocaml title="drawer_placement.mlx" +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Show = Solidtype.Show +module Button = Solidtype_heroui.Button +module Drawer = Solidtype_heroui.Drawer + +let placements = + [| (`bottom, "bottom"); (`top, "top"); (`left, "left"); (`right, "right") |] + +let make () = +
    + + (fun (placement, name) _ -> + + + + + + + true + | `top | `left | `right -> false)> + + + + + (Jsx.string (String.capitalize_ascii name)) " Drawer" + + + +

    + "This drawer slides in from the " + (Jsx.string name) + " edge of the screen." +

    +
    + + + + + true + | `bottom | `left | `right -> false)> + + +
    +
    +
    +
    ) +
    +
    +``` + +### Non-Dismissable + +Set `is_dismissable=false` on `Drawer.Backdrop` to prevent closing by clicking +outside or dragging. The user must interact with the drawer's action buttons. + +```ocaml title="drawer_non_dismissable.mlx" +module Button = Solidtype_heroui.Button +module Drawer = Solidtype_heroui.Drawer + +let make () = + + + + + + + "Confirm Action" + + +

    + "This drawer cannot be dismissed by clicking outside or \ + dragging. You must use one of the buttons below." +

    +
    + + + + +
    +
    +
    +
    +``` + +### Scrollable Content + +`Drawer.Body` automatically handles overflow with native scrolling. +Drag-to-dismiss is excluded from the body area to avoid scroll conflicts. + +```ocaml title="drawer_scrollable.mlx" +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Button = Solidtype_heroui.Button +module Drawer = Solidtype_heroui.Drawer + +let paragraphs = Array.init 20 (fun i -> i + 1) + +let make () = + + + + + + + + + "Terms & Conditions" + + + + (fun n _ -> +

    + "Paragraph " + (Jsx.int n) + ": Lorem ipsum dolor sit amet, consectetur adipiscing elit. \ + Nullam pulvinar risus non risus hendrerit venenatis. \ + Pellentesque sit amet hendrerit risus, sed porttitor quam." +

    ) +
    +
    + + + + +
    +
    +
    +
    +``` + +### Controlled State + +Keep the open state in a signal, and give it to `is_open` and `on_open_change`. + +```ocaml title="drawer_controlled.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Button = Solidtype_heroui.Button +module Drawer = Solidtype_heroui.Drawer + +(* HeroUI shows React's useState and its own useOverlayState; a signal is + Solid's state, so both halves keep the drawer's in one. *) +let make () = + let is_open, set_open = S.create_signal false in + let state_open, set_state_open = S.create_signal false in +
    +
    +

    "With a signal"

    +

    + "Control the drawer using Solid's " + "signal" + " for simple state management." +

    +
    +
    +

    + "Status: " + + (Jsx.string (if S.get is_open then "open" else "closed")) + +

    +
    +
    + + +
    +
    + + + + + + "Controlled with a signal" + + +

    + "This drawer is controlled by Solid's " + "signal" + ". Pass " + "is_open" + " and " + "on_open_change" + " props to manage the drawer state externally." +

    +
    + + + +
    +
    +
    +
    +
    +

    + "With a signal's setter" +

    +

    + "Use the " + "signal" + "'s setter for a cleaner API with convenient calls like " + "S.set set_open true" + ", " + "S.set set_open false" + ", and " + "S.update set_open not" + "." +

    +
    +
    +

    + "Status: " + + (Jsx.string (if S.get state_open then "open" else "closed")) + +

    +
    +
    + + +
    +
    + + + + + + + "Controlled with a signal's setter" + + + +

    + "The " + "signal" + {js|'s setter covers the common operations. No need to manually create callbacks—just use |js} + "S.set set_open true" + ", " + "S.set set_open false" + ", or " + "S.update set_open not" + "." +

    +
    + + + +
    +
    +
    +
    +
    +``` + +### With Form + +```ocaml title="drawer_form.mlx" +module Button = Solidtype_heroui.Button +module Drawer = Solidtype_heroui.Drawer +module Input = Solidtype_heroui.Input +module Label = Solidtype_heroui.Label +module Text_field = Solidtype_heroui.Text_field + +let make () = + + + + + + + + "Edit Profile" + + +
    + + + + + + + + + + + + + +
    + + + + +
    +
    +
    +
    +``` + +### Navigation Drawer + +```ocaml title="drawer_navigation.mlx" +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Button = Solidtype_heroui.Button +module Drawer = Solidtype_heroui.Drawer +module Gravity = Solidtype_gravity_icons + +let nav_items = + [| + ((fun () -> ), "Home"); + ((fun () -> ), "Search"); + ((fun () -> ), "Notifications"); + ((fun () -> ), "Messages"); + ((fun () -> ), "Profile"); + ((fun () -> ), "Settings"); + |] + +let make () = + + + + + + + + "Navigation" + + + + + + + + +``` + +### Backdrop Variants + +```ocaml title="drawer_backdrop_variants.mlx" +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Button = Solidtype_heroui.Button +module Drawer = Solidtype_heroui.Drawer + +let variants = + [| (`opaque, "opaque"); (`blur, "blur"); (`transparent, "transparent") |] + +let make () = +
    + + (fun (variant, name) _ -> + + + + + + + + + + "Backdrop: " (Jsx.string (String.capitalize_ascii name)) + + + +

    + "This drawer uses the " + (Jsx.string name) + " backdrop variant." +

    +
    + + + +
    +
    +
    +
    ) +
    +
    +``` + +## Customization + +### Tailwind CSS + +`class_` is added after HeroUI's classes. + +```ocaml title="drawer_tailwind.mlx" +module Button = Solidtype_heroui.Button +module Drawer = Solidtype_heroui.Drawer + +let make () = + + + + + + + "Filters" + + +

    + "Narrow results by status, owner, or date." +

    +
    + + + + +
    +
    +
    +
    +``` + +### Global CSS + +To customize the Drawer component classes, you can use the +`@layer components` directive. +[Learn more](https://tailwindcss.com/docs/adding-custom-styles#adding-component-classes). + +```css +@layer components { + .drawer__dialog { + @apply rounded-t-3xl; + } + + .drawer__heading { + @apply text-lg font-semibold; + } +} +``` + +## Styling Reference + +### CSS Classes + +- `.drawer__trigger` - Trigger element that opens the drawer +- `.drawer__backdrop` - Overlay backdrop behind the drawer +- `.drawer__content` - Positioning wrapper for the drawer panel +- `.drawer__dialog` - The drawer panel itself +- `.drawer__header` - Header section for titles +- `.drawer__heading` - Main title text +- `.drawer__body` - Main scrollable content area +- `.drawer__footer` - Footer section for actions +- `.drawer__handle` - Visual drag handle indicator +- `.drawer__close-trigger` - Close button element +- `.drawer__backdrop--opaque` - Opaque colored backdrop (default) +- `.drawer__backdrop--blur` - Blurred backdrop with glass effect +- `.drawer__backdrop--transparent` - Transparent backdrop (no overlay) +- `.drawer__content--bottom` - Slides up from the bottom edge (default) +- `.drawer__content--top` - Slides down from the top edge +- `.drawer__content--left` - Slides in from the left edge +- `.drawer__content--right` - Slides in from the right edge +- `.drawer__dialog--top`, `--bottom`, `--left`, `--right` - The same, on the + dialog + +### Interactive States + +- **Entering**: `[data-entering="true"]` on the backdrop and the content - + Applied during drawer opening animation +- **Exiting**: `[data-exiting="true"]` on the backdrop and the content - + Applied during drawer closing animation +- **Placement**: `[data-placement="*"]` on the content and the dialog - + Applied based on drawer position (top, bottom, left, right) + +## API Reference + +Each prop beside the name HeroUI's React component gives it. + +### Drawer + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `isOpen` | `is_open` | `bool` | | Controlled open state | +| `defaultOpen` | `default_open` | `bool` | `false` | Whether it starts open (uncontrolled) | +| `onOpenChange` | `on_open_change` | `bool -> unit` | | Open state change handler | + +### Drawer.Backdrop + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `variant` | `variant` | `` `opaque `` \| `` `blur `` \| `` `transparent `` | `` `opaque `` | Backdrop overlay style | +| `isDismissable` | `is_dismissable` | `bool` | `true` | Close on backdrop click, or on a drag | +| `isKeyboardDismissDisabled` | `is_keyboard_dismiss_disabled` | `bool` | `false` | Disable ESC key to close | +| `isOpen` | `is_open` | `bool` | | With no `Drawer` around it, whether it is open | +| `onOpenChange` | `on_open_change` | `bool -> unit` | | With no `Drawer` around it, told as it opens or closes | +| `className` | `class_` | `string` | | Added after HeroUI's classes | + +### Drawer.Content + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `placement` | `placement` | `` `top `` \| `` `bottom `` \| `` `left `` \| `` `right `` | `` `bottom `` | Edge the drawer slides from | +| `className` | `class_` | `string` | | Added after HeroUI's classes | + +### Drawer.Trigger, Dialog, Header, Body, Footer, Heading, Handle, CloseTrigger + +| React | solidtype | Type | Description | +|---|---|---|---| +| `className` | `class_` | `string` | Added after HeroUI's classes | +| `children` | `children` | elements | What it holds, where it holds any | + +## Accessibility + +Implements the [WAI-ARIA Dialog pattern](https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/): + +- **Focus trap**: Focus locked within drawer when open, and given back as it + closes +- **Keyboard**: `ESC` closes (when dismissable), `Tab` cycles elements +- **Screen readers**: the dialog is named by its heading +- **Scroll lock**: Body scroll disabled when open +- **Drag to dismiss**: from anywhere on the dialog but a button, a field, a + link or its body; it closes past a third of its size or at a flick, else + springs back diff --git a/agents/pages/heroui/dropdown.md b/agents/pages/heroui/dropdown.md new file mode 100644 index 00000000..d8778766 --- /dev/null +++ b/agents/pages/heroui/dropdown.md @@ -0,0 +1,1167 @@ +# Dropdown + +A dropdown displays a list of actions or options that a user can choose. + +A `Button` inside it is its trigger; anything else is wrapped in +`Dropdown.Trigger`. + +Original HeroUI documentation: [Dropdown](https://heroui.com/en/docs/react/components/dropdown). + +## Usage + +```ocaml title="dropdown_usage.mlx" +module Button = Solidtype_heroui.Button +module Dropdown = Solidtype_heroui.Dropdown +module Label = Solidtype_heroui.Label + +let make () = + + + + ())> + + + + + + + + + + + + + + + +``` + +## Parity + +The same HeroUI Dropdown twice, under the same props: in solidtype on the +left, in React on the right. Below them, every attribute of each trigger: a +marked row is one they disagree on, and a dimmed row is a framework's own, +which no style reads. + +## Anatomy + +```ocaml + + ... + + + + + ... + ... + + + + +
    ...
    + +
    + + + + + + + + + + + +
    +
    +
    +``` + +## Examples + +### With Icons + +```ocaml title="dropdown_with_icons.mlx" +module Button = Solidtype_heroui.Button +module Dropdown = Solidtype_heroui.Dropdown +module Kbd = Solidtype_heroui.Kbd +module Label = Solidtype_heroui.Label +module Gravity = Solidtype_gravity_icons + +let make () = + + + + ())> + + + + + "N" + + + + + + + "O" + + + + + + + "S" + + + + + + + + + "D" + + + + + +``` + +### With Descriptions + +```ocaml title="dropdown_with_descriptions.mlx" +module Button = Solidtype_heroui.Button +module Description = Solidtype_heroui.Description +module Dropdown = Solidtype_heroui.Dropdown +module Kbd = Solidtype_heroui.Kbd +module Label = Solidtype_heroui.Label +module Gravity = Solidtype_gravity_icons + +let make () = + + + + ())> + +
    + +
    +
    + + "Create a new file" +
    + + "N" + +
    + +
    + +
    +
    + + "Open an existing file" +
    + + "O" + +
    + +
    + +
    +
    + + "Save the current file" +
    + + "S" + +
    + +
    + +
    +
    + + "Move to trash" +
    + + + + "D" + +
    +
    +
    +
    +``` + +### With Disabled Items + +```ocaml title="dropdown_with_disabled_items.mlx" +module Button = Solidtype_heroui.Button +module Description = Solidtype_heroui.Description +module Dropdown = Solidtype_heroui.Dropdown +module Header = Solidtype_heroui.Header +module Kbd = Solidtype_heroui.Kbd +module Label = Solidtype_heroui.Label +module Separator = Solidtype_heroui.Separator +module Gravity = Solidtype_gravity_icons + +let make () = + + + + ())> + +
    "Actions"
    + +
    + +
    +
    + + "Create a new file" +
    + + "N" + +
    + +
    + +
    +
    + + "Make changes" +
    + + "E" + +
    +
    + + +
    "Danger zone"
    + +
    + +
    +
    + + "Move to trash" +
    + + + + "D" + +
    +
    +
    +
    +
    +``` + +### With Sections + +```ocaml title="dropdown_with_sections.mlx" +module Button = Solidtype_heroui.Button +module Description = Solidtype_heroui.Description +module Dropdown = Solidtype_heroui.Dropdown +module Header = Solidtype_heroui.Header +module Kbd = Solidtype_heroui.Kbd +module Label = Solidtype_heroui.Label +module Separator = Solidtype_heroui.Separator +module Gravity = Solidtype_gravity_icons + +let make () = + + + + ())> + +
    "Actions"
    + +
    + +
    +
    + + "Create a new file" +
    + + "N" + +
    + +
    + +
    +
    + + "Make changes" +
    + + "E" + +
    +
    + + +
    "Danger zone"
    + +
    + +
    +
    + + "Move to trash" +
    + + + + "D" + +
    +
    +
    +
    +
    +``` + +### With Multiple Selection + +```ocaml title="dropdown_with_multiple_selection.mlx" +module S = Solidtype.Solid +module Button = Solidtype_heroui.Button +module Dropdown = Solidtype_heroui.Dropdown +module Header = Solidtype_heroui.Header +module Label = Solidtype_heroui.Label + +let make () = + let selected, set_selected = S.create_signal [| "apple" |] in + + + + + +
    "Select a fruit"
    + + + + + + + + + +
    + + + + + + +
    +
    +
    +``` + +### Controlled + +```ocaml title="dropdown_controlled.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Button = Solidtype_heroui.Button +module Dropdown = Solidtype_heroui.Dropdown +module Label = Solidtype_heroui.Label + +let make () = + let selected, set_selected = S.create_signal [| "bold" |] in +
    +

    + "Selected: " + (match S.get selected with + | [||] -> Jsx.string "None" + | keys -> Jsx.string (Js.Array.join ~sep:", " keys)) +

    + + + + + + + + + + + + + + + + +
    +``` + +### Controlled Open State + +```ocaml title="dropdown_controlled_open_state.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Button = Solidtype_heroui.Button +module Dropdown = Solidtype_heroui.Dropdown +module Label = Solidtype_heroui.Label + +let make () = + let is_open, set_open = S.create_signal false in +
    +

    + "Dropdown is: " + (Jsx.string (if S.get is_open then "open" else "closed")) +

    + + + + + + + + + + + + + + + + + + + +
    +``` + +### With Single Selection + +```ocaml title="dropdown_with_single_selection.mlx" +module S = Solidtype.Solid +module Button = Solidtype_heroui.Button +module Dropdown = Solidtype_heroui.Dropdown +module Header = Solidtype_heroui.Header +module Label = Solidtype_heroui.Label + +let make () = + let selected, set_selected = S.create_signal [| "apple" |] in + + + + + +
    "Select a fruit"
    + + + + + + + + + +
    + + + + + + +
    +
    +
    +``` + +### Single With Custom Indicator + +```ocaml title="dropdown_single_with_custom_indicator.mlx" +module S = Solidtype.Solid +module Button = Solidtype_heroui.Button +module Dropdown = Solidtype_heroui.Dropdown +module Header = Solidtype_heroui.Header +module Label = Solidtype_heroui.Label +module Gravity = Solidtype_gravity_icons + +let make () = + let selected, set_selected = S.create_signal [| "apple" |] in + + + + + +
    "Select a fruit"
    + + + (fun selected -> + if S.get selected then + + else Solidtype.Jsx.nothing) + + + + + + (fun selected -> + if S.get selected then + + else Solidtype.Jsx.nothing) + + + + + + (fun selected -> + if S.get selected then + + else Solidtype.Jsx.nothing) + + + +
    + + + (fun selected -> + if S.get selected then + + else Solidtype.Jsx.nothing) + + + + + + (fun selected -> + if S.get selected then + + else Solidtype.Jsx.nothing) + + + +
    +
    +
    +``` + +### With Section Level Selection + +```ocaml title="dropdown_with_section_level_selection.mlx" +module S = Solidtype.Solid +module Button = Solidtype_heroui.Button +module Dropdown = Solidtype_heroui.Dropdown +module Header = Solidtype_heroui.Header +module Kbd = Solidtype_heroui.Kbd +module Label = Solidtype_heroui.Label +module Separator = Solidtype_heroui.Separator + +let make () = + let text_styles, set_text_styles = S.create_signal [| "bold"; "italic" |] in + let text_alignment, set_text_alignment = S.create_signal [| "left" |] in + + + + + +
    "Actions"
    + + + + "X" + + + + + + "C" + + + + + + "U" + + +
    + + +
    "Text Style"
    + + + + + "B" + + + + + + + "I" + + + + + + + "U" + + +
    + + +
    "Text Alignment"
    + + + + + "A" + + + + + + + "H" + + + + + + + "D" + + +
    +
    +
    +
    +``` + +### With Keyboard Shortcuts + +```ocaml title="dropdown_with_keyboard_shortcuts.mlx" +module Button = Solidtype_heroui.Button +module Dropdown = Solidtype_heroui.Dropdown +module Kbd = Solidtype_heroui.Kbd +module Label = Solidtype_heroui.Label + +let make () = + + + + ())> + + + + "N" + + + + + + "O" + + + + + + "S" + + + + + + + + "D" + + + + + +``` + +### With Submenus + +```ocaml title="dropdown_with_submenus.mlx" +module Button = Solidtype_heroui.Button +module Dropdown = Solidtype_heroui.Dropdown +module Label = Solidtype_heroui.Label + +let make () = + + + + ())> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +``` + +### With Custom Submenu Indicator + +```ocaml title="dropdown_with_custom_submenu_indicator.mlx" +module Button = Solidtype_heroui.Button +module Dropdown = Solidtype_heroui.Dropdown +module Label = Solidtype_heroui.Label +module Gravity = Solidtype_gravity_icons + +let make () = + + + + ())> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +``` + +### Custom Trigger + +```ocaml title="dropdown_custom_trigger.mlx" +module Avatar = Solidtype_heroui.Avatar +module Dropdown = Solidtype_heroui.Dropdown +module Label = Solidtype_heroui.Label +module Gravity = Solidtype_gravity_icons + +let make () = + + + + + "JD" + + + +
    +
    + + + "JD" + +
    +

    "Jane Doe"

    +

    "jane@example.com"

    +
    +
    +
    + + + + + + + + +
    + + +
    +
    + +
    + + +
    +
    + +
    + + +
    +
    +
    +
    +
    +``` + +### Long Press Trigger + +```ocaml title="dropdown_long_press_trigger.mlx" +module Button = Solidtype_heroui.Button +module Dropdown = Solidtype_heroui.Dropdown +module Label = Solidtype_heroui.Label + +let make () = + + + + + + + + + + + + + + + + + + + +``` + +## Customization + +### Tailwind CSS + +`class_` is added after HeroUI's classes. + +```ocaml title="dropdown_tailwind.mlx" +module Button = Solidtype_heroui.Button +module Dropdown = Solidtype_heroui.Dropdown +module Label = Solidtype_heroui.Label + +let make () = + + + + + + + + + + + + + + + + +``` + +### Global CSS + +To customize the Dropdown component classes, you can use the +`@layer components` directive. +[Learn more](https://tailwindcss.com/docs/adding-custom-styles#adding-component-classes). + +```css +@layer components { + .dropdown__trigger { + @apply outline-none; + } + + .dropdown__popover { + @apply rounded-lg border border-border bg-overlay p-2; + } + + .dropdown__menu { + @apply flex flex-col gap-1; + } +} +``` + +## Styling Reference + +### CSS Classes + +- `.dropdown__trigger` - The button or element that triggers the dropdown +- `.dropdown__popover` - The popover container +- `.dropdown__menu` - The menu container inside the popover +- `[data-slot="separator"]` - Separator elements within the menu + +The menu's items and sections take these classes: + +- `.menu-item` - Base menu item container +- `.menu-item__indicator` - Selection indicator (checkmark or dot) + - `[data-slot="menu-item-indicator--checkmark"]` - Checkmark indicator SVG + - `[data-slot="menu-item-indicator--dot"]` - Dot indicator SVG +- `.menu-item__indicator--submenu` - Submenu indicator (chevron) +- `.menu-item--default` - Default variant styling +- `.menu-item--danger` - Danger variant styling +- `.menu-section` - Base menu section container, and `.header` for its title + +### Interactive States + +- **Hover**: `[data-hovered="true"]` on trigger and items +- **Focus**: `:focus-visible` or `[data-focus-visible="true"]` on trigger and + items, and `[data-focused="true"]` on the item with the focus +- **Pressed**: `[data-pressed="true"]` on trigger and items; on the trigger + also while the menu is open +- **Disabled**: `[data-disabled="true"]` on items +- **Selected**: `[data-selected="true"]` or `[aria-checked="true"]` on items +- **Selection**: `[data-selection-mode="single"]` or `"multiple"` on the menu + and its items +- **Submenu**: `[data-has-submenu="true"]` on an item that opens one, and + `[data-open="true"]` while it is open +- **Entering** and **Exiting**: `[data-entering="true"]` and + `[data-exiting="true"]` on the popover, while it appears and disappears +- **Placement**: `[data-placement="bottom"]`, and the other sides, on the + popover + +## API Reference + +Each prop beside the name HeroUI's React component gives it. + +### Dropdown + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `isOpen` | `is_open` | `bool` | | Sets the open state of the menu (controlled) | +| `defaultOpen` | `default_open` | `bool` | `false` | Sets the default open state of the menu (uncontrolled) | +| `onOpenChange` | `on_open_change` | `bool -> unit` | | Handler called when the open state changes | +| `trigger` | `trigger` | `` `press `` \| `` `long_press `` | `` `press `` | The type of interaction that triggers the menu | +| `children` | `children` | elements | | Dropdown content: its trigger and its popover | + +### Dropdown.Trigger + +| React | solidtype | Type | Description | +|---|---|---|---| +| `aria-label` | `aria_label` | `string` | Its name, where its children give none | +| `className` | `class_` | `string` | Added after HeroUI's classes | +| `children` | `children` | elements | What it wraps | + +### Dropdown.Popover + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `placement` | `placement` | `` `bottom ``, and React Aria's others: `` `bottom_end ``, `` `top_start ``, `` `start ``... | `` `bottom `` | Placement of the popover relative to the trigger | +| `className` | `class_` | `string` | | Added after HeroUI's classes | +| `children` | `children` | elements | | Its menu | + +### Dropdown.Menu + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `selectionMode` | `selection_mode` | `` `none `` \| `` `single `` \| `` `multiple `` | `` `none `` | Whether single or multiple selection is enabled, read as it is made | +| `selectedKeys` | `selected_keys` | `string array` | | The currently selected keys (controlled) | +| `defaultSelectedKeys` | `default_selected_keys` | `string array` | | The initial selected keys (uncontrolled) | +| `onSelectionChange` | `on_selection_change` | `string array -> unit` | | Handler called when the selection changes | +| `disabledKeys` | `disabled_keys` | `string array` | | Keys of disabled items | +| `onAction` | `on_action` | `string -> unit` | | Handler called when an item is activated | +| `className` | `class_` | `string` | | Added after HeroUI's classes | +| `children` | `children` | elements | | Its items, sections and separators | + +### Dropdown.Section + +| React | solidtype | Type | Description | +|---|---|---|---| +| `selectionMode` | `selection_mode` | `` `single `` \| `` `multiple `` | Selection mode for items within this section, read as it is made | +| `selectedKeys` | `selected_keys` | `string array` | The currently selected keys (controlled) | +| `defaultSelectedKeys` | `default_selected_keys` | `string array` | The initial selected keys (uncontrolled) | +| `onSelectionChange` | `on_selection_change` | `string array -> unit` | Handler called when the selection changes | +| `disabledKeys` | `disabled_keys` | `string array` | Keys of disabled items | +| `className` | `class_` | `string` | Added after HeroUI's classes | +| `children` | `children` | elements | Its header and items | + +### Dropdown.Item + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `id` | `id` | `string` | | Unique identifier for the item | +| `textValue` | `text_value` | `string` | | Text content of the item for typeahead | +| `isDisabled` | `is_disabled` | `bool` | `false` | Whether it is disabled | +| `variant` | `variant` | `` `default `` \| `` `danger `` | `` `default `` | Visual variant of the item | +| `className` | `class_` | `string` | | Added after HeroUI's classes | +| `children` | `children` | elements | | What it shows | + +### Dropdown.Item_indicator + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `type` | `type_` | `` `checkmark `` \| `` `dot `` | `` `checkmark `` | Type of indicator to display | +| `className` | `class_` | `string` | | Added after HeroUI's classes | +| `children` | `children` | `bool accessor -> element` | | Custom indicator content, given whether its item is selected | + +### Dropdown.Submenu_indicator + +| React | solidtype | Type | Description | +|---|---|---|---| +| `className` | `class_` | `string` | Added after HeroUI's classes | +| `children` | `children` | elements | Custom indicator content, in place of HeroUI's chevron | + +### Dropdown.Submenu_trigger + +| React | solidtype | Type | Description | +|---|---|---|---| +| `children` | `children` | elements | The item that opens the submenu, and its popover | + +## Accessibility + +`Dropdown` implements the ARIA menu pattern and provides: + +- Full keyboard navigation support (arrow keys, Home and End, typeahead) +- Proper focus management: the menu gives the focus to its selected item as + it opens, and back to its trigger as it closes on Escape or a press outside +- Support for disabled states +- Long press interaction support: with `` trigger=`long_press `` the menu opens + on a press held half a second, or on Alt and an arrow, and its trigger is + described so to a screen reader +- Submenu navigation: a submenu opens by a hover or the arrow toward it +- In a selection of many, Enter on an item closes the menu, and a press or + Space keeps it open diff --git a/agents/pages/heroui/empty-state.md b/agents/pages/heroui/empty-state.md new file mode 100644 index 00000000..d2a82fb1 --- /dev/null +++ b/agents/pages/heroui/empty-state.md @@ -0,0 +1,32 @@ +# EmptyState + +What a list shows where it has nothing to show. + +What a list, a table or a select shows where it has nothing to show. It says +"No results found" unless it is given children. + +Original HeroUI source: [EmptyState](https://github.com/heroui-inc/heroui/tree/v3/packages/react/src/components/empty-state), which heroui.com has no page for. + +## Usage + +```ocaml title="empty_state_usage.mlx" +module Empty_state = Solidtype_heroui.Empty_state + +let make () = +
    + "No tasks yet" +
    +``` + +## Styling Reference + +### CSS Classes + +- `.empty-state` - Base empty state container + +## API Reference + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `className` | `class_` | `string` | | Added after HeroUI's class | +| `children` | `children` | elements | "No results found" | Its content | diff --git a/agents/pages/heroui/error-message.md b/agents/pages/heroui/error-message.md new file mode 100644 index 00000000..1127a9dc --- /dev/null +++ b/agents/pages/heroui/error-message.md @@ -0,0 +1,109 @@ +# ErrorMessage + +An error message for non-form components such as a TagGroup. + +It shows inside a [TagGroup](tag-group.md), which it +describes, and draws nothing elsewhere. A form field's error is a +[FieldError](field-error.md). + +Original HeroUI documentation: [ErrorMessage](https://heroui.com/en/docs/react/components/error-message). + +## Usage + +```ocaml title="error_message_usage.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Description = Solidtype_heroui.Description +module Error_message = Solidtype_heroui.Error_message +module Label = Solidtype_heroui.Label +module Tag = Solidtype_heroui.Tag +module Tag_group = Solidtype_heroui.Tag_group + +let make () = + let selected, set_selected = S.create_signal [||] in + + + + "News" + "Travel" + "Gaming" + "Shopping" + + "Select at least one category" + + (Jsx.string + (if Array.length (S.get selected) = 0 then + "Please select at least one category" + else "")) + + +``` + +## Anatomy + +```ocaml + + +``` + +## Customization + +### Tailwind CSS + +`class_` is added after HeroUI's class. + +```ocaml title="error_message_custom_styles.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Description = Solidtype_heroui.Description +module Error_message = Solidtype_heroui.Error_message +module Label = Solidtype_heroui.Label +module Tag = Solidtype_heroui.Tag +module Tag_group = Solidtype_heroui.Tag_group + +let make () = + let selected, set_selected = S.create_signal [||] in + + + + "API" + "Design" + "Docs" + + "Pick at least one topic" + + (Jsx.string + (if Array.length (S.get selected) = 0 then "Choose at least one topic" + else "")) + + +``` + +## Styling Reference + +### CSS Classes + +- `.error-message` - Base error message styles with danger color +- `[slot="errorMessage"]` - The slot it fills + +## API Reference + +| React | solidtype | Type | Description | +|---|---|---|---| +| `className` | `class_` | `string` | Added after HeroUI's class | +| `children` | `children` | nodes | The error message content | + +## Accessibility + +- Its component's list is described by it, after its description. diff --git a/agents/pages/heroui/field-error.md b/agents/pages/heroui/field-error.md new file mode 100644 index 00000000..75127714 --- /dev/null +++ b/agents/pages/heroui/field-error.md @@ -0,0 +1,92 @@ +# FieldError + +Displays validation error messages for form fields. + +It is used inside a field: outside one it raises `Invalid_argument`. + +Original HeroUI documentation: [FieldError](https://heroui.com/en/docs/react/components/field-error). + +## Usage + +The FieldError component displays validation error messages for form fields. +It automatically appears when the parent field is marked as invalid. + +```ocaml title="field_error_usage.mlx" +module S = Solidtype.Solid +module Field_error = Solidtype_heroui.Field_error +module Input = Solidtype_heroui.Input +module Label = Solidtype_heroui.Label +module Text_field = Solidtype_heroui.Text_field + +let make () = + let value, set_value = S.create_signal "jr" in + let invalid () = + let n = String.length (S.get value) in + n > 0 && n < 3 + in + + + + "Username must be at least 3 characters" + +``` + +## Customization + +### Tailwind CSS + +`class_` is added after HeroUI's classes. + +```ocaml title="field_error_tailwind.mlx" +module S = Solidtype.Solid +module Field_error = Solidtype_heroui.Field_error +module Input = Solidtype_heroui.Input +module Label = Solidtype_heroui.Label +module Text_field = Solidtype_heroui.Text_field + +let make () = + let value, set_value = S.create_signal "jr" in + let invalid () = + let n = String.length (S.get value) in + n > 0 && n < 3 + in + + + + + "Handle must be at least 3 characters" + + +``` + +## Styling Reference + +### CSS Classes + +- `.field-error` - Base error styles with danger color +- Only shows when the `data-visible` attribute is present +- Text is truncated with ellipsis for long messages + +## API Reference + +| React | solidtype | Type | Description | +|---|---|---|---| +| `className` | `class_` | `string` | Added after HeroUI's class | +| `children` | `children` | elements, or a function of `state` | Error message content or render function; a form's server error for the field, while it stands, shows instead | + +## Accessibility + +The FieldError component ensures accessibility by: + +- Describing the field's input while it shows, so a screen reader reads the + error with it +- Providing visual and programmatic error indication +- Automatically managing visibility based on validation state diff --git a/agents/pages/heroui/fieldset.md b/agents/pages/heroui/fieldset.md new file mode 100644 index 00000000..74fcfddb --- /dev/null +++ b/agents/pages/heroui/fieldset.md @@ -0,0 +1,221 @@ +# Fieldset + +Group related form controls with legends, descriptions, and actions. + +Original HeroUI documentation: [Fieldset](https://heroui.com/en/docs/react/components/fieldset). + +## Usage + +```ocaml title="fieldset_usage.mlx" +module Button = Solidtype_heroui.Button +module Description = Solidtype_heroui.Description +module Fieldset = Solidtype_heroui.Fieldset +module Input = Solidtype_heroui.Input +module Label = Solidtype_heroui.Label +module Text_area = Solidtype_heroui.Text_area +module Text_field = Solidtype_heroui.Text_field + +external prevent_default : Dom.event -> unit = "preventDefault" [@@mel.send] + +let make () = +
    prevent_default e)> +
    + "Profile Settings" + "Update your profile information." + + + + + + + + + + + + "Minimum 10 characters" + + + + + + +
    + +``` + +## Parity + +The same HeroUI Fieldset twice, under the same props: in solidtype on the +left, in React on the right. Below them, every attribute of the two buttons +it holds: a marked row is one they disagree on. + +## Anatomy + +```ocaml +
    + "Profile" + (* form fields go here *) + (* action buttons go here *) +
    +``` + +## Examples + +### In Surface + +When used inside a [Surface](surface.md) component, use +`` variant=`secondary `` on form controls (`Input`, `Text_area`, etc.) to +apply the lower emphasis variant suitable for surface backgrounds. + +```ocaml title="fieldset_surface.mlx" +module Button = Solidtype_heroui.Button +module Description = Solidtype_heroui.Description +module Fieldset = Solidtype_heroui.Fieldset +module Input = Solidtype_heroui.Input +module Label = Solidtype_heroui.Label +module Text_area = Solidtype_heroui.Text_area +module Text_field = Solidtype_heroui.Text_field +module Surface = Solidtype_heroui.Surface + +let make () = +
    + +
    + "Profile Settings" + "Update your profile information." + + + + + + + + + + + + + "Minimum 10 characters" + + + + + + +
    +
    +
    +``` + +### Disabled + +A component's own `is_disabled` is its own: the fieldset's Help button stays +enabled. + +```ocaml title="fieldset_disabled.mlx" +module S = Solidtype.Solid +module Button = Solidtype_heroui.Button +module Description = Solidtype_heroui.Description +module Fieldset = Solidtype_heroui.Fieldset +module Input = Solidtype_heroui.Input +module Label = Solidtype_heroui.Label +module Text_area = Solidtype_heroui.Text_area +module Text_field = Solidtype_heroui.Text_field +module Switch = Solidtype_heroui.Switch + +let make () = + let disabled, set_disabled = S.create_signal true in +
    + + + + + + +
    + "Notifications" + + + + + + + + + + +
    +
    +``` + +### Not yet + +HeroUI's examples validate each field with a `validate` function, which the +port does not take yet; the port's examples use required fields. + +## Customization + +### Global CSS + +Use the `@layer components` directive to target Fieldset +[BEM](https://bem.info/en/methodology/)-style classes. + +```css +@layer components { + .fieldset { + @apply gap-6 rounded-lg border p-6; + } + + .fieldset__legend { + @apply text-2xl font-bold; + } +} +``` + +## Styling Reference + +HeroUI follows the [BEM](https://bem.info/en/methodology/) methodology to +ensure component variants and states are reusable and easy to customize. + +### CSS Classes + +- `.fieldset` - Root container +- `.fieldset__legend` - Legend element +- `.fieldset__field-group` - Wrapper for grouped fields +- `.fieldset__actions` - Action bar below the fields + +### Interactive States + +- **Disabled**: `[data-disabled="true"]`, from which HeroUI's styles show + the fields inside disabled + +## API Reference + +Each prop beside the name HeroUI's React component gives it. + +### Fieldset + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `disabled` | `disabled` | `bool` | `false` | Whether it and what is inside it are disabled | +| `name` | `name` | `string` | | Its name in a form | +| `className` | `class_` | `string` | | Added after HeroUI's classes | +| `children` | `children` | elements | | Fieldset content (legend, groups, descriptions, actions) | + +### Fieldset.Legend, Fieldset.Group, Fieldset.Actions + +| React | solidtype | Type | Description | +|---|---|---|---| +| `className` | `class_` | `string` | Added after HeroUI's class | +| `children` | `children` | elements | Its content | + +## Note + +- A disabled fieldset disables the `Button`s, `Link`s and `Radio_group`s + inside it, as well as native inputs +- A component's own `is_disabled` overrides the fieldset's diff --git a/agents/pages/heroui/form.md b/agents/pages/heroui/form.md new file mode 100644 index 00000000..fc8f8142 --- /dev/null +++ b/agents/pages/heroui/form.md @@ -0,0 +1,435 @@ +# Form + +Wrapper component for form validation and submission handling. + +A field validates nothing itself: it is invalid as its `is_invalid` says, and +a submit while one is invalid is refused. + +Original HeroUI documentation: [Form](https://heroui.com/en/docs/react/components/form). + +## Usage + +The rules are the application's, from its signals; each error shows once its +field is left. + +```ocaml title="form_usage.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Button = Solidtype_heroui.Button +module Description = Solidtype_heroui.Description +module Field_error = Solidtype_heroui.Field_error +module Form = Solidtype_heroui.Form +module Input = Solidtype_heroui.Input +module Label = Solidtype_heroui.Label +module Text_field = Solidtype_heroui.Text_field + +external prevent_default : Dom.event -> unit = "preventDefault" [@@mel.send] + +(* The form's rules, from its own state: each field's error, if any. *) +let email_error v = + match String.index_opt v '@' with + | Some at when at > 0 && String.contains_from v at '.' -> None + | Some _ | None -> Some "Please enter a valid email address" + +let password_error v = + let has p = String.exists p v in + if String.length v < 8 then Some "Password must be at least 8 characters" + else if not (has (fun c -> c >= 'A' && c <= 'Z')) then + Some "Password must contain at least one uppercase letter" + else if not (has (fun c -> c >= '0' && c <= '9')) then + Some "Password must contain at least one number" + else None + +let make () = + let email, set_email = S.create_signal "" in + let password, set_password = S.create_signal "" in + (* An error shows once its field is left, or the form submitted. *) + let left, set_left = S.create_signal [] in + let leave name () = S.set set_left (name :: S.get left) in + let shown name error () = + if List.exists (String.equal name) (S.get left) then error () else None + in + let email_shown = shown "email" (fun () -> email_error (S.get email)) in + let password_shown = + shown "password" (fun () -> password_error (S.get password)) + in + let sent, set_sent = S.create_signal false in +
    + prevent_default e; + S.set set_sent true) + on_reset=(fun _ -> + S.set set_email ""; + S.set set_password ""; + S.set set_left []; + S.set set_sent false)> + leave "email" ()) + is_invalid=(Option.is_some (email_error (S.get email)))> + + + + (Jsx.string (Option.value (email_shown ()) ~default:"")) + + + leave "password" ()) + is_invalid=(Option.is_some (password_error (S.get password)))> + + + + "Must be at least 8 characters with 1 uppercase and 1 number" + + + (Jsx.string (Option.value (password_shown ()) ~default:"")) + + +
    + + +
    +

    + (Jsx.string (if S.get sent then "Submitted." else "")) +

    + +``` + +## Parity + +HeroUI's Form has no classes and no state of its own to compare; its test runs +the same server error through the port and HeroUI's React Form, shown, typed +into and left. + +## Anatomy + +```ocaml +
    + (* form fields go here *) + + + +``` + +## Examples + +### Server Errors + +`validation_errors`, a server's errors by field name, makes each field it names +invalid, shown by its `Field_error`, until the field is changed and then left, +as React's does, or until the errors are given again. + +```ocaml title="form_server_errors.mlx" +module S = Solidtype.Solid +module Button = Solidtype_heroui.Button +module Field_error = Solidtype_heroui.Field_error +module Form = Solidtype_heroui.Form +module Input = Solidtype_heroui.Input +module Label = Solidtype_heroui.Label +module Text_field = Solidtype_heroui.Text_field + +external prevent_default : Dom.event -> unit = "preventDefault" [@@mel.send] + +let make () = + (* What a server answered, by field name: here, every name is taken. *) + let errors, set_errors = S.create_signal [] in +
    + prevent_default e; + S.set set_errors [ ("username", "This username is taken.") ])> + + + + + +``` + +### From a codec + +A client wiretype prints for an application's routes checks a body against +the routes' own rules before it sends it, and reads a server's refusal: each +problem it finds is at a path in the body, with a sentence for that place. +A field's `name` is that path, so the problems are `validation_errors` in one +`List.map`, and `solidtype-heroui` needs no codec of its own. The example +board's form to add a task, whose title the routes say is 1 to 120 +characters and its note at most 200: + +```ocaml title="example/src/add_task.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Button = Solidtype_heroui.Button +module Description = Solidtype_heroui.Description +module Field_error = Solidtype_heroui.Field_error +module Form = Solidtype_heroui.Form +module Input = Solidtype_heroui.Input +module Label = Solidtype_heroui.Label +module List_box = Solidtype_heroui.List_box +module Modal = Solidtype_heroui.Modal +module Select = Solidtype_heroui.Select +module Text_area = Solidtype_heroui.Text_area +module Text_field = Solidtype_heroui.Text_field +module Gravity = Solidtype_gravity_icons + +external prevent_default : Dom.event -> unit = "preventDefault" [@@mel.send] + +(* The labels written in one field, split by commas, each once. *) +let labels written = + List.fold_left + (fun kept l -> + match String.trim l with + | "" -> kept + | l when List.exists (String.equal l) kept -> kept + | l -> kept @ [ l ]) + [] + (String.split_on_char ',' written) + +let optional = function "" -> None | s -> Some s + +(* The dialog that puts a task on a project's board, [project] chosen at + first; [on_added] is told its title. What the server finds wrong with a + field is shown on that field. *) +let%component make ~(projects : Api.project array) ~(project : float option) + ~(on_added : string -> unit) () = + let open_, set_open = S.create_signal false in + let chosen, set_chosen = S.create_signal None in + let title, set_title = S.create_signal "" in + let note, set_note = S.create_signal "" in + let link, set_link = S.create_signal "" in + let written, set_written = S.create_signal "" in + let refused, set_refused = S.create_signal [] in + let problem, set_problem = S.create_signal "" in + let target () = + match S.get chosen with + | Some id -> Some id + | None -> ( + match S.get project with + | Some id -> Some id + | None -> + Option.map + (fun (p : Api.project) -> p.id) + (Array.find_opt (fun _ -> true) (S.get projects))) + in + let opened o = + S.batch (fun () -> + if not o then ( + S.set set_chosen None; + S.set set_title ""; + S.set set_note ""; + S.set set_link ""; + S.set set_written ""; + S.set set_refused []; + S.set set_problem ""); + S.set set_open o) + in + let answered = function + | Ok (t : Api.task) -> + opened false; + on_added t.title + | Error e -> ( + match Said.on_fields e with + | [] -> S.set set_problem (Said.error e) + | on_fields -> S.set set_refused on_fields) + in + let submit e = + prevent_default e; + match target () with + | Some project -> + ignore + (Js.Promise.then_ + (fun a -> Js.Promise.resolve (answered a)) + (Api.post_api_tasks + ~body: + { + project; + title = S.get title; + note = optional (S.get note); + link = optional (String.trim (S.get link)); + labels = Array.of_list (labels (S.get written)); + } + ()) + : unit Js.Promise.t) + | None -> () + in + + + + + + + "New task" +
    + + + + + + "Give the task a title." + + + + + "The note is too long." + + + + + + "Give a link that starts with https://." + + + + + + "Up to five, split by commas." + + "Up to five labels, each a short word." + + +

    + (Jsx.string (S.get problem)) +

    +
    + + + + + +
    +
    +
    +
    +``` + +A body the client finds wrong is never sent: `Api.post_api_tasks` answers +`` `Invalid `` with its problems, at the body's own paths, `title` or `note`. +A server's refusal, `` `Refused ``, names each problem by where it is in the +request, `body.title`, so a form that shows those on its fields takes the +prefix off first: + +```ocaml +| Error (`Refused ({ problems = Some problems; _ } : Api.refusal)) -> + S.set set_refused + (Array.to_list problems + |> List.filter_map (fun (p : Api.problem) -> + match String.split_on_char '.' p.at with + | "body" :: path -> Some (String.concat "." path, p.message) + | _ -> None)) +``` + +### Focus on a refused submit + +A refused submit calls `on_invalid` once, with a cancelable `invalid` event +on the form, before it focuses the first invalid field. A handler that calls +`preventDefault` keeps that focus from moving, and moves it as it chooses. +React's `onInvalid` is called once for each invalid field, as the browser's +own `invalid` event is; one submit refused here is one call. + +```ocaml +
    prevent_default e; focus_summary ())> + (* fields *) + +``` + +## Styling Reference + +`Form` renders a native `
    ` element without dedicated BEM classes. Apply +layout, spacing, and surface styles through `class_`. Field appearance and +validation states come from child components such as `Text_field`, `Input`, +`Label`, `Description`, and `Field_error`. For structured multi-field layouts, +compose with [Fieldset](fieldset.md). + +## API Reference + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `onSubmit` | `on_submit` | `Dom.event -> unit` | | Handler called when the form is submitted, while every field is valid | +| `onReset` | `on_reset` | `Dom.event -> unit` | | Handler called when the form is reset | +| `validationErrors` | `validation_errors` | `(string * string) list` | | Server-side validation errors mapped by field name, cleared when the user changes the field and leaves it | +| `action` | `action` | `string` | | The URL to submit the form data to | +| `method` | `method_` | `` [ `get \| `post \| `dialog ] `` | | The HTTP method to use when submitting the form | +| `aria-label` | `aria_label` | `string` | | Accessibility label for the form | +| `aria-labelledby` | `aria_labelledby` | `string` | | ID of element that labels the form. Creates a form landmark when provided | +| `className` | `class_` | `string` | | Tailwind CSS classes applied to the form element | +| `onInvalid` | `on_invalid` | `Dom.event -> unit` | | Called once a submit is refused, before the first invalid field is focused; `preventDefault` keeps the focus where it is | +| `validationBehavior` | — | | | Left out: a field validates nothing itself, and is invalid as the application says | + +### Form Submission + +Forms can be submitted in several ways: + +- **Traditional submission**: Set the `action` prop to submit to a URL +- **Handled in OCaml**: Use the `on_submit` handler to process the form data + +### Integration with Form Fields + +Every field inside a `Form` tells it its name and whether it is invalid: +`Text_field`, `Number_field`, `Search_field`, `Time_field`, `Color_field`, +`Checkbox`, `Checkbox_group`, `Radio_group`, `Switch`, `Slider`, +`Color_slider`, `Select`, `Combo_box` and `Autocomplete`. + +## Accessibility + +- Native `` element semantics +- Form landmark creation with `aria_label` or `aria_labelledby` +- Automatic focus management on validation errors: a refused submit focuses + the first invalid field diff --git a/agents/pages/heroui/input-group.md b/agents/pages/heroui/input-group.md new file mode 100644 index 00000000..5bc27650 --- /dev/null +++ b/agents/pages/heroui/input-group.md @@ -0,0 +1,762 @@ +# InputGroup + +Group related input controls with prefix and suffix elements for enhanced form fields. + +Original HeroUI documentation: [InputGroup](https://heroui.com/en/docs/react/components/input-group). + +## Usage + +HeroUI's examples, with HeroUI's icons from [`solidtype-gravity-icons`](../heroui.md#icons). + +```ocaml title="input_group_usage.mlx" +module Description = Solidtype_heroui.Description +module Input_group = Solidtype_heroui.Input_group +module Label = Solidtype_heroui.Label +module Text_field = Solidtype_heroui.Text_field +module Gravity = Solidtype_gravity_icons + +let make () = + + + + + + + + + +``` + +## Parity + +The same HeroUI InputGroup twice, under the same props: in solidtype on the +left, in React on the right. Below them, every attribute of the two groups: a +marked row is one they disagree on. + +## Anatomy + +```ocaml + + + + "https://" + (* or Input_group.Text_area for multiline input *) + ".com" + + +``` + +`Input_group` wraps an input field with optional prefix and suffix elements, +creating a visually cohesive group. It's typically used within +[TextField](text-field.md) to add icons, text, buttons, or +other elements before or after the input. Use `Input_group.Input` for +single-line inputs or `Input_group.Text_area` for multiline text inputs. A +click on the group outside its input focuses the input. + +## Examples + +### Variants + +The InputGroup component supports two visual variants: + +- **`` `primary ``** (default) - Standard styling with shadow, suitable for + most use cases +- **`` `secondary ``** - Lower emphasis variant without shadow, suitable for + use in Surface components + +```ocaml title="input_group_variants.mlx" +module Description = Solidtype_heroui.Description +module Input_group = Solidtype_heroui.Input_group +module Label = Solidtype_heroui.Label +module Text_field = Solidtype_heroui.Text_field +module Gravity = Solidtype_gravity_icons + +let make () = +
    + + + + + + + + + + + + + + + + + + +
    +``` + +### In Surface + +When used inside a [Surface](surface.md) component, use +`` variant=`secondary `` to apply the lower emphasis variant suitable for +surface backgrounds. + +```ocaml title="input_group_surface.mlx" +module Description = Solidtype_heroui.Description +module Input_group = Solidtype_heroui.Input_group +module Label = Solidtype_heroui.Label +module Text_field = Solidtype_heroui.Text_field +module Surface = Solidtype_heroui.Surface +module Gravity = Solidtype_gravity_icons + +let make () = + + + + + + + + + + "We'll never share this with anyone else" + + +``` + +### Loading State + +Show a loading spinner in the suffix to indicate processing. + +```ocaml title="input_group_loading.mlx" +module Description = Solidtype_heroui.Description +module Input_group = Solidtype_heroui.Input_group +module Label = Solidtype_heroui.Label +module Text_field = Solidtype_heroui.Text_field +module Spinner = Solidtype_heroui.Spinner + +let make () = + + + + + + +``` + +### Required Field + +InputGroup respects the required state from its parent TextField. + +```ocaml title="input_group_required.mlx" +module Description = Solidtype_heroui.Description +module Input_group = Solidtype_heroui.Input_group +module Label = Solidtype_heroui.Label +module Text_field = Solidtype_heroui.Text_field +module Gravity = Solidtype_gravity_icons + +let make () = +
    + + + + + + + + + + + + + "$" + + "USD" + + "What customers would pay" + +
    +``` + +### Disabled State + +InputGroup respects the disabled state from its parent TextField. + +```ocaml title="input_group_disabled.mlx" +module Description = Solidtype_heroui.Description +module Input_group = Solidtype_heroui.Input_group +module Label = Solidtype_heroui.Label +module Text_field = Solidtype_heroui.Text_field +module Gravity = Solidtype_gravity_icons + +let make () = +
    + + + + + + + + + + + + + "$" + + "USD" + + +
    +``` + +### Full Width + +```ocaml title="input_group_full_width.mlx" +module Description = Solidtype_heroui.Description +module Input_group = Solidtype_heroui.Input_group +module Label = Solidtype_heroui.Label +module Text_field = Solidtype_heroui.Text_field +module Gravity = Solidtype_gravity_icons + +let make () = +
    + + + + + + + + + + + + + + + + + + +
    +``` + +### Text Prefix + +Use text as a prefix, such as currency symbols or protocol prefixes. + +```ocaml title="input_group_text_prefix.mlx" +module Description = Solidtype_heroui.Description +module Input_group = Solidtype_heroui.Input_group +module Label = Solidtype_heroui.Label +module Text_field = Solidtype_heroui.Text_field + +let make () = + + + + "https://" + + + +``` + +### Text Suffix + +Use text as a suffix, such as domain extensions or units. + +```ocaml title="input_group_text_suffix.mlx" +module Description = Solidtype_heroui.Description +module Input_group = Solidtype_heroui.Input_group +module Label = Solidtype_heroui.Label +module Text_field = Solidtype_heroui.Text_field + +let make () = + + + + + ".com" + + +``` + +### Icon Prefix and Text Suffix + +Combine an icon prefix with a text suffix. + +```ocaml title="input_group_icon_prefix_text_suffix.mlx" +module Description = Solidtype_heroui.Description +module Input_group = Solidtype_heroui.Input_group +module Label = Solidtype_heroui.Label +module Text_field = Solidtype_heroui.Text_field +module Gravity = Solidtype_gravity_icons + +let make () = + + + + + + + + ".com" + + +``` + +### Copy Button Suffix + +Add an interactive button in the suffix, such as a copy button. + +```ocaml title="input_group_copy_suffix.mlx" +module Description = Solidtype_heroui.Description +module Input_group = Solidtype_heroui.Input_group +module Label = Solidtype_heroui.Label +module Text_field = Solidtype_heroui.Text_field +module Button = Solidtype_heroui.Button +module Gravity = Solidtype_gravity_icons + +let make () = + + + + + + + + + +``` + +### Icon Prefix and Copy Button + +Combine an icon prefix with an interactive button suffix. + +```ocaml title="input_group_icon_prefix_copy_suffix.mlx" +module Description = Solidtype_heroui.Description +module Input_group = Solidtype_heroui.Input_group +module Label = Solidtype_heroui.Label +module Text_field = Solidtype_heroui.Text_field +module Button = Solidtype_heroui.Button +module Gravity = Solidtype_gravity_icons + +let make () = + + + + + + + + + + + + +``` + +### Password Toggle + +Use a button in the suffix to toggle password visibility. + +```ocaml title="input_group_password.mlx" +module Description = Solidtype_heroui.Description +module Input_group = Solidtype_heroui.Input_group +module Label = Solidtype_heroui.Label +module Text_field = Solidtype_heroui.Text_field +module S = Solidtype.Solid +module Button = Solidtype_heroui.Button +module Gravity = Solidtype_gravity_icons + +let make () = + let visible, set_visible = S.create_signal false in + + + + + + + + + +``` + +### Keyboard Shortcut + +Display keyboard shortcuts using the [Kbd](kbd.md) component. + +```ocaml title="input_group_shortcut.mlx" +module Description = Solidtype_heroui.Description +module Input_group = Solidtype_heroui.Input_group +module Label = Solidtype_heroui.Label +module Text_field = Solidtype_heroui.Text_field +module Kbd = Solidtype_heroui.Kbd + +let make () = + + + + + + "K" + + + + +``` + +### Badge Suffix + +Add a badge or chip in the suffix to show status or labels. + +```ocaml title="input_group_badge_suffix.mlx" +module Description = Solidtype_heroui.Description +module Input_group = Solidtype_heroui.Input_group +module Label = Solidtype_heroui.Label +module Text_field = Solidtype_heroui.Text_field +module Chip = Solidtype_heroui.Chip + +let make () = + + + + + "Pro" + + + +``` + +### Validation + +InputGroup automatically reflects invalid state from its parent TextField. + +```ocaml title="input_group_invalid.mlx" +module Description = Solidtype_heroui.Description +module Input_group = Solidtype_heroui.Input_group +module Label = Solidtype_heroui.Label +module Text_field = Solidtype_heroui.Text_field +module Field_error = Solidtype_heroui.Field_error +module Gravity = Solidtype_gravity_icons + +let make () = +
    + + + + + + + + + "Please enter a valid email address" + + + + + "$" + + "USD" + + "Price must be greater than 0" + +
    +``` + +### With Prefix Icon + +Add an icon before the input field. + +```ocaml title="input_group_prefix_icon.mlx" +module Description = Solidtype_heroui.Description +module Input_group = Solidtype_heroui.Input_group +module Label = Solidtype_heroui.Label +module Text_field = Solidtype_heroui.Text_field +module Gravity = Solidtype_gravity_icons + +let make () = + + + + + + + + + "We'll never share this with anyone else" + +``` + +### With Suffix Icon + +Add an icon after the input field. + +```ocaml title="input_group_suffix_icon.mlx" +module Description = Solidtype_heroui.Description +module Input_group = Solidtype_heroui.Input_group +module Label = Solidtype_heroui.Label +module Text_field = Solidtype_heroui.Text_field +module Gravity = Solidtype_gravity_icons + +let make () = + + + + + + + + + "We don't send spam" + +``` + +### With Prefix and Suffix + +Combine both prefix and suffix elements. + +```ocaml title="input_group_prefix_suffix.mlx" +module Description = Solidtype_heroui.Description +module Input_group = Solidtype_heroui.Input_group +module Label = Solidtype_heroui.Label +module Text_field = Solidtype_heroui.Text_field + +let make () = + + + + "$" + + "USD" + + "What customers would pay" + +``` + +### With TextArea + +Use `Input_group.Text_area` for multiline text inputs with prefix and suffix +elements. When a textarea is present, the container automatically adjusts its +height to accommodate the content and aligns prefix/suffix elements to the +top. + +```ocaml title="input_group_text_area.mlx" +module Description = Solidtype_heroui.Description +module Input_group = Solidtype_heroui.Input_group +module Label = Solidtype_heroui.Label +module Text_field = Solidtype_heroui.Text_field +module S = Solidtype.Solid +module Button = Solidtype_heroui.Button +module Spinner = Solidtype_heroui.Spinner +module Gravity = Solidtype_gravity_icons + +let make () = + let value, set_value = S.create_signal "" in + let submitting, set_submitting = S.create_signal false in + let empty () = String.equal (String.trim (S.get value)) "" in + let submit _ = + if not (empty ()) then begin + S.set set_submitting true; + ignore + (Js.Global.setTimeout + ~f:(fun () -> + S.set set_submitting false; + S.set set_value "") + 1000 + : Js.Global.timeoutId) + end + in + + + + + + + + + +
    + + +
    +
    +
    +
    +``` + +## Customization + +### Tailwind CSS + +`class_` is added after HeroUI's classes. + +```ocaml title="input_group_tailwind.mlx" +module Description = Solidtype_heroui.Description +module Input_group = Solidtype_heroui.Input_group +module Label = Solidtype_heroui.Label +module Text_field = Solidtype_heroui.Text_field +module Gravity = Solidtype_gravity_icons + +let make () = + + + + + + + + + +``` + +## Styling Reference + +HeroUI follows the [BEM](https://bem.info/en/methodology/) methodology to +ensure component variants and states are reusable and easy to customize. + +### CSS Classes + +- `.input-group` - Root container with border, background, and flex layout, + switching to top alignment when a textarea is present +- `.input-group__input` - Input element with transparent background and no + border, also the base class for textarea elements +- `.input-group__prefix` - Prefix container with left border radius +- `.input-group__suffix` - Suffix container with right border radius +- `.input-group--primary` - Primary variant with shadow (default) +- `.input-group--secondary` - Secondary variant without shadow, suitable for + use in surfaces +- `.input-group--full-width` - Full width modifier + +With `Input_group.Text_area`, the container grows with its content and the +prefix and suffix align to the top. The textarea's own styles, a minimum +height and vertical resize, apply through +`[data-slot="input-group-textarea"]`. + +### Interactive States + +InputGroup automatically manages these data attributes based on its state: + +- **Hover**: `[data-hovered="true"]` - Applied when hovering over the group +- **Focus within**: `[data-focus-within="true"]` - Applied when the input is + focused +- **Focus visible**: `[data-focus-visible="true"]` +- **Disabled**: `[data-disabled="true"]` - Applied when it or its parent + TextField is disabled +- **Invalid**: `[data-invalid="true"]` - Applied when it or its parent + TextField is invalid + +## API Reference + +Each prop beside the name HeroUI's React component gives it. + +### InputGroup + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `variant` | `variant` | `` [ `primary \| `secondary ] `` | its field's, else `` `primary `` | Visual variant of the component. `` `primary `` is the default style with shadow. `` `secondary `` is a lower emphasis variant without shadow, suitable for use in surfaces | +| `fullWidth` | `full_width` | `bool` | `false` | Whether the input group should take full width of its container | +| `isDisabled` | `is_disabled` | `bool` | its field's | Whether it is shown disabled | +| `isInvalid` | `is_invalid` | `bool` | its field's | Whether it is shown invalid | +| `className` | `class_` | `string` | | Added after HeroUI's classes | + +### InputGroup.Input, InputGroup.TextArea + +Each takes every attribute its element takes, as [Input](input.md) and +[TextArea](text-area.md) do. + +### InputGroup.Prefix, InputGroup.Suffix + +Each takes `class_`, added after HeroUI's class, and its children: the +content to display in the prefix or suffix (icons, text, buttons, badges, +etc.). diff --git a/agents/pages/heroui/input.md b/agents/pages/heroui/input.md new file mode 100644 index 00000000..513d5323 --- /dev/null +++ b/agents/pages/heroui/input.md @@ -0,0 +1,128 @@ +# Input + +Primitive single-line text input component that accepts standard HTML attributes. + +For validation, labels, and error messages, see +[TextField](text-field.md): inside one, an input takes the +field's value, state, label and description. + +Original HeroUI documentation: [Input](https://heroui.com/en/docs/react/components/input). + +## Usage + +```ocaml title="input_usage.mlx" +module Input = Solidtype_heroui.Input + +let make () = + +``` + +## Examples + +### Variants + +The Input component supports two visual variants: + +- **`` `primary ``** (default) - Standard styling with shadow, suitable for + most use cases +- **`` `secondary ``** - Lower emphasis variant without shadow, suitable for + use in Surface components + +```ocaml title="input_variants.mlx" +module Input = Solidtype_heroui.Input + +let make () = +
    + + +
    +``` + +### Full Width + +```ocaml title="input_full_width.mlx" +module Input = Solidtype_heroui.Input + +let make () = +
    + +
    +``` + +### Input Types + +```ocaml title="input_types.mlx" +module Input = Solidtype_heroui.Input + +let make () = +
    + + + + + +
    +``` + +### Controlled + +Alone, an input is an ``: its value is its `value`, and its changes are its `on_input`. + +```ocaml title="input_controlled.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Input = Solidtype_heroui.Input + +external target : Dom.inputEvent -> Dom.htmlInputElement = "target" [@@mel.get] +external value_of : Dom.htmlInputElement -> string = "value" [@@mel.get] + +let make () = + let value, set_value = S.create_signal "heroui.com" in +
    + S.set set_value (value_of (target e))) + /> + + (Jsx.string ("https://" ^ S.get value)) + +
    +``` + +## Styling Reference + +HeroUI follows the [BEM](https://bem.info/en/methodology/) methodology to +ensure component variants and states are reusable and easy to customize. + +### CSS Classes + +- `.input` - Native input element styling +- `.input--primary`, `.input--secondary` - Variants +- `.input--full-width` - Full width modifier + +### Interactive States + +- **Hover**: `:hover` or `[data-hovered="true"]` +- **Focus Visible**: `:focus-visible` or `[data-focus-visible="true"]` +- **Invalid**: `[data-invalid="true"]` (also syncs with `aria_invalid`) +- **Disabled**: `:disabled` or `[data-disabled="true"]` + +## API Reference + +Input accepts all standard HTML `` attributes plus the following: + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `variant` | `variant` | `` [ `primary \| `secondary ] `` | `` `primary ``, or its field's | Visual variant of the component. `` `primary `` is the default style with shadow. `` `secondary `` is a lower emphasis variant without shadow, suitable for use in surfaces | +| `fullWidth` | `full_width` | `bool` | `false` | Whether the input should take full width of its container | +| `className` | `class_` | `string` | | Added after HeroUI's classes | + +For validation props like `is_invalid`, `is_required`, and error handling, +use [TextField](text-field.md) with Input as a child +component. diff --git a/agents/pages/heroui/kbd.md b/agents/pages/heroui/kbd.md new file mode 100644 index 00000000..b9caee11 --- /dev/null +++ b/agents/pages/heroui/kbd.md @@ -0,0 +1,289 @@ +# Kbd + +Display keyboard shortcuts and key combinations. + +Original HeroUI documentation: [Kbd](https://heroui.com/en/docs/react/components/kbd). + +## Usage + +```ocaml title="kbd_usage.mlx" +module Kbd = Solidtype_heroui.Kbd + +let make () = +
    + "K" + "P" + "C" + "D" +
    +``` + +## Parity + +The same HeroUI Kbd twice, under the same props: in solidtype on the left, in +React on the right. Below them, every attribute of the two keys: a marked row +is one they disagree on. + +## Anatomy + +```ocaml + + + "K" + +``` + +`Kbd.Abbr`'s `key_value` draws the key's symbol, ⌘ here, with its name as +the title for accessibility. + +## Examples + +### Variants + +```ocaml title="kbd_variants.mlx" +module Kbd = Solidtype_heroui.Kbd + +let make () = +
    +
    + "Copy:" + "C" + + "C" + +
    +
    + "Paste:" + "V" + + "V" + +
    +
    + "Cut:" + "X" + + "X" + +
    +
    + "Undo:" + "Z" + + "Z" + +
    +
    + "Redo:" + + + + "Z" + + + + + "Z" + +
    +
    +``` + +### Navigation Keys + +```ocaml title="kbd_navigation.mlx" +module Kbd = Solidtype_heroui.Kbd + +let make () = +
    +
    + "Arrow Keys:" +
    + + + + +
    +
    +
    + "Page Navigation:" +
    + + + + +
    +
    +
    +``` + +### Inline Usage + +```ocaml title="kbd_inline.mlx" +module Kbd = Solidtype_heroui.Kbd + +let make () = +
    +

    + "Press " + "Esc" + " to close the dialog." +

    +

    + "Use " + "K" + " to open the command palette." +

    +

    + "Navigate with " + + " and " + + " arrow keys." +

    +

    + "Save your work with " + "S" + " regularly." +

    +
    +``` + +### Special Keys + +```ocaml title="kbd_special.mlx" +module Kbd = Solidtype_heroui.Kbd + +let make () = +
    +

    + "Press " + + " to confirm or " + + " to cancel." +

    +

    + "Use " + + " to navigate between form fields and " + + " to go back." +

    +

    + "Hold " + + " to temporarily enable panning mode." +

    +
    +``` + +## Customization + +### Tailwind CSS + +`class_` is added after HeroUI's classes, on the key and on each part. + +```ocaml title="kbd_tailwind.mlx" +module Kbd = Solidtype_heroui.Kbd + +let make () = +
    + + "K" + + + "P" + +
    +``` + +### Global CSS + +To customize the Kbd component classes, you can use the `@layer components` +directive. +[Learn more](https://tailwindcss.com/docs/adding-custom-styles#adding-component-classes). + +```css +@layer components { + .kbd { + @apply bg-gray-100 dark:bg-gray-800 border-gray-300; + } + + .kbd__abbr { + @apply font-bold; + } + + .kbd__content { + @apply text-sm; + } +} +``` + +## Styling Reference + +HeroUI follows the [BEM](https://bem.info/en/methodology/) methodology to +ensure component variants and states are reusable and easy to customize. + +### CSS Classes + +- `.kbd` - Base keyboard key styles with background, border, and spacing +- `.kbd--default`, `.kbd--light` - Variants +- `.kbd__abbr` - Abbreviation element for modifier keys +- `.kbd__content` - Content wrapper for key text + +## API Reference + +Each prop beside the name HeroUI's React component gives it. + +### Kbd + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `variant` | `variant` | `` [ `default \| `light ] `` | `` `default `` | Variant of the keyboard key | +| `className` | `class_` | `string` | | Added after HeroUI's classes | +| `children` | `children` | elements | | Content of the key | + +### Kbd.Abbr + +| React | solidtype | Type | Description | +|---|---|---|---| +| `keyValue` | `key_value` | `Kbd.key` | The key whose symbol it draws, titled with its name for accessibility (e.g., "Command" for ⌘) | +| `className` | `class_` | `string` | Added after HeroUI's class | + +### Kbd.Content + +| React | solidtype | Type | Description | +|---|---|---|---| +| `className` | `class_` | `string` | Added after HeroUI's class | +| `children` | `children` | elements | Text content of the key | + +### Kbd.key + +Available key values for the `key_value` prop, the name React gives each, and +its symbol and title: + +| solidtype | React | Drawn | +|---|---|---| +| `` `command `` | `"command"` | ⌘ Command | +| `` `shift `` | `"shift"` | ⇧ Shift | +| `` `ctrl `` | `"ctrl"` | ⌃ Control | +| `` `option `` | `"option"` | ⌥ Option | +| `` `enter `` | `"enter"` | ↵ Enter | +| `` `delete `` | `"delete"` | ⌫ Delete | +| `` `escape `` | `"escape"` | ⎋ Escape | +| `` `tab `` | `"tab"` | ⇥ Tab | +| `` `capslock `` | `"capslock"` | ⇪ Caps Lock | +| `` `up `` | `"up"` | ↑ Up | +| `` `right `` | `"right"` | → Right | +| `` `down `` | `"down"` | ↓ Down | +| `` `left `` | `"left"` | ← Left | +| `` `pageup `` | `"pageup"` | ⇞ Page Up | +| `` `pagedown `` | `"pagedown"` | ⇟ Page Down | +| `` `home `` | `"home"` | ↖ Home | +| `` `end_ `` | `"end"` | ↘ End | +| `` `help `` | `"help"` | ? Help | +| `` `space `` | `"space"` | ␣ Space | +| `` `fn `` | `"fn"` | Fn Fn | +| `` `win `` | `"win"` | ⌘ Win | +| `` `alt `` | `"alt"` | ⌥ Alt | diff --git a/agents/pages/heroui/label.md b/agents/pages/heroui/label.md new file mode 100644 index 00000000..f2f58868 --- /dev/null +++ b/agents/pages/heroui/label.md @@ -0,0 +1,107 @@ +# Label + +Renders an accessible label associated with form controls. + +Inside a [TextField](text-field.md) or a +[Radio Group](radio-group.md) it names the field; the +[Switch](switch.md), [Checkbox](checkbox.md) +and Radio Group pages show it in its fields. + +Original HeroUI documentation: [Label](https://heroui.com/en/docs/react/components/label). + +## Usage + +```ocaml title="label_usage.mlx" +module Input = Solidtype_heroui.Input +module Label = Solidtype_heroui.Label + +let make () = +
    + + +
    +``` + +## Customization + +### Tailwind CSS + +`class_` is added after HeroUI's classes. + +```ocaml title="label_tailwind.mlx" +module Input = Solidtype_heroui.Input +module Label = Solidtype_heroui.Label + +let make () = +
    + + +
    +``` + +### Global CSS + +To customize the Label component classes, you can use the `@layer components` +directive. +[Learn more](https://tailwindcss.com/docs/adding-custom-styles#adding-component-classes). + +```css +@layer components { + .label { + @apply font-semibold; + } +} +``` + +## Styling Reference + +HeroUI follows the [BEM](https://bem.info/en/methodology/) methodology to +ensure component variants and states are reusable and easy to customize. + +### CSS Classes + +- `.label` - Base label styles with text styling +- `.label--required` or `[data-required="true"] > .label` - Shows required + asterisk indicator +- `.label--disabled` or `[data-disabled="true"] .label` - Disabled state + styling +- `.label--invalid` or `[data-invalid="true"] .label` or + `[aria-invalid="true"] .label` - Invalid state styling (danger/red text + color) + +The required asterisk is not shown on a group's label (`role="group"`, +`role="radiogroup"` or `role="checkboxgroup"`) or inside a radio or a +checkbox (`data-slot="radio"` or `data-slot="checkbox"`), so a required group +shows one asterisk. + +## API Reference + +Each prop beside the name HeroUI's React component gives it. + +### Label + +| React | solidtype | Type | Description | +|---|---|---|---| +| `className` | `class_` | `string` | Added after HeroUI's classes | +| `children` | `children` | elements | The content of the label | +| `isRequired` | `is_required` | `bool` | Whether to display a required indicator | +| `isDisabled` | `is_disabled` | `bool` | Whether the label is in a disabled state | +| `isInvalid` | `is_invalid` | `bool` | Whether the label is in an invalid state | + +### Label.Slot + +How a label renders inside a part, given its classes and its children: +`Switch.Content` and `Checkbox.Content` render it as a ``, and +`Radio_group` as the label that names the group. + +## Accessibility + +- Renders a native `
    + + + + "Name" + "Role" + "Status" + "Email" + + + + "Kate Moore" + "CEO" + "Active" + "kate@acme.com" + + + "John Smith" + "CTO" + "Active" + "john@acme.com" + + + "Sara Johnson" + "CMO" + "On Leave" + "sara@acme.com" + + + "Michael Brown" + "CFO" + "Active" + "michael@acme.com" + + + + +
    +``` + +## Parity + +The same HeroUI Table twice, under the same props: in solidtype on the left, +in React on the right. Below them, every attribute of the two tables: a marked +row is one they disagree on. + +## Anatomy + +```ocaml + + + + + "Name" + "Role" + + + + "Kate Moore" + "CEO" + + + + + +
    +``` + +## Examples + +### Secondary Variant + +```ocaml title="table_secondary.mlx" +module Table = Solidtype_heroui.Table + +let make () = + + + + + "Name" + "Role" + "Status" + "Email" + + + + "Kate Moore" + "CEO" + "Active" + "kate@acme.com" + + + "John Smith" + "CTO" + "Active" + "john@acme.com" + + + "Sara Johnson" + "CMO" + "On Leave" + "sara@acme.com" + + + "Michael Brown" + "CFO" + "Active" + "michael@acme.com" + + + + +
    +``` + +### Async Loading + +Use `Table.Load_more` at the end of `Table.Body` for infinite scrolling. It +renders a sentinel row that triggers `on_load_more` when scrolled into view, +and again as loading ends with it still in view. While `is_loading`, it draws +a row across every column holding its `Table.Load_more_content`. It never asks +while loading, so the application keeps no guard of its own. + +```ocaml title="table_async_loading.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Show = Solidtype.Show +module Chip = Solidtype_heroui.Chip +module Spinner = Solidtype_heroui.Spinner +module Table = Solidtype_heroui.Table + +type user = { + id : int; + name : string; + role : string; + status : string; + email : string; +} + +let status_color = function + | "Active" -> `success + | "Inactive" -> `danger + | _ -> `warning + +let all_users = + [| + { + email = "kate@acme.com"; + id = 1; + name = "Kate Moore"; + role = "CEO"; + status = "Active"; + }; + { + email = "john@acme.com"; + id = 2; + name = "John Smith"; + role = "CTO"; + status = "Active"; + }; + { + email = "sara@acme.com"; + id = 3; + name = "Sara Johnson"; + role = "CMO"; + status = "On Leave"; + }; + { + email = "michael@acme.com"; + id = 4; + name = "Michael Brown"; + role = "CFO"; + status = "Active"; + }; + { + email = "emily@acme.com"; + id = 5; + name = "Emily Davis"; + role = "Product Manager"; + status = "Inactive"; + }; + { + email = "davis@acme.com"; + id = 6; + name = "Davis Wilson"; + role = "Lead Designer"; + status = "Active"; + }; + { + email = "olivia@acme.com"; + id = 7; + name = "Olivia Martinez"; + role = "Frontend Engineer"; + status = "Active"; + }; + { + email = "james@acme.com"; + id = 8; + name = "James Taylor"; + role = "Backend Engineer"; + status = "Active"; + }; + { + email = "sophia@acme.com"; + id = 9; + name = "Sophia Anderson"; + role = "QA Engineer"; + status = "On Leave"; + }; + { + email = "liam@acme.com"; + id = 10; + name = "Liam Thomas"; + role = "DevOps Engineer"; + status = "Active"; + }; + { + email = "lucas@acme.com"; + id = 11; + name = "Lucas Martinez"; + role = "Product Manager"; + status = "Active"; + }; + { + email = "emma@acme.com"; + id = 12; + name = "Emma Johnson"; + role = "Frontend Engineer"; + status = "Active"; + }; + { + email = "noah@acme.com"; + id = 13; + name = "Noah Davis"; + role = "Backend Engineer"; + status = "Active"; + }; + { + email = "ava@acme.com"; + id = 14; + name = "Ava Wilson"; + role = "Lead Designer"; + status = "Active"; + }; + { + email = "oliver@acme.com"; + id = 15; + name = "Oliver Martinez"; + role = "Frontend Engineer"; + status = "Active"; + }; + { + email = "isabella@acme.com"; + id = 16; + name = "Isabella Johnson"; + role = "Backend Engineer"; + status = "Active"; + }; + { + email = "mia@acme.com"; + id = 17; + name = "Mia Davis"; + role = "Lead Designer"; + status = "Active"; + }; + { + email = "william@acme.com"; + id = 18; + name = "William Wilson"; + role = "Frontend Engineer"; + status = "Active"; + }; + |] + +let items_per_page = 6 + +(* How long the fetch it stands in for takes. *) +let load_ms = 1500 + +let columns = + [| + ("name", "Name"); ("role", "Role"); ("status", "Status"); ("email", "Email"); + |] + +let make () = + let count, set_count = S.create_signal items_per_page in + let loading, set_loading = S.create_signal false in + let has_more () = S.get count < Array.length all_users in + let timer = ref None in + S.on_cleanup (fun () -> Option.iter Js.Global.clearTimeout !timer); + (* The table asks for more only while it is not loading. *) + let load_more () = + if has_more () then begin + S.set set_loading true; + timer := + Some + (Js.Global.setTimeout + ~f:(fun () -> + S.batch (fun () -> + S.set set_count + (min (Array.length all_users) + (S.get count + items_per_page)); + S.set set_loading false)) + load_ms) + end + in + + + + + + (fun (id, name) _ -> + + (Jsx.string name) + ) + + + + + (fun user _ -> + + (Jsx.string user.name) + (Jsx.string user.role) + + + (Jsx.string user.status) + + + (Jsx.string user.email) + ) + + + + + + + + + + + +
    +``` + +### Sorting + +Columns can be made sortable using the `allows_sorting` and `id` props on +`Table.Column`. Use `sort_descriptor` and `on_sort_change` on `Table.Content` +to manage sort state; the rows' order is the application's. Wrap the label in +`Table.Sortable_column_header` to render the default ascending/descending +indicator: it reads its column's direction itself. +A sortable column is sorted by a press, Enter or Space. + +```ocaml title="table_sorting.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Table = Solidtype_heroui.Table + +type user = { + id : int; + name : string; + role : string; + status : string; + email : string; +} + +let users = + [| + { + email = "kate@acme.com"; + id = 1; + name = "Kate Moore"; + role = "CEO"; + status = "Active"; + }; + { + email = "john@acme.com"; + id = 2; + name = "John Smith"; + role = "CTO"; + status = "Active"; + }; + { + email = "sara@acme.com"; + id = 3; + name = "Sara Johnson"; + role = "CMO"; + status = "On Leave"; + }; + { + email = "michael@acme.com"; + id = 4; + name = "Michael Brown"; + role = "CFO"; + status = "Active"; + }; + { + email = "emily@acme.com"; + id = 5; + name = "Emily Davis"; + role = "Product Manager"; + status = "Inactive"; + }; + |] + +let field column (u : user) = + match column with + | "role" -> u.role + | "status" -> u.status + | "email" -> u.email + | _ -> u.name + +external locale_compare : string -> string -> int = "localeCompare" [@@mel.send] + +let make () = + let sort, set_sort = + S.create_signal { Table.column = "name"; direction = `ascending } + in + let sorted_users () = + let { Table.column; direction } = S.get sort in + let order = + List.sort + (fun a b -> locale_compare (field column a) (field column b)) + (Array.to_list users) + in + Array.of_list + (match direction with + | `ascending -> order + | `descending -> List.rev order) + in + + + + + + "Name" + + + "Role" + + + + "Status" + + + + "Email" + + + + + (fun user _ -> + + (Jsx.string user.name) + (Jsx.string user.role) + (Jsx.string user.status) + (Jsx.string user.email) + ) + + + + +
    +``` + +### Selection + +Enable row selection with `selection_mode` on `Table.Content`. Use `Checkbox` +with `` slot=`selection `` for select-all and per-row checkboxes. A row is +selected by a press, Space or Enter. + +```ocaml title="table_selection.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Checkbox = Solidtype_heroui.Checkbox +module Table = Solidtype_heroui.Table + +type user = { + id : int; + name : string; + role : string; + status : string; + email : string; +} + +let users = + [| + { + email = "kate@acme.com"; + id = 1; + name = "Kate Moore"; + role = "CEO"; + status = "Active"; + }; + { + email = "john@acme.com"; + id = 2; + name = "John Smith"; + role = "CTO"; + status = "Active"; + }; + { + email = "sara@acme.com"; + id = 3; + name = "Sara Johnson"; + role = "CMO"; + status = "On Leave"; + }; + { + email = "michael@acme.com"; + id = 4; + name = "Michael Brown"; + role = "CFO"; + status = "Active"; + }; + |] + +let make () = + let selected_keys, set_selected_keys = S.create_signal [||] in +
    + + + + + + + + + + + + "Name" + "Role" + "Status" + "Email" + + + + (fun user _ -> + + + + + + + + + + + (Jsx.string user.name) + (Jsx.string user.role) + (Jsx.string user.status) + (Jsx.string user.email) + ) + + + + +
    +

    + "Selected: " + + (Jsx.string + (match S.get selected_keys with + | [||] -> "None" + | keys -> String.concat ", " (Array.to_list keys))) + +

    +
    +``` + +### Expandable Rows + +Rows can be nested to display hierarchical data: write a `Table.Row` inside +another, among its cells. Use the `tree_column` prop, the `id` of a column, to +designate a column, and render a `Button` with `` slot=`chevron `` in that +column's cells so users can expand and collapse the row. Use the +`expanded_keys` prop, or `default_expanded_keys`, and `on_expanded_change` to +control which rows are expanded. The arrow forward on a row expands it, and +the arrow back collapses it, then reaches the row it is in. + +`Table.Row.Context.use` and `Table.Cell.Context.use`, read in a cell, tell +whether its row holds rows and is expanded, and whether the cell is in the +tree column; a handler reads the row the cell was drawn in. + +```ocaml title="table_expandable_rows.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Show = Solidtype.Show +module Button = Solidtype_heroui.Button +module Table = Solidtype_heroui.Table +module Gravity = Solidtype_gravity_icons + +type file = { + id : string; + title : string; + kind : string; + date : string; + children : file array; +} + +let data = + [| + { + id = "1"; + title = "Documents"; + kind = "Directory"; + date = "10/20/2025"; + children = + [| + { + id = "2"; + title = "Project"; + kind = "Directory"; + date = "8/2/2025"; + children = + [| + { + id = "3"; + title = "Weekly Report"; + kind = "File"; + date = "7/10/2025"; + children = [||]; + }; + { + id = "4"; + title = "Budget"; + kind = "File"; + date = "8/20/2025"; + children = [||]; + }; + |]; + }; + |]; + }; + { + id = "5"; + title = "Photos"; + kind = "Directory"; + date = "2/3/2026"; + children = + [| + { + id = "6"; + title = "Image 1"; + kind = "File"; + date = "1/23/2026"; + children = [||]; + }; + { + id = "7"; + title = "Image 2"; + kind = "File"; + date = "2/3/2026"; + children = [||]; + }; + |]; + }; + |] + +(* A row, and the rows it holds written inside it; its chevron in the tree + column while it holds rows, turned while it is expanded, as HeroUI's + example draws it from its cell's render function. *) +let rec expandable_row item = + + + (let row = Table.Row.Context.use () in + let cell = Table.Cell.Context.use () in + + + + + (Jsx.string item.title) + ) + + (Jsx.string item.kind) + (Jsx.string item.date) + (fun child _ -> expandable_row child) + + +let make () = + let expanded, set_expanded = S.create_signal [| "1" |] in + + + S.set set_expanded keys)> + + "Name" + "Type" + "Date Modified" + + + (fun item _ -> expandable_row item) + + + +
    +``` + +### Drag and Drop + +Give `Table.Content` an `on_reorder` and each row a `Button` with +`` slot=`drag ``. Enter on it grabs the row, the arrows move it, Enter drops +it and Escape lets it go; a pointer drags it. `on_reorder` is told the rows +moved, `keys`, and the row they land beside, `target`, `` `before `` or +`` `after `` it, as its `position`. A selected row is dragged with the others +selected. HeroUI's React Table does this with React Aria's `useDragAndDrop`, +whose keyboard drag moves by Tab. + +```ocaml title="table_drag_and_drop.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Button = Solidtype_heroui.Button +module Data_grid = Solidtype_heroui.Data_grid +module Table = Solidtype_heroui.Table +module Gravity = Solidtype_gravity_icons + +type task = { id : string; title : string; status : string } + +let tasks = + [| + { id = "1"; title = "Design the landing page"; status = "In progress" }; + { id = "2"; title = "Write the launch post"; status = "To do" }; + { id = "3"; title = "Fix the sign-up form"; status = "In review" }; + { id = "4"; title = "Plan the next sprint"; status = "To do" }; + |] + +let make () = + let rows, set_rows = S.create_signal tasks in + + + + S.set set_rows + (Data_grid.reordered + ~row_id:(fun t -> t.id) + (S.get rows) r))> + + "" + "Task" + "Status" + + + + (fun t _ -> + + + + + (Jsx.string t.title) + (Jsx.string t.status) + ) + + + + +
    +``` + +### Pagination + +Use `Table.Footer` to add a pagination component below the table. + +```ocaml title="table_pagination.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Pagination = Solidtype_heroui.Pagination +module Table = Solidtype_heroui.Table + +type user = { + id : int; + name : string; + role : string; + status : string; + email : string; +} + +type column = { field : user -> string; name : string; row_header : bool } + +let columns = + [| + { field = (fun u -> u.name); name = "Name"; row_header = true }; + { field = (fun u -> u.role); name = "Role"; row_header = false }; + { field = (fun u -> u.status); name = "Status"; row_header = false }; + { field = (fun u -> u.email); name = "Email"; row_header = false }; + |] + +let users = + [| + { + email = "kate@acme.com"; + id = 1; + name = "Kate Moore"; + role = "CEO"; + status = "Active"; + }; + { + email = "john@acme.com"; + id = 2; + name = "John Smith"; + role = "CTO"; + status = "Active"; + }; + { + email = "sara@acme.com"; + id = 3; + name = "Sara Johnson"; + role = "CMO"; + status = "On Leave"; + }; + { + email = "michael@acme.com"; + id = 4; + name = "Michael Brown"; + role = "CFO"; + status = "Active"; + }; + { + email = "emily@acme.com"; + id = 5; + name = "Emily Davis"; + role = "Product Manager"; + status = "Inactive"; + }; + { + email = "davis@acme.com"; + id = 6; + name = "Davis Wilson"; + role = "Lead Designer"; + status = "Active"; + }; + { + email = "olivia@acme.com"; + id = 7; + name = "Olivia Martinez"; + role = "Frontend Engineer"; + status = "Active"; + }; + { + email = "james@acme.com"; + id = 8; + name = "James Taylor"; + role = "Backend Engineer"; + status = "Active"; + }; + |] + +let rows_per_page = 4 +let total_pages = (Array.length users + rows_per_page - 1) / rows_per_page +let pages = Array.init total_pages (fun i -> i + 1) + +let make () = + let page, set_page = S.create_signal 1 in + let shown () = + let start = (S.get page - 1) * rows_per_page in + Array.sub users start (Int.min rows_per_page (Array.length users - start)) + in + let first () = ((S.get page - 1) * rows_per_page) + 1 in + let last () = Int.min (S.get page * rows_per_page) (Array.length users) in + + + + + + (fun column _ -> + + (Jsx.string column.name) + ) + + + + + (fun user _ -> + + + (fun column _ -> + (Jsx.string (column.field user))) + + ) + + + + + + + + (Jsx.int (first ())) + " to " + (Jsx.int (last ())) + " of " + (Jsx.int (Array.length users)) + " results" + + + + + S.update set_page (fun p -> Int.max 1 (p - 1)))> + "Prev" + + + + (fun p _ -> + + S.set set_page p)> + (Jsx.int p) + + ) + + + + S.update set_page (fun p -> + Int.min total_pages (p + 1)))> + "Next" + + + + + +
    +``` + +### Column Resizing + +Wrap the table in `Table.Resizable_container`, in place of +`Table.Scroll_container`, and add `Table.Column_resizer` inside each resizable +column. A column's `width`, or `default_width` until it is resized, is +`Pixels`, a `Percent` of the table's width, or a `Fraction` of what the others +leave, between `min_width`, 75 pixels by default, and `max_width`. + +A resizer is dragged, or reached by Tab from its column's header: its arrows +resize the column by 10 pixels, and Enter begins a resize that Enter, Escape, +Space, Tab or leaving it ends. `on_resize_start`, `on_resize` and +`on_resize_end` on the container are told every column's size by its `id`. + +```ocaml title="table_column_resizing.mlx" +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Chip = Solidtype_heroui.Chip +module Table = Solidtype_heroui.Table + +type user = { + id : string; + name : string; + role : string; + status : string; + color : [ `accent | `danger | `default | `success | `warning ]; + email : string; +} + +let users = + [| + { + id = "1"; + name = "Kate Moore"; + role = "CEO"; + status = "Active"; + color = `success; + email = "kate@acme.com"; + }; + { + id = "2"; + name = "John Smith"; + role = "CTO"; + status = "Active"; + color = `success; + email = "john@acme.com"; + }; + { + id = "3"; + name = "Sara Johnson"; + role = "CMO"; + status = "On Leave"; + color = `warning; + email = "sara@acme.com"; + }; + { + id = "4"; + name = "Michael Brown"; + role = "CFO"; + status = "Active"; + color = `success; + email = "michael@acme.com"; + }; + { + id = "5"; + name = "Emily Davis"; + role = "Product Manager"; + status = "Inactive"; + color = `danger; + email = "emily@acme.com"; + }; + |] + +let make () = + + + + + + "Name" + + + "Role" + + + "Status" + + + "Email" + + + + + (fun user _ -> + + (Jsx.string user.name) + (Jsx.string user.role) + + + (Jsx.string user.status) + + + (Jsx.string user.email) + ) + + + + +
    +``` + +### Empty State + +Use `render_empty_state` on `Table.Body` to display a custom message when the +table has no data. + +```ocaml title="table_empty_state.mlx" +module Empty_state = Solidtype_heroui.Empty_state +module Table = Solidtype_heroui.Table +module Gravity = Solidtype_gravity_icons + +let make () = + + + + + "Name" + "Role" + "Status" + "Email" + + + + + + "No results found" + + )> + "" + + + +
    +``` + +### Custom Cells + +Any element in a cell: here a selection, sorting, `Avatar`, `Chip` and +`Button`, together. + +```ocaml title="table_custom_cells.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Avatar = Solidtype_heroui.Avatar +module Button = Solidtype_heroui.Button +module Checkbox = Solidtype_heroui.Checkbox +module Chip = Solidtype_heroui.Chip +module Table = Solidtype_heroui.Table +module Gravity = Solidtype_gravity_icons + +type status = Active | Inactive | On_leave + +type user = { + id : int; + name : string; + image_url : string; + role : string; + status : status; + email : string; +} + +let status_name = function + | Active -> "Active" + | Inactive -> "Inactive" + | On_leave -> "On Leave" + +let status_color = function + | Active -> `success + | Inactive -> `danger + | On_leave -> `warning + +let avatar color = + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/" ^ color + ^ ".jpg" + +let users = + [| + { + email = "kate@acme.com"; + id = 4586932; + image_url = avatar "red"; + name = "Kate Moore"; + role = "Chief Executive Officer"; + status = Active; + }; + { + email = "john@acme.com"; + id = 5273849; + image_url = avatar "green"; + name = "John Smith"; + role = "Chief Technology Officer"; + status = Active; + }; + { + email = "sara@acme.com"; + id = 7492836; + image_url = avatar "blue"; + name = "Sara Johnson"; + role = "Chief Marketing Officer"; + status = On_leave; + }; + { + email = "michael@acme.com"; + id = 8293746; + image_url = avatar "purple"; + name = "Michael Brown"; + role = "Chief Financial Officer"; + status = Active; + }; + { + email = "emily@acme.com"; + id = 1234567; + image_url = avatar "orange"; + name = "Emily Davis"; + role = "Product Manager"; + status = Inactive; + }; + |] + +let field column (u : user) = + match column with + | "id" -> string_of_int u.id + | "role" -> u.role + | "status" -> status_name u.status + | _ -> u.name + +external locale_compare : string -> string -> int = "localeCompare" [@@mel.send] + +let initials name = + String.split_on_char ' ' name + |> List.filter_map (fun w -> + if String.length w > 0 then Some (String.sub w 0 1) else None) + |> String.concat "" + +let make () = + let selected_keys, set_selected_keys = S.create_signal [||] in + let sort, set_sort = + S.create_signal { Table.column = "name"; direction = `ascending } + in + let sorted_users () = + let { Table.column; direction } = S.get sort in + let order = + List.sort + (fun a b -> locale_compare (field column a) (field column b)) + (Array.to_list users) + in + Array.of_list + (match direction with + | `ascending -> order + | `descending -> List.rev order) + in + + + + + + + + + + + + + + "Worker ID" + + + + + "Member" + + + + "Role" + + + + "Status" + + + "Actions" + + + + (fun user _ -> + + + + + + + + + + + +
    + (Jsx.string ("#" ^ string_of_int user.id)) + " " + +
    +
    + +
    + + + + (Jsx.string (initials user.name)) + + +
    + (Jsx.string user.name) + + (Jsx.string user.email) + +
    +
    +
    + + (Jsx.string user.role) + + + + (Jsx.string (status_name user.status)) + + + +
    + + + +
    +
    +
    ) +
    +
    +
    +
    +
    +``` + +### Virtualization + +Table supports virtualization through `Virtualizer`, given +`Virtualizer.table_layout`, enabling efficient rendering of large datasets by +displaying only the rows visible within the viewport. The table is what +scrolls: give it a height and an overflow by its class. The keys reach every +row, drawn or not. A table whose rows hold rows is not virtualized yet. + +```ocaml title="table_virtualization.mlx" +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Table = Solidtype_heroui.Table +module Virtualizer = Solidtype_heroui.Virtualizer + +type user = { id : int; name : string; role : string; email : string } + +let roles = + [| + "Software Engineer"; + "Senior Engineer"; + "Staff Engineer"; + "Product Manager"; + "Designer"; + "Data Analyst"; + "QA Engineer"; + "DevOps Engineer"; + "Marketing Manager"; + "Sales Representative"; + |] + +let first_names = + [| + "Emma"; + "Liam"; + "Olivia"; + "Noah"; + "Ava"; + "James"; + "Sophia"; + "Oliver"; + "Isabella"; + "Lucas"; + "Mia"; + "Ethan"; + "Charlotte"; + "Mason"; + "Amelia"; + "Logan"; + "Harper"; + "Alexander"; + "Ella"; + "Benjamin"; + |] + +let last_names = + [| + "Smith"; + "Johnson"; + "Williams"; + "Brown"; + "Jones"; + "Garcia"; + "Miller"; + "Davis"; + "Rodriguez"; + "Martinez"; + "Anderson"; + "Taylor"; + "Thomas"; + "Jackson"; + "White"; + "Harris"; + "Clark"; + "Lewis"; + "Robinson"; + "Walker"; + |] + +(* HeroUI's example's thousand users, made as its generateUsers makes them. *) +let users = + Array.init 1000 (fun i -> + let first = first_names.(i mod Array.length first_names) in + let last = + last_names.(i / Array.length first_names mod Array.length last_names) + in + { + id = i + 1; + name = first ^ " " ^ last; + role = roles.(i mod Array.length roles); + email = + String.lowercase_ascii first + ^ "." + ^ String.lowercase_ascii last + ^ "@acme.com"; + }) + +let make () = + + + + + + + "Name" + + "Role" + "Email" + + + + (fun user _ -> + + (Jsx.string user.name) + (Jsx.string user.role) + (Jsx.string user.email) + ) + + + + +
    +
    +``` + +### TanStack Table + +HeroUI's Table works as a rendering layer on top of headless table libraries. +HeroUI's example uses `@tanstack/react-table`; a Solid application uses +[TanStack Table](https://tanstack.com/table)'s `@tanstack/solid-table`, whose +rows and columns a table of `For`s draws. + +## Customization + +### Tailwind CSS + +`class_` is added after HeroUI's classes, on each part. + +```ocaml title="table_tailwind.mlx" +module Table = Solidtype_heroui.Table + +let header_cell = + "text-xs font-semibold uppercase tracking-wide text-neutral-500 \ + dark:text-neutral-400" + +let row_class = + "border-t border-border/60 transition-colors hover:bg-neutral-100/60 \ + even:bg-neutral-50/50 dark:hover:bg-neutral-800/50 \ + dark:even:bg-neutral-900/30" + +let name_cell = "font-medium text-neutral-900 dark:text-neutral-100" + +let make () = + + + + + + "Name" + + "Role" + "Status" + + + + "Kate Moore" + "CEO" + "Active" + + + "John Smith" + "CTO" + "Active" + + + "Sara Johnson" + "CMO" + "On leave" + + + + +
    +``` + +## Styling Reference + +HeroUI follows the [BEM](https://bem.info/en/methodology/) methodology to +ensure component variants and states are reusable and easy to customize. + +### CSS Classes + +#### Base Classes + +- `.table-root` - Root container (named `table-root` instead of `table` + because `table` is a built-in Tailwind CSS utility class for + `display: table`) +- `.table__scroll-container` - Horizontal scroll wrapper with custom scrollbar +- `.table__content` - The `` element +- `.table__header` - Header row (``) +- `.table__column` - Column header cell (``) +- `.table__row` - Row element (``) +- `.table__cell` - Data cell (`
    `) +- `.table__body` - Body section (`
    `) +- `.table__footer` - Footer container (outside table) + +#### Advanced Classes + +- `.table__column-resizer` - Drag handle for column resizing +- `.table__resizable-container` - Wrapper enabling column resizing +- `.table__load-more` - Sentinel row for infinite scrolling +- `.table__load-more-content` - Styled container for the loading indicator +- `.table__sortable-column-header` - A sortable column's label +- `.table__sortable-column-indicator` - Its sort indicator + +#### Variant Classes + +- `.table-root--primary` - Gray background container with card-style body + (default) +- `.table-root--secondary` - No background, standalone rounded headers + +### Interactive States + +The Table supports both CSS pseudo-classes and data attributes for +flexibility: + +- **Hover**: `:hover` or `[data-hovered="true"]` (row background change), on + rows, columns and column resizers +- **Selected**: `[data-selected="true"]` (row highlight) +- **Focus**: `:focus-visible` or `[data-focus-visible="true"]` (inset focus + ring on rows, columns, cells and column resizers) +- **Disabled**: `[aria-disabled="true"]` (reduced opacity) +- **Sortable**: `[data-allows-sorting="true"]` (interactive cursor on columns) +- **Sort direction**: `[data-direction]` on a sortable header and its + indicator +- **Resizing**: `[data-resizing="true"]` and `[data-resizable-direction]` on a + column resizer +- **Dragging**: `[data-dragging="true"]` on a row dragged (reduced opacity) +- **Drop position**: `[data-drop-position="before"]` or `"after"` on the row + a drop would land beside (a line in the accent on that side) +- **Tree**: `[data-level]`, `[data-expanded="true"]`, + `[data-has-child-items="true"]` on a row and its cells, + `[data-tree-column="true"]` on a cell, and the row's `--table-row-level` + +## API Reference + +Each prop beside the name HeroUI's React component gives it. + +### Table + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `variant` | `variant` | `` [ `primary \| `secondary ] `` | `` `primary `` | Visual variant. Primary has a gray background container; secondary is flat with transparent rows | +| `className` | `class_` | `string` | | Added after HeroUI's classes | + +### Table.ScrollContainer, Table.Footer + +Each takes `class_`, added after HeroUI's class, and its `children`. + +### Table.Content + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `aria-label` | `aria_label` | `string` | | Accessible label for the table | +| `aria-labelledby` | `aria_labelledby` | `string` | | What names it | +| `selectionMode` | `selection_mode` | `` [ `none \| `single \| `multiple ] `` | `` `none `` | Selection behavior: how many rows may be selected | +| `selectionBehavior` | `selection_behavior` | `` [ `toggle \| `replace ] `` | `` `toggle `` | Whether a press toggles a row or chooses it alone | +| `selectedKeys` | `selected_keys` | `string array` | | Controlled selected keys | +| `defaultSelectedKeys` | `default_selected_keys` | `string array` | | Its rows' keys selected at first, kept by itself | +| `onSelectionChange` | `on_selection_change` | `string array -> unit` | | Selection change handler; all is every row's key but a disabled one | +| `disabledKeys` | `disabled_keys` | `string array` | | Its rows' keys disabled | +| `disallowEmptySelection` | `disallow_empty_selection` | `bool` | `false` | Whether one row stays selected | +| `sortDescriptor` | `sort_descriptor` | `Table.sort_descriptor` | | Current sort state | +| `onSortChange` | `on_sort_change` | `Table.sort_descriptor -> unit` | | Sort change handler | +| `treeColumn` | `tree_column` | `string` | | The `id` of the column whose cells hold a tree's chevrons | +| `expandedKeys` | `expanded_keys` | `string array` | | Its rows' keys expanded, controlled | +| `defaultExpandedKeys` | `default_expanded_keys` | `string array` | | Its rows' keys expanded at first, kept by itself | +| `onExpandedChange` | `on_expanded_change` | `string array -> unit` | | Called with the keys expanded | +| `onRowAction` | `on_row_action` | `string -> unit` | | Called with a row's key as its action runs, after the row's own | +| `dragAndDropHooks` | `on_reorder` | `Table.reorder -> unit` | | Its rows dragged by a `` slot=`drag `` button, and told where they were dropped | +| — | `reorder_messages` | `Table.reorder_messages` | React Aria's | What a drag tells a reader | +| `className` | `class_` | `string` | | Added after HeroUI's class | + +### Table.Header + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `columns` | — | | | Its columns given by data are a `For` | +| `className` | `class_` | `string` | | Added after HeroUI's class | + +### Table.Column + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `id` | `id` | `string` | one of its own | Column identifier, which a sort names | +| `allowsSorting` | `allows_sorting` | `bool` | `false` | Whether the column is sortable | +| `isRowHeader` | `is_row_header` | `bool` | `false` | Whether this column is a row header | +| `width` | `width` | `Table.column_size` | | Its width, controlled, in a resizable table | +| `defaultWidth` | `default_width` | `Table.column_size` | `Fraction 1.` | Default width for resizable columns | +| `minWidth` | `min_width` | `float` | `75.` | Minimum width for resizable columns, in pixels | +| `maxWidth` | `max_width` | `float` | | How wide it may be, in pixels | +| `children` | `children` | | | Its label; HeroUI's render function of its sort direction is `Table.Sortable_column_header`'s reading of it | +| `className` | `class_` | `string` | | Added after HeroUI's class | + +### Table.SortableColumnHeader + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `sortDirection` | `sort_direction` | `` [ `ascending \| `descending ] `` | its column's | Current sort direction | +| `showIndicator` | `show_indicator` | `bool` | `true` | Whether to render the sort indicator icon when a direction is set | +| `indicator` | `indicator` | `Jsx.element` | HeroUI's chevron | Custom indicator element. Overrides the default chevron, in a span that receives a `data-direction` attribute | +| `className` | `class_` | `string` | | Added after HeroUI's class | + +### Table.Body + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `items` | — | | | Its rows given by data are a `For` | +| `renderEmptyState` | `render_empty_state` | `unit -> Jsx.element` | | Content to display when the table is empty | +| `className` | `class_` | `string` | | Added after HeroUI's class | + +### Table.Row + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `id` | `id` | `string` | one of its own | Row identifier | +| `onAction` | `on_action` | `unit -> unit` | | Run by Enter, and by a press as the selection lets it | +| `href` | `href` | `string` | | Opened as its action, as a link is | +| `target`, `rel`, `download`, `hrefLang`, `ping`, `referrerPolicy` | `target`, `rel`, `download`, `href_lang`, `ping`, `referrer_policy` | `string` | | Its link's | +| `routerOptions` | — | | | A link opens as the browser opens one | +| `className` | `class_` | `string` | | Added after HeroUI's class | + +### Table.Cell + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `className` | `class_` | `string` | | Added after HeroUI's class | + +### Table.ResizableContainer + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `onResizeStart` | `on_resize_start` | `(string * Table.column_size) array -> unit` | | Called as a resize begins, with every column's size | +| `onResize` | `on_resize` | `(string * Table.column_size) array -> unit` | | Called at each step of a resize | +| `onResizeEnd` | `on_resize_end` | `(string * Table.column_size) array -> unit` | | Called as a resize ends | +| `className` | `class_` | `string` | | Added after HeroUI's class | + +### Table.ColumnResizer + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `aria-label` | `aria_label` | `string` | `"Resizer"` | Its input's name, beside its column's | +| `className` | `class_` | `string` | | Added after HeroUI's class | + +### Table.LoadMore + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `isLoading` | `is_loading` | `bool` | `false` | Whether data is currently loading, its row drawn while it is | +| `onLoadMore` | `on_load_more` | `unit -> unit` | | Handler called when the sentinel row is visible, never while loading | +| `scrollOffset` | `scroll_offset` | `float` | `1.` | How many heights of the view before the end it asks | +| `className` | `class_` | `string` | | Added after HeroUI's class, on the loading row | + +### TableLayout + +`Virtualizer.table_layout`, each option in pixels. + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `rowHeight` | `row_size` | `float` | `48.` | The fixed height of a row in px | +| `headingHeight` | `heading_size` | `float` | its row's | The fixed height of the header in px | +| `loaderHeight` | `loader_size` | `float` | its row's | The fixed height of a loader element in px | +| `gap` | `gap` | `float` | `0.` | The gap between items | +| `padding` | `padding` | `float` | `0.` | The padding around the list | +| `estimatedRowHeight`, `estimatedHeadingHeight` | — | | | A virtualized table's rows are as high as `row_size` | + +### Table.LoadMoreContent + +It takes `class_`, added after HeroUI's class, and its `children`. diff --git a/agents/pages/heroui/tabs.md b/agents/pages/heroui/tabs.md new file mode 100644 index 00000000..a470029a --- /dev/null +++ b/agents/pages/heroui/tabs.md @@ -0,0 +1,585 @@ +# Tabs + +Tabs organize content into multiple sections and allow users to navigate between them. + +A panel is shown while the tab of the same `id` is selected; each requires +its `id`. The arrows of its orientation move between the tabs, round from the +last to the first, and Home and End to either end, skipping a disabled tab; +focus selects the tab it reaches, or Enter and Space do with +`` keyboard_activation=`manual ``. + +Original HeroUI documentation: [Tabs](https://heroui.com/en/docs/react/components/tabs). + +## Usage + +HeroUI's examples. + +```ocaml title="tabs_usage.mlx" +module Tabs = Solidtype_heroui.Tabs + +let make () = + + + + "Overview" + "Analytics" + "Reports" + + + +

    "View your project overview and recent activity."

    +
    + +

    "Track your metrics and analyze performance data."

    +
    + +

    "Generate and download detailed reports."

    +
    +
    +``` + +## Parity + +The same HeroUI Tabs twice, under the same props: in solidtype on the left, in +React on the right. Below them, every attribute of the two roots: a marked +row is one they disagree on, and a dimmed row is a framework's own, which no +style reads. + +A tab is Kobalte's button where React Aria's is a div, each of role `tab`. +A panel names no orientation, as React Aria's names none, so the spacing +HeroUI's styles would give it by its orientation reaches neither, and a panel +sits as close to its list as on heroui.com. React Aria marks its root focused while a tab is, +which no style reads and the port does not. + +## Anatomy + +```ocaml + + + + + + + + + + + +``` + +`Tabs.Separator` is optional. + +## Examples + +### Vertical + +```ocaml title="tabs_vertical.mlx" +module Tabs = Solidtype_heroui.Tabs + +let make () = + + + + "Account" + "Security" + + "Notifications" + + "Billing" + + + +

    "Account Settings"

    +

    + "Manage your account information and preferences." +

    +
    + +

    "Security Settings"

    +

    + "Configure two-factor authentication and password settings." +

    +
    + +

    "Notification Preferences"

    +

    + "Choose how and when you want to receive notifications." +

    +
    + +

    "Billing Information"

    +

    + "View and manage your subscription and payment methods." +

    +
    +
    +``` + +### Overflow + +When the tab list exceeds the available space, `Tabs.List_container` +automatically renders scroll chevrons and fading edges so users can navigate +the hidden tabs. This works the same way for both horizontal and vertical +orientations. + +```ocaml title="tabs_overflow.mlx" +module Tabs = Solidtype_heroui.Tabs + +let items = + [| + ("overview", "Overview"); + ("analytics", "Analytics"); + ("reports", "Reports"); + ("performance", "Performance"); + ("engagement", "Engagement"); + ("audience", "Audience"); + ("acquisition", "Acquisition"); + ("retention", "Retention"); + ("settings", "Settings"); + |] + +let make () = +
    + + + + + (fun (id, label) _ -> + + (Solidtype.Jsx.string label) + ) + + + + + (fun (id, label) _ -> + +

    (Solidtype.Jsx.string (label ^ " panel content."))

    +
    ) +
    +
    +
    +``` + +### Disabled Tab + +A tab is disabled while it or the tabs are; the arrows pass over it. + +```ocaml title="tabs_disabled.mlx" +module Tabs = Solidtype_heroui.Tabs + +let make () = + + + + "Active" + + "Disabled" + + "Available" + + + +

    "This tab is active and can be selected."

    +
    + +

    "This content cannot be accessed."

    +
    + +

    "This tab is also available for selection."

    +
    +
    +``` + +### With Separator + +Add `` inside each `` (except the first) to +display separator lines between tabs, hidden beside the selected one. + +```ocaml title="tabs_separator.mlx" +module Tabs = Solidtype_heroui.Tabs + +let make () = + + + + "Overview" + + "Analytics" + + + "Reports" + + + + +

    "View your project overview and recent activity."

    +
    + +

    "Track your metrics and analyze performance data."

    +
    + +

    "Generate and download detailed reports."

    +
    +
    +``` + +### Secondary Variant + +```ocaml title="tabs_secondary.mlx" +module Tabs = Solidtype_heroui.Tabs + +let make () = + + + + "Overview" + "Analytics" + "Reports" + + + +

    "View your project overview and recent activity."

    +
    + +

    "Track your metrics and analyze performance data."

    +
    + +

    "Generate and download detailed reports."

    +
    +
    +``` + +### Secondary Variant Vertical + +```ocaml title="tabs_secondary_vertical.mlx" +module Tabs = Solidtype_heroui.Tabs + +let make () = + + + + "Account" + "Security" + + "Notifications" + + "Billing" + + + +

    "Account Settings"

    +

    + "Manage your account information and preferences." +

    +
    + +

    "Security Settings"

    +

    + "Configure two-factor authentication and password settings." +

    +
    + +

    "Notification Preferences"

    +

    + "Choose how and when you want to receive notifications." +

    +
    + +

    "Billing Information"

    +

    + "View and manage your subscription and payment methods." +

    +
    +
    +``` + +### Alignment + +Tab content is centered by default. Use `align` to align it to the +`` `start `` or `` `end_ `` instead, which is especially useful for vertical, +sidebar-style navigation. Individual tabs can still be overridden with +`class_` on `Tabs.Tab`. + +```ocaml title="tabs_alignment.mlx" +module Tabs = Solidtype_heroui.Tabs + +let make () = + + + + "General" + + "Subscription & Billing" + + "Appearance" + + "Notifications" + + "Privacy" + + + +

    "General"

    +

    + "Manage your account information and preferences." +

    +
    + +

    "Subscription & Billing"

    +

    + "View and manage your plan and payment methods." +

    +
    + +

    "Appearance"

    +

    + "Choose a theme and adjust the interface density." +

    +
    + +

    "Notifications"

    +

    + "Choose how and when you want to receive notifications." +

    +
    + +

    "Privacy"

    +

    + "Control what you share and who can see your activity." +

    +
    +
    +``` + +### Links + +A tab given an `href` is a link: a press or Enter follows it, and never +selects it, so the tab selected is the one `selected_key` names, the route an +application's router says is open. The arrows still move focus along the +tabs. A disabled tab is never followed. Here each tab links to a hash, which +the example's selection follows. + +```ocaml title="tabs_links.mlx" +module S = Solidtype.Solid +module Tabs = Solidtype_heroui.Tabs + +external hash : string = "hash" [@@mel.scope "window", "location"] + +external add_listener : string -> (Dom.event -> unit) -> unit + = "addEventListener" +[@@mel.scope "window"] + +external remove_listener : string -> (Dom.event -> unit) -> unit + = "removeEventListener" +[@@mel.scope "window"] + +let pages = [ "getting-started"; "components"; "releases" ] + +(* The page a link went to, as a router would say which route is open: here, + the location's hash, read once the page has a location. *) +let page () = List.find_opt (fun page -> String.equal hash ("#" ^ page)) pages + +let make () = + let current, set_current = S.create_signal "getting-started" in + let follow () = Option.iter (S.set set_current) (page ()) in + let on_hash_change (_ : Dom.event) = follow () in + S.on_mount (fun () -> + follow (); + add_listener "hashchange" on_hash_change; + S.on_cleanup (fun () -> remove_listener "hashchange" on_hash_change)); + + + + + "Getting Started" + + + "Components" + + + "Releases" + + + + +

    "Install the library and render a first component."

    +
    + +

    "Every component, with its examples and props."

    +
    + +

    "What changed in each version."

    +
    +
    +``` + +No key or press that reaches a link tab selects it or calls +`on_selection_change`. + +## Customization + +### Tailwind CSS + +`class_` is added after HeroUI's classes, on every part. + +```ocaml title="tabs_tailwind.mlx" +module Tabs = Solidtype_heroui.Tabs + +let list_class = + String.concat " " + [ + "rounded-xl border border-accent/10 bg-accent-soft/30 p-1"; + "**:data-[slot=tabs-tab]:rounded-lg"; + "**:data-[slot=tabs-tab]:bg-transparent"; + "**:data-[slot=tabs-tab]:text-muted"; + "**:data-[slot=tabs-tab]:opacity-100"; + "**:data-[slot=tabs-tab]:transition-colors"; + "**:data-[slot=tabs-tab]:data-[hovered=true]:not-data-[selected=true]:bg-accent-soft"; + "**:data-[slot=tabs-tab]:data-[hovered=true]:not-data-[selected=true]:text-accent-soft-foreground"; + "**:data-[slot=tabs-tab]:data-[pressed=true]:not-data-[selected=true]:bg-accent-soft-hover"; + "**:data-[slot=tabs-tab]:data-[focus-visible=true]:ring-2"; + "**:data-[slot=tabs-tab]:data-[focus-visible=true]:ring-accent/15"; + "**:data-[slot=tabs-tab]:data-[selected=true]:font-medium"; + "**:data-[slot=tabs-tab]:data-[selected=true]:text-accent-foreground"; + "**:data-[slot=tabs-tab]:shadow-none"; + "**:data-[slot=tabs-indicator]:rounded-lg"; + "**:data-[slot=tabs-indicator]:bg-accent"; + "**:data-[slot=tabs-indicator]:shadow-none"; + ] + +let make () = + + + + "Monthly" + "Yearly" + + + + "Billed monthly, cancel anytime." + + + "Save 20% with annual billing." + + +``` + +### Global CSS + +HeroUI's classes are global, so a stylesheet restyles every tabs, as with +HeroUI in React: + +```css +@layer components { + .tabs__list { + @apply rounded-xl border border-border bg-surface p-1; + } + + .tabs__indicator { + @apply rounded-lg bg-foreground shadow-sm; + } +} +``` + +## Styling Reference + +HeroUI follows the [BEM](https://bem.info/en/methodology/) methodology to +ensure component variants and states are reusable and easy to customize. + +### CSS Classes + +#### Base Classes + +- `.tabs` - Base tabs container +- `.tabs__list-container` - Tab list container wrapper +- `.tabs__list-container__scroller` - Scrollable wrapper around the tab list + (handles overflow and fading edges) +- `.tabs__list-container__scroll-prev` - Scroll chevron button for the + previous (left / up) direction +- `.tabs__list-container__scroll-next` - Scroll chevron button for the next + (right / down) direction +- `.tabs__list` - Tab list container +- `.tabs__tab` - Individual tab button +- `.tabs__separator` - Separator between tabs +- `.tabs__panel` - Tab panel content +- `.tabs__indicator` - Tab indicator + +#### Orientation Attributes + +- `.tabs[data-orientation="horizontal"]` - Horizontal tab layout (default) +- `.tabs[data-orientation="vertical"]` - Vertical tab layout + +The list and the panel carry `[data-orientation]` too. + +#### Variant Classes + +- `.tabs--secondary` - Secondary variant with underline indicator + +#### Alignment Classes + +- `.tabs--align-start` - Aligns tab content to the start +- `.tabs--align-end` - Aligns tab content to the end + +### Interactive States + +The component supports both CSS pseudo-classes and data attributes, on the +tab: + +- **Selected**: `[aria-selected="true"]` or `[data-selected="true"]` +- **Hover**: `:hover` or `[data-hovered="true"]` +- **Focus**: `:focus-visible` or `[data-focus-visible="true"]` +- **Disabled**: `[aria-disabled="true"]` or `[data-disabled="true"]` + +## API Reference + +Each prop beside the name HeroUI's React component gives it. + +### Tabs + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `selectedKey` | `selected_key` | `string` | | Controlled selected tab key | +| `defaultSelectedKey` | `default_selected_key` | `string` | the first not disabled | Default selected tab key | +| `onSelectionChange` | `on_selection_change` | `string -> unit` | | Selection change handler | +| `orientation` | `orientation` | `` [ `horizontal \| `vertical ] `` | `` `horizontal `` | Tab layout orientation | +| `variant` | `variant` | `` [ `primary \| `secondary ] `` | `` `primary `` | Visual style variant. Primary uses a filled indicator, secondary uses an underline indicator | +| `align` | `align` | `` [ `start \| `center \| `end_ ] `` | `` `center `` | Alignment of the content inside each tab | +| `keyboardActivation` | `keyboard_activation` | `` [ `automatic \| `manual ] `` | `` `automatic `` | Whether focus selects, or Enter and Space do | +| `isDisabled` | `is_disabled` | `bool` | `false` | Whether every tab is disabled | +| `className` | `class_` | `string` | | Added after HeroUI's classes | +| `render` | `as_` | a function of its props and state | | Draws another element in its place | + +### Tabs.List + +| React | solidtype | Type | Description | +|---|---|---|---| +| `aria-label` | `aria_label` | `string` | Accessibility label for tab list | +| `className` | `class_` | `string` | Added after HeroUI's classes | + +### Tabs.Tab + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `id` | `id` | `string` | | Unique tab identifier, its panel's too; required | +| `isDisabled` | `is_disabled` | `bool` | `false` | Whether tab is disabled | +| `className` | `class_` | `string` | | Added after HeroUI's classes | +| `href` | `href` | `string` | | Where it links: it is an ``, followed and never selected by a press or a key | +| `render` | `as_` | a function of its props and state | | Draws another element in its place | + +### Tabs.Panel + +| React | solidtype | Type | Description | +|---|---|---|---| +| `id` | `id` | `string` | Panel identifier matching tab id; required | +| `className` | `class_` | `string` | Added after HeroUI's classes | + +### Tabs.List_container, Tabs.Indicator, Tabs.Separator + +| React | solidtype | Type | Description | +|---|---|---|---| +| `className` | `class_` | `string` | Added after HeroUI's classes | diff --git a/agents/pages/heroui/tag-group.md b/agents/pages/heroui/tag-group.md new file mode 100644 index 00000000..d7538c98 --- /dev/null +++ b/agents/pages/heroui/tag-group.md @@ -0,0 +1,635 @@ +# TagGroup + +A focusable list of tags with support for keyboard navigation, selection, and removal. + +A tag's key is its `id`. Keys are `string`s, and a selection is a +`string array`. + +Original HeroUI documentation: [TagGroup](https://heroui.com/en/docs/react/components/tag-group). + +## Usage + +```ocaml title="tag_group_usage.mlx" +module Tag = Solidtype_heroui.Tag +module Tag_group = Solidtype_heroui.Tag_group +module Gravity = Solidtype_gravity_icons + +let make () = + + + "News" + "Travel" + "Gaming" + "Shopping" + + +``` + +## Parity + +The same HeroUI TagGroup twice, under the same props: in solidtype on the +left, in React on the right. Below them, every attribute of the two groups: a +marked row is one they disagree on. + +## Anatomy + +```ocaml + + +``` + +## Examples + +### Sizes + +```ocaml title="tag_group_sizes.mlx" +module Label = Solidtype_heroui.Label +module Tag = Solidtype_heroui.Tag +module Tag_group = Solidtype_heroui.Tag_group + +let make () = +
    + + + + "News" "Travel" "Gaming" + + + + + + "News" "Travel" "Gaming" + + + + + + "News" "Travel" "Gaming" + + +
    +``` + +### Variants + +```ocaml title="tag_group_variants.mlx" +module Label = Solidtype_heroui.Label +module Tag = Solidtype_heroui.Tag +module Tag_group = Solidtype_heroui.Tag_group + +let make () = +
    + + + + "News" "Travel" "Gaming" + + + + + + "News" "Travel" "Gaming" + + +
    +``` + +### Disabled + +A tag is disabled by its own `is_disabled`, or by the group's `disabled_keys`. +The group's `is_disabled` disables every tag. + +```ocaml title="tag_group_disabled.mlx" +module Description = Solidtype_heroui.Description +module Label = Solidtype_heroui.Label +module Tag = Solidtype_heroui.Tag +module Tag_group = Solidtype_heroui.Tag_group + +let make () = +
    + + + + "News" + "Travel" + "Gaming" + + "Some tags are disabled" + + + + + "News" + "Travel" + "Gaming" + + "Tags disabled via disabled_keys prop" + +
    +``` + +### Selection Modes + +```ocaml title="tag_group_selection_modes.mlx" +module S = Solidtype.Solid +module Description = Solidtype_heroui.Description +module Label = Solidtype_heroui.Label +module Tag = Solidtype_heroui.Tag +module Tag_group = Solidtype_heroui.Tag_group + +let make () = + let single, set_single = S.create_signal [| "news" |] in + let multiple, set_multiple = S.create_signal [| "news"; "travel" |] in +
    + + + + "News" + "Travel" + "Gaming" + "Shopping" + + "Choose one category" + + + + + "News" + "Travel" + "Gaming" + "Shopping" + + "Choose multiple categories" + +
    +``` + +### Controlled + +```ocaml title="tag_group_controlled.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Description = Solidtype_heroui.Description +module Label = Solidtype_heroui.Label +module Tag = Solidtype_heroui.Tag +module Tag_group = Solidtype_heroui.Tag_group + +let make () = + let selected, set_selected = S.create_signal [| "news"; "travel" |] in +
    + + + + "News" + "Travel" + "Gaming" + "Shopping" + + + "Selected: " + (Jsx.string + (match S.get selected with + | [||] -> "None" + | keys -> String.concat ", " (Array.to_list keys))) + + +
    +``` + +### With Error Message + +```ocaml title="tag_group_with_error_message.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module Description = Solidtype_heroui.Description +module Error_message = Solidtype_heroui.Error_message +module Label = Solidtype_heroui.Label +module Tag = Solidtype_heroui.Tag +module Tag_group = Solidtype_heroui.Tag_group + +let make () = + let selected, set_selected = S.create_signal [||] in + let invalid () = Array.length (S.get selected) = 0 in + + + + "Laundry" + "Fitness center" + "Parking" + "Swimming pool" + "Breakfast" + + + (Jsx.string + (if invalid () then "Select at least one category" + else + "Selected: " ^ String.concat ", " (Array.to_list (S.get selected)))) + + + (Jsx.string + (if invalid () then "Please select at least one category" else "")) + + +``` + +### With List Data + +Tags drawn from a signal by `For`, removed from it by `on_remove`. + +```ocaml title="tag_group_with_list_data.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Show = Solidtype.Show +module Avatar = Solidtype_heroui.Avatar +module Description = Solidtype_heroui.Description +module Empty_state = Solidtype_heroui.Empty_state +module Label = Solidtype_heroui.Label +module Tag = Solidtype_heroui.Tag +module Tag_group = Solidtype_heroui.Tag_group + +type user = { id : string; name : string; avatar : string; fallback : string } + +let avatar color = + "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/" ^ color + ^ ".jpg" + +let users = + [| + { id = "fred"; name = "Fred"; avatar = avatar "blue"; fallback = "F" }; + { + id = "michael"; + name = "Michael"; + avatar = avatar "green"; + fallback = "M"; + }; + { id = "jane"; name = "Jane"; avatar = avatar "purple"; fallback = "J" }; + { id = "alice"; name = "Alice"; avatar = avatar "red"; fallback = "A" }; + { id = "bob"; name = "Bob"; avatar = avatar "orange"; fallback = "B" }; + { + id = "charlie"; + name = "Charlie"; + avatar = avatar "black"; + fallback = "C"; + }; + |] + +let make () = + let items, set_items = S.create_signal users in + let selected, set_selected = S.create_signal [| "fred"; "michael" |] in + let kept keys k = not (Array.exists (String.equal k) keys) in + let remove keys = + S.update set_items (Js.Array.filter ~f:(fun u -> kept keys u.id)); + S.update set_selected (Js.Array.filter ~f:(kept keys)) + in + let chosen () = + Js.Array.filter + ~f:(fun u -> Array.exists (String.equal u.id) (S.get selected)) + (S.get items) + in +
    + + + + + "No team members" + )> + + (fun user _ -> + + + + (Jsx.string user.fallback) + + (Jsx.string user.name) + ) + + + "Select team members for your project" + + 0)> +
    +

    "Selected:"

    +
    + + (fun user _ -> +
    + + + (Jsx.string user.fallback) + + (Jsx.string user.name) +
    ) +
    +
    +
    +
    +
    +``` + +### With Prefix + +```ocaml title="tag_group_with_prefix.mlx" +module Avatar = Solidtype_heroui.Avatar +module Description = Solidtype_heroui.Description +module Label = Solidtype_heroui.Label +module Tag = Solidtype_heroui.Tag +module Tag_group = Solidtype_heroui.Tag_group +module Gravity = Solidtype_gravity_icons + +let make () = +
    + + + + "News" + "Travel" + "Gaming" + "Shopping" + + "Tags with icons" + + + + + + + + "F" + + "Fred" + + + + + "M" + + "Michael" + + + + + "J" + + "Jane" + + + "Tags with avatars" + +
    +``` + +### With Remove Button + +Given `on_remove`, each tag draws a remove button. A `Tag.Remove_button` +among a tag's children takes its place; a tag whose children are a function +draws its own, where `allows_removing` holds. + +```ocaml title="tag_group_with_remove_button.mlx" +module S = Solidtype.Solid +module Jsx = Solidtype.Jsx +module For = Solidtype.For +module Description = Solidtype_heroui.Description +module Empty_state = Solidtype_heroui.Empty_state +module Label = Solidtype_heroui.Label +module Tag = Solidtype_heroui.Tag +module Tag_group = Solidtype_heroui.Tag_group +module Gravity = Solidtype_gravity_icons + +let without keys = + Js.Array.filter ~f:(fun (id, _) -> not (Array.exists (String.equal id) keys)) + +let make () = + let tags, set_tags = + S.create_signal + [| + ("news", "News"); + ("travel", "Travel"); + ("gaming", "Gaming"); + ("shopping", "Shopping"); + |] + in + let frameworks, set_frameworks = + S.create_signal + [| + ("react", "React"); + ("vue", "Vue"); + ("angular", "Angular"); + ("svelte", "Svelte"); + |] + in +
    +
    + S.update set_tags (without keys))> + + + + "No categories found" + )> + + (fun (id, name) _ -> + (Jsx.string name)) + + + "Click the X to remove tags" + +
    +
    + S.update set_frameworks (without keys))> + + + + "No frameworks found" + )> + + (fun (id, name) _ -> + + (fun (s : Tag.state) -> + Jsx.fragment + [| + Jsx.string name; + (if S.get s.allows_removing then + + + + else Jsx.nothing); + |]) + ) + + + "Custom remove button with icon" + +
    +
    +``` + +### Render Function + +`as_` draws another element in its place, given its props and its state, as [Composition](composition.md#custom-dom-element) shows. + +## Customization + +### Tailwind CSS + +`class_` is added after HeroUI's classes, on each part. + +```ocaml title="tag_group_custom_styles.mlx" +module Tag = Solidtype_heroui.Tag +module Tag_group = Solidtype_heroui.Tag_group +module Gravity = Solidtype_gravity_icons + +let tag_class = + "group/tag gap-1.5 rounded-full border border-neutral-300/80 bg-white/80 \ + px-2.5 py-1 text-sm font-medium text-neutral-700 shadow-sm ring-1 \ + ring-black/5 backdrop-blur-sm transition-colors \ + data-[selected=true]:border-neutral-500 data-[selected=true]:bg-neutral-900 \ + data-[selected=true]:text-neutral-50 dark:border-neutral-600/80 \ + dark:bg-neutral-900/60 dark:text-neutral-200 dark:ring-white/10 \ + dark:data-[selected=true]:border-neutral-400 \ + dark:data-[selected=true]:bg-neutral-100 \ + dark:data-[selected=true]:text-neutral-900" + +let icon_class = + "size-4 shrink-0 text-neutral-500 \ + group-data-[selected=true]/tag:text-current dark:text-neutral-400" + +let make () = + + + + "News" + + + "Travel" + + + "Gaming" + + + "Shopping" + + + +``` + +## Styling Reference + +### CSS Classes + +- `.tag-group` - Base tag group container +- `.tag-group__list` - Container for the list of tags +- `.tag` - Base tag styles +- `.tag__remove-button` - Remove button trigger +- `.tag--sm`, `.tag--md`, `.tag--lg` - Sizes +- `.tag--default`, `.tag--surface` - Variants + +### Interactive States + +Each tag: + +- **Selected**: `[data-selected="true"]` +- **Disabled**: `[data-disabled="true"]` +- **Hovered**: `[data-hovered="true"]`, while it can be chosen +- **Pressed**: `[data-pressed="true"]`, while it can be chosen +- **Focus**: `[data-focus-visible="true"]`, and `[data-focused="true"]` + +The list declares `[data-empty="true"]` while it holds no tag. + +## API Reference + +Each prop beside the name HeroUI's React component gives it. + +### TagGroup + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `selectionMode` | `selection_mode` | `` [ `none \| `single \| `multiple ] `` | `` `none `` | The type of selection that is allowed | +| `selectedKeys` | `selected_keys` | `string array` | | The currently selected keys (controlled) | +| `defaultSelectedKeys` | `default_selected_keys` | `string array` | | The initial selected keys (uncontrolled) | +| `onSelectionChange` | `on_selection_change` | `string array -> unit` | | Handler called when the selection changes | +| `disabledKeys` | `disabled_keys` | `string array` | | Keys of disabled tags | +| `isDisabled` | `is_disabled` | `bool` | | Whether every tag is disabled | +| `onRemove` | `on_remove` | `string array -> unit` | | Handler called with the keys of tags removed | +| `size` | `size` | `` [ `sm \| `md \| `lg ] `` | `` `md `` | Size of the tags | +| `variant` | `variant` | `` [ `default \| `surface ] `` | `` `default `` | Look of the tags | +| `aria-label` | `aria_label` | `string` | | Its name, where it has no `Label` | +| `className` | `class_` | `string` | | Added after HeroUI's classes | +| `render` | `as_` | a function of its props | | Draws another element in its place | + +### TagGroup.List + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `renderEmptyState` | `render_empty_state` | `unit -> Jsx.element` | | What it shows while it holds no tag | +| `className` | `class_` | `string` | | Added after HeroUI's class | +| `render` | `as_` | a function of its props | | Draws another element in its place | + +### Tag + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `id` | `id` | `string` | unique | The tag's key | +| `textValue` | `text_value` | `string` | its first text | What a reader is told it is | +| `isDisabled` | `is_disabled` | `bool` | | Whether the tag is disabled | +| `className` | `class_` | `string` | | Added after HeroUI's classes | +| `children` | `children` | elements, or a function of `Tag.state` | required | Its content | +| `render` | `as_` | a function of its props and state | | Draws another element in its place | + +`Tag.state` holds `is_selected`, `is_disabled`, `is_hovered`, `is_pressed`, +`is_focused`, `is_focus_visible` and `allows_removing`. + +### Tag.RemoveButton + +| React | solidtype | Type | Default | Description | +|---|---|---|---|---| +| `className` | `class_` | `string` | | Added after HeroUI's classes | +| `children` | `children` | nodes | a cross | What it shows | + +## Accessibility + +- Tab reaches the tag last focused, or the first chosen, or the first, then + its remove button. +- The arrows move from tag to tag, a disabled one passed over, wrapping at + either end; Home and End reach the first and the last, and typing the start + of a tag's name reaches it. +- A press, Space or Enter chooses a tag, and Escape clears what is chosen. +- Delete and Backspace remove the focused tag, or every chosen tag where it is + chosen; the focus moves to the next tag, or to the list once none is left. +- A removable tag tells a reader how to remove it. diff --git a/agents/pages/heroui/text-area.md b/agents/pages/heroui/text-area.md new file mode 100644 index 00000000..f6277e0d --- /dev/null +++ b/agents/pages/heroui/text-area.md @@ -0,0 +1,87 @@ +# TextArea + +Primitive multiline text input component that accepts standard HTML attributes. + +Original HeroUI documentation: [TextArea](https://heroui.com/en/docs/react/components/text-area). + +## Usage + +```ocaml title="text_area_usage.mlx" +module Text_area = Solidtype_heroui.Text_area + +let make () = + +``` + +For validation, labels, and error messages, see +[TextField](text-field.md). + +## Examples + +### Variants + +The TextArea component supports two visual variants: + +- **`` `primary ``** (default) - Standard styling with shadow, suitable for + most use cases +- **`` `secondary ``** - Lower emphasis variant without shadow, suitable for + use in Surface components + +```ocaml title="text_area_variants.mlx" +module Text_area = Solidtype_heroui.Text_area + +let make () = +
    + + +
    +``` + +### Rows and Resizing + +```ocaml title="text_area_rows.mlx" +module Text_area = Solidtype_heroui.Text_area + +let make () = +
    + + +
    +``` + +## Styling Reference + +HeroUI follows the [BEM](https://bem.info/en/methodology/) methodology to +ensure component variants and states are reusable and easy to customize. + +### CSS Classes + +- `.textarea` - Underlying `