perspective_viewer/components/
type_icon.rs1use perspective_client::config::ColumnType;
14use yew::html::IntoPropValue;
15use yew::{Properties, classes, function_component, html};
16
17#[derive(PartialEq, Debug, Clone, Copy)]
18pub enum TypeIconType {
19 Type(ColumnType),
20 Expr,
21}
22
23#[derive(PartialEq, Properties, Debug)]
24pub struct TypeIconProps {
25 pub ty: TypeIconType,
26}
27
28#[function_component(TypeIcon)]
29pub fn type_icon(p: &TypeIconProps) -> yew::Html {
30 let class = classes!(p.ty.to_string(), "type-icon");
31 html! { <><span {class} /></> }
32}
33
34impl From<ColumnType> for TypeIconType {
35 fn from(value: ColumnType) -> Self {
36 Self::Type(value)
37 }
38}
39
40impl IntoPropValue<TypeIconType> for ColumnType {
41 fn into_prop_value(self) -> TypeIconType {
42 TypeIconType::Type(self)
43 }
44}
45
46impl std::fmt::Display for TypeIconType {
47 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
48 match self {
49 TypeIconType::Type(t) => f.write_fmt(format_args!("{t}")),
50 TypeIconType::Expr => f.write_str("expression"),
51 }
52 }
53}