chore: storybook tweaks

pull/19104/head^2
Adam 2026-03-25 11:29:31 -05:00
parent 77fc88c8ad
commit d6fc5f414b
No known key found for this signature in database
GPG Key ID: 9CB48779AF150E75
1 changed files with 17 additions and 4 deletions

View File

@ -1082,13 +1082,21 @@ function Playground() {
let previewRef: HTMLDivElement | undefined
let pick: HTMLInputElement | undefined
const sample = (ctrl: CSSControl) => {
if (!ctrl.group.startsWith("Markdown")) return ctrl.selector
return ctrl.selector.replace(
'[data-component="markdown"]',
'[data-component="text-part"] [data-component="markdown"]',
)
}
/** Read computed styles from the DOM to seed slider defaults */
const readDefaults = () => {
const root = previewRef
if (!root) return
const next: Record<string, string> = {}
for (const ctrl of CSS_CONTROLS) {
const el = root.querySelector(ctrl.selector) as HTMLElement | null
const el = (root.querySelector(sample(ctrl)) ?? root.querySelector(ctrl.selector)) as HTMLElement | null
if (!el) continue
const styles = getComputedStyle(el)
// Use bracket access — getPropertyValue doesn't resolve shorthands
@ -1439,9 +1447,14 @@ function Playground() {
}
setApplyResult(lines.join("\n"))
if (ok > 0) {
// Clear overrides — values are now in source CSS, Vite will HMR.
resetCss()
if (ok === edits.length) {
batch(() => {
for (const ctrl of controls) {
setDefaults(ctrl.key, css[ctrl.key]!)
setCss(ctrl.key, undefined as any)
}
})
updateStyle()
// Wait for Vite HMR then re-read computed defaults
setTimeout(readDefaults, 500)
}