Getting Started
Configuration
Configure your Styleframe instance with custom options for indentation, variable naming, utility selectors, and theme selectors.
Overview
The Styleframe instance accepts configuration options that allow you to customize how your styles are generated. These options give you fine-grained control over indentation, variable naming conventions, utility class selectors, and theme selectors — ensuring the generated CSS matches your project's conventions and requirements.
Why configure Styleframe?
Configuration helps you:
- Match your code style: Set custom indentation to align with your project's formatting rules.
- Follow naming conventions: Customize how CSS variable names are generated to match your design system.
- Control selector output: Define how utility classes and theme selectors are generated.
- Ensure consistency: Maintain consistent patterns across your entire codebase.
Configuration Options
You configure Styleframe by passing an options object when creating an instance:
export type StyleframeOptions = {
indent?: string;
variables?: {
name?: VariableNameFn;
};
utilities?: {
selector?: UtilitySelectorFn;
};
theme?: {
selector?: ThemeSelectorFn;
};
};
import { styleframe } from "styleframe";
const s = styleframe({
... // Your configuration options here
});
export default s;
Let's explore each configuration option in detail.
variables.name
function
type VariableNameFn = (options: { name: string }) => string;
-- prefix if not present. You can provide a custom function to transform variable names.utilities.selector
function
type UtilitySelectorFn = (options: {
name: string;
value: string;
modifiers: string[];
}) => string;
._${name}:${value}:${modifiers}. You can provide a custom function to change how utility selectors are generated.theme.selector
function
type ThemeSelectorFn = (options: { name: string }) => string;
[data-theme="${name}"]. You can provide a custom function to change how theme selectors are generated.Best Practices
- Define configuration once: Create a single configured instance and export it for use across your project.
- Match your project conventions: Align the configuration with your existing CSS and naming conventions.
- Document your choices: Add comments explaining why specific configuration options were chosen.
- Use consistent patterns: Ensure your naming functions produce predictable, consistent results.
- Test generated output: Verify that the generated CSS matches your expectations after configuration changes.
FAQ
Yes, however it's recommended to set the configuration once during instance creation to avoid inconsistencies in the generated CSS.
Styleframe uses sensible defaults: tab indentation, standard CSS variable naming with
-- prefix, and conventional selector patterns.Yes! You can create multiple Styleframe instances with different configurations. Just be mindful of potential naming conflicts in the generated CSS.
The
ref() helper automatically uses the transformed names based on your configuration, so you don't need to worry about the transformation when referencing variables.The naming functions should return valid CSS identifiers. Avoid special characters that aren't allowed in CSS variable names or selectors.