lostcoords-ui 0.8.0 → 0.8.1

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: a8f4a7f674aefbf78e3ff41660cda9bd23afe68b1f77fd9683b4200cbab18ce7
4
- data.tar.gz: f23756106e41ee9caa58beb818311dbe7352e044d969b1f25785b261e5a5179f
3
+ metadata.gz: db54a76098cb1b3f4c681f8fb3f6d71c7f471f7591bf207acf3033f08f5a1959
4
+ data.tar.gz: bca0af8ce9fa3ce85af477e2dca0040d47f73fb39a89de668d35dbe675363f75
5
5
  SHA512:
6
- metadata.gz: 2beae0fe5660fc82bdba61e82961a6d09768cf03d7a8fdea2f0defa1805b7b3e6d76556ddbc0a5210e3b70284d453541ed65d9bd86b9e27fc9509267d79a4f67
7
- data.tar.gz: 4de9907189cb70af9b8445b368da65c34dea9e8dfd9821883503d889355fe4fed22240c169c75d6665960f274644f3753d739b99f30beef888061a0e699dafa8
6
+ metadata.gz: c2796617e1b75150f50196f739ee940408eabb78d4373451bfccac04c8e8ac0a70133daa8518d03668a0dad03b8e24f9a5a461db338429ec0abaa605d2e1aab3
7
+ data.tar.gz: 48d9fdb18abe90101be6f791965b2ccd9fe628799c4ac882a8dd586f2c8a7a34834a97663df1512d638dfbfcf06f0139a95db4d107837b276af4991ecdce05fa
data/README.md CHANGED
@@ -194,6 +194,23 @@ lazyLoadControllersFrom("controllers", application)
194
194
  `eagerLoadControllersFrom` also works and downloads all of them on every page. A host file with the
195
195
  same name, such as `app/javascript/controllers/lc_dialog_controller.js`, replaces the gem's.
196
196
 
197
+ ## Changes in 0.8.1
198
+
199
+ Nothing needs an edit, but these look different:
200
+
201
+ - **A secondary destructive button has a soft destructive fill.** Before: `variant: :secondary, tone: :destructive`
202
+ kept the neutral secondary fill with destructive ink. After: it fills with the same soft destructive mix a
203
+ destructive ghost button shows on hover, so the tones read solid, soft, then ink only.
204
+ - **Toggles style `aria-checked`.** An `lc_toggle_class` element with `aria-checked="true"` now looks pressed, so
205
+ toggle pills can be the radios of a `variant: :pills` toggle group.
206
+ - **A toggle's fill follows `--lc-field-bg`.** Before: `lc_toggle` always filled with `--input`. After: it reads
207
+ `--lc-field-bg` like fields and the select trigger, so on a card or list row it takes `--card-input`.
208
+ - **The emoji picker's skin-tone menu opens downward.** Before: it opened above its toggle, which sits in the
209
+ picker's top row, so it escaped the picker. After: it opens below the toggle, inside the picker.
210
+ - **A card's destructive edge ignores its closed menus.** Before: a destructive option in a menu or popover
211
+ inside a card (a row's "Remove") tinted the card's edge. After: only the card's own controls and invalid
212
+ fields do.
213
+
197
214
  ## Upgrading from 0.7
198
215
 
199
216
  Everything else in 0.8 is additive. These changes need edits in an app built on 0.7:
@@ -242,12 +259,16 @@ Button hover and press fills mix 94% of the base background with 6% of its foreg
242
259
  Ghost and icon buttons stay transparent at rest and use the secondary base for that calculation.
243
260
  Apps can override `--secondary` for the neutral base, or `--lc-button-bg` and `--lc-button-ink` on individual buttons.
244
261
  Inputs use `--input` and `--lc-input-hover`.
245
- `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. `block: true` makes any button full width. Block helpers capture ERB content.
262
+ `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.
246
263
  Use `icon: "plus"` for a leading Heroicon or `icon_position: :end` for a trailing one. Custom icons and
247
264
  spinners use `data-icon="inline-start"` or `data-icon="inline-end"`; buttons adjust that edge's padding.
248
- `tone: :destructive` recolours any variant for destructive actions: a ghost, outline or secondary
249
- button keeps its emphasis and takes destructive ink, and a primary button becomes the filled
250
- `variant: :destructive` surface.
265
+ `lc_button(expanded_icon: "x-mark")` swaps its content for that icon while `aria-expanded` is true, for a trigger
266
+ that closes what it opened; the content stays as the accessible name.
267
+ `lc_button(as: :span)` renders the look without a control, for a decorative button inside a larger target such as
268
+ a file drop zone's label; give it `aria: { hidden: true }` when the target already names the action.
269
+ `tone: :destructive` recolours any variant for destructive actions and keeps its emphasis: a ghost or
270
+ outline button takes destructive ink, a secondary button a soft destructive fill (the ghost button's hover),
271
+ and a primary button becomes the filled `variant: :destructive` surface.
251
272
  `lc_select_trigger` is a button that looks like `lc_select`, for buttons that open a menu or picker. Its label
252
273
  starts at the inline start and its chevron sits at the inline end and turns while `aria-expanded` is true.
253
274
  `lc_split_button` is one pill with two targets: a primary action, a link with `href:`, and a square toggle
@@ -289,8 +310,10 @@ Add `class: "@container"` when a card owns its width and its children use contai
289
310
  Use `--lc-card-bg`, `--lc-card-border`, `--lc-card-radius` and `--lc-card-shadow` for local appearance overrides.
290
311
 
291
312
  `lc_badge` handles labels, counts and status. Pass `shape: :pill` for a fully rounded label such as "You" or an error count.
292
- `lc_icon_badge` handles decorative icon containers: pass `icon:` for a library icon, or content or a block for an emoji. It takes `shape: :square` or `:circle` and `sm` (26px), `md` (40px), `lg` (48px) or `xl` (56px) sizes.
313
+ `lc_icon_badge` handles decorative icon containers: pass `icon:` for a library icon, or content or a block for an emoji. It takes `shape: :square`, `:circle` or `:plain` (no tile and a larger glyph, as at the start of a list row) and `sm` (26px), `md` (40px), `lg` (48px) or `xl` (56px) sizes.
293
314
  `lc_avatar` sizes are `xs` (20px), `sm` (26px), `md` (32px), `lg` (48px), `xl` (96px) and `xxl` (112px).
315
+ Between them, both take a step on the spacing scale, as in `size-7`: `lc_avatar` takes `7` (28px) and `11` (44px),
316
+ `lc_icon_badge` takes `6` (24px), `7` (28px) and `11` (44px).
294
317
  Pass `as: :button` when the avatar is itself the control, such as a colour picker's trigger. `lc_avatar_stack`
295
318
  takes `row:` attributes for the inner row that overlaps the avatars, such as a controller target.
296
319
  Initials and icons scale with the size, including a size set through `--lc-avatar-size` or `--lc-icon-badge-size`;
@@ -305,7 +328,7 @@ With `name:` they are native radios in labels, which bring their own arrows, sub
305
328
  `value:` and `checked:`, and the group's `value:` checks the matching item. With `as: :nav` they are links in a
306
329
  labelled `nav`; items take `href:` and `current:`. Otherwise they are radio buttons whose selection lives in the
307
330
  `lc-selection` controller, which dispatches `lc-selection:change`; items take `value:` and `selected:`. An item
308
- given another kind's arguments raises.
331
+ 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.
309
332
 
310
333
  ```erb
311
334
  <%= lc_toggle_group label: "Period", as: :nav do %>
@@ -330,8 +353,9 @@ given another kind's arguments raises.
330
353
  ```
331
354
 
332
355
  The `summary` part replaces `title:` with your own markup and takes attributes for the `<summary>`.
333
- `card: false` drops the card surface, `summary_class:` styles the summary (a button class works), and
334
- `indicator:` is `:marker` (native), `:chevron` (turns as it opens) or `:none`.
356
+ `card: false` drops the card surface, `summary_class:` adds classes to the summary, `button: { variant:, tone:, size: }`
357
+ makes the summary look like that `lc_button` without the native marker, and `indicator:` is `:marker` (native),
358
+ `:chevron` (turns as it opens) or `:none`.
335
359
 
336
360
  ```erb
337
361
  <%= lc_list_section "Security", id: "security", footnote: "Keep one way to sign in." do %>
@@ -354,6 +378,25 @@ out the same icon, title and subtitle inside your own element. `lc_list_section`
354
378
  footnote; with an `id:`, the heading labels the section. Put a form around `lc_list_group` inside it
355
379
  when the rows save together.
356
380
 
381
+ `lc_list_field` is a form row in the same group: a label column, then the block as the control. In a
382
+ narrow row the label folds to its `icon:`, and the text stays the accessible name. `id:` makes the label
383
+ a `<label>` for that control; `tag: :fieldset` names a group of controls, such as chips, with a legend.
384
+ `tag: :span, surface: false` draws the row inside another element, such as a collapsible's summary.
385
+ `lc_input(plain: true)` drops the field's fill, border, padding and height so the text sits in the row,
386
+ which tints while that input has focus. Toggles take `--lc-field-bg` like fields, so on a card or list
387
+ row they use `--card-input`.
388
+
389
+ ```erb
390
+ <%= lc_list_group do %>
391
+ <%= lc_list_field "Description", icon: "pencil", id: "description" do %>
392
+ <%= lc_input plain: true, id: "description", name: "description" %>
393
+ <% end %>
394
+ <%= lc_list_field "Paid by", icon: "user", tag: :fieldset do %>
395
+ <div class="flex flex-wrap gap-related"><%= lc_toggle "Ada", size: :sm, aria: { pressed: true } %></div>
396
+ <% end %>
397
+ <% end %>
398
+ ```
399
+
357
400
  ### Parts and slots
358
401
 
359
402
  Compound components yield a builder, so their parts are scoped and discoverable. A card stacks its
@@ -471,7 +514,7 @@ nests a link. `layout: :row` lays links in a line, `:dock` stacks each icon abov
471
514
  cells for a phone's bottom bar, and `:responsive` is a dock below `sm` and a row from `sm`; position a
472
515
  dock yourself, such as `fixed bottom-0`. `indicator: true` slides one fill to the current link, and
473
516
  after a Turbo visit the new list starts the fill where the last one left it. Set `--lc-nav-indicator`
474
- to change the fill, and pass `layout:` to `lc_nav_link_class` for links you render yourself. `lc_pager` takes `[title, url]`
517
+ (or `--lc-nav-dock-indicator` for a dock, such as one on glass) to change the fill, and pass `layout:` to `lc_nav_link_class` for links you render yourself. `lc_pager` takes `[title, url]`
475
518
  for each side and `compact: true` for icon buttons. `lc_link` has `inherit`, `muted` and `primary`
476
519
  tones; `lc_link_class` styles links you render yourself. `lc_skip_link` targets `#main` by default.
477
520
  Pass `card: true` to `lc_radio` or `lc_checkbox` for selectable tiles; a block adds content, such as a
@@ -494,6 +537,8 @@ labels line up with and without them. `hint:` adds a secondary line. `checked: t
494
537
  a `menuitemradio` with a check mark. `checkbox: true` makes a `menuitemcheckbox` that flips its
495
538
  `aria-checked` on click, dispatches `lc-menu:check` with `{ checked }`, and leaves the menu open.
496
539
  `method:` renders a `button_to` form and passes `params:` and `form:` on.
540
+ `lc_menu_group(label, id:)` wraps options in a `role="group"` labelled by an eyebrow heading; its
541
+ options stay on the menu's columns.
497
542
  `lc_menu` and `lc_popover` take `trigger: false` to render only the panel, named by `label:` (or
498
543
  `title:`), when an ancestor hosts the `lc-menu` or `lc-popover` controller and wires its own
499
544
  `trigger` targets. With `click->lc-popover#toggleFromRow` on that host, a click anywhere on it that
@@ -520,10 +565,12 @@ to choose mobile height stops; the default is `"fit"`. Icon buttons, avatar grou
520
565
  appear with their parent component examples.
521
566
 
522
567
  `size:` sets the desktop width: `:sm` (24rem), `:md` (32rem, the modal default), `:lg` (40rem) or `:xl`
523
- (64rem). The size sets `--lc-dialog-width`, which the width reads: widen a dialog in a state with
524
- `has-[…]:[--lc-dialog-width:64rem]`, or size content with `calc(var(--lc-dialog-width) - 2px)`. On desktop
525
- the header stays put and the body scrolls. `dialog.actions` adds content to the header, before the close
526
- button. Pass `trigger: false` when a controller of your own opens the dialog: only the `<dialog>` renders,
568
+ (64rem). Content marked `data-dialog-size="xl"` (any size) switches the dialog to that size while it is in
569
+ the dialog, for a step that needs more room. The size sets `--lc-dialog-width`, so content can size itself
570
+ with `calc(var(--lc-dialog-width) - 2px)`. On desktop the header stays put and the body scrolls; an anchored
571
+ dialog stops 1rem above the viewport's bottom edge. `dialog.actions` adds content to the header, before the
572
+ close button. `dialog.trigger { |attrs| … }` renders your own element as the trigger, like `menu.trigger`:
573
+ splat `**attrs` into it to wire it to open the dialog. Pass `trigger: false` when a controller of your own opens the dialog: only the `<dialog>` renders,
527
574
  and `close_action:` (default `"lc-dialog#close"`) and `close_label:` wire the close buttons to it. `data:`
528
575
  and `aria:` reach the `<dialog>`; `title_attributes:` and `description_attributes:` reach the heading and
529
576
  description, for a controller that rewrites them.
@@ -600,7 +647,9 @@ the same helpers' markup, cloned from a `<template>`; the docs search does this
600
647
  The block also renders what shows before anything is typed. Arrow keys move through the results,
601
648
  Enter opens the first one, and choosing a result or pressing Escape closes search and returns focus.
602
649
  Groups without a visible result hide, a query with none shows the empty note, and a status region
603
- announces the count. Pass `shortcut: nil` to drop the page shortcut, and `id:` when a page has two searches.
650
+ announces the count. `empty:` sets that note, with `%{query}` standing for the query, and `prompt:`
651
+ adds a note for when nothing is typed and there is nothing to show. While `src` is answering, the
652
+ panel is `aria-busy` and both notes wait, so they never flash before the results arrive. Pass `shortcut: nil` to drop the page shortcut, and `id:` when a page has two searches.
604
653
 
605
654
  ### Keyboard
606
655
 
@@ -810,7 +859,7 @@ Generated by `bin/rails lostcoords:ui:builders`; `bin/lint` checks this list aga
810
859
  - `lc_toggle_class(active: false, ghost: false, size: :md, extra: nil)` (BadgeHelper)
811
860
  - `lc_button_class(variant: :primary, tone: :default, size: :md, block: false, extra: nil)` (ButtonHelper)
812
861
  - `lc_select_trigger_class(size: :md, block: false, extra: nil)` (ButtonHelper)
813
- - `lc_icon_button_class(shape: :square, size: :md, extra: nil)` (ButtonHelper)
862
+ - `lc_icon_button_class(shape: :square, size: :md, variant: :ghost, tone: :default, extra: nil)` (ButtonHelper)
814
863
  - `lc_card_class(interactive: false, padding: :md, extra: nil)` (CardHelper)
815
864
  - `lc_choice_label_class(card: false, extra: nil)` (ChoiceHelper)
816
865
  - `lc_checkbox_class(extra: nil)` (ChoiceHelper)
@@ -831,7 +880,7 @@ Generated by `bin/rails lostcoords:ui:builders`; `bin/lint` checks this list aga
831
880
  - `lc_empty_state_class(extra: nil)` (FeedbackHelper)
832
881
  - `lc_toggle_group_class(extra: nil)` (FormHelper)
833
882
  - `lc_toggle_group_item_class(active: false, extra: nil)` (FormHelper)
834
- - `lc_input_class(size: :md, extra: nil)` (FormHelper)
883
+ - `lc_input_class(size: :md, plain: false, extra: nil)` (FormHelper)
835
884
  - `lc_select_class(size: :md, extra: nil)` (FormHelper)
836
885
  - `lc_textarea_class(extra: nil)` (FormHelper)
837
886
  - `lc_field_class(size: :md, extra: nil)` (FormHelper)
@@ -26,7 +26,9 @@
26
26
  border-color var(--lc-motion-control) var(--lc-ease-out),
27
27
  box-shadow var(--lc-motion-control) var(--lc-ease-out);
28
28
 
29
- &:has([data-tone="destructive"], [aria-invalid="true"]) {
29
+ /* A closed menu or popover inside the card (a row's "Remove" option) is
30
+ not the card's own control, so it doesn't tint the edge. */
31
+ &:has(:is([data-tone="destructive"], [aria-invalid="true"]):not([data-slot="menu"] *, [data-slot="popover"] *)) {
30
32
  border-color: color-mix(in oklab, var(--destructive) 30%, var(--border));
31
33
  }
32
34
  }
@@ -48,6 +48,23 @@
48
48
  }
49
49
  }
50
50
 
51
+ /* The size scale. Content marked data-dialog-size switches the dialog to that size while it is
52
+ inside, so the :has() rules come after the size classes and win over them. */
53
+ --lc-dialog-sm: 24rem;
54
+ --lc-dialog-md: 32rem;
55
+ --lc-dialog-lg: 40rem;
56
+ --lc-dialog-xl: 64rem;
57
+
58
+ &.lc-dialog-context { --lc-dialog-width: 22rem; }
59
+ &.lc-dialog-sm { --lc-dialog-width: var(--lc-dialog-sm); }
60
+ &.lc-dialog-md { --lc-dialog-width: var(--lc-dialog-md); }
61
+ &.lc-dialog-lg { --lc-dialog-width: var(--lc-dialog-lg); }
62
+ &.lc-dialog-xl { --lc-dialog-width: var(--lc-dialog-xl); }
63
+ &:has([data-dialog-size="sm"]) { --lc-dialog-width: var(--lc-dialog-sm); }
64
+ &:has([data-dialog-size="md"]) { --lc-dialog-width: var(--lc-dialog-md); }
65
+ &:has([data-dialog-size="lg"]) { --lc-dialog-width: var(--lc-dialog-lg); }
66
+ &:has([data-dialog-size="xl"]) { --lc-dialog-width: var(--lc-dialog-xl); }
67
+
51
68
  &.lc-dialog-context[open]::backdrop {
52
69
  background: var(--lc-scrim-soft);
53
70
  backdrop-filter: none;
@@ -219,9 +219,10 @@
219
219
  &[aria-expanded="true"] { background: color-mix(in oklab, var(--primary) 12%, var(--background)); }
220
220
  }
221
221
 
222
+ /* The tone toggle sits in the picker's top row, so the menu opens downward and stays inside the picker. */
222
223
  .lc-emoji-picker__tone-menu {
223
224
  position: absolute;
224
- inset-block-end: calc(100% + 6px);
225
+ inset-block-start: calc(100% + 6px);
225
226
  inset-inline-end: 0;
226
227
  z-index: 4;
227
228
  display: flex;
@@ -12,10 +12,16 @@ module Lostcoords::Ui
12
12
  sm: "[--lc-icon-badge-size-default:--spacing(6.5)] [--lc-icon-badge-font-scale-default:0.5]",
13
13
  md: "",
14
14
  lg: "[--lc-icon-badge-size-default:--spacing(12)] [--lc-icon-badge-font-scale-default:0.5]",
15
- xl: "[--lc-icon-badge-size-default:--spacing(14)] [--lc-icon-badge-font-scale-default:0.5]"
15
+ xl: "[--lc-icon-badge-size-default:--spacing(14)] [--lc-icon-badge-font-scale-default:0.5]",
16
+ # Steps on the spacing scale, as in size-7, for row glyphs between the named sizes.
17
+ 6 => "[--lc-icon-badge-size-default:--spacing(6)] [--lc-icon-badge-font-scale-default:0.5]",
18
+ 7 => "[--lc-icon-badge-size-default:--spacing(7)] [--lc-icon-badge-font-scale-default:0.5]",
19
+ 11 => "[--lc-icon-badge-size-default:--spacing(11)] [--lc-icon-badge-font-scale-default:0.5]"
16
20
  }.freeze
17
21
 
18
- ICON_BADGE_SHAPES = { square: "lc-squircle rounded-2xl", circle: "rounded-full" }.freeze
22
+ # plain drops the tile: the emoji or icon is the badge, as at the start of a list row.
23
+ ICON_BADGE_SHAPES = { square: "lc-squircle rounded-2xl", circle: "rounded-full", plain: "rounded-none" }.freeze
24
+ ICON_BADGE_PLAIN = "bg-transparent [--lc-icon-badge-font-scale-default:0.875]"
19
25
 
20
26
  AVATAR_BASE =
21
27
  "lc-avatar grid place-items-center shrink-0 rounded-full font-medium tracking-[var(--lc-avatar-tracking,0.05em)] " \
@@ -32,7 +38,10 @@ module Lostcoords::Ui
32
38
  md: "",
33
39
  lg: "[--lc-avatar-size-default:--spacing(12)] [--lc-avatar-font-scale-default:0.333]",
34
40
  xl: "[--lc-avatar-size-default:--spacing(24)] [--lc-avatar-font-scale-default:0.208]",
35
- xxl: "[--lc-avatar-size-default:--spacing(28)] [--lc-avatar-font-scale-default:0.25]"
41
+ xxl: "[--lc-avatar-size-default:--spacing(28)] [--lc-avatar-font-scale-default:0.25]",
42
+ # Steps on the spacing scale, as in size-7, between the named sizes.
43
+ 7 => "[--lc-avatar-size-default:--spacing(7)]",
44
+ 11 => "[--lc-avatar-size-default:--spacing(11)] [--lc-avatar-font-scale-default:0.35]"
36
45
  }.freeze
37
46
 
38
47
  AVATAR_INK = "[--lc-avatar-color:var(--foreground)]"
@@ -73,11 +82,12 @@ module Lostcoords::Ui
73
82
 
74
83
  TOGGLE_BASE =
75
84
  "inline-flex items-center justify-center gap-related rounded-pill " \
76
- "border border-transparent bg-input " \
85
+ "border border-transparent bg-(--lc-field-bg,var(--input)) " \
77
86
  "font-sans text-muted-foreground whitespace-nowrap cursor-pointer no-underline " \
78
87
  "transition-[background-color,border-color,color,transform] duration-(--lc-motion-quick) ease-(--lc-ease-out) " \
79
88
  "lc-press hover:text-foreground " \
80
89
  "aria-pressed:bg-primary-soft aria-pressed:border-primary aria-pressed:text-primary aria-pressed:shadow-none " \
90
+ "aria-checked:bg-primary-soft aria-checked:border-primary aria-checked:text-primary aria-checked:shadow-none " \
81
91
  "aria-[current]:not-aria-[current=false]:bg-primary-soft aria-[current]:not-aria-[current=false]:border-primary " \
82
92
  "aria-[current]:not-aria-[current=false]:text-primary aria-[current]:not-aria-[current=false]:shadow-none " \
83
93
  "has-checked:bg-primary-soft has-checked:border-primary has-checked:text-primary has-checked:shadow-none " \
@@ -93,7 +103,7 @@ module Lostcoords::Ui
93
103
  shape = lc_option!(:shape, shape, ICON_BADGE_SHAPES.keys)
94
104
  tone = lc_option!(:tone, tone, BADGE_TONES.keys)
95
105
  lc_tw(ICON_BADGE_BASE, ICON_BADGE_SIZES.fetch(size), ICON_BADGE_SHAPES.fetch(shape),
96
- (tone == :neutral ? "bg-tile text-foreground" : BADGE_TONES.fetch(tone)), extra)
106
+ (tone == :neutral ? "bg-tile text-foreground" : BADGE_TONES.fetch(tone)), (ICON_BADGE_PLAIN if shape == :plain), extra)
97
107
  end
98
108
 
99
109
  def lc_avatar_class(size: :md, ink: false, linked: false, extra: nil)
@@ -34,16 +34,17 @@ module Lostcoords::Ui
34
34
  }.freeze
35
35
 
36
36
  BUTTON_DESTRUCTIVE_INK = "text-destructive [--lc-button-ink:var(--destructive)]"
37
+ BUTTON_DESTRUCTIVE_SOFT = "[--lc-button-bg:color-mix(in_oklab,var(--destructive)_12%,var(--background))]"
37
38
 
38
39
  # A tone recolours a variant without changing its emphasis, so a destructive action can stay quiet.
39
40
  BUTTON_TONES = {
40
41
  default: BUTTON_VARIANTS.transform_values { "" },
41
42
  destructive: {
42
43
  primary: "[--lc-button-bg:color-mix(in_oklab,var(--destructive)_60%,black)] [--lc-button-ink:#fff]",
43
- secondary: BUTTON_DESTRUCTIVE_INK,
44
+ secondary: "#{BUTTON_DESTRUCTIVE_INK} #{BUTTON_DESTRUCTIVE_SOFT}",
44
45
  outline: "#{BUTTON_DESTRUCTIVE_INK} border-[color-mix(in_oklab,var(--destructive)_32%,var(--border))]",
45
46
  glass: BUTTON_DESTRUCTIVE_INK,
46
- ghost: "#{BUTTON_DESTRUCTIVE_INK} [--lc-button-bg:color-mix(in_oklab,var(--destructive)_12%,var(--background))]",
47
+ ghost: "#{BUTTON_DESTRUCTIVE_INK} #{BUTTON_DESTRUCTIVE_SOFT}",
47
48
  destructive: ""
48
49
  }
49
50
  }.freeze
@@ -127,13 +128,19 @@ module Lostcoords::Ui
127
128
  lc_tw(SELECT_TRIGGER_BASE, TailwindHelper::CONTROL_SIZES.fetch(size), ("w-full" if block), extra)
128
129
  end
129
130
 
130
- def lc_icon_button_class(shape: :square, size: :md, extra: nil)
131
+ # 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)
131
133
  shape = lc_option!(:shape, shape, ICON_BUTTON_SHAPES.keys)
132
134
  size = lc_option!(:size, size, ICON_BUTTON_SIZES.keys)
135
+ variant = lc_option!(:variant, variant, BUTTON_VARIANTS.keys)
136
+ tone = lc_option!(:tone, tone, BUTTON_TONES.keys)
133
137
  lc_tw(
134
138
  ICON_BUTTON_BASE,
135
139
  ICON_BUTTON_SHAPES.fetch(shape),
136
140
  ICON_BUTTON_SIZES.fetch(size),
141
+ (lc_glass_class(shape: :bar) if variant == :glass),
142
+ (BUTTON_VARIANTS.fetch(variant) unless variant == :ghost),
143
+ BUTTON_TONES.fetch(tone).fetch(variant),
137
144
  extra
138
145
  )
139
146
  end
@@ -6,15 +6,18 @@ module Lostcoords::Ui
6
6
  # card: false drops the card surface. summary_class: styles the summary, such as a button class.
7
7
  # indicator: :chevron swaps the native marker for a chevron that turns as it opens; it follows the
8
8
  # summary's content, so push it to the end with me-auto on a summary element.
9
- def lc_collapsible(title: nil, open: false, card: true, summary_class: nil, indicator: :marker, **attributes, &block)
9
+ # button: { variant:, tone:, size: } styles the summary as that lc_button and drops the native marker.
10
+ def lc_collapsible(title: nil, open: false, card: true, summary_class: nil, indicator: :marker, button: nil, **attributes, &block)
10
11
  indicator = lc_option!(:indicator, indicator, COLLAPSIBLE_INDICATORS)
12
+ indicator = :none if button && indicator == :marker
13
+ raise ArgumentError, "button: takes variant:, tone: and size:" if button && (button.keys - %i[variant tone size]).any?
11
14
  parts = Parts::Collapsible.new(self)
12
15
  content = capture(parts, &block) if block
13
16
  summary = parts.summary_content || title
14
17
  raise ArgumentError, "lc_collapsible needs a title: or a summary part" if summary.blank?
15
18
  summary = tag.span(summary, class: "me-auto") if indicator == :chevron && parts.summary_content.nil?
16
19
 
17
- summary_classes = lc_tw("cursor-pointer text-label font-semibold",
20
+ summary_classes = lc_tw((button ? lc_button_class(**button) : "cursor-pointer text-label font-semibold"),
18
21
  ("list-none [&::-webkit-details-marker]:hidden" unless indicator == :marker),
19
22
  ("flex min-h-control-md items-center gap-related" if indicator == :chevron), summary_class)
20
23
  chevron = lc_icon("chevron-down", variant: :mini, options: { class: "size-4 shrink-0 text-muted-foreground", aria: { hidden: true }, data: { slot: "collapsible-indicator" } }) if indicator == :chevron
@@ -4,7 +4,9 @@ module Lostcoords::Ui
4
4
  SHEET_DIALOG_SURFACE =
5
5
  "sm:border sm:border-(--lc-glass-edge) sm:rounded-3xl sm:bg-popover text-popover-foreground sm:shadow-[var(--lc-glass-rim),var(--lc-shadow-lg)]"
6
6
 
7
- ANCHORED = "data-anchored:[inset:var(--lc-dialog-top)_var(--lc-dialog-right)_auto_auto] data-anchored:m-0"
7
+ # An anchored dialog opens below its trigger, so its height stops short of the viewport's bottom edge.
8
+ ANCHORED = "data-anchored:[inset:var(--lc-dialog-top)_var(--lc-dialog-right)_auto_auto] data-anchored:m-0 " \
9
+ "data-anchored:sm:max-h-[calc(100dvh-var(--lc-dialog-top)-1rem)]"
8
10
 
9
11
  # The desktop width reads --lc-dialog-width, so a caller can widen the dialog or size content to it.
10
12
  DIALOG_WIDTH = "sm:w-[min(var(--lc-dialog-width),calc(100vw-2rem))]"
@@ -12,16 +14,17 @@ module Lostcoords::Ui
12
14
  DIALOGS = {
13
15
  modal: "lc-dialog #{SHEET_DIALOG_SURFACE} #{DIALOG_WIDTH} sm:max-h-[calc(100dvh-2rem)]",
14
16
  context:
15
- "lc-dialog lc-dialog-context #{SHEET_DIALOG_SURFACE} #{DIALOG_WIDTH} [--lc-dialog-width:22rem] " \
17
+ "lc-dialog lc-dialog-context #{SHEET_DIALOG_SURFACE} #{DIALOG_WIDTH} " \
16
18
  "sm:max-h-[calc(100dvh-2rem)] sm:origin-(--lc-dialog-origin,center) [--lc-dialog-from:scale(0.96)] #{ANCHORED}"
17
19
  }.freeze
18
20
 
19
- # Desktop widths; below sm every dialog is a full-width sheet.
21
+ # Desktop widths, set in dialog.css, which also applies them to content marked
22
+ # data-dialog-size="sm|md|lg|xl". Below sm every dialog is a full-width sheet.
20
23
  DIALOG_SIZES = {
21
- sm: "[--lc-dialog-width:24rem]",
22
- md: "[--lc-dialog-width:32rem]",
23
- lg: "[--lc-dialog-width:40rem]",
24
- xl: "[--lc-dialog-width:64rem]"
24
+ sm: "lc-dialog-sm",
25
+ md: "lc-dialog-md",
26
+ lg: "lc-dialog-lg",
27
+ xl: "lc-dialog-xl"
25
28
  }.freeze
26
29
 
27
30
  CONFIRM_SHEET_ID = "lc-confirm-sheet"
@@ -34,7 +37,8 @@ module Lostcoords::Ui
34
37
  lc_tw("lc-squircle", DIALOGS.fetch(kind), (DIALOG_SIZES.fetch(size) if size), extra)
35
38
  end
36
39
 
37
- # Yields a builder with actions, footer and close parts.
40
+ # Yields a builder with trigger, actions, footer and close parts. dialog.trigger { |attrs| … } renders
41
+ # your own element as the trigger, with the attributes that open the dialog.
38
42
  # trigger: false renders only the <dialog>, for a controller of your own to open; point close_action at it.
39
43
  # title_attributes: and description_attributes: reach the heading and description, for a controller that rewrites them.
40
44
  def lc_dialog(id:, title:, description: nil, trigger: lc_t("lostcoords.ui.dialog.trigger"), kind: :modal, size: nil, detents: "fit",
@@ -50,7 +54,8 @@ module Lostcoords::Ui
50
54
  content = capture(parts, &block) if block
51
55
  title_tag = tag.h2(title, **lc_attributes({ class: lc_heading_class(size: :subheading), data: { slot: "dialog-title" } }, title_attributes, { id: "#{id}-title" }))
52
56
  description_tag = tag.p(description, **lc_attributes({ class: lc_text_class(size: :small, tone: :muted), data: { slot: "dialog-description" } }, description_attributes, { id: "#{id}-description" })) if description.present?
53
- render "lostcoords/ui/components/lc_dialog", id: id, title: title_tag, description: description_tag, trigger: trigger, detents: detents,
57
+ raise ArgumentError, "dialog.trigger can't be used with trigger: false" if trigger == false && parts.rendered_trigger
58
+ render "lostcoords/ui/components/lc_dialog", id: id, title: title_tag, description: description_tag, trigger: trigger, rendered_trigger: parts.rendered_trigger, detents: detents,
54
59
  close_action: close_action, close_label: close_label || lc_t("lostcoords.ui.dialog.close", title: title),
55
60
  attributes: lc_attributes(defaults, attributes, required), actions: parts.header_actions, content: content
56
61
  end
@@ -29,6 +29,11 @@ module Lostcoords::Ui
29
29
  "focus:shadow-[0_0_0_calc(var(--spacing)*0.5)_var(--ring,color-mix(in_oklab,var(--primary)_50%,transparent))] " \
30
30
  "aria-invalid:border-destructive aria-invalid:shadow-[0_0_0_3px_color-mix(in_oklab,var(--destructive)_16%,transparent)]"
31
31
 
32
+ # Text and nothing else: for a control inside a row that shows focus itself, such as lc_list_field.
33
+ INPUT_PLAIN =
34
+ "w-full max-w-full min-w-0 min-h-9 p-0 border-0 bg-transparent font-sans text-base text-foreground " \
35
+ "placeholder:text-muted-foreground aria-invalid:placeholder:text-destructive outline-none"
36
+
32
37
  FIELD_BASE = "lc-field grid min-w-0 has-aria-invalid:[&>label]:text-destructive"
33
38
  FIELD_SIZES = { sm: "gap-tight", md: "gap-related" }.freeze
34
39
  # Field labels use the text roles; TypographyHelper loads after this file, so its sizes are read at call time.
@@ -58,8 +63,11 @@ module Lostcoords::Ui
58
63
  lc_tw(TOGGLE_GROUP_ITEM_BASE, (TOGGLE_GROUP_ITEM_ACTIVE if active), extra)
59
64
  end
60
65
 
61
- def lc_input_class(size: :md, extra: nil)
62
- lc_tw(INPUT_BASE, TailwindHelper::CONTROL_SIZES.fetch(lc_option!(:size, size, TailwindHelper::CONTROL_SIZES.keys)), extra)
66
+ def lc_input_class(size: :md, plain: false, extra: nil)
67
+ size = lc_option!(:size, size, TailwindHelper::CONTROL_SIZES.keys)
68
+ return lc_tw(INPUT_PLAIN, extra) if plain
69
+
70
+ lc_tw(INPUT_BASE, TailwindHelper::CONTROL_SIZES.fetch(size), extra)
63
71
  end
64
72
 
65
73
 
@@ -5,6 +5,12 @@ module Lostcoords::Ui
5
5
  LIST_ROW_PADDING = "px-content py-heading sm:px-inset"
6
6
  LIST_ICON = "grid size-10 shrink-0 place-items-center rounded-full bg-tile [&>svg:not([class*='size-'])]:size-4.5"
7
7
  LIST_ROW_TAGS = %i[div li label details a].freeze
8
+ LIST_FIELD_TAGS = %i[div fieldset span].freeze
9
+ LIST_FIELD = "@container px-content py-2.5 transition-colors duration-(--lc-motion-quick) has-[[data-plain]:focus]:bg-accent"
10
+ 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)]"
11
+ LIST_FIELD_LABEL =
12
+ "flex items-center gap-related text-label font-semibold text-muted-foreground " \
13
+ "[&_svg]:size-5 [&_svg]:shrink-0 @md:[&_svg]:size-4.5"
8
14
 
