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;
    };
};

Let's explore each configuration option in detail.


variables.name

function
type VariableNameFn = (options: { name: string }) => string;
By default, variable names are converted to CSS custom properties by adding the -- 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;
By default, utility class selectors use the pattern ._${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;
By default, theme selectors use the pattern [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