Skip to content

Commit

Permalink
feat: modify the spinner style
Browse files Browse the repository at this point in the history
  • Loading branch information
luoxiaozero committed Dec 15, 2023
1 parent 5c5f796 commit d437078
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 23 deletions.
2 changes: 0 additions & 2 deletions demo/src/pages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,3 @@ pub use time_picker::*;
pub use toast::*;
pub use typography::*;
pub use upload::*;


16 changes: 12 additions & 4 deletions demo/src/pages/spinner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,22 @@ pub fn SpinnerPage() -> impl IntoView {
<tbody>
<tr>
<td>"class"</td>
<td>"MaybeSignal<String>"</td>
<td>"Default::default()"</td>
<td>
<Text code=true>"MaybeSignal<String>"</Text>
</td>
<td>
<Text code=true>"Default::default()"</Text>
</td>
<td>"Additional classes for the spinner element."</td>
</tr>
<tr>
<td>"size"</td>
<td>"MaybeSignal<SpinnerSize>"</td>
<td>"SpinnerSize::Medium"</td>
<td>
<Text code=true>"MaybeSignal<SpinnerSize>"</Text>
</td>
<td>
<Text code=true>"SpinnerSize::Medium"</Text>
</td>
<td>"Spinner size."</td>
</tr>
</tbody>
Expand Down
23 changes: 11 additions & 12 deletions src/spinner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ mod theme;

#[cfg(not(feature = "ssr"))]
use crate::utils::dyn_classes;
use crate::{theme::use_theme, utils::{mount_style, ssr_class}, Theme};
use crate::{
theme::use_theme,
utils::{mount_style, ssr_class},
Theme,
};
use leptos::*;

pub use theme::SpinnerTheme;
Expand All @@ -17,7 +21,6 @@ pub enum SpinnerSize {
}

impl SpinnerSize {

fn theme_height(&self, theme: &Theme) -> String {
match self {
SpinnerSize::Tiny => theme.common.height_tiny.clone(),
Expand All @@ -28,13 +31,12 @@ impl SpinnerSize {
}
}


#[component]
pub fn Spinner(
#[prop(optional, into)] class: MaybeSignal<String>,
#[prop(optional, into)] size: MaybeSignal<SpinnerSize>,
) -> impl IntoView {
mount_style("tag", include_str!("./spinner.css"));
mount_style("spinner", include_str!("./spinner.css"));
let theme = use_theme(Theme::light);
let css_vars = create_memo(move |_| {
let mut css_vars = String::new();
Expand All @@ -47,21 +49,18 @@ pub fn Spinner(
"--thaw-background-color: {};",
&theme.spinner.background_color
));
css_vars.push_str(&format!(
"--thaw-color: {};",
&theme.spinner.color
));
css_vars.push_str(&format!("--thaw-color: {};", &theme.common.color_primary));
});
css_vars
});

let ssr_class = ssr_class(&class);
view! {
<div
<div
class=ssr_class
use:dyn_classes=class
class="thaw-spinner"
style=move || css_vars.get()>
</div>
class="thaw-spinner"
style=move || css_vars.get()
></div>
}
}
1 change: 1 addition & 0 deletions src/spinner/spinner.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
height: var(--thaw-height);
outline: 1px solid transparent;
animation: 1s linear 0s infinite normal none running spin;
box-sizing: border-box;
}

@keyframes spin {
Expand Down
3 changes: 0 additions & 3 deletions src/spinner/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,18 @@ use crate::theme::ThemeMethod;
#[derive(Clone)]
pub struct SpinnerTheme {
pub background_color: String,
pub color: String,
}

impl ThemeMethod for SpinnerTheme {
fn light() -> Self {
Self {
background_color: "#0000000a".into(),
color: " #0078ff".into(),
}
}

fn dark() -> Self {
Self {
background_color: "#2b2f31".into(),
color: "#0078ff".into(),
}
}
}
4 changes: 2 additions & 2 deletions src/theme/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use crate::{
mobile::{NavBarTheme, TabbarTheme},
AlertTheme, AutoCompleteTheme, AvatarTheme, BreadcrumbTheme, ButtonTheme, CalendarTheme,
ColorPickerTheme, InputTheme, MenuTheme, MessageTheme, ProgressTheme, SelectTheme,
SkeletionTheme, SliderTheme, SwitchTheme, TableTheme, TagTheme, TimePickerTheme,
TypographyTheme, UploadTheme, SpinnerTheme
SkeletionTheme, SliderTheme, SpinnerTheme, SwitchTheme, TableTheme, TagTheme, TimePickerTheme,
TypographyTheme, UploadTheme,
};
use leptos::*;

Expand Down

0 comments on commit d437078

Please sign in to comment.