lostcoords-ui 0.12.1 → 0.13.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 +65 -14
- data/app/assets/tailwind/lostcoords/ui/components/menu.css +0 -1
- data/app/assets/tailwind/lostcoords/ui/dialog.css +7 -0
- data/app/assets/tailwind/lostcoords/ui/popover.css +10 -0
- data/app/assets/tailwind/lostcoords/ui/sheet.css +3 -0
- data/app/helpers/lostcoords/ui/card_helper.rb +1 -1
- data/app/helpers/lostcoords/ui/dialog_helper.rb +3 -3
- data/app/helpers/lostcoords/ui/list_group_helper.rb +24 -24
- data/app/helpers/lostcoords/ui/menu_helper.rb +31 -24
- data/app/helpers/lostcoords/ui/primitives_helper.rb +8 -15
- data/app/helpers/lostcoords/ui/sheet_helper.rb +11 -11
- data/app/helpers/lostcoords/ui/tailwind_helper.rb +8 -2
- data/app/javascript/lostcoords/ui/controllers/lc_hovercard_controller.js +3 -2
- data/app/javascript/lostcoords/ui/controllers/lc_menu_controller.js +14 -9
- data/app/javascript/lostcoords/ui/controllers/lc_search_controller.js +1 -1
- data/app/javascript/lostcoords/ui/controllers/lc_tooltip_controller.js +3 -5
- data/app/javascript/lostcoords/ui/helpers/catalog_picker.js +1 -1
- data/app/javascript/lostcoords/ui/helpers/dialog.js +18 -0
- data/app/javascript/lostcoords/ui/helpers/dismiss_stack.js +12 -2
- data/app/javascript/lostcoords/ui/helpers/floating_panel.js +16 -14
- data/app/views/lostcoords/ui/components/_lc_confirm_sheet.html.erb +1 -1
- data/app/views/lostcoords/ui/components/_lc_dialog.html.erb +1 -1
- data/lib/lostcoords/ui/version.rb +1 -1
- metadata +1 -2
- data/app/views/lostcoords/ui/components/_lc_floating_panel.html.erb +0 -13
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b3f578cb7c1458cb27bd0c44a42cf6c854c723b2563f1423ff475abcf15f6501
|
|
4
|
+
data.tar.gz: 88bcd94b3ab445751a2015bdd2bca39cc0c598975a3ea552aa8bbd0d56c72a5c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bff6b27cab3259589f45378404fb05076cd94599b46adb679ad4648100c1c1eaea96233c5d608ce4a7142b84361e12760fcc497c5cff3ecde001c0004ff8d4ae
|
|
7
|
+
data.tar.gz: ce449b6a22fc76aaf00706565579b10e04ebac494f3244160dadc4d36be75dc37c1f9864c941abee28d8abc3e84eeae51995cc63cee9420dc4cc129f8eb79a65
|
data/README.md
CHANGED
|
@@ -170,6 +170,56 @@ 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.13.0
|
|
174
|
+
|
|
175
|
+
Two renames to make, and the rest needs no edit:
|
|
176
|
+
|
|
177
|
+
- **`tag:` is `as:` on `lc_list_group`, `lc_list_row`, `lc_list_field`, `lc_list_item` and `lc_sheet`**, as on
|
|
178
|
+
every other builder that picks its element. Before: `lc_sheet tag: :dialog`, `lc_list_row "Alerts", tag: :label`.
|
|
179
|
+
After: `lc_sheet as: :dialog`, `lc_list_row "Alerts", as: :label`. A leftover `tag:` no longer picks the element:
|
|
180
|
+
it renders as a `tag` attribute, so search your views for it.
|
|
181
|
+
- **`lc_dialog_class` takes `kind:` as a keyword**, like every other class helper. Before:
|
|
182
|
+
`lc_dialog_class(:context)`. After: `lc_dialog_class(kind: :context)`.
|
|
183
|
+
|
|
184
|
+
Changed:
|
|
185
|
+
|
|
186
|
+
- **A split button's toggle runs your actions before the menu's.** `toggle: { data: { action: … } }` now comes
|
|
187
|
+
first in `data-action`, as `trigger_attributes:` does on `lc_menu`. `lc_split_button` renders through the same
|
|
188
|
+
code as `lc_menu`, so the two cannot drift.
|
|
189
|
+
|
|
190
|
+
Fixed:
|
|
191
|
+
|
|
192
|
+
- **A menu in a row that a Turbo morph reordered no longer breaks the next visit.** The morph moves a menu's
|
|
193
|
+
trigger and panel, which carry ids, into the row that takes its place and removes the emptied host. That
|
|
194
|
+
host's `lc-menu` failed to disconnect and left listeners behind, and the next visit threw
|
|
195
|
+
`Missing target element "popover" for "lc-menu" controller` once per orphaned menu. `FloatingPanel` now
|
|
196
|
+
listens to the document only while its panel is open, and no teardown reads a target; a subclass's
|
|
197
|
+
`disconnect` should not read one either.
|
|
198
|
+
- **A trigger that a morph replaces keeps its arrow keys.** `lc-menu` hears keys on its host, not on the
|
|
199
|
+
trigger and panel it found when it connected.
|
|
200
|
+
- **Menus, popovers, dialogs, phone sheets and linked cards stay put under reduced motion.** They still fade, but
|
|
201
|
+
no longer slide, grow or lift. Before, only the document reset in `base.css` shortened these, so a host that
|
|
202
|
+
skips `base.css` kept the movement.
|
|
203
|
+
|
|
204
|
+
New options:
|
|
205
|
+
|
|
206
|
+
- **`lc_menu` and `lc_popover` take the same options.** `lc_menu` gains `trigger_variant:`, `lc_popover` gains
|
|
207
|
+
`side:` and `trigger_size:`, and `trigger_size:` now also sizes a text trigger.
|
|
208
|
+
|
|
209
|
+
Faster:
|
|
210
|
+
|
|
211
|
+
- **`lc_tw` keeps one class merger for the process** instead of one per view, so a class list merged in one
|
|
212
|
+
request is a cache hit in the next.
|
|
213
|
+
|
|
214
|
+
## Changes in 0.12.2
|
|
215
|
+
|
|
216
|
+
Nothing needs an edit. Fixed:
|
|
217
|
+
|
|
218
|
+
- **Back no longer brings a dialog back half open.** Turbo snapshots a page with its open dialogs, and
|
|
219
|
+
restoring one kept the `open` attribute without the top layer: no backdrop, focus trap or Escape, and the
|
|
220
|
+
page stayed pinned by the scroll lock. A dialog joined through `registerDialog` now comes back closed and
|
|
221
|
+
the page unpinned; a controller that reopens its dialog on connect shows it as a real modal again.
|
|
222
|
+
|
|
173
223
|
## Changes in 0.12.1
|
|
174
224
|
|
|
175
225
|
Nothing needs an edit. Changed:
|
|
@@ -350,7 +400,7 @@ Everything else in 0.8 is additive. These changes need edits in an app built on
|
|
|
350
400
|
mark the selected item with `checked:` or the group's `value:` instead of `selected:`. A group without
|
|
351
401
|
`name:` keeps the radio buttons and `lc-selection:change`; it no longer has an `input` target.
|
|
352
402
|
- **`lc_sheet_data` is gone.** Before: `tag.dialog data: lc_sheet_data({ controller: "picker" }, detents: "large")`.
|
|
353
|
-
After: `lc_sheet
|
|
403
|
+
After: `lc_sheet as: :dialog, detents: "large", data: { controller: "picker" }`. `lc_sheet` also renders
|
|
354
404
|
non-dialog sheets, so drop any hand-written `data-controller="lc-sheet"` and handle element too.
|
|
355
405
|
- **The `lc-confirm-dialog` controller is gone.** Before: a pre-rendered confirm `<dialog>` wired to
|
|
356
406
|
`lc-confirm-dialog`. After: render `lc_confirm_sheet` once in the layout and put `data-turbo-confirm` on
|
|
@@ -384,7 +434,7 @@ Primary, secondary and destructive buttons have visible filled surfaces. Ghost b
|
|
|
384
434
|
Primary, secondary and destructive buttons are flat. Secondary buttons use a soft neutral fill distinct from page and card backgrounds.
|
|
385
435
|
Outline buttons have a transparent fill and a visible edge. Glass buttons use the shared translucent material, rim and shadow for floating controls.
|
|
386
436
|
The default light theme uses white pages and softly shaded cards, with no visible card borders or resting shadows.
|
|
387
|
-
|
|
437
|
+
Menu and popover triggers accept `trigger_variant` using the same button variants.
|
|
388
438
|
Button hover and press fills mix 94% of the base background with 6% of its foreground in OKLab.
|
|
389
439
|
Ghost and icon buttons stay transparent at rest and use the secondary base for that calculation.
|
|
390
440
|
Apps can override `--secondary` for the neutral base, or `--lc-button-bg` and `--lc-button-ink` on individual buttons.
|
|
@@ -541,7 +591,7 @@ makes the summary look like that `lc_button` without the native marker, and `ind
|
|
|
541
591
|
<%= lc_list_row "Email", subtitle: "ada@example.com", icon: "envelope" do %>
|
|
542
592
|
<%= lc_button "Change", variant: :secondary, size: :sm %>
|
|
543
593
|
<% end %>
|
|
544
|
-
<%= lc_list_row "Alerts",
|
|
594
|
+
<%= lc_list_row "Alerts", as: :label do %><%= check_box_tag :alerts, class: lc_switch_class %><% end %>
|
|
545
595
|
<% end %>
|
|
546
596
|
<% end %>
|
|
547
597
|
```
|
|
@@ -550,8 +600,8 @@ makes the summary look like that `lc_button` without the native marker, and `ind
|
|
|
550
600
|
only the group's ends round. The group rounds its first and last shown child, so a collapsible or any other
|
|
551
601
|
element at an end rounds too, and a `hidden` row hands its corners to the next one shown. Rows are card surfaces, so fields and buttons in them follow
|
|
552
602
|
`--card-input` and `--card-secondary`. `lc_list_row` with a title lays out `icon:` (a name, or your own
|
|
553
|
-
markup such as a logo), the title, `subtitle:` and the block as trailing content; `
|
|
554
|
-
`label`, `li`, `details` or `a` (`href:`). `href:` with `
|
|
603
|
+
markup such as a logo), the title, `subtitle:` and the block as trailing content; `as:` makes it a
|
|
604
|
+
`label`, `li`, `details` or `a` (`href:`). `href:` with `as: :li` or `:div` links the title instead
|
|
555
605
|
and stretches it over the row, so the block can hold buttons and links of its own; a click anywhere
|
|
556
606
|
else in the row follows the title. Without a title the block is the whole row, and
|
|
557
607
|
`padded: false` leaves the padding to content such as an `lc_list_item` button or summary, which lays
|
|
@@ -573,8 +623,8 @@ with `--primary-soft` and its text turns semibold, and the focus halo rings the
|
|
|
573
623
|
|
|
574
624
|
`lc_list_field` is a form row in the same group: a label column, then the block as the control. In a
|
|
575
625
|
narrow row the label folds to its `icon:`, and the text stays the accessible name. `id:` makes the label
|
|
576
|
-
a `<label>` for that control; `
|
|
577
|
-
`
|
|
626
|
+
a `<label>` for that control; `as: :fieldset` names a group of controls, such as chips, with a legend.
|
|
627
|
+
`as: :span, surface: false` draws the row inside another element, such as a collapsible's summary.
|
|
578
628
|
`lc_input(plain: true)` drops the field's fill, border, padding and height so the text sits in the row,
|
|
579
629
|
which tints while that input has focus. Toggles take `--lc-field-bg` like fields, so on a card or list
|
|
580
630
|
row they use `--card-input`.
|
|
@@ -584,7 +634,7 @@ row they use `--card-input`.
|
|
|
584
634
|
<%= lc_list_field "Description", icon: "pencil", id: "description" do %>
|
|
585
635
|
<%= lc_input plain: true, id: "description", name: "description" %>
|
|
586
636
|
<% end %>
|
|
587
|
-
<%= lc_list_field "Paid by", icon: "user",
|
|
637
|
+
<%= lc_list_field "Paid by", icon: "user", as: :fieldset do %>
|
|
588
638
|
<div class="flex flex-wrap gap-related"><%= lc_toggle "Ada", size: :sm, aria: { pressed: true } %></div>
|
|
589
639
|
<% end %>
|
|
590
640
|
<% end %>
|
|
@@ -847,8 +897,9 @@ options stay on the menu's columns.
|
|
|
847
897
|
`trigger` targets. With `click->lc-popover#toggleFromRow` on that host, a click anywhere on it that
|
|
848
898
|
misses a control opens the panel; mark other regions `data-lc-menu-ignore`.
|
|
849
899
|
`lc_menu` and `lc_popover` take `trigger: :icon` with `icon:` for a quiet icon button named by `label:`,
|
|
850
|
-
or rendered content such as an avatar for a custom trigger. `
|
|
851
|
-
`
|
|
900
|
+
or rendered content such as an avatar for a custom trigger. `trigger_size: :sm` makes any trigger a small control, and
|
|
901
|
+
`trigger_variant:` picks the button variant of a text trigger.
|
|
902
|
+
`side: :top` opens the panel above its trigger, for one near the bottom of the screen. `trigger_attributes:` adds attributes such as `class:` or `title:` to either.
|
|
852
903
|
For any other trigger, call the yielded part's `trigger` with a block. It receives the attributes that
|
|
853
904
|
wire an element as the trigger (its id, `aria-haspopup`, `aria-expanded`, `aria-controls` and the
|
|
854
905
|
Stimulus target and action), merged with any passed to `trigger`, and the element it renders replaces
|
|
@@ -905,9 +956,9 @@ has `data-turbo-confirm-tone="destructive"`, or the submitter is an `lc_button_t
|
|
|
905
956
|
the sheet beside the menu on desktop. `ask(message, { description, accept, destructive, anchor })` from the
|
|
906
957
|
same module opens it from your own code and resolves to `true` or `false`.
|
|
907
958
|
|
|
908
|
-
`lc_sheet` renders any other phone sheet, with the `lc-sheet` controller wired. `
|
|
959
|
+
`lc_sheet` renders any other phone sheet, with the `lc-sheet` controller wired. `as: :dialog` makes a
|
|
909
960
|
modal `<dialog>` sheet, which is what `lc_dialog` and `lc_confirm_sheet` render; with `size:` it gets
|
|
910
|
-
`lc_dialog`'s frame and width without its header, for content that brings its own. The default `
|
|
961
|
+
`lc_dialog`'s frame and width without its header, for content that brings its own. The default `as: :div`
|
|
911
962
|
shows while it is `:popover-open` or carries `[data-open]`, so a native `[popover]` and a FloatingPanel
|
|
912
963
|
picker both work; a div you toggle yourself sets `data-open` and removes it to slide out. From `sm` up
|
|
913
964
|
the div keeps your frame, or `anchored: true` makes it a popover under its trigger inside a positioned
|
|
@@ -920,7 +971,7 @@ above), so content scrolls under them. Put the footer last in a scroller padded
|
|
|
920
971
|
the scroller's edges and clears the home indicator.
|
|
921
972
|
|
|
922
973
|
```erb
|
|
923
|
-
<%= lc_sheet
|
|
974
|
+
<%= lc_sheet as: :dialog, size: :lg, aria: { label: "New expense" } do |sheet| %>
|
|
924
975
|
<%= sheet.header do %>…<% end %>
|
|
925
976
|
<div class="min-h-0 overflow-y-auto px-inset">
|
|
926
977
|
…
|
|
@@ -1213,7 +1264,7 @@ Generated by `bin/rails lostcoords:ui:builders`; `bin/lint` checks this list aga
|
|
|
1213
1264
|
- `lc_checkbox_class(extra: nil)` (ChoiceHelper)
|
|
1214
1265
|
- `lc_radio_class(extra: nil)` (ChoiceHelper)
|
|
1215
1266
|
- `lc_switch_class(extra: nil)` (ChoiceHelper)
|
|
1216
|
-
- `lc_dialog_class(kind
|
|
1267
|
+
- `lc_dialog_class(kind: :modal, size: nil, extra: nil)` (DialogHelper)
|
|
1217
1268
|
- `lc_emoji_picker_groups` (EmojiPickerHelper)
|
|
1218
1269
|
- `lc_emoji_picker_count` (EmojiPickerHelper)
|
|
1219
1270
|
- `lc_emoji_picker_version` (EmojiPickerHelper)
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/* lc_menu, lc_menu_option and lc_popover. */
|
|
2
2
|
@source "../../../../../helpers/lostcoords/ui/menu_helper.rb";
|
|
3
|
-
@source "../../../../../views/lostcoords/ui/components/_lc_floating_panel.html.erb";
|
|
4
3
|
@source "../../../../../javascript/lostcoords/ui/controllers/lc_menu_controller.js";
|
|
5
4
|
@source "../../../../../javascript/lostcoords/ui/controllers/lc_popover_controller.js";
|
|
@@ -73,7 +73,14 @@
|
|
|
73
73
|
backdrop-filter: none;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
/* The dialog still fades; it no longer moves or grows. */
|
|
76
77
|
@media (prefers-reduced-motion: reduce) {
|
|
78
|
+
transform: none;
|
|
79
|
+
|
|
80
|
+
&[open] {
|
|
81
|
+
@starting-style { transform: none; }
|
|
82
|
+
}
|
|
83
|
+
|
|
77
84
|
&::backdrop { transition: none; }
|
|
78
85
|
}
|
|
79
86
|
}
|
|
@@ -22,4 +22,14 @@
|
|
|
22
22
|
transform: var(--lc-popover-from, translateY(--spacing(-1)) scale(0.98));
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
+
|
|
26
|
+
/* The panel still fades; it no longer moves or grows. */
|
|
27
|
+
@media (prefers-reduced-motion: reduce) {
|
|
28
|
+
/* stylelint-disable-next-line no-invalid-position-declaration -- an @utility body nests like a rule */
|
|
29
|
+
transform: none;
|
|
30
|
+
|
|
31
|
+
&:is([data-open], :popover-open) {
|
|
32
|
+
@starting-style { transform: none; }
|
|
33
|
+
}
|
|
34
|
+
}
|
|
25
35
|
}
|
|
@@ -109,7 +109,10 @@
|
|
|
109
109
|
@starting-style { opacity: 0; }
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
+
/* The sheet appears in place; lc-sheet's own slides already skip under reduced motion. */
|
|
112
113
|
@media (prefers-reduced-motion: reduce) {
|
|
114
|
+
transition: none;
|
|
115
|
+
|
|
113
116
|
&::backdrop { transition: none; }
|
|
114
117
|
}
|
|
115
118
|
}
|
|
@@ -8,7 +8,7 @@ module Lostcoords::Ui
|
|
|
8
8
|
md: "p-inset",
|
|
9
9
|
sm: "[--lc-inset:var(--spacing-content)] p-inset"
|
|
10
10
|
}.freeze
|
|
11
|
-
HOVER_LIFT = "transition-[transform,box-shadow] duration-(--lc-motion-control) ease-(--lc-ease-out) hover:-translate-y-0.5 hover:shadow-(--lc-shadow)"
|
|
11
|
+
HOVER_LIFT = "transition-[transform,box-shadow] duration-(--lc-motion-control) ease-(--lc-ease-out) motion-safe:hover:-translate-y-0.5 hover:shadow-(--lc-shadow)"
|
|
12
12
|
|
|
13
13
|
def lc_card_class(interactive: false, padding: :md, extra: nil)
|
|
14
14
|
padding = lc_option!(:padding, padding, CARD_PADDING.keys)
|
|
@@ -30,7 +30,7 @@ module Lostcoords::Ui
|
|
|
30
30
|
CONFIRM_SHEET_ID = "lc-confirm-sheet"
|
|
31
31
|
|
|
32
32
|
# size: :sm, :md, :lg or :xl. A modal defaults to :md; a context dialog keeps its compact width.
|
|
33
|
-
def lc_dialog_class(kind
|
|
33
|
+
def lc_dialog_class(kind: :modal, size: nil, extra: nil)
|
|
34
34
|
kind = lc_option!(:kind, kind, DIALOGS.keys)
|
|
35
35
|
size = lc_option!(:size, size, DIALOG_SIZES.keys) unless size.nil?
|
|
36
36
|
size ||= :md if kind == :modal
|
|
@@ -48,7 +48,7 @@ module Lostcoords::Ui
|
|
|
48
48
|
lc_label!(trigger, :trigger) unless trigger == false
|
|
49
49
|
lc_label!(close_action, :close_action)
|
|
50
50
|
detents = lc_option!(:detents, detents, SheetHelper::SHEET_DETENTS.map(&:to_sym)).to_s
|
|
51
|
-
defaults = { class: lc_dialog_class(kind, size: size), aria: { describedby: ("#{id}-description" if description.present?) }, data: { slot: "dialog" } }
|
|
51
|
+
defaults = { class: lc_dialog_class(kind: kind, size: size), aria: { describedby: ("#{id}-description" if description.present?) }, data: { slot: "dialog" } }
|
|
52
52
|
required = { id: id, aria: { labelledby: "#{id}-title" }, data: ({ lc_dialog_target: "dialog" } if trigger) }.compact
|
|
53
53
|
parts = Parts::Dialog.new(self, id, close_action)
|
|
54
54
|
content = capture(parts, &block) if block
|
|
@@ -63,7 +63,7 @@ module Lostcoords::Ui
|
|
|
63
63
|
# The sheet Turbo's confirm opens. Render it once in the layout and set
|
|
64
64
|
# Turbo.config.forms.confirm to `confirm` from lostcoords/ui/helpers/confirm.
|
|
65
65
|
def lc_confirm_sheet(**attributes)
|
|
66
|
-
defaults = { class: lc_dialog_class(:context), data: { slot: "confirm-sheet", turbo_permanent: true } }
|
|
66
|
+
defaults = { class: lc_dialog_class(kind: :context), data: { slot: "confirm-sheet", turbo_permanent: true } }
|
|
67
67
|
required = { id: CONFIRM_SHEET_ID, tabindex: -1, aria: { labelledby: "#{CONFIRM_SHEET_ID}-message", describedby: "#{CONFIRM_SHEET_ID}-description" } }
|
|
68
68
|
render "lostcoords/ui/components/lc_confirm_sheet", id: CONFIRM_SHEET_ID, attributes: lc_attributes(defaults, attributes, required)
|
|
69
69
|
end
|
|
@@ -9,7 +9,7 @@ module Lostcoords::Ui
|
|
|
9
9
|
LIST_ITEM = "flex min-h-16 min-w-0 items-center gap-heading px-content py-heading text-start sm:px-inset"
|
|
10
10
|
LIST_ROW_PADDING = "px-content py-heading sm:px-inset"
|
|
11
11
|
LIST_ICON = "grid size-10 shrink-0 place-items-center rounded-full bg-tile [&>svg:not([class*='size-'])]:size-4.5"
|
|
12
|
-
|
|
12
|
+
LIST_ROW_ELEMENTS = %i[div li label details a].freeze
|
|
13
13
|
LIST_ROW_HOVER = "transition-colors duration-(--lc-motion-quick) hover:bg-accent"
|
|
14
14
|
# A linked li or div row: the title's link covers the row, the row's own controls sit above it,
|
|
15
15
|
# and the row shows the link's focus ring.
|
|
@@ -25,7 +25,7 @@ module Lostcoords::Ui
|
|
|
25
25
|
"group/choice flex items-center gap-heading cursor-pointer transition-colors duration-(--lc-motion-quick) " \
|
|
26
26
|
"hover:bg-accent has-checked:bg-primary-soft has-checked:font-semibold has-disabled:cursor-not-allowed has-disabled:opacity-45"
|
|
27
27
|
LIST_ROW_CHOICE_CHECK = "ms-auto size-4 shrink-0 text-primary invisible group-has-checked/choice:visible"
|
|
28
|
-
|
|
28
|
+
LIST_FIELD_ELEMENTS = %i[div fieldset span].freeze
|
|
29
29
|
LIST_FIELD = "@container px-content py-2.5 transition-colors duration-(--lc-motion-quick) has-[[data-plain]:focus]:bg-accent"
|
|
30
30
|
LIST_FIELD_GRID = "grid min-h-9 grid-cols-[1.25rem_minmax(0,1fr)] items-center gap-x-heading gap-y-related @md:grid-cols-[8rem_minmax(0,1fr)]"
|
|
31
31
|
LIST_FIELD_LABEL =
|
|
@@ -50,9 +50,9 @@ module Lostcoords::Ui
|
|
|
50
50
|
|
|
51
51
|
# Rows as in iOS settings: each row is its own card-coloured panel, 2px apart, and only the
|
|
52
52
|
# first and last rows round.
|
|
53
|
-
def lc_list_group(
|
|
54
|
-
|
|
55
|
-
content_tag(
|
|
53
|
+
def lc_list_group(as: :div, **attributes, &block)
|
|
54
|
+
as = lc_option!(:as, as, %i[div ul])
|
|
55
|
+
content_tag(as, (capture(&block) if block), **lc_attributes({ class: LIST_GROUP, data: { slot: "list-group" } }, attributes))
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
# With a title, the row lays out icon:, the title and subtitle, then the block as its trailing
|
|
@@ -63,21 +63,21 @@ module Lostcoords::Ui
|
|
|
63
63
|
# choice: :radio makes the row one choice of a radio group: a label around a hidden radio named
|
|
64
64
|
# name: with value:, then the title or block, then a check shown while checked:. input: adds
|
|
65
65
|
# attributes to the radio.
|
|
66
|
-
def lc_list_row(title = nil, subtitle: nil, icon: nil, href: nil,
|
|
66
|
+
def lc_list_row(title = nil, subtitle: nil, icon: nil, href: nil, as: nil, padded: true, choice: nil, name: nil, value: nil, checked: false, input: {}, **attributes, &block)
|
|
67
67
|
return lc_list_choice_row(title, choice, name, value, checked, input, attributes, &block) if choice
|
|
68
68
|
raise ArgumentError, "name:, value:, checked: and input: belong to a choice: row" if name || value || checked || input.any?
|
|
69
69
|
|
|
70
|
-
|
|
71
|
-
titled = href &&
|
|
72
|
-
raise ArgumentError, "href: needs
|
|
70
|
+
as = lc_option!(:as, as || (href ? :a : :div), LIST_ROW_ELEMENTS)
|
|
71
|
+
titled = href && as != :a
|
|
72
|
+
raise ArgumentError, "href: needs as: :a, :li or :div" if titled && !%i[li div].include?(as)
|
|
73
73
|
raise ArgumentError, "href: on an li or div row links its title, so it needs one" if titled && title.blank?
|
|
74
74
|
|
|
75
75
|
link = (titled ? lc_tw(LIST_ROW_HOVER, LIST_ROW_LINKED) : lc_tw("no-underline", LIST_ROW_HOVER)) if href
|
|
76
76
|
defaults = { href: (href unless titled), data: { slot: "list-row" } }
|
|
77
|
-
return lc_list_item(title, subtitle: subtitle, icon: icon, link: (href if titled),
|
|
77
|
+
return lc_list_item(title, subtitle: subtitle, icon: icon, link: (href if titled), as: as, **lc_attributes(defaults.merge(class: lc_tw(LIST_ROW, link)), attributes), &block) if title.present?
|
|
78
78
|
|
|
79
79
|
classes = lc_tw(LIST_ROW, (LIST_ROW_PADDING if padded), link)
|
|
80
|
-
content_tag(
|
|
80
|
+
content_tag(as, (capture(&block) if block), **lc_attributes(defaults.merge(class: classes), attributes))
|
|
81
81
|
end
|
|
82
82
|
|
|
83
83
|
private def lc_list_choice_row(title, choice, name, value, checked, input, attributes, &block)
|
|
@@ -100,36 +100,36 @@ module Lostcoords::Ui
|
|
|
100
100
|
|
|
101
101
|
# A form row: a label column, then the block as the control. In a narrow row the label folds to
|
|
102
102
|
# icon: alone and stays the accessible name. id: makes the label a <label> for that control;
|
|
103
|
-
#
|
|
104
|
-
# for a row drawn inside another element, such as a collapsible's summary (with
|
|
105
|
-
def lc_list_field(label, icon: nil, id: nil,
|
|
103
|
+
# as: :fieldset names a group of controls with a legend. surface: false drops the row's panel,
|
|
104
|
+
# for a row drawn inside another element, such as a collapsible's summary (with as: :span).
|
|
105
|
+
def lc_list_field(label, icon: nil, id: nil, as: :div, surface: true, **attributes, &block)
|
|
106
106
|
lc_label!(label, :label)
|
|
107
|
-
|
|
108
|
-
raise ArgumentError, "id: labels one control; a fieldset is named by its legend" if id &&
|
|
107
|
+
as = lc_option!(:as, as, LIST_FIELD_ELEMENTS)
|
|
108
|
+
raise ArgumentError, "id: labels one control; a fieldset is named by its legend" if id && as == :fieldset
|
|
109
109
|
|
|
110
|
-
inline =
|
|
110
|
+
inline = as == :span ? :span : :div
|
|
111
111
|
text = content_tag(:span, label, class: "@max-md:sr-only", data: { slot: "list-field-text" })
|
|
112
112
|
glyph = (icon.is_a?(ActiveSupport::SafeBuffer) ? icon : lc_icon(icon, options: { "aria-hidden": true })) if icon.present?
|
|
113
|
-
label_classes = lc_tw(LIST_FIELD_LABEL, ("self-start min-h-control-sm" if
|
|
113
|
+
label_classes = lc_tw(LIST_FIELD_LABEL, ("self-start min-h-control-sm" if as == :fieldset))
|
|
114
114
|
label_tag = if id
|
|
115
115
|
content_tag(:label, safe_join([ glyph, text ].compact), for: id, class: label_classes, data: { slot: "list-field-label" })
|
|
116
116
|
else
|
|
117
|
-
content_tag(:span, safe_join([ glyph, text ].compact), class: label_classes, aria: { hidden: (true if
|
|
117
|
+
content_tag(:span, safe_join([ glyph, text ].compact), class: label_classes, aria: { hidden: (true if as == :fieldset) }, data: { slot: "list-field-label" })
|
|
118
118
|
end
|
|
119
119
|
grid = content_tag(inline, safe_join([ label_tag, (capture(&block) if block) ].compact), class: LIST_FIELD_GRID)
|
|
120
|
-
legend = content_tag(:legend, label, class: "sr-only") if
|
|
121
|
-
classes = lc_tw((LIST_ROW if surface), LIST_FIELD, ("block" if
|
|
122
|
-
content_tag(
|
|
120
|
+
legend = content_tag(:legend, label, class: "sr-only") if as == :fieldset
|
|
121
|
+
classes = lc_tw((LIST_ROW if surface), LIST_FIELD, ("block" if as == :span), ("m-0 min-w-0 border-0" if as == :fieldset))
|
|
122
|
+
content_tag(as, safe_join([ legend, grid ].compact), **lc_attributes({ class: classes, data: { slot: "list-field" } }, attributes))
|
|
123
123
|
end
|
|
124
124
|
|
|
125
125
|
# The row layout without the row's surface, for an element inside a free-form row: a summary, a
|
|
126
126
|
# button that opens an editor. icon: takes an icon name or your own markup, such as a logo.
|
|
127
127
|
# link: links the title to that URL and stretches the link over the nearest positioned ancestor.
|
|
128
|
-
def lc_list_item(title, subtitle: nil, icon: nil, link: nil,
|
|
128
|
+
def lc_list_item(title, subtitle: nil, icon: nil, link: nil, as: :div, **attributes, &block)
|
|
129
129
|
lc_label!(title, :title)
|
|
130
130
|
glyph = icon.is_a?(ActiveSupport::SafeBuffer) ? icon : lc_icon(icon) if icon.present?
|
|
131
131
|
title = link_to(title, link, class: LIST_LINK, data: { slot: "list-link" }) if link
|
|
132
|
-
content_tag(
|
|
132
|
+
content_tag(as, **lc_attributes({ class: LIST_ITEM, data: { slot: "list-item" } }, attributes)) do
|
|
133
133
|
text = safe_join([
|
|
134
134
|
content_tag(:span, title, class: "font-semibold", data: { slot: "list-title" }),
|
|
135
135
|
(content_tag(:span, subtitle, class: "text-small text-muted-foreground [overflow-wrap:anywhere]", data: { slot: "list-subtitle" }) if subtitle.present?)
|
|
@@ -59,20 +59,19 @@ module Lostcoords::Ui
|
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
# trigger: :icon renders a quiet icon button named by label; rendered HTML becomes the content
|
|
62
|
-
# of a custom trigger, also named by label. trigger_size:
|
|
63
|
-
def lc_menu(id:, label: lc_t("lostcoords.ui.menu.label"), align: :end, side: :bottom, trigger: :button, trigger_size: :md, icon: "ellipsis-vertical", trigger_attributes: {}, wrapper_attributes: {}, **attributes, &block)
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
62
|
+
# of a custom trigger, also named by label. trigger_variant: and trigger_size: style the trigger.
|
|
63
|
+
def lc_menu(id:, label: lc_t("lostcoords.ui.menu.label"), align: :end, side: :bottom, trigger: :button, trigger_variant: :secondary, trigger_size: :md, icon: "ellipsis-vertical", trigger_attributes: {}, wrapper_attributes: {}, **attributes, &block)
|
|
64
|
+
default_trigger = lc_panel_trigger(label, trigger, icon, trigger_variant, trigger_size)
|
|
65
|
+
lc_panel(id: id, label: label, controller: "lc-menu", role: "menu", classes: lc_menu_popover_class(align: align, side: side), attributes: lc_attributes({ data: { slot: "menu" } }, attributes),
|
|
66
|
+
default_trigger: default_trigger, trigger_attributes: trigger_attributes, wrapper_attributes: wrapper_attributes, &block)
|
|
67
67
|
end
|
|
68
68
|
|
|
69
|
-
# Takes the same trigger options as lc_menu, including trigger: false.
|
|
70
|
-
def lc_popover(id:, label: lc_t("lostcoords.ui.popover.trigger"), title: nil, align: :end,
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
lc_render_panel(id, label, title, "lc-popover", "dialog", classes, lc_attributes({ data: { slot: "popover" } }, attributes), default_trigger, trigger_attributes, wrapper_attributes, &block)
|
|
69
|
+
# Takes the same trigger and placement options as lc_menu, including trigger: false.
|
|
70
|
+
def lc_popover(id:, label: lc_t("lostcoords.ui.popover.trigger"), title: nil, align: :end, side: :bottom, trigger: :button, trigger_variant: :secondary, trigger_size: :md, icon: "ellipsis-vertical", trigger_attributes: {}, wrapper_attributes: {}, **attributes, &block)
|
|
71
|
+
default_trigger = lc_panel_trigger(label, trigger, icon, trigger_variant, trigger_size)
|
|
72
|
+
classes = lc_popover_class(align: align, side: side, extra: "data-open:flex flex-col gap-content p-inset z-(--lc-z-popover) min-w-64 max-w-[calc(100vw-2rem)]")
|
|
73
|
+
lc_panel(id: id, label: label, title: title.presence, controller: "lc-popover", role: "dialog", classes: classes, attributes: lc_attributes({ data: { slot: "popover" } }, attributes),
|
|
74
|
+
default_trigger: default_trigger, trigger_attributes: trigger_attributes, wrapper_attributes: wrapper_attributes, &block)
|
|
76
75
|
end
|
|
77
76
|
|
|
78
77
|
# icon: names a leading Heroicon; leading: takes other rendered content, such as an avatar, and is
|
|
@@ -119,23 +118,28 @@ module Lostcoords::Ui
|
|
|
119
118
|
end
|
|
120
119
|
|
|
121
120
|
private
|
|
122
|
-
|
|
121
|
+
# The default trigger as a callable that takes the panel's wiring, or nil for trigger: false.
|
|
122
|
+
def lc_panel_trigger(label, trigger, icon, variant, size)
|
|
123
|
+
return if trigger == false
|
|
124
|
+
|
|
125
|
+
size = lc_option!(:trigger_size, size, ButtonHelper::BUTTON_SIZES.keys)
|
|
126
|
+
variant = lc_option!(:trigger_variant, variant, ButtonHelper::BUTTON_VARIANTS.keys)
|
|
123
127
|
custom = trigger.is_a?(String) && trigger.html_safe?
|
|
124
128
|
kind = custom ? :custom : lc_option!(:trigger, trigger, MENU_TRIGGERS)
|
|
125
|
-
|
|
126
|
-
|
|
129
|
+
lambda do |wiring|
|
|
130
|
+
next lc_button(label, variant: variant, size: size, **wiring) if kind == :button
|
|
131
|
+
|
|
127
132
|
content = custom ? trigger : lc_icon(icon, options: { "aria-hidden": true })
|
|
128
133
|
icon_button = { type: "button", class: lc_icon_button_class(shape: :circle, size: size, extra: ButtonHelper::ICON_BUTTON_QUIET), aria: { label: label }, data: { slot: "icon-button" } }
|
|
129
|
-
tag.button(content, **lc_attributes(icon_button,
|
|
130
|
-
else
|
|
131
|
-
lc_button(label, variant: variant, **attributes)
|
|
134
|
+
tag.button(content, **lc_attributes(icon_button, wiring))
|
|
132
135
|
end
|
|
133
136
|
end
|
|
134
137
|
|
|
135
|
-
#
|
|
136
|
-
#
|
|
137
|
-
#
|
|
138
|
-
|
|
138
|
+
# A trigger and the panel it opens, in a wrapper that hosts the controller. The block runs
|
|
139
|
+
# before the default trigger renders, so a trigger part can replace it. Without a default
|
|
140
|
+
# trigger only the panel renders, for a caller that hosts the controller on an ancestor and
|
|
141
|
+
# wires its own triggers.
|
|
142
|
+
def lc_panel(id:, label:, controller:, role:, classes:, attributes:, default_trigger:, title: nil, trigger_attributes: {}, wrapper_attributes: {}, &block)
|
|
139
143
|
lc_label!(id, :id)
|
|
140
144
|
lc_label!(label, :label)
|
|
141
145
|
standalone = default_trigger.nil?
|
|
@@ -149,8 +153,11 @@ module Lostcoords::Ui
|
|
|
149
153
|
required = { id: id, role: role, aria: name, data: { "#{controller}_target" => "popover" } }
|
|
150
154
|
required[:tabindex] = -1 if role == "dialog"
|
|
151
155
|
merged = lc_attributes({ class: classes }, attributes, required)
|
|
152
|
-
|
|
153
|
-
|
|
156
|
+
heading = tag.h2(title, id: "#{id}-title", class: lc_heading_class(size: :subheading)) if title
|
|
157
|
+
panel = tag.div(safe_join([ heading, content ].compact), **merged)
|
|
158
|
+
return panel if standalone
|
|
159
|
+
|
|
160
|
+
tag.div(safe_join([ trigger, panel ]), **lc_attributes({ class: "relative inline-flex" }, wrapper_attributes, { data: { controller: controller } }))
|
|
154
161
|
end
|
|
155
162
|
end
|
|
156
163
|
end
|
|
@@ -50,7 +50,6 @@ module Lostcoords::Ui
|
|
|
50
50
|
tag.button(safe_join([ body, chevron ]), **lc_attributes(defaults, attributes))
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
-
# A block replaces the icon with custom content, such as an avatar or two stacked icons.
|
|
54
53
|
# One pill with a primary action and a toggle on its inline end that opens a menu of the block's
|
|
55
54
|
# lc_menu_option items. With href: the action is a link. label may be rendered HTML. action:,
|
|
56
55
|
# toggle: and menu: add attributes to those parts; other attributes go on the wrapper.
|
|
@@ -60,8 +59,6 @@ module Lostcoords::Ui
|
|
|
60
59
|
# <% end %>
|
|
61
60
|
def lc_split_button(label, id:, href: nil, menu_label: lc_t("lostcoords.ui.menu.label"), variant: :primary, tone: :default, size: :md,
|
|
62
61
|
icon: nil, icon_position: :start, block: false, align: :end, action: {}, toggle: {}, menu: {}, **attributes, &items)
|
|
63
|
-
lc_label!(id, :id)
|
|
64
|
-
lc_label!(menu_label, :menu_label)
|
|
65
62
|
variant = lc_option!(:variant, variant, ButtonHelper::BUTTON_VARIANTS.keys)
|
|
66
63
|
size = lc_option!(:size, size, ButtonHelper::BUTTON_SIZES.keys)
|
|
67
64
|
button = { variant: variant, tone: tone, size: size, icon: icon, icon_position: icon_position }
|
|
@@ -72,20 +69,16 @@ module Lostcoords::Ui
|
|
|
72
69
|
ButtonHelper::SPLIT_BUTTON_PART, ButtonHelper::SPLIT_BUTTON_TOGGLE, ButtonHelper::SPLIT_BUTTON_TOGGLE_WIDTHS.fetch(size),
|
|
73
70
|
(ButtonHelper::SPLIT_BUTTON_DIVIDER unless variant == :outline)
|
|
74
71
|
))
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
{ id: id, role: "menu", aria: { labelledby: "#{id}-trigger" }, data: { lc_menu_target: "popover" } }
|
|
83
|
-
))
|
|
84
|
-
|
|
85
|
-
defaults = { class: lc_tw(ButtonHelper::SPLIT_BUTTON_BASE, ("flex w-full" if block)), data: { controller: "lc-menu", slot: "split-button" } }
|
|
86
|
-
tag.div(safe_join([ primary, toggle, popover ]), **lc_attributes(defaults, attributes))
|
|
72
|
+
halves = lambda do |wiring|
|
|
73
|
+
chevron = lc_icon("chevron-down", variant: :mini, options: { "aria-hidden": true })
|
|
74
|
+
safe_join([ primary, tag.button(chevron, **lc_attributes({ type: "button", class: toggle_class, aria: { label: menu_label }, data: { slot: "split-button-toggle" } }, wiring)) ])
|
|
75
|
+
end
|
|
76
|
+
wrapper = lc_attributes({ class: lc_tw(ButtonHelper::SPLIT_BUTTON_BASE, ("flex w-full" if block)), data: { controller: "lc-menu", slot: "split-button" } }, attributes)
|
|
77
|
+
lc_panel(id: id, label: menu_label, controller: "lc-menu", role: "menu", classes: lc_menu_popover_class(align: align), attributes: lc_attributes({ data: { slot: "menu" } }, menu),
|
|
78
|
+
default_trigger: halves, trigger_attributes: toggle, wrapper_attributes: wrapper, &items)
|
|
87
79
|
end
|
|
88
80
|
|
|
81
|
+
# A block replaces the icon with custom content, such as an avatar or two stacked icons.
|
|
89
82
|
def lc_icon_button(label, icon: nil, size: :md, icon_size: size, shape: :circle, variant: :ghost, tone: :default, tooltip: nil, **attributes, &content)
|
|
90
83
|
attributes = lc_icon_button_attributes(label, size, icon_size, shape, variant, tone, { type: "button" }, attributes)
|
|
91
84
|
lc_icon_button_tooltip(label, tooltip, attributes) { |tip| tag.button(lc_icon_button_content(icon, &content), **lc_attributes(attributes, tip)) }
|
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
module Lostcoords::Ui
|
|
2
2
|
module SheetHelper
|
|
3
|
-
|
|
3
|
+
SHEET_ELEMENTS = %i[div dialog].freeze
|
|
4
4
|
SHEET_DETENTS = [ "fit", "medium large", "large" ].freeze
|
|
5
5
|
SHEET_SURFACES = %i[glass].freeze
|
|
6
6
|
SHEET_HANDLE = "grid min-h-7 w-full flex-none cursor-grab touch-none place-items-center active:cursor-grabbing sm:hidden"
|
|
7
7
|
|
|
8
|
-
# A panel that is an iOS sheet on phones, with the lc-sheet controller.
|
|
8
|
+
# A panel that is an iOS sheet on phones, with the lc-sheet controller. as: :dialog is a modal
|
|
9
9
|
# <dialog> (lc_dialog builds on it). A :div shows while [data-open] or, with popover:, :popover-open;
|
|
10
10
|
# from sm up it keeps your frame, or with anchored: true it is a popover under its trigger, opened by a
|
|
11
11
|
# FloatingPanel inside a positioned ancestor. detents: "fit", "medium large" or "large". handle: true
|
|
12
12
|
# adds a grab strip above the content; without one the sheet draws its grabber over it.
|
|
13
13
|
# A swipe down dispatches lc-sheet:dismiss; unless a listener cancels it, an open popover hides.
|
|
14
|
-
# With
|
|
14
|
+
# With as: :dialog, size: draws lc_dialog's modal frame at that width, for a dialog whose content
|
|
15
15
|
# brings its own header and labels the dialog with aria-label.
|
|
16
16
|
# surface: :glass draws a :div in the translucent menu material, a menu on desktop and a sheet on phones.
|
|
17
17
|
# Yields a builder whose header and footer parts stay pinned while the content scrolls.
|
|
18
|
-
def lc_sheet(
|
|
19
|
-
|
|
18
|
+
def lc_sheet(as: :div, anchored: false, detents: "fit", handle: false, size: nil, surface: nil, **attributes, &block)
|
|
19
|
+
as = lc_option!(:as, as, SHEET_ELEMENTS)
|
|
20
20
|
detents = lc_option!(:detents, detents, SHEET_DETENTS.map(&:to_sym)).to_s
|
|
21
21
|
surface = lc_option!(:surface, surface, SHEET_SURFACES) unless surface.nil?
|
|
22
|
-
raise ArgumentError, "anchored: true needs
|
|
23
|
-
raise ArgumentError, "size: needs
|
|
24
|
-
raise ArgumentError, "surface: :glass needs
|
|
22
|
+
raise ArgumentError, "anchored: true needs as: :div" if anchored && as == :dialog
|
|
23
|
+
raise ArgumentError, "size: needs as: :dialog" if size && as != :dialog
|
|
24
|
+
raise ArgumentError, "surface: :glass needs as: :div" if surface && as == :dialog
|
|
25
25
|
|
|
26
26
|
defaults = { data: { slot: "sheet", controller: "lc-sheet", lc_sheet_detents_value: detents } }
|
|
27
|
-
defaults[:class] = lc_tw("lc-sheet", ("lc-sheet-anchored" if anchored), (lc_glass_class(shape: :picker) if surface == :glass)) unless
|
|
27
|
+
defaults[:class] = lc_tw("lc-sheet", ("lc-sheet-anchored" if anchored), (lc_glass_class(shape: :picker) if surface == :glass)) unless as == :dialog
|
|
28
28
|
defaults[:class] = lc_dialog_class(size: size) if size
|
|
29
|
-
strip =
|
|
29
|
+
strip = tag.span(class: SHEET_HANDLE, aria: { hidden: true }, data: { slot: "sheet-handle", lc_sheet_target: "handle" }) if handle
|
|
30
30
|
content = capture(Parts::Sheet.new(self), &block) if block
|
|
31
|
-
content_tag(
|
|
31
|
+
content_tag(as, safe_join([ strip, content ].compact), **lc_attributes(defaults, attributes))
|
|
32
32
|
end
|
|
33
33
|
end
|
|
34
34
|
end
|
|
@@ -15,9 +15,15 @@ module Lostcoords::Ui
|
|
|
15
15
|
"radius" => %w[pill]
|
|
16
16
|
}.freeze
|
|
17
17
|
|
|
18
|
+
# One merger for the process. Its cache is thread-safe and keyed by the class string, so a class
|
|
19
|
+
# list merged in one request is a lookup in every later one; a merger per view would start each
|
|
20
|
+
# request cold.
|
|
21
|
+
def self.merger
|
|
22
|
+
@merger ||= TailwindMerge::Merger.new(config: { theme: MERGE_THEME, cache_size: 4096 })
|
|
23
|
+
end
|
|
24
|
+
|
|
18
25
|
def lc_tw(*classes)
|
|
19
|
-
|
|
20
|
-
@tailwind_merger.merge(classes.flatten.compact.join(" "))
|
|
26
|
+
TailwindHelper.merger.merge(classes.flatten.compact.join(" "))
|
|
21
27
|
end
|
|
22
28
|
end
|
|
23
29
|
end
|
|
@@ -15,12 +15,10 @@ export default class extends Controller {
|
|
|
15
15
|
static values = { src: String }
|
|
16
16
|
|
|
17
17
|
connect() {
|
|
18
|
-
this.stopPageLeave = onPageLeave(() => this.close({ immediate: true }))
|
|
19
18
|
this.untab()
|
|
20
19
|
}
|
|
21
20
|
|
|
22
21
|
disconnect() {
|
|
23
|
-
this.stopPageLeave?.()
|
|
24
22
|
this.cancelTimers()
|
|
25
23
|
this.close({ immediate: true })
|
|
26
24
|
}
|
|
@@ -52,6 +50,7 @@ export default class extends Controller {
|
|
|
52
50
|
}
|
|
53
51
|
this.element.toggleAttribute("data-open", true)
|
|
54
52
|
this.release = liftToTopLayer(this.contentTarget, this.triggerTarget)
|
|
53
|
+
this.stopPageLeave = onPageLeave(() => this.close({ immediate: true }))
|
|
55
54
|
this.unregister = registerDismissable({
|
|
56
55
|
type: "hovercard",
|
|
57
56
|
element: this.element,
|
|
@@ -92,6 +91,8 @@ export default class extends Controller {
|
|
|
92
91
|
this.element.toggleAttribute("data-open", false)
|
|
93
92
|
this.release?.({ immediate })
|
|
94
93
|
this.release = null
|
|
94
|
+
this.stopPageLeave?.()
|
|
95
|
+
this.stopPageLeave = null
|
|
95
96
|
this.unregister?.()
|
|
96
97
|
this.unregister = null
|
|
97
98
|
}
|
|
@@ -12,25 +12,33 @@ export default class extends FloatingPanel {
|
|
|
12
12
|
super.initialize()
|
|
13
13
|
this.focusOutHandler = this.handleFocusOut.bind(this)
|
|
14
14
|
this.pointerDownHandler = this.handlePointerDown.bind(this)
|
|
15
|
-
this.keydownHandler = (
|
|
16
|
-
this.triggerKeydownHandler = this.handleTriggerKeydown.bind(this)
|
|
15
|
+
this.keydownHandler = this.handleKeydown.bind(this)
|
|
17
16
|
this.focusOutSuppressed = false
|
|
18
17
|
this.focusOutSuppressionTimer = null
|
|
19
18
|
}
|
|
20
19
|
|
|
20
|
+
// Keys are heard on the host, so a trigger or panel that a morph replaces needs no listener of its own.
|
|
21
21
|
connect() {
|
|
22
|
-
|
|
23
|
-
this.triggerTarget.addEventListener("keydown", this.triggerKeydownHandler)
|
|
22
|
+
this.element.addEventListener("keydown", this.keydownHandler)
|
|
24
23
|
}
|
|
25
24
|
|
|
26
25
|
disconnect() {
|
|
27
|
-
this.
|
|
26
|
+
this.element.removeEventListener("keydown", this.keydownHandler)
|
|
28
27
|
this.clearFocusOutSuppression()
|
|
29
28
|
super.disconnect()
|
|
30
29
|
}
|
|
31
30
|
|
|
31
|
+
handleKeydown(event) {
|
|
32
|
+
if (!this.hasPopoverTarget) return
|
|
33
|
+
if (this.popoverTarget.contains(event.target)) {
|
|
34
|
+
if (this.isOpen) navigateMenu(event, this.popoverTarget)
|
|
35
|
+
} else if (this.triggerTargets.some((trigger) => trigger.contains(event.target))) {
|
|
36
|
+
this.openFromTrigger(event)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
32
40
|
// Arrow Down opens the menu on its first item, Arrow Up on its last.
|
|
33
|
-
|
|
41
|
+
openFromTrigger(event) {
|
|
34
42
|
if (event.key !== "ArrowDown" && event.key !== "ArrowUp") return
|
|
35
43
|
if (event.altKey || event.ctrlKey || event.metaKey) return
|
|
36
44
|
|
|
@@ -62,15 +70,12 @@ export default class extends FloatingPanel {
|
|
|
62
70
|
super.open()
|
|
63
71
|
this.element.addEventListener("focusout", this.focusOutHandler)
|
|
64
72
|
this.element.addEventListener("pointerdown", this.pointerDownHandler)
|
|
65
|
-
this.popoverTarget.addEventListener("keydown", this.keydownHandler)
|
|
66
73
|
}
|
|
67
74
|
|
|
68
75
|
release(options) {
|
|
69
76
|
super.release(options)
|
|
70
77
|
this.element.removeEventListener("focusout", this.focusOutHandler)
|
|
71
78
|
this.element.removeEventListener("pointerdown", this.pointerDownHandler)
|
|
72
|
-
if (this.hasPopoverTarget)
|
|
73
|
-
this.popoverTarget.removeEventListener("keydown", this.keydownHandler)
|
|
74
79
|
}
|
|
75
80
|
|
|
76
81
|
handleFocusOut(event) {
|
|
@@ -74,7 +74,7 @@ export default class extends Controller {
|
|
|
74
74
|
reset() {
|
|
75
75
|
this.animations.forEach((animation) => animation.cancel())
|
|
76
76
|
this.animations = []
|
|
77
|
-
this.dialogTarget.close()
|
|
77
|
+
if (this.hasDialogTarget) this.dialogTarget.close()
|
|
78
78
|
this.unregisterDialog?.()
|
|
79
79
|
this.unregisterDialog = null
|
|
80
80
|
this.closing = false
|
|
@@ -9,12 +9,7 @@ import { liftToTopLayer, onPageLeave } from "lostcoords/ui/helpers/top_layer"
|
|
|
9
9
|
export default class extends Controller {
|
|
10
10
|
static targets = ["content"]
|
|
11
11
|
|
|
12
|
-
connect() {
|
|
13
|
-
this.stopPageLeave = onPageLeave(() => this.close({ immediate: true }))
|
|
14
|
-
}
|
|
15
|
-
|
|
16
12
|
disconnect() {
|
|
17
|
-
this.stopPageLeave?.()
|
|
18
13
|
this.close({ immediate: true })
|
|
19
14
|
}
|
|
20
15
|
|
|
@@ -24,6 +19,7 @@ export default class extends Controller {
|
|
|
24
19
|
|
|
25
20
|
this.element.toggleAttribute("data-open", true)
|
|
26
21
|
this.release = liftToTopLayer(this.contentTarget, this.element)
|
|
22
|
+
this.stopPageLeave = onPageLeave(() => this.close({ immediate: true }))
|
|
27
23
|
this.unregister = registerDismissable({
|
|
28
24
|
type: "tooltip",
|
|
29
25
|
element: this.element,
|
|
@@ -48,6 +44,8 @@ export default class extends Controller {
|
|
|
48
44
|
this.element.toggleAttribute("data-open", false)
|
|
49
45
|
this.release?.({ immediate })
|
|
50
46
|
this.release = null
|
|
47
|
+
this.stopPageLeave?.()
|
|
48
|
+
this.stopPageLeave = null
|
|
51
49
|
this.unregister?.()
|
|
52
50
|
this.unregister = null
|
|
53
51
|
}
|
|
@@ -468,7 +468,7 @@ export class CatalogPicker extends FloatingPanel {
|
|
|
468
468
|
}
|
|
469
469
|
|
|
470
470
|
get catalogElement() {
|
|
471
|
-
return this.bodyTarget.querySelector("[data-picker-catalog]")
|
|
471
|
+
return this.hasBodyTarget ? this.bodyTarget.querySelector("[data-picker-catalog]") : null
|
|
472
472
|
}
|
|
473
473
|
|
|
474
474
|
get optionSelector() {
|
|
@@ -2,6 +2,22 @@ import { registerDismissable } from "lostcoords/ui/helpers/dismiss_stack"
|
|
|
2
2
|
|
|
3
3
|
const registrations = new WeakMap()
|
|
4
4
|
|
|
5
|
+
// Turbo snapshots a page for Back with its open dialogs, and restoring one brings back the open
|
|
6
|
+
// attribute but not the top layer: the dialog shows inline, with no backdrop, focus trap or
|
|
7
|
+
// Escape. A dialog registered when the snapshot was taken is marked, so it comes back closed.
|
|
8
|
+
const MARK = "lcDialog"
|
|
9
|
+
document.addEventListener("turbo:before-render", ({ detail: { newBody } }) => {
|
|
10
|
+
for (const dialog of newBody.querySelectorAll("dialog[data-lc-dialog]")) {
|
|
11
|
+
dialog.removeAttribute("open")
|
|
12
|
+
delete dialog.dataset[MARK]
|
|
13
|
+
}
|
|
14
|
+
})
|
|
15
|
+
// A same-URL refresh morphs the page against server HTML, which never carries the mark.
|
|
16
|
+
document.addEventListener("turbo:before-morph-attribute", (event) => {
|
|
17
|
+
if (event.detail.attributeName === "data-lc-dialog" && registrations.has(event.target))
|
|
18
|
+
event.preventDefault()
|
|
19
|
+
})
|
|
20
|
+
|
|
5
21
|
// Shows a modal <dialog> with focus on the dialog itself rather than its first control: a close
|
|
6
22
|
// button would draw the focus ring after a tap that focused nothing, and a first field would raise
|
|
7
23
|
// a phone's keyboard. A control marked autofocus still takes focus, and Tab reaches every control.
|
|
@@ -53,12 +69,14 @@ export function registerDialog(
|
|
|
53
69
|
const unregister = () => {
|
|
54
70
|
if (registrations.get(dialog) !== unregister) return
|
|
55
71
|
registrations.delete(dialog)
|
|
72
|
+
delete dialog.dataset[MARK]
|
|
56
73
|
dialog.removeEventListener("close", unregisterOnClose)
|
|
57
74
|
dialog.removeEventListener("click", closeOnBackdrop)
|
|
58
75
|
unregisterDismissable()
|
|
59
76
|
}
|
|
60
77
|
|
|
61
78
|
registrations.set(dialog, unregister)
|
|
79
|
+
dialog.dataset[MARK] = ""
|
|
62
80
|
dialog.addEventListener("close", unregisterOnClose)
|
|
63
81
|
dialog.addEventListener("click", closeOnBackdrop)
|
|
64
82
|
return unregister
|
|
@@ -167,12 +167,22 @@ function unlockDocumentScroll() {
|
|
|
167
167
|
const body = document.body
|
|
168
168
|
if (body?.dataset.modalScrollLock !== "true") return
|
|
169
169
|
|
|
170
|
+
releaseScrollLock(body)
|
|
171
|
+
window.scrollTo({ top: lockedScrollY, behavior: "instant" })
|
|
172
|
+
lockedScrollY = 0
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function releaseScrollLock(body) {
|
|
170
176
|
body.style.position = ""
|
|
171
177
|
body.style.inset = ""
|
|
172
178
|
body.style.top = ""
|
|
173
179
|
body.style.removeProperty("--lc-scroll-lock-y")
|
|
174
180
|
body.style.inlineSize = ""
|
|
175
181
|
delete body.dataset.modalScrollLock
|
|
176
|
-
window.scrollTo({ top: lockedScrollY, behavior: "instant" })
|
|
177
|
-
lockedScrollY = 0
|
|
178
182
|
}
|
|
183
|
+
|
|
184
|
+
// A page snapshotted for Back while a dialog held the lock comes back pinned; the dialog
|
|
185
|
+
// that held it comes back closed (helpers/dialog), so the restored page is free to scroll.
|
|
186
|
+
document.addEventListener("turbo:before-render", ({ detail: { newBody } }) => {
|
|
187
|
+
if (newBody.dataset.modalScrollLock === "true") releaseScrollLock(newBody)
|
|
188
|
+
})
|
|
@@ -4,6 +4,10 @@ import { liftToTopLayer, onPageLeave } from "lostcoords/ui/helpers/top_layer"
|
|
|
4
4
|
|
|
5
5
|
const BEFORE_OPEN = "overlay:before-open"
|
|
6
6
|
|
|
7
|
+
// A panel listens to the document only while it is open, and its teardown (disconnect, a page
|
|
8
|
+
// leave) never reads a target. A Turbo morph moves a panel's id-carrying trigger and panel into
|
|
9
|
+
// another host before Stimulus disconnects the emptied one, so a target read there would throw
|
|
10
|
+
// and leave the rest of the teardown undone.
|
|
7
11
|
export class FloatingPanel extends Controller {
|
|
8
12
|
static targets = ["trigger", "popover"]
|
|
9
13
|
static values = { lift: { type: Boolean, default: true } }
|
|
@@ -20,18 +24,10 @@ export class FloatingPanel extends Controller {
|
|
|
20
24
|
this.closeOnOutsideClick = (event) => {
|
|
21
25
|
if (!this.element.contains(event.target)) this.close()
|
|
22
26
|
}
|
|
23
|
-
this.closeForPageLeave = () => this.closeNow({ immediate: true })
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
connect() {
|
|
27
|
-
document.addEventListener(BEFORE_OPEN, this.closeForOther)
|
|
28
|
-
this.stopPageLeave = onPageLeave(this.closeForPageLeave)
|
|
29
27
|
}
|
|
30
28
|
|
|
31
29
|
disconnect() {
|
|
32
|
-
|
|
33
|
-
this.stopPageLeave?.()
|
|
34
|
-
this.release({ immediate: true })
|
|
30
|
+
this.closeNow({ immediate: true })
|
|
35
31
|
}
|
|
36
32
|
|
|
37
33
|
toggle(event) {
|
|
@@ -58,6 +54,8 @@ export class FloatingPanel extends Controller {
|
|
|
58
54
|
if (this.lifts) this.releaseLift = liftToTopLayer(this.popoverTarget, this.opener)
|
|
59
55
|
this.triggerTarget.setAttribute("aria-expanded", "true")
|
|
60
56
|
|
|
57
|
+
document.addEventListener(BEFORE_OPEN, this.closeForOther)
|
|
58
|
+
this.stopPageLeave = onPageLeave(() => this.closeNow({ immediate: true }))
|
|
61
59
|
if (this.constructor.closesOnOutsideClick)
|
|
62
60
|
document.addEventListener("click", this.closeOnOutsideClick)
|
|
63
61
|
this.unregisterDismissable = registerDismissable({
|
|
@@ -74,11 +72,12 @@ export class FloatingPanel extends Controller {
|
|
|
74
72
|
}
|
|
75
73
|
|
|
76
74
|
closeNow({ immediate = false } = {}) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
this.hide()
|
|
75
|
+
const wasOpen = this.isOpen
|
|
76
|
+
if (wasOpen) this.hide()
|
|
80
77
|
this.release({ immediate })
|
|
81
|
-
|
|
78
|
+
if (!wasOpen) return
|
|
79
|
+
|
|
80
|
+
if (this.hasTriggerTarget) this.triggerTarget.setAttribute("aria-expanded", "false")
|
|
82
81
|
this.afterClose()
|
|
83
82
|
}
|
|
84
83
|
|
|
@@ -87,6 +86,9 @@ export class FloatingPanel extends Controller {
|
|
|
87
86
|
release({ immediate = false } = {}) {
|
|
88
87
|
this.releaseLift?.({ immediate })
|
|
89
88
|
this.releaseLift = null
|
|
89
|
+
document.removeEventListener(BEFORE_OPEN, this.closeForOther)
|
|
90
|
+
this.stopPageLeave?.()
|
|
91
|
+
this.stopPageLeave = null
|
|
90
92
|
document.removeEventListener("click", this.closeOnOutsideClick)
|
|
91
93
|
this.unregisterDismissable?.()
|
|
92
94
|
this.unregisterDismissable = null
|
|
@@ -103,7 +105,7 @@ export class FloatingPanel extends Controller {
|
|
|
103
105
|
}
|
|
104
106
|
|
|
105
107
|
get isOpen() {
|
|
106
|
-
return this.popoverTarget.hasAttribute("data-open")
|
|
108
|
+
return this.hasPopoverTarget && this.popoverTarget.hasAttribute("data-open")
|
|
107
109
|
}
|
|
108
110
|
|
|
109
111
|
get lifts() {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<%# locals: (id:, attributes:) %>
|
|
2
|
-
<%= lc_sheet(
|
|
2
|
+
<%= lc_sheet(as: :dialog, **attributes) do %>
|
|
3
3
|
<form method="dialog" class="flex flex-col gap-inset p-inset max-sm:pt-7" data-slot="confirm-sheet-content">
|
|
4
4
|
<div class="flex flex-col gap-tight max-sm:text-center">
|
|
5
5
|
<p id="<%= id %>-message" class="<%= lc_heading_class(size: :subheading) %>" data-slot="confirm-sheet-message"></p>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<%# locals: (id:, title:, description:, trigger:, rendered_trigger:, detents:, close_action:, close_label:, attributes:, actions:, content:) %>
|
|
2
|
-
<% dialog = lc_sheet(
|
|
2
|
+
<% dialog = lc_sheet(as: :dialog, detents: detents, **attributes) do %>
|
|
3
3
|
<div class="flex min-h-0 flex-col gap-inset p-inset sm:h-full sm:max-h-[inherit]" data-slot="dialog-content">
|
|
4
4
|
<header class="flex shrink-0 items-start justify-between gap-content" data-slot="dialog-header">
|
|
5
5
|
<div class="flex min-w-0 flex-col gap-tight">
|
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.13.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Lost Coordinates
|
|
@@ -205,7 +205,6 @@ files:
|
|
|
205
205
|
- app/views/lostcoords/ui/components/_lc_collapsible.html.erb
|
|
206
206
|
- app/views/lostcoords/ui/components/_lc_confirm_sheet.html.erb
|
|
207
207
|
- app/views/lostcoords/ui/components/_lc_dialog.html.erb
|
|
208
|
-
- app/views/lostcoords/ui/components/_lc_floating_panel.html.erb
|
|
209
208
|
- app/views/lostcoords/ui/components/_lc_search.html.erb
|
|
210
209
|
- config/emoji_search_aliases.yml
|
|
211
210
|
- config/emoji_search_names.yml
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
<%# locals: (id:, title:, wrapper:, trigger:, attributes:, content:) %>
|
|
2
|
-
<% panel = tag.div(**attributes) do %>
|
|
3
|
-
<% if title %><h2 id="<%= id %>-title" class="<%= lc_heading_class(size: :subheading) %>"><%= title %></h2><% end %>
|
|
4
|
-
<%= content %>
|
|
5
|
-
<% end %>
|
|
6
|
-
<% if wrapper %>
|
|
7
|
-
<%= tag.div(**wrapper) do %>
|
|
8
|
-
<%= trigger %>
|
|
9
|
-
<%= panel %>
|
|
10
|
-
<% end %>
|
|
11
|
-
<% else %>
|
|
12
|
-
<%= panel %>
|
|
13
|
-
<% end %>
|