@kolkrabbi/kol-component 0.6.0 → 0.8.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.
Files changed (38) hide show
  1. package/README.md +8 -0
  2. package/package.json +2 -3
  3. package/src/atoms/RotaryDial.jsx +35 -21
  4. package/src/index.js +6 -18
  5. package/src/molecules/ButtonGroup.jsx +45 -0
  6. package/src/molecules/ColorInputRow.jsx +146 -126
  7. package/src/molecules/Slider.jsx +29 -14
  8. package/src/molecules/SplitToolButton.jsx +133 -0
  9. package/src/organisms/ContentFilters.jsx +2 -2
  10. package/src/organisms/GalleryCarousel.jsx +2 -1
  11. package/src/organisms/LoaderOverlay.jsx +11 -14
  12. package/src/organisms/MediaTileGallery.jsx +57 -0
  13. package/src/organisms/MediaViewer.jsx +89 -64
  14. package/src/atoms/PriceDisplay.jsx +0 -34
  15. package/src/atoms/TextPressure.jsx +0 -331
  16. package/src/atoms/TypeSample.jsx +0 -50
  17. package/src/atoms/TypeSpecCard.jsx +0 -42
  18. package/src/molecules/ArticleCard.jsx +0 -178
  19. package/src/molecules/WorkListItem.jsx +0 -83
  20. package/src/molecules/foundry/SpecimenSectionHeader.jsx +0 -89
  21. package/src/organisms/ArticleHeader.jsx +0 -95
  22. package/src/organisms/ColorLoader.jsx +0 -155
  23. package/src/organisms/DiagonalMarqueeRiver.jsx +0 -138
  24. package/src/organisms/ParallaxShelf.jsx +0 -141
  25. package/src/organisms/PortableTextRenderer.jsx +0 -115
  26. package/src/organisms/ProductDetailLayout.jsx +0 -189
  27. package/src/organisms/ScrollDriftGallery.jsx +0 -214
  28. package/src/organisms/StackHero.jsx +0 -83
  29. package/src/organisms/WorkCard.jsx +0 -120
  30. package/src/organisms/WorkViewToggle.jsx +0 -170
  31. package/src/organisms/foundry/FontPreviewSection.jsx +0 -187
  32. package/src/organisms/foundry/FoundryCharacterSets.jsx +0 -113
  33. package/src/organisms/foundry/GlyphMetricsGrid.jsx +0 -335
  34. package/src/organisms/foundry/TypefaceHero.jsx +0 -107
  35. package/src/organisms/foundry/TypefaceStyleSection.jsx +0 -163
  36. package/src/organisms/foundry/VariableFontSection.jsx +0 -158
  37. package/src/organisms/foundry/glyphData.js +0 -30
  38. package/src/organisms/foundry/index.js +0 -21
