pub struct Variant<'a> { /* private fields */ }
Expand description
A selector variant.
Implementations§
Source§impl<'a> Variant<'a>
impl<'a> Variant<'a>
Sourcepub fn new<T: Into<Cow<'a, str>>>(order: usize, template: T) -> Self
pub fn new<T: Into<Cow<'a, str>>>(order: usize, template: T) -> Self
Create a new variant.
The order is used to decide where the generated class having this variant will be placed in
the generated CSS. Config::last_variant_order
can be used to insert a variant after all
the others.
The template is a string which defines how the class will be modified. If it starts with @
,
a CSS block will wrap the inner class (like media queries), otherwise just the class name will
be modified.
The template should contain &
which will be replaced by the complete class name.
§Example
use encre_css::{Config, selector::Variant};
use std::borrow::Cow;
let mut config = Config::default();
config.register_variant(
"headings",
// Insert the classes having this variant after all the other variants
Variant::new(config.last_variant_order(), "& :where(h1, h2, h3, h4, h5, h6)")
);
let generated = encre_css::generate(
["headings:text-gray-700"],
&config,
);
assert!(generated.ends_with(".headings\\:text-gray-700 :where(h1, h2, h3, h4, h5, h6) {
color: oklch(37.3% .034 259.733);
}"));
Sourcepub const fn with_prefixed(self) -> Self
pub const fn with_prefixed(self) -> Self
Defines a prefixed variant which is composed of a prefix and an arbitrary value which will be inserted into the variant template.
A prefixed variant can have {}
in its template which will be replaced by the arbitrary
value.
§Example
use encre_css::{Config, selector::Variant};
use std::borrow::Cow;
let mut config = Config::default();
config.register_variant(
"media",
// Insert the classes having this variant after all the other variants
Variant::new(config.last_variant_order(), "@media {}").with_prefixed()
);
let generated = encre_css::generate(
["media-[print]:flex"],
&config,
);
assert!(generated.ends_with(r"@media print {
.media-\[print\]\:flex {
display: flex;
}
}"));
Trait Implementations§
impl<'a> Eq for Variant<'a>
Auto Trait Implementations§
impl<'a> Freeze for Variant<'a>
impl<'a> RefUnwindSafe for Variant<'a>
impl<'a> Send for Variant<'a>
impl<'a> Sync for Variant<'a>
impl<'a> Unpin for Variant<'a>
impl<'a> UnwindSafe for Variant<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more