pub struct ListProperties<Str, ArrayStr, MapStr, MapArrayStr> {
pub props: MapArrayStr,
pub namespace: Option<Str>,
pub extra_rule_css: Option<ArrayStr>,
pub extra_css: Option<MapStr>,
pub extra_class: Option<Str>,
}Expand description
Define a plugin using a map between utility classes and raw CSS lines.
It directly generates the CSS of the map value if the utility class as map key is scanned.
Map values are arrays which represent individual lines of the CSS so that each line can be correctly indented.
If a utility class maps to an empty array, no class will be generated at all. This behavior can
be combined with ListProperties::extra_css to generate root-level CSS blocks (like
@keyframe animations).
If you instead need to map CSS property values to a single CSS property, use ListValues.
§Example
use encre_css::{Config, generate};
use encre_css::prelude::build_plugin::*;
const PLUGIN: StaticPlugin = Plugin::ListProperties(ListProperties {
props: map! {
"overflow-visible" => &["overflow: visible;"],
"overflow-hidden" => &["overflow: hidden;"],
"overflow-clip" => &["overflow: clip;"],
"overflow-scroll" => &["overflow: scroll;"],
"overflow-auto" => &["overflow: auto;"],
},
..ListProperties::default()
});
let mut config = Config::default();
config.register_plugin(&PLUGIN);
let generated = generate(["overflow-scroll"], &config);
assert!(generated.ends_with(r".overflow-scroll {
overflow: scroll;
}"));§Example in TOML
[[custom_plugins]]
[custom_plugins.ListProperties]
[custom_plugins.ListProperties.props]
overflow-visible = ["overflow: visible;"]
overflow-hidden = ["overflow: hidden;"]
overflow-clip = ["overflow: clip;"]
overflow-scroll = ["overflow: scroll;"]
overflow-auto = ["overflow: auto;"]Fields§
§props: MapArrayStrThe map between utility classes and raw CSS lines.
This field should be assigned separately after calling ListProperties::default (or
ListProperties::default_dynamic).
namespace: Option<Str>Define a namespace (i.e a prefix) common to all utility classes declared in the map keys.
The last dash character (-) should be omitted due to the way the parsing of utility classes work
(e.g in the example below, overflow is correct while overflow- is incorrect).
§Example
use encre_css::{Config, generate};
use encre_css::prelude::build_plugin::*;
const PLUGIN: StaticPlugin = Plugin::ListProperties(ListProperties {
namespace: Some("overflow"),
props: map! {
"visible" => &["overflow: visible;"],
"hidden" => &["overflow: hidden;"],
"clip" => &["overflow: clip;"],
"scroll" => &["overflow: scroll;"],
"auto" => &["overflow: auto;"],
},
..ListProperties::default()
});
let mut config = Config::default();
config.register_plugin(&PLUGIN);
let generated = generate(["overflow-scroll"], &config);
assert!(generated.ends_with(r".overflow-scroll {
overflow: scroll;
}"));extra_rule_css: Option<ArrayStr>Add one or several extra CSS line(s) inside the CSS rule generated for the utility class.
This field takes an array which represents the CSS lines that will be properly indented and added, one after another, in the order they are defined, to the CSS rule.
§Example
use encre_css::{Config, generate};
use encre_css::prelude::build_plugin::*;
const PLUGIN: StaticPlugin = Plugin::Spacing(Spacing {
namespace: "custom-translate-x",
prop: SingleProp("--translate-x"),
extra_rule_css: Some(&["transform: translate(var(--translate-x), 12px);"]),
..Spacing::default()
});
let mut config = Config::default();
config.register_plugin(&PLUGIN);
let generated = generate(["custom-translate-x-8"], &config);
assert!(generated.ends_with(".custom-translate-x-8 {
--translate-x: 2rem;
transform: translate(var(--translate-x), 12px);
}"));§Example in TOML
[[custom_plugins]]
[custom_plugins.Spacing]
namespace = "custom-translate-x"
prop = "--translate-x"
extra_rule_css = ["transform: translate(var(--translate-x), 12px);"]extra_css: Option<MapStr>Add one or several extra CSS line(s) outside the CSS rule generated for the utility class.
The argument is a map which allows choosing the added CSS based on the modifier value.
§Example
use encre_css::{Config, generate};
use encre_css::prelude::build_plugin::*;
const SPIN_ANIMATION: &str = "@keyframes anim-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}\n\n";
const FADE_IN_ANIMATION: &str = "@keyframes anim-fade-in {
from {
opacity: 0;
}
to {
opacity: 1;
}
}\n\n";
const PLUGIN: StaticPlugin = Plugin::ListValues(ListValues {
prop: SingleProp("animation"),
values: map! {
"custom-animate-spin" => "anim-spin",
"custom-animate-fade-in" => "anim-fade-in",
},
extra_css: Some(map! {
"custom-animate-spin" => SPIN_ANIMATION,
"custom-animate-fade-in" => FADE_IN_ANIMATION,
}),
..ListValues::default()
});
let mut config = Config::default();
config.register_plugin(&PLUGIN);
let generated = generate(["custom-animate-spin"], &config);
assert!(generated.ends_with("@keyframes anim-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
.custom-animate-spin {
animation: anim-spin;
}"));§Example in TOML
[[custom_plugins]]
[custom_plugins.ListValues]
prop = "animation"
[custom_plugins.ListValues.values]
custom-animate-spin = "anim-spin"
custom-animate-fade-in = "anim-fade-in"
[custom_plugins.ListValues.extra_css]
custom-animate-spin = """@keyframes anim-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}\n\n"""
custom-animate-fade-in = """@keyframes anim-fade-in {
from {
opacity: 0;
}
to {
opacity: 1;
}
}\n\n"""extra_class: Option<Str>Add a suffix string to the class selector of the generated CSS rule.
§Example
use encre_css::{Config, generate};
use encre_css::prelude::build_plugin::*;
pub(crate) const PLUGIN: StaticPlugin = Plugin::Spacing(Spacing {
namespace: "custom-divide",
prop: SingleProp("margin-inline"),
extra_class: Some(" > :not(:last-child)"),
..Spacing::default()
});
let mut config = Config::default();
config.register_plugin(&PLUGIN);
let generated = generate(["custom-divide-2"], &config);
assert!(generated.ends_with(".custom-divide-2 > :not(:last-child) {
margin-inline: 0.5rem;
}"));§Example in TOML
[[custom_plugins]]
[custom_plugins.Spacing]
namespace = "custom-divide"
prop = "margin-inline"
extra_class = " > :not(:last-child)"Implementations§
Source§impl<Str, ArrayStr, MapStr> ListProperties<Str, ArrayStr, MapStr, Map<&'static str, &'static [&'static str]>>
impl<Str, ArrayStr, MapStr> ListProperties<Str, ArrayStr, MapStr, Map<&'static str, &'static [&'static str]>>
Sourcepub const fn default() -> Self
pub const fn default() -> Self
Make a default ListProperties plugin kind.
All required fields are initialized with empty values and optional fields are initialized
with None.
You should at least set ListProperties::props after calling this function.
This function is intended to be used as an automatic filler for default values using the struct update syntax.
The difference with ListProperties::default_dynamic is that this function can only be used to
build a plugin using static structures like &[]s, &'static strs.
§Example
use encre_css::prelude::build_plugin::*;
const PLUGIN: StaticPlugin = Plugin::ListProperties(ListProperties {
props: map! {
"overflow-visible" => &["overflow: visible;"],
"overflow-hidden" => &["overflow: hidden;"],
"overflow-clip" => &["overflow: clip;"],
"overflow-scroll" => &["overflow: scroll;"],
"overflow-auto" => &["overflow: auto;"],
},
..ListProperties::default()
});Source§impl<Str, ArrayStr, MapStr> ListProperties<Str, ArrayStr, MapStr, HashMap<String, Vec<String>>>
impl<Str, ArrayStr, MapStr> ListProperties<Str, ArrayStr, MapStr, HashMap<String, Vec<String>>>
Sourcepub fn default_dynamic() -> Self
pub fn default_dynamic() -> Self
Make a default ListProperties plugin kind.
All required fields are initialized with empty values and optional fields are initialized
with None.
You should at least set ListProperties::props after calling this function.
This function is intended to be used as an automatic filler for default values using the struct update syntax.
The difference with ListProperties::default is that this function can only be used to
build a plugin using heap-allocated structures like Strings, Vecs.
§Example
use std::collections::HashMap;
use encre_css::prelude::build_plugin::*;
fn main() {
let props = HashMap::from_iter(
["visible", "hidden", "clip", "scroll", "auto"].iter().map(|v| {
(format!("overflow-{v}"), vec![format!("overflow: {v};")])
})
);
// Note: the DynamicPlugin type hint is required to help the compiler
// find the concrete types of type parameters
let _plugin: DynamicPlugin = Plugin::ListProperties(ListProperties {
props,
..ListProperties::default_dynamic()
});
}This example is equivalent to the one of ListProperties::default.
Trait Implementations§
Source§impl<Str: Clone, ArrayStr: Clone, MapStr: Clone, MapArrayStr: Clone> Clone for ListProperties<Str, ArrayStr, MapStr, MapArrayStr>
impl<Str: Clone, ArrayStr: Clone, MapStr: Clone, MapArrayStr: Clone> Clone for ListProperties<Str, ArrayStr, MapStr, MapArrayStr>
Source§fn clone(&self) -> ListProperties<Str, ArrayStr, MapStr, MapArrayStr>
fn clone(&self) -> ListProperties<Str, ArrayStr, MapStr, MapArrayStr>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more