From 75cbcd315c13ac822b135b95f354a82e9254a384 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=8A=E6=AC=A7?= Date: Tue, 29 Oct 2024 01:01:37 +0800 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Move=20context.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/components/src/form/button/button.rs | 17 ++--- .../src/form/button/button_group.rs | 62 ++++--------------- packages/theme/src/components/form/button.rs | 47 ++++++++++++++ 3 files changed, 63 insertions(+), 63 deletions(-) diff --git a/packages/components/src/form/button/button.rs b/packages/components/src/form/button/button.rs index d654dec..4709d85 100644 --- a/packages/components/src/form/button/button.rs +++ b/packages/components/src/form/button/button.rs @@ -1,16 +1,10 @@ use stylist::yew::styled_component; use yew::prelude::*; -use hikari_theme::types::{ColorType, SizeType}; - -#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] -pub enum BorderRadiusType { - #[default] - Default, - None, - OnlyLeft, - OnlyRight, -} +use hikari_theme::{ + components::form::button::*, + types::{ColorType, SizeType}, +}; #[derive(Properties, Debug, PartialEq)] pub struct Props { @@ -30,8 +24,7 @@ pub struct Props { #[styled_component] pub fn Button(props: &Props) -> Html { - let radius_type = - use_context::(); + let radius_type = use_context::(); let radius_type = match &radius_type { Some(ctx) => ctx.border_radius_type, None => BorderRadiusType::Default, diff --git a/packages/components/src/form/button/button_group.rs b/packages/components/src/form/button/button_group.rs index a093941..2279254 100644 --- a/packages/components/src/form/button/button_group.rs +++ b/packages/components/src/form/button/button_group.rs @@ -1,51 +1,11 @@ use stylist::yew::styled_component; use yew::{html::ChildrenRenderer, prelude::*, virtual_dom::VChild}; -use hikari_theme::types::{ColorType, SizeType}; - -use super::button::{BorderRadiusType, Button}; - -pub(crate) mod group_injector_context { - use yew::prelude::*; - - use super::BorderRadiusType; - use hikari_theme::types::{ColorType, SizeType}; - - #[derive(Debug, PartialEq, Clone)] - pub struct Context { - pub border_radius_type: BorderRadiusType, - } - - #[derive(Properties, Debug, PartialEq)] - pub struct ContextProviderProps { - #[prop_or(SizeType::Medium)] - pub size: SizeType, - #[prop_or(ColorType::Primary)] - pub color: ColorType, - #[prop_or(false)] - pub outlined: bool, - #[prop_or_default] - pub border_radius_type: BorderRadiusType, - - #[prop_or_default] - pub children: Children, - } - - pub type ContextProviderType = UseStateHandle; - - #[function_component] - pub fn ContextShell(props: &ContextProviderProps) -> Html { - let ctx = use_state(|| Context { - border_radius_type: props.border_radius_type, - }); - - html! { - context={ctx.clone()}> - {props.children.clone() } - > - } - } -} +use super::button::Button; +use hikari_theme::{ + components::form::button::*, + types::{ColorType, SizeType}, +}; #[derive(Clone, derive_more::From, PartialEq)] pub enum ButtonGroupVariant { @@ -91,7 +51,7 @@ pub fn ButtonGroup(props: &Props) -> Html { display: flex; flex-direction: row; "#)}> - { @@ -101,20 +61,20 @@ pub fn ButtonGroup(props: &Props) -> Html { html! {} } } - + {props.children.iter().skip(1).take(props.children.len() - 2).map(|child| html! { - {{ let child: Html = child.clone().into(); child }} - + }).collect::()} - { @@ -124,7 +84,7 @@ pub fn ButtonGroup(props: &Props) -> Html { html! {} } } - + }, } diff --git a/packages/theme/src/components/form/button.rs b/packages/theme/src/components/form/button.rs index e69de29..18721fd 100644 --- a/packages/theme/src/components/form/button.rs +++ b/packages/theme/src/components/form/button.rs @@ -0,0 +1,47 @@ +use yew::prelude::*; + +use crate::types::{ColorType, SizeType}; + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] +pub enum BorderRadiusType { + #[default] + Default, + None, + OnlyLeft, + OnlyRight, +} + +#[derive(Debug, PartialEq, Clone)] +pub struct ContextState { + pub border_radius_type: BorderRadiusType, +} + +#[derive(Properties, Debug, PartialEq)] +pub struct ContextProps { + #[prop_or(SizeType::Medium)] + pub size: SizeType, + #[prop_or(ColorType::Primary)] + pub color: ColorType, + #[prop_or(false)] + pub outlined: bool, + #[prop_or_default] + pub border_radius_type: BorderRadiusType, + + #[prop_or_default] + pub children: Children, +} + +pub type ContextProviderType = UseStateHandle; + +#[function_component] +pub fn ContextShell(props: &ContextProps) -> Html { + let ctx = use_state(|| ContextState { + border_radius_type: props.border_radius_type, + }); + + html! { + context={ctx.clone()}> + {props.children.clone() } + > + } +}