@kolkrabbi/kol-component 0.265.0 → 0.266.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.
@@ -1,226 +1,10 @@
1
- import { useEffect, useRef, useState } from 'react'
2
- import { pushLayer, popLayer, isTopLayer } from '../utilities/layerStack.js'
3
- import { createPortal } from 'react-dom'
4
- import { Icon } from '@kolkrabbi/kol-icons'
5
- import CloseButton from '../atoms/CloseButton.jsx'
6
- import usePrefersReducedMotion from '../hooks/usePrefersReducedMotion.js'
7
-
8
- /* taxonomy-ok: nests kol-icons's Icon (a package import the relative-import
9
- * check can't see). */
10
-
11
- const FOCUSABLE =
12
- 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'
1
+ import Rail from './Rail.jsx'
13
2
 
14
3
  /**
15
- * ShellDrawer — A panel that slides in from an edge. THE edge drawer: a portalled panel that slides in from the
16
- * left, right or BOTTOM viewport edge over a dimming backdrop. Distinct from Modal
17
- * (centered prompt/confirm) and FullscreenOverlay (fills the whole viewport,
18
- * not an edge sheet). Escape, backdrop click and the built-in close button
19
- * all call `onClose`; body scroll locks while open; focus moves into the
20
- * panel on open, is trapped there, and returns to the opener on close.
21
- *
22
- * The slide transition is gated on prefers-reduced-motion: reduced users get
23
- * an instant mount/unmount with no transform animation.
24
- *
25
- * Presentational shell — the parent owns the open state and supplies the
26
- * header slot and body; no navigation or routing logic lives here.
27
- *
28
- * @param {boolean} open drawer visible (drives slide in/out)
29
- * @param {Function} onClose close request (Esc / backdrop / close button)
30
- * @param {string} side 'left' | 'right' | 'bottom' — edge the panel slides from.
31
- * `bottom` (ShellDrawerBottomSide, kol-mirror 2026-09-01) is the
32
- * phone's sheet: full viewport width, slides up from +100% on Y,
33
- * takes `height` where the sides take `width`, and pads its foot by
34
- * `env(safe-area-inset-bottom)` so the last row clears the home bar.
35
- * ONE DETENT — open or closed. A collapsed bar that grows on tap is
36
- * a second height the consumer owns (mirror's 56px → 68dvh); this
37
- * sheet does not carry it, and says so rather than half-build it.
38
- * @param {number|string} width panel width (px number or CSS length); omit for full-width sheet — sides only
39
- * @param {number|string} height panel height (px number or CSS length); omit for a content-sized sheet — `bottom` only
40
- * @param {ReactNode} header header-row content beside the close button (replaces the source's baked-in wordmark)
41
- * @param {boolean} backdrop render the dimming scrim (default true); false = panel alone, no darken/blur, close via × / Esc
42
- * @param {'xs'|'sm'|'md'|'lg'} closeSize the close control's rung (default 'sm' — match the controls in the panel)
43
- * @param {ReactNode} children scrollable panel body
44
- * @param {string} className extra classes on the panel
4
+ * @deprecated 2026-10-17 — alias of Rail (RailOverlay: two words, rail and overlay). Drops when nobody imports it (04-retirements.md).
5
+ * ShellDrawer — Old name for Rail. The edge drawer is a rail now: same props (`side`, `width`, `height`, `header`,
6
+ * `backdrop`, `closeSide`, `closeSize`, `edge`, `shadow`), plus `side="top"`, `mode="push"` and `resizable`.
45
7
  */
46
- export default function ShellDrawer({
47
- open,
48
- onClose,
49
- side = 'left',
50
- width,
51
- height,
52
- header,
53
- closeSide = 'end',
54
- backdrop = true,
55
- /* THE CLOSE SITS ON THE ROW'S RUNG (user 2026-09-03, on the settings drawer:
56
- * *"does this button follow the size ladder?"*). It was pinned `md` (32) while
57
- * every control in the panel below it — the switches, the dropdowns, the reset
58
- * frame — is `sm` (26), so the one control that is not a setting was the
59
- * largest thing on the surface. A size is a height and a row is one height;
60
- * `sm` is the default because a drawer header sits over its own controls.
61
- * Named `closeSize`, not `size` — `size` is already the panel's own box. */
62
- closeSize = 'sm',
63
- children,
64
- className = '',
65
- /* SettingsPanelApproved (2026-08-27): the settings drawer has neither */
66
- edge = true,
67
- shadow = true,
68
- }) {
69
- const reduced = usePrefersReducedMotion()
70
- const panelRef = useRef(null)
71
-
72
- /* Mount/slide state machine: `present` keeps the portal mounted through
73
- * the exit slide; `shown` drives the transform/opacity classes. Reduced
74
- * motion collapses both onto `open` — instant show/hide, no transform. */
75
- const [present, setPresent] = useState(open)
76
- const [shown, setShown] = useState(open)
77
-
78
- useEffect(() => {
79
- if (reduced) {
80
- setPresent(open)
81
- setShown(open)
82
- return undefined
83
- }
84
- if (open) {
85
- setPresent(true)
86
- // double rAF: let the off-screen position paint before sliding in
87
- let raf2
88
- const raf1 = requestAnimationFrame(() => {
89
- raf2 = requestAnimationFrame(() => setShown(true))
90
- })
91
- return () => {
92
- cancelAnimationFrame(raf1)
93
- if (raf2) cancelAnimationFrame(raf2)
94
- }
95
- }
96
- setShown(false)
97
- const t = setTimeout(() => setPresent(false), 200) // matches duration-200
98
- return () => clearTimeout(t)
99
- }, [open, reduced])
100
-
101
- // Escape closes; Tab is trapped inside the panel while open — while this is the TOP layer
102
- // (`layerStack`: a sheet opened over the drawer owns the keyboard until it closes)
103
- const onCloseRef = useRef(onClose)
104
- onCloseRef.current = onClose
105
- useEffect(() => {
106
- if (!open) return undefined
107
- const layer = pushLayer()
108
- const onKey = (e) => {
109
- if (!isTopLayer(layer)) return
110
- if (e.key === 'Escape') {
111
- onCloseRef.current?.()
112
- return
113
- }
114
- if (e.key !== 'Tab') return
115
- const panel = panelRef.current
116
- if (!panel) return
117
- const nodes = panel.querySelectorAll(FOCUSABLE)
118
- if (!nodes.length) {
119
- e.preventDefault()
120
- panel.focus()
121
- return
122
- }
123
- const first = nodes[0]
124
- const last = nodes[nodes.length - 1]
125
- const active = document.activeElement
126
- if (!panel.contains(active)) {
127
- e.preventDefault()
128
- first.focus()
129
- } else if (e.shiftKey && (active === first || active === panel)) {
130
- e.preventDefault()
131
- last.focus()
132
- } else if (!e.shiftKey && active === last) {
133
- e.preventDefault()
134
- first.focus()
135
- }
136
- }
137
- document.addEventListener('keydown', onKey)
138
- return () => { popLayer(layer); document.removeEventListener('keydown', onKey) }
139
- }, [open])
140
-
141
- /* Body scroll-lock + focus in/out. Gated on `present` too so the panel
142
- * exists before we focus it (it mounts one commit after `open` flips). */
143
- useEffect(() => {
144
- if (!(open && present)) return undefined
145
- const prevOverflow = document.body.style.overflow
146
- document.body.style.overflow = 'hidden'
147
- const prevFocus = document.activeElement
148
- panelRef.current?.focus()
149
- return () => {
150
- document.body.style.overflow = prevOverflow
151
- if (prevFocus instanceof HTMLElement) prevFocus.focus()
152
- }
153
- }, [open, present])
154
-
155
- if (!present || typeof document === 'undefined') return null
156
-
157
- const bottom = side === 'bottom'
158
- const slideOut = bottom ? 'translate-y-full' : side === 'right' ? 'translate-x-full' : '-translate-x-full'
159
- const motionPanel = reduced
160
- ? ''
161
- : `transition-transform duration-200 ease-out ${shown ? (bottom ? 'translate-y-0' : 'translate-x-0') : slideOut}`
162
- /* the sheet's edge is the top; the sides' is the inner vertical */
163
- const place = bottom
164
- ? `inset-x-0 bottom-0 w-full max-h-full ${edge ? 'border-t' : ''}`
165
- : `inset-y-0 max-w-full ${side === 'right' ? `right-0 ${edge ? 'border-l' : ''}` : `left-0 ${edge ? 'border-r' : ''}`} ${width == null ? 'w-full' : ''}`
166
- const size = bottom
167
- ? { ...(height != null ? { height: typeof height === 'number' ? `${height}px` : height } : {}), paddingBottom: 'calc(1rem + env(safe-area-inset-bottom, 0px))' }
168
- : width != null ? { width: typeof width === 'number' ? `${width}px` : width } : undefined
169
- const motionBackdrop = reduced
170
- ? ''
171
- : `transition-opacity duration-200 ease-out ${shown ? 'opacity-100' : 'opacity-0'}`
172
-
173
- return createPortal(
174
- <>
175
- {backdrop && (
176
- /* A BUTTON, not a div (OverlayScrimTapDismiss, 2026-09-01): iOS Safari
177
- * does not bubble tap-clicks from non-interactive elements, so a div
178
- * scrim's onClick never fires on a phone — the same line that broke
179
- * the search overlay's dismiss. */
180
- <button
181
- type="button"
182
- aria-label="Close"
183
- className={`fixed inset-0 z-[100] kol-overlay-scrim ${motionBackdrop}`}
184
- onClick={onClose}
185
- />
186
- )}
187
- <div
188
- ref={panelRef}
189
- role="dialog"
190
- aria-modal="true"
191
- tabIndex={-1}
192
- /* `edge` / `shadow` (SettingsPanelApproved, 2026-08-27): the approved settings
193
- * drawer has neither — the sheet meets the page flat */
194
- className={`fixed z-[200] flex flex-col bg-surface-primary px-4 py-4 outline-none md:px-5 lg:px-6 ${backdrop && shadow ? 'shadow-2xl' : ''} ${place} border-oq-08 ${motionPanel} ${className}`}
195
- style={size}
196
- >
197
- {/* closeSide="start": the reference sets the × glyph ~9px deeper than
198
- * the label column's edge, with extra top air (both reference frames
199
- * 2026-08-09 measure the same inset) */}
200
- <div className={`mb-6 flex items-center gap-4${closeSide === 'start' ? ' pt-3 pl-2' : ''}`}>
201
- {/* closeSide="start" — the record-surface anatomy (reference frame,
202
- * 2026-08-09): × leads, the header's actions sit at the far end. */}
203
- {closeSide === 'start' && (
204
- /* bare glyph, no container (user 2026-08-09: "the X close icon
205
- * does not need a container") — body ink at rest, emphasis on hover */
206
- <CloseButton onClick={onClose} size={closeSize} className="shrink-0" />
207
- )}
208
- {header != null && <div className="min-w-0 flex-1">{header}</div>}
209
- {/* A NORMAL ICON BUTTON (user 2026-09-02: *"it should just be like a
210
- * normal button with a close icon, its not new?"*). It carried
211
- * `iconSize={14}` — kept in 2026-08-01 to preserve the glyph size the
212
- * hand-rolled button before it happened to have — so the box sat at
213
- * the md rung's 32px around a glyph six under it, and it read as an
214
- * oversized empty square. No override: the rung sets both. */}
215
- {closeSide !== 'start' && (
216
- <CloseButton onClick={onClose} size={closeSize} className="ml-auto shrink-0" />
217
- )}
218
- </div>
219
- <div className="flex-1 overflow-y-auto pr-1" style={{ overflowAnchor: 'none' }}>
220
- {children}
221
- </div>
222
- </div>
223
- </>,
224
- document.body,
225
- )
8
+ export default function ShellDrawer(props) {
9
+ return <Rail {...props} />
226
10
  }
@@ -1,50 +1,9 @@
1
- import Button from '../atoms/Button.jsx'
1
+ import TabsRow from './TabsRow.jsx'
2
2
 
3
3
  /**
4
- * TabChips — Tabs as a row of chips. the active tab is a filled chip, the rest are quiet text.
5
- *
6
- * WHY IT EXISTS (user, 2026-10-01, on the showcase's Preview / Code and pnpm / npm / yarn / bun rows:
7
- * *"what is this button? its not DS?"* → *"we can just make a tab chip for this purpose exactly
8
- * like this"*). It was `DocTabs`, a strip local to the showcase, built there because neither
9
- * shipped tab control fits a toolbar: `SegmentedToggle` is a joined strip with radiogroup
10
- * semantics, `TabsRow` is an underline strip that wants a rule beneath it. This is the third tab
11
- * idiom — small, unframed, sits inside a bar — promoted as it was, class for class.
12
- *
13
- * Labels render as authored. Selection is the parent's.
14
- *
15
- * ON THE CONTROL SIZE RAMP (user 2026-10-02: *"can we make the tabtoggle align with the size ramp
16
- * controls use?"*). A chip was a bare button at its own 24px, beside a 26px dropdown in the same
17
- * bar. Each chip is a `Button variant="tab"` now, so `size` is the ramp's (22 · 26 · 32 · 40) and
18
- * the chip's look is a Button state anything else can wear.
19
- *
20
- * @param {Array} tabs `[{ id, label }]`
21
- * @param {string} value id of the active tab (controlled)
22
- * @param {Function} onChange `(id) => void`
23
- * @param {'xs'|'sm'|'md'|'lg'} [size='sm'] the control ramp's rung
24
- * @param {string} [ariaLabel] accessible name for the strip
25
- * @param {string} [className] extra classes on the row
4
+ * @deprecated 2026-10-17 — alias of `TabsRow look="chip"` (TabsStackedLayout: one tab component). Drops when nobody imports it (04-retirements.md).
5
+ * TabChips — Old name for TabsRow's chip look. Same props: `tabs` · `value` · `onChange` · `size` · `ariaLabel` · `className`.
26
6
  */
27
- export default function TabChips({ tabs = [], value, onChange, size = 'sm', ariaLabel, className = '' }) {
28
- return (
29
- <div className={`flex items-center gap-1 ${className}`.trim()} role="tablist" aria-label={ariaLabel}>
30
- {tabs.map((t) => {
31
- const active = t.id === value
32
- return (
33
- /* a tab is selected, not pressed — the role's own attribute replaces Button's aria-pressed */
34
- <Button
35
- key={t.id}
36
- variant="tab"
37
- size={size}
38
- pressed={active}
39
- role="tab"
40
- aria-selected={active}
41
- aria-pressed={undefined}
42
- onClick={() => onChange?.(t.id)}
43
- >
44
- {t.label}
45
- </Button>
46
- )
47
- })}
48
- </div>
49
- )
7
+ export default function TabChips(props) {
8
+ return <TabsRow look="chip" {...props} />
50
9
  }
@@ -1,5 +1,6 @@
1
1
  import { useRef } from 'react'
2
2
  import CloseButton from '../atoms/CloseButton.jsx'
3
+ import Button from '../atoms/Button.jsx'
3
4
  import { Icon } from '@kolkrabbi/kol-icons'
4
5
 
5
6
  /* taxonomy-ok: nests kol-icons's Icon */
@@ -20,8 +21,102 @@ import { Icon } from '@kolkrabbi/kol-icons'
20
21
  * @param {Function} onChange (id) => void — fires on tab click or arrow-key move
21
22
  * @param {Function} onClose () => void — show + wire the leading close button
22
23
  * @param {Function} onMinimise () => void — show + wire the trailing minimise chevron
24
+ *
25
+ * ONE TAB COMPONENT, FOUR LOOKS (TabsStackedLayout, kol-monitor 2026-10-17 — four components drew one control):
26
+ * @param {'underline'|'chip'|'text'|'stacked'} [look='underline']
27
+ * underline — this row, as it always was
28
+ * chip — the active tab a filled chip, the rest quiet (was `TabChips`); `size` is the control rung
29
+ * text — flat helper-type tabs, the active one bright (was kol-shell's `TabStrip`); `size` is the
30
+ * helper size (default 14), `tracked` adds 1px tracking
31
+ * stacked — icon over label (was `MobileTabBar`); tabs take `icon`
32
+ * @param {'inline'|'phone'} [placement='inline'] `phone` floats a stacked bar fixed to the bottom below `md`
33
+ * (MobileTabBar's placement — the consumer owes the list `--kol-tabbar-h` of bottom padding)
34
+ * Tabs are `{ id, label }` or `{ value, label }` (either key), plus `icon` for stacked.
23
35
  */
24
- export default function TabsRow({ tabs = [], value, onChange, onClose, onMinimise }) {
36
+ export const TABBAR_H = 56
37
+
38
+ export default function TabsRow({ tabs: raw = [], value, onChange, onClose, onMinimise, look = 'underline', placement = 'inline', size, tracked = false, ariaLabel, className, style }) {
39
+ const tabs = raw.map((t) => ({ ...t, id: t.id ?? t.value }))
40
+ if (look === 'chip') return <ChipTabs tabs={tabs} value={value} onChange={onChange} size={size ?? 'sm'} ariaLabel={ariaLabel} className={className ?? ''} />
41
+ if (look === 'text') return <TextTabs tabs={tabs} value={value} onChange={onChange} size={size ?? 14} tracked={tracked} className={className ?? 'gap-6'} style={style} />
42
+ if (look === 'stacked') return <StackedTabs tabs={tabs} value={value} onChange={onChange} placement={placement} className={className ?? ''} />
43
+ return <UnderlineTabs tabs={tabs} value={value} onChange={onChange} onClose={onClose} onMinimise={onMinimise} />
44
+ }
45
+
46
+ /* chip — TabChips verbatim */
47
+ function ChipTabs({ tabs, value, onChange, size, ariaLabel, className }) {
48
+ return (
49
+ <div className={`flex items-center gap-1 ${className}`.trim()} role="tablist" aria-label={ariaLabel}>
50
+ {tabs.map((t) => {
51
+ const active = t.id === value
52
+ return (
53
+ /* a tab is selected, not pressed — the role's own attribute replaces Button's aria-pressed */
54
+ <Button key={t.id} variant="tab" size={size} pressed={active} role="tab" aria-selected={active} aria-pressed={undefined} onClick={() => onChange?.(t.id)}>
55
+ {t.label}
56
+ </Button>
57
+ )
58
+ })}
59
+ </div>
60
+ )
61
+ }
62
+
63
+ /* text — kol-shell's TabStrip verbatim */
64
+ function TextTabs({ tabs, value, onChange, size, tracked, className, style }) {
65
+ return (
66
+ <div className={`flex items-center ${className}`.trim()} style={style}>
67
+ {tabs.map((opt) => (
68
+ <span
69
+ key={opt.id}
70
+ onClick={() => onChange?.(opt.id)}
71
+ className={`kol-helper-${size} cursor-pointer select-none ${value === opt.id ? 'text-fg-96' : 'text-fg-32 hover:text-fg-48'}`}
72
+ style={tracked ? { letterSpacing: 1 } : undefined}
73
+ >
74
+ {opt.label}
75
+ </span>
76
+ ))}
77
+ </div>
78
+ )
79
+ }
80
+
81
+ /* stacked — MobileTabBar's tab verbatim; its fixed bottom pill is `placement="phone"`, inline is a plain row */
82
+ function StackedTabs({ tabs, value, onChange, placement, className }) {
83
+ if (tabs.length === 0) return null
84
+ const phone = placement === 'phone'
85
+ return (
86
+ <nav
87
+ className={`${phone ? 'kol-mobile-tabbar md:hidden fixed inset-x-0 bottom-0 z-[var(--kol-z-sticky)] ' : ''}flex items-stretch ${className}`.trim()}
88
+ style={phone ? {
89
+ height: TABBAR_H,
90
+ /* the pill's own ground, not the page's — it floats OVER content, so a
91
+ * transparent bar would show rows sliding through the labels */
92
+ background: 'var(--kol-surface-primary)',
93
+ borderTop: '1px solid var(--kol-oq-08)',
94
+ paddingBottom: 'env(safe-area-inset-bottom, 0px)',
95
+ } : { height: TABBAR_H }}
96
+ aria-label="Sections"
97
+ >
98
+ {tabs.map((t) => {
99
+ const active = t.id === value
100
+ return (
101
+ <button
102
+ key={t.id}
103
+ type="button"
104
+ onClick={() => onChange?.(t.id)}
105
+ aria-current={active ? 'page' : undefined}
106
+ className="flex-1 min-w-0 flex flex-col items-center justify-center gap-1 cursor-pointer"
107
+ style={{ background: 'transparent', border: 'none', color: active ? 'var(--kol-fg-default)' : 'var(--kol-fg-48)' }}
108
+ >
109
+ {t.icon && <Icon name={t.icon} size={18} />}
110
+ {/* helper is single-line chrome, which a tab label always is */}
111
+ <span className="kol-helper-10 truncate max-w-full px-1">{t.label}</span>
112
+ </button>
113
+ )
114
+ })}
115
+ </nav>
116
+ )
117
+ }
118
+
119
+ function UnderlineTabs({ tabs, value, onChange, onClose, onMinimise }) {
25
120
  const listRef = useRef(null)
26
121
  const activeIdx = tabs.findIndex((t) => t.id === value)
27
122