@kolkrabbi/kol-component 0.287.0 → 0.289.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 +3 -3
- package/src/index.js +2 -0
- package/src/molecules/ColorRamp.jsx +11 -5
- package/src/molecules/ContentCard.jsx +11 -5
- package/src/molecules/ContentRow.jsx +13 -6
- package/src/molecules/MenuItem.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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kolkrabbi/kol-component",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.289.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-
|
|
30
|
-
"@kolkrabbi/kol-
|
|
29
|
+
"@kolkrabbi/kol-markdown": "^0.1.3",
|
|
30
|
+
"@kolkrabbi/kol-search": "^0.3.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"@kolkrabbi/kol-icons": ">=0.22.0",
|
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,5 +1,6 @@
|
|
|
1
1
|
import ContentMedia from './ContentMedia.jsx'
|
|
2
2
|
import ContentText from './ContentText.jsx'
|
|
3
|
+
import { toneClass } from '../utilities/tone.js'
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* ContentCard — the card form of the content-card system. Variants differ in
|
|
@@ -179,6 +180,10 @@ export default function ContentCard({
|
|
|
179
180
|
* move together. For the card's INK, pass `text` — it falls through to
|
|
180
181
|
* ContentText with the rest of the slots. */
|
|
181
182
|
bg,
|
|
183
|
+
/* `tone` — the ground from the control set's tone ladder (ContentCardRowTone, kol-fxr 2026-10-22):
|
|
184
|
+
* the rest fill AND its hover step from one `kol-tone-*` bundle, so they move together. `bg`
|
|
185
|
+
* still wins the rest fill when both are passed. Unset → the variant's own ground. */
|
|
186
|
+
tone,
|
|
182
187
|
control,
|
|
183
188
|
controlStart,
|
|
184
189
|
reveal,
|
|
@@ -203,6 +208,7 @@ export default function ContentCard({
|
|
|
203
208
|
* escape hatch that would let any variant borrow another's box. */
|
|
204
209
|
const variant = aliased.startsWith('showcase') && layout ? LAYOUT_KEY[layout] ?? aliased : aliased
|
|
205
210
|
const box = BOX[variant] ?? BOX.file
|
|
211
|
+
const ground = bg ?? (tone ? 'var(--kol-tone-bg)' : box.bg)
|
|
206
212
|
const doFlip = flip ?? box.flip
|
|
207
213
|
/* HERO (2026-08-27 — the featured card riding a page's fold; ListingCard
|
|
208
214
|
* size="hero" had no ContentCard equivalent, which is why Stack still
|
|
@@ -250,7 +256,7 @@ export default function ContentCard({
|
|
|
250
256
|
* true: a rounded still floating inside a square grey card, plate corners
|
|
251
257
|
* square (kol-client-hrafn, screenshot-confirmed on 0.183.0, fixed 0.183.1).
|
|
252
258
|
* One prop is not done until every derivation reads it. */
|
|
253
|
-
const framed = box.border != null ||
|
|
259
|
+
const framed = box.border != null || ground != null
|
|
254
260
|
|
|
255
261
|
/* NO COVER IS NOT A MISSING COVER (content-card-needs-no-cover,
|
|
256
262
|
* kol-client-olina 2026-09-04). `ContentMedia` turns absent children into an
|
|
@@ -287,7 +293,7 @@ export default function ContentCard({
|
|
|
287
293
|
zIndex: box.layout === 'canvas' ? 1 : undefined,
|
|
288
294
|
}}
|
|
289
295
|
>
|
|
290
|
-
{hasText && <ContentText variant={variant} form={isHero ? 'hero' : 'card'} tagVariant={tagVariant ?? (/surface-/.test(
|
|
296
|
+
{hasText && <ContentText variant={variant} form={isHero ? 'hero' : 'card'} tagVariant={tagVariant ?? (/surface-/.test(ground ?? '') ? 'tertiary' : 'primary')} {...textSlots} />}
|
|
291
297
|
{/* ABSOLUTE, not a flex sibling: the plate's height moves with the title
|
|
292
298
|
* and the meta, so a laid-out stack would stretch or drift with it. The
|
|
293
299
|
* inset reads the SAME pad token the plate uses, so the icons sit the
|
|
@@ -436,16 +442,16 @@ export default function ContentCard({
|
|
|
436
442
|
if (onClick) onClick(event)
|
|
437
443
|
}
|
|
438
444
|
const interactive = href || onClick
|
|
439
|
-
const hoverBg = HOVER[variant]
|
|
445
|
+
const hoverBg = tone ? 'var(--kol-tone-hover-bg)' : HOVER[variant]
|
|
440
446
|
|
|
441
447
|
const common = {
|
|
442
448
|
'data-tags': isHero && Array.isArray(text.tags) && text.tags.length ? text.tags.join(' ') : undefined,
|
|
443
|
-
className: `kol-card group flex ${box.layout === 'canvas' && reveal != null ? 'has-reveal' : ''} ${expanded ? 'flex-col md:flex-row-reverse' : 'flex-col'} ${box.layout === 'drawer' ? 'relative overflow-hidden rounded-[var(--kol-radius-sm)]' : ''} ${framed ? 'overflow-hidden rounded-[var(--kol-radius-sm)]' : ''} ${box.border ? 'border' : ''} ${box.layout === 'canvas' ? 'relative' : ''} ${interactive ? 'cursor-pointer select-none' : ''} ${hoverBg && interactive ? 'kol-content-hover' : ''} ${interactive && box.frameHover ? 'kol-content-hover-frame' : ''} ${className}`.trim(),
|
|
449
|
+
className: `kol-card group flex ${toneClass(tone)} ${box.layout === 'canvas' && reveal != null ? 'has-reveal' : ''} ${expanded ? 'flex-col md:flex-row-reverse' : 'flex-col'} ${box.layout === 'drawer' ? 'relative overflow-hidden rounded-[var(--kol-radius-sm)]' : ''} ${framed ? 'overflow-hidden rounded-[var(--kol-radius-sm)]' : ''} ${box.border ? 'border' : ''} ${box.layout === 'canvas' ? 'relative' : ''} ${interactive ? 'cursor-pointer select-none' : ''} ${hoverBg && interactive ? 'kol-content-hover' : ''} ${interactive && box.frameHover ? 'kol-content-hover-frame' : ''} ${className}`.trim(),
|
|
444
450
|
style: {
|
|
445
451
|
/* same reason as ContentRow: rest colors are PROPERTIES, because an
|
|
446
452
|
* inline background/borderColor outranks the hover class and the step
|
|
447
453
|
* would never render. */
|
|
448
|
-
'--kol-card-bg':
|
|
454
|
+
'--kol-card-bg': ground ?? undefined,
|
|
449
455
|
'--kol-card-border': box.border ? (selected ? 'var(--kol-fg-64)' : box.border) : undefined,
|
|
450
456
|
'--kol-content-hover-bg': hoverBg ?? undefined,
|
|
451
457
|
'--kol-content-hover-border': box.frameHover ?? undefined,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import ContentMedia from './ContentMedia.jsx'
|
|
2
2
|
import ContentText from './ContentText.jsx'
|
|
3
|
+
import { toneClass } from '../utilities/tone.js'
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* ContentRow — The row form of a content card. the row form of the content-card system: leading thumb (where
|
|
@@ -183,12 +184,18 @@ export default function ContentRow({
|
|
|
183
184
|
* a selected row is the list's state, not the consumer's ground. For the
|
|
184
185
|
* row's INK, pass `text` — it falls through to ContentText. */
|
|
185
186
|
bg,
|
|
187
|
+
/* `tone` — the ground from the control set's tone ladder (ContentCardRowTone, kol-fxr 2026-10-22):
|
|
188
|
+
* the rest fill AND its hover step from one `kol-tone-*` bundle, so they move together. `bg`
|
|
189
|
+
* still wins the rest fill when both are passed. Unset → the variant's own ground. */
|
|
190
|
+
tone,
|
|
186
191
|
className = '',
|
|
187
192
|
...text
|
|
188
193
|
}) {
|
|
189
194
|
const aliased = ALIAS[variantProp] ?? variantProp
|
|
190
195
|
const variant = aliased.startsWith('showcase') && layout ? LAYOUT_KEY[layout] ?? aliased : aliased
|
|
191
196
|
const box = BOX[variant] ?? BOX.file
|
|
197
|
+
const ground = bg ?? (tone ? 'var(--kol-tone-bg)' : box.bg)
|
|
198
|
+
const hover = tone ? 'var(--kol-tone-hover-bg)' : box.hover
|
|
192
199
|
/* `media={false}` — NO COVER, not a missing one (content-card-needs-no-cover,
|
|
193
200
|
* kol-client-olina 2026-09-04). The row could already hide its thumb with
|
|
194
201
|
* `thumb={0}`, but that is a SIZE answering a question about MEANING, and a
|
|
@@ -240,12 +247,12 @@ export default function ContentRow({
|
|
|
240
247
|
* consumer setting it got no error and no change. Undefined publishes
|
|
241
248
|
* nothing and the CSS fallback keeps every current row square. */
|
|
242
249
|
'--kol-row-thumb-ratio': ratio ?? box.ratio,
|
|
243
|
-
'--kol-content-hover-bg':
|
|
250
|
+
'--kol-content-hover-bg': hover,
|
|
244
251
|
'--kol-content-hover-border': box.frameHover,
|
|
245
252
|
/* rest values are PROPERTIES, not inline declarations — an inline
|
|
246
253
|
* `background`/`borderColor` outranks every class, so the hover rules in
|
|
247
254
|
* kol-theme could never win and no row hover fired at all. */
|
|
248
|
-
'--kol-row-bg': selected ? 'var(--kol-fg-04)' :
|
|
255
|
+
'--kol-row-bg': selected ? 'var(--kol-fg-04)' : ground,
|
|
249
256
|
'--kol-row-border': box.frame || undefined,
|
|
250
257
|
}
|
|
251
258
|
|
|
@@ -260,7 +267,7 @@ export default function ContentRow({
|
|
|
260
267
|
* (a rendered alphabet, a waveform, a sparkline) is never the family's. */
|
|
261
268
|
const inner = box.column ? (
|
|
262
269
|
<>
|
|
263
|
-
<ContentText variant={variant} form="row" className="w-full" tagVariant={tagVariant ?? (/surface-/.test(
|
|
270
|
+
<ContentText variant={variant} form="row" className="w-full" tagVariant={tagVariant ?? (/surface-/.test(ground ?? '') ? 'tertiary' : 'primary')} {...text} />
|
|
264
271
|
{footer}
|
|
265
272
|
</>
|
|
266
273
|
) : (
|
|
@@ -298,11 +305,11 @@ export default function ContentRow({
|
|
|
298
305
|
<div className="flex flex-1 min-w-0 items-stretch" style={{ padding: box.plate, gap: box.plateGap ?? box.plate }}>
|
|
299
306
|
{/* the meta line's leading is its type size, so its baseline lands on the bottom pad, level with the last
|
|
300
307
|
* control — at its 16px line the digits sat ~4px above it (user 2026-10-22) */}
|
|
301
|
-
<ContentText variant={variant} form="row" className="flex-1 justify-between [&_.kol-mono-12]:leading-none" tagVariant={tagVariant ?? (/surface-/.test(
|
|
308
|
+
<ContentText variant={variant} form="row" className="flex-1 justify-between [&_.kol-mono-12]:leading-none" tagVariant={tagVariant ?? (/surface-/.test(ground ?? '') ? 'tertiary' : 'primary')} {...text} />
|
|
302
309
|
{actions && <div className="shrink-0">{actions}</div>}
|
|
303
310
|
</div>
|
|
304
311
|
) : (
|
|
305
|
-
<ContentText variant={variant} form="row" className={`flex-1 ${box.height != null ? 'py-[2px]' : ''}`.trim()} tagVariant={tagVariant ?? (/surface-/.test(
|
|
312
|
+
<ContentText variant={variant} form="row" className={`flex-1 ${box.height != null ? 'py-[2px]' : ''}`.trim()} tagVariant={tagVariant ?? (/surface-/.test(ground ?? '') ? 'tertiary' : 'primary')} {...text} />
|
|
306
313
|
)}
|
|
307
314
|
{/* `specs` rides the trailing edge on EVERY variant — year · material ·
|
|
308
315
|
* edition is a content difference, not a geometry one, and minting a
|
|
@@ -326,7 +333,7 @@ export default function ContentRow({
|
|
|
326
333
|
)
|
|
327
334
|
|
|
328
335
|
const common = {
|
|
329
|
-
className: `kol-row group flex ${box.column ? 'flex-col' : ''} ${box.align} ${box.height != null ? 'kol-row--fixed' : ''} ${box.heightSm != null ? 'kol-row--fixed-sm' : ''} ${box.divider ? 'kol-row--divided' : ''} ${box.frame ? 'rounded-[var(--kol-radius-sm)] border' : ''} ${box.clip ? 'overflow-hidden rounded-[var(--kol-radius-sm)]' : ''} ${interactive ? 'cursor-pointer select-none' : ''} ${interactive &&
|
|
336
|
+
className: `kol-row group flex ${toneClass(tone)} ${box.column ? 'flex-col' : ''} ${box.align} ${box.height != null ? 'kol-row--fixed' : ''} ${box.heightSm != null ? 'kol-row--fixed-sm' : ''} ${box.divider ? 'kol-row--divided' : ''} ${box.frame ? 'rounded-[var(--kol-radius-sm)] border' : ''} ${box.clip ? 'overflow-hidden rounded-[var(--kol-radius-sm)]' : ''} ${interactive ? 'cursor-pointer select-none' : ''} ${interactive && hover ? 'kol-content-hover' : ''} ${interactive && box.frameHover ? 'kol-content-hover-frame' : ''} ${className}`.trim(),
|
|
330
337
|
style: vars,
|
|
331
338
|
}
|
|
332
339
|
|
|
@@ -127,7 +127,7 @@ export function MenuItem({
|
|
|
127
127
|
/* xs wears the TRIGGER's face (kol-mono-8), not the helper: the trigger's ghost
|
|
128
128
|
* stack reserves the widest label in its own face, and a row set in a different
|
|
129
129
|
* one measured 3px wider and clipped the selected row beside its check. */
|
|
130
|
-
const ROW_BY_SIZE = { xs: 'kol-mono-8 px-2 h-5', sm: 'kol-helper-12 px-
|
|
130
|
+
const ROW_BY_SIZE = { xs: 'kol-mono-8 px-2 h-5', sm: 'kol-helper-12 px-2 h-8', md: 'kol-helper-12 px-2 h-8', lg: 'kol-helper-12 px-2 h-8' }
|
|
131
131
|
/* `rowClass` — the row's type, side padding and height, whole, in place of the size's own
|
|
132
132
|
* (Dropdown passes it, 2026-10-02: its rows wear the trigger's face and sit on the trigger's
|
|
133
133
|
* text edge; a menu's rows keep `ROW_BY_SIZE`). */
|
|
@@ -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
|
}
|