Skip to content

Commit

Permalink
zu: Remove style clone
Browse files Browse the repository at this point in the history
  • Loading branch information
XuShaohua committed Nov 25, 2023
1 parent afb54dc commit c006c2a
Show file tree
Hide file tree
Showing 24 changed files with 89 additions and 77 deletions.
3 changes: 2 additions & 1 deletion crates/zu/src/alert_title/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ pub fn alert_title(props: &Props) -> Html {
// TODO(Shaohua): Merge properties with props!() macro.

html! {
<Typography classes={root_cls}
<Typography
classes={root_cls}
style={&props.style}
component="div">
{for props.children.iter()}
Expand Down
5 changes: 3 additions & 2 deletions crates/zu/src/app_bar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ pub fn app_bar(props: &Props) -> Html {
);

html! {
<Paper classes={root_cls}
<Paper
classes={root_cls}
component="header"
style={props.style.clone()}
style={&props.style}
elevation={4}>
</Paper>
}
Expand Down
2 changes: 1 addition & 1 deletion crates/zu/src/avatar_group/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub fn avatar_group(props: &Props) -> Html {
if props.style.is_empty() {
props.style = avatar_style.clone();
} else {
props.style = format!("{}; {}", props.style, avatar_style).into();
props.style = format!("{}; {avatar_style}", props.style).into();
}
item
})
Expand Down
3 changes: 2 additions & 1 deletion crates/zu/src/backdrop/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ pub fn backdrop(props: &Props) -> Html {
// TODO(Shaohua): Add transition component.

html! {
<@{props.component.to_string()} class={root_cls}
<@{props.component.to_string()}
class={root_cls}
style={props.style.to_attr()}>
{for props.children.iter()}
</@>
Expand Down
4 changes: 3 additions & 1 deletion crates/zu/src/badge/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ pub fn badge(props: &Props) -> Html {
};

html! {
<@{props.component.to_string()} class={root_cls} style={props.style.to_attr()}>
<@{props.component.to_string()}
class={root_cls}
style={props.style.to_attr()}>
{for props.children.iter()}
<span class={badge_cls} style={props.badge_style.to_attr()}>
{display_value}
Expand Down
3 changes: 2 additions & 1 deletion crates/zu/src/bottom_navigation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ pub fn bottom_navigation(props: &Props) -> Html {
// TODO(Shaohua): Add on_change, value and show_label to children props.

html! {
<@{props.component.to_string()} class={root_cls}
<@{props.component.to_string()}
class={root_cls}
style={props.style.to_attr()}>
{for props.children.iter()}
</@>
Expand Down
3 changes: 2 additions & 1 deletion crates/zu/src/bottom_navigation_action/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ pub fn bottom_navigation_action(props: &Props) -> Html {

// TODO(Shaohua): Check value of focus_ripple.
html! {
<ButtonBase classes={root_cls}
<ButtonBase
classes={root_cls}
style={&props.style}
focus_ripple={true}>
{props.icon.clone()}
Expand Down
3 changes: 2 additions & 1 deletion crates/zu/src/boxed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ pub fn r#box(props: &Props) -> Html {
let root_cls = classes!("ZuBox-root", props.classes.clone());

html! {
<@{props.component.to_string()} class={root_cls}
<@{props.component.to_string()}
class={root_cls}
style={props.style.to_attr()}>
{for props.children.iter()}
</@>
Expand Down
3 changes: 2 additions & 1 deletion crates/zu/src/breadcrumbs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ pub fn breadcrumbs(props: &Props) -> Html {
let root_cls = classes!("ZuBreadcrumb-root", props.classes.clone(),);

html! {
<Typography classes={root_cls}
<Typography
classes={root_cls}
aria_label={&props.aria_label}
component={props.component.clone()}
style={&props.style}>
Expand Down
33 changes: 16 additions & 17 deletions crates/zu/src/button/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,28 +199,27 @@ pub fn button(props: &Props) -> Html {
classes={root_cls}
aria_label={&props.aria_label}
button_type={props.button_type}
component={props.component.clone()}
component={&props.component}
disabled={props.disabled}
disable_ripple={props.disable_ripple}
focus_ripple={props.disable_focus_ripple}
style={&props.style}
tab_index={props.tab_index}
on_blur={props.on_blur.clone()}
on_click={props.on_click.clone()}
on_context_menu={props.on_context_menu.clone()}
on_drag_leave={props.on_drag_leave.clone()}
on_focus={props.on_focus.clone()}
on_focus_visible={props.on_focus_visible.clone()}
on_key_down={props.on_key_down.clone()}
on_key_up={props.on_key_up.clone()}
on_mouse_down={props.on_mouse_down.clone()}
on_mouse_enter={props.on_mouse_enter.clone()}
on_mouse_leave={props.on_mouse_leave.clone()}
on_mouse_up={props.on_mouse_up.clone()}
on_touch_end={props.on_touch_end.clone()}
on_touch_move={props.on_touch_move.clone()}
on_touch_start={props.on_touch_start.clone()}
>
on_blur={&props.on_blur}
on_click={&props.on_click}
on_context_menu={&props.on_context_menu}
on_drag_leave={&props.on_drag_leave}
on_focus={&props.on_focus}
on_focus_visible={&props.on_focus_visible}
on_key_down={&props.on_key_down}
on_key_up={&props.on_key_up}
on_mouse_down={&props.on_mouse_down}
on_mouse_enter={&props.on_mouse_enter}
on_mouse_leave={&props.on_mouse_leave}
on_mouse_up={&props.on_mouse_up}
on_touch_end={&props.on_touch_end}
on_touch_move={&props.on_touch_move}
on_touch_start={&props.on_touch_start}>
{create_icon(true, &props.start_icon, props.size, props.start_icon_classes.clone())}
{for props.children.iter()}
{create_icon(false, &props.end_icon, props.size, props.end_icon_classes.clone())}
Expand Down
3 changes: 2 additions & 1 deletion crates/zu/src/card/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ pub fn card(props: &Props) -> Html {
let elevation = if props.raised { 8 } else { 0 };

html! {
<Paper classes={props.classes.clone()}
<Paper
classes={&props.classes}
style={&props.style}
square={props.square}
variant={props.variant}
Expand Down
3 changes: 2 additions & 1 deletion crates/zu/src/card_content/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ pub fn card_content(props: &Props) -> Html {
let root_cls = classes!("ZuCardContent-root", props.classes.clone());

html! {
<@{props.component.to_string()} class={root_cls}
<@{props.component.to_string()}
class={root_cls}
style={props.style.to_attr()}>
{for props.children.iter()}
</@>
Expand Down
53 changes: 27 additions & 26 deletions crates/zu/src/card_header/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,34 +51,35 @@ pub fn card_header(props: &Props) -> Html {
let root_cls = classes!("ZuCardHeader-root", props.classes.clone());

html! {
<@{component.to_owned()} class={root_cls} style={props.style.to_attr()}>
if let Some(avatar) = &props.avatar {
<div class="ZuCardHeader-avatar">
{avatar.clone()}
<@{component.to_owned()}
class={root_cls}
style={props.style.to_attr()}>
if let Some(avatar) = &props.avatar {
<div class="ZuCardHeader-avatar">
{avatar.clone()}
</div>
}

<div class="ZuCardHeader-content">
<Typography classes="ZuCardHeader-title"
variant={if props.avatar.is_some() {Variant::Body2 } else { Variant::H5 }}
component="span">
{props.title.clone().unwrap_or_default()}
</Typography>

<Typography classes="ZuCardHeader-subheader"
variant={if props.avatar.is_some() { Variant::Body2 } else { Variant::Body1 }}
color={Color::Secondary}
component="span">
{props.subheader.clone().unwrap_or_default()}
</Typography>
</div>
}

<div class="ZuCardHeader-content">
<Typography classes="ZuCardHeader-title"
variant={if props.avatar.is_some() {Variant::Body2 } else { Variant::H5 }}
component="span">
{props.title.clone().unwrap_or_default()}
</Typography>

<Typography classes="ZuCardHeader-subheader"
variant={if props.avatar.is_some() { Variant::Body2 } else { Variant::Body1 }}
color={Color::Secondary}
component="span">
{props.subheader.clone().unwrap_or_default()}
</Typography>
</div>

if let Some(action) = &props.action {
<div class="ZuCardHeader-action">
{action.clone()}
</div>
}

if let Some(action) = &props.action {
<div class="ZuCardHeader-action">
{action.clone()}
</div>
}
</@>
}
}
2 changes: 1 addition & 1 deletion crates/zu/src/checkbox/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ pub fn checkbox(props: &Props) -> Html {
disabled={props.disabled}
icon={icon}
name={&props.name}
on_change={props.on_change.clone()}
on_change={&props.on_change}
size={props.size}
style={&props.style}
variant={Variant::Checkbox}
Expand Down
5 changes: 2 additions & 3 deletions crates/zu/src/divider/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,14 @@ pub fn divider(props: &Props) -> Html {
} else {
None
};
let style = props.style.to_attr();

if props.children.is_empty() {
html! {
<@{component} class={root_cls} style={style} role={role} />
<@{component} class={root_cls} style={props.style.to_attr()} role={role} />
}
} else {
html! {
<@{component} class={root_cls} style={style} role={role}>
<@{component} class={root_cls} style={props.style.to_attr()} role={role}>
<span class={wrapper_cls}>
{for props.children.iter()}
</span>
Expand Down
5 changes: 3 additions & 2 deletions crates/zu/src/icon_button/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,13 @@ pub fn icon_button(props: &Props) -> Html {
);

html! {
<ButtonBase classes={root_cls}
<ButtonBase
classes={root_cls}
aria_label={&props.aria_label}
center_ripple={props.center_ripple}
disabled={props.disabled}
focus_ripple={!props.disable_focus_ripple}
style={props.style.clone()}>
style={&props.style}>
{for props.children.iter()}
</ButtonBase>
}
Expand Down
3 changes: 2 additions & 1 deletion crates/zu/src/input_label/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ pub fn input_label(props: &Props) -> Html {
// TODO(Shaohua): Merge props.size into styles.

html! {
<FormLabel classes={root_cls}
<FormLabel
classes={root_cls}
color={props.color}
disabled={props.disabled}
error={props.error}
Expand Down
6 changes: 3 additions & 3 deletions crates/zu/src/link/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ pub fn link(props: &Props) -> Html {
html! {
<Typography
classes={root_cls}
style={props.style.clone()}
color={props.color}
component={props.component.clone()}
href={props.href.clone()}
component={&props.component}
href={&props.href}
style={&props.style}
variant={props.variant}>
{for props.children.iter()}
</Typography>
Expand Down
3 changes: 2 additions & 1 deletion crates/zu/src/list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ pub fn list(props: &Props) -> Html {
);

html! {
<@{props.component.to_string()} class={root_cls}
<@{props.component.to_string()}
class={root_cls}
style={props.style.to_attr()}>
if let Some(subheader) = &props.subheader {
{subheader.clone()}
Expand Down
3 changes: 2 additions & 1 deletion crates/zu/src/paper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ pub fn paper(props: &Props) -> Html {
);

html! {
<@{props.component.to_string()} class={root_cls}
<@{props.component.to_string()}
class={root_cls}
style={props.style.to_attr()}>
{for props.children.iter()}
</@>
Expand Down
3 changes: 1 addition & 2 deletions crates/zu/src/radio_group/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ pub fn radio_group(props: &Props) -> Html {
<FormGroup
classes={&props.classes}
role="radio-group"
style={&props.style}
>
style={&props.style}>
{for props.children.iter()}
</FormGroup>
}
Expand Down
3 changes: 2 additions & 1 deletion crates/zu/src/stack/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ pub fn stack(props: &Props) -> Html {
// TODO(Shaohua): Add divider elements

html! {
<@{props.component.to_string()} class={root_cls}
<@{props.component.to_string()}
class={root_cls}
style={props.style.to_attr()}>
{for props.children.iter()}
</@>
Expand Down
3 changes: 2 additions & 1 deletion crates/zu/src/svg_icon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ pub fn svg_icon(props: &Props) -> Html {
let aria_hidden = !props.title_access.is_empty();

html! {
<@{props.component.to_string()} class={root_cls}
<@{props.component.to_string()}
class={root_cls}
style={props.style.to_attr()}
focusable={"false"}
color={props.html_color.to_attr()}
Expand Down
9 changes: 3 additions & 6 deletions crates/zu/src/switch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ pub fn switch(props: &Props) -> Html {
};

html! {
<span
class={root_cls}
style={&props.style}>
<span class={root_cls} style={&props.style}>
<SwitchBase
aria_label={&props.aria_label}
classes={base_cls}
Expand All @@ -101,9 +99,8 @@ pub fn switch(props: &Props) -> Html {
input_classes={base_input_cls}
icon={icon}
name={&props.name}
on_change={props.on_change.clone()}
variant={Variant::Switch}
>
on_change={&props.on_change}
variant={Variant::Switch}>
</SwitchBase>
<span class="ZuSwitch-track">
</span>
Expand Down

0 comments on commit c006c2a

Please sign in to comment.