Skip to content

Commit

Permalink
zu: Impl RadioGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
XuShaohua committed Nov 25, 2023
1 parent 370f646 commit afb54dc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
4 changes: 4 additions & 0 deletions crates/zu/src/form_group/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ pub struct Props {
#[prop_or(false)]
pub error: bool,

#[prop_or_default]
pub role: AttrValue,

/// Display group of elements in a compact row.
#[prop_or(false)]
pub row: bool,
Expand All @@ -42,6 +45,7 @@ pub fn form_group(props: &Props) -> Html {
<div
aria-label={props.aria_label.to_attr()}
class={root_cls}
role={props.role.to_attr()}
style={props.style.to_attr()}>
{for props.children.iter()}
</div>
Expand Down
33 changes: 29 additions & 4 deletions crates/zu/src/radio_group/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,61 @@
// Use of this source is governed by Lesser General Public License that can be
// found in the LICENSE file.

use yew::{function_component, html, AttrValue, Callback, Children, Html, Properties};
use yew::{function_component, html, AttrValue, Callback, Children, Classes, Html, Properties};

use crate::form_group::FormGroup;

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

/// The content of the component.
#[prop_or_default]
pub children: Children,

#[prop_or_default]
pub classes: Classes,

/// The default value.
///
/// Use when the component is not controlled.
#[prop_or_default]
pub default_value: AttrValue,

/// The name used to reference the value of the control.
///
/// If you don't provide this prop, it falls back to a randomly generated name.
#[prop_or_default]
pub name: AttrValue,

/// Callback fired when a radio button is selected.
#[prop_or_default]
pub on_change: Option<Callback<String>>,

/// Show in row mode or not.
///
/// Default is false, which means showing in column mode.
#[prop_or(false)]
pub row: bool,

#[prop_or_default]
pub style: AttrValue,

/// Value of the selected radio button. The DOM API casts this to a string.
#[prop_or_default]
pub value: AttrValue,
}

#[function_component(RadioGroup)]
pub fn radio_group(_props: &Props) -> Html {
pub fn radio_group(props: &Props) -> Html {
html! {
<>
</>
<FormGroup
classes={&props.classes}
role="radio-group"
style={&props.style}
>
{for props.children.iter()}
</FormGroup>
}
}

0 comments on commit afb54dc

Please sign in to comment.