perspective_viewer/components/
type_icon.rs1use 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}
25
26#[derive(PartialEq, Properties, Debug)]
27pub struct TypeIconProps {
28 pub ty: TypeIconType,
29}
30
31#[function_component(TypeIcon)]
32pub fn type_icon(p: &TypeIconProps) -> yew::Html {
33 let class = classes!(p.ty.to_string(), "type-icon");
34 html! { <><LocalStyle href={css!("type-icon")} /><span {class} /></> }
35}
36
37impl From<ColumnType> for TypeIconType {
38 fn from(value: ColumnType) -> Self {
39 Self::Type(value)
40 }
41}
42
43impl IntoPropValue<TypeIconType> for ColumnType {
44 fn into_prop_value(self) -> TypeIconType {
45 TypeIconType::Type(self)
46 }
47}
48
49impl std::fmt::Display for TypeIconType {
50 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
51 match self {
52 TypeIconType::Type(t) => f.write_fmt(format_args!("{t}")),
53 TypeIconType::Expr => f.write_str("expression"),
54 }
55 }
56}