dioxus_tw_components/components/organisms/form/toggle/
style.rs

1use super::props::*;
2use crate::attributes::*;
3use dioxus::prelude::*;
4
5impl Class for ToggleProps {
6    fn base(&self) -> &'static str {
7        "peer relative bg-input rounded-full focus:outline-hidden focus:ring-2 cursor-pointer focus:ring-black focus:ring-offset-2 data-[state=active]:after:translate-x-full data-[state=active]:after:border-white after:content-[''] after:absolute after:bg-background after:border-input after:border after:rounded-full disabled:opacity-40"
8    }
9
10    fn color(&self) -> Option<&'static str> {
11        Some(match *self.color.read() {
12            Color::Default => "data-[state=active]:bg-foreground",
13            Color::Primary => "data-[state=active]:bg-primary",
14            Color::Secondary => "data-[state=active]:bg-secondary",
15            Color::Destructive => "data-[state=active]:bg-destructive",
16            Color::Success => "data-[state=active]:bg-success",
17            _ => "",
18        })
19    }
20
21    fn size(&self) -> Option<&'static str> {
22        Some(match *self.size.read() {
23            Size::Lg | Size::Xl => "w-14 h-7 after:top-0.5 after:start-[4px] after:h-6 after:w-6",
24            Size::Md => "w-11 h-6 after:top-[2px] after:start-[2px] after:h-5 after:w-5",
25            Size::Sm | Size::Xs => "w-9 h-5 after:top-[2px] after:start-[2px] after:h-4 after:w-4",
26        })
27    }
28
29    fn animation(&self) -> Option<&'static str> {
30        Some(match *self.animation.read() {
31            Animation::None => "",
32            Animation::Light => "after:transition-all",
33            Animation::Full => "after:transition-all transition-colors duration-200",
34        })
35    }
36}