@kolkrabbi/kol-component 0.303.0 → 0.305.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 +2 -2
- package/src/index.js +1 -1
- package/src/molecules/TabsRow.jsx +70 -11
- package/src/organisms/NavRailSite.jsx +22 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kolkrabbi/kol-component",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.305.0",
|
|
4
4
|
"description": "The core component library",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"react-dom": "^18.3.0 || ^19.0.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@kolkrabbi/kol-icons": "^0.
|
|
41
|
+
"@kolkrabbi/kol-icons": "^0.47.0"
|
|
42
42
|
},
|
|
43
43
|
"files": [
|
|
44
44
|
"src",
|
package/src/index.js
CHANGED
|
@@ -145,7 +145,7 @@ export { default as SplitToolButton } from './molecules/SplitToolButton.jsx'
|
|
|
145
145
|
export { default as ToolPalette } from './organisms/ToolPalette.jsx'
|
|
146
146
|
export { default as DocumentEditor } from './organisms/DocumentEditor.jsx'
|
|
147
147
|
export { default as SwatchControls, SwatchStack, EyedropPick } from './molecules/SwatchControls.jsx'
|
|
148
|
-
export { default as TabsRow, TABBAR_H, TABBAR_PILL_INSET, tabbarPillWidth } from './molecules/TabsRow.jsx'
|
|
148
|
+
export { default as TabsRow, TABBAR_H, TABBAR_PILL_INSET, TABBAR_PILL_TAB, tabbarPillWidth } from './molecules/TabsRow.jsx'
|
|
149
149
|
/** @deprecated 2026-10-17 — alias of `TabsRow look="chip"` */
|
|
150
150
|
export { default as TabChips } from './molecules/TabChips.jsx'
|
|
151
151
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useRef } from 'react'
|
|
1
|
+
import { useRef, useState } from 'react'
|
|
2
2
|
import CloseButton from '../atoms/CloseButton.jsx'
|
|
3
3
|
import Button from '../atoms/Button.jsx'
|
|
4
4
|
import { Icon } from '@kolkrabbi/kol-icons'
|
|
@@ -38,7 +38,17 @@ import { RAIL_ROW } from '../hooks/railRow.js'
|
|
|
38
38
|
* phone bar collapses into one round × at its right end — the pill shrinks to a 56 circle where More was, the bar
|
|
39
39
|
* keeps its width and shows the × in More's slot — while a sheet is open; `onExpand` is the ×. It expands back
|
|
40
40
|
* @param {Function} [onExpand] the ×'s press
|
|
41
|
-
*
|
|
41
|
+
* THE PILL'S OPTIONS (PhoneNavTopAndFold + TransportPill, kol-fxr 2026-10-27, frame E — one pill that the phone nav and
|
|
42
|
+
* the transport both compose, so the two stay one size and one look):
|
|
43
|
+
* @param {'bottom'|'top'} [edge='bottom'] the pill's edge; `top` sits TABBAR_PILL_INSET under the top safe-area inset
|
|
44
|
+
* @param {boolean} [border=true] the pill's 1px oq-08 hairline
|
|
45
|
+
* @param {boolean} [shadow=false] a drop shadow — for a pill that floats over content (the transport), not the nav
|
|
46
|
+
* @param {'fill'|'circle'} [active='fill'] the lit slot: `fill` its whole 56 slot (today), `circle` a 44×44 1:1 circle
|
|
47
|
+
* @param {boolean} [foldable=false] a sideways swipe (> 40px) folds the pill into a 28×72 edge tab; a tap restores it
|
|
48
|
+
* @param {boolean} [folded] · {Function} [onFoldChange] the folded state, controlled (else the pill holds it)
|
|
49
|
+
* @param {'left'|'right'} [foldSide='left'] the screen edge the tab sits on
|
|
50
|
+
* Tabs are `{ id, label }` or `{ value, label }` (either key), plus `icon` for stacked; a stacked tab's `selected`
|
|
51
|
+
* lights it whatever `value` is — action slots (the transport) light more than one.
|
|
42
52
|
*/
|
|
43
53
|
export const TABBAR_H = 56
|
|
44
54
|
/* the pill's air off the bottom edge — a page under it owes TABBAR_H + this */
|
|
@@ -49,11 +59,11 @@ export const tabbarPillWidth = (count) => count * TABBAR_PILL_TAB + 14
|
|
|
49
59
|
/* the collapse's motion — one duration for the width and the glyph swap (300, user 2026-10-23: 180 read as abrupt) */
|
|
50
60
|
const COLLAPSE_MS = 300
|
|
51
61
|
|
|
52
|
-
export default function TabsRow({ tabs: raw = [], value, onChange, onClose, onMinimise, look = 'underline', placement = 'inline', shape = 'bar', collapsed = false, onExpand, size, tracked = false, ariaLabel, className, style }) {
|
|
62
|
+
export default function TabsRow({ tabs: raw = [], value, onChange, onClose, onMinimise, look = 'underline', placement = 'inline', shape = 'bar', collapsed = false, onExpand, edge, border, shadow, active, foldable, folded, onFoldChange, foldSide, size, tracked = false, ariaLabel, className, style }) {
|
|
53
63
|
const tabs = raw.map((t) => ({ ...t, id: t.id ?? t.value }))
|
|
54
64
|
if (look === 'chip') return <ChipTabs tabs={tabs} value={value} onChange={onChange} size={size ?? 'sm'} ariaLabel={ariaLabel} className={className ?? ''} />
|
|
55
65
|
if (look === 'text') return <TextTabs tabs={tabs} value={value} onChange={onChange} size={size ?? 14} tracked={tracked} className={className ?? 'gap-6'} style={style} />
|
|
56
|
-
if (look === 'stacked') return <StackedTabs tabs={tabs} value={value} onChange={onChange} placement={placement} shape={shape} collapsed={collapsed} onExpand={onExpand} className={className ?? ''} />
|
|
66
|
+
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} active={active} foldable={foldable} folded={folded} onFoldChange={onFoldChange} foldSide={foldSide} ariaLabel={ariaLabel} className={className ?? ''} />
|
|
57
67
|
return <UnderlineTabs tabs={tabs} value={value} onChange={onChange} onClose={onClose} onMinimise={onMinimise} />
|
|
58
68
|
}
|
|
59
69
|
|
|
@@ -93,14 +103,56 @@ function TextTabs({ tabs, value, onChange, size, tracked, className, style }) {
|
|
|
93
103
|
}
|
|
94
104
|
|
|
95
105
|
/* stacked — MobileTabBar's tab verbatim; its fixed bottom pill is `placement="phone"`, inline is a plain row */
|
|
96
|
-
|
|
106
|
+
/* the fold: a sideways swipe past this folds the pill, as frame E's prototype measures it */
|
|
107
|
+
const FOLD_SWIPE = 40
|
|
108
|
+
|
|
109
|
+
function StackedTabs({ tabs, value, onChange, placement, shape = 'bar', collapsed = false, onExpand, edge = 'bottom', border = true, shadow = false, active: activeShape = 'fill', foldable = false, folded: foldedProp, onFoldChange, foldSide = 'left', ariaLabel = 'Sections', className }) {
|
|
110
|
+
const [foldedOwn, setFoldedOwn] = useState(false)
|
|
111
|
+
const swipe = useRef({ x: null, swiped: false })
|
|
97
112
|
if (tabs.length === 0) return null
|
|
98
113
|
const phone = placement === 'phone'
|
|
99
114
|
const pill = phone && shape === 'pill'
|
|
100
115
|
const isCollapsed = phone && collapsed
|
|
101
116
|
const W = tabbarPillWidth(tabs.length)
|
|
117
|
+
const top = pill && edge === 'top'
|
|
118
|
+
const isFolded = pill && foldable && (foldedProp ?? foldedOwn)
|
|
119
|
+
const setFolded = (v) => { if (foldedProp === undefined) setFoldedOwn(v); onFoldChange?.(v) }
|
|
120
|
+
/* the edge offset: the pill's inset from the safe area on its edge */
|
|
121
|
+
const inset = `calc(env(safe-area-inset-${top ? 'top' : 'bottom'}, 0px) + ${TABBAR_PILL_INSET}px)`
|
|
122
|
+
const swipeProps = pill && foldable ? {
|
|
123
|
+
onPointerDown: (e) => { swipe.current.x = e.clientX },
|
|
124
|
+
onPointerUp: (e) => {
|
|
125
|
+
const { x } = swipe.current
|
|
126
|
+
swipe.current.x = null
|
|
127
|
+
if (x != null && Math.abs(e.clientX - x) > FOLD_SWIPE) { swipe.current.swiped = true; setFolded(true) }
|
|
128
|
+
},
|
|
129
|
+
/* a swipe that ended on a slot must not also press it */
|
|
130
|
+
onClickCapture: (e) => { if (swipe.current.swiped) { swipe.current.swiped = false; e.stopPropagation(); e.preventDefault() } },
|
|
131
|
+
style: { touchAction: 'pan-y' },
|
|
132
|
+
} : {}
|
|
133
|
+
if (isFolded) {
|
|
134
|
+
/* THE EDGE TAB (frame E): 28×72 flush to the screen edge, the pill's ground, no border, a chevron pointing back in */
|
|
135
|
+
return (
|
|
136
|
+
<button
|
|
137
|
+
type="button"
|
|
138
|
+
aria-label={`Show ${ariaLabel.toLowerCase()}`}
|
|
139
|
+
onClick={() => setFolded(false)}
|
|
140
|
+
className="kol-mobile-tabbar-tab md:hidden fixed z-[calc(var(--kol-z-sticky)+1)] flex items-center justify-center cursor-pointer"
|
|
141
|
+
style={{
|
|
142
|
+
[foldSide]: 0,
|
|
143
|
+
[top ? 'top' : 'bottom']: `calc(env(safe-area-inset-${top ? 'top' : 'bottom'}, 0px) + ${TABBAR_PILL_INSET + 8}px)`,
|
|
144
|
+
width: 28, height: 72, padding: 0, border: 'none',
|
|
145
|
+
borderRadius: foldSide === 'left' ? '0 16px 16px 0' : '16px 0 0 16px',
|
|
146
|
+
background: 'var(--kol-surface-secondary)', color: RAIL_ROW.rest,
|
|
147
|
+
}}
|
|
148
|
+
>
|
|
149
|
+
<Icon name={foldSide === 'left' ? 'chevron-right' : 'chevron-left'} size={18} />
|
|
150
|
+
</button>
|
|
151
|
+
)
|
|
152
|
+
}
|
|
102
153
|
return (
|
|
103
154
|
<nav
|
|
155
|
+
{...swipeProps}
|
|
104
156
|
className={`${pill
|
|
105
157
|
? 'kol-mobile-tabbar kol-mobile-tabbar-pill md:hidden fixed z-[calc(var(--kol-z-sticky)+1)] rounded-full p-1.5 overflow-hidden '
|
|
106
158
|
: phone ? 'kol-mobile-tabbar md:hidden fixed inset-x-0 bottom-0 z-[var(--kol-z-sticky)] ' : ''}flex items-stretch ${className}`.trim()}
|
|
@@ -111,10 +163,13 @@ function StackedTabs({ tabs, value, onChange, placement, shape = 'bar', collapse
|
|
|
111
163
|
height: TABBAR_H,
|
|
112
164
|
width: isCollapsed ? TABBAR_H : W,
|
|
113
165
|
right: `calc(50% - ${W / 2}px)`,
|
|
114
|
-
bottom:
|
|
166
|
+
[top ? 'top' : 'bottom']: inset,
|
|
115
167
|
background: 'var(--kol-surface-secondary)',
|
|
116
|
-
|
|
168
|
+
/* without the hairline the 1px it took stays, transparent, so the slots never move */
|
|
169
|
+
border: `1px solid ${border ? 'var(--kol-oq-08)' : 'transparent'}`,
|
|
170
|
+
boxShadow: shadow ? '0 8px 40px rgba(0, 0, 0, 0.45)' : undefined,
|
|
117
171
|
transition: `width ${COLLAPSE_MS}ms ease`,
|
|
172
|
+
...swipeProps.style,
|
|
118
173
|
} : phone ? {
|
|
119
174
|
height: TABBAR_H,
|
|
120
175
|
/* the pill's own ground, not the page's — it floats OVER content, so a
|
|
@@ -123,11 +178,12 @@ function StackedTabs({ tabs, value, onChange, placement, shape = 'bar', collapse
|
|
|
123
178
|
borderTop: '1px solid var(--kol-oq-08)',
|
|
124
179
|
paddingBottom: 'env(safe-area-inset-bottom, 0px)',
|
|
125
180
|
} : { height: TABBAR_H }}
|
|
126
|
-
aria-label=
|
|
181
|
+
aria-label={ariaLabel}
|
|
127
182
|
>
|
|
128
183
|
<div className={`flex items-stretch ${pill ? 'flex-none' : 'flex-1 min-w-0'}`} style={{ width: pill ? W - 14 : undefined, opacity: isCollapsed ? 0 : 1, pointerEvents: isCollapsed ? 'none' : 'auto', transition: `opacity ${COLLAPSE_MS}ms ease` }}>
|
|
129
184
|
{tabs.map((t) => {
|
|
130
|
-
const active = t.id === value
|
|
185
|
+
const active = t.selected ?? t.id === value
|
|
186
|
+
const circle = pill && activeShape === 'circle'
|
|
131
187
|
return (
|
|
132
188
|
<button
|
|
133
189
|
key={t.id}
|
|
@@ -140,9 +196,12 @@ function StackedTabs({ tabs, value, onChange, placement, shape = 'bar', collapse
|
|
|
140
196
|
className={pill ? 'flex items-center justify-center rounded-full cursor-pointer' : 'flex-1 min-w-0 flex flex-col items-center justify-center gap-1 cursor-pointer'}
|
|
141
197
|
/* the PHONE bar wears the rail's row type and ink (review 2, § 7.1 — RAIL_ROW, the one constant the rail reads);
|
|
142
198
|
* an inline stacked row keeps MobileTabBar's own */
|
|
143
|
-
style={{ background: pill && active ? 'var(--kol-oq-08)' : 'transparent', border: 'none', width: pill ? 56 : undefined, color: phone ? (active ? RAIL_ROW.active : RAIL_ROW.rest) : (active ? 'var(--kol-fg-default)' : 'var(--kol-fg-48)') }}
|
|
199
|
+
style={{ background: pill && active && !circle ? 'var(--kol-oq-08)' : 'transparent', border: 'none', width: pill ? 56 : undefined, color: phone ? (active ? RAIL_ROW.active : RAIL_ROW.rest) : (active ? 'var(--kol-fg-default)' : 'var(--kol-fg-48)') }}
|
|
144
200
|
>
|
|
145
|
-
{
|
|
201
|
+
{/* the circle: 44×44, 1:1 inside the 56 slot (frame E — the fill stretched to the slot's width) */}
|
|
202
|
+
{t.icon && (circle
|
|
203
|
+
? <span className="inline-flex items-center justify-center rounded-full" style={{ width: 44, height: 44, background: active ? 'var(--kol-oq-08)' : 'transparent' }}><Icon name={t.icon} size={28} /></span>
|
|
204
|
+
: <Icon name={t.icon} size={pill ? 28 : phone ? 24 : 18} />)}
|
|
146
205
|
{/* helper is single-line chrome, which a tab label always is */}
|
|
147
206
|
{!phone && <span className="kol-helper-10 truncate max-w-full px-1">{t.label}</span>}
|
|
148
207
|
</button>
|
|
@@ -121,6 +121,14 @@ import useDragResize from '../hooks/useDragResize.js'
|
|
|
121
121
|
* ruling "pressing any icon would expand the sidebar"): a
|
|
122
122
|
* collapsed rail stays collapsed, the press does its job
|
|
123
123
|
* `defaultCollapsed` boots collapsed when nothing is stored (useDragResize)
|
|
124
|
+
* THE RAIL'S BEHAVIOURS ARE PROPS (SiteRailTitleNavigatesOnly, kol-branding 2026-10-27 — user: "clicking on title
|
|
125
|
+
* shouldnt also expand, that is what the chevron is for", and: a small rail behaviour should never need a ticket here —
|
|
126
|
+
* a sensible default plus a prop the consumer sets in its own repo):
|
|
127
|
+
* `discloseOnTitle` `true` lets a foldernote's TITLE also open its pages; default `false` — the title navigates, the
|
|
128
|
+
* chevron alone expands and collapses
|
|
129
|
+
* `defaultOpen` category ids open on first render (default none — the rail loads closed, elder ruling 2026-08-06)
|
|
130
|
+
* `openOnRoute` `true` opens the category holding the current route whenever the route changes (default `false`
|
|
131
|
+
* — nothing auto-expands on arrival); it only adds, never closes what you opened
|
|
124
132
|
* `background` (2026-08-09, prop): `true` (default) paints the rail surface;
|
|
125
133
|
* `false` renders chromeless so the rail can float over a consumer's media
|
|
126
134
|
* (the brand-hero model — the consumer owns the plane). `hairline` (2026-08-26,
|
|
@@ -193,6 +201,9 @@ export default function NavRailSite({
|
|
|
193
201
|
iconComponent,
|
|
194
202
|
expandOnSelect = false,
|
|
195
203
|
defaultCollapsed = false,
|
|
204
|
+
discloseOnTitle = false,
|
|
205
|
+
defaultOpen = [],
|
|
206
|
+
openOnRoute = false,
|
|
196
207
|
}) {
|
|
197
208
|
const Glyph = iconComponent ?? Icon
|
|
198
209
|
const isPageActive = (to) => (isActive ? isActive(to) : pathname === to)
|
|
@@ -226,7 +237,7 @@ export default function NavRailSite({
|
|
|
226
237
|
/* Which categories are disclosed. INDEPENDENT per category (elder ruling
|
|
227
238
|
* 2026-08-01) — arriving somewhere must not silently close wherever you
|
|
228
239
|
* were. Loads closed, in-memory only (elder ruling 2026-08-06). */
|
|
229
|
-
const [openCats, setOpenCats] = useState(() => new Set())
|
|
240
|
+
const [openCats, setOpenCats] = useState(() => new Set(defaultOpen))
|
|
230
241
|
/* the ONE open panel leaf (by id) and where its panel sits */
|
|
231
242
|
const [openPanel, setOpenPanel] = useState(null)
|
|
232
243
|
const [panelBox, setPanelBox] = useState(null)
|
|
@@ -236,6 +247,13 @@ export default function NavRailSite({
|
|
|
236
247
|
return next
|
|
237
248
|
})
|
|
238
249
|
const discloseCat = (id) => setOpenCats((prev) => new Set(prev).add(id))
|
|
250
|
+
/* `openOnRoute`: the category holding the route opens on arrival, adding to what is open */
|
|
251
|
+
useEffect(() => {
|
|
252
|
+
if (!openOnRoute) return
|
|
253
|
+
const here = [...navTree, ...bottomItems].find((c) => c.id != null && (isActiveCat(c) || (c.to && isPageActive(c.to))))
|
|
254
|
+
if (here) discloseCat(here.id)
|
|
255
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
256
|
+
}, [openOnRoute, pathname])
|
|
239
257
|
|
|
240
258
|
/* One collapse contract, two gestures — the hook owns the stamp, the
|
|
241
259
|
* storage schema and the state; the chip Button and the grab edge both
|
|
@@ -348,10 +366,10 @@ export default function NavRailSite({
|
|
|
348
366
|
definition, and an <a href> would promise a page that does
|
|
349
367
|
not exist. Clicking it discloses its pages. */
|
|
350
368
|
const head = isFolder ? (
|
|
351
|
-
/* the row opens the page and discloses; the caret beside it (a sibling — a
|
|
352
|
-
* inside a link) toggles the disclosure
|
|
369
|
+
/* the row opens the page (and discloses only with `discloseOnTitle`); the caret beside it (a sibling — a
|
|
370
|
+
* button cannot sit inside a link) toggles the disclosure */
|
|
353
371
|
<>
|
|
354
|
-
<RouteLeaf {...leafProps(cat.to)} onPress={() => discloseCat(cat.id)} className={(active) => `${rowCls}${(active || isActiveCat(cat)) ? ' is-active' : ''}`}>
|
|
372
|
+
<RouteLeaf {...leafProps(cat.to)} onPress={discloseOnTitle ? () => discloseCat(cat.id) : undefined} className={(active) => `${rowCls}${(active || isActiveCat(cat)) ? ' is-active' : ''}`}>
|
|
355
373
|
{glyph}
|
|
356
374
|
<span className="kol-sidenav-hop-label flex-1 min-w-0">{cat.label}</span>
|
|
357
375
|
</RouteLeaf>
|