nes_yew/components/
controller_icon.rs1use std::borrow::Cow;
2use strum::{EnumIter, IntoEnumIterator};
3use yew::prelude::*;
4
5#[derive(Properties, PartialEq)]
6pub struct ControllerIconProps {
7 pub controller: ControllerKind,
8 pub class: Option<Cow<'static, str>>,
9 pub style: Option<AttrValue>,
10}
11
12#[derive(Copy, Clone, PartialEq, EnumIter)]
13#[strum(serialize_all = "snake_case")]
14pub enum ControllerKind {
15 Snes,
16 SnesJp,
17 Nes,
18 NesJp,
19}
20
21impl ControllerKind {
22 pub fn iter() -> impl Iterator<Item = Self> {
23 <Self as IntoEnumIterator>::iter()
24 }
25
26 pub fn to_str(&self) -> &'static str {
27 match self {
28 ControllerKind::Snes => "snes-logo",
29 ControllerKind::SnesJp => "snes-jp-logo",
30 ControllerKind::Nes => "nes-logo",
31 ControllerKind::NesJp => "nes-jp-logo",
32 }
33 }
34}
35
36#[function_component(ControllerIcon)]
37pub fn controller_icon(
38 ControllerIconProps {
39 controller,
40 class,
41 style,
42 }: &ControllerIconProps,
43) -> Html {
44 html! {
45 <i
46 class={classes!(class, controller.to_str())}
47 style={style.clone()}
48 />
49 }
50}