lostcoords-ui 0.7.0 → 0.8.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.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +338 -28
  3. data/app/assets/tailwind/lostcoords/ui/card.css +14 -6
  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/dialog.css +17 -0
  10. data/app/assets/tailwind/lostcoords/ui/emoji-picker.css +2 -1
  11. data/app/assets/tailwind/lostcoords/ui/popover.css +6 -4
  12. data/app/assets/tailwind/lostcoords/ui/search.css +96 -0
  13. data/app/assets/tailwind/lostcoords/ui/sheet.css +41 -8
  14. data/app/assets/tailwind/lostcoords/ui/theme.css +18 -0
  15. data/app/assets/tailwind/lostcoords/ui/toast.css +34 -4
  16. data/app/assets/tailwind/lostcoords/ui/typography.css +10 -0
  17. data/app/helpers/lostcoords/ui/badge_helper.rb +33 -15
  18. data/app/helpers/lostcoords/ui/button_helper.rb +71 -2
  19. data/app/helpers/lostcoords/ui/choice_helper.rb +9 -16
  20. data/app/helpers/lostcoords/ui/collapsible_helper.rb +26 -4
  21. data/app/helpers/lostcoords/ui/dialog_helper.rb +52 -12
  22. data/app/helpers/lostcoords/ui/form_helper.rb +30 -10
  23. data/app/helpers/lostcoords/ui/glass_helper.rb +6 -0
  24. data/app/helpers/lostcoords/ui/layout_helper.rb +13 -5
  25. data/app/helpers/lostcoords/ui/list_group_helper.rb +95 -0
  26. data/app/helpers/lostcoords/ui/menu_helper.rb +84 -13
  27. data/app/helpers/lostcoords/ui/navigation_helper.rb +57 -12
  28. data/app/helpers/lostcoords/ui/primitives_helper.rb +128 -34
  29. data/app/helpers/lostcoords/ui/render_attributes_helper.rb +3 -1
  30. data/app/helpers/lostcoords/ui/search_helper.rb +55 -0
  31. data/app/helpers/lostcoords/ui/sheet_helper.rb +20 -8
  32. data/app/helpers/lostcoords/ui/structures_helper.rb +114 -20
  33. data/app/helpers/lostcoords/ui/tailwind_helper.rb +1 -1
  34. data/app/helpers/lostcoords/ui/toast_helper.rb +11 -4
  35. data/app/helpers/lostcoords/ui/typography_helper.rb +5 -3
  36. data/app/javascript/lostcoords/ui/controllers/lc_menu_controller.js +5 -6
  37. data/app/javascript/lostcoords/ui/controllers/lc_nav_controller.js +79 -0
  38. data/app/javascript/lostcoords/ui/controllers/lc_search_controller.js +288 -0
  39. data/app/javascript/lostcoords/ui/controllers/lc_selection_controller.js +1 -6
  40. data/app/javascript/lostcoords/ui/controllers/lc_sheet_controller.js +29 -15
  41. data/app/javascript/lostcoords/ui/helpers/confirm.js +57 -0
  42. data/app/javascript/lostcoords/ui/helpers/floating_panel.js +9 -0
  43. data/app/javascript/lostcoords/ui/index.js +4 -2
  44. data/app/views/lostcoords/ui/components/_lc_collapsible.html.erb +3 -3
  45. data/app/views/lostcoords/ui/components/_lc_confirm_sheet.html.erb +14 -0
  46. data/app/views/lostcoords/ui/components/_lc_dialog.html.erb +28 -16
  47. data/app/views/lostcoords/ui/components/_lc_floating_panel.html.erb +11 -6
  48. data/app/views/lostcoords/ui/components/_lc_search.html.erb +26 -0
  49. data/config/locales/en.yml +11 -0
  50. data/config/locales/es.yml +11 -0
  51. data/config/locales/ja.yml +11 -0
  52. data/lib/lostcoords/ui/builders.rb +1 -1
  53. data/lib/lostcoords/ui/form_builder.rb +27 -12
  54. data/lib/lostcoords/ui/parts.rb +72 -8
  55. data/lib/lostcoords/ui/tokens.rb +3 -1
  56. data/lib/lostcoords/ui/version.rb +1 -1
  57. metadata +10 -2
  58. data/app/javascript/lostcoords/ui/controllers/lc_confirm_dialog_controller.js +0 -39
