@kolkrabbi/kol-component 0.263.0 → 0.265.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/atoms/IconPlate.jsx +55 -0
- package/src/hooks/colorMath.js +25 -0
- package/src/index.js +6 -3
- package/src/organisms/ColorPickerPopover.jsx +127 -0
- package/src/organisms/CompareGrid.jsx +103 -0
- package/src/organisms/ShellSearchOverlay.jsx +20 -3
- package/src/organisms/ShortcutsOverlay.jsx +18 -2
- package/src/organisms/SpectrumControls.jsx +68 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kolkrabbi/kol-component",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.265.0",
|
|
4
4
|
"description": "The core component library",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"react-dom": "^18.3.0 || ^19.0.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@kolkrabbi/kol-icons": "^0.
|
|
41
|
+
"@kolkrabbi/kol-icons": "^0.39.0"
|
|
42
42
|
},
|
|
43
43
|
"files": [
|
|
44
44
|
"src",
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IconPlate — A glyph's specimen plate. The box IS the size: the ground, the keyline guide and the glyph
|
|
3
|
+
* share one square, so a 20 plate is 20px and the guide's lines are the glyph's own grid (CompareGridDevTab,
|
|
4
|
+
* kol-monitor 2026-10-17 — the icon gallery, the open-questions review and monitor's Dev tab each drew this
|
|
5
|
+
* plate by hand, and only one of the three sized it right).
|
|
6
|
+
*
|
|
7
|
+
* The ground is a SPECIMEN ground, literal on purpose: a light or dark plate the app theme never touches,
|
|
8
|
+
* so a glyph is judged on the same paper in either theme. The guide is the 24-unit keyline grid
|
|
9
|
+
* (Material-style: dashed diagonals, the three keyline rectangles, the centre circle).
|
|
10
|
+
*
|
|
11
|
+
* The plate draws no glyph of its own — pass one as children, sized to the plate (`<Icon size={size} />`,
|
|
12
|
+
* raw SVG markup, anything). `size="fill"` takes the parent's width and stays square.
|
|
13
|
+
*
|
|
14
|
+
* @param {number|'fill'} [size=24] the plate's edge in px, or 'fill'
|
|
15
|
+
* @param {'light'|'dark'} [ground='light']
|
|
16
|
+
* @param {boolean} [guide=false] the keyline grid behind the glyph
|
|
17
|
+
*/
|
|
18
|
+
export default function IconPlate({ size = 24, ground = 'light', guide = false, className = '', style, children, ...rest }) {
|
|
19
|
+
const light = ground !== 'dark'
|
|
20
|
+
const box = size === 'fill' ? { width: '100%', aspectRatio: '1 / 1' } : { width: size, height: size }
|
|
21
|
+
return (
|
|
22
|
+
<span
|
|
23
|
+
{...rest}
|
|
24
|
+
className={`relative inline-flex shrink-0 items-center justify-center overflow-hidden ${className}`.trim()}
|
|
25
|
+
style={{ ...box, background: light ? '#FFFFFF' : '#0E0E11', color: light ? '#0E0E11' : '#FFFFFF', ...style }}
|
|
26
|
+
>
|
|
27
|
+
{guide && <KeylineGuide light={light} />}
|
|
28
|
+
{children}
|
|
29
|
+
</span>
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* KeylineGuide — The 24-unit keyline grid. Fills its positioned parent; diagonals in teal, keylines in
|
|
35
|
+
* magenta on a light ground and yellow on a dark one.
|
|
36
|
+
*
|
|
37
|
+
* @param {boolean} [light=true] which ground it is drawn on
|
|
38
|
+
*/
|
|
39
|
+
export function KeylineGuide({ light = true }) {
|
|
40
|
+
const key = light ? '#CA3ABC' : '#F2D24B'
|
|
41
|
+
return (
|
|
42
|
+
<svg aria-hidden="true" width="100%" height="100%" viewBox="0 0 24 24" style={{ position: 'absolute', inset: 0, pointerEvents: 'none' }}>
|
|
43
|
+
<g stroke="#0A8DA4" strokeWidth="0.1" strokeDasharray="0.4 0.6" fill="none">
|
|
44
|
+
<path d="M0 0 L24 24" />
|
|
45
|
+
<path d="M24 0 L0 24" />
|
|
46
|
+
</g>
|
|
47
|
+
<g stroke={key} strokeWidth="0.1" strokeDasharray="0.4 0.6" fill="none">
|
|
48
|
+
<rect x="4" y="2" width="16" height="20" rx="1" />
|
|
49
|
+
<rect x="3" y="3" width="18" height="18" rx="1" />
|
|
50
|
+
<rect x="2" y="4" width="20" height="16" rx="1" />
|
|
51
|
+
<circle cx="12" cy="12" r="4" />
|
|
52
|
+
</g>
|
|
53
|
+
</svg>
|
|
54
|
+
)
|
|
55
|
+
}
|
package/src/hooks/colorMath.js
CHANGED
|
@@ -65,6 +65,31 @@ export function rgbToHex(r, g, b) {
|
|
|
65
65
|
.toUpperCase()
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
/* ── HSVA / hex — the picker's model (ColorPickerPopover, kol-monitor 2026-10-17) ── */
|
|
69
|
+
|
|
70
|
+
/** '#RRGGBB' | '#RRGGBBAA' → { hue 0–360, sat 0–100, val 0–100, alpha 0–1 }; null when unparsable. */
|
|
71
|
+
export function hexToHsva(hex) {
|
|
72
|
+
const m = /^#?([0-9a-f]{6})([0-9a-f]{2})?$/i.exec(hex ?? '')
|
|
73
|
+
if (!m) return null
|
|
74
|
+
const [r, g, b] = [0, 2, 4].map((i) => parseInt(m[1].slice(i, i + 2), 16) / 255)
|
|
75
|
+
const max = Math.max(r, g, b)
|
|
76
|
+
const d = max - Math.min(r, g, b)
|
|
77
|
+
const hue = d === 0 ? 0
|
|
78
|
+
: max === r ? 60 * (((g - b) / d) % 6)
|
|
79
|
+
: max === g ? 60 * ((b - r) / d + 2)
|
|
80
|
+
: 60 * ((r - g) / d + 4)
|
|
81
|
+
return { hue: normHue(hue), sat: max ? (d / max) * 100 : 0, val: max * 100, alpha: m[2] ? parseInt(m[2], 16) / 255 : 1 }
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** { hue, sat, val, alpha } → uppercase '#RRGGBB', or '#RRGGBBAA' when alpha < 1. */
|
|
85
|
+
export function hsvaToHex({ hue, sat, val, alpha = 1 }) {
|
|
86
|
+
const s = sat / 100
|
|
87
|
+
const v = val / 100
|
|
88
|
+
const f = (n) => { const k = (n + hue / 60) % 6; return (v - v * s * Math.max(0, Math.min(k, 4 - k, 1))) * 255 }
|
|
89
|
+
const hex = rgbToHex(f(5), f(3), f(1))
|
|
90
|
+
return alpha < 1 ? hex + Math.round(Math.max(0, alpha) * 255).toString(16).padStart(2, '0').toUpperCase() : hex
|
|
91
|
+
}
|
|
92
|
+
|
|
68
93
|
/** Wrap any hue into [0, 360). */
|
|
69
94
|
export const normHue = (h) => ((h % 360) + 360) % 360
|
|
70
95
|
|
package/src/index.js
CHANGED
|
@@ -35,6 +35,7 @@ export { default as DocsToc } from './molecules/DocsToc.jsx'
|
|
|
35
35
|
export { default as DropdownTagFilter } from './molecules/DropdownTagFilter.jsx'
|
|
36
36
|
export { default as EmptyState } from './molecules/EmptyState.jsx'
|
|
37
37
|
export { default as IconFrame } from './atoms/IconFrame.jsx'
|
|
38
|
+
export { default as IconPlate, KeylineGuide } from './atoms/IconPlate.jsx'
|
|
38
39
|
export { default as IconToggle } from './atoms/IconToggle.jsx'
|
|
39
40
|
export { default as ExitPreview } from './utilities/ExitPreview.jsx'
|
|
40
41
|
export { default as Figure } from './atoms/Figure.jsx'
|
|
@@ -127,10 +128,12 @@ export { default as ShapeDropdown } from './molecules/ShapeDropdown.jsx'
|
|
|
127
128
|
export { default as ShellDrawer } from './molecules/ShellDrawer.jsx'
|
|
128
129
|
export { default as ShellSearchOverlay } from './organisms/ShellSearchOverlay.jsx'
|
|
129
130
|
/* the keymap sheet — moved in from kol-shell 2026-09-28 so the workshop shell and the apps open ONE sheet on S */
|
|
130
|
-
export { default as ShortcutsOverlay } from './organisms/ShortcutsOverlay.jsx'
|
|
131
|
+
export { default as ShortcutsOverlay, shortcutInScope } from './organisms/ShortcutsOverlay.jsx'
|
|
131
132
|
export { default as Slider } from './molecules/Slider.jsx'
|
|
132
133
|
export { default as SpecList } from './molecules/SpecList.jsx'
|
|
133
|
-
export { default as SpectrumControls, HueStrip, SBSquare, WheelTriangle } from './organisms/SpectrumControls.jsx'
|
|
134
|
+
export { default as SpectrumControls, HueStrip, SBSquare, WheelTriangle, AlphaStrip } from './organisms/SpectrumControls.jsx'
|
|
135
|
+
export { default as ColorPickerPopover } from './organisms/ColorPickerPopover.jsx'
|
|
136
|
+
export { default as CompareGrid } from './organisms/CompareGrid.jsx'
|
|
134
137
|
export { default as SplitToolButton } from './molecules/SplitToolButton.jsx'
|
|
135
138
|
export { default as ToolPalette } from './organisms/ToolPalette.jsx'
|
|
136
139
|
export { default as DocumentEditor } from './organisms/DocumentEditor.jsx'
|
|
@@ -263,7 +266,7 @@ export { resolveCssVar, resolveCssColor, isLight } from './hooks/cssVar.js'
|
|
|
263
266
|
|
|
264
267
|
// color math (support module — HSL/hex conversion + harmony generation)
|
|
265
268
|
export {
|
|
266
|
-
hexToHsl, hslToHex, rgbToHex, normHue,
|
|
269
|
+
hexToHsl, hslToHex, rgbToHex, normHue, hexToHsva, hsvaToHex,
|
|
267
270
|
HARMONIES, harmonyById, harmonyColors, generateHarmony,
|
|
268
271
|
SEED_MODE_IDS, seedHarmony,
|
|
269
272
|
} from './hooks/colorMath.js'
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { useState } from 'react'
|
|
2
|
+
import ColorSwatch from '../molecules/ColorSwatch.jsx'
|
|
3
|
+
import Input from '../atoms/Input'
|
|
4
|
+
import { usePopover, PopoverPanel } from '../utilities/Popover.jsx'
|
|
5
|
+
import { HueStrip, SBSquare, AlphaStrip } from './SpectrumControls.jsx'
|
|
6
|
+
import { hexToHsva, hsvaToHex } from '../hooks/colorMath.js'
|
|
7
|
+
import { resolveCssColor } from '../hooks/cssVar.js'
|
|
8
|
+
|
|
9
|
+
/* taxonomy-ok: organism — composes the SpectrumControls family (an organism) with a swatch and the hex Input */
|
|
10
|
+
|
|
11
|
+
const SWATCH = { xs: 16, sm: 24 }
|
|
12
|
+
const PANEL_W = 180
|
|
13
|
+
|
|
14
|
+
/* the browser's computed `rgb()` / `rgba()` → '#RRGGBB(AA)' — for `currentColor` and tokens */
|
|
15
|
+
function cssToHex(css) {
|
|
16
|
+
const n = css.match(/[\d.]+/g)
|
|
17
|
+
if (!n || n.length < 3) return '#000000'
|
|
18
|
+
return hsvaToHex({ ...hexToHsva('#' + n.slice(0, 3).map((v) => Math.round(+v).toString(16).padStart(2, '0')).join('')), alpha: n[3] != null ? +n[3] : 1 })
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* ColorPickerPopover — A swatch that opens a colour picker. Click the swatch: a popover with the
|
|
23
|
+
* saturation square, hue and opacity strips, and the hex under them (ColorPickerPopover, kol-monitor
|
|
24
|
+
* 2026-10-17 — the estate's only click-a-colour-in picker was monitor's local react-colorful atom).
|
|
25
|
+
* Built on the KOL's own `SpectrumControls` family plus `AlphaStrip`, so no picker dependency.
|
|
26
|
+
*
|
|
27
|
+
* The swatch paints `color` live — a `var(--kol-*)` or `currentColor` follows the theme by CSS, no
|
|
28
|
+
* observer. Opening resolves it once against the swatch for the picker. Placement is `usePopover`'s:
|
|
29
|
+
* right-aligned under the swatch, flipping up where there is no room. Esc and an outside press close
|
|
30
|
+
* it; ⌥-click on the swatch resets to `defaultValue` instead of opening.
|
|
31
|
+
*
|
|
32
|
+
* @param {string} color '#RRGGBB' · '#RRGGBBAA' · 'transparent' / empty (none) · any CSS colour
|
|
33
|
+
* @param {Function} onChange (hex) => void — every drag, and every complete 6- or 8-digit hex typed.
|
|
34
|
+
* Uppercase; 8 digits only when opacity < 100%
|
|
35
|
+
* @param {string} [defaultValue] ⌥-click on the swatch resets to it
|
|
36
|
+
* @param {'xs'|'sm'} [size='xs'] swatch 16 · 24
|
|
37
|
+
* @param {string} [label='Color'] the swatch's accessible name
|
|
38
|
+
*/
|
|
39
|
+
export default function ColorPickerPopover({ color, onChange, defaultValue, size = 'xs', label = 'Color', className = '' }) {
|
|
40
|
+
const isNone = !color || color === 'transparent'
|
|
41
|
+
const [open, setOpen] = useState(false)
|
|
42
|
+
const [hsva, setHsva] = useState(null)
|
|
43
|
+
const [draft, setDraft] = useState('')
|
|
44
|
+
|
|
45
|
+
const popover = usePopover({
|
|
46
|
+
open,
|
|
47
|
+
placement: 'bottom-end',
|
|
48
|
+
offset: 4,
|
|
49
|
+
onOpenChange: (next, event) => {
|
|
50
|
+
if (next && event?.altKey) {
|
|
51
|
+
if (defaultValue !== undefined) onChange?.(defaultValue)
|
|
52
|
+
return
|
|
53
|
+
}
|
|
54
|
+
if (next) {
|
|
55
|
+
/* the working copy is HSVA, kept while open — so the hue survives a drag to grey */
|
|
56
|
+
const literal = isNone ? '#000000'
|
|
57
|
+
: hexToHsva(color) ? color
|
|
58
|
+
: cssToHex(resolveCssColor(color, popover.refs.reference.current))
|
|
59
|
+
const h = hexToHsva(literal) ?? { hue: 0, sat: 0, val: 0, alpha: 1 }
|
|
60
|
+
setHsva(h)
|
|
61
|
+
setDraft(hsvaToHex(h).slice(1))
|
|
62
|
+
}
|
|
63
|
+
setOpen(next)
|
|
64
|
+
},
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
const commit = (next) => {
|
|
68
|
+
setHsva(next)
|
|
69
|
+
const hex = hsvaToHex(next)
|
|
70
|
+
setDraft(hex.slice(1))
|
|
71
|
+
onChange?.(hex)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const onHex = (e) => {
|
|
75
|
+
const digits = e.target.value.replace(/[^0-9a-f]/gi, '').slice(0, 8).toUpperCase()
|
|
76
|
+
setDraft(digits)
|
|
77
|
+
const next = (digits.length === 6 || digits.length === 8) && hexToHsva(digits)
|
|
78
|
+
if (next) { setHsva(next); onChange?.('#' + digits) }
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const opaque = hsva && hsvaToHex({ ...hsva, alpha: 1 })
|
|
82
|
+
|
|
83
|
+
return (
|
|
84
|
+
<>
|
|
85
|
+
<button
|
|
86
|
+
type="button"
|
|
87
|
+
ref={popover.refs.setReference}
|
|
88
|
+
{...popover.getReferenceProps()}
|
|
89
|
+
aria-label={`${label}: ${isNone ? 'none' : color}`}
|
|
90
|
+
aria-expanded={open}
|
|
91
|
+
className={`inline-flex shrink-0 rounded focus-visible:outline-1 focus-visible:outline-offset-2 ${className}`}
|
|
92
|
+
>
|
|
93
|
+
<ColorSwatch
|
|
94
|
+
hex={isNone ? null : color}
|
|
95
|
+
size={SWATCH[size] ?? SWATCH.xs}
|
|
96
|
+
showTransparent={isNone}
|
|
97
|
+
transparentTone="error"
|
|
98
|
+
hoverable={false}
|
|
99
|
+
className="border border-[var(--kol-border-default)]"
|
|
100
|
+
/>
|
|
101
|
+
</button>
|
|
102
|
+
{open && hsva && (
|
|
103
|
+
<PopoverPanel
|
|
104
|
+
popover={popover}
|
|
105
|
+
panel={false}
|
|
106
|
+
className="bg-surface-secondary border border-fg-08 rounded p-2 flex flex-col gap-2 shadow-lg"
|
|
107
|
+
style={{ width: PANEL_W + 16 }}
|
|
108
|
+
>
|
|
109
|
+
<div className="rounded-[var(--kol-radius-xs)] overflow-hidden" style={{ width: PANEL_W, height: 140 }}>
|
|
110
|
+
<SBSquare hue={hsva.hue} sat={hsva.sat} val={hsva.val} onChange={(sat, val) => commit({ ...hsva, sat, val })} />
|
|
111
|
+
</div>
|
|
112
|
+
<HueStrip hue={hsva.hue} onChange={(hue) => commit({ ...hsva, hue })} />
|
|
113
|
+
<AlphaStrip alpha={hsva.alpha} color={opaque} onChange={(alpha) => commit({ ...hsva, alpha })} />
|
|
114
|
+
<Input
|
|
115
|
+
variant="filled"
|
|
116
|
+
size="sm"
|
|
117
|
+
prefix="#"
|
|
118
|
+
maxLength={8}
|
|
119
|
+
value={draft}
|
|
120
|
+
onChange={onHex}
|
|
121
|
+
aria-label={`${label} hex`}
|
|
122
|
+
/>
|
|
123
|
+
</PopoverPanel>
|
|
124
|
+
)}
|
|
125
|
+
</>
|
|
126
|
+
)
|
|
127
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { useMemo, useState } from 'react'
|
|
2
|
+
import IconPlate from '../atoms/IconPlate.jsx'
|
|
3
|
+
import IconToggle from '../atoms/IconToggle.jsx'
|
|
4
|
+
import Pill from '../atoms/Pill.jsx'
|
|
5
|
+
import SegmentedToggle from '../atoms/SegmentedToggle.jsx'
|
|
6
|
+
import ViewToggle from '../atoms/ViewToggle.jsx'
|
|
7
|
+
|
|
8
|
+
/* taxonomy-ok: organism — a toolbar of atoms over a wall of IconPlate pairs */
|
|
9
|
+
|
|
10
|
+
const SIZES = [24, 48, 96, 128]
|
|
11
|
+
const GROUNDS = [
|
|
12
|
+
{ value: 'dark', label: 'Dark ground', icon: 'mode-toggle-01' },
|
|
13
|
+
{ value: 'light', label: 'Light ground', icon: 'brightness' },
|
|
14
|
+
]
|
|
15
|
+
/* states are the consumer's words (monitor: same · redrawn · missing); shown capitalised, in the order
|
|
16
|
+
* they first appear */
|
|
17
|
+
const stateLabel = (s) => s.charAt(0).toUpperCase() + s.slice(1)
|
|
18
|
+
const ACTUAL = 16
|
|
19
|
+
|
|
20
|
+
/* a side is a node or a renderer `(ctx) => node`; ctx is `{ size, ground, guide }` */
|
|
21
|
+
const draw = (side, ctx) => (typeof side === 'function' ? side(ctx) : side)
|
|
22
|
+
|
|
23
|
+
function Side({ name, item, side, size, ground, guide, showActual }) {
|
|
24
|
+
const node = item[side]
|
|
25
|
+
const missing = node == null
|
|
26
|
+
return (
|
|
27
|
+
<span className="inline-flex flex-col items-center gap-2">
|
|
28
|
+
<IconPlate size={size} ground={ground} guide={guide && !missing}>
|
|
29
|
+
{missing ? <span className="kol-mono-10 opacity-60 px-1 text-center break-all">{item.candidate ?? item.label}</span> : draw(node, { size, ground, guide })}
|
|
30
|
+
</IconPlate>
|
|
31
|
+
<span className="flex items-center gap-2">
|
|
32
|
+
{showActual && !missing && <IconPlate size={ACTUAL} ground={ground}>{draw(node, { size: ACTUAL, ground, guide: false })}</IconPlate>}
|
|
33
|
+
<span className="kol-mono-12 text-meta">{name}</span>
|
|
34
|
+
</span>
|
|
35
|
+
</span>
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* CompareGrid — Two versions of many things, side by side. Each item is a pair of plates, A beside B, each
|
|
41
|
+
* side named in words, the item's name under the pair (CompareGridDevTab, kol-monitor 2026-10-17 — user:
|
|
42
|
+
* *"why are we inventing the wheel for this every time in multiple repos … the way you diff local vs DS is
|
|
43
|
+
* very confusing, its ill labeled, hard to read"*). The open-questions icon review was the readable one;
|
|
44
|
+
* this is it, for any two renderers.
|
|
45
|
+
*
|
|
46
|
+
* The toolbar is controls, not text: size (24 · 48 · 96 · 128), ground, guide, and a filter by state. A
|
|
47
|
+
* side draws at the chosen size on an `IconPlate`, with its real 16px size beside its name. A missing side
|
|
48
|
+
* is an empty plate carrying the item's name.
|
|
49
|
+
*
|
|
50
|
+
* @param {Array} items `[{ id, label, a, b, state?, candidate? }]` — `a` / `b` a node, or
|
|
51
|
+
* `({ size, ground, guide }) => node` (an Icon sized to `size`); `state` is the consumer's
|
|
52
|
+
* word ('same' · 'redrawn' · 'missing'), a chip and the filter; `candidate` names what an
|
|
53
|
+
* empty side would map to
|
|
54
|
+
* @param {Object} labels `{ a, b }` — what each side IS ("monitor" / "kol-icons", "old" / "new")
|
|
55
|
+
* @param {number} [defaultSize=96]
|
|
56
|
+
* @param {'light'|'dark'} [defaultGround='light']
|
|
57
|
+
* @param {boolean} [defaultGuide=true]
|
|
58
|
+
* @param {boolean} [showActual=true] the 16px real size beside each side's name
|
|
59
|
+
*/
|
|
60
|
+
export default function CompareGrid({ items = [], labels = { a: 'A', b: 'B' }, defaultSize = 96, defaultGround = 'light', defaultGuide = true, showActual = true, className = '' }) {
|
|
61
|
+
const [size, setSize] = useState(defaultSize)
|
|
62
|
+
const [ground, setGround] = useState(defaultGround)
|
|
63
|
+
const [guide, setGuide] = useState(defaultGuide)
|
|
64
|
+
const [filter, setFilter] = useState('all')
|
|
65
|
+
|
|
66
|
+
const states = useMemo(() => [...new Set(items.map((i) => i.state).filter(Boolean))], [items])
|
|
67
|
+
const counts = useMemo(() => Object.fromEntries(states.map((s) => [s, items.filter((i) => i.state === s).length])), [items, states])
|
|
68
|
+
const hasStates = states.length > 0
|
|
69
|
+
const shown = filter === 'all' ? items : items.filter((i) => i.state === filter)
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<div className={`flex flex-col gap-6 ${className}`.trim()}>
|
|
73
|
+
<div className="flex flex-wrap items-center gap-4">
|
|
74
|
+
<SegmentedToggle ariaLabel="Size" value={size} onChange={setSize} options={SIZES.map((v) => ({ value: v, label: String(v) }))} size="sm" />
|
|
75
|
+
<ViewToggle variant="icon" options={GROUNDS} viewMode={ground} onViewChange={setGround} />
|
|
76
|
+
<IconToggle icon="grid" label="Guide" title="Keyline guide" pressed={guide} onChange={setGuide} size="sm" />
|
|
77
|
+
{hasStates && (
|
|
78
|
+
<SegmentedToggle
|
|
79
|
+
ariaLabel="Show"
|
|
80
|
+
value={filter}
|
|
81
|
+
onChange={setFilter}
|
|
82
|
+
size="sm"
|
|
83
|
+
options={[{ value: 'all', label: `All ${items.length}` }, ...states.map((s) => ({ value: s, label: `${stateLabel(s)} ${counts[s]}` }))]}
|
|
84
|
+
/>
|
|
85
|
+
)}
|
|
86
|
+
</div>
|
|
87
|
+
<div className="grid gap-4" style={{ gridTemplateColumns: `repeat(auto-fill, minmax(min(100%, ${2 * size + 52}px), 1fr))` }}>
|
|
88
|
+
{shown.map((item) => (
|
|
89
|
+
<div key={item.id} className="flex flex-col items-center gap-3 rounded border border-fg-08 p-3">
|
|
90
|
+
<div className="flex items-start gap-3">
|
|
91
|
+
<Side name={labels.a} item={item} side="a" size={size} ground={ground} guide={guide} showActual={showActual} />
|
|
92
|
+
<Side name={labels.b} item={item} side="b" size={size} ground={ground} guide={guide} showActual={showActual} />
|
|
93
|
+
</div>
|
|
94
|
+
<span className="flex flex-wrap items-center justify-center gap-2">
|
|
95
|
+
<span className="kol-mono-12 text-emphasis">{item.label}</span>
|
|
96
|
+
{item.state && <Pill size="sm" variant={item.state === 'same' ? 'secondary' : 'primary'}>{stateLabel(item.state)}</Pill>}
|
|
97
|
+
</span>
|
|
98
|
+
</div>
|
|
99
|
+
))}
|
|
100
|
+
</div>
|
|
101
|
+
</div>
|
|
102
|
+
)
|
|
103
|
+
}
|
|
@@ -4,6 +4,8 @@ import SearchInput from '../molecules/SearchInput.jsx'
|
|
|
4
4
|
import Tag from '../atoms/Tag.jsx'
|
|
5
5
|
import Kbd from '../atoms/Kbd.jsx'
|
|
6
6
|
import OptionRow from '../molecules/OptionRow.jsx'
|
|
7
|
+
import Button from '../atoms/Button.jsx'
|
|
8
|
+
import { Tooltip } from '../utilities/Popover.jsx'
|
|
7
9
|
|
|
8
10
|
/* ONE COLUMN (2026-09-30): rows, headings and footer sit on the field's own
|
|
9
11
|
* geometry — the p-2 inset, then the md control's 1px ring + 16px pad — so
|
|
@@ -91,6 +93,10 @@ export function HighlightMatch({ label, query, ranges }) {
|
|
|
91
93
|
* @param {Function} [onOpenResults] (query) => void — ⌘/Ctrl+Enter: every hit, on the consumer's
|
|
92
94
|
* own results surface. Plain Enter keeps its meaning.
|
|
93
95
|
* @param {string} [resultsLabel] the footer's second line for ⌘Enter (e.g. `All results`)
|
|
96
|
+
* @param {Function} [onBack] a drill-in's way back (CommandOverlayModes, kol-monitor 2026-10-17): set, the
|
|
97
|
+
* field row leads with a back arrow, and Backspace on an empty field calls it —
|
|
98
|
+
* instead of a "← All" row that scrolls away with the list
|
|
99
|
+
* @param {string} [backLabel] the arrow's tooltip (default `Back`) — name where it goes ("All modules")
|
|
94
100
|
* @param {string} [selectLabel] the footer's Enter line while a row is highlighted (default
|
|
95
101
|
* `Go to page`) — a modal whose rows are not pages says what
|
|
96
102
|
* Enter does instead (the rack's module search: `Add module`)
|
|
@@ -117,6 +123,8 @@ export default function ShellSearchOverlay({
|
|
|
117
123
|
onOpenResults,
|
|
118
124
|
resultsLabel = 'All results',
|
|
119
125
|
selectLabel = 'Go to page',
|
|
126
|
+
onBack,
|
|
127
|
+
backLabel = 'Back',
|
|
120
128
|
}) {
|
|
121
129
|
const panelRef = useRef(null)
|
|
122
130
|
const listRef = useRef(null)
|
|
@@ -173,7 +181,10 @@ export default function ShellSearchOverlay({
|
|
|
173
181
|
const optionId = (item) => `${listId}-${item.id}`
|
|
174
182
|
|
|
175
183
|
const handleKeyDown = (e) => {
|
|
176
|
-
if (e.key === '
|
|
184
|
+
if (e.key === 'Backspace' && !query && onBack) {
|
|
185
|
+
e.preventDefault()
|
|
186
|
+
onBack()
|
|
187
|
+
} else if (e.key === 'Escape') {
|
|
177
188
|
e.preventDefault()
|
|
178
189
|
onClose?.()
|
|
179
190
|
} else if (e.key === 'ArrowDown') {
|
|
@@ -237,9 +248,15 @@ export default function ShellSearchOverlay({
|
|
|
237
248
|
)}
|
|
238
249
|
{/* A REAL FIELD, inset in the panel (2026-09-30, shadcn's search modal as
|
|
239
250
|
* the aim) — the flush `bare` strip read as a hole, not a control. */}
|
|
240
|
-
<div className="kol-tone-grey p-2">
|
|
251
|
+
<div className="kol-tone-grey p-2 flex items-center gap-2">
|
|
252
|
+
{onBack && (
|
|
253
|
+
<Tooltip label={backLabel}>
|
|
254
|
+
{/* mousedown keeps focus in the field, as the rows do */}
|
|
255
|
+
<Button iconOnly="arrow-left" tone="ghost" size="md" aria-label={backLabel} onMouseDown={(e) => e.preventDefault()} onClick={onBack} />
|
|
256
|
+
</Tooltip>
|
|
257
|
+
)}
|
|
241
258
|
<SearchInput
|
|
242
|
-
className="w-full"
|
|
259
|
+
className="w-full min-w-0 flex-1"
|
|
243
260
|
value={query}
|
|
244
261
|
onChange={(e) => onQueryChange?.(e.target.value)}
|
|
245
262
|
placeholder={chips.length > 0 ? 'Narrow these results…' : placeholder}
|
|
@@ -41,8 +41,16 @@ import SettingsSections from './SettingsSections.jsx'
|
|
|
41
41
|
*
|
|
42
42
|
* @param {Array} props.shortcuts - `[{ label, combo }]` or `[{ section, items: [{ id, label, combo }] }]` — the same array `SettingsShortcuts` takes (ShellHomeSystemMonitorGaps, kol-monitor 2026-08-27: the overlay read `keys` while the settings block read `combo`; `combo` is the name, `keys` is tolerated for a release)
|
|
43
43
|
* @param {Function} props.onClose
|
|
44
|
+
* @param {string} [props.currentPath] sections may carry `routes: ['/rack']` (CommandOverlayModes, kol-monitor
|
|
45
|
+
* 2026-10-17 — user: *"im in dev, how can I cable lock here?"*): with a path, the sections that work here come
|
|
46
|
+
* first and the rest sit muted under ELSEWHERE, never as if they worked here. A section without `routes`
|
|
47
|
+
* works everywhere. Bind keys from the same scope with `shortcutInScope`.
|
|
44
48
|
*/
|
|
45
49
|
|
|
50
|
+
/** Does a shortcut section work on `path`? No `routes` → everywhere; a route matches itself and below it. */
|
|
51
|
+
export const shortcutInScope = (section, path) => !section?.routes?.length || path == null
|
|
52
|
+
|| section.routes.some((r) => path === r || path.startsWith(`${r.replace(/\/$/, '')}/`))
|
|
53
|
+
|
|
46
54
|
const isSectioned = (list) => Array.isArray(list?.[0]?.items)
|
|
47
55
|
|
|
48
56
|
/* A shortcut as a settings ROW: the label on the left, the combo as the row's
|
|
@@ -57,7 +65,7 @@ const toRow = ({ label, combo, keys }) => ({
|
|
|
57
65
|
value: <span className="text-fg-32 kol-helper-12 sm:whitespace-nowrap">{combo ?? keys}</span>,
|
|
58
66
|
})
|
|
59
67
|
|
|
60
|
-
export default function ShortcutsOverlay({ shortcuts = [], onClose }) {
|
|
68
|
+
export default function ShortcutsOverlay({ shortcuts = [], onClose, currentPath }) {
|
|
61
69
|
useEffect(() => {
|
|
62
70
|
const onKey = (e) => { if (e.key === 'Escape') onClose?.() }
|
|
63
71
|
window.addEventListener('keydown', onKey)
|
|
@@ -65,6 +73,8 @@ export default function ShortcutsOverlay({ shortcuts = [], onClose }) {
|
|
|
65
73
|
}, [onClose])
|
|
66
74
|
|
|
67
75
|
const sectioned = isSectioned(shortcuts)
|
|
76
|
+
const here = sectioned ? shortcuts.filter((s) => shortcutInScope(s, currentPath)) : []
|
|
77
|
+
const elsewhere = sectioned ? shortcuts.filter((s) => !shortcutInScope(s, currentPath)) : []
|
|
68
78
|
|
|
69
79
|
return (
|
|
70
80
|
<div
|
|
@@ -95,9 +105,15 @@ export default function ShortcutsOverlay({ shortcuts = [], onClose }) {
|
|
|
95
105
|
>
|
|
96
106
|
<SettingsSections
|
|
97
107
|
sections={sectioned
|
|
98
|
-
?
|
|
108
|
+
? here.map(({ section, items = [] }) => ({ label: section, rowGap: 1, rows: items.map(toRow) }))
|
|
99
109
|
: [{ rowGap: 1, rows: shortcuts.map(toRow) }]}
|
|
100
110
|
/>
|
|
111
|
+
{elsewhere.length > 0 && (
|
|
112
|
+
<div className="flex flex-col gap-4 opacity-[var(--kol-opacity-disabled)]">
|
|
113
|
+
<span className="kol-helper-10 text-fg-48">ELSEWHERE</span>
|
|
114
|
+
<SettingsSections sections={elsewhere.map(({ section, items = [] }) => ({ label: section, rowGap: 1, rows: items.map(toRow) }))} />
|
|
115
|
+
</div>
|
|
116
|
+
)}
|
|
101
117
|
</div>
|
|
102
118
|
</div>
|
|
103
119
|
)
|
|
@@ -115,6 +115,74 @@ export function HueStrip({ hue, onChange }) {
|
|
|
115
115
|
)
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
+
/* the transparency checker behind an alpha ramp — literal greys, like the spectra (not themeable) */
|
|
119
|
+
const CHECKER = 'repeating-conic-gradient(#ccc 0% 25%, #fff 0% 50%) 0 0 / 8px 8px'
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* AlphaStrip — An opacity slider. HueStrip's twin for alpha: the colour ramped from transparent to
|
|
123
|
+
* opaque over a checker, same knob, same inset (ColorPickerPopover, kol-monitor 2026-10-17). Focus +
|
|
124
|
+
* Left/Right (or Down/Up) nudge alpha by 1% (role="slider").
|
|
125
|
+
*
|
|
126
|
+
* @param {number} alpha controlled alpha, 0–1
|
|
127
|
+
* @param {string} color the opaque colour the ramp ends on (any CSS colour)
|
|
128
|
+
* @param {Function} onChange (alpha: number) => void — fires on press, drag, and arrow keys
|
|
129
|
+
*/
|
|
130
|
+
export function AlphaStrip({ alpha, color, onChange }) {
|
|
131
|
+
const ref = useRef(null)
|
|
132
|
+
const dragging = useRef(false)
|
|
133
|
+
|
|
134
|
+
const update = useCallback((clientX) => {
|
|
135
|
+
const node = ref.current
|
|
136
|
+
if (!node) return
|
|
137
|
+
const rect = node.getBoundingClientRect()
|
|
138
|
+
const inner = rect.width - 2 * HANDLE_R
|
|
139
|
+
if (inner <= 0) return
|
|
140
|
+
onChange(Math.max(0, Math.min(1, (clientX - rect.left - HANDLE_R) / inner)))
|
|
141
|
+
}, [onChange])
|
|
142
|
+
|
|
143
|
+
useEffect(() => {
|
|
144
|
+
const onMove = (e) => { if (dragging.current) update(e.clientX) }
|
|
145
|
+
const onUp = () => { dragging.current = false }
|
|
146
|
+
window.addEventListener('pointermove', onMove)
|
|
147
|
+
window.addEventListener('pointerup', onUp)
|
|
148
|
+
window.addEventListener('pointercancel', onUp)
|
|
149
|
+
return () => {
|
|
150
|
+
window.removeEventListener('pointermove', onMove)
|
|
151
|
+
window.removeEventListener('pointerup', onUp)
|
|
152
|
+
window.removeEventListener('pointercancel', onUp)
|
|
153
|
+
}
|
|
154
|
+
}, [update])
|
|
155
|
+
|
|
156
|
+
const onKeyDown = (e) => {
|
|
157
|
+
let next = null
|
|
158
|
+
if (e.key === 'ArrowRight' || e.key === 'ArrowUp') next = Math.min(1, alpha + 0.01)
|
|
159
|
+
else if (e.key === 'ArrowLeft' || e.key === 'ArrowDown') next = Math.max(0, alpha - 0.01)
|
|
160
|
+
if (next === null) return
|
|
161
|
+
e.preventDefault()
|
|
162
|
+
onChange(next)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return (
|
|
166
|
+
<div
|
|
167
|
+
ref={ref}
|
|
168
|
+
role="slider"
|
|
169
|
+
tabIndex={0}
|
|
170
|
+
aria-label="Opacity"
|
|
171
|
+
aria-valuemin={0}
|
|
172
|
+
aria-valuemax={100}
|
|
173
|
+
aria-valuenow={Math.round(alpha * 100)}
|
|
174
|
+
onPointerDown={(e) => { dragging.current = true; update(e.clientX); e.preventDefault() }}
|
|
175
|
+
onKeyDown={onKeyDown}
|
|
176
|
+
className="relative rounded-[var(--kol-radius-xs)] cursor-pointer touch-none"
|
|
177
|
+
style={{ height: 12, background: `linear-gradient(to right, transparent, ${color}), ${CHECKER}` }}
|
|
178
|
+
>
|
|
179
|
+
<div className="absolute inset-y-0" style={{ left: HANDLE_R, right: HANDLE_R }}>
|
|
180
|
+
<Handle left={`${alpha * 100}%`} top="50%" />
|
|
181
|
+
</div>
|
|
182
|
+
</div>
|
|
183
|
+
)
|
|
184
|
+
}
|
|
185
|
+
|
|
118
186
|
/**
|
|
119
187
|
* SBSquare — Pick saturation and value on a square. 2D saturation/value picker: white→hue horizontal gradient with
|
|
120
188
|
* a black overlay fading upward, crosshair handle. Fills its container
|