lostcoords-ui 0.8.1 → 0.9.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 +124 -66
- data/app/assets/tailwind/lostcoords/ui/components/shell.css +4 -0
- data/app/assets/tailwind/lostcoords/ui/components.css +1 -0
- data/app/assets/tailwind/lostcoords/ui/core.css +1 -1
- data/app/assets/tailwind/lostcoords/ui/dialog.css +3 -0
- data/app/assets/tailwind/lostcoords/ui/prose.css +9 -0
- data/app/assets/tailwind/lostcoords/ui/shell.css +161 -0
- data/app/assets/tailwind/lostcoords/ui/typography.css +26 -0
- data/app/helpers/lostcoords/ui/emoji_picker_helper.rb +8 -5
- data/app/helpers/lostcoords/ui/layout_helper.rb +5 -3
- data/app/helpers/lostcoords/ui/navigation_helper.rb +29 -0
- data/app/helpers/lostcoords/ui/reading_helper.rb +23 -2
- data/app/helpers/lostcoords/ui/shell_helper.rb +64 -0
- data/app/helpers/lostcoords/ui/translation_helper.rb +1 -5
- data/app/helpers/lostcoords/ui/typography_helper.rb +9 -2
- data/app/javascript/lostcoords/ui/controllers/lc_app_header_controller.js +15 -0
- data/app/javascript/lostcoords/ui/controllers/lc_dock_controller.js +21 -0
- data/app/javascript/lostcoords/ui/controllers/lc_nav_controller.js +13 -7
- data/app/javascript/lostcoords/ui/controllers/lc_scroll_keeper_controller.js +53 -0
- data/app/javascript/lostcoords/ui/controllers/lc_toc_controller.js +96 -0
- data/app/javascript/lostcoords/ui/index.js +8 -0
- data/config/locales/en.yml +9 -0
- data/config/locales/es.yml +9 -0
- data/config/locales/ja.yml +9 -0
- data/lib/lostcoords/ui/helpers.rb +1 -1
- data/lib/lostcoords/ui/icons.rb +1 -1
- data/lib/lostcoords/ui/parts.rb +87 -0
- data/lib/lostcoords/ui/version.rb +1 -1
- data/lib/lostcoords/ui.rb +12 -2
- data/lib/tasks/lostcoords_ui.rake +0 -1
- metadata +10 -6
- data/lib/lostcoords/ui/action_view.rb +0 -13
- data/lib/lostcoords/ui/rails.rb +0 -3
- data/lib/lostcoords/ui/resources.rb +0 -17
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6c7fa09422f0fbfb2b1e2caa70338f1c842d12d900097efe8d9577c610041e46
|
|
4
|
+
data.tar.gz: 1b366575265b9d3662710ec2131fe7bfe64e7b2afcce0662d222189643aa1fbd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 27d701fa2951f3a60871a013ef2618a6dfb09ee9f932bf93b91b3aaae85371c349345e10fbfdfb92c6645e3b24769b2d8c4c55dd144389a05ee4a7cf41f69116
|
|
7
|
+
data.tar.gz: a1ca746f2c919e114d2a0dbf5995704cacc6389eec9b545c9b26bf3055dd1b8803d03a8adb689dda3463dac5cea925aa81934f61e441d24ff943366167100490
|
data/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# lostcoords-ui
|
|
2
2
|
|
|
3
|
-
Render complete UI components from Rails
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
Render complete UI components from Rails views. Helpers include semantic HTML, accessible attributes and
|
|
4
|
+
Stimulus wiring. Tailwind v4 supplies the styles. The Rails engine integrates Propshaft, importmap and
|
|
5
|
+
`tailwindcss-rails`.
|
|
6
6
|
|
|
7
7
|
```erb
|
|
8
8
|
<%= lc_button "Save changes", type: :submit, icon: "check" %>
|
|
@@ -15,52 +15,33 @@ and importmap automatically; standalone applications own their asset build.
|
|
|
15
15
|
<% end %>
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
The supported stack is
|
|
19
|
-
its gem version, so publishing a library update does not upgrade consumers.
|
|
18
|
+
The supported stack is Rails 8 or later with ERB, Tailwind and Stimulus. Each host application's
|
|
19
|
+
lockfile pins its gem version, so publishing a library update does not upgrade consumers.
|
|
20
20
|
|
|
21
21
|
## Install
|
|
22
22
|
|
|
23
23
|
```ruby
|
|
24
|
-
gem "lostcoords-ui", "~> 0.
|
|
24
|
+
gem "lostcoords-ui", "~> 0.9.0"
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
The engine adds its rendering helpers to host views, its
|
|
28
|
-
the importmap. Translations live under
|
|
27
|
+
The engine adds its rendering helpers to host views, its views and translations to the host's lookup
|
|
28
|
+
paths, its JavaScript to the asset paths and its pins to the importmap. Translations live under
|
|
29
|
+
`lostcoords.ui.*`; a host locale file overrides any of them.
|
|
29
30
|
|
|
30
|
-
###
|
|
31
|
+
### Stylesheets
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
class ViewContext < ActionView::Base
|
|
36
|
-
include Lostcoords::Ui::Helpers
|
|
37
|
-
end
|
|
33
|
+
Import the engine's stylesheet after your Tailwind imports. `tailwindcss-rails` generates this path from
|
|
34
|
+
the installed gem on every build:
|
|
38
35
|
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
```css
|
|
37
|
+
/* app/assets/tailwind/application.css */
|
|
38
|
+
@import "../builds/tailwind/lostcoords_ui.css";
|
|
41
39
|
```
|
|
42
40
|
|
|
43
|
-
For an existing view context, include the helpers and append `Lostcoords::Ui.view_paths` to its
|
|
44
|
-
lookup paths after application paths. The loader registers the library's translations without changing
|
|
45
|
-
the default locale. If the host has its own locale handling, override private `lc_locale` in the view
|
|
46
|
-
context; components do not call the host's `t` helper.
|
|
47
|
-
|
|
48
|
-
Standalone applications compile Tailwind and register Stimulus controllers through their own asset
|
|
49
|
-
pipeline. `Lostcoords::Ui.root` locates the gem's source assets. Rails applications receive automatic
|
|
50
|
-
registration; use `require "lostcoords/ui/rails"` explicitly if Rails loads after the components.
|
|
51
|
-
|
|
52
|
-
### Standalone assets
|
|
53
|
-
|
|
54
|
-
Import `app/assets/tailwind/lostcoords/ui/components.css` from the Bundler-resolved gem root
|
|
55
|
-
into your Tailwind build. This entry includes component rules, default tokens and source scanning.
|
|
56
|
-
It does not set body styles, heading defaults, global inline-code styles or document corner radii.
|
|
57
|
-
Map the library's tokens to your app's theme and keep your Tailwind theme declarations after the import.
|
|
58
|
-
The full `ui.css` entry includes those document defaults and remains the Rails default.
|
|
59
|
-
|
|
60
41
|
Tailwind always ships component rules, used or not, and generates every utility the scanned helpers
|
|
61
42
|
mention. For a smaller build, import `core.css` and the opt-in components you render instead of
|
|
62
|
-
everything. Each entry carries the rules and scans the sources of its own component only.
|
|
63
|
-
|
|
43
|
+
everything. Each entry carries the rules and scans the sources of its own component only. Every
|
|
44
|
+
Tailwind build writes stable paths for them next to the engine's own import:
|
|
64
45
|
|
|
65
46
|
```css
|
|
66
47
|
/* app/assets/tailwind/application.css, instead of ../builds/tailwind/lostcoords_ui.css */
|
|
@@ -70,34 +51,17 @@ every Tailwind build writes stable paths for them next to the engine's own impor
|
|
|
70
51
|
@import "../builds/tailwind/lostcoords_ui/components/menu.css";
|
|
71
52
|
```
|
|
72
53
|
|
|
73
|
-
|
|
74
|
-
|
|
54
|
+
`base.css` holds the document defaults: body styles, heading defaults, global inline-code styles and
|
|
55
|
+
document corner radii. Skip it when the host owns its base styles, map the library's tokens to your
|
|
56
|
+
app's theme and keep your Tailwind theme declarations after the imports.
|
|
75
57
|
`core.css` holds the tokens, buttons, badges, avatars, cards, alerts, form controls, choices,
|
|
76
58
|
toggles, layout, typography and navigation. The opt-in entries are `dialog` (with the phone sheet),
|
|
77
59
|
`menu` (menus and popovers), `toast`, `search`, `tooltip`, `collapsible`, `code-block`,
|
|
78
|
-
`emoji-picker`, `table` and `
|
|
79
|
-
|
|
80
|
-
Start one Stimulus application in the host, then register the controllers you use:
|
|
81
|
-
|
|
82
|
-
```javascript
|
|
83
|
-
import { Application } from "@hotwired/stimulus"
|
|
84
|
-
import { registerControllers } from "lostcoords/ui"
|
|
85
|
-
|
|
86
|
-
const application = Application.start()
|
|
87
|
-
registerControllers(application, { only: ["lc-copy", "lc-collapsible"] })
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
Resolve `lostcoords/ui/*` to the gem's `app/javascript/lostcoords/ui/*` and `@hotwired/stimulus` to
|
|
91
|
-
the host's installed package. `registerControllers` imports every controller, so a bundle carries
|
|
92
|
-
them all; to bundle only some, import them directly:
|
|
93
|
-
`import Dialog from "lostcoords/ui/controllers/lc_dialog_controller"` and
|
|
94
|
-
`application.register("lc-dialog", Dialog)`. Build configuration belongs to the host. The entry does not start
|
|
95
|
-
Stimulus or register anything on import. Omit `only` to register all library controllers. Register
|
|
96
|
-
defaults before application overrides. Repeated calls on the same application preserve later
|
|
97
|
-
overrides; unknown controller identifiers raise before registration.
|
|
60
|
+
`emoji-picker`, `table`, `prose` and `shell` (`lc_app_header`, `lc_docs_shell` and `lc_dock`; the dock's action
|
|
61
|
+
menu also needs `menu`). A component whose entry is missing renders unstyled.
|
|
98
62
|
|
|
99
63
|
The gem's stylesheets write into the `components` and `modules` layers, so the host declares that layer order.
|
|
100
|
-
The theme defines the `dark:` variant with `html[data-theme="dark"]`.
|
|
64
|
+
The theme defines the `dark:` variant with `html[data-theme="dark"]`. Each entry carries its own `@source` lines, so Tailwind
|
|
101
65
|
scans the gem's helpers, views and JavaScript wherever the gem is installed.
|
|
102
66
|
|
|
103
67
|
### Theming
|
|
@@ -194,6 +158,68 @@ lazyLoadControllersFrom("controllers", application)
|
|
|
194
158
|
`eagerLoadControllersFrom` also works and downloads all of them on every page. A host file with the
|
|
195
159
|
same name, such as `app/javascript/controllers/lc_dialog_controller.js`, replaces the gem's.
|
|
196
160
|
|
|
161
|
+
To register controllers by hand instead, import `registerControllers` from the `lostcoords/ui` pin:
|
|
162
|
+
|
|
163
|
+
```javascript
|
|
164
|
+
import { registerControllers } from "lostcoords/ui"
|
|
165
|
+
|
|
166
|
+
registerControllers(application, { only: ["lc-copy", "lc-collapsible"] })
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Omit `only` to register every library controller. Unknown identifiers raise before anything is
|
|
170
|
+
registered, and repeated calls on the same application keep later overrides, so register defaults
|
|
171
|
+
before application overrides.
|
|
172
|
+
|
|
173
|
+
## Changes in 0.9.0
|
|
174
|
+
|
|
175
|
+
The gem is Rails-only. It loads through its Rails engine, and the standalone ActionView mode is gone:
|
|
176
|
+
|
|
177
|
+
- **`require "lostcoords/ui/action_view"` and `require "lostcoords/ui/rails"` are removed.** Use
|
|
178
|
+
`require "lostcoords/ui"`, or let Bundler require the gem. Both load the engine.
|
|
179
|
+
- **`Lostcoords::Ui.view_paths`, `Lostcoords::Ui.load_translations!` and `Lostcoords::Ui.root` are removed.**
|
|
180
|
+
The engine adds the gem's views and translations to the host's lookup paths. Use
|
|
181
|
+
`Lostcoords::Ui::Engine.root` to locate the gem's files.
|
|
182
|
+
- **Components no longer call a private `lc_locale`.** They translate with `I18n.locale`. Set the locale
|
|
183
|
+
through Rails, for example with `I18n.with_locale` in a controller `around_action`.
|
|
184
|
+
- **The gem depends on `railties` instead of `activesupport`.** An app outside Rails moves to a Rails
|
|
185
|
+
application and the engine's asset setup above.
|
|
186
|
+
|
|
187
|
+
Rails apps that load the gem through Bundler need no edits.
|
|
188
|
+
|
|
189
|
+
New components and options:
|
|
190
|
+
|
|
191
|
+
- **`lc_toc` is an "On this page" list that follows the reader.** It marks the section scrolled to with
|
|
192
|
+
`aria-current="location"` and slides an indicator to it. Pass links with `toc.link "Usage", "#usage"`, or
|
|
193
|
+
rendered HTML with `lc_toc(headings: html)` to list its `h2` and `h3` that carry an id.
|
|
194
|
+
- **Headings and sections can link to themselves.** `lc_heading "Usage", id: "usage", anchor: true` and
|
|
195
|
+
`lc_section title: "Usage", id: "usage", anchor: true` wrap the title in a link with a `#` mark on hover.
|
|
196
|
+
`anchor: "section-id"` links a heading to an element around it. `lc_prose(anchors: true)` does the same for
|
|
197
|
+
rendered Markdown, whose headings Kiln gives ids.
|
|
198
|
+
- **Anchored targets clear sticky chrome.** `.lc-anchor-target` sets a scroll margin of `--lc-sticky-offset`,
|
|
199
|
+
which `lc_app_header` sets to `5rem` while it renders. Override the property if your header is taller.
|
|
200
|
+
- **`lc_app_header`, `lc_docs_shell` and `lc_dock` move from the Blocks examples into the gem**, in the new
|
|
201
|
+
`shell` stylesheet entry, with the `lc-app-header` and `lc-dock` controllers. `lc_app_header` yields
|
|
202
|
+
`header.brand`, `header.nav` and `header.actions`. `lc_docs_shell(navigation:, contents:)` lays out a sidebar,
|
|
203
|
+
the page and an `lc_toc`. `lc_dock` yields `dock.nav` and `dock.menu`, reserves its height at the end of the
|
|
204
|
+
page and hides while the on-screen keyboard is open. If you copied the Application header, Documentation
|
|
205
|
+
layout or Mobile navigation block, you can replace the copy with the helper and delete its stylesheet and
|
|
206
|
+
controller.
|
|
207
|
+
|
|
208
|
+
## Changes in 0.8.2
|
|
209
|
+
|
|
210
|
+
Nothing needs an edit. New options, and one change you may see:
|
|
211
|
+
|
|
212
|
+
- **`lc_emoji_picker` takes `picker_class:`, `trigger_class:` and `popover_class:`.** The gem leaves the desktop
|
|
213
|
+
popover unpainted so the host can match its own floating surfaces; until now that meant rendering the
|
|
214
|
+
`lostcoords/ui/components/emoji_picker` partial directly. Pass the classes to the helper instead.
|
|
215
|
+
- **A dialog slides to a new width.** `.lc-dialog` transitions `inline-size`, so a dialog that widens, such as
|
|
216
|
+
one opening a side panel, animates instead of jumping. A host that restated the dialog's `transition` only to
|
|
217
|
+
add `inline-size` can delete that rule.
|
|
218
|
+
- **`lc-scroll-keeper` keeps a scroll container's position.** Put `data-controller="lc-scroll-keeper"` on a
|
|
219
|
+
sidebar that every page renders again; it restores its scroll across Turbo visits and reloads.
|
|
220
|
+
- **`lc_nav_list` keeps the server's current link after a back visit.** Before: a page restored from Turbo's
|
|
221
|
+
cache showed the link clicked before leaving as current. After: it shows the one the server marked.
|
|
222
|
+
|
|
197
223
|
## Changes in 0.8.1
|
|
198
224
|
|
|
199
225
|
Nothing needs an edit, but these look different:
|
|
@@ -520,8 +546,36 @@ tones; `lc_link_class` styles links you render yourself. `lc_skip_link` targets
|
|
|
520
546
|
Pass `card: true` to `lc_radio` or `lc_checkbox` for selectable tiles; a block adds content, such as a
|
|
521
547
|
preview, under the label.
|
|
522
548
|
|
|
523
|
-
|
|
524
|
-
|
|
549
|
+
A sidebar that scrolls on its own starts at the top on every page. Put `data-controller="lc-scroll-keeper"`
|
|
550
|
+
on the scroll container to keep its position across Turbo visits and reloads. Containers with the same
|
|
551
|
+
`data-lc-scroll-keeper-key-value` share one position for the browser tab. Without a saved position,
|
|
552
|
+
it scrolls the `aria-current="page"` link into view.
|
|
553
|
+
|
|
554
|
+
Page chrome lives in the `shell` stylesheet entry. `lc_app_header` is a sticky glass header,
|
|
555
|
+
`lc_docs_shell` lays out a documentation page, and `lc_toc` lists the page's sections and marks the one
|
|
556
|
+
the reader has scrolled to. This documentation site is built with them.
|
|
557
|
+
|
|
558
|
+
```erb
|
|
559
|
+
<%= lc_app_header do |header| %>
|
|
560
|
+
<%= header.brand root_path, label: "Acme home" do %><%= image_tag "logo.svg", alt: "" %> Acme<% end %>
|
|
561
|
+
<%= header.nav class: "max-sm:hidden" do |nav| %>
|
|
562
|
+
<%= nav.link "Guides", guides_path, current: true %>
|
|
563
|
+
<% end %>
|
|
564
|
+
<%= header.actions do %><%= lc_icon_button "Search", icon: "magnifying-glass", size: :sm %><% end %>
|
|
565
|
+
<% end %>
|
|
566
|
+
|
|
567
|
+
<% contents = lc_toc do |toc| %>
|
|
568
|
+
<%= toc.link "Usage", "#usage" %>
|
|
569
|
+
<%= toc.link "Sizes", "#sizes", indent: true %>
|
|
570
|
+
<% end %>
|
|
571
|
+
<%= lc_docs_shell navigation: render("guides/sidebar"), contents: do %>
|
|
572
|
+
<%= lc_section title: "Usage", id: "usage", anchor: true do %>…<% end %>
|
|
573
|
+
<% end %>
|
|
574
|
+
```
|
|
575
|
+
|
|
576
|
+
For rendered Markdown, such as a Kiln `.md` view, pass the HTML to both: `lc_prose(anchors: true) { html }`
|
|
577
|
+
links its headings, and `lc_toc(headings: html)` lists them. On phones, `lc_dock` floats `dock.nav` and a
|
|
578
|
+
`dock.menu` of quick actions at the bottom of the screen; render it last, since it reserves its height there.
|
|
525
579
|
|
|
526
580
|
```erb
|
|
527
581
|
<%= lc_menu id: "member-actions", label: "Actions for #{member.name}", trigger: :icon do %>
|
|
@@ -915,11 +969,15 @@ Blocks live in the docs app. They add no rendering helpers or installable block
|
|
|
915
969
|
## Docs
|
|
916
970
|
|
|
917
971
|
The docs app lives in `test/dummy`. Run `parcela up --detach` and open https://ui.localhost.
|
|
918
|
-
Parcela starts Rails
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
972
|
+
Parcela starts Rails (with live reload through Hotwire Spark) and the Tailwind watcher.
|
|
973
|
+
`parcela down` stops this environment.
|
|
974
|
+
|
|
975
|
+
`bin/rails kiln:build` exports every docs route to `docs/` for GitHub Pages with
|
|
976
|
+
[Kiln](https://github.com/davafons/kiln): pages, blocks, the token reference, the machine-readable API and
|
|
977
|
+
assets. Param sources for the component and block pages live in `test/dummy/config/kiln.rb`, and a route
|
|
978
|
+
without one fails the build. `bin/rails kiln:serve` serves the export the way GitHub Pages does. CI runs
|
|
979
|
+
`bin/rails kiln:build` and fails when `docs/` changes, and checks that every public rendering helper has a
|
|
980
|
+
runnable example.
|
|
923
981
|
|
|
924
982
|
## Development
|
|
925
983
|
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
@import "./theme.css";
|
|
6
6
|
@source "../../../../helpers/lostcoords/ui/{badge,button,card,choice,copy_button,description_list,feedback,form,glass,icon,layout,list_group,navigation,primitives,render_attributes,structures,tailwind,translation,typography}_helper.rb";
|
|
7
7
|
@source "../../../../javascript/lostcoords/ui/helpers/*.js";
|
|
8
|
-
@source "../../../../javascript/lostcoords/ui/controllers/lc_{copy,kbd,nav,selection,shortcut,tabs,toggle}_controller.js";
|
|
8
|
+
@source "../../../../javascript/lostcoords/ui/controllers/lc_{copy,kbd,nav,scroll_keeper,selection,shortcut,tabs,toc,toggle}_controller.js";
|
|
9
9
|
@source "../../../../../lib/lostcoords/ui/parts.rb";
|
|
10
10
|
|
|
11
11
|
@import "./glass.css";
|
|
@@ -10,9 +10,12 @@
|
|
|
10
10
|
overscroll-behavior: contain;
|
|
11
11
|
opacity: 0;
|
|
12
12
|
transform: var(--lc-dialog-from);
|
|
13
|
+
|
|
14
|
+
/* inline-size: a dialog that widens, such as one opening a side panel, slides to its new width. */
|
|
13
15
|
transition:
|
|
14
16
|
opacity var(--lc-dialog-fade) var(--lc-ease-out-expo),
|
|
15
17
|
transform var(--lc-dialog-duration) var(--lc-ease-out-expo),
|
|
18
|
+
inline-size var(--lc-dialog-duration) var(--lc-ease-out-expo),
|
|
16
19
|
display var(--lc-dialog-duration) allow-discrete,
|
|
17
20
|
overlay var(--lc-dialog-duration) allow-discrete;
|
|
18
21
|
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/* A sticky lc_app_header covers the top of the page; anchors and the docs
|
|
2
|
+
sidebars start below it. Override --lc-sticky-offset if your header is taller. */
|
|
3
|
+
:root:has(.lc-app-header) {
|
|
4
|
+
--lc-sticky-offset: 5rem;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
@layer components {
|
|
8
|
+
.lc-app-header__glass {
|
|
9
|
+
opacity: 0;
|
|
10
|
+
transition: opacity 300ms ease;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.lc-app-header[data-scrolled] .lc-app-header__glass {
|
|
14
|
+
opacity: 1;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/* The sidebar scrolls on its own without a visible scrollbar. */
|
|
18
|
+
.lc-docs-shell__sidebar {
|
|
19
|
+
scrollbar-width: none;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.lc-docs-shell__sidebar::-webkit-scrollbar {
|
|
23
|
+
display: none;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.lc-dock {
|
|
27
|
+
--lc-dock-edge: max(1rem, env(safe-area-inset-left));
|
|
28
|
+
--lc-dock-gap: max(1rem, env(safe-area-inset-right));
|
|
29
|
+
--lc-dock-bottom: max(0.75rem, env(safe-area-inset-bottom));
|
|
30
|
+
--lc-dock-size: 4rem;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/* Holds the dock's height at the end of the page, so the last content scrolls clear of it. */
|
|
34
|
+
.lc-dock__space {
|
|
35
|
+
block-size: calc(var(--lc-dock-bottom) + var(--lc-dock-size) + 1rem);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.lc-dock__menu {
|
|
39
|
+
position: fixed;
|
|
40
|
+
z-index: calc(var(--lc-z-sticky) + 1);
|
|
41
|
+
inset-inline-end: var(--lc-dock-gap);
|
|
42
|
+
bottom: var(--lc-dock-bottom);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.lc-dock__trigger,
|
|
46
|
+
.lc-dock__action {
|
|
47
|
+
display: grid;
|
|
48
|
+
width: var(--lc-dock-size);
|
|
49
|
+
height: var(--lc-dock-size);
|
|
50
|
+
place-items: center;
|
|
51
|
+
padding: 0;
|
|
52
|
+
color: var(--primary);
|
|
53
|
+
cursor: pointer;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.lc-dock__trigger {
|
|
57
|
+
position: relative;
|
|
58
|
+
z-index: 2;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.lc-dock__trigger svg {
|
|
62
|
+
transition: rotate 300ms var(--lc-ease-sheet, ease);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.lc-dock__trigger[aria-expanded="true"] svg {
|
|
66
|
+
rotate: 135deg;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.lc-dock__actions {
|
|
70
|
+
visibility: hidden;
|
|
71
|
+
pointer-events: none;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.lc-dock__actions[data-open] {
|
|
75
|
+
visibility: visible;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.lc-dock__scrim {
|
|
79
|
+
position: fixed;
|
|
80
|
+
inset: 0;
|
|
81
|
+
border: 0;
|
|
82
|
+
background: color-mix(in oklab, var(--foreground) 18%, transparent);
|
|
83
|
+
opacity: 0;
|
|
84
|
+
-webkit-backdrop-filter: blur(calc(var(--spacing) * 2));
|
|
85
|
+
backdrop-filter: blur(calc(var(--spacing) * 2));
|
|
86
|
+
transition: opacity 220ms ease;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.lc-dock__actions[data-open] .lc-dock__scrim {
|
|
90
|
+
pointer-events: auto;
|
|
91
|
+
opacity: 1;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.lc-dock__action {
|
|
95
|
+
position: absolute;
|
|
96
|
+
z-index: 1;
|
|
97
|
+
inset: 0;
|
|
98
|
+
width: calc(var(--lc-dock-size) - 0.5rem);
|
|
99
|
+
height: calc(var(--lc-dock-size) - 0.5rem);
|
|
100
|
+
margin: 0.25rem;
|
|
101
|
+
color: var(--foreground);
|
|
102
|
+
opacity: 0;
|
|
103
|
+
transform: scale(0.4);
|
|
104
|
+
transition: transform 300ms ease, opacity 150ms ease;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.lc-dock__actions[data-open] .lc-dock__action {
|
|
108
|
+
pointer-events: auto;
|
|
109
|
+
opacity: 1;
|
|
110
|
+
transform: translateY(calc(var(--lc-dock-action-index, 1) * -4.5rem)) scale(1);
|
|
111
|
+
transition: transform 420ms cubic-bezier(0.34, 1.45, 0.64, 1), opacity 160ms ease;
|
|
112
|
+
transition-delay: calc((var(--lc-dock-action-index, 1) - 1) * 40ms);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.lc-dock__action-label {
|
|
116
|
+
position: absolute;
|
|
117
|
+
inset-inline-end: calc(100% + 0.75rem);
|
|
118
|
+
width: max-content;
|
|
119
|
+
max-width: calc(100vw - 7rem);
|
|
120
|
+
padding: 0.5rem 0.875rem;
|
|
121
|
+
border-radius: var(--radius-pill);
|
|
122
|
+
background: var(--background);
|
|
123
|
+
box-shadow: var(--lc-shadow);
|
|
124
|
+
color: var(--foreground);
|
|
125
|
+
font-size: 0.875rem;
|
|
126
|
+
font-weight: 600;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
.lc-dock[data-keyboard] :is(.lc-dock__nav, .lc-dock__menu, .lc-dock__space) {
|
|
130
|
+
display: none;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
@media (prefers-reduced-motion: reduce) {
|
|
134
|
+
.lc-app-header__glass,
|
|
135
|
+
.lc-dock__trigger svg,
|
|
136
|
+
.lc-dock__scrim,
|
|
137
|
+
.lc-dock__action,
|
|
138
|
+
.lc-dock__actions[data-open] .lc-dock__action {
|
|
139
|
+
transition: none;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/* The nav is an lc_nav_list, whose relative position is a utility, so the dock's
|
|
145
|
+
placement sits in the utilities layer too. */
|
|
146
|
+
@layer utilities {
|
|
147
|
+
.lc-dock__nav {
|
|
148
|
+
position: fixed;
|
|
149
|
+
z-index: var(--lc-z-sticky);
|
|
150
|
+
inset-inline: var(--lc-dock-edge) var(--lc-dock-gap);
|
|
151
|
+
bottom: var(--lc-dock-bottom);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
.lc-dock:has(.lc-dock__menu) .lc-dock__nav {
|
|
155
|
+
inset-inline-end: calc(var(--lc-dock-gap) + var(--lc-dock-size) + 0.75rem);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
.lc-dock[data-keyboard] .lc-dock__nav {
|
|
159
|
+
display: none;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
@@ -12,6 +12,32 @@
|
|
|
12
12
|
overflow-wrap: anywhere;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
/* Headings and sections a link can point to. --lc-sticky-offset is the height
|
|
16
|
+
of sticky chrome, such as lc_app_header, so the target lands below it. */
|
|
17
|
+
:where(.lc-anchor-target) {
|
|
18
|
+
scroll-margin-block-start: calc(var(--lc-sticky-offset, 0rem) + var(--lc-anchor-gap, 1.5rem));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/* A heading that links to itself. The mark shows on hover and keyboard focus. */
|
|
22
|
+
:where(.lc-anchor) {
|
|
23
|
+
color: inherit;
|
|
24
|
+
text-decoration: none;
|
|
25
|
+
border-radius: var(--radius-sm);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.lc-anchor::after {
|
|
29
|
+
content: "#" / "";
|
|
30
|
+
margin-inline-start: 0.4em;
|
|
31
|
+
color: var(--muted-foreground);
|
|
32
|
+
opacity: 0;
|
|
33
|
+
transition: opacity var(--lc-motion-quick) ease;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.lc-anchor:hover::after,
|
|
37
|
+
.lc-anchor:focus-visible::after {
|
|
38
|
+
opacity: 1;
|
|
39
|
+
}
|
|
40
|
+
|
|
15
41
|
:where(.lc-eyebrow) {
|
|
16
42
|
font-family: var(--font-eyebrow);
|
|
17
43
|
text-transform: uppercase;
|
|
@@ -6,15 +6,18 @@ module Lostcoords::Ui
|
|
|
6
6
|
module EmojiPickerHelper
|
|
7
7
|
include TranslationHelper
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
# popover_class paints the desktop popover: the gem leaves it unpainted so the host can match
|
|
10
|
+
# its floating surfaces. picker_class and trigger_class style the wrapper and its button.
|
|
11
|
+
def lc_emoji_picker(form:, field:, label:, catalog_url:, value: nil, quick: [], recent: [], recent_scope: nil, auto_submit: false, picker_class: nil, trigger_class: nil, popover_class: nil, **attributes)
|
|
10
12
|
lc_label!(label, :label)
|
|
11
13
|
lc_label!(catalog_url, :catalog_url)
|
|
12
|
-
render "lostcoords/ui/components/emoji_picker", form: form, field: field, label: label, catalog_url: catalog_url, value: value, quick: quick, recent: recent, recent_scope: recent_scope, auto_submit: auto_submit,
|
|
14
|
+
render "lostcoords/ui/components/emoji_picker", form: form, field: field, label: label, catalog_url: catalog_url, value: value, quick: quick, recent: recent, recent_scope: recent_scope, auto_submit: auto_submit,
|
|
15
|
+
picker_class: picker_class, trigger_class: trigger_class, popover_class: popover_class, attributes: attributes
|
|
13
16
|
end
|
|
14
17
|
|
|
15
|
-
SEARCH_NAMES_PATH = Lostcoords::Ui.root.join("config/emoji_search_names.yml")
|
|
16
|
-
SEARCH_NAMES_JA_PATH = Lostcoords::Ui.root.join("config/emoji_search_names_ja.yml")
|
|
17
|
-
SEARCH_ALIASES_PATH = Lostcoords::Ui.root.join("config/emoji_search_aliases.yml")
|
|
18
|
+
SEARCH_NAMES_PATH = Lostcoords::Ui::Engine.root.join("config/emoji_search_names.yml")
|
|
19
|
+
SEARCH_NAMES_JA_PATH = Lostcoords::Ui::Engine.root.join("config/emoji_search_names_ja.yml")
|
|
20
|
+
SEARCH_ALIASES_PATH = Lostcoords::Ui::Engine.root.join("config/emoji_search_aliases.yml")
|
|
18
21
|
|
|
19
22
|
# Representative glyph for each category's tab in the picker navigation.
|
|
20
23
|
CATEGORY_ICONS = {
|
|
@@ -51,11 +51,13 @@ module Lostcoords::Ui
|
|
|
51
51
|
tag.div(**lc_attributes({ class: lc_container_class(size: size) }, attributes), &block)
|
|
52
52
|
end
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
# anchor: true links the heading to the section's id:, for pages readers link into.
|
|
55
|
+
def lc_section(title:, level: 2, actions: nil, anchor: false, **attributes, &block)
|
|
55
56
|
raise ArgumentError, "title must not be blank" if title.blank?
|
|
57
|
+
raise ArgumentError, "anchor: true needs an id" if anchor && attributes[:id].blank?
|
|
56
58
|
|
|
57
|
-
tag.section(**lc_attributes({ class: lc_stack_class(gap: :heading) }, attributes)) do
|
|
58
|
-
heading = lc_heading(title, level: level, size: :heading)
|
|
59
|
+
tag.section(**lc_attributes({ class: lc_stack_class(gap: :heading, extra: ("lc-anchor-target" if anchor)) }, attributes)) do
|
|
60
|
+
heading = lc_heading(title, level: level, size: :heading, anchor: (attributes[:id] if anchor))
|
|
59
61
|
action_content = actions.respond_to?(:call) ? capture(&actions) : actions
|
|
60
62
|
header = lc_section_header { safe_join([ heading, action_content ].compact) }
|
|
61
63
|
safe_join([ header, lc_stack(&block) ])
|
|
@@ -84,6 +84,35 @@ module Lostcoords::Ui
|
|
|
84
84
|
end
|
|
85
85
|
end
|
|
86
86
|
|
|
87
|
+
TOC_INDICATOR = "pointer-events-none absolute -start-px top-0 h-0 w-0.5 rounded-pill bg-primary opacity-0 " \
|
|
88
|
+
"transition-[translate,height,opacity] duration-300 ease-(--lc-ease-out-expo) motion-reduce:transition-none"
|
|
89
|
+
|
|
90
|
+
# An "On this page" list that marks the section the reader has scrolled to with aria-current="location".
|
|
91
|
+
# Yields a builder: `toc.link "Usage", "#usage"`, with indent: true for a subsection. headings: takes
|
|
92
|
+
# rendered HTML, such as Markdown output, and lists its headings that carry an id, nesting the deeper level.
|
|
93
|
+
def lc_toc(label: lc_t("lostcoords.ui.toc.label"), headings: nil, levels: 2..3, **attributes, &block)
|
|
94
|
+
lc_label!(label, :label)
|
|
95
|
+
raise ArgumentError, "lc_toc takes headings: or a block, not both" if headings && block
|
|
96
|
+
raise ArgumentError, "lc_toc needs headings: or a block" unless headings || block
|
|
97
|
+
levels = Array(levels)
|
|
98
|
+
raise ArgumentError, "levels must be heading levels from 1 to 6" unless levels.any? && levels.all? { |level| (1..6).cover?(level) }
|
|
99
|
+
|
|
100
|
+
toc = Parts::Toc.new(self)
|
|
101
|
+
links = if block
|
|
102
|
+
capture(toc, &block)
|
|
103
|
+
else
|
|
104
|
+
found = Nokogiri::HTML5.fragment(headings.to_s).css(levels.map { |level| "h#{level}[id]" }.join(", "))
|
|
105
|
+
safe_join(found.map { |heading| toc.link(heading.text.strip, "##{heading['id']}", indent: heading.name.delete("h").to_i > levels.min) })
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
tag.nav(**lc_attributes({ class: "relative", aria: { label: label }, data: { slot: "toc", controller: "lc-toc" } }, attributes)) do
|
|
109
|
+
safe_join([
|
|
110
|
+
tag.span(class: TOC_INDICATOR, aria: { hidden: true }, data: { slot: "toc-indicator", lc_toc_target: "indicator" }),
|
|
111
|
+
tag.ul(links, class: "m-0 flex list-none flex-col border-s border-border p-0")
|
|
112
|
+
])
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
87
116
|
# Previous and next links between pages in a sequence. Each side takes [title, url] or nil.
|
|
88
117
|
# compact: true shows icon buttons, for a page header.
|
|
89
118
|
def lc_pager(previous: nil, next: nil, label: lc_t("lostcoords.ui.pager.label"), compact: false, **attributes)
|
|
@@ -8,8 +8,29 @@ module Lostcoords::Ui
|
|
|
8
8
|
lc_tw(PROSE_BASE, extra)
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
# anchors: true links every h2, h3 and h4 that has an id to itself, as rendered Markdown's headings
|
|
12
|
+
# do. Pass the same HTML to lc_toc(headings:) for an "On this page" list.
|
|
13
|
+
def lc_prose(anchors: false, **attributes, &block)
|
|
14
|
+
content = capture(&block) if block
|
|
15
|
+
content = lc_anchor_headings(content) if anchors && content
|
|
16
|
+
tag.div(content, **lc_attributes({ class: lc_prose_class }, attributes))
|
|
13
17
|
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
def lc_anchor_headings(html)
|
|
21
|
+
fragment = Nokogiri::HTML5.fragment(html.to_s)
|
|
22
|
+
fragment.css("h2[id], h3[id], h4[id]").each do |heading|
|
|
23
|
+
next if heading.at_css("a.lc-anchor")
|
|
24
|
+
|
|
25
|
+
heading["class"] = [ heading["class"], "lc-anchor-target" ].compact.join(" ")
|
|
26
|
+
link = Nokogiri::XML::Node.new("a", fragment.document)
|
|
27
|
+
link["href"] = "##{heading['id']}"
|
|
28
|
+
link["class"] = "lc-anchor"
|
|
29
|
+
link["data-slot"] = "heading-anchor"
|
|
30
|
+
link.children = heading.children
|
|
31
|
+
heading.add_child(link)
|
|
32
|
+
end
|
|
33
|
+
fragment.to_html.html_safe
|
|
34
|
+
end
|
|
14
35
|
end
|
|
15
36
|
end
|