@kolkrabbi/kol-component 0.314.0 → 0.315.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.314.0",
3
+ "version": "0.315.0",
4
4
  "description": "The core component library",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -0,0 +1,25 @@
1
+ /**
2
+ * ProgressBar — How far along something is. A thin track and its fill, and a caption under it (record's project card:
3
+ * `3/7 done` — DocumentLibraryAndBoardParts, kol-website 2026-10-29). The fill takes the status tones the chips wear, or
4
+ * the ink when none is given.
5
+ *
6
+ * @param {number} value
7
+ * @param {number} max default 100
8
+ * @param {boolean|ReactNode|Function} caption `true` → `value/max`; a node; or `(value, max) => node`; omit for none
9
+ * @param {'success'|'warning'|'error'|'info'} tone the fill's colour (default the ink)
10
+ * @param {string} ariaLabel
11
+ */
12
+ const TONE = { success: 'var(--ui-success)', warning: 'var(--ui-warning)', error: 'var(--ui-error)', info: 'var(--ui-info)' }
13
+
14
+ export default function ProgressBar({ value = 0, max = 100, caption, tone, ariaLabel, className = '' }) {
15
+ const pct = max > 0 ? Math.max(0, Math.min(100, (value / max) * 100)) : 0
16
+ const text = caption === true ? `${value}/${max}` : typeof caption === 'function' ? caption(value, max) : caption
17
+ return (
18
+ <div className={`flex flex-col gap-1 ${className}`.trim()}>
19
+ <div role="progressbar" aria-valuenow={value} aria-valuemin={0} aria-valuemax={max} aria-label={ariaLabel} className="h-1 overflow-hidden rounded bg-fg-08">
20
+ <div className="h-full transition-[width] duration-300" style={{ width: `${pct}%`, background: TONE[tone] ?? 'var(--kol-fg-64)' }} />
21
+ </div>
22
+ {text != null && text !== false && <span className="kol-mono-10 text-meta">{text}</span>}
23
+ </div>
24
+ )
25
+ }
package/src/index.js CHANGED
@@ -230,6 +230,12 @@ export { default as MediaPlayer, VideoSheet, AudioSheet, AudioPreview, AudioPlay
230
230
  export { AudioTile, VideoTile, formatLength } from './molecules/PlayTile.jsx'
231
231
  export { default as PlaybackBar } from './molecules/PlaybackBar.jsx'
232
232
  export { default as QuickLookFrame } from './molecules/QuickLookFrame.jsx'
233
+ export { default as FileQuickLook } from './organisms/FileQuickLook.jsx'
234
+ export { default as FlipCard } from './utilities/FlipCard.jsx'
235
+ export { default as Kanban } from './organisms/Kanban.jsx'
236
+ export { default as SortableGrid } from './organisms/SortableGrid.jsx'
237
+ export { default as ProgressBar } from './atoms/ProgressBar.jsx'
238
+ export { default as formatAge } from './utilities/formatAge.js'
233
239
  export { default as MediaTile } from './molecules/MediaTile.jsx'
234
240
  export { default as RowMenuButton } from './molecules/RowMenuButton.jsx'
235
241
  export { default as DocPage } from './molecules/DocPage.jsx'
@@ -37,11 +37,15 @@ import OptionRow from './OptionRow.jsx'
37
37
  * info maps onto the --ui-* ladder (.kol-status-chip--* in kol-theme); the
38
38
  * chip wears the ACTIVE option's tone. No tone → the plain Tag look.
39
39
  *
40
+ * `cycle` (DocumentLibraryAndBoardParts, kol-website 2026-10-29 — record's project status and card size): a click steps
41
+ * to the next option, no menu and no chevron — the same chip, so a status that cycles and one that opens a list look
42
+ * alike. `placeholder` is the label while `value` matches no option (record's `·` for an unsized card).
43
+ *
40
44
  * variant="primary" — the toneless pill wears the Dropdown-primary fill
41
45
  * instead of the neutral mix (RecordManager's select columns, user frame
42
46
  * 2026-08-09: "use status pill, but same look as dropdown primary"). An
43
47
  * option's tone always outranks the variant. */
44
- export function StatusChip({ value, options = [], onChange, variant = 'neutral', size = 'sm' }) {
48
+ export function StatusChip({ value, options = [], onChange, variant = 'neutral', size = 'sm', cycle = false, placeholder, ariaLabel }) {
45
49
  const [open, setOpen] = useState(false)
46
50
  const popover = usePopover({
47
51
  open,
@@ -61,6 +65,19 @@ export function StatusChip({ value, options = [], onChange, variant = 'neutral',
61
65
  * this?") carries visible air; 2px is the minimum that restores it.
62
66
  * mono-12 at its own 16px leading. The chevron is a direct child of the flex
63
67
  * row, centred by items-center; it cannot sit off the label's middle. */
68
+ if (cycle) {
69
+ const next = norm[(norm.findIndex((o) => o.value === value) + 1) % (norm.length || 1)]
70
+ return (
71
+ <button
72
+ type="button"
73
+ aria-label={ariaLabel}
74
+ className={`kol-status-chip${toneCls} kol-mono-12 inline-flex items-center gap-2 rounded-full border-0 px-2 py-0.5 cursor-pointer`}
75
+ onClick={() => next && onChange?.(next.value)}
76
+ >
77
+ {activeOpt?.label ?? placeholder ?? value}
78
+ </button>
79
+ )
80
+ }
64
81
  const chip = (interactive) => (
65
82
  <button
66
83
  type="button"
@@ -0,0 +1,54 @@
1
+ import Button from '../atoms/Button.jsx'
2
+ import FullscreenOverlay from '../utilities/FullscreenOverlay.jsx'
3
+ import QuickLookFrame from '../molecules/QuickLookFrame.jsx'
4
+ import KindPreview from '../molecules/KindPreview.jsx'
5
+ import { kindOf, extOf, KIND_LABEL } from '../utilities/mediaKinds.js'
6
+
7
+ /* taxonomy-ok: organism — nests FullscreenOverlay (utility) + QuickLookFrame / KindPreview (molecules) + Button (atom). */
8
+
9
+ /**
10
+ * FileQuickLook — Quick Look over a list of files. The composition three places drew by hand — kol-styleguide's
11
+ * `DocumentIndex`, record's `QuickLook` (Bucket.jsx) and its documents table (DocumentLibraryAndBoardParts, kol-website
12
+ * 2026-10-29 — *"I already asked for tables, and download and file preview"*): `FullscreenOverlay` dims the page,
13
+ * `QuickLookFrame` holds the file, pages ‹ › through the list and carries a download; an image shows directly, anything
14
+ * else through `KindPreview`.
15
+ *
16
+ * @param {Array} files `[{ key, name?, title?, url?, size?, type? }]` — `key` classifies (its extension), `type` is
17
+ * the content type when known
18
+ * @param {number} index the open file; `null` closes
19
+ * @param {Function} onIndex (i) => void — ‹ › paging
20
+ * @param {Function} onClose
21
+ * @param {Function} urlOf (file) => string — default `file.url`
22
+ * @param {boolean} download the download button in the header (default true)
23
+ * @param {Function} meta (file) => node — the header's facts (default: the size, else the kind)
24
+ * @param {ReactNode} actions more header controls, before the download
25
+ */
26
+ const sizeLabel = (n) => (n >= 1048576 ? `${(n / 1048576).toFixed(1)} MB` : `${Math.max(1, Math.round(n / 1024))} KB`)
27
+ const nameOf = (f) => f.name ?? f.title ?? f.key?.split('/').pop() ?? ''
28
+
29
+ export default function FileQuickLook({ files = [], index, onIndex, onClose, urlOf = (f) => f.url, download = true, meta, actions }) {
30
+ const f = index == null ? null : files[index]
31
+ if (!f) return null
32
+ const url = urlOf(f)
33
+ const kind = kindOf({ key: f.key ?? nameOf(f), contentType: f.type ?? f.contentType })
34
+ const facts = meta ? meta(f) : (f.size ? sizeLabel(f.size) : (KIND_LABEL[kind] ?? extOf(f.key ?? '').toUpperCase()))
35
+ const nav = files.length > 1
36
+ ? { index, total: files.length, onPrev: () => onIndex?.((index - 1 + files.length) % files.length), onNext: () => onIndex?.((index + 1) % files.length) }
37
+ : undefined
38
+ return (
39
+ /* QUICK LOOK DIMS, it does not black out — the list stays in view (MediaLibraryPages' rule) */
40
+ <FullscreenOverlay open onClose={onClose} closeButton={false} scrim>
41
+ <QuickLookFrame
42
+ title={nameOf(f)}
43
+ meta={facts}
44
+ actions={<>{actions}{download && url && <Button variant="nav" size="sm" iconOnly="download" href={url} download={nameOf(f)} aria-label="Download" />}</>}
45
+ onClose={onClose}
46
+ nav={nav}
47
+ >
48
+ {kind === 'image'
49
+ ? <img src={url} alt={nameOf(f)} className="kol-quicklook-media" />
50
+ : <KindPreview key={url} o={{ key: (f.key ?? url).split('?')[0], contentType: f.type ?? f.contentType, size: f.size, url }} fit="sheet" urlOf={() => url} />}
51
+ </QuickLookFrame>
52
+ </FullscreenOverlay>
53
+ )
54
+ }
@@ -0,0 +1,110 @@
1
+ import { useState } from 'react'
2
+ import Button from '../atoms/Button.jsx'
3
+
4
+ /* taxonomy-ok: organism — nests Button (atom); the cards are the consumer's (`renderCard`). */
5
+
6
+ /**
7
+ * Kanban — Cards in columns, moved between them. record's Capture board, made the DS's (DocumentLibraryAndBoardParts,
8
+ * kol-website 2026-10-29 — *"DASHBOARD NEEDS TO CONSUME DS COMPONENTS"*). Controlled: the board draws `cards` in
9
+ * `columns` by `order` and reports a move; the consumer owns the data and the write-back.
10
+ *
11
+ * A card moves three ways: dragged into a column (it lands last) or onto a card (it lands before it), within a column
12
+ * or between, and by its ‹ › buttons, which a keyboard reaches and a phone can press — at 390 the columns stack.
13
+ * Something dragged in from outside the board lands too: give `externalType`, the `dataTransfer` key the outside item
14
+ * sets, and `onExternalDrop` receives its payload (record drags inbox lines in).
15
+ *
16
+ * @param {Array} columns `[{ id, label, tone? }]` — tone ∈ success · warning · error · info (the header's dot)
17
+ * @param {Array} cards `[{ id, column, order, … }]` — a card with `archived` is not drawn
18
+ * @param {Function} onMove (cardId, toColumn, beforeId | null) => void
19
+ * @param {Function} renderCard (card) => node — the card's body
20
+ * @param {Function} cardActions (card) => node — the hover row, right of ‹ ›
21
+ * @param {Function} columnActions (column, cards) => node — beside the count ("archive all")
22
+ * @param {ReactNode} footer under the board (the archive list)
23
+ * @param {string} externalType the `dataTransfer` key an outside drag carries
24
+ * @param {Function} onExternalDrop (column, beforeId | null, payload) => void
25
+ * @param {ReactNode} empty a column with no cards (default `—`)
26
+ */
27
+ const CARD_TYPE = 'application/x-kol-kanban-card'
28
+ const TONE = { success: 'var(--ui-success)', warning: 'var(--ui-warning)', error: 'var(--ui-error)', info: 'var(--ui-info)' }
29
+
30
+ export default function Kanban({ columns = [], cards = [], onMove, renderCard, cardActions, columnActions, footer, externalType, onExternalDrop, empty = '—', className = '' }) {
31
+ const [over, setOver] = useState(null) // { column, before }
32
+ const ids = columns.map((c) => c.id)
33
+ const accepts = (e) => e.dataTransfer.types.includes(CARD_TYPE) || (externalType && e.dataTransfer.types.includes(externalType))
34
+
35
+ const drop = (e, column, before) => {
36
+ e.preventDefault()
37
+ e.stopPropagation()
38
+ setOver(null)
39
+ const id = e.dataTransfer.getData(CARD_TYPE)
40
+ if (id) { if (id !== before) onMove?.(id, column, before); return }
41
+ if (externalType) {
42
+ const payload = e.dataTransfer.getData(externalType)
43
+ if (payload) onExternalDrop?.(column, before, payload)
44
+ }
45
+ }
46
+ const dragOver = (column, before) => (e) => {
47
+ if (!accepts(e)) return
48
+ e.preventDefault()
49
+ e.stopPropagation()
50
+ if (over?.column !== column || over?.before !== before) setOver({ column, before })
51
+ }
52
+ const step = (card, d) => {
53
+ const i = ids.indexOf(card.column) + d
54
+ if (i >= 0 && i < ids.length) onMove?.(card.id, ids[i], null)
55
+ }
56
+
57
+ return (
58
+ <div className={className}>
59
+ <div className="kol-kanban" style={{ '--kol-kanban-cols': columns.length }} onDragLeave={(e) => { if (!e.currentTarget.contains(e.relatedTarget)) setOver(null) }}>
60
+ {columns.map((col, ci) => {
61
+ const list = cards.filter((c) => c.column === col.id && !c.archived).sort((a, b) => (a.order ?? 0) - (b.order ?? 0))
62
+ return (
63
+ <section
64
+ key={col.id}
65
+ aria-label={col.label}
66
+ className={`kol-kanban-column${over?.column === col.id ? ' is-over' : ''}`}
67
+ onDragOver={dragOver(col.id, null)}
68
+ onDrop={(e) => drop(e, col.id, null)}
69
+ >
70
+ {/* wraps: a column action ("Archive") never runs past a narrow column */}
71
+ <header className="flex flex-wrap items-center justify-between gap-x-2 gap-y-1">
72
+ <span className="flex items-center gap-1.5">
73
+ {col.tone && <span className="inline-block size-2 rounded-full" style={{ background: TONE[col.tone] }} />}
74
+ <span className="kol-mono-12 text-emphasis">{col.label}</span>
75
+ </span>
76
+ <span className="flex items-center gap-2">
77
+ <span className="kol-mono-10 text-meta tabular-nums">{list.length}</span>
78
+ {columnActions?.(col, list)}
79
+ </span>
80
+ </header>
81
+ <ul className="flex flex-col gap-2 m-0 p-0 list-none">
82
+ {list.map((card) => (
83
+ <li
84
+ key={card.id}
85
+ draggable
86
+ onDragStart={(e) => { e.dataTransfer.setData(CARD_TYPE, card.id); e.dataTransfer.effectAllowed = 'move' }}
87
+ onDragOver={dragOver(col.id, card.id)}
88
+ onDrop={(e) => drop(e, col.id, card.id)}
89
+ className={`kol-kanban-card group${over?.column === col.id && over.before === card.id ? ' is-drop-target' : ''}`}
90
+ >
91
+ {renderCard?.(card)}
92
+ <div className="flex items-center justify-between gap-2">
93
+ <span className="flex items-center gap-0.5">
94
+ <Button variant="nav" size="sm" iconOnly="chevron-left" disabled={ci === 0} onClick={() => step(card, -1)} aria-label={`Move to ${columns[ci - 1]?.label ?? ''}`.trim()} />
95
+ <Button variant="nav" size="sm" iconOnly="chevron-right" disabled={ci === columns.length - 1} onClick={() => step(card, 1)} aria-label={`Move to ${columns[ci + 1]?.label ?? ''}`.trim()} />
96
+ </span>
97
+ {cardActions && <span className="flex items-center gap-1 opacity-0 transition-opacity group-hover:opacity-100 focus-within:opacity-100">{cardActions(card)}</span>}
98
+ </div>
99
+ </li>
100
+ ))}
101
+ {!list.length && <li className="kol-sans-body-03 text-meta">{empty}</li>}
102
+ </ul>
103
+ </section>
104
+ )
105
+ })}
106
+ </div>
107
+ {footer}
108
+ </div>
109
+ )
110
+ }
@@ -0,0 +1,54 @@
1
+ import { useState } from 'react'
2
+ import Button from '../atoms/Button.jsx'
3
+
4
+ /* taxonomy-ok: organism — nests Button (atom, the drag handle); the items are the consumer's (`renderItem`). */
5
+
6
+ /**
7
+ * SortableGrid — A grid of cards reordered by drag. record's Projects grid (DocumentLibraryAndBoardParts, kol-website
8
+ * 2026-10-29): `auto-fill` tracks at least `min` wide, each item dragged by its handle onto another to take its place.
9
+ * The handle is a button, so a keyboard reorders too — ← ↑ one back, → ↓ one on. The item's wrapper wears
10
+ * `is-dragging` and `is-drop-target` (kol-theme `.kol-sortable-item`).
11
+ *
12
+ * @param {Array} items
13
+ * @param {Function} getId (item) => key (default `item.id`)
14
+ * @param {Function} renderItem (item, { handle, dragging, dropTarget, index }) => node — put `handle` where the grip goes
15
+ * @param {Function} onReorder (from, to) => void — indexes into `items`
16
+ * @param {number} min the smallest track, px (default 280, record's)
17
+ */
18
+ const TYPE = 'application/x-kol-sortable'
19
+
20
+ export default function SortableGrid({ items = [], getId = (it) => it.id, renderItem, onReorder, min = 280, className = '' }) {
21
+ const [drag, setDrag] = useState(null)
22
+ const [target, setTarget] = useState(null)
23
+ const end = () => { setDrag(null); setTarget(null) }
24
+ const move = (from, to) => { if (to >= 0 && to < items.length && to !== from) onReorder?.(from, to) }
25
+ return (
26
+ <div className={`kol-sortable-grid ${className}`.trim()} style={{ '--kol-sortable-min': `${min}px` }}>
27
+ {items.map((item, i) => {
28
+ const handle = onReorder ? (
29
+ <Button
30
+ variant="nav" size="sm" iconOnly="drag-handle" aria-label="Drag to reorder"
31
+ className="kol-sortable-handle"
32
+ draggable
33
+ onDragStart={(e) => { e.dataTransfer.setData(TYPE, String(i)); e.dataTransfer.effectAllowed = 'move'; setDrag(i) }}
34
+ onDragEnd={end}
35
+ onKeyDown={(e) => {
36
+ if (e.key === 'ArrowLeft' || e.key === 'ArrowUp') { e.preventDefault(); move(i, i - 1) }
37
+ if (e.key === 'ArrowRight' || e.key === 'ArrowDown') { e.preventDefault(); move(i, i + 1) }
38
+ }}
39
+ />
40
+ ) : null
41
+ return (
42
+ <div
43
+ key={getId(item)}
44
+ className={`kol-sortable-item${drag === i ? ' is-dragging' : ''}${target === i && drag !== i ? ' is-drop-target' : ''}`}
45
+ onDragOver={(e) => { if (!e.dataTransfer.types.includes(TYPE)) return; e.preventDefault(); if (target !== i) setTarget(i) }}
46
+ onDrop={(e) => { const from = Number(e.dataTransfer.getData(TYPE)); e.preventDefault(); end(); if (!Number.isNaN(from)) move(from, i) }}
47
+ >
48
+ {renderItem?.(item, { handle, dragging: drag === i, dropTarget: target === i && drag !== i, index: i })}
49
+ </div>
50
+ )
51
+ })}
52
+ </div>
53
+ )
54
+ }
@@ -0,0 +1,54 @@
1
+ import { useState } from 'react'
2
+
3
+ /**
4
+ * FlipCard — A face that turns to show its back. A face that turns over in place to show its back. Born in kol-hardware's
5
+ * frames (2026-09-27, kol-mirror's channel flip); moved here for record's project cards (DocumentLibraryAndBoardParts,
6
+ * kol-website 2026-10-29 — *"DASHBOARD NEEDS TO CONSUME DS COMPONENTS"*), and kol-hardware re-exports it. The body
7
+ * turns; everything around it holds still, so the back is the same shaped object as the front.
8
+ *
9
+ * THE FACES SWAP BY BACKFACE, NOT BY A CLOCK (FlipCardFaceSwap, kol-monitor 2026-10-24 — user: *"the card flipps,
10
+ * but the image snaps in once its landed. not believable."*). Both faces hide their backface and the back is pre-rotated
11
+ * 180° in the preserve-3d turner, so the back shows exactly as the card passes edge-on, whatever the easing. The face
12
+ * that is away is `inert` (and aria-hidden): out of tab order.
13
+ *
14
+ * TWO SHAPES. Without `height` the front sets the card's size and the back lies over it, scrolling what does not fit
15
+ * (mirror's strip). With `height` the card is a fixed tile and each face scrolls its own overflow (record's 240 card).
16
+ *
17
+ * @param {boolean} flipped controlled; omit it and the card keeps its own (`defaultFlipped`)
18
+ * @param {Function} onFlippedChange (flipped) => void
19
+ * @param {ReactNode|Function} front · back a node, or `({ flipped, flip, setFlipped }) => node` — a face's own
20
+ * button turns the card ("Details →", "‹ Back")
21
+ * @param {number|string} width the card's width
22
+ * @param {number|string} height a fixed height (record's 240); omitted, the front's height
23
+ * @param {number} duration ms (default 450, mirror's)
24
+ */
25
+ export default function FlipCard({ flipped: flippedProp, defaultFlipped = false, onFlippedChange, front, back, width, height, duration = 450, className = '' }) {
26
+ const [own, setOwn] = useState(defaultFlipped)
27
+ const flipped = flippedProp ?? own
28
+ const setFlipped = (v) => {
29
+ const next = typeof v === 'function' ? v(flipped) : v
30
+ if (flippedProp === undefined) setOwn(next)
31
+ onFlippedChange?.(next)
32
+ }
33
+ const api = { flipped, flip: () => setFlipped(!flipped), setFlipped }
34
+ const face = (f) => (typeof f === 'function' ? f(api) : f)
35
+ const hidden = { backfaceVisibility: 'hidden', WebkitBackfaceVisibility: 'hidden' }
36
+ const fixed = height != null
37
+ const scroll = { overflowY: 'auto', scrollbarWidth: 'none' }
38
+ return (
39
+ <div className={className} style={{ perspective: 1400, position: 'relative', width, height }}>
40
+ <div style={{ transition: `transform ${duration}ms ease`, transformStyle: 'preserve-3d', transform: flipped ? 'rotateY(180deg)' : 'none', ...(fixed ? { position: 'relative', height: '100%' } : null) }}>
41
+ <div aria-hidden={flipped || undefined} inert={flipped || undefined} style={fixed ? { position: 'absolute', inset: 0, ...scroll, ...hidden } : hidden}>
42
+ {face(front)}
43
+ </div>
44
+ <div
45
+ aria-hidden={!flipped || undefined}
46
+ inert={!flipped || undefined}
47
+ style={{ position: 'absolute', inset: 0, transform: 'rotateY(180deg)', ...scroll, ...hidden }}
48
+ >
49
+ {face(back)}
50
+ </div>
51
+ </div>
52
+ </div>
53
+ )
54
+ }
@@ -0,0 +1,9 @@
1
+ /* formatAge — how long ago, in the fewest characters: `now` under an hour, `5h` under a day, `3d` after. record's board
2
+ * reads a card's time in its column this way (DocumentLibraryAndBoardParts, kol-website 2026-10-29). '' for no time. */
3
+ export default function formatAge(ms, now = Date.now()) {
4
+ if (!ms) return ''
5
+ const d = now - ms
6
+ if (d < 36e5) return 'now'
7
+ if (d < 864e5) return `${Math.floor(d / 36e5)}h`
8
+ return `${Math.floor(d / 864e5)}d`
9
+ }