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
@@ -11,9 +11,11 @@ module Lostcoords::Ui
11
11
  "aria-selected:bg-background aria-selected:text-foreground " \
12
12
  "aria-checked:bg-background aria-checked:text-foreground " \
13
13
  "aria-pressed:bg-background aria-pressed:text-foreground " \
14
+ "has-checked:bg-background has-checked:text-foreground " \
14
15
  "aria-[current]:not-aria-[current=false]:bg-background aria-[current]:not-aria-[current=false]:text-foreground " \
15
16
  "transition-[background-color,color,box-shadow,transform] duration-(--lc-motion-quick) ease-(--lc-ease-out) " \
16
17
  "disabled:cursor-not-allowed disabled:text-[color-mix(in_oklab,var(--foreground)_38%,transparent)] " \
18
+ "has-disabled:cursor-not-allowed has-disabled:text-[color-mix(in_oklab,var(--foreground)_38%,transparent)] " \
17
19
  "[&_svg]:size-[1.1em] [&_svg]:shrink-0"
18
20
 
19
21
  TOGGLE_GROUP_ITEM_ACTIVE = "bg-background text-foreground hover:text-foreground"
@@ -27,15 +29,24 @@ module Lostcoords::Ui
27
29
  "focus:shadow-[0_0_0_calc(var(--spacing)*0.5)_var(--ring,color-mix(in_oklab,var(--primary)_50%,transparent))] " \
28
30
  "aria-invalid:border-destructive aria-invalid:shadow-[0_0_0_3px_color-mix(in_oklab,var(--destructive)_16%,transparent)]"
29
31
 
30
- FIELD_BASE = "lc-field grid min-w-0 gap-related has-aria-invalid:[&>label]:text-destructive"
32
+ FIELD_BASE = "lc-field grid min-w-0 has-aria-invalid:[&>label]:text-destructive"
33
+ FIELD_SIZES = { sm: "gap-tight", md: "gap-related" }.freeze
34
+ # Field labels use the text roles; TypographyHelper loads after this file, so its sizes are read at call time.
35
+ FIELD_LABEL_ROLES = { sm: :caption, md: :label }.freeze
31
36
 
32
37
  FIELD_LABEL_BASE =
33
- "block font-sans text-label font-semibold text-muted-foreground " \
38
+ "block font-sans font-semibold text-muted-foreground " \
34
39
  "transition-colors duration-(--lc-motion-quick) ease-(--lc-ease-out)"
35
40
 
36
41
  # form_with with Lostcoords::Ui::FormBuilder, so form.text_field, form.field and form.submit
37
- # render library controls.
38
- def lc_form_with(**options, &block)
42
+ # render library controls. card: true makes the form the card, and gap: makes it a stack, so the
43
+ # form needs no wrapper element.
44
+ def lc_form_with(card: false, padding: :md, gap: nil, **options, &block)
45
+ if card || gap
46
+ stack = lc_stack_class(gap: gap || :inset)
47
+ layout = { class: card ? lc_card_class(padding: padding, extra: stack) : stack, data: ({ slot: "card" } if card) }.compact
48
+ options = lc_attributes(layout, options)
49
+ end
39
50
  form_with(**options, builder: Lostcoords::Ui::FormBuilder, &block)
40
51
  end
41
52
 
@@ -60,12 +71,13 @@ module Lostcoords::Ui
60
71
  lc_tw(INPUT_BASE, "min-h-28 py-2 resize-y", extra)
61
72
  end
62
73
 
63
- def lc_field_class(extra: nil)
64
- lc_tw(FIELD_BASE, extra)
74
+ def lc_field_class(size: :md, extra: nil)
75
+ lc_tw(FIELD_BASE, FIELD_SIZES.fetch(lc_option!(:size, size, FIELD_SIZES.keys)), extra)
65
76
  end
66
77
 
67
- def lc_field_label_class(extra: nil)
68
- lc_tw(FIELD_LABEL_BASE, extra)
78
+ def lc_field_label_class(size: :md, extra: nil)
79
+ role = FIELD_LABEL_ROLES.fetch(lc_option!(:size, size, FIELD_LABEL_ROLES.keys))
80
+ lc_tw(FIELD_LABEL_BASE, TypographyHelper::TEXT_SIZES.fetch(role), extra)
69
81
  end
70
82
  end
71
83
  end
@@ -21,5 +21,11 @@ module Lostcoords::Ui
21
21
  def lc_glass_class(shape: :bar, thick: false, extra: nil)
22
22
  lc_tw("lc-glass", GLASS_SHAPES.fetch(lc_option!(:shape, shape, GLASS_SHAPES.keys)), (GLASS_THICK if thick), extra)
23
23
  end
24
+
25
+ GLASS_ELEMENTS = %i[div span label section aside header footer nav].freeze
26
+
27
+ def lc_glass(shape: :bar, thick: false, as: :div, **attributes, &block)
28
+ tag.public_send(lc_option!(:as, as, GLASS_ELEMENTS), **lc_attributes({ class: lc_glass_class(shape: shape, thick: thick), data: { slot: "glass" } }, attributes), &block)
29
+ end
24
30
  end
25
31
  end
@@ -10,6 +10,8 @@ module Lostcoords::Ui
10
10
  section: "gap-section"
11
11
  }.freeze
12
12
 
