mirror of
https://github.com/adoyle0/thaw.git
synced 2025-02-02 08:34:15 -05:00
feat: theme
This commit is contained in:
parent
5b57d9a63d
commit
8db136f0d5
13 changed files with 121 additions and 31 deletions
|
@ -1,22 +1,32 @@
|
||||||
|
mod theme;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
theme::use_theme,
|
theme::use_theme,
|
||||||
utils::{maybe_rw_signal::MaybeRwSignal, mount_style::mount_style},
|
utils::{maybe_rw_signal::MaybeRwSignal, mount_style::mount_style},
|
||||||
Theme,
|
Theme,
|
||||||
};
|
};
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
use wasm_bindgen::JsCast;
|
pub use theme::SliderTheme;
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn Slider(
|
pub fn Slider(
|
||||||
#[prop(optional, into)] value: MaybeRwSignal<f64>,
|
#[prop(optional, into)] value: MaybeRwSignal<f64>,
|
||||||
#[prop(default = MaybeSignal::Static(100f64), into)] max: MaybeSignal<f64>,
|
#[prop(default = MaybeSignal::Static(100f64), into)] max: MaybeSignal<f64>,
|
||||||
) -> impl IntoView {
|
) -> impl IntoView {
|
||||||
|
mount_style("slider", include_str!("./slider.css"));
|
||||||
let theme = use_theme(Theme::light);
|
let theme = use_theme(Theme::light);
|
||||||
let css_vars = create_memo(move |_| {
|
let css_vars = create_memo(move |_| {
|
||||||
let mut css_vars = String::new();
|
let mut css_vars = String::new();
|
||||||
let theme = theme.get();
|
theme.with(|theme| {
|
||||||
let bg_color = theme.common.color_primary;
|
css_vars.push_str(&format!(
|
||||||
css_vars.push_str(&format!("--background-color-fill: {bg_color};"));
|
"--melt-background-color: {};",
|
||||||
|
&theme.slider.background_color
|
||||||
|
));
|
||||||
|
css_vars.push_str(&format!(
|
||||||
|
"--melt-background-color-fill: {};",
|
||||||
|
&theme.common.color_primary
|
||||||
|
));
|
||||||
|
});
|
||||||
|
|
||||||
css_vars
|
css_vars
|
||||||
});
|
});
|
||||||
|
@ -30,7 +40,6 @@ pub fn Slider(
|
||||||
value.get() / max.get() * 100.0
|
value.get() / max.get() * 100.0
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
mount_style("slider", include_str!("./slider.css"));
|
|
||||||
|
|
||||||
let do_update_value = move |val| {
|
let do_update_value = move |val| {
|
||||||
value.set(val);
|
value.set(val);
|
||||||
|
@ -51,7 +60,6 @@ pub fn Slider(
|
||||||
let on_mouse_move = window_event_listener(ev::mousemove, move |ev| {
|
let on_mouse_move = window_event_listener(ev::mousemove, move |ev| {
|
||||||
if is_mouse_move.get_untracked() {
|
if is_mouse_move.get_untracked() {
|
||||||
if let Some(rail) = rail_ref.get_untracked() {
|
if let Some(rail) = rail_ref.get_untracked() {
|
||||||
let ev = ev.unchecked_into::<web_sys::MouseEvent>();
|
|
||||||
let rect = rail.get_bounding_client_rect();
|
let rect = rail.get_bounding_client_rect();
|
||||||
let ev_x = f64::from(ev.x());
|
let ev_x = f64::from(ev.x());
|
||||||
if ev_x <= rect.x() {
|
if ev_x <= rect.x() {
|
||||||
|
|
|
@ -5,13 +5,13 @@
|
||||||
}
|
}
|
||||||
.melt-slider-rail {
|
.melt-slider-rail {
|
||||||
height: 4px;
|
height: 4px;
|
||||||
background-color: #e6e6e6;
|
background-color: var(--melt-background-color);
|
||||||
border-radius: 2px;
|
border-radius: 2px;
|
||||||
}
|
}
|
||||||
.melt-slider-rail__fill {
|
.melt-slider-rail__fill {
|
||||||
width: 0%;
|
width: 0%;
|
||||||
height: 4px;
|
height: 4px;
|
||||||
background-color: var(--background-color-fill);
|
background-color: var(--melt-background-color-fill);
|
||||||
border-radius: 2px;
|
border-radius: 2px;
|
||||||
}
|
}
|
||||||
.melt-slider-handle {
|
.melt-slider-handle {
|
||||||
|
|
20
src/slider/theme.rs
Normal file
20
src/slider/theme.rs
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
use crate::theme::ThemeMethod;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct SliderTheme {
|
||||||
|
pub background_color: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ThemeMethod for SliderTheme {
|
||||||
|
fn light() -> Self {
|
||||||
|
Self {
|
||||||
|
background_color: "#dbdbdf".into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn dark() -> Self {
|
||||||
|
Self {
|
||||||
|
background_color: "#ffffff33".into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,8 @@
|
||||||
|
mod theme;
|
||||||
|
|
||||||
use crate::{mount_style, theme::use_theme, utils::maybe_rw_signal::MaybeRwSignal, Theme};
|
use crate::{mount_style, theme::use_theme, utils::maybe_rw_signal::MaybeRwSignal, Theme};
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
|
pub use theme::SwitchTheme;
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn Switch(#[prop(optional, into)] value: MaybeRwSignal<bool>) -> impl IntoView {
|
pub fn Switch(#[prop(optional, into)] value: MaybeRwSignal<bool>) -> impl IntoView {
|
||||||
|
@ -9,8 +12,12 @@ pub fn Switch(#[prop(optional, into)] value: MaybeRwSignal<bool>) -> impl IntoVi
|
||||||
let mut css_vars = String::new();
|
let mut css_vars = String::new();
|
||||||
theme.with(|theme| {
|
theme.with(|theme| {
|
||||||
css_vars.push_str(&format!(
|
css_vars.push_str(&format!(
|
||||||
"--background-color: {};",
|
"--melt-background-color: {};",
|
||||||
theme.common.color_primary.clone()
|
theme.switch.background_color
|
||||||
|
));
|
||||||
|
css_vars.push_str(&format!(
|
||||||
|
"--melt-background-color-active: {};",
|
||||||
|
theme.common.color_primary
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
css_vars
|
css_vars
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
width: 35px;
|
width: 35px;
|
||||||
height: 19px;
|
height: 19px;
|
||||||
padding: 2px 5px 3px;
|
padding: 2px 5px 3px;
|
||||||
background-color: #f6f6f6;
|
background-color: var(--melt-background-color);
|
||||||
border-radius: 25px;
|
border-radius: 25px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
box-shadow: inset 0 0 1px 0 rgba(0, 0, 0, 0.05);
|
box-shadow: inset 0 0 1px 0 rgba(0, 0, 0, 0.05);
|
||||||
|
@ -24,7 +24,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.melt-switch--active {
|
.melt-switch--active {
|
||||||
background-color: var(--background-color);
|
background-color: var(--melt-background-color-active);
|
||||||
}
|
}
|
||||||
|
|
||||||
.melt-switch--active .melt-switch__button {
|
.melt-switch--active .melt-switch__button {
|
||||||
|
|
20
src/switch/theme.rs
Normal file
20
src/switch/theme.rs
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
use crate::theme::ThemeMethod;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct SwitchTheme {
|
||||||
|
pub background_color: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ThemeMethod for SwitchTheme {
|
||||||
|
fn light() -> Self {
|
||||||
|
Self {
|
||||||
|
background_color: "#00000024".into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn dark() -> Self {
|
||||||
|
Self {
|
||||||
|
background_color: "#ffffff33".into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -18,20 +18,14 @@ pub fn Table(
|
||||||
theme.with(|theme| {
|
theme.with(|theme| {
|
||||||
css_vars.push_str(&format!(
|
css_vars.push_str(&format!(
|
||||||
"--background-color: {};",
|
"--background-color: {};",
|
||||||
theme.table.background_color.clone()
|
theme.table.background_color
|
||||||
));
|
));
|
||||||
css_vars.push_str(&format!(
|
css_vars.push_str(&format!(
|
||||||
"--background-color-striped: {};",
|
"--background-color-striped: {};",
|
||||||
theme.table.background_color_striped.clone()
|
theme.table.background_color_striped
|
||||||
));
|
|
||||||
css_vars.push_str(&format!(
|
|
||||||
"--border-color: {};",
|
|
||||||
theme.table.border_color.clone()
|
|
||||||
));
|
|
||||||
css_vars.push_str(&format!(
|
|
||||||
"--border-radius: {};",
|
|
||||||
theme.common.border_radius.clone()
|
|
||||||
));
|
));
|
||||||
|
css_vars.push_str(&format!("--border-color: {};", theme.table.border_color));
|
||||||
|
css_vars.push_str(&format!("--border-radius: {};", theme.common.border_radius));
|
||||||
});
|
});
|
||||||
|
|
||||||
css_vars
|
css_vars
|
||||||
|
|
|
@ -18,9 +18,9 @@ impl ThemeMethod for TableTheme {
|
||||||
|
|
||||||
fn dark() -> Self {
|
fn dark() -> Self {
|
||||||
Self {
|
Self {
|
||||||
background_color: "#fff".into(),
|
background_color: "#18181c".into(),
|
||||||
background_color_striped: "#fafafc".into(),
|
background_color_striped: "#26262a".into(),
|
||||||
border_color: "#efeff5".into(),
|
border_color: "#2d2d30".into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ mod common;
|
||||||
use self::common::CommonTheme;
|
use self::common::CommonTheme;
|
||||||
use crate::{
|
use crate::{
|
||||||
AlertTheme, AvatarTheme, ButtonTheme, InputTheme, MenuTheme, MessageTheme, SelectTheme,
|
AlertTheme, AvatarTheme, ButtonTheme, InputTheme, MenuTheme, MessageTheme, SelectTheme,
|
||||||
SkeletionTheme, TableTheme, TagTheme,
|
SkeletionTheme, SliderTheme, SwitchTheme, TableTheme, TagTheme, UploadTheme,
|
||||||
};
|
};
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
|
|
||||||
|
@ -26,6 +26,9 @@ pub struct Theme {
|
||||||
pub avatar: AvatarTheme,
|
pub avatar: AvatarTheme,
|
||||||
pub message: MessageTheme,
|
pub message: MessageTheme,
|
||||||
pub select: SelectTheme,
|
pub select: SelectTheme,
|
||||||
|
pub slider: SliderTheme,
|
||||||
|
pub switch: SwitchTheme,
|
||||||
|
pub upload: UploadTheme,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Theme {
|
impl Theme {
|
||||||
|
@ -43,6 +46,9 @@ impl Theme {
|
||||||
avatar: AvatarTheme::light(),
|
avatar: AvatarTheme::light(),
|
||||||
message: MessageTheme::light(),
|
message: MessageTheme::light(),
|
||||||
select: SelectTheme::light(),
|
select: SelectTheme::light(),
|
||||||
|
slider: SliderTheme::light(),
|
||||||
|
switch: SwitchTheme::light(),
|
||||||
|
upload: UploadTheme::light(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn dark() -> Self {
|
pub fn dark() -> Self {
|
||||||
|
@ -59,6 +65,9 @@ impl Theme {
|
||||||
avatar: AvatarTheme::dark(),
|
avatar: AvatarTheme::dark(),
|
||||||
message: MessageTheme::dark(),
|
message: MessageTheme::dark(),
|
||||||
select: SelectTheme::dark(),
|
select: SelectTheme::dark(),
|
||||||
|
slider: SliderTheme::dark(),
|
||||||
|
switch: SwitchTheme::dark(),
|
||||||
|
upload: UploadTheme::dark(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
|
mod theme;
|
||||||
mod upload_dragger;
|
mod upload_dragger;
|
||||||
|
|
||||||
use crate::mount_style;
|
use crate::mount_style;
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
|
pub use theme::UploadTheme;
|
||||||
pub use upload_dragger::UploadDragger;
|
pub use upload_dragger::UploadDragger;
|
||||||
pub use web_sys::FileList;
|
pub use web_sys::FileList;
|
||||||
|
|
||||||
|
|
23
src/upload/theme.rs
Normal file
23
src/upload/theme.rs
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
use crate::theme::ThemeMethod;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct UploadTheme {
|
||||||
|
pub dragger_background_color: String,
|
||||||
|
pub dragger_border_color: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ThemeMethod for UploadTheme {
|
||||||
|
fn light() -> Self {
|
||||||
|
Self {
|
||||||
|
dragger_background_color: "#fafafc".into(),
|
||||||
|
dragger_border_color: "#e0e0e6".into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn dark() -> Self {
|
||||||
|
Self {
|
||||||
|
dragger_background_color: "#ffffff0f".into(),
|
||||||
|
dragger_border_color: "#ffffff3d".into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,8 +1,7 @@
|
||||||
.melt-upload-dragger {
|
.melt-upload-dragger {
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
background-color: #fafbfc;
|
background-color: var(--melt-background-color);
|
||||||
color: #24292e;
|
border: 1px dashed var(--melt-border-color);
|
||||||
border: 1px solid #e0e0e6;
|
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
@ -10,5 +9,5 @@
|
||||||
}
|
}
|
||||||
.melt-upload-dragger:hover,
|
.melt-upload-dragger:hover,
|
||||||
.melt-upload--drag-over .melt-upload-dragger {
|
.melt-upload--drag-over .melt-upload-dragger {
|
||||||
border: 1px dashed var(--border-color-hover);
|
border: 1px dashed var(--melt-border-color-hover);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,16 @@ pub fn UploadDragger(children: Children) -> impl IntoView {
|
||||||
let css_vars = create_memo(move |_| {
|
let css_vars = create_memo(move |_| {
|
||||||
let mut css_vars = String::new();
|
let mut css_vars = String::new();
|
||||||
theme.with(|theme| {
|
theme.with(|theme| {
|
||||||
|
css_vars.push_str(&format!(
|
||||||
|
"--melt-background-color: {};",
|
||||||
|
theme.upload.dragger_background_color
|
||||||
|
));
|
||||||
|
css_vars.push_str(&format!(
|
||||||
|
"--melt-border-color: {};",
|
||||||
|
theme.upload.dragger_border_color
|
||||||
|
));
|
||||||
let border_color_hover = theme.common.color_primary.clone();
|
let border_color_hover = theme.common.color_primary.clone();
|
||||||
css_vars.push_str(&format!("--border-color-hover: {border_color_hover};"));
|
css_vars.push_str(&format!("--melt-border-color-hover: {border_color_hover};"));
|
||||||
});
|
});
|
||||||
css_vars
|
css_vars
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue