phlex_kit 0.14.1 → 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: cc498540064c2a8e95dbe9b86dad991b2decb5dbd36c58f8ea8c39dce04fd146
4
- data.tar.gz: 4b04765fe0ef28d0562542546df1d841fe2a9bd0a6df3cde2c344a5f80902d98
3
+ metadata.gz: 5970949c9d2e28fee9964407ceb7df89ca7b00bd04e8a32d33ed4369c03796d3
4
+ data.tar.gz: 3a6d4cf2ea38958195395fac9ba28ca88aa71216d47a404a514aaec6d3dcb4b7
5
5
  SHA512:
6
- metadata.gz: f94e22d2a6537aae8571df45dea339fe6f03c2ed64b084223ee9359240f4032c85c1ce2132b63321e9d334b99cd9e0619babe7ec390937446913759434ae2a6c
7
- data.tar.gz: e8a31936f3a6bd52fa30b61f3faf36e0ac8845ad78fd5c10624a021f3c0c6e6e99124eab540e42e0a0fd0dbe99bb4e6e2e2845c978939f646755a92e0576e30e
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
@@ -16,7 +16,11 @@ module PhlexKit
16
16
  # the year list). Pass `input_id:` a CSS selector (e.g. "#due-date") to
17
17
  # push the picked date (or "start – end" range) into a
18
18
  # phlex-kit--calendar-input outlet — that's how PhlexKit::DatePicker binds
19
- # an Input. Sizing rides --pk-cell-size/--pk-cell-radius (calendar.css).
19
+ # an Input. `locale:` (a BCP 47 tag) drives every Intl call the controller
20
+ # makes — caption, weekday headers, month dropdown, day accessible names and
21
+ # the EEEE/MMMM format tokens; unset follows the browser. The server-rendered
22
+ # month/weekday words stay English as the pre-JS baseline. Note the `do`/PPPP
23
+ # ordinal suffixes (st/nd/rd/th) are an English rule and stay English. Sizing rides --pk-cell-size/--pk-cell-radius (calendar.css).
20
24
  class Calendar < BaseComponent
21
25
  MODES = { single: "single", range: "range", multiple: "multiple" }.freeze
22
26
  CAPTION_LAYOUTS = %i[label dropdown].freeze
@@ -25,7 +29,7 @@ module PhlexKit
25
29
  def initialize(mode: :single, selected_date: nil, selected_dates: [], range_start: nil, range_end: nil,
26
30
  min_date: nil, max_date: nil, disabled_dates: [], week_numbers: false,
27
31
  caption_layout: :label, from_year: nil, to_year: nil,
28
- input_id: nil, date_format: "yyyy-MM-dd", **attrs)
32
+ input_id: nil, date_format: "yyyy-MM-dd", locale: nil, **attrs)
29
33
  @mode = MODES.fetch(mode.to_sym)
30
34
  @selected_date = selected_date
31
35
  @selected_dates = Array(selected_dates).map(&:to_s)
@@ -41,6 +45,7 @@ module PhlexKit
41
45
  @to_year = to_year
42
46
  @input_id = input_id
43
47
  @date_format = date_format
48
+ @locale = locale
44
49
  @attrs = attrs
45
50
  end
46
51
 
@@ -112,6 +117,8 @@ module PhlexKit
112
117
  data[:phlex_kit__calendar_selected_dates_value] = JSON.generate(@selected_dates) if @selected_dates.any?
113
118
  data[:phlex_kit__calendar_disabled_dates_value] = JSON.generate(@disabled_dates) if @disabled_dates.any?
114
119
  data[:phlex_kit__calendar_week_numbers_value] = "true" if @week_numbers
120
+ # Unset = the runtime's own locale (the controller passes undefined to Intl).
121
+ data[:phlex_kit__calendar_locale_value] = @locale if @locale
115
122
  # Seed the view on the selection so the grid opens on the right month.
116
123
  view_seed = @selected_date || @range_start || @selected_dates.first
117
124
  data[:phlex_kit__calendar_view_date_value] = view_seed.to_s if view_seed