13
+ LAYOUT_ELEMENTS = %i[div section article aside header footer nav main form fieldset ul ol li].freeze
14
+
13
15
  CONTAINER_SIZES = {
14
16
  page: "lc-container-page max-w-page",
15
17
  reading: "max-w-reading",
@@ -36,12 +38,13 @@ module Lostcoords::Ui
36
38
  lc_inline_class(extra: lc_tw("min-h-control-md justify-between", extra))
37
39
  end
38
40
 
39
- def lc_stack(gap: :content, **attributes, &block)
40
- tag.div(**lc_attributes({ class: lc_stack_class(gap: gap) }, attributes), &block)
41
+ # as: picks the element, such as :section, :ul or :form, for layout that carries meaning.
42
+ def lc_stack(gap: :content, as: :div, **attributes, &block)
43
+ tag.public_send(lc_option!(:as, as, LAYOUT_ELEMENTS), **lc_attributes({ class: lc_stack_class(gap: gap) }, attributes), &block)
41
44
  end
42
45
 
43
- def lc_inline(gap: :related, **attributes, &block)
44
- tag.div(**lc_attributes({ class: lc_inline_class(gap: gap) }, attributes), &block)
46
+ def lc_inline(gap: :related, as: :div, **attributes, &block)
47
+ tag.public_send(lc_option!(:as, as, LAYOUT_ELEMENTS), **lc_attributes({ class: lc_inline_class(gap: gap) }, attributes), &block)
45
48
  end
46
49
 
47
50
  def lc_container(size: :page, **attributes, &block)
@@ -54,9 +57,14 @@ module Lostcoords::Ui
54
57
  tag.section(**lc_attributes({ class: lc_stack_class(gap: :heading) }, attributes)) do
55
58
  heading = lc_heading(title, level: level, size: :heading)
56
59
  action_content = actions.respond_to?(:call) ? capture(&actions) : actions
57
- header = tag.header(class: lc_section_header_class) { safe_join([ heading, action_content ].compact) }
60
+ header = lc_section_header { safe_join([ heading, action_content ].compact) }
58
61
  safe_join([ header, lc_stack(&block) ])
59
62
  end
60
63
  end
64
+
65
+ # The heading row of a section whose heading needs more than a title, such as a lede under it.
66
+ def lc_section_header(as: :header, **attributes, &block)
67
+ tag.public_send(lc_option!(:as, as, %i[header div]), **lc_attributes({ class: lc_section_header_class }, attributes), &block)
68
+ end
61
69
  end
62
70
  end
@@ -0,0 +1,65 @@
1
+ module Lostcoords::Ui
2
+ module ListGroupHelper
3
+ LIST_ROW = "lc-list-row min-w-0 bg-card text-card-foreground first:rounded-t-3xl last:rounded-b-3xl lc-squircle"
4
+ LIST_ITEM = "flex min-h-16 min-w-0 items-center gap-heading px-content py-heading text-start sm:px-inset"
5
+ LIST_ROW_PADDING = "px-content py-heading sm:px-inset"
6
+ LIST_ICON = "grid size-10 shrink-0 place-items-center rounded-full bg-tile [&>svg:not([class*='size-'])]:size-4.5"
7
+ LIST_ROW_TAGS = %i[div li label details a].freeze
8
+
9
+ # A titled group of list rows: the heading, then the block, then an optional footnote. The block
10
+ # holds lc_list_group and anything that belongs with it, such as the form that wraps the rows.
11
+ def lc_list_section(heading, footnote: nil, level: 2, **attributes, &block)
12
+ lc_label!(heading, :heading)
13
+ raise ArgumentError, "Invalid level: #{level.inspect}. Expected an integer from 1 to 6" unless level.is_a?(Integer) && (1..6).include?(level)
14
+
15
+ heading_id = "#{attributes[:id]}-heading" if attributes[:id]
16
+ tag.section(**lc_attributes({ class: "grid min-w-0 gap-related", aria: { labelledby: heading_id }, data: { slot: "list-section" } }, attributes)) do
17
+ safe_join([
18
+ tag.public_send("h#{level}", heading, id: heading_id, class: "m-0 px-content text-label font-semibold text-muted-foreground sm:px-inset", data: { slot: "list-heading" }),
19
+ (capture(&block) if block),
20
+ (tag.p(footnote, class: "m-0 px-content text-small text-muted-foreground sm:px-inset [&_a]:text-foreground [&_a]:underline [&_a]:underline-offset-4", data: { slot: "list-footnote" }) if footnote.present?)
21
+ ].compact)
22
+ end
23
+ end
24
+
25
+ # Rows as in iOS settings: each row is its own card-coloured panel, 2px apart, and only the
26
+ # first and last rows round.
27
+ def lc_list_group(tag: :div, **attributes, &block)
28
+ tag = lc_option!(:tag, tag, %i[div ul])
29
+ content_tag(tag, (capture(&block) if block), **lc_attributes({ class: "m-0 grid min-w-0 list-none gap-0.5 p-0", data: { slot: "list-group" } }, attributes))
30
+ end
31
+
32
+ # With a title, the row lays out icon:, the title and subtitle, then the block as its trailing
33
+ # content. Without one, the block is the whole row; padded: false drops the row's padding for
34
+ # content that pads itself, such as an lc_list_item button. href: makes the row a link.
35
+ def lc_list_row(title = nil, subtitle: nil, icon: nil, href: nil, tag: nil, padded: true, **attributes, &block)
36
+ tag = lc_option!(:tag, tag || (href ? :a : :div), LIST_ROW_TAGS)
37
+ raise ArgumentError, "href: needs tag: :a" if href && tag != :a
38
+
39
+ link = ("no-underline transition-colors duration-(--lc-motion-quick) hover:bg-accent" if href)
40
+ defaults = { href: href, data: { slot: "list-row" } }
41
+ return lc_list_item(title, subtitle: subtitle, icon: icon, tag: tag, **lc_attributes(defaults.merge(class: lc_tw(LIST_ROW, link)), attributes), &block) if title.present?
42
+
43
+ classes = lc_tw(LIST_ROW, (LIST_ROW_PADDING if padded), link)
44
+ content_tag(tag, (capture(&block) if block), **lc_attributes(defaults.merge(class: classes), attributes))
45
+ end
46
+
47
+ # The row layout without the row's surface, for an element inside a free-form row: a summary, a
48
+ # button that opens an editor. icon: takes an icon name or your own markup, such as a logo.
49
+ def lc_list_item(title, subtitle: nil, icon: nil, tag: :div, **attributes, &block)
50
+ lc_label!(title, :title)
51
+ glyph = icon.is_a?(ActiveSupport::SafeBuffer) ? icon : lc_icon(icon) if icon.present?
52
+ content_tag(tag, **lc_attributes({ class: LIST_ITEM, data: { slot: "list-item" } }, attributes)) do
53
+ text = safe_join([
54
+ content_tag(:span, title, class: "font-semibold", data: { slot: "list-title" }),
55
+ (content_tag(:span, subtitle, class: "text-small text-muted-foreground [overflow-wrap:anywhere]", data: { slot: "list-subtitle" }) if subtitle.present?)
56
+ ].compact)
57
+ safe_join([
58
+ (content_tag(:span, glyph, class: LIST_ICON, aria: { hidden: true }, data: { slot: "list-icon" }) if glyph),
59
+ content_tag(:span, text, class: "grid min-w-0 flex-1 gap-0.5", data: { slot: "list-text" }),
60
+ (capture(&block) if block)
61
+ ].compact)
62
+ end
63
+ end
64
+ end
65
+ end
@@ -5,7 +5,8 @@ module Lostcoords::Ui
5
5
  "lc-menu__popover lc-squircle lc-popover-shell hidden absolute top-[calc(100%+--spacing(1))] end-0 overscroll-contain [&_form]:m-0"
6
6
 
7
7
  MENU_POPOVER_BASE =
8
- "data-open:flex flex-col gap-px z-(--lc-z-popover) p-related " \
8
+ "data-open:grid grid-cols-[auto_minmax(0,1fr)_auto] content-start gap-y-px [&>*]:col-span-full " \
9
+ "[&_[data-slot=menu-item]]:grid-cols-subgrid z-(--lc-z-popover) p-related " \
9
10
  "min-w-56 max-w-[calc(100vw-clamp(1rem,3vw,1.5rem)*2)] max-h-[min(24rem,70vh)] overflow-y-auto"
10
11
 
11
12
  MENU_POPOVER_ALIGN = {
@@ -15,7 +16,7 @@ module Lostcoords::Ui
15
16
  }.freeze
16
17
 
17
18
  MENU_OPTION_BASE =
18
- "lc-menu__item lc-press [--lc-press-scale:0.98] group/option grid grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-x-3 w-full " \
19
+ "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 " \
19
20
  "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 " \
20
21
  "no-underline cursor-pointer transition-[background-color] duration-120 [--lc-avatar-size:--spacing(7)] " \
21
22
  "hover:bg-accent focus-visible:bg-accent focus-visible:outline-none " \
@@ -26,6 +27,14 @@ module Lostcoords::Ui
26
27
  destructive: "text-destructive hover:bg-destructive-soft focus-visible:bg-destructive-soft"
27
28
  }.freeze
