feat(css): add classNameSlug option to createCssContext #4834

Openflow-pie wants to merge 1 commit into main from feat/css-class-name-slug· opened 2 days ago
+61−18
flow-pie commented 2 days agoAuthor

Description

Adds an optional classNameSlug function to createCssContext that lets users customize generated CSS class names instead of the default css-1234567890 format.

Closes #4577

Before: Always generates css-1234567890 After: Pass classNameSlug: (hash, label, css) => string to get custom names

const { css, Style } = createCssContext({
  id: 'my-styles',
  classNameSlug: (hash, label) => label.trim() ? `h-${label.trim()}` : hash,
})

const hero = css`/* hero-section */ background: blue;`
// .h-hero-section { background: blue; }

Changes

  • src/helper/css/common.ts: exported ClassNameSlug type, added optional classNameSlug param to cssCommon()
  • src/helper/css/index.ts: added classNameSlug option to createCssContext(), exported ClassNameSlug type
  • src/helper/css/index.test.tsx: 4 new tests for custom slug, label extraction, fallback, and default behavior

Verification

  • All existing tests pass
  • TypeScript: 0 errors
  • ESLint: 0 warnings
  • Prettier: all files formatted

API

type ClassNameSlug = (hash: string, label: string, css: string) => string

createCssContext({
  id: string,
  classNameSlug?: ClassNameSlug,
})

The function receives:

  • hash: the default css-1234567890 string
  • label: extracted from /* comment */ at start of template (may be empty)
  • css: the minified CSS string
flow-pie added 1 commit 2 days ago
feat(css): add classNameSlug option to createCssContext906a667

Review required

Review the changes, then submit to get graded.

Some checks haven’t completed yet

1 check: dojo / review-grader

Keyboard shortcuts

Site-wide

Focus the search bar
/
Show this dialog
?

Pull request

Move to the next file
j
Move to the previous file
k
Filter changed files
t
Comment on the selected lines
c
Select a range of lines
Shiftclick