@kolkrabbi/kol-component 0.311.3 → 0.312.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 +1 -1
- package/src/index.js +2 -0
- package/src/molecules/VariantsControl.jsx +39 -0
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -67,6 +67,8 @@ export { default as InspectorSection, default as Section } from './molecules/Ins
|
|
|
67
67
|
export { default as SectionText, SECTION_TEXT_LEVELS } from './molecules/SectionText.jsx'
|
|
68
68
|
export { default as SectionLabel } from './atoms/SectionLabel.jsx'
|
|
69
69
|
export { default as SegmentedToggle } from './atoms/SegmentedToggle.jsx'
|
|
70
|
+
/* a page's variants — the pinned slider button and its panel of segmented rows (OneVariantsControl, 2026-10-29; catalog's) */
|
|
71
|
+
export { default as VariantsControl } from './molecules/VariantsControl.jsx'
|
|
70
72
|
export { default as Stepper } from './molecules/Stepper.jsx'
|
|
71
73
|
export { default as Kbd } from './atoms/Kbd.jsx'
|
|
72
74
|
export { default as OptionRow } from './molecules/OptionRow.jsx'
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { useState } from 'react'
|
|
2
|
+
import Button from '../atoms/Button.jsx'
|
|
3
|
+
import SegmentedToggle from '../atoms/SegmentedToggle.jsx'
|
|
4
|
+
import { usePopover, PopoverPanel } from '../utilities/Popover.jsx'
|
|
5
|
+
|
|
6
|
+
const cap = (v) => String(v).charAt(0).toUpperCase() + String(v).slice(1)
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* VariantsControl — a page's variants: a round `slider-01` button pinned top-right at the shell's page pad that opens a
|
|
10
|
+
* panel of labelled segmented rows, one per axis. apps/catalog's `VariantsButton`, shipped (OneVariantsControl, kol-website
|
|
11
|
+
* 2026-10-29 — user: *"why are they reinventing the wheel? we already have a component for this"*); catalog, rails, shell
|
|
12
|
+
* and layouts each had it, by hand or reinvented. Each axis is a SEGMENTED row, not a dropdown (user 2026-10-22, on a
|
|
13
|
+
* dropdown list opening over the panel in the panel's own colour): every option visible, one click, nothing floats over the
|
|
14
|
+
* panel.
|
|
15
|
+
*
|
|
16
|
+
* @param {Array} axes `[{ key, label, values }]` (each value labelled with its first letter capitalised) or
|
|
17
|
+
* `[{ key, label, options: [{ value, label }] }]`
|
|
18
|
+
* @param {Object} value the current value by axis key
|
|
19
|
+
* @param {Function} onChange `(key, value)`
|
|
20
|
+
* @param {Object} [style] merged onto the pinned wrapper — a host whose own chrome holds that corner moves it
|
|
21
|
+
*/
|
|
22
|
+
export default function VariantsControl({ axes = [], value = {}, onChange, style, className = '' }) {
|
|
23
|
+
const [open, setOpen] = useState(false)
|
|
24
|
+
const popover = usePopover({ open, onOpenChange: setOpen, placement: 'bottom-end', offset: 8 })
|
|
25
|
+
return (
|
|
26
|
+
<div className={`fixed z-10 ${className}`.trim()} style={{ top: 'var(--kol-shell-page-pad, 24px)', right: 'var(--kol-shell-page-pad, 24px)', ...style }}>
|
|
27
|
+
<span ref={popover.refs.setReference} {...popover.getReferenceProps()} className="inline-flex">
|
|
28
|
+
<Button iconOnly="slider-01" size="lg" tone="inverted" radius="full" aria-label="Variants" style={{ boxShadow: 'var(--kol-shadow-lg)' }} pressed={open} />
|
|
29
|
+
</span>
|
|
30
|
+
<PopoverPanel popover={popover} className="grid grid-cols-[auto_1fr] items-center gap-x-4 gap-y-2 p-3">
|
|
31
|
+
{axes.map((a) => [
|
|
32
|
+
<span key={`${a.key}-l`} className="kol-mono-12 text-fg-64">{a.label}</span>,
|
|
33
|
+
<SegmentedToggle key={a.key} size="sm" ariaLabel={a.label} value={value[a.key]} onChange={(v) => onChange?.(a.key, v)}
|
|
34
|
+
options={a.options ?? (a.values ?? []).map((v) => ({ value: v, label: cap(v) }))} />,
|
|
35
|
+
])}
|
|
36
|
+
</PopoverPanel>
|
|
37
|
+
</div>
|
|
38
|
+
)
|
|
39
|
+
}
|