Crates.io | hallings |
lib.rs | hallings |
version | 0.1.2 |
source | src |
created_at | 2023-01-05 15:49:40.202493 |
updated_at | 2024-04-09 17:45:29.645414 |
description | Styling framework for Yew β |
homepage | https://github.com/davidstyrbjorn/hallings |
repository | https://github.com/davidstyrbjorn/hallings |
max_upload_size | |
id | 751619 |
size | 57,571 |
β this is not a finished library it is meant as a prototype/test during a master's course at LiU (Sweden), it should not be used for any real world projects
β Yew: version "0.20"
Cargo.toml
file hallings = "0.1"
use hallings::prelude::*
π·ββοΈ As simple as that to get started
All tests are located in test.rs
.
To run tests make sure you have installed everything required, then run.
wasm-pack test --chrome
You could replace --chrome
with --firefox
. Check the wasm-pack documentation for more info
Halling uses Context Providers to provide components with theme data. Currently you can not pass your own theme struct.
<MaestroProvider> halling components </MaestroProvider>
All of the examples have been tested using yew = "0.20"
inside Function Components
<Text
size={"40px"}
color={"purple"} // if none is specified theme color is used
class={classes!("Custom class")}
>
{"Pretty large text"}
</Text>
Or feed text through as prop variable,
<Text size={"40px"} custom={TextProps { label: "Test".into() }}/>
let counter = use_state(|| 0);
let click = {
let counter = counter.clone();
Callback::from(move |_s: yew::MouseEvent| {
counter.set(*counter + 1);
})
};
<Button custom={
ButtonProps { onclick: cb }
}>
<Text color={"white"}>{"Next"}</Text>
</Button>
This component provides a password input component while also providing feedback dependent on how strong the given password currently is. You can provide your own strength checking function and formatting functions. Right now there is no direct way to extract the password value.
<PasswordStrengthInput
custom = { PasswordStrengthInputProps
{
calculate_strength_level: None,
strength_level_to_text_and_color: None,
strength_callback: None
}}
/>
Example 1 (default behaviour)
pub fn calculate_strength_level(value: String) -> StrengthLevel {
if value.contains("secure") {
return StrengthLevel::HIGH;
}
StrengthLevel::LOW
}
pub fn on_level_change(strength_level: StrengthLevel) {
// use strength_level
}
fn strength_level_to_text_and_color(value: StrengthLevel) -> (String, String) {
match value {
StrengthLevel::LOW => ("Password not strong enough".into(), "red".into()),
StrengthLevel::MEDIUM => ("Password weak but passable".into(), "blue".into()),
StrengthLevel::HIGH => ("Password strong".into(), "green".into()),
}
}
<PasswordStrengthInput
custom = { PasswordStrengthInputProps {
calculate_strength_level: Some(calculate_strength_level),
strength_level_to_text_and_color: Some(strength_level_to_text_and_color),
strength_callback: Some(on_level_change)
}}
/>
Example 2 (customized behaviour)
Steps left draws its UI using svg, circle
& lines
. The width and height dictates the width and height of the svg image. You can feed however many steps and the component will dynamically position and space the steps.
<StepsLeft
custom = {
StepsLeftProps {
width: 800,
height: 200,
current_step: (*counter).clone(),
steps: vec![
Step {
label: "Check out".into()
},
Step {
label: "Confirm".into()
},
Step {
label: "Pay".into()
},
]
}
}
/>