pub struct Style {
pub css: String,
pub class: String,
pub effects: HashMap<String, String>,
pub components: HashMap<String, String>,
}Expand description
Represents a CSS Style
Fields§
§css: String§class: String§effects: HashMap<String, String>§components: HashMap<String, String>Implementations§
source§impl Style
impl Style
sourcepub fn new(css: String, class: Option<String>) -> Result<Self, WasmCssError>
pub fn new(css: String, class: Option<String>) -> Result<Self, WasmCssError>
Construct a Style from a CSS string
-
See
style!for built-in formatting -
Generates random class name if one is not provided
-
Returns
WasmCssErrorif unable to locate Crypto when generating uuid -
Returns
WasmCssErrorif unable to locate Document/Window/Head
Example Usage:
let style: Style = Style::new(
"
gap: 10rem;
display: flex;
flex-direction: column;
",
None,
)?;sourcepub fn append(&mut self, source: &Style) -> Result<(), WasmCssError>
pub fn append(&mut self, source: &Style) -> Result<(), WasmCssError>
Append another Style to this one, overwriting any fields on
self matching with source, or adding them if they did not
previously exist, updating the Style
Example Usage:
let mut style_one = style!("color: red; font-size: 10rem;")?;
let style_two = style!("font-size: 30rem; background-color: red;")?;
style_one.append(&style_two)?;
// style_one.css: "color: red; font-size: 30rem; background-color: red;"sourcepub fn insert<V: Into<String>>(
&mut self,
key: &str,
value: V,
) -> Result<(), WasmCssError>
pub fn insert<V: Into<String>>( &mut self, key: &str, value: V, ) -> Result<(), WasmCssError>
Insert a new CSS line into the Style
- Skips invalid keys
Example Usage:
let mut style = style!("color: red; font-size: 10rem;")?;
style.insert("font-weight", "bold");sourcepub fn remove(&mut self, key: &str) -> Result<(), WasmCssError>
pub fn remove(&mut self, key: &str) -> Result<(), WasmCssError>
Remove a CSS line from Style
Example Usage:
let mut style = style!("color: red; font-size: 10rem;")?;
style.remove("color", "red")?;sourcepub fn insert_many<V: Into<String>>(
&mut self,
components: Vec<(&str, V)>,
) -> Result<(), WasmCssError>
pub fn insert_many<V: Into<String>>( &mut self, components: Vec<(&str, V)>, ) -> Result<(), WasmCssError>
Insert many CSS lines into the Style
- Skips invalid keys
Example Usage:
let mut style = style!("color: red; font-size: 10rem;")?;
style.insert_many(vec![
("font-weight", "bold"),
("background-color", "red")
])?;sourcepub fn remove_many(&mut self, keys: Vec<&str>) -> Result<(), WasmCssError>
pub fn remove_many(&mut self, keys: Vec<&str>) -> Result<(), WasmCssError>
Remove CSS lines from Style
Example Usage:
let mut style = style!("color: red; font-size: 10rem;")?;
style.remove("color", "red")?;sourcepub fn insert_effect<E: Into<String>>(
&mut self,
effect: E,
) -> Result<(), WasmCssError>
pub fn insert_effect<E: Into<String>>( &mut self, effect: E, ) -> Result<(), WasmCssError>
Add a effect to the Style
Effect meaning sub-components to a class like MediaQuery, Hover, Etc.
The ID of the effect becomes its tag component.
Example Usage:
let mut style = style!("color: red;")?;
// Effect ID = '&:hover'
style.insert_effect("&:hover { font-size: 10rem; }")?;sourcepub fn remove_effect(&mut self, id: &str) -> Result<(), WasmCssError>
pub fn remove_effect(&mut self, id: &str) -> Result<(), WasmCssError>
Remove a effect from the Style
Effect meaning sub-components to a class like MediaQuery, Hover, Etc.
The ID or name of the added effect is just its tag.
Example Usage:
let mut style = style!("color: red;")?;
// Effect ID = '&:hover'
style.insert_effect("&:hover { font-size: 10rem; };")?;
style.remove_effect("&:hover")?;sourcepub fn insert_effect_many<E: Into<String>>(
&mut self,
effects: Vec<E>,
) -> Result<(), WasmCssError>
pub fn insert_effect_many<E: Into<String>>( &mut self, effects: Vec<E>, ) -> Result<(), WasmCssError>
Add many effects to the Style
Effect meaning sub-components to a class like MediaQuery, Hover, Etc.
The ID of the effect becomes its tag component.
Example Usage:
let mut style = style!("color: red;")?;
// Effect IDs = '&:hover' & '@media (max-width: 400px)'
style.insert_effect_many(vec![
"&:hover { font-size: 10rem; }",
"@media (max-width: 400px) { color: blue; }"
])?;sourcepub fn remove_effect_many(
&mut self,
effect_ids: Vec<&str>,
) -> Result<(), WasmCssError>
pub fn remove_effect_many( &mut self, effect_ids: Vec<&str>, ) -> Result<(), WasmCssError>
Remove many effects from the Style
Effect meaning sub-components to a class like MediaQuery, Hover, Etc.
The ID of the effect becomes its tag component.
Example Usage:
let mut style = style!("color: red;")?;
// Effect IDs = '&:hover' & '@media (max-width: 400px)'
style.insert_effect_many(vec![
"&:hover { font-size: 10rem; }",
"@media (max-width: 400px) { color: blue; }"
])?;
style.remove_effect_many(vec!["&:hover", "@media (max-width: 400px)"])?;Trait Implementations§
Auto Trait Implementations§
impl Freeze for Style
impl RefUnwindSafe for Style
impl Send for Style
impl Sync for Style
impl Unpin for Style
impl UnwindSafe for Style
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)