@kolkrabbi/kol-component 0.190.0 → 0.192.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/molecules/DocsToc.jsx +51 -14
- package/src/organisms/SectionSplit.jsx +26 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kolkrabbi/kol-component",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.192.0",
|
|
4
4
|
"description": "KOL design-system components — atoms through organisms, emitting canonical kol-* classes. Pairs with @kolkrabbi/kol-theme for styling.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -72,6 +72,7 @@ import useScrollSpy from '../hooks/useScrollSpy.js'
|
|
|
72
72
|
* @param {Element} root IntersectionObserver root passed to the spy
|
|
73
73
|
* @param {number} minors RAIL: graduations between one heading and the next — the dial's resolution, so literally how many clicks a heading is worth (default 10)
|
|
74
74
|
* @param {number} falloff RAIL: the gaussian's sigma in px, measured against the TICK pitch not the label pitch — at 10 graduations of 3px a section spans ~52px, so 14 crosses four or five clicks. Widen it and the whole column swells together, which is a column getting bigger rather than a lens moving over it (default 14)
|
|
75
|
+
* @param {'tick'|'label'|'off'} snap RAIL: what the lens locks to — `tick` (default) is the safecracker dial, locking to the nearest graduation and holding across its band; `label` locks to headings only, which is the ONLY sensible detent at `minors={0}`; `off` lets the lens follow the pointer continuously, which is the honest fisheye and reads better on a long rail with no graduations
|
|
75
76
|
* @param {'left'|'right'} position RAIL: which edge it pins to (default 'right')
|
|
76
77
|
* @param {number} minSections RAIL: render nothing under this many headings — an index of one is noise (default 2)
|
|
77
78
|
* @param {string} ariaLabel RAIL: the nav's accessible name (default 'On this page')
|
|
@@ -85,6 +86,7 @@ export default function DocsToc({
|
|
|
85
86
|
root = null,
|
|
86
87
|
minors = 10,
|
|
87
88
|
falloff = 14,
|
|
89
|
+
snap = 'tick',
|
|
88
90
|
position = 'right',
|
|
89
91
|
minSections = 2,
|
|
90
92
|
ariaLabel = 'On this page',
|
|
@@ -100,6 +102,7 @@ export default function DocsToc({
|
|
|
100
102
|
onNavigate={onNavigate}
|
|
101
103
|
minors={minors}
|
|
102
104
|
falloff={falloff}
|
|
105
|
+
snap={snap}
|
|
103
106
|
position={position}
|
|
104
107
|
minSections={minSections}
|
|
105
108
|
ariaLabel={ariaLabel}
|
|
@@ -145,7 +148,7 @@ export default function DocsToc({
|
|
|
145
148
|
* do not belong in the other's render path.
|
|
146
149
|
*
|
|
147
150
|
* The magnitudes go to the DOM as `--m`, never to state — see the header. */
|
|
148
|
-
function TocRail({ toc, activeId, onNavigate, minors, falloff, position, minSections, ariaLabel, className }) {
|
|
151
|
+
function TocRail({ toc, activeId, onNavigate, minors, falloff, snap, position, minSections, ariaLabel, className }) {
|
|
149
152
|
const navRef = useRef(null)
|
|
150
153
|
const centresRef = useRef([])
|
|
151
154
|
const frameRef = useRef(0)
|
|
@@ -166,19 +169,38 @@ function TocRail({ toc, activeId, onNavigate, minors, falloff, position, minSect
|
|
|
166
169
|
const nav = navRef.current
|
|
167
170
|
if (!nav) return
|
|
168
171
|
|
|
169
|
-
/* DETENT
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
+
/* THE DETENT. `tick` is the safecracker's dial — the lens locks to the
|
|
173
|
+
* nearest mark and holds across its whole band, so dragging down the rail
|
|
174
|
+
* is a run of discrete clicks rather than a smear. The three modes differ
|
|
175
|
+
* only in WHICH array is snapped against, which is why this is a prop and
|
|
176
|
+
* not three components (`docstoc-rail-tracking-and-snap-prop`, 2026-09-04):
|
|
177
|
+
*
|
|
178
|
+
* tick every graduation — the default, right for an index you aim with
|
|
179
|
+
* label the headings only — coarse at 10 minors, and the ONLY sensible
|
|
180
|
+
* detent at `minors={0}`, which the component already allows: no
|
|
181
|
+
* ticks plus a tick-snap is `label` by accident rather than choice
|
|
182
|
+
* off no snap at all — the honest fisheye, and better on a long rail
|
|
183
|
+
* with many headings and no graduations
|
|
184
|
+
*
|
|
185
|
+
* Majors are every (minors + 1)th child, because the render interleaves
|
|
186
|
+
* one heading with `minors` ticks and stops after the last heading. */
|
|
172
187
|
const marks = centresRef.current
|
|
173
|
-
const
|
|
188
|
+
const targets = snap === 'off'
|
|
174
189
|
? null
|
|
175
|
-
:
|
|
190
|
+
: snap === 'label'
|
|
191
|
+
? marks.filter((_, i) => i % (minors + 1) === 0)
|
|
192
|
+
: marks
|
|
193
|
+
const focus = y == null
|
|
194
|
+
? null
|
|
195
|
+
: !targets?.length
|
|
196
|
+
? y
|
|
197
|
+
: targets.reduce((best, c) => (Math.abs(c - y) < Math.abs(best - y) ? c : best), targets[0])
|
|
176
198
|
|
|
177
199
|
marks.forEach((c, i) => {
|
|
178
200
|
const m = focus == null ? 0 : Math.exp(-(((focus - c) / falloff) ** 2))
|
|
179
201
|
nav.children[i]?.style.setProperty('--m', m.toFixed(3))
|
|
180
202
|
})
|
|
181
|
-
}, [falloff])
|
|
203
|
+
}, [falloff, snap, minors])
|
|
182
204
|
|
|
183
205
|
const onMove = useCallback((e) => {
|
|
184
206
|
/* Reduced motion: the curve is the animation, so there is nothing to damp —
|
|
@@ -228,13 +250,28 @@ function TocRail({ toc, activeId, onNavigate, minors, falloff, position, minSect
|
|
|
228
250
|
data-active={active ? '' : undefined}
|
|
229
251
|
className="kol-toc-row"
|
|
230
252
|
>
|
|
231
|
-
{/*
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
|
|
253
|
+
{/* `kol-helper-12`, and it is the FAULT LINE that says so, not
|
|
254
|
+
* taste (01-foundations/03-typography: *"can this string ever
|
|
255
|
+
* wrap? No (structurally single-line) → helper"*). This label is
|
|
256
|
+
* `white-space: nowrap` — a graduation on a ruler, which is the
|
|
257
|
+
* helper family's own listed use.
|
|
258
|
+
*
|
|
259
|
+
* The line-height is the functional half. `kol-mono-14` carries
|
|
260
|
+
* 18px leading on a 14px label: 4px this string never uses, and
|
|
261
|
+
* THIS component measures its rows — `measure()` reads
|
|
262
|
+
* `getBoundingClientRect()` on every child to place the detents,
|
|
263
|
+
* so leading inflates each row box and moves the label's centre
|
|
264
|
+
* off its own tick. A ramp built for wrapping text is the wrong
|
|
265
|
+
* tool for a mark on a ruler.
|
|
266
|
+
*
|
|
267
|
+
* It shipped as `kol-mono-14` in 0.188.0 because validate:rails
|
|
268
|
+
* R1 tested the class PREFIX rather than the rung's purpose and I
|
|
269
|
+
* took the gate's word over the type law. The filer had specified
|
|
270
|
+
* helper-12 deliberately (user: *"its a bit big and tight and
|
|
271
|
+
* bold"*, and then *"I just dont get the point of me desiging for
|
|
272
|
+
* the design be ignored?!"*). R1 now carries the exemption with
|
|
273
|
+
* this reason — see `docstoc-rail-tracking-and-snap-prop`. */}
|
|
274
|
+
<span className="kol-toc-label kol-helper-12 text-meta">{label}</span>
|
|
238
275
|
<span aria-hidden="true" className="kol-toc-rule" />
|
|
239
276
|
</a>
|
|
240
277
|
)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import SectionText from '../molecules/SectionText.jsx'
|
|
2
|
+
import AssetPlaceholder from '../utilities/AssetPlaceholder.jsx'
|
|
2
3
|
import { FULL_BLEED } from './sectionBleed.js'
|
|
3
4
|
import { surfaceClass } from '../utilities/sectionSurface.js'
|
|
4
5
|
import useSectionTheme from '../hooks/useSectionTheme.js'
|
|
@@ -14,8 +15,19 @@ import { minHeightClass } from './sectionHeights.js'
|
|
|
14
15
|
* 'right' media on the right, text on the left — the default
|
|
15
16
|
* 'left' media first (the old `flip`)
|
|
16
17
|
* 'center' ONE column: text centred, media below
|
|
18
|
+
* 'top' ONE column: media ABOVE the text, both centred
|
|
19
|
+
* 'bottom' ONE column: text above, media below — the explicit name for what
|
|
20
|
+
* `center` has always rendered, kept as its own value because
|
|
21
|
+
* "centred" says where the column sits and nothing about the order
|
|
17
22
|
* One anatomy, one prop — not a third component.
|
|
18
23
|
*
|
|
24
|
+
* THE VERTICAL PAIR (section-split-vertical-align, kol-client-hrafn
|
|
25
|
+
* 2026-09-03). The filer asked what `center` renders when `media` is passed and
|
|
26
|
+
* could not tell from the source: it STACKS, text first, media below, capped at
|
|
27
|
+
* 640. So `bottom` already existed under a name that did not say so, and only
|
|
28
|
+
* `top` was missing. Both are values a page can name now, and `center` keeps
|
|
29
|
+
* its behaviour exactly, so no existing call moves.
|
|
30
|
+
*
|
|
19
31
|
* `meta` and `actions` are mutually exclusive by intent (pick one); `actions`
|
|
20
32
|
* is conventionally a row of KOL Buttons. The media column renders only when
|
|
21
33
|
* `media` is passed, and `caption` gates both the gradient veil and the
|
|
@@ -59,7 +71,8 @@ import { minHeightClass } from './sectionHeights.js'
|
|
|
59
71
|
* than only in `fill`, because a prop that silently does nothing in the default form is a
|
|
60
72
|
* seam wired to nothing. Unset, each form keeps exactly what it did: `fill` centres,
|
|
61
73
|
* bounded follows `align` (centred when `align="center"`, else start).
|
|
62
|
-
* @param {'right'|'left'|'center'} [align='right'] media side, or centred single column
|
|
74
|
+
* @param {'right'|'left'|'center'|'top'|'bottom'} [align='right'] media side, or a centred single column: `top` puts the media above the text, `center` and `bottom` below it
|
|
75
|
+
* @param {boolean|ReactNode} [placeholder=false] what stands in when `media` is absent — `true` renders the DS `AssetPlaceholder` at the frame's ratio, a node renders itself. OFF by default: a text-only `SectionSplit` is a real and common call, and injecting a visible box into every one of them estate-wide is not a fix (section-split-vertical-align, kol-client-hrafn 2026-09-03, which asked for the placeholder and gets it opt-in)
|
|
63
76
|
* @param {'full'|'80'|'60'|string} [height='60'] min-height on the family's ladder — full = 100dvh,
|
|
64
77
|
* 80 = 70svh / 80vh, 60 = 50svh / 60vh (default), 40 = 35svh / 40vh; the columns stay vertically centred inside it
|
|
65
78
|
* @param {ReactNode} caption mono caption + gradient veil over the media
|
|
@@ -87,6 +100,7 @@ export default function SectionSplit({
|
|
|
87
100
|
mediaHover = false,
|
|
88
101
|
mediaClip = true,
|
|
89
102
|
align = 'right',
|
|
103
|
+
placeholder = false,
|
|
90
104
|
textAlign,
|
|
91
105
|
fill = false,
|
|
92
106
|
height = '60',
|
|
@@ -106,8 +120,13 @@ export default function SectionSplit({
|
|
|
106
120
|
? { backgroundImage: `url(${bgImage})`, backgroundSize: 'cover', backgroundPosition: 'center' }
|
|
107
121
|
: undefined
|
|
108
122
|
const bleed = fullBleed ? FULL_BLEED : ''
|
|
109
|
-
|
|
110
|
-
|
|
123
|
+
/* the three single-column forms — `center` and `bottom` are one layout under
|
|
124
|
+
* two names, `top` reverses the order */
|
|
125
|
+
const centred = align === 'center' || align === 'top' || align === 'bottom'
|
|
126
|
+
/* `order-*` and not DOM order: the grid is one column in every centred form
|
|
127
|
+
* and below 901px, and the order utilities are what lift the media above the
|
|
128
|
+
* text for `left` and `top` alike. */
|
|
129
|
+
const mediaFirst = align === 'left' || align === 'top'
|
|
111
130
|
/* unset = each form's own prior behaviour, so nothing existing moves */
|
|
112
131
|
const fillText = textAlign ?? 'center'
|
|
113
132
|
const boundedText = textAlign ?? (centred ? 'center' : 'start')
|
|
@@ -206,7 +225,7 @@ export default function SectionSplit({
|
|
|
206
225
|
</div>
|
|
207
226
|
)}
|
|
208
227
|
</SectionText>
|
|
209
|
-
{media && (
|
|
228
|
+
{(media || placeholder) && (
|
|
210
229
|
/* height = the rung minus the padding; width follows the ratio and
|
|
211
230
|
* caps at the column — the media takes its size from the section,
|
|
212
231
|
* never gives it */
|
|
@@ -235,7 +254,9 @@ export default function SectionSplit({
|
|
|
235
254
|
className={`kol-section-split-visual relative w-full max-w-full justify-self-center rounded-[var(--kol-radius-sm)] min-[901px]:h-[calc(var(--kol-section-h,60vh)_-_2*var(--kol-section-py,4rem))] ${mediaClip ? 'overflow-hidden' : ''} ${mediaHover ? 'is-hoverable' : ''} ${mediaFirst ? 'order-1' : ''} ${centred ? 'max-w-[640px]' : ''}`.replace(/\s+/g, ' ').trim()}
|
|
236
255
|
style={{ aspectRatio: ratio }}
|
|
237
256
|
>
|
|
238
|
-
{media
|
|
257
|
+
{media ?? (placeholder === true
|
|
258
|
+
? <AssetPlaceholder className="h-full w-full" />
|
|
259
|
+
: placeholder)}
|
|
239
260
|
{caption && <div className="kol-section-split-visual-veil" aria-hidden="true" />}
|
|
240
261
|
{caption && <span className="kol-section-split-visual-caption">{caption}</span>}
|
|
241
262
|
</div>
|