chore: storybook tweaks

This commit is contained in:
Adam
2026-03-25 11:30:41 -05:00
parent 77fc88c8ad
commit d6fc5f414b
@@ -1082,13 +1082,21 @@ function Playground() {
let previewRef: HTMLDivElement | undefined let previewRef: HTMLDivElement | undefined
let pick: HTMLInputElement | 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 */ /** Read computed styles from the DOM to seed slider defaults */
const readDefaults = () => { const readDefaults = () => {
const root = previewRef const root = previewRef
if (!root) return if (!root) return
const next: Record<string, string> = {} const next: Record<string, string> = {}
for (const ctrl of CSS_CONTROLS) { 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 if (!el) continue
const styles = getComputedStyle(el) const styles = getComputedStyle(el)
// Use bracket access — getPropertyValue doesn't resolve shorthands // Use bracket access — getPropertyValue doesn't resolve shorthands
@@ -1439,9 +1447,14 @@ function Playground() {
} }
setApplyResult(lines.join("\n")) setApplyResult(lines.join("\n"))
if (ok > 0) { if (ok === edits.length) {
// Clear overrides — values are now in source CSS, Vite will HMR. batch(() => {
resetCss() 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 // Wait for Vite HMR then re-read computed defaults
setTimeout(readDefaults, 500) setTimeout(readDefaults, 500)
} }