Presets
Overview
The useModifiersPreset composable registers all available modifier categories with your Styleframe instance in a single function call. It returns a flat object containing all individual modifier instances, ready to be passed to utility creator functions.
Why use presets?
- Complete Coverage: Register all 8 modifier categories with one function call
- Flat Return Value: All individual modifiers are spread into a single flat object for easy destructuring
- Selective Disabling: Disable specific categories you don't need via configuration
Quick Start
import { styleframe } from 'styleframe';
import { useModifiersPreset, useUtilitiesPreset } from '@styleframe/theme';
const s = styleframe();
// Register all modifiers
const { hover, focus, active, dark, disabled, first, last } = useModifiersPreset(s);
// Register utilities and create values with modifiers
const { createBackgroundColorUtility, createOpacityUtility } = useUtilitiesPreset(s);
createBackgroundColorUtility({
primary: '#006cff',
secondary: '#6c757d',
}, [hover, focus, dark]);
createOpacityUtility({
0: '0',
50: '0.5',
100: '1',
}, [hover]);
export default s;
/* Base utilities */
._background-color\:primary { background-color: #006cff; }
._background-color\:secondary { background-color: #6c757d; }
/* Hover modifier variants */
._hover\:background-color\:primary:hover { background-color: #006cff; }
._hover\:background-color\:secondary:hover { background-color: #6c757d; }
/* Focus modifier variants */
._focus\:background-color\:primary:focus { background-color: #006cff; }
._focus\:background-color\:secondary:focus { background-color: #6c757d; }
/* Dark mode modifier variants */
@media (prefers-color-scheme: dark) {
._dark\:background-color\:primary { background-color: #006cff; }
._dark\:background-color\:secondary { background-color: #6c757d; }
}
/* Opacity with hover */
._opacity\:0 { opacity: 0; }
._opacity\:50 { opacity: 0.5; }
._opacity\:100 { opacity: 1; }
._hover\:opacity\:0:hover { opacity: 0; }
._hover\:opacity\:50:hover { opacity: 0.5; }
._hover\:opacity\:100:hover { opacity: 1; }
useModifiersPreset
Registers all modifier categories with the Styleframe instance and returns a flat object containing all individual modifier instances.
Signature
function useModifiersPreset(
s: Styleframe,
config?: ModifiersConfig
): ModifierInstances
Configuration Options
Each modifier category can be configured as:
- Omitted or
undefined(default): Enable the category false: Disable the category entirely
| Option | Type | Default | Description |
|---|---|---|---|
pseudoStates | boolean | true | Pseudo-class state modifiers (hover, focus, active, etc.) |
formStates | boolean | true | Form state modifiers (disabled, checked, valid, etc.) |
structural | boolean | true | Structural pseudo-class modifiers (first, last, odd, even, etc.) |
pseudoElements | boolean | true | Pseudo-element modifiers (before, after, placeholder, etc.) |
mediaPreferences | boolean | true | Media/preference query modifiers (dark, motionSafe, print, etc.) |
ariaStates | boolean | true | ARIA state modifiers (ariaExpanded, ariaDisabled, etc.) |
directional | boolean | true | Directional modifiers (rtl, ltr) |
otherStates | boolean | true | Other state modifiers (open, inert) |
Return Value
Returns a flat ModifierInstances object containing all individual modifiers from every enabled category. The modifiers are spread into a single object for easy destructuring:
const {
// Pseudo-State
hover, focus, focusWithin, focusVisible, active, visited, target,
// Form State
disabled, enabled, checked, indeterminate, required, optional, valid, invalid,
placeholderShown, autofill, readOnly,
// Structural
first, last, only, odd, even, firstOfType, lastOfType, onlyOfType, empty,
// Pseudo-Elements
before, after, placeholder, selection, firstLetter, firstLine, marker, backdrop, file,
// Media & Preferences
dark, motionSafe, motionReduce, contrastMore, contrastLess, portrait, landscape, print, forcedColors,
// ARIA State
ariaBusy, ariaChecked, ariaDisabled, ariaExpanded, ariaHidden, ariaPressed, ariaReadonly,
ariaRequired, ariaSelected,
// Directional
rtl, ltr,
// Other State
open, inert,
} = useModifiersPreset(s);
Selective Registration
Disable specific categories you don't need:
import { styleframe } from 'styleframe';
import { useModifiersPreset } from '@styleframe/theme';
const s = styleframe();
const modifiers = useModifiersPreset(s, {
pseudoStates: true, // Keep hover, focus, active, etc.
formStates: true, // Keep disabled, checked, valid, etc.
mediaPreferences: true, // Keep dark, motionReduce, etc.
structural: false, // Skip first, last, odd, even
pseudoElements: false, // Skip before, after, placeholder
ariaStates: false, // Skip ARIA modifiers
directional: false, // Skip rtl, ltr
otherStates: false, // Skip open, inert
});
export default s;
Pre-generating Modifier Variants
When using the Styleframe Vite plugin, the scanner automatically detects modifier-prefixed utility class names in your source files and generates the corresponding CSS — so you don't need to manually pass modifiers to every utility creator. However, if you want to pre-generate specific modifier variants tied to your design tokens, you can pass modifier instances to creator functions:
import { styleframe } from 'styleframe';
import { useUtilitiesPreset, useModifiersPreset, useColor } from '@styleframe/theme';
const s = styleframe();
// Register modifiers and get instances
const { hover, focus, dark } = useModifiersPreset(s);
// Register utilities and get creators
const { createBackgroundColorUtility, createTextColorUtility } = useUtilitiesPreset(s);
// Create color tokens
const { colorPrimary, colorSecondary } = useColor(s, {
primary: '#006cff',
secondary: '#6c757d',
} as const);
// Pre-generate modifier variants for specific values
createBackgroundColorUtility({
primary: s.ref(colorPrimary),
secondary: s.ref(colorSecondary),
}, [hover, focus, dark]);
createTextColorUtility({
primary: s.ref(colorPrimary),
secondary: s.ref(colorSecondary),
}, [hover]);
export default s;
This generates classes like _background-color:primary, _hover:background-color:primary, _focus:background-color:primary, and _dark:background-color:primary.
Available Modifier Groups
| Group Function | Modifiers | Purpose |
|---|---|---|
usePseudoStateModifiers(s) | hover, focus, focusWithin, focusVisible, active, visited, target | Interactive states |
useFormStateModifiers(s) | disabled, enabled, checked, indeterminate, required, optional, valid, invalid, placeholderShown, autofill, readOnly | Form element states |
usePseudoElementModifiers(s) | before, after, placeholder, selection, firstLetter, firstLine, marker, backdrop, file | Element sub-parts |
useAriaStateModifiers(s) | ariaBusy, ariaChecked, ariaDisabled, ariaExpanded, ariaHidden, ariaPressed, ariaReadonly, ariaRequired, ariaSelected | ARIA attribute states |
useStructuralModifiers(s) | first, last, only, odd, even, firstOfType, lastOfType, onlyOfType, empty | DOM position |
useMediaPreferenceModifiers(s) | dark, motionSafe, motionReduce, contrastMore, contrastLess, portrait, landscape, print, forcedColors | User preferences |
useDirectionalModifiers(s) | rtl, ltr | Text direction |
useOtherStateModifiers(s) | open, inert | Miscellaneous states |
FAQ
useHoverModifier) register a single modifier, while group composables (like usePseudoStateModifiers) register all modifiers in a category. useModifiersPreset() registers all 8 categories at once, making it the most convenient option when you need comprehensive modifier coverage.Yes! You can use the preset for most modifiers and add individual ones separately:
const { hover, focus } = useModifiersPreset(s, {
pseudoStates: true,
formStates: false, // Skip form states in preset
});
// Register only specific form state modifiers
import { useDisabledModifier, useCheckedModifier } from '@styleframe/theme';
const disabled = useDisabledModifier(s);
const checked = useCheckedModifier(s);
useUtilitiesPreset() only registers utility factories. Call useModifiersPreset() separately to register modifier factories. Both are needed for full coverage when using the scanner.Pass an array of modifier instances as the second argument to any utility creator function:
const { hover, focus, dark } = useModifiersPreset(s);
const { createOpacityUtility } = useUtilitiesPreset(s);
createOpacityUtility({ 0: '0', 50: '0.5', 100: '1' }, [hover, focus, dark]);
// Generates: _opacity:50, _hover:opacity:50, _focus:opacity:50, _dark:opacity:50, etc.