Last active
November 6, 2021 17:00
-
-
Save autarch/e092df5fb08570dcb9a832f56eaa7a75 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // icons/mod.rs | |
| use crate::Msg; | |
| use seed::{prelude::*, *}; | |
| use typed_builder::TypedBuilder; | |
| #[derive(TypedBuilder)] | |
| #[builder(doc)] | |
| pub struct Icon { | |
| path: Attrs, | |
| #[builder(default = 20)] | |
| size: u16, | |
| #[builder(default = "currentColor")] | |
| fill: &'static str, | |
| #[builder(default = vec![])] | |
| classes: Vec<&'static str>, | |
| title: &'static str, | |
| } | |
| pub fn x_circle() -> IconBuilder<((seed::Attrs,), (), (), (), ())> { | |
| Icon::builder().path(attrs! { | |
| At::FillRule => "evenodd", | |
| At::D => "M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z", | |
| At::ClipRule => "evenodd", | |
| }) | |
| } | |
| impl Icon { | |
| pub fn into_svg(self) -> Node<Msg> { | |
| let mut svg = svg![ | |
| attrs! { | |
| At::Height => self.size.to_string(), | |
| At::Width => self.size.to_string(), | |
| At::ViewBox => "0 0 20 20", | |
| At::Fill => self.fill, | |
| }, | |
| path![self.path], | |
| ]; | |
| for c in self.classes { | |
| svg.add_class(c); | |
| } | |
| svg.add_child(title![self.title]); | |
| svg | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use crate::{icons, models::Thing}; | |
| #[derive(Debug)] | |
| pub struct Model { | |
| things: RemoteData<Vec<Thing>>, | |
| } | |
| #[derive(Clone, Debug)] | |
| pub enum Msg { | |
| ThingsFetched(Vec<Thing>), | |
| } | |
| pub fn view(model: &Model) -> Node<Msg> { | |
| let mut things = model.client.things(); | |
| things.sort_by_key(|a| a.name.to_lowercase()); | |
| section![div![things.iter().map(|a| one_thing(a)),]] | |
| } | |
| fn one_thing(thing: &Thing) -> Node<Msg> { | |
| div![ | |
| a![ | |
| attrs! { | |
| At::Href => &thing.url, | |
| }, | |
| &thing.name, | |
| ], | |
| // XXX - This is the wrong type | |
| icons::x_circle().build().into_svg(), | |
| ] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment