lostcoords-ui 0.9.3 → 0.11.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.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +164 -4
  3. data/app/assets/tailwind/lostcoords/ui/components/hovercard.css +4 -0
  4. data/app/assets/tailwind/lostcoords/ui/components/shell.css +2 -2
  5. data/app/assets/tailwind/lostcoords/ui/components.css +1 -0
  6. data/app/assets/tailwind/lostcoords/ui/core.css +2 -1
  7. data/app/assets/tailwind/lostcoords/ui/hovercard.css +47 -0
  8. data/app/assets/tailwind/lostcoords/ui/shell.css +66 -9
  9. data/app/assets/tailwind/lostcoords/ui/toggle-group.css +58 -0
  10. data/app/helpers/lostcoords/ui/badge_helper.rb +9 -7
  11. data/app/helpers/lostcoords/ui/description_list_helper.rb +39 -0
  12. data/app/helpers/lostcoords/ui/form_helper.rb +4 -4
  13. data/app/helpers/lostcoords/ui/hovercard_helper.rb +31 -0
  14. data/app/helpers/lostcoords/ui/layout_helper.rb +31 -0
  15. data/app/helpers/lostcoords/ui/navigation_helper.rb +13 -0
  16. data/app/helpers/lostcoords/ui/primitives_helper.rb +20 -2
  17. data/app/helpers/lostcoords/ui/shell_helper.rb +32 -1
  18. data/app/helpers/lostcoords/ui/structures_helper.rb +65 -14
  19. data/app/helpers/lostcoords/ui/typography_helper.rb +30 -0
  20. data/app/javascript/lostcoords/ui/controllers/lc_char_counter_controller.js +63 -0
  21. data/app/javascript/lostcoords/ui/controllers/lc_hovercard_controller.js +104 -0
  22. data/app/javascript/lostcoords/ui/controllers/lc_sidebar_controller.js +48 -0
  23. data/app/javascript/lostcoords/ui/helpers/dismiss_stack.js +1 -1
  24. data/app/javascript/lostcoords/ui/index.js +6 -0
  25. data/config/locales/en.yml +14 -0
  26. data/config/locales/es.yml +14 -0
  27. data/config/locales/ja.yml +14 -0
  28. data/lib/lostcoords/ui/parts.rb +86 -0
  29. data/lib/lostcoords/ui/version.rb +1 -1
  30. metadata +8 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d402851fc66b028bc97b880c2397d3c8a2d612284d0f51ddec90e6ba3a0ee2bb
4
- data.tar.gz: 2d5856ffb98d6bc1326a6270237fc31c0fb8dffd6f6581a4c53830a97c042a40
3
+ metadata.gz: 2054816b6a7ff56d849935ab460b5b507d18e75f0bad9153ff12aa3325c6e336
4
+ data.tar.gz: 306f6d0f412c0bb972290c9436f5020e8a1c29cb90ff757384ca596a6590124c
5
5
  SHA512:
6
- metadata.gz: 0f0d50a8f0baf942139ab75986fbe8b4316926e74d86ca5a5c88f0401828c809ad4479ee9035befd70d38e1195c4da293c4629f25d06d4d3a05ef75399fbe373
7
- data.tar.gz: 5300070c7fa90987821000e3a7494d76a66e1e462c0ca0a169804137d14be1cb6ecdd4eab1658dff5a2172ae9473022e1582b87ca05a4dda626cd32c957f3361
6
+ metadata.gz: ca0712c7a3f9cef74431634ffa1c1da04b6b0cc9299ab28dec6d446df45642161bf17dc8d5154101aff8a24865a992ad36ef02927c2541f8d4337d8af09ae229
7
+ data.tar.gz: f74402ec4c561044d13e22d61e7184213b1f930c41a6c953ce5fb2e927acf46f99dbf7f189689ab676d5a9647a2aa646655bf063088124e306bfc0bca5e1a1b2
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.9.1"
24
+ gem "lostcoords-ui", "~> 0.11.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
@@ -57,8 +57,8 @@ app's theme and keep your Tailwind theme declarations after the imports.
57
57
  `core.css` holds the tokens, buttons, badges, avatars, cards, alerts, form controls, choices,
58
58
  toggles, layout, typography and navigation. The opt-in entries are `dialog` (with the phone sheet),
59
59
  `menu` (menus and popovers), `toast`, `search`, `tooltip`, `collapsible`, `code-block`,
60
- `emoji-picker`, `table`, `prose` and `shell` (`lc_app_header`, `lc_docs_shell` and `lc_dock`; the dock's action
61
- menu also needs `menu`). A component whose entry is missing renders unstyled.
60
+ `emoji-picker`, `table`, `prose` and `shell` (`lc_app_header`, `lc_sidebar`, `lc_docs_shell` and `lc_dock`; the
61
+ dock's action menu and the sidebar's account menu also need `menu`). A component whose entry is missing renders unstyled.
62
62
 
63
63
  The gem's stylesheets write into the `components` and `modules` layers, so the host declares that layer order.
64
64
  The theme defines the `dark:` variant with `html[data-theme="dark"]`, and with `html[data-theme="system"]` under an OS dark preference. Each entry carries its own `@source` lines, so Tailwind
@@ -170,6 +170,51 @@ 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.11.0
174
+
175
+ Nothing needs an edit. New:
176
+
177
+ - **`lc_hovercard` previews what a link points to**, such as a profile card over a name, with the
178
+ `lc-hovercard` controller, in the `components` entry. It opens on hover or keyboard focus, takes its card
179
+ as `content:` or loads it lazily from `src:`, and keeps the card out of the accessibility tree as a
180
+ preview of the linked page.
181
+
182
+ ## Changes in 0.10.0
183
+
184
+ Nothing needs an edit, but toggles look different:
185
+
186
+ - **A selected toggle pill fills solid.** Before: a pressed, checked or current `lc_toggle` (and a
187
+ `variant: :pills` toggle group item) had a soft primary fill, a primary edge and primary ink. After: it
188
+ fills with `--primary` and `--primary-foreground` ink over a transparent border, so selecting never shifts
189
+ its edge. A host that restyled the soft state for contrast can drop that override.
190
+ - **A segmented toggle group slides one indicator.** Items stretch to share the track, and their corners are
191
+ concentric with it. Where the browser supports anchor positioning, the current item's surface is one
192
+ indicator that slides from item to item, whichever state marks it (`aria-current`, `aria-selected`,
193
+ `aria-checked`, `aria-pressed`, a checked radio or `active:`); elsewhere each current item paints its own,
194
+ as before. Items carry `lc-toggle-group-item`, and the track `lc-toggle-group`.
195
+
196
+ New components and options, moved from apps that built them by hand:
197
+
198
+ - **`lc_tab_bar` is a row of links styled as underlined tabs.** The current tab is bold with a rounded
199
+ underline in `--lc-tab-bar-indicator`; `count:` adds a muted number and `fill: true` shares the row. Unlike
200
+ `lc_tabs`, each tab is a link to its own URL.
201
+ - **`lc_sidebar` is a sticky app sidebar that folds to an icon rail**, with the `lc-sidebar` controller, in the
202
+ `shell` entry. It keeps the reader's choice in a cookie the helper reads back, starts as a rail below
203
+ `rail_below:` unless expanded, and yields `sidebar.header` (with the toggle), `sidebar.body`, `sidebar.footer`
204
+ and `sidebar.account`, a row that opens an `lc_menu`. The `lc-rail:` variant styles your own content on the
205
+ rail, and `--lc-sidebar-indicator` paints the current link's bar. If you built a sidebar with a rail variant
206
+ and a cookie of your own, you can replace it and delete its stylesheet rules and controller.
207
+ - **`lc_stats` and `lc_stat` show headline numbers** in a description list, in a line or as tiles.
208
+ - **`lc_char_counter` is the character ring X shows under a post**, with the `lc-char-counter` controller. It
209
+ counts a field, or takes a count you supply for weighted characters.
210
+ - **`lc_time` renders the short relative time X shows**, "12m", "4h", "4 Nov", with the full date as its title.
211
+ - **`lc_split` and `lc_columns` lay out a main column beside an aside and balanced columns of groups**, with
212
+ `lc_split_class` and `lc_columns_class` for markup you render yourself.
213
+ - **`lc_empty_state` takes `title:`, `text:`, `icon:`, `level:` and `card:`** to lay out the usual empty state;
214
+ the block form still works.
215
+ - **`lc_toggle` takes `icon:`, `icon_only:` and `tooltip:`.** `icon_only: true` makes a square toggle of just the
216
+ icon whose label stays as its accessible name.
217
+
173
218
  ## Changes in 0.9.1
174
219
 
175
220
  Nothing needs an edit:
@@ -356,6 +401,8 @@ Badge, icon badge, Alert and Toast share `neutral`, `primary`, `success`, `warni
356
401
  `lc_toggle` renders a button that flips its own `aria-pressed`; set `aria-pressed` or `aria-expanded` yourself
357
402
  and it leaves the state to your controller. `href:` renders a link marked `aria-current` when active, and `name:`
358
403
  with `value:` a label around a visually hidden native radio, styled by `:checked`.
404
+ `icon:` adds a leading icon, and `icon_only: true` makes a square toggle of just that icon whose label stays as its
405
+ accessible name; `tooltip: true` shows the label on hover and focus, as on `lc_icon_button`.
359
406
  `lc_toggle_group` with `lc_toggle_group_item` holds mutually exclusive choices, and the group decides what its items are.
360
407
  With `name:` they are native radios in labels, which bring their own arrows, submitted value and reset; items take
361
408
  `value:` and `checked:`, and the group's `value:` checks the matching item. With `as: :nav` they are links in a
@@ -373,8 +420,37 @@ given another kind's arguments raises. `variant: :pills` lays any of them out as
373
420
  <%= lc_toggle_group_item "Annual", value: "annual" %>
374
421
  <% end %>
375
422
  <%= lc_toggle "Food", aria: { pressed: false }, data: { value: "food" } %>
423
+ <%= lc_toggle "Bold", icon: "bold", icon_only: true, tooltip: true %>
424
+ ```
425
+
426
+ `lc_empty_state(title:, text:, icon:)` lays out the usual empty state: a round icon badge, a heading
427
+ (`level:`, 2 by default), a line of muted text, then the block, such as an action. `card: true` puts it on a card.
428
+ Without those options the block is the whole content, as before.
429
+
430
+ ```erb
431
+ <%= lc_empty_state title: "No drafts yet", text: "Drafts appear here until you post them.", icon: "pencil-square", card: true do %>
432
+ <%= lc_button_link_to "New draft", new_draft_path, icon: "plus" %>
433
+ <% end %>
434
+ ```
435
+
436
+ `lc_stats` shows headline numbers as a description list of `lc_stat` items: the value in bold tabular figures
437
+ and its label in muted text. `layout: :inline` (the default) runs them along a line; `layout: :grid` gives each a
438
+ tile, in `columns:` 2, 3 or 4, or as many as fit. `tone:` colours a value with a status tone, and a block replaces
439
+ the value, such as a link around it.
440
+
441
+ ```erb
442
+ <%= lc_stats do %>
443
+ <%= lc_stat number_with_delimiter(@replies), label: "replies sent", tone: :primary %>
444
+ <%= lc_stat(label: "people") { link_to @people, people_path } %>
445
+ <% end %>
446
+ <%= lc_stats layout: :grid, columns: 2 do %>…<% end %>
376
447
  ```
