lostcoords-ui 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +296 -27
  3. data/app/assets/tailwind/lostcoords/ui/card.css +11 -5
  4. data/app/assets/tailwind/lostcoords/ui/collapsible.css +6 -0
  5. data/app/assets/tailwind/lostcoords/ui/components/dialog.css +2 -2
  6. data/app/assets/tailwind/lostcoords/ui/components/search.css +5 -0
  7. data/app/assets/tailwind/lostcoords/ui/components.css +1 -0
  8. data/app/assets/tailwind/lostcoords/ui/core.css +2 -2
  9. data/app/assets/tailwind/lostcoords/ui/popover.css +6 -56
  10. data/app/assets/tailwind/lostcoords/ui/search.css +96 -0
  11. data/app/assets/tailwind/lostcoords/ui/sheet.css +42 -69
  12. data/app/assets/tailwind/lostcoords/ui/theme.css +18 -0
  13. data/app/assets/tailwind/lostcoords/ui/toast.css +34 -4
  14. data/app/assets/tailwind/lostcoords/ui/typography.css +10 -0
  15. data/app/helpers/lostcoords/ui/badge_helper.rb +20 -12
  16. data/app/helpers/lostcoords/ui/button_helper.rb +63 -1
  17. data/app/helpers/lostcoords/ui/choice_helper.rb +9 -16
  18. data/app/helpers/lostcoords/ui/collapsible_helper.rb +23 -4
  19. data/app/helpers/lostcoords/ui/dialog_helper.rb +46 -11
  20. data/app/helpers/lostcoords/ui/form_helper.rb +23 -10
  21. data/app/helpers/lostcoords/ui/glass_helper.rb +6 -0
  22. data/app/helpers/lostcoords/ui/layout_helper.rb +13 -5
  23. data/app/helpers/lostcoords/ui/list_group_helper.rb +65 -0
  24. data/app/helpers/lostcoords/ui/menu_helper.rb +73 -13
  25. data/app/helpers/lostcoords/ui/navigation_helper.rb +57 -12
  26. data/app/helpers/lostcoords/ui/primitives_helper.rb +112 -34
  27. data/app/helpers/lostcoords/ui/render_attributes_helper.rb +2 -0
  28. data/app/helpers/lostcoords/ui/search_helper.rb +51 -0
  29. data/app/helpers/lostcoords/ui/sheet_helper.rb +20 -8
  30. data/app/helpers/lostcoords/ui/structures_helper.rb +106 -15
  31. data/app/helpers/lostcoords/ui/tailwind_helper.rb +1 -1
  32. data/app/helpers/lostcoords/ui/toast_helper.rb +11 -4
  33. data/app/helpers/lostcoords/ui/typography_helper.rb +5 -3
  34. data/app/javascript/lostcoords/ui/controllers/lc_menu_controller.js +5 -6
  35. data/app/javascript/lostcoords/ui/controllers/lc_nav_controller.js +79 -0
  36. data/app/javascript/lostcoords/ui/controllers/lc_search_controller.js +264 -0
  37. data/app/javascript/lostcoords/ui/controllers/lc_selection_controller.js +3 -8
  38. data/app/javascript/lostcoords/ui/controllers/lc_sheet_controller.js +42 -16
  39. data/app/javascript/lostcoords/ui/helpers/confirm.js +57 -0
  40. data/app/javascript/lostcoords/ui/helpers/floating_panel.js +9 -0
  41. data/app/javascript/lostcoords/ui/index.js +4 -2
  42. data/app/views/lostcoords/ui/components/_lc_collapsible.html.erb +3 -3
  43. data/app/views/lostcoords/ui/components/_lc_confirm_sheet.html.erb +14 -0
  44. data/app/views/lostcoords/ui/components/_lc_dialog.html.erb +24 -16
  45. data/app/views/lostcoords/ui/components/_lc_floating_panel.html.erb +11 -6
  46. data/app/views/lostcoords/ui/components/_lc_search.html.erb +25 -0
  47. data/config/locales/en.yml +11 -0
  48. data/config/locales/es.yml +11 -0
  49. data/config/locales/ja.yml +11 -0
  50. data/lib/lostcoords/ui/builders.rb +1 -1
  51. data/lib/lostcoords/ui/form_builder.rb +59 -12
  52. data/lib/lostcoords/ui/parts.rb +65 -8
  53. data/lib/lostcoords/ui/tokens.rb +3 -1
  54. data/lib/lostcoords/ui/version.rb +1 -1
  55. metadata +10 -2
  56. data/app/javascript/lostcoords/ui/controllers/lc_confirm_dialog_controller.js +0 -39
