lostcoords-ui 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +26 -1
- data/app/assets/tailwind/lostcoords/ui/components/hovercard.css +4 -0
- data/app/assets/tailwind/lostcoords/ui/components.css +1 -0
- data/app/assets/tailwind/lostcoords/ui/hovercard.css +47 -0
- data/app/helpers/lostcoords/ui/hovercard_helper.rb +31 -0
- data/app/javascript/lostcoords/ui/controllers/lc_hovercard_controller.js +104 -0
- data/app/javascript/lostcoords/ui/helpers/dismiss_stack.js +1 -1
- data/app/javascript/lostcoords/ui/index.js +2 -0
- data/lib/lostcoords/ui/version.rb +1 -1
- metadata +5 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2054816b6a7ff56d849935ab460b5b507d18e75f0bad9153ff12aa3325c6e336
|
|
4
|
+
data.tar.gz: 306f6d0f412c0bb972290c9436f5020e8a1c29cb90ff757384ca596a6590124c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ca0712c7a3f9cef74431634ffa1c1da04b6b0cc9299ab28dec6d446df45642161bf17dc8d5154101aff8a24865a992ad36ef02927c2541f8d4337d8af09ae229
|
|
7
|
+
data.tar.gz: f74402ec4c561044d13e22d61e7184213b1f930c41a6c953ce5fb2e927acf46f99dbf7f189689ab676d5a9647a2aa646655bf063088124e306bfc0bca5e1a1b2
|
data/README.md
CHANGED
|
@@ -21,7 +21,7 @@ lockfile pins its gem version, so publishing a library update does not upgrade c
|
|
|
21
21
|
## Install
|
|
22
22
|
|
|
23
23
|
```ruby
|
|
24
|
-
gem "lostcoords-ui", "~> 0.
|
|
24
|
+
gem "lostcoords-ui", "~> 0.11.0"
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
The engine adds its rendering helpers to host views, its views and translations to the host's lookup
|
|
@@ -170,6 +170,15 @@ Omit `only` to register every library controller. Unknown identifiers raise befo
|
|
|
170
170
|
registered, and repeated calls on the same application keep later overrides, so register defaults
|
|
171
171
|
before application overrides.
|
|
172
172
|
|
|
173
|
+
## Changes in 0.11.0
|
|
174
|
+
|
|
175
|
+
Nothing needs an edit. New:
|
|
176
|
+
|
|
177
|
+
- **`lc_hovercard` previews what a link points to**, such as a profile card over a name, with the
|
|
178
|
+
`lc-hovercard` controller, in the `components` entry. It opens on hover or keyboard focus, takes its card
|
|
179
|
+
as `content:` or loads it lazily from `src:`, and keeps the card out of the accessibility tree as a
|
|
180
|
+
preview of the linked page.
|
|
181
|
+
|
|
173
182
|
## Changes in 0.10.0
|
|
174
183
|
|
|
175
184
|
Nothing needs an edit, but toggles look different:
|
|
@@ -817,6 +826,22 @@ hides.
|
|
|
817
826
|
`lc-popover-shell` gives a native `[popover]` menu the same enter and exit as FloatingPanel panels. Set
|
|
818
827
|
`--lc-popover-from` to change the closed pose and an `origin-*` utility for where it grows from.
|
|
819
828
|
|
|
829
|
+
`lc_hovercard` previews what a link points to, such as a profile over a name, with the `lc-hovercard`
|
|
830
|
+
controller. The card opens after a short hover, or at once on keyboard focus, in the top layer beside the
|
|
831
|
+
trigger, flips above it near the bottom of the screen, and stays open while the pointer crosses onto it.
|
|
832
|
+
Leaving both closes it, Escape closes it at once, and touch screens never open it, so a tap follows the
|
|
833
|
+
link. Splat the yielded attributes on the trigger. `content:` renders the card up front; `src:` loads it as
|
|
834
|
+
HTML from your endpoint the first time it opens, from the page's own origin only, so a long list of
|
|
835
|
+
triggers costs nothing until one is hovered, and a skeleton shows until then. The card is a preview: it is
|
|
836
|
+
hidden from assistive technology and its links leave the tab order, so keep everything in it reachable
|
|
837
|
+
from the page the link opens. Inside a paragraph, keep `content:` to phrasing elements such as spans.
|
|
838
|
+
|
|
839
|
+
```erb
|
|
840
|
+
<%= lc_hovercard src: card_person_path(person) do |card| %>
|
|
841
|
+
<%= link_to person.name, person, **card %>
|
|
842
|
+
<% end %>
|
|
843
|
+
```
|
|
844
|
+
|
|
820
845
|
### Search
|
|
821
846
|
|
|
822
847
|
`lc_search` renders a search trigger, a pill with the ⌘K hint that shrinks to an icon on phones, and
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
@import "./components/toast.css";
|
|
7
7
|
@import "./components/search.css";
|
|
8
8
|
@import "./components/tooltip.css";
|
|
9
|
+
@import "./components/hovercard.css";
|
|
9
10
|
@import "./components/collapsible.css";
|
|
10
11
|
@import "./components/code-block.css";
|
|
11
12
|
@import "./components/emoji-picker.css";
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
@layer components {
|
|
2
|
+
/* lc-hovercard lifts the card into the top layer while it shows. It keeps a
|
|
3
|
+
box while closed, invisible, so the lift can measure where it belongs. */
|
|
4
|
+
.lc-hovercard__content {
|
|
5
|
+
position: absolute;
|
|
6
|
+
inset-block-start: calc(100% + var(--spacing-related));
|
|
7
|
+
inset-inline-start: 0;
|
|
8
|
+
z-index: var(--lc-z-popover);
|
|
9
|
+
display: flex;
|
|
10
|
+
flex-direction: column;
|
|
11
|
+
inline-size: min(20rem, calc(100vw - 2rem));
|
|
12
|
+
overflow: visible;
|
|
13
|
+
margin: 0;
|
|
14
|
+
padding: var(--spacing-inset);
|
|
15
|
+
color: var(--popover-foreground);
|
|
16
|
+
text-align: start;
|
|
17
|
+
white-space: normal;
|
|
18
|
+
pointer-events: none;
|
|
19
|
+
opacity: 0;
|
|
20
|
+
visibility: hidden;
|
|
21
|
+
transform: translateY(calc(var(--spacing) * -1)) scale(0.98);
|
|
22
|
+
|
|
23
|
+
/* allow-discrete keeps a lifted card in the top layer while it fades out. */
|
|
24
|
+
transition:
|
|
25
|
+
opacity 160ms var(--lc-ease-out-expo),
|
|
26
|
+
transform 160ms var(--lc-ease-out-expo),
|
|
27
|
+
visibility 160ms,
|
|
28
|
+
display 160ms allow-discrete,
|
|
29
|
+
overlay 160ms allow-discrete;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.lc-hovercard[data-side="top"] > .lc-hovercard__content {
|
|
33
|
+
inset-block: auto calc(100% + var(--spacing-related));
|
|
34
|
+
transform: translateY(var(--spacing)) scale(0.98);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.lc-hovercard[data-open] > .lc-hovercard__content {
|
|
38
|
+
pointer-events: auto;
|
|
39
|
+
opacity: 1;
|
|
40
|
+
visibility: visible;
|
|
41
|
+
transform: none;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@media (prefers-reduced-motion: reduce) {
|
|
45
|
+
.lc-hovercard__content { transform: none; }
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module Lostcoords::Ui
|
|
2
|
+
module HovercardHelper
|
|
3
|
+
HOVERCARD_SIDES = %i[bottom top].freeze
|
|
4
|
+
|
|
5
|
+
# A preview card for what a link points to, such as a profile over a name. It opens after a short
|
|
6
|
+
# hover or on keyboard focus and stays open while the pointer is on it.
|
|
7
|
+
#
|
|
8
|
+
# Yields attributes for the trigger; splat them with `**card` on the link. Pass the card as content:,
|
|
9
|
+
# or src: to load it as HTML from your endpoint the first time it opens, so a long list of triggers
|
|
10
|
+
# costs nothing until one is hovered. The card is a preview: it is hidden from assistive technology
|
|
11
|
+
# and its links are out of the tab order, so everything in it must also be reachable from the page
|
|
12
|
+
# the trigger opens. Inside a paragraph, keep content: to phrasing elements such as spans; HTML that
|
|
13
|
+
# src: loads can hold anything.
|
|
14
|
+
def lc_hovercard(src: nil, content: nil, side: :bottom, **attributes, &block)
|
|
15
|
+
raise ArgumentError, "Pass src: or content:, not both" if src && content
|
|
16
|
+
raise ArgumentError, "Pass src: or content:" unless src || content
|
|
17
|
+
raise ArgumentError, "lc_hovercard needs a block that renders its trigger" unless block
|
|
18
|
+
lc_label!(src, :src) if src
|
|
19
|
+
side = lc_option!(:side, side, HOVERCARD_SIDES)
|
|
20
|
+
trigger = capture({ data: { lc_hovercard_target: "trigger" } }, &block)
|
|
21
|
+
body = content || tag.span(class: "flex flex-col gap-related", data: { slot: "hovercard-loading" }) do
|
|
22
|
+
safe_join([ lc_skeleton(class: "h-10 w-10 rounded-full"), lc_skeleton, lc_skeleton(class: "h-4 w-2/3") ])
|
|
23
|
+
end
|
|
24
|
+
data = { slot: "hovercard", side: side, controller: "lc-hovercard", lc_hovercard_src_value: src,
|
|
25
|
+
action: "mouseenter->lc-hovercard#enter focusin->lc-hovercard#enter mouseleave->lc-hovercard#leave focusout->lc-hovercard#leave" }.compact
|
|
26
|
+
tag.span(**lc_attributes({ class: "lc-hovercard relative inline-flex min-w-0", data: data }, attributes)) do
|
|
27
|
+
safe_join([ trigger, tag.span(body, class: lc_glass_class(shape: :menu, extra: "lc-hovercard__content lc-squircle"), aria: { hidden: true }, data: { slot: "hovercard-content", lc_hovercard_target: "content", loaded: (true unless src) }) ])
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Controller } from "@hotwired/stimulus"
|
|
2
|
+
import { registerDismissable } from "lostcoords/ui/helpers/dismiss_stack"
|
|
3
|
+
import { liftToTopLayer, onPageLeave } from "lostcoords/ui/helpers/top_layer"
|
|
4
|
+
|
|
5
|
+
const OPEN_DELAY = 450
|
|
6
|
+
const CLOSE_DELAY = 200
|
|
7
|
+
|
|
8
|
+
// Opens a preview card after a short hover, or at once on keyboard focus, in
|
|
9
|
+
// the top layer beside its trigger. With a src it loads the card's HTML the
|
|
10
|
+
// first time it opens. The pointer can cross the gap to the card and stay on
|
|
11
|
+
// it; leaving both closes it after a moment, and Escape closes it at once.
|
|
12
|
+
// Touch screens never open it: a tap follows the link.
|
|
13
|
+
export default class extends Controller {
|
|
14
|
+
static targets = ["trigger", "content"]
|
|
15
|
+
static values = { src: String }
|
|
16
|
+
|
|
17
|
+
connect() {
|
|
18
|
+
this.stopPageLeave = onPageLeave(() => this.close({ immediate: true }))
|
|
19
|
+
this.untab()
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
disconnect() {
|
|
23
|
+
this.stopPageLeave?.()
|
|
24
|
+
this.cancelTimers()
|
|
25
|
+
this.close({ immediate: true })
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
enter(event) {
|
|
29
|
+
if (event.type === "focusin" && !event.target.matches(":focus-visible")) return
|
|
30
|
+
if (event.type === "mouseenter" && !matchMedia("(hover: hover)").matches) return
|
|
31
|
+
clearTimeout(this.closing)
|
|
32
|
+
if (this.release || this.opening) return
|
|
33
|
+
this.opening = setTimeout(() => this.open(), event.type === "focusin" ? 0 : OPEN_DELAY)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
leave() {
|
|
37
|
+
clearTimeout(this.opening)
|
|
38
|
+
this.opening = null
|
|
39
|
+
this.closing = setTimeout(() => {
|
|
40
|
+
if (this.element.matches(":hover") || this.element.querySelector(":focus-visible")) return
|
|
41
|
+
this.close()
|
|
42
|
+
}, CLOSE_DELAY)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async open() {
|
|
46
|
+
this.opening = null
|
|
47
|
+
if (this.release || !this.element.isConnected) return
|
|
48
|
+
if (!this.contentTarget.hasAttribute("data-loaded") && this.hasSrcValue && this.srcValue) {
|
|
49
|
+
this.loading ??= this.load().finally(() => (this.loading = null))
|
|
50
|
+
if (!(await this.loading) || this.release) return
|
|
51
|
+
if (!this.element.matches(":hover") && !this.element.querySelector(":focus-visible")) return
|
|
52
|
+
}
|
|
53
|
+
this.element.toggleAttribute("data-open", true)
|
|
54
|
+
this.release = liftToTopLayer(this.contentTarget, this.triggerTarget)
|
|
55
|
+
this.unregister = registerDismissable({
|
|
56
|
+
type: "hovercard",
|
|
57
|
+
element: this.element,
|
|
58
|
+
isOpen: () => this.element.hasAttribute("data-open"),
|
|
59
|
+
close: () => this.close({ immediate: true }),
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Only the page's own origin can fill the card.
|
|
64
|
+
async load() {
|
|
65
|
+
const url = new URL(this.srcValue, window.location.href)
|
|
66
|
+
if (url.origin !== window.location.origin) return false
|
|
67
|
+
try {
|
|
68
|
+
const response = await fetch(url, {
|
|
69
|
+
headers: { Accept: "text/html", "X-Requested-With": "XMLHttpRequest" },
|
|
70
|
+
credentials: "same-origin",
|
|
71
|
+
})
|
|
72
|
+
if (!response.ok) return false
|
|
73
|
+
this.contentTarget.innerHTML = await response.text()
|
|
74
|
+
this.untab()
|
|
75
|
+
this.contentTarget.toggleAttribute("data-loaded", true)
|
|
76
|
+
return true
|
|
77
|
+
} catch {
|
|
78
|
+
return false
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// The card is a preview: its links stay clickable but out of the tab order.
|
|
83
|
+
untab() {
|
|
84
|
+
for (const element of this.contentTarget.querySelectorAll(
|
|
85
|
+
"a, button, input, select, textarea, [tabindex]",
|
|
86
|
+
)) {
|
|
87
|
+
element.setAttribute("tabindex", "-1")
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
close({ immediate = false } = {}) {
|
|
92
|
+
this.element.toggleAttribute("data-open", false)
|
|
93
|
+
this.release?.({ immediate })
|
|
94
|
+
this.release = null
|
|
95
|
+
this.unregister?.()
|
|
96
|
+
this.unregister = null
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
cancelTimers() {
|
|
100
|
+
clearTimeout(this.opening)
|
|
101
|
+
clearTimeout(this.closing)
|
|
102
|
+
this.opening = null
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -130,7 +130,7 @@ function defaultIsOpen() {
|
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
function priorityFor(type) {
|
|
133
|
-
if (type === "tooltip") return 40
|
|
133
|
+
if (type === "tooltip" || type === "hovercard") return 40
|
|
134
134
|
if (type === "popover") return 30
|
|
135
135
|
if (type === "panel") return 20
|
|
136
136
|
return 10
|
|
@@ -6,6 +6,7 @@ import Copy from "lostcoords/ui/controllers/lc_copy_controller"
|
|
|
6
6
|
import Dialog from "lostcoords/ui/controllers/lc_dialog_controller"
|
|
7
7
|
import Dock from "lostcoords/ui/controllers/lc_dock_controller"
|
|
8
8
|
import EmojiPicker from "lostcoords/ui/controllers/lc_emoji_picker_controller"
|
|
9
|
+
import Hovercard from "lostcoords/ui/controllers/lc_hovercard_controller"
|
|
9
10
|
import Kbd from "lostcoords/ui/controllers/lc_kbd_controller"
|
|
10
11
|
import Menu from "lostcoords/ui/controllers/lc_menu_controller"
|
|
11
12
|
import Nav from "lostcoords/ui/controllers/lc_nav_controller"
|
|
@@ -32,6 +33,7 @@ const controllers = {
|
|
|
32
33
|
"lc-dialog": Dialog,
|
|
33
34
|
"lc-dock": Dock,
|
|
34
35
|
"lc-emoji-picker": EmojiPicker,
|
|
36
|
+
"lc-hovercard": Hovercard,
|
|
35
37
|
"lc-kbd": Kbd,
|
|
36
38
|
"lc-menu": Menu,
|
|
37
39
|
"lc-nav": Nav,
|
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.11.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Lost Coordinates
|
|
@@ -96,6 +96,7 @@ files:
|
|
|
96
96
|
- app/assets/tailwind/lostcoords/ui/components/collapsible.css
|
|
97
97
|
- app/assets/tailwind/lostcoords/ui/components/dialog.css
|
|
98
98
|
- app/assets/tailwind/lostcoords/ui/components/emoji-picker.css
|
|
99
|
+
- app/assets/tailwind/lostcoords/ui/components/hovercard.css
|
|
99
100
|
- app/assets/tailwind/lostcoords/ui/components/menu.css
|
|
100
101
|
- app/assets/tailwind/lostcoords/ui/components/prose.css
|
|
101
102
|
- app/assets/tailwind/lostcoords/ui/components/search.css
|
|
@@ -109,6 +110,7 @@ files:
|
|
|
109
110
|
- app/assets/tailwind/lostcoords/ui/emoji-picker.css
|
|
110
111
|
- app/assets/tailwind/lostcoords/ui/field.css
|
|
111
112
|
- app/assets/tailwind/lostcoords/ui/glass.css
|
|
113
|
+
- app/assets/tailwind/lostcoords/ui/hovercard.css
|
|
112
114
|
- app/assets/tailwind/lostcoords/ui/layout.css
|
|
113
115
|
- app/assets/tailwind/lostcoords/ui/popover.css
|
|
114
116
|
- app/assets/tailwind/lostcoords/ui/prose.css
|
|
@@ -138,6 +140,7 @@ files:
|
|
|
138
140
|
- app/helpers/lostcoords/ui/feedback_helper.rb
|
|
139
141
|
- app/helpers/lostcoords/ui/form_helper.rb
|
|
140
142
|
- app/helpers/lostcoords/ui/glass_helper.rb
|
|
143
|
+
- app/helpers/lostcoords/ui/hovercard_helper.rb
|
|
141
144
|
- app/helpers/lostcoords/ui/icon_helper.rb
|
|
142
145
|
- app/helpers/lostcoords/ui/layout_helper.rb
|
|
143
146
|
- app/helpers/lostcoords/ui/list_group_helper.rb
|
|
@@ -164,6 +167,7 @@ files:
|
|
|
164
167
|
- app/javascript/lostcoords/ui/controllers/lc_dialog_controller.js
|
|
165
168
|
- app/javascript/lostcoords/ui/controllers/lc_dock_controller.js
|
|
166
169
|
- app/javascript/lostcoords/ui/controllers/lc_emoji_picker_controller.js
|
|
170
|
+
- app/javascript/lostcoords/ui/controllers/lc_hovercard_controller.js
|
|
167
171
|
- app/javascript/lostcoords/ui/controllers/lc_kbd_controller.js
|
|
168
172
|
- app/javascript/lostcoords/ui/controllers/lc_menu_controller.js
|
|
169
173
|
- app/javascript/lostcoords/ui/controllers/lc_nav_controller.js
|