@@ -41,6 +41,10 @@ export default class extends Controller {
41
41
  // toISOString() is UTC (wrong day for non-UTC users near midnight).
42
42
  viewDate: { type: String, default: "" },
43
43
  format: { type: String, default: "yyyy-MM-dd" },
44
+ // BCP 47 tag for every Intl call below. Unset = "" = undefined to Intl,
45
+ // i.e. the runtime's own locale (the server markup is English only as the
46
+ // pre-JS baseline, so the grid localizes itself on first render).
47
+ locale: { type: String, default: "" },
44
48
  };
45
49
  static outlets = ["phlex-kit--calendar-input"];
46
50
 
@@ -274,6 +278,34 @@ export default class extends Controller {
274
278
  // `focusDay` overrides the day to refocus after re-render: on a keyboard
275
279
  // month cross the target day lives in the NEW grid, not the pre-render
276
280
  // activeElement, so onKeydown passes it explicitly.
281
+ // undefined (not "") is what Intl wants for "use the runtime default".
282
+ locale() {
283
+ return this.localeValue || undefined;
284
+ }
285
+
286
+ // The weekday <th>s are cloned verbatim from a server template and the month
287
+ // dropdown's <option>s are server-rendered — both English. Relabel them from
288
+ // Intl on every render so the whole chrome speaks one language.
289
+ localizeChrome() {
290
+ const heads = [...this.calendarTarget.querySelectorAll(".pk-calendar-weekday")].filter(
291
+ (th) => !th.classList.contains("pk-calendar-weeknumber-head"),
292
+ );
293
+ // The server row runs Monday..Sunday; 2024-01-01 was a Monday.
294
+ heads.forEach((th, index) => {
295
+ const day = new Date(2024, 0, 1 + index);
296
+ const name = day.toLocaleDateString(this.locale(), { weekday: "long" });
297
+ th.setAttribute("aria-label", name);
298
+ th.textContent = day.toLocaleDateString(this.locale(), { weekday: "short" }).slice(0, 2);
299
+ });
300
+
301
+ if (!this.hasMonthSelectTarget) return;
302
+ [...this.monthSelectTarget.options].forEach((option) => {
303
+ const month = Number(option.value);
304
+ if (!Number.isFinite(month)) return;
305
+ option.textContent = new Date(2024, month, 1).toLocaleDateString(this.locale(), { month: "long" });
306
+ });
307
+ }
308
+
277
309
  updateCalendar(focusDay = null) {
278
310
  if (this.hasTitleTarget) {
279
311
  this.titleTarget.textContent = this.monthAndYear();
@@ -288,6 +320,7 @@ export default class extends Controller {
288
320
  ? document.activeElement.dataset?.day
289
321
  : null);
290
322
  this.calendarTarget.innerHTML = this.calendarHTML();
323
+ this.localizeChrome();
291
324
  this.ensureGridTabStop(focusedDay);
292
325
  }
293
326
 
@@ -419,7 +452,7 @@ export default class extends Controller {
419
452
  dayDate: day.getDate(),
420
453
  // full human-readable date for the button's accessible name — a bare
421
454
  // day number ("14") is meaningless to a screen reader
422
- dayLabel: day.toLocaleDateString("en-US", { weekday: "long", month: "long", day: "numeric", year: "numeric" }),
455
+ dayLabel: day.toLocaleDateString(this.locale(), { weekday: "long", month: "long", day: "numeric", year: "numeric" }),
423
456
  state: this.dayState(day),
424
457
  };
425
458
 
@@ -499,10 +532,10 @@ export default class extends Controller {
499
532
  .filter(Boolean);
500
533
  }
501
534
 
535
+ // One Intl call rather than `${month} ${year}` so locales that order the
536
+ // parts differently (ja-JP → "2026年1月") come out right, not just translated.
502
537
  monthAndYear() {
503
- const month = this.viewDate().toLocaleString("en-US", { month: "long" });
504
- const year = this.viewDate().getFullYear();
505
- return `${month} ${year}`;
538
+ return this.viewDate().toLocaleDateString(this.locale(), { month: "long", year: "numeric" });
506
539
  }
507
540
 
508
541
  selectedDate() {
@@ -592,8 +625,8 @@ export default class extends Controller {
592
625
  const hours = date.getHours();
593
626
  const minutes = date.getMinutes();
594
627
  const seconds = date.getSeconds();
595
- const dayOfWeek = date.toLocaleString("en-US", { weekday: "long" });
596
- const monthName = date.toLocaleString("en-US", { month: "long" });
628
+ const dayOfWeek = date.toLocaleString(this.locale(), { weekday: "long" });
629
+ const monthName = date.toLocaleString(this.locale(), { month: "long" });
597
630
  const daySuffix = this.getDaySuffix(day);
598
631
 
599
632
  const map = {
@@ -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,7 +7,15 @@ module PhlexKit
7
7
  # Upstream's fuse.js fuzzy search is replaced with a dependency-free substring
8
8
  # match in the controller. Tailwind → vanilla `.pk-command*` (command.css).
9
9
  class Command < BaseComponent
10
- def initialize(**attrs)
10
+ # Announcement templates for the live region — the only strings the
11
+ # controller writes itself (CommandEmpty is server-rendered, so it
12
+ # localizes with the rest of your markup). %{count} is interpolated.
13
+ DEFAULT_RESULTS_FORMAT = "%{count} result(s)"
14
+ DEFAULT_NO_RESULTS_TEXT = "No results"
15
+
16
+ def initialize(results_format: DEFAULT_RESULTS_FORMAT, no_results_text: DEFAULT_NO_RESULTS_TEXT, **attrs)
17
+ @results_format = results_format
18
+ @no_results_text = no_results_text
11
19
  @attrs = attrs
12
20
  end
13
21
 
@@ -21,12 +29,17 @@ module PhlexKit
21
29
  private
22
30
 
23
31
  # Screen-reader announcement of the filtered result count — the controller
24
- # writes "N results" / "No results" into it from filter().
32
+ # writes the results_format / no_results_text strings into it from
33
+ # filter(), interpolating %{count}.
25
34
  def live_region
26
35
  div(
27
36
  class: "pk-sr-only",
28
37
  aria: { live: "polite" },
29
- data: { phlex_kit__command_target: "liveRegion" }
38
+ data: {
39
+ phlex_kit__command_target: "liveRegion",
40
+ results_format: @results_format,
41
+ no_results_text: @no_results_text
42
+ }
30
43
  )
31
44
  end
32
45
  end
@@ -262,8 +262,13 @@ export default class extends Controller {
262
262
  if (count === null) {
263
263
  this.liveRegionTarget.textContent = "";
264
264
  } else {
265
+ // Templates come from the server (Command's results_format: /
266
+ // no_results_text: kwargs) — the defaults mirror command.rb's.
267
+ const data = this.liveRegionTarget.dataset;
265
268
  this.liveRegionTarget.textContent =
266
- count === 0 ? "No results" : `${count} result${count === 1 ? "" : "s"}`;
269
+ count === 0
270
+ ? data.noResultsText || "No results"
271
+ : (data.resultsFormat || "%{count} result(s)").replace("%{count}", count);
267
272
  }
268
273
  }
269
274
 
@@ -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
@@ -20,6 +20,7 @@ module PhlexKit
20
20
  placeholder: "Select a date",
21
21
  selected_date: value,
22
22
  date_format: "yyyy-MM-dd",
23
+ locale: nil,
23
24
  input_attrs: {},
24
25
  calendar_attrs: {},
25
26
  trigger_attrs: {},
@@ -31,6 +32,7 @@ module PhlexKit
31
32
  @label = label
32
33
  @selected_date = selected_date
33
34
  @date_format = date_format
35
+ @locale = locale
34
36
  # Seed the input with the same date_format the calendar controller
35
37
  # writes — a bare `selected_date.to_s` (ISO) would mismatch the format
36
38
  # until the first interaction.
@@ -65,7 +67,8 @@ module PhlexKit
65
67
  end
66
68
  end
67
69
  render PopoverContent.new(**@content_attrs) do
68
- render Calendar.new(input_id: input_selector, selected_date: @selected_date, date_format: @date_format, **@calendar_attrs)
70
+ render Calendar.new(input_id: input_selector, selected_date: @selected_date, date_format: @date_format,
71
+ locale: @locale, **@calendar_attrs)
69
72
  end
70
73
  end
71
74
  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.14.1"
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.14.1
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.