@@ -1,9 +1,31 @@
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
+ # button: { variant:, tone:, size: } styles the summary as that lc_button and drops the native marker.
10
+ def lc_collapsible(title: nil, open: false, card: true, summary_class: nil, indicator: :marker, button: nil, **attributes, &block)
11
+ indicator = lc_option!(:indicator, indicator, COLLAPSIBLE_INDICATORS)
12
+ indicator = :none if button && indicator == :marker
13
+ raise ArgumentError, "button: takes variant:, tone: and size:" if button && (button.keys - %i[variant tone size]).any?
14
+ parts = Parts::Collapsible.new(self)
15
+ content = capture(parts, &block) if block
16
+ summary = parts.summary_content || title
17
+ raise ArgumentError, "lc_collapsible needs a title: or a summary part" if summary.blank?
18
+ summary = tag.span(summary, class: "me-auto") if indicator == :chevron && parts.summary_content.nil?
19
+
20
+ summary_classes = lc_tw((button ? lc_button_class(**button) : "cursor-pointer text-label font-semibold"),
21
+ ("list-none [&::-webkit-details-marker]:hidden" unless indicator == :marker),
22
+ ("flex min-h-control-md items-center gap-related" if indicator == :chevron), summary_class)
23
+ 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
24
+ defaults = { class: (card ? lc_card_class(extra: "lc-collapsible") : "lc-collapsible"), open: open, data: { slot: "collapsible", controller: "lc-collapsible", action: "click->lc-collapsible#toggle" } }
25
+ render "lostcoords/ui/components/lc_collapsible",
26
+ summary: safe_join([ summary, chevron ].compact),
27
+ summary_attributes: lc_attributes({ class: summary_classes, data: { slot: "collapsible-summary" } }, parts.summary_attributes),
28
+ attributes: lc_attributes(defaults, attributes), content: content
7
29
  end
8
30
  end
9
31
  end
@@ -4,28 +4,68 @@ module Lostcoords::Ui
4
4
  SHEET_DIALOG_SURFACE =
5
5
  "sm:border sm:border-(--lc-glass-edge) sm:rounded-3xl sm:bg-popover text-popover-foreground sm:shadow-[var(--lc-glass-rim),var(--lc-shadow-lg)]"
6
6
 
7
- ANCHORED = "data-anchored:[inset:var(--lc-dialog-top)_var(--lc-dialog-right)_auto_auto] data-anchored:m-0"
7
+ # An anchored dialog opens below its trigger, so its height stops short of the viewport's bottom edge.
8
+ ANCHORED = "data-anchored:[inset:var(--lc-dialog-top)_var(--lc-dialog-right)_auto_auto] data-anchored:m-0 " \
9
+ "data-anchored:sm:max-h-[calc(100dvh-var(--lc-dialog-top)-1rem)]"
10
+
11
+ # The desktop width reads --lc-dialog-width, so a caller can widen the dialog or size content to it.
12
+ DIALOG_WIDTH = "sm:w-[min(var(--lc-dialog-width),calc(100vw-2rem))]"
8
13
 
9
14
  DIALOGS = {
10
- modal: "lc-dialog #{SHEET_DIALOG_SURFACE} sm:w-[min(92vw,31rem)]",
15
+ modal: "lc-dialog #{SHEET_DIALOG_SURFACE} #{DIALOG_WIDTH} sm:max-h-[calc(100dvh-2rem)]",
11
16
  context:
12
- "lc-dialog lc-dialog-context #{SHEET_DIALOG_SURFACE} sm:w-[min(22rem,calc(100vw-2rem))] " \
17
+ "lc-dialog lc-dialog-context #{SHEET_DIALOG_SURFACE} #{DIALOG_WIDTH} " \
13
18
  "sm:max-h-[calc(100dvh-2rem)] sm:origin-(--lc-dialog-origin,center) [--lc-dialog-from:scale(0.96)] #{ANCHORED}"
14
19
  }.freeze
15
20
 
