lostcoords-ui 0.11.0 → 0.12.1
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 +147 -23
- data/app/assets/tailwind/lostcoords/ui/base.css +2 -2
- data/app/assets/tailwind/lostcoords/ui/core.css +2 -2
- data/app/assets/tailwind/lostcoords/ui/emoji-picker.css +1 -1
- data/app/helpers/lostcoords/ui/avatar_badge_helper.rb +43 -0
- data/app/helpers/lostcoords/ui/badge_helper.rb +20 -2
- data/app/helpers/lostcoords/ui/button_helper.rb +16 -4
- data/app/helpers/lostcoords/ui/card_helper.rb +3 -1
- data/app/helpers/lostcoords/ui/choice_helper.rb +1 -2
- data/app/helpers/lostcoords/ui/emoji_picker_helper.rb +5 -1
- data/app/helpers/lostcoords/ui/file_drop_helper.rb +32 -0
- data/app/helpers/lostcoords/ui/form_helper.rb +18 -4
- data/app/helpers/lostcoords/ui/layout_helper.rb +7 -3
- data/app/helpers/lostcoords/ui/list_group_helper.rb +38 -3
- data/app/helpers/lostcoords/ui/menu_helper.rb +23 -14
- data/app/helpers/lostcoords/ui/primitives_helper.rb +20 -12
- data/app/helpers/lostcoords/ui/render_attributes_helper.rb +1 -1
- data/app/helpers/lostcoords/ui/sheet_helper.rb +9 -3
- data/app/helpers/lostcoords/ui/structures_helper.rb +37 -17
- data/app/helpers/lostcoords/ui/typography_helper.rb +4 -2
- data/app/javascript/lostcoords/ui/controllers/lc_dialog_controller.js +2 -2
- data/app/javascript/lostcoords/ui/helpers/dialog.js +38 -4
- data/app/views/lostcoords/ui/components/_lc_dialog.html.erb +2 -1
- data/lib/lostcoords/ui/form_builder.rb +7 -0
- data/lib/lostcoords/ui/parts.rb +15 -0
- data/lib/lostcoords/ui/version.rb +1 -1
- metadata +3 -1
|
@@ -20,6 +20,18 @@ module Lostcoords::Ui
|
|
|
20
20
|
|
|
21
21
|
TOGGLE_GROUP_ITEM_ACTIVE = "lc-toggle-group-item-active bg-background text-foreground hover:text-foreground"
|
|
22
22
|
|
|
23
|
+
# :stacked puts each item's icon over its label; :adaptive makes the group full width and stacks
|
|
24
|
+
# its items only while the group itself is narrow.
|
|
25
|
+
TOGGLE_GROUP_LAYOUTS = { inline: nil, stacked: nil, adaptive: "@container/lc-toggle flex w-full" }.freeze
|
|
26
|
+
TOGGLE_GROUP_ITEM_LAYOUTS = {
|
|
27
|
+
inline: nil,
|
|
28
|
+
stacked: "flex-col h-auto min-h-control-sm gap-0.5 px-1.5 py-1.5 text-caption whitespace-normal text-center text-balance [&_svg]:size-5",
|
|
29
|
+
adaptive: "@max-sm/lc-toggle:flex-col @max-sm/lc-toggle:h-auto @max-sm/lc-toggle:gap-0.5 @max-sm/lc-toggle:px-1.5 " \
|
|
30
|
+
"@max-sm/lc-toggle:py-1.5 @max-sm/lc-toggle:text-caption @max-sm/lc-toggle:[&_svg]:size-5"
|
|
31
|
+
}.freeze
|
|
32
|
+
# A track wider than its container scrolls sideways, its edges fading while there is more to see.
|
|
33
|
+
TOGGLE_GROUP_SCROLL = "lc-scroll-fade-x max-w-full overflow-x-auto [scrollbar-width:none] *:shrink-0"
|
|
34
|
+
|
|
23
35
|
INPUT_BASE =
|
|
24
36
|
"w-full max-w-full min-w-0 " \
|
|
25
37
|
"px-3 " \
|
|
@@ -55,12 +67,14 @@ module Lostcoords::Ui
|
|
|
55
67
|
form_with(**options, builder: Lostcoords::Ui::FormBuilder, &block)
|
|
56
68
|
end
|
|
57
69
|
|
|
58
|
-
def lc_toggle_group_class(extra: nil)
|
|
59
|
-
|
|
70
|
+
def lc_toggle_group_class(layout: :inline, scroll: false, extra: nil)
|
|
71
|
+
layout = lc_option!(:layout, layout, TOGGLE_GROUP_LAYOUTS.keys)
|
|
72
|
+
lc_tw(TOGGLE_GROUP_BASE, TOGGLE_GROUP_LAYOUTS.fetch(layout), (TOGGLE_GROUP_SCROLL if scroll), extra)
|
|
60
73
|
end
|
|
61
74
|
|
|
62
|
-
def lc_toggle_group_item_class(active: false, extra: nil)
|
|
63
|
-
|
|
75
|
+
def lc_toggle_group_item_class(active: false, layout: :inline, extra: nil)
|
|
76
|
+
layout = lc_option!(:layout, layout, TOGGLE_GROUP_ITEM_LAYOUTS.keys)
|
|
77
|
+
lc_tw(TOGGLE_GROUP_ITEM_BASE, TOGGLE_GROUP_ITEM_LAYOUTS.fetch(layout), (TOGGLE_GROUP_ITEM_ACTIVE if active), extra)
|
|
64
78
|
end
|
|
65
79
|
|
|
66
80
|
def lc_input_class(size: :md, plain: false, extra: nil)
|
|
@@ -83,15 +83,19 @@ module Lostcoords::Ui
|
|
|
83
83
|
end
|
|
84
84
|
|
|
85
85
|
# anchor: true links the heading to the section's id:, for pages readers link into.
|
|
86
|
-
|
|
86
|
+
# header: :from_sm shows the heading row from sm up, for content that explains itself on a phone. Below
|
|
87
|
+
# sm the heading stays for screen readers (sr-only also takes it out of the stack gap) and the actions go.
|
|
88
|
+
def lc_section(title:, level: 2, actions: nil, anchor: false, header: :visible, **attributes, &block)
|
|
87
89
|
raise ArgumentError, "title must not be blank" if title.blank?
|
|
88
90
|
raise ArgumentError, "anchor: true needs an id" if anchor && attributes[:id].blank?
|
|
89
91
|
|
|
90
92
|
tag.section(**lc_attributes({ class: lc_stack_class(gap: :heading, extra: ("lc-anchor-target" if anchor)) }, attributes)) do
|
|
91
93
|
heading = lc_heading(title, level: level, size: :heading, anchor: (attributes[:id] if anchor))
|
|
92
94
|
action_content = actions.respond_to?(:call) ? capture(&actions) : actions
|
|
93
|
-
|
|
94
|
-
|
|
95
|
+
from_sm = lc_option!(:header, header, %i[visible from_sm]) == :from_sm
|
|
96
|
+
action_content = tag.div(action_content, class: "contents max-sm:hidden") if from_sm && action_content.present?
|
|
97
|
+
header_row = lc_section_header(class: ("max-sm:sr-only" if from_sm)) { safe_join([ heading, action_content ].compact) }
|
|
98
|
+
safe_join([ header_row, lc_stack(&block) ])
|
|
95
99
|
end
|
|
96
100
|
end
|
|
97
101
|
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
module Lostcoords::Ui
|
|
2
2
|
module ListGroupHelper
|
|
3
|
-
LIST_ROW = "lc-list-row min-w-0 bg-card text-card-foreground
|
|
3
|
+
LIST_ROW = "lc-list-row min-w-0 bg-card text-card-foreground lc-squircle"
|
|
4
|
+
# The group rounds its first and last shown children, whatever they are: a row, a field, or a
|
|
5
|
+
# collapsible of rows. A hidden row leaves the rounding to its next shown sibling.
|
|
6
|
+
LIST_GROUP =
|
|
7
|
+
"m-0 grid min-w-0 list-none gap-0.5 p-0 " \
|
|
8
|
+
"[&>:not([hidden]):not(:not([hidden])~*)]:rounded-t-3xl [&>:not([hidden]):not(:has(~:not([hidden])))]:rounded-b-3xl"
|
|
4
9
|
LIST_ITEM = "flex min-h-16 min-w-0 items-center gap-heading px-content py-heading text-start sm:px-inset"
|
|
5
10
|
LIST_ROW_PADDING = "px-content py-heading sm:px-inset"
|
|
6
11
|
LIST_ICON = "grid size-10 shrink-0 place-items-center rounded-full bg-tile [&>svg:not([class*='size-'])]:size-4.5"
|
|
@@ -14,6 +19,12 @@ module Lostcoords::Ui
|
|
|
14
19
|
"[&_:is(a[href],button,input,select,textarea,summary,[tabindex]):not([data-slot=list-link])]:relative " \
|
|
15
20
|
"[&_:is(a[href],button,input,select,textarea,summary,[tabindex]):not([data-slot=list-link])]:z-raised"
|
|
16
21
|
LIST_LINK = "text-inherit no-underline focus-visible:outline-none after:absolute after:inset-0 after:rounded-[inherit] after:content-['']"
|
|
22
|
+
# A label row around a hidden radio: the checked row fills, bolds and shows a trailing check, as
|
|
23
|
+
# a menuitemradio does. The global focus halo rings the row while its radio has focus.
|
|
24
|
+
LIST_ROW_CHOICE =
|
|
25
|
+
"group/choice flex items-center gap-heading cursor-pointer transition-colors duration-(--lc-motion-quick) " \
|
|
26
|
+
"hover:bg-accent has-checked:bg-primary-soft has-checked:font-semibold has-disabled:cursor-not-allowed has-disabled:opacity-45"
|
|
27
|
+
LIST_ROW_CHOICE_CHECK = "ms-auto size-4 shrink-0 text-primary invisible group-has-checked/choice:visible"
|
|
17
28
|
LIST_FIELD_TAGS = %i[div fieldset span].freeze
|
|
18
29
|
LIST_FIELD = "@container px-content py-2.5 transition-colors duration-(--lc-motion-quick) has-[[data-plain]:focus]:bg-accent"
|
|
19
30
|
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)]"
|
|
@@ -41,7 +52,7 @@ module Lostcoords::Ui
|
|
|
41
52
|
# first and last rows round.
|
|
42
53
|
def lc_list_group(tag: :div, **attributes, &block)
|
|
43
54
|
tag = lc_option!(:tag, tag, %i[div ul])
|
|
44
|
-
content_tag(tag, (capture(&block) if block), **lc_attributes({ class:
|
|
55
|
+
content_tag(tag, (capture(&block) if block), **lc_attributes({ class: LIST_GROUP, data: { slot: "list-group" } }, attributes))
|
|
45
56
|
end
|
|
46
57
|
|
|
47
58
|
# With a title, the row lays out icon:, the title and subtitle, then the block as its trailing
|
|
@@ -49,7 +60,13 @@ module Lostcoords::Ui
|
|
|
49
60
|
# content that pads itself, such as an lc_list_item button. href: makes the row a link. On an li
|
|
50
61
|
# or div row, the title is the link and covers the row, so the block can hold buttons and links
|
|
51
62
|
# of its own; a click elsewhere in the row follows the title.
|
|
52
|
-
|
|
63
|
+
# choice: :radio makes the row one choice of a radio group: a label around a hidden radio named
|
|
64
|
+
# name: with value:, then the title or block, then a check shown while checked:. input: adds
|
|
65
|
+
# attributes to the radio.
|
|
66
|
+
def lc_list_row(title = nil, subtitle: nil, icon: nil, href: nil, tag: nil, padded: true, choice: nil, name: nil, value: nil, checked: false, input: {}, **attributes, &block)
|
|
67
|
+
return lc_list_choice_row(title, choice, name, value, checked, input, attributes, &block) if choice
|
|
68
|
+
raise ArgumentError, "name:, value:, checked: and input: belong to a choice: row" if name || value || checked || input.any?
|
|
69
|
+
|
|
53
70
|
tag = lc_option!(:tag, tag || (href ? :a : :div), LIST_ROW_TAGS)
|
|
54
71
|
titled = href && tag != :a
|
|
55
72
|
raise ArgumentError, "href: needs tag: :a, :li or :div" if titled && !%i[li div].include?(tag)
|
|
@@ -63,6 +80,24 @@ module Lostcoords::Ui
|
|
|
63
80
|
content_tag(tag, (capture(&block) if block), **lc_attributes(defaults.merge(class: classes), attributes))
|
|
64
81
|
end
|
|
65
82
|
|
|
83
|
+
private def lc_list_choice_row(title, choice, name, value, checked, input, attributes, &block)
|
|
84
|
+
lc_option!(:choice, choice, %i[radio])
|
|
85
|
+
lc_label!(name, :name)
|
|
86
|
+
raise ArgumentError, "a choice row needs value:" if value.nil?
|
|
87
|
+
raise ArgumentError, "a choice row takes a title or a block, not both" if title.present? && block
|
|
88
|
+
|
|
89
|
+
attributes = attributes.dup
|
|
90
|
+
input = input.merge(disabled: attributes.delete(:disabled)) if attributes.key?(:disabled)
|
|
91
|
+
content = block ? capture(&block) : content_tag(:span, title, class: "min-w-0", data: { slot: "list-title" })
|
|
92
|
+
content_tag(:label, **lc_attributes({ class: lc_tw(LIST_ROW, LIST_ROW_PADDING, LIST_ROW_CHOICE), data: { slot: "list-row", choice: "radio" } }, attributes)) do
|
|
93
|
+
safe_join([
|
|
94
|
+
radio_button_tag(name, value, checked, **lc_attributes({ class: "sr-only" }, input)),
|
|
95
|
+
content,
|
|
96
|
+
lc_icon("check", variant: :mini, options: { class: LIST_ROW_CHOICE_CHECK, "aria-hidden": true })
|
|
97
|
+
])
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
66
101
|
# A form row: a label column, then the block as the control. In a narrow row the label folds to
|
|
67
102
|
# icon: alone and stays the accessible name. id: makes the label a <label> for that control;
|
|
68
103
|
# tag: :fieldset names a group of controls with a legend. surface: false drops the row's panel,
|
|
@@ -15,6 +15,12 @@ module Lostcoords::Ui
|
|
|
15
15
|
center: "start-1/2 end-auto -translate-x-1/2"
|
|
16
16
|
}.freeze
|
|
17
17
|
|
|
18
|
+
# Below the trigger by default; :top opens upward, for a menu near the bottom of the screen.
|
|
19
|
+
MENU_POPOVER_SIDES = {
|
|
20
|
+
bottom: "",
|
|
21
|
+
top: "top-auto bottom-[calc(100%+--spacing(1))] [--lc-popover-from:translateY(--spacing(1))_scale(0.98)]"
|
|
22
|
+
}.freeze
|
|
23
|
+
|
|
18
24
|
MENU_OPTION_BASE =
|
|
19
25
|
"lc-menu__item lc-press [--lc-press-scale:0.98] group/option grid col-span-full grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-x-3 w-full " \
|
|
20
26
|
"min-h-control-md px-3 py-1.5 rounded-2xl lc-squircle border-none bg-transparent text-start font-sans text-label text-foreground " \
|
|
@@ -38,12 +44,14 @@ module Lostcoords::Ui
|
|
|
38
44
|
MENU_GROUP_BASE = "col-span-full grid grid-cols-subgrid gap-y-px"
|
|
39
45
|
MENU_GROUP_LABEL = "col-span-full px-3 pt-2 pb-1"
|
|
40
46
|
|
|
41
|
-
def lc_popover_class(align: :end, extra: nil)
|
|
42
|
-
|
|
47
|
+
def lc_popover_class(align: :end, side: :bottom, extra: nil)
|
|
48
|
+
align = MENU_POPOVER_ALIGN.fetch(lc_option!(:align, align, MENU_POPOVER_ALIGN.keys))
|
|
49
|
+
side = MENU_POPOVER_SIDES.fetch(lc_option!(:side, side, MENU_POPOVER_SIDES.keys))
|
|
50
|
+
lc_glass_class(shape: :menu, extra: lc_tw(POPOVER_BASE, align, side, extra))
|
|
43
51
|
end
|
|
44
52
|
|
|
45
|
-
def lc_menu_popover_class(align: :end, extra: nil)
|
|
46
|
-
lc_popover_class(align: align, extra: lc_tw(MENU_POPOVER_BASE, extra))
|
|
53
|
+
def lc_menu_popover_class(align: :end, side: :bottom, extra: nil)
|
|
54
|
+
lc_popover_class(align: align, side: side, extra: lc_tw(MENU_POPOVER_BASE, extra))
|
|
47
55
|
end
|
|
48
56
|
|
|
49
57
|
def lc_menu_option_class(tone: :default, extra: nil)
|
|
@@ -51,11 +59,11 @@ module Lostcoords::Ui
|
|
|
51
59
|
end
|
|
52
60
|
|
|
53
61
|
# trigger: :icon renders a quiet icon button named by label; rendered HTML becomes the content
|
|
54
|
-
# of a custom trigger, also named by label.
|
|
55
|
-
def lc_menu(id:, label: lc_t("lostcoords.ui.menu.label"), align: :end, trigger: :button, icon: "ellipsis-vertical", trigger_attributes: {}, wrapper_attributes: {}, **attributes, &block)
|
|
56
|
-
|
|
57
|
-
default_trigger = ->(wiring) { lc_panel_trigger(label, trigger, icon, :secondary, wiring) } unless trigger == false
|
|
58
|
-
lc_render_panel(id, label, nil, "lc-menu", "menu", lc_menu_popover_class(align: align), lc_attributes({ data: { slot: "menu" } }, attributes), default_trigger, trigger_attributes, wrapper_attributes, &block)
|
|
62
|
+
# of a custom trigger, also named by label. trigger_size: sizes either one.
|
|
63
|
+
def lc_menu(id:, label: lc_t("lostcoords.ui.menu.label"), align: :end, side: :bottom, trigger: :button, trigger_size: :md, icon: "ellipsis-vertical", trigger_attributes: {}, wrapper_attributes: {}, **attributes, &block)
|
|
64
|
+
trigger_size = lc_option!(:trigger_size, trigger_size, ButtonHelper::ICON_BUTTON_SIZES.keys)
|
|
65
|
+
default_trigger = ->(wiring) { lc_panel_trigger(label, trigger, icon, :secondary, wiring, trigger_size) } unless trigger == false
|
|
66
|
+
lc_render_panel(id, label, nil, "lc-menu", "menu", lc_menu_popover_class(align: align, side: side), lc_attributes({ data: { slot: "menu" } }, attributes), default_trigger, trigger_attributes, wrapper_attributes, &block)
|
|
59
67
|
end
|
|
60
68
|
|
|
61
69
|
# Takes the same trigger options as lc_menu, including trigger: false.
|
|
@@ -70,8 +78,9 @@ module Lostcoords::Ui
|
|
|
70
78
|
# icon: names a leading Heroicon; leading: takes other rendered content, such as an avatar, and is
|
|
71
79
|
# hidden from assistive technology so the label stays the name. checked: true or false makes a
|
|
72
80
|
# menuitemradio with a check mark. checkbox: true makes a menuitemcheckbox that flips on click and
|
|
73
|
-
# leaves the menu open. method: renders a button_to form for href
|
|
74
|
-
|
|
81
|
+
# leaves the menu open. method: renders a button_to form for href, with form_attributes: on the
|
|
82
|
+
# form. form: is the button's own attribute, naming a form elsewhere on the page to submit.
|
|
83
|
+
def lc_menu_option(label = nil, href: nil, tone: :default, icon: nil, leading: nil, hint: nil, checked: nil, checkbox: false, method: nil, params: {}, form_attributes: {}, **attributes, &block)
|
|
75
84
|
tone = lc_option!(:tone, tone, MENU_OPTION_TONES.keys)
|
|
76
85
|
raise ArgumentError, "Pass icon: or leading:, not both" if icon && leading
|
|
77
86
|
raise ArgumentError, "checked: must be true, false or nil" unless [ true, false, nil ].include?(checked)
|
|
@@ -91,7 +100,7 @@ module Lostcoords::Ui
|
|
|
91
100
|
defaults[:aria] = { checked: checked } unless checked.nil?
|
|
92
101
|
|
|
93
102
|
if method
|
|
94
|
-
button_to(content, href, **lc_attributes(defaults, attributes), method: method, params: params, form: lc_attributes({ class: "contents" },
|
|
103
|
+
button_to(content, href, **lc_attributes(defaults, attributes), method: method, params: params, form: lc_attributes({ class: "contents" }, form_attributes))
|
|
95
104
|
elsif href
|
|
96
105
|
raise ArgumentError, "Links cannot be disabled; use a menu button instead" if attributes[:disabled] || attributes["disabled"]
|
|
97
106
|
|
|
@@ -110,13 +119,13 @@ module Lostcoords::Ui
|
|
|
110
119
|
end
|
|
111
120
|
|
|
112
121
|
private
|
|
113
|
-
def lc_panel_trigger(label, trigger, icon, variant, attributes)
|
|
122
|
+
def lc_panel_trigger(label, trigger, icon, variant, attributes, size = :md)
|
|
114
123
|
custom = trigger.is_a?(String) && trigger.html_safe?
|
|
115
124
|
kind = custom ? :custom : lc_option!(:trigger, trigger, MENU_TRIGGERS)
|
|
116
125
|
case kind
|
|
117
126
|
when :custom, :icon
|
|
118
127
|
content = custom ? trigger : lc_icon(icon, options: { "aria-hidden": true })
|
|
119
|
-
icon_button = { type: "button", class: lc_icon_button_class(shape: :circle, size:
|
|
128
|
+
icon_button = { type: "button", class: lc_icon_button_class(shape: :circle, size: size, extra: ButtonHelper::ICON_BUTTON_QUIET), aria: { label: label }, data: { slot: "icon-button" } }
|
|
120
129
|
tag.button(content, **lc_attributes(icon_button, attributes))
|
|
121
130
|
else
|
|
122
131
|
lc_button(label, variant: variant, **attributes)
|
|
@@ -37,7 +37,7 @@ module Lostcoords::Ui
|
|
|
37
37
|
content = capture(&content_block)
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
-
button_to(lc_button_content(content, icon, icon_position), url, lc_button_attributes(variant, tone, size, block, {}, attributes))
|
|
40
|
+
button_to(lc_button_content(content, icon, icon_position), url, lc_button_attributes(variant, tone, size, block, {}, lc_button_form(attributes)))
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
# A button styled as a select for opening a menu or picker. A string label truncates; a block
|
|
@@ -86,21 +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, tooltip: nil, **attributes, &content)
|
|
90
|
-
attributes = lc_icon_button_attributes(label, size, shape, variant, tone, { type: "button" }, attributes)
|
|
89
|
+
def lc_icon_button(label, icon: nil, size: :md, icon_size: size, shape: :circle, variant: :ghost, tone: :default, tooltip: nil, **attributes, &content)
|
|
90
|
+
attributes = lc_icon_button_attributes(label, size, icon_size, shape, variant, tone, { type: "button" }, attributes)
|
|
91
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, tooltip: nil, **attributes, &content)
|
|
95
|
-
attributes = lc_icon_button_attributes(label, size, shape, variant, tone, {}, attributes)
|
|
94
|
+
def lc_icon_button_link_to(label, url, icon: nil, size: :md, icon_size: size, shape: :circle, variant: :ghost, tone: :default, tooltip: nil, **attributes, &content)
|
|
95
|
+
attributes = lc_icon_button_attributes(label, size, icon_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
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, 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)) }
|
|
101
|
+
def lc_icon_button_to(label, url, icon: nil, size: :md, icon_size: size, shape: :circle, variant: :ghost, tone: :default, tooltip: nil, **attributes, &content)
|
|
102
|
+
attributes = lc_icon_button_attributes(label, size, icon_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(lc_button_form(attributes), tip)) }
|
|
104
104
|
end
|
|
105
105
|
|
|
106
106
|
def lc_badge(content = nil, tone: :neutral, shape: :rounded, **attributes, &block)
|
|
@@ -133,8 +133,9 @@ module Lostcoords::Ui
|
|
|
133
133
|
end
|
|
134
134
|
|
|
135
135
|
# row: takes attributes for the inner row that overlaps the avatars, such as a controller target.
|
|
136
|
-
|
|
137
|
-
|
|
136
|
+
# size: pins every avatar in the stack to one lc_avatar size; overlap: :sm tightens it for a line of text.
|
|
137
|
+
def lc_avatar_stack(compact: false, size: :md, overlap: :md, row: {}, **attributes, &block)
|
|
138
|
+
tag.span(**lc_attributes({ class: lc_avatar_stack_class(compact: compact, size: size, overlap: overlap), data: { slot: "avatar-stack" } }, attributes)) do
|
|
138
139
|
tag.span(**lc_attributes({ class: lc_avatar_stack_row_class }, row), &block)
|
|
139
140
|
end
|
|
140
141
|
end
|
|
@@ -222,11 +223,11 @@ module Lostcoords::Ui
|
|
|
222
223
|
lc_attributes(defaults.merge(class: lc_button_class(variant: variant, tone: tone, size: size, block: block), data: data), attributes)
|
|
223
224
|
end
|
|
224
225
|
|
|
225
|
-
def lc_icon_button_attributes(label, size, shape, variant, tone, defaults, attributes)
|
|
226
|
+
def lc_icon_button_attributes(label, size, icon_size, shape, variant, tone, defaults, attributes)
|
|
226
227
|
size = lc_option!(:size, size, ButtonHelper::ICON_BUTTON_SIZES.keys)
|
|
227
228
|
shape = lc_option!(:shape, shape, ButtonHelper::ICON_BUTTON_SHAPES.keys)
|
|
228
229
|
data = { slot: "icon-button", size: size, variant: (variant.to_sym unless variant.to_sym == :ghost), tone: (tone.to_sym unless tone.to_sym == :default) }.compact
|
|
229
|
-
defaults = defaults.merge(class: lc_icon_button_class(size: size, shape: shape, variant: variant, tone: tone), aria: { label: label }, data: data)
|
|
230
|
+
defaults = defaults.merge(class: lc_icon_button_class(size: size, icon_size: icon_size, shape: shape, variant: variant, tone: tone), aria: { label: label }, data: data)
|
|
230
231
|
attributes = lc_attributes(defaults, attributes)
|
|
231
232
|
accessible_label = attributes.fetch(:"aria-label", attributes.dig(:aria, :label))
|
|
232
233
|
raise ArgumentError, "lc_icon_button requires a nonblank accessible label" if label.blank? || accessible_label.blank?
|
|
@@ -244,6 +245,13 @@ module Lostcoords::Ui
|
|
|
244
245
|
lc_tooltip(text, id: id) { |tip| yield(tip) }
|
|
245
246
|
end
|
|
246
247
|
|
|
248
|
+
# button_to's form is a box of its own; contents lets the button sit in the caller's row or grid.
|
|
249
|
+
def lc_button_form(attributes)
|
|
250
|
+
attributes = attributes.dup
|
|
251
|
+
form = attributes.delete(:form) || attributes.delete("form") || {}
|
|
252
|
+
attributes.merge(form: lc_attributes({ class: "contents" }, form))
|
|
253
|
+
end
|
|
254
|
+
|
|
247
255
|
def lc_icon_button_content(icon, &content)
|
|
248
256
|
raise ArgumentError, "Pass icon: or a block" unless icon || content
|
|
249
257
|
|
|
@@ -55,7 +55,7 @@ module Lostcoords::Ui
|
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
def lc_option!(name, value, allowed)
|
|
58
|
-
normalized = value.is_a?(
|
|
58
|
+
normalized = value.is_a?(Numeric) ? value : (value.to_sym if value.is_a?(String) || value.is_a?(Symbol))
|
|
59
59
|
return normalized if allowed.include?(normalized)
|
|
60
60
|
|
|
61
61
|
raise ArgumentError, "Invalid #{name}: #{value.inspect}. Expected one of: #{allowed.map(&:inspect).join(', ')}"
|
|
@@ -2,6 +2,7 @@ module Lostcoords::Ui
|
|
|
2
2
|
module SheetHelper
|
|
3
3
|
SHEET_TAGS = %i[div dialog].freeze
|
|
4
4
|
SHEET_DETENTS = [ "fit", "medium large", "large" ].freeze
|
|
5
|
+
SHEET_SURFACES = %i[glass].freeze
|
|
5
6
|
SHEET_HANDLE = "grid min-h-7 w-full flex-none cursor-grab touch-none place-items-center active:cursor-grabbing sm:hidden"
|
|
6
7
|
|
|
7
8
|
# A panel that is an iOS sheet on phones, with the lc-sheet controller. tag: :dialog is a modal
|
|
@@ -12,17 +13,22 @@ module Lostcoords::Ui
|
|
|
12
13
|
# A swipe down dispatches lc-sheet:dismiss; unless a listener cancels it, an open popover hides.
|
|
13
14
|
# With tag: :dialog, size: draws lc_dialog's modal frame at that width, for a dialog whose content
|
|
14
15
|
# brings its own header and labels the dialog with aria-label.
|
|
15
|
-
|
|
16
|
+
# surface: :glass draws a :div in the translucent menu material, a menu on desktop and a sheet on phones.
|
|
17
|
+
# Yields a builder whose header and footer parts stay pinned while the content scrolls.
|
|
18
|
+
def lc_sheet(tag: :div, anchored: false, detents: "fit", handle: false, size: nil, surface: nil, **attributes, &block)
|
|
16
19
|
tag = lc_option!(:tag, tag, SHEET_TAGS)
|
|
17
20
|
detents = lc_option!(:detents, detents, SHEET_DETENTS.map(&:to_sym)).to_s
|
|
21
|
+
surface = lc_option!(:surface, surface, SHEET_SURFACES) unless surface.nil?
|
|
18
22
|
raise ArgumentError, "anchored: true needs tag: :div" if anchored && tag == :dialog
|
|
19
23
|
raise ArgumentError, "size: needs tag: :dialog" if size && tag != :dialog
|
|
24
|
+
raise ArgumentError, "surface: :glass needs tag: :div" if surface && tag == :dialog
|
|
20
25
|
|
|
21
26
|
defaults = { data: { slot: "sheet", controller: "lc-sheet", lc_sheet_detents_value: detents } }
|
|
22
|
-
defaults[:class] = lc_tw("lc-sheet", ("lc-sheet-anchored" if anchored)) unless tag == :dialog
|
|
27
|
+
defaults[:class] = lc_tw("lc-sheet", ("lc-sheet-anchored" if anchored), (lc_glass_class(shape: :picker) if surface == :glass)) unless tag == :dialog
|
|
23
28
|
defaults[:class] = lc_dialog_class(size: size) if size
|
|
24
29
|
strip = self.tag.span(class: SHEET_HANDLE, aria: { hidden: true }, data: { slot: "sheet-handle", lc_sheet_target: "handle" }) if handle
|
|
25
|
-
|
|
30
|
+
content = capture(Parts::Sheet.new(self), &block) if block
|
|
31
|
+
content_tag(tag, safe_join([ strip, content ].compact), **lc_attributes(defaults, attributes))
|
|
26
32
|
end
|
|
27
33
|
end
|
|
28
34
|
end
|
|
@@ -3,10 +3,21 @@ module Lostcoords::Ui
|
|
|
3
3
|
INPUT_TYPES = %i[text search email password tel url number date time datetime-local month week].freeze
|
|
4
4
|
|
|
5
5
|
# plain: true drops the fill, border, padding and height, for a control in an lc_list_field row.
|
|
6
|
-
|
|
6
|
+
INPUT_ICON = "pointer-events-none absolute start-3.5 size-4.5 text-muted-foreground"
|
|
7
|
+
|
|
8
|
+
# icon: draws a leading icon inside the field, such as a magnifying glass on a search field; the field
|
|
9
|
+
# comes wrapped in a span then, and class: and the other attributes still reach the <input>.
|
|
10
|
+
def lc_input(name: nil, value: nil, type: :text, size: :md, plain: false, icon: nil, **attributes)
|
|
7
11
|
type = lc_option!(:type, type, INPUT_TYPES)
|
|
12
|
+
raise ArgumentError, "icon: needs a field; plain: true has no room for one" if icon && plain
|
|
13
|
+
|
|
8
14
|
data = { slot: "input", plain: (true if plain) }.compact
|
|
9
|
-
tag.input(**lc_attributes({ type: type, name: name, value: value, class: lc_input_class(size: size, plain: plain), data: data }, attributes))
|
|
15
|
+
input = tag.input(**lc_attributes({ type: type, name: name, value: value, class: lc_input_class(size: size, plain: plain, extra: ("ps-10" if icon)), data: data }, attributes))
|
|
16
|
+
return input unless icon
|
|
17
|
+
|
|
18
|
+
tag.span(class: "relative flex min-w-0 items-center", data: { slot: "input-group" }) do
|
|
19
|
+
safe_join([ lc_icon(icon, options: { class: INPUT_ICON, "aria-hidden": true }), input ])
|
|
20
|
+
end
|
|
10
21
|
end
|
|
11
22
|
|
|
12
23
|
def lc_textarea(content = nil, name: nil, **attributes, &block)
|
|
@@ -97,18 +108,21 @@ module Lostcoords::Ui
|
|
|
97
108
|
# as: :nav makes links, the current one marked with aria-current; otherwise radio buttons whose
|
|
98
109
|
# selection lives in the lc-selection controller.
|
|
99
110
|
# variant: :pills lays the items out as wrapping toggle pills, sized by size:, instead of a segmented track.
|
|
100
|
-
|
|
111
|
+
# layout: and scroll: shape the segmented track; see lc_toggle_group_class.
|
|
112
|
+
def lc_toggle_group(label:, name: nil, value: nil, as: :div, variant: :segmented, size: :md, layout: :inline, scroll: false, **attributes, &block)
|
|
101
113
|
lc_label!(label, :label)
|
|
102
114
|
as = lc_option!(:as, as, %i[div nav])
|
|
103
115
|
variant = lc_option!(:variant, variant, %i[segmented pills])
|
|
104
116
|
size = lc_option!(:size, size, ButtonHelper::BUTTON_SIZES.keys)
|
|
117
|
+
layout = lc_option!(:layout, layout, FormHelper::TOGGLE_GROUP_LAYOUTS.keys)
|
|
105
118
|
raise ArgumentError, "size: sizes pills; a segmented toggle group has one size" if variant == :segmented && size != :md
|
|
119
|
+
raise ArgumentError, "layout: and scroll: shape a segmented track; pills wrap" if variant == :pills && (layout != :inline || scroll)
|
|
106
120
|
raise ArgumentError, "a nav toggle group marks its current link; it takes no name: or value:" if as == :nav && (name || value)
|
|
107
121
|
|
|
108
122
|
mode = as == :nav ? :links : (name ? :radios : :buttons)
|
|
109
|
-
content = lc_within_toggle_group({ mode: mode, name: name, value: value&.to_s, variant: variant, size: size }) { capture(&block) if block }
|
|
123
|
+
content = lc_within_toggle_group({ mode: mode, name: name, value: value&.to_s, variant: variant, size: size, layout: layout }) { capture(&block) if block }
|
|
110
124
|
|
|
111
|
-
defaults = { class: (variant == :pills ? lc_inline_class : lc_toggle_group_class), data: { slot: "toggle-group" } }
|
|
125
|
+
defaults = { class: (variant == :pills ? lc_inline_class : lc_toggle_group_class(layout: layout, scroll: scroll)), data: { slot: "toggle-group" } }
|
|
112
126
|
case mode
|
|
113
127
|
when :links
|
|
114
128
|
tag.nav(content, **lc_attributes(defaults, attributes, { aria: { label: label } }))
|
|
@@ -121,17 +135,19 @@ module Lostcoords::Ui
|
|
|
121
135
|
end
|
|
122
136
|
|
|
123
137
|
# Takes href: and current: in a nav group, value: and checked: in a named group, and value: and
|
|
124
|
-
# selected: in a button group; arguments from another kind of group raise.
|
|
125
|
-
|
|
126
|
-
|
|
138
|
+
# selected: in a button group; arguments from another kind of group raise. icon: and icon_only:
|
|
139
|
+
# work as on lc_toggle.
|
|
140
|
+
def lc_toggle_group_item(label = nil, value: nil, selected: nil, checked: nil, href: nil, current: nil, input: {}, icon: nil, icon_only: false, **attributes, &block)
|
|
141
|
+
group = @_lc_toggle_group || { mode: :buttons, variant: :segmented, layout: :inline }
|
|
127
142
|
given = { value: value, selected: selected, checked: checked, href: href, current: current }.compact.keys
|
|
128
143
|
allowed = { links: %i[href current], radios: %i[value checked], buttons: %i[value selected] }.fetch(group[:mode])
|
|
129
144
|
stray = given - allowed
|
|
130
145
|
raise ArgumentError, "#{stray.join(', ')} can't be used on an item of a #{group[:mode]} toggle group" if stray.any?
|
|
131
146
|
raise ArgumentError, "an item of a nav toggle group needs href:" if group[:mode] == :links && !href
|
|
132
147
|
|
|
133
|
-
content =
|
|
134
|
-
|
|
148
|
+
content = lc_toggle_content(label, icon, icon_only, &block)
|
|
149
|
+
item_class = group[:variant] == :pills ? lc_toggle_class(size: group[:size]) : lc_toggle_group_item_class(layout: group[:layout] || :inline)
|
|
150
|
+
defaults = { class: lc_tw(item_class, (TOGGLE_ICON_ONLY if icon_only)), data: { slot: "toggle-group-item", icon_only: (true if icon_only) }.compact }
|
|
135
151
|
return lc_toggle_link(content, href, current, defaults, attributes) if group[:mode] == :links
|
|
136
152
|
|
|
137
153
|
value ||= label
|
|
@@ -154,13 +170,7 @@ module Lostcoords::Ui
|
|
|
154
170
|
# the label stays as its accessible name. tooltip: true shows the label on hover and focus, and
|
|
155
171
|
# tooltip: "text" describes the toggle with other text, as on lc_icon_button.
|
|
156
172
|
def lc_toggle(label = nil, active: false, ghost: false, size: :md, href: nil, name: nil, value: nil, input: {}, icon: nil, icon_only: false, tooltip: nil, **attributes, &block)
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
content = block ? capture(&block) : label
|
|
160
|
-
if icon
|
|
161
|
-
glyph = lc_icon(icon, options: { "aria-hidden": true, "data-icon": ("inline-start" unless icon_only) }.compact)
|
|
162
|
-
content = safe_join([ glyph, (icon_only ? tag.span(label, class: "sr-only") : content) ])
|
|
163
|
-
end
|
|
173
|
+
content = lc_toggle_content(label, icon, icon_only, &block)
|
|
164
174
|
defaults = { class: lc_toggle_class(ghost: ghost, size: size, extra: (TOGGLE_ICON_ONLY if icon_only)), data: { slot: "toggle", icon_only: (true if icon_only) }.compact }
|
|
165
175
|
lc_icon_button_tooltip(label, tooltip, attributes) do |tip|
|
|
166
176
|
attributes = lc_attributes(attributes, tip)
|
|
@@ -183,6 +193,16 @@ module Lostcoords::Ui
|
|
|
183
193
|
end
|
|
184
194
|
|
|
185
195
|
private
|
|
196
|
+
def lc_toggle_content(label, icon, icon_only, &block)
|
|
197
|
+
raise ArgumentError, "icon_only: true needs icon: and a label, not a block" if icon_only && (icon.nil? || label.blank? || block)
|
|
198
|
+
|
|
199
|
+
content = block ? capture(&block) : label
|
|
200
|
+
return content unless icon
|
|
201
|
+
|
|
202
|
+
glyph = lc_icon(icon, options: { "aria-hidden": true, "data-icon": ("inline-start" unless icon_only) }.compact)
|
|
203
|
+
safe_join([ glyph, (icon_only ? tag.span(label, class: "sr-only") : content) ])
|
|
204
|
+
end
|
|
205
|
+
|
|
186
206
|
# Items read the enclosing group's mode, so a nested group restores the outer one.
|
|
187
207
|
def lc_within_toggle_group(group)
|
|
188
208
|
previous, @_lc_toggle_group = @_lc_toggle_group, group
|
|
@@ -26,7 +26,8 @@ module Lostcoords::Ui
|
|
|
26
26
|
|
|
27
27
|
# anchor: true links the heading to itself, so readers can copy a link to it; it needs id:.
|
|
28
28
|
# anchor: "section-id" links it to an element around it instead, such as its <section>.
|
|
29
|
-
|
|
29
|
+
# as: :span or :div sets text in a heading role without making it a heading, such as an amount in a row.
|
|
30
|
+
def lc_heading(content = nil, level: 2, size: :heading, trim: false, anchor: false, as: nil, **attributes, &block)
|
|
30
31
|
raise ArgumentError, "Invalid level: #{level.inspect}. Expected an integer from 1 to 6" unless (1..6).include?(level) && level.is_a?(Integer)
|
|
31
32
|
|
|
32
33
|
target = anchor == true ? attributes[:id].to_s : anchor.presence&.to_s
|
|
@@ -34,7 +35,8 @@ module Lostcoords::Ui
|
|
|
34
35
|
|
|
35
36
|
content = capture(&block) if block
|
|
36
37
|
content = tag.a(content, href: "##{target}", class: "lc-anchor", data: { slot: "heading-anchor" }) if target
|
|
37
|
-
|
|
38
|
+
element = as ? lc_option!(:as, as, %i[span div]) : "h#{level}"
|
|
39
|
+
tag.public_send(element, content, **lc_attributes({ class: lc_heading_class(size: size, trim: trim, extra: ("lc-anchor-target" if anchor == true)) }, attributes))
|
|
38
40
|
end
|
|
39
41
|
|
|
40
42
|
# as: picks the element, such as :span inside a row or :h3 for a heading set in a text role.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Controller } from "@hotwired/stimulus"
|
|
2
|
-
import { registerDialog } from "lostcoords/ui/helpers/dialog"
|
|
2
|
+
import { registerDialog, showDialog } from "lostcoords/ui/helpers/dialog"
|
|
3
3
|
|
|
4
4
|
// Opens a dialog whose body is a Turbo frame fetched on open. It reloads on every
|
|
5
5
|
// open, so what it shows is never staler than the page that opened it.
|
|
@@ -16,7 +16,7 @@ export default class extends Controller {
|
|
|
16
16
|
if (this.frameTarget.src) this.frameTarget.reload()
|
|
17
17
|
else this.frameTarget.src = this.frameTarget.dataset.src
|
|
18
18
|
}
|
|
19
|
-
|
|
19
|
+
showDialog(this.dialogTarget)
|
|
20
20
|
|
|
21
21
|
this.unregisterDialog = registerDialog(this.dialogTarget)
|
|
22
22
|
}
|
|
@@ -2,7 +2,26 @@ import { registerDismissable } from "lostcoords/ui/helpers/dismiss_stack"
|
|
|
2
2
|
|
|
3
3
|
const registrations = new WeakMap()
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
// Shows a modal <dialog> with focus on the dialog itself rather than its first control: a close
|
|
6
|
+
// button would draw the focus ring after a tap that focused nothing, and a first field would raise
|
|
7
|
+
// a phone's keyboard. A control marked autofocus still takes focus, and Tab reaches every control.
|
|
8
|
+
export function showDialog(dialog) {
|
|
9
|
+
if (dialog.open) return
|
|
10
|
+
dialog.showModal()
|
|
11
|
+
if (dialog.querySelector("[autofocus]")) return
|
|
12
|
+
if (!dialog.hasAttribute("tabindex")) dialog.tabIndex = -1
|
|
13
|
+
dialog.focus({ preventScroll: true })
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Joins a <dialog> to the dismiss stack: Escape, the backdrop and a swipe call close, which may
|
|
17
|
+
// return false to keep it open, such as while it asks whether to discard changes. priority ranks
|
|
18
|
+
// it against panels open in it (a dialog is 10, a panel 20); restoreFocus runs after a close;
|
|
19
|
+
// lockScroll: false leaves the page scrollable behind it. Calling it again for an open dialog
|
|
20
|
+
// returns its registration; it ends when the dialog closes.
|
|
21
|
+
export function registerDialog(
|
|
22
|
+
dialog,
|
|
23
|
+
{ close = () => dialog.close(), lockScroll, priority, restoreFocus } = {},
|
|
24
|
+
) {
|
|
6
25
|
const existing = registrations.get(dialog)
|
|
7
26
|
if (existing) return existing
|
|
8
27
|
|
|
@@ -10,22 +29,37 @@ export function registerDialog(dialog, { close = () => dialog.close(), lockScrol
|
|
|
10
29
|
element: dialog,
|
|
11
30
|
type: "lc-dialog",
|
|
12
31
|
lockScroll,
|
|
32
|
+
priority,
|
|
33
|
+
restoreFocus,
|
|
13
34
|
close,
|
|
14
35
|
isOpen: () => dialog.open,
|
|
15
36
|
})
|
|
37
|
+
// A click on the dialog element itself lands on its backdrop, or on its own padding, which
|
|
38
|
+
// is inside its box and must not close it.
|
|
16
39
|
const closeOnBackdrop = (event) => {
|
|
17
|
-
if (event.target
|
|
40
|
+
if (event.target !== dialog) return
|
|
41
|
+
const box = dialog.getBoundingClientRect()
|
|
42
|
+
const inside =
|
|
43
|
+
event.clientX >= box.left &&
|
|
44
|
+
event.clientX <= box.right &&
|
|
45
|
+
event.clientY >= box.top &&
|
|
46
|
+
event.clientY <= box.bottom
|
|
47
|
+
if (!inside) close(event)
|
|
48
|
+
}
|
|
49
|
+
// A dialog closed and shown again in the same task fires close while it is already open again.
|
|
50
|
+
const unregisterOnClose = () => {
|
|
51
|
+
if (!dialog.open) unregister()
|
|
18
52
|
}
|
|
19
53
|
const unregister = () => {
|
|
20
54
|
if (registrations.get(dialog) !== unregister) return
|
|
21
55
|
registrations.delete(dialog)
|
|
22
|
-
dialog.removeEventListener("close",
|
|
56
|
+
dialog.removeEventListener("close", unregisterOnClose)
|
|
23
57
|
dialog.removeEventListener("click", closeOnBackdrop)
|
|
24
58
|
unregisterDismissable()
|
|
25
59
|
}
|
|
26
60
|
|
|
27
61
|
registrations.set(dialog, unregister)
|
|
28
|
-
dialog.addEventListener("close",
|
|
62
|
+
dialog.addEventListener("close", unregisterOnClose)
|
|
29
63
|
dialog.addEventListener("click", closeOnBackdrop)
|
|
30
64
|
return unregister
|
|
31
65
|
}
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
<button type="button" class="<%= lc_icon_button_class(size: :sm, shape: :circle) %>" aria-label="<%= close_label %>" data-action="<%= close_action %>" data-slot="dialog-dismiss"><%= lc_icon "x-mark", options: { "aria-hidden": true } %></button>
|
|
12
12
|
</div>
|
|
13
13
|
</header>
|
|
14
|
-
|
|
14
|
+
<%# Children keep their height, so a long body scrolls instead of squashing a fixed-height button. %>
|
|
15
|
+
<div class="-mx-inset -mb-inset flex min-h-0 flex-1 flex-col gap-inset px-inset pb-inset *:shrink-0 sm:overflow-y-auto sm:overscroll-contain" data-slot="dialog-body"><%= content %></div>
|
|
15
16
|
</div>
|
|
16
17
|
<% end %>
|
|
17
18
|
<% if trigger %>
|
|
@@ -80,6 +80,13 @@ module Lostcoords::Ui
|
|
|
80
80
|
choice_label(method, label, hint, "switch", input)
|
|
81
81
|
end
|
|
82
82
|
|
|
83
|
+
# lc_file_drop around this attribute's file_field; options other than the drop zone's go to the input.
|
|
84
|
+
def file_drop(method, title:, hint: nil, button: nil, icon: "arrow-up-tray", **options)
|
|
85
|
+
@template.lc_file_drop(title: title, hint: hint, button: button, icon: icon) do
|
|
86
|
+
file_field(method, options.merge(class: @template.lc_tw("sr-only", options[:class])))
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
83
90
|
# A checkbox with its label beside it.
|
|
84
91
|
def choice(method, label: nil, hint: nil, checked_value: "1", unchecked_value: "0", **options)
|
|
85
92
|
input = rails_check_box(method, control_options(method, options, "checkbox-input", @template.lc_checkbox_class, described: true), checked_value, unchecked_value)
|
data/lib/lostcoords/ui/parts.rb
CHANGED
|
@@ -85,6 +85,21 @@ module Lostcoords::Ui
|
|
|
85
85
|
end
|
|
86
86
|
end
|
|
87
87
|
|
|
88
|
+
# Rows that stay put while the sheet's content scrolls under them, painted with the sheet's surface.
|
|
89
|
+
# The footer sits last in an inset-padded scroller and bleeds to its edges, clearing the home indicator.
|
|
90
|
+
class Sheet < Base
|
|
91
|
+
SURFACE = "sticky z-sticky bg-(--lc-sheet-bg,var(--popover))"
|
|
92
|
+
|
|
93
|
+
def header(**attributes, &block)
|
|
94
|
+
part(:header, "sheet-header", "#{SURFACE} top-0 flex min-h-14 shrink-0 items-center", attributes, &block)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def footer(**attributes, &block)
|
|
98
|
+
part(:footer, "sheet-footer", "#{SURFACE} bottom-0 -mx-inset flex flex-wrap items-center justify-end gap-related " \
|
|
99
|
+
"px-inset pt-3 pb-[max(env(safe-area-inset-bottom),--spacing(3))]", attributes, &block)
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
88
103
|
class Dialog < Base
|
|
89
104
|
include CustomTrigger
|
|
90
105
|
|