@kolkrabbi/kol-component 0.383.0 → 0.384.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.383.0",
3
+ "version": "0.384.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-search": "^0.3.0",
36
- "@kolkrabbi/kol-growth": "^0.5.0",
37
- "@kolkrabbi/kol-markdown": "^0.2.0"
36
+ "@kolkrabbi/kol-markdown": "^0.2.0",
37
+ "@kolkrabbi/kol-growth": "^0.5.0"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "@kolkrabbi/kol-icons": ">=0.69.0",
@@ -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 KolboxGlyph from '../utilities/kolboxGlyph.jsx'
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
- * @param {'kolbox'} props.variant - also `kolbox` (plan-2026-11-18-kolbox-system W31.2 batch 3, 2026-11-18): kolbox's button, `--kol-kolbox-ctl` high (24), 12 in, radius 4, a 1px line, Inter 12 / 16 / 500, one size. Its grounds are tones: `primary` the accent with the on-accent ink (110% brightness on hover), `secondary` (also unset) the oq-16 field with the oq-24 line (the line's oq-24 on hover), `ghost` bare in oq-64 (the field and the ink on hover); `pressed` is its lit look (the accent tint, the accent ink) and sets aria-pressed. `iconLeft` is a 16 glyph 8 off the label. With `iconOnly` it is kolbox's icon button: a 28 box, the glyph in oq-64, the ink on hover over a 28 oq-16 frame drawn centred on the glyph, so a caller may set a 16 or 24 box and the frame still lights 28; `pressed` lights the frame in the accent tint with the accent glyph; `aria-pressed` is always set; `children` stand in for a glyph that is not an icon. The glyph is your icons by the set's name at 16 with the stroke lift (`.kol-kolbox-icon`, KolboxGlyph); `iconComponent` is not read here (C9.2: kolbox's data carries the set's names).
42
- * @param {'folio'} props.variant - also `folio` (Folio migration batch A, 2026-11-22): Folio's buttons carried class for class, the chrome in kol-theme `.kol-btn--folio` and `.kol-icon-btn--folio`, the colors Folio's (`--kol-folio-*`). `size` picks the shape: `md` (default) Folio's editor tool, 32 high, 10 in, radius 3, Inter 11, a 16 `iconLeft` 8 off the label; `lg` Folio's page action, 42 high, 16 in, radius 3, a 1px line, the label 12 / 600 and its `glyph` (a character, 16) 12 after it. Grounds are tones: `ghost` (md's default) bare in the ink, the surface on hover; `outline` (lg's default) the paper with the rule line; `primary` the accent fill with the paper ink. `pressed` is its lit look (the accent's soft ground and strong ink) and sets aria-pressed. With `iconOnly` it is Folio's tool icon: a 32 square at radius 4, the glyph 20, the paper on hover, lit when `pressed`. A press does not take the focus (`mousedown` is prevented), so the editor's selection stays.
43
- * @param {string} props.glyph - folio `lg` only: the character after the label (`+`, `⌄`, `→`)
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
- /* kolbox's grounds, by KOL's tone names; unset is its secondary. `outline` the line with no fill (Figma's browser
49
- top bar: Share, the adjust and star boxes, 2026-11-23) */
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 kolbox button names itself in a tooltip unless it already sits in one */
86
- const inTip = useContext(InTooltipKolbox)
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
- // Add size class — pairs the padding rule with its mono type class.
198
- const sizeClass = size === 'sm'
199
- ? 'kol-btn-sm kol-mono-12'
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={resolvedIconSize} />
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: resolvedIconSize, height: resolvedIconSize, overflow: 'hidden' }}>
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={resolvedIconSize}
250
- className="kol-icon-default"
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={resolvedIconSize}
256
- className="kol-icon-hover"
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 ?? 8 }}>
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
- if (onClick || !href) {
300
- return (
301
- <button
302
- onClick={onClick}
303
- type={type}
304
- className={combinedClass}
305
- style={mergedStyle}
306
- disabled={disabled}
307
- aria-pressed={pressed !== undefined ? pressed : (selected ? true : undefined)}
308
- aria-label={iconOnly ? (props['aria-label'] || 'Button') : undefined}
309
- {...props}
310
- >
311
- {renderContent()}
312
- </button>
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/index.js CHANGED
@@ -60,7 +60,7 @@ export { default as LabeledControl } from './molecules/LabeledControl.jsx'
60
60
  export { default as RailFloat, default as FloatModule } from './molecules/RailFloat.jsx'
61
61
  export { default as OverlayGlassPanel } from './utilities/OverlayGlassPanel.jsx'
62
62
  export { default as Pill } from './atoms/Pill.jsx'
63
- export { usePopover, PopoverPanel, PopoverLayer, Tooltip } from './utilities/Popover.jsx'
63
+ export { usePopover, PopoverPanel, PopoverLayer, Tooltip, InTooltip, InTooltip as InTooltipKolbox, PanelShell, PanelShell as KolboxShell } from './utilities/Popover.jsx'
64
64
  export { floatSurfaceClass, FLOAT_SURFACES } from './utilities/tone.js'
65
65
  export { floatMotion, FLOAT_MOTION } from './utilities/motion.js'
66
66
  /* armLongPress — the touch hold the panel value controls report (moved from kol-hardware 2026-10-01) */
@@ -170,7 +170,7 @@ function JoinedFolio({ value, onChange, options, ariaLabel, className }) {
170
170
  if (value == null) {
171
171
  return (
172
172
  <span role="group" aria-label={ariaLabel} className={`flex shrink-0 items-center ${className}`.trim()}>
173
- {options.map(({ icon, ariaLabel: name, pressed, onPress }) => <Button key={name} variant="folio" iconOnly={icon} aria-label={name} pressed={pressed} onClick={onPress} />)}
173
+ {options.map(({ icon, ariaLabel: name, pressed, onPress }) => <Button key={name} variant="folio" keepFocus iconOnly={icon} aria-label={name} pressed={pressed} onClick={onPress} />)}
174
174
  </span>
175
175
  )
176
176
  }