@@ -0,0 +1,264 @@
1
+ import { Controller } from "@hotwired/stimulus"
2
+ import { registerDialog } from "lostcoords/ui/helpers/dialog"
3
+ import { prefersReducedMotion } from "lostcoords/ui/helpers/viewport"
4
+
5
+ // Full-screen search. Each query dispatches lc-search:query with { query, results }; a listener
6
+ // that calls preventDefault fills results itself. Otherwise the controller asks the server
7
+ // (src) for the results HTML, or filters the rows already rendered by their text.
8
+ export default class extends Controller {
9
+ static targets = [
10
+ "trigger",
11
+ "dialog",
12
+ "stack",
13
+ "bar",
14
+ "glyph",
15
+ "input",
16
+ "clear",
17
+ "cancel",
18
+ "panel",
19
+ "results",
20
+ "result",
21
+ "empty",
22
+ "status",
23
+ ]
24
+ static values = { src: String, param: { type: String, default: "q" }, one: String, other: String }
25
+
26
+ connect() {
27
+ this.animations = []
28
+ this.observer = new MutationObserver(() => this.refresh())
29
+ this.observer.observe(this.resultsTarget, { childList: true, subtree: true })
30
+ }
31
+
32
+ disconnect() {
33
+ this.observer.disconnect()
34
+ clearTimeout(this.timeout)
35
+ this.request?.abort()
36
+ this.returnFocus = null
37
+ this.reset()
38
+ }
39
+
40
+ // ⌘K / Ctrl+K comes from lc-shortcut: it presses the trigger while search is closed
41
+ // and refocuses the field while it is open.
42
+ open() {
43
+ if (this.closing) return
44
+ if (this.dialogTarget.open) return this.inputTarget.focus()
45
+ this.returnFocus =
46
+ document.activeElement === document.body ? this.triggerTarget : document.activeElement
47
+ this.element.dataset.open = ""
48
+ this.dialogTarget.showModal()
49
+ this.unregisterDialog = registerDialog(this.dialogTarget, { close: () => this.close() })
50
+ this.inputTarget.focus({ preventScroll: true })
51
+ this.inputTarget.select()
52
+ if (this.searched !== this.query) this.search()
53
+ this.refresh()
54
+ this.grow()
55
+ }
56
+
57
+ close() {
58
+ if (!this.dialogTarget.open || this.closing) return
59
+ this.closing = true
60
+ this.fade()
61
+ Promise.allSettled(this.animations.map((animation) => animation.finished)).then(() =>
62
+ this.reset(),
63
+ )
64
+ }
65
+
66
+ // Also runs before Turbo caches the page, so a restored page never shows search open.
67
+ reset() {
68
+ this.animations.forEach((animation) => animation.cancel())
69
+ this.animations = []
70
+ this.dialogTarget.close()
71
+ this.unregisterDialog?.()
72
+ this.unregisterDialog = null
73
+ this.closing = false
74
+ delete this.element.dataset.open
75
+ }
76
+
77
+ closed() {
78
+ this.reset()
79
+ this.returnFocus?.focus({ preventScroll: true })
80
+ this.returnFocus = null
81
+ }
82
+
83
+ // A click on the backdrop closes search, and so does choosing a result, which matters for
84
+ // links within the page and Turbo visits that keep it.
85
+ dismiss(event) {
86
+ if (event.target.hasAttribute("data-lc-search-dismiss")) this.close()
87
+ else if (event.target.closest?.("[data-slot=search-result]")) this.close()
88
+ }
89
+
90
+ clear() {
91
+ this.inputTarget.value = ""
92
+ this.inputTarget.focus()
93
+ this.input()
94
+ }
95
+
96
+ input(event) {
97
+ if (event?.isComposing) return
98
+ this.clearTarget.hidden = !this.inputTarget.value
99
+ clearTimeout(this.timeout)
100
+ // The server answers each query, so it waits for a pause in typing.
101
+ if (this.srcValue) this.timeout = setTimeout(() => this.search(), 150)
102
+ else this.search()
103
+ }
104
+
105
+ submit(event) {
106
+ event.preventDefault()
107
+ this.openFirst()
108
+ }
109
+
110
+ navigate(event) {
111
+ if (event.isComposing || event.keyCode === 229) return
112
+ if (event.key !== "ArrowDown" && event.key !== "ArrowUp") return
113
+ event.preventDefault()
114
+ const items = [this.inputTarget, ...this.visibleResults()]
115
+ const index = items.indexOf(document.activeElement)
116
+ const step = event.key === "ArrowDown" ? 1 : -1
117
+ items[Math.min(Math.max(index + step, 0), items.length - 1)].focus()
118
+ }
119
+
120
+ get query() {
121
+ return this.inputTarget.value.normalize("NFKC").trim()
122
+ }
123
+
124
+ search() {
125
+ const query = this.query
126
+ this.searched = query
127
+ const event = this.dispatch("query", {
128
+ detail: { query, results: this.resultsTarget },
129
+ cancelable: true,
130
+ })
131
+ if (event.defaultPrevented) return
132
+ if (this.srcValue) this.load(query)
133
+ else this.filter(query)
134
+ }
135
+
136
+ load(query) {
137
+ this.request?.abort()
138
+ const request = new AbortController()
139
+ this.request = request
140
+ const url = new URL(this.srcValue, location.href)
141
+ url.searchParams.set(this.paramValue, query)
142
+ this.loading = fetch(url, { headers: { Accept: "text/html" }, signal: request.signal })
143
+ .then((response) => {
144
+ if (!response.ok) throw new Error(`${url} answered ${response.status}`)
145
+ return response.text()
146
+ })
147
+ .then((html) => {
148
+ if (this.request !== request) return
149
+ this.resultsTarget.innerHTML = html
150
+ this.loaded = query
151
+ })
152
+ .catch((error) => {
153
+ if (error.name !== "AbortError") console.error(error)
154
+ })
155
+ return this.loading
156
+ }
157
+
158
+ filter(query) {
159
+ const words = query.toLowerCase().split(/\s+/).filter(Boolean)
160
+ for (const result of this.resultTargets) {
161
+ const text = `${result.dataset.lcSearchKeywords ?? ""} ${result.textContent}`
162
+ .normalize("NFKC")
163
+ .toLowerCase()
164
+ result.hidden = !words.every((word) => text.includes(word))
165
+ }
166
+ this.refresh()
167
+ }
168
+
169
+ // Enter in the field opens the top result; while the server is still answering a newer
170
+ // query, it waits for that answer.
171
+ openFirst() {
172
+ clearTimeout(this.timeout)
173
+ if (this.srcValue && this.loaded !== this.query) {
174
+ const query = this.query
175
+ if (this.searched !== query) this.search()
176
+ this.loading?.then(() => this.loaded === query && this.openFirst())
177
+ return
178
+ }
179
+ this.visibleResults()[0]?.click()
180
+ }
181
+
182
+ visibleResults() {
183
+ return this.resultTargets.filter((result) => result.checkVisibility())
184
+ }
185
+
186
+ // Groups without a visible result hide, the empty note shows for a query with no results,
187
+ // and the status announces the count.
188
+ refresh() {
189
+ for (const group of this.resultsTarget.querySelectorAll("[data-slot=search-group]")) {
190
+ group.hidden = ![...group.querySelectorAll("[data-slot=search-result]")].some(
191
+ (result) => !result.hidden,
192
+ )
193
+ }
194
+ const count = this.resultTargets.filter(
195
+ (result) => !result.hidden && !result.closest("[hidden]"),
196
+ ).length
197
+ const query = this.query
198
+ this.emptyTarget.hidden = count > 0 || !query
199
+ this.panelTarget.hidden = count === 0 && this.emptyTarget.hidden
200
+ this.statusTarget.textContent = query
201
+ ? (count === 1 ? this.oneValue : this.otherValue).replace("%{count}", count)
202
+ : ""
203
+ }
204
+
205
+ // The bar grows out of the trigger and the glyph slides from the trigger's icon to its
206
+ // place in the field; the rest fades in behind it.
207
+ grow() {
208
+ this.animations.forEach((animation) => animation.cancel())
209
+ this.animations = []
210
+ if (prefersReducedMotion()) return
211
+ const from = this.triggerTarget.getBoundingClientRect()
212
+ const to = this.barTarget.getBoundingClientRect()
213
+ const glyph = this.glyphTarget.getBoundingClientRect()
214
+ const icon = this.triggerTarget.querySelector("svg").getBoundingClientRect()
215
+ const insetY = Math.max((to.height - from.height) / 2, 0)
216
+ const shiftY = from.top + from.height / 2 - (to.top + to.height / 2)
217
+ const timing = { duration: 420, easing: "cubic-bezier(0.16, 1, 0.3, 1)", fill: "both" }
218
+ const fade = [
219
+ { opacity: 0, translate: "0 -0.5rem" },
220
+ { opacity: 1, translate: "0 0" },
221
+ ]
222
+ this.animations = [
223
+ this.barTarget.animate(
224
+ [
225
+ {
226
+ clipPath: `inset(${insetY}px ${Math.max(to.right - from.right, 0)}px ${insetY}px ${Math.max(from.left - to.left, 0)}px round 999px)`,
227
+ translate: `0 ${shiftY}px`,
228
+ },
229
+ { clipPath: "inset(-1.5rem round 999px)", translate: "0 0" },
230
+ ],
231
+ timing,
232
+ ),
233
+ this.glyphTarget.animate(
234
+ [
235
+ { translate: `${icon.left + (icon.width - glyph.width) / 2 - glyph.left}px 0` },
236
+ { translate: "0 0" },
237
+ ],
238
+ timing,
239
+ ),
240
+ this.inputTarget.animate([{ opacity: 0 }, { opacity: 1 }], { ...timing, delay: 120 }),
241
+ this.panelTarget.animate(fade, { ...timing, delay: 60 }),
242
+ this.cancelTarget.animate(fade, timing),
243
+ this.dialogTarget.animate([{ opacity: 0 }, { opacity: 1 }], {
244
+ ...timing,
245
+ pseudoElement: "::backdrop",
246
+ }),
247
+ ]
248
+ }
249
+
250
+ // Closing doesn't play the opening back into the trigger: the overlay just fades.
251
+ fade() {
252
+ this.animations.forEach((animation) => animation.cancel())
253
+ this.animations = []
254
+ if (prefersReducedMotion()) return
255
+ const timing = { duration: 160, easing: "ease-out", fill: "both" }
256
+ this.animations = [
257
+ this.stackTarget.animate([{ opacity: 1 }, { opacity: 0 }], timing),
258
+ this.dialogTarget.animate([{ opacity: 1 }, { opacity: 0 }], {
259
+ ...timing,
260
+ pseudoElement: "::backdrop",
261
+ }),
262
+ ]
263
+ }
264
+ }
@@ -2,14 +2,14 @@ import { Controller } from "@hotwired/stimulus"
2
2
  import { navigate } from "lostcoords/ui/helpers/roving_focus"
