@kolkrabbi/kol-component 0.288.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kolkrabbi/kol-component",
3
- "version": "0.288.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-search": "^0.3.0",
30
- "@kolkrabbi/kol-markdown": "^0.1.3"
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
- <div className="grid gap-2" style={{ gridTemplateColumns: `repeat(${cols}, minmax(0, 1fr))` }}>
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
  )
@@ -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
- * @param {number} cols grid column count (grid layout only)
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="min-w-0">
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
  }