@@ -1,335 +0,0 @@
1
- import { useEffect, useRef, useState } from 'react'
2
- import Tag from '../../atoms/Tag.jsx'
3
- import { glyphSets } from './glyphData.js'
4
-
5
- /* taxonomy-ok: organism — nests DS Tag (relative import) and owns font I/O +
6
- * parsed-metric geometry. */
7
-
8
- /* ---------------------------------------------------------------------------
9
- * FontLoader (same-file) — fetch → FontFace inject → best-effort opentype parse.
10
- *
11
- * The font face is ALWAYS injected (under a unique family name) so the big
12
- * glyph + grid cells render the real file even when metric parsing is
13
- * unavailable. opentype.js is loaded via a DYNAMIC import so a consumer that
14
- * hasn't installed the peer dep simply gets no parsed metrics (the grid renders
15
- * without the baseline/x-height/cap/ascender/descender overlay) instead of a
16
- * hard crash. Folds in the fallback-chain metric extraction the monorepo's
17
- * inline overlay added (os2 ?? hhea ?? literal), so incomplete fonts don't throw.
18
- * ------------------------------------------------------------------------- */
19
- class FontLoader {
20
- constructor(options = {}) {
21
- this.callbacks = options
22
- this.family = null
23
- }
24
-
25
- async loadFont(buffer, filename) {
26
- // Inject the face first — this never needs opentype and guarantees the
27
- // glyph renders in the real font.
28
- const uniqueFontName = `KolFoundryFont_${Date.now()}`
29
- try {
30
- const fontFace = new FontFace(uniqueFontName, buffer)
31
- await fontFace.load()
32
- document.fonts.add(fontFace)
33
- this.family = uniqueFontName
34
- } catch (err) {
35
- this.callbacks.onError?.(err)
36
- }
37
-
38
- // Best-effort metric parse. Dynamic import degrades gracefully when the
39
- // opentype.js peer dep is absent.
40
- let font = null
41
- try {
42
- const mod = await import('opentype.js')
43
- const parse = mod.parse || mod.default?.parse || mod.default
44
- font = parse(buffer)
45
- } catch (err) {
46
- // No metrics — the overlay just won't draw. Not fatal.
47
- this.callbacks.onError?.(err)
48
- }
49
-
50
- this.callbacks.onFontLoaded?.({ font, fontFamily: this.family, filename })
51
- return { font, fontFamily: this.family }
52
- }
53
-
54
- cleanup() {
55
- if (typeof document === 'undefined') return
56
- document.fonts.forEach((f) => {
57
- if (f.family && f.family.startsWith('KolFoundryFont_')) document.fonts.delete(f)
58
- })
59
- this.family = null
60
- }
61
- }
62
-
63
- /**
64
- * GlyphMetricsGrid — table-style glyph inspector with real, parsed font metrics.
65
- *
66
- * One giant glyph carrying a live baseline / x-height / cap-height / ascender /
67
- * descender overlay drawn from the font's OWN OS/2 + hhea tables, beside two
68
- * clickable uppercase/lowercase glyph grids and a Unicode / decimal / hex
69
- * readout. Clicking a cell pins the big glyph; hovering previews it.
70
- * `variationSettings` feed straight into `font-variation-settings` so the
71
- * overlay stays correct under a live variable axis driven from the parent.
72
- *
73
- * FONT-ASSET CONTRACT: pass a real `.ttf`/`.otf` at `fontUrl` (same-origin, so
74
- * the fetch + FontFace injection succeed). The metric lines require opentype.js
75
- * (a peer dep, dynamically imported) — without it the grids still render, just
76
- * with no overlay. The showcase serves fonts under `/fonts/`; e.g.
77
- * `/fonts/Right-Grotesk-ttf/PPRightGrotesk-Regular.ttf`.
78
- *
79
- * Metric extraction uses fallback chains so incomplete fonts degrade instead of
80
- * throwing: unitsPerEm ← font.unitsPerEm ?? 1000; ascender ← os2.sTypoAscender
81
- * ?? hhea.ascender ?? 800; descender ← os2.sTypoDescender ?? hhea.descender ??
82
- * -200; capHeight ← os2.sCapHeight ?? 700; xHeight ← os2.sxHeight ?? 500.
83
- *
84
- * Text casing: metadata labels, grid titles and tab labels render verbatim.
85
- *
86
- * @param {Object} props
87
- * @param {string} props.fontUrl - URL of the font to fetch + parse (required for real metrics).
88
- * @param {string} props.fontFamily - CSS family fallback until the parsed face is injected.
89
- * @param {'normal'|'italic'} props.fontStyle - Inline font-style + the Roman/Italic metadata label.
90
- * @param {string} props.initialGlyph - Initially selected glyph (default 'f').
91
- * @param {string[]} props.uppercaseGlyphs - Top grid contents.
92
- * @param {string[]} props.lowercaseGlyphs - Bottom grid contents.
93
- * @param {Object} props.variationSettings - axis→value map serialized to font-variation-settings.
94
- */
95
- const GlyphMetricsGrid = ({
96
- fontUrl,
97
- fontFamily = 'sans-serif',
98
- fontStyle = 'normal',
99
- initialGlyph = 'f',
100
- uppercaseGlyphs = [...glyphSets.uppercase, ...glyphSets.latin1],
101
- lowercaseGlyphs = [...glyphSets.lowercase, ...glyphSets.latinExtended],
102
- variationSettings = {},
103
- }) => {
104
- const [selectedGlyph, setSelectedGlyph] = useState(initialGlyph)
105
- const [hoveredGlyph, setHoveredGlyph] = useState(null)
106
- const [metrics, setMetrics] = useState(null)
107
- const [fontData, setFontData] = useState(null)
108
- const [loadedFamily, setLoadedFamily] = useState(null)
109
- const [activeTab, setActiveTab] = useState('uppercase')
110
-
111
- const glyphRef = useRef(null)
112
- const overlayRef = useRef(null)
113
-
114
- const displayGlyph = hoveredGlyph || selectedGlyph
115
- const renderFamily = loadedFamily || fontFamily
116
-
117
- // Serialize the axis map once for the big glyph + every cell.
118
- const fontVariationSettingsCSS =
119
- Object.entries(variationSettings)
120
- .map(([axis, value]) => `"${axis}" ${value}`)
121
- .join(', ') || 'normal'
122
-
123
- // Load font + extract metrics (keyed on fontUrl only).
124
- useEffect(() => {
125
- if (!fontUrl) return
126
- const glyphElement = glyphRef.current
127
- if (!glyphElement) return
128
-
129
- const loader = new FontLoader({
130
- onFontLoaded: ({ font, fontFamily: injectedFamily }) => {
131
- if (injectedFamily) setLoadedFamily(injectedFamily)
132
- glyphElement.textContent = displayGlyph
133
- if (!font) return
134
-
135
- const os2 = font.tables?.os2
136
- const hhea = font.tables?.hhea
137
- setFontData({ font })
138
- setMetrics({
139
- unitsPerEm: font.unitsPerEm || 1000,
140
- ascender: os2?.sTypoAscender ?? hhea?.ascender ?? 800,
141
- descender: os2?.sTypoDescender ?? hhea?.descender ?? -200,
142
- capHeight: os2?.sCapHeight ?? 700,
143
- xHeight: os2?.sxHeight ?? 500,
144
- })
145
- },
146
- onError: (err) => console.warn('GlyphMetricsGrid: metrics unavailable', err),
147
- })
148
-
149
- let cancelled = false
150
- ;(async () => {
151
- try {
152
- const response = await fetch(fontUrl)
153
- const buffer = await response.arrayBuffer()
154
- const filename = fontUrl.split('/').pop() || 'font.ttf'
155
- if (!cancelled) await loader.loadFont(buffer, filename)
156
- } catch (err) {
157
- if (!cancelled) console.warn('GlyphMetricsGrid: font fetch failed', err)
158
- }
159
- })()
160
-
161
- return () => {
162
- cancelled = true
163
- loader.cleanup()
164
- }
165
- // eslint-disable-next-line react-hooks/exhaustive-deps
166
- }, [fontUrl])
167
-
168
- // Imperative glyph text on select/hover.
169
- useEffect(() => {
170
- if (glyphRef.current) glyphRef.current.textContent = displayGlyph
171
- }, [displayGlyph])
172
-
173
- // Metric-line overlay — overlay-relative coords, KOL tokens, mono type var.
174
- useEffect(() => {
175
- if (!fontData || !metrics || !glyphRef.current || !overlayRef.current) return
176
- const glyph = glyphRef.current
177
- const overlay = overlayRef.current
178
-
179
- const render = () => {
180
- const overlayRect = overlay.getBoundingClientRect()
181
- const glyphRect = glyph.getBoundingClientRect()
182
- const glyphTop = glyphRect.top - overlayRect.top
183
-
184
- const fontSize = parseFloat(window.getComputedStyle(glyph).fontSize)
185
- if (!fontSize || Number.isNaN(fontSize)) return
186
-
187
- const scale = fontSize / metrics.unitsPerEm
188
- const totalPixelHeight = (metrics.ascender - metrics.descender) * scale
189
- const baseline =
190
- glyphTop + glyphRect.height / 2 - totalPixelHeight / 2 + metrics.ascender * scale
191
-
192
- const lines = [
193
- { y: baseline - metrics.capHeight * scale, label: 'Cap Height', value: metrics.capHeight },
194
- { y: baseline - metrics.ascender * scale, label: 'Ascender', value: metrics.ascender },
195
- { y: baseline - metrics.xHeight * scale, label: 'x-height', value: metrics.xHeight },
196
- { y: baseline, label: 'Baseline', value: 0 },
197
- { y: baseline - metrics.descender * scale, label: 'Descender', value: metrics.descender },
198
- ]
199
-
200
- overlay.innerHTML = ''
201
- const labelCss = (side, y) => `
202
- position: absolute; ${side}: 13px; top: ${y - 18}px;
203
- opacity: 0.8; color: var(--kol-surface-on-primary);
204
- font-size: 12px; font-family: var(--kol-font-family-mono, monospace);
205
- line-height: 12px; user-select: none;`
206
- lines.forEach(({ y, label, value }) => {
207
- if (!Number.isFinite(y)) return
208
- const line = document.createElement('div')
209
- line.style.cssText = `position: absolute; left: 0; right: 0; top: ${y}px; border-top: 1px solid var(--kol-border-default);`
210
- overlay.appendChild(line)
211
- const left = document.createElement('div')
212
- left.style.cssText = labelCss('left', y)
213
- left.textContent = label
214
- overlay.appendChild(left)
215
- const right = document.createElement('div')
216
- right.style.cssText = labelCss('right', y)
217
- right.textContent = value
218
- overlay.appendChild(right)
219
- })
220
- }
221
-
222
- const raf = requestAnimationFrame(render)
223
- return () => cancelAnimationFrame(raf)
224
- }, [fontData, metrics, displayGlyph])
225
-
226
- const charCode = displayGlyph.charCodeAt(0)
227
- const unicodeHex = charCode.toString(16).toUpperCase().padStart(4, '0')
228
-
229
- const cellStyle = {
230
- fontFamily: renderFamily,
231
- fontStyle,
232
- fontVariationSettings: fontVariationSettingsCSS,
233
- outline: '1px solid var(--kol-border-default)',
234
- outlineOffset: '-0.5px',
235
- }
236
-
237
- const renderGrid = (glyphs, title) => (
238
- <div className="w-full flex flex-col gap-4">
239
- <div className="text-auto text-base md:text-lg kol-mono-text leading-7">{title}</div>
240
- <div
241
- className="inline-flex justify-start items-start flex-wrap"
242
- onMouseLeave={() => setHoveredGlyph(null)}
243
- >
244
- {glyphs.map((glyph, index) => {
245
- const isSelected = glyph === selectedGlyph
246
- return (
247
- <div
248
- key={index}
249
- onClick={() => setSelectedGlyph(glyph)}
250
- onMouseEnter={() => setHoveredGlyph(glyph)}
251
- className={`w-12 h-12 md:w-14 md:h-14 lg:w-16 lg:h-16 inline-flex flex-col justify-center items-center overflow-hidden cursor-pointer transition-colors duration-150 text-center text-lg md:text-xl lg:text-2xl leading-6 ${
252
- isSelected ? 'bg-surface-inverse' : 'bg-transparent text-auto hover:bg-fg-08'
253
- }`}
254
- style={cellStyle}
255
- >
256
- {glyph}
257
- </div>
258
- )
259
- })}
260
- </div>
261
- </div>
262
- )
263
-
264
- return (
265
- <div className="bg-surface-primary flex flex-col lg:flex-row justify-start items-start gap-6 md:gap-8 lg:gap-10">
266
- {/* Left: glyph viewer + metrics overlay */}
267
- <div className="w-full lg:flex-[504] flex flex-col justify-start items-start gap-4 md:gap-6">
268
- <div className="text-auto text-base md:text-lg kol-mono-text leading-7">Glyph Viewer</div>
269
-
270
- <div className="w-full flex flex-col justify-start items-start gap-4 md:gap-6 lg:gap-10">
271
- <div className="self-stretch h-64 md:h-80 lg:h-96 relative rounded-md overflow-hidden">
272
- <div className="absolute inset-0 flex items-center justify-center">
273
- <span
274
- ref={glyphRef}
275
- className="text-center text-auto"
276
- style={{
277
- fontSize: 'clamp(180px, 25vw, 316px)',
278
- lineHeight: '1',
279
- fontFamily: renderFamily,
280
- fontStyle,
281
- fontVariationSettings: fontVariationSettingsCSS,
282
- }}
283
- >
284
- {displayGlyph}
285
- </span>
286
- </div>
287
- <div ref={overlayRef} className="absolute inset-0 pointer-events-none" aria-hidden />
288
- </div>
289
-
290
- {/* Metadata */}
291
- <div className="hidden md:inline-flex justify-start items-start gap-8">
292
- <div className="opacity-80 text-auto text-sm md:text-base lg:text-lg kol-mono-text leading-7">
293
- Font style<br />
294
- Glyph name<br />
295
- Unicode<br />
296
- Decimal<br />
297
- Hex
298
- </div>
299
- <div className="opacity-80 text-auto text-sm md:text-base lg:text-lg kol-mono-text leading-7">
300
- {fontStyle === 'italic' ? 'Italic' : 'Roman'}<br />
301
- {displayGlyph}<br />
302
- U+{unicodeHex}<br />
303
- {charCode}<br />
304
- 0x{unicodeHex}
305
- </div>
306
- </div>
307
- </div>
308
- </div>
309
-
310
- {/* Right: dual grids */}
311
- <div className="w-full lg:flex-[832] flex flex-col justify-start items-start gap-4 md:gap-6">
312
- <div className="flex lg:hidden gap-3">
313
- <Tag hash={false} active={activeTab === 'uppercase'} onClick={() => setActiveTab('uppercase')}>
314
- Uppercase &amp; Latin
315
- </Tag>
316
- <Tag hash={false} active={activeTab === 'lowercase'} onClick={() => setActiveTab('lowercase')}>
317
- Lowercase &amp; Extended
318
- </Tag>
319
- </div>
320
-
321
- <div className="lg:hidden w-full">
322
- {activeTab === 'uppercase' && renderGrid(uppercaseGlyphs, 'Uppercase & Latin')}
323
- {activeTab === 'lowercase' && renderGrid(lowercaseGlyphs, 'Lowercase & Extended')}
324
- </div>
325
-
326
- <div className="hidden lg:flex lg:flex-col lg:gap-6 w-full">
327
- {renderGrid(uppercaseGlyphs, 'Uppercase & Latin')}
328
- {renderGrid(lowercaseGlyphs, 'Lowercase & Extended')}
329
- </div>
330
- </div>
331
- </div>
332
- )
333
- }
334
-
335
- export default GlyphMetricsGrid
@@ -1,107 +0,0 @@
1
- import Pill from '../../atoms/Pill.jsx'
2
- import Button from '../../atoms/Button.jsx'
3
-
4
- /* taxonomy-ok: organism — nests Pill + Button (relative imports); a full
5
- * page-hero region rendering live in the specimen's own font-family. */
6
-
7
- /**
8
- * TypefaceHero — the specimen hero for a typeface page: a centered stack of
9
- * category pill → giant display name rendered in the typeface's OWN fontFamily
10
- * → in-family description → download / view-specimen CTAs → an optional
11
- * licensing caption. Data-driven from one `typeface` object; the giant name is
12
- * the live font-family preview (arbitrary loaded font, inline `fontFamily`, not
13
- * a fixed KOL type class — only the size stops are Tailwind).
14
- *
15
- * Router-decoupled: the monorepo source called `useNavigate(specimenLink)`;
16
- * here the "View Specimen" CTA takes an `href` and/or `onSpecimenClick` callback
17
- * so the DS never depends on a router. CTA copy + the license note are
18
- * prop-driven (license default off), and `displayName` falls back to
19
- * `id`/`fontFamily` when the config omits it.
20
- *
21
- * Text casing: displayName, category, description and CTA/license strings render
22
- * verbatim as authored — no text-transform.
23
- *
24
- * @param {Object} props
25
- * @param {Object} props.typeface - Config: { displayName?, id?, fontFamily, fontStyle?, category?, description?, specimenLink? }.
26
- * @param {string} props.downloadHref - Optional href for the "Download font" CTA.
27
- * @param {string} props.downloadLabel - Download CTA label (default 'Download font').
28
- * @param {string} props.specimenLabel - View-specimen CTA label (default 'View Specimen').
29
- * @param {Function} props.onSpecimenClick - Handler for the view-specimen CTA (receives the event).
30
- * @param {string} props.licenseNote - Licensing caption; omit to hide.
31
- */
32
- const TypefaceHero = ({
33
- typeface = {},
34
- downloadHref,
35
- downloadLabel = 'Download font',
36
- specimenLabel = 'View Specimen',
37
- onSpecimenClick,
38
- licenseNote,
39
- }) => {
40
- const { displayName, id, fontFamily, fontStyle, category, description, specimenLink } = typeface
41
- const name = displayName || id || fontFamily
42
- const isItalic = fontStyle === 'italic'
43
-
44
- const handleSpecimenClick = (e) => {
45
- if (onSpecimenClick) {
46
- e.preventDefault()
47
- onSpecimenClick(e)
48
- }
49
- }
50
-
51
- return (
52
- <section className="py-48 md:py-72 flex flex-col justify-center text-center items-center overflow-hidden">
53
- <div className="flex flex-col items-center gap-2 max-w-[1400px]">
54
- {category && (
55
- <div className="pb-5 flex flex-col items-center gap-2">
56
- <Pill variant="subtle">{category}</Pill>
57
- </div>
58
- )}
59
-
60
- <div className="pb-16 flex flex-col items-center gap-0">
61
- <h1
62
- className={`text-[64px] leading-[100%] md:text-[128px] font-semibold ${
63
- isItalic ? 'italic' : ''
64
- } text-auto transition-colors duration-300`}
65
- style={{ fontFamily }}
66
- >
67
- {name}
68
- </h1>
69
-
70
- {description && (
71
- <p
72
- className={`text-xl font-semibold ${
73
- isItalic ? 'italic' : ''
74
- } text-auto transition-colors duration-300`}
75
- style={{ fontFamily }}
76
- >
77
- {description}
78
- </p>
79
- )}
80
- </div>
81
-
82
- <div className="flex flex-col items-center gap-2">
83
- <div className="flex flex-wrap items-center justify-center gap-3">
84
- <Button variant="primary" href={downloadHref}>
85
- {downloadLabel}
86
- </Button>
87
- <Button
88
- variant="outline"
89
- href={specimenLink}
90
- onClick={onSpecimenClick ? handleSpecimenClick : undefined}
91
- >
92
- {specimenLabel}
93
- </Button>
94
- </div>
95
-
96
- {licenseNote && (
97
- <p className="kol-mono-12 text-auto pt-4 transition-colors duration-300" style={{ opacity: 0.64 }}>
98
- {licenseNote}
99
- </p>
100
- )}
101
- </div>
102
- </div>
103
- </section>
104
- )
105
- }
106
-
107
- export default TypefaceHero
@@ -1,163 +0,0 @@
1
- import { useState } from 'react'
2
- import SpecimenSectionHeader from '../../molecules/foundry/SpecimenSectionHeader.jsx'
3
-
4
- /* taxonomy-ok: organism — nests SpecimenSectionHeader (relative import) plus a
5
- * same-file StyleCard row; owns the axis/selection state. */
6
-
7
- /**
8
- * StyleCard (same-file) — one style row: the label rendered live in its own
9
- * weight/width/italic on the left, the numeric value on the right, with an
10
- * active/hover flip. Inlined (the monorepo's `.style-card` CSS classes aren't
11
- * in the DS theme) and rebuilt Tailwind-first.
12
- */
13
- function StyleCard({ label, weight, width, italic, isActive, onHover, onClick, fontFamily }) {
14
- return (
15
- <div
16
- onMouseEnter={onHover}
17
- onClick={onClick}
18
- className={`flex items-center justify-between gap-4 px-4 py-3 rounded cursor-pointer border transition-colors duration-150 ${
19
- isActive ? 'bg-surface-inverse' : 'border-transparent hover:bg-fg-08'
20
- }`}
21
- style={{ borderColor: isActive ? 'transparent' : undefined }}
22
- >
23
- <span
24
- className="text-2xl md:text-3xl leading-none truncate"
25
- style={{
26
- fontFamily,
27
- fontStyle: italic ? 'italic' : 'normal',
28
- fontWeight: weight || 400,
29
- fontVariationSettings: width ? `'wdth' ${width}` : undefined,
30
- }}
31
- >
32
- {label}
33
- </span>
34
- <span className="kol-mono-12 shrink-0 opacity-70">{width || weight}</span>
35
- </div>
36
- )
37
- }
38
-
39
- const pickDefault = (list) => list.find((s) => s.isDefault) || list[3] || list[0]
40
-
41
- /**
42
- * TypefaceStyleSection — the weight/width/italic style showcase: a sticky
43
- * inverted preview panel on the left (renders `AaBbCc / 01234567 / {(!@#$?&)}`
44
- * in the hovered/selected style) beside a grid of every available style on the
45
- * right. Derives its behavior generically from `typeface.styles`: italic →
46
- * Roman/Italic dropdown; weight+width → Weight/Width axis dropdown; single-axis
47
- * / static → no dropdown.
48
- *
49
- * Default selection prefers a style flagged `isDefault`, falling back to index
50
- * (Regular ≈ [3]) — the monorepo's magic indices assumed a fixed ordering; the
51
- * flag survives reordering. All preview typography stays inline from the
52
- * selected style (fontFamily / fontWeight / fontStyle / wdth variation) because
53
- * arbitrary loaded fonts + variable axes can't be fixed KOL type classes.
54
- *
55
- * Text casing: badgeText, style labels and specimen strings render verbatim.
56
- *
57
- * @param {Object} props.typeface - { fontFamily, badgeText, styles:{ hasWeight, hasWidth, hasItalic, defaultStyle?, weights[], widths[] } }.
58
- * @param {string[]} props.sampleLines - Preview lines (default AaBbCc / 01234567 / {(!@#$?&)}).
59
- */
60
- const TypefaceStyleSection = ({
61
- typeface = {},
62
- sampleLines = ['AaBbCc', '01234567', '{(!@#$?&)}'],
63
- }) => {
64
- const { fontFamily, badgeText, styles: styleConfig = {} } = typeface
65
- const {
66
- hasWeight,
67
- hasWidth,
68
- hasItalic,
69
- defaultStyle = 'weight',
70
- weights = [],
71
- widths = [],
72
- } = styleConfig
73
-
74
- const showDropdown = hasItalic || (hasWeight && hasWidth)
75
- const styleOptions = hasItalic
76
- ? [
77
- { label: 'Roman', value: 'roman' },
78
- { label: 'Italic', value: 'italic' },
79
- ]
80
- : hasWeight && hasWidth
81
- ? [
82
- { label: 'Weight', value: 'weight' },
83
- { label: 'Width', value: 'width' },
84
- ]
85
- : null
86
-
87
- const [selectedStyleVariant, setSelectedStyleVariant] = useState(
88
- hasItalic ? 'italic' : defaultStyle,
89
- )
90
- const isItalic = selectedStyleVariant === 'italic'
91
- const activeList = showDropdown && selectedStyleVariant === 'width' ? widths : weights
92
-
93
- const [currentStyle, setCurrentStyle] = useState(() => pickDefault(activeList) || {})
94
-
95
- const handleStyleVariantChange = (newVariant) => {
96
- setSelectedStyleVariant(newVariant)
97
- if (newVariant === 'width') setCurrentStyle(pickDefault(widths) || {})
98
- else setCurrentStyle(pickDefault(weights) || {})
99
- }
100
-
101
- const previewStyle = {
102
- fontFamily,
103
- fontWeight: currentStyle.weight || 400,
104
- fontStyle: isItalic ? 'italic' : 'normal',
105
- ...(currentStyle.width ? { fontVariationSettings: `'wdth' ${currentStyle.width}` } : {}),
106
- }
107
-
108
- return (
109
- <section className="w-full py-12 lg:py-16">
110
- <div className="max-w-[1400px] mx-auto flex flex-col gap-8">
111
- <SpecimenSectionHeader
112
- selectedStyle={selectedStyleVariant}
113
- onStyleChange={handleStyleVariantChange}
114
- styleOptions={styleOptions || undefined}
115
- showDropdown={showDropdown}
116
- badgeText={badgeText}
117
- icon="foundation"
118
- size="sm"
119
- />
120
-
121
- <div className="flex flex-row gap-4 md:gap-6 lg:gap-8 items-start w-full">
122
- {/* Left: sticky inverted preview panel */}
123
- <div className="w-1/2 aspect-[4/3] p-6 md:p-12 transition-colors duration-300 sticky top-24 bg-surface-inverse rounded">
124
- <div
125
- className="text-center transition-colors duration-300 w-full h-full flex flex-col justify-center items-center gap-2"
126
- style={previewStyle}
127
- >
128
- {sampleLines.map((line, i) => (
129
- <div key={i} className="text-3xl md:text-5xl lg:text-6xl leading-none">
130
- {line}
131
- </div>
132
- ))}
133
- </div>
134
- </div>
135
-
136
- {/* Right: styles list */}
137
- <div className="w-1/2 flex flex-col gap-3">
138
- {activeList.map((style, index) => (
139
- <StyleCard
140
- key={`${style.label}-${index}`}
141
- label={style.label}
142
- weight={style.weight}
143
- width={style.width}
144
- italic={isItalic}
145
- isActive={
146
- currentStyle?.label === style.label &&
147
- (style.weight
148
- ? currentStyle?.weight === style.weight
149
- : currentStyle?.width === style.width)
150
- }
151
- onHover={() => setCurrentStyle(style)}
152
- onClick={() => setCurrentStyle(style)}
153
- fontFamily={fontFamily}
154
- />
155
- ))}
156
- </div>
157
- </div>
158
- </div>
159
- </section>
160
- )
161
- }
162
-
163
- export default TypefaceStyleSection