lostcoords-ui 0.11.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2054816b6a7ff56d849935ab460b5b507d18e75f0bad9153ff12aa3325c6e336
4
- data.tar.gz: 306f6d0f412c0bb972290c9436f5020e8a1c29cb90ff757384ca596a6590124c
3
+ metadata.gz: d40b25262f26a57dea7b82cada5df30d683de3fb28f2c9db0046130cfb26a26f
4
+ data.tar.gz: 3c3b01b38a8d674bd8a59f068b6b5e7db92563cecd5d56bdeb43b08257373526
5
5
  SHA512:
6
- metadata.gz: ca0712c7a3f9cef74431634ffa1c1da04b6b0cc9299ab28dec6d446df45642161bf17dc8d5154101aff8a24865a992ad36ef02927c2541f8d4337d8af09ae229
7
- data.tar.gz: f74402ec4c561044d13e22d61e7184213b1f930c41a6c953ce5fb2e927acf46f99dbf7f189689ab676d5a9647a2aa646655bf063088124e306bfc0bca5e1a1b2
6
+ metadata.gz: d05b7df8c044fed6d94d2d8ff97caab7d9e589bdb2d218bf3d5a49bba27c5b7dbb7df2b7c4354e55947ef48025803167fc0d542892ce640bb50c0461efc175fb
7
+ data.tar.gz: 9ccbd01d8a5171657cd56e71dd6537628efed50f75fb00445226abc96999559b58fd4ba415664c17ac4820e919908cc74a8dabf2ad8c53efef6b559e6736ef86
data/README.md CHANGED
@@ -21,7 +21,7 @@ lockfile pins its gem version, so publishing a library update does not upgrade c
21
21
  ## Install
22
22
 
23
23
  ```ruby
24
- gem "lostcoords-ui", "~> 0.11.0"
24
+ gem "lostcoords-ui", "~> 0.12.0"
25
25
  ```
26
26
 
27
27
  The engine adds its rendering helpers to host views, its views and translations to the host's lookup
@@ -170,6 +170,42 @@ Omit `only` to register every library controller. Unknown identifiers raise befo
170
170
  registered, and repeated calls on the same application keep later overrides, so register defaults
171
171
  before application overrides.
172
172
 
173
+ ## Changes in 0.12.0
174
+
175
+ One edit, and some components look different:
176
+
177
+ - **`lc_menu_option` takes `form_attributes:` for the form `method:` builds.** Before: `form:` set that
178
+ form's attributes. After: `form:` is the option button's own HTML `form` attribute, so an option can submit a
179
+ form elsewhere on the page (`type: "submit", form: "profile-form"`). Rename `form:` to `form_attributes:`
180
+ wherever an option passes it alongside `method:`.
181
+ - **A small icon button draws an 18px icon**, up from 16px; `icon_size:` picks another.
182
+ - **`lc_button_to` and `lc_icon_button_to` wrap their button in a `contents` form**, so the button sits in a
183
+ flex or grid row as if the form weren't there. A caller's `form: { class: }` still merges over it. A
184
+ margin or alignment class that was on the form belongs on the button now.
185
+ - **`lc_list_group` rounds its first and last visible child**, whatever it is, instead of each row rounding
186
+ itself. Non-row children and hidden rows need no corner classes.
187
+ - **`lc_card(padding: :none)` drops the border and clips its children** to its corners, so rows reach the
188
+ edge without negative margins.
189
+ - **A dialog's body no longer shrinks its children**, so a long body scrolls instead of squashing buttons.
190
+ - **The choice card uses the global focus halo** instead of its own outline.
191
+
192
+ New components and options, moved from apps that built them by hand:
193
+
194
+ - **`lc_avatar_badge`** puts an icon badge on an avatar's corner: a decorative mark, a button or a file label.
195
+ - **`lc_file_drop`** (and `form.file_drop`) is a dashed drop zone around a file input.
196
+ - **`lc_list_row(choice: :radio, name:, value:, checked:)`** is a selectable row with a trailing check.
197
+ - **`lc_toggle_group(layout: :inline | :stacked | :adaptive, scroll:)`** and
198
+ **`lc_toggle_group_item(icon:, icon_only:)`**: icons in segmented controls, stacked over their labels on
199
+ narrow groups, and a scrolling track with faded edges.
200
+ - **`lc_menu(side: :top, trigger_size:)`** opens upward and sizes its trigger; `lc_popover_class` and
201
+ `lc_menu_popover_class` take `side:` too.
202
+ - **`lc_icon_button(icon_size:)`** and the **`:inset` variant**, a page-coloured fill for buttons inside a card.
203
+ - **`lc_avatar_stack(size:, overlap:)`**, **`lc_emoji_picker(popover_size:)`**, **`lc_input(icon:)`**,
204
+ **`lc_sheet(surface: :glass)`** with pinned `sheet.header` and `sheet.footer` parts, and
205
+ **`lc_heading(as:)`**.
206
+ - **`registerDialog` takes `priority:` and `restoreFocus:`**, so a host dialog no longer registers with the
207
+ dismiss stack directly. A click on the dialog's own padding no longer closes it.
208
+
173
209
  ## Changes in 0.11.0
174
210
 
175
211
  Nothing needs an edit. New:
@@ -321,12 +357,13 @@ Everything else in 0.8 is additive. These changes need edits in an app built on
321
357
 
322
358
  ## Components
323
359
 
324
- [Installation and setup](https://ui.lostcoords.com/installation.html) · [Live examples](https://ui.lostcoords.com). Each example renders the same ERB source shown
360
+ [Installation and setup](https://ui.lostcoords.com/installation) · [Live examples](https://ui.lostcoords.com). Each example renders the same ERB source shown
325
361
  in its code panel. The API reference reads signatures from the helper definitions.
326
362
  [API JSON](https://ui.lostcoords.com/api.json) and [llms.txt](https://ui.lostcoords.com/llms.txt)
327
363
  include those signatures and the runnable examples.
328
364
 
329
- Buttons use `primary`, `secondary`, `outline`, `ghost`, `glass` or `destructive`, with `sm`, `md` or `lg` sizes.
365
+ Buttons use `primary`, `secondary`, `outline`, `ghost`, `inset`, `glass` or `destructive`, with `sm`, `md` or `lg` sizes.
366
+ `inset` fills with the page colour and muted ink, for a quiet control on a card.
330
367
  Primary, secondary and destructive buttons have visible filled surfaces. Ghost buttons and the
331
368
  `lc_icon_button` toolbar action are transparent at rest and show their full shape on hover.
332
369
  Primary, secondary and destructive buttons are flat. Secondary buttons use a soft neutral fill distinct from page and card backgrounds.
@@ -337,7 +374,7 @@ Button hover and press fills mix 94% of the base background with 6% of its foreg
337
374
  Ghost and icon buttons stay transparent at rest and use the secondary base for that calculation.
338
375
  Apps can override `--secondary` for the neutral base, or `--lc-button-bg` and `--lc-button-ink` on individual buttons.
339
376
  Inputs use `--input` and `--lc-input-hover`.
340
- `lc_button_to` preserves Rails' form, HTTP method and CSRF behavior. `lc_icon_button_link_to` and `lc_icon_button_to` are the link and form versions of `lc_icon_button`; a block replaces its icon with custom content. Icon buttons take `lc_button`'s `variant:` and `tone:` too; the default `:ghost` is the quiet toolbar look. `block: true` makes any button full width. Block helpers capture ERB content.
377
+ `lc_button_to` preserves Rails' form, HTTP method and CSRF behavior. Its form is `display: contents`, so the button sits directly in the caller's row or grid; `form: { class: }` merges over that. `lc_icon_button_link_to` and `lc_icon_button_to` are the link and form versions of `lc_icon_button`; a block replaces its icon with custom content. Icon buttons take `lc_button`'s `variant:` and `tone:` too; the default `:ghost` is the quiet toolbar look. Their icon is 18, 20 or 24px for `sm`, `md` or `lg`; `icon_size:` picks another of those tiers, as in `size: :sm, icon_size: :md`. `block: true` makes any button full width. Block helpers capture ERB content.
341
378
  Use `icon: "plus"` for a leading Heroicon or `icon_position: :end` for a trailing one. Custom icons and
342
379
  spinners use `data-icon="inline-start"` or `data-icon="inline-end"`; buttons adjust that edge's padding.
343
380
  `lc_button(expanded_icon: "x-mark")` swaps its content for that icon while `aria-expanded` is true, for a trigger
@@ -383,6 +420,7 @@ Wrap wide tables in an app-owned horizontal scroll region with an accessible nam
383
420
  Use `lc_table_class` when an existing table renderer owns the markup.
384
421
 
385
422
  Cards share one API: `lc_card(padding: :md)`, with `:sm` and `:none` for tighter or custom spacing. Padding sizes set `--lc-inset`, so content inside follows the card.
423
+ An unpadded card drops its border and clips its children to its corners, so full-bleed rows meet its edge and a hovered row's fill rounds with it, with no negative margins or corner classes. Menus and dialogs inside it render in the top layer and are not clipped.
386
424
  Fields and secondary buttons inside cards take `--card-input` and `--card-secondary`, which default to the page fills; set them in the theme when `--card` equals `--input` or `--secondary`, or set `--lc-field-bg` to change fields in one context. Cards provide avatar cutouts and a validation border when they contain errors. Fills that are muted on the page switch so they stay visible on the card: choice tiles, alerts, neutral badges and skeletons take the page background (`--lc-tile-bg`), and toggle group and tab tracks take the accent fill (`--lc-track-bg`). Set either variable to apply the same context to your own muted surface.
387
425
  Add `class: "@container"` when a card owns its width and its children use container queries.
388
426
  Use `--lc-card-bg`, `--lc-card-border`, `--lc-card-radius` and `--lc-card-shadow` for local appearance overrides.
@@ -392,8 +430,15 @@ Use `--lc-card-bg`, `--lc-card-border`, `--lc-card-radius` and `--lc-card-shadow
392
430
  `lc_avatar` sizes are `xs` (20px), `sm` (26px), `md` (32px), `lg` (48px), `xl` (96px) and `xxl` (112px).
393
431
  Between them, both take a step on the spacing scale, as in `size-7`: `lc_avatar` takes `7` (28px) and `11` (44px),
394
432
  `lc_icon_badge` takes `6` (24px), `7` (28px) and `11` (44px).
395
- Pass `as: :button` when the avatar is itself the control, such as a colour picker's trigger. `lc_avatar_stack`
396
- takes `row:` attributes for the inner row that overlaps the avatars, such as a controller target.
433
+ Pass `as: :button` when the avatar is itself the control, such as a colour picker's trigger.
434
+ `lc_avatar_badge(icon, label:, as:)` pins a round badge to an avatar's bottom corner; render it after the avatar
435
+ in a `relative` wrapper. `as: :span` (the default) is a 28px decorative mark, such as a lock on a gated group;
436
+ `as: :button` and `as: :label` are 44px controls named by `label:`, such as a camera that changes the photo. A
437
+ label needs `for:` and shows the focus halo while the visually hidden input after it has focus; as a menu
438
+ trigger, splat `menu.trigger`'s attributes into an `as: :button` badge. `lc_avatar_stack`
439
+ takes `row:` attributes for the inner row that overlaps the avatars, such as a controller target. Its `size:`
440
+ (`xs`, `5.5`, `sm`, `md` or `lg`) pins every avatar in it to one size, and `overlap: :sm` tucks them closer and
441
+ drops the row's padding, for a stack in a line of text. `compact: true` is a preset of both and takes neither.
397
442
  Initials and icons scale with the size, including a size set through `--lc-avatar-size` or `--lc-icon-badge-size`;
398
443
  set `--lc-avatar-font-scale` or `--lc-icon-badge-font-scale` to change the share, or the `-font-size` variable to pin it.
399
444
  Badge, icon badge, Alert and Toast share `neutral`, `primary`, `success`, `warning` and `destructive` tones.
@@ -409,6 +454,9 @@ With `name:` they are native radios in labels, which bring their own arrows, sub
409
454
  labelled `nav`; items take `href:` and `current:`. Otherwise they are radio buttons whose selection lives in the
410
455
  `lc-selection` controller, which dispatches `lc-selection:change`; items take `value:` and `selected:`. An item
411
456
  given another kind's arguments raises. `variant: :pills` lays any of them out as wrapping toggle pills, sized by `size:`, instead of a segmented track.
457
+ Items take `icon:` and `icon_only:` as `lc_toggle` does. A segmented group's `layout: :stacked` puts each item's icon
458
+ over its label, and `layout: :adaptive` makes the group full width and stacks its items only while the group is
459
+ narrower than 24rem. `scroll: true` lets a track wider than its container scroll sideways, its edges fading.
412
460
 
413
461
  ```erb
414
462
  <%= lc_toggle_group label: "Period", as: :nav do %>
@@ -421,8 +469,14 @@ given another kind's arguments raises. `variant: :pills` lays any of them out as
421
469
  <% end %>
422
470
  <%= lc_toggle "Food", aria: { pressed: false }, data: { value: "food" } %>
423
471
  <%= lc_toggle "Bold", icon: "bold", icon_only: true, tooltip: true %>
472
+ <%= lc_toggle_group label: "View", as: :nav do %>
473
+ <%= lc_toggle_group_item "List", href: "/", current: true, icon: "list-bullet", icon_only: true %>
474
+ <%= lc_toggle_group_item "Calendar", href: "/calendar", icon: "calendar-days", icon_only: true %>
475
+ <% end %>
424
476
  ```
425
477
 
478
+ `lc_emoji_picker(popover_size: :lg)` widens the desktop popover from 22rem to 28rem for a roomier grid.
479
+
426
480
  `lc_empty_state(title:, text:, icon:)` lays out the usual empty state: a round icon badge, a heading
427
481
  (`level:`, 2 by default), a line of muted text, then the block, such as an action. `card: true` puts it on a card.
428
482
  Without those options the block is the whole content, as before.
@@ -478,7 +532,8 @@ makes the summary look like that `lc_button` without the native marker, and `ind
478
532
  ```
479
533
 
480
534
  `lc_list_group` draws grouped settings rows: each row is its own card-coloured panel, 2px apart, and
481
- only the group's ends round. Rows are card surfaces, so fields and buttons in them follow
535
+ only the group's ends round. The group rounds its first and last shown child, so a collapsible or any other
536
+ element at an end rounds too, and a `hidden` row hands its corners to the next one shown. Rows are card surfaces, so fields and buttons in them follow
482
537
  `--card-input` and `--card-secondary`. `lc_list_row` with a title lays out `icon:` (a name, or your own
483
538
  markup such as a logo), the title, `subtitle:` and the block as trailing content; `tag:` makes it a
484
539
  `label`, `li`, `details` or `a` (`href:`). `href:` with `tag: :li` or `:div` links the title instead
@@ -489,6 +544,18 @@ out the same icon, title and subtitle inside your own element. `lc_list_section`
489
544
  footnote; with an `id:`, the heading labels the section. Put a form around `lc_list_group` inside it
490
545
  when the rows save together.
491
546
 
547
+ `lc_list_row(choice: :radio, name:, value:, checked:)` makes a row one choice of a radio group: a `label` around a
548
+ visually hidden radio, then the title or block, then a check shown while it is checked. The checked row fills
549
+ with `--primary-soft` and its text turns semibold, and the focus halo rings the row while its radio has focus.
550
+ `input:` adds attributes to the radio, such as `required: true` or a Stimulus action.
551
+
552
+ ```erb
553
+ <%= lc_list_group role: "radiogroup", aria: { label: "How did you hear about us?" } do %>
554
+ <%= lc_list_row "A friend", choice: :radio, name: :heard_about, value: "friend", checked: true %>
555
+ <%= lc_list_row "Search", choice: :radio, name: :heard_about, value: "search" %>
556
+ <% end %>
557
+ ```
558
+
492
559
  `lc_list_field` is a form row in the same group: a label column, then the block as the control. In a
493
560
  narrow row the label folds to its `icon:`, and the text stays the accessible name. `id:` makes the label
494
561
  a `<label>` for that control; `tag: :fieldset` names a group of controls, such as chips, with a legend.
@@ -576,6 +643,20 @@ before JavaScript runs.
576
643
  <% end %>
577
644
  ```
578
645
 
646
+ `lc_file_drop(title:, hint:, button:, icon:)` is a dashed drop zone: a label around a visually hidden file
647
+ input, so a click or a dropped file reaches it. `name:` builds the input with `accept:`, `multiple:` and
648
+ `input:` attributes, such as a controller target; `form.file_drop :files, title: …` wraps the form's own
649
+ `file_field`, and its other options (`accept:`, `multiple:`, `data:`) reach the input. `button:` adds a
650
+ decorative button inside, which the label already names.
651
+
652
+ ```erb
653
+ <%= form.file_drop :files, title: "Add receipts", hint: "Up to 10 MB each", button: "Browse",
654
+ multiple: true, accept: "image/*,application/pdf", data: { action: "change->upload#update" } %>
655
+ ```
656
+
657
+ `lc_input(icon: "magnifying-glass")` draws a leading icon inside the field. The input comes wrapped in a
658
+ span then; `class:` and the other attributes still reach the `<input>`.
659
+
579
660
  `lc_checkbox`, `lc_radio` and `lc_switch` render native inputs with a label and optional hint.
580
661
  Checkboxes and switches submit an unchecked value like Rails' `check_box`; pass `unchecked_value: nil`
581
662
  to omit it. A `nil` label renders the bare input, for a row selector the row labels; give it
@@ -742,7 +823,8 @@ assistive technology so the label stays the name. Leading visuals share one colu
742
823
  labels line up with and without them. `hint:` adds a secondary line. `checked: true` or `false` makes
743
824
  a `menuitemradio` with a check mark. `checkbox: true` makes a `menuitemcheckbox` that flips its
744
825
  `aria-checked` on click, dispatches `lc-menu:check` with `{ checked }`, and leaves the menu open.
745
- `method:` renders a `button_to` form and passes `params:` and `form:` on.
826
+ `method:` renders a `button_to` form and passes `params:` on, and `form_attributes:` to the form. `form:` is the
827
+ button's own attribute: with `type: "submit"` the option submits that form from elsewhere on the page.
746
828
  `lc_menu_group(label, id:)` wraps options in a `role="group"` labelled by an eyebrow heading; its
747
829
  options stay on the menu's columns.
748
830
  `lc_menu` and `lc_popover` take `trigger: false` to render only the panel, named by `label:` (or
@@ -750,7 +832,8 @@ options stay on the menu's columns.
750
832
  `trigger` targets. With `click->lc-popover#toggleFromRow` on that host, a click anywhere on it that
751
833
  misses a control opens the panel; mark other regions `data-lc-menu-ignore`.
752
834
  `lc_menu` and `lc_popover` take `trigger: :icon` with `icon:` for a quiet icon button named by `label:`,
753
- or rendered content such as an avatar for a custom trigger. `trigger_attributes:` adds attributes such as `class:` or `title:` to either.
835
+ or rendered content such as an avatar for a custom trigger. `lc_menu(trigger_size: :sm)` makes either one a small control.
836
+ `lc_menu(side: :top)` opens the menu above its trigger, for a menu near the bottom of the screen. `trigger_attributes:` adds attributes such as `class:` or `title:` to either.
754
837
  For any other trigger, call the yielded part's `trigger` with a block. It receives the attributes that
755
838
  wire an element as the trigger (its id, `aria-haspopup`, `aria-expanded`, `aria-controls` and the
756
839
  Stimulus target and action), merged with any passed to `trigger`, and the element it renders replaces
@@ -815,7 +898,29 @@ picker both work; a div you toggle yourself sets `data-open` and removes it to s
815
898
  the div keeps your frame, or `anchored: true` makes it a popover under its trigger inside a positioned
816
899
  ancestor. `detents:` takes the same stops as `lc_dialog`, and `handle: true` adds a grab strip above the
817
900
  content. A swipe down dispatches `lc-sheet:dismiss`; unless a listener cancels it, an open popover then
818
- hides.
901
+ hides. `surface: :glass` draws a div in the translucent menu material, as a picker that is a menu on desktop
902
+ and a sheet on phones. The block gets a builder: `sheet.header` and `sheet.footer` stay pinned to the top and
903
+ bottom of the scrolling content, painted with the sheet's surface (`--lc-sheet-bg` on phones, `--popover`
904
+ above), so content scrolls under them. Put the footer last in a scroller padded with `px-inset`; it bleeds to
905
+ the scroller's edges and clears the home indicator.
906
+
907
+ ```erb
908
+ <%= lc_sheet tag: :dialog, size: :lg, aria: { label: "New expense" } do |sheet| %>
909
+ <%= sheet.header do %>…<% end %>
910
+ <div class="min-h-0 overflow-y-auto px-inset">
911
+ …
912
+ <%= sheet.footer do %><%= lc_button "Save" %><% end %>
913
+ </div>
914
+ <% end %>
915
+ ```
916
+
917
+ A controller that opens a `<dialog>` itself joins it to the dismiss stack with `registerDialog` from
918
+ `lostcoords/ui/helpers/dialog`, so Escape, a backdrop click and a swipe close it, and the page stops scrolling
919
+ behind it. `registerDialog(dialog, { close, priority, restoreFocus, lockScroll })`: `close` may return `false`
920
+ to keep the dialog open, such as while it asks to discard changes; `priority` ranks it against panels open in
921
+ it (a dialog is 10, a panel 20); `restoreFocus` runs after a close; `lockScroll: false` leaves the page
922
+ scrollable. It returns the unregister function and ends when the dialog closes; a click on the dialog's own
923
+ padding does not close it.
819
924
 
820
925
  ```erb
821
926
  <button type="button" popovertarget="filters">Filters</button>
@@ -985,8 +1090,8 @@ Buttons include hover and press feedback. Override `--lc-motion-quick` (140ms),
985
1090
  Reduced motion removes control movement and makes copy feedback immediate. Your application owns the
986
1091
  pending, success and failure states of network actions such as saving a form.
987
1092
 
988
- [Try the copy button](https://ui.lostcoords.com/components/copy_button.html) ·
989
- [Motion reference](https://ui.lostcoords.com/components/foundations.html#motion)
1093
+ [Try the copy button](https://ui.lostcoords.com/components/copy_button) ·
1094
+ [Motion reference](https://ui.lostcoords.com/components/foundations#motion)
990
1095
 
991
1096
  ### Icons
992
1097
 
@@ -1027,7 +1132,7 @@ Heading sizes are `display`, `title`, `heading` and `subheading`. Text sizes are
1027
1132
  styles a kicker or footer column label; under `lang="ja"` it keeps natural case and letter spacing. Pass `trim: true` to trim the text box.
1028
1133
  Stacks and inline groups take the spacing names from [Foundations](#foundations). `lc_stack`, `lc_inline`,
1029
1134
  `lc_text` and `lc_card` take `as:` to render a meaningful element, such as `lc_stack(as: :ul)`, `lc_text(as: :span)` or
1030
- `lc_card(as: :section)`. `lc_section` leaves
1135
+ `lc_card(as: :section)`. `lc_heading(as: :span)` sets text in a heading role without adding a heading to the outline, such as a total in a summary row. `lc_section` leaves
1031
1136
  `heading` below its title and `content` between blocks. `lc_split` lays out a main column and an aside: one
1032
1137
  column on small screens, and from `lg` a flexible main beside an aside of `aside: :sm` (16rem), `:md` (20rem)
1033
1138
  or `:lg` (24rem). `lc_columns(count: 2)` flows groups, such as settings sections, into balanced columns from
@@ -1036,7 +1141,7 @@ for a heading that needs more than a title, such as a lede under it. `lc_contain
1036
1141
  `form` widths; only the page container adds gutters. Japanese headings inherit `lang="ja"` and use
1037
1142
  natural letter spacing.
1038
1143
 
1039
- [Browse the foundations examples](https://ui.lostcoords.com/components/foundations.html).
1144
+ [Browse the foundations examples](https://ui.lostcoords.com/components/foundations).
1040
1145
 
1041
1146
  ### Reading content
1042
1147
 
@@ -1076,15 +1181,16 @@ Class helpers remain available for custom markup. The application owns its seman
1076
1181
  Generated by `bin/rails lostcoords:ui:builders`; `bin/lint` checks this list against the style helpers.
1077
1182
 
1078
1183
  <!-- builders -->
1184
+ - `lc_avatar_badge_class(size: :md, control: false, extra: nil)` (AvatarBadgeHelper)
1079
1185
  - `lc_icon_badge_class(size: :md, shape: :square, tone: :neutral, extra: nil)` (BadgeHelper)
1080
1186
  - `lc_avatar_class(size: :md, ink: false, linked: false, extra: nil)` (BadgeHelper)
1081
- - `lc_avatar_stack_class(compact: false, extra: nil)` (BadgeHelper)
1187
+ - `lc_avatar_stack_class(compact: false, size: :md, overlap: :md, extra: nil)` (BadgeHelper)
1082
1188
  - `lc_avatar_stack_row_class(extra: nil)` (BadgeHelper)
1083
1189
  - `lc_badge_class(tone: :neutral, shape: :rounded, extra: nil)` (BadgeHelper)
1084
1190
  - `lc_toggle_class(active: false, ghost: false, size: :md, extra: nil)` (BadgeHelper)
1085
1191
  - `lc_button_class(variant: :primary, tone: :default, size: :md, block: false, extra: nil)` (ButtonHelper)
1086
1192
  - `lc_select_trigger_class(size: :md, block: false, extra: nil)` (ButtonHelper)
1087
- - `lc_icon_button_class(shape: :square, size: :md, variant: :ghost, tone: :default, extra: nil)` (ButtonHelper)
1193
+ - `lc_icon_button_class(shape: :square, size: :md, icon_size: size, variant: :ghost, tone: :default, extra: nil)` (ButtonHelper)
1088
1194
  - `lc_card_class(interactive: false, padding: :md, extra: nil)` (CardHelper)
1089
1195
  - `lc_choice_label_class(card: false, extra: nil)` (ChoiceHelper)
1090
1196
  - `lc_checkbox_class(extra: nil)` (ChoiceHelper)
@@ -1103,8 +1209,9 @@ Generated by `bin/rails lostcoords:ui:builders`; `bin/lint` checks this list aga
1103
1209
  - `lc_spinner_class(size: :md, extra: nil)` (FeedbackHelper)
1104
1210
  - `lc_skeleton_class(extra: nil)` (FeedbackHelper)
1105
1211
  - `lc_empty_state_class(extra: nil)` (FeedbackHelper)
1106
- - `lc_toggle_group_class(extra: nil)` (FormHelper)
1107
- - `lc_toggle_group_item_class(active: false, extra: nil)` (FormHelper)
1212
+ - `lc_file_drop_class(extra: nil)` (FileDropHelper)
1213
+ - `lc_toggle_group_class(layout: :inline, scroll: false, extra: nil)` (FormHelper)
1214
+ - `lc_toggle_group_item_class(active: false, layout: :inline, extra: nil)` (FormHelper)
1108
1215
  - `lc_input_class(size: :md, plain: false, extra: nil)` (FormHelper)
1109
1216
  - `lc_select_class(size: :md, extra: nil)` (FormHelper)
1110
1217
  - `lc_textarea_class(extra: nil)` (FormHelper)
@@ -1117,8 +1224,8 @@ Generated by `bin/rails lostcoords:ui:builders`; `bin/lint` checks this list aga
1117
1224
  - `lc_split_class(aside: :md, extra: nil)` (LayoutHelper)
1118
1225
  - `lc_columns_class(count: 2, extra: nil)` (LayoutHelper)
1119
1226
  - `lc_section_header_class(extra: nil)` (LayoutHelper)
1120
- - `lc_popover_class(align: :end, extra: nil)` (MenuHelper)
1121
- - `lc_menu_popover_class(align: :end, extra: nil)` (MenuHelper)
1227
+ - `lc_popover_class(align: :end, side: :bottom, extra: nil)` (MenuHelper)
1228
+ - `lc_menu_popover_class(align: :end, side: :bottom, extra: nil)` (MenuHelper)
1122
1229
  - `lc_menu_option_class(tone: :default, extra: nil)` (MenuHelper)
1123
1230
  - `lc_link_class(tone: :inherit, extra: nil)` (NavigationHelper)
1124
1231
  - `lc_nav_link_class(compact: false, layout: :column, extra: nil)` (NavigationHelper)
@@ -1133,7 +1240,7 @@ Generated by `bin/rails lostcoords:ui:builders`; `bin/lint` checks this list aga
1133
1240
 
1134
1241
  ## Blocks
1135
1242
 
1136
- [Browse the blocks](https://ui.lostcoords.com/blocks.html) for complete layouts assembled from the
1243
+ [Browse the blocks](https://ui.lostcoords.com/blocks) for complete layouts assembled from the
1137
1244
  existing components. Each block has an interactive preview and the ERB, CSS and JavaScript that
1138
1245
  render it. Copy the files into your app and adapt the content, routes and actions.
1139
1246
 
@@ -1145,10 +1252,10 @@ The docs app lives in `test/dummy`. Run `parcela up --detach` and open https://u
1145
1252
  Parcela starts Rails (with live reload through Hotwire Spark) and the Tailwind watcher.
1146
1253
  `parcela down` stops this environment.
1147
1254
 
1148
- `bin/rails kiln:build` exports every docs route to `docs/` for GitHub Pages with
1255
+ `bin/rails kiln:build` exports every docs route to `docs/`, which Cloudflare serves at ui.lostcoords.com, with
1149
1256
  [Kiln](https://github.com/davafons/kiln): pages, blocks, the token reference, the machine-readable API and
1150
1257
  assets. Param sources for the component and block pages live in `test/dummy/config/kiln.rb`, and a route
1151
- without one fails the build. `bin/rails kiln:serve` serves the export the way GitHub Pages does. CI runs
1258
+ without one fails the build. `bin/rails kiln:serve` serves the export the way Cloudflare does. CI runs
1152
1259
  `bin/rails kiln:build` and fails when `docs/` changes, and checks that every public rendering helper has a
1153
1260
  runnable example.
1154
1261
 
@@ -25,7 +25,7 @@
25
25
  :where([popover]) { color: inherit; }
26
26
 
27
27
  :is(a, button, input, textarea, select, summary, [tabindex]):focus-visible,
28
- label:has(input.sr-only:focus-visible) {
28
+ label:has(input.sr-only:focus-visible, + input.sr-only:focus-visible) {
29
29
  outline: calc(var(--spacing) * 0.5) solid var(--ring, color-mix(in oklab, var(--primary) 50%, transparent));
30
30
  outline-offset: 0;
31
31
  }
@@ -1,9 +1,9 @@
1
1
  /* Tokens, foundations and the components almost every app uses: buttons,
2
- badges, avatars, cards, alerts, form controls, choices, toggles, copy buttons,
2
+ badges, avatars and their corner badges, cards, alerts, form controls, file drops, choices, toggles, copy buttons,
3
3
  layout, typography and navigation. Add the opt-in components in ./components/ that
4
4
  you render, or import ../components.css for everything. */
5
5
  @import "./theme.css";
6
- @source "../../../../helpers/lostcoords/ui/{badge,button,card,choice,copy_button,description_list,feedback,form,glass,icon,layout,list_group,navigation,primitives,render_attributes,structures,tailwind,translation,typography}_helper.rb";
6
+ @source "../../../../helpers/lostcoords/ui/{avatar_badge,badge,button,card,choice,copy_button,description_list,feedback,file_drop,form,glass,icon,layout,list_group,navigation,primitives,render_attributes,structures,tailwind,translation,typography}_helper.rb";
7
7
  @source "../../../../javascript/lostcoords/ui/helpers/*.js";
8
8
  @source "../../../../javascript/lostcoords/ui/controllers/lc_{char_counter,copy,kbd,nav,scroll_keeper,selection,shortcut,tabs,toc,toggle}_controller.js";
9
9
  @source "../../../../../lib/lostcoords/ui/parts.rb";
@@ -425,7 +425,7 @@
425
425
  position: absolute;
426
426
  inset-block: calc(100% + 8px) auto;
427
427
  inset-inline: 0 auto;
428
- inline-size: min(22rem, calc(100vw - 32px));
428
+ inline-size: min(var(--lc-emoji-picker-popover-width, 22rem), calc(100vw - 32px));
429
429
  max-block-size: min(28rem, calc(100vh - 96px));
430
430
  padding-block-end: 0;
431
431
  border-radius: var(--radius-3xl, 1.5rem);
@@ -0,0 +1,43 @@
1
+ module Lostcoords::Ui
2
+ module AvatarBadgeHelper
3
+ AVATAR_BADGE_BASE = "absolute -bottom-1 -end-1 grid place-items-center rounded-full bg-background"
4
+
5
+ # :sm is a status mark, such as a lock; :md is the 44px control size.
6
+ AVATAR_BADGE_SIZES = {
7
+ sm: "size-7 text-muted-foreground ring-1 ring-border shadow-(--lc-shadow-sm) [&_svg]:size-4",
8
+ md: "size-11 text-foreground shadow-(--lc-shadow) [&_svg]:size-5"
9
+ }.freeze
10
+
11
+ AVATAR_BADGE_CONTROL = "cursor-pointer border-0 p-0 transition-colors hover:bg-muted"
12
+ AVATAR_BADGE_TAGS = %i[span button label].freeze
13
+
14
+ def lc_avatar_badge_class(size: :md, control: false, extra: nil)
15
+ size = lc_option!(:size, size, AVATAR_BADGE_SIZES.keys)
16
+ lc_tw(AVATAR_BADGE_BASE, AVATAR_BADGE_SIZES.fetch(size), (AVATAR_BADGE_CONTROL if control), extra)
17
+ end
18
+
19
+ # A round badge on an avatar's bottom corner. Render it after the avatar inside a `relative` wrapper.
20
+ # as: :span is a decorative mark (size :sm by default); :button and :label are 44px controls named by
21
+ # label:. A :label needs for:, and shows the focus halo while the visually hidden input after it has focus.
22
+ # Inside menu.trigger, splat the yielded attributes into an as: :button badge.
23
+ def lc_avatar_badge(icon, label: nil, as: :span, size: nil, **attributes)
24
+ as = lc_option!(:as, as, AVATAR_BADGE_TAGS)
25
+ control = as != :span
26
+ size = lc_option!(:size, size || (control ? :md : :sm), AVATAR_BADGE_SIZES.keys)
27
+ raise ArgumentError, "a #{as} badge is a 44px control; use size: :md" if control && size != :md
28
+ lc_label!(label, :label) if control
29
+ raise ArgumentError, "as: :label needs for:" if as == :label && attributes[:for].blank?
30
+
31
+ glyph = lc_icon(icon, variant: (size == :sm ? :mini : :outline), options: { "aria-hidden": true })
32
+ defaults = { class: lc_avatar_badge_class(size: size, control: control), data: { slot: "avatar-badge" } }
33
+ case as
34
+ when :button
35
+ tag.button(glyph, **lc_attributes(defaults.merge(type: "button", aria: { label: label }), attributes))
36
+ when :label
37
+ tag.label(safe_join([ glyph, tag.span(label, class: "sr-only") ]), **lc_attributes(defaults.merge(title: label), attributes))
38
+ else
39
+ tag.span(glyph, **lc_attributes(defaults.merge(aria: (label ? { label: label } : { hidden: true }), role: ("img" if label)), attributes))
40
+ end
41
+ end
42
+ end
43
+ end
@@ -61,6 +61,20 @@ module Lostcoords::Ui
61
61
  "@sm:[--lc-avatar-size:--spacing(5.5)] @sm:[--lc-avatar-font-size:0.5rem] " \
62
62
  "[--lc-avatar-stack-overlap:--spacing(1.25)] [--lc-avatar-stack-padding:0px]"
63
63
 
64
+ # A stack pins its avatars' size, so avatars rendered at another size still line up. Small stacks
65
+ # take a thinner cutout.
66
+ AVATAR_STACK_SIZES = {
67
+ xs: "[--lc-avatar-size:--spacing(5)] [--lc-avatar-border:--spacing(0.375)]",
68
+ 5.5 => "[--lc-avatar-size:--spacing(5.5)] [--lc-avatar-border:--spacing(0.375)]",
69
+ sm: "[--lc-avatar-size:--spacing(6.5)] [--lc-avatar-border:--spacing(0.375)]",
70
+ md: "",
71
+ lg: "[--lc-avatar-size:--spacing(12)]"
72
+ }.freeze
73
+
74
+ # :sm tucks each avatar further under the one before and drops the row's padding, for a stack
75
+ # that sits in a line of text.
76
+ AVATAR_STACK_OVERLAPS = { md: "", sm: "[--lc-avatar-stack-overlap:--spacing(0.5)] [--lc-avatar-stack-padding:0px]" }.freeze
77
+
64
78
  # dynamic_avatar_stack_controller marks the leading visible avatar with data-first as it narrows the stack.
65
79
  AVATAR_STACK_ROW =
66
80
  "lc-avatar-stack__row flex shrink-0 p-[var(--lc-avatar-stack-padding,--spacing(1))] " \
@@ -112,8 +126,12 @@ module Lostcoords::Ui
112
126
  lc_tw(AVATAR_BASE, AVATAR_SIZES.fetch(lc_option!(:size, size, AVATAR_SIZES.keys)), (AVATAR_INK if ink), (AVATAR_LINKED if linked), extra)
113
127
  end
114
128
 
115
- def lc_avatar_stack_class(compact: false, extra: nil)
116
- lc_tw(AVATAR_STACK_BASE, (AVATAR_STACK_COMPACT if compact), extra)
129
+ def lc_avatar_stack_class(compact: false, size: :md, overlap: :md, extra: nil)
130
+ size = lc_option!(:size, size, AVATAR_STACK_SIZES.keys)
131
+ overlap = lc_option!(:overlap, overlap, AVATAR_STACK_OVERLAPS.keys)
132
+ raise ArgumentError, "compact: sets its own size and overlap" if compact && (size != :md || overlap != :md)
133
+
134
+ lc_tw(AVATAR_STACK_BASE, (AVATAR_STACK_COMPACT if compact), AVATAR_STACK_SIZES.fetch(size), AVATAR_STACK_OVERLAPS.fetch(overlap), extra)
117
135
  end
118
136
 
119
137
  def lc_avatar_stack_row_class(extra: nil)
@@ -30,6 +30,8 @@ module Lostcoords::Ui
30
30
  outline: "border border-border bg-transparent text-(--lc-button-ink,var(--foreground)) #{BUTTON_HOVER}",
31
31
  glass: "[--lc-button-bg:var(--_lc-glass-fill)] text-(--lc-button-ink,var(--foreground)) #{BUTTON_HOVER}",
32
32
  ghost: "border border-transparent bg-transparent text-muted-foreground not-disabled:hover:text-(--lc-button-ink,var(--foreground)) #{BUTTON_HOVER}",
33
+ # The page's own fill, for a quiet control sitting on a card.
34
+ inset: "border border-transparent [--lc-button-bg:var(--background)] bg-(--lc-button-bg) text-muted-foreground not-disabled:hover:text-(--lc-button-ink,var(--foreground)) #{BUTTON_HOVER}",
33
35
  destructive: "border border-transparent [--lc-button-bg:color-mix(in_oklab,var(--destructive)_60%,black)] [--lc-button-ink:#fff] bg-(--lc-button-bg) text-(--lc-button-ink) #{BUTTON_HOVER}"
34
36
  }.freeze
35
37
 
@@ -45,6 +47,7 @@ module Lostcoords::Ui
45
47
  outline: "#{BUTTON_DESTRUCTIVE_INK} border-[color-mix(in_oklab,var(--destructive)_32%,var(--border))]",
46
48
  glass: BUTTON_DESTRUCTIVE_INK,
47
49
  ghost: "#{BUTTON_DESTRUCTIVE_INK} #{BUTTON_DESTRUCTIVE_SOFT}",
50
+ inset: BUTTON_DESTRUCTIVE_INK,
48
51
  destructive: ""
49
52
  }
50
53
  }.freeze
@@ -95,9 +98,16 @@ module Lostcoords::Ui
95
98
  }.freeze
96
99
 
97
100
  ICON_BUTTON_SIZES = {
98
- sm: "size-control-sm [&_svg]:size-4",
99
- md: "size-control-md [&_svg]:size-5",
100
- lg: "size-control-lg [&_svg]:size-6"
101
+ sm: "size-control-sm",
102
+ md: "size-control-md",
103
+ lg: "size-control-lg"
104
+ }.freeze
105
+
106
+ # The icon keeps about the same share of the button at every size; icon_size: picks another tier.
107
+ ICON_BUTTON_ICON_SIZES = {
108
+ sm: "[&_svg]:size-4.5",
109
+ md: "[&_svg]:size-5",
110
+ lg: "[&_svg]:size-6"
101
111
  }.freeze
102
112
 
103
113
  # A row action that stays out of the way until it is hovered, focused or open.
@@ -129,15 +139,17 @@ module Lostcoords::Ui
129
139
  end
130
140
 
131
141
  # The base is already a ghost button, so variant: :ghost adds nothing; tone: recolours any variant.
132
- def lc_icon_button_class(shape: :square, size: :md, variant: :ghost, tone: :default, extra: nil)
142
+ def lc_icon_button_class(shape: :square, size: :md, icon_size: size, variant: :ghost, tone: :default, extra: nil)
133
143
  shape = lc_option!(:shape, shape, ICON_BUTTON_SHAPES.keys)
134
144
  size = lc_option!(:size, size, ICON_BUTTON_SIZES.keys)
145
+ icon_size = lc_option!(:icon_size, icon_size, ICON_BUTTON_ICON_SIZES.keys)
135
146
  variant = lc_option!(:variant, variant, BUTTON_VARIANTS.keys)
136
147
  tone = lc_option!(:tone, tone, BUTTON_TONES.keys)
137
148
  lc_tw(
138
149
  ICON_BUTTON_BASE,
139
150
  ICON_BUTTON_SHAPES.fetch(shape),
140
151
  ICON_BUTTON_SIZES.fetch(size),
152
+ ICON_BUTTON_ICON_SIZES.fetch(icon_size),
141
153
  (lc_glass_class(shape: :bar) if variant == :glass),
142
154
  (BUTTON_VARIANTS.fetch(variant) unless variant == :ghost),
143
155
  BUTTON_TONES.fetch(tone).fetch(variant),
@@ -1,8 +1,10 @@
1
1
  module Lostcoords::Ui
2
2
  module CardHelper
3
3
  # Padding sizes set --lc-inset, so nested content that pads or gaps with inset follows the card.
4
+ # An unpadded card drops its border and clips to its corners, so rows inside meet its edge and
5
+ # their hover fills round with it. Menus and dialogs inside render in the top layer, unclipped.
4
6
  CARD_PADDING = {
5
- none: "p-0",
7
+ none: "p-0 border-0 overflow-clip",
6
8
  md: "p-inset",
7
9
  sm: "[--lc-inset:var(--spacing-content)] p-inset"
8
10
  }.freeze
@@ -8,8 +8,7 @@ module Lostcoords::Ui
8
8
  # card: true draws the whole label as a selectable tile, for plan or theme pickers.
9
9
  CHOICE_CARD = "flex w-full rounded-2xl lc-squircle border border-transparent bg-tile p-content " \
10
10
  "transition-[background-color,border-color] duration-(--lc-motion-quick) ease-(--lc-ease-out) hover:bg-accent " \
11
- "has-checked:border-primary has-checked:bg-primary-soft has-focus-visible:outline-2 has-focus-visible:outline-offset-2 " \
12
- "has-focus-visible:outline-(--ring,color-mix(in_oklab,var(--primary)_50%,transparent))"
11
+ "has-checked:border-primary has-checked:bg-primary-soft"
13
12
 
14
13
  def lc_choice_label_class(card: false, extra: nil)
15
14
  lc_tw(CHOICE_LABEL, (CHOICE_CARD if card), extra)
@@ -8,9 +8,13 @@ module Lostcoords::Ui
8
8
 
9
9
  # popover_class paints the desktop popover: the gem leaves it unpainted so the host can match
10
10
  # its floating surfaces. picker_class and trigger_class style the wrapper and its button.
11
- def lc_emoji_picker(form:, field:, label:, catalog_url:, value: nil, quick: [], recent: [], recent_scope: nil, auto_submit: false, picker_class: nil, trigger_class: nil, popover_class: nil, **attributes)
11
+ # popover_size: :lg widens the desktop popover for a roomier grid.
12
+ POPOVER_SIZES = { md: nil, lg: "[--lc-emoji-picker-popover-width:28rem]" }.freeze
13
+
14
+ def lc_emoji_picker(form:, field:, label:, catalog_url:, value: nil, quick: [], recent: [], recent_scope: nil, auto_submit: false, popover_size: :md, picker_class: nil, trigger_class: nil, popover_class: nil, **attributes)
12
15
  lc_label!(label, :label)
13
16
  lc_label!(catalog_url, :catalog_url)
17
+ picker_class = lc_tw(POPOVER_SIZES.fetch(lc_option!(:popover_size, popover_size, POPOVER_SIZES.keys)), picker_class)
14
18
  render "lostcoords/ui/components/emoji_picker", form: form, field: field, label: label, catalog_url: catalog_url, value: value, quick: quick, recent: recent, recent_scope: recent_scope, auto_submit: auto_submit,
15
19
  picker_class: picker_class, trigger_class: trigger_class, popover_class: popover_class, attributes: attributes
16
20
  end
@@ -0,0 +1,32 @@
1
+ module Lostcoords::Ui
2
+ module FileDropHelper
3
+ FILE_DROP =
4
+ "grid min-h-45 cursor-pointer place-items-center content-center gap-2 rounded-2xl border-2 border-dashed border-border bg-muted p-4 text-center " \
5
+ "transition-[background-color,border-color,box-shadow] duration-150 ease-out hover:border-primary hover:bg-accent hover:shadow-(--lc-shadow-sm) sm:p-6"
6
+
7
+ def lc_file_drop_class(extra: nil)
8
+ lc_tw(FILE_DROP, extra)
9
+ end
10
+
11
+ # A dashed drop zone: a label around a visually hidden file input, so a click or a dropped file reaches the
12
+ # input. name: builds the input with accept:, multiple: and input: attributes, such as a controller target;
13
+ # a block renders your own input instead (form.file_drop passes the form's), and must give it class "sr-only".
14
+ # button: adds a decorative button inside the label, which the label already names.
15
+ def lc_file_drop(name: nil, title:, hint: nil, button: nil, icon: "arrow-up-tray", accept: nil, multiple: false, input: {}, **attributes, &block)
16
+ lc_label!(title, :title)
17
+ raise ArgumentError, "Pass name: or a block that renders the file input, not both" if name && block
18
+ raise ArgumentError, "lc_file_drop needs name: or a block that renders the file input" unless name || block
19
+
20
+ field = block ? capture(&block) : file_field_tag(name, **lc_attributes({ class: "sr-only", accept: accept, multiple: multiple }, input))
21
+ tag.label(**lc_attributes({ class: lc_file_drop_class, data: { slot: "file-drop" } }, attributes)) do
22
+ safe_join([
23
+ lc_icon_badge(icon: icon, size: :lg, shape: :circle, tone: :primary, class: "mb-2", aria: { hidden: true }),
24
+ tag.span(title, class: lc_heading_class(size: :subheading), data: { slot: "file-drop-title" }),
25
+ (lc_text(hint, as: :span, size: :small, tone: :muted, data: { slot: "file-drop-hint" }) if hint.present?),
26
+ (lc_button(button, as: :span, size: :sm, class: "mt-2 pointer-events-none", aria: { hidden: true }) if button.present?),
27
+ field
28
+ ].compact)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -20,6 +20,18 @@ module Lostcoords::Ui
20
20
 
21
21
  TOGGLE_GROUP_ITEM_ACTIVE = "lc-toggle-group-item-active bg-background text-foreground hover:text-foreground"
22
22
 
23
+ # :stacked puts each item's icon over its label; :adaptive makes the group full width and stacks
24
+ # its items only while the group itself is narrow.
25
+ TOGGLE_GROUP_LAYOUTS = { inline: nil, stacked: nil, adaptive: "@container/lc-toggle flex w-full" }.freeze
26
+ TOGGLE_GROUP_ITEM_LAYOUTS = {
27
+ inline: nil,
28
+ stacked: "flex-col h-auto min-h-control-sm gap-0.5 px-1.5 py-1.5 text-caption whitespace-normal text-center text-balance [&_svg]:size-5",
29
+ adaptive: "@max-sm/lc-toggle:flex-col @max-sm/lc-toggle:h-auto @max-sm/lc-toggle:gap-0.5 @max-sm/lc-toggle:px-1.5 " \
30
+ "@max-sm/lc-toggle:py-1.5 @max-sm/lc-toggle:text-caption @max-sm/lc-toggle:[&_svg]:size-5"
31
+ }.freeze
32
+ # A track wider than its container scrolls sideways, its edges fading while there is more to see.
33
+ TOGGLE_GROUP_SCROLL = "lc-scroll-fade-x max-w-full overflow-x-auto [scrollbar-width:none] *:shrink-0"
34
+
23
35
  INPUT_BASE =
24
36
  "w-full max-w-full min-w-0 " \
25
37
  "px-3 " \
@@ -55,12 +67,14 @@ module Lostcoords::Ui
55
67
  form_with(**options, builder: Lostcoords::Ui::FormBuilder, &block)
56
68
  end
57
69
 
58
- def lc_toggle_group_class(extra: nil)
59
- lc_tw(TOGGLE_GROUP_BASE, extra)
70
+ def lc_toggle_group_class(layout: :inline, scroll: false, extra: nil)
71
+ layout = lc_option!(:layout, layout, TOGGLE_GROUP_LAYOUTS.keys)
72
+ lc_tw(TOGGLE_GROUP_BASE, TOGGLE_GROUP_LAYOUTS.fetch(layout), (TOGGLE_GROUP_SCROLL if scroll), extra)
60
73
  end
61
74
 
62
- def lc_toggle_group_item_class(active: false, extra: nil)
63
- lc_tw(TOGGLE_GROUP_ITEM_BASE, (TOGGLE_GROUP_ITEM_ACTIVE if active), extra)
75
+ def lc_toggle_group_item_class(active: false, layout: :inline, extra: nil)
76
+ layout = lc_option!(:layout, layout, TOGGLE_GROUP_ITEM_LAYOUTS.keys)
77
+ lc_tw(TOGGLE_GROUP_ITEM_BASE, TOGGLE_GROUP_ITEM_LAYOUTS.fetch(layout), (TOGGLE_GROUP_ITEM_ACTIVE if active), extra)
64
78
  end
65
79
 
66
80
  def lc_input_class(size: :md, plain: false, extra: nil)
@@ -1,6 +1,11 @@
1
1
  module Lostcoords::Ui
2
2
  module ListGroupHelper
3
- LIST_ROW = "lc-list-row min-w-0 bg-card text-card-foreground first:rounded-t-3xl last:rounded-b-3xl lc-squircle"
3
+ LIST_ROW = "lc-list-row min-w-0 bg-card text-card-foreground lc-squircle"
4
+ # The group rounds its first and last shown children, whatever they are: a row, a field, or a
5
+ # collapsible of rows. A hidden row leaves the rounding to its next shown sibling.
6
+ LIST_GROUP =
7
+ "m-0 grid min-w-0 list-none gap-0.5 p-0 " \
8
+ "[&>:not([hidden]):not(:not([hidden])~*)]:rounded-t-3xl [&>:not([hidden]):not(:has(~:not([hidden])))]:rounded-b-3xl"
4
9
  LIST_ITEM = "flex min-h-16 min-w-0 items-center gap-heading px-content py-heading text-start sm:px-inset"
5
10
  LIST_ROW_PADDING = "px-content py-heading sm:px-inset"
6
11
  LIST_ICON = "grid size-10 shrink-0 place-items-center rounded-full bg-tile [&>svg:not([class*='size-'])]:size-4.5"
@@ -14,6 +19,12 @@ module Lostcoords::Ui
14
19
  "[&_:is(a[href],button,input,select,textarea,summary,[tabindex]):not([data-slot=list-link])]:relative " \
15
20
  "[&_:is(a[href],button,input,select,textarea,summary,[tabindex]):not([data-slot=list-link])]:z-raised"
16
21
  LIST_LINK = "text-inherit no-underline focus-visible:outline-none after:absolute after:inset-0 after:rounded-[inherit] after:content-['']"
22
+ # A label row around a hidden radio: the checked row fills, bolds and shows a trailing check, as
23
+ # a menuitemradio does. The global focus halo rings the row while its radio has focus.
24
+ LIST_ROW_CHOICE =
25
+ "group/choice flex items-center gap-heading cursor-pointer transition-colors duration-(--lc-motion-quick) " \
26
+ "hover:bg-accent has-checked:bg-primary-soft has-checked:font-semibold has-disabled:cursor-not-allowed has-disabled:opacity-45"
27
+ LIST_ROW_CHOICE_CHECK = "ms-auto size-4 shrink-0 text-primary invisible group-has-checked/choice:visible"
17
28
  LIST_FIELD_TAGS = %i[div fieldset span].freeze
18
29
  LIST_FIELD = "@container px-content py-2.5 transition-colors duration-(--lc-motion-quick) has-[[data-plain]:focus]:bg-accent"
19
30
  LIST_FIELD_GRID = "grid min-h-9 grid-cols-[1.25rem_minmax(0,1fr)] items-center gap-x-heading gap-y-related @md:grid-cols-[8rem_minmax(0,1fr)]"
@@ -41,7 +52,7 @@ module Lostcoords::Ui
41
52
  # first and last rows round.
42
53
  def lc_list_group(tag: :div, **attributes, &block)
43
54
  tag = lc_option!(:tag, tag, %i[div ul])
44
- content_tag(tag, (capture(&block) if block), **lc_attributes({ class: "m-0 grid min-w-0 list-none gap-0.5 p-0", data: { slot: "list-group" } }, attributes))
55
+ content_tag(tag, (capture(&block) if block), **lc_attributes({ class: LIST_GROUP, data: { slot: "list-group" } }, attributes))
45
56
  end
46
57
 
47
58
  # With a title, the row lays out icon:, the title and subtitle, then the block as its trailing
@@ -49,7 +60,13 @@ module Lostcoords::Ui
49
60
  # content that pads itself, such as an lc_list_item button. href: makes the row a link. On an li
50
61
  # or div row, the title is the link and covers the row, so the block can hold buttons and links
51
62
  # of its own; a click elsewhere in the row follows the title.
52
- def lc_list_row(title = nil, subtitle: nil, icon: nil, href: nil, tag: nil, padded: true, **attributes, &block)
63
+ # choice: :radio makes the row one choice of a radio group: a label around a hidden radio named
64
+ # name: with value:, then the title or block, then a check shown while checked:. input: adds
65
+ # attributes to the radio.
66
+ def lc_list_row(title = nil, subtitle: nil, icon: nil, href: nil, tag: nil, padded: true, choice: nil, name: nil, value: nil, checked: false, input: {}, **attributes, &block)
67
+ return lc_list_choice_row(title, choice, name, value, checked, input, attributes, &block) if choice
68
+ raise ArgumentError, "name:, value:, checked: and input: belong to a choice: row" if name || value || checked || input.any?
69
+
53
70
  tag = lc_option!(:tag, tag || (href ? :a : :div), LIST_ROW_TAGS)
54
71
  titled = href && tag != :a
55
72
  raise ArgumentError, "href: needs tag: :a, :li or :div" if titled && !%i[li div].include?(tag)
@@ -63,6 +80,24 @@ module Lostcoords::Ui
63
80
  content_tag(tag, (capture(&block) if block), **lc_attributes(defaults.merge(class: classes), attributes))
64
81
  end
65
82
 
83
+ private def lc_list_choice_row(title, choice, name, value, checked, input, attributes, &block)
84
+ lc_option!(:choice, choice, %i[radio])
85
+ lc_label!(name, :name)
86
+ raise ArgumentError, "a choice row needs value:" if value.nil?
87
+ raise ArgumentError, "a choice row takes a title or a block, not both" if title.present? && block
88
+
89
+ attributes = attributes.dup
90
+ input = input.merge(disabled: attributes.delete(:disabled)) if attributes.key?(:disabled)
91
+ content = block ? capture(&block) : content_tag(:span, title, class: "min-w-0", data: { slot: "list-title" })
92
+ content_tag(:label, **lc_attributes({ class: lc_tw(LIST_ROW, LIST_ROW_PADDING, LIST_ROW_CHOICE), data: { slot: "list-row", choice: "radio" } }, attributes)) do
93
+ safe_join([
94
+ radio_button_tag(name, value, checked, **lc_attributes({ class: "sr-only" }, input)),
95
+ content,
96
+ lc_icon("check", variant: :mini, options: { class: LIST_ROW_CHOICE_CHECK, "aria-hidden": true })
97
+ ])
98
+ end
99
+ end
100
+
66
101
  # A form row: a label column, then the block as the control. In a narrow row the label folds to
67
102
  # icon: alone and stays the accessible name. id: makes the label a <label> for that control;
68
103
  # tag: :fieldset names a group of controls with a legend. surface: false drops the row's panel,
@@ -15,6 +15,12 @@ module Lostcoords::Ui
15
15
  center: "start-1/2 end-auto -translate-x-1/2"
16
16
  }.freeze
17
17
 
18
+ # Below the trigger by default; :top opens upward, for a menu near the bottom of the screen.
19
+ MENU_POPOVER_SIDES = {
20
+ bottom: "",
21
+ top: "top-auto bottom-[calc(100%+--spacing(1))] [--lc-popover-from:translateY(--spacing(1))_scale(0.98)]"
22
+ }.freeze
23
+
18
24
  MENU_OPTION_BASE =
19
25
  "lc-menu__item lc-press [--lc-press-scale:0.98] group/option grid col-span-full grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-x-3 w-full " \
20
26
  "min-h-control-md px-3 py-1.5 rounded-2xl lc-squircle border-none bg-transparent text-start font-sans text-label text-foreground " \
@@ -38,12 +44,14 @@ module Lostcoords::Ui
38
44
  MENU_GROUP_BASE = "col-span-full grid grid-cols-subgrid gap-y-px"
39
45
  MENU_GROUP_LABEL = "col-span-full px-3 pt-2 pb-1"
40
46
 
41
- def lc_popover_class(align: :end, extra: nil)
42
- lc_glass_class(shape: :menu, extra: lc_tw(POPOVER_BASE, MENU_POPOVER_ALIGN.fetch(lc_option!(:align, align, MENU_POPOVER_ALIGN.keys)), extra))
47
+ def lc_popover_class(align: :end, side: :bottom, extra: nil)
48
+ align = MENU_POPOVER_ALIGN.fetch(lc_option!(:align, align, MENU_POPOVER_ALIGN.keys))
49
+ side = MENU_POPOVER_SIDES.fetch(lc_option!(:side, side, MENU_POPOVER_SIDES.keys))
50
+ lc_glass_class(shape: :menu, extra: lc_tw(POPOVER_BASE, align, side, extra))
43
51
  end
44
52
 
45
- def lc_menu_popover_class(align: :end, extra: nil)
46
- lc_popover_class(align: align, extra: lc_tw(MENU_POPOVER_BASE, extra))
53
+ def lc_menu_popover_class(align: :end, side: :bottom, extra: nil)
54
+ lc_popover_class(align: align, side: side, extra: lc_tw(MENU_POPOVER_BASE, extra))
47
55
  end
48
56
 
49
57
  def lc_menu_option_class(tone: :default, extra: nil)
@@ -51,11 +59,11 @@ module Lostcoords::Ui
51
59
  end
52
60
 
53
61
  # trigger: :icon renders a quiet icon button named by label; rendered HTML becomes the content
54
- # of a custom trigger, also named by label.
55
- def lc_menu(id:, label: lc_t("lostcoords.ui.menu.label"), align: :end, trigger: :button, icon: "ellipsis-vertical", trigger_attributes: {}, wrapper_attributes: {}, **attributes, &block)
56
- align = lc_option!(:align, align, MENU_POPOVER_ALIGN.keys)
57
- default_trigger = ->(wiring) { lc_panel_trigger(label, trigger, icon, :secondary, wiring) } unless trigger == false
58
- lc_render_panel(id, label, nil, "lc-menu", "menu", lc_menu_popover_class(align: align), lc_attributes({ data: { slot: "menu" } }, attributes), default_trigger, trigger_attributes, wrapper_attributes, &block)
62
+ # of a custom trigger, also named by label. trigger_size: sizes either one.
63
+ def lc_menu(id:, label: lc_t("lostcoords.ui.menu.label"), align: :end, side: :bottom, trigger: :button, trigger_size: :md, icon: "ellipsis-vertical", trigger_attributes: {}, wrapper_attributes: {}, **attributes, &block)
64
+ trigger_size = lc_option!(:trigger_size, trigger_size, ButtonHelper::ICON_BUTTON_SIZES.keys)
65
+ default_trigger = ->(wiring) { lc_panel_trigger(label, trigger, icon, :secondary, wiring, trigger_size) } unless trigger == false
66
+ lc_render_panel(id, label, nil, "lc-menu", "menu", lc_menu_popover_class(align: align, side: side), lc_attributes({ data: { slot: "menu" } }, attributes), default_trigger, trigger_attributes, wrapper_attributes, &block)
59
67
  end
60
68
 
61
69
  # Takes the same trigger options as lc_menu, including trigger: false.
@@ -70,8 +78,9 @@ module Lostcoords::Ui
70
78
  # icon: names a leading Heroicon; leading: takes other rendered content, such as an avatar, and is
71
79
  # hidden from assistive technology so the label stays the name. checked: true or false makes a
72
80
  # menuitemradio with a check mark. checkbox: true makes a menuitemcheckbox that flips on click and
73
- # leaves the menu open. method: renders a button_to form for href.
74
- def lc_menu_option(label = nil, href: nil, tone: :default, icon: nil, leading: nil, hint: nil, checked: nil, checkbox: false, method: nil, params: {}, form: {}, **attributes, &block)
81
+ # leaves the menu open. method: renders a button_to form for href, with form_attributes: on the
82
+ # form. form: is the button's own attribute, naming a form elsewhere on the page to submit.
83
+ def lc_menu_option(label = nil, href: nil, tone: :default, icon: nil, leading: nil, hint: nil, checked: nil, checkbox: false, method: nil, params: {}, form_attributes: {}, **attributes, &block)
75
84
  tone = lc_option!(:tone, tone, MENU_OPTION_TONES.keys)
76
85
  raise ArgumentError, "Pass icon: or leading:, not both" if icon && leading
77
86
  raise ArgumentError, "checked: must be true, false or nil" unless [ true, false, nil ].include?(checked)
@@ -91,7 +100,7 @@ module Lostcoords::Ui
91
100
  defaults[:aria] = { checked: checked } unless checked.nil?
92
101
 
93
102
  if method
94
- button_to(content, href, **lc_attributes(defaults, attributes), method: method, params: params, form: lc_attributes({ class: "contents" }, form))
103
+ button_to(content, href, **lc_attributes(defaults, attributes), method: method, params: params, form: lc_attributes({ class: "contents" }, form_attributes))
95
104
  elsif href
96
105
  raise ArgumentError, "Links cannot be disabled; use a menu button instead" if attributes[:disabled] || attributes["disabled"]
97
106
 
@@ -110,13 +119,13 @@ module Lostcoords::Ui
110
119
  end
111
120
 
112
121
  private
113
- def lc_panel_trigger(label, trigger, icon, variant, attributes)
122
+ def lc_panel_trigger(label, trigger, icon, variant, attributes, size = :md)
114
123
  custom = trigger.is_a?(String) && trigger.html_safe?
115
124
  kind = custom ? :custom : lc_option!(:trigger, trigger, MENU_TRIGGERS)
116
125
  case kind
117
126
  when :custom, :icon
118
127
  content = custom ? trigger : lc_icon(icon, options: { "aria-hidden": true })
119
- icon_button = { type: "button", class: lc_icon_button_class(shape: :circle, size: :md, extra: ButtonHelper::ICON_BUTTON_QUIET), aria: { label: label }, data: { slot: "icon-button" } }
128
+ icon_button = { type: "button", class: lc_icon_button_class(shape: :circle, size: size, extra: ButtonHelper::ICON_BUTTON_QUIET), aria: { label: label }, data: { slot: "icon-button" } }
120
129
  tag.button(content, **lc_attributes(icon_button, attributes))
121
130
  else
122
131
  lc_button(label, variant: variant, **attributes)
@@ -37,7 +37,7 @@ module Lostcoords::Ui
37
37
  content = capture(&content_block)
38
38
  end
39
39
 
40
- button_to(lc_button_content(content, icon, icon_position), url, lc_button_attributes(variant, tone, size, block, {}, attributes))
40
+ button_to(lc_button_content(content, icon, icon_position), url, lc_button_attributes(variant, tone, size, block, {}, lc_button_form(attributes)))
41
41
  end
42
42
 
43
43
  # A button styled as a select for opening a menu or picker. A string label truncates; a block
@@ -86,21 +86,21 @@ module Lostcoords::Ui
86
86
  tag.div(safe_join([ primary, toggle, popover ]), **lc_attributes(defaults, attributes))
87
87
  end
88
88
 
89
- def lc_icon_button(label, icon: nil, size: :md, shape: :circle, variant: :ghost, tone: :default, tooltip: nil, **attributes, &content)
90
- attributes = lc_icon_button_attributes(label, size, shape, variant, tone, { type: "button" }, attributes)
89
+ def lc_icon_button(label, icon: nil, size: :md, icon_size: size, shape: :circle, variant: :ghost, tone: :default, tooltip: nil, **attributes, &content)
90
+ attributes = lc_icon_button_attributes(label, size, icon_size, shape, variant, tone, { type: "button" }, attributes)
91
91
  lc_icon_button_tooltip(label, tooltip, attributes) { |tip| tag.button(lc_icon_button_content(icon, &content), **lc_attributes(attributes, tip)) }
92
92
  end
93
93
 
94
- def lc_icon_button_link_to(label, url, icon: nil, size: :md, shape: :circle, variant: :ghost, tone: :default, tooltip: nil, **attributes, &content)
95
- attributes = lc_icon_button_attributes(label, size, shape, variant, tone, {}, attributes)
94
+ def lc_icon_button_link_to(label, url, icon: nil, size: :md, icon_size: size, shape: :circle, variant: :ghost, tone: :default, tooltip: nil, **attributes, &content)
95
+ attributes = lc_icon_button_attributes(label, size, icon_size, shape, variant, tone, {}, attributes)
96
96
  raise ArgumentError, "Links cannot be disabled; use lc_icon_button for a disabled control" if attributes[:disabled]
97
97
 
98
98
  lc_icon_button_tooltip(label, tooltip, attributes) { |tip| link_to(lc_icon_button_content(icon, &content), url, lc_attributes(attributes, tip)) }
99
99
  end
100
100
 
101
- def lc_icon_button_to(label, url, icon: nil, size: :md, shape: :circle, variant: :ghost, tone: :default, tooltip: nil, **attributes, &content)
102
- attributes = lc_icon_button_attributes(label, size, shape, variant, tone, {}, attributes)
103
- lc_icon_button_tooltip(label, tooltip, attributes) { |tip| button_to(lc_icon_button_content(icon, &content), url, lc_attributes(attributes, tip)) }
101
+ def lc_icon_button_to(label, url, icon: nil, size: :md, icon_size: size, shape: :circle, variant: :ghost, tone: :default, tooltip: nil, **attributes, &content)
102
+ attributes = lc_icon_button_attributes(label, size, icon_size, shape, variant, tone, {}, attributes)
103
+ lc_icon_button_tooltip(label, tooltip, attributes) { |tip| button_to(lc_icon_button_content(icon, &content), url, lc_attributes(lc_button_form(attributes), tip)) }
104
104
  end
105
105
 
106
106
  def lc_badge(content = nil, tone: :neutral, shape: :rounded, **attributes, &block)
@@ -133,8 +133,9 @@ module Lostcoords::Ui
133
133
  end
134
134
 
135
135
  # row: takes attributes for the inner row that overlaps the avatars, such as a controller target.
136
- def lc_avatar_stack(compact: false, row: {}, **attributes, &block)
137
- tag.span(**lc_attributes({ class: lc_avatar_stack_class(compact: compact), data: { slot: "avatar-stack" } }, attributes)) do
136
+ # size: pins every avatar in the stack to one lc_avatar size; overlap: :sm tightens it for a line of text.
137
+ def lc_avatar_stack(compact: false, size: :md, overlap: :md, row: {}, **attributes, &block)
138
+ tag.span(**lc_attributes({ class: lc_avatar_stack_class(compact: compact, size: size, overlap: overlap), data: { slot: "avatar-stack" } }, attributes)) do
138
139
  tag.span(**lc_attributes({ class: lc_avatar_stack_row_class }, row), &block)
139
140
  end
140
141
  end
@@ -222,11 +223,11 @@ module Lostcoords::Ui
222
223
  lc_attributes(defaults.merge(class: lc_button_class(variant: variant, tone: tone, size: size, block: block), data: data), attributes)
223
224
  end
224
225
 
225
- def lc_icon_button_attributes(label, size, shape, variant, tone, defaults, attributes)
226
+ def lc_icon_button_attributes(label, size, icon_size, shape, variant, tone, defaults, attributes)
226
227
  size = lc_option!(:size, size, ButtonHelper::ICON_BUTTON_SIZES.keys)
227
228
  shape = lc_option!(:shape, shape, ButtonHelper::ICON_BUTTON_SHAPES.keys)
228
229
  data = { slot: "icon-button", size: size, variant: (variant.to_sym unless variant.to_sym == :ghost), tone: (tone.to_sym unless tone.to_sym == :default) }.compact
229
- defaults = defaults.merge(class: lc_icon_button_class(size: size, shape: shape, variant: variant, tone: tone), aria: { label: label }, data: data)
230
+ defaults = defaults.merge(class: lc_icon_button_class(size: size, icon_size: icon_size, shape: shape, variant: variant, tone: tone), aria: { label: label }, data: data)
230
231
  attributes = lc_attributes(defaults, attributes)
231
232
  accessible_label = attributes.fetch(:"aria-label", attributes.dig(:aria, :label))
232
233
  raise ArgumentError, "lc_icon_button requires a nonblank accessible label" if label.blank? || accessible_label.blank?
@@ -244,6 +245,13 @@ module Lostcoords::Ui
244
245
  lc_tooltip(text, id: id) { |tip| yield(tip) }
245
246
  end
246
247
 
248
+ # button_to's form is a box of its own; contents lets the button sit in the caller's row or grid.
249
+ def lc_button_form(attributes)
250
+ attributes = attributes.dup
251
+ form = attributes.delete(:form) || attributes.delete("form") || {}
252
+ attributes.merge(form: lc_attributes({ class: "contents" }, form))
253
+ end
254
+
247
255
  def lc_icon_button_content(icon, &content)
248
256
  raise ArgumentError, "Pass icon: or a block" unless icon || content
249
257
 
@@ -55,7 +55,7 @@ module Lostcoords::Ui
55
55
  end
56
56
 
57
57
  def lc_option!(name, value, allowed)
58
- normalized = value.is_a?(Integer) ? value : (value.to_sym if value.is_a?(String) || value.is_a?(Symbol))
58
+ normalized = value.is_a?(Numeric) ? value : (value.to_sym if value.is_a?(String) || value.is_a?(Symbol))
59
59
  return normalized if allowed.include?(normalized)
60
60
 
61
61
  raise ArgumentError, "Invalid #{name}: #{value.inspect}. Expected one of: #{allowed.map(&:inspect).join(', ')}"
@@ -2,6 +2,7 @@ module Lostcoords::Ui
2
2
  module SheetHelper
3
3
  SHEET_TAGS = %i[div dialog].freeze
4
4
  SHEET_DETENTS = [ "fit", "medium large", "large" ].freeze
5
+ SHEET_SURFACES = %i[glass].freeze
5
6
  SHEET_HANDLE = "grid min-h-7 w-full flex-none cursor-grab touch-none place-items-center active:cursor-grabbing sm:hidden"
6
7
 
7
8
  # A panel that is an iOS sheet on phones, with the lc-sheet controller. tag: :dialog is a modal
@@ -12,17 +13,22 @@ module Lostcoords::Ui
12
13
  # A swipe down dispatches lc-sheet:dismiss; unless a listener cancels it, an open popover hides.
13
14
  # With tag: :dialog, size: draws lc_dialog's modal frame at that width, for a dialog whose content
14
15
  # brings its own header and labels the dialog with aria-label.
15
- def lc_sheet(tag: :div, anchored: false, detents: "fit", handle: false, size: nil, **attributes, &block)
16
+ # surface: :glass draws a :div in the translucent menu material, a menu on desktop and a sheet on phones.
17
+ # Yields a builder whose header and footer parts stay pinned while the content scrolls.
18
+ def lc_sheet(tag: :div, anchored: false, detents: "fit", handle: false, size: nil, surface: nil, **attributes, &block)
16
19
  tag = lc_option!(:tag, tag, SHEET_TAGS)
17
20
  detents = lc_option!(:detents, detents, SHEET_DETENTS.map(&:to_sym)).to_s
21
+ surface = lc_option!(:surface, surface, SHEET_SURFACES) unless surface.nil?
18
22
  raise ArgumentError, "anchored: true needs tag: :div" if anchored && tag == :dialog
19
23
  raise ArgumentError, "size: needs tag: :dialog" if size && tag != :dialog
24
+ raise ArgumentError, "surface: :glass needs tag: :div" if surface && tag == :dialog
20
25
 
21
26
  defaults = { data: { slot: "sheet", controller: "lc-sheet", lc_sheet_detents_value: detents } }
22
- defaults[:class] = lc_tw("lc-sheet", ("lc-sheet-anchored" if anchored)) unless tag == :dialog
27
+ defaults[:class] = lc_tw("lc-sheet", ("lc-sheet-anchored" if anchored), (lc_glass_class(shape: :picker) if surface == :glass)) unless tag == :dialog
23
28
  defaults[:class] = lc_dialog_class(size: size) if size
24
29
  strip = self.tag.span(class: SHEET_HANDLE, aria: { hidden: true }, data: { slot: "sheet-handle", lc_sheet_target: "handle" }) if handle
25
- content_tag(tag, safe_join([ strip, (capture(&block) if block) ].compact), **lc_attributes(defaults, attributes))
30
+ content = capture(Parts::Sheet.new(self), &block) if block
31
+ content_tag(tag, safe_join([ strip, content ].compact), **lc_attributes(defaults, attributes))
26
32
  end
27
33
  end
28
34
  end
@@ -3,10 +3,21 @@ module Lostcoords::Ui
3
3
  INPUT_TYPES = %i[text search email password tel url number date time datetime-local month week].freeze
4
4
 
5
5
  # plain: true drops the fill, border, padding and height, for a control in an lc_list_field row.
6
- def lc_input(name: nil, value: nil, type: :text, size: :md, plain: false, **attributes)
6
+ INPUT_ICON = "pointer-events-none absolute start-3.5 size-4.5 text-muted-foreground"
7
+
8
+ # icon: draws a leading icon inside the field, such as a magnifying glass on a search field; the field
9
+ # comes wrapped in a span then, and class: and the other attributes still reach the <input>.
10
+ def lc_input(name: nil, value: nil, type: :text, size: :md, plain: false, icon: nil, **attributes)
7
11
  type = lc_option!(:type, type, INPUT_TYPES)
12
+ raise ArgumentError, "icon: needs a field; plain: true has no room for one" if icon && plain
13
+
8
14
  data = { slot: "input", plain: (true if plain) }.compact
9
- tag.input(**lc_attributes({ type: type, name: name, value: value, class: lc_input_class(size: size, plain: plain), data: data }, attributes))
15
+ input = tag.input(**lc_attributes({ type: type, name: name, value: value, class: lc_input_class(size: size, plain: plain, extra: ("ps-10" if icon)), data: data }, attributes))
16
+ return input unless icon
17
+
18
+ tag.span(class: "relative flex min-w-0 items-center", data: { slot: "input-group" }) do
19
+ safe_join([ lc_icon(icon, options: { class: INPUT_ICON, "aria-hidden": true }), input ])
20
+ end
10
21
  end
11
22
 
12
23
  def lc_textarea(content = nil, name: nil, **attributes, &block)
@@ -97,18 +108,21 @@ module Lostcoords::Ui
97
108
  # as: :nav makes links, the current one marked with aria-current; otherwise radio buttons whose
98
109
  # selection lives in the lc-selection controller.
99
110
  # variant: :pills lays the items out as wrapping toggle pills, sized by size:, instead of a segmented track.
100
- def lc_toggle_group(label:, name: nil, value: nil, as: :div, variant: :segmented, size: :md, **attributes, &block)
111
+ # layout: and scroll: shape the segmented track; see lc_toggle_group_class.
112
+ def lc_toggle_group(label:, name: nil, value: nil, as: :div, variant: :segmented, size: :md, layout: :inline, scroll: false, **attributes, &block)
101
113
  lc_label!(label, :label)
102
114
  as = lc_option!(:as, as, %i[div nav])
103
115
  variant = lc_option!(:variant, variant, %i[segmented pills])
104
116
  size = lc_option!(:size, size, ButtonHelper::BUTTON_SIZES.keys)
117
+ layout = lc_option!(:layout, layout, FormHelper::TOGGLE_GROUP_LAYOUTS.keys)
105
118
  raise ArgumentError, "size: sizes pills; a segmented toggle group has one size" if variant == :segmented && size != :md
119
+ raise ArgumentError, "layout: and scroll: shape a segmented track; pills wrap" if variant == :pills && (layout != :inline || scroll)
106
120
  raise ArgumentError, "a nav toggle group marks its current link; it takes no name: or value:" if as == :nav && (name || value)
107
121
 
108
122
  mode = as == :nav ? :links : (name ? :radios : :buttons)
109
- content = lc_within_toggle_group({ mode: mode, name: name, value: value&.to_s, variant: variant, size: size }) { capture(&block) if block }
123
+ content = lc_within_toggle_group({ mode: mode, name: name, value: value&.to_s, variant: variant, size: size, layout: layout }) { capture(&block) if block }
110
124
 
111
- defaults = { class: (variant == :pills ? lc_inline_class : lc_toggle_group_class), data: { slot: "toggle-group" } }
125
+ defaults = { class: (variant == :pills ? lc_inline_class : lc_toggle_group_class(layout: layout, scroll: scroll)), data: { slot: "toggle-group" } }
112
126
  case mode
113
127
  when :links
114
128
  tag.nav(content, **lc_attributes(defaults, attributes, { aria: { label: label } }))
@@ -121,17 +135,19 @@ module Lostcoords::Ui
121
135
  end
122
136
 
123
137
  # Takes href: and current: in a nav group, value: and checked: in a named group, and value: and
124
- # selected: in a button group; arguments from another kind of group raise.
125
- def lc_toggle_group_item(label = nil, value: nil, selected: nil, checked: nil, href: nil, current: nil, input: {}, **attributes, &block)
126
- group = @_lc_toggle_group || { mode: :buttons, variant: :segmented }
138
+ # selected: in a button group; arguments from another kind of group raise. icon: and icon_only:
139
+ # work as on lc_toggle.
140
+ def lc_toggle_group_item(label = nil, value: nil, selected: nil, checked: nil, href: nil, current: nil, input: {}, icon: nil, icon_only: false, **attributes, &block)
141
+ group = @_lc_toggle_group || { mode: :buttons, variant: :segmented, layout: :inline }
127
142
  given = { value: value, selected: selected, checked: checked, href: href, current: current }.compact.keys
128
143
  allowed = { links: %i[href current], radios: %i[value checked], buttons: %i[value selected] }.fetch(group[:mode])
129
144
  stray = given - allowed
130
145
  raise ArgumentError, "#{stray.join(', ')} can't be used on an item of a #{group[:mode]} toggle group" if stray.any?
131
146
  raise ArgumentError, "an item of a nav toggle group needs href:" if group[:mode] == :links && !href
132
147
 
133
- content = block ? capture(&block) : label
134
- defaults = { class: (group[:variant] == :pills ? lc_toggle_class(size: group[:size]) : lc_toggle_group_item_class), data: { slot: "toggle-group-item" } }
148
+ content = lc_toggle_content(label, icon, icon_only, &block)
149
+ item_class = group[:variant] == :pills ? lc_toggle_class(size: group[:size]) : lc_toggle_group_item_class(layout: group[:layout] || :inline)
150
+ defaults = { class: lc_tw(item_class, (TOGGLE_ICON_ONLY if icon_only)), data: { slot: "toggle-group-item", icon_only: (true if icon_only) }.compact }
135
151
  return lc_toggle_link(content, href, current, defaults, attributes) if group[:mode] == :links
136
152
 
137
153
  value ||= label
@@ -154,13 +170,7 @@ module Lostcoords::Ui
154
170
  # the label stays as its accessible name. tooltip: true shows the label on hover and focus, and
155
171
  # tooltip: "text" describes the toggle with other text, as on lc_icon_button.
156
172
  def lc_toggle(label = nil, active: false, ghost: false, size: :md, href: nil, name: nil, value: nil, input: {}, icon: nil, icon_only: false, tooltip: nil, **attributes, &block)
157
- raise ArgumentError, "icon_only: true needs icon: and a label, not a block" if icon_only && (icon.nil? || label.blank? || block)
158
-
159
- content = block ? capture(&block) : label
160
- if icon
161
- glyph = lc_icon(icon, options: { "aria-hidden": true, "data-icon": ("inline-start" unless icon_only) }.compact)
162
- content = safe_join([ glyph, (icon_only ? tag.span(label, class: "sr-only") : content) ])
163
- end
173
+ content = lc_toggle_content(label, icon, icon_only, &block)
164
174
  defaults = { class: lc_toggle_class(ghost: ghost, size: size, extra: (TOGGLE_ICON_ONLY if icon_only)), data: { slot: "toggle", icon_only: (true if icon_only) }.compact }
165
175
  lc_icon_button_tooltip(label, tooltip, attributes) do |tip|
166
176
  attributes = lc_attributes(attributes, tip)
@@ -183,6 +193,16 @@ module Lostcoords::Ui
183
193
  end
184
194
 
185
195
  private
196
+ def lc_toggle_content(label, icon, icon_only, &block)
197
+ raise ArgumentError, "icon_only: true needs icon: and a label, not a block" if icon_only && (icon.nil? || label.blank? || block)
198
+
199
+ content = block ? capture(&block) : label
200
+ return content unless icon
201
+
202
+ glyph = lc_icon(icon, options: { "aria-hidden": true, "data-icon": ("inline-start" unless icon_only) }.compact)
203
+ safe_join([ glyph, (icon_only ? tag.span(label, class: "sr-only") : content) ])
204
+ end
205
+
186
206
  # Items read the enclosing group's mode, so a nested group restores the outer one.
187
207
  def lc_within_toggle_group(group)
188
208
  previous, @_lc_toggle_group = @_lc_toggle_group, group
@@ -26,7 +26,8 @@ module Lostcoords::Ui
26
26
 
27
27
  # anchor: true links the heading to itself, so readers can copy a link to it; it needs id:.
28
28
  # anchor: "section-id" links it to an element around it instead, such as its <section>.
29
- def lc_heading(content = nil, level: 2, size: :heading, trim: false, anchor: false, **attributes, &block)
29
+ # as: :span or :div sets text in a heading role without making it a heading, such as an amount in a row.
30
+ def lc_heading(content = nil, level: 2, size: :heading, trim: false, anchor: false, as: nil, **attributes, &block)
30
31
  raise ArgumentError, "Invalid level: #{level.inspect}. Expected an integer from 1 to 6" unless (1..6).include?(level) && level.is_a?(Integer)
31
32
 
32
33
  target = anchor == true ? attributes[:id].to_s : anchor.presence&.to_s
@@ -34,7 +35,8 @@ module Lostcoords::Ui
34
35
 
35
36
  content = capture(&block) if block
36
37
  content = tag.a(content, href: "##{target}", class: "lc-anchor", data: { slot: "heading-anchor" }) if target
37
- tag.public_send("h#{level}", content, **lc_attributes({ class: lc_heading_class(size: size, trim: trim, extra: ("lc-anchor-target" if anchor == true)) }, attributes))
38
+ element = as ? lc_option!(:as, as, %i[span div]) : "h#{level}"
39
+ tag.public_send(element, content, **lc_attributes({ class: lc_heading_class(size: size, trim: trim, extra: ("lc-anchor-target" if anchor == true)) }, attributes))
38
40
  end
39
41
 
40
42
  # as: picks the element, such as :span inside a row or :h3 for a heading set in a text role.
@@ -2,7 +2,15 @@ import { registerDismissable } from "lostcoords/ui/helpers/dismiss_stack"
2
2
 
3
3
  const registrations = new WeakMap()
4
4
 
5
- export function registerDialog(dialog, { close = () => dialog.close(), lockScroll } = {}) {
5
+ // Joins a <dialog> to the dismiss stack: Escape, the backdrop and a swipe call close, which may
6
+ // return false to keep it open, such as while it asks whether to discard changes. priority ranks
7
+ // it against panels open in it (a dialog is 10, a panel 20); restoreFocus runs after a close;
8
+ // lockScroll: false leaves the page scrollable behind it. Calling it again for an open dialog
9
+ // returns its registration; it ends when the dialog closes.
10
+ export function registerDialog(
11
+ dialog,
12
+ { close = () => dialog.close(), lockScroll, priority, restoreFocus } = {},
13
+ ) {
6
14
  const existing = registrations.get(dialog)
7
15
  if (existing) return existing
8
16
 
@@ -10,22 +18,37 @@ export function registerDialog(dialog, { close = () => dialog.close(), lockScrol
10
18
  element: dialog,
11
19
  type: "lc-dialog",
12
20
  lockScroll,
21
+ priority,
22
+ restoreFocus,
13
23
  close,
14
24
  isOpen: () => dialog.open,
15
25
  })
26
+ // A click on the dialog element itself lands on its backdrop, or on its own padding, which
27
+ // is inside its box and must not close it.
16
28
  const closeOnBackdrop = (event) => {
17
- if (event.target === dialog) close(event)
29
+ if (event.target !== dialog) return
30
+ const box = dialog.getBoundingClientRect()
31
+ const inside =
32
+ event.clientX >= box.left &&
33
+ event.clientX <= box.right &&
34
+ event.clientY >= box.top &&
35
+ event.clientY <= box.bottom
36
+ if (!inside) close(event)
37
+ }
38
+ // A dialog closed and shown again in the same task fires close while it is already open again.
39
+ const unregisterOnClose = () => {
40
+ if (!dialog.open) unregister()
18
41
  }
19
42
  const unregister = () => {
20
43
  if (registrations.get(dialog) !== unregister) return
21
44
  registrations.delete(dialog)
22
- dialog.removeEventListener("close", unregister)
45
+ dialog.removeEventListener("close", unregisterOnClose)
23
46
  dialog.removeEventListener("click", closeOnBackdrop)
24
47
  unregisterDismissable()
25
48
  }
26
49
 
27
50
  registrations.set(dialog, unregister)
28
- dialog.addEventListener("close", unregister)
51
+ dialog.addEventListener("close", unregisterOnClose)
29
52
  dialog.addEventListener("click", closeOnBackdrop)
30
53
  return unregister
31
54
  }
@@ -11,7 +11,8 @@
11
11
  <button type="button" class="<%= lc_icon_button_class(size: :sm, shape: :circle) %>" aria-label="<%= close_label %>" data-action="<%= close_action %>" data-slot="dialog-dismiss"><%= lc_icon "x-mark", options: { "aria-hidden": true } %></button>
12
12
  </div>
13
13
  </header>
14
- <div class="-mx-inset -mb-inset flex min-h-0 flex-1 flex-col gap-inset px-inset pb-inset sm:overflow-y-auto sm:overscroll-contain" data-slot="dialog-body"><%= content %></div>
14
+ <%# Children keep their height, so a long body scrolls instead of squashing a fixed-height button. %>
15
+ <div class="-mx-inset -mb-inset flex min-h-0 flex-1 flex-col gap-inset px-inset pb-inset *:shrink-0 sm:overflow-y-auto sm:overscroll-contain" data-slot="dialog-body"><%= content %></div>
15
16
  </div>
16
17
  <% end %>
17
18
  <% if trigger %>
@@ -80,6 +80,13 @@ module Lostcoords::Ui
80
80
  choice_label(method, label, hint, "switch", input)
81
81
  end
82
82
 
83
+ # lc_file_drop around this attribute's file_field; options other than the drop zone's go to the input.
84
+ def file_drop(method, title:, hint: nil, button: nil, icon: "arrow-up-tray", **options)
85
+ @template.lc_file_drop(title: title, hint: hint, button: button, icon: icon) do
86
+ file_field(method, options.merge(class: @template.lc_tw("sr-only", options[:class])))
87
+ end
88
+ end
89
+
83
90
  # A checkbox with its label beside it.
84
91
  def choice(method, label: nil, hint: nil, checked_value: "1", unchecked_value: "0", **options)
85
92
  input = rails_check_box(method, control_options(method, options, "checkbox-input", @template.lc_checkbox_class, described: true), checked_value, unchecked_value)
@@ -85,6 +85,21 @@ module Lostcoords::Ui
85
85
  end
86
86
  end
87
87
 
88
+ # Rows that stay put while the sheet's content scrolls under them, painted with the sheet's surface.
89
+ # The footer sits last in an inset-padded scroller and bleeds to its edges, clearing the home indicator.
90
+ class Sheet < Base
91
+ SURFACE = "sticky z-sticky bg-(--lc-sheet-bg,var(--popover))"
92
+
93
+ def header(**attributes, &block)
94
+ part(:header, "sheet-header", "#{SURFACE} top-0 flex min-h-14 shrink-0 items-center", attributes, &block)
95
+ end
96
+
97
+ def footer(**attributes, &block)
98
+ part(:footer, "sheet-footer", "#{SURFACE} bottom-0 -mx-inset flex flex-wrap items-center justify-end gap-related " \
99
+ "px-inset pt-3 pb-[max(env(safe-area-inset-bottom),--spacing(3))]", attributes, &block)
100
+ end
101
+ end
102
+
88
103
  class Dialog < Base
89
104
  include CustomTrigger
90
105
 
@@ -1,5 +1,5 @@
1
1
  module Lostcoords
2
2
  module Ui
3
- VERSION = "0.11.0"
3
+ VERSION = "0.12.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lostcoords-ui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lost Coordinates
@@ -127,6 +127,7 @@ files:
127
127
  - app/assets/tailwind/lostcoords/ui/ui.css
128
128
  - app/assets/tailwind/lostcoords/ui/utilities.css
129
129
  - app/assets/tailwind/lostcoords_ui/engine.css
130
+ - app/helpers/lostcoords/ui/avatar_badge_helper.rb
130
131
  - app/helpers/lostcoords/ui/badge_helper.rb
131
132
  - app/helpers/lostcoords/ui/button_helper.rb
132
133
  - app/helpers/lostcoords/ui/card_helper.rb
@@ -138,6 +139,7 @@ files:
138
139
  - app/helpers/lostcoords/ui/dialog_helper.rb
139
140
  - app/helpers/lostcoords/ui/emoji_picker_helper.rb
140
141
  - app/helpers/lostcoords/ui/feedback_helper.rb
142
+ - app/helpers/lostcoords/ui/file_drop_helper.rb
141
143
  - app/helpers/lostcoords/ui/form_helper.rb
142
144
  - app/helpers/lostcoords/ui/glass_helper.rb
143
145
  - app/helpers/lostcoords/ui/hovercard_helper.rb