lostcoords-ui 0.9.3 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +139 -4
- data/app/assets/tailwind/lostcoords/ui/components/shell.css +2 -2
- data/app/assets/tailwind/lostcoords/ui/core.css +2 -1
- data/app/assets/tailwind/lostcoords/ui/shell.css +66 -9
- data/app/assets/tailwind/lostcoords/ui/toggle-group.css +58 -0
- data/app/helpers/lostcoords/ui/badge_helper.rb +9 -7
- data/app/helpers/lostcoords/ui/description_list_helper.rb +39 -0
- data/app/helpers/lostcoords/ui/form_helper.rb +4 -4
- data/app/helpers/lostcoords/ui/layout_helper.rb +31 -0
- data/app/helpers/lostcoords/ui/navigation_helper.rb +13 -0
- data/app/helpers/lostcoords/ui/primitives_helper.rb +20 -2
- data/app/helpers/lostcoords/ui/shell_helper.rb +32 -1
- data/app/helpers/lostcoords/ui/structures_helper.rb +65 -14
- data/app/helpers/lostcoords/ui/typography_helper.rb +30 -0
- data/app/javascript/lostcoords/ui/controllers/lc_char_counter_controller.js +63 -0
- data/app/javascript/lostcoords/ui/controllers/lc_sidebar_controller.js +48 -0
- data/app/javascript/lostcoords/ui/index.js +4 -0
- data/config/locales/en.yml +14 -0
- data/config/locales/es.yml +14 -0
- data/config/locales/ja.yml +14 -0
- data/lib/lostcoords/ui/parts.rb +86 -0
- data/lib/lostcoords/ui/version.rb +1 -1
- metadata +4 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fc1eac8e5c8d5395e53290a9f939d22a981c17ee7a3badbfb4d88825d876be49
|
|
4
|
+
data.tar.gz: bfc62ca69d504fb8ae72e623ed031ee82dfaf0f904ef7bc94a6874cdbfaa1b16
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4f9c03d1e4b09af19ef947c081b9b308f51d16400987e149ee20a108bf1a48f20466561d12ce9704a0bd4eca92dcfd9d85e1826bbdb1510f0dce116694ad1e56
|
|
7
|
+
data.tar.gz: 5a444fd100b3af57bc79cc55529400791c70df467618599babc9e0d2fa39c703830008c1905fb40e586bc69802ac68e78d85eb7d1ab5ed47b4764f4bf7134289
|
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.
|
|
24
|
+
gem "lostcoords-ui", "~> 0.10.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
|
|
61
|
-
menu also
|
|
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,42 @@ Omit `only` to register every library controller. Unknown identifiers raise befo
|
|
|
170
170
|
registered, and repeated calls on the same application keep later overrides, so register defaults
|
|
171
171
|
before application overrides.
|
|
172
172
|
|
|
173
|
+
## Changes in 0.10.0
|
|
174
|
+
|
|
175
|
+
Nothing needs an edit, but toggles look different:
|
|
176
|
+
|
|
177
|
+
- **A selected toggle pill fills solid.** Before: a pressed, checked or current `lc_toggle` (and a
|
|
178
|
+
`variant: :pills` toggle group item) had a soft primary fill, a primary edge and primary ink. After: it
|
|
179
|
+
fills with `--primary` and `--primary-foreground` ink over a transparent border, so selecting never shifts
|
|
180
|
+
its edge. A host that restyled the soft state for contrast can drop that override.
|
|
181
|
+
- **A segmented toggle group slides one indicator.** Items stretch to share the track, and their corners are
|
|
182
|
+
concentric with it. Where the browser supports anchor positioning, the current item's surface is one
|
|
183
|
+
indicator that slides from item to item, whichever state marks it (`aria-current`, `aria-selected`,
|
|
184
|
+
`aria-checked`, `aria-pressed`, a checked radio or `active:`); elsewhere each current item paints its own,
|
|
185
|
+
as before. Items carry `lc-toggle-group-item`, and the track `lc-toggle-group`.
|
|
186
|
+
|
|
187
|
+
New components and options, moved from apps that built them by hand:
|
|
188
|
+
|
|
189
|
+
- **`lc_tab_bar` is a row of links styled as underlined tabs.** The current tab is bold with a rounded
|
|
190
|
+
underline in `--lc-tab-bar-indicator`; `count:` adds a muted number and `fill: true` shares the row. Unlike
|
|
191
|
+
`lc_tabs`, each tab is a link to its own URL.
|
|
192
|
+
- **`lc_sidebar` is a sticky app sidebar that folds to an icon rail**, with the `lc-sidebar` controller, in the
|
|
193
|
+
`shell` entry. It keeps the reader's choice in a cookie the helper reads back, starts as a rail below
|
|
194
|
+
`rail_below:` unless expanded, and yields `sidebar.header` (with the toggle), `sidebar.body`, `sidebar.footer`
|
|
195
|
+
and `sidebar.account`, a row that opens an `lc_menu`. The `lc-rail:` variant styles your own content on the
|
|
196
|
+
rail, and `--lc-sidebar-indicator` paints the current link's bar. If you built a sidebar with a rail variant
|
|
197
|
+
and a cookie of your own, you can replace it and delete its stylesheet rules and controller.
|
|
198
|
+
- **`lc_stats` and `lc_stat` show headline numbers** in a description list, in a line or as tiles.
|
|
199
|
+
- **`lc_char_counter` is the character ring X shows under a post**, with the `lc-char-counter` controller. It
|
|
200
|
+
counts a field, or takes a count you supply for weighted characters.
|
|
201
|
+
- **`lc_time` renders the short relative time X shows**, "12m", "4h", "4 Nov", with the full date as its title.
|
|
202
|
+
- **`lc_split` and `lc_columns` lay out a main column beside an aside and balanced columns of groups**, with
|
|
203
|
+
`lc_split_class` and `lc_columns_class` for markup you render yourself.
|
|
204
|
+
- **`lc_empty_state` takes `title:`, `text:`, `icon:`, `level:` and `card:`** to lay out the usual empty state;
|
|
205
|
+
the block form still works.
|
|
206
|
+
- **`lc_toggle` takes `icon:`, `icon_only:` and `tooltip:`.** `icon_only: true` makes a square toggle of just the
|
|
207
|
+
icon whose label stays as its accessible name.
|
|
208
|
+
|
|
173
209
|
## Changes in 0.9.1
|
|
174
210
|
|
|
175
211
|
Nothing needs an edit:
|
|
@@ -356,6 +392,8 @@ Badge, icon badge, Alert and Toast share `neutral`, `primary`, `success`, `warni
|
|
|
356
392
|
`lc_toggle` renders a button that flips its own `aria-pressed`; set `aria-pressed` or `aria-expanded` yourself
|
|
357
393
|
and it leaves the state to your controller. `href:` renders a link marked `aria-current` when active, and `name:`
|
|
358
394
|
with `value:` a label around a visually hidden native radio, styled by `:checked`.
|
|
395
|
+
`icon:` adds a leading icon, and `icon_only: true` makes a square toggle of just that icon whose label stays as its
|
|
396
|
+
accessible name; `tooltip: true` shows the label on hover and focus, as on `lc_icon_button`.
|
|
359
397
|
`lc_toggle_group` with `lc_toggle_group_item` holds mutually exclusive choices, and the group decides what its items are.
|
|
360
398
|
With `name:` they are native radios in labels, which bring their own arrows, submitted value and reset; items take
|
|
361
399
|
`value:` and `checked:`, and the group's `value:` checks the matching item. With `as: :nav` they are links in a
|
|
@@ -373,8 +411,37 @@ given another kind's arguments raises. `variant: :pills` lays any of them out as
|
|
|
373
411
|
<%= lc_toggle_group_item "Annual", value: "annual" %>
|
|
374
412
|
<% end %>
|
|
375
413
|
<%= lc_toggle "Food", aria: { pressed: false }, data: { value: "food" } %>
|
|
414
|
+
<%= lc_toggle "Bold", icon: "bold", icon_only: true, tooltip: true %>
|
|
376
415
|
```
|
|
377
416
|
|
|
417
|
+
`lc_empty_state(title:, text:, icon:)` lays out the usual empty state: a round icon badge, a heading
|
|
418
|
+
(`level:`, 2 by default), a line of muted text, then the block, such as an action. `card: true` puts it on a card.
|
|
419
|
+
Without those options the block is the whole content, as before.
|
|
420
|
+
|
|
421
|
+
```erb
|
|
422
|
+
<%= lc_empty_state title: "No drafts yet", text: "Drafts appear here until you post them.", icon: "pencil-square", card: true do %>
|
|
423
|
+
<%= lc_button_link_to "New draft", new_draft_path, icon: "plus" %>
|
|
424
|
+
<% end %>
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
`lc_stats` shows headline numbers as a description list of `lc_stat` items: the value in bold tabular figures
|
|
428
|
+
and its label in muted text. `layout: :inline` (the default) runs them along a line; `layout: :grid` gives each a
|
|
429
|
+
tile, in `columns:` 2, 3 or 4, or as many as fit. `tone:` colours a value with a status tone, and a block replaces
|
|
430
|
+
the value, such as a link around it.
|
|
431
|
+
|
|
432
|
+
```erb
|
|
433
|
+
<%= lc_stats do %>
|
|
434
|
+
<%= lc_stat number_with_delimiter(@replies), label: "replies sent", tone: :primary %>
|
|
435
|
+
<%= lc_stat(label: "people") { link_to @people, people_path } %>
|
|
436
|
+
<% end %>
|
|
437
|
+
<%= lc_stats layout: :grid, columns: 2 do %>…<% end %>
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
`lc_time(time)` renders a `<time>` with the short text X shows: "now", "12m" and "4h" within a day, then
|
|
441
|
+
"4 Nov", and "4 Nov 2025" in another year. The full date and time is its title, and `detail:` adds to it. The
|
|
442
|
+
texts and date formats are translations under `lostcoords.ui.time`; month names come from the host's
|
|
443
|
+
`date.month_names`, as rails-i18n provides them, and fall back to English. `now:` sets the moment to count from.
|
|
444
|
+
|
|
378
445
|
`lc_collapsible` expands content through a native `<details>` element. `lc_alert` renders persistent inline feedback;
|
|
379
446
|
`lc_toast` adds timed dismissal.
|
|
380
447
|
|
|
@@ -485,6 +552,21 @@ attribute. `form.field … size: :sm` (or `lc_field size: :sm`) is the compact f
|
|
|
485
552
|
with a caption label. Pass `builder: Lostcoords::Ui::FormBuilder` to `form_with` directly, or call `lc_field`
|
|
486
553
|
with `error: record.errors.full_messages_for(:name)` when you keep your own builder.
|
|
487
554
|
|
|
555
|
+
`lc_char_counter(max:)` is the ring X shows under a post: it fills as a field nears `max:` characters, hides
|
|
556
|
+
while the field is empty, turns to the warning tone with the characters left once `warn:` (20) or fewer remain,
|
|
557
|
+
and to the destructive tone with a negative number past the limit. Its accessible name reads "120 of 280
|
|
558
|
+
characters". It counts the field whose id is `for:`, or the nearest field around it. To count another way,
|
|
559
|
+
such as X's weighted characters, set `data-lc-char-counter-count-value` or send it an event whose
|
|
560
|
+
`detail.count` is the count, as in `data: { action: "composer:count@window->lc-char-counter#update" }`; `count:` renders a count
|
|
561
|
+
before JavaScript runs.
|
|
562
|
+
|
|
563
|
+
```erb
|
|
564
|
+
<%= lc_field label: "Post", id: "post" do |field| %>
|
|
565
|
+
<%= lc_textarea name: "post[text]", rows: 4, **field %>
|
|
566
|
+
<%= lc_char_counter max: 280, for: "post" %>
|
|
567
|
+
<% end %>
|
|
568
|
+
```
|
|
569
|
+
|
|
488
570
|
`lc_checkbox`, `lc_radio` and `lc_switch` render native inputs with a label and optional hint.
|
|
489
571
|
Checkboxes and switches submit an unchecked value like Rails' `check_box`; pass `unchecked_value: nil`
|
|
490
572
|
to omit it. A `nil` label renders the bare input, for a row selector the row labels; give it
|
|
@@ -517,6 +599,19 @@ Text that labels something other than one control, such as a list, uses `lc_text
|
|
|
517
599
|
<% end %>
|
|
518
600
|
```
|
|
519
601
|
|
|
602
|
+
```erb
|
|
603
|
+
<%= lc_tab_bar label: "Drafts", fill: true do |bar| %>
|
|
604
|
+
<%= bar.link "Open", drafts_path, current: true, count: @open_count %>
|
|
605
|
+
<%= bar.link "Posted", drafts_path(status: :posted), count: @posted_count %>
|
|
606
|
+
<% end %>
|
|
607
|
+
```
|
|
608
|
+
|
|
609
|
+
`lc_tab_bar` is a row of links styled as underlined tabs, for the views of a page that each have a URL; use
|
|
610
|
+
`lc_tabs` when the panels live on one page. The current tab carries `aria-current="page"`, bold text and a
|
|
611
|
+
rounded underline in `--lc-tab-bar-indicator` (the primary color by default). `count:` adds a muted number after
|
|
612
|
+
the label, and `fill: true` stretches the tabs to share the row. A row too long for its container scrolls
|
|
613
|
+
sideways and fades at the edge it continues past.
|
|
614
|
+
|
|
520
615
|
Tabs follow the ARIA tabs pattern with arrow key, Home and End navigation, and dispatch
|
|
521
616
|
`lc-tabs:change`. `orientation: :vertical` stacks the tabs beside their panels and moves with Arrow Up
|
|
522
617
|
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 +681,41 @@ the reader has scrolled to. This documentation site is built with them.
|
|
|
586
681
|
<% end %>
|
|
587
682
|
```
|
|
588
683
|
|
|
684
|
+
`lc_sidebar` is a sticky, full-height app sidebar that folds to an icon rail. Its toggle stores the choice in a
|
|
685
|
+
cookie (`cookie:`, `lc_sidebar` by default) that the helper reads back, so the server renders the next page the
|
|
686
|
+
same way; `state: "collapsed"` or `"expanded"` overrides it. Below `rail_below:` (`:xl` by default; `:md`, `:lg`,
|
|
687
|
+
`:2xl`, or `false` for never) it starts as a rail unless the reader expanded it. On the rail, `lc_nav_list` group
|
|
688
|
+
titles and link labels stay for screen readers only and links center their icons, so give each link a `title:`.
|
|
689
|
+
The current link gets a bar at the sidebar's edge in `--lc-sidebar-indicator` (any background, such as a
|
|
690
|
+
gradient). `--lc-sidebar-width` (15rem) and `--lc-sidebar-rail-width` (4rem) set the widths, and the `lc-rail:`
|
|
691
|
+
variant styles your own content on the rail, as in `lc-rail:hidden`. It dispatches `lc-sidebar:toggle` with
|
|
692
|
+
`{ collapsed }`.
|
|
693
|
+
|
|
694
|
+
```erb
|
|
695
|
+
<%= lc_sidebar cookie: "sidebar" do |sidebar| %>
|
|
696
|
+
<%= sidebar.header do %>
|
|
697
|
+
<%= link_to root_path, aria: { label: "Acme home" } do %>
|
|
698
|
+
<span class="lc-rail:hidden">Acme</span><span class="hidden lc-rail:inline" aria-hidden="true">A</span>
|
|
699
|
+
<% end %>
|
|
700
|
+
<% end %>
|
|
701
|
+
<%= sidebar.body do %>
|
|
702
|
+
<%= lc_nav_list label: "Main", indicator: true do |nav| %>
|
|
703
|
+
<%= nav.link "Inbox", inbox_path, icon: "inbox", title: "Inbox", current: true %>
|
|
704
|
+
<% end %>
|
|
705
|
+
<% end %>
|
|
706
|
+
<%= sidebar.footer do %>
|
|
707
|
+
<%= sidebar.account current_user.name, detail: current_user.email, avatar: lc_avatar(current_user.initials, size: :sm) do %>
|
|
708
|
+
<%= lc_menu_option "Settings", icon: "cog-6-tooth", href: settings_path %>
|
|
709
|
+
<%= lc_menu_option "Sign out", href: session_path, method: :delete %>
|
|
710
|
+
<% end %>
|
|
711
|
+
<% end %>
|
|
712
|
+
<% end %>
|
|
713
|
+
```
|
|
714
|
+
|
|
715
|
+
`sidebar.header` renders the toggle after its block (`toggle: false` leaves it out; `sidebar.toggle` renders it
|
|
716
|
+
anywhere). `sidebar.account` is a full-width row, the avatar, name, a detail line and an ellipsis, that opens an
|
|
717
|
+
`lc_menu` of the block's options; on the rail only the avatar shows.
|
|
718
|
+
|
|
589
719
|
For rendered Markdown, such as a Kiln `.md` view, pass the HTML to both: `lc_prose(anchors: true) { html }`
|
|
590
720
|
links its headings, and `lc_toc(headings: html)` lists them. On phones, `lc_dock` floats `dock.nav` and a
|
|
591
721
|
`dock.menu` of quick actions at the bottom of the screen; render it last, since it reserves its height there.
|
|
@@ -873,7 +1003,10 @@ styles a kicker or footer column label; under `lang="ja"` it keeps natural case
|
|
|
873
1003
|
Stacks and inline groups take the spacing names from [Foundations](#foundations). `lc_stack`, `lc_inline`,
|
|
874
1004
|
`lc_text` and `lc_card` take `as:` to render a meaningful element, such as `lc_stack(as: :ul)`, `lc_text(as: :span)` or
|
|
875
1005
|
`lc_card(as: :section)`. `lc_section` leaves
|
|
876
|
-
`heading` below its title and `content` between blocks. `
|
|
1006
|
+
`heading` below its title and `content` between blocks. `lc_split` lays out a main column and an aside: one
|
|
1007
|
+
column on small screens, and from `lg` a flexible main beside an aside of `aside: :sm` (16rem), `:md` (20rem)
|
|
1008
|
+
or `:lg` (24rem). `lc_columns(count: 2)` flows groups, such as settings sections, into balanced columns from
|
|
1009
|
+
`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
1010
|
for a heading that needs more than a title, such as a lede under it. `lc_container` provides `page`, `reading` and
|
|
878
1011
|
`form` widths; only the page container adds gutters. Japanese headings inherit `lang="ja"` and use
|
|
879
1012
|
natural letter spacing.
|
|
@@ -956,6 +1089,8 @@ Generated by `bin/rails lostcoords:ui:builders`; `bin/lint` checks this list aga
|
|
|
956
1089
|
- `lc_stack_class(gap: :content, extra: nil)` (LayoutHelper)
|
|
957
1090
|
- `lc_inline_class(gap: :related, extra: nil)` (LayoutHelper)
|
|
958
1091
|
- `lc_container_class(size: :page, extra: nil)` (LayoutHelper)
|
|
1092
|
+
- `lc_split_class(aside: :md, extra: nil)` (LayoutHelper)
|
|
1093
|
+
- `lc_columns_class(count: 2, extra: nil)` (LayoutHelper)
|
|
959
1094
|
- `lc_section_header_class(extra: nil)` (LayoutHelper)
|
|
960
1095
|
- `lc_popover_class(align: :end, extra: nil)` (MenuHelper)
|
|
961
1096
|
- `lc_menu_popover_class(align: :end, extra: nil)` (MenuHelper)
|
|
@@ -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";
|
|
@@ -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";
|
|
@@ -4,25 +4,81 @@
|
|
|
4
4
|
--lc-sticky-offset: 5rem;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
14
|
-
|
|
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-
|
|
38
|
+
.lc-sidebar {
|
|
19
39
|
scrollbar-width: none;
|
|
20
40
|
}
|
|
21
41
|
|
|
22
|
-
.lc-
|
|
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
|
|
90
|
-
"aria-checked:bg-primary
|
|
91
|
-
"aria-[current]:not-aria-[current=false]:bg-primary
|
|
92
|
-
"aria-[current]:not-aria-[current=false]:text-primary aria-[current]:not-aria-[current=false]:shadow-none " \
|
|
93
|
-
"has-checked:bg-primary
|
|
94
|
-
"aria-expanded:bg-primary
|
|
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
|
|
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 " \
|
|
@@ -18,6 +18,15 @@ module Lostcoords::Ui
|
|
|
18
18
|
form: "max-w-form"
|
|
19
19
|
}.freeze
|
|
20
20
|
|
|
21
|
+
# The aside's width from the lg breakpoint; below it the aside stacks under the main column.
|
|
22
|
+
SPLIT_ASIDES = {
|
|
23
|
+
sm: "lg:grid-cols-[minmax(0,1fr)_16rem]",
|
|
24
|
+
md: "lg:grid-cols-[minmax(0,1fr)_20rem]",
|
|
25
|
+
lg: "lg:grid-cols-[minmax(0,1fr)_24rem]"
|
|
26
|
+
}.freeze
|
|
27
|
+
|
|
28
|
+
COLUMN_COUNTS = { 2 => "lg:columns-2", 3 => "md:columns-2 xl:columns-3" }.freeze
|
|
29
|
+
|
|
21
30
|
def lc_stack_class(gap: :content, extra: nil)
|
|
22
31
|
gap = lc_option!(:gap, gap, LAYOUT_GAPS.keys)
|
|
23
32
|
lc_tw("flex min-w-0 flex-col", LAYOUT_GAPS.fetch(gap), extra)
|
|
@@ -33,6 +42,20 @@ module Lostcoords::Ui
|
|
|
33
42
|
lc_tw("mx-auto min-w-0 w-full", CONTAINER_SIZES.fetch(size), extra)
|
|
34
43
|
end
|
|
35
44
|
|
|
45
|
+
# A main column and an aside: one column on small screens, and from lg a flexible main beside an
|
|
46
|
+
# aside of fixed width (aside: :sm 16rem, :md 20rem, :lg 24rem). Children align to the top.
|
|
47
|
+
def lc_split_class(aside: :md, extra: nil)
|
|
48
|
+
aside = lc_option!(:aside, aside, SPLIT_ASIDES.keys)
|
|
49
|
+
lc_tw("grid min-w-0 items-start gap-section", SPLIT_ASIDES.fetch(aside), extra)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Groups that flow into balanced columns, as newspaper columns do, without breaking a group across
|
|
53
|
+
# two: count: 2 from lg, or 3 from xl (2 from md). Children keep a section's spacing.
|
|
54
|
+
def lc_columns_class(count: 2, extra: nil)
|
|
55
|
+
count = lc_option!(:count, count, COLUMN_COUNTS.keys)
|
|
56
|
+
lc_tw("min-w-0 gap-section *:break-inside-avoid *:not-last:mb-section", COLUMN_COUNTS.fetch(count), extra)
|
|
57
|
+
end
|
|
58
|
+
|
|
36
59
|
# The header keeps a control's height, so a section with actions and one without line up.
|
|
37
60
|
def lc_section_header_class(extra: nil)
|
|
38
61
|
lc_inline_class(extra: lc_tw("min-h-control-md justify-between", extra))
|
|
@@ -47,6 +70,14 @@ module Lostcoords::Ui
|
|
|
47
70
|
tag.public_send(lc_option!(:as, as, LAYOUT_ELEMENTS), **lc_attributes({ class: lc_inline_class(gap: gap) }, attributes), &block)
|
|
48
71
|
end
|
|
49
72
|
|
|
73
|
+
def lc_split(aside: :md, as: :div, **attributes, &block)
|
|
74
|
+
tag.public_send(lc_option!(:as, as, LAYOUT_ELEMENTS), **lc_attributes({ class: lc_split_class(aside: aside) }, attributes), &block)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def lc_columns(count: 2, as: :div, **attributes, &block)
|
|
78
|
+
tag.public_send(lc_option!(:as, as, LAYOUT_ELEMENTS), **lc_attributes({ class: lc_columns_class(count: count) }, attributes), &block)
|
|
79
|
+
end
|
|
80
|
+
|
|
50
81
|
def lc_container(size: :page, **attributes, &block)
|
|
51
82
|
tag.div(**lc_attributes({ class: lc_container_class(size: size) }, attributes), &block)
|
|
52
83
|
end
|
|
@@ -84,6 +84,19 @@ module Lostcoords::Ui
|
|
|
84
84
|
end
|
|
85
85
|
end
|
|
86
86
|
|
|
87
|
+
# Links styled as a row of tabs over a rule, each page of a view behind one. Unlike lc_tabs, every
|
|
88
|
+
# tab is a link to its own URL. Yields a builder: `bar.link "Replies", replies_path, current: true, count: 12`.
|
|
89
|
+
# fill: true stretches the tabs to share the row; a row too long for its container scrolls sideways.
|
|
90
|
+
def lc_tab_bar(label:, fill: false, **attributes, &block)
|
|
91
|
+
lc_label!(label, :label)
|
|
92
|
+
raise ArgumentError, "lc_tab_bar needs a block" unless block
|
|
93
|
+
|
|
94
|
+
data = { slot: "tab-bar", fill: (true if fill) }.compact
|
|
95
|
+
tag.nav(**lc_attributes({ class: "min-w-0 border-b border-border", aria: { label: label }, data: data }, attributes)) do
|
|
96
|
+
tag.ul(capture(Parts::TabBar.new(self, fill), &block), class: "m-0 flex min-w-0 list-none overflow-x-auto p-0 [scrollbar-width:none] lc-scroll-fade-x [&::-webkit-scrollbar]:hidden")
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
87
100
|
TOC_INDICATOR = "pointer-events-none absolute -start-px top-0 h-0 w-0.5 rounded-pill bg-primary opacity-0 " \
|
|
88
101
|
"transition-[translate,height,opacity] duration-300 ease-(--lc-ease-out-expo) motion-reduce:transition-none"
|
|
89
102
|
|
|
@@ -154,8 +154,26 @@ module Lostcoords::Ui
|
|
|
154
154
|
end
|
|
155
155
|
end
|
|
156
156
|
|
|
157
|
-
|
|
158
|
-
|
|
157
|
+
# title:, text: and icon: lay out the usual empty state: a round icon badge, a heading and a line
|
|
158
|
+
# of muted text, then the block, such as an action. Without them the block is the whole content.
|
|
159
|
+
# level: sets the heading level, and card: true puts the empty state on an lc_card.
|
|
160
|
+
def lc_empty_state(title: nil, text: nil, icon: nil, level: 2, card: false, **attributes, &block)
|
|
161
|
+
extra = capture(&block) if block
|
|
162
|
+
content = if title.present? || text.present? || icon
|
|
163
|
+
heading = [
|
|
164
|
+
(lc_heading(title, level: level, size: :subheading, data: { slot: "empty-state-title" }) if title.present?),
|
|
165
|
+
(lc_text(text, size: :small, tone: :muted, data: { slot: "empty-state-description" }) if text.present?)
|
|
166
|
+
].compact
|
|
167
|
+
safe_join([
|
|
168
|
+
(lc_icon_badge(icon: icon, shape: :circle, size: :lg, data: { slot: "empty-state-icon" }) if icon),
|
|
169
|
+
(lc_stack(gap: :tight, class: "max-w-md") { safe_join(heading) } if heading.any?),
|
|
170
|
+
extra
|
|
171
|
+
].compact)
|
|
172
|
+
else
|
|
173
|
+
extra
|
|
174
|
+
end
|
|
175
|
+
state = tag.div(content, **lc_attributes({ class: lc_empty_state_class, data: { slot: "empty-state" } }, attributes))
|
|
176
|
+
card ? lc_card { state } : state
|
|
159
177
|
end
|
|
160
178
|
|
|
161
179
|
def lc_spinner(size: :md, label: lc_t("lostcoords.ui.spinner.label"), **attributes)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
module Lostcoords::Ui
|
|
2
|
-
# Page chrome: the sticky application header, the documentation layout and the phone dock.
|
|
2
|
+
# Page chrome: the sticky application header, the app sidebar, the documentation layout and the phone dock.
|
|
3
3
|
module ShellHelper
|
|
4
4
|
DOCS_SHELL = "lc-docs-shell mx-auto flex w-full max-w-360 gap-10 px-5 sm:px-8 lg:px-10"
|
|
5
5
|
DOCS_SHELL_ASIDE = "sticky top-(--lc-sticky-offset,0rem) hidden h-[calc(100dvh-var(--lc-sticky-offset,0rem))] shrink-0 overflow-y-auto"
|
|
@@ -48,6 +48,37 @@ module Lostcoords::Ui
|
|
|
48
48
|
end
|
|
49
49
|
end
|
|
50
50
|
|
|
51
|
+
SIDEBAR = "lc-sidebar sticky top-0 flex h-dvh w-(--lc-sidebar-width,15rem) shrink-0 flex-col gap-content overflow-y-auto px-related py-inset " \
|
|
52
|
+
"lc-rail:w-(--lc-sidebar-rail-width,4rem)"
|
|
53
|
+
SIDEBAR_RAIL_BELOW = %i[md lg xl 2xl].freeze
|
|
54
|
+
SIDEBAR_STATES = %w[collapsed expanded].freeze
|
|
55
|
+
|
|
56
|
+
# A sticky, full-height app sidebar that folds to an icon rail. Yields a builder: sidebar.header
|
|
57
|
+
# (a wordmark and the toggle), sidebar.body (usually lc_nav_list), sidebar.footer and
|
|
58
|
+
# sidebar.account. The toggle stores the choice in the cookie named cookie:, which the helper
|
|
59
|
+
# reads back, so the server renders the next page the same way; state: "collapsed" or "expanded"
|
|
60
|
+
# overrides it. Below rail_below: (a breakpoint, or false for never) it starts as a rail unless
|
|
61
|
+
# the reader expanded it. Style your own content for the rail with the lc-rail: variant.
|
|
62
|
+
def lc_sidebar(label: lc_t("lostcoords.ui.sidebar.label"), cookie: "lc_sidebar", rail_below: :xl, state: nil, **attributes, &block)
|
|
63
|
+
lc_label!(label, :label)
|
|
64
|
+
lc_label!(cookie, :cookie)
|
|
65
|
+
raise ArgumentError, "lc_sidebar needs a block" unless block
|
|
66
|
+
|
|
67
|
+
rail_below = lc_option!(:rail_below, rail_below, SIDEBAR_RAIL_BELOW) unless rail_below == false
|
|
68
|
+
# cookies is a controller helper_method that respond_to? can't see from the view, so read the request's.
|
|
69
|
+
state = (state || (request.cookies[cookie] if respond_to?(:request) && request)).to_s
|
|
70
|
+
state = nil unless SIDEBAR_STATES.include?(state)
|
|
71
|
+
collapse_label = lc_t("lostcoords.ui.sidebar.collapse")
|
|
72
|
+
expand_label = lc_t("lostcoords.ui.sidebar.expand")
|
|
73
|
+
|
|
74
|
+
content = capture(Parts::Sidebar.new(self, state == "collapsed" ? expand_label : collapse_label, state != "collapsed"), &block)
|
|
75
|
+
data = { slot: "sidebar", controller: "lc-sidebar lc-scroll-keeper", rail_below: rail_below || nil,
|
|
76
|
+
collapsed: (true if state == "collapsed"), expanded: (true if state == "expanded"),
|
|
77
|
+
lc_sidebar_cookie_value: cookie, lc_sidebar_collapse_label_value: collapse_label, lc_sidebar_expand_label_value: expand_label,
|
|
78
|
+
lc_scroll_keeper_key_value: cookie }.compact
|
|
79
|
+
tag.aside(content, **lc_attributes({ class: SIDEBAR, aria: { label: label }, data: data }, attributes))
|
|
80
|
+
end
|
|
81
|
+
|
|
51
82
|
# A floating bar at the bottom of a phone screen: dock.nav for primary destinations and dock.menu
|
|
52
83
|
# for a button whose actions fan out above it. It reserves its height at the end of the page, so
|
|
53
84
|
# render it last, and it hides while the on-screen keyboard is open.
|
|
@@ -13,6 +13,43 @@ module Lostcoords::Ui
|
|
|
13
13
|
tag.textarea(block ? capture(&block) : content, **lc_attributes({ name: name, class: lc_textarea_class, data: { slot: "textarea" } }, attributes))
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
+
CHAR_COUNTER = "inline-flex items-center gap-related text-small tabular-nums text-primary data-[state=near]:text-warning data-[state=over]:text-destructive"
|
|
17
|
+
CHAR_COUNTER_RADIUS = 9
|
|
18
|
+
|
|
19
|
+
# A ring that fills as a field nears max: characters, as on X. It hides while the field is empty,
|
|
20
|
+
# turns to the warning tone and shows the characters left once warn: or fewer remain, and to the
|
|
21
|
+
# destructive tone with a negative number past the limit. for: is the field's id; without it the
|
|
22
|
+
# nearest field around the counter is counted. To count another way, such as weighted characters,
|
|
23
|
+
# set data-lc-char-counter-count-value or send an event with detail.count to lc-char-counter#update.
|
|
24
|
+
# count: renders that count before JavaScript runs.
|
|
25
|
+
def lc_char_counter(max:, for: nil, warn: 20, count: nil, **attributes)
|
|
26
|
+
field = binding.local_variable_get(:for)
|
|
27
|
+
raise ArgumentError, "max: must be a positive integer" unless max.is_a?(Integer) && max.positive?
|
|
28
|
+
raise ArgumentError, "warn: must be a non-negative integer" unless warn.is_a?(Integer) && !warn.negative?
|
|
29
|
+
raise ArgumentError, "count: must be an integer" unless count.nil? || count.is_a?(Integer)
|
|
30
|
+
|
|
31
|
+
shown = count || 0
|
|
32
|
+
left = max - shown
|
|
33
|
+
circumference = 2 * Math::PI * CHAR_COUNTER_RADIUS
|
|
34
|
+
data = { slot: "char-counter", state: (left.negative? ? "over" : (left <= warn ? "near" : "ok")), controller: "lc-char-counter",
|
|
35
|
+
lc_char_counter_max_value: max, lc_char_counter_warn_value: warn, lc_char_counter_for_value: field.presence,
|
|
36
|
+
lc_char_counter_label_value: lc_t("lostcoords.ui.char_counter.label"), lc_char_counter_count_value: count }.compact
|
|
37
|
+
defaults = { class: CHAR_COUNTER, role: "img", hidden: shown.zero?, aria: { label: lc_t("lostcoords.ui.char_counter.label", count: shown, max: max) }, data: data }
|
|
38
|
+
circle = { cx: 10, cy: 10, r: CHAR_COUNTER_RADIUS, fill: "none", stroke: "currentColor", "stroke-width": 2 }
|
|
39
|
+
tag.span(**lc_attributes(defaults, attributes)) do
|
|
40
|
+
safe_join([
|
|
41
|
+
tag.span((left if left <= warn), data: { slot: "char-counter-remaining", lc_char_counter_target: "remaining" }),
|
|
42
|
+
tag.svg(viewBox: "0 0 20 20", class: "size-6 shrink-0 -rotate-90", aria: { hidden: true }) do
|
|
43
|
+
safe_join([
|
|
44
|
+
tag.circle(**circle, class: "opacity-20"),
|
|
45
|
+
tag.circle(**circle, "stroke-linecap": "round", "stroke-dasharray": "#{([ shown.fdiv(max), 1 ].min * circumference).round(2)} #{circumference.round(2)}",
|
|
46
|
+
data: { lc_char_counter_target: "progress" })
|
|
47
|
+
])
|
|
48
|
+
end
|
|
49
|
+
])
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
16
53
|
def lc_select(options = nil, name: nil, selected: nil, size: :md, **attributes, &block)
|
|
17
54
|
size = lc_option!(:size, size, TailwindHelper::CONTROL_SIZES.keys)
|
|
18
55
|
content = block ? capture(&block) : options_for_select(options || [], selected)
|
|
@@ -108,27 +145,41 @@ module Lostcoords::Ui
|
|
|
108
145
|
tag.button(content, **lc_attributes(defaults.merge(aria: { checked: selected || false }), attributes, required))
|
|
109
146
|
end
|
|
110
147
|
|
|
148
|
+
TOGGLE_ICON_ONLY = "aspect-square px-0"
|
|
149
|
+
|
|
111
150
|
# A button that flips its own aria-pressed. href: renders a link marked current when active, and
|
|
112
151
|
# name: a label around a radio checked when active. A caller that sets aria-pressed or
|
|
113
152
|
# aria-expanded owns the state, so the toggle drops its own controller.
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
153
|
+
# icon: adds a leading icon; with icon_only: true the toggle is a square of just the icon and
|
|
154
|
+
# the label stays as its accessible name. tooltip: true shows the label on hover and focus, and
|
|
155
|
+
# tooltip: "text" describes the toggle with other text, as on lc_icon_button.
|
|
156
|
+
def lc_toggle(label = nil, active: false, ghost: false, size: :md, href: nil, name: nil, value: nil, input: {}, icon: nil, icon_only: false, tooltip: nil, **attributes, &block)
|
|
157
|
+
raise ArgumentError, "icon_only: true needs icon: and a label, not a block" if icon_only && (icon.nil? || label.blank? || block)
|
|
118
158
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
159
|
+
content = block ? capture(&block) : label
|
|
160
|
+
if icon
|
|
161
|
+
glyph = lc_icon(icon, options: { "aria-hidden": true, "data-icon": ("inline-start" unless icon_only) }.compact)
|
|
162
|
+
content = safe_join([ glyph, (icon_only ? tag.span(label, class: "sr-only") : content) ])
|
|
123
163
|
end
|
|
164
|
+
defaults = { class: lc_toggle_class(ghost: ghost, size: size, extra: (TOGGLE_ICON_ONLY if icon_only)), data: { slot: "toggle", icon_only: (true if icon_only) }.compact }
|
|
165
|
+
lc_icon_button_tooltip(label, tooltip, attributes) do |tip|
|
|
166
|
+
attributes = lc_attributes(attributes, tip)
|
|
167
|
+
next lc_toggle_link(content, href, active, defaults, attributes) if href
|
|
168
|
+
|
|
169
|
+
if name
|
|
170
|
+
value ||= label
|
|
171
|
+
lc_label!(value, :value)
|
|
172
|
+
next lc_toggle_radio(content, name, value, active, input, defaults, attributes)
|
|
173
|
+
end
|
|
124
174
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
175
|
+
if lc_normalize_attributes(attributes).fetch(:aria, {}).slice(:pressed, :expanded).any?
|
|
176
|
+
raise ArgumentError, "pass active: or aria: { pressed: }, not both" if active
|
|
177
|
+
else
|
|
178
|
+
defaults[:aria] = { pressed: active }
|
|
179
|
+
defaults[:data].merge!(controller: "lc-toggle", action: "click->lc-toggle#toggle")
|
|
180
|
+
end
|
|
181
|
+
tag.button(content, **lc_attributes(defaults, attributes).merge(type: "button"))
|
|
130
182
|
end
|
|
131
|
-
tag.button(content, **lc_attributes(defaults, attributes).merge(type: "button"))
|
|
132
183
|
end
|
|
133
184
|
|
|
134
185
|
private
|
|
@@ -42,6 +42,28 @@ module Lostcoords::Ui
|
|
|
42
42
|
tag.public_send(lc_option!(:as, as, TEXT_ELEMENTS), content, **lc_attributes({ class: lc_text_class(size: size, tone: tone, trim: trim) }, attributes), &block)
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
+
# A <time> with the short text X shows: "now", "12m" and "4h" within a day, then "4 Nov", and
|
|
46
|
+
# "4 Nov 2025" in another year; a Date shows its day. The full date and time is its title, and
|
|
47
|
+
# detail: adds to it. now: is the moment to count from. Texts and formats are lostcoords.ui.time.*.
|
|
48
|
+
def lc_time(time, now: Time.current, detail: nil, **attributes)
|
|
49
|
+
raise ArgumentError, "lc_time needs a Time, DateTime or Date" unless time.is_a?(Time) || time.is_a?(Date)
|
|
50
|
+
|
|
51
|
+
date = time.instance_of?(Date)
|
|
52
|
+
time = time.in_time_zone
|
|
53
|
+
elapsed = now - time
|
|
54
|
+
text = if date || elapsed.negative? || elapsed >= 1.day
|
|
55
|
+
lc_localize_time(time, time.year == now.year ? :date : :date_with_year)
|
|
56
|
+
elsif elapsed < 1.minute
|
|
57
|
+
lc_t("lostcoords.ui.time.now")
|
|
58
|
+
elsif elapsed < 1.hour
|
|
59
|
+
lc_t("lostcoords.ui.time.minutes", count: (elapsed / 1.minute).floor)
|
|
60
|
+
else
|
|
61
|
+
lc_t("lostcoords.ui.time.hours", count: (elapsed / 1.hour).floor)
|
|
62
|
+
end
|
|
63
|
+
title = [ lc_localize_time(time, date ? :date_with_year : :full), detail.presence ].compact.join(" · ")
|
|
64
|
+
tag.time(text, **lc_attributes({ datetime: (date ? time.to_date.iso8601 : time.iso8601), title: title, data: { slot: "time" } }, attributes))
|
|
65
|
+
end
|
|
66
|
+
|
|
45
67
|
# A key hint, such as lc_kbd("mod+k"). "mod" renders Ctrl and reads ⌘ on Apple platforms once JS runs.
|
|
46
68
|
def lc_kbd(keys, **attributes)
|
|
47
69
|
lc_label!(keys, :keys)
|
|
@@ -63,5 +85,13 @@ module Lostcoords::Ui
|
|
|
63
85
|
data = data.to_h.symbolize_keys
|
|
64
86
|
data.merge(controller: [ data[:controller], "lc-shortcut" ].compact.join(" "), lc_shortcut_keys_value: keys)
|
|
65
87
|
end
|
|
88
|
+
|
|
89
|
+
private
|
|
90
|
+
# Month names come from the host's locale, as rails-i18n provides them; without them, English ones.
|
|
91
|
+
def lc_localize_time(time, format)
|
|
92
|
+
pattern = lc_t("lostcoords.ui.time.formats.#{format}")
|
|
93
|
+
named = I18n.exists?(:"date.month_names") && I18n.exists?(:"date.abbr_month_names")
|
|
94
|
+
named ? I18n.l(time, format: pattern) : time.strftime(pattern)
|
|
95
|
+
end
|
|
66
96
|
end
|
|
67
97
|
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Controller } from "@hotwired/stimulus"
|
|
2
|
+
|
|
3
|
+
const FIELDS =
|
|
4
|
+
"textarea, input:not([type=hidden], [type=checkbox], [type=radio], [type=submit], [type=button], [type=reset])"
|
|
5
|
+
|
|
6
|
+
// Fills lc_char_counter's ring from a field's characters, or from a count you supply: set the count value,
|
|
7
|
+
// or send an event whose detail.count is the count to update.
|
|
8
|
+
export default class extends Controller {
|
|
9
|
+
static targets = ["remaining", "progress"]
|
|
10
|
+
static values = {
|
|
11
|
+
max: Number,
|
|
12
|
+
warn: { type: Number, default: 20 },
|
|
13
|
+
for: String,
|
|
14
|
+
label: String,
|
|
15
|
+
count: Number,
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
connect() {
|
|
19
|
+
this.field = this.forValue ? document.getElementById(this.forValue) : this.nearestField()
|
|
20
|
+
this.input = () => this.render()
|
|
21
|
+
this.field?.addEventListener("input", this.input)
|
|
22
|
+
this.render()
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
disconnect() {
|
|
26
|
+
this.field?.removeEventListener("input", this.input)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
update({ detail }) {
|
|
30
|
+
this.countValue = detail.count
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
countValueChanged() {
|
|
34
|
+
if (this.field !== undefined) this.render()
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
get count() {
|
|
38
|
+
if (this.hasCountValue) return this.countValue
|
|
39
|
+
return Array.from(this.field?.value ?? "").length
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
render() {
|
|
43
|
+
const count = this.count
|
|
44
|
+
const left = this.maxValue - count
|
|
45
|
+
const circumference = 2 * Math.PI * Number(this.progressTarget.getAttribute("r"))
|
|
46
|
+
this.progressTarget.style.strokeDasharray = `${Math.min(count / this.maxValue, 1) * circumference} ${circumference}`
|
|
47
|
+
this.element.dataset.state = left < 0 ? "over" : left <= this.warnValue ? "near" : "ok"
|
|
48
|
+
this.element.hidden = count === 0
|
|
49
|
+
this.remainingTarget.textContent = left <= this.warnValue ? String(left) : ""
|
|
50
|
+
this.element.setAttribute(
|
|
51
|
+
"aria-label",
|
|
52
|
+
this.labelValue.replace("%{count}", count).replace("%{max}", this.maxValue),
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
nearestField() {
|
|
57
|
+
for (let node = this.element.parentElement; node; node = node.parentElement) {
|
|
58
|
+
const field = node.querySelector(FIELDS)
|
|
59
|
+
if (field) return field
|
|
60
|
+
}
|
|
61
|
+
return null
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Controller } from "@hotwired/stimulus"
|
|
2
|
+
|
|
3
|
+
const BREAKPOINTS = { md: "48rem", lg: "64rem", xl: "80rem", "2xl": "96rem" }
|
|
4
|
+
|
|
5
|
+
// Folds lc_sidebar to an icon rail and back, and keeps the choice in a cookie so the server renders the
|
|
6
|
+
// next page the same way. Below its data-rail-below breakpoint it is a rail unless the reader expanded it.
|
|
7
|
+
export default class extends Controller {
|
|
8
|
+
static targets = ["toggle"]
|
|
9
|
+
static values = { cookie: String, collapseLabel: String, expandLabel: String }
|
|
10
|
+
|
|
11
|
+
connect() {
|
|
12
|
+
const width = BREAKPOINTS[this.element.dataset.railBelow]
|
|
13
|
+
this.query = width ? matchMedia(`(width < ${width})`) : null
|
|
14
|
+
this.sync = () => this.label()
|
|
15
|
+
this.query?.addEventListener("change", this.sync)
|
|
16
|
+
this.label()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
disconnect() {
|
|
20
|
+
this.query?.removeEventListener("change", this.sync)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
toggle() {
|
|
24
|
+
const collapse = !this.rail
|
|
25
|
+
this.element.toggleAttribute("data-collapsed", collapse)
|
|
26
|
+
this.element.toggleAttribute("data-expanded", !collapse)
|
|
27
|
+
// biome-ignore lint/suspicious/noDocumentCookie: the server reads this cookie to render the next page the same way
|
|
28
|
+
document.cookie = `${encodeURIComponent(this.cookieValue)}=${collapse ? "collapsed" : "expanded"}; path=/; max-age=31536000; samesite=lax`
|
|
29
|
+
this.label()
|
|
30
|
+
this.dispatch("toggle", { detail: { collapsed: collapse } })
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
get rail() {
|
|
34
|
+
if (this.element.hasAttribute("data-collapsed")) return true
|
|
35
|
+
if (this.element.hasAttribute("data-expanded")) return false
|
|
36
|
+
return Boolean(this.query?.matches)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
label() {
|
|
40
|
+
const rail = this.rail
|
|
41
|
+
const label = rail ? this.expandLabelValue : this.collapseLabelValue
|
|
42
|
+
for (const toggle of this.toggleTargets) {
|
|
43
|
+
toggle.setAttribute("aria-label", label)
|
|
44
|
+
toggle.setAttribute("title", label)
|
|
45
|
+
toggle.setAttribute("aria-expanded", String(!rail))
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import AppHeader from "lostcoords/ui/controllers/lc_app_header_controller"
|
|
2
|
+
import CharCounter from "lostcoords/ui/controllers/lc_char_counter_controller"
|
|
2
3
|
import CodeBlock from "lostcoords/ui/controllers/lc_code_block_controller"
|
|
3
4
|
import Collapsible from "lostcoords/ui/controllers/lc_collapsible_controller"
|
|
4
5
|
import Copy from "lostcoords/ui/controllers/lc_copy_controller"
|
|
@@ -14,6 +15,7 @@ import Search from "lostcoords/ui/controllers/lc_search_controller"
|
|
|
14
15
|
import Selection from "lostcoords/ui/controllers/lc_selection_controller"
|
|
15
16
|
import Sheet from "lostcoords/ui/controllers/lc_sheet_controller"
|
|
16
17
|
import Shortcut from "lostcoords/ui/controllers/lc_shortcut_controller"
|
|
18
|
+
import Sidebar from "lostcoords/ui/controllers/lc_sidebar_controller"
|
|
17
19
|
import Tabs from "lostcoords/ui/controllers/lc_tabs_controller"
|
|
18
20
|
import Toast from "lostcoords/ui/controllers/lc_toast_controller"
|
|
19
21
|
import ToastRegion from "lostcoords/ui/controllers/lc_toast_region_controller"
|
|
@@ -23,6 +25,7 @@ import Tooltip from "lostcoords/ui/controllers/lc_tooltip_controller"
|
|
|
23
25
|
|
|
24
26
|
const controllers = {
|
|
25
27
|
"lc-app-header": AppHeader,
|
|
28
|
+
"lc-char-counter": CharCounter,
|
|
26
29
|
"lc-collapsible": Collapsible,
|
|
27
30
|
"lc-code-block": CodeBlock,
|
|
28
31
|
"lc-copy": Copy,
|
|
@@ -38,6 +41,7 @@ const controllers = {
|
|
|
38
41
|
"lc-selection": Selection,
|
|
39
42
|
"lc-sheet": Sheet,
|
|
40
43
|
"lc-shortcut": Shortcut,
|
|
44
|
+
"lc-sidebar": Sidebar,
|
|
41
45
|
"lc-tabs": Tabs,
|
|
42
46
|
"lc-toc": Toc,
|
|
43
47
|
"lc-toast": Toast,
|
data/config/locales/en.yml
CHANGED
|
@@ -29,6 +29,20 @@ en:
|
|
|
29
29
|
navigation: "Main"
|
|
30
30
|
dock:
|
|
31
31
|
close: "Close %{label}"
|
|
32
|
+
sidebar:
|
|
33
|
+
label: "Sidebar"
|
|
34
|
+
collapse: "Collapse sidebar"
|
|
35
|
+
expand: "Expand sidebar"
|
|
36
|
+
char_counter:
|
|
37
|
+
label: "%{count} of %{max} characters"
|
|
38
|
+
time:
|
|
39
|
+
now: "now"
|
|
40
|
+
minutes: "%{count}m"
|
|
41
|
+
hours: "%{count}h"
|
|
42
|
+
formats:
|
|
43
|
+
date: "%-d %b"
|
|
44
|
+
date_with_year: "%-d %b %Y"
|
|
45
|
+
full: "%-d %B %Y, %H:%M"
|
|
32
46
|
breadcrumb:
|
|
33
47
|
label: "Breadcrumb"
|
|
34
48
|
code_block:
|
data/config/locales/es.yml
CHANGED
|
@@ -29,6 +29,20 @@ es:
|
|
|
29
29
|
navigation: "Principal"
|
|
30
30
|
dock:
|
|
31
31
|
close: "Cerrar %{label}"
|
|
32
|
+
sidebar:
|
|
33
|
+
label: "Barra lateral"
|
|
34
|
+
collapse: "Contraer la barra lateral"
|
|
35
|
+
expand: "Expandir la barra lateral"
|
|
36
|
+
char_counter:
|
|
37
|
+
label: "%{count} de %{max} caracteres"
|
|
38
|
+
time:
|
|
39
|
+
now: "ahora"
|
|
40
|
+
minutes: "%{count} min"
|
|
41
|
+
hours: "%{count} h"
|
|
42
|
+
formats:
|
|
43
|
+
date: "%-d %b"
|
|
44
|
+
date_with_year: "%-d %b %Y"
|
|
45
|
+
full: "%-d de %B de %Y, %H:%M"
|
|
32
46
|
breadcrumb:
|
|
33
47
|
label: "Ruta de navegación"
|
|
34
48
|
code_block:
|
data/config/locales/ja.yml
CHANGED
|
@@ -29,6 +29,20 @@ ja:
|
|
|
29
29
|
navigation: "メイン"
|
|
30
30
|
dock:
|
|
31
31
|
close: "%{label}を閉じる"
|
|
32
|
+
sidebar:
|
|
33
|
+
label: "サイドバー"
|
|
34
|
+
collapse: "サイドバーを折りたたむ"
|
|
35
|
+
expand: "サイドバーを展開する"
|
|
36
|
+
char_counter:
|
|
37
|
+
label: "%{max}文字中%{count}文字"
|
|
38
|
+
time:
|
|
39
|
+
now: "たった今"
|
|
40
|
+
minutes: "%{count}分"
|
|
41
|
+
hours: "%{count}時間"
|
|
42
|
+
formats:
|
|
43
|
+
date: "%-m月%-d日"
|
|
44
|
+
date_with_year: "%Y年%-m月%-d日"
|
|
45
|
+
full: "%Y年%-m月%-d日 %H:%M"
|
|
32
46
|
breadcrumb:
|
|
33
47
|
label: "パンくずリスト"
|
|
34
48
|
code_block:
|
data/lib/lostcoords/ui/parts.rb
CHANGED
|
@@ -195,6 +195,35 @@ module Lostcoords::Ui
|
|
|
195
195
|
end
|
|
196
196
|
end
|
|
197
197
|
|
|
198
|
+
class TabBar < Base
|
|
199
|
+
LINK = "flex justify-center px-content text-small text-muted-foreground no-underline transition-colors duration-(--lc-motion-quick) " \
|
|
200
|
+
"hover:bg-accent hover:text-foreground aria-[current=page]:font-semibold aria-[current=page]:text-foreground"
|
|
201
|
+
|
|
202
|
+
def initialize(view, fill)
|
|
203
|
+
super(view)
|
|
204
|
+
@fill = fill
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
# current: marks the tab of the page the reader is on with aria-current="page". count: shows a
|
|
208
|
+
# muted number after the label; nil shows none.
|
|
209
|
+
def link(label, url, current: false, count: nil, **attributes)
|
|
210
|
+
view.send(:lc_label!, label, :label)
|
|
211
|
+
raise ArgumentError, "tab bar link needs a URL" if url.blank?
|
|
212
|
+
|
|
213
|
+
view.tag.li(class: (@fill ? "min-w-fit flex-1" : "shrink-0"), data: { slot: "tab-bar-item" }) do
|
|
214
|
+
view.link_to(url, **merge({ class: LINK, aria: { current: ("page" if current) }, data: { slot: "tab-bar-link" } }, attributes)) do
|
|
215
|
+
view.tag.span(class: "relative flex items-center gap-tight py-content whitespace-nowrap") do
|
|
216
|
+
view.safe_join([
|
|
217
|
+
label,
|
|
218
|
+
(view.tag.span(count, class: "font-normal tabular-nums text-muted-foreground", data: { slot: "tab-bar-count" }) unless count.nil?),
|
|
219
|
+
(view.tag.span(class: "absolute inset-x-0 bottom-0 h-1 rounded-pill bg-(--lc-tab-bar-indicator,var(--primary))", aria: { hidden: true }, data: { slot: "tab-bar-indicator" }) if current)
|
|
220
|
+
].compact)
|
|
221
|
+
end
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
end
|
|
225
|
+
end
|
|
226
|
+
|
|
198
227
|
class Toc < Base
|
|
199
228
|
LINK = "relative block py-tight ps-content pe-tight text-small text-muted-foreground no-underline transition-colors " \
|
|
200
229
|
"duration-(--lc-motion-quick) hover:text-foreground aria-[current=location]:font-medium aria-[current=location]:text-foreground"
|
|
@@ -233,6 +262,63 @@ module Lostcoords::Ui
|
|
|
233
262
|
end
|
|
234
263
|
end
|
|
235
264
|
|
|
265
|
+
class Sidebar < Base
|
|
266
|
+
ACCOUNT_TRIGGER = "flex w-full min-w-0 cursor-pointer items-center gap-related rounded-xl lc-squircle px-heading py-related text-start " \
|
|
267
|
+
"transition-colors duration-(--lc-motion-quick) hover:bg-accent aria-expanded:bg-accent lc-rail:justify-center lc-rail:px-0"
|
|
268
|
+
|
|
269
|
+
def initialize(view, toggle_label, expanded)
|
|
270
|
+
super(view)
|
|
271
|
+
@toggle_label = toggle_label
|
|
272
|
+
@expanded = expanded
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
# The top row: the block, usually a wordmark linking home, then the toggle. On the rail the row
|
|
276
|
+
# stacks; show a short mark there with the lc-rail: variant. toggle: false leaves the toggle out.
|
|
277
|
+
def header(toggle: true, **attributes, &block)
|
|
278
|
+
part(:div, "sidebar-header", "flex items-center justify-between gap-related ps-heading lc-rail:flex-col lc-rail:ps-0", attributes) do
|
|
279
|
+
view.safe_join([ (view.capture(&block) if block), (self.toggle if toggle) ].compact)
|
|
280
|
+
end
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
# The button that folds the sidebar to a rail and back. Its label, title and aria-expanded follow the state.
|
|
284
|
+
def toggle(**attributes)
|
|
285
|
+
view.lc_icon_button(@toggle_label, icon: "chevron-double-left", size: :sm,
|
|
286
|
+
**merge({ class: "lc-sidebar__toggle", title: @toggle_label, aria: { expanded: @expanded },
|
|
287
|
+
data: { slot: "sidebar-toggle", action: "lc-sidebar#toggle", lc_sidebar_target: "toggle" } }, attributes))
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
# The growing middle, usually an lc_nav_list. On the rail its group titles and link labels stay
|
|
291
|
+
# for screen readers only and the links center their icons; give each link a title:.
|
|
292
|
+
def body(**attributes, &block)
|
|
293
|
+
part(:div, "sidebar-body", "flex min-h-0 flex-1 flex-col gap-content", attributes, &block)
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
def footer(**attributes, &block)
|
|
297
|
+
part(:div, "sidebar-footer", "flex min-w-0 flex-col gap-related", attributes, &block)
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
# A full-width row that opens an lc_menu of the block's lc_menu_option items: avatar:, the name and
|
|
301
|
+
# a detail line, such as an email. On the rail only the avatar shows. Attributes go to the row.
|
|
302
|
+
def account(name, detail: nil, avatar: nil, id: "sidebar-account", align: :start, **attributes, &block)
|
|
303
|
+
view.send(:lc_label!, name, :name)
|
|
304
|
+
raise ArgumentError, "sidebar account needs a block of menu options" unless block
|
|
305
|
+
|
|
306
|
+
text = view.tag.span(class: "min-w-0 grow lc-rail:sr-only", data: { slot: "sidebar-account-text" }) do
|
|
307
|
+
view.safe_join([
|
|
308
|
+
view.tag.span(name, class: "block truncate text-label"),
|
|
309
|
+
(view.tag.span(detail, class: "block truncate text-caption text-muted-foreground") if detail.present?)
|
|
310
|
+
].compact)
|
|
311
|
+
end
|
|
312
|
+
ellipsis = view.lc_icon("ellipsis-horizontal", options: { class: "size-4 shrink-0 text-muted-foreground lc-rail:hidden", "aria-hidden": true })
|
|
313
|
+
view.lc_menu(id: id, align: align, wrapper_attributes: { class: "flex w-full", data: { slot: "sidebar-account" } }) do |menu|
|
|
314
|
+
menu.trigger(**merge({ class: ACCOUNT_TRIGGER, title: name, data: { slot: "sidebar-account-trigger" } }, attributes)) do |wiring|
|
|
315
|
+
view.tag.button(view.safe_join([ avatar, text, ellipsis ].compact), type: "button", **wiring)
|
|
316
|
+
end
|
|
317
|
+
view.capture(&block)
|
|
318
|
+
end
|
|
319
|
+
end
|
|
320
|
+
end
|
|
321
|
+
|
|
236
322
|
class Dock < Base
|
|
237
323
|
# The primary destinations, icon above label; yields the lc_nav_list builder.
|
|
238
324
|
def nav(label:, **attributes, &block)
|
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.
|
|
4
|
+
version: 0.10.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Lost Coordinates
|
|
@@ -119,6 +119,7 @@ files:
|
|
|
119
119
|
- app/assets/tailwind/lostcoords/ui/table.css
|
|
120
120
|
- app/assets/tailwind/lostcoords/ui/theme.css
|
|
121
121
|
- app/assets/tailwind/lostcoords/ui/toast.css
|
|
122
|
+
- app/assets/tailwind/lostcoords/ui/toggle-group.css
|
|
122
123
|
- app/assets/tailwind/lostcoords/ui/tooltip.css
|
|
123
124
|
- app/assets/tailwind/lostcoords/ui/typography.css
|
|
124
125
|
- app/assets/tailwind/lostcoords/ui/ui.css
|
|
@@ -156,6 +157,7 @@ files:
|
|
|
156
157
|
- app/helpers/lostcoords/ui/translation_helper.rb
|
|
157
158
|
- app/helpers/lostcoords/ui/typography_helper.rb
|
|
158
159
|
- app/javascript/lostcoords/ui/controllers/lc_app_header_controller.js
|
|
160
|
+
- app/javascript/lostcoords/ui/controllers/lc_char_counter_controller.js
|
|
159
161
|
- app/javascript/lostcoords/ui/controllers/lc_code_block_controller.js
|
|
160
162
|
- app/javascript/lostcoords/ui/controllers/lc_collapsible_controller.js
|
|
161
163
|
- app/javascript/lostcoords/ui/controllers/lc_copy_controller.js
|
|
@@ -171,6 +173,7 @@ files:
|
|
|
171
173
|
- app/javascript/lostcoords/ui/controllers/lc_selection_controller.js
|
|
172
174
|
- app/javascript/lostcoords/ui/controllers/lc_sheet_controller.js
|
|
173
175
|
- app/javascript/lostcoords/ui/controllers/lc_shortcut_controller.js
|
|
176
|
+
- app/javascript/lostcoords/ui/controllers/lc_sidebar_controller.js
|
|
174
177
|
- app/javascript/lostcoords/ui/controllers/lc_tabs_controller.js
|
|
175
178
|
- app/javascript/lostcoords/ui/controllers/lc_toast_controller.js
|
|
176
179
|
- app/javascript/lostcoords/ui/controllers/lc_toast_region_controller.js
|