@kolkrabbi/kol-component 0.288.0 → 0.290.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 +1 -1
- package/src/index.js +2 -0
- package/src/molecules/ColorRamp.jsx +11 -5
- package/src/molecules/ContentCard.jsx +18 -1
- package/src/molecules/ContentRow.jsx +1 -1
- package/src/molecules/TextFold.jsx +39 -0
- package/src/organisms/GalleryCarousel.jsx +6 -4
- package/src/organisms/MediaGalleryModes.jsx +52 -0
- package/src/organisms/MediaTileGallery.jsx +12 -9
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -103,6 +103,7 @@ export { default as SectionCardItem, default as CardFeatureItem } from './molecu
|
|
|
103
103
|
export { default as CodeBlock } from './molecules/CodeBlock.jsx'
|
|
104
104
|
export { default as ColorInputRow } from './molecules/ColorInputRow.jsx'
|
|
105
105
|
export { default as ColorRamp } from './molecules/ColorRamp.jsx'
|
|
106
|
+
export { default as TextFold } from './molecules/TextFold.jsx'
|
|
106
107
|
export { default as ColorSwatch } from './molecules/ColorSwatch.jsx'
|
|
107
108
|
export { default as Dropdown } from './molecules/Dropdown.jsx'
|
|
108
109
|
/* MultiSelect — several pick-one settings in one dropdown, a column each (2026-10-01, first cut) */
|
|
@@ -197,6 +198,7 @@ export { default as MediaLibrary, MediaLibraryProvider, useMediaLibrary, MediaPi
|
|
|
197
198
|
export { MediaInspector, mediaSettingsSections, SETTINGS_BASE as MEDIA_SETTINGS_BASE } from './organisms/MediaLibraryPages.jsx'
|
|
198
199
|
export { default as MediaLibraryExplorer } from './organisms/MediaLibraryExplorer.jsx'
|
|
199
200
|
export { default as MediaTileGallery } from './organisms/MediaTileGallery.jsx'
|
|
201
|
+
export { default as MediaGalleryModes } from './organisms/MediaGalleryModes.jsx'
|
|
200
202
|
export { default as MediaViewer } from './organisms/MediaViewer.jsx'
|
|
201
203
|
export { default as SettingsPanel, LabeledControlSection, SettingsRow, SettingsSwitch, SettingsChoice, SettingsMulti, SettingsChipRow, SettingsFooter } from './organisms/SettingsPanel.jsx'
|
|
202
204
|
/* the settings BODY as data — one call for the page, the drawer and a sheet
|
|
@@ -86,13 +86,19 @@ export default function ColorRamp({
|
|
|
86
86
|
{note && <span className="kol-mono-12 text-meta italic max-w-[60ch] text-right">{note}</span>}
|
|
87
87
|
</div>
|
|
88
88
|
)}
|
|
89
|
-
|
|
89
|
+
{/* narrow widths (ColorRampNarrowCaptions, kol-branding 2026-10-22): a 10-step ramp at 390 gave
|
|
90
|
+
* ~30px columns its captions ran out of and the page scrolled sideways. Below sm it wraps to
|
|
91
|
+
* five a row, and a caption truncates inside its column instead of widening it. */}
|
|
92
|
+
<div
|
|
93
|
+
className="grid gap-2 grid-cols-[repeat(var(--ramp-cols-narrow),minmax(0,1fr))] sm:grid-cols-[repeat(var(--ramp-cols),minmax(0,1fr))]"
|
|
94
|
+
style={{ '--ramp-cols': cols, '--ramp-cols-narrow': Math.min(cols, 5) }}
|
|
95
|
+
>
|
|
90
96
|
{chips.map((c, i) => {
|
|
91
97
|
const value = c.literal ?? values[c.key] ?? ''
|
|
92
98
|
const fill = c.literal ?? `var(${c.token})`
|
|
93
99
|
const isAnchor = anchor != null && (anchor === c.stop || anchor === c.name || anchor === i)
|
|
94
100
|
return (
|
|
95
|
-
<div key={c.key} className="flex flex-col gap-1.5">
|
|
101
|
+
<div key={c.key} className="flex min-w-0 flex-col gap-1.5">
|
|
96
102
|
<div className="relative">
|
|
97
103
|
<ColorSwatch hex={fill} size="fill" radius="sm" title={`${c.name} ${value}`} />
|
|
98
104
|
{isAnchor && value && (
|
|
@@ -101,9 +107,9 @@ export default function ColorRamp({
|
|
|
101
107
|
</span>
|
|
102
108
|
)}
|
|
103
109
|
</div>
|
|
104
|
-
<div className="flex flex-col items-start gap-0.5 leading-tight">
|
|
105
|
-
<span className="kol-helper-10 text-emphasis">{c.name}{isAnchor && ' ★'}</span>
|
|
106
|
-
<span className="kol-helper-10 text-meta">{value}</span>
|
|
110
|
+
<div className="flex min-w-0 flex-col items-start gap-0.5 leading-tight">
|
|
111
|
+
<span className="kol-helper-10 text-emphasis max-w-full truncate">{c.name}{isAnchor && ' ★'}</span>
|
|
112
|
+
<span className="kol-helper-10 text-meta max-w-full truncate">{value}</span>
|
|
107
113
|
</div>
|
|
108
114
|
</div>
|
|
109
115
|
)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useLayoutEffect, useRef, useState } from 'react'
|
|
1
2
|
import ContentMedia from './ContentMedia.jsx'
|
|
2
3
|
import ContentText from './ContentText.jsx'
|
|
3
4
|
import { toneClass } from '../utilities/tone.js'
|
|
@@ -240,6 +241,20 @@ export default function ContentCard({
|
|
|
240
241
|
* left, instead of bottom-right (the 2026-08-15 ruling). Block from the
|
|
241
242
|
* first value, inline from the second (or the same one). */
|
|
242
243
|
const [padBlock, padInline = padBlock] = String(padding ?? '0').trim().split(/\s+/)
|
|
244
|
+
/* the copy stops BEFORE the actions (FileCardTitleClearsActions, kol-fxr 2026-10-22): they are
|
|
245
|
+
* absolute, so the text column spanned the plate and a long title's ellipsis landed under the cog.
|
|
246
|
+
* Their measured width (+ one pad) is reserved on the text side, so `truncate` ends left of them. */
|
|
247
|
+
const actionsRef = useRef(null)
|
|
248
|
+
const [actionsW, setActionsW] = useState(0)
|
|
249
|
+
useLayoutEffect(() => {
|
|
250
|
+
const el = actionsRef.current
|
|
251
|
+
if (!el) { setActionsW(0); return undefined }
|
|
252
|
+
const measure = () => setActionsW(el.offsetWidth)
|
|
253
|
+
measure()
|
|
254
|
+
const ro = new ResizeObserver(measure)
|
|
255
|
+
ro.observe(el)
|
|
256
|
+
return () => ro.disconnect()
|
|
257
|
+
}, [actions != null])
|
|
243
258
|
/* image-only cards (print) pass no text slots — the empty plate must not render */
|
|
244
259
|
const hasText = ['title', 'body', 'kicker', 'detail', 'date', 'size', 'meta', 'tags'].some((k) => textSlots[k] != null)
|
|
245
260
|
/* `actions` sit IN THE TEXT PLATE, bottom-right (user ruling 2026-08-15:
|
|
@@ -280,6 +295,7 @@ export default function ContentCard({
|
|
|
280
295
|
className="kol-card-plate relative"
|
|
281
296
|
style={{
|
|
282
297
|
'--kol-plate-pad': padding,
|
|
298
|
+
'--kol-plate-actions-w': actionsW ? `calc(${actionsW}px + ${padInline})` : undefined,
|
|
283
299
|
'--kol-plate-pad-md': box.padMd,
|
|
284
300
|
padding,
|
|
285
301
|
/* a fill-card with no cover keeps its frame and its plate keeps the FOOT — dropping the media
|
|
@@ -293,13 +309,14 @@ export default function ContentCard({
|
|
|
293
309
|
zIndex: box.layout === 'canvas' ? 1 : undefined,
|
|
294
310
|
}}
|
|
295
311
|
>
|
|
296
|
-
{hasText && <ContentText variant={variant} form={isHero ? 'hero' : 'card'} tagVariant={tagVariant ?? (/surface-/.test(ground ?? '') ? 'tertiary' : 'primary')} {...textSlots} />}
|
|
312
|
+
{hasText && <ContentText variant={variant} form={isHero ? 'hero' : 'card'} className={actionsW ? 'min-w-0 pr-[var(--kol-plate-actions-w)]' : ''} tagVariant={tagVariant ?? (/surface-/.test(ground ?? '') ? 'tertiary' : 'primary')} {...textSlots} />}
|
|
297
313
|
{/* ABSOLUTE, not a flex sibling: the plate's height moves with the title
|
|
298
314
|
* and the meta, so a laid-out stack would stretch or drift with it. The
|
|
299
315
|
* inset reads the SAME pad token the plate uses, so the icons sit the
|
|
300
316
|
* same distance from the top and right edges as the copy does. */}
|
|
301
317
|
{actions && (
|
|
302
318
|
<div
|
|
319
|
+
ref={actionsRef}
|
|
303
320
|
className="absolute flex"
|
|
304
321
|
style={{ top: padBlock, bottom: padBlock, right: padInline }}
|
|
305
322
|
>
|
|
@@ -305,7 +305,7 @@ export default function ContentRow({
|
|
|
305
305
|
<div className="flex flex-1 min-w-0 items-stretch" style={{ padding: box.plate, gap: box.plateGap ?? box.plate }}>
|
|
306
306
|
{/* the meta line's leading is its type size, so its baseline lands on the bottom pad, level with the last
|
|
307
307
|
* control — at its 16px line the digits sat ~4px above it (user 2026-10-22) */}
|
|
308
|
-
<ContentText variant={variant} form="row" className="flex-1 justify-between [&_.kol-mono-12]:leading-none" tagVariant={tagVariant ?? (/surface-/.test(ground ?? '') ? 'tertiary' : 'primary')} {...text} />
|
|
308
|
+
<ContentText variant={variant} form="row" className="min-w-0 flex-1 justify-between [&_.kol-mono-12]:leading-none" tagVariant={tagVariant ?? (/surface-/.test(ground ?? '') ? 'tertiary' : 'primary')} {...text} />
|
|
309
309
|
{actions && <div className="shrink-0">{actions}</div>}
|
|
310
310
|
</div>
|
|
311
311
|
) : (
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { useLayoutEffect, useRef, useState } from 'react'
|
|
2
|
+
import Button from '../atoms/Button.jsx'
|
|
3
|
+
|
|
4
|
+
/* literal classes — a runtime-built `line-clamp-${n}` is never emitted */
|
|
5
|
+
const CLAMP = { 2: 'max-md:line-clamp-2', 3: 'max-md:line-clamp-3', 4: 'max-md:line-clamp-4', 6: 'max-md:line-clamp-6' }
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* TextFold — Long text folded to a few lines on phones. (TextFold, kol-branding 2026-10-22 — the
|
|
9
|
+
* user: *"on mobile text heavy blocks are not always relevant but good to know more information
|
|
10
|
+
* is there if you want it"*.) Below md the text clamps to `lines` with a More / Less ghost button;
|
|
11
|
+
* md and up shows it whole. The button only appears when the text is actually cut — measured,
|
|
12
|
+
* so text that fits shows nothing.
|
|
13
|
+
*
|
|
14
|
+
* @param {2|3|4|6} lines lines shown while folded (default 4)
|
|
15
|
+
* @param {string} as the text element (default `div`)
|
|
16
|
+
* @param {string} moreLabel · lessLabel the toggle's words, as authored (default More · Less)
|
|
17
|
+
* @param {string} className the text's own type classes
|
|
18
|
+
*/
|
|
19
|
+
export default function TextFold({ lines = 4, as: Tag = 'div', moreLabel = 'More', lessLabel = 'Less', className = '', children }) {
|
|
20
|
+
const ref = useRef(null)
|
|
21
|
+
const [open, setOpen] = useState(false)
|
|
22
|
+
const [cut, setCut] = useState(false)
|
|
23
|
+
useLayoutEffect(() => {
|
|
24
|
+
const el = ref.current
|
|
25
|
+
const measure = () => setCut(el.scrollHeight > el.clientHeight + 1)
|
|
26
|
+
measure()
|
|
27
|
+
const ro = new ResizeObserver(measure)
|
|
28
|
+
ro.observe(el)
|
|
29
|
+
return () => ro.disconnect()
|
|
30
|
+
}, [])
|
|
31
|
+
return (
|
|
32
|
+
<div className="flex min-w-0 flex-col items-start gap-1">
|
|
33
|
+
<Tag ref={ref} className={`w-full min-w-0 break-words ${open ? '' : CLAMP[lines] ?? CLAMP[4]} ${className}`.trim()}>{children}</Tag>
|
|
34
|
+
{(cut || open) && (
|
|
35
|
+
<Button tone="ghost" size="sm" className="md:hidden" onClick={() => setOpen(!open)}>{open ? lessLabel : moreLabel}</Button>
|
|
36
|
+
)}
|
|
37
|
+
</div>
|
|
38
|
+
)
|
|
39
|
+
}
|
|
@@ -29,8 +29,10 @@ const DRAG_THRESHOLD_SQ = 25
|
|
|
29
29
|
* @param {string} title alt-text fallback (`${title} ${i+1}`)
|
|
30
30
|
* @param {number} defaultAspect tile aspect when an item omits `aspect` (default 0.8)
|
|
31
31
|
* @param {string} className extra classes on the section
|
|
32
|
+
* @param {Function} onOpen `(index) => void` — a host that owns the viewer (MediaGalleryModes)
|
|
33
|
+
* takes the click; the carousel then draws no viewer of its own
|
|
32
34
|
*/
|
|
33
|
-
export default function GalleryCarousel({ media = [], title = '', defaultAspect = 0.8, className = '' }) {
|
|
35
|
+
export default function GalleryCarousel({ media = [], title = '', defaultAspect = 0.8, className = '', onOpen }) {
|
|
34
36
|
const [viewerIndex, setViewerIndex] = useState(null)
|
|
35
37
|
const pointerStart = useRef({ x: 0, y: 0 })
|
|
36
38
|
const dragged = useRef(false)
|
|
@@ -60,7 +62,7 @@ export default function GalleryCarousel({ media = [], title = '', defaultAspect
|
|
|
60
62
|
style={{ aspectRatio: aspect }}
|
|
61
63
|
onPointerDown={onPointerDown}
|
|
62
64
|
onPointerMove={onPointerMove}
|
|
63
|
-
onClick={() => { if (!dragged.current) setViewerIndex(i) }}
|
|
65
|
+
onClick={() => { if (!dragged.current) (onOpen ?? setViewerIndex)(i) }}
|
|
64
66
|
>
|
|
65
67
|
{item.kind === 'video' ? (
|
|
66
68
|
<video src={item.url} autoPlay muted playsInline loop className="w-full h-full object-cover" />
|
|
@@ -72,13 +74,13 @@ export default function GalleryCarousel({ media = [], title = '', defaultAspect
|
|
|
72
74
|
})}
|
|
73
75
|
</Carousel>
|
|
74
76
|
|
|
75
|
-
<MediaViewer
|
|
77
|
+
{!onOpen && <MediaViewer
|
|
76
78
|
open={viewerIndex !== null}
|
|
77
79
|
media={media}
|
|
78
80
|
index={viewerIndex ?? 0}
|
|
79
81
|
onIndexChange={setViewerIndex}
|
|
80
82
|
onClose={() => setViewerIndex(null)}
|
|
81
|
-
/>
|
|
83
|
+
/>}
|
|
82
84
|
</section>
|
|
83
85
|
)
|
|
84
86
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { useState } from 'react'
|
|
2
|
+
import SegmentedToggle from '../atoms/SegmentedToggle.jsx'
|
|
3
|
+
import GalleryCarousel from './GalleryCarousel.jsx'
|
|
4
|
+
import MediaTileGallery from './MediaTileGallery.jsx'
|
|
5
|
+
import MediaViewer from './MediaViewer.jsx'
|
|
6
|
+
|
|
7
|
+
const LABELS = { carousel: 'Carousel', grid: 'Grid', waterfall: 'Waterfall' }
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* MediaGalleryModes — One media set, three ways to look at it. (MediaGalleryModes, kol-branding
|
|
11
|
+
* 2026-10-21 — the user: *"a carousel is a nice viewing experience, unless you are looking for
|
|
12
|
+
* specific thing, then you might wanna grid or waterfall the images"*.) The viewer switches
|
|
13
|
+
* carousel (`GalleryCarousel`) · grid · waterfall (`MediaTileGallery`); any item opens the one
|
|
14
|
+
* `MediaViewer` here, paged across the whole set, so the item last opened survives a mode change.
|
|
15
|
+
*
|
|
16
|
+
* @param {Array} items [{ url, kind?: 'image'|'video', alt?, caption?, aspect? }]
|
|
17
|
+
* @param {string[]} modes which modes are offered (default all three); one hides the switch
|
|
18
|
+
* @param {string} mode · defaultMode · onModeChange controlled or uncontrolled (default carousel)
|
|
19
|
+
* @param {number} cols grid + waterfall columns from sm up (default 3); two below
|
|
20
|
+
* @param {string} title the header label, and the alt fallback
|
|
21
|
+
*/
|
|
22
|
+
export default function MediaGalleryModes({
|
|
23
|
+
items = [], modes = ['carousel', 'grid', 'waterfall'], mode: modeProp, defaultMode, onModeChange,
|
|
24
|
+
cols = 3, title, className = '',
|
|
25
|
+
}) {
|
|
26
|
+
const [own, setOwn] = useState(defaultMode ?? modes[0])
|
|
27
|
+
const mode = modeProp ?? own
|
|
28
|
+
const setMode = (m) => { setOwn(m); onModeChange?.(m) }
|
|
29
|
+
const [open, setOpen] = useState(false)
|
|
30
|
+
const [index, setIndex] = useState(0)
|
|
31
|
+
const show = (i) => { setIndex(i); setOpen(true) }
|
|
32
|
+
|
|
33
|
+
if (!items.length) return null
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<section className={`flex flex-col gap-4 ${className}`.trim()}>
|
|
37
|
+
{(title || modes.length > 1) && (
|
|
38
|
+
<div className="flex items-center justify-between gap-4">
|
|
39
|
+
{title ? <span className="kol-helper-12 text-meta">{title}</span> : <span />}
|
|
40
|
+
{modes.length > 1 && (
|
|
41
|
+
<SegmentedToggle size="sm" ariaLabel="View" value={mode} onChange={setMode}
|
|
42
|
+
options={modes.map((m) => ({ value: m, label: LABELS[m] }))} />
|
|
43
|
+
)}
|
|
44
|
+
</div>
|
|
45
|
+
)}
|
|
46
|
+
{mode === 'carousel'
|
|
47
|
+
? <GalleryCarousel media={items} title={title} onOpen={show} />
|
|
48
|
+
: <MediaTileGallery items={items} layout={mode} cols={cols} onOpen={show} />}
|
|
49
|
+
<MediaViewer open={open} media={items} index={index} onIndexChange={setIndex} onClose={() => setOpen(false)} />
|
|
50
|
+
</section>
|
|
51
|
+
)
|
|
52
|
+
}
|
|
@@ -12,16 +12,19 @@ import MediaViewer from './MediaViewer.jsx'
|
|
|
12
12
|
* render verbatim — authored case, no auto-casing.
|
|
13
13
|
*
|
|
14
14
|
* @param {Array} items [{ url, alt?, kind?: 'image' | 'video', caption? }] — the viewer's media shape
|
|
15
|
-
* @param {string} layout 'stack' (flow column, default) | 'grid'
|
|
16
|
-
*
|
|
15
|
+
* @param {string} layout 'stack' (flow column, default) | 'grid' | 'waterfall' — CSS columns, each
|
|
16
|
+
* item at its own aspect, no crop (MediaGalleryModes, kol-branding 2026-10-21)
|
|
17
|
+
* @param {number} cols column count from sm up (grid · waterfall); two below sm
|
|
18
|
+
* @param {Function} onOpen `(index) => void` — a host that owns the viewer takes the click; no viewer here then
|
|
17
19
|
* @param {string} tileClassName extra classes merged onto each tile button
|
|
18
20
|
*/
|
|
19
|
-
export default function MediaTileGallery({ items = [], layout = 'stack', cols = 4, tileClassName = '' }) {
|
|
21
|
+
export default function MediaTileGallery({ items = [], layout = 'stack', cols = 4, tileClassName = '', onOpen }) {
|
|
20
22
|
const [current, setCurrent] = useState(null)
|
|
21
23
|
|
|
22
24
|
if (!items.length) return null
|
|
23
25
|
|
|
24
26
|
const isGrid = layout === 'grid'
|
|
27
|
+
const isFall = layout === 'waterfall'
|
|
25
28
|
|
|
26
29
|
return (
|
|
27
30
|
<>
|
|
@@ -29,15 +32,15 @@ export default function MediaTileGallery({ items = [], layout = 'stack', cols =
|
|
|
29
32
|
* grid collapse is canonical, first break sm). The count rides a variable so the theme's one
|
|
30
33
|
* phone rule can override it: an inline `gridTemplateColumns` could not be out-ranked. */}
|
|
31
34
|
<div
|
|
32
|
-
className={isGrid ? 'kol-media-tiles grid gap-4' : 'flex flex-col gap-4'}
|
|
33
|
-
style={isGrid ? { '--kol-media-tiles-cols': cols } : undefined}
|
|
35
|
+
className={isGrid ? 'kol-media-tiles grid gap-4' : isFall ? 'columns-2 gap-4 sm:[column-count:var(--kol-media-tiles-cols)]' : 'flex flex-col gap-4'}
|
|
36
|
+
style={isGrid || isFall ? { '--kol-media-tiles-cols': cols } : undefined}
|
|
34
37
|
>
|
|
35
38
|
{items.map((item, i) => (
|
|
36
|
-
<figure key={i} className=
|
|
39
|
+
<figure key={i} className={isFall ? 'mb-4 min-w-0 break-inside-avoid' : 'min-w-0'}>
|
|
37
40
|
<button
|
|
38
41
|
type="button"
|
|
39
42
|
className={`block w-full cursor-zoom-in overflow-hidden rounded border border-fg-08 bg-fg-04 ${tileClassName}`.trim()}
|
|
40
|
-
onClick={() => setCurrent(i)}
|
|
43
|
+
onClick={() => (onOpen ?? setCurrent)(i)}
|
|
41
44
|
>
|
|
42
45
|
<img src={item.url} alt={item.alt || ''} loading="lazy" className="block h-auto w-full" />
|
|
43
46
|
</button>
|
|
@@ -48,13 +51,13 @@ export default function MediaTileGallery({ items = [], layout = 'stack', cols =
|
|
|
48
51
|
))}
|
|
49
52
|
</div>
|
|
50
53
|
|
|
51
|
-
<MediaViewer
|
|
54
|
+
{!onOpen && <MediaViewer
|
|
52
55
|
open={current != null}
|
|
53
56
|
media={items}
|
|
54
57
|
index={current ?? 0}
|
|
55
58
|
onIndexChange={setCurrent}
|
|
56
59
|
onClose={() => setCurrent(null)}
|
|
57
|
-
/>
|
|
60
|
+
/>}
|
|
58
61
|
</>
|
|
59
62
|
)
|
|
60
63
|
}
|