Skip to content

Commit

Permalink
refactor: MaybeSignal refactored to Signal (#314)
Browse files Browse the repository at this point in the history
* refactor: MaybeSignal refactored to Signal

* fix: CI error
  • Loading branch information
luoxiaozero authored Nov 19, 2024
1 parent 854c018 commit 4e23651
Show file tree
Hide file tree
Showing 97 changed files with 325 additions and 395 deletions.
2 changes: 1 addition & 1 deletion demo/src/components/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub fn Demo(
class=("demo-demo__toolbar--code", move || !is_show_code.get())
>
<Tooltip
content=MaybeSignal::derive(move || {
content=Signal::derive(move || {
if is_show_code.get() {
"Hide code".to_string()
} else {
Expand Down
5 changes: 2 additions & 3 deletions thaw/src/accordion/accordion_item.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use crate::AccordionInjection;
use leptos::{html, prelude::*};
use thaw_components::CSSTransition;
use thaw_utils::{class_list, mount_style, update, with, StoredMaybeSignal};
use thaw_utils::{class_list, mount_style, update, with};

#[component]
pub fn AccordionItem(
#[prop(optional, into)] class: MaybeProp<String>,
/// Required value that identifies this item inside an Accordion component.
#[prop(into)]
value: MaybeSignal<String>,
value: Signal<String>,
accordion_header: AccordionHeader,
children: Children,
) -> impl IntoView {
Expand All @@ -19,7 +19,6 @@ pub fn AccordionItem(
collapsible,
} = AccordionInjection::expect_context();
let panel_ref = NodeRef::<html::Div>::new();
let value: StoredMaybeSignal<_> = value.into();

let is_show_panel = Memo::new(move |_| with!(|open_items, value| open_items.contains(value)));

Expand Down
2 changes: 1 addition & 1 deletion thaw/src/accordion/docs/mod.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ view! {
| Name | Type | Default | Description |
| --- | --- | --- | --- |
| class | `MaybeProp<String>` | `Default::default()` | |
| value | `MaybeSignal<String>` | | Required value that identifies this item inside an Accordion component. |
| value | `Signal<String>` | | Required value that identifies this item inside an Accordion component. |
| accordion_header | slot `AccordionHeader` | | |
| children | `Children` | | |

Expand Down
5 changes: 2 additions & 3 deletions thaw/src/anchor/anchor_link.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
use super::AnchorInjection;
use leptos::{html, prelude::*};
use thaw_components::OptionComp;
use thaw_utils::{class_list, StoredMaybeSignal};
use thaw_utils::class_list;

#[component]
pub fn AnchorLink(
#[prop(optional, into)] class: MaybeProp<String>,
/// The content of link.
#[prop(into)]
title: MaybeSignal<String>,
title: Signal<String>,
/// The target of link.
#[prop(into)]
href: String,
#[prop(optional)] children: Option<Children>,
) -> impl IntoView {
let anchor = AnchorInjection::expect_context();

let title: StoredMaybeSignal<_> = title.into();
let title_ref = NodeRef::<html::A>::new();
let href_id = StoredValue::new(None::<String>);
let is_active = Memo::new(move |_| {
Expand Down
12 changes: 6 additions & 6 deletions thaw/src/anchor/docs/mod.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ view! {

### AnchorLink Props

| Name | Type | Default | Description |
| -------- | --------------------- | -------------------- | -------------------- |
| class | `MaybeProp<String>` | `Default::default()` | |
| title | `MaybeSignal<String>` | | The content of link. |
| href | `String` | | The target of link. |
| children | `Option<Children>` | `None` | |
| Name | Type | Default | Description |
| -------- | ------------------- | -------------------- | -------------------- |
| class | `MaybeProp<String>` | `Default::default()` | |
| title | `Signal<String>` | | The content of link. |
| href | `String` | | The target of link. |
| children | `Option<Children>` | `None` | |
6 changes: 3 additions & 3 deletions thaw/src/auto_complete/docs/mod.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ view! {
| class | `MaybeProp<String>` | `Default::default()` | |
| value | `Model<String>` | `Default::default()` | Input of autocomplete. |
| placeholder | `MaybeProp<String>` | `Default::default()` | Autocomplete's placeholder. |
| disabled | `MaybeSignal<bool>` | `false` | Whether the input is disabled. |
| clear_after_select | `MaybeSignal<bool>` | `false` | Whether to clear after selection. |
| blur_after_select | `MaybeSignal<bool>` | `false` | Whether to blur after selection. |
| disabled | `Signal<bool>` | `false` | Whether the input is disabled. |
| clear_after_select | `Signal<bool>` | `false` | Whether to clear after selection. |
| blur_after_select | `Signal<bool>` | `false` | Whether to blur after selection. |
| auto_complete_prefix | slot `Option<AutoCompletePrefix>` | `None` | |
| auto_complete_suffix | slot `Option<AutoCompleteSuffix>` | `None` | |
| comp_ref | ref `ComponentRef<AutoCompleteRef>` | `Default::default()` | |
Expand Down
6 changes: 3 additions & 3 deletions thaw/src/auto_complete/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ pub fn AutoComplete(
#[prop(optional, into)]
placeholder: MaybeProp<String>,
// Whether to clear after selection.
#[prop(optional, into)] clear_after_select: MaybeSignal<bool>,
#[prop(optional, into)] clear_after_select: Signal<bool>,
/// Whether to blur after selection.
#[prop(optional, into)]
blur_after_select: MaybeSignal<bool>,
blur_after_select: Signal<bool>,
// On select callback function.
#[prop(optional, into)] on_select: Option<BoxOneCallback<String>>,
/// Whether the input is disabled.
#[prop(optional, into)]
disabled: MaybeSignal<bool>,
disabled: Signal<bool>,
#[prop(optional)] auto_complete_prefix: Option<AutoCompletePrefix>,
#[prop(optional)] auto_complete_suffix: Option<AutoCompleteSuffix>,
#[prop(optional)] comp_ref: ComponentRef<AutoCompleteRef>,
Expand Down
2 changes: 1 addition & 1 deletion thaw/src/avatar/docs/mod.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ view! {
| src | `MaybeProp<String>` | `Default::default()` | The Avatar's image. |
| name | `MaybeProp<String>` | `Default::default()` | The name of the person or entity represented by this Avatar. |
| initials | `MaybeProp<String>` | `Default::default()` | Custom initials. |
| shape | `MaybeSignal<AvatarShape>` | `Default::default()` | The avatar can have a circular or square shape. |
| shape | `Signal<AvatarShape>` | `Default::default()` | The avatar can have a circular or square shape. |
| size | `MaybeProp<u8>` | `Default::default()` | Size of the avatar in pixels. |
2 changes: 1 addition & 1 deletion thaw/src/avatar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn Avatar(
initials: MaybeProp<String>,
/// The avatar can have a circular or square shape.
#[prop(optional, into)]
shape: MaybeSignal<AvatarShape>,
shape: Signal<AvatarShape>,
/// Size of the avatar in pixels.
#[prop(optional, into)]
size: MaybeProp<u8>,
Expand Down
6 changes: 3 additions & 3 deletions thaw/src/back_top/docs/mod.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ view! {
| Name | Type | Default | Description |
| --- | --- | --- | --- |
| class | `MaybeProp<String>` | `Default::default()` | |
| right | `MaybeSignal<i32>` | `40` | The width of BackTop from the right side of the page. |
| bottom | `MaybeSignal<i32>` | `40` | The height of BackTop from the bottom of the page. |
| visibility_height | `MaybeSignal<i32>` | `180` | BackTop's trigger scroll top. |
| right | `Signal<i32>` | `40` | The width of BackTop from the right side of the page. |
| bottom | `Signal<i32>` | `40` | The height of BackTop from the bottom of the page. |
| visibility_height | `Signal<i32>` | `180` | BackTop's trigger scroll top. |
| children | `Option<Children>` | `None` | |

<div style="height: 600px">
Expand Down
6 changes: 3 additions & 3 deletions thaw/src/back_top/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ pub fn BackTop(
#[prop(optional, into)] class: MaybeProp<String>,
/// The width of BackTop from the right side of the page.
#[prop(default=40.into(), into)]
right: MaybeSignal<i32>,
right: Signal<i32>,
/// The height of BackTop from the bottom of the page.
#[prop(default=40.into(), into)]
bottom: MaybeSignal<i32>,
bottom: Signal<i32>,
/// BackTop's trigger scroll top.
#[prop(default=180.into(), into)]
visibility_height: MaybeSignal<i32>,
visibility_height: Signal<i32>,
#[prop(optional)] children: Option<Children>,
) -> impl IntoView {
mount_style("back-top", include_str!("./back-top.css"));
Expand Down
6 changes: 3 additions & 3 deletions thaw/src/badge/badge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ pub fn Badge(
#[prop(optional, into)] class: MaybeProp<String>,
/// A Badge can be filled, outline, ghost, inverted.
#[prop(optional, into)]
appearance: MaybeSignal<BadgeAppearance>,
appearance: Signal<BadgeAppearance>,
/// A Badge can be on of several preset sizes.
#[prop(optional, into)]
size: MaybeSignal<BadgeSize>,
size: Signal<BadgeSize>,
/// A Badge can be one of preset colors.
#[prop(optional, into)]
color: MaybeSignal<BadgeColor>,
color: Signal<BadgeColor>,
#[prop(optional)] children: Option<Children>,
) -> impl IntoView {
mount_style("badge", include_str!("./badge.css"));
Expand Down
14 changes: 7 additions & 7 deletions thaw/src/badge/docs/mod.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ view! {

### Badge Props

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| class | `MaybeProp<String>` | `Default::default()` | |
| appearance | `MaybeSignal<BadgeAppearance>` | `Default::default()` | A Badge can be filled, outline, ghost, inverted. |
| size | `MaybeSignal<BadgeSize>` | `Default::default()` | A Badge can be on of several preset sizes. |
| color | `MaybeSignal<BadgeColor>` | `Default::default()` | A Badge can be one of preset colors. |
| children | `Option<Children>` | `None` | |
| Name | Type | Default | Description |
| ---------- | ------------------------- | -------------------- | ------------------------------------------------ |
| class | `MaybeProp<String>` | `Default::default()` | |
| appearance | `Signal<BadgeAppearance>` | `Default::default()` | A Badge can be filled, outline, ghost, inverted. |
| size | `Signal<BadgeSize>` | `Default::default()` | A Badge can be on of several preset sizes. |
| color | `Signal<BadgeColor>` | `Default::default()` | A Badge can be one of preset colors. |
| children | `Option<Children>` | `None` | |
2 changes: 1 addition & 1 deletion thaw/src/breadcrumb/docs/mod.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ view! {
| Name | Type | Default | Description |
| -------- | ------------------- | -------------------- | ----------------------------------------- |
| class | `MaybeProp<String>` | `Default::default()` | |
| current | `MaybeSignal<bool>` | `false` | Defines current sate of BreadcrumbButton. |
| current | `Signal<bool>` | `false` | Defines current sate of BreadcrumbButton. |
| children | `Children` | | |

### BreadcrumbDivider Props
Expand Down
2 changes: 1 addition & 1 deletion thaw/src/breadcrumb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn BreadcrumbButton(
#[prop(optional, into)] class: MaybeProp<String>,
/// Defines current sate of BreadcrumbButton.
#[prop(optional, into)]
current: MaybeSignal<bool>,
current: Signal<bool>,
children: Children,
) -> impl IntoView {
view! {
Expand Down
18 changes: 9 additions & 9 deletions thaw/src/button/button/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,39 @@ pub fn Button(
#[prop(optional, into)] class: MaybeProp<String>,
/// A button can have its content and borders styled for greater emphasis or to be subtle.
#[prop(optional, into)]
appearance: MaybeSignal<ButtonAppearance>,
appearance: Signal<ButtonAppearance>,
/// A button can be rounded, circular, or square.
#[prop(optional, into)]
shape: MaybeSignal<ButtonShape>,
shape: Signal<ButtonShape>,
/// A button supports different sizes.
#[prop(optional, into)]
size: Option<MaybeSignal<ButtonSize>>,
size: Option<Signal<ButtonSize>>,
/// The default behavior of the button.
#[prop(optional, into)]
button_type: MaybeProp<ButtonType>,
/// Whether the button is displayed as block.
#[prop(optional, into)]
block: MaybeSignal<bool>,
block: Signal<bool>,
/// The icon of the button.
#[prop(optional, into)]
icon: MaybeProp<icondata_core::Icon>,
/// Whether the button is disabled.
#[prop(optional, into)]
disabled: MaybeSignal<bool>,
disabled: Signal<bool>,
/// When set, allows the button to be focusable even when it has been disabled.
#[prop(optional, into)]
disabled_focusable: MaybeSignal<bool>,
disabled_focusable: Signal<bool>,
/// Whether the button shows the loading status.
#[prop(optional, into)]
loading: MaybeSignal<bool>,
loading: Signal<bool>,
#[prop(optional, into)] on_click: Option<BoxOneCallback<ev::MouseEvent>>,
#[prop(optional)] children: Option<Children>,
) -> impl IntoView {
mount_style("button", include_str!("./button.css"));

let none_children = children.is_none();
let size_injection = ButtonSizeInjection::use_context().map(|s| s.0);
let size = size.unwrap_or_else(|| MaybeSignal::Static(size_injection.unwrap_or_default()));
let size = size.unwrap_or_else(|| Signal::stored(size_injection.unwrap_or_default()));
let only_icon = Memo::new(move |_| icon.with(|i| i.is_some()) && none_children);
let btn_disabled = Memo::new(move |_| disabled.get() || disabled_focusable.get());
let aria_disabled = move || {
Expand Down Expand Up @@ -96,7 +96,7 @@ pub fn Button(
if loading.get() {
EitherOf3::A(view! {
<span class="thaw-button__icon">
<Spinner size=MaybeSignal::derive(move || size.get().into())/>
<Spinner size=Signal::derive(move || size.get().into())/>
</span>
})
} else if let Some(icon) = icon.get() {
Expand Down
14 changes: 7 additions & 7 deletions thaw/src/button/docs/mod.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,14 @@ view! {
| Name | Type | Default | Description |
| --- | --- | --- | --- |
| class | `MaybeProp<String>` | `Default::default()` | |
| appearance | `MaybeSignal<ButtonAppearance>` | `Default::default()` | A button can have its content and borders styled for greater emphasis or to be subtle. |
| shape | `MaybeSignal<ButtonShape>` | `Default::default()` | A button can be rounded, circular, or square. |
| size | `Option<MaybeSignal<ButtonSize>>` | `ButtonSize::Medium` | A button supports different sizes. |
| block | `MaybeSignal<bool>` | `false` | Whether the button is displayed as block. |
| appearance | `Signal<ButtonAppearance>` | `Default::default()` | A button can have its content and borders styled for greater emphasis or to be subtle. |
| shape | `Signal<ButtonShape>` | `Default::default()` | A button can be rounded, circular, or square. |
| size | `Option<Signal<ButtonSize>>` | `ButtonSize::Medium` | A button supports different sizes. |
| block | `Signal<bool>` | `false` | Whether the button is displayed as block. |
| icon | `MaybeProp<icondata_core::Icon>` | `None` | The icon of the button. |
| disabled | `MaybeSignal<bool>` | `false` | Whether the button is disabled. |
| disabled_focusable | `MaybeSignal<bool>` | `false` | When set, allows the button to be focusable even when it has been disabled. |
| loading | `MaybeSignal<bool>` | `false` | Whether the button shows the loading status. |
| disabled | `Signal<bool>` | `false` | Whether the button is disabled. |
| disabled_focusable | `Signal<bool>` | `false` | When set, allows the button to be focusable even when it has been disabled. |
| loading | `Signal<bool>` | `false` | Whether the button shows the loading status. |
| on_click | `Option<BoxOneCallback<ev::MouseEvent>>` | `None` | Listen for button click events. |
| children | `Option<Children>` | | |

Expand Down
6 changes: 3 additions & 3 deletions thaw/src/checkbox/checkbox_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub enum CheckboxGroupRuleTrigger {
pub struct CheckboxGroupRule(Rule<HashSet<String>, CheckboxGroupRuleTrigger>);

impl CheckboxGroupRule {
pub fn required(required: MaybeSignal<bool>) -> Self {
pub fn required(required: Signal<bool>) -> Self {
Self::validator(move |value, name| {
if required.get_untracked() && value.is_empty() {
let message = name.get_untracked().map_or_else(
Expand All @@ -76,8 +76,8 @@ impl CheckboxGroupRule {
}

pub fn required_with_message(
required: MaybeSignal<bool>,
message: MaybeSignal<String>,
required: Signal<bool>,
message: Signal<String>,
) -> Self {
Self::validator(move |value, _| {
if required.get_untracked() && value.is_empty() {
Expand Down
14 changes: 7 additions & 7 deletions thaw/src/combobox/combobox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn Combobox(
selected_options: VecModel<String>,
/// Whether the input is disabled.
#[prop(optional, into)]
disabled: MaybeSignal<bool>,
disabled: Signal<bool>,
/// Placeholder text for the input.
#[prop(optional, into)]
placeholder: MaybeProp<String>,
Expand All @@ -36,7 +36,7 @@ pub fn Combobox(
let input_ref = NodeRef::<html::Input>::new();
let listbox_ref = NodeRef::<html::Div>::new();
let is_show_listbox = RwSignal::new(false);
let options = StoredValue::new(HashMap::<String, (String, String, MaybeSignal<bool>)>::new());
let options = StoredValue::new(HashMap::<String, (String, String, Signal<bool>)>::new());

let clear_icon_ref = NodeRef::<html::Span>::new();
let is_show_clear_icon = Memo::new(move |_| {
Expand Down Expand Up @@ -284,7 +284,7 @@ pub fn Combobox(
pub(crate) struct ComboboxInjection {
value: Model<String>,
selected_options: VecModel<String>,
options: StoredValue<HashMap<String, (String, String, MaybeSignal<bool>)>>,
options: StoredValue<HashMap<String, (String, String, Signal<bool>)>>,
is_show_listbox: RwSignal<bool>,
validate: Callback<Option<ComboboxRuleTrigger>, bool>,
pub multiselect: bool,
Expand All @@ -296,7 +296,7 @@ impl ComboboxInjection {
}

/// value: (value, text, disabled)
pub fn insert_option(&self, id: String, value: (String, String, MaybeSignal<bool>)) {
pub fn insert_option(&self, id: String, value: (String, String, Signal<bool>)) {
self.options.update_value(|options| {
options.insert(id, value);
});
Expand Down Expand Up @@ -357,7 +357,7 @@ pub enum ComboboxRuleTrigger {
pub struct ComboboxRule(Rule<Vec<String>, ComboboxRuleTrigger>);

impl ComboboxRule {
pub fn required(required: MaybeSignal<bool>) -> Self {
pub fn required(required: Signal<bool>) -> Self {
Self::validator(move |value, name| {
if required.get_untracked() && value.is_empty() {
let message = name.get_untracked().map_or_else(
Expand All @@ -372,8 +372,8 @@ impl ComboboxRule {
}

pub fn required_with_message(
required: MaybeSignal<bool>,
message: MaybeSignal<String>,
required: Signal<bool>,
message: Signal<String>,
) -> Self {
Self::validator(move |value, _| {
if required.get_untracked() && value.is_empty() {
Expand Down
2 changes: 1 addition & 1 deletion thaw/src/combobox/combobox_option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn ComboboxOption(
/// Sets an option to the disabled state. Disabled options cannot be selected,
/// but are still keyboard navigable.
#[prop(optional, into)]
disabled: MaybeSignal<bool>,
disabled: Signal<bool>,
/// Defines a unique identifier for the option. Defaults to `text` if not provided.
#[prop(optional, into)]
value: Option<String>,
Expand Down
4 changes: 2 additions & 2 deletions thaw/src/combobox/docs/mod.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ view! {
| rules | `Vec<ComboboxRule>` | `vec![]` | The rules to validate Field. |
| value | `Model<String>` | `Default::default()` | |
| selected_options | `VecModel<String>` | `Default::default()` | Selected option. |
| disabled | `MaybeSignal<bool>` | `false` | Whether the input is disabled. |
| disabled | `Signal<bool>` | `false` | Whether the input is disabled. |
| placeholder | `MaybeProp<String>` | `Default::default()` | Placeholder text for the input. |
| clearable | `bool` | `false` | If set, the combobox will show an icon to clear the current value. |
| children | `Children` | | |
Expand All @@ -95,7 +95,7 @@ view! {
| Name | Type | Default | Desciption |
| --- | --- | --- | --- |
| class | `MaybeProp<String>` | `Default::default()` | |
| disabled | `MaybeSignal<bool>` | `false` | Sets an option to the disabled state. Disabled options cannot be selected, but are still keyboard navigable. |
| disabled | `Signal<bool>` | `false` | Sets an option to the disabled state. Disabled options cannot be selected, but are still keyboard navigable. |
| value | `Option<String>` | `None` | Defines a unique identifier for the option. Defaults to `text` if not provided. |
| text | `String` | | An optional override the string value of the Option's display text, defaulting to the Option's child content. |
| children | `Children` | | |
Expand Down
Loading

0 comments on commit 4e23651

Please sign in to comment.