9
15
  # A titled group of list rows: the heading, then the block, then an optional footnote. The block
10
16
  # holds lc_list_group and anything that belongs with it, such as the form that wraps the rows.
@@ -44,6 +50,30 @@ module Lostcoords::Ui
44
50
  content_tag(tag, (capture(&block) if block), **lc_attributes(defaults.merge(class: classes), attributes))
45
51
  end
46
52
 
53
+ # A form row: a label column, then the block as the control. In a narrow row the label folds to
54
+ # icon: alone and stays the accessible name. id: makes the label a <label> for that control;
55
+ # tag: :fieldset names a group of controls with a legend. surface: false drops the row's panel,
56
+ # for a row drawn inside another element, such as a collapsible's summary (with tag: :span).
57
+ def lc_list_field(label, icon: nil, id: nil, tag: :div, surface: true, **attributes, &block)
58
+ lc_label!(label, :label)
59
+ tag = lc_option!(:tag, tag, LIST_FIELD_TAGS)
60
+ raise ArgumentError, "id: labels one control; a fieldset is named by its legend" if id && tag == :fieldset
61
+
62
+ inline = tag == :span ? :span : :div
63
+ text = content_tag(:span, label, class: "@max-md:sr-only", data: { slot: "list-field-text" })
64
+ glyph = (icon.is_a?(ActiveSupport::SafeBuffer) ? icon : lc_icon(icon, options: { "aria-hidden": true })) if icon.present?
65
+ label_classes = lc_tw(LIST_FIELD_LABEL, ("self-start min-h-control-sm" if tag == :fieldset))
66
+ label_tag = if id
67
+ content_tag(:label, safe_join([ glyph, text ].compact), for: id, class: label_classes, data: { slot: "list-field-label" })
68
+ else
69
+ content_tag(:span, safe_join([ glyph, text ].compact), class: label_classes, aria: { hidden: (true if tag == :fieldset) }, data: { slot: "list-field-label" })
70
+ end
71
+ grid = content_tag(inline, safe_join([ label_tag, (capture(&block) if block) ].compact), class: LIST_FIELD_GRID)
72
+ legend = content_tag(:legend, label, class: "sr-only") if tag == :fieldset
73
+ classes = lc_tw((LIST_ROW if surface), LIST_FIELD, ("block" if tag == :span), ("m-0 min-w-0 border-0" if tag == :fieldset))
74
+ content_tag(tag, safe_join([ legend, grid ].compact), **lc_attributes({ class: classes, data: { slot: "list-field" } }, attributes))
75
+ end
76
+
47
77
  # The row layout without the row's surface, for an element inside a free-form row: a summary, a
48
78
  # button that opens an editor. icon: takes an icon name or your own markup, such as a logo.
49
79
  def lc_list_item(title, subtitle: nil, icon: nil, tag: :div, **attributes, &block)
@@ -35,6 +35,9 @@ module Lostcoords::Ui
35
35
 
36
36
  MENU_TRIGGERS = %i[button icon].freeze
37
37
 
38
+ MENU_GROUP_BASE = "col-span-full grid grid-cols-subgrid gap-y-px"
39
+ MENU_GROUP_LABEL = "col-span-full px-3 pt-2 pb-1"
40
+
38
41
  def lc_popover_class(align: :end, extra: nil)
39
42
  lc_glass_class(shape: :menu, extra: lc_tw(POPOVER_BASE, MENU_POPOVER_ALIGN.fetch(lc_option!(:align, align, MENU_POPOVER_ALIGN.keys)), extra))
40
43
  end
@@ -98,6 +101,14 @@ module Lostcoords::Ui
98
101
  end
99
102
  end
100
103
 
104
+ # A labelled run of options inside a menu panel. Its options stay on the menu's columns.
105
+ def lc_menu_group(label, id:, **attributes, &block)
106
+ lc_label!(label, :label)
107
+ lc_label!(id, :id)
108
+ heading = lc_text(label, size: :eyebrow, tone: :muted, as: :div, id: "#{id}-label", class: MENU_GROUP_LABEL, role: "presentation")
109
+ tag.div(safe_join([ heading, capture(&block) ]), **lc_attributes({ class: MENU_GROUP_BASE, data: { slot: "menu-group" } }, attributes, { id: id, role: "group", aria: { labelledby: "#{id}-label" } }))
110
+ end
111
+
101
112
  private