28
29
 
30
+ MENU_OPTION_LEADING = "col-start-1 me-3 grid min-w-5 place-items-center text-lg leading-none"
31
+ MENU_OPTION_ICON = "size-5 text-muted-foreground group-aria-checked/option:text-primary group-data-[tone=destructive]/option:text-current"
32
+ MENU_OPTION_LABEL = "col-start-2 grid min-w-0 group-aria-checked/option:font-semibold"
33
+ MENU_OPTION_HINT = "text-caption font-normal text-muted-foreground"
34
+ MENU_OPTION_CHECK = "col-start-3 ms-3 size-4 text-primary invisible group-aria-checked/option:visible"
35
+
36
+ MENU_TRIGGERS = %i[button icon].freeze
37
+
29
38
  def lc_popover_class(align: :end, extra: nil)
30
39
  lc_glass_class(shape: :menu, extra: lc_tw(POPOVER_BASE, MENU_POPOVER_ALIGN.fetch(lc_option!(:align, align, MENU_POPOVER_ALIGN.keys)), extra))
31
40
  end
@@ -38,23 +47,49 @@ module Lostcoords::Ui
38
47
  lc_tw(MENU_OPTION_BASE, MENU_OPTION_TONES.fetch(lc_option!(:tone, tone, MENU_OPTION_TONES.keys)), extra)
39
48
  end
40
49
 
41
- def lc_menu(id:, label: lc_t("lostcoords.ui.menu.label"), align: :end, **attributes, &block)
50
+ # trigger: :icon renders a quiet icon button named by label; rendered HTML becomes the content
51
+ # of a custom trigger, also named by label.
52
+ def lc_menu(id:, label: lc_t("lostcoords.ui.menu.label"), align: :end, trigger: :button, icon: "ellipsis-vertical", trigger_attributes: {}, wrapper_attributes: {}, **attributes, &block)
42
53
  align = lc_option!(:align, align, MENU_POPOVER_ALIGN.keys)
43
- lc_render_panel(id, label, nil, "lc-menu", "menu", lc_menu_popover_class(align: align), lc_attributes({ data: { slot: "menu" } }, attributes), &block)
54
+ default_trigger = ->(wiring) { lc_panel_trigger(label, trigger, icon, :secondary, wiring) } unless trigger == false
55
+ 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)
44
56
  end
45
57
 
46
- def lc_popover(id:, label: lc_t("lostcoords.ui.popover.trigger"), title: nil, align: :end, trigger_variant: :secondary, **attributes, &block)
58
+ # Takes the same trigger options as lc_menu, including trigger: false.
59
+ def lc_popover(id:, label: lc_t("lostcoords.ui.popover.trigger"), title: nil, align: :end, trigger_variant: :secondary, trigger: :button, icon: "ellipsis-vertical", trigger_attributes: {}, wrapper_attributes: {}, **attributes, &block)
47
60
  title = title.presence
48
61
  align = lc_option!(:align, align, MENU_POPOVER_ALIGN.keys)
62
+ default_trigger = ->(wiring) { lc_panel_trigger(label, trigger, icon, trigger_variant, wiring) } unless trigger == false
49
63
  classes = lc_popover_class(align: align, extra: "data-open:flex flex-col gap-content p-inset z-(--lc-z-popover) min-w-64 max-w-[calc(100vw-2rem)]")
50
- lc_render_panel(id, label, title, "lc-popover", "dialog", classes, lc_attributes({ data: { slot: "popover" } }, attributes), trigger_variant: trigger_variant, &block)
64
+ lc_render_panel(id, label, title, "lc-popover", "dialog", classes, lc_attributes({ data: { slot: "popover" } }, attributes), default_trigger, trigger_attributes, wrapper_attributes, &block)
51
65
  end
