Selectors
Map short names to CSS selector patterns for concise nested style definitions.
Custom selectors let you define short, readable names for complex CSS selectors. Instead of writing full @media queries or compound selectors repeatedly, define them once and reference them by name in your style definitions.
The $ placeholder in a selector value is replaced with the generated atomic class selector.
Config
Selectors can be defined as static pairs or dynamic patterns:
ts
import { defineEngineConfig } from '@pikacss/core'
export default defineEngineConfig({
selectors: {
definitions: [
// Static pair: [name, cssSelector]
['@dark', 'html.dark $'],
['@light', 'html:not(.dark) $'],
// Media query selectors
['@sm', '@media (min-width: 640px)'],
['@md', '@media (min-width: 768px)'],
['@lg', '@media (min-width: 1024px)'],
['@xl', '@media (min-width: 1280px)'],
// Dynamic pattern: [RegExp, resolver, autocomplete?]
[/^@container-(.+)$/, ([, name]) => `@container ${name}`],
],
},
})Use custom selectors in style definitions:
ts
pika({
'color': 'black',
'@dark': { color: 'white' },
'@sm': { fontSize: '14px' },
'@lg': { fontSize: '18px' },
})Examples
ts
import { defineEngineConfig } from '@pikacss/core'
export const selectorsConfig = defineEngineConfig({
selectors: {
definitions: [
['@dark', 'html.dark $'],
['@light', 'html:not(.dark) $'],
['@sm', '@media (min-width: 640px)'],
['@md', '@media (min-width: 768px)'],
['@lg', '@media (min-width: 1024px)'],
],
},
})