@kolkrabbi/kol-component 0.344.0 → 0.345.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kolkrabbi/kol-component",
3
- "version": "0.344.0",
3
+ "version": "0.345.0",
4
4
  "description": "The core component library",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -30,8 +30,8 @@
30
30
  "pdfjs-dist": "^6.3.289",
31
31
  "react-syntax-highlighter": "^16.1.1",
32
32
  "@kolkrabbi/kol-search": "^0.3.0",
33
- "@kolkrabbi/kol-growth": "^0.5.0",
34
- "@kolkrabbi/kol-markdown": "^0.2.0"
33
+ "@kolkrabbi/kol-markdown": "^0.2.0",
34
+ "@kolkrabbi/kol-growth": "^0.5.0"
35
35
  },
36
36
  "peerDependencies": {
37
37
  "@kolkrabbi/kol-icons": ">=0.61.1",
package/src/index.js CHANGED
@@ -68,7 +68,7 @@ export { default as SearchInput } from './molecules/SearchInput.jsx'
68
68
  export { default as InspectorSection, default as Section } from './molecules/InspectorSection.jsx'
69
69
  export { default as SectionText, SECTION_TEXT_LEVELS } from './molecules/SectionText.jsx'
70
70
  export { default as SectionLabel } from './atoms/SectionLabel.jsx'
71
- export { default as SegmentedToggle } from './atoms/SegmentedToggle.jsx'
71
+ export { default as SegmentedToggle } from './molecules/SegmentedToggle.jsx'
72
72
  /* a page's variants — the pinned slider button and its panel of segmented rows (OneVariantsControl, 2026-10-29; catalog's) */
73
73
  export { default as VariantsControl } from './molecules/VariantsControl.jsx'
74
74
  export { default as Stepper } from './molecules/Stepper.jsx'
@@ -1,5 +1,5 @@
1
1
  import { Icon } from '@kolkrabbi/kol-icons'
2
- import SegmentedToggle from '../atoms/SegmentedToggle.jsx'
2
+ import ButtonGroup from './ButtonGroup.jsx'
3
3
  import { glyphSize } from '../hooks/glyphLadders.js'
4
4
 
5
5
  /**
@@ -42,7 +42,7 @@ export default function AlignmentGrid({ onAlign, items = ALIGN_BUTTONS, size = '
42
42
  const cells = strip(axis)
43
43
  if (!cells.length) return null
44
44
  return (
45
- <SegmentedToggle
45
+ <ButtonGroup layout="joined"
46
46
  key={axis}
47
47
  variant="filled"
48
48
  size={size}
@@ -1,20 +1,95 @@
1
1
  /**
2
- * ButtonGroup — Lay out a group of buttons. responsive layout wrapper for a group of Buttons: stacked
3
- * full-width on mobile, horizontal row from `sm` up, aligned left / center /
4
- * right. Pure layout — children compose at the call site and render as-is
5
- * (nothing is cloned, no props injected); all button behavior lives on each
6
- * Button. `center` (default) hugs its content and self-centers; `left` /
7
- * `right` stay full-width block. Alignment classes come from static lookup
8
- * maps of complete literals — never interpolated — so Tailwind's scanner
9
- * sees them.
2
+ * ButtonGroup — the one component for a group of buttons (plan-2026-11-06-buttons-page 2.7; the user,
3
+ * 2026-11-06: *"button group CAN be segmented toggle … just by the fact it wraps multiple buttons"*).
4
+ * Three layouts:
10
5
  *
6
+ * layout="row" (default) — a responsive layout wrapper for a group of Buttons: stacked full-width on
7
+ * mobile, a horizontal row from `sm` up, aligned left / center / right. Pure layout —
8
+ * children compose at the call site and render as-is (nothing is cloned, no props
9
+ * injected); all button behavior lives on each Button. `center` (default) hugs its
10
+ * content and self-centers; `left` / `right` stay full-width block. Alignment classes
11
+ * come from static lookup maps of complete literals — never interpolated — so
12
+ * Tailwind's scanner sees them.
13
+ * layout="stack" — the same wrapper, stacked at every width (the row's 8 stacked gap).
14
+ * layout="joined" — the segmented control (was `SegmentedToggle`, kept as its alias on the retirement
15
+ * ledger): joined cells, no gap, built from `options` instead of children. See below.
16
+ *
17
+ * row / stack props:
11
18
  * @param {'left'|'center'|'right'} align horizontal alignment + container layout mode (default 'center')
12
19
  * @param {string} title optional heading rendered above the group, authored at the call site
13
20
  * @param {string} className extra container classes (appended) — note this lands on the OUTER
14
21
  * container, not the flex row that carries the gap; the gap is responsive by default (8 stacked,
15
22
  * 16 as a row) rather than reachable, so there is nothing to reach for.
16
23
  * @param {ReactNode} children the Buttons
24
+ *
25
+ * layout="joined" — N-way segmented control. Joined cells sharing one outer stroke; thin dividers
26
+ * between cells; no gap. Active cell fills with surface-secondary + text-emphasis, inactive is
27
+ * text-meta with hover lifting. Chrome comes from .kol-seg* in kol-theme (NOT Tailwind utilities —
28
+ * those never generate from package sources).
29
+ *
30
+ * <ButtonGroup layout="joined"
31
+ * value={current}
32
+ * onChange={setCurrent}
33
+ * options={[{ value, label }]}
34
+ * />
35
+ *
36
+ * Companion to `ViewToggle`:
37
+ * - ViewToggle (text) — bare segmented buttons separated by gap; no shared shell.
38
+ * - ViewToggle (icon) — inset-well row of square icon buttons.
39
+ * - ButtonGroup joined — flat segmented strip with shared border + dividers.
40
+ *
41
+ * Labels accept any node — pass strings or inline SVG previews. Optional `ariaLabel` per option for
42
+ * non-text labels.
43
+ *
44
+ * A11y: radiogroup/radio semantics with a roving tabindex — Tab enters the group on the active cell,
45
+ * ←/→ (or ↑/↓) move selection + focus.
46
+ *
47
+ * Props (joined):
48
+ * value — current option value. `null`/`undefined` = STATELESS mode
49
+ * (the segmented state law, 2026-08-12): role `group`, no
50
+ * aria-checked, no selected styling — a pure one-shot ACTION
51
+ * strip (canvas alignment, transform cluster); onChange is the
52
+ * action dispatch.
53
+ * onChange — handler (newValue) => void
54
+ * options — [{ value, label, ariaLabel?, tooltip?, disabled?, count? }] — a cell whose label is not a string
55
+ * (a glyph) shows its `ariaLabel` as a KOL Tooltip; `tooltip` overrides it.
56
+ * `count` (float-everything W2 row 26, 2026-11-04): a number after the label, mono one step down,
57
+ * 12 off the label — `Open 5`; drawn on `variant="float"` (`.kol-seg-count`), ignored elsewhere.
58
+ * `disabled` (kol-fxr 2026-10-09): the cell draws the family's disabled ink
59
+ * (`aria-disabled`, not the attribute — the tooltip still gives the reason),
60
+ * refuses the press, and ←/→ step over it. It may still be the current `value`
61
+ * (the ground changed under it): selected + disabled, no throw.
62
+ * variant — 'default' — BORDERLESS (2026-10-29, the user: *"WE DONT USE BORDER, almost NEVER … DONT USE FUCKING
63
+ * BORDER unless I APPROVE it"*): the `sunken` tone, no outer stroke, the selected cell on the sunken
64
+ * ground. A choice is a Dropdown or text tabs first; a toggle that stays is this one |
65
+ * 'outlined' (the old default: shared outer stroke + dividers, filled active cell — only where he has
66
+ * approved a border) | 'filled' (the state law's tiles: every
67
+ * cell a surface-secondary tile with 1px transparent gaps, NO
68
+ * outline shell; the inset ring marks ONLY the selected cell) |
69
+ * 'tonal' (filled tiles, but the clicked cell marks itself by
70
+ * TONE — surface-tertiary fill, no ring; 2026-08-12).
71
+ * 'float' (W16, round 3 — 2026-10-31): a capsule track 6 in on its `surface`, pills 4 apart at the
72
+ * float heights (28/36/44, touch 36/44/52), the selected pill filled with the ink.
73
+ * Every other variant renders at the SAME pinned button-ladder
74
+ * height (22/26/32/40) — icon or text, the box never moves.
75
+ * size — mirrors Button exactly: 'sm' (26px, mono-12, 4/12 pad) |
76
+ * 'md' (default, 32px, mono-14, 6/16 pad) | 'lg' (40px,
77
+ * mono-16, 8/20 pad). Same cell padding + mono type as the
78
+ * matching `.kol-btn-{sm,md,lg}`, so a segmented strip lines
79
+ * up with a Button of the same size.
80
+ * tone — the ground (segmented-toggle-sunken-tone, kol-client-olina 2026-09-03: the one
81
+ * control ControlToneSunken skipped; kol-fxr and olina carried the same three CSS
82
+ * lines to fake it). `sunken` (alias `inverse`): shell border transparent, the
83
+ * selected cell on `--kol-surface-sunken` / `fg-96`, rest cells as the default paints
84
+ * them; `filled` and `tonal` keep their own selected law. Through `toneClass`, so a
85
+ * `kol-tone-sunken` wrapper reaches it too. Unset = inherit.
86
+ * surface — `variant="float"` only: 'solid' (default) | 'glass-dark' | 'glass-light' — the track's material
87
+ * (`floatSurfaceClass`, kol-theme `.kol-float-*`)
88
+ * ariaLabel — accessible name for the group
89
+ * className — additional classes on the outer shell
17
90
  */
91
+ import { toneClass, floatSurfaceClass } from '../utilities/tone.js'
92
+ import { Tooltip } from '../utilities/Popover.jsx'
18
93
 
19
94
  const CONTAINER = {
20
95
  left: 'flex flex-col w-full',
@@ -28,7 +103,8 @@ const JUSTIFY = {
28
103
  right: 'sm:justify-end',
29
104
  }
30
105
 
31
- export default function ButtonGroup({ align = 'center', title, className = '', children }) {
106
+ export default function ButtonGroup({ layout = 'row', align = 'center', title, className = '', children, ...joined }) {
107
+ if (layout === 'joined') return <Joined className={className} {...joined} />
32
108
  return (
33
109
  <div className={[CONTAINER[align] || CONTAINER.center, className].filter(Boolean).join(' ')}>
34
110
  {title && <h3 className="kol-sans-heading-05 text-emphasis mb-6">{title}</h3>}
@@ -42,13 +118,77 @@ export default function ButtonGroup({ align = 'center', title, className = '', c
42
118
  * big, at least lets see 8 or 12"), and 8 is what looks right on device.
43
119
  * A responsive default rather than a prop — the stacked case IS the
44
120
  * narrow viewport, so the value is pickable once instead of per
45
- * consumer. The row keeps today's 16 and nothing moves at `sm` and up. */
46
- 'flex flex-col gap-2 sm:flex-row sm:gap-4 sm:items-center',
47
- JUSTIFY[align] || JUSTIFY.center,
48
- ].join(' ')}
121
+ * consumer. The row keeps today's 16 and nothing moves at `sm` and up.
122
+ * `stack` keeps the stacked half at every width. */
123
+ layout === 'stack' ? 'flex flex-col gap-2' : 'flex flex-col gap-2 sm:flex-row sm:gap-4 sm:items-center',
124
+ layout === 'stack' ? '' : JUSTIFY[align] || JUSTIFY.center,
125
+ ].filter(Boolean).join(' ')}
49
126
  >
50
127
  {children}
51
128
  </div>
52
129
  </div>
53
130
  )
54
131
  }
132
+
133
+ /* layout="joined" — the segmented control (SegmentedToggle's implementation, moved here 2026-11-06) */
134
+ function Joined({ value, onChange, options = [], variant = 'default', size = 'md', tone = 'default', surface = 'solid', ariaLabel, className = '' }) {
135
+ const float = variant === 'float'
136
+ const cellType = { xs: 'kol-mono-8', sm: 'kol-mono-12', md: 'kol-mono-14', lg: 'kol-mono-16' }[size]
137
+ const stateless = value == null
138
+ const focusIdx = Math.max(0, options.findIndex((opt) => opt.value === value))
139
+
140
+ const handleKeyDown = (e) => {
141
+ if (stateless) return // plain button row — Tab moves focus, arrows do nothing
142
+ const dir = { ArrowLeft: -1, ArrowUp: -1, ArrowRight: 1, ArrowDown: 1 }[e.key]
143
+ if (!dir || !options.length) return
144
+ e.preventDefault()
145
+ let next = focusIdx
146
+ for (let step = 0; step < options.length; step++) {
147
+ next = (next + dir + options.length) % options.length
148
+ if (!options[next].disabled) break
149
+ }
150
+ if (options[next].disabled) return
151
+ onChange?.(options[next].value)
152
+ e.currentTarget.children[next]?.focus()
153
+ }
154
+
155
+ /* the default draws borderless — the sunken tone — unless a tone is asked for; `outlined` keeps the stroke */
156
+ const resolvedTone = variant === 'default' && tone === 'default' ? 'sunken' : tone
157
+ return (
158
+ <div
159
+ role={stateless ? 'group' : 'radiogroup'}
160
+ aria-label={ariaLabel}
161
+ onKeyDown={handleKeyDown}
162
+ className={[
163
+ 'kol-seg',
164
+ (variant === 'filled' || variant === 'tonal') && 'kol-seg--filled',
165
+ variant === 'tonal' && 'kol-seg--tonal',
166
+ size !== 'md' && `kol-seg--${size}`,
167
+ float && `kol-seg--float ${floatSurfaceClass(surface)}`,
168
+ toneClass(resolvedTone),
169
+ className,
170
+ ].filter(Boolean).join(' ')}
171
+ >
172
+ {options.map((opt, i) => {
173
+ const isActive = !stateless && opt.value === value
174
+ return (
175
+ <Tooltip key={opt.value} asChild label={opt.tooltip ?? (typeof opt.label === 'string' ? null : opt.ariaLabel)}>
176
+ <button
177
+ type="button"
178
+ role={stateless ? undefined : 'radio'}
179
+ aria-checked={stateless ? undefined : isActive}
180
+ aria-label={opt.ariaLabel}
181
+ aria-disabled={opt.disabled || undefined}
182
+ tabIndex={stateless ? 0 : (i === focusIdx ? 0 : -1)}
183
+ onClick={opt.disabled ? undefined : () => onChange?.(opt.value)}
184
+ className={['kol-seg-cell', cellType, isActive && 'is-active'].filter(Boolean).join(' ')}
185
+ >
186
+ {opt.label}
187
+ {float && opt.count != null && <span className="kol-seg-count">{opt.count}</span>}
188
+ </button>
189
+ </Tooltip>
190
+ )
191
+ })}
192
+ </div>
193
+ )
194
+ }
@@ -1,5 +1,5 @@
1
1
  import Tag from '../atoms/Tag.jsx'
2
- import SegmentedToggle from '../atoms/SegmentedToggle.jsx'
2
+ import ButtonGroup from './ButtonGroup.jsx'
3
3
  import TabsRow from './TabsRow.jsx'
4
4
 
5
5
  /* taxonomy-ok: molecule — composes Tag, SegmentedToggle (atoms) and TabsRow (a molecule of chips) into one strip */
@@ -44,7 +44,7 @@ export default function PageControls({ toggles, views = [], count, jump, legend,
44
44
  </div>
45
45
  )}
46
46
  {views.map((v) => (
47
- <SegmentedToggle key={v.label} ariaLabel={v.label} size="sm" value={v.value} onChange={v.onChange} options={v.options} />
47
+ <ButtonGroup layout="joined" key={v.label} ariaLabel={v.label} size="sm" value={v.value} onChange={v.onChange} options={v.options} />
48
48
  ))}
49
49
  {count != null && <span className="kol-mono-12 text-fg-48 ml-auto">{count}</span>}
50
50
  </div>
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @deprecated 2026-11-06 — alias of `<ButtonGroup layout="joined">` (plan-2026-11-06-buttons-page 2.7). Drops when nobody imports it (04-retirements.md).
3
+ * SegmentedToggle — Old name for the joined ButtonGroup. Same props, same DOM: the implementation lives
4
+ * in ButtonGroup's `joined` layout; this alias is kept so a consumer's next bump does not break.
5
+ */
6
+ import ButtonGroup from './ButtonGroup.jsx'
7
+
8
+ let warned = false
9
+
10
+ export default function SegmentedToggle(props) {
11
+ if (import.meta.env?.DEV && !warned) {
12
+ warned = true
13
+ console.warn('SegmentedToggle is deprecated — use <ButtonGroup layout="joined">')
14
+ }
15
+ return <ButtonGroup layout="joined" {...props} />
16
+ }
@@ -1,6 +1,6 @@
1
1
  import Input from '../atoms/Input.jsx'
2
2
  import Button from '../atoms/Button.jsx'
3
- import SegmentedToggle from '../atoms/SegmentedToggle.jsx'
3
+ import ButtonGroup from './ButtonGroup.jsx'
4
4
  import ToggleSwitch from '../atoms/ToggleSwitch.jsx'
5
5
  import Dropdown from './Dropdown.jsx'
6
6
  import Slider from './Slider.jsx'
@@ -103,7 +103,7 @@ export function SettingsSelect({ value, onChange, options = [], disabled, ariaLa
103
103
  export function SettingsSegmented({ value, onChange, options = [], disabled, ariaLabel }) {
104
104
  return (
105
105
  <Dim disabled={disabled} className={`${FIELD} p-0.5`}>
106
- <SegmentedToggle value={value} onChange={onChange} options={options} ariaLabel={ariaLabel} size="sm"
106
+ <ButtonGroup layout="joined" value={value} onChange={onChange} options={options} ariaLabel={ariaLabel} size="sm"
107
107
  className="!flex w-full h-full !border-0 !bg-transparent !p-0 gap-0 [&_.kol-seg-cell]:flex-1 [&_.kol-seg-cell]:h-full [&_.kol-seg-cell]:!rounded-[3px] [&_.kol-seg-cell]:!border-0 [&_.kol-seg-cell]:!bg-transparent [&_.kol-seg-cell]:!text-[10px] [&_.kol-seg-cell]:!text-(--kol-oq-64) [&_.kol-seg-cell]:font-(family-name:--kol-font-family-float) [&_.kol-seg-cell.is-active]:!bg-(--kol-oq-16) [&_.kol-seg-cell.is-active]:!text-(--kol-fg-96) [&_.kol-seg-cell.is-active]:font-medium" />
108
108
  </Dim>
109
109
  )
@@ -1,6 +1,6 @@
1
1
  import { useEffect, useRef, useState } from 'react'
2
2
  import Button from '../atoms/Button.jsx'
3
- import SegmentedToggle from '../atoms/SegmentedToggle.jsx'
3
+ import ButtonGroup from './ButtonGroup.jsx'
4
4
  import { usePopover, PopoverPanel } from '../utilities/Popover.jsx'
5
5
 
6
6
  const cap = (v) => String(v).charAt(0).toUpperCase() + String(v).slice(1)
@@ -80,7 +80,7 @@ export default function VariantsControl({ axes = [], value = {}, onChange, child
80
80
  <span key={`${a.key}-l`} className="kol-mono-12 text-fg-64">{a.label}</span>,
81
81
  /* a row wider than the panel (a phone, a long axis) scrolls sideways in its cell — every option still one tap away */
82
82
  <div key={a.key} className="min-w-0 overflow-x-auto">
83
- <SegmentedToggle size="sm" className="w-max min-w-full" ariaLabel={a.label} value={value[a.key]} onChange={(v) => onChange?.(a.key, v)}
83
+ <ButtonGroup layout="joined" size="sm" className="w-max min-w-full" ariaLabel={a.label} value={value[a.key]} onChange={(v) => onChange?.(a.key, v)}
84
84
  options={a.options ?? (a.values ?? []).map((v) => ({ value: v, label: cap(v) }))} />
85
85
  </div>,
86
86
  ])}
@@ -2,7 +2,7 @@ import { useMemo, useState } from 'react'
2
2
  import IconPlate from '../atoms/IconPlate.jsx'
3
3
  import IconToggle from '../atoms/IconToggle.jsx'
4
4
  import Pill from '../atoms/Pill.jsx'
5
- import SegmentedToggle from '../atoms/SegmentedToggle.jsx'
5
+ import ButtonGroup from '../molecules/ButtonGroup.jsx'
6
6
  import ViewToggle from '../atoms/ViewToggle.jsx'
7
7
 
8
8
  /* taxonomy-ok: organism — a toolbar of atoms over a wall of IconPlate pairs */
@@ -71,11 +71,11 @@ export default function CompareGrid({ items = [], labels = { a: 'A', b: 'B' }, d
71
71
  return (
72
72
  <div className={`flex flex-col gap-6 ${className}`.trim()}>
73
73
  <div className="flex flex-wrap items-center gap-4">
74
- <SegmentedToggle ariaLabel="Size" value={size} onChange={setSize} options={SIZES.map((v) => ({ value: v, label: String(v) }))} size="sm" />
74
+ <ButtonGroup layout="joined" ariaLabel="Size" value={size} onChange={setSize} options={SIZES.map((v) => ({ value: v, label: String(v) }))} size="sm" />
75
75
  <ViewToggle variant="icon" options={GROUNDS} viewMode={ground} onViewChange={setGround} />
76
76
  <IconToggle icon="grid" label="Guide" title="Keyline guide" pressed={guide} onChange={setGuide} size="sm" />
77
77
  {hasStates && (
78
- <SegmentedToggle
78
+ <ButtonGroup layout="joined"
79
79
  ariaLabel="Show"
80
80
  value={filter}
81
81
  onChange={setFilter}
@@ -1,5 +1,5 @@
1
1
  import { useState } from 'react'
2
- import SegmentedToggle from '../atoms/SegmentedToggle.jsx'
2
+ import ButtonGroup from '../molecules/ButtonGroup.jsx'
3
3
  import GalleryCarousel from './GalleryCarousel.jsx'
4
4
  import MediaTileGallery from './MediaTileGallery.jsx'
5
5
  import MediaViewer from './MediaViewer.jsx'
@@ -38,7 +38,7 @@ export default function MediaGalleryModes({
38
38
  <div className="flex items-center justify-between gap-4">
39
39
  {title ? <span className="kol-helper-12 text-meta">{title}</span> : <span />}
40
40
  {modes.length > 1 && (
41
- <SegmentedToggle size="sm" ariaLabel="View" value={mode} onChange={setMode}
41
+ <ButtonGroup layout="joined" size="sm" ariaLabel="View" value={mode} onChange={setMode}
42
42
  options={modes.map((m) => ({ value: m, label: LABELS[m] }))} />
43
43
  )}
44
44
  </div>
@@ -1,4 +1,4 @@
1
- import SegmentedToggle from '../atoms/SegmentedToggle.jsx'
1
+ import ButtonGroup from '../molecules/ButtonGroup.jsx'
2
2
  import Button from '../atoms/Button.jsx'
3
3
  import { Tooltip } from '../utilities/Popover.jsx'
4
4
  import { RAIL_ROW } from '../hooks/railRow.js'
@@ -50,7 +50,7 @@ export function RailHeader({ title, subtitle, actions }) {
50
50
 
51
51
  /** RailTabs — segmented tabs across the rail: `tabs` `[{ value, label }]`, controlled by `value` / `onChange`. */
52
52
  export function RailTabs({ tabs = [], value, onChange, ariaLabel = 'Tabs', className = '' }) {
53
- return <SegmentedToggle size="sm" className={`w-full ${className}`.trim()} options={tabs} value={value} onChange={onChange} ariaLabel={ariaLabel} />
53
+ return <ButtonGroup layout="joined" size="sm" className={`w-full ${className}`.trim()} options={tabs} value={value} onChange={onChange} ariaLabel={ariaLabel} />
54
54
  }
55
55
 
56
56
  /** RailHint — one quiet line of guidance under a row or a group; a sentence, never a label. */
@@ -1,132 +0,0 @@
1
- /**
2
- * SegmentedToggle — N-way segmented control. Joined cells sharing one
3
- * outer stroke; thin dividers between cells; no gap. Active cell fills
4
- * with surface-secondary + text-emphasis, inactive is text-meta with
5
- * hover lifting. Chrome comes from .kol-seg* in kol-theme (NOT Tailwind
6
- * utilities — those never generate from package sources).
7
- *
8
- * <SegmentedToggle
9
- * value={current}
10
- * onChange={setCurrent}
11
- * options={[{ value, label }]}
12
- * />
13
- *
14
- * Companion to `ViewToggle`:
15
- * - ViewToggle (text) — bare segmented buttons separated by gap; no shared shell.
16
- * - ViewToggle (icon) — inset-well row of square icon buttons.
17
- * - SegmentedToggle — flat segmented strip with shared border + dividers.
18
- *
19
- * Labels accept any node — pass strings or inline SVG previews. Optional
20
- * `ariaLabel` per option for non-text labels.
21
- *
22
- * A11y: radiogroup/radio semantics with a roving tabindex — Tab enters
23
- * the group on the active cell, ←/→ (or ↑/↓) move selection + focus.
24
- *
25
- * Props:
26
- * value — current option value. `null`/`undefined` = STATELESS mode
27
- * (the segmented state law, 2026-08-12): role `group`, no
28
- * aria-checked, no selected styling — a pure one-shot ACTION
29
- * strip (canvas alignment, transform cluster); onChange is the
30
- * action dispatch.
31
- * onChange — handler (newValue) => void
32
- * options — [{ value, label, ariaLabel?, tooltip?, disabled?, count? }] — a cell whose label is not a string
33
- * (a glyph) shows its `ariaLabel` as a KOL Tooltip; `tooltip` overrides it.
34
- * `count` (float-everything W2 row 26, 2026-11-04): a number after the label, mono one step down,
35
- * 12 off the label — `Open 5`; drawn on `variant="float"` (`.kol-seg-count`), ignored elsewhere.
36
- * `disabled` (kol-fxr 2026-10-09): the cell draws the family's disabled ink
37
- * (`aria-disabled`, not the attribute — the tooltip still gives the reason),
38
- * refuses the press, and ←/→ step over it. It may still be the current `value`
39
- * (the ground changed under it): selected + disabled, no throw.
40
- * variant — 'default' — BORDERLESS (2026-10-29, the user: *"WE DONT USE BORDER, almost NEVER … DONT USE FUCKING
41
- * BORDER unless I APPROVE it"*): the `sunken` tone, no outer stroke, the selected cell on the sunken
42
- * ground. A choice is a Dropdown or text tabs first; a toggle that stays is this one |
43
- * 'outlined' (the old default: shared outer stroke + dividers, filled active cell — only where he has
44
- * approved a border) | 'filled' (the state law's tiles: every
45
- * cell a surface-secondary tile with 1px transparent gaps, NO
46
- * outline shell; the inset ring marks ONLY the selected cell) |
47
- * 'tonal' (filled tiles, but the clicked cell marks itself by
48
- * TONE — surface-tertiary fill, no ring; 2026-08-12).
49
- * 'float' (W16, round 3 — 2026-10-31): a capsule track 6 in on its `surface`, pills 4 apart at the
50
- * float heights (28/36/44, touch 36/44/52), the selected pill filled with the ink.
51
- * Every other variant renders at the SAME pinned button-ladder
52
- * height (22/26/32/40) — icon or text, the box never moves.
53
- * size — mirrors Button exactly: 'sm' (26px, mono-12, 4/12 pad) |
54
- * 'md' (default, 32px, mono-14, 6/16 pad) | 'lg' (40px,
55
- * mono-16, 8/20 pad). Same cell padding + mono type as the
56
- * matching `.kol-btn-{sm,md,lg}`, so a segmented strip lines
57
- * up with a Button of the same size.
58
- * tone — the ground (segmented-toggle-sunken-tone, kol-client-olina 2026-09-03: the one
59
- * control ControlToneSunken skipped; kol-fxr and olina carried the same three CSS
60
- * lines to fake it). `sunken` (alias `inverse`): shell border transparent, the
61
- * selected cell on `--kol-surface-sunken` / `fg-96`, rest cells as the default paints
62
- * them; `filled` and `tonal` keep their own selected law. Through `toneClass`, so a
63
- * `kol-tone-sunken` wrapper reaches it too. Unset = inherit.
64
- * surface — `variant="float"` only: 'solid' (default) | 'glass-dark' | 'glass-light' — the track's material
65
- * (`floatSurfaceClass`, kol-theme `.kol-float-*`)
66
- * ariaLabel — accessible name for the group
67
- * className — additional classes on the outer shell
68
- */
69
- import { toneClass, floatSurfaceClass } from '../utilities/tone.js'
70
- import { Tooltip } from '../utilities/Popover.jsx'
71
-
72
- export default function SegmentedToggle({ value, onChange, options = [], variant = 'default', size = 'md', tone = 'default', surface = 'solid', ariaLabel, className = '' }) {
73
- const float = variant === 'float'
74
- const cellType = { xs: 'kol-mono-8', sm: 'kol-mono-12', md: 'kol-mono-14', lg: 'kol-mono-16' }[size]
75
- const stateless = value == null
76
- const focusIdx = Math.max(0, options.findIndex((opt) => opt.value === value))
77
-
78
- const handleKeyDown = (e) => {
79
- if (stateless) return // plain button row — Tab moves focus, arrows do nothing
80
- const dir = { ArrowLeft: -1, ArrowUp: -1, ArrowRight: 1, ArrowDown: 1 }[e.key]
81
- if (!dir || !options.length) return
82
- e.preventDefault()
83
- let next = focusIdx
84
- for (let step = 0; step < options.length; step++) {
85
- next = (next + dir + options.length) % options.length
86
- if (!options[next].disabled) break
87
- }
88
- if (options[next].disabled) return
89
- onChange?.(options[next].value)
90
- e.currentTarget.children[next]?.focus()
91
- }
92
-
93
- /* the default draws borderless — the sunken tone — unless a tone is asked for; `outlined` keeps the stroke */
94
- const resolvedTone = variant === 'default' && tone === 'default' ? 'sunken' : tone
95
- return (
96
- <div
97
- role={stateless ? 'group' : 'radiogroup'}
98
- aria-label={ariaLabel}
99
- onKeyDown={handleKeyDown}
100
- className={[
101
- 'kol-seg',
102
- (variant === 'filled' || variant === 'tonal') && 'kol-seg--filled',
103
- variant === 'tonal' && 'kol-seg--tonal',
104
- size !== 'md' && `kol-seg--${size}`,
105
- float && `kol-seg--float ${floatSurfaceClass(surface)}`,
106
- toneClass(resolvedTone),
107
- className,
108
- ].filter(Boolean).join(' ')}
109
- >
110
- {options.map((opt, i) => {
111
- const isActive = !stateless && opt.value === value
112
- return (
113
- <Tooltip key={opt.value} asChild label={opt.tooltip ?? (typeof opt.label === 'string' ? null : opt.ariaLabel)}>
114
- <button
115
- type="button"
116
- role={stateless ? undefined : 'radio'}
117
- aria-checked={stateless ? undefined : isActive}
118
- aria-label={opt.ariaLabel}
119
- aria-disabled={opt.disabled || undefined}
120
- tabIndex={stateless ? 0 : (i === focusIdx ? 0 : -1)}
121
- onClick={opt.disabled ? undefined : () => onChange?.(opt.value)}
122
- className={['kol-seg-cell', cellType, isActive && 'is-active'].filter(Boolean).join(' ')}
123
- >
124
- {opt.label}
125
- {float && opt.count != null && <span className="kol-seg-count">{opt.count}</span>}
126
- </button>
127
- </Tooltip>
128
- )
129
- })}
130
- </div>
131
- )
132
- }