@kolkrabbi/kol-component 0.315.0 → 0.316.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.315.0",
3
+ "version": "0.316.0",
4
4
  "description": "The core component library",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -26,8 +26,8 @@
26
26
  "embla-carousel-react": "^8.6.0",
27
27
  "pdfjs-dist": "^6.3.289",
28
28
  "react-syntax-highlighter": "^16.1.1",
29
- "@kolkrabbi/kol-markdown": "^0.2.0",
30
- "@kolkrabbi/kol-search": "^0.3.0"
29
+ "@kolkrabbi/kol-search": "^0.3.0",
30
+ "@kolkrabbi/kol-markdown": "^0.2.0"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "@kolkrabbi/kol-icons": ">=0.22.0",
@@ -6,15 +6,23 @@ import { useEffect } from 'react'
6
6
  * box is scrolled, and `data-fade-bottom` while more lies below; kol-theme's `.kol-scroll-fade` draws the two fades from
7
7
  * them. Re-read on scroll and whenever the box or its content changes size. One rule for every vertically scrolling rail
8
8
  * or list that clips: the site rail, the app rail, the workshop's rails.
9
+ *
10
+ * `axis="x"` (TabsRowOverflow, kol-website 2026-10-29): the same for a row that scrolls sideways — `data-fade-left` once
11
+ * scrolled, `data-fade-right` while more lies to the right; `.kol-scroll-fade--x` draws them.
9
12
  */
10
- export default function useScrollFade(ref, enabled = true) {
13
+ export default function useScrollFade(ref, enabled = true, axis = 'y') {
11
14
  useEffect(() => {
12
15
  const el = ref.current
13
16
  if (!el || !enabled) return undefined
14
- const read = () => {
15
- el.toggleAttribute('data-fade-top', el.scrollTop > 1)
16
- el.toggleAttribute('data-fade-bottom', el.scrollTop + el.clientHeight < el.scrollHeight - 1)
17
- }
17
+ const read = axis === 'x'
18
+ ? () => {
19
+ el.toggleAttribute('data-fade-left', el.scrollLeft > 1)
20
+ el.toggleAttribute('data-fade-right', el.scrollLeft + el.clientWidth < el.scrollWidth - 1)
21
+ }
22
+ : () => {
23
+ el.toggleAttribute('data-fade-top', el.scrollTop > 1)
24
+ el.toggleAttribute('data-fade-bottom', el.scrollTop + el.clientHeight < el.scrollHeight - 1)
25
+ }
18
26
  read()
19
27
  el.addEventListener('scroll', read, { passive: true })
20
28
  const ro = new ResizeObserver(read)
@@ -26,8 +34,7 @@ export default function useScrollFade(ref, enabled = true) {
26
34
  el.removeEventListener('scroll', read)
27
35
  ro.disconnect()
28
36
  mo.disconnect()
29
- el.removeAttribute('data-fade-top')
30
- el.removeAttribute('data-fade-bottom')
37
+ for (const a of ['top', 'bottom', 'left', 'right']) el.removeAttribute(`data-fade-${a}`)
31
38
  }
32
- }, [ref, enabled])
39
+ }, [ref, enabled, axis])
33
40
  }
@@ -1,4 +1,5 @@
1
- import { useRef, useState } from 'react'
1
+ import { useLayoutEffect, useRef, useState } from 'react'
2
+ import useScrollFade from '../hooks/useScrollFade.js'
2
3
  import CloseButton from '../atoms/CloseButton.jsx'
3
4
  import Button from '../atoms/Button.jsx'
4
5
  import { Icon } from '@kolkrabbi/kol-icons'
@@ -24,6 +25,11 @@ import { RAIL_ROW } from '../hooks/railRow.js'
24
25
  * @param {Function} onMinimise () => void — show + wire the trailing minimise chevron
25
26
  *
26
27
  * ONE TAB COMPONENT, FOUR LOOKS (TabsStackedLayout, kol-monitor 2026-10-17 — four components drew one control):
28
+ * @param {'scroll'|'wrap'} [overflow='scroll'] A ROW WIDER THAN ITS COLUMN (TabsRowOverflow, kol-website 2026-10-29 — six
29
+ * underline tabs are 394px, so at 390 the page scrolled sideways and record wrapped the row in its own div): `scroll`
30
+ * keeps one line that scrolls sideways with no scrollbar, `.kol-scroll-fade--x` fading the clipped edge(s), and the
31
+ * active tab scrolled into view when it changes — arrow keys included; `wrap` breaks the tabs onto a second line.
32
+ * Every look but `stacked`, which has its phone bar
27
33
  * @param {'underline'|'chip'|'text'|'stacked'} [look='underline']
28
34
  * underline — this row, as it always was
29
35
  * chip — the active tab a filled chip, the rest quiet (was `TabChips`); `size` is the control rung
@@ -63,12 +69,32 @@ export const tabbarPillWidth = (count) => count * TABBAR_PILL_TAB + 14
63
69
  /* the collapse's motion — one duration for the width and the glyph swap (300, user 2026-10-23: 180 read as abrupt) */
64
70
  const COLLAPSE_MS = 300
65
71
 
66
- export default function TabsRow({ tabs: raw = [], value, onChange, onClose, onMinimise, look = 'underline', placement = 'inline', shape = 'bar', collapsed = false, onExpand, edge, border, shadow, dock, active, foldable, folded, onFoldChange, foldSide, size, tracked = false, ariaLabel, className, style }) {
72
+ export default function TabsRow({ tabs: raw = [], value, onChange, onClose, onMinimise, look = 'underline', placement = 'inline', shape = 'bar', collapsed = false, onExpand, edge, border, shadow, dock, active, foldable, folded, onFoldChange, foldSide, size, tracked = false, overflow = 'scroll', ariaLabel, className, style }) {
67
73
  const tabs = raw.map((t) => ({ ...t, id: t.id ?? t.value }))
68
- if (look === 'chip') return <ChipTabs tabs={tabs} value={value} onChange={onChange} size={size ?? 'sm'} ariaLabel={ariaLabel} className={className ?? ''} />
69
- if (look === 'text') return <TextTabs tabs={tabs} value={value} onChange={onChange} size={size ?? 14} tracked={tracked} className={className ?? 'gap-6'} style={style} />
74
+ const wrap = overflow === 'wrap'
75
+ if (look === 'chip') return <Overflow mode={overflow} value={value}><ChipTabs tabs={tabs} value={value} onChange={onChange} size={size ?? 'sm'} ariaLabel={ariaLabel} className={`${wrap ? 'flex-wrap ' : ''}${className ?? ''}`} /></Overflow>
76
+ if (look === 'text') return <Overflow mode={overflow} value={value}><TextTabs tabs={tabs} value={value} onChange={onChange} size={size ?? 14} tracked={tracked} className={`${wrap ? 'flex-wrap gap-y-2 ' : ''}${className ?? 'gap-6'}`} style={style} /></Overflow>
70
77
  if (look === 'stacked') return <StackedTabs tabs={tabs} value={value} onChange={onChange} placement={placement} shape={shape} collapsed={collapsed} onExpand={onExpand} edge={edge} border={border} shadow={shadow} dock={dock} active={active} foldable={foldable} folded={folded} onFoldChange={onFoldChange} foldSide={foldSide} ariaLabel={ariaLabel} className={className ?? ''} />
71
- return <UnderlineTabs tabs={tabs} value={value} onChange={onChange} onClose={onClose} onMinimise={onMinimise} />
78
+ return <Overflow mode={overflow} value={value}><UnderlineTabs tabs={tabs} value={value} onChange={onChange} onClose={onClose} onMinimise={onMinimise} wrap={wrap} /></Overflow>
79
+ }
80
+
81
+ /* `overflow="scroll"`: the row in a sideways scroller that fades its clipped edges and keeps the active tab (`data-active`)
82
+ * in view — by the scroller's own scrollLeft, never scrollIntoView, which would scroll the page too. `wrap` draws as is. */
83
+ function Overflow({ mode, value, children }) {
84
+ const ref = useRef(null)
85
+ const scroll = mode !== 'wrap'
86
+ useScrollFade(ref, scroll, 'x')
87
+ useLayoutEffect(() => {
88
+ const strip = ref.current
89
+ const tab = strip?.querySelector('[data-active]')
90
+ if (!scroll || !strip || !tab) return
91
+ const s = strip.getBoundingClientRect()
92
+ const t = tab.getBoundingClientRect()
93
+ if (t.left < s.left) strip.scrollLeft += t.left - s.left
94
+ else if (t.right > s.right) strip.scrollLeft += t.right - s.right
95
+ }, [value, scroll])
96
+ if (!scroll) return children
97
+ return <div ref={ref} className="kol-tabs-scroll kol-scroll-fade--x">{children}</div>
72
98
  }
73
99
 
74
100
  /* chip — TabChips verbatim */
@@ -79,7 +105,7 @@ function ChipTabs({ tabs, value, onChange, size, ariaLabel, className }) {
79
105
  const active = t.id === value
80
106
  return (
81
107
  /* a tab is selected, not pressed — the role's own attribute replaces Button's aria-pressed */
82
- <Button key={t.id} variant="tab" size={size} pressed={active} role="tab" aria-selected={active} aria-pressed={undefined} onClick={() => onChange?.(t.id)}>
108
+ <Button key={t.id} variant="tab" size={size} pressed={active} role="tab" aria-selected={active} aria-pressed={undefined} data-active={active || undefined} onClick={() => onChange?.(t.id)}>
83
109
  {t.label}
84
110
  </Button>
85
111
  )
@@ -95,6 +121,7 @@ function TextTabs({ tabs, value, onChange, size, tracked, className, style }) {
95
121
  {tabs.map((opt) => (
96
122
  <span
97
123
  key={opt.id}
124
+ data-active={value === opt.id || undefined}
98
125
  onClick={() => onChange?.(opt.id)}
99
126
  className={`kol-helper-${size} cursor-pointer select-none ${value === opt.id ? 'text-fg-96' : 'text-fg-32 hover:text-fg-48'}`}
100
127
  style={tracked ? { letterSpacing: 1 } : undefined}
@@ -236,7 +263,7 @@ function StackedTabs({ tabs, value, onChange, placement, shape = 'bar', collapse
236
263
  )
237
264
  }
238
265
 
239
- function UnderlineTabs({ tabs, value, onChange, onClose, onMinimise }) {
266
+ function UnderlineTabs({ tabs, value, onChange, onClose, onMinimise, wrap }) {
240
267
  const listRef = useRef(null)
241
268
  const activeIdx = tabs.findIndex((t) => t.id === value)
242
269
 
@@ -250,14 +277,14 @@ function UnderlineTabs({ tabs, value, onChange, onClose, onMinimise }) {
250
277
  }
251
278
 
252
279
  return (
253
- <div className="flex items-stretch gap-4 h-10">
280
+ <div className={`flex items-stretch gap-4 ${wrap ? 'min-h-10' : 'h-10'}`}>
254
281
  {onClose && (
255
282
  /* the one close, at the rung whose glyph is the 12 this hand-rolled
256
283
  * (2026-09-03) — xs SOLO is 12, so the drawing does not move */
257
284
  <CloseButton onClick={onClose} size="xs" className="self-center" />
258
285
  )}
259
286
 
260
- <div ref={listRef} role="tablist" onKeyDown={onKeyDown} className="flex items-stretch gap-4">
287
+ <div ref={listRef} role="tablist" onKeyDown={onKeyDown} className={`flex items-stretch gap-4${wrap ? ' flex-wrap gap-y-1' : ''}`}>
261
288
  {tabs.map((t, i) => {
262
289
  const isActive = t.id === value
263
290
  return (
@@ -266,6 +293,7 @@ function UnderlineTabs({ tabs, value, onChange, onClose, onMinimise }) {
266
293
  type="button"
267
294
  role="tab"
268
295
  aria-selected={isActive}
296
+ data-active={isActive || undefined}
269
297
  tabIndex={isActive || (activeIdx === -1 && i === 0) ? 0 : -1}
270
298
  onClick={() => onChange?.(t.id)}
271
299
  className={[