phlex_kit 0.15.0 → 0.16.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7e817130c54d3e6a8c547328c09b8e632e13adda0cafa7ed0f415359fd1c0ed9
4
- data.tar.gz: bcb04540a46d3442ac21b8d54d10b1f903bbcf33af2ec65344e7ad6879ab8462
3
+ metadata.gz: 5970949c9d2e28fee9964407ceb7df89ca7b00bd04e8a32d33ed4369c03796d3
4
+ data.tar.gz: 3a6d4cf2ea38958195395fac9ba28ca88aa71216d47a404a514aaec6d3dcb4b7
5
5
  SHA512:
6
- metadata.gz: ad56db4fec9925c964ed13084658ddf29942d79d17d4cd141bdb3efa0bef5d3e0be0c6c9ff8f53b28da163dfb0f080c1a79c8330b806f01823e0e092b479a5f5
7
- data.tar.gz: 3e90c49dc0cb097b2aee66a28d7537c7c834df03015338832e6f00c9cbe40c93374d7a1d034a3c9765b848dc12407afc44681d2b6ef4aa62176295fecb1f3ad2
6
+ metadata.gz: 2967eeb7c11ccec4a50c3f136b42961cd2564815894983145715f3f4771104ed23d597e46f4009bd1942d3e8f29d1d385b43042a1872586e3b29548a498680d1
7
+ data.tar.gz: 4b9fee8a7c0449e816fc92bdb0573e507a86b92334ae81dd3cbf701ac6b980de1d9aac58cb2eaf16d1318e3a80d439056cb0670924e84b346b329ab31cfa92d4
@@ -6,10 +6,12 @@ module PhlexKit
6
6
  # See alert_dialog.rb.
7
7
  class AlertDialogContent < BaseComponent
8
8
  # size => panel modifier; :sm is shadcn's compact variant.
9
- SIZES = { default: nil, sm: "sm" }.freeze
9
+ SIZES = { md: nil, sm: "sm" }.freeze
10
10
 
11
- def initialize(size: :default, **attrs)
11
+ def initialize(size: :md, labelledby: nil, describedby: nil, **attrs)
12
12
  @size = size.to_sym
13
+ @labelledby = labelledby
14
+ @describedby = describedby
13
15
  @attrs = attrs
14
16
  end
15
17
 
@@ -32,6 +34,8 @@ module PhlexKit
32
34
  # tabindex="-1 0" instead of overriding.
33
35
  panel_attrs[:role] = "alertdialog" unless attr_set?(:role)
34
36
  panel_attrs[:"aria-modal"] = "true" unless aria_key_set?(:modal)
37
+ panel_attrs[:"aria-labelledby"] = @labelledby if @labelledby
38
+ panel_attrs[:"aria-describedby"] = @describedby if @describedby
35
39
  panel_attrs[:tabindex] = "-1" unless attr_set?(:tabindex)
36
40
  div(**mix(panel_attrs, @attrs), &block)
37
41
  end
@@ -8,10 +8,10 @@ module PhlexKit
8
8
  # `.pk-attachment*` (attachment.css).
9
9
  class Attachment < BaseComponent
10
10
  STATES = { idle: "idle", uploading: "uploading", processing: "processing", error: "error", done: "done" }.freeze
11
- SIZES = { default: nil, sm: "sm", xs: "xs" }.freeze
11
+ SIZES = { md: nil, sm: "sm", xs: "xs" }.freeze
12
12
  ORIENTATIONS = { horizontal: nil, vertical: "vertical" }.freeze
13
13
 
14
- def initialize(state: :done, size: :default, orientation: :horizontal, **attrs)
14
+ def initialize(state: :done, size: :md, orientation: :horizontal, **attrs)
15
15
  @state = state.to_sym
16
16
  @size = size.to_sym
17
17
  @orientation = orientation.to_sym
@@ -19,9 +19,9 @@ module PhlexKit
19
19
  # end
20
20
  class Card < BaseComponent
21
21
  # size => modifier class; :sm tightens --pk-card-spacing (shadcn's size prop).
22
- SIZES = { default: nil, sm: "sm" }.freeze
22
+ SIZES = { md: nil, sm: "sm" }.freeze
23
23
 
24
- def initialize(size: :default, **attrs)
24
+ def initialize(size: :md, **attrs)
25
25
  @size = size.to_sym
26
26
  @attrs = attrs
27
27
  end
@@ -7,9 +7,18 @@ module PhlexKit
7
7
  class CommandDialogContent < BaseComponent
8
8
  SIZES = { xs: "xs", sm: "sm", md: nil, lg: "lg", xl: "xl", full: "full" }.freeze
9
9
 
10
- def initialize(size: :md, aria_label: "Command palette", **attrs)
10
+ DEFAULT_LABEL = "Command palette"
11
+
12
+ def initialize(size: :md, labelledby: nil, describedby: nil, **attrs)
13
+ # aria_label: was the API through 0.15.0 — overlays now name themselves
14
+ # with labelledby:/describedby: like every other overlay content. A bare
15
+ # accessible name still rides attrs, same as anywhere else in the kit.
16
+ if attrs.key?(:aria_label) || attrs.key?("aria_label")
17
+ raise ArgumentError, "CommandDialogContent does not support aria_label: — pass aria: { label: \"…\" }, or labelledby: for an id reference"
18
+ end
11
19
  @size = size.to_sym
12
- @aria_label = aria_label
20
+ @labelledby = labelledby
21
+ @describedby = describedby
13
22
  @attrs = attrs
14
23
  end
15
24
 
@@ -35,7 +44,10 @@ module PhlexKit
35
44
  panel_attrs[:role] = "dialog" unless attr_set?(:role)
36
45
  aria = {}
37
46
  aria[:modal] = "true" unless aria_key_set?(:modal)
38
- aria[:label] = @aria_label unless aria_labelled?
47
+ aria[:labelledby] = @labelledby if @labelledby
48
+ aria[:describedby] = @describedby if @describedby
49
+ # Falls back to a default name only when nothing else names it.
50
+ aria[:label] = DEFAULT_LABEL unless @labelledby || aria_labelled?
39
51
  panel_attrs[:aria] = aria unless aria.empty?
40
52
  div(**mix(panel_attrs, @attrs), &block)
41
53
  end
@@ -5,8 +5,10 @@ module PhlexKit
5
5
  class DrawerContent < BaseComponent
6
6
  SIDES = { bottom: "bottom", top: "top", left: "left", right: "right" }.freeze
7
7
 
8
- def initialize(side: :bottom, **attrs)
8
+ def initialize(side: :bottom, labelledby: nil, describedby: nil, **attrs)
9
9
  @side = side.to_sym
10
+ @labelledby = labelledby
11
+ @describedby = describedby
10
12
  @attrs = attrs
11
13
  end
12
14
 
@@ -19,7 +21,11 @@ module PhlexKit
19
21
  # would fuse role="dialog region" / aria-modal="true false" /
20
22
  # tabindex="-1 0" instead of overriding.
21
23
  panel_attrs[:role] = "dialog" unless attr_set?(:role)
22
- panel_attrs[:aria] = { modal: "true" } unless aria_key_set?(:modal)
24
+ aria = {}
25
+ aria[:modal] = "true" unless aria_key_set?(:modal)
26
+ aria[:labelledby] = @labelledby if @labelledby
27
+ aria[:describedby] = @describedby if @describedby
28
+ panel_attrs[:aria] = aria unless aria.empty?
23
29
  panel_attrs[:tabindex] = "-1" unless attr_set?(:tabindex)
24
30
  div(**mix(panel_attrs, @attrs)) do
25
31
  div(class: "pk-drawer-handle", aria: { hidden: "true" })
@@ -13,20 +13,20 @@ module PhlexKit
13
13
  #
14
14
  # The yielded block is the <option>/<optgroup> list; `name:`/`id:`/`required:`/
15
15
  # `**on(...)` pass through to the <select> via `mix`. `size:` is the kit's lone
16
- # selector here (default | sm) — `SIZES.fetch` fails loud on anything else.
16
+ # selector here (md | sm) — `SIZES.fetch` fails loud on anything else.
17
17
  class NativeSelect < BaseComponent
18
- # size => extra class appended after the base select class (nil = default).
18
+ # size => extra class appended after the base select class (nil = md).
19
19
  SIZES = {
20
- default: nil,
20
+ md: nil,
21
21
  sm: "sm"
22
22
  }.freeze
23
23
 
24
24
  # An Integer size: is the NATIVE <select size> (multi-row list box) and
25
25
  # passes straight through — the kit's visual sizes stay symbols.
26
- def initialize(size: :default, **attrs)
26
+ def initialize(size: :md, **attrs)
27
27
  if size.is_a?(Integer)
28
28
  @native_size = size
29
- @size = :default
29
+ @size = :md
30
30
  else
31
31
  @size = size.to_sym
32
32
  end
@@ -60,9 +60,12 @@ export default class extends Controller {
60
60
  // Only the initiating pointer drives the drag — a second touch point
61
61
  // over the handle must not hijack it.
62
62
  if (ev.pointerId !== e.pointerId) return
63
- // LTR assumption: clientX grows toward the trailing panel; RTL drag
64
- // inversion is a documented limitation.
65
- const delta = (horizontal ? ev.clientX : ev.clientY) - drag.startPos
63
+ // clientX grows toward the trailing panel in LTR but toward the LEADING
64
+ // one in RTL, where the row runs right-to-left — negate so the divider
65
+ // follows the pointer in both directions. (Vertical groups are
66
+ // unaffected: clientY is direction-independent.)
67
+ const raw = (horizontal ? ev.clientX : ev.clientY) - drag.startPos
68
+ const delta = horizontal && this.isRtl() ? -raw : raw
66
69
  const total = drag.prevSize + drag.nextSize
67
70
  const prevSize = Math.min(Math.max(drag.prevSize + delta, 0), total)
68
71
  const prevGrow = this.clampPrevGrow(prev, next, (prevSize / total) * drag.pairGrow, drag.pairGrow, drag.groupGrow)
@@ -100,7 +103,7 @@ export default class extends Controller {
100
103
  // ArrowLeft must GROW it (move the divider visually left). Only the
101
104
  // pointer-drag clientX math keeps its documented LTR exemption; Up/Down
102
105
  // never flip. Runtime dir check — reliable after a dynamic flip.
103
- const rtl = horizontal && getComputedStyle(this.element).direction === "rtl"
106
+ const rtl = horizontal && this.isRtl()
104
107
  const steps = horizontal
105
108
  ? (rtl ? { ArrowLeft: 0.05, ArrowRight: -0.05 } : { ArrowLeft: -0.05, ArrowRight: 0.05 })
106
109
  : { ArrowUp: -0.05, ArrowDown: 0.05 }
@@ -125,6 +128,12 @@ export default class extends Controller {
125
128
  this.handleTargets.forEach((h) => this.syncValuenow(h))
126
129
  }
127
130
 
131
+ // Read at use time, not connect: a dynamic dir flip must take effect
132
+ // immediately (the same reason the keyboard handler checks it inline).
133
+ isRtl() {
134
+ return getComputedStyle(this.element).direction === "rtl"
135
+ }
136
+
128
137
  growOf(el) {
129
138
  const g = parseFloat(getComputedStyle(el).flexGrow)
130
139
  return Number.isFinite(g) ? g : 1
@@ -2,9 +2,11 @@ module PhlexKit
2
2
  class SheetContent < BaseComponent
3
3
  SIDES = { top: "top", right: "right", bottom: "bottom", left: "left" }.freeze
4
4
 
5
- def initialize(side: :right, show_close_button: true, **attrs)
5
+ def initialize(side: :right, show_close_button: true, labelledby: nil, describedby: nil, **attrs)
6
6
  @side = side.to_sym
7
7
  @show_close_button = show_close_button
8
+ @labelledby = labelledby
9
+ @describedby = describedby
8
10
  @attrs = attrs
9
11
  end
10
12
  def view_template(&block)
@@ -19,7 +21,11 @@ module PhlexKit
19
21
  # would fuse role="dialog region" / aria-modal="true false" /
20
22
  # tabindex="-1 0" instead of overriding.
21
23
  panel_attrs[:role] = "dialog" unless attr_set?(:role)
22
- panel_attrs[:aria] = { modal: "true" } unless aria_key_set?(:modal)
24
+ aria = {}
25
+ aria[:modal] = "true" unless aria_key_set?(:modal)
26
+ aria[:labelledby] = @labelledby if @labelledby
27
+ aria[:describedby] = @describedby if @describedby
28
+ panel_attrs[:aria] = aria unless aria.empty?
23
29
  panel_attrs[:tabindex] = "-1" unless attr_set?(:tabindex)
24
30
  div(**mix(panel_attrs, @attrs)) do
25
31
  block&.call
@@ -20,7 +20,7 @@
20
20
  width: 16rem;
21
21
  flex-shrink: 0;
22
22
  background: var(--pk-sidebar, var(--pk-surface));
23
- border-right: 1px solid var(--pk-sidebar-border, var(--pk-border));
23
+ border-inline-end: 1px solid var(--pk-sidebar-border, var(--pk-border));
24
24
  }
25
25
 
26
26
  .pk-sidebar-header { display: flex; flex-direction: column; gap: .5rem; padding: 1rem .75rem .25rem; }
@@ -172,9 +172,9 @@
172
172
  /* visibility rides the transition: it stays visible while sliding out and
173
173
  flips hidden at the end — hidden also drops the off-screen links from
174
174
  the tab order (they stayed focusable while invisible before). */
175
- transition: margin-left .2s ease, transform .2s ease, width .2s ease, visibility .2s;
175
+ transition: margin-inline-start .2s ease, margin-inline-end .2s ease, transform .2s ease, width .2s ease, visibility .2s;
176
176
  }
177
- .pk-sidebar-wrapper.collapsible-offcanvas[data-collapsed] .pk-sidebar { margin-left: -16rem; visibility: hidden; }
177
+ .pk-sidebar-wrapper.collapsible-offcanvas[data-collapsed] .pk-sidebar { margin-inline-start: -16rem; visibility: hidden; }
178
178
 
179
179
  /* Icon mode: the rail shrinks to a 3rem strip — labels and text hide, menu
180
180
  buttons become centered icon squares, hover shows a data-tooltip bubble. */
@@ -203,7 +203,7 @@
203
203
  .pk-sidebar-wrapper.collapsible-icon[data-collapsed] .pk-sidebar-menu-button[data-tooltip]:hover::after {
204
204
  content: attr(data-tooltip);
205
205
  position: absolute;
206
- left: calc(100% + .625rem);
206
+ inset-inline-start: calc(100% + .625rem);
207
207
  top: 50%;
208
208
  transform: translateY(-50%);
209
209
  z-index: 60;
@@ -220,7 +220,7 @@
220
220
  .pk-sidebar-rail {
221
221
  position: absolute;
222
222
  inset-block: 0;
223
- right: -.5rem;
223
+ inset-inline-end: -.5rem;
224
224
  z-index: 20;
225
225
  width: 1rem;
226
226
  border: 0;
@@ -236,7 +236,7 @@
236
236
  content: "";
237
237
  position: absolute;
238
238
  inset-block: 0;
239
- left: 50%;
239
+ inset-inline-start: 50%;
240
240
  width: 2px;
241
241
  background: var(--pk-sidebar-border, var(--pk-border));
242
242
  }
@@ -269,11 +269,15 @@
269
269
  .pk-sidebar-wrapper:is(.collapsible-offcanvas, .collapsible-icon) .pk-sidebar {
270
270
  position: fixed;
271
271
  inset-block: 0;
272
- left: 0;
272
+ inset-inline-start: 0;
273
273
  z-index: 50;
274
274
  height: 100dvh;
275
- margin-left: 0;
276
- transform: translateX(-100%);
275
+ margin-inline-start: 0;
276
+ margin-inline-end: 0;
277
+ /* translateX is physical, so the hide vector can't be expressed logically:
278
+ the drawer must slide out through whichever edge it is pinned to.
279
+ --pk-sidebar-hide-x is flipped by the side-end / [dir=rtl] arms below. */
280
+ transform: translateX(var(--pk-sidebar-hide-x, -100%));
277
281
  /* closed drawer: invisible AND out of the tab order */
278
282
  visibility: hidden;
279
283
  box-shadow: 0 8px 30px color-mix(in srgb, var(--pk-shadow-color) 35%, transparent);
@@ -294,3 +298,42 @@
294
298
  @media (prefers-reduced-motion: reduce) {
295
299
  .pk-sidebar-wrapper:is(.collapsible-offcanvas, .collapsible-icon) .pk-sidebar { transition: none; }
296
300
  }
301
+
302
+ /* --- side: :end -----------------------------------------------------------
303
+ The panel moves to the far edge. `order` flips it inside the wrapper's flex
304
+ row without touching markup, and every edge-anchored piece mirrors with it:
305
+ the border, the offcanvas collapse margin, the rail strip and the icon-mode
306
+ tooltip bubble. All logical, so :start/:end stay reading-relative in RTL. */
307
+ .pk-sidebar-wrapper.side-end .pk-sidebar {
308
+ order: 1;
309
+ border-inline-end: 0;
310
+ border-inline-start: 1px solid var(--pk-sidebar-border, var(--pk-border));
311
+ }
312
+ .pk-sidebar-wrapper.side-end.collapsible-offcanvas[data-collapsed] .pk-sidebar {
313
+ margin-inline-start: 0;
314
+ margin-inline-end: -16rem;
315
+ }
316
+ .pk-sidebar-wrapper.side-end .pk-sidebar-rail {
317
+ inset-inline-end: auto;
318
+ inset-inline-start: -.5rem;
319
+ }
320
+ .pk-sidebar-wrapper.side-end.collapsible-icon[data-collapsed] .pk-sidebar-menu-button[data-tooltip]:hover::after {
321
+ inset-inline-start: auto;
322
+ inset-inline-end: calc(100% + .625rem);
323
+ }
324
+
325
+ /* The mobile drawer's hide vector, per side x direction. Attribute selectors
326
+ (not :dir()) so a dynamic dir flip re-styles existing elements — see the
327
+ kit-wide RTL note. */
328
+ .pk-sidebar-wrapper.side-end { --pk-sidebar-hide-x: 100%; }
329
+ [dir="rtl"] .pk-sidebar-wrapper { --pk-sidebar-hide-x: 100%; }
330
+ [dir="rtl"] .pk-sidebar-wrapper.side-end { --pk-sidebar-hide-x: -100%; }
331
+
332
+ /* The rail's resize cursor is a physical affordance: which way the panel
333
+ collapses depends on the side AND the direction. */
334
+ .pk-sidebar-wrapper.side-end .pk-sidebar-rail,
335
+ [dir="rtl"] .pk-sidebar-wrapper .pk-sidebar-rail { cursor: e-resize; }
336
+ .pk-sidebar-wrapper.side-end[data-collapsed] .pk-sidebar-rail,
337
+ [dir="rtl"] .pk-sidebar-wrapper[data-collapsed] .pk-sidebar-rail { cursor: w-resize; }
338
+ [dir="rtl"] .pk-sidebar-wrapper.side-end .pk-sidebar-rail { cursor: w-resize; }
339
+ [dir="rtl"] .pk-sidebar-wrapper.side-end[data-collapsed] .pk-sidebar-rail { cursor: e-resize; }
@@ -20,12 +20,20 @@ module PhlexKit
20
20
  # `default_collapsed: cookies[:pk_sidebar_state] == "collapsed"` from the
21
21
  # host layout to render the collapsed rail server-side with no flash.
22
22
  # Add a PhlexKit::SidebarRail inside the Sidebar for the edge grab-strip.
23
+ # `side:` is logical — :start (default) pins it to the reading-start edge,
24
+ # :end to the far edge; both flip with the document direction.
23
25
  # See sidebar.rb.
24
26
  class SidebarWrapper < BaseComponent
25
27
  COLLAPSIBLE = { none: nil, offcanvas: "collapsible-offcanvas", icon: "collapsible-icon" }.freeze
28
+ # Logical, not physical: :start is the reading-start edge (left in LTR,
29
+ # right in RTL), so a bare sidebar follows the document direction. The
30
+ # CSS is written in logical properties to match — physical :left/:right
31
+ # deliberately raise.
32
+ SIDES = { start: nil, end: "side-end" }.freeze
26
33
 
27
- def initialize(collapsible: :none, default_collapsed: false, **attrs)
34
+ def initialize(collapsible: :none, side: :start, default_collapsed: false, **attrs)
28
35
  @collapsible = collapsible.to_sym
36
+ @side = side.to_sym
29
37
  @default_collapsed = default_collapsed
30
38
  @attrs = attrs
31
39
  end
@@ -59,7 +67,8 @@ module PhlexKit
59
67
  def collapsible? = @collapsible != :none
60
68
 
61
69
  def classes
62
- [ "pk-sidebar-wrapper", fetch_option(COLLAPSIBLE, @collapsible, :collapsible) ].compact.join(" ")
70
+ [ "pk-sidebar-wrapper", fetch_option(COLLAPSIBLE, @collapsible, :collapsible),
71
+ fetch_option(SIDES, @side, :side) ].compact.join(" ")
63
72
  end
64
73
  end
65
74
  end
@@ -2,18 +2,20 @@ module PhlexKit
2
2
  # On/off toggle rendered as a checkbox styled as a track+thumb. Ported from
3
3
  # ruby_ui's RubyUI::Switch — pure CSS (`:has(:checked)`), no Stimulus. Emits an
4
4
  # optional hidden field so an unchecked box still posts a value (Rails idiom).
5
+ # The checked value is plain `value:` (defaulting to "1"), same as Checkbox;
6
+ # `unchecked_value:` is what the hidden field posts.
5
7
  class Switch < BaseComponent
6
8
  SIZES = { md: nil, sm: "sm" }.freeze
7
9
 
8
- def initialize(include_hidden: true, checked_value: "1", unchecked_value: "0", size: :md, wrapper: {}, **attrs)
9
- # value: is silently clobbered below (the checkbox's real value comes
10
- # from checked_value:) — fail loud rather than let a caller's value:
11
- # vanish (mirrors ToggleGroupItem's unsupported-kwargs guard).
12
- if attrs.key?(:value) || attrs.key?("value")
13
- raise ArgumentError, "Switch does not support value: — the checkbox's value comes from checked_value:, pass that instead"
10
+ def initialize(include_hidden: true, unchecked_value: "0", size: :md, wrapper: {}, **attrs)
11
+ # checked_value: was the API through 0.15.0; the checked value is now
12
+ # plain value:, matching Checkbox and HTML. Fail loud rather than let the
13
+ # old kwarg land in **attrs, where it would render a bogus
14
+ # checked_value="…" attribute while the real value reverts to "1".
15
+ if attrs.key?(:checked_value) || attrs.key?("checked_value")
16
+ raise ArgumentError, "Switch does not support checked_value: — pass the checked value as value:"
14
17
  end
15
18
  @include_hidden = include_hidden
16
- @checked_value = checked_value
17
19
  @unchecked_value = unchecked_value
18
20
  @size = size.to_sym
19
21
  @wrapper = wrapper
@@ -22,18 +24,26 @@ module PhlexKit
22
24
 
23
25
  def view_template
24
26
  label(**mix({ class: [ "pk-switch", fetch_option(SIZES, @size, :size) ].compact.join(" ") }, @wrapper)) do
25
- if @include_hidden && @attrs[:name]
27
+ # Never for array-style names ("ids[]") — an unchecked "0" would inject
28
+ # a bogus element into the collection param (mirrors Checkbox).
29
+ if @include_hidden && @attrs[:name] && !@attrs[:name].to_s.end_with?("[]")
26
30
  # Disabled in lockstep with the checkbox (Rails' check_box idiom) —
27
31
  # a disabled switch must not still post its unchecked value.
32
+ # form: rides along too, so a form-attributed switch outside its
33
+ # <form> posts the unchecked value to the same form.
28
34
  input(type: "hidden", name: @attrs[:name], value: @unchecked_value,
29
- disabled: @attrs[:disabled] ? true : nil)
35
+ disabled: @attrs[:disabled] ? true : nil,
36
+ form: @attrs[:form] || @attrs["form"])
30
37
  end
31
38
  # role="switch" belongs on the focusable control: native checkedness then
32
39
  # maps to aria-checked for AT, and the label stays a plain label.
33
40
  # Default role only when the caller didn't supply their own — `mix` fuses.
34
41
  input_base = { class: "pk-switch-input" }
35
42
  input_base[:role] = "switch" unless attr_set?(:role)
36
- input(**mix(input_base, @attrs).merge(type: "checkbox", value: @checked_value))
43
+ # Rails' check_box idiom: a switch with no explicit value posts "1".
44
+ # Guarded because `mix` fuses String+String rather than overriding.
45
+ input_base[:value] = "1" unless attr_set?(:value)
46
+ input(**mix(input_base, @attrs).merge(type: "checkbox"))
37
47
  span(class: "pk-switch-thumb")
38
48
  end
39
49
  end
@@ -4,7 +4,7 @@ module PhlexKit
4
4
  # the pressed state can post with a form. phlex-kit--toggle drives the state.
5
5
  class Toggle < BaseComponent
6
6
  VARIANTS = { default: nil, outline: "outline" }.freeze
7
- SIZES = { sm: "sm", default: nil, lg: "lg" }.freeze
7
+ SIZES = { sm: "sm", md: nil, lg: "lg" }.freeze
8
8
 
9
9
  def self.modifier_classes(variant:, size:)
10
10
  # Plain fetch — an unknown variant/size raises KeyError (kit-wide
@@ -12,12 +12,20 @@ module PhlexKit
12
12
  [ VARIANTS.fetch(variant), SIZES.fetch(size) ].compact
13
13
  end
14
14
 
15
- def initialize(pressed: false, name: nil, value: "1", unpressed_value: nil,
16
- variant: :default, size: :default, disabled: false, wrapper: {}, **attrs)
15
+ def initialize(pressed: false, name: nil, value: "1", unchecked_value: nil, include_hidden: true,
16
+ variant: :default, size: :md, disabled: false, wrapper: {}, **attrs)
17
+ # unpressed_value: was the API through 0.15.0 — the off value is now
18
+ # spelled unchecked_value:, matching Checkbox and Switch. Fail loud
19
+ # rather than let the old kwarg land in **attrs, where it would render a
20
+ # bogus unpressed_value="…" attribute and silently drop the value.
21
+ if attrs.key?(:unpressed_value) || attrs.key?("unpressed_value")
22
+ raise ArgumentError, "Toggle does not support unpressed_value: — pass the off value as unchecked_value:"
23
+ end
17
24
  @pressed = pressed
25
+ @include_hidden = include_hidden
18
26
  @name = name
19
27
  @value = value
20
- @unpressed_value = unpressed_value
28
+ @unchecked_value = unchecked_value
21
29
  @variant = variant.to_sym
22
30
  @size = size.to_sym
23
31
  @disabled = disabled
@@ -28,7 +36,7 @@ module PhlexKit
28
36
  def view_template(&block)
29
37
  span(**mix(wrapper_default_attrs, @wrapper)) do
30
38
  button(**mix(button_default_attrs, @attrs), &block)
31
- render_hidden_input if @name
39
+ render_hidden_input if @include_hidden && @name
32
40
  end
33
41
  end
34
42
 
@@ -50,13 +58,13 @@ module PhlexKit
50
58
  action: "click->phlex-kit--toggle#toggle",
51
59
  phlex_kit__toggle_pressed_value: @pressed.to_s,
52
60
  phlex_kit__toggle_value_value: @value.to_s,
53
- phlex_kit__toggle_unpressed_value_value: @unpressed_value.to_s } }
61
+ phlex_kit__toggle_unchecked_value_value: @unchecked_value.to_s } }
54
62
  end
