@kolkrabbi/kol-component 0.351.0 → 0.353.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.351.0",
3
+ "version": "0.353.0",
4
4
  "description": "The core component library",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -33,8 +33,8 @@
33
33
  "pdfjs-dist": "^6.3.289",
34
34
  "react-syntax-highlighter": "^16.1.1",
35
35
  "@kolkrabbi/kol-markdown": "^0.2.0",
36
- "@kolkrabbi/kol-growth": "^0.5.0",
37
- "@kolkrabbi/kol-search": "^0.3.0"
36
+ "@kolkrabbi/kol-search": "^0.3.0",
37
+ "@kolkrabbi/kol-growth": "^0.5.0"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "@kolkrabbi/kol-icons": ">=0.61.1",
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
+ }
@@ -146,6 +146,8 @@ import useScrollFade from '../hooks/useScrollFade.js'
146
146
  * `icon` on any node at any depth (page, group label, action row, nested child), through `iconComponent`
147
147
  * `iconSize` `{ category, group, page }` (defaults 16, 12, 12); a node's own `iconSize` wins
148
148
  * `alignIcons` `true` (default): a level where any row has an icon reserves the icon column for all its rows
149
+ * `pageIcons` `'inline'` (default) — a page's glyph sits before its label (the column above) · `'gutter'` — it hangs
150
+ * in the gutter under the category glyph and the label stays where a plain page label sits
149
151
  * `collapsedIcons` `'category'` (default) — the collapsed rail shows category glyphs only; `'all'` also shows the
150
152
  * icon-bearing pages of an open category under it
151
153
  * per node `trailing` (a count, badge or node, right-aligned), `className`, `title` (the tooltip when the
@@ -244,6 +246,7 @@ export default function NavRailSite({
244
246
  casePage,
245
247
  iconSize: iconSizes,
246
248
  alignIcons = true,
249
+ pageIcons = 'inline',
247
250
  collapsedIcons = 'category',
248
251
  toggleRef,
249
252
  }) {
@@ -352,12 +355,27 @@ export default function NavRailSite({
352
355
  /* THE ICON COLUMN (NavRailRowProps): with `alignIcons`, a level where any row has an icon reserves the column for all
353
356
  * its rows, as wide as its widest glyph; a level with no icon draws exactly as before */
354
357
  const levelOf = (r) => (r.children ? 'group' : 'page')
355
- const iconW = rows.reduce((w, r) => (r.icon ? Math.max(w, sizeOf(r, levelOf(r))) : w), 0)
358
+ /* `pageIcons="gutter"`: a page row's glyph hangs in the gutter under the category's glyph, so its label stays where a
359
+ * plain page label sits — no column, no shift (kol-kerner via kol-hq 2026-11-08: "app rail has it") */
360
+ const hangs = (r) => pageIcons === 'gutter' && !r.children
361
+ const iconW = rows.reduce((w, r) => (r.icon && !hangs(r) ? Math.max(w, sizeOf(r, levelOf(r))) : w), 0)
356
362
  const aligned = alignIcons && iconW > 0
357
363
  /* a row with an icon, a reserved column or a tail lays out as glyph · label · tail; its case rides the label span
358
364
  * (a flex item, so `::first-letter` applies). A plain row keeps its text bare and the case rides the row. */
359
365
  const body = (row, cc) => {
360
366
  const tail = tailOf(row)
367
+ if (hangs(row) && row.icon) {
368
+ const size = sizeOf(row, 'page')
369
+ const glyph = (
370
+ /* centred under the category glyph's 16px column, left of the active dot */
371
+ <span className="kol-sidenav-hop-icon absolute top-1/2 -translate-y-1/2 inline-flex items-center justify-center" style={{ left: `calc(var(--kol-sidenav-pad-x) + ${depth} * var(--kol-spacing-3))`, width: 16 }} aria-hidden="true">
372
+ <Glyph name={row.icon} size={size} />
373
+ </span>
374
+ )
375
+ return tail
376
+ ? { rowCase: '', content: <>{glyph}<span className="flex items-center gap-2 min-w-0"><span className={withCls('flex-1 min-w-0 truncate', cc)}>{row.label}</span>{tail}</span></> }
377
+ : { rowCase: cc, content: <>{glyph}{row.label}</> }
378
+ }
361
379
  if (!row.icon && !aligned && !tail) return { rowCase: cc, content: row.label }
362
380
  const size = sizeOf(row, levelOf(row))
363
381
  return {