@kolkrabbi/kol-component 0.351.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 +2 -2
- package/src/index.js +1 -0
- 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,8 +32,8 @@
|
|
|
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-markdown": "^0.2.0",
|
|
36
35
|
"@kolkrabbi/kol-growth": "^0.5.0",
|
|
36
|
+
"@kolkrabbi/kol-markdown": "^0.2.0",
|
|
37
37
|
"@kolkrabbi/kol-search": "^0.3.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
package/src/index.js
CHANGED
|
@@ -197,6 +197,7 @@ export { default as ShellSearchOverlay } from './organisms/ShellSearchOverlay.js
|
|
|
197
197
|
/* the keymap sheet — moved in from kol-shell 2026-09-28 so the workshop shell and the apps open ONE sheet on S */
|
|
198
198
|
export { default as ShortcutsOverlay, shortcutInScope } from './organisms/ShortcutsOverlay.jsx'
|
|
199
199
|
export { default as Slider } from './molecules/Slider.jsx'
|
|
200
|
+
export { default as TypeTester } from './molecules/TypeTester.jsx'
|
|
200
201
|
export { default as SpecList } from './molecules/SpecList.jsx'
|
|
201
202
|
export { default as SpectrumControls, HueStrip, SBSquare, WheelTriangle, AlphaStrip } from './organisms/SpectrumControls.jsx'
|
|
202
203
|
export { default as ColorPickerPopover } from './organisms/ColorPickerPopover.jsx'
|
|
@@ -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
|
+
}
|