52
66
 
53
- def lc_menu_option(label = nil, href: nil, tone: :default, **attributes, &block)
67
+ # icon: names a leading Heroicon; leading: takes other rendered content, such as an avatar, and is
68
+ # hidden from assistive technology so the label stays the name. checked: true or false makes a
69
+ # menuitemradio with a check mark. checkbox: true makes a menuitemcheckbox that flips on click and
70
+ # leaves the menu open. method: renders a button_to form for href.
71
+ 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, &block)
54
72
  tone = lc_option!(:tone, tone, MENU_OPTION_TONES.keys)
55
- content = tag.span(block ? capture(&block) : label, class: "col-span-3")
56
- defaults = { class: lc_menu_option_class(tone: tone), role: "menuitem", data: { slot: "menu-item", action: "click->lc-menu#close" } }
57
- if href
73
+ raise ArgumentError, "Pass icon: or leading:, not both" if icon && leading
74
+ raise ArgumentError, "checked: must be true, false or nil" unless [ true, false, nil ].include?(checked)
75
+ raise ArgumentError, "method: needs an href:" if method && !href
76
+ raise ArgumentError, "checkbox: true renders a button; drop href:" if checkbox && href
77
+ checked = !!checked if checkbox
78
+
79
+ leading = lc_icon(icon, options: { class: MENU_OPTION_ICON }) if icon
80
+ text = block ? capture(&block) : label
81
+ content = safe_join([
82
+ (tag.span(leading, class: MENU_OPTION_LEADING, aria: { hidden: true }, data: { slot: "menu-item-leading" }) if leading),
83
+ tag.span(hint ? safe_join([ tag.span(text), tag.span(hint, class: MENU_OPTION_HINT, data: { slot: "menu-item-hint" }) ]) : text, class: MENU_OPTION_LABEL),
84
+ (lc_icon("check", variant: :mini, options: { class: MENU_OPTION_CHECK, "aria-hidden": true }) unless checked.nil?)
85
+ ])
86
+ role = checkbox ? "menuitemcheckbox" : (checked.nil? ? "menuitem" : "menuitemradio")
87
+ defaults = { class: lc_menu_option_class(tone: tone, extra: "gap-x-0"), role: role, data: { slot: "menu-item", tone: tone, action: checkbox ? "click->lc-menu#check" : "click->lc-menu#close" } }
88
+ defaults[:aria] = { checked: checked } unless checked.nil?
89
+
90
+ if method
91
+ button_to(content, href, **lc_attributes(defaults, attributes), method: method, params: params, form: lc_attributes({ class: "contents" }, form))
92
+ elsif href
58
93
  raise ArgumentError, "Links cannot be disabled; use a menu button instead" if attributes[:disabled] || attributes["disabled"]
59
94
 
60
95
  tag.a(content, **lc_attributes(defaults.merge(href: href), attributes))
@@ -64,13 +99,38 @@ module Lostcoords::Ui
64
99
  end
65
100
 
66
101
  private
67
- def lc_render_panel(id, label, title, controller, role, classes, attributes, trigger_variant: :secondary, &block)
102
+ def lc_panel_trigger(label, trigger, icon, variant, attributes)
103
+ custom = trigger.is_a?(String) && trigger.html_safe?
104
+ kind = custom ? :custom : lc_option!(:trigger, trigger, MENU_TRIGGERS)
105
+ case kind
106
+ when :custom, :icon
107
+ content = custom ? trigger : lc_icon(icon, options: { "aria-hidden": true })
108
+ icon_button = { type: "button", class: lc_icon_button_class(shape: :circle, size: :md, extra: ButtonHelper::ICON_BUTTON_QUIET), aria: { label: label }, data: { slot: "icon-button" } }
109
+ tag.button(content, **lc_attributes(icon_button, attributes))
110
+ else
111
+ lc_button(label, variant: variant, **attributes)
112
+ end
113
+ end
114
+
115
+ # The block runs before the default trigger renders, so a menu.trigger part can replace it.
116
+ # trigger: false renders only the panel, for a caller that hosts the controller on an ancestor
117
+ # and wires its own triggers.
118
+ def lc_render_panel(id, label, title, controller, role, classes, attributes, default_trigger, trigger_attributes, wrapper_attributes, &block)
68
119
  lc_label!(id, :id)
69
120
  lc_label!(label, :label)
70
- required = { id: id, role: role, aria: { labelledby: "#{id}-#{title ? 'title' : 'trigger'}" }, data: { "#{controller}_target" => "popover" } }
121
+ standalone = default_trigger.nil?
122
+ raise ArgumentError, "trigger: false renders no trigger or wrapper" if standalone && (trigger_attributes.present? || wrapper_attributes.present?)
123
+
124
+ wiring = { id: "#{id}-trigger", aria: { haspopup: role, expanded: false, controls: id }, data: { "#{controller}_target" => "trigger", action: "#{controller}#toggle" } }
125
+ parts = Parts::Panel.new(self, wiring)
126
+ content = capture(parts, &block) if block
127
+ trigger = parts.rendered_trigger || default_trigger.call(lc_attributes(trigger_attributes, wiring)) unless standalone
128
+ name = if title then { labelledby: "#{id}-title" } elsif standalone then { label: label } else { labelledby: "#{id}-trigger" } end
129
+ required = { id: id, role: role, aria: name, data: { "#{controller}_target" => "popover" } }
71
130
  required[:tabindex] = -1 if role == "dialog"
72
131
  merged = lc_attributes({ class: classes }, attributes, required)
73
- render "lostcoords/ui/components/lc_floating_panel", id: id, label: label, title: title, controller: controller, role: role, trigger_variant: trigger_variant, attributes: merged, content: (capture(&block) if block)
132
+ wrapper = lc_attributes({ class: "relative inline-flex" }, wrapper_attributes, { data: { controller: controller } }) unless standalone
133
+ render "lostcoords/ui/components/lc_floating_panel", id: id, title: title, wrapper: wrapper, trigger: trigger, attributes: merged, content: content
74
134
  end
