@kolkrabbi/kol-component 0.383.0 → 0.385.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/atoms/Button.jsx +65 -121
- package/src/atoms/Input.jsx +46 -100
- package/src/atoms/Kbd.jsx +15 -25
- package/src/atoms/Textarea.jsx +14 -15
- package/src/index.js +1 -1
- package/src/molecules/ButtonGroup.jsx +1 -1
- package/src/molecules/FieldPair.jsx +20 -40
- package/src/molecules/LabeledControl.jsx +20 -51
- package/src/molecules/Modal.jsx +129 -272
- package/src/molecules/ModalShell.jsx +10 -12
- package/src/organisms/FindBar.jsx +3 -3
- package/src/utilities/Popover.jsx +170 -215
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kolkrabbi/kol-component",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.385.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.69.0",
|
package/src/atoms/Button.jsx
CHANGED
|
@@ -3,8 +3,7 @@ import { toneClass, VARIANT_TONE } from '../utilities/tone.js'
|
|
|
3
3
|
import { IconLoader } from '@kolkrabbi/kol-icons'
|
|
4
4
|
import { glyphSize } from '../hooks/glyphLadders.js'
|
|
5
5
|
import Kbd from './Kbd.jsx'
|
|
6
|
-
import
|
|
7
|
-
import { InTooltipKolbox, Tooltip } from '../utilities/Popover.jsx'
|
|
6
|
+
import { InTooltip, Tooltip } from '../utilities/Popover.jsx'
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* Button — canonical KOL button. Emits kol-btn* classes (CSS in @kol/theme).
|
|
@@ -38,18 +37,22 @@ import { InTooltipKolbox, Tooltip } from '../utilities/Popover.jsx'
|
|
|
38
37
|
* @param {boolean} props.selected - Selected/active state (toggle highlight)
|
|
39
38
|
* @param {ElementType|ReactNode} props.iconComponent - Icon renderer seam — a component that receives `{ name, size, className, style }` in place of the DS Icon (custom icon registries plug in here), or a pre-rendered node dropped in verbatim where the glyph would go. Defaults to DS Icon.
|
|
40
39
|
* @param {boolean} props.pressed - Toggle state — sets `aria-pressed` (true/false) and `kol-btn-pressed`; a `quiet` button drops its dimming while pressed. Leave undefined for non-toggle buttons.
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
40
|
+
* ONE BUTTON, ITS LOOK THE THEME'S (plan-2026-11-29-one-set-fold 1.4): height, padding, radius, type, the glyph's size
|
|
41
|
+
* and line, the focus line and the tone fills are `--kol-btn-*` (kol-theme kol-components-atoms.css, Button); the
|
|
42
|
+
* default theme leaves them unset and draws what the default path always drew, `data-theme-variant="kolbox"` sets
|
|
43
|
+
* kolbox's (one size, 24 high, 12 in, radius 4, 11 / 16). `variant="kolbox"` and `variant="folio"` are accepted and do
|
|
44
|
+
* nothing (their branches went to `_tmp/2026-11-29-one-set-fold/`). An icon-only button with an `aria-label` names itself
|
|
45
|
+
* in a Tooltip unless it already sits in one, and carries a hover layer (`::before`) that a theme may draw bigger than
|
|
46
|
+
* its box (kolbox: a 24 fill around a caller's 16 box); `children` stand in for a glyph that is not an icon.
|
|
47
|
+
* @param {'kolbox'|'folio'} props.variant - also `kolbox` and `folio`: accepted and nothing (1.4; on the retirement ledger), the theme draws the look
|
|
48
|
+
* @param {ReactNode} props.glyph - a character after the label (`+`, `⌄`, `→`), `.kol-btn-glyph` (Folio's page actions)
|
|
49
|
+
* @param {boolean} props.keepFocus - a press does not take the focus (`mousedown` is prevented), so an editor's selection stays (Folio's tools)
|
|
44
50
|
* @param {'primary'|'secondary'} [props.accent='primary'] - which of the theme's two accents the part draws (KolboxAccentBlueAndSecondary, 2026-11-28): `secondary` stamps `data-accent="secondary"`, which points every primary accent token at the secondary's on the part and inside it (kol-theme kol-color.css). A theme with no secondary draws its primary.
|
|
45
51
|
* @param {string} props.kbd - a key cap after the label, inside the button (float-everything W2 row 12, 2026-11-04): `Kbd size="sm"`, a leading ⌘ drawn as the `command` icon.
|
|
46
52
|
*/
|
|
47
53
|
const warned = new Set()
|
|
48
|
-
/*
|
|
49
|
-
|
|
50
|
-
const KOLBOX_TONES = ['primary', 'secondary', 'outline', 'ghost']
|
|
51
|
-
/* Folio's three grounds; unset is the shape's own (md ghost, lg outline) */
|
|
52
|
-
const FOLIO_TONES = ['primary', 'outline', 'ghost']
|
|
54
|
+
/* the old theme words in `variant`: accepted, nothing (1.4, on the retirement ledger) */
|
|
55
|
+
const THEME_WORDS = ['kolbox', 'folio']
|
|
53
56
|
|
|
54
57
|
const Button = ({
|
|
55
58
|
children,
|
|
@@ -78,12 +81,13 @@ const Button = ({
|
|
|
78
81
|
tone = 'default',
|
|
79
82
|
kbd,
|
|
80
83
|
glyph,
|
|
84
|
+
keepFocus = false,
|
|
81
85
|
accent,
|
|
82
86
|
...props
|
|
83
87
|
}) => {
|
|
84
88
|
if (accent === 'secondary') props['data-accent'] = accent
|
|
85
|
-
/* an icon-only
|
|
86
|
-
const inTip = useContext(
|
|
89
|
+
/* an icon-only button names itself in a tooltip unless it already sits in one */
|
|
90
|
+
const inTip = useContext(InTooltip)
|
|
87
91
|
/* `variant="bare"` (MetricRebuild, 2026-10-31): a pressable SURFACE — a stat tile, a bar row, a column head — that
|
|
88
92
|
* draws itself. No kol-btn chrome (ground, size, type, radius); the button keeps its type, the KOL focus ring
|
|
89
93
|
* (`kol-menu-btn`, as MenuItem's rows) and `disabled`;
|
|
@@ -91,85 +95,17 @@ const Button = ({
|
|
|
91
95
|
if (variant === 'bare') {
|
|
92
96
|
return <button type={type} onClick={onClick} disabled={disabled} className={`kol-menu-btn kol-menu-btn--bare ${className}`.trim()} style={style} {...props}>{children}</button>
|
|
93
97
|
}
|
|
94
|
-
/* `variant="kolbox"` (plan-2026-11-18-kolbox-system W31.2 batch 3, 2026-11-18): kolbox's Button and IconButton carried
|
|
95
|
-
* class for class, the chrome in kol-theme `.kol-btn--kolbox` and `.kol-icon-btn--kolbox`. */
|
|
96
|
-
if (variant === 'kolbox') {
|
|
97
|
-
const on = Boolean(pressed !== undefined ? pressed : selected)
|
|
98
|
-
/* your icons as kolbox draws them (KolboxGlyph: the stroke lift, every chevron 12 at the dock chevron's stroke) */
|
|
99
|
-
const glyph = (name) => <KolboxGlyph name={name} />
|
|
100
|
-
/* IconButton: a box at the kolbox control height (`--kol-kolbox-ctl`, 24) whose hover and pressed fill is its own
|
|
101
|
-
layer (::before) at the same height, centred on the glyph, so a caller's 16 box keeps its size in the layout and
|
|
102
|
-
still lights 24 */
|
|
103
|
-
if (iconOnly) {
|
|
104
|
-
const tip = !inTip && props['aria-label'] && props['aria-hidden'] == null ? props['aria-label'] : null
|
|
105
|
-
const btn = (
|
|
106
|
-
<button
|
|
107
|
-
type={type}
|
|
108
|
-
onClick={onClick}
|
|
109
|
-
disabled={disabled}
|
|
110
|
-
style={style}
|
|
111
|
-
aria-pressed={on}
|
|
112
|
-
className={`kol-icon-btn--kolbox${on ? ' is-pressed' : ''} relative inline-flex size-(--kol-kolbox-ctl) shrink-0 items-center justify-center outline-none focus-visible:outline-solid focus-visible:outline-1 disabled:opacity-40 disabled:pointer-events-none isolate before:absolute before:top-1/2 before:left-1/2 before:-z-10 before:size-(--kol-kolbox-ctl) before:-translate-1/2 before:content-[''] ${className}`}
|
|
113
|
-
{...props}
|
|
114
|
-
>
|
|
115
|
-
{children ?? glyph(iconOnly)}
|
|
116
|
-
</button>
|
|
117
|
-
)
|
|
118
|
-
return tip ? <Tooltip variant="kolbox" asChild label={tip}>{btn}</Tooltip> : btn
|
|
119
|
-
}
|
|
120
|
-
const look = on ? 'lit' : KOLBOX_TONES.includes(tone) ? tone : 'secondary'
|
|
121
|
-
/* the secondary tone is fill only, no border in any state (W15.4, his "I dont like borders with fill") */
|
|
122
|
-
return (
|
|
123
|
-
<button
|
|
124
|
-
type={type}
|
|
125
|
-
onClick={onClick}
|
|
126
|
-
disabled={disabled}
|
|
127
|
-
style={style}
|
|
128
|
-
aria-pressed={pressed}
|
|
129
|
-
className={`kol-btn--kolbox kol-btn--kolbox-${look} inline-flex h-(--kol-kolbox-ctl) shrink-0 items-center justify-center gap-2 ${look === 'secondary' ? 'border-0' : 'border'} px-3 whitespace-nowrap outline-none focus-visible:outline-solid focus-visible:outline-1 focus-visible:outline-offset-1 disabled:opacity-40${look === 'primary' ? ' enabled:hover:brightness-110' : ''} ${className}`}
|
|
130
|
-
{...props}
|
|
131
|
-
>
|
|
132
|
-
{iconLeft && glyph(iconLeft)}
|
|
133
|
-
{children}
|
|
134
|
-
</button>
|
|
135
|
-
)
|
|
136
|
-
}
|
|
137
|
-
/* `variant="folio"` (Folio migration batch A, 2026-11-22): Folio's Action, Tool and ToolIcon carried class for class
|
|
138
|
-
* (apps/folio parts.jsx, EditorChrome.jsx), the chrome in kol-theme `.kol-btn--folio` and `.kol-icon-btn--folio`. */
|
|
139
|
-
if (variant === 'folio') {
|
|
140
|
-
const on = pressed !== undefined ? pressed : (selected || undefined)
|
|
141
|
-
const keep = (e) => e.preventDefault()
|
|
142
|
-
if (iconOnly) {
|
|
143
|
-
return (
|
|
144
|
-
<button type={type} onMouseDown={keep} onClick={onClick} disabled={disabled} style={style} aria-pressed={on} {...props} className={`kol-icon-btn--folio flex size-[32px] shrink-0 items-center justify-center rounded-[4px] ${className}`}>
|
|
145
|
-
{children ?? <IconLoader name={iconOnly} size={20} />}
|
|
146
|
-
</button>
|
|
147
|
-
)
|
|
148
|
-
}
|
|
149
|
-
const look = FOLIO_TONES.includes(tone) ? tone : size === 'lg' ? 'outline' : 'ghost'
|
|
150
|
-
if (size === 'lg') {
|
|
151
|
-
return (
|
|
152
|
-
<button type={type} onClick={onClick} disabled={disabled} style={style} aria-pressed={on} {...props} className={`kol-btn--folio kol-btn--folio-lg kol-btn--folio-${look} flex h-[42px] shrink-0 items-center gap-[12px] whitespace-nowrap rounded-[3px] border px-[16px] ${className}`}>
|
|
153
|
-
<span className="kol-btn-label">{children}</span>
|
|
154
|
-
<span className="kol-btn-glyph">{glyph}</span>
|
|
155
|
-
</button>
|
|
156
|
-
)
|
|
157
|
-
}
|
|
158
|
-
return (
|
|
159
|
-
<button type={type} onMouseDown={keep} onClick={onClick} disabled={disabled} style={style} aria-pressed={on} {...props} className={`kol-btn--folio kol-btn--folio-md kol-btn--folio-${look} flex h-[32px] shrink-0 items-center gap-[8px] whitespace-nowrap rounded-[3px] px-[10px] disabled:opacity-30 ${className}`}>
|
|
160
|
-
{iconLeft && <IconLoader name={iconLeft} size={16} />}{children}
|
|
161
|
-
</button>
|
|
162
|
-
)
|
|
163
|
-
}
|
|
164
98
|
// Two ladders, split on whether a label sits beside the glyph. An icon-only
|
|
165
99
|
// button is a solo glyph in a pinned square, so it takes SOLO (16/20/24) —
|
|
166
100
|
// it took the text-adjacent ladder until component 0.20.0, which put a 14px
|
|
167
|
-
// glyph in a 28px square at `sm`. `iconSize` still overrides either
|
|
101
|
+
// glyph in a 28px square at `sm`. `iconSize` still overrides either; unset, the
|
|
102
|
+
// theme may set one size for every rung (`--kol-btn-icon`, kolbox 16).
|
|
168
103
|
const resolvedIconSize = iconSize ?? glyphSize(size, Boolean(iconOnly))
|
|
104
|
+
const glyphBox = iconSize != null ? iconSize : `var(--kol-btn-icon, ${resolvedIconSize}px)`
|
|
169
105
|
|
|
170
106
|
// `control` is a legacy alias for `ghost` (kept so web call-sites passing
|
|
171
|
-
// variant="control" keep working post-migration).
|
|
172
|
-
const resolvedVariant = variant === 'control' ? 'ghost' : variant
|
|
107
|
+
// variant="control" keep working post-migration). The theme words are nothing.
|
|
108
|
+
const resolvedVariant = variant === 'control' ? 'ghost' : THEME_WORDS.includes(variant) ? undefined : variant
|
|
173
109
|
|
|
174
110
|
/* THE GROUND IS A TONE (tone-is-the-ground-axis, 2026-09-03). No variant →
|
|
175
111
|
* NO class: the button paints from the `--kol-tone-*` properties it inherits
|
|
@@ -194,14 +130,9 @@ const Button = ({
|
|
|
194
130
|
if (!known && import.meta.env.DEV) console.warn(`Button: unknown variant "${resolvedVariant}" — rendering the inherited tone (primary)`)
|
|
195
131
|
const variantClass = resolvedVariant && known ? `kol-btn-${resolvedVariant}` : ''
|
|
196
132
|
|
|
197
|
-
//
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
: size === 'xs'
|
|
201
|
-
? 'kol-btn-xs kol-mono-8'
|
|
202
|
-
: size === 'lg'
|
|
203
|
-
? 'kol-btn-lg kol-mono-16'
|
|
204
|
-
: 'kol-btn-md kol-mono-14'
|
|
133
|
+
// Size class — the padding AND the type live in its own rule (ARCHITECTURE §5; the `kol-mono-*` utility it carried
|
|
134
|
+
// until 1.4 could not be themed): xs mono 8, sm 12, md 14, lg 16 unless the theme sets `--kol-btn-*`.
|
|
135
|
+
const sizeClass = size === 'sm' ? 'kol-btn-sm' : size === 'xs' ? 'kol-btn-xs' : size === 'lg' ? 'kol-btn-lg' : 'kol-btn-md'
|
|
205
136
|
|
|
206
137
|
// Add kol-btn-animate class if animateIcon is true to disable default hover states
|
|
207
138
|
const animateClass = animateIcon ? 'kol-btn-animate' : ''
|
|
@@ -235,25 +166,31 @@ const Button = ({
|
|
|
235
166
|
// registry (EditorIcon etc.); a pre-rendered node drops in verbatim.
|
|
236
167
|
if (isValidElement(iconComponent)) return iconComponent
|
|
237
168
|
const IconCmp = iconComponent || IconLoader
|
|
169
|
+
/* your icons take the theme's size and line (`.kol-btn-svg`); a custom registry keeps the number it always got */
|
|
170
|
+
const own = !iconComponent
|
|
171
|
+
/* a chevron's box is the theme's own (`--kol-btn-chevron`, kolbox 12); unset, any glyph's */
|
|
172
|
+
const chev = own && iconSize == null && iconName?.startsWith('chevron-')
|
|
173
|
+
const s = !own ? resolvedIconSize : chev ? `var(--kol-btn-chevron, ${glyphBox})` : glyphBox
|
|
174
|
+
const cls = own ? `kol-btn-svg${chev ? ' kol-btn-chevron' : ''}` : undefined
|
|
238
175
|
|
|
239
176
|
// If no hover icon, render single icon
|
|
240
177
|
if (!iconHoverName) {
|
|
241
|
-
return <IconCmp name={iconName} size={
|
|
178
|
+
return <IconCmp name={iconName} size={s} className={cls} />
|
|
242
179
|
}
|
|
243
180
|
|
|
244
181
|
// Render both default and hover icons with positioning
|
|
245
182
|
return (
|
|
246
|
-
<span className="kol-icon-swap-container" style={{ position: 'relative', display: 'inline-flex', width:
|
|
183
|
+
<span className="kol-icon-swap-container" style={{ position: 'relative', display: 'inline-flex', width: s, height: s, overflow: 'hidden' }}>
|
|
247
184
|
<IconCmp
|
|
248
185
|
name={iconName}
|
|
249
|
-
size={
|
|
250
|
-
className=
|
|
186
|
+
size={s}
|
|
187
|
+
className={`kol-icon-default ${cls ?? ''}`.trim()}
|
|
251
188
|
style={{ position: 'absolute' }}
|
|
252
189
|
/>
|
|
253
190
|
<IconCmp
|
|
254
191
|
name={iconHoverName}
|
|
255
|
-
size={
|
|
256
|
-
className=
|
|
192
|
+
size={s}
|
|
193
|
+
className={`kol-icon-hover ${cls ?? ''}`.trim()}
|
|
257
194
|
style={{ position: 'absolute' }}
|
|
258
195
|
/>
|
|
259
196
|
</span>
|
|
@@ -271,19 +208,23 @@ const Button = ({
|
|
|
271
208
|
const renderContent = () => {
|
|
272
209
|
// Icon-only button
|
|
273
210
|
if (iconOnly) {
|
|
274
|
-
return renderIcon(iconOnly, iconOnlyHover)
|
|
211
|
+
return children ?? renderIcon(iconOnly, iconOnlyHover)
|
|
275
212
|
}
|
|
276
213
|
|
|
214
|
+
/* the trailing glyph (Folio's page actions): a character after the label */
|
|
215
|
+
const tail = glyph != null && <span className="kol-btn-glyph">{glyph}</span>
|
|
216
|
+
|
|
277
217
|
// Button with icon(s) and text. Icons render directly as flex items —
|
|
278
218
|
// wrapper spans (with the old -2px optical margins) sat the glyphs on
|
|
279
219
|
// the span's text baseline instead of letting align-items center them
|
|
280
220
|
// against the label.
|
|
281
|
-
if (iconLeft || iconRight || iconLeftHover || iconRightHover) {
|
|
221
|
+
if (iconLeft || iconRight || iconLeftHover || iconRightHover || tail) {
|
|
282
222
|
return (
|
|
283
|
-
<span className="flex items-center" style={{ gap: iconGap ??
|
|
223
|
+
<span className="flex items-center" style={{ gap: iconGap ?? 'var(--kol-btn-gap, 8px)' }}>
|
|
284
224
|
{(iconLeft || iconLeftHover) && renderIcon(iconLeft, iconLeftHover)}
|
|
285
225
|
{children}
|
|
286
226
|
{(iconRight || iconRightHover) && renderIcon(iconRight, iconRightHover)}
|
|
227
|
+
{tail}
|
|
287
228
|
{cap}
|
|
288
229
|
</span>
|
|
289
230
|
)
|
|
@@ -294,37 +235,40 @@ const Button = ({
|
|
|
294
235
|
}
|
|
295
236
|
|
|
296
237
|
const mergedStyle = style
|
|
238
|
+
/* `keepFocus`: the press keeps the focus where it was (the caller's own onMouseDown still runs) */
|
|
239
|
+
const onMouseDown = keepFocus ? (e) => { e.preventDefault(); props.onMouseDown?.(e) } : props.onMouseDown
|
|
240
|
+
/* the auto tooltip: an icon-only button with an `aria-label`, not already in a Tooltip, not hidden */
|
|
241
|
+
const tip = iconOnly && !inTip && props['aria-label'] && props['aria-hidden'] == null ? props['aria-label'] : null
|
|
297
242
|
|
|
298
243
|
// Render as button
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
// Render as link
|
|
317
|
-
return (
|
|
244
|
+
const el = onClick || !href ? (
|
|
245
|
+
<button
|
|
246
|
+
onClick={onClick}
|
|
247
|
+
type={type}
|
|
248
|
+
className={combinedClass}
|
|
249
|
+
style={mergedStyle}
|
|
250
|
+
disabled={disabled}
|
|
251
|
+
aria-pressed={pressed !== undefined ? pressed : (selected ? true : undefined)}
|
|
252
|
+
aria-label={iconOnly ? (props['aria-label'] || 'Button') : undefined}
|
|
253
|
+
{...props}
|
|
254
|
+
onMouseDown={onMouseDown}
|
|
255
|
+
>
|
|
256
|
+
{renderContent()}
|
|
257
|
+
</button>
|
|
258
|
+
) : (
|
|
259
|
+
// Render as link
|
|
318
260
|
<a
|
|
319
261
|
href={href}
|
|
320
262
|
className={combinedClass}
|
|
321
263
|
style={mergedStyle}
|
|
322
264
|
aria-label={iconOnly ? (props['aria-label'] || 'Link') : undefined}
|
|
323
265
|
{...props}
|
|
266
|
+
onMouseDown={onMouseDown}
|
|
324
267
|
>
|
|
325
268
|
{renderContent()}
|
|
326
269
|
</a>
|
|
327
270
|
)
|
|
271
|
+
return tip ? <Tooltip asChild label={tip}>{el}</Tooltip> : el
|
|
328
272
|
}
|
|
329
273
|
|
|
330
274
|
export default Button
|
package/src/atoms/Input.jsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useRef, useState } from 'react'
|
|
2
2
|
import { IconLoader } from '@kolkrabbi/kol-icons'
|
|
3
3
|
import { toneClass } from '../utilities/tone.js'
|
|
4
4
|
import { glyphSize } from '../hooks/glyphLadders.js'
|
|
@@ -11,25 +11,16 @@ import { glyphSize } from '../hooks/glyphLadders.js'
|
|
|
11
11
|
* variant="outline" — bordered, transparent bg — THE secondary
|
|
12
12
|
* treatment (2026-07-08 chrome law: one
|
|
13
13
|
* secondary, always subordinate to filled)
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* `(text) => void`) it is kolbox's field (`useKolboxField`): Enter or leaving commits a
|
|
25
|
-
* changed value, Escape restores the value from before the edit and leaves, ArrowUp and
|
|
26
|
-
* ArrowDown step a number by 1 (Shift 10) and commit. Chrome in kol-theme `.kol-input--kolbox`.
|
|
27
|
-
* md with no `iconLeft` is 8 in, as sm (KolboxInputPlainTextField, 2026-11-28). `text`
|
|
28
|
-
* sets a field for words in the sans 11 / 16; unset, sm keeps the mono for values.
|
|
29
|
-
* variant="folio" — Folio's field (Folio migration batch A, 2026-11-22), carried class for class: a bare
|
|
30
|
-
* <input> 32 high, 16 in, radius 4, the rule line on the paper, the value JetBrains Mono
|
|
31
|
-
* 12 / 16 in the ink, the accent line focused; no shell, so the slots and `size` are not
|
|
32
|
-
* read and the width is the caller's `className`. Chrome in kol-theme `.kol-input--folio`.
|
|
14
|
+
* ONE INPUT, ITS LOOK THE THEME'S (plan-2026-11-29-one-set-fold W2): height, padding, gap, radius, the fill, the
|
|
15
|
+
* focus line, the value's and the affixes' type, the glyph's size and line are
|
|
16
|
+
* `--kol-input-*` (kol-theme kol-components-atoms.css, Input); the default theme leaves them
|
|
17
|
+
* unset and draws what the default path always drew, `data-theme-variant="kolbox"` sets
|
|
18
|
+
* kolbox's per size (sm the 24 field, md the rail's search 32, lg the search modal's 44).
|
|
19
|
+
* `variant="kolbox"` and `variant="folio"` are accepted and do nothing but keep their old
|
|
20
|
+
* default size, sm (their branches are in `_tmp/2026-11-29-one-set-fold/`).
|
|
21
|
+
* Every field: the press that focuses it selects its whole value, a second press places the
|
|
22
|
+
* caret; `hug` sizes the value to its text (a number field, its unit right after it); `text`
|
|
23
|
+
* marks a field for words (a theme may set its type, kolbox the sans 11 / 16).
|
|
33
24
|
* tone="inverse" — the dark chip (`fg-ab-24`) for a washed plane
|
|
34
25
|
* (ControlToneInverse, 2026-08-27); same prop on ViewToggle · Dropdown
|
|
35
26
|
* size="xs" — the panel rung (ControlsXsRung, 2026-09-01):
|
|
@@ -45,6 +36,9 @@ import { glyphSize } from '../hooks/glyphLadders.js'
|
|
|
45
36
|
* `type="number"` + `onCommit` the draft/commit
|
|
46
37
|
* number idiom outright (parse and clamp at the
|
|
47
38
|
* call site; fxr's NumberField, retired 2026-09-03).
|
|
39
|
+
* It is `useFieldCommit` (W2, adopted for every field): a changed value
|
|
40
|
+
* commits on Enter or leaving, Escape restores and leaves, ArrowUp and
|
|
41
|
+
* ArrowDown step a number by 1 (Shift 10) and commit.
|
|
48
42
|
* variant="ghost" — legacy alias, resolves to outline
|
|
49
43
|
* variant="property" — the Figma property field (PropertyField,
|
|
50
44
|
* 2026-08-12): filled chrome, dim `affordance`
|
|
@@ -88,17 +82,13 @@ import { glyphSize } from '../hooks/glyphLadders.js'
|
|
|
88
82
|
* Input owns prefix/suffix/icon layout + the inner <input> styling.
|
|
89
83
|
*/
|
|
90
84
|
|
|
91
|
-
/*
|
|
92
|
-
const
|
|
93
|
-
sm: { box: 'h-(--kol-kolbox-ctl) gap-1 px-2 focus-within:outline-1 focus-within:-outline-offset-1', icon: 16 },
|
|
94
|
-
md: { box: 'h-8 gap-2 px-1 focus-within:outline-1 focus-within:-outline-offset-1', icon: 18 },
|
|
95
|
-
lg: { box: 'h-11 gap-3 px-3', icon: 20 },
|
|
96
|
-
}
|
|
85
|
+
/* the old theme words in `variant`: accepted, nothing but their old default size (W2, on the retirement ledger) */
|
|
86
|
+
const THEME_WORDS = ['kolbox', 'folio']
|
|
97
87
|
|
|
98
88
|
const SIZE_TYPE = { xs: 'kol-mono-8', sm: 'kol-mono-12', md: 'kol-mono-14', lg: 'kol-mono-16' }
|
|
99
89
|
|
|
100
|
-
/*
|
|
101
|
-
A mousedown handler for any
|
|
90
|
+
/* a field's first press: the press that focuses a field selects its whole value; a press in a focused field places the
|
|
91
|
+
caret. A mousedown handler for any field <input> (ColorInputRow's hex and opacity take it too). */
|
|
102
92
|
export function selectOnFirstPress(e) {
|
|
103
93
|
const el = e.currentTarget
|
|
104
94
|
if (e.button !== 0 || document.activeElement === el || el.disabled || el.readOnly) return
|
|
@@ -107,7 +97,7 @@ export function selectOnFirstPress(e) {
|
|
|
107
97
|
el.select()
|
|
108
98
|
}
|
|
109
99
|
|
|
110
|
-
/*
|
|
100
|
+
/* the field's arrow step: a number, alone or with a unit after it (12, -4.5, 45°, 50%), moves by `by`; anything else
|
|
111
101
|
(a hex, a word, empty) does not step and gives null */
|
|
112
102
|
const STEPPABLE = /^\s*(-?\d*\.?\d+)\s*(°|%|px|pt|ms|s|x)?\s*$/
|
|
113
103
|
export function stepText(text, by) {
|
|
@@ -117,11 +107,11 @@ export function stepText(text, by) {
|
|
|
117
107
|
return `${Number((parseFloat(m[1]) + by).toFixed(places))}${m[2] ?? ''}`
|
|
118
108
|
}
|
|
119
109
|
|
|
120
|
-
/*
|
|
110
|
+
/* the field's commit, one place for every field (Input's own, ColorInputRow's hex and opacity, Slider's readout): a draft
|
|
121
111
|
while editing; Enter or leaving commits it, when it differs; Escape puts back the value from before the edit and
|
|
122
112
|
leaves the field; ArrowUp and ArrowDown step a number by 1, with Shift by 10, and commit at once (`step: false`
|
|
123
113
|
for a value that is not a number). `commit(text)` gets the trimmed text. Returns the <input>'s props. */
|
|
124
|
-
export function
|
|
114
|
+
export function useFieldCommit(value, commit, { step = true } = {}) {
|
|
125
115
|
const shown = value == null ? '' : String(value)
|
|
126
116
|
const [draft, setDraft] = useState(null)
|
|
127
117
|
const live = useRef(null)
|
|
@@ -148,6 +138,9 @@ export function useKolboxField(value, commit, { step = true } = {}) {
|
|
|
148
138
|
}
|
|
149
139
|
}
|
|
150
140
|
|
|
141
|
+
/** @deprecated 2026-11-29 → useFieldCommit (the same hook; plan-2026-11-29-one-set-fold W2, on the retirement ledger) */
|
|
142
|
+
export const useKolboxField = useFieldCommit
|
|
143
|
+
|
|
151
144
|
export default function Input({
|
|
152
145
|
type = 'text',
|
|
153
146
|
value,
|
|
@@ -176,8 +169,8 @@ export default function Input({
|
|
|
176
169
|
text = false,
|
|
177
170
|
...inputProps
|
|
178
171
|
}) {
|
|
179
|
-
/*
|
|
180
|
-
const size = sizeProp ?? (variant
|
|
172
|
+
/* md, or sm for a caller still passing an old theme word (its field was sm) */
|
|
173
|
+
const size = sizeProp ?? (THEME_WORDS.includes(variant) ? 'sm' : 'md')
|
|
181
174
|
const isNumber = type === 'number'
|
|
182
175
|
const fixedChars = typeof chars === 'number'
|
|
183
176
|
// The text-adjacent ladder — an Input's icon sits in the rung's line box
|
|
@@ -190,10 +183,11 @@ export default function Input({
|
|
|
190
183
|
// ghost folds into outline (2026-07-08 chrome law): one secondary treatment.
|
|
191
184
|
// property rides the filled chrome — it is a behaviour variant, not new paint.
|
|
192
185
|
const isProperty = variant === 'property'
|
|
193
|
-
const resolvedVariant = variant === 'ghost' ? 'outline' : isProperty ? 'filled' : variant
|
|
186
|
+
const resolvedVariant = variant === 'ghost' ? 'outline' : isProperty ? 'filled' : THEME_WORDS.includes(variant) ? undefined : variant
|
|
194
187
|
|
|
195
188
|
const shellCls = [
|
|
196
189
|
'kol-control',
|
|
190
|
+
'kol-input',
|
|
197
191
|
/* no variant → no modifier: the shell inherits a wrapper's tone, else filled (2026-09-03) */
|
|
198
192
|
resolvedVariant && `kol-control--${resolvedVariant}`,
|
|
199
193
|
`kol-control-${size}`,
|
|
@@ -203,6 +197,7 @@ export default function Input({
|
|
|
203
197
|
'cursor-text',
|
|
204
198
|
/* the dark chip on a washed plane (ControlToneInverse, kol-website 2026-08-27) */
|
|
205
199
|
toneClass(tone),
|
|
200
|
+
text && 'kol-input--text',
|
|
206
201
|
isProperty && 'w-full',
|
|
207
202
|
className,
|
|
208
203
|
].filter(Boolean).join(' ')
|
|
@@ -211,64 +206,14 @@ export default function Input({
|
|
|
211
206
|
* `${len}ch` hugs the value with no probe element, and stays number-safe
|
|
212
207
|
* where the HTML `size` attr is ignored (<input type="number">). +2px keeps
|
|
213
208
|
* the caret from clipping at the end. Tracks `value` → controlled only. */
|
|
214
|
-
/* commit-on-blur/Enter (ControlsXsRung, 2026-09-01
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
const
|
|
218
|
-
/* the ref mirrors the draft so a blur that lands in the same tick as the
|
|
219
|
-
* last keystroke commits what was typed, not the last RENDER's draft */
|
|
220
|
-
const draftRef = useRef(value ?? '')
|
|
221
|
-
const kolboxField = useKolboxField(value, onCommit)
|
|
222
|
-
useEffect(() => { if (onCommit) { setDraft(value ?? ''); draftRef.current = value ?? '' } }, [value, onCommit])
|
|
209
|
+
/* commit-on-blur/Enter (ControlsXsRung, 2026-09-01; the field's commit since W2): `useFieldCommit` keeps a draft
|
|
210
|
+
* while editing and drops it after the commit, so the field shows `value` again and a commit the caller REJECTED falls
|
|
211
|
+
* back to the last good value (kol-fxr's NumberField existed for that re-snap). `onChange` still fires live. */
|
|
212
|
+
const field = useFieldCommit(value, onCommit)
|
|
223
213
|
const commitProps = onCommit
|
|
224
|
-
? {
|
|
225
|
-
value: draft,
|
|
226
|
-
onChange: (e) => { draftRef.current = e.target.value; setDraft(e.target.value); onChange?.(e) },
|
|
227
|
-
/* RE-SNAP AFTER EVERY COMMIT, not only when `value` changes. The
|
|
228
|
-
* effect above re-syncs the draft on a value change — so a commit the
|
|
229
|
-
* caller REJECTED (invalid input, value kept) left the bad draft on
|
|
230
|
-
* screen, and `1` → `19` → `19x` showed `19x` after blur. kol-fxr's
|
|
231
|
-
* `NumberField` existed for exactly this line (34 lines wrapping this
|
|
232
|
-
* atom: commit, then `setDraft(String(value))`); with the re-snap here
|
|
233
|
-
* it is `<Input type="number" onCommit>` and no component
|
|
234
|
-
* (editor-panels-the-held-specs A8, 2026-09-03). The order matters —
|
|
235
|
-
* commit first, so a caller that DOES accept the value re-renders
|
|
236
|
-
* with the new prop and the effect wins over this fallback. */
|
|
237
|
-
onBlur: () => { onCommit(String(draftRef.current).trim()); draftRef.current = value ?? ''; setDraft(value ?? '') },
|
|
238
|
-
onKeyDown: (e) => {
|
|
239
|
-
if (e.key === 'Enter') e.currentTarget.blur()
|
|
240
|
-
if (e.key === 'Escape') { draftRef.current = value ?? ''; setDraft(value ?? ''); e.currentTarget.blur() }
|
|
241
|
-
},
|
|
242
|
-
}
|
|
214
|
+
? { ...field, onChange: (e) => { field.onChange(e); onChange?.(e) } }
|
|
243
215
|
: null
|
|
244
216
|
|
|
245
|
-
/* `variant="kolbox"` (plan-2026-11-18-kolbox-system W31.2 batch 3, 2026-11-18): kolbox's Input carried class for
|
|
246
|
-
* class, the chrome in kol-theme `.kol-input--kolbox`. Its sizes are its three fields: sm the field (`--kol-kolbox-ctl`, 24), md the rail's
|
|
247
|
-
* search (32), lg the search modal's (44). A slot that holds nothing is not drawn, so it takes no space. */
|
|
248
|
-
if (variant === 'kolbox') {
|
|
249
|
-
const k = KOLBOX_SIZE[size] ?? KOLBOX_SIZE.sm
|
|
250
|
-
/* md with no glyph sets plain words 8 from each edge, as sm does; the glyph is what insets md's text */
|
|
251
|
-
const box = size === 'md' && !iconLeft ? k.box.replace('px-1', 'px-2') : k.box
|
|
252
|
-
return (
|
|
253
|
-
<label className={`kol-input--kolbox kol-input--kolbox-${KOLBOX_SIZE[size] ? size : 'sm'}${text ? ' kol-input--kolbox-text' : ''} flex min-w-0 items-center has-disabled:opacity-40 ${box} ${className}`}>
|
|
254
|
-
{iconLeft && <IconLoader name={iconLeft} size={k.icon} className="kol-input-icon kol-kolbox-icon shrink-0" />}
|
|
255
|
-
{prefix !== undefined && <span className="kol-input-lead w-4 shrink-0">{prefix}</span>}
|
|
256
|
-
<input type={type} value={value} onChange={onChange} placeholder={placeholder} disabled={disabled} className={`kol-input-value min-w-0 ${hug ? 'field-sizing-content' : 'flex-1'} bg-transparent text-left outline-none`} {...inputProps}
|
|
257
|
-
{...(onCommit ? kolboxField : null)}
|
|
258
|
-
onMouseDown={(e) => { inputProps.onMouseDown?.(e); selectOnFirstPress(e) }} />
|
|
259
|
-
{suffix !== undefined && <span className="kol-input-suffix shrink-0">{suffix}</span>}
|
|
260
|
-
{slotRight}
|
|
261
|
-
</label>
|
|
262
|
-
)
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
/* `variant="folio"` (Folio migration batch A, 2026-11-22): Folio's text field carried class for class (apps/folio
|
|
266
|
-
* EditorChrome.jsx Input), the bare field with no shell, the chrome in kol-theme `.kol-input--folio`. The width is the
|
|
267
|
-
* caller's `className`. */
|
|
268
|
-
if (variant === 'folio') {
|
|
269
|
-
return <input type={type} value={value} onChange={onChange} placeholder={placeholder} disabled={disabled} {...inputProps} className={`kol-input--folio h-[32px] rounded-[4px] border px-[16px] outline-none ${className}`} />
|
|
270
|
-
}
|
|
271
|
-
|
|
272
217
|
const propertyLen = Math.max(String(value ?? placeholder ?? '').length, 1)
|
|
273
218
|
|
|
274
219
|
/* the error: a mark inside, a message under (row 36) */
|
|
@@ -292,14 +237,14 @@ export default function Input({
|
|
|
292
237
|
const heightCls = `${size === 'xs' ? 'h-3' : size === 'sm' ? 'h-4' : size === 'md' ? 'h-[18px]' : 'h-[22px]'} pointer-coarse:not-[.kol-hw-panel_*]:h-[22px]`
|
|
293
238
|
|
|
294
239
|
const inputCls = [
|
|
295
|
-
'min-w-0 bg-transparent border-none outline-none text-auto',
|
|
240
|
+
'kol-input-value min-w-0 bg-transparent border-none outline-none text-auto',
|
|
296
241
|
heightCls,
|
|
297
|
-
!fixedChars && !isProperty && 'flex-1',
|
|
242
|
+
hug ? 'field-sizing-content' : !fixedChars && !isProperty && 'flex-1',
|
|
298
243
|
/* Balance the dim prefix/suffix visual weight with extra inner padding
|
|
299
244
|
* on the opposite side. Without this the bright value sits closer to
|
|
300
|
-
* the affordance than to the empty edge, reads off-balance. */
|
|
301
|
-
prefix !== undefined && '
|
|
302
|
-
suffix !== undefined && '
|
|
245
|
+
* the affordance than to the empty edge, reads off-balance (`.kol-input-value--lead` / `--suffix`, the theme's). */
|
|
246
|
+
prefix !== undefined && 'kol-input-value--lead',
|
|
247
|
+
suffix !== undefined && 'kol-input-value--suffix',
|
|
303
248
|
isNumber && 'hide-number-spinners',
|
|
304
249
|
inputClassName,
|
|
305
250
|
].filter(Boolean).join(' ')
|
|
@@ -312,15 +257,15 @@ export default function Input({
|
|
|
312
257
|
aria-invalid={error ? true : undefined}
|
|
313
258
|
>
|
|
314
259
|
{slotLeft && (
|
|
315
|
-
<span className="flex items-center shrink-0
|
|
260
|
+
<span className="kol-input-slot flex items-center shrink-0">{slotLeft}</span>
|
|
316
261
|
)}
|
|
317
262
|
{iconLeft && (
|
|
318
|
-
<span aria-hidden="true" className="flex items-center
|
|
319
|
-
<IconLoader name={iconLeft} size={resolvedIconSize} />
|
|
263
|
+
<span aria-hidden="true" className="kol-input-icon flex items-center shrink-0">
|
|
264
|
+
<IconLoader name={iconLeft} size={iconSize ?? `var(--kol-input-icon, ${resolvedIconSize}px)`} />
|
|
320
265
|
</span>
|
|
321
266
|
)}
|
|
322
267
|
{prefix !== undefined && (
|
|
323
|
-
<span aria-hidden="true" className="
|
|
268
|
+
<span aria-hidden="true" className="kol-input-lead shrink-0">{prefix}</span>
|
|
324
269
|
)}
|
|
325
270
|
{affordance !== undefined && (
|
|
326
271
|
<span aria-hidden="true" className="text-meta pr-1.5 shrink-0 inline-flex items-center">{affordance}</span>
|
|
@@ -345,15 +290,16 @@ export default function Input({
|
|
|
345
290
|
{...inputProps}
|
|
346
291
|
/* the commit pair LAST, so nothing spread above it can shadow onBlur / onKeyDown */
|
|
347
292
|
{...(commitProps || {})}
|
|
293
|
+
onMouseDown={(e) => { inputProps.onMouseDown?.(e); selectOnFirstPress(e) }}
|
|
348
294
|
/>
|
|
349
295
|
{unit !== undefined && (
|
|
350
296
|
<span aria-hidden="true" className="text-meta shrink-0">{unit}</span>
|
|
351
297
|
)}
|
|
352
298
|
{suffix !== undefined && (
|
|
353
|
-
<span aria-hidden="true" className="
|
|
299
|
+
<span aria-hidden="true" className="kol-input-suffix shrink-0">{suffix}</span>
|
|
354
300
|
)}
|
|
355
301
|
{slotRight && (
|
|
356
|
-
<span className="flex items-center shrink-0
|
|
302
|
+
<span className="kol-input-trail flex items-center shrink-0 ml-auto">{slotRight}</span>
|
|
357
303
|
)}
|
|
358
304
|
{errorMark}
|
|
359
305
|
</label>
|