16
- def lc_dialog_class(kind = :modal, extra: nil)
17
- lc_tw("lc-squircle", DIALOGS.fetch(lc_option!(:kind, kind, DIALOGS.keys)), extra)
21
+ # Desktop widths, set in dialog.css, which also applies them to content marked
22
+ # data-dialog-size="sm|md|lg|xl". Below sm every dialog is a full-width sheet.
23
+ DIALOG_SIZES = {
24
+ sm: "lc-dialog-sm",
25
+ md: "lc-dialog-md",
26
+ lg: "lc-dialog-lg",
27
+ xl: "lc-dialog-xl"
28
+ }.freeze
29
+
30
+ CONFIRM_SHEET_ID = "lc-confirm-sheet"
31
+
32
+ # size: :sm, :md, :lg or :xl. A modal defaults to :md; a context dialog keeps its compact width.
33
+ def lc_dialog_class(kind = :modal, size: nil, extra: nil)
34
+ kind = lc_option!(:kind, kind, DIALOGS.keys)
35
+ size = lc_option!(:size, size, DIALOG_SIZES.keys) unless size.nil?
36
+ size ||= :md if kind == :modal
37
+ lc_tw("lc-squircle", DIALOGS.fetch(kind), (DIALOG_SIZES.fetch(size) if size), extra)
18
38
  end
19
39
 
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)
40
+ # Yields a builder with trigger, actions, footer and close parts. dialog.trigger { |attrs| … } renders
41
+ # your own element as the trigger, with the attributes that open the dialog.
42
+ # trigger: false renders only the <dialog>, for a controller of your own to open; point close_action at it.
43
+ # title_attributes: and description_attributes: reach the heading and description, for a controller that rewrites them.
44
+ def lc_dialog(id:, title:, description: nil, trigger: lc_t("lostcoords.ui.dialog.trigger"), kind: :modal, size: nil, detents: "fit",
45
+ close_action: "lc-dialog#close", close_label: nil, title_attributes: {}, description_attributes: {}, **attributes, &block)
22
46
  lc_label!(id, :id)
23
47
  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)
48
+ lc_label!(trigger, :trigger) unless trigger == false
49
+ lc_label!(close_action, :close_action)
50
+ detents = lc_option!(:detents, detents, SheetHelper::SHEET_DETENTS.map(&:to_sym)).to_s
51
+ defaults = { class: lc_dialog_class(kind, size: size), aria: { describedby: ("#{id}-description" if description.present?) }, data: { slot: "dialog" } }
52
+ required = { id: id, aria: { labelledby: "#{id}-title" }, data: ({ lc_dialog_target: "dialog" } if trigger) }.compact
53
+ parts = Parts::Dialog.new(self, id, close_action)
54
+ content = capture(parts, &block) if block
55
+ title_tag = tag.h2(title, **lc_attributes({ class: lc_heading_class(size: :subheading), data: { slot: "dialog-title" } }, title_attributes, { id: "#{id}-title" }))
56
+ 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?
57
+ raise ArgumentError, "dialog.trigger can't be used with trigger: false" if trigger == false && parts.rendered_trigger
58
+ render "lostcoords/ui/components/lc_dialog", id: id, title: title_tag, description: description_tag, trigger: trigger, rendered_trigger: parts.rendered_trigger, detents: detents,
59
+ close_action: close_action, close_label: close_label || lc_t("lostcoords.ui.dialog.close", title: title),
60
+ attributes: lc_attributes(defaults, attributes, required), actions: parts.header_actions, content: content
61
+ end
62
+
63
+ # The sheet Turbo's confirm opens. Render it once in the layout and set
64
+ # Turbo.config.forms.confirm to `confirm` from lostcoords/ui/helpers/confirm.
65
+ def lc_confirm_sheet(**attributes)
66
+ defaults = { class: lc_dialog_class(:context), data: { slot: "confirm-sheet", turbo_permanent: true } }
67
+ required = { id: CONFIRM_SHEET_ID, tabindex: -1, aria: { labelledby: "#{CONFIRM_SHEET_ID}-message", describedby: "#{CONFIRM_SHEET_ID}-description" } }
68
+ render "lostcoords/ui/components/lc_confirm_sheet", id: CONFIRM_SHEET_ID, attributes: lc_attributes(defaults, attributes, required)
29
69
  end
30
70
  end
31
71
  end
@@ -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,29 @@ 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
+ # Text and nothing else: for a control inside a row that shows focus itself, such as lc_list_field.
33
+ INPUT_PLAIN =
34
+ "w-full max-w-full min-w-0 min-h-9 p-0 border-0 bg-transparent font-sans text-base text-foreground " \
35
+ "placeholder:text-muted-foreground aria-invalid:placeholder:text-destructive outline-none"
36
+
37
+ FIELD_BASE = "lc-field grid min-w-0 has-aria-invalid:[&>label]:text-destructive"
38
+ FIELD_SIZES = { sm: "gap-tight", md: "gap-related" }.freeze
39
+ # Field labels use the text roles; TypographyHelper loads after this file, so its sizes are read at call time.
40
+ FIELD_LABEL_ROLES = { sm: :caption, md: :label }.freeze
31
41
 
32
42
  FIELD_LABEL_BASE =
33
- "block font-sans text-label font-semibold text-muted-foreground " \
43
+ "block font-sans font-semibold text-muted-foreground " \
34
44
  "transition-colors duration-(--lc-motion-quick) ease-(--lc-ease-out)"
35
45
 
36
46
  # 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)
47
+ # render library controls. card: true makes the form the card, and gap: makes it a stack, so the
48
+ # form needs no wrapper element.
49
+ def lc_form_with(card: false, padding: :md, gap: nil, **options, &block)
50
+ if card || gap
51
+ stack = lc_stack_class(gap: gap || :inset)
52
+ layout = { class: card ? lc_card_class(padding: padding, extra: stack) : stack, data: ({ slot: "card" } if card) }.compact
53
+ options = lc_attributes(layout, options)
54
+ end
39
55
  form_with(**options, builder: Lostcoords::Ui::FormBuilder, &block)
40
56
  end
41
57
 
@@ -47,8 +63,11 @@ module Lostcoords::Ui
47
63
  lc_tw(TOGGLE_GROUP_ITEM_BASE, (TOGGLE_GROUP_ITEM_ACTIVE if active), extra)
48
64
  end
49
65
 
50
- def lc_input_class(size: :md, extra: nil)
51
- lc_tw(INPUT_BASE, TailwindHelper::CONTROL_SIZES.fetch(lc_option!(:size, size, TailwindHelper::CONTROL_SIZES.keys)), extra)
66
+ def lc_input_class(size: :md, plain: false, extra: nil)
67
+ size = lc_option!(:size, size, TailwindHelper::CONTROL_SIZES.keys)
68
+ return lc_tw(INPUT_PLAIN, extra) if plain
69
+
70
+ lc_tw(INPUT_BASE, TailwindHelper::CONTROL_SIZES.fetch(size), extra)
52
71
  end
53
72
 
54
73
 
@@ -60,12 +79,13 @@ module Lostcoords::Ui
60
79
  lc_tw(INPUT_BASE, "min-h-28 py-2 resize-y", extra)
61
80
  end
62
81
 
63
- def lc_field_class(extra: nil)
64
- lc_tw(FIELD_BASE, extra)
82
+ def lc_field_class(size: :md, extra: nil)
83
+ lc_tw(FIELD_BASE, FIELD_SIZES.fetch(lc_option!(:size, size, FIELD_SIZES.keys)), extra)
65
84
  end
66
85
 
67
- def lc_field_label_class(extra: nil)
68
- lc_tw(FIELD_LABEL_BASE, extra)
86
+ def lc_field_label_class(size: :md, extra: nil)
87
+ role = FIELD_LABEL_ROLES.fetch(lc_option!(:size, size, FIELD_LABEL_ROLES.keys))
88
+ lc_tw(FIELD_LABEL_BASE, TypographyHelper::TEXT_SIZES.fetch(role), extra)
69
89
  end
70
90
  end