75
135
  end
76
136
  end
@@ -8,8 +8,38 @@ module Lostcoords::Ui
8
8
  primary: "text-primary decoration-current/40 hover:decoration-current"
9
9
  }.freeze
10
10
 
11
- NAV_LINK = "flex min-w-0 items-center rounded-xl lc-squircle no-underline transition-colors duration-(--lc-motion-quick) " \
12
- "text-muted-foreground hover:text-foreground aria-[current=page]:text-foreground"
11
+ NAV_LINK = "flex min-w-0 items-center gap-related rounded-xl lc-squircle no-underline transition-colors duration-(--lc-motion-quick) " \
12
+ "text-muted-foreground hover:text-foreground aria-[current=page]:text-foreground [&_svg]:shrink-0 " \
13
+ "group-data-[indicator]/nav:relative group-data-[indicator]/nav:aria-[current=page]:bg-transparent"
14
+
15
+ # Each layout styles the list and its links; the indicator fill follows the links' corners.
16
+ NAV_LAYOUTS = {
17
+ column: {
18
+ list: "m-0 flex list-none flex-col gap-px p-0",
19
+ link: "[&_svg]:size-4.5",
20
+ indicator: "rounded-xl lc-squircle"
21
+ },
22
+ row: {
23
+ list: "m-0 flex min-w-0 list-none flex-wrap items-center gap-tight p-0",
24
+ link: "shrink-0 justify-center [&_svg]:size-4.5",
25
+ indicator: "rounded-xl lc-squircle"
26
+ },
27
+ dock: {
28
+ list: "m-0 grid list-none grid-flow-col auto-cols-fr gap-0.5 rounded-pill p-tight",
29
+ link: "min-h-14 flex-col justify-center gap-0.5 rounded-pill px-0 text-caption font-semibold hover:bg-transparent [&_svg]:size-6",
30
+ indicator: "rounded-pill"
31
+ },
32
+ responsive: {
33
+ list: "m-0 list-none p-0 max-sm:grid max-sm:grid-flow-col max-sm:auto-cols-fr max-sm:gap-0.5 max-sm:rounded-pill max-sm:p-tight " \
34
+ "sm:flex sm:min-w-0 sm:flex-wrap sm:items-center sm:gap-tight",
35
+ link: "justify-center max-sm:min-h-14 max-sm:flex-col max-sm:gap-0.5 max-sm:rounded-pill max-sm:px-0 max-sm:text-caption " \
36
+ "max-sm:font-semibold max-sm:hover:bg-transparent max-sm:[&_svg]:size-6 sm:shrink-0 sm:[&_svg]:size-4.5",
37
+ indicator: "max-sm:rounded-pill sm:rounded-xl lc-squircle"
38
+ }
39
+ }.freeze
40
+ NAV_INDICATOR = "pointer-events-none absolute start-0 top-0 bg-(--lc-nav-indicator,var(--accent)) opacity-0 " \
41
+ "transition-[translate,width,height,opacity] duration-[400ms] ease-(--lc-ease-out-expo) motion-reduce:transition-none " \
42
+ "group-data-[indicator]/nav:opacity-100"
13
43
 
14
44
  # An inline text link. Prose inside lc_prose styles its links already.
15
45
  def lc_link_class(tone: :inherit, extra: nil)
@@ -27,17 +57,30 @@ module Lostcoords::Ui
27
57
  link_to(content, url, **lc_attributes({ class: lc_link_class(tone: tone), data: { slot: "link" } }, attributes))
28
58
  end
29
59
 
30
- # compact: true is the quieter style for an "On this page" list.
31
- def lc_nav_link_class(compact: false, extra: nil)
60
+ # compact: true is the quieter style for an "On this page" list, in the column layout only.
61
+ def lc_nav_link_class(compact: false, layout: :column, extra: nil)
62
+ layout = lc_option!(:layout, layout, NAV_LAYOUTS.keys)
63
+ raise ArgumentError, "compact: true needs layout: :column" if compact && layout != :column
64
+
32
65
  size = compact ? "py-tight text-small aria-[current=page]:font-medium" : "min-h-control-md px-3 py-1.5 text-label hover:bg-accent aria-[current=page]:bg-accent aria-[current=page]:font-semibold"
33
- lc_tw(NAV_LINK, size, extra)
66
+ lc_tw(NAV_LINK, size, (NAV_LAYOUTS.dig(layout, :link) unless compact), extra)
34
67
  end
35
68
 
36
69
  # Yields a builder with link and group parts; links mark the current page with aria-current.
37
- def lc_nav_list(label:, compact: false, **attributes, &block)
70
+ # layout: :row lays links in a line, :dock stacks each icon above its label in equal cells for a
71
+ # phone's bottom bar, and :responsive is a dock below sm and a row from sm. indicator: true slides
72
+ # one fill to the current link, starting where it was on the previous page.
73
+ def lc_nav_list(label:, compact: false, layout: :column, indicator: false, **attributes, &block)
38
74
  lc_label!(label, :label)
39
- tag.nav(**lc_attributes({ aria: { label: label }, data: { slot: "nav-list", compact: (true if compact) } }, attributes)) do
40
- tag.ul(capture(Parts::NavList.new(self, compact), &block), class: "m-0 flex list-none flex-col gap-px p-0")
75
+ layout = lc_option!(:layout, layout, NAV_LAYOUTS.keys)
76
+ raise ArgumentError, "compact: true needs layout: :column" if compact && layout != :column
77
+
78
+ data = { slot: "nav-list", compact: (true if compact), layout: (layout unless layout == :column), controller: ("lc-nav" if indicator) }.compact
79
+ tag.nav(**lc_attributes({ class: ("group/nav relative" if indicator), aria: { label: label }, data: data }, attributes)) do
80
+ safe_join([
81
+ (tag.span(class: lc_tw(NAV_INDICATOR, NAV_LAYOUTS.dig(layout, :indicator)), aria: { hidden: true }, data: { slot: "nav-indicator", lc_nav_target: "indicator" }) if indicator),
82
+ tag.ul(capture(Parts::NavList.new(self, compact, layout, indicator), &block), class: NAV_LAYOUTS.dig(layout, :list))
83
+ ].compact)
41
84
  end
