@kolkrabbi/kol-component 0.350.0 → 0.352.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/SwatchCaption.jsx +61 -0
- package/src/molecules/SwatchTile.jsx +5 -17
- package/src/molecules/TypeTester.jsx +102 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kolkrabbi/kol-component",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.352.0",
|
|
4
4
|
"description": "The core component library",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
"embla-carousel-react": "^8.6.0",
|
|
33
33
|
"pdfjs-dist": "^6.3.289",
|
|
34
34
|
"react-syntax-highlighter": "^16.1.1",
|
|
35
|
-
"@kolkrabbi/kol-search": "^0.3.0",
|
|
36
35
|
"@kolkrabbi/kol-growth": "^0.5.0",
|
|
37
|
-
"@kolkrabbi/kol-markdown": "^0.2.0"
|
|
36
|
+
"@kolkrabbi/kol-markdown": "^0.2.0",
|
|
37
|
+
"@kolkrabbi/kol-search": "^0.3.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"@kolkrabbi/kol-icons": ">=0.61.1",
|
package/src/index.js
CHANGED
|
@@ -159,6 +159,7 @@ export { default as TextFold } from './molecules/TextFold.jsx'
|
|
|
159
159
|
export { default as PageControls } from './molecules/PageControls.jsx'
|
|
160
160
|
export { default as ColorSwatch } from './molecules/ColorSwatch.jsx'
|
|
161
161
|
export { default as SwatchTile } from './molecules/SwatchTile.jsx'
|
|
162
|
+
export { default as SwatchCaption } from './molecules/SwatchCaption.jsx'
|
|
162
163
|
export { default as Dropdown } from './molecules/Dropdown.jsx'
|
|
163
164
|
/* MultiSelect — several pick-one settings in one dropdown, a column each (2026-10-01, first cut) */
|
|
164
165
|
export { default as MultiSelect } from './molecules/MultiSelect.jsx'
|
|
@@ -196,6 +197,7 @@ export { default as ShellSearchOverlay } from './organisms/ShellSearchOverlay.js
|
|
|
196
197
|
/* the keymap sheet — moved in from kol-shell 2026-09-28 so the workshop shell and the apps open ONE sheet on S */
|
|
197
198
|
export { default as ShortcutsOverlay, shortcutInScope } from './organisms/ShortcutsOverlay.jsx'
|
|
198
199
|
export { default as Slider } from './molecules/Slider.jsx'
|
|
200
|
+
export { default as TypeTester } from './molecules/TypeTester.jsx'
|
|
199
201
|
export { default as SpecList } from './molecules/SpecList.jsx'
|
|
200
202
|
export { default as SpectrumControls, HueStrip, SBSquare, WheelTriangle, AlphaStrip } from './organisms/SpectrumControls.jsx'
|
|
201
203
|
export { default as ColorPickerPopover } from './organisms/ColorPickerPopover.jsx'
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SwatchCaption — The name, value and meta lines under a swatch. the text block of the SWATCH family
|
|
3
|
+
* (SwatchTile renders it for every size, 2026-11-08), as ContentText / SectionText are for theirs: slots
|
|
4
|
+
* opt-in, type by ROLE, every default class a SEAM. It renders siblings (a fragment), so the parent owns the
|
|
5
|
+
* gap and the alignment — SwatchTile wraps it where a form needs a box.
|
|
6
|
+
*
|
|
7
|
+
* layout 'inline' — name and value share one baseline row, space-between, wrapping; meta under it (the tile)
|
|
8
|
+
* layout 'stacked' — name, value, meta one under the other
|
|
9
|
+
* tone 'muted' — name quiet (text-meta), value strong semibold (the tile, the fixed chip)
|
|
10
|
+
* tone 'strong' — name emphasised, value quiet, both truncating and always drawn so a grid cell keeps its
|
|
11
|
+
* lines (the grid cell)
|
|
12
|
+
*
|
|
13
|
+
* @param {ReactNode} name - The label
|
|
14
|
+
* @param {ReactNode} value - The printed value
|
|
15
|
+
* @param {ReactNode} meta - Optional third line, e.g. the token name
|
|
16
|
+
* @param {'inline'|'stacked'} layout - default 'stacked'
|
|
17
|
+
* @param {'muted'|'strong'} tone - default 'muted'
|
|
18
|
+
* @param {string} rowClass - Replaces the inline row's classes whole (inline only)
|
|
19
|
+
* @param {string} nameClass - Replaces the name's classes whole
|
|
20
|
+
* @param {string} valueClass - Replaces the value's classes whole
|
|
21
|
+
* @param {string} metaClass - Replaces the meta line's classes whole
|
|
22
|
+
*/
|
|
23
|
+
export default function SwatchCaption({
|
|
24
|
+
name,
|
|
25
|
+
value,
|
|
26
|
+
meta,
|
|
27
|
+
layout = 'stacked',
|
|
28
|
+
tone = 'muted',
|
|
29
|
+
rowClass,
|
|
30
|
+
nameClass,
|
|
31
|
+
valueClass,
|
|
32
|
+
metaClass = 'kol-helper-10 text-meta',
|
|
33
|
+
}) {
|
|
34
|
+
const strong = tone === 'strong'
|
|
35
|
+
const inline = layout === 'inline'
|
|
36
|
+
const nc = nameClass ?? (inline ? 'text-meta' : strong ? 'kol-helper-10 text-emphasis max-w-full truncate' : 'kol-helper-10 text-meta')
|
|
37
|
+
const vc = valueClass ?? (inline ? 'text-strong font-semibold' : strong ? 'kol-helper-10 text-meta max-w-full truncate' : 'kol-helper-10 text-strong font-semibold')
|
|
38
|
+
const metaLine = meta && <span className={metaClass}>{meta}</span>
|
|
39
|
+
|
|
40
|
+
if (inline) return (
|
|
41
|
+
<>
|
|
42
|
+
{/* .kol-swatch-meta: row, space-between, baseline, wrapping */}
|
|
43
|
+
<div
|
|
44
|
+
className={rowClass ?? 'kol-helper-10 flex flex-row flex-wrap items-baseline justify-between'}
|
|
45
|
+
style={{ gap: '4px 12px' }}
|
|
46
|
+
>
|
|
47
|
+
{name && <span className={nc}>{name}</span>}
|
|
48
|
+
{value && <span className={vc}>{value}</span>}
|
|
49
|
+
</div>
|
|
50
|
+
{metaLine}
|
|
51
|
+
</>
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<>
|
|
56
|
+
{strong || name ? <span className={nc}>{name}</span> : null}
|
|
57
|
+
{strong || value ? <span className={vc}>{value}</span> : null}
|
|
58
|
+
{metaLine}
|
|
59
|
+
</>
|
|
60
|
+
)
|
|
61
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import ColorSwatch from './ColorSwatch.jsx'
|
|
2
|
+
import SwatchCaption from './SwatchCaption.jsx'
|
|
2
3
|
import { isLight } from '../hooks/cssVar.js'
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -16,7 +17,7 @@ import { isLight } from '../hooks/cssVar.js'
|
|
|
16
17
|
* <SwatchTile hex="#131316" name="Ink" anchor />
|
|
17
18
|
*
|
|
18
19
|
* @param {string} hex - The paint — any CSS color, `var(--token)` included
|
|
19
|
-
* @param {ReactNode} name - The label
|
|
20
|
+
* @param {ReactNode} name - The label (the caption is SwatchCaption)
|
|
20
21
|
* @param {ReactNode} meta - Optional third line, e.g. the token name
|
|
21
22
|
* @param {ReactNode} value - The printed value (default: `hex` uppercased); null hides it
|
|
22
23
|
* @param {'tile'|'grid'|number} size - The form (default 'tile')
|
|
@@ -43,7 +44,6 @@ export default function SwatchTile({
|
|
|
43
44
|
className = '',
|
|
44
45
|
}) {
|
|
45
46
|
const chip = { hex, selected, onClick, title, radius: 'sm', className: chipClassName }
|
|
46
|
-
const metaLine = meta && <span className="kol-helper-10 text-meta">{meta}</span>
|
|
47
47
|
|
|
48
48
|
if (size === 'grid') return (
|
|
49
49
|
<div className={`flex min-w-0 flex-col gap-1.5 ${className}`.trim()}>
|
|
@@ -56,9 +56,7 @@ export default function SwatchTile({
|
|
|
56
56
|
)}
|
|
57
57
|
</div>
|
|
58
58
|
<div className="flex min-w-0 flex-col items-start gap-0.5 leading-tight">
|
|
59
|
-
<
|
|
60
|
-
<span className="kol-helper-10 text-meta max-w-full truncate">{value}</span>
|
|
61
|
-
{metaLine}
|
|
59
|
+
<SwatchCaption name={<>{name}{anchor && ' ★'}</>} value={value} meta={meta} tone="strong" />
|
|
62
60
|
</div>
|
|
63
61
|
</div>
|
|
64
62
|
)
|
|
@@ -66,9 +64,7 @@ export default function SwatchTile({
|
|
|
66
64
|
if (typeof size === 'number') return (
|
|
67
65
|
<div className={`flex flex-col items-start gap-1.5 ${className}`.trim()}>
|
|
68
66
|
<ColorSwatch {...chip} size={size} />
|
|
69
|
-
{name
|
|
70
|
-
{value && <span className="kol-helper-10 text-strong font-semibold">{value}</span>}
|
|
71
|
-
{metaLine}
|
|
67
|
+
<SwatchCaption name={name} value={value} meta={meta} />
|
|
72
68
|
</div>
|
|
73
69
|
)
|
|
74
70
|
|
|
@@ -91,15 +87,7 @@ export default function SwatchTile({
|
|
|
91
87
|
</span>
|
|
92
88
|
)}
|
|
93
89
|
</div>
|
|
94
|
-
{
|
|
95
|
-
<div
|
|
96
|
-
className="kol-helper-10 flex flex-row flex-wrap items-baseline justify-between"
|
|
97
|
-
style={{ gap: '4px 12px' }}
|
|
98
|
-
>
|
|
99
|
-
{name && <span className="text-meta">{name}</span>}
|
|
100
|
-
{value && <span className="text-strong font-semibold">{value}</span>}
|
|
101
|
-
</div>
|
|
102
|
-
{metaLine}
|
|
90
|
+
<SwatchCaption name={name} value={value} meta={meta} layout="inline" />
|
|
103
91
|
</div>
|
|
104
92
|
)
|
|
105
93
|
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from 'react'
|
|
2
|
+
import Dropdown from './Dropdown.jsx'
|
|
3
|
+
import Slider from './Slider.jsx'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* TypeTester — One live type-testing block. a style Dropdown and Size / Leading / Spacing Sliders over an
|
|
7
|
+
* editable sample in the font under test (lobby TypeTester, 2026-11-08 — ported class-for-class from
|
|
8
|
+
* kol-website's foundry FontPreviewItem). The size ladder around it is the caller's: render one per rung.
|
|
9
|
+
*
|
|
10
|
+
* Leading maps 0–50 → 90–140% line-height. Below md only Size shows. The sample re-seeds from `text` only
|
|
11
|
+
* when its content differs, so in-place edits survive a re-render.
|
|
12
|
+
*
|
|
13
|
+
* SIDE BEARINGS: the sample pads 0.15em inline and pulls back by the same, so overhangs (italic s, ð, f)
|
|
14
|
+
* survive the clamp's own overflow: hidden. The wrapper must NOT clip (FontPreviewClampAndBearings, 2026-08-27).
|
|
15
|
+
*
|
|
16
|
+
* @param {string} fontFamily - Family of the sample
|
|
17
|
+
* @param {'normal'|'italic'} fontStyle - Style of the sample (default 'normal')
|
|
18
|
+
* @param {string} text - The editable sample text (re-seeded when it changes)
|
|
19
|
+
* @param {{label: string, value: string|number}[]} styles - The Dropdown's options; `value` is the CSS font-weight
|
|
20
|
+
* @param {string} initialStyle - The Dropdown's starting option, by label or value (default 'Regular')
|
|
21
|
+
* @param {number} initialSize - Size slider start, px (default 64)
|
|
22
|
+
* @param {number} initialLeading - Leading slider start, 0–50 → 90–140% (default 10)
|
|
23
|
+
* @param {number|null} lineClamp - Clamp the sample to n lines with an ellipsis (default null)
|
|
24
|
+
*/
|
|
25
|
+
export default function TypeTester({
|
|
26
|
+
fontFamily,
|
|
27
|
+
fontStyle = 'normal',
|
|
28
|
+
text = '',
|
|
29
|
+
styles = [],
|
|
30
|
+
initialStyle = 'Regular',
|
|
31
|
+
initialSize = 64,
|
|
32
|
+
initialLeading = 10,
|
|
33
|
+
lineClamp = null,
|
|
34
|
+
}) {
|
|
35
|
+
const seed = styles.find((s) => s.label === initialStyle || s.value === initialStyle)?.value ?? initialStyle
|
|
36
|
+
const [size, setSize] = useState(initialSize)
|
|
37
|
+
const [leading, setLeading] = useState(initialLeading)
|
|
38
|
+
const [spacing, setSpacing] = useState(0)
|
|
39
|
+
const [weight, setWeight] = useState(seed)
|
|
40
|
+
const editableRef = useRef(null)
|
|
41
|
+
|
|
42
|
+
useEffect(() => setWeight(seed), [seed])
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
if (editableRef.current && editableRef.current.textContent !== text) {
|
|
45
|
+
editableRef.current.textContent = text
|
|
46
|
+
}
|
|
47
|
+
}, [text])
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<div className="self-stretch min-h-40 p-4 md:p-6 rounded border border-fg-08 hover:border-fg-24 transition-colors duration-300 flex flex-col justify-start items-start gap-6 bg-surface-primary">
|
|
51
|
+
<div className="self-stretch flex flex-wrap justify-between items-start gap-4 md:gap-8">
|
|
52
|
+
<div className="flex-shrink-0">
|
|
53
|
+
<Dropdown options={styles} value={weight} onChange={setWeight} />
|
|
54
|
+
</div>
|
|
55
|
+
<div className="flex flex-wrap justify-start items-start gap-4 md:gap-8">
|
|
56
|
+
<Slider readoutPreset="rail" displayWidth={4} label="Size" min={12} max={200} value={size} onChange={setSize} className="w-56" />
|
|
57
|
+
<Slider readoutPreset="rail" displayWidth={4}
|
|
58
|
+
label="Leading"
|
|
59
|
+
min={0}
|
|
60
|
+
max={50}
|
|
61
|
+
value={leading}
|
|
62
|
+
onChange={setLeading}
|
|
63
|
+
className="hidden md:flex w-56"
|
|
64
|
+
formatValue={(val) => 90 + val}
|
|
65
|
+
/>
|
|
66
|
+
<Slider readoutPreset="rail" displayWidth={4} label="Spacing" min={-50} max={50} value={spacing} onChange={setSpacing} className="hidden md:flex w-56" />
|
|
67
|
+
</div>
|
|
68
|
+
</div>
|
|
69
|
+
|
|
70
|
+
{/* no overflow clip on the wrapper — the clamped element clips itself */}
|
|
71
|
+
<div className="self-stretch rounded flex justify-start items-start">
|
|
72
|
+
<div
|
|
73
|
+
ref={editableRef}
|
|
74
|
+
contentEditable
|
|
75
|
+
suppressContentEditableWarning
|
|
76
|
+
className="flex-1 bg-transparent outline-none border-none text-auto"
|
|
77
|
+
style={{
|
|
78
|
+
fontFamily,
|
|
79
|
+
fontStyle,
|
|
80
|
+
fontWeight: weight,
|
|
81
|
+
fontSize: `${size}px`,
|
|
82
|
+
lineHeight: `${90 + leading}%`,
|
|
83
|
+
letterSpacing: `${spacing}px`,
|
|
84
|
+
wordWrap: 'break-word',
|
|
85
|
+
overflowWrap: 'break-word',
|
|
86
|
+
whiteSpace: 'normal',
|
|
87
|
+
hyphens: 'none',
|
|
88
|
+
maxWidth: '100%',
|
|
89
|
+
paddingInline: '0.15em',
|
|
90
|
+
marginInline: '-0.15em',
|
|
91
|
+
...(lineClamp && {
|
|
92
|
+
display: '-webkit-box',
|
|
93
|
+
WebkitLineClamp: lineClamp,
|
|
94
|
+
WebkitBoxOrient: 'vertical',
|
|
95
|
+
overflow: 'hidden',
|
|
96
|
+
}),
|
|
97
|
+
}}
|
|
98
|
+
/>
|
|
99
|
+
</div>
|
|
100
|
+
</div>
|
|
101
|
+
)
|
|
102
|
+
}
|