71
91
  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,95 @@
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
+ LIST_FIELD_TAGS = %i[div fieldset span].freeze
9
+ LIST_FIELD = "@container px-content py-2.5 transition-colors duration-(--lc-motion-quick) has-[[data-plain]:focus]:bg-accent"
10
+ 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)]"
11
+ LIST_FIELD_LABEL =
12
+ "flex items-center gap-related text-label font-semibold text-muted-foreground " \
13
+ "[&_svg]:size-5 [&_svg]:shrink-0 @md:[&_svg]:size-4.5"
14
+
15
+ # A titled group of list rows: the heading, then the block, then an optional footnote. The block
16
+ # holds lc_list_group and anything that belongs with it, such as the form that wraps the rows.
17
+ def lc_list_section(heading, footnote: nil, level: 2, **attributes, &block)
18
+ lc_label!(heading, :heading)
19
+ raise ArgumentError, "Invalid level: #{level.inspect}. Expected an integer from 1 to 6" unless level.is_a?(Integer) && (1..6).include?(level)
20
+
21
+ heading_id = "#{attributes[:id]}-heading" if attributes[:id]
22
+ tag.section(**lc_attributes({ class: "grid min-w-0 gap-related", aria: { labelledby: heading_id }, data: { slot: "list-section" } }, attributes)) do
23
+ safe_join([
24
+ 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" }),
25
+ (capture(&block) if block),
26
+ (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?)
27
+ ].compact)
28
+ end
29
+ end
30
+
31
+ # Rows as in iOS settings: each row is its own card-coloured panel, 2px apart, and only the
32
+ # first and last rows round.
33
+ def lc_list_group(tag: :div, **attributes, &block)
34
+ tag = lc_option!(:tag, tag, %i[div ul])
35
+ 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))
36
+ end
37
+
38
+ # With a title, the row lays out icon:, the title and subtitle, then the block as its trailing
39
+ # content. Without one, the block is the whole row; padded: false drops the row's padding for
40
+ # content that pads itself, such as an lc_list_item button. href: makes the row a link.
41
+ def lc_list_row(title = nil, subtitle: nil, icon: nil, href: nil, tag: nil, padded: true, **attributes, &block)
42
+ tag = lc_option!(:tag, tag || (href ? :a : :div), LIST_ROW_TAGS)
43
+ raise ArgumentError, "href: needs tag: :a" if href && tag != :a
44
+
45
+ link = ("no-underline transition-colors duration-(--lc-motion-quick) hover:bg-accent" if href)
46
+ defaults = { href: href, data: { slot: "list-row" } }
47
+ return lc_list_item(title, subtitle: subtitle, icon: icon, tag: tag, **lc_attributes(defaults.merge(class: lc_tw(LIST_ROW, link)), attributes), &block) if title.present?
48
+
49
+ classes = lc_tw(LIST_ROW, (LIST_ROW_PADDING if padded), link)
50
+ content_tag(tag, (capture(&block) if block), **lc_attributes(defaults.merge(class: classes), attributes))
51
+ end
52
+
53
+ # A form row: a label column, then the block as the control. In a narrow row the label folds to
54
+ # icon: alone and stays the accessible name. id: makes the label a <label> for that control;
55
+ # tag: :fieldset names a group of controls with a legend. surface: false drops the row's panel,
56
+ # for a row drawn inside another element, such as a collapsible's summary (with tag: :span).
57
+ def lc_list_field(label, icon: nil, id: nil, tag: :div, surface: true, **attributes, &block)
58
+ lc_label!(label, :label)
59
+ tag = lc_option!(:tag, tag, LIST_FIELD_TAGS)
60
+ raise ArgumentError, "id: labels one control; a fieldset is named by its legend" if id && tag == :fieldset
61
+
62
+ inline = tag == :span ? :span : :div
63
+ text = content_tag(:span, label, class: "@max-md:sr-only", data: { slot: "list-field-text" })
64
+ glyph = (icon.is_a?(ActiveSupport::SafeBuffer) ? icon : lc_icon(icon, options: { "aria-hidden": true })) if icon.present?
65
+ label_classes = lc_tw(LIST_FIELD_LABEL, ("self-start min-h-control-sm" if tag == :fieldset))
66
+ label_tag = if id
67
+ content_tag(:label, safe_join([ glyph, text ].compact), for: id, class: label_classes, data: { slot: "list-field-label" })
68
+ else
69
+ content_tag(:span, safe_join([ glyph, text ].compact), class: label_classes, aria: { hidden: (true if tag == :fieldset) }, data: { slot: "list-field-label" })
70
+ end
71
+ grid = content_tag(inline, safe_join([ label_tag, (capture(&block) if block) ].compact), class: LIST_FIELD_GRID)
72
+ legend = content_tag(:legend, label, class: "sr-only") if tag == :fieldset
73
+ classes = lc_tw((LIST_ROW if surface), LIST_FIELD, ("block" if tag == :span), ("m-0 min-w-0 border-0" if tag == :fieldset))
74
+ content_tag(tag, safe_join([ legend, grid ].compact), **lc_attributes({ class: classes, data: { slot: "list-field" } }, attributes))
75
+ end
76
+
77
+ # The row layout without the row's surface, for an element inside a free-form row: a summary, a
78
+ # button that opens an editor. icon: takes an icon name or your own markup, such as a logo.
79
+ def lc_list_item(title, subtitle: nil, icon: nil, tag: :div, **attributes, &block)
80
+ lc_label!(title, :title)
81
+ glyph = icon.is_a?(ActiveSupport::SafeBuffer) ? icon : lc_icon(icon) if icon.present?
82
+ content_tag(tag, **lc_attributes({ class: LIST_ITEM, data: { slot: "list-item" } }, attributes)) do
83
+ text = safe_join([
84
+ content_tag(:span, title, class: "font-semibold", data: { slot: "list-title" }),
85
+ (content_tag(:span, subtitle, class: "text-small text-muted-foreground [overflow-wrap:anywhere]", data: { slot: "list-subtitle" }) if subtitle.present?)
86
+ ].compact)
87
+ safe_join([
88
+ (content_tag(:span, glyph, class: LIST_ICON, aria: { hidden: true }, data: { slot: "list-icon" }) if glyph),
89
+ content_tag(:span, text, class: "grid min-w-0 flex-1 gap-0.5", data: { slot: "list-text" }),
90
+ (capture(&block) if block)
91
+ ].compact)
92
+ end
93
+ end
94
+ end
95
+ 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,17 @@ 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
+
38
+ MENU_GROUP_BASE = "col-span-full grid grid-cols-subgrid gap-y-px"
39
+ MENU_GROUP_LABEL = "col-span-full px-3 pt-2 pb-1"
40
+
29
41
  def lc_popover_class(align: :end, extra: nil)
