@kolkrabbi/kol-component 0.295.1 → 0.297.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.
@@ -44,6 +44,7 @@ import { Tooltip } from '../utilities/Popover.jsx'
44
44
  * @param {string} intro a note under the header (the approved drawer passes none)
45
45
  * @param {Function} onClose × · scrim · Escape
46
46
  * @param {ReactNode} footer the foot slot — `SettingsFooter` is the default shape
47
+ * @param {ReactNode} headerActions controls on the header line, before the × (the file rail's edit pencil, 2026-10-23)
47
48
  * @param {ReactNode} children the sections
48
49
  */
49
50
  export default function SettingsPanel({
@@ -55,11 +56,13 @@ export default function SettingsPanel({
55
56
  intro,
56
57
  onClose,
57
58
  footer,
59
+ headerActions,
58
60
  children,
59
61
  className = '',
60
62
  }) {
61
63
  const header = (
62
- <div className="flex min-w-0 flex-col">
64
+ <div className="flex min-w-0 items-center gap-2">
65
+ <div className="flex min-w-0 flex-1 flex-col">
63
66
  {/* THE APP REGISTER (SettingsPanelChromeAndColumnPreview, kol-r2b2 2026-08-27 —
64
67
  * user: "all wrong font styles"): the collection beside the panel is the
65
68
  * reference — helper-14 uppercase titles, the eyebrow for section labels,
@@ -67,6 +70,8 @@ export default function SettingsPanel({
67
70
  {title && <span className="kol-helper-14 uppercase text-emphasis">{title}</span>}
68
71
  {subtitle && <span className="kol-mono-12 text-meta">{subtitle}</span>}
69
72
  </div>
73
+ {headerActions}
74
+ </div>
70
75
  )
71
76
  const body = (
72
77
  <>
@@ -90,7 +95,7 @@ export default function SettingsPanel({
90
95
  >
91
96
  <div className="mb-6 flex items-center gap-4">
92
97
  <div className="min-w-0 flex-1">{header}</div>
93
- <CloseButton onClick={onClose} className="shrink-0" />
98
+ <CloseButton onClick={onClose} hover={false} className="shrink-0" />
94
99
  </div>
95
100
  <div className="flex flex-col gap-4"><Divider />{body}</div>
96
101
  </div>
@@ -107,7 +112,7 @@ export default function SettingsPanel({
107
112
  paints `bg-surface-primary`, the same token as the page, so the scrim was
108
113
  the only thing separating them — with it off the panel was invisible and
109
114
  the controls floated in the right third of the screen. */
110
- <Rail open={open} onClose={onClose} side="right" width={width} header={header} className={className} edge={false} shadow={false}>
115
+ <Rail open={open} onClose={onClose} side="right" width={width} header={header} className={className} edge={false} shadow={false} closeHover={false}>
111
116
  <div className="flex flex-col gap-4"><Divider />{body}</div>
112
117
  </Rail>
113
118
  )
@@ -185,7 +190,7 @@ export function LabeledControlSection({ label, divided = false, rowGap = 2, chil
185
190
  * falls back to primary — the same render wherever there is no wrapper. */
186
191
  export function SettingsChoice({ options = [], value, onChange, ariaLabel, tone = 'default', size = 'sm', variant, className = '' }) {
187
192
  const opts = options.map((o) => (o != null && typeof o === 'object' ? o : { value: o, label: String(o) }))
188
- return <Dropdown size={size} variant={variant} tone={tone} value={value} onChange={onChange} options={opts} className={`w-full ${className}`.trim()} aria-label={ariaLabel} />
193
+ return <Dropdown size={size} variant={variant} tone={tone} value={value} onChange={onChange} options={opts} className={`w-full ${className}`.trim()} ariaLabel={ariaLabel} />
189
194
  }
190
195
 
191
196
  /* THE CONTROL CHIP (SettingsPanelCompliance, user 2026-08-27: "WROOOONG" on the
@@ -268,15 +273,17 @@ export function SettingsChipRow({ options = [], selected = [], onToggle, allChip
268
273
  *
269
274
  * `gap-2` on the row (user 2026-08-28): `flex justify-end` with no gap is right
270
275
  * for one control and wrong for two — the chip and the reset icon touched. */
271
- export function SettingsFooter({ onReset, resetLabel = 'Reset to defaults', children }) {
276
+ export function SettingsFooter({ onReset, resetLabel = 'Reset to defaults', resetDisabled = false, children }) {
272
277
  return (
273
278
  <div className="flex flex-col gap-4">
274
279
  <Divider />
275
- <div className="flex justify-end items-center gap-2">
280
+ <div className="kol-ink-step flex justify-end items-center gap-2">
276
281
  {children}
277
- {onReset && (
278
- <Tooltip label={resetLabel}>
279
- <IconFrame name="refresh" variant="primary" size="sm" onClick={onReset} aria-label={resetLabel} />
282
+ {/* `resetDisabled`: the control stays in its place, dimmed and inert — one footer shape on every rail, whether or
283
+ * not the app has preferences to reset yet (user 2026-10-24: *"standardise what goes in"*) */}
284
+ {(onReset || resetDisabled) && (
285
+ <Tooltip label={resetDisabled ? 'Nothing to reset' : resetLabel}>
286
+ <IconFrame name="refresh" variant="nav" size="sm" onClick={resetDisabled ? undefined : onReset} aria-label={resetLabel} aria-disabled={resetDisabled || undefined} className={resetDisabled ? 'opacity-40 pointer-events-none' : ''} />
280
287
  </Tooltip>
281
288
  )}
282
289
  </div>
@@ -1,4 +1,23 @@
1
- import { LabeledControlSection, SettingsRow } from './SettingsPanel.jsx'
1
+ import { LabeledControlSection, SettingsChoice, SettingsRow, SettingsSwitch } from './SettingsPanel.jsx'
2
+
3
+ /* A STRING VALUE WEARS THE DS'S CLASS (user 2026-10-24, on Mirror's settings rail: *"YOU ARE USING A HELPER text for
4
+ * paragraphs"* — *"THIS SHOULDNT BE POSSIBLE if you were using a preset"*). A consumer that hands rows as data never
5
+ * picks a text class: a plain `value` is drawn in `kol-mono-12 text-body`, the file rail's and the shortcut rows' voice.
6
+ * A node passed as `value` is the consumer's and stays as given. */
7
+ const isText = (v) => typeof v === 'string' || typeof v === 'number'
8
+ const textValue = (v) => <span className="kol-mono-12 text-body">{v}</span>
9
+ /* a section's `note` — a sentence or two under the eyebrow, before the rows (Mirror's Memory, Monitor's Patches): mono-12
10
+ * in the meta ink, the panel's own intro voice. It wraps — the helper law is about helper text, and this is not helper */
11
+ const notes = (note) => (Array.isArray(note) ? note : [note]).map((n, i) => <p key={i} className="kol-mono-12 text-meta">{n}</p>)
12
+ /* the typed controls — the DS's, in the surface's tone; `render` stays the escape hatch for a control the DS has no word for */
13
+ const control = (row) => {
14
+ if (row.type === 'choice') return <SettingsChoice options={row.options ?? []} value={row.value} onChange={row.onChange} ariaLabel={row.ariaLabel ?? (typeof row.label === 'string' ? row.label : undefined)} />
15
+ if (row.type === 'switch') return <SettingsSwitch on={!!row.on} onChange={row.onChange} disabled={row.disabled} disabledHint={row.disabledHint} label={row.ariaLabel ?? (typeof row.label === 'string' ? row.label : undefined)} />
16
+ if (row.render) return row.render()
17
+ return isText(row.value) ? textValue(row.value) : row.value
18
+ }
19
+ /* a typed row's cell: a choice fills the value column, a switch sits at its end, text sits on the baseline */
20
+ const rowAlign = (row, fallback) => row.align ?? (row.type === 'choice' ? 'fill' : fallback)
2
21
 
3
22
  /**
4
23
  * SettingsSections — settings rows AS DATA, rendered once.
@@ -31,11 +50,16 @@ import { LabeledControlSection, SettingsRow } from './SettingsPanel.jsx'
31
50
  * text (a keyboard combo, a version string), which is what lets the shortcuts
32
51
  * sheet and the settings page's shortcut block be the same call.
33
52
  *
53
+ * TYPED ROWS (user 2026-10-24, on FXR's rail drawing its own sunken dropdown beside the reference's: *"we are literally
54
+ * avoiding this custom per repo shit"*): a row names its CONTROL as data and this draws it — `{ type: 'choice', options,
55
+ * value, onChange, ariaLabel? }` is a `SettingsChoice`, `{ type: 'switch', on, onChange, disabled?, disabledHint? }` a
56
+ * `SettingsSwitch` — in the surface's tone, never the consumer's. The Hub's rail takes typed rows and refuses `render`.
57
+ *
34
58
  * `divided` puts the hairline above a section — pass it on EVERY section, the
35
59
  * first included: the rule is `.kol-section--divided + .kol-section--divided`,
36
60
  * so the first draws nothing and skipping it just costs the next its line.
37
61
  *
38
- * @param {Array<{label?: string, rows: Array<{label: ReactNode, render?: Function, value?: ReactNode, hint?: string, align?: string, labelWidth?: number|'auto', text?: boolean, id?: string}>, rowGap?: number}>} sections - The settings body, in order (`hint` → SettingsRow's hint)
62
+ * @param {Array<{label?: string, note?: string|string[], rows?: Array<{label: ReactNode, type?: 'choice'|'switch', options?: Array, value?: ReactNode, on?: boolean, onChange?: Function, render?: Function, hint?: string, align?: string, labelWidth?: number|'auto', text?: boolean, id?: string}>, rowGap?: number}>} sections - The settings body, in order (`hint` → SettingsRow's hint; `note` a sentence or two under the eyebrow; a string `value` is drawn in the DS's mono-12 and sits on the baseline; `type: 'choice'` / `'switch'` rows are drawn here)
39
63
  * @param {boolean} [divided=false] - Hairline above each section
40
64
  * @param {number|'auto'} [labelWidth] - Default label column for every row — `'auto'` makes the label yield and the control hug, which is what a narrow column or a nowrap value needs
41
65
  * @param {string} [align] - Default row alignment passed to `SettingsRow`
@@ -46,16 +70,17 @@ export default function SettingsSections({ sections = [], divided = false, label
46
70
  <div className={`kol-settings-sections flex flex-col gap-6 ${className}`.trim()}>
47
71
  {sections.map((sec, i) => (
48
72
  <LabeledControlSection key={sec.label ?? i} label={sec.label} divided={divided} rowGap={sec.rowGap}>
49
- {sec.rows.map((row, j) => (
73
+ {sec.note != null && notes(sec.note)}
74
+ {(sec.rows ?? []).map((row, j) => (
50
75
  <SettingsRow
51
76
  key={row.id ?? row.label ?? j}
52
77
  label={row.label}
53
78
  hint={row.hint}
54
- align={row.align ?? align}
79
+ align={rowAlign(row, align)}
55
80
  labelWidth={row.labelWidth ?? labelWidth}
56
- text={row.text}
81
+ text={row.text ?? (!row.render && !row.type && isText(row.value))}
57
82
  >
58
- {row.render ? row.render() : row.value}
83
+ {control(row)}
59
84
  </SettingsRow>
60
85
  ))}
61
86
  </LabeledControlSection>
@@ -0,0 +1,39 @@
1
+ /**
2
+ * imageToDataUrl — a picked image file as a small data URL, for a card's cover (the file rail's Upload
3
+ * image, 2026-10-24 — plan home-library-detail-one-card 2.2). Decodes the file, fits it inside `max`
4
+ * on its longer side, encodes webp at `quality`. What the editor's `captureThumb` writes for a save,
5
+ * for a picture the user supplies.
6
+ *
7
+ * @param {File} file
8
+ * @param {Object} [opts]
9
+ * @param {number} [opts.max=640] the longer side, px
10
+ * @param {number} [opts.quality=0.82]
11
+ * @returns {Promise<string>} `data:image/webp;base64,…`
12
+ */
13
+ export default async function imageToDataUrl(file, { max = 640, quality = 0.82 } = {}) {
14
+ const bitmap = await createImageBitmap(file)
15
+ const scale = Math.min(1, max / Math.max(bitmap.width, bitmap.height))
16
+ const w = Math.max(1, Math.round(bitmap.width * scale))
17
+ const h = Math.max(1, Math.round(bitmap.height * scale))
18
+ const canvas = document.createElement('canvas')
19
+ canvas.width = w
20
+ canvas.height = h
21
+ canvas.getContext('2d').drawImage(bitmap, 0, 0, w, h)
22
+ bitmap.close?.()
23
+ return canvas.toDataURL('image/webp', quality)
24
+ }
25
+
26
+ /** pickImage — opens the file chooser for one image and resolves with its data URL, or null when cancelled. */
27
+ export function pickImage(opts) {
28
+ return new Promise((resolve) => {
29
+ const input = document.createElement('input')
30
+ input.type = 'file'
31
+ input.accept = 'image/*'
32
+ input.onchange = async () => {
33
+ const f = input.files?.[0]
34
+ resolve(f ? await imageToDataUrl(f, opts).catch(() => null) : null)
35
+ }
36
+ input.oncancel = () => resolve(null)
37
+ input.click()
38
+ })
39
+ }