Skip to content

Commit

Permalink
Create ChipPreview and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
matthunz committed Oct 29, 2023
1 parent 9628d36 commit 41bfc56
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 41 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion lookbook/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ dioxus = { git = "https://github.com/dioxuslabs/dioxus" }
dioxus-web = { git = "https://github.com/dioxuslabs/dioxus" }
lookbook = { git = "https://github.com/matthunz/lookbook" }
dioxus-material = { git = "https://github.com/matthunz/dioxus-material" }

17 changes: 7 additions & 10 deletions lookbook/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use dioxus::prelude::*;
use lookbook::LookBook;

mod previews;
use previews::{ButtonPreview, TabRowPreview, TextButtonPreview, TextFieldPreview};
use previews::{ButtonPreview, ChipPreview,TabRowPreview, TextButtonPreview, TextFieldPreview};

#[component]
fn Home(cx: Scope) -> Element {
Expand All @@ -22,15 +22,12 @@ fn Home(cx: Scope) -> Element {
}

fn app(cx: Scope) -> Element {
render!(LookBook {
home: Home,
previews: [
ButtonPreview,
TabRowPreview,
TextButtonPreview,
TextFieldPreview
]
})
render!(
LookBook {
home: Home,
previews: [ButtonPreview, ChipPreview, TabRowPreview, TextButtonPreview, TextFieldPreview]
}
)
}

fn main() {
Expand Down
9 changes: 3 additions & 6 deletions lookbook/src/previews/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ pub fn ButtonPreview(
#[lookbook(default = &*use_theme(cx).border_radius_medium)]
border_radius: &'a str,
) -> Element {
render!(Button {
background_color: background_color,
border_radius: border_radius,
onpress: |_| {},
label
})
render!(
Button { background_color: background_color, border_radius: border_radius, onpress: |_| {}, label }
)
}
21 changes: 21 additions & 0 deletions lookbook/src/previews/chip.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use dioxus::prelude::*;
use dioxus_material::{use_theme, Chip};
use lookbook::{preview, Json};

/// Buttons let people take action and make choices with one tap.
#[preview]
pub fn ChipPreview(
cx: Scope,
/// Label for the button.
#[lookbook(default = "Label")]
label: &'a str,

/// Background color of the container (optional).
#[lookbook(default = false)]
is_selected: Json<bool>,

) -> Element {
render!(
Chip { is_selected: is_selected.0, onclick: |_| {}, label }
)
}
3 changes: 3 additions & 0 deletions lookbook/src/previews/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
mod button;
pub use button::ButtonPreview;

mod chip;
pub use chip::ChipPreview;

mod tab_row;
pub use tab_row::TabRowPreview;

Expand Down
9 changes: 3 additions & 6 deletions lookbook/src/previews/text_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ pub fn TextButtonPreview(
#[lookbook(default = &*use_theme(cx).border_radius_medium)]
border_radius: &'a str,
) -> Element {
render!(TextButton {
color: color,
border_radius: border_radius,
onpress: |_| {},
label
})
render!(
TextButton { color: color, border_radius: border_radius, onpress: |_| {}, label }
)
}
12 changes: 7 additions & 5 deletions lookbook/src/previews/text_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ pub fn TextFieldPreview<'a>(
) -> Element<'a> {
let value = use_state(cx, || String::from("Text Field"));

render!(TextField {
label: label,
value: value,
onchange: move |event: FormEvent| value.set(event.data.value.clone())
})
render!(
TextField {
label: label,
value: value,
onchange: move |event: FormEvent| value.set(event.data.value.clone())
}
)
}
14 changes: 8 additions & 6 deletions src/chip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,21 @@ pub fn Chip<'a>(
height: "32px",
line_height: "32px",
border_radius: "{theme.border_radius_small}",
padding: "0 14px",
font_family: "sans-serif",
font_size: "14px",
font_weight: 500,
border: "1px solid {border_color}",
background: background,
Ripple { onclick: |event| onclick.call(event),
if *is_selected == Some(true) {
render!(Icon { kind: IconKind::Check })
} else {
None
div { display: "inline-flex", flex_direction: "row", align_items: "center",
if *is_selected == Some(true) {
render!(Icon { kind: IconKind::Check })
} else {
None
}

div { padding: "0 14px", children }
}
children
}
}
)
Expand Down
9 changes: 3 additions & 6 deletions src/tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ use dioxus::prelude::*;

#[component]
pub fn Tab<'a>(cx: Scope<'a>, children: Element<'a>) -> Element<'a> {
render!(div {
font_size: "1.2em",
padding: "10px 0",
text_align: "center",
children
})
render!(
div { font_size: "1.2em", padding: "10px 0", text_align: "center", children }
)
}

0 comments on commit 41bfc56

Please sign in to comment.