3
3
 
4
4
  export default class extends Controller {
5
- static targets = ["option", "input"]
5
+ static targets = ["option"]
6
6
  static values = { value: String }
7
7
 
8
8
  connect() {
9
9
  const selected = this.options.find((option) =>
10
10
  this.hasValueValue
11
11
  ? option.dataset.value === this.valueValue
12
- : option.getAttribute("aria-pressed") === "true",
12
+ : option.getAttribute("aria-checked") === "true",
13
13
  )
14
14
  this.initialOption = selected || this.options[0]
15
15
  this.apply(this.initialOption)
@@ -41,17 +41,12 @@ export default class extends Controller {
41
41
 
42
42
  apply(selected) {
43
43
  for (const option of this.optionTargets) {
44
- option.setAttribute("aria-pressed", String(option === selected))
44
+ option.setAttribute("aria-checked", String(option === selected))
45
45
  option.tabIndex = option === selected ? 0 : -1
46
46
  }
47
- if (this.hasInputTarget) this.inputTarget.value = selected?.dataset.value || ""
48
47
  }
49
48
 
50
49
  changed(option) {
51
- if (this.hasInputTarget) {
52
- this.inputTarget.dispatchEvent(new Event("input", { bubbles: true }))
53
- this.inputTarget.dispatchEvent(new Event("change", { bubbles: true }))
54
- }
55
50
  this.dispatch("change", { detail: { value: option.dataset.value } })
56
51
  }
57
52
 
@@ -1,6 +1,7 @@
1
1
  import { Controller } from "@hotwired/stimulus"
2
2
  import { holdDocumentScroll } from "lostcoords/ui/helpers/dismiss_stack"
3
3
  import { SHEET_TIMING, sheetDuration } from "lostcoords/ui/helpers/sheet_motion"
4
+ import { hideTopLayer, supportsTopLayer } from "lostcoords/ui/helpers/top_layer"
4
5
  import { isSheetViewport, prefersReducedMotion, TEXT_ENTRY } from "lostcoords/ui/helpers/viewport"
5
6
 
6
7
  const PROJECTION_MS = 180
@@ -29,20 +30,27 @@ export default class extends Controller {
29
30
  this.element.addEventListener("touchcancel", this.onTouchEnd)
30
31
  this.element.addEventListener("pointerdown", this.onPointerDown)
31
32
 
32
- if (this.isDialog) {
33
- this.observer = new MutationObserver(() =>
34
- this.element.open ? this.present() : this.closed(),
35
- )
36
- this.observer.observe(this.element, { attributes: true, attributeFilter: ["open"] })
37
- if (this.element.open) this.present()
38
- } else {
39
- this.observer = new MutationObserver(() => this.element.hidden || this.pinFloor())
40
- this.observer.observe(this.element, { attributes: true, attributeFilter: ["hidden"] })
41
- }
33
+ this.sync = this.sync.bind(this)
34
+ this.shown = false
35
+ this.observer = new MutationObserver(this.sync)
36
+ this.observer.observe(this.element, {
37
+ attributes: true,
38
+ attributeFilter: ["open", "data-open"],
39
+ })
40
+ this.element.addEventListener("toggle", this.sync)
41
+ this.sync()
42
+ }
43
+
44
+ sync() {
45
+ const shown = this.isShown
46
+ if (shown === this.shown) return
47
+ this.shown = shown
48
+ shown ? this.present() : this.closed()
42
49
  }
43
50
 
44
51
  disconnect() {
45
52
  this.observer?.disconnect()
53
+ this.element.removeEventListener("toggle", this.sync)
46
54
  this.element.removeEventListener("touchstart", this.onTouchStart)
47
55
  this.element.removeEventListener("touchmove", this.onTouchMove)
48
56
  this.element.removeEventListener("touchend", this.onTouchEnd)
@@ -155,8 +163,11 @@ export default class extends Controller {
155
163
  if (this.gesture?.dragging) this.track(event.clientY, event.timeStamp)
156
164
  }
157
165
 
158
- onPointerUp() {
166
+ // A mouse drag that ends off the sheet is followed by a click on the
167
+ // <dialog> itself, which reads as a backdrop click and would close it.
168
+ onPointerUp(event) {
159
169
  this.stopMouseTracking()
170
+ if (this.gesture && Math.abs(event.clientY - this.gesture.startY) > 4) swallowNextClick()
160
171
  this.onTouchEnd()
161
172
  }
162
173
 
@@ -239,7 +250,8 @@ export default class extends Controller {
239
250
  this.transition()
240
251
  this.element.style.transform = `translateY(${this.element.getBoundingClientRect().height + 48}px)`
241
252
  this.later(() => {
242
- this.dispatch("dismiss", { bubbles: false })
253
+ const event = this.dispatch("dismiss", { bubbles: false, cancelable: true })
254
+ if (!event.defaultPrevented) hideTopLayer(this.element)
243
255
  requestAnimationFrame(() => this.resetSurface())
244
256
  })
245
257
  }
@@ -374,10 +386,7 @@ export default class extends Controller {
374
386
 
375
387
  transition() {
376
388
  const timing = prefersReducedMotion() ? "0s" : SHEET_TIMING
377
- const discrete = this.isDialog
378
- ? `, display ${timing} allow-discrete, overlay ${timing} allow-discrete`
379
- : ""
380
- this.element.style.transition = `transform ${timing}, block-size ${timing}${discrete}`
389
+ this.element.style.transition = `transform ${timing}, block-size ${timing}, display ${timing} allow-discrete, overlay ${timing} allow-discrete`
381
390
  clearTimeout(this.transitionTimer)
382
391
  this.transitionTimer = setTimeout(() => {
383
392
  this.element.style.transition = ""
@@ -416,7 +425,24 @@ export default class extends Controller {
416
425
  return this.element instanceof HTMLDialogElement
417
426
  }
418
427
 
428
+ get isShown() {
429
+ if (this.isDialog) return this.element.open
430
+ return (
431
+ this.element.hasAttribute("data-open") ||
432
+ (supportsTopLayer() && this.element.matches(":popover-open"))
433
+ )
434
+ }
435
+
419
436
  get isSheet() {
420
437
  return isSheetViewport()
421
438
  }
422
439
  }
440
+
441
+ function swallowNextClick() {
442
+ const swallow = (event) => {
443
+ event.preventDefault()
444
+ event.stopImmediatePropagation()
445
+ }
446
+ window.addEventListener("click", swallow, { capture: true, once: true })
447
+ setTimeout(() => window.removeEventListener("click", swallow, { capture: true }), 0)
448
+ }
@@ -0,0 +1,57 @@
1
+ import { showContextDialog } from "lostcoords/ui/helpers/context_dialog"
2
+ import { registerDialog } from "lostcoords/ui/helpers/dialog"
3
+
4
+ const SHEET_ID = "lc-confirm-sheet"
5
+ const SHORT_LABEL = 24
6
+ const DESTRUCTIVE =
7
+ "[data-turbo-confirm-tone=destructive], [data-variant=destructive], [data-tone=destructive]"
8
+ const MENU = "[data-lc-menu-target~=popover]"
9
+
10
+ // Turbo.config.forms.confirm = confirm. The submitter, then the form, can set
11
+ // data-turbo-confirm-description, data-turbo-confirm-accept and data-turbo-confirm-tone.
12
+ // Without an accept label, a short submitter label replaces "Confirm".
13
+ export function confirm(message, element, submitter) {
14
+ const nodes = [submitter, element].filter((node) => node instanceof Element)
15
+ const read = (name) => nodes.map((node) => node.dataset[name]).find(Boolean) || null
16
+ const label = (submitter || element)?.textContent?.trim().replace(/\s+/g, " ")
17
+ return ask(message, {
18
+ description: read("turboConfirmDescription"),
19
+ accept: read("turboConfirmAccept") || (label && label.length <= SHORT_LABEL ? label : null),
20
+ destructive: nodes.some((node) => node.matches(DESTRUCTIVE)),
21
+ anchor: nodes[0]?.closest(MENU),
22
+ })
23
+ }
24
+
25
+ // anchor: on desktop the sheet opens beside this element, as a menu's follow-up does.
26
+ export function ask(
27
+ message,
28
+ { description = null, accept = null, destructive = false, anchor = null } = {},
29
+ ) {
30
+ const dialog = document.getElementById(SHEET_ID)
31
+ if (!dialog) return Promise.resolve(window.confirm(message))
32
+ if (dialog.open) return Promise.resolve(false)
33
+
34
+ dialog.querySelector("[data-slot=confirm-sheet-message]").textContent = message
35
+ const details = dialog.querySelector("[data-slot=confirm-sheet-description]")
36
+ details.textContent = description || ""
37
+ details.hidden = !description
38
+ for (const button of dialog.querySelectorAll("[data-slot=confirm-sheet-accept]")) {
39
+ const shown = (button.dataset.variant === "destructive") === destructive
40
+ button.hidden = !shown
41
+ button.dataset.defaultLabel ??= button.textContent.trim()
42
+ button.textContent = (shown && accept) || button.dataset.defaultLabel
43
+ }
44
+
45
+ return new Promise((resolve) => {
46
+ dialog.returnValue = ""
47
+ dialog.addEventListener("close", () => resolve(dialog.returnValue === "confirm"), {
48
+ once: true,
49
+ })
50
+ dialog.style.removeProperty("--lc-dialog-origin")
51
+ showContextDialog(dialog, anchor)
52
+ registerDialog(dialog, { lockScroll: false })
53
+ // showModal focuses Cancel, and a confirm raised while typing would hand it the field's focus ring.
54
+ // The sheet itself takes focus; Tab still reaches both buttons.
55
+ dialog.focus({ preventScroll: true })
56
+ })
57
+ }
@@ -40,6 +40,15 @@ export class FloatingPanel extends Controller {
40
40
  this.isOpen ? this.close() : this.open()
41
41
  }
42
42
 
43
+ // A host that is a whole row opens its panel from a click anywhere on the row except its controls.
44
+ toggleFromRow(event) {
45
+ if (this.popoverTarget.contains(event.target)) return
46
+ if (event.target.closest("a, button, input, select, textarea, [data-lc-menu-ignore]")) return
47
+
48
+ event.preventDefault()
49
+ this.isOpen ? this.close() : this.open()
50
+ }
51
+
43
52
  open(opener) {
44
53
  if (this.isOpen) return
45
54
  this.opener = opener instanceof Element ? opener : this.triggerTarget
@@ -1,12 +1,13 @@
1
1
  import CodeBlock from "lostcoords/ui/controllers/lc_code_block_controller"
2
2
  import Collapsible from "lostcoords/ui/controllers/lc_collapsible_controller"
3
- import ConfirmDialog from "lostcoords/ui/controllers/lc_confirm_dialog_controller"
4
3
  import Copy from "lostcoords/ui/controllers/lc_copy_controller"
5
4
  import Dialog from "lostcoords/ui/controllers/lc_dialog_controller"
6
5
  import EmojiPicker from "lostcoords/ui/controllers/lc_emoji_picker_controller"
7
6
  import Kbd from "lostcoords/ui/controllers/lc_kbd_controller"
8
7
  import Menu from "lostcoords/ui/controllers/lc_menu_controller"
8
+ import Nav from "lostcoords/ui/controllers/lc_nav_controller"
9
9
  import Popover from "lostcoords/ui/controllers/lc_popover_controller"
10
+ import Search from "lostcoords/ui/controllers/lc_search_controller"
10
11
  import Selection from "lostcoords/ui/controllers/lc_selection_controller"
11
12
  import Sheet from "lostcoords/ui/controllers/lc_sheet_controller"
12
13
  import Shortcut from "lostcoords/ui/controllers/lc_shortcut_controller"
@@ -17,7 +18,6 @@ import Toggle from "lostcoords/ui/controllers/lc_toggle_controller"
17
18
  import Tooltip from "lostcoords/ui/controllers/lc_tooltip_controller"
18
19
 
19
20
  const controllers = {
20
- "lc-confirm-dialog": ConfirmDialog,
21
21
  "lc-collapsible": Collapsible,
22
22
  "lc-code-block": CodeBlock,
23
23
  "lc-copy": Copy,
@@ -25,7 +25,9 @@ const controllers = {
25
25
  "lc-emoji-picker": EmojiPicker,
26
26
  "lc-kbd": Kbd,
27
27
  "lc-menu": Menu,
28
+ "lc-nav": Nav,
28
29
  "lc-popover": Popover,
30
+ "lc-search": Search,
29
31
  "lc-selection": Selection,
30
32
  "lc-sheet": Sheet,
31
33
  "lc-shortcut": Shortcut,
@@ -1,5 +1,5 @@
1
- <%# locals: (title:, attributes:, content:) %>
1
+ <%# locals: (summary:, summary_attributes:, attributes:, content:) %>
2
2
  <%= tag.details(**attributes) do %>
3
- <summary class="cursor-pointer text-label font-semibold"><%= title %></summary>
4
- <div class="pt-heading"><%= content %></div>
3
+ <%= tag.summary(summary, **summary_attributes) %>
4
+ <div class="pt-heading" data-slot="collapsible-content"><%= content %></div>
5
5
  <% end %>
@@ -0,0 +1,14 @@
1
+ <%# locals: (id:, attributes:) %>
2
+ <%= lc_sheet(tag: :dialog, **attributes) do %>
3
+ <form method="dialog" class="flex flex-col gap-inset p-inset max-sm:pt-7" data-slot="confirm-sheet-content">
4
+ <div class="flex flex-col gap-tight max-sm:text-center">
5
+ <p id="<%= id %>-message" class="<%= lc_heading_class(size: :subheading) %>" data-slot="confirm-sheet-message"></p>
6
+ <p id="<%= id %>-description" class="<%= lc_text_class(size: :small, tone: :muted) %>" data-slot="confirm-sheet-description" hidden></p>
7
+ </div>
8
+ <div class="grid grid-cols-2 gap-related" data-slot="confirm-sheet-actions">
9
+ <button type="submit" value="cancel" class="<%= lc_button_class(variant: :secondary, block: true) %>" data-slot="confirm-sheet-cancel"><%= lc_t("lostcoords.ui.confirm.cancel") %></button>
10
+ <button type="submit" value="confirm" class="<%= lc_button_class(variant: :primary, block: true) %>" data-slot="confirm-sheet-accept" data-variant="primary"><%= lc_t("lostcoords.ui.confirm.accept") %></button>
11
+ <button type="submit" value="confirm" class="<%= lc_button_class(variant: :destructive, block: true) %>" data-slot="confirm-sheet-accept" data-variant="destructive" hidden><%= lc_t("lostcoords.ui.confirm.accept") %></button>
12
+ </div>
13
+ </form>
14
+ <% end %>
@@ -1,16 +1,24 @@
1
- <%# locals: (id:, title:, description:, trigger:, attributes:, content:) %>
2
- <div data-controller="lc-dialog">
3
- <button type="button" class="<%= lc_button_class(variant: :secondary) %>" aria-haspopup="dialog" aria-controls="<%= id %>" data-action="lc-dialog#open" data-slot="dialog-trigger"><%= trigger %></button>
4
- <%= tag.dialog(**attributes) do %>
5
- <div class="flex flex-col gap-inset p-inset" data-slot="dialog-content">
6
- <header class="flex items-start justify-between gap-content" data-slot="dialog-header">
7
- <div class="flex min-w-0 flex-col gap-tight">
8
- <h2 id="<%= id %>-title" class="<%= lc_heading_class(size: :subheading) %>" data-slot="dialog-title"><%= title %></h2>
9
- <% if description.present? %><p id="<%= id %>-description" class="<%= lc_text_class(size: :small, tone: :muted) %>" data-slot="dialog-description"><%= description %></p><% end %>
10
- </div>
11
- <button type="button" class="<%= lc_icon_button_class(size: :sm, shape: :circle, extra: "-me-related -mt-tight") %>" aria-label="<%= lc_t("lostcoords.ui.dialog.close", title: title) %>" data-action="lc-dialog#close"><%= lc_icon "x-mark", options: { "aria-hidden": true } %></button>
12
- </header>
13
- <%= content %>
14
- </div>
15
- <% end %>
16
- </div>
1
+ <%# locals: (id:, title:, description:, trigger:, detents:, close_action:, close_label:, attributes:, actions:, content:) %>
2
+ <% dialog = lc_sheet(tag: :dialog, detents: detents, **attributes) do %>
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
+ <header class="flex shrink-0 items-start justify-between gap-content" data-slot="dialog-header">
5
+ <div class="flex min-w-0 flex-col gap-tight">
6
+ <%= title %>
7
+ <%= description %>
8
+ </div>
9
+ <div class="flex shrink-0 items-center gap-related -me-related -mt-tight" data-slot="dialog-actions">
10
+ <%= actions %>
11
+ <button type="button" class="<%= lc_icon_button_class(size: :sm, shape: :circle) %>" aria-label="<%= close_label %>" data-action="<%= close_action %>" data-slot="dialog-dismiss"><%= lc_icon "x-mark", options: { "aria-hidden": true } %></button>
12
+ </div>
13
+ </header>
14
+ <div class="-mx-inset -mb-inset flex min-h-0 flex-1 flex-col gap-inset px-inset pb-inset sm:overflow-y-auto sm:overscroll-contain" data-slot="dialog-body"><%= content %></div>
15
+ </div>
16
+ <% end %>
17
+ <% if trigger %>
18
+ <div data-controller="lc-dialog">
19
+ <button type="button" class="<%= lc_button_class(variant: :secondary) %>" aria-haspopup="dialog" aria-controls="<%= id %>" data-action="lc-dialog#open" data-slot="dialog-trigger"><%= trigger %></button>
20
+ <%= dialog %>
21
+ </div>
22
+ <% else %>
23
+ <%= dialog %>
24
+ <% end %>
@@ -1,8 +1,13 @@
1
- <%# locals: (id:, label:, title:, controller:, role:, trigger_variant:, attributes:, content:) %>
2
- <%= tag.div(class: "relative inline-flex", data: { controller: controller }) do %>
3
- <%= lc_button label, variant: trigger_variant, id: "#{id}-trigger", aria: { haspopup: role, expanded: false, controls: id }, data: { "#{controller}_target" => "trigger", action: "#{controller}#toggle" } %>
4
- <%= tag.div(**attributes) do %>
5
- <% if title %><h2 id="<%= id %>-title" class="<%= lc_heading_class(size: :subheading) %>"><%= title %></h2><% end %>
6
- <%= content %>
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 %>
7
10
  <% end %>
11
+ <% else %>
12
+ <%= panel %>
8
13
  <% end %>
@@ -0,0 +1,25 @@
1
+ <%# locals: (id:, label:, src:, param:, placeholder:, trigger:, shortcut:, attributes:, content:) %>
2
+ <div class="contents" data-slot="search" data-controller="lc-search" data-action="turbo:before-cache@document->lc-search#reset" data-lc-search-src-value="<%= src %>" data-lc-search-param-value="<%= param %>" data-lc-search-one-value="<%= lc_t("lostcoords.ui.search.results.one", count: "%{count}") %>" data-lc-search-other-value="<%= lc_t("lostcoords.ui.search.results.other", count: "%{count}") %>">
3
+ <%= tag.button(**attributes) do %>
4
+ <%= lc_icon "magnifying-glass", options: { class: "size-4 shrink-0", "aria-hidden": true } %>
5
+ <span class="flex-1 truncate text-start max-sm:sr-only"><%= trigger %></span>
6
+ <% if shortcut %><%= lc_kbd shortcut, class: "hidden bg-transparent px-0 any-pointer-fine:sm:inline", aria: { hidden: true } %><% end %>
7
+ <% end %>
8
+ <dialog id="<%= id %>" class="lc-search" aria-label="<%= label %>" data-lc-search-target="dialog" data-action="close->lc-search#closed keydown->lc-search#navigate click->lc-search#dismiss">
9
+ <div class="lc-search-stack" data-lc-search-target="stack" data-lc-search-dismiss>
10
+ <%= tag.form action: src, method: :get, role: "search", class: "flex shrink-0 items-center gap-heading", data: { action: "submit->lc-search#submit" } do %>
11
+ <label class="<%= lc_glass_class(extra: "flex min-h-14 min-w-0 flex-1 cursor-text items-center gap-heading ps-5 pe-2 sm:min-h-16") %>" data-lc-search-target="bar">
12
+ <%= lc_icon "magnifying-glass", options: { class: "size-6 shrink-0 text-muted-foreground", "aria-hidden": true, "data-lc-search-target": "glyph" } %>
13
+ <input type="search" name="<%= param %>" class="lc-search-input min-w-0 flex-1 self-stretch border-0 bg-transparent text-base text-foreground outline-none placeholder:text-muted-foreground" aria-label="<%= label %>" placeholder="<%= placeholder %>" autocomplete="off" autocapitalize="off" spellcheck="false" enterkeyhint="search" data-lc-search-target="input" data-action="input->lc-search#input"<% if shortcut %> data-controller="lc-shortcut" data-lc-shortcut-keys-value="<%= shortcut %>"<% end %>>
14
+ <%= lc_icon_button lc_t("lostcoords.ui.search.clear"), icon: "x-circle", size: :sm, shape: :circle, hidden: true, data: { lc_search_target: "clear", action: "lc-search#clear" } %>
15
+ </label>
16
+ <%= lc_button lc_t("lostcoords.ui.search.cancel"), variant: :ghost, size: :sm, class: "sm:hidden", data: { lc_search_target: "cancel", action: "lc-search#close" } %>
17
+ <% end %>
18
+ <div class="<%= lc_glass_class(shape: :panel, extra: "lc-search-panel min-h-0 overflow-y-auto overscroll-contain p-related") %>" data-lc-search-target="panel" data-slot="search-panel">
19
+ <div data-lc-search-target="results" data-slot="search-results"><%= content %></div>
20
+ <p class="px-content py-10 text-center text-label text-muted-foreground" data-lc-search-target="empty" data-slot="search-empty" hidden><%= lc_t("lostcoords.ui.search.empty") %></p>
21
+ </div>
22
+ <p class="sr-only" role="status" aria-atomic="true" data-lc-search-target="status"></p>
23
+ </div>
24
+ </dialog>
25
+ </div>
@@ -13,6 +13,9 @@ en:
13
13
  trigger: "Open dialog"
14
14
  cancel: "Cancel"
15
15
  close: "Close %{title}"
16
+ confirm:
17
+ cancel: "Cancel"
18
+ accept: "Confirm"
16
19
  menu:
17
20
  label: "Actions"
18
21
  popover:
@@ -54,3 +57,11 @@ en:
54
57
  objects: "Objects"
55
58
  symbols: "Symbols"
56
59
  flags: "Flags"
60
+ search:
61
+ trigger: "Search…"
62
+ clear: "Clear search"
63
+ cancel: "Cancel"
64
+ empty: "No results"
65
+ results:
66
+ one: "%{count} result"
67
+ other: "%{count} results"