lostcoords-ui 0.7.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 +287 -26
  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 -4
  10. data/app/assets/tailwind/lostcoords/ui/search.css +96 -0
  11. data/app/assets/tailwind/lostcoords/ui/sheet.css +41 -8
  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 +20 -8
  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 +105 -16
  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 +1 -6
  38. data/app/javascript/lostcoords/ui/controllers/lc_sheet_controller.js +29 -15
  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 +27 -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,96 @@
1
+ /* lc_search: a pill trigger that opens a full-screen search over a
2
+ blurred page. The controller animates it open and closed. */
3
+ @layer components {
4
+ .lc-search-trigger {
5
+ display: flex;
6
+ align-items: center;
7
+ gap: var(--spacing-related);
8
+ min-block-size: var(--spacing-control-sm);
9
+ padding-inline: var(--spacing-heading);
10
+ border: 0;
11
+ border-radius: var(--radius-pill);
12
+ background: var(--muted);
13
+ color: var(--muted-foreground);
14
+ font-size: var(--text-label);
15
+ cursor: pointer;
16
+ transition: background-color var(--lc-motion-control), color var(--lc-motion-control);
17
+
18
+ &:hover { background: var(--accent); color: var(--foreground); }
19
+
20
+ /* The bar grows out of the trigger, so the trigger steps aside while search is open. */
21
+ [data-slot="search"][data-open] & { opacity: 0; }
22
+
23
+ @media (width < 40rem) {
24
+ justify-content: center;
25
+ inline-size: var(--spacing-control-sm);
26
+ padding-inline: 0;
27
+ }
28
+
29
+ @media (width >= 40rem) { inline-size: calc(var(--spacing) * 64); }
30
+ @media (width >= 80rem) { inline-size: calc(var(--spacing) * 84); }
31
+ }
32
+
33
+ .lc-search {
34
+ position: fixed;
35
+ inset: 0;
36
+ inline-size: 100%;
37
+ max-inline-size: none;
38
+ block-size: 100%;
39
+ max-block-size: none;
40
+ margin: 0;
41
+ padding: 0;
42
+ overflow: hidden;
43
+ border: 0;
44
+ background: transparent;
45
+ color: var(--foreground);
46
+
47
+ /* Safari drops custom properties inside -webkit-backdrop-filter, so the blur is literal. */
48
+ &::backdrop {
49
+ background: var(--lc-scrim-veil);
50
+ -webkit-backdrop-filter: blur(20px) saturate(160%);
51
+ backdrop-filter: blur(20px) saturate(160%);
52
+ }
53
+
54
+ @media (prefers-reduced-transparency: reduce) {
55
+ &::backdrop {
56
+ background: var(--background);
57
+ -webkit-backdrop-filter: none;
58
+ backdrop-filter: none;
59
+ }
60
+ }
61
+
62
+ /* Rows and groups carry display utilities, which outrank this layer unless it is important. */
63
+ [hidden] { display: none !important; }
64
+ }
65
+
66
+ .lc-search-stack {
67
+ display: flex;
68
+ flex-direction: column;
69
+ gap: var(--spacing-heading);
70
+ inline-size: min(calc(var(--spacing) * 160), calc(100% - var(--spacing) * 6));
71
+ block-size: 100%;
72
+ margin-inline: auto;
73
+ padding-block:
74
+ max(var(--spacing-heading), env(safe-area-inset-top))
75
+ max(var(--spacing-heading), env(safe-area-inset-bottom));
76
+
77
+ @media (width >= 40rem) { padding-block-start: 14vh; }
78
+ }
79
+
80
+ .lc-search-input::-webkit-search-cancel-button {
81
+ /* stylelint-disable-next-line property-no-vendor-prefix -- The clear button has an accessible label. */
82
+ -webkit-appearance: none;
83
+ }
84
+
85
+ .lc-search-panel {
86
+ --lc-glass-fill: color-mix(in oklab, var(--background) 82%, transparent);
87
+
88
+ @media (width >= 40rem) { max-block-size: min(60dvh, calc(var(--spacing) * 136)); }
89
+ }
90
+
91
+ .lc-search-result {
92
+ color: var(--foreground);
93
+
94
+ &:is(:hover, :focus-visible) { background: color-mix(in oklab, var(--foreground) 6%, transparent); }
95
+ }
96
+ }
@@ -1,7 +1,10 @@
1
1
  @layer components {
2
2
  @media (width < 40rem) {
3
3
  /* UIKit's 36×5 grabber. */
4
- :is([data-lc-sheet-target~="handle"], dialog[data-controller~="lc-sheet"])::before {
4
+ :is(
5
+ [data-lc-sheet-target~="handle"],
6
+ :is(dialog[data-controller~="lc-sheet"], .lc-sheet):not(:has([data-lc-sheet-target~="handle"]))
7
+ )::before {
5
8
  content: "";
6
9
  display: block;
7
10
  inline-size: 2.25rem;
@@ -10,15 +13,37 @@
10
13
  background: color-mix(in oklab, var(--muted-foreground) 45%, transparent);
11
14
  }
12
15
  }
16
+
17
+ /* From sm up an anchored sheet is a popover under its trigger, opened by a
18
+ FloatingPanel ([data-open]); the positioned ancestor is the caller's. */
19
+ @media (width >= 40rem) {
20
+ .lc-sheet-anchored {
21
+ @apply lc-popover-shell;
22
+
23
+ display: none;
24
+ flex-direction: column;
25
+ position: absolute;
26
+ inset-block: calc(100% + --spacing(2)) auto;
27
+ inset-inline: auto 0;
28
+ z-index: var(--lc-z-popover);
29
+ inline-size: min(24rem, calc(100vw - --spacing(8)));
30
+ max-block-size: min(28rem, calc(100vh - --spacing(24)));
31
+ border-radius: var(--radius-3xl);
32
+
33
+ &[data-open] { display: flex; }
34
+ }
35
+ }
13
36
  }
14
37
 
15
38
  @layer modules {
16
- /* Phones: every modal dialog is an iOS sheet (lc-sheet). It floats
17
- inset with all corners round while it is short, and docks to the screen
18
- edges as it reaches the large detent: --lc-sheet-p runs 0 → 1 between them.
19
- Lives in this layer so it out-ranks a dialog's own frame. */
39
+ /* Phones: every modal dialog is an iOS sheet (lc-sheet), and so is any
40
+ .lc-sheet panel. It floats inset with all corners round while it is short,
41
+ and docks to the screen edges as it reaches the large detent: --lc-sheet-p
42
+ runs 0 → 1 between them. Lives in this layer so it out-ranks a panel's own
43
+ frame. A dialog is open while [open]; a .lc-sheet while :popover-open or
44
+ [data-open]. */
20
45
  @media (width < 40rem) {
21
- dialog[data-controller~="lc-sheet"] {
46
+ :is(dialog[data-controller~="lc-sheet"], .lc-sheet) {
22
47
  --lc-sheet-p: 0;
23
48
  --lc-sheet-inset: 0.5rem;
24
49
  --lc-sheet-radius: 2.25rem;
@@ -54,7 +79,7 @@
54
79
  display var(--lc-sheet-duration) allow-discrete,
55
80
  overlay var(--lc-sheet-duration) allow-discrete;
56
81
 
57
- &[open] {
82
+ &:is([open], :popover-open, .lc-sheet[data-open]) {
58
83
  transform: none;
59
84
 
60
85
  @starting-style { transform: translateY(var(--lc-sheet-offscreen)); }
@@ -78,7 +103,7 @@
78
103
  overlay var(--lc-sheet-duration) allow-discrete;
79
104
  }
80
105
 
81
- &[open]::backdrop {
106
+ &:is([open], :popover-open)::backdrop {
82
107
  opacity: 1;
83
108
 
84
109
  @starting-style { opacity: 0; }
@@ -89,6 +114,14 @@
89
114
  }
90
115
  }
91
116
 
117
+ .lc-sheet {
118
+ z-index: var(--lc-z-overlay);
119
+ display: none;
120
+ flex-direction: column;
121
+
122
+ &:is(:popover-open, [data-open]) { display: flex; }
123
+ }
124
+
92
125
  /* Behind a large sheet the page shrinks back and rounds off, over black,
93
126
  as UIKit's page sheet does; lc-sheet drives the variables. */
94
127
  html[data-lc-sheet-page] {
@@ -70,6 +70,7 @@
70
70
 
71
71
  @theme {
72
72
  --font-display: var(--font-sans);
73
+ --font-eyebrow: var(--font-mono);
73
74
  --font-japanese: "Hiragino Sans", "Yu Gothic", "YuGothic", "Meiryo", ui-sans-serif, system-ui, sans-serif;
74
75
 
75
76
  /* Type roles. Each sets size, line height, tracking and weight together. */
@@ -98,6 +99,10 @@
98
99
  --text-label--font-weight: 500;
99
100
  --text-caption: 0.75rem;
100
101
  --text-caption--line-height: 1rem;
102
+ --text-eyebrow: 0.75rem;
103
+ --text-eyebrow--line-height: 1rem;
104
+ --text-eyebrow--letter-spacing: 0.1em;
105
+ --text-eyebrow--font-weight: 500;
101
106
 
102
107
  --container-page: 75rem;
103
108
  --container-reading: 65ch;
@@ -136,6 +141,10 @@
136
141
  --lc-z-overlay: 60;
137
142
  --lc-z-toast: 70;
138
143
 
144
+ /* Distance from the screen edge to the toast region, on top of the safe area.
145
+ --lc-toast-offset-top and --lc-toast-offset-bottom override one edge. */
146
+ --lc-toast-offset: var(--lc-gutter);
147
+
139
148
  --background: oklch(100% 0 0deg);
140
149
  --foreground: oklch(23.1% 0 0deg);
141
150
 
@@ -148,6 +157,11 @@
148
157
  --primary-foreground: #fff;
149
158
  --secondary: var(--accent);
150
159
  --secondary-foreground: var(--foreground);
160
+
161
+ /* Fields and secondary buttons inside a card. Point them at another fill when --card
162
+ matches --input or --secondary, or they vanish on cards. */
163
+ --card-input: var(--input);
164
+ --card-secondary: var(--secondary);
151
165
  --muted: oklch(97.6% 0 0deg);
152
166
  --muted-foreground: oklch(48% 0 0deg);
153
167
  --accent: oklch(95.2% 0 0deg);
@@ -161,6 +175,9 @@
161
175
  --lc-scrim: color-mix(in oklab, var(--foreground) 55%, transparent);
162
176
  --lc-scrim-soft: color-mix(in oklab, var(--foreground) 12%, transparent);
163
177
  --lc-scrim-sheet: rgb(0 0 0 / 0.28);
178
+
179
+ /* Behind full-screen search: a light veil, so the blurred page still shows through. */
180
+ --lc-scrim-veil: color-mix(in oklab, var(--background) 35%, transparent);
164
181
  --lc-input-hover: color-mix(in oklab, var(--foreground) 13%, var(--accent));
165
182
 
166
183
  --lc-shadow-sm: 0 1px 2px rgb(0 0 0 / 0.05);
@@ -211,6 +228,7 @@
211
228
 
212
229
  --lc-scrim: rgb(0 0 0 / 0.6);
213
230
  --lc-scrim-soft: rgb(0 0 0 / 0.32);
231
+ --lc-scrim-veil: rgb(0 0 0 / 0.4);
214
232
 
215
233
  --lc-shadow-sm: 0 1px 2px rgb(0 0 0 / 0.2);
216
234
  --lc-shadow:
@@ -1,15 +1,21 @@
1
1
  @layer components {
2
2
  /* lc-toast-region opens it as a popover; these rules also override the
3
- popover defaults, which would centre it and hide it while closed. */
3
+ popover defaults, which would centre it and hide it while closed. A
4
+ mobile placement sets every edge, so it fully replaces the desktop one. */
4
5
  .lc-toast-region {
6
+ --_lc-toast-top: calc(var(--lc-toast-offset-top, var(--lc-toast-offset)) + env(safe-area-inset-top));
7
+ --_lc-toast-bottom: calc(var(--lc-toast-offset-bottom, var(--lc-toast-offset)) + env(safe-area-inset-bottom));
8
+
5
9
  position: fixed;
6
- inset: auto var(--spacing-gutter) var(--spacing-gutter) auto;
10
+ inset-block: auto var(--_lc-toast-bottom);
11
+ inset-inline: auto var(--lc-toast-offset);
7
12
  z-index: var(--lc-z-toast);
8
13
  display: flex;
9
14
  flex-direction: column;
10
15
  align-items: flex-end;
11
16
  gap: var(--spacing-related);
12
- max-inline-size: calc(100vw - var(--spacing-gutter) * 2);
17
+ inline-size: fit-content;
18
+ max-inline-size: calc(100vw - var(--lc-toast-offset) * 2);
13
19
  margin: 0;
14
20
  padding: 0;
15
21
  overflow: visible;
@@ -17,7 +23,31 @@
17
23
  background: none;
18
24
  color: inherit;
19
25
 
20
- &:dir(rtl) { inset: auto auto var(--spacing-gutter) var(--spacing-gutter); }
26
+ &[data-placement^="top"] { inset-block: var(--_lc-toast-top) auto; }
27
+
28
+ &[data-placement$="center"] {
29
+ inset-inline: var(--lc-toast-offset);
30
+ margin-inline: auto;
31
+ align-items: center;
32
+ }
33
+
34
+ @media (width < 40rem) {
35
+ &[data-mobile-placement^="top"] { inset-block: var(--_lc-toast-top) auto; }
36
+ &[data-mobile-placement^="bottom"] { inset-block: auto var(--_lc-toast-bottom); }
37
+
38
+ &[data-mobile-placement$="center"] {
39
+ inset-inline: var(--lc-toast-offset);
40
+ margin-inline: auto;
41
+ align-items: center;
42
+ }
43
+
44
+ &[data-mobile-placement$="end"] {
45
+ inset-inline: auto var(--lc-toast-offset);
46
+ margin-inline: 0;
47
+ align-items: flex-end;
48
+ }
49
+ }
50
+
21
51
  &:empty { display: none; }
22
52
  }
23
53
  }
@@ -12,6 +12,16 @@
12
12
  overflow-wrap: anywhere;
13
13
  }
14
14
 
15
+ :where(.lc-eyebrow) {
16
+ font-family: var(--font-eyebrow);
17
+ text-transform: uppercase;
18
+ }
19
+
20
+ :where(.lc-eyebrow):lang(ja) {
21
+ font-family: var(--font-sans);
22
+ text-transform: none;
23
+ }
24
+
15
25
  /* Type role utilities read --tw-tracking first, so this wins over their tracking. */
16
26
  :where(.lc-heading, .lc-text):lang(ja) {
17
27
  --tw-tracking: 0;
@@ -4,14 +4,15 @@ module Lostcoords::Ui
4
4
  "lc-icon-badge grid place-items-center shrink-0 " \
5
5
  "size-[var(--lc-icon-badge-size,var(--lc-icon-badge-size-default,--spacing(10)))] " \
6
6
  "[border:var(--lc-icon-badge-border,1px_solid_transparent)] " \
7
- "text-[length:var(--lc-icon-badge-font-size,var(--lc-icon-badge-font-size-default,1.125rem))] leading-none"
7
+ "text-[length:var(--lc-icon-badge-font-size,calc(var(--lc-icon-badge-size,var(--lc-icon-badge-size-default,--spacing(10)))*var(--lc-icon-badge-font-scale,var(--lc-icon-badge-font-scale-default,0.45))))] leading-none"
8
8
 
9
- # Sizes set the default, so a context that pins --lc-icon-badge-size still wins.
9
+ # Sizes set the defaults, so a context that pins --lc-icon-badge-size still wins and the emoji
10
+ # or icon follows it. --lc-icon-badge-font-scale sets the glyph's share of the badge.
10
11
  ICON_BADGE_SIZES = {
11
- sm: "[--lc-icon-badge-size-default:--spacing(6.5)] [--lc-icon-badge-font-size-default:0.8125rem]",
12
+ sm: "[--lc-icon-badge-size-default:--spacing(6.5)] [--lc-icon-badge-font-scale-default:0.5]",
12
13
  md: "",
13
- lg: "[--lc-icon-badge-size-default:--spacing(12)] [--lc-icon-badge-font-size-default:1.5rem]",
14
- xl: "[--lc-icon-badge-size-default:--spacing(14)] [--lc-icon-badge-font-size-default:1.75rem]"
14
+ lg: "[--lc-icon-badge-size-default:--spacing(12)] [--lc-icon-badge-font-scale-default:0.5]",
15
+ xl: "[--lc-icon-badge-size-default:--spacing(14)] [--lc-icon-badge-font-scale-default:0.5]"
15
16
  }.freeze
16
17
 
17
18
  ICON_BADGE_SHAPES = { square: "lc-squircle rounded-2xl", circle: "rounded-full" }.freeze
@@ -19,16 +20,19 @@ module Lostcoords::Ui
19
20
  AVATAR_BASE =
20
21
  "lc-avatar grid place-items-center shrink-0 rounded-full font-medium tracking-[var(--lc-avatar-tracking,0.05em)] " \
21
22
  "size-[var(--lc-avatar-size,var(--lc-avatar-size-default,--spacing(8)))] " \
22
- "text-[length:var(--lc-avatar-font-size,var(--lc-avatar-font-size-default,0.75rem))] " \
23
+ "text-[length:var(--lc-avatar-font-size,calc(var(--lc-avatar-size,var(--lc-avatar-size-default,--spacing(8)))*var(--lc-avatar-font-scale,var(--lc-avatar-font-scale-default,0.375))))] " \
23
24
  "text-[color:var(--lc-avatar-color,var(--primary-foreground))] " \
24
25
  "border-[length:var(--lc-avatar-border,0px)] border-[color:var(--lc-avatar-cutout,var(--background))]"
25
26
 
26
- # Sizes set the default, so a context that pins --lc-avatar-size (a stack, a dialog) still wins.
27
+ # Sizes set the defaults, so a context that pins --lc-avatar-size (a stack, a dialog) still wins
28
+ # and the initials follow it. --lc-avatar-font-scale sets their share of the avatar.
27
29
  AVATAR_SIZES = {
30
+ xs: "[--lc-avatar-size-default:--spacing(5)] [--lc-avatar-font-scale-default:0.4]",
31
+ sm: "[--lc-avatar-size-default:--spacing(6.5)] [--lc-avatar-font-scale-default:0.385]",
28
32
  md: "",
29
- lg: "[--lc-avatar-size-default:--spacing(12)] [--lc-avatar-font-size-default:1rem]",
30
- sm: "[--lc-avatar-size-default:--spacing(6.5)] [--lc-avatar-font-size-default:0.625rem]",
31
- xl: "[--lc-avatar-size-default:--spacing(24)] [--lc-avatar-font-size-default:1.25rem]"
33
+ lg: "[--lc-avatar-size-default:--spacing(12)] [--lc-avatar-font-scale-default:0.333]",
34
+ xl: "[--lc-avatar-size-default:--spacing(24)] [--lc-avatar-font-scale-default:0.208]",
35
+ xxl: "[--lc-avatar-size-default:--spacing(28)] [--lc-avatar-font-scale-default:0.25]"
32
36
  }.freeze
33
37
 
34
38
  AVATAR_INK = "[--lc-avatar-color:var(--foreground)]"
@@ -65,6 +69,8 @@ module Lostcoords::Ui
65
69
  primary: "bg-primary-soft text-primary"
66
70
  }.freeze
67
71
 
72
+ BADGE_SHAPES = { rounded: "", pill: "rounded-full px-2.5" }.freeze
73
+
68
74
  TOGGLE_BASE =
69
75
  "inline-flex items-center justify-center gap-related rounded-pill " \
70
76
  "border border-transparent bg-input " \
@@ -75,6 +81,7 @@ module Lostcoords::Ui
75
81
  "aria-[current]:not-aria-[current=false]:bg-primary-soft aria-[current]:not-aria-[current=false]:border-primary " \
76
82
  "aria-[current]:not-aria-[current=false]:text-primary aria-[current]:not-aria-[current=false]:shadow-none " \
77
83
  "has-checked:bg-primary-soft has-checked:border-primary has-checked:text-primary has-checked:shadow-none " \
84
+ "aria-expanded:bg-primary-soft aria-expanded:border-primary aria-expanded:text-primary aria-expanded:shadow-none " \
78
85
  "[&_svg]:size-[1.1em] [&_svg]:shrink-0"
79
86
 
80
87
  TOGGLE_ACTIVE = "bg-primary-soft border-primary text-primary hover:text-primary shadow-none"
@@ -101,9 +108,10 @@ module Lostcoords::Ui
101
108
  lc_tw(AVATAR_STACK_ROW, extra)
102
109
  end
103
110
 
104
- def lc_badge_class(tone: :neutral, extra: nil)
111
+ def lc_badge_class(tone: :neutral, shape: :rounded, extra: nil)
105
112
  tone = lc_option!(:tone, tone, BADGE_TONES.keys)
106
- lc_tw(BADGE_BASE, BADGE_TONES.fetch(tone), extra)
113
+ shape = lc_option!(:shape, shape, BADGE_SHAPES.keys)
114
+ lc_tw(BADGE_BASE, BADGE_SHAPES.fetch(shape), BADGE_TONES.fetch(tone), extra)
107
115
  end
108
116
 
109
117
  def lc_toggle_class(active: false, ghost: false, size: :md, extra: nil)
@@ -33,6 +33,53 @@ module Lostcoords::Ui
33
33
  destructive: "border border-transparent [--lc-button-bg:color-mix(in_oklab,var(--destructive)_60%,black)] [--lc-button-ink:#fff] bg-(--lc-button-bg) text-(--lc-button-ink) #{BUTTON_HOVER}"
34
34
  }.freeze
35
35
 
36
+ BUTTON_DESTRUCTIVE_INK = "text-destructive [--lc-button-ink:var(--destructive)]"
37
+
38
+ # A tone recolours a variant without changing its emphasis, so a destructive action can stay quiet.
39
+ BUTTON_TONES = {
40
+ default: BUTTON_VARIANTS.transform_values { "" },
41
+ destructive: {
42
+ primary: "[--lc-button-bg:color-mix(in_oklab,var(--destructive)_60%,black)] [--lc-button-ink:#fff]",
43
+ secondary: BUTTON_DESTRUCTIVE_INK,
44
+ outline: "#{BUTTON_DESTRUCTIVE_INK} border-[color-mix(in_oklab,var(--destructive)_32%,var(--border))]",
45
+ glass: BUTTON_DESTRUCTIVE_INK,
46
+ ghost: "#{BUTTON_DESTRUCTIVE_INK} [--lc-button-bg:color-mix(in_oklab,var(--destructive)_12%,var(--background))]",
47
+ destructive: ""
48
+ }
49
+ }.freeze
50
+
51
+ SELECT_TRIGGER_BASE =
52
+ "inline-flex items-center justify-start gap-related min-w-0 max-w-full ps-4 pe-3 " \
53
+ "rounded-pill border border-transparent bg-(--lc-field-bg,var(--input)) " \
54
+ "font-sans text-base text-start text-foreground whitespace-nowrap no-underline cursor-pointer " \
55
+ "transition-[background-color,color] duration-(--lc-motion-quick) ease-(--lc-ease-out) " \
56
+ "not-disabled:hover:bg-(--lc-input-hover) aria-expanded:bg-(--lc-input-hover) " \
57
+ "disabled:cursor-not-allowed disabled:text-[color-mix(in_oklab,var(--foreground)_38%,transparent)] " \
58
+ "[&_svg]:block [&_svg]:shrink-0 " \
59
+ "[&>[data-icon=inline-end]]:ms-auto [&>[data-icon=inline-end]]:size-5 [&>[data-icon=inline-end]]:text-muted-foreground " \
60
+ "motion-safe:[&>[data-icon=inline-end]]:transition-transform motion-safe:[&>[data-icon=inline-end]]:duration-(--lc-motion-quick) " \
61
+ "aria-expanded:[&>[data-icon=inline-end]]:rotate-180"
62
+
63
+ SPLIT_BUTTON_BASE = "relative inline-flex max-w-full min-w-0 items-stretch"
64
+
65
+ SPLIT_BUTTON_ACTION = "min-w-0 flex-1 rounded-e-none border-e-0"
66
+
67
+ # The two halves press as one pill, so neither lifts on its own.
68
+ SPLIT_BUTTON_PART = "motion-safe:not-disabled:hover:translate-y-0 motion-safe:not-disabled:active:translate-y-0"
69
+
70
+ SPLIT_BUTTON_TOGGLE =
71
+ "shrink-0 px-0 rounded-s-none aria-expanded:bg-[color-mix(in_oklab,var(--lc-button-bg,var(--secondary))_94%,var(--lc-button-ink,var(--foreground)))] [&_svg]:size-4 " \
72
+ "motion-safe:[&_svg]:transition-transform motion-safe:[&_svg]:duration-(--lc-motion-quick) aria-expanded:[&_svg]:rotate-180"
73
+
74
+ SPLIT_BUTTON_TOGGLE_WIDTHS = {
75
+ sm: "w-control-sm",
76
+ md: "w-control-md",
77
+ lg: "w-control-lg"
78
+ }.freeze
79
+
80
+ # Outline halves already share a visible edge; filled and transparent halves draw one from their ink.
81
+ SPLIT_BUTTON_DIVIDER = "border-s border-s-[color-mix(in_oklab,currentColor_24%,transparent)]"
82
+
36
83
  ICON_BUTTON_BASE =
37
84
  "lc-press inline-grid place-items-center shrink-0 border-0 bg-transparent " \
38
85
  "text-muted-foreground cursor-pointer no-underline " \
@@ -52,19 +99,34 @@ module Lostcoords::Ui
52
99
  lg: "size-control-lg [&_svg]:size-6"
53
100
  }.freeze
54
101
 
55
- def lc_button_class(variant: :primary, size: :md, block: false, extra: nil)
102
+ # A row action that stays out of the way until it is hovered, focused or open.
103
+ ICON_BUTTON_QUIET =
104
+ "focus-visible:text-foreground aria-expanded:text-foreground " \
105
+ "motion-safe:[&_svg]:transition-transform motion-safe:[&_svg]:duration-(--lc-motion-control) motion-safe:[&_svg]:ease-(--lc-ease-out-expo) " \
106
+ "motion-safe:not-disabled:hover:[&_svg]:scale-125 motion-safe:focus-visible:[&_svg]:scale-125 motion-safe:aria-expanded:[&_svg]:scale-125"
107
+
108
+ def lc_button_class(variant: :primary, tone: :default, size: :md, block: false, extra: nil)
56
109
  variant = lc_option!(:variant, variant, BUTTON_VARIANTS.keys)
110
+ tone = lc_option!(:tone, tone, BUTTON_TONES.keys)
57
111
  size = lc_option!(:size, size, BUTTON_SIZES.keys)
58
112
  lc_tw(
59
113
  BUTTON_BASE,
60
114
  BUTTON_SIZES.fetch(size),
61
115
  (lc_glass_class(shape: :bar) if variant == :glass),
62
116
  BUTTON_VARIANTS.fetch(variant),
117
+ BUTTON_TONES.fetch(tone).fetch(variant),
63
118
  ("w-full" if block),
64
119
  extra
65
120
  )
66
121
  end
67
122
 
123
+ # A button that reads as a select: start-aligned content and a trailing chevron that turns while
124
+ # aria-expanded is true. Use it for buttons that open a menu or picker.
125
+ def lc_select_trigger_class(size: :md, block: false, extra: nil)
126
+ size = lc_option!(:size, size, TailwindHelper::CONTROL_SIZES.keys)
127
+ lc_tw(SELECT_TRIGGER_BASE, TailwindHelper::CONTROL_SIZES.fetch(size), ("w-full" if block), extra)
128
+ end
129
+
68
130
  def lc_icon_button_class(shape: :square, size: :md, extra: nil)
69
131
  shape = lc_option!(:shape, shape, ICON_BUTTON_SHAPES.keys)
70
132
  size = lc_option!(:size, size, ICON_BUTTON_SIZES.keys)
@@ -28,7 +28,8 @@ module Lostcoords::Ui
28
28
  end
29
29
 
30
30
  # A native checkbox. unchecked_value: submits a value when unchecked, like Rails' check_box; pass nil to omit it.
31
- # A block adds content under the label, such as a preview inside a card: true tile.
31
+ # A block adds content under the label, such as a preview inside a card: true tile. A nil label renders the
32
+ # bare input for a row selector the row labels, which then needs aria: { label: }.
32
33
  def lc_checkbox(label, name: nil, value: "1", checked: false, unchecked_value: "0", hint: nil, card: false, **attributes, &block)
33
34
  lc_choice("checkbox", label, hint, card, name, unchecked_value, { type: "checkbox", name: name, value: value, checked: checked, class: lc_checkbox_class }, attributes, &block)
34
35
  end
@@ -42,28 +43,20 @@ module Lostcoords::Ui
42
43
  lc_choice("switch", label, hint, false, name, unchecked_value, { type: "checkbox", role: "switch", name: name, value: value, checked: checked, class: lc_switch_class }, attributes)
43
44
  end
44
45
 
45
- # A fieldset of checkboxes, radios or switches with a legend, hint and error. With an id, the
46
- # fieldset's aria-describedby points at the hint and error, as lc_field does for its control.
47
- def lc_choice_group(legend:, id: nil, hint: nil, error: nil, **attributes, &block)
48
- lc_label!(legend, :legend)
49
- errors = Array(error).compact_blank
50
- described = [ ("#{id}-hint" if id && hint.present?), ("#{id}-error" if id && errors.any?) ].compact.presence&.join(" ")
51
- defaults = { id: id, class: lc_field_class(extra: "m-0 min-w-0 border-0 p-0"), aria: { invalid: (true if errors.any?), describedby: described }, data: { slot: "choice-group", invalid: (true if errors.any?) } }
52
- tag.fieldset(**lc_attributes(defaults, attributes)) do
53
- safe_join([
54
- tag.legend(legend, class: lc_field_label_class(extra: "p-0"), data: { slot: "choice-group-legend" }),
55
- tag.div(class: "flex flex-col gap-related", &block),
56
- *lc_field_messages(id, hint, errors)
57
- ])
46
+ # lc_fieldset with its checkboxes, radios or switches stacked.
47
+ def lc_choice_group(legend:, **options, &block)
48
+ lc_fieldset(legend: legend, **lc_attributes({ data: { slot: "choice-group" } }, options)) do
49
+ tag.div(class: "flex flex-col gap-related", &block)
58
50
  end
59
51
  end
60
52
 
61
53
  private
62
54
  def lc_choice(slot, label, hint, card, name, unchecked_value, defaults, attributes, &block)
63
- lc_label!(label, :label)
64
55
  input = lc_attributes(defaults.merge(data: { slot: "#{slot}-input" }), attributes)
56
+ lc_label!(label || input.dig(:aria, :label), :label)
65
57
  hidden = hidden_field_tag(name, unchecked_value, id: nil, disabled: input[:disabled]) if name && !unchecked_value.nil?
66
- lc_choice_label(slot, label, hint, safe_join([ hidden, tag.input(**input) ].compact), card: card, &block)
58
+ control = safe_join([ hidden, tag.input(**input) ].compact)
59
+ label.nil? ? control : lc_choice_label(slot, label, hint, control, card: card, &block)
67
60
  end
68
61
 
69
62
  # Shared with Lostcoords::Ui::FormBuilder, which renders its own inputs.
@@ -1,9 +1,28 @@
1
1
  module Lostcoords::Ui
2
2
  module CollapsibleHelper
3
- def lc_collapsible(title:, open: false, **attributes, &block)
4
- lc_label!(title, :title)
5
- defaults = { class: lc_card_class(extra: "lc-collapsible"), open: open, data: { slot: "collapsible", controller: "lc-collapsible", action: "click->lc-collapsible#toggle" } }
6
- render "lostcoords/ui/components/lc_collapsible", title: title, attributes: lc_attributes(defaults, attributes), content: (capture(&block) if block)
3
+ COLLAPSIBLE_INDICATORS = %i[marker chevron none].freeze
4
+
5
+ # Yields a builder; `collapsible.summary do … end` replaces the title with your own markup.
6
+ # card: false drops the card surface. summary_class: styles the summary, such as a button class.
7
+ # indicator: :chevron swaps the native marker for a chevron that turns as it opens; it follows the
8
+ # summary's content, so push it to the end with me-auto on a summary element.
9
+ def lc_collapsible(title: nil, open: false, card: true, summary_class: nil, indicator: :marker, **attributes, &block)
10
+ indicator = lc_option!(:indicator, indicator, COLLAPSIBLE_INDICATORS)
11
+ parts = Parts::Collapsible.new(self)
12
+ content = capture(parts, &block) if block
13
+ summary = parts.summary_content || title
14
+ raise ArgumentError, "lc_collapsible needs a title: or a summary part" if summary.blank?
15
+ summary = tag.span(summary, class: "me-auto") if indicator == :chevron && parts.summary_content.nil?
16
+
17
+ summary_classes = lc_tw("cursor-pointer text-label font-semibold",
18
+ ("list-none [&::-webkit-details-marker]:hidden" unless indicator == :marker),
19
+ ("flex min-h-control-md items-center gap-related" if indicator == :chevron), summary_class)
20
+ chevron = lc_icon("chevron-down", variant: :mini, options: { class: "size-4 shrink-0 text-muted-foreground", aria: { hidden: true }, data: { slot: "collapsible-indicator" } }) if indicator == :chevron
21
+ defaults = { class: (card ? lc_card_class(extra: "lc-collapsible") : "lc-collapsible"), open: open, data: { slot: "collapsible", controller: "lc-collapsible", action: "click->lc-collapsible#toggle" } }
22
+ render "lostcoords/ui/components/lc_collapsible",
23
+ summary: safe_join([ summary, chevron ].compact),
24
+ summary_attributes: lc_attributes({ class: summary_classes, data: { slot: "collapsible-summary" } }, parts.summary_attributes),
25
+ attributes: lc_attributes(defaults, attributes), content: content
7
26
  end
8
27
  end
9
28
  end
@@ -6,26 +6,61 @@ module Lostcoords::Ui
6
6
 
7
7
  ANCHORED = "data-anchored:[inset:var(--lc-dialog-top)_var(--lc-dialog-right)_auto_auto] data-anchored:m-0"
8
8
 
9
+ # The desktop width reads --lc-dialog-width, so a caller can widen the dialog or size content to it.
10
+ DIALOG_WIDTH = "sm:w-[min(var(--lc-dialog-width),calc(100vw-2rem))]"
11
+
9
12
  DIALOGS = {
10
- modal: "lc-dialog #{SHEET_DIALOG_SURFACE} sm:w-[min(92vw,31rem)]",
13
+ modal: "lc-dialog #{SHEET_DIALOG_SURFACE} #{DIALOG_WIDTH} sm:max-h-[calc(100dvh-2rem)]",
11
14
  context:
12
- "lc-dialog lc-dialog-context #{SHEET_DIALOG_SURFACE} sm:w-[min(22rem,calc(100vw-2rem))] " \
15
+ "lc-dialog lc-dialog-context #{SHEET_DIALOG_SURFACE} #{DIALOG_WIDTH} [--lc-dialog-width:22rem] " \
13
16
  "sm:max-h-[calc(100dvh-2rem)] sm:origin-(--lc-dialog-origin,center) [--lc-dialog-from:scale(0.96)] #{ANCHORED}"
14
17
  }.freeze
15
18
 
16
- def lc_dialog_class(kind = :modal, extra: nil)
17
- lc_tw("lc-squircle", DIALOGS.fetch(lc_option!(:kind, kind, DIALOGS.keys)), extra)
19
+ # Desktop widths; below sm every dialog is a full-width sheet.
20
+ DIALOG_SIZES = {
21
+ sm: "[--lc-dialog-width:24rem]",
22
+ md: "[--lc-dialog-width:32rem]",
23
+ lg: "[--lc-dialog-width:40rem]",
24
+ xl: "[--lc-dialog-width:64rem]"
25
+ }.freeze
26
+
27
+ CONFIRM_SHEET_ID = "lc-confirm-sheet"
28
+
29
+ # size: :sm, :md, :lg or :xl. A modal defaults to :md; a context dialog keeps its compact width.
30
+ def lc_dialog_class(kind = :modal, size: nil, extra: nil)
31
+ kind = lc_option!(:kind, kind, DIALOGS.keys)
32
+ size = lc_option!(:size, size, DIALOG_SIZES.keys) unless size.nil?
33
+ size ||= :md if kind == :modal
34
+ lc_tw("lc-squircle", DIALOGS.fetch(kind), (DIALOG_SIZES.fetch(size) if size), extra)
18
35
  end
19
36
 
20
- # Yields a builder with footer and close parts.
21
- def lc_dialog(id:, title:, description: nil, trigger: lc_t("lostcoords.ui.dialog.trigger"), kind: :modal, detents: "fit", **attributes, &block)
37
+ # Yields a builder with actions, footer and close parts.
38
+ # trigger: false renders only the <dialog>, for a controller of your own to open; point close_action at it.
39
+ # title_attributes: and description_attributes: reach the heading and description, for a controller that rewrites them.
40
+ def lc_dialog(id:, title:, description: nil, trigger: lc_t("lostcoords.ui.dialog.trigger"), kind: :modal, size: nil, detents: "fit",
41
+ close_action: "lc-dialog#close", close_label: nil, title_attributes: {}, description_attributes: {}, **attributes, &block)
22
42
  lc_label!(id, :id)
23
43
  lc_label!(title, :title)
24
- lc_label!(trigger, :trigger)
25
- defaults = { class: lc_dialog_class(kind), aria: { describedby: ("#{id}-description" if description.present?) }, data: lc_sheet_data({ slot: "dialog" }, detents: detents) }
26
- required = { id: id, aria: { labelledby: "#{id}-title" }, data: { lc_dialog_target: "dialog" } }
27
- render "lostcoords/ui/components/lc_dialog", id: id, title: title, description: description, trigger: trigger,
28
- attributes: lc_attributes(defaults, attributes, required), content: (capture(Parts::Dialog.new(self, id), &block) if block)
44
+ lc_label!(trigger, :trigger) unless trigger == false
45
+ lc_label!(close_action, :close_action)
46
+ detents = lc_option!(:detents, detents, SheetHelper::SHEET_DETENTS.map(&:to_sym)).to_s
47
+ defaults = { class: lc_dialog_class(kind, size: size), aria: { describedby: ("#{id}-description" if description.present?) }, data: { slot: "dialog" } }
48
+ required = { id: id, aria: { labelledby: "#{id}-title" }, data: ({ lc_dialog_target: "dialog" } if trigger) }.compact
49
+ parts = Parts::Dialog.new(self, id, close_action)
50
+ content = capture(parts, &block) if block
51
+ title_tag = tag.h2(title, **lc_attributes({ class: lc_heading_class(size: :subheading), data: { slot: "dialog-title" } }, title_attributes, { id: "#{id}-title" }))
52
+ description_tag = tag.p(description, **lc_attributes({ class: lc_text_class(size: :small, tone: :muted), data: { slot: "dialog-description" } }, description_attributes, { id: "#{id}-description" })) if description.present?
53
+ render "lostcoords/ui/components/lc_dialog", id: id, title: title_tag, description: description_tag, trigger: trigger, detents: detents,
54
+ close_action: close_action, close_label: close_label || lc_t("lostcoords.ui.dialog.close", title: title),
55
+ attributes: lc_attributes(defaults, attributes, required), actions: parts.header_actions, content: content
56
+ end
57
+
58
+ # The sheet Turbo's confirm opens. Render it once in the layout and set
59
+ # Turbo.config.forms.confirm to `confirm` from lostcoords/ui/helpers/confirm.
60
+ def lc_confirm_sheet(**attributes)
61
+ defaults = { class: lc_dialog_class(:context), data: { slot: "confirm-sheet", turbo_permanent: true } }
62
+ required = { id: CONFIRM_SHEET_ID, tabindex: -1, aria: { labelledby: "#{CONFIRM_SHEET_ID}-message", describedby: "#{CONFIRM_SHEET_ID}-description" } }
63
+ render "lostcoords/ui/components/lc_confirm_sheet", id: CONFIRM_SHEET_ID, attributes: lc_attributes(defaults, attributes, required)
29
64
  end
30
65
  end
31
66
  end