42
85
  end
43
86
 
@@ -106,8 +149,8 @@ module Lostcoords::Ui
106
149
 
107
150
  # Yields a builder; each `tabs.panel "Label" do … end` adds a tab and its panel.
108
151
  # orientation: :vertical stacks the tabs beside the panels and moves them with Arrow Up and Down.
109
- # activation: :manual moves focus with the arrows and selects with Enter or Space.
110
- def lc_tabs(id:, label:, selected: nil, orientation: :horizontal, activation: :automatic, **attributes, &block)
152
+ # activation: :manual moves focus with the arrows and selects with Enter or Space. list: adds attributes to the tab list.
153
+ def lc_tabs(id:, label:, selected: nil, orientation: :horizontal, activation: :automatic, list: {}, **attributes, &block)
111
154
  lc_label!(id, :id)
112
155
  lc_label!(label, :label)
113
156
  orientation = lc_option!(:orientation, orientation, TABS_ORIENTATIONS.keys)
@@ -123,7 +166,9 @@ module Lostcoords::Ui
123
166
  key = ->(panel) { "#{id}-#{panel.value.gsub(/[^\w-]+/, '-')}" }
124
167
  ids = tabs.panels.map(&key)
125
168
  raise ArgumentError, "tab values #{tabs.panels.map(&:value).inspect} produce duplicate ids" unless ids.uniq.size == ids.size
126
- list = tag.div(role: "tablist", aria: { label: label, orientation: (orientation if orientation == :vertical) }, class: lc_toggle_group_class(extra: layout[:list]), data: { slot: "tabs-list" }) do
169
+ list_attributes = lc_attributes({ class: lc_toggle_group_class(extra: layout[:list]), data: { slot: "tabs-list" } }, list,
170
+ { role: "tablist", aria: { label: label, orientation: (orientation if orientation == :vertical) } })
171
+ tablist = tag.div(**list_attributes) do
127
172
  safe_join(tabs.panels.map do |panel|
128
173
  active = panel.value == selected
129
174
  tag.button(panel.label, type: "button", role: "tab", id: "#{key.(panel)}-tab", tabindex: (active ? 0 : -1),
@@ -137,7 +182,7 @@ module Lostcoords::Ui
137
182
  end
138
183
  data = { slot: "tabs", controller: "lc-tabs", lc_tabs_activation_value: (activation.to_s if activation == :manual) }.compact
139
184
  tag.div(**lc_attributes({ id: id, class: layout[:root], data: data }, attributes)) do
140
- safe_join([ list, *panels ])
185
+ safe_join([ tablist, *panels ])
141
186
  end
142
187
  end
143
188
  end
@@ -1,77 +1,137 @@
1
1
  module Lostcoords::Ui
2
2
  module PrimitivesHelper
3
- def lc_button(content = nil, variant: :primary, size: :md, icon: nil, icon_position: :start, **attributes, &block)
4
- tag.button(lc_button_content(content, icon, icon_position, &block), **lc_button_attributes(variant, size, { type: "button" }, attributes))
3
+ def lc_button(content = nil, variant: :primary, tone: :default, size: :md, block: false, icon: nil, icon_position: :start, **attributes, &content_block)
4
+ tag.button(lc_button_content(content, icon, icon_position, &content_block), **lc_button_attributes(variant, tone, size, block, { type: "button" }, attributes))
5
5
  end
6
6
 
7
- def lc_button_link_to(content = nil, url = nil, variant: :primary, size: :md, icon: nil, icon_position: :start, **attributes, &block)
8
- attributes = lc_button_attributes(variant, size, {}, attributes)
7
+ def lc_button_link_to(content = nil, url = nil, variant: :primary, tone: :default, size: :md, block: false, icon: nil, icon_position: :start, **attributes, &content_block)
8
+ attributes = lc_button_attributes(variant, tone, size, block, {}, attributes)
9
9
  raise ArgumentError, "Links cannot be disabled; use lc_button for a disabled control" if attributes[:disabled]
10
10
 
11
- if block
11
+ if content_block
12
12
  url ||= content
13
- content = capture(&block)
13
+ content = capture(&content_block)
14
14
  end
15
15
 
16
16
  link_to(lc_button_content(content, icon, icon_position), url, attributes)
17
17
  end
18
18
 
19
- def lc_button_to(content = nil, url = nil, variant: :primary, size: :md, icon: nil, icon_position: :start, **attributes, &block)
20
- if block
19
+ def lc_button_to(content = nil, url = nil, variant: :primary, tone: :default, size: :md, block: false, icon: nil, icon_position: :start, **attributes, &content_block)
20
+ if content_block
21
21
  url ||= content
22
- content = capture(&block)
22
+ content = capture(&content_block)
23
23
  end
24
24
 
25
- button_to(lc_button_content(content, icon, icon_position), url, lc_button_attributes(variant, size, {}, attributes))
25
+ button_to(lc_button_content(content, icon, icon_position), url, lc_button_attributes(variant, tone, size, block, {}, attributes))
26
26
  end
27
27
 
28
- def lc_icon_button(label, icon:, size: :md, shape: :circle, **attributes)
29
- size = lc_option!(:size, size, ButtonHelper::ICON_BUTTON_SIZES.keys)
30
- shape = lc_option!(:shape, shape, ButtonHelper::ICON_BUTTON_SHAPES.keys)
31
- defaults = { type: "button", class: lc_icon_button_class(size: size, shape: shape), aria: { label: label }, data: { slot: "icon-button", size: size } }
32
- attributes = lc_attributes(defaults, attributes)
33
- accessible_label = attributes.fetch(:"aria-label", attributes.dig(:aria, :label))
34
- raise ArgumentError, "lc_icon_button requires a nonblank accessible label" if label.blank? || accessible_label.blank?
28
+ # A button styled as a select for opening a menu or picker. A string label truncates; a block
29
+ # renders its own content, such as an avatar and a label. The chevron is appended either way.
30
+ def lc_select_trigger(label = nil, size: :md, block: false, **attributes, &content)
31
+ size = lc_option!(:size, size, TailwindHelper::CONTROL_SIZES.keys)
32
+ body = content ? capture(&content) : tag.span(label, class: "min-w-0 truncate")
33
+ chevron = lc_icon("chevron-down", variant: :mini, options: { "aria-hidden": true, "data-icon": "inline-end" })
34
+ defaults = { type: "button", class: lc_select_trigger_class(size: size, block: block), data: { slot: "select-trigger", size: size } }
35
+ tag.button(safe_join([ body, chevron ]), **lc_attributes(defaults, attributes))
36
+ end
35
37
 
36
- tag.button(**attributes) do
37
- lc_icon(icon, options: { "aria-hidden": true })
38
- end
38
+ # A block replaces the icon with custom content, such as an avatar or two stacked icons.
39
+ # One pill with a primary action and a toggle on its inline end that opens a menu of the block's
40
+ # lc_menu_option items. With href: the action is a link. label may be rendered HTML. action:,
41
+ # toggle: and menu: add attributes to those parts; other attributes go on the wrapper.
42
+ #
43
+ # <%= lc_split_button "Add expense", id: "add", href: new_expense_path, icon: "plus", menu_label: "More ways to add" do %>
44
+ # <%= lc_menu_option "Import a CSV", icon: "arrow-down-tray" %>
45
+ # <% end %>
46
+ def lc_split_button(label, id:, href: nil, menu_label: lc_t("lostcoords.ui.menu.label"), variant: :primary, tone: :default, size: :md,
47
+ icon: nil, icon_position: :start, block: false, align: :end, action: {}, toggle: {}, menu: {}, **attributes, &items)
48
+ lc_label!(id, :id)
49
+ lc_label!(menu_label, :menu_label)
50
+ variant = lc_option!(:variant, variant, ButtonHelper::BUTTON_VARIANTS.keys)
51
+ size = lc_option!(:size, size, ButtonHelper::BUTTON_SIZES.keys)
52
+ button = { variant: variant, tone: tone, size: size, icon: icon, icon_position: icon_position }
53
+ action = lc_attributes({ class: lc_tw(ButtonHelper::SPLIT_BUTTON_PART, ButtonHelper::SPLIT_BUTTON_ACTION) }, action)
54
+ primary = href ? lc_button_link_to(label, href, **button, **action) : lc_button(label, **button, **action)
55
+
56
+ toggle_class = lc_button_class(variant: variant, tone: tone, size: size, extra: lc_tw(
57
+ ButtonHelper::SPLIT_BUTTON_PART, ButtonHelper::SPLIT_BUTTON_TOGGLE, ButtonHelper::SPLIT_BUTTON_TOGGLE_WIDTHS.fetch(size),
58
+ (ButtonHelper::SPLIT_BUTTON_DIVIDER unless variant == :outline)
59
+ ))
60
+ toggle = tag.button(lc_icon("chevron-down", variant: :mini, options: { "aria-hidden": true }), **lc_attributes(
61
+ { type: "button", class: toggle_class, data: { slot: "split-button-toggle", action: "lc-menu#toggle" } }, toggle,
62
+ { id: "#{id}-trigger", aria: { label: menu_label, haspopup: "menu", expanded: false, controls: id }, data: { lc_menu_target: "trigger" } }
63
+ ))
64
+
65
+ popover = tag.div(capture(&items), **lc_attributes(
66
+ { class: lc_menu_popover_class(align: align), data: { slot: "menu" } }, menu,
67
+ { id: id, role: "menu", aria: { labelledby: "#{id}-trigger" }, data: { lc_menu_target: "popover" } }
68
+ ))
69
+
70
+ defaults = { class: lc_tw(ButtonHelper::SPLIT_BUTTON_BASE, ("flex w-full" if block)), data: { controller: "lc-menu", slot: "split-button" } }
71
+ tag.div(safe_join([ primary, toggle, popover ]), **lc_attributes(defaults, attributes))
72
+ end
73
+
74
+ def lc_icon_button(label, icon: nil, size: :md, shape: :circle, **attributes, &content)
75
+ attributes = lc_icon_button_attributes(label, size, shape, { type: "button" }, attributes)
76
+ tag.button(lc_icon_button_content(icon, &content), **attributes)
77
+ end
78
+
79
+ def lc_icon_button_link_to(label, url, icon: nil, size: :md, shape: :circle, **attributes, &content)
80
+ attributes = lc_icon_button_attributes(label, size, shape, {}, attributes)
81
+ raise ArgumentError, "Links cannot be disabled; use lc_icon_button for a disabled control" if attributes[:disabled]
82
+
83
+ link_to(lc_icon_button_content(icon, &content), url, attributes)
84
+ end
85
+
86
+ def lc_icon_button_to(label, url, icon: nil, size: :md, shape: :circle, **attributes, &content)
87
+ button_to(lc_icon_button_content(icon, &content), url, lc_icon_button_attributes(label, size, shape, {}, attributes))
39
88
  end
40
89
 
41
- def lc_badge(content = nil, tone: :neutral, **attributes, &block)
90
+ def lc_badge(content = nil, tone: :neutral, shape: :rounded, **attributes, &block)
42
91
  tone = lc_option!(:tone, tone, BadgeHelper::BADGE_TONES.keys)
43
- tag.span(content, **lc_attributes({ class: lc_badge_class(tone: tone), data: { slot: "badge", tone: tone } }, attributes), &block)
92
+ tag.span(content, **lc_attributes({ class: lc_badge_class(tone: tone, shape: shape), data: { slot: "badge", tone: tone } }, attributes), &block)
44
93
  end
45
94
 
46
- def lc_icon_badge(icon:, size: :md, shape: :square, tone: :neutral, **attributes)
95
+ # Pass icon: for a library icon, or content or a block for an emoji or a custom glyph.
96
+ def lc_icon_badge(content = nil, icon: nil, size: :md, shape: :square, tone: :neutral, **attributes, &block)
97
+ raise ArgumentError, "Pass icon:, content or a block, not more than one" if [ icon, content, block ].compact.size > 1
98
+
47
99
  tag.span(**lc_attributes({ class: lc_icon_badge_class(size: size, shape: shape, tone: tone), data: { slot: "icon-badge" } }, attributes)) do
48
- lc_icon(icon, options: { class: "size-[1em]", "aria-hidden": true })
100
+ icon ? lc_icon(icon, options: { class: "size-[1em]", "aria-hidden": true }) : block ? capture(&block) : content
49
101
  end
50
102
  end
51
103
 
52
- def lc_avatar(content = nil, src: nil, alt: nil, size: :md, ink: false, linked: false, **attributes, &block)
104
+ # as: :button makes the avatar itself the control, such as a picker's trigger.
105
+ def lc_avatar(content = nil, src: nil, alt: nil, size: :md, ink: false, linked: false, as: :span, **attributes, &block)
53
106
  size = lc_option!(:size, size, BadgeHelper::AVATAR_SIZES.keys)
107
+ as = lc_option!(:as, as, %i[span button])
54
108
  defaults = { class: lc_avatar_class(size: size, ink: ink, linked: linked), data: { slot: "avatar" } }
55
109
  if src
56
110
  tag.img(**lc_attributes(defaults.merge(src: src, alt: alt.to_s, class: lc_tw(defaults[:class], "object-cover")), attributes))
111
+ elsif as == :button
112
+ defaults.merge!(type: "button", class: lc_tw(defaults[:class], "cursor-pointer border-0 p-0"))
113
+ tag.button(content, **lc_attributes(defaults, attributes), &block)
57
114
  else
58
115
  tag.span(content, **lc_attributes(defaults, attributes), &block)
59
116
  end
60
117
  end
61
118
 
62
- def lc_avatar_stack(compact: false, **attributes, &block)
119
+ # row: takes attributes for the inner row that overlaps the avatars, such as a controller target.
120
+ def lc_avatar_stack(compact: false, row: {}, **attributes, &block)
63
121
  tag.span(**lc_attributes({ class: lc_avatar_stack_class(compact: compact), data: { slot: "avatar-stack" } }, attributes)) do
64
- tag.span(class: lc_avatar_stack_row_class, &block)
122
+ tag.span(**lc_attributes({ class: lc_avatar_stack_row_class }, row), &block)
65
123
  end
66
124
  end
67
125
 
126
+ CARD_ELEMENTS = %i[div section article aside li form].freeze
127
+
68
128
  # Yields a card builder with header, title, description, content and footer parts. The card stacks
69
- # its children with the same inset it pads with.
70
- def lc_card(href: nil, interactive: false, padding: :md, **attributes, &block)
71
- defaults = { class: lc_card_class(interactive: interactive || !href.nil?, padding: padding, extra: "flex flex-col gap-inset"), data: { slot: "card" } }
129
+ # its children with the same inset it pads with; an unpadded card's children meet edge to edge.
130
+ def lc_card(href: nil, interactive: false, padding: :md, as: :div, **attributes, &block)
131
+ defaults = { class: lc_card_class(interactive: interactive || !href.nil?, padding: padding, extra: [ "flex flex-col", ("gap-inset" unless padding.to_s == "none") ]), data: { slot: "card" } }
72
132
  content = capture(Parts::Card.new(self), &block) if block
73
133
  if href.nil?
74
- tag.div(content, **lc_attributes(defaults, attributes))
134
+ tag.public_send(lc_option!(:as, as, CARD_ELEMENTS), content, **lc_attributes(defaults, attributes))
75
135
  else
76
136
  defaults.merge!(href: href, class: lc_tw(defaults[:class], "no-underline text-inherit"))
77
137
  tag.a(content, **lc_attributes(defaults, attributes))
@@ -122,9 +182,27 @@ module Lostcoords::Ui
122
182
  safe_join(position == :start ? [ glyph, content ] : [ content, glyph ])
123
183
  end
124
184
 
125
- def lc_button_attributes(variant, size, defaults, attributes)
126
- data = { slot: "button", variant: lc_option!(:variant, variant, ButtonHelper::BUTTON_VARIANTS.keys), size: lc_option!(:size, size, ButtonHelper::BUTTON_SIZES.keys) }
127
- lc_attributes(defaults.merge(class: lc_button_class(variant: variant, size: size), data: data), attributes)
185
+ def lc_button_attributes(variant, tone, size, block, defaults, attributes)
186
+ tone = lc_option!(:tone, tone, ButtonHelper::BUTTON_TONES.keys)
187
+ data = { slot: "button", variant: lc_option!(:variant, variant, ButtonHelper::BUTTON_VARIANTS.keys), tone: (tone unless tone == :default), size: lc_option!(:size, size, ButtonHelper::BUTTON_SIZES.keys) }
188
+ lc_attributes(defaults.merge(class: lc_button_class(variant: variant, tone: tone, size: size, block: block), data: data), attributes)
189
+ end
190
+
191
+ def lc_icon_button_attributes(label, size, shape, defaults, attributes)
192
+ size = lc_option!(:size, size, ButtonHelper::ICON_BUTTON_SIZES.keys)
193
+ shape = lc_option!(:shape, shape, ButtonHelper::ICON_BUTTON_SHAPES.keys)
194
+ defaults = defaults.merge(class: lc_icon_button_class(size: size, shape: shape), aria: { label: label }, data: { slot: "icon-button", size: size })
195
+ attributes = lc_attributes(defaults, attributes)
196
+ accessible_label = attributes.fetch(:"aria-label", attributes.dig(:aria, :label))
197
+ raise ArgumentError, "lc_icon_button requires a nonblank accessible label" if label.blank? || accessible_label.blank?
198
+
199
+ attributes
200
+ end
201
+
202
+ def lc_icon_button_content(icon, &content)
203
+ raise ArgumentError, "Pass icon: or a block" unless icon || content
204
+
205
+ content ? capture(&content) : lc_icon(icon, options: { "aria-hidden": true })
128
206
  end
129
207
  end
130
208
  end