Block library: styles step uses the token styles.css; test that every token utility exists in the preset
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
e686fb2af5
commit
f338324762
@@ -61,11 +61,15 @@ export const blockRegistry = createBlockRegistry(content, {
|
||||
The plugin never imports `next/*` itself, so `Image` and `Link` are passed in. `createPageRoute(content, { blocks: blockRegistry, … })`
|
||||
or `<RenderBlocks components={blockRegistry} />` renders them (docs/frontend.md, docs/blocks.md).
|
||||
|
||||
**3. Styles.** The components use the token utilities of the design-token preset (`@intecion/ipal-kit/tailwind.css`)
|
||||
and Tailwind must scan the plugin's files — the line projects already have:
|
||||
**3. Styles.** The components use the token utilities of the design-token preset, and Tailwind must scan the
|
||||
plugin's files. The standard `styles.css` ([design-tokens.md](./design-tokens.md)) already does both:
|
||||
|
||||
```css
|
||||
@import "tailwindcss";
|
||||
@import "@intecion/ipal-kit/fluid-wide.css";
|
||||
@import "@intecion/ipal-kit/tokens.css";
|
||||
@import "@intecion/ipal-kit/tailwind.css";
|
||||
@import "../../design/tokens.css";
|
||||
@source "../../../node_modules/@intecion/ipal-kit/dist/**/*.js";
|
||||
```
|
||||
|
||||
|
||||
@@ -230,6 +230,34 @@ describe('styling: design tokens only', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('styling: every token utility the blocks use exists in the preset', () => {
|
||||
test('colours, radii, spacing and widths come from tailwind.css', () => {
|
||||
const preset = readFileSync(path.join(root, 'src/styles/tailwind.css'), 'utf8')
|
||||
const theme = (ns: string) => new Set([...preset.matchAll(new RegExp(`--${ns}-([\\w-]+?)(?:--[\\w-]+)?:`, 'g'))].map((m) => m[1]))
|
||||
const colors = theme('color')
|
||||
const radii = new Set(['full', 'none', ...theme('radius')])
|
||||
const spacing = theme('spacing')
|
||||
const widths = new Set(['full', 'md', 'none', ...theme('container')])
|
||||
const text = new Set(['center', 'left', 'right', ...theme('text')])
|
||||
const problems: string[] = []
|
||||
const classes = libraryFiles().filter((f) => !f.endsWith('thumbnails.ts')).flatMap((file) =>
|
||||
[...readFileSync(file, 'utf8').matchAll(/'([^'\n]*)'|"([^"\n]*)"/g)].flatMap((m) => (m[1] ?? m[2] ?? '').split(/\s+/).map((c) => [path.relative(root, file), c] as const)),
|
||||
)
|
||||
for (const [file, raw] of classes) {
|
||||
const c = raw.replace(/^(?:[a-z0-9@-]+:)+/, '') // drop variants: hover:, md:, group-open:, after:
|
||||
let m: null | RegExpMatchArray
|
||||
if ((m = c.match(/^(?:bg|text|border|from|to|outline|ring|before:text)-([a-z][\w-]*)$/)) && !/^(?:\d|[blrtxy](?:-|$)|offset|linear|transparent|inherit|current)/.test(m[1])) {
|
||||
const name = m[1]
|
||||
const known = colors.has(name) || (c.startsWith('text-') && text.has(name)) || (c.startsWith('border-') && /^\d+$/.test(name))
|
||||
if (!known) {problems.push(`${file}: ${raw} (no --color-${name})`)}
|
||||
} else if ((m = c.match(/^rounded-([a-z][\w-]*)$/)) && !radii.has(m[1])) {problems.push(`${file}: ${raw}`)}
|
||||
else if ((m = c.match(/^(?:p[xytblr]?|m[xytblr]?|gap(?:-[xy])?|space-y)-([a-z][a-z-]*)$/)) && !['auto', 'px'].includes(m[1]) && !spacing.has(m[1])) {problems.push(`${file}: ${raw}`)}
|
||||
else if ((m = c.match(/^max-w-([a-z][\w-]*)$/)) && !widths.has(m[1])) {problems.push(`${file}: ${raw}`)}
|
||||
}
|
||||
expect(problems).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
describe('ipal-blocks eject', () => {
|
||||
const tmp = mkdtempSync(path.join(os.tmpdir(), 'ipal-eject-'))
|
||||
afterAll(() => rmSync(tmp, { force: true, recursive: true }))
|
||||
|
||||
Reference in New Issue
Block a user