Skip to content

Commit

Permalink
zu: Add more props to Button
Browse files Browse the repository at this point in the history
  • Loading branch information
XuShaohua committed Nov 25, 2023
1 parent 606d153 commit 8a2b3a3
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 3 deletions.
6 changes: 5 additions & 1 deletion crates/zu/src/button/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use yew::{
FocusEvent, Html, KeyboardEvent, MouseEvent, Properties, TouchEvent,
};

use crate::button_base::ButtonBase;
use crate::button_base::{ButtonBase, ButtonType};
use crate::styles::button_variant::ButtonVariant;
use crate::styles::{color::Color, size::Size};

Expand All @@ -20,6 +20,9 @@ pub struct Props {
#[prop_or_default]
pub aria_label: AttrValue,

#[prop_or_default]
pub button_type: ButtonType,

#[prop_or_default]
pub children: Children,

Expand Down Expand Up @@ -195,6 +198,7 @@ pub fn button(props: &Props) -> Html {
<ButtonBase
classes={root_cls}
aria_label={&props.aria_label}
button_type={props.button_type}
component={props.component.clone()}
disabled={props.disabled}
disable_ripple={props.disable_ripple}
Expand Down
30 changes: 30 additions & 0 deletions crates/zu/src/button_base/button_type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) 2023 Xu Shaohua <shaohua@biofan.org>. All rights reserved.
// Use of this source is governed by Apache-2.0 License that can be found
// in the LICENSE file.

use crate::styles::CssValue;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ButtonType {
Button,
Reset,
Submit,
}

impl Default for ButtonType {
fn default() -> Self {
Self::Button
}
}

impl CssValue for ButtonType {
#[inline]
#[must_use]
fn css_value(&self) -> &'static str {
match self {
Self::Button => "button",
Self::Reset => "reset",
Self::Submit => "submit",
}
}
}
8 changes: 7 additions & 1 deletion crates/zu/src/button_base/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//! It aims to be a simple building block for creating a button.
//! It contains a load of style reset and some focus/ripple logic.

mod button_type;
mod touch_ripple;

use yew::{
Expand All @@ -15,13 +16,18 @@ use yew::{
};
use zu_util::prop::ToAttr;

use crate::styles::CssValue;
pub use button_type::ButtonType;
pub use touch_ripple::TouchRipple;

#[derive(Debug, Clone, PartialEq, Properties)]
pub struct Props {
#[prop_or_default]
pub aria_label: AttrValue,

#[prop_or_default]
pub button_type: ButtonType,

// TODO(Shaohua): Add action ref.
/// If true, the ripples are centered.
#[prop_or(false)]
Expand Down Expand Up @@ -170,7 +176,7 @@ pub fn button_base(props: &Props) -> Html {
aria-label={props.aria_label.to_attr()}
disabled={props.disabled}
tab_index={tab_index}
type="button"
type={props.button_type.css_value()}
onblur={props.on_blur.clone()}
onclick={props.on_click.clone()}
oncontextmenu={props.on_context_menu.clone()}
Expand Down
3 changes: 3 additions & 0 deletions crates/zu/src/form_label/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ pub struct Props {
#[prop_or(false)]
pub focused: bool,

#[prop_or_default]
pub id: AttrValue,

/// If true, the label will indicate that the input is required.
#[prop_or(false)]
pub required: bool,
Expand Down
5 changes: 4 additions & 1 deletion crates/zu/src/radio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ pub struct Props {
#[prop_or_default]
pub id: AttrValue,

#[prop_or_default]
pub input_aria_label: AttrValue,

#[prop_or_default]
pub name: AttrValue,

#[prop_or_default]
pub on_change: Option<Callback<()>>,
pub on_change: Option<Callback<String>>,

#[prop_or(false)]
pub required: bool,
Expand Down
6 changes: 6 additions & 0 deletions crates/zu/src/radio_group/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ use yew::{function_component, html, AttrValue, Callback, Children, Html, Propert

#[derive(Debug, Clone, PartialEq, Properties)]
pub struct Props {
#[prop_or_default]
pub aria_labelled_by: AttrValue,

#[prop_or_default]
pub children: Children,

Expand All @@ -18,6 +21,9 @@ pub struct Props {
#[prop_or_default]
pub on_change: Option<Callback<String>>,

#[prop_or(false)]
pub row: bool,

#[prop_or_default]
pub value: AttrValue,
}
Expand Down

0 comments on commit 8a2b3a3

Please sign in to comment.