dioxus_tw_components/components/molecules/callout/
style.rs1use std::str::FromStr;
2
3use super::props::*;
4use crate::attributes::*;
5use dioxus::prelude::*;
6
7impl Class for CalloutProps {
8 fn base(&self) -> &'static str {
9 "flex flex-col bg-muted border-l-6 border-solid p-2 pl-4 rounded-global-radius"
10 }
11
12 fn variant(&self) -> Option<&'static str> {
13 Some(match *self.variant.read() {
14 CalloutVariant::Note => "border-primary bg-primary/10 text-primary",
15 CalloutVariant::Tip => "border-success bg-success/10 text-success",
16 CalloutVariant::Warning => "border-yellow-500 bg-yellow-500/10 text-yellow-500",
17 CalloutVariant::Caution => "border-destructive bg-destructive/10 text-destructive",
18 })
19 }
20}
21
22#[derive(Default, Clone, Copy, PartialEq)]
23pub enum CalloutVariant {
24 #[default]
25 Note,
26 Tip,
27 Warning,
28 Caution,
29}
30
31impl FromStr for CalloutVariant {
32 type Err = &'static str;
33
34 fn from_str(s: &str) -> Result<Self, Self::Err> {
35 match s {
36 "tip" => Ok(CalloutVariant::Tip),
37 "warning" => Ok(CalloutVariant::Warning),
38 "caution" => Ok(CalloutVariant::Caution),
39 _ => Ok(CalloutVariant::Note),
40 }
41 }
42}
43
44impl std::fmt::Display for CalloutVariant {
45 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
46 let s = match self {
47 CalloutVariant::Tip => "Tip",
48 CalloutVariant::Warning => "Warning",
49 CalloutVariant::Caution => "Caution",
50 _ => "Note",
51 };
52 f.write_str(s)
53 }
54}