30
42
  lc_glass_class(shape: :menu, extra: lc_tw(POPOVER_BASE, MENU_POPOVER_ALIGN.fetch(lc_option!(:align, align, MENU_POPOVER_ALIGN.keys)), extra))
31
43
  end
@@ -38,23 +50,49 @@ module Lostcoords::Ui
38
50
  lc_tw(MENU_OPTION_BASE, MENU_OPTION_TONES.fetch(lc_option!(:tone, tone, MENU_OPTION_TONES.keys)), extra)
39
51
  end
40
52
 
41
- def lc_menu(id:, label: lc_t("lostcoords.ui.menu.label"), align: :end, **attributes, &block)
53
+ # 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)
42
56
  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)
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)
44
59
  end
45
60
 
46
- def lc_popover(id:, label: lc_t("lostcoords.ui.popover.trigger"), title: nil, align: :end, trigger_variant: :secondary, **attributes, &block)
61
+ # Takes the same trigger options as lc_menu, including trigger: false.
62
+ 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
63
  title = title.presence
48
64
  align = lc_option!(:align, align, MENU_POPOVER_ALIGN.keys)
65
+ default_trigger = ->(wiring) { lc_panel_trigger(label, trigger, icon, trigger_variant, wiring) } unless trigger == false
49
66
  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)
67
+ lc_render_panel(id, label, title, "lc-popover", "dialog", classes, lc_attributes({ data: { slot: "popover" } }, attributes), default_trigger, trigger_attributes, wrapper_attributes, &block)
51
68
  end
52
69
 
53
- def lc_menu_option(label = nil, href: nil, tone: :default, **attributes, &block)
70
+ # icon: names a leading Heroicon; leading: takes other rendered content, such as an avatar, and is
71
+ # hidden from assistive technology so the label stays the name. checked: true or false makes a
72
+ # 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
+ 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
75
  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
76
+ raise ArgumentError, "Pass icon: or leading:, not both" if icon && leading
77
+ raise ArgumentError, "checked: must be true, false or nil" unless [ true, false, nil ].include?(checked)
78
+ raise ArgumentError, "method: needs an href:" if method && !href
79
+ raise ArgumentError, "checkbox: true renders a button; drop href:" if checkbox && href
80
+ checked = !!checked if checkbox
81
+
82
+ leading = lc_icon(icon, options: { class: MENU_OPTION_ICON }) if icon
83
+ text = block ? capture(&block) : label
84
+ content = safe_join([
85
+ (tag.span(leading, class: MENU_OPTION_LEADING, aria: { hidden: true }, data: { slot: "menu-item-leading" }) if leading),
86
+ 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),
87
+ (lc_icon("check", variant: :mini, options: { class: MENU_OPTION_CHECK, "aria-hidden": true }) unless checked.nil?)
88
+ ])
89
+ role = checkbox ? "menuitemcheckbox" : (checked.nil? ? "menuitem" : "menuitemradio")
90
+ 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" } }
91
+ defaults[:aria] = { checked: checked } unless checked.nil?
92
+
93
+ if method
94
+ button_to(content, href, **lc_attributes(defaults, attributes), method: method, params: params, form: lc_attributes({ class: "contents" }, form))
95
+ elsif href
58
96
  raise ArgumentError, "Links cannot be disabled; use a menu button instead" if attributes[:disabled] || attributes["disabled"]
