lostcoords-ui 0.9.1 → 0.9.3
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 +10 -4
- data/app/assets/tailwind/lostcoords/ui/base.css +1 -0
- data/app/assets/tailwind/lostcoords/ui/theme.css +65 -39
- data/app/helpers/lostcoords/ui/list_group_helper.rb +21 -6
- data/app/helpers/lostcoords/ui/primitives_helper.rb +17 -6
- data/app/helpers/lostcoords/ui/tooltip_helper.rb +5 -4
- data/lib/lostcoords/ui/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d402851fc66b028bc97b880c2397d3c8a2d612284d0f51ddec90e6ba3a0ee2bb
|
|
4
|
+
data.tar.gz: 2d5856ffb98d6bc1326a6270237fc31c0fb8dffd6f6581a4c53830a97c042a40
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0f0d50a8f0baf942139ab75986fbe8b4316926e74d86ca5a5c88f0401828c809ad4479ee9035befd70d38e1195c4da293c4629f25d06d4d3a05ef75399fbe373
|
|
7
|
+
data.tar.gz: 5300070c7fa90987821000e3a7494d76a66e1e462c0ca0a169804137d14be1cb6ecdd4eab1658dff5a2172ae9473022e1582b87ca05a4dda626cd32c957f3361
|
data/README.md
CHANGED
|
@@ -61,13 +61,13 @@ toggles, layout, typography and navigation. The opt-in entries are `dialog` (wit
|
|
|
61
61
|
menu also needs `menu`). A component whose entry is missing renders unstyled.
|
|
62
62
|
|
|
63
63
|
The gem's stylesheets write into the `components` and `modules` layers, so the host declares that layer order.
|
|
64
|
-
The theme defines the `dark:` variant with `html[data-theme="dark"]
|
|
64
|
+
The theme defines the `dark:` variant with `html[data-theme="dark"]`, and with `html[data-theme="system"]` under an OS dark preference. Each entry carries its own `@source` lines, so Tailwind
|
|
65
65
|
scans the gem's helpers, views and JavaScript wherever the gem is installed.
|
|
66
66
|
|
|
67
67
|
### Theming
|
|
68
68
|
|
|
69
69
|
Colors use [shadcn/ui](https://ui.shadcn.com/docs/theming) names, so a shadcn or tweakcn theme drops in.
|
|
70
|
-
Set `data-theme="dark"` on `<html>` for dark mode
|
|
70
|
+
Set `data-theme="dark"` on `<html>` for dark mode, or `data-theme="system"` to follow the OS with no pre-paint script, which keeps cached HTML theme-agnostic. Your app owns the switch and saved preference. A dark override written for `html[data-theme="dark"]` does not reach `system`: use `light-dark()` for colors, or repeat it under `@media (prefers-color-scheme: dark)`.
|
|
71
71
|
Override any of these after the engine import:
|
|
72
72
|
|
|
73
73
|
```css
|
|
@@ -405,7 +405,9 @@ makes the summary look like that `lc_button` without the native marker, and `ind
|
|
|
405
405
|
only the group's ends round. Rows are card surfaces, so fields and buttons in them follow
|
|
406
406
|
`--card-input` and `--card-secondary`. `lc_list_row` with a title lays out `icon:` (a name, or your own
|
|
407
407
|
markup such as a logo), the title, `subtitle:` and the block as trailing content; `tag:` makes it a
|
|
408
|
-
`label`, `li`, `details` or `a` (`href:`).
|
|
408
|
+
`label`, `li`, `details` or `a` (`href:`). `href:` with `tag: :li` or `:div` links the title instead
|
|
409
|
+
and stretches it over the row, so the block can hold buttons and links of its own; a click anywhere
|
|
410
|
+
else in the row follows the title. Without a title the block is the whole row, and
|
|
409
411
|
`padded: false` leaves the padding to content such as an `lc_list_item` button or summary, which lays
|
|
410
412
|
out the same icon, title and subtitle inside your own element. `lc_list_section` adds the heading and
|
|
411
413
|
footnote; with an `id:`, the heading labels the section. Put a form around `lc_list_group` inside it
|
|
@@ -507,6 +509,8 @@ Text that labels something other than one control, such as a list, uses `lc_text
|
|
|
507
509
|
<%= lc_icon_button "Copy link", icon: "link", **tip %>
|
|
508
510
|
<% end %>
|
|
509
511
|
|
|
512
|
+
<%= lc_icon_button "Stop", icon: "stop", tooltip: true %>
|
|
513
|
+
|
|
510
514
|
<%= lc_description_list do |list| %>
|
|
511
515
|
<%= list.item "Owner", @project.owner.name %>
|
|
512
516
|
<%= list.item("Plan") { lc_badge @project.plan } %>
|
|
@@ -515,7 +519,9 @@ Text that labels something other than one control, such as a list, uses `lc_text
|
|
|
515
519
|
|
|
516
520
|
Tabs follow the ARIA tabs pattern with arrow key, Home and End navigation, and dispatch
|
|
517
521
|
`lc-tabs:change`. `orientation: :vertical` stacks the tabs beside their panels and moves with Arrow Up
|
|
518
|
-
and Down; `activation: :manual` moves focus with the arrows and selects with Enter or Space; `list:` adds attributes to the tab list.
|
|
522
|
+
and Down; `activation: :manual` moves focus with the arrows and selects with Enter or Space; `list:` adds attributes to the tab list. Icon buttons take `tooltip: true` to show their label, or `tooltip: "text"` to describe themselves
|
|
523
|
+
with other text. A tooltip without an `id:` repeats its trigger's label and stays hidden from
|
|
524
|
+
assistive technology. Tooltips show on hover and keyboard focus, Escape hides them, and they describe
|
|
519
525
|
their trigger, in the top layer; keep essential information visible. Description lists stack on phones and use two
|
|
520
526
|
columns from `sm`.
|
|
521
527
|
|
|
@@ -109,7 +109,31 @@
|
|
|
109
109
|
--container-form: 32rem;
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
|
|
112
|
+
/* data-theme="system" follows the OS, for a host that leaves the choice unresolved in cached HTML. */
|
|
113
|
+
@custom-variant dark {
|
|
114
|
+
&:where(html[data-theme="dark"], html[data-theme="dark"] *) {
|
|
115
|
+
@slot;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
@media (prefers-color-scheme: dark) {
|
|
119
|
+
&:where(html[data-theme="system"], html[data-theme="system"] *) {
|
|
120
|
+
@slot;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/* The dark token block's own selector. A host may redefine `dark` to scope it; this one stays put. */
|
|
126
|
+
@custom-variant lc-dark-tokens {
|
|
127
|
+
&[data-theme="dark"] {
|
|
128
|
+
@slot;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
@media (prefers-color-scheme: dark) {
|
|
132
|
+
&[data-theme="system"] {
|
|
133
|
+
@slot;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
113
137
|
|
|
114
138
|
@layer theme {
|
|
115
139
|
:root {
|
|
@@ -213,44 +237,46 @@
|
|
|
213
237
|
}
|
|
214
238
|
}
|
|
215
239
|
|
|
216
|
-
html
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
240
|
+
html {
|
|
241
|
+
@variant lc-dark-tokens {
|
|
242
|
+
--background: oklch(20.5% 0 0deg);
|
|
243
|
+
--foreground: oklch(91.5% 0 0deg);
|
|
244
|
+
--primary: oklch(91.5% 0 0deg);
|
|
245
|
+
--primary-foreground: var(--background);
|
|
246
|
+
--muted: oklch(24.2% 0 0deg);
|
|
247
|
+
--muted-foreground: color-mix(in oklab, var(--foreground) 76%, var(--background));
|
|
248
|
+
--accent: oklch(28.4% 0 0deg);
|
|
249
|
+
--destructive: oklch(78% 0.120 41.4deg);
|
|
250
|
+
--success: oklch(78% 0.089 144.3deg);
|
|
251
|
+
--warning: oklch(80% 0.110 86deg);
|
|
252
|
+
--border: color-mix(in oklab, var(--foreground) 16%, transparent);
|
|
253
|
+
|
|
254
|
+
--lc-scrim: rgb(0 0 0 / 0.6);
|
|
255
|
+
--lc-scrim-soft: rgb(0 0 0 / 0.32);
|
|
256
|
+
--lc-scrim-veil: rgb(0 0 0 / 0.4);
|
|
257
|
+
|
|
258
|
+
--lc-shadow-sm: 0 1px 2px rgb(0 0 0 / 0.2);
|
|
259
|
+
--lc-shadow:
|
|
260
|
+
0 1px 2px rgb(0 0 0 / 0.16),
|
|
261
|
+
0 8px 24px -8px rgb(0 0 0 / 0.32);
|
|
262
|
+
--lc-shadow-lg:
|
|
263
|
+
0 1px 3px rgb(0 0 0 / 0.2),
|
|
264
|
+
0 24px 48px -12px rgb(0 0 0 / 0.55);
|
|
265
|
+
|
|
266
|
+
--lc-glass-fill: color-mix(in oklab, var(--background) 80%, transparent);
|
|
267
|
+
--lc-glass-edge: transparent;
|
|
268
|
+
--lc-glass-rim: 0 0 #0000;
|
|
269
|
+
--lc-glass-bar-edge: rgb(255 255 255 / 0.06);
|
|
270
|
+
--lc-glass-shadow: 0 1px 3px rgb(0 0 0 / 0.04), 0 4px 12px rgb(0 0 0 / 0.03);
|
|
271
|
+
--lc-glass-hud-fill:
|
|
272
|
+
linear-gradient(rgb(255 255 255 / 0.06), rgb(255 255 255 / 0) 60%),
|
|
273
|
+
color-mix(in oklab, var(--accent) 90%, transparent);
|
|
274
|
+
--lc-glass-hud-solid: var(--accent);
|
|
275
|
+
--lc-glass-hud-shadow:
|
|
276
|
+
inset 0 1px 0 rgb(255 255 255 / 0.1),
|
|
277
|
+
inset 0 0 0 1px rgb(255 255 255 / 0.1),
|
|
278
|
+
0 8px 20px -8px rgb(0 0 0 / 0.6);
|
|
279
|
+
}
|
|
254
280
|
}
|
|
255
281
|
|
|
256
282
|
html:lang(ja) { --font-sans: var(--font-japanese); }
|
|
@@ -5,6 +5,15 @@ module Lostcoords::Ui
|
|
|
5
5
|
LIST_ROW_PADDING = "px-content py-heading sm:px-inset"
|
|
6
6
|
LIST_ICON = "grid size-10 shrink-0 place-items-center rounded-full bg-tile [&>svg:not([class*='size-'])]:size-4.5"
|
|
7
7
|
LIST_ROW_TAGS = %i[div li label details a].freeze
|
|
8
|
+
LIST_ROW_HOVER = "transition-colors duration-(--lc-motion-quick) hover:bg-accent"
|
|
9
|
+
# A linked li or div row: the title's link covers the row, the row's own controls sit above it,
|
|
10
|
+
# and the row shows the link's focus ring.
|
|
11
|
+
LIST_ROW_LINKED =
|
|
12
|
+
"relative has-[[data-slot=list-link]:focus-visible]:outline-2 has-[[data-slot=list-link]:focus-visible]:outline-offset-2 " \
|
|
13
|
+
"has-[[data-slot=list-link]:focus-visible]:outline-(--ring,color-mix(in_oklab,var(--primary)_50%,transparent)) " \
|
|
14
|
+
"[&_:is(a[href],button,input,select,textarea,summary,[tabindex]):not([data-slot=list-link])]:relative " \
|
|
15
|
+
"[&_:is(a[href],button,input,select,textarea,summary,[tabindex]):not([data-slot=list-link])]:z-raised"
|
|
16
|
+
LIST_LINK = "text-inherit no-underline focus-visible:outline-none after:absolute after:inset-0 after:rounded-[inherit] after:content-['']"
|
|
8
17
|
LIST_FIELD_TAGS = %i[div fieldset span].freeze
|
|
9
18
|
LIST_FIELD = "@container px-content py-2.5 transition-colors duration-(--lc-motion-quick) has-[[data-plain]:focus]:bg-accent"
|
|
10
19
|
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)]"
|
|
@@ -37,14 +46,18 @@ module Lostcoords::Ui
|
|
|
37
46
|
|
|
38
47
|
# With a title, the row lays out icon:, the title and subtitle, then the block as its trailing
|
|
39
48
|
# content. Without one, the block is the whole row; padded: false drops the row's padding for
|
|
40
|
-
# content that pads itself, such as an lc_list_item button. href: makes the row a link.
|
|
49
|
+
# content that pads itself, such as an lc_list_item button. href: makes the row a link. On an li
|
|
50
|
+
# or div row, the title is the link and covers the row, so the block can hold buttons and links
|
|
51
|
+
# of its own; a click elsewhere in the row follows the title.
|
|
41
52
|
def lc_list_row(title = nil, subtitle: nil, icon: nil, href: nil, tag: nil, padded: true, **attributes, &block)
|
|
42
53
|
tag = lc_option!(:tag, tag || (href ? :a : :div), LIST_ROW_TAGS)
|
|
43
|
-
|
|
54
|
+
titled = href && tag != :a
|
|
55
|
+
raise ArgumentError, "href: needs tag: :a, :li or :div" if titled && !%i[li div].include?(tag)
|
|
56
|
+
raise ArgumentError, "href: on an li or div row links its title, so it needs one" if titled && title.blank?
|
|
44
57
|
|
|
45
|
-
link = (
|
|
46
|
-
defaults = { href: href, data: { slot: "list-row" } }
|
|
47
|
-
return lc_list_item(title, subtitle: subtitle, icon: icon, tag: tag, **lc_attributes(defaults.merge(class: lc_tw(LIST_ROW, link)), attributes), &block) if title.present?
|
|
58
|
+
link = (titled ? lc_tw(LIST_ROW_HOVER, LIST_ROW_LINKED) : lc_tw("no-underline", LIST_ROW_HOVER)) if href
|
|
59
|
+
defaults = { href: (href unless titled), data: { slot: "list-row" } }
|
|
60
|
+
return lc_list_item(title, subtitle: subtitle, icon: icon, link: (href if titled), tag: tag, **lc_attributes(defaults.merge(class: lc_tw(LIST_ROW, link)), attributes), &block) if title.present?
|
|
48
61
|
|
|
49
62
|
classes = lc_tw(LIST_ROW, (LIST_ROW_PADDING if padded), link)
|
|
50
63
|
content_tag(tag, (capture(&block) if block), **lc_attributes(defaults.merge(class: classes), attributes))
|
|
@@ -76,9 +89,11 @@ module Lostcoords::Ui
|
|
|
76
89
|
|
|
77
90
|
# The row layout without the row's surface, for an element inside a free-form row: a summary, a
|
|
78
91
|
# button that opens an editor. icon: takes an icon name or your own markup, such as a logo.
|
|
79
|
-
|
|
92
|
+
# link: links the title to that URL and stretches the link over the nearest positioned ancestor.
|
|
93
|
+
def lc_list_item(title, subtitle: nil, icon: nil, link: nil, tag: :div, **attributes, &block)
|
|
80
94
|
lc_label!(title, :title)
|
|
81
95
|
glyph = icon.is_a?(ActiveSupport::SafeBuffer) ? icon : lc_icon(icon) if icon.present?
|
|
96
|
+
title = link_to(title, link, class: LIST_LINK, data: { slot: "list-link" }) if link
|
|
82
97
|
content_tag(tag, **lc_attributes({ class: LIST_ITEM, data: { slot: "list-item" } }, attributes)) do
|
|
83
98
|
text = safe_join([
|
|
84
99
|
content_tag(:span, title, class: "font-semibold", data: { slot: "list-title" }),
|
|
@@ -86,20 +86,21 @@ module Lostcoords::Ui
|
|
|
86
86
|
tag.div(safe_join([ primary, toggle, popover ]), **lc_attributes(defaults, attributes))
|
|
87
87
|
end
|
|
88
88
|
|
|
89
|
-
def lc_icon_button(label, icon: nil, size: :md, shape: :circle, variant: :ghost, tone: :default, **attributes, &content)
|
|
89
|
+
def lc_icon_button(label, icon: nil, size: :md, shape: :circle, variant: :ghost, tone: :default, tooltip: nil, **attributes, &content)
|
|
90
90
|
attributes = lc_icon_button_attributes(label, size, shape, variant, tone, { type: "button" }, attributes)
|
|
91
|
-
tag.button(lc_icon_button_content(icon, &content), **attributes)
|
|
91
|
+
lc_icon_button_tooltip(label, tooltip, attributes) { |tip| tag.button(lc_icon_button_content(icon, &content), **lc_attributes(attributes, tip)) }
|
|
92
92
|
end
|
|
93
93
|
|
|
94
|
-
def lc_icon_button_link_to(label, url, icon: nil, size: :md, shape: :circle, variant: :ghost, tone: :default, **attributes, &content)
|
|
94
|
+
def lc_icon_button_link_to(label, url, icon: nil, size: :md, shape: :circle, variant: :ghost, tone: :default, tooltip: nil, **attributes, &content)
|
|
95
95
|
attributes = lc_icon_button_attributes(label, size, shape, variant, tone, {}, attributes)
|
|
96
96
|
raise ArgumentError, "Links cannot be disabled; use lc_icon_button for a disabled control" if attributes[:disabled]
|
|
97
97
|
|
|
98
|
-
link_to(lc_icon_button_content(icon, &content), url, attributes)
|
|
98
|
+
lc_icon_button_tooltip(label, tooltip, attributes) { |tip| link_to(lc_icon_button_content(icon, &content), url, lc_attributes(attributes, tip)) }
|
|
99
99
|
end
|
|
100
100
|
|
|
101
|
-
def lc_icon_button_to(label, url, icon: nil, size: :md, shape: :circle, variant: :ghost, tone: :default, **attributes, &content)
|
|
102
|
-
|
|
101
|
+
def lc_icon_button_to(label, url, icon: nil, size: :md, shape: :circle, variant: :ghost, tone: :default, tooltip: nil, **attributes, &content)
|
|
102
|
+
attributes = lc_icon_button_attributes(label, size, shape, variant, tone, {}, attributes)
|
|
103
|
+
lc_icon_button_tooltip(label, tooltip, attributes) { |tip| button_to(lc_icon_button_content(icon, &content), url, lc_attributes(attributes, tip)) }
|
|
103
104
|
end
|
|
104
105
|
|
|
105
106
|
def lc_badge(content = nil, tone: :neutral, shape: :rounded, **attributes, &block)
|
|
@@ -215,6 +216,16 @@ module Lostcoords::Ui
|
|
|
215
216
|
attributes
|
|
216
217
|
end
|
|
217
218
|
|
|
219
|
+
# tooltip: true shows the label on hover and keyboard focus; a string shows that text instead,
|
|
220
|
+
# and describes the button with it.
|
|
221
|
+
def lc_icon_button_tooltip(label, tooltip, attributes)
|
|
222
|
+
return yield({}) if tooltip.nil? || tooltip == false
|
|
223
|
+
|
|
224
|
+
text = tooltip == true ? label : tooltip
|
|
225
|
+
id = ("#{attributes[:id] || "lc-icon-button-#{@lc_tooltip_count = (@lc_tooltip_count || 0) + 1}"}-tooltip" unless text == label)
|
|
226
|
+
lc_tooltip(text, id: id) { |tip| yield(tip) }
|
|
227
|
+
end
|
|
228
|
+
|
|
218
229
|
def lc_icon_button_content(icon, &content)
|
|
219
230
|
raise ArgumentError, "Pass icon: or a block" unless icon || content
|
|
220
231
|
|
|
@@ -3,14 +3,15 @@ module Lostcoords::Ui
|
|
|
3
3
|
TOOLTIP_SIDES = %i[top bottom].freeze
|
|
4
4
|
|
|
5
5
|
# Yields attributes for the trigger; splat them with `**tip` so the trigger is described by the tooltip.
|
|
6
|
+
# Leave out id: when the tooltip repeats the trigger's own label, so it is not read twice.
|
|
6
7
|
# The tooltip shows on hover and keyboard focus, and Escape hides it. It is a hint: keep essential information visible.
|
|
7
|
-
def lc_tooltip(text, id
|
|
8
|
+
def lc_tooltip(text, id: nil, side: :top, **attributes, &block)
|
|
8
9
|
lc_label!(text, :text)
|
|
9
|
-
lc_label!(id, :id)
|
|
10
|
+
lc_label!(id, :id) unless id.nil?
|
|
10
11
|
side = lc_option!(:side, side, TOOLTIP_SIDES)
|
|
11
|
-
trigger = capture({ aria: { describedby: id } }, &block) if block
|
|
12
|
+
trigger = capture(id ? { aria: { describedby: id } } : {}, &block) if block
|
|
12
13
|
tag.span(**lc_attributes({ class: "lc-tooltip relative inline-flex", data: { slot: "tooltip", side: side, controller: "lc-tooltip", action: "mouseenter->lc-tooltip#show focusin->lc-tooltip#show mouseleave->lc-tooltip#hide focusout->lc-tooltip#hide" } }, attributes)) do
|
|
13
|
-
safe_join([ trigger, tag.span(text, id: id, role: "tooltip", class: "lc-tooltip__content", data: { slot: "tooltip-content", lc_tooltip_target: "content" }) ].compact)
|
|
14
|
+
safe_join([ trigger, tag.span(text, id: id, role: ("tooltip" if id), aria: { hidden: ("true" unless id) }, class: "lc-tooltip__content", data: { slot: "tooltip-content", lc_tooltip_target: "content" }) ].compact)
|
|
14
15
|
end
|
|
15
16
|
end
|
|
16
17
|
end
|