102
113
  def lc_panel_trigger(label, trigger, icon, variant, attributes)
103
114
  custom = trigger.is_a?(String) && trigger.html_safe?
@@ -27,14 +27,14 @@ module Lostcoords::Ui
27
27
  dock: {
28
28
  list: "m-0 grid list-none grid-flow-col auto-cols-fr gap-0.5 rounded-pill p-tight",
29
29
  link: "min-h-14 flex-col justify-center gap-0.5 rounded-pill px-0 text-caption font-semibold hover:bg-transparent [&_svg]:size-6",
30
- indicator: "rounded-pill"
30
+ indicator: "rounded-pill bg-(--lc-nav-dock-indicator,var(--lc-nav-indicator,var(--accent)))"
31
31
  },
32
32
  responsive: {
33
33
  list: "m-0 list-none p-0 max-sm:grid max-sm:grid-flow-col max-sm:auto-cols-fr max-sm:gap-0.5 max-sm:rounded-pill max-sm:p-tight " \
34
34
  "sm:flex sm:min-w-0 sm:flex-wrap sm:items-center sm:gap-tight",
35
35
  link: "justify-center max-sm:min-h-14 max-sm:flex-col max-sm:gap-0.5 max-sm:rounded-pill max-sm:px-0 max-sm:text-caption " \
36
36
  "max-sm:font-semibold max-sm:hover:bg-transparent max-sm:[&_svg]:size-6 sm:shrink-0 sm:[&_svg]:size-4.5",
37
- indicator: "max-sm:rounded-pill sm:rounded-xl lc-squircle"
37
+ indicator: "max-sm:rounded-pill max-sm:bg-(--lc-nav-dock-indicator,var(--lc-nav-indicator,var(--accent))) sm:rounded-xl lc-squircle"
38
38
  }
39
39
  }.freeze
40
40
  NAV_INDICATOR = "pointer-events-none absolute start-0 top-0 bg-(--lc-nav-indicator,var(--accent)) opacity-0 " \
@@ -1,7 +1,22 @@
1
1
  module Lostcoords::Ui
2
2
  module PrimitivesHelper
3
- def lc_button(content = nil, variant: :primary, tone: :default, size: :md, block: false, icon: nil, icon_position: :start, **attributes, &content_block)
4
- tag.button(lc_button_content(content, icon, icon_position, &content_block), **lc_button_attributes(variant, tone, size, block, { type: "button" }, attributes))
3
+ BUTTON_EXPANDED_SWAP = "[&>[data-slot=button-expanded-icon]]:hidden aria-expanded:[&>[data-slot=button-label]]:sr-only aria-expanded:[&>[data-slot=button-expanded-icon]]:block"
4
+
5
+ # as: :span renders the look without a control, for a decorative button inside a larger target
6
+ # such as a file drop zone's label. expanded_icon: swaps the content for that icon while
7
+ # aria-expanded is true; the content stays as the accessible name.
8
+ def lc_button(content = nil, variant: :primary, tone: :default, size: :md, block: false, icon: nil, icon_position: :start, as: :button, expanded_icon: nil, **attributes, &content_block)
9
+ as = lc_option!(:as, as, %i[button span])
10
+ content = lc_button_content(content, icon, icon_position, &content_block)
11
+ if expanded_icon
12
+ content = safe_join([
13
+ tag.span(content, class: "inline-flex items-center gap-related", data: { slot: "button-label" }),
14
+ lc_icon(expanded_icon, options: { "aria-hidden": true, "data-slot": "button-expanded-icon" })
15
+ ])
16
+ attributes = lc_attributes({ class: BUTTON_EXPANDED_SWAP }, attributes)
17
+ end
18
+ attributes = lc_button_attributes(variant, tone, size, block, (as == :button ? { type: "button" } : {}), attributes)
19
+ tag.public_send(as, content, **attributes)
5
20
  end
6
21
 
7
22
  def lc_button_link_to(content = nil, url = nil, variant: :primary, tone: :default, size: :md, block: false, icon: nil, icon_position: :start, **attributes, &content_block)
@@ -71,20 +86,20 @@ module Lostcoords::Ui
71
86
  tag.div(safe_join([ primary, toggle, popover ]), **lc_attributes(defaults, attributes))
72
87
  end
73
88
 
74
- def lc_icon_button(label, icon: nil, size: :md, shape: :circle, **attributes, &content)
75
- attributes = lc_icon_button_attributes(label, size, shape, { type: "button" }, attributes)
89
+ def lc_icon_button(label, icon: nil, size: :md, shape: :circle, variant: :ghost, tone: :default, **attributes, &content)
90
+ attributes = lc_icon_button_attributes(label, size, shape, variant, tone, { type: "button" }, attributes)
76
91
  tag.button(lc_icon_button_content(icon, &content), **attributes)
77
92
  end
78
93
 
79
- def lc_icon_button_link_to(label, url, icon: nil, size: :md, shape: :circle, **attributes, &content)
80
- attributes = lc_icon_button_attributes(label, size, shape, {}, attributes)
94
+ def lc_icon_button_link_to(label, url, icon: nil, size: :md, shape: :circle, variant: :ghost, tone: :default, **attributes, &content)
95
+ attributes = lc_icon_button_attributes(label, size, shape, variant, tone, {}, attributes)
81
96
  raise ArgumentError, "Links cannot be disabled; use lc_icon_button for a disabled control" if attributes[:disabled]
82
97
 
83
98
  link_to(lc_icon_button_content(icon, &content), url, attributes)
84
99
  end
85
100
 
86
- def lc_icon_button_to(label, url, icon: nil, size: :md, shape: :circle, **attributes, &content)
87
- button_to(lc_icon_button_content(icon, &content), url, lc_icon_button_attributes(label, size, shape, {}, attributes))
101
+ def lc_icon_button_to(label, url, icon: nil, size: :md, shape: :circle, variant: :ghost, tone: :default, **attributes, &content)
102
+ button_to(lc_icon_button_content(icon, &content), url, lc_icon_button_attributes(label, size, shape, variant, tone, {}, attributes))
88
103
  end
89
104
 
90
105
  def lc_badge(content = nil, tone: :neutral, shape: :rounded, **attributes, &block)
@@ -188,10 +203,11 @@ module Lostcoords::Ui
188
203
  lc_attributes(defaults.merge(class: lc_button_class(variant: variant, tone: tone, size: size, block: block), data: data), attributes)
189
204
  end
190
205
 
191
- def lc_icon_button_attributes(label, size, shape, defaults, attributes)
206
+ def lc_icon_button_attributes(label, size, shape, variant, tone, defaults, attributes)
192
207
  size = lc_option!(:size, size, ButtonHelper::ICON_BUTTON_SIZES.keys)
193
208
  shape = lc_option!(:shape, shape, ButtonHelper::ICON_BUTTON_SHAPES.keys)
194
- defaults = defaults.merge(class: lc_icon_button_class(size: size, shape: shape), aria: { label: label }, data: { slot: "icon-button", size: size })
209
+ 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
210
+ defaults = defaults.merge(class: lc_icon_button_class(size: size, shape: shape, variant: variant, tone: tone), aria: { label: label }, data: data)
195
211
  attributes = lc_attributes(defaults, attributes)
196
212
  accessible_label = attributes.fetch(:"aria-label", attributes.dig(:aria, :label))
197
213
  raise ArgumentError, "lc_icon_button requires a nonblank accessible label" if label.blank? || accessible_label.blank?
@@ -55,7 +55,7 @@ module Lostcoords::Ui
55
55
  end
56
56
 
57
57
  def lc_option!(name, value, allowed)
58
- normalized = value.to_sym if value.is_a?(String) || value.is_a?(Symbol)
58
+ normalized = value.is_a?(Integer) ? 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(', ')}"
@@ -11,17 +11,21 @@ module Lostcoords::Ui
11
11
  # - The block: rows rendered there are filtered in the browser by their text and keywords.
12
12
  # - Your own code: handle lc-search:query, call preventDefault and fill event.detail.results.
13
13
  #
14
- # The block also renders what shows before anything is typed. Pass id: when a page has two searches,
15
- # and shortcut: nil to drop the page shortcut.
16
- def lc_search(label:, src: nil, param: "q", placeholder: label, trigger: lc_t("lostcoords.ui.search.trigger"), shortcut: "mod+k", id: "lc-search", **attributes, &block)
14
+ # The block also renders what shows before anything is typed. empty: is the note for a query with
15
+ # no results, where %{query} stands for the query, and prompt: the note shown before anything is
16
+ # typed when there is nothing else to show. Pass id: when a page has two searches, and shortcut: nil
17
+ # to drop the page shortcut.
18
+ def lc_search(label:, src: nil, param: "q", placeholder: label, trigger: lc_t("lostcoords.ui.search.trigger"), empty: lc_t("lostcoords.ui.search.empty"), prompt: nil,
19
+ shortcut: "mod+k", id: "lc-search", **attributes, &block)
17
20
  lc_label!(label, :label)
18
21
  lc_label!(trigger, :trigger)
19
22
  lc_label!(param, :param)
20
23
  lc_label!(id, :id)
24
+ lc_label!(empty, :empty)
21
25
  defaults = { class: "lc-search-trigger", aria: { label: label } }
22
26
  data = { lc_search_target: "trigger", action: "lc-search#open", slot: "search-trigger" }
23
27
  required = { type: "button", aria: { haspopup: "dialog", controls: id }, data: shortcut ? lc_shortcut_data(shortcut, data) : data }
24
- render "lostcoords/ui/components/lc_search", id:, label:, src:, param:, placeholder:, trigger:, shortcut:,
28
+ render "lostcoords/ui/components/lc_search", id:, label:, src:, param:, placeholder:, trigger:, empty:, prompt: prompt.presence, shortcut:,
25
29
  attributes: lc_attributes(defaults, attributes, required), content: (capture(&block) if block)
26
30
  end
27
31
 
@@ -2,10 +2,11 @@ module Lostcoords::Ui
2
2
  module StructuresHelper
3
3
  INPUT_TYPES = %i[text search email password tel url number date time datetime-local month week].freeze
4
4
 
5
- def lc_input(name: nil, value: nil, type: :text, size: :md, **attributes)
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
7
  type = lc_option!(:type, type, INPUT_TYPES)
7
- size = lc_option!(:size, size, TailwindHelper::CONTROL_SIZES.keys)
8
- tag.input(**lc_attributes({ type: type, name: name, value: value, class: lc_input_class(size: size), data: { slot: "input" } }, attributes))
8
+ 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))
9
10
  end
10
11
 
11
12
  def lc_textarea(content = nil, name: nil, **attributes, &block)
@@ -58,15 +59,19 @@ module Lostcoords::Ui
58
59
  # name: makes native radios inside labels, which bring their own arrows, form value and reset;
59
60
  # as: :nav makes links, the current one marked with aria-current; otherwise radio buttons whose
60
61
  # selection lives in the lc-selection controller.
61
- def lc_toggle_group(label:, name: nil, value: nil, as: :div, **attributes, &block)
62
+ # variant: :pills lays the items out as wrapping toggle pills, sized by size:, instead of a segmented track.
63
+ def lc_toggle_group(label:, name: nil, value: nil, as: :div, variant: :segmented, size: :md, **attributes, &block)
62
64
  lc_label!(label, :label)
63
65
  as = lc_option!(:as, as, %i[div nav])
66
+ variant = lc_option!(:variant, variant, %i[segmented pills])
67
+ size = lc_option!(:size, size, ButtonHelper::BUTTON_SIZES.keys)
68
+ raise ArgumentError, "size: sizes pills; a segmented toggle group has one size" if variant == :segmented && size != :md
64
69
  raise ArgumentError, "a nav toggle group marks its current link; it takes no name: or value:" if as == :nav && (name || value)
65
70
 
66
71
  mode = as == :nav ? :links : (name ? :radios : :buttons)
67
- content = lc_within_toggle_group({ mode: mode, name: name, value: value&.to_s }) { capture(&block) if block }
72
+ content = lc_within_toggle_group({ mode: mode, name: name, value: value&.to_s, variant: variant, size: size }) { capture(&block) if block }
68
73
 
69
- defaults = { class: lc_toggle_group_class, data: { slot: "toggle-group" } }
74
+ defaults = { class: (variant == :pills ? lc_inline_class : lc_toggle_group_class), data: { slot: "toggle-group" } }
70
75
  case mode
71
76
  when :links
72
77
  tag.nav(content, **lc_attributes(defaults, attributes, { aria: { label: label } }))
@@ -81,7 +86,7 @@ module Lostcoords::Ui
81
86
  # Takes href: and current: in a nav group, value: and checked: in a named group, and value: and
82
87
  # selected: in a button group; arguments from another kind of group raise.
83
88
  def lc_toggle_group_item(label = nil, value: nil, selected: nil, checked: nil, href: nil, current: nil, input: {}, **attributes, &block)
84
- group = @_lc_toggle_group || { mode: :buttons }
89
+ group = @_lc_toggle_group || { mode: :buttons, variant: :segmented }
85
90
  given = { value: value, selected: selected, checked: checked, href: href, current: current }.compact.keys
86
91
  allowed = { links: %i[href current], radios: %i[value checked], buttons: %i[value selected] }.fetch(group[:mode])
87
92
  stray = given - allowed
@@ -89,11 +94,11 @@ module Lostcoords::Ui
89
94
  raise ArgumentError, "an item of a nav toggle group needs href:" if group[:mode] == :links && !href
90
95
 
91
96
  content = block ? capture(&block) : label
92
- defaults = { class: lc_toggle_group_item_class, data: { slot: "toggle-group-item" } }
97
+ defaults = { class: (group[:variant] == :pills ? lc_toggle_class(size: group[:size]) : lc_toggle_group_item_class), data: { slot: "toggle-group-item" } }
93
98
  return lc_toggle_link(content, href, current, defaults, attributes) if group[:mode] == :links
94
99
 
95
100
  value ||= label
96
- lc_label!(value, :value)
101
+ raise ArgumentError, "a toggle group item needs a value: or a label" if value.nil?
97
102
  if group[:mode] == :radios
98
103
  checked = group[:value] == value.to_s if checked.nil?
99
104
  return lc_toggle_radio(content, group[:name], value, checked, input, defaults, attributes)
@@ -19,9 +19,16 @@ export default class extends Controller {
19
19
  "results",
20
20
  "result",
21
21
  "empty",
22
+ "prompt",
22
23
  "status",
23
24
  ]
24
- static values = { src: String, param: { type: String, default: "q" }, one: String, other: String }
25
+ static values = {
26
+ src: String,
27
+ param: { type: String, default: "q" },
28
+ empty: String,
29
+ one: String,
30
+ other: String,
31
+ }
25
32
 
26
33
  connect() {
27
34
  this.animations = []
@@ -139,6 +146,7 @@ export default class extends Controller {
139
146
  this.request = request
140
147
  const url = new URL(this.srcValue, location.href)
141
148
  url.searchParams.set(this.paramValue, query)
149
+ this.busy(true)
142
150
  this.loading = fetch(url, { headers: { Accept: "text/html" }, signal: request.signal })
143
151
  .then((response) => {
144
152
  if (!response.ok) throw new Error(`${url} answered ${response.status}`)
@@ -146,15 +154,26 @@ export default class extends Controller {
146
154
  })
147
155
  .then((html) => {
148
156
  if (this.request !== request) return
149
- this.resultsTarget.innerHTML = html
150
157
  this.loaded = query
158
+ this.busy(false)
159
+ this.resultsTarget.innerHTML = html
151
160
  })
152
161
  .catch((error) => {
153
- if (error.name !== "AbortError") console.error(error)
162
+ if (error.name === "AbortError") return
163
+ console.error(error)
164
+ if (this.request === request) this.busy(false)
154
165
  })
155
166
  return this.loading
156
167
  }
157
168
 
169
+ // While the server answers, the empty and prompt notes wait, so they never flash before results.
170
+ busy(pending) {
171
+ this.pending = pending
172
+ if (pending) this.panelTarget.setAttribute("aria-busy", "true")
173
+ else this.panelTarget.removeAttribute("aria-busy")
174
+ this.refresh()
175
+ }
176
+
158
177
  filter(query) {
159
178
  const words = query.toLowerCase().split(/\s+/).filter(Boolean)
160
179
  for (const result of this.resultTargets) {
@@ -183,8 +202,8 @@ export default class extends Controller {
183
202
  return this.resultTargets.filter((result) => result.checkVisibility())
184
203
  }
185
204
 
186
- // Groups without a visible result hide, the empty note shows for a query with no results,
187
- // and the status announces the count.
205
+ // Groups without a visible result hide, the empty note shows for a query with no results, the
206
+ // prompt for no query and nothing to show, and the status announces the count.
188
207
  refresh() {
189
208
  for (const group of this.resultsTarget.querySelectorAll("[data-slot=search-group]")) {
190
209
  group.hidden = ![...group.querySelectorAll("[data-slot=search-result]")].some(
@@ -195,8 +214,13 @@ export default class extends Controller {
195
214
  (result) => !result.hidden && !result.closest("[hidden]"),
196
215
  ).length
197
216
  const query = this.query
198
- this.emptyTarget.hidden = count > 0 || !query
199
- this.panelTarget.hidden = count === 0 && this.emptyTarget.hidden
217
+ const settled = !this.pending && count === 0
218
+ this.emptyTarget.hidden = !(settled && query)
219
+ if (!this.emptyTarget.hidden)
220
+ this.emptyTarget.textContent = this.emptyValue.replace("%{query}", query)
221
+ if (this.hasPromptTarget) this.promptTarget.hidden = !(settled && !query)
222
+ const note = !this.emptyTarget.hidden || (this.hasPromptTarget && !this.promptTarget.hidden)
223
+ this.panelTarget.hidden = count === 0 && !note
200
224
  this.statusTarget.textContent = query
201
225
  ? (count === 1 ? this.oneValue : this.otherValue).replace("%{count}", count)
202
226
  : ""
@@ -1,4 +1,4 @@
1
- <%# locals: (id:, title:, description:, trigger:, detents:, close_action:, close_label:, attributes:, actions:, content:) %>
1
+ <%# locals: (id:, title:, description:, trigger:, rendered_trigger:, detents:, close_action:, close_label:, attributes:, actions:, content:) %>
2
2
  <% dialog = lc_sheet(tag: :dialog, detents: detents, **attributes) do %>
3
3
  <div class="flex min-h-0 flex-col gap-inset p-inset sm:h-full sm:max-h-[inherit]" data-slot="dialog-content">
4
4
  <header class="flex shrink-0 items-start justify-between gap-content" data-slot="dialog-header">
@@ -16,7 +16,11 @@
16
16
  <% end %>
17
17
  <% if trigger %>
18
18
  <div data-controller="lc-dialog">
19
- <button type="button" class="<%= lc_button_class(variant: :secondary) %>" aria-haspopup="dialog" aria-controls="<%= id %>" data-action="lc-dialog#open" data-slot="dialog-trigger"><%= trigger %></button>
19
+ <% if rendered_trigger %>
20
+ <%= rendered_trigger %>
21
+ <% else %>
22
+ <button type="button" class="<%= lc_button_class(variant: :secondary) %>" aria-haspopup="dialog" aria-controls="<%= id %>" data-action="lc-dialog#open" data-slot="dialog-trigger"><%= trigger %></button>
23
+ <% end %>
20
24
  <%= dialog %>
21
25
  </div>
22
26
  <% else %>
@@ -1,5 +1,5 @@
1
- <%# locals: (id:, label:, src:, param:, placeholder:, trigger:, shortcut:, attributes:, content:) %>
2
- <div class="contents" data-slot="search" data-controller="lc-search" data-action="turbo:before-cache@document->lc-search#reset" data-lc-search-src-value="<%= src %>" data-lc-search-param-value="<%= param %>" data-lc-search-one-value="<%= lc_t("lostcoords.ui.search.results.one", count: "%{count}") %>" data-lc-search-other-value="<%= lc_t("lostcoords.ui.search.results.other", count: "%{count}") %>">
1
+ <%# locals: (id:, label:, src:, param:, placeholder:, trigger:, empty:, prompt:, shortcut:, attributes:, content:) %>
2
+ <div class="contents" data-slot="search" data-controller="lc-search" data-action="turbo:before-cache@document->lc-search#reset" data-lc-search-src-value="<%= src %>" data-lc-search-param-value="<%= param %>" data-lc-search-empty-value="<%= empty %>" data-lc-search-one-value="<%= lc_t("lostcoords.ui.search.results.one", count: "%{count}") %>" data-lc-search-other-value="<%= lc_t("lostcoords.ui.search.results.other", count: "%{count}") %>">
3
3
  <%= tag.button(**attributes) do %>
4
4
  <%= lc_icon "magnifying-glass", options: { class: "size-4 shrink-0", "aria-hidden": true } %>
5
5
  <span class="flex-1 truncate text-start max-sm:sr-only"><%= trigger %></span>
@@ -17,7 +17,8 @@
17
17
  <% end %>
18
18
  <div class="<%= lc_glass_class(shape: :panel, extra: "lc-search-panel min-h-0 overflow-y-auto overscroll-contain p-related") %>" data-lc-search-target="panel" data-slot="search-panel">
19
19
  <div data-lc-search-target="results" data-slot="search-results"><%= content %></div>
20
- <p class="px-content py-10 text-center text-label text-muted-foreground" data-lc-search-target="empty" data-slot="search-empty" hidden><%= lc_t("lostcoords.ui.search.empty") %></p>
20
+ <p class="px-content py-10 text-center text-label text-muted-foreground" data-lc-search-target="empty" data-slot="search-empty" hidden><%= empty.sub("%{query}", "") %></p>
21
+ <% if prompt %><p class="px-content py-10 text-center text-label text-muted-foreground" data-lc-search-target="prompt" data-slot="search-prompt" hidden><%= prompt %></p><% end %>
21
22
  </div>
22
23
  <p class="sr-only" role="status" aria-atomic="true" data-lc-search-target="status"></p>
23
24
  </div>
@@ -72,13 +72,29 @@ module Lostcoords::Ui
72
72
  def to_hash = @control
73
73
  end
74
74
 
75
+ # trigger yields the attributes that wire an element to open the panel, merged with the ones passed
76
+ # to it, and the element it renders replaces the default trigger. Shared by menus and dialogs.
77
+ module CustomTrigger
78
+ attr_reader :rendered_trigger
79
+
80
+ def trigger(**attributes, &block)
81
+ raise ArgumentError, "trigger needs a block that renders the trigger element" unless block
82
+
83
+ @rendered_trigger = view.capture(view.send(:lc_attributes, attributes, {}, @wiring), &block)
84
+ nil
85
+ end
86
+ end
87
+
75
88
  class Dialog < Base
89
+ include CustomTrigger
90
+
76
91
  attr_reader :header_actions
77
92
 
78
93
  def initialize(view, id, close_action = "lc-dialog#close")
79
94
  super(view)
80
95
  @id = id
81
96
  @close_action = close_action
97
+ @wiring = { aria: { haspopup: "dialog", controls: id }, data: { action: "lc-dialog#open" } }
82
98
  end
83
99
 
84
100
  # Content placed in the header, before the close button. Renders nothing where it is called.
@@ -179,22 +195,13 @@ module Lostcoords::Ui
179
195
  end
180
196
  end
181
197
 
182
- # menu.trigger yields the attributes that wire an element as the panel's trigger, merged with
183
- # the ones passed to it, and the element it renders replaces the default trigger.
184
198
  class Panel < Base
185
- attr_reader :rendered_trigger
199
+ include CustomTrigger
186
200
 
187
201
  def initialize(view, wiring)
188
202
  super(view)
189
203
  @wiring = wiring
190
204
  end
191
-
192
- def trigger(**attributes, &block)
193
- raise ArgumentError, "trigger needs a block that renders the trigger element" unless block
194
-
195
- @rendered_trigger = view.capture(view.send(:lc_attributes, attributes, {}, @wiring), &block)
196
- nil
197
- end
198
205
  end
199
206
 
200
207
  class DescriptionList < Base
@@ -1,5 +1,5 @@
1
1
  module Lostcoords
2
2
  module Ui
3
- VERSION = "0.8.0"
3
+ VERSION = "0.8.1"
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.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lost Coordinates