59
97
 
60
98
  tag.a(content, **lc_attributes(defaults.merge(href: href), attributes))
@@ -63,14 +101,47 @@ module Lostcoords::Ui
63
101
  end
64
102
  end
65
103
 
104
+ # A labelled run of options inside a menu panel. Its options stay on the menu's columns.
105
+ def lc_menu_group(label, id:, **attributes, &block)
106
+ lc_label!(label, :label)
107
+ lc_label!(id, :id)
108
+ heading = lc_text(label, size: :eyebrow, tone: :muted, as: :div, id: "#{id}-label", class: MENU_GROUP_LABEL, role: "presentation")
109
+ tag.div(safe_join([ heading, capture(&block) ]), **lc_attributes({ class: MENU_GROUP_BASE, data: { slot: "menu-group" } }, attributes, { id: id, role: "group", aria: { labelledby: "#{id}-label" } }))
110
+ end
111
+
66
112
  private
67
- def lc_render_panel(id, label, title, controller, role, classes, attributes, trigger_variant: :secondary, &block)
113
+ def lc_panel_trigger(label, trigger, icon, variant, attributes)
114
+ custom = trigger.is_a?(String) && trigger.html_safe?
115
+ kind = custom ? :custom : lc_option!(:trigger, trigger, MENU_TRIGGERS)
116
+ case kind
117
+ when :custom, :icon
118
+ content = custom ? trigger : lc_icon(icon, options: { "aria-hidden": true })
119
+ 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" } }
120
+ tag.button(content, **lc_attributes(icon_button, attributes))
121
+ else
122
+ lc_button(label, variant: variant, **attributes)
123
+ end
124
+ end
125
+
126
+ # The block runs before the default trigger renders, so a menu.trigger part can replace it.
127
+ # trigger: false renders only the panel, for a caller that hosts the controller on an ancestor
128
+ # and wires its own triggers.
129
+ def lc_render_panel(id, label, title, controller, role, classes, attributes, default_trigger, trigger_attributes, wrapper_attributes, &block)
68
130
  lc_label!(id, :id)
69
131
  lc_label!(label, :label)
70
- required = { id: id, role: role, aria: { labelledby: "#{id}-#{title ? 'title' : 'trigger'}" }, data: { "#{controller}_target" => "popover" } }
132
+ standalone = default_trigger.nil?
133
+ raise ArgumentError, "trigger: false renders no trigger or wrapper" if standalone && (trigger_attributes.present? || wrapper_attributes.present?)
134
+
135
+ wiring = { id: "#{id}-trigger", aria: { haspopup: role, expanded: false, controls: id }, data: { "#{controller}_target" => "trigger", action: "#{controller}#toggle" } }
136
+ parts = Parts::Panel.new(self, wiring)
137
+ content = capture(parts, &block) if block
138
+ trigger = parts.rendered_trigger || default_trigger.call(lc_attributes(trigger_attributes, wiring)) unless standalone
139
+ name = if title then { labelledby: "#{id}-title" } elsif standalone then { label: label } else { labelledby: "#{id}-trigger" } end
140
+ required = { id: id, role: role, aria: name, data: { "#{controller}_target" => "popover" } }
71
141
  required[:tabindex] = -1 if role == "dialog"
72
142
  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)
143
+ wrapper = lc_attributes({ class: "relative inline-flex" }, wrapper_attributes, { data: { controller: controller } }) unless standalone
144
+ render "lostcoords/ui/components/lc_floating_panel", id: id, title: title, wrapper: wrapper, trigger: trigger, attributes: merged, content: content
74
145
  end
75
146
  end
76
147
  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 bg-(--lc-nav-dock-indicator,var(--lc-nav-indicator,var(--accent)))"
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 max-sm:bg-(--lc-nav-dock-indicator,var(--lc-nav-indicator,var(--accent))) 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