Module config

Source
Expand description

Define the Config structure used to configure the generate function using a Tailwind-like configuration.

§Example

use encre_css::{Config, config::DarkMode};

let mut config = Config::default();

// Toggles the dark mode using the class `.dark`
config.theme.dark_mode = DarkMode::new_class(".dark");

// Defines some custom colors, they will be usable in the `text`, `bg`,
// `border`, etc utilities.
config.theme.colors.add("primary", "#d3198c");
config.theme.colors.add("secondary", "#fff");

// Defines some custom screen breakpoints
config.theme.screens.add("tablet", "640px");
config.theme.screens.add("laptop", "1024px");
config.theme.screens.add("desktop", "1280px");

let generated = encre_css::generate(
    ["tablet:dark:bg-primary"],
    &config,
);

assert!(generated.ends_with(r#"@media (min-width: 640px) {
  .dark .tablet\:dark\:bg-primary {
    --en-bg-opacity: 1;
    background-color: rgb(211 25 140 / var(--en-bg-opacity));
  }
}"#));

The previous example is equivalent to the following TOML configuration file:

[theme]
dark_mode = { type = "class", class = ".dark" }
colors = { primary = "#d3198c", secondary = "#fff" }
screens = { tablet = "640px", laptop = "1024px", desktop = "1280px" }

Structs§

Aria
Configuration for the Theme::aria field.
Colors
Configuration for the Theme::colors field.
Config
The configuration of the CSS generation done in the generate function.
Extra
Configuration for the Config::extra field.
MaxShortcutDepth
The maximum depth at which shortcuts will be resolved.
Safelist
Configuration for the Config::safelist field.
Screens
Configuration for the Theme::screens field.
Shortcuts
Configuration for the Config::shortcuts field.
Theme
Configuration for the Config::theme field.

Enums§

DarkMode
Configuration for the Theme::dark_mode field.

Constants§

BUILTIN_COLORS
The list of all default colors.
BUILTIN_PLUGINS
The list of all default plugins.
BUILTIN_SCREENS
The list of all default screen breakpoints.
BUILTIN_VARIANTS
The list of all default variants (sorted following their importance in the CSS file).