perspective_viewer/components/
type_icon.rs

1// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
2// ┃ ██████ ██████ ██████       █      █      █      █      █ █▄  ▀███ █       ┃
3// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█  ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄  ▀█ █ ▀▀▀▀▀ ┃
4// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄   █ ▄▄▄▄▄ ┃
5// ┃ █      ██████ █  ▀█▄       █ ██████      █      ███▌▐███ ███████▄ █       ┃
6// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
7// ┃ Copyright (c) 2017, the Perspective Authors.                              ┃
8// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
9// ┃ This file is part of the Perspective library, distributed under the terms ┃
10// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
11// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
12
13use perspective_client::config::ColumnType;
14use yew::html::IntoPropValue;
15use yew::{Properties, classes, function_component, html};
16
17use crate::components::style::LocalStyle;
18use crate::css;
19
20#[derive(PartialEq, Debug, Clone, Copy)]
21pub enum TypeIconType {
22    Type(ColumnType),
23    Expr,
24}
25impl From<ColumnType> for TypeIconType {
26    fn from(value: ColumnType) -> Self {
27        Self::Type(value)
28    }
29}
30impl IntoPropValue<TypeIconType> for ColumnType {
31    fn into_prop_value(self) -> TypeIconType {
32        TypeIconType::Type(self)
33    }
34}
35impl std::fmt::Display for TypeIconType {
36    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
37        match self {
38            TypeIconType::Type(t) => f.write_fmt(format_args!("{t}")),
39            TypeIconType::Expr => f.write_str("expression"),
40        }
41    }
42}
43
44#[derive(PartialEq, Properties, Debug)]
45pub struct TypeIconProps {
46    pub ty: TypeIconType,
47}
48
49#[function_component(TypeIcon)]
50pub fn type_icon(p: &TypeIconProps) -> yew::Html {
51    let class = classes!(p.ty.to_string(), "type-icon");
52    html! { <><LocalStyle href={css!("type-icon")} /><span {class} /></> }
53}