스타일 토큰 회귀 강화: focus-visible 링/오프셋, disabled/readonly 토큰 및 규칙 추가, 테스트 보강
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { exportFrame } from '@/lib/wysiwyg/export'
|
||||
import type { Frame } from '@/lib/wysiwyg/schema'
|
||||
|
||||
function baseFrame(): Frame {
|
||||
return {
|
||||
id: 'f', width: 320, height: 200, background: '#111111',
|
||||
layers: [{ id: 'l1', name: 'Base', visible: true, locked: false, objects: [] }],
|
||||
}
|
||||
}
|
||||
|
||||
describe('wysiwyg export - disabled/read-only control tokens', () => {
|
||||
it('defines disabled tokens and uses them for :disabled and [readonly]', () => {
|
||||
const out = exportFrame(baseFrame())
|
||||
// tokens
|
||||
expect(out.css).toMatch(/:root\s*{[^}]*--disabled-bg:/)
|
||||
expect(out.css).toMatch(/:root\s*{[^}]*--disabled-fg:/)
|
||||
// usage
|
||||
expect(out.css).toMatch(/input:disabled,select:disabled,textarea:disabled\s*{[^}]*background:var\(--disabled-bg\)/)
|
||||
expect(out.css).toMatch(/input:disabled,select:disabled,textarea:disabled\s*{[^}]*color:var\(--disabled-fg\)/)
|
||||
expect(out.css).toMatch(/input\[readonly\],select\[readonly\],textarea\[readonly\]\s*{[^}]*color:var\(--disabled-fg\)/)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,22 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { exportFrame } from '@/lib/wysiwyg/export'
|
||||
import type { Frame } from '@/lib/wysiwyg/schema'
|
||||
|
||||
function baseFrame(): Frame {
|
||||
return {
|
||||
id: 'f', width: 320, height: 200, background: '#111111',
|
||||
layers: [{ id: 'l1', name: 'Base', visible: true, locked: false, objects: [] }],
|
||||
}
|
||||
}
|
||||
|
||||
describe('wysiwyg export - focus-visible ring tokens', () => {
|
||||
it('defines ring tokens and uses them in :focus-visible styles', () => {
|
||||
const out = exportFrame(baseFrame())
|
||||
// tokens
|
||||
expect(out.css).toMatch(/:root\s*{[^}]*--ring:/)
|
||||
expect(out.css).toMatch(/:root\s*{[^}]*--ring-offset:/)
|
||||
// usage (focus-visible across common focusables and controls)
|
||||
expect(out.css).toMatch(/:focus-visible\s*{[^}]*outline:2px solid var\(--ring\)/)
|
||||
expect(out.css).toMatch(/:focus-visible\s*{[^}]*outline-offset:var\(--ring-offset\)/)
|
||||
})
|
||||
})
|
||||
@@ -120,15 +120,18 @@ export function exportFrame(frame: Frame): Exported {
|
||||
}
|
||||
const inner = `<div class="frame-scale"><div class="frame">${piecesHtml.join('')}</div></div>`
|
||||
const css = [
|
||||
`:root{--bg:${frame.background};--text:#f9fafb;--border:#94a3b8;--primary:#0ea5e9;--danger:#ef4444}`,
|
||||
`[data-theme="light"]{--bg:#ffffff;--text:#0f172a;--border:#cbd5e1;--primary:#0ea5e9;--danger:#ef4444}`,
|
||||
`[data-theme="dark"]{--bg:#111111;--text:#f9fafb;--border:#94a3b8;--primary:#0ea5e9;--danger:#ef4444}`,
|
||||
`:root{--bg:${frame.background};--text:#f9fafb;--border:#94a3b8;--primary:#0ea5e9;--danger:#ef4444;--ring:#22c55e;--ring-offset:2px;--disabled-bg:#e5e7eb;--disabled-fg:#9ca3af}`,
|
||||
`[data-theme="light"]{--bg:#ffffff;--text:#0f172a;--border:#cbd5e1;--primary:#0ea5e9;--danger:#ef4444;--ring:#22c55e;--ring-offset:2px;--disabled-bg:#e5e7eb;--disabled-fg:#6b7280}`,
|
||||
`[data-theme="dark"]{--bg:#111111;--text:#f9fafb;--border:#94a3b8;--primary:#0ea5e9;--danger:#ef4444;--ring:#22c55e;--ring-offset:2px;--disabled-bg:#1f2937;--disabled-fg:#9ca3af}`,
|
||||
`.frame{position:relative;width:${frame.width}px;height:${frame.height}px;background:var(--bg)}`,
|
||||
`.frame-scale{transform-origin:0 0}`,
|
||||
`a{color:var(--primary);text-decoration:none}`,
|
||||
`input,select,textarea{color:var(--text);background:transparent;border:1px solid var(--border)}`,
|
||||
`:focus-visible{outline:2px solid var(--ring);outline-offset:var(--ring-offset)}`,
|
||||
`input:focus,select:focus,textarea:focus{outline:2px solid var(--primary);outline-offset:2px}`,
|
||||
`input:invalid,select:invalid,textarea:invalid{border-color:var(--danger)}`,
|
||||
`input:disabled,select:disabled,textarea:disabled{background:var(--disabled-bg);color:var(--disabled-fg)}`,
|
||||
`input[readonly],select[readonly],textarea[readonly]{color:var(--disabled-fg)}`,
|
||||
`fieldset{border:1px solid var(--border)}`,
|
||||
`legend{color:var(--text)}`,
|
||||
...piecesCss,
|
||||
|
||||
Reference in New Issue
Block a user