55
63
 
56
64
  def render_hidden_input
57
65
  # Disabled in lockstep with the button — a disabled toggle must not
58
66
  # submit its value (matches native disabled-control form semantics).
59
- a = { type: "hidden", name: @name, value: @pressed ? @value : @unpressed_value.to_s,
67
+ a = { type: "hidden", name: @name, value: @pressed ? @value : @unchecked_value.to_s,
60
68
  data: { phlex_kit__toggle_target: "input" } }
61
69
  a[:disabled] = true if @disabled
62
70
  input(**a)
@@ -3,7 +3,7 @@ import { Controller } from "@hotwired/stimulus"
3
3
  // Connects to data-controller="phlex-kit--toggle"
4
4
  export default class extends Controller {
5
5
  static targets = ["button", "input"]
6
- static values = { pressed: Boolean, value: String, unpressedValue: String }
6
+ static values = { pressed: Boolean, value: String, uncheckedValue: String }
7
7
 
8
8
  toggle() {
9
9
  if (this.buttonTarget.disabled) return
@@ -16,7 +16,7 @@ export default class extends Controller {
16
16
  this.buttonTarget.dataset.state = current ? "on" : "off"
17
17
  }
18
18
  if (this.hasInputTarget) {
19
- this.inputTarget.value = current ? this.valueValue : this.unpressedValueValue
19
+ this.inputTarget.value = current ? this.valueValue : this.uncheckedValueValue
20
20
  }
21
21
  if (previous !== undefined) {
22
22
  this.dispatch("change", { detail: { pressed: current }, bubbles: true })
@@ -5,7 +5,7 @@ module PhlexKit
5
5
  class ToggleGroup < BaseComponent
6
6
  VALID_TYPES = %i[single multiple].freeze
7
7
 
8
- def initialize(type: :single, name: nil, value: nil, variant: :default, size: :default,
8
+ def initialize(type: :single, name: nil, value: nil, variant: :default, size: :md,
9
9
  disabled: false, spacing: 0, orientation: :horizontal, **attrs)
10
10
  @type = type.to_sym
11
11
  raise ArgumentError, "type must be :single or :multiple" unless VALID_TYPES.include?(@type)
@@ -4,7 +4,7 @@ module PhlexKit
4
4
  # Toggle kwargs this item renders no markup for, or that the group
5
5
  # derives itself (pressed: comes from the group's selected_values) —
6
6
  # inheriting them silently discarded the caller's input.
7
- unsupported = attrs.keys & %i[wrapper name unpressed_value pressed]
7
+ unsupported = attrs.keys & %i[wrapper name unchecked_value unpressed_value pressed]
8
8
  if unsupported.any?
9
9
  raise ArgumentError, "ToggleGroupItem does not support #{unsupported.join(", ")} (group items render a bare button)"
10
10
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PhlexKit
4
- VERSION = "0.15.0"
4
+ VERSION = "0.16.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phlex_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.0
4
+ version: 0.16.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Kennedy
@@ -629,7 +629,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
629
629
  - !ruby/object:Gem::Version
630
630
  version: '0'
631
631
  requirements: []
632
- rubygems_version: 4.0.15
632
+ rubygems_version: 4.0.20
633
633
  specification_version: 4
634
634
  summary: shadcn/ui-style component system for Phlex, styled with vanilla CSS and design
635
635
  tokens.