377
448
 
449
+ `lc_time(time)` renders a `<time>` with the short text X shows: "now", "12m" and "4h" within a day, then
450
+ "4 Nov", and "4 Nov 2025" in another year. The full date and time is its title, and `detail:` adds to it. The
451
+ texts and date formats are translations under `lostcoords.ui.time`; month names come from the host's
452
+ `date.month_names`, as rails-i18n provides them, and fall back to English. `now:` sets the moment to count from.
453
+
378
454
  `lc_collapsible` expands content through a native `<details>` element. `lc_alert` renders persistent inline feedback;
379
455
  `lc_toast` adds timed dismissal.
380
456
 
@@ -485,6 +561,21 @@ attribute. `form.field … size: :sm` (or `lc_field size: :sm`) is the compact f
485
561
  with a caption label. Pass `builder: Lostcoords::Ui::FormBuilder` to `form_with` directly, or call `lc_field`
486
562
  with `error: record.errors.full_messages_for(:name)` when you keep your own builder.
487
563
 
564
+ `lc_char_counter(max:)` is the ring X shows under a post: it fills as a field nears `max:` characters, hides
565
+ while the field is empty, turns to the warning tone with the characters left once `warn:` (20) or fewer remain,
566
+ and to the destructive tone with a negative number past the limit. Its accessible name reads "120 of 280
567
+ characters". It counts the field whose id is `for:`, or the nearest field around it. To count another way,
568
+ such as X's weighted characters, set `data-lc-char-counter-count-value` or send it an event whose
569
+ `detail.count` is the count, as in `data: { action: "composer:count@window->lc-char-counter#update" }`; `count:` renders a count
570
+ before JavaScript runs.
571
+
572
+ ```erb
573
+ <%= lc_field label: "Post", id: "post" do |field| %>
574
+ <%= lc_textarea name: "post[text]", rows: 4, **field %>
575
+ <%= lc_char_counter max: 280, for: "post" %>
576
+ <% end %>
577
+ ```
578
+
488
579
  `lc_checkbox`, `lc_radio` and `lc_switch` render native inputs with a label and optional hint.
489
580
  Checkboxes and switches submit an unchecked value like Rails' `check_box`; pass `unchecked_value: nil`
490
581
  to omit it. A `nil` label renders the bare input, for a row selector the row labels; give it
@@ -517,6 +608,19 @@ Text that labels something other than one control, such as a list, uses `lc_text
517
608
  <% end %>
518
609
  ```
519
610
 
611
+ ```erb
612
+ <%= lc_tab_bar label: "Drafts", fill: true do |bar| %>
613
+ <%= bar.link "Open", drafts_path, current: true, count: @open_count %>
614
+ <%= bar.link "Posted", drafts_path(status: :posted), count: @posted_count %>
615
+ <% end %>
616
+ ```
617
+
618
+ `lc_tab_bar` is a row of links styled as underlined tabs, for the views of a page that each have a URL; use
619
+ `lc_tabs` when the panels live on one page. The current tab carries `aria-current="page"`, bold text and a
620
+ rounded underline in `--lc-tab-bar-indicator` (the primary color by default). `count:` adds a muted number after
621
+ the label, and `fill: true` stretches the tabs to share the row. A row too long for its container scrolls
622
+ sideways and fades at the edge it continues past.
623
+
520
624
  Tabs follow the ARIA tabs pattern with arrow key, Home and End navigation, and dispatch
521
625
  `lc-tabs:change`. `orientation: :vertical` stacks the tabs beside their panels and moves with Arrow Up
522
626
  and Down; `activation: :manual` moves focus with the arrows and selects with Enter or Space; `list:` adds attributes to the tab list. Icon buttons take `tooltip: true` to show their label, or `tooltip: "text"` to describe themselves
@@ -586,6 +690,41 @@ the reader has scrolled to. This documentation site is built with them.
586
690
  <% end %>
587
691
  ```
588
692
 
693
+ `lc_sidebar` is a sticky, full-height app sidebar that folds to an icon rail. Its toggle stores the choice in a
694
+ cookie (`cookie:`, `lc_sidebar` by default) that the helper reads back, so the server renders the next page the
695
+ same way; `state: "collapsed"` or `"expanded"` overrides it. Below `rail_below:` (`:xl` by default; `:md`, `:lg`,
696
+ `:2xl`, or `false` for never) it starts as a rail unless the reader expanded it. On the rail, `lc_nav_list` group
697
+ titles and link labels stay for screen readers only and links center their icons, so give each link a `title:`.
698
+ The current link gets a bar at the sidebar's edge in `--lc-sidebar-indicator` (any background, such as a
699
+ gradient). `--lc-sidebar-width` (15rem) and `--lc-sidebar-rail-width` (4rem) set the widths, and the `lc-rail:`
700
+ variant styles your own content on the rail, as in `lc-rail:hidden`. It dispatches `lc-sidebar:toggle` with
701
+ `{ collapsed }`.
702
+
703
+ ```erb
704
+ <%= lc_sidebar cookie: "sidebar" do |sidebar| %>
705
+ <%= sidebar.header do %>
706
+ <%= link_to root_path, aria: { label: "Acme home" } do %>
707
+ <span class="lc-rail:hidden">Acme</span><span class="hidden lc-rail:inline" aria-hidden="true">A</span>
708
+ <% end %>
709
+ <% end %>
710
+ <%= sidebar.body do %>
711
+ <%= lc_nav_list label: "Main", indicator: true do |nav| %>
712
+ <%= nav.link "Inbox", inbox_path, icon: "inbox", title: "Inbox", current: true %>
713
+ <% end %>
714
+ <% end %>
715
+ <%= sidebar.footer do %>
716
+ <%= sidebar.account current_user.name, detail: current_user.email, avatar: lc_avatar(current_user.initials, size: :sm) do %>
717
+ <%= lc_menu_option "Settings", icon: "cog-6-tooth", href: settings_path %>
718
+ <%= lc_menu_option "Sign out", href: session_path, method: :delete %>
719
+ <% end %>
720
+ <% end %>
721
+ <% end %>
722
+ ```
723
+
724
+ `sidebar.header` renders the toggle after its block (`toggle: false` leaves it out; `sidebar.toggle` renders it
725
+ anywhere). `sidebar.account` is a full-width row, the avatar, name, a detail line and an ellipsis, that opens an
726
+ `lc_menu` of the block's options; on the rail only the avatar shows.
727
+
589
728
  For rendered Markdown, such as a Kiln `.md` view, pass the HTML to both: `lc_prose(anchors: true) { html }`
590
729
  links its headings, and `lc_toc(headings: html)` lists them. On phones, `lc_dock` floats `dock.nav` and a
591
730
  `dock.menu` of quick actions at the bottom of the screen; render it last, since it reserves its height there.
@@ -687,6 +826,22 @@ hides.
687
826
  `lc-popover-shell` gives a native `[popover]` menu the same enter and exit as FloatingPanel panels. Set
688
827
  `--lc-popover-from` to change the closed pose and an `origin-*` utility for where it grows from.
689
828
 
829
+ `lc_hovercard` previews what a link points to, such as a profile over a name, with the `lc-hovercard`
830
+ controller. The card opens after a short hover, or at once on keyboard focus, in the top layer beside the
831
+ trigger, flips above it near the bottom of the screen, and stays open while the pointer crosses onto it.
832
+ Leaving both closes it, Escape closes it at once, and touch screens never open it, so a tap follows the
833
+ link. Splat the yielded attributes on the trigger. `content:` renders the card up front; `src:` loads it as
834
+ HTML from your endpoint the first time it opens, from the page's own origin only, so a long list of
835
+ triggers costs nothing until one is hovered, and a skeleton shows until then. The card is a preview: it is
836
+ hidden from assistive technology and its links leave the tab order, so keep everything in it reachable
837
+ from the page the link opens. Inside a paragraph, keep `content:` to phrasing elements such as spans.
838
+
839
+ ```erb
840
+ <%= lc_hovercard src: card_person_path(person) do |card| %>
841
+ <%= link_to person.name, person, **card %>
842
+ <% end %>
843
+ ```
844
+
690
845
  ### Search
691
846
 
692
847
  `lc_search` renders a search trigger, a pill with the ⌘K hint that shrinks to an icon on phones, and
@@ -873,7 +1028,10 @@ styles a kicker or footer column label; under `lang="ja"` it keeps natural case
873
1028
  Stacks and inline groups take the spacing names from [Foundations](#foundations). `lc_stack`, `lc_inline`,
874
1029
  `lc_text` and `lc_card` take `as:` to render a meaningful element, such as `lc_stack(as: :ul)`, `lc_text(as: :span)` or
875
1030
  `lc_card(as: :section)`. `lc_section` leaves
876
- `heading` below its title and `content` between blocks. `lc_section_header` is that heading row on its own,
1031
+ `heading` below its title and `content` between blocks. `lc_split` lays out a main column and an aside: one
1032
+ column on small screens, and from `lg` a flexible main beside an aside of `aside: :sm` (16rem), `:md` (20rem)
1033
+ or `:lg` (24rem). `lc_columns(count: 2)` flows groups, such as settings sections, into balanced columns from
1034
+ `lg` (`count: 3` adds a third from `xl`) without breaking a group across two. `lc_section_header` is that heading row on its own,
877
1035
  for a heading that needs more than a title, such as a lede under it. `lc_container` provides `page`, `reading` and
878
1036
  `form` widths; only the page container adds gutters. Japanese headings inherit `lang="ja"` and use
879
1037
  natural letter spacing.
@@ -956,6 +1114,8 @@ Generated by `bin/rails lostcoords:ui:builders`; `bin/lint` checks this list aga
956
1114
  - `lc_stack_class(gap: :content, extra: nil)` (LayoutHelper)
957
1115
  - `lc_inline_class(gap: :related, extra: nil)` (LayoutHelper)
958
1116
  - `lc_container_class(size: :page, extra: nil)` (LayoutHelper)
1117
+ - `lc_split_class(aside: :md, extra: nil)` (LayoutHelper)
1118
+ - `lc_columns_class(count: 2, extra: nil)` (LayoutHelper)
959
1119
  - `lc_section_header_class(extra: nil)` (LayoutHelper)
960
1120
  - `lc_popover_class(align: :end, extra: nil)` (MenuHelper)
961
1121
  - `lc_menu_popover_class(align: :end, extra: nil)` (MenuHelper)
@@ -0,0 +1,4 @@
1
+ /* lc_hovercard. */
2
+ @import "../hovercard.css";
3
+ @source "../../../../../helpers/lostcoords/ui/hovercard_helper.rb";
4
+ @source "../../../../../javascript/lostcoords/ui/controllers/lc_hovercard_controller.js";
@@ -1,4 +1,4 @@
1
- /* lc_app_header, lc_docs_shell and lc_dock. */
1
+ /* lc_app_header, lc_sidebar, lc_docs_shell and lc_dock. */
2
2
  @import "../shell.css";
3
3
  @source "../../../../../helpers/lostcoords/ui/shell_helper.rb";
4
- @source "../../../../../javascript/lostcoords/ui/controllers/lc_{app_header,dock}_controller.js";
4
+ @source "../../../../../javascript/lostcoords/ui/controllers/lc_{app_header,dock,sidebar}_controller.js";
@@ -6,6 +6,7 @@
6
6
  @import "./components/toast.css";
7
7
  @import "./components/search.css";
8
8
  @import "./components/tooltip.css";
9
+ @import "./components/hovercard.css";
9
10
  @import "./components/collapsible.css";
10
11
  @import "./components/code-block.css";
11
12
  @import "./components/emoji-picker.css";
@@ -5,7 +5,7 @@
5
5
  @import "./theme.css";
6
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";
7
7
  @source "../../../../javascript/lostcoords/ui/helpers/*.js";
8
- @source "../../../../javascript/lostcoords/ui/controllers/lc_{copy,kbd,nav,scroll_keeper,selection,shortcut,tabs,toc,toggle}_controller.js";
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";
10
10
 
11
11
  @import "./glass.css";
@@ -18,4 +18,5 @@
18
18
  @import "./layout.css";
19
19
  @import "./field.css";
20
20
  @import "./choice.css";
21
+ @import "./toggle-group.css";
21
22
  @import "./copy-button.css";
@@ -0,0 +1,47 @@
1
+ @layer components {
2
+ /* lc-hovercard lifts the card into the top layer while it shows. It keeps a
3
+ box while closed, invisible, so the lift can measure where it belongs. */
4
+ .lc-hovercard__content {
5
+ position: absolute;
6
+ inset-block-start: calc(100% + var(--spacing-related));
7
+ inset-inline-start: 0;
8
+ z-index: var(--lc-z-popover);
9
+ display: flex;
10
+ flex-direction: column;
11
+ inline-size: min(20rem, calc(100vw - 2rem));
12
+ overflow: visible;
13
+ margin: 0;
14
+ padding: var(--spacing-inset);
15
+ color: var(--popover-foreground);
16
+ text-align: start;
17
+ white-space: normal;
18
+ pointer-events: none;
19
+ opacity: 0;
20
+ visibility: hidden;
21
+ transform: translateY(calc(var(--spacing) * -1)) scale(0.98);
22
+
23
+ /* allow-discrete keeps a lifted card in the top layer while it fades out. */
24
+ transition:
25
+ opacity 160ms var(--lc-ease-out-expo),
26
+ transform 160ms var(--lc-ease-out-expo),
27
+ visibility 160ms,
28
+ display 160ms allow-discrete,
29
+ overlay 160ms allow-discrete;
30
+ }
31
+
32
+ .lc-hovercard[data-side="top"] > .lc-hovercard__content {
33
+ inset-block: auto calc(100% + var(--spacing-related));
34
+ transform: translateY(var(--spacing)) scale(0.98);
35
+ }
36
+
37
+ .lc-hovercard[data-open] > .lc-hovercard__content {
38
+ pointer-events: auto;
39
+ opacity: 1;
40
+ visibility: visible;
41
+ transform: none;
42
+ }
43
+
44
+ @media (prefers-reduced-motion: reduce) {
45
+ .lc-hovercard__content { transform: none; }
46
+ }
47
+ }
@@ -4,25 +4,81 @@
4
4
  --lc-sticky-offset: 5rem;
5
5
  }
6
6
 
7
- @layer components {
8
- .lc-app-header__glass {
9
- opacity: 0;
10
- transition: opacity 300ms ease;
7
+ /* lc_sidebar folds to an icon rail when the reader collapsed it, or below its
8
+ rail_below breakpoint unless they expanded it. lc-rail: styles anything in it
9
+ for the rail, as in lc-rail:hidden. */
10
+ @custom-variant lc-rail {
11
+ &:where(.lc-sidebar[data-collapsed], .lc-sidebar[data-collapsed] *) {
12
+ @slot;
13
+ }
14
+ @media (width < 48rem) {
15
+ &:where(.lc-sidebar[data-rail-below="md"]:not([data-expanded]), .lc-sidebar[data-rail-below="md"]:not([data-expanded]) *) {
16
+ @slot;
17
+ }
11
18
  }
12
-
13
- .lc-app-header[data-scrolled] .lc-app-header__glass {
14
- opacity: 1;
19
+ @media (width < 64rem) {
20
+ &:where(.lc-sidebar[data-rail-below="lg"]:not([data-expanded]), .lc-sidebar[data-rail-below="lg"]:not([data-expanded]) *) {
21
+ @slot;
22
+ }
23
+ }
24
+ @media (width < 80rem) {
25
+ &:where(.lc-sidebar[data-rail-below="xl"]:not([data-expanded]), .lc-sidebar[data-rail-below="xl"]:not([data-expanded]) *) {
26
+ @slot;
27
+ }
28
+ }
29
+ @media (width < 96rem) {
30
+ &:where(.lc-sidebar[data-rail-below="2xl"]:not([data-expanded]), .lc-sidebar[data-rail-below="2xl"]:not([data-expanded]) *) {
31
+ @slot;
32
+ }
15
33
  }
34
+ }
16
35
 
36
+ @layer components {
17
37
  /* The sidebar scrolls on its own without a visible scrollbar. */
18
- .lc-docs-shell__sidebar {
38
+ .lc-sidebar {
19
39
  scrollbar-width: none;
20
40
  }
21
41
 
22
- .lc-docs-shell__sidebar::-webkit-scrollbar {
42
+ .lc-sidebar::-webkit-scrollbar {
23
43
  display: none;
24
44
  }
25
45
 
46
+ /* A bar at the sidebar's edge marks the current link. Set --lc-sidebar-indicator
47
+ to any background, such as a gradient. On the rail, links center their icons
48
+ and their labels and group titles stay for screen readers only. */
49
+ .lc-sidebar [data-slot="nav-link"] {
50
+ position: relative;
51
+
52
+ @apply lc-rail:justify-center;
53
+ }
54
+
55
+ .lc-sidebar [data-slot="nav-link"][aria-current="page"]::before {
56
+ content: "";
57
+ position: absolute;
58
+ inset-block: calc(var(--spacing) * 2);
59
+ inset-inline-start: calc(var(--spacing-related) * -1);
60
+ width: calc(var(--spacing) * 0.75);
61
+ border-radius: var(--radius-pill);
62
+ background: var(--lc-sidebar-indicator, var(--primary));
63
+ }
64
+
65
+ .lc-sidebar :is([data-slot="nav-group-title"], [data-slot="nav-link"] > span) {
66
+ @apply lc-rail:sr-only;
67
+ }
68
+
69
+ /* The toggle's chevrons point the way the sidebar will move. */
70
+ .lc-sidebar__toggle svg {
71
+ transition: rotate var(--lc-motion-control) var(--lc-ease-out);
72
+
73
+ @apply lc-rail:rotate-180;
74
+ }
75
+
76
+ .lc-sidebar__toggle:dir(rtl) svg {
77
+ rotate: 180deg;
78
+
79
+ @apply lc-rail:rotate-0;
80
+ }
81
+
26
82
  .lc-dock {
27
83
  --lc-dock-edge: max(1rem, env(safe-area-inset-left));
28
84
  --lc-dock-gap: max(1rem, env(safe-area-inset-right));
@@ -132,6 +188,7 @@
132
188
 
133
189
  @media (prefers-reduced-motion: reduce) {
134
190
  .lc-app-header__glass,
191
+ .lc-sidebar__toggle svg,
135
192
  .lc-dock__trigger svg,
136
193
  .lc-dock__scrim,
137
194
  .lc-dock__action,
@@ -0,0 +1,58 @@
1
+ /* Segmented toggle group (lc_toggle_group_class, lc_toggle_group_item_class).
2
+
3
+ Where anchor positioning is supported, the current item's surface is one
4
+ indicator on the track that slides from item to item, whichever state marks
5
+ it (aria-current, aria-selected, aria-checked, aria-pressed, a checked radio
6
+ or the active: class). Elsewhere each current item paints its own surface. */
7
+
8
+ @layer components {
9
+ /* Concentric with the track: its radius (rounded-2xl) less its padding (p-1).
10
+ Spelled out because --radius-2xl resolves at :root, before lc-squircle
11
+ scales it. */
12
+ .lc-toggle-group {
13
+ --lc-toggle-item-radius: calc(var(--radius) * 2 * var(--lc-corner-scale, 1) - var(--spacing));
14
+ position: relative;
15
+ isolation: isolate;
16
+ }
17
+ }
18
+
19
+ @supports (anchor-name: --a) and (anchor-scope: all) {
20
+ .lc-toggle-group {
21
+ anchor-scope: --lc-toggle-current;
22
+ }
23
+
24
+ .lc-toggle-group::after {
25
+ content: "";
26
+ position: absolute;
27
+ z-index: -1;
28
+ position-anchor: --lc-toggle-current;
29
+ inset: anchor(top) anchor(right) anchor(bottom) anchor(left);
30
+ border-radius: var(--lc-toggle-item-radius);
31
+ corner-shape: inherit;
32
+ background-color: var(--color-background);
33
+ pointer-events: none;
34
+ }
35
+
36
+ @media (prefers-reduced-motion: no-preference) {
37
+ .lc-toggle-group::after {
38
+ transition: inset var(--lc-motion-control) var(--lc-ease-out);
39
+ }
40
+ }
41
+
42
+ /* Unlayered, so it wins over the items' own aria-*:bg-background utilities. */
43
+ .lc-toggle-group .lc-toggle-group-item {
44
+ background-color: transparent;
45
+ }
46
+
47
+ .lc-toggle-group
48
+ .lc-toggle-group-item:is(
49
+ [aria-current]:not([aria-current="false"]),
50
+ [aria-selected="true"],
51
+ [aria-checked="true"],
52
+ [aria-pressed="true"],
53
+ :has(input:checked),
54
+ .lc-toggle-group-item-active
55
+ ) {
56
+ anchor-name: --lc-toggle-current;
57
+ }
58
+ }
@@ -80,21 +80,23 @@ module Lostcoords::Ui
80
80
 
81
81
  BADGE_SHAPES = { rounded: "", pill: "rounded-full px-2.5" }.freeze
82
82
 
83
+ # A selected pill fills solid with the primary color; its border stays transparent, so the
84
+ # fill alone carries the state and selecting never shifts the pill's edge.
83
85
  TOGGLE_BASE =
84
86
  "inline-flex items-center justify-center gap-related rounded-pill " \
85
87
  "border border-transparent bg-(--lc-field-bg,var(--input)) " \
86
88
  "font-sans text-muted-foreground whitespace-nowrap cursor-pointer no-underline " \
87
89
  "transition-[background-color,border-color,color,transform] duration-(--lc-motion-quick) ease-(--lc-ease-out) " \
88
90
  "lc-press hover:text-foreground " \
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 " \
91
- "aria-[current]:not-aria-[current=false]:bg-primary-soft aria-[current]:not-aria-[current=false]:border-primary " \
92
- "aria-[current]:not-aria-[current=false]:text-primary aria-[current]:not-aria-[current=false]:shadow-none " \
93
- "has-checked:bg-primary-soft has-checked:border-primary has-checked:text-primary has-checked:shadow-none " \
94
- "aria-expanded:bg-primary-soft aria-expanded:border-primary aria-expanded:text-primary aria-expanded:shadow-none " \
91
+ "aria-pressed:bg-primary aria-pressed:border-transparent aria-pressed:text-primary-foreground aria-pressed:shadow-none " \
92
+ "aria-checked:bg-primary aria-checked:border-transparent aria-checked:text-primary-foreground aria-checked:shadow-none " \
93
+ "aria-[current]:not-aria-[current=false]:bg-primary aria-[current]:not-aria-[current=false]:border-transparent " \
94
+ "aria-[current]:not-aria-[current=false]:text-primary-foreground aria-[current]:not-aria-[current=false]:shadow-none " \
95
+ "has-checked:bg-primary has-checked:border-transparent has-checked:text-primary-foreground has-checked:shadow-none " \
96
+ "aria-expanded:bg-primary aria-expanded:border-transparent aria-expanded:text-primary-foreground aria-expanded:shadow-none " \
95
97
  "[&_svg]:size-[1.1em] [&_svg]:shrink-0"
96
98
 
97
- TOGGLE_ACTIVE = "bg-primary-soft border-primary text-primary hover:text-primary shadow-none"
99
+ TOGGLE_ACTIVE = "bg-primary border-transparent text-primary-foreground hover:text-primary-foreground shadow-none"
98
100
 
99
101
  TOGGLE_GHOST = "border-dashed border-muted-foreground/40 [background:none] shadow-none text-muted-foreground"
100
102
 
@@ -1,5 +1,14 @@
1
1
  module Lostcoords::Ui
2
2
  module DescriptionListHelper
3
+ STAT_TONES = { default: "text-foreground", primary: "text-primary", success: "text-success", warning: "text-warning", destructive: "text-destructive" }.freeze
4
+ STATS_COLUMNS = { nil => "grid-cols-[repeat(auto-fit,minmax(min(100%,9rem),1fr))]", 2 => "grid-cols-2", 3 => "grid-cols-3", 4 => "grid-cols-2 sm:grid-cols-4" }.freeze
5
+ STATS_LAYOUTS = {
6
+ inline: "flex flex-wrap items-baseline gap-x-section gap-y-tight",
7
+ grid: "grid gap-related"
8
+ }.freeze
9
+ STAT = "flex min-w-0 items-baseline gap-tight group-data-[layout=grid]/stats:flex-col group-data-[layout=grid]/stats:items-stretch " \
10
+ "group-data-[layout=grid]/stats:rounded-2xl group-data-[layout=grid]/stats:lc-squircle group-data-[layout=grid]/stats:bg-tile group-data-[layout=grid]/stats:p-content"
11
+
3
12
  # Yields a builder; `list.item "Owner", "Ada"` or `list.item("Owner") { … }` adds a row.
4
13
  # Rows stack on phones and sit in two columns from the sm breakpoint.
5
14
  def lc_description_list(**attributes, &block)
@@ -8,5 +17,35 @@ module Lostcoords::Ui
8
17
  capture(Parts::DescriptionList.new(self), &block) if block
9
18
  end
10
19
  end
20
+
21
+ # Headline numbers as a description list of lc_stat items. layout: :inline runs them along a line,
22
+ # each value followed by its label; :grid gives each a tile, the label under the value, in
23
+ # columns: (2, 3 or 4; nil fits as many as the width allows).
24
+ def lc_stats(layout: :inline, columns: nil, **attributes, &block)
25
+ layout = lc_option!(:layout, layout, STATS_LAYOUTS.keys)
26
+ raise ArgumentError, "columns: lays out a grid; pass layout: :grid" if columns && layout != :grid
27
+
28
+ columns = lc_option!(:columns, columns, STATS_COLUMNS.keys.compact) if columns
29
+ classes = lc_tw("group/stats m-0 min-w-0", STATS_LAYOUTS.fetch(layout), (STATS_COLUMNS.fetch(columns) if layout == :grid))
30
+ tag.dl(**lc_attributes({ class: classes, data: { slot: "stats", layout: layout } }, attributes)) do
31
+ capture(&block) if block
32
+ end
33
+ end
34
+
35
+ # One number in lc_stats: the value in bold tabular figures and its label in muted text. tone:
36
+ # colours the value with a status tone. A block replaces the value, such as a link around it.
37
+ def lc_stat(value = nil, label:, tone: :default, **attributes, &block)
38
+ lc_label!(label, :label)
39
+ tone = lc_option!(:tone, tone, STAT_TONES.keys)
40
+ value = capture(&block) if block
41
+ raise ArgumentError, "lc_stat needs a value or a block" if value.nil?
42
+
43
+ tag.div(**lc_attributes({ class: STAT, data: { slot: "stat", tone: (tone unless tone == :default) }.compact }, attributes)) do
44
+ safe_join([
45
+ tag.dt(label, class: "order-last text-small text-muted-foreground group-data-[layout=grid]/stats:text-caption", data: { slot: "stat-label" }),
46
+ tag.dd(value, class: lc_tw("m-0 text-heading font-semibold tabular-nums", STAT_TONES.fetch(tone)), data: { slot: "stat-value" })
47
+ ])
48
+ end
49
+ end
11
50
  end
12
51
  end
@@ -1,11 +1,11 @@
1
1
  module Lostcoords::Ui
2
2
  module FormHelper
3
3
  TOGGLE_GROUP_BASE =
4
- "inline-flex items-center gap-1 rounded-2xl bg-track p-1 lc-squircle"
4
+ "lc-toggle-group inline-flex items-center gap-1 rounded-2xl bg-track p-1 lc-squircle *:grow"
5
5
 
6
6
  TOGGLE_GROUP_ITEM_BASE =
7
- "lc-press inline-flex items-center justify-center gap-1.5 whitespace-nowrap " \
8
- "h-control-sm rounded-xl border-0 bg-transparent " \
7
+ "lc-toggle-group-item lc-press inline-flex items-center justify-center gap-1.5 whitespace-nowrap " \
8
+ "h-control-sm rounded-(--lc-toggle-item-radius,var(--radius-xl)) lc-squircle border-0 bg-transparent " \
9
9
  "px-3 font-sans text-label cursor-pointer no-underline " \
10
10
  "text-muted-foreground not-disabled:hover:text-foreground " \
11
11
  "aria-selected:bg-background aria-selected:text-foreground " \
@@ -18,7 +18,7 @@ module Lostcoords::Ui
18
18
  "has-disabled:cursor-not-allowed has-disabled:text-[color-mix(in_oklab,var(--foreground)_38%,transparent)] " \
19
19
  "[&_svg]:size-[1.1em] [&_svg]:shrink-0"
20
20
 
21
- TOGGLE_GROUP_ITEM_ACTIVE = "bg-background text-foreground hover:text-foreground"
21
+ TOGGLE_GROUP_ITEM_ACTIVE = "lc-toggle-group-item-active bg-background text-foreground hover:text-foreground"
22
22
 
23
23
  INPUT_BASE =
24
24
  "w-full max-w-full min-w-0 " \
@@ -0,0 +1,31 @@
1
+ module Lostcoords::Ui
2
+ module HovercardHelper
3
+ HOVERCARD_SIDES = %i[bottom top].freeze
4
+
5
+ # A preview card for what a link points to, such as a profile over a name. It opens after a short
6
+ # hover or on keyboard focus and stays open while the pointer is on it.
7
+ #
8
+ # Yields attributes for the trigger; splat them with `**card` on the link. Pass the card as content:,
9
+ # or src: to load it as HTML from your endpoint the first time it opens, so a long list of triggers
10
+ # costs nothing until one is hovered. The card is a preview: it is hidden from assistive technology
11
+ # and its links are out of the tab order, so everything in it must also be reachable from the page
12
+ # the trigger opens. Inside a paragraph, keep content: to phrasing elements such as spans; HTML that
13
+ # src: loads can hold anything.
14
+ def lc_hovercard(src: nil, content: nil, side: :bottom, **attributes, &block)
15
+ raise ArgumentError, "Pass src: or content:, not both" if src && content
16
+ raise ArgumentError, "Pass src: or content:" unless src || content
17
+ raise ArgumentError, "lc_hovercard needs a block that renders its trigger" unless block
18
+ lc_label!(src, :src) if src
19
+ side = lc_option!(:side, side, HOVERCARD_SIDES)
20
+ trigger = capture({ data: { lc_hovercard_target: "trigger" } }, &block)
21
+ body = content || tag.span(class: "flex flex-col gap-related", data: { slot: "hovercard-loading" }) do
22
+ safe_join([ lc_skeleton(class: "h-10 w-10 rounded-full"), lc_skeleton, lc_skeleton(class: "h-4 w-2/3") ])
23
+ end
24
+ data = { slot: "hovercard", side: side, controller: "lc-hovercard", lc_hovercard_src_value: src,
25
+ action: "mouseenter->lc-hovercard#enter focusin->lc-hovercard#enter mouseleave->lc-hovercard#leave focusout->lc-hovercard#leave" }.compact
26
+ tag.span(**lc_attributes({ class: "lc-hovercard relative inline-flex min-w-0", data: data }, attributes)) do
27
+ safe_join([ trigger, tag.span(body, class: lc_glass_class(shape: :menu, extra: "lc-hovercard__content lc-squircle"), aria: { hidden: true }, data: { slot: "hovercard-content", lc_hovercard_target: "content", loaded: (true unless src) }) ])
28
+ end
29
+ end
30
+ end
31
+ end