@kolkrabbi/kol-component 0.384.0 → 0.386.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/Input.jsx +46 -100
- package/src/atoms/Kbd.jsx +15 -25
- package/src/atoms/Textarea.jsx +14 -15
- package/src/atoms/ToggleCheckbox.jsx +8 -23
- package/src/atoms/ToggleSwitch.jsx +13 -42
- package/src/atoms/XYPad.jsx +12 -31
- package/src/molecules/FieldPair.jsx +20 -40
- package/src/molecules/LabeledControl.jsx +20 -51
- package/src/molecules/QuantityInput.jsx +37 -46
- package/src/molecules/Slider.jsx +48 -111
package/src/atoms/XYPad.jsx
CHANGED
|
@@ -29,9 +29,11 @@ import { useRef } from 'react'
|
|
|
29
29
|
* @param {Function} onChange - `(x, y) => void` on pointer down and on every move while a button is held — the caller coalesces if it wants one patch per gesture
|
|
30
30
|
* @param {ReactNode} xLabel - Left label above the pad
|
|
31
31
|
* @param {ReactNode} yLabel - Right label above the pad
|
|
32
|
-
* @param {'default'|'kolbox'} [variant
|
|
33
|
-
*
|
|
34
|
-
*
|
|
32
|
+
* @param {'default'|'kolbox'} [variant] - accepted and nothing (plan-2026-11-29-one-set-fold W2 run 2, on the retirement
|
|
33
|
+
* ledger): one pad, its look the theme's. The labels' type and ink, the ground, its line and radius, the guides and the
|
|
34
|
+
* puck are `--kol-xy-*` (kol-theme); the default theme leaves them unset, `data-theme-variant="kolbox"` sets kolbox's
|
|
35
|
+
* (no line, the field's ground at radius 4, 1px guides in the edge, the puck in the ink, the labels Inter 11 / 15 in
|
|
36
|
+
* oq-64). Every pad takes `w-full min-w-0`, as kolbox's did. The old branch is in `_tmp/2026-11-29-one-set-fold/`.
|
|
35
37
|
* @param {string} [className] - Extra classes on the wrapper
|
|
36
38
|
*/
|
|
37
39
|
export default function XYPad({
|
|
@@ -41,7 +43,6 @@ export default function XYPad({
|
|
|
41
43
|
onChange,
|
|
42
44
|
xLabel,
|
|
43
45
|
yLabel,
|
|
44
|
-
variant = 'default',
|
|
45
46
|
className = '',
|
|
46
47
|
}) {
|
|
47
48
|
const ref = useRef(null)
|
|
@@ -70,30 +71,10 @@ export default function XYPad({
|
|
|
70
71
|
const puckX = ((xValue - xMin) / span(xMax, xMin)) * 100
|
|
71
72
|
const puckY = (1 - (yValue - yMin) / span(yMax, yMin)) * 100
|
|
72
73
|
|
|
73
|
-
|
|
74
|
-
return (
|
|
75
|
-
<div className={`kol-xy-pad--kolbox flex w-full min-w-0 flex-col gap-1 ${className}`.trim()}>
|
|
76
|
-
<div className="kol-xy-pad-labels flex justify-between">
|
|
77
|
-
<span>{xLabel}</span>
|
|
78
|
-
<span>{yLabel}</span>
|
|
79
|
-
</div>
|
|
80
|
-
<div
|
|
81
|
-
ref={ref}
|
|
82
|
-
onPointerDown={onPointerDown}
|
|
83
|
-
onPointerMove={onPointerMove}
|
|
84
|
-
className="kol-xy-pad relative aspect-square w-full cursor-crosshair touch-none"
|
|
85
|
-
>
|
|
86
|
-
<div className="kol-xy-pad-guide absolute inset-x-0 top-1/2 h-px" />
|
|
87
|
-
<div className="kol-xy-pad-guide absolute inset-y-0 left-1/2 w-px" />
|
|
88
|
-
<div className="kol-xy-pad-puck pointer-events-none absolute -mt-1.5 -ml-1.5 size-3 rounded-full" style={{ left: `${puckX}%`, top: `${puckY}%` }} />
|
|
89
|
-
</div>
|
|
90
|
-
</div>
|
|
91
|
-
)
|
|
92
|
-
}
|
|
93
|
-
|
|
74
|
+
/* one pad, its look the theme's (`--kol-xy-*`, kol-theme kol-components-atoms.css, XYPad) */
|
|
94
75
|
return (
|
|
95
|
-
<div className={`flex flex-col gap-1 ${className}`.trim()}>
|
|
96
|
-
<div className="
|
|
76
|
+
<div className={`kol-xy flex w-full min-w-0 flex-col gap-1 ${className}`.trim()}>
|
|
77
|
+
<div className="kol-xy-pad-labels flex justify-between">
|
|
97
78
|
<span>{xLabel}</span>
|
|
98
79
|
<span>{yLabel}</span>
|
|
99
80
|
</div>
|
|
@@ -101,14 +82,14 @@ export default function XYPad({
|
|
|
101
82
|
ref={ref}
|
|
102
83
|
onPointerDown={onPointerDown}
|
|
103
84
|
onPointerMove={onPointerMove}
|
|
104
|
-
className="relative w-full aspect-square
|
|
85
|
+
className="kol-xy-pad relative w-full aspect-square cursor-crosshair touch-none"
|
|
105
86
|
>
|
|
106
87
|
{/* crosshair guides */}
|
|
107
|
-
<div className="absolute inset-x-0 top-1/2
|
|
108
|
-
<div className="absolute inset-y-0 left-1/2
|
|
88
|
+
<div className="kol-xy-pad-guide absolute inset-x-0 top-1/2 h-px" />
|
|
89
|
+
<div className="kol-xy-pad-guide absolute inset-y-0 left-1/2 w-px" />
|
|
109
90
|
{/* puck */}
|
|
110
91
|
<div
|
|
111
|
-
className="
|
|
92
|
+
className="kol-xy-pad-puck absolute pointer-events-none"
|
|
112
93
|
style={{ left: `${puckX}%`, top: `${puckY}%` }}
|
|
113
94
|
/>
|
|
114
95
|
</div>
|
|
@@ -5,56 +5,36 @@ import Input from '../atoms/Input.jsx'
|
|
|
5
5
|
* two-up position fields). Two `Input`s 8 apart, each led by its letter (`prefix`), sharing one `variant` and `size`;
|
|
6
6
|
* the pair fills its row, each field half. A position, a size, a range — any two values that are read together.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* ONE PAIR (plan-2026-11-29-one-set-fold W2, slots adopted for everyone; kolbox's PropertyRow, Figma 70:12121): two slots,
|
|
9
|
+
* `first` and `second`, then `trailing` (icons or a tag); `fields` fills the two slots with Inputs. THE RAIL'S ONE GRID
|
|
10
|
+
* (plan-2026-11-19-kolbox-whats-left R3.1): the row is a grid on `--kol-kolbox-row-cols`, the tracks
|
|
11
11
|
* LabeledControlSection kolbox sets for every row it holds: two field columns and two 16 icon columns, 8 apart (in the
|
|
12
12
|
* 240 rail: 76, 76, 16, 16, his design's Stroke row, 149:26890). `first` takes column 1 (`span`: columns 1 and 2, a
|
|
13
13
|
* row of one field), `second` column 2, `trailing` the icon columns from the right, so a lone icon sits on the last and
|
|
14
|
-
* a pair on both. Outside a section the tracks are
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* radius 4, padded 16, Folio's hairline round each (green while it has focus), each led by its `prefix` in the muted
|
|
19
|
-
* ink; the value in mono 12 / 16. `fields` as the default's, each a plain input's props. Chrome in kol-theme
|
|
20
|
-
* `.kol-field-pair--folio`.
|
|
14
|
+
* a pair on both. Outside a section the tracks are the theme's `--kol-field-pair-cols` (unset: two equal columns, and
|
|
15
|
+
* the trailing's own width after them when there is one; kolbox always keeps that third column). Each control fills its
|
|
16
|
+
* cell. It draws nothing of its own; the wrapper carries `data-property-row`. `variant="kolbox"` and `variant="folio"`
|
|
17
|
+
* are accepted and do nothing (their branches are in `_tmp/2026-11-29-one-set-fold/`; folio's own fields are two Inputs).
|
|
21
18
|
*
|
|
22
19
|
* @param {Array} fields two Input prop sets — `[{ prefix: 'X', value, onChange, ... }, { prefix: 'Y', ... }]`
|
|
23
|
-
* @param {'filled'|'outline'
|
|
20
|
+
* @param {'filled'|'outline'} [variant] passed to both `fields` Inputs
|
|
24
21
|
* @param {'sm'|'md'|'lg'} [size] passed to both
|
|
25
|
-
* @param {ReactNode} [first]
|
|
26
|
-
* @param {ReactNode} [second]
|
|
27
|
-
* @param {ReactNode} [trailing]
|
|
28
|
-
* @param {boolean} [span]
|
|
22
|
+
* @param {ReactNode} [first] the left cell (in place of `fields[0]`)
|
|
23
|
+
* @param {ReactNode} [second] the right cell (in place of `fields[1]`)
|
|
24
|
+
* @param {ReactNode} [trailing] the icon columns
|
|
25
|
+
* @param {boolean} [span] `first` spans both field columns
|
|
29
26
|
* @param {string} [className]
|
|
30
27
|
*/
|
|
31
28
|
export default function FieldPair({ fields = [], variant, size, first, second, trailing, span = false, className = '', ...rest }) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
{!span && <div className="flex min-w-0">{second}</div>}
|
|
37
|
-
{trailing && <div className="col-start-3 -col-end-1 flex items-center justify-end gap-2">{trailing}</div>}
|
|
38
|
-
</div>
|
|
39
|
-
)
|
|
40
|
-
}
|
|
41
|
-
if (variant === 'folio') {
|
|
42
|
-
return (
|
|
43
|
-
<div {...rest} className={`kol-field-pair--folio flex items-center gap-[8px] ${className}`.trim()}>
|
|
44
|
-
{fields.map(({ prefix, ...f }) => (
|
|
45
|
-
<label key={prefix} className="kol-field-pair-field flex h-[32px] min-w-0 flex-1 items-center rounded-[4px] border px-[16px]">
|
|
46
|
-
<span className="kol-field-pair-prefix shrink-0 pr-[4px]">{prefix}</span>
|
|
47
|
-
<input {...f} className="min-w-0 flex-1 bg-transparent outline-none" />
|
|
48
|
-
</label>
|
|
49
|
-
))}
|
|
50
|
-
</div>
|
|
51
|
-
)
|
|
52
|
-
}
|
|
29
|
+
const field = (f, i) => f && <Input key={f.key ?? f.prefix ?? i} variant={variant} size={size} width="100%" className="flex-1 min-w-0" {...f} />
|
|
30
|
+
const one = first ?? field(fields[0], 0)
|
|
31
|
+
const two = second ?? field(fields[1], 1)
|
|
32
|
+
const cols = trailing ? 'minmax(0,1fr) minmax(0,1fr) auto' : 'minmax(0,1fr) minmax(0,1fr)'
|
|
53
33
|
return (
|
|
54
|
-
<div className={`
|
|
55
|
-
{
|
|
56
|
-
|
|
57
|
-
|
|
34
|
+
<div {...rest} className={`grid min-w-0 items-center gap-2 ${className}`.trim()} style={{ gridTemplateColumns: `var(--kol-kolbox-row-cols, var(--kol-field-pair-cols, ${cols}))`, ...rest.style }} data-property-row>
|
|
35
|
+
<div className={`flex min-w-0 ${span ? 'col-span-2' : ''}`}>{one}</div>
|
|
36
|
+
{!span && <div className="flex min-w-0">{two}</div>}
|
|
37
|
+
{trailing && <div className="col-start-3 -col-end-1 flex items-center justify-end gap-2">{trailing}</div>}
|
|
58
38
|
</div>
|
|
59
39
|
)
|
|
60
40
|
}
|
|
@@ -37,15 +37,15 @@
|
|
|
37
37
|
* `'settings'` (plan-2026-11-12-float-rails-figma W13.1): the generator settings window's row (`Dialog
|
|
38
38
|
* variant="settings"`): the label in Inter 10 at oq-64, 6 over the control; `horizontal` puts it beside the
|
|
39
39
|
* control, 8 apart, the label hugging its text (a `labelWidth` still sets a column).
|
|
40
|
-
* `'kolbox'` (plan-2026-11-
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
40
|
+
* `'kolbox'` and `'folio'` are accepted and do nothing (plan-2026-11-29-one-set-fold W2; their branches are
|
|
41
|
+
* in `_tmp/2026-11-29-one-set-fold/`): the look is the theme's. The label's type and ink, its column, the gaps,
|
|
42
|
+
* the row's least height and the body are `--kol-label-*` (kol-theme kol-components-molecules.css,
|
|
43
|
+
* LabeledControl); the default theme leaves them unset, `data-theme-variant="kolbox"` sets kolbox's (the label
|
|
44
|
+
* the UI text 11 / 16 at the label weight in oq-64, horizontal a 76 column 8 from the control and the row at
|
|
45
|
+
* least 24, the control cell a row 8 apart; stacked the label 4 over a row of controls 4 apart).
|
|
46
|
+
* controlFirst — bool: the control at the left, inset 4, then 8 apart its label (a checkbox row, kolbox's Clip content
|
|
47
|
+
* row), the row as tall as its control. The label is the help type (`--kol-label-help-*`; kolbox 11 / 15 in
|
|
48
|
+
* oq-64, unset the row's own).
|
|
49
49
|
* labelClass — the label's type and ink, replacing the variant's (a row that keeps its own label look: Slider's
|
|
50
50
|
* kol-helper-12, a toggle's words in the settings ink). On `panel` it defaults to kol-helper-8.
|
|
51
51
|
* children — the control body.
|
|
@@ -73,44 +73,11 @@ export default function LabeledControl({
|
|
|
73
73
|
controlFirst = false,
|
|
74
74
|
...rest
|
|
75
75
|
}) {
|
|
76
|
-
if (
|
|
77
|
-
const mark = { 'data-labeled-control': '', ...rest }
|
|
78
|
-
if (controlFirst) {
|
|
79
|
-
return (
|
|
80
|
-
<div {...mark} className={`kol-labeled-control--kolbox flex items-center gap-2 pl-1 ${className}`.trim()}>
|
|
81
|
-
{children}
|
|
82
|
-
<span className="kol-labeled-control-help min-w-0 flex-1 truncate">{label}</span>
|
|
83
|
-
</div>
|
|
84
|
-
)
|
|
85
|
-
}
|
|
86
|
-
if (!(horizontal ?? inline ?? false)) {
|
|
87
|
-
return (
|
|
88
|
-
<div {...mark} className={`kol-labeled-control--kolbox flex flex-col gap-1 ${className}`.trim()}>
|
|
89
|
-
<span className="kol-labeled-control-label">{label}</span>
|
|
90
|
-
<div className="flex min-w-0 items-center gap-1">{children}</div>
|
|
91
|
-
</div>
|
|
92
|
-
)
|
|
93
|
-
}
|
|
76
|
+
if (controlFirst) {
|
|
94
77
|
return (
|
|
95
|
-
<div {...
|
|
96
|
-
<span className={`kol-labeled-control-label ${labelWidth == null ? 'w-19 ' : ''}shrink-0 truncate`} style={labelWidth == null ? undefined : { width: labelWidth }}>{label}</span>
|
|
97
|
-
<div className="flex min-w-0 flex-1 items-center gap-2">{children}</div>
|
|
98
|
-
</div>
|
|
99
|
-
)
|
|
100
|
-
}
|
|
101
|
-
if (variant === 'folio') {
|
|
102
|
-
if (horizontal ?? inline ?? false) {
|
|
103
|
-
return (
|
|
104
|
-
<div {...rest} className={`kol-labeled-control--folio flex items-center gap-[12px] ${className}`.trim()}>
|
|
105
|
-
<p className="kol-labeled-control-label w-[48px] shrink-0">{label}</p>
|
|
106
|
-
<div className="flex min-w-0 flex-1 items-center">{children}</div>
|
|
107
|
-
</div>
|
|
108
|
-
)
|
|
109
|
-
}
|
|
110
|
-
return (
|
|
111
|
-
<div {...rest} className={`kol-labeled-control--folio flex flex-col gap-[8px] ${className}`.trim()}>
|
|
112
|
-
<p className="kol-labeled-control-title">{label}</p>
|
|
78
|
+
<div data-labeled-control="" {...rest} className={`flex items-center gap-2 pl-1 ${className}`.trim()}>
|
|
113
79
|
{children}
|
|
80
|
+
<span className="kol-labeled-control-help min-w-0 flex-1 truncate">{label}</span>
|
|
114
81
|
</div>
|
|
115
82
|
)
|
|
116
83
|
}
|
|
@@ -131,10 +98,12 @@ export default function LabeledControl({
|
|
|
131
98
|
}
|
|
132
99
|
const showLabel = !!label
|
|
133
100
|
const settings = variant === 'settings'
|
|
134
|
-
|
|
101
|
+
/* the column: the caller's, the settings row's hug, else the theme's (unset 48) */
|
|
102
|
+
const lw = labelWidth ?? (settings ? 'fit-content' : 'var(--kol-label-w, 48px)')
|
|
135
103
|
const gapClass = settings ? (horizontal ?? inline ? 'gap-2' : 'gap-1.5') : null
|
|
136
104
|
const mark = { 'data-labeled-control': '', ...rest }
|
|
137
|
-
|
|
105
|
+
/* the label's own type is the theme's (`.kol-labeled-control-label`, unset kol-helper-10 tracked in the meta ink) */
|
|
106
|
+
const labelType = labelClass ?? (settings ? SETTINGS_LABEL : 'kol-labeled-control-label')
|
|
138
107
|
/* a display class from the caller replaces the wrapper's own (`hidden md:flex` must hold) */
|
|
139
108
|
const display = DISPLAY.test(className) ? '' : 'flex'
|
|
140
109
|
/* …and so does a gap class: the caller's spacing, not two utilities racing */
|
|
@@ -158,7 +127,7 @@ export default function LabeledControl({
|
|
|
158
127
|
* showed as "C" or not at all. Label on its line, the value under it. */
|
|
159
128
|
const labelAuto = lw === 'auto'
|
|
160
129
|
return (
|
|
161
|
-
<div {...mark} className={`${display} ${labelAuto ? `flex-col items-start gap-1 sm:flex-row ${text ? 'sm:items-baseline' : 'sm:items-center'} sm:gap-3` :
|
|
130
|
+
<div {...mark} className={`${display} ${labelAuto ? `flex-col items-start gap-1 sm:flex-row ${text ? 'sm:items-baseline' : 'sm:items-center'} sm:gap-3` : `kol-labeled-control-row ${text ? 'items-baseline' : 'items-center'} ${ownGap ? '' : gapClass ?? ''}`}${className}`}>
|
|
162
131
|
{showLabel && (
|
|
163
132
|
<span
|
|
164
133
|
/* A LABEL NEVER WRAPS (review 2, § 6.2 — the helper law by construction, 01-foundations/03-typography.md:29):
|
|
@@ -169,17 +138,17 @@ export default function LabeledControl({
|
|
|
169
138
|
{labelInner}
|
|
170
139
|
</span>
|
|
171
140
|
)}
|
|
172
|
-
<div className={`${text ? 'flex ' : settings ? 'flex items-center ' : ''}${labelAuto ? 'min-w-0 max-w-full sm:overflow-hidden' : 'flex-1 min-w-0'}`}>{children}</div>
|
|
141
|
+
<div className={`${text ? 'flex ' : settings ? 'flex items-center ' : labelAuto ? '' : 'kol-labeled-control-cell '}${labelAuto ? 'min-w-0 max-w-full sm:overflow-hidden' : 'flex-1 min-w-0'}`}>{children}</div>
|
|
173
142
|
</div>
|
|
174
143
|
)
|
|
175
144
|
}
|
|
176
145
|
|
|
177
146
|
return (
|
|
178
|
-
<div {...mark} className={`${display} flex-col ${ownGap ? '' : gapClass ?? '
|
|
147
|
+
<div {...mark} className={`${display} flex-col ${settings ? '' : 'kol-labeled-control-stack'} ${ownGap ? '' : gapClass ?? ''} ${className}`}>
|
|
179
148
|
{showLabel && (
|
|
180
149
|
<span className={labelType}>{labelInner}</span>
|
|
181
150
|
)}
|
|
182
|
-
{children}
|
|
151
|
+
{settings ? children : <div className="kol-labeled-control-body">{children}</div>}
|
|
183
152
|
</div>
|
|
184
153
|
)
|
|
185
154
|
}
|
|
@@ -1,58 +1,53 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react'
|
|
2
|
+
import Input, { useFieldCommit, selectOnFirstPress } from '../atoms/Input.jsx'
|
|
3
|
+
import Button from '../atoms/Button.jsx'
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
|
-
* QuantityInput — Pick a whole-number quantity. a compact integer quantity picker with
|
|
6
|
+
* QuantityInput — Pick a whole-number quantity. a compact integer quantity picker with three control layouts.
|
|
5
7
|
*
|
|
6
8
|
* controls="chevron" (default) — value with a stacked up/down chevron pair
|
|
7
9
|
* on the right, inside a full-width field.
|
|
8
10
|
* controls="split" — a − value + pill (minus and plus flank the
|
|
9
11
|
* value). The former `QuantityStepper`.
|
|
12
|
+
* controls="field" — the value in an `Input` (sm) between two icon `Button`s, − and +
|
|
13
|
+
* (your icons' `minus` and `plus`), 4 apart, the root as wide as its row:
|
|
14
|
+
* kolbox's stepper, every theme's since W2 run 2 (their look the theme's).
|
|
10
15
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* (sm < 768 ≤ md < 1024 ≤ lg) unless `size` pins it. Controlled: `value` +
|
|
14
|
-
* `
|
|
16
|
+
* The value is typed in every layout (kolbox's, adopted in W2 run 2): Enter or leaving commits it, held to
|
|
17
|
+
* [min, max] and snapped to `step`; Escape restores; ArrowUp and ArrowDown step it. Size auto-adapts to the
|
|
18
|
+
* viewport (sm < 768 ≤ md < 1024 ≤ lg) unless `size` pins it. Controlled: `value` + `(next) => onChange`.
|
|
19
|
+
* `variant="kolbox"` and `"folio"` are accepted and draw `controls="field"` (plan-2026-11-29-one-set-fold W2 run 2;
|
|
20
|
+
* the old branches are in `_tmp/2026-11-29-one-set-fold/`).
|
|
15
21
|
*
|
|
16
22
|
* @param {number} value current quantity (default 1)
|
|
17
23
|
* @param {Function} onChange (next) => void
|
|
18
24
|
* @param {number} min lower bound (default 1)
|
|
19
25
|
* @param {number} max upper bound (default 99)
|
|
20
|
-
* @param {string} controls 'chevron' (default) | 'split'
|
|
26
|
+
* @param {string} controls 'chevron' (default) | 'split' | 'field'
|
|
21
27
|
* @param {string} size 'sm' | 'md' | 'lg' — pins the responsive size
|
|
22
28
|
* @param {string} unit a word after the value (`22 px`)
|
|
23
29
|
* @param {string} ariaLabel what the value is; the − + read `Decrease <it>` / `Increase <it>` (default quantity)
|
|
24
|
-
* @param {
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* @param {
|
|
28
|
-
* @param {ReactNode}
|
|
29
|
-
* @param {ReactNode} up FOLIO: the + square's text (`A+`)
|
|
30
|
-
* @param {string} downLabel FOLIO: the − square's name (`Smaller text`)
|
|
31
|
-
* @param {string} upLabel FOLIO: the + square's name (`Larger text`)
|
|
32
|
-
* @param {'kolbox'} variant also `kolbox` (Folio on kolbox, 2026-11-22): kolbox has no stepper of its own, so it is built
|
|
33
|
-
* from its parts: `Input variant="kolbox"` (its sm field, `--kol-kolbox-ctl` high: the value
|
|
34
|
-
* in mono with `unit` after it, typed and committed on Enter or leaving, ↑↓ step it) between
|
|
35
|
-
* two kolbox icon Buttons, − and + (your icons' `minus` and `plus`), 4 apart, the root as wide
|
|
36
|
-
* as its row. `step`, `min`, `max` as folio's: a typed value is held to the range and the step;
|
|
37
|
-
* a button at a bound is disabled. `downLabel`, `upLabel` name the buttons (else
|
|
38
|
-
* `Decrease <ariaLabel>`, `Increase <ariaLabel>`); `down`, `up` are not drawn (the set's glyphs are)
|
|
30
|
+
* @param {number} step how far one press moves the value in `field` (default 1); a typed value snaps to it
|
|
31
|
+
* @param {string} downLabel the − button's name in `field` (else `Decrease <ariaLabel>`)
|
|
32
|
+
* @param {string} upLabel the + button's name in `field` (else `Increase <ariaLabel>`)
|
|
33
|
+
* @param {ReactNode} down accepted, not drawn (folio's square text; the set's glyphs are)
|
|
34
|
+
* @param {ReactNode} up accepted, not drawn
|
|
39
35
|
* @param {string} className extra classes on the root
|
|
40
36
|
*/
|
|
41
|
-
import Input from '../atoms/Input.jsx'
|
|
42
|
-
import Button from '../atoms/Button.jsx'
|
|
43
|
-
|
|
44
37
|
const SIZE_MAP = {
|
|
45
38
|
sm: { fontSize: 11, paddingY: 12, paddingX: 24, radius: 20, icon: 10 },
|
|
46
39
|
md: { fontSize: 12, paddingY: 14, paddingX: 24, radius: 22, icon: 12 },
|
|
47
40
|
lg: { fontSize: 14, paddingY: 16, paddingX: 24, radius: 24, icon: 14 },
|
|
48
41
|
}
|
|
49
42
|
|
|
43
|
+
const THEME_WORDS = ['kolbox', 'folio']
|
|
44
|
+
|
|
50
45
|
const QuantityInput = ({
|
|
51
46
|
value = 1,
|
|
52
47
|
onChange,
|
|
53
48
|
min = 1,
|
|
54
49
|
max = 99,
|
|
55
|
-
controls = 'chevron',
|
|
50
|
+
controls: controlsProp = 'chevron',
|
|
56
51
|
size,
|
|
57
52
|
variant,
|
|
58
53
|
unit,
|
|
@@ -92,32 +87,28 @@ const QuantityInput = ({
|
|
|
92
87
|
return () => window.removeEventListener('resize', updateWidth)
|
|
93
88
|
}, [])
|
|
94
89
|
|
|
90
|
+
/* the old theme words: accepted, they draw the field stepper they drew (on the retirement ledger) */
|
|
91
|
+
const controls = THEME_WORDS.includes(variant) ? 'field' : controlsProp
|
|
95
92
|
const metrics = SIZE_MAP[resolvedSize] || SIZE_MAP.md
|
|
96
93
|
const increment = () => { if (value < max) onChange?.(value + 1) }
|
|
97
94
|
const decrement = () => { if (value > min) onChange?.(value - 1) }
|
|
98
95
|
|
|
99
|
-
/*
|
|
100
|
-
|
|
101
|
-
if (
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
<button type="button" aria-label={upLabel} disabled={value >= max} onClick={() => onChange?.(value + step)} className={stepCls}>{up}</button>
|
|
108
|
-
</div>
|
|
109
|
-
)
|
|
110
|
-
}
|
|
96
|
+
/* a typed value, held to the range and snapped to the step (kolbox's, every layout's since W2 run 2) */
|
|
97
|
+
const to = (n) => Math.min(max, Math.max(min, min + Math.round((n - min) / step) * step))
|
|
98
|
+
const commit = (text) => { const n = parseFloat(text); if (Number.isFinite(n) && to(n) !== value) onChange?.(to(n)) }
|
|
99
|
+
const field = useFieldCommit(value, commit)
|
|
100
|
+
const typed = (style) => (
|
|
101
|
+
<input type="text" inputMode="numeric" aria-label={ariaLabel} spellCheck={false} {...field} onMouseDown={selectOnFirstPress}
|
|
102
|
+
style={{ fieldSizing: 'content', padding: 0, border: 'none', outline: 'none', background: 'transparent', ...style }} />
|
|
103
|
+
)
|
|
111
104
|
|
|
112
|
-
/* kolbox
|
|
113
|
-
if (
|
|
114
|
-
const to = (n) => Math.min(max, Math.max(min, min + Math.round((n - min) / step) * step))
|
|
115
|
-
const commit = (text) => { const n = parseFloat(text); if (Number.isFinite(n) && to(n) !== value) onChange?.(to(n)) }
|
|
105
|
+
/* controls="field" (kolbox's stepper, Folio on kolbox 2026-11-22): the field between its two icon buttons */
|
|
106
|
+
if (controls === 'field') {
|
|
116
107
|
return (
|
|
117
108
|
<div className={`flex min-w-0 items-center gap-1 ${className}`.trim()}>
|
|
118
|
-
<Button
|
|
119
|
-
<Input
|
|
120
|
-
<Button
|
|
109
|
+
<Button iconOnly="minus" aria-label={downLabel ?? `Decrease ${ariaLabel}`} disabled={value <= min} onClick={() => onChange?.(to(value - step))} />
|
|
110
|
+
<Input size="sm" aria-label={ariaLabel} value={value} onCommit={commit} suffix={unit} className="flex-1" />
|
|
111
|
+
<Button iconOnly="plus" aria-label={upLabel ?? `Increase ${ariaLabel}`} disabled={value >= max} onClick={() => onChange?.(to(value + step))} />
|
|
121
112
|
</div>
|
|
122
113
|
)
|
|
123
114
|
}
|
|
@@ -146,7 +137,7 @@ const QuantityInput = ({
|
|
|
146
137
|
}}
|
|
147
138
|
>
|
|
148
139
|
<button type="button" onClick={decrement} disabled={value <= min} style={btn(value <= min)} aria-label="Decrease quantity">−</button>
|
|
149
|
-
|
|
140
|
+
{typed({ minWidth: '24px', textAlign: 'center', color: 'var(--kol-surface-on-primary)', fontFamily: 'var(--kol-font-family-mono)', fontSize: `${metrics.fontSize}px`, lineHeight: '120%' })}
|
|
150
141
|
<button type="button" onClick={increment} disabled={value >= max} style={btn(value >= max)} aria-label="Increase quantity">+</button>
|
|
151
142
|
</div>
|
|
152
143
|
)
|
|
@@ -168,7 +159,7 @@ const QuantityInput = ({
|
|
|
168
159
|
fontFamily: 'var(--kol-font-family-mono)', boxSizing: 'border-box',
|
|
169
160
|
}}
|
|
170
161
|
>
|
|
171
|
-
|
|
162
|
+
{typed({ color: 'inherit', font: 'inherit', lineHeight: 'inherit' })}
|
|
172
163
|
<div style={{ position: 'absolute', right: `${metrics.paddingX}px`, top: '50%', transform: 'translateY(-50%)', display: 'flex', flexDirection: 'column' }}>
|
|
173
164
|
<button type="button" onClick={increment} disabled={value >= max} style={{ backgroundColor: 'transparent', border: 'none', padding: '0', cursor: value >= max ? 'not-allowed' : 'pointer', opacity: value >= max ? 0.3 : 1, lineHeight: 0, display: 'block' }} aria-label="Increase quantity">
|
|
174
165
|
<svg width={metrics.icon} height={metrics.icon} viewBox="0 0 12 12" fill="none">
|