peacock_crest/style/prop_validation/
color.rs1use super::{CssValue, TokenExpected};
2use crate::Unit;
3
4#[derive(Debug, Clone)]
5pub struct CssColor(Unit);
6
7#[derive(Debug, Clone)]
8pub struct CssBackgroundColor(Unit);
9
10#[derive(Debug, Clone, strum_macros::EnumString, strum_macros::Display)]
11pub enum KeywordColor {
12 #[strum(to_string = "currentcolor", serialize = "currentcolor")]
13 CurrentColor,
14
15 #[strum(to_string = "black", serialize = "black")]
16 Black,
17 #[strum(to_string = "silver", serialize = "silver")]
18 Silver,
19 #[strum(to_string = "gray", serialize = "gray")]
20 Gray,
21 #[strum(to_string = "white", serialize = "white")]
22 White,
23 #[strum(to_string = "maroon", serialize = "maroon")]
24 Maroon,
25 #[strum(to_string = "red", serialize = "red")]
26 Red,
27 #[strum(to_string = "purple", serialize = "purple")]
28 Purple,
29 #[strum(to_string = "fuchsia", serialize = "fuchsia")]
30 Fuchsia,
31 #[strum(to_string = "green", serialize = "green")]
32 Green,
33 #[strum(to_string = "lime", serialize = "lime")]
34 Lime,
35 #[strum(to_string = "olive", serialize = "olive")]
36 Olive,
37 #[strum(to_string = "yellow", serialize = "yellow")]
38 Yellow,
39 #[strum(to_string = "navy", serialize = "navy")]
40 Navy,
41 #[strum(to_string = "blue", serialize = "blue")]
42 Blue,
43 #[strum(to_string = "teal", serialize = "teal")]
44 Teal,
45 #[strum(to_string = "aqua", serialize = "aqua")]
46 Aqua,
47 }
49
50impl From<Unit> for CssColor {
51 fn from(value: Unit) -> Self {
52 Self(value)
53 }
54}
55
56impl From<Unit> for CssBackgroundColor {
57 fn from(value: Unit) -> Self {
58 Self(value)
59 }
60}
61
62impl Into<Unit> for CssColor {
63 fn into(self) -> Unit {
64 self.0
65 }
66}
67
68impl Into<Unit> for CssBackgroundColor {
69 fn into(self) -> Unit {
70 self.0
71 }
72}
73
74impl CssValue for CssColor {
75 type Keyword = KeywordColor;
76
77 fn type_name() -> &'static str {
78 "CssColor"
79 }
80 fn type_token() -> TokenExpected {
81 TokenExpected::QuotedString | TokenExpected::Ident | TokenExpected::Hash
82 }
83}
84
85impl CssValue for CssBackgroundColor {
86 type Keyword = KeywordColor;
87
88 fn type_name() -> &'static str {
89 "CssBackgroundColor"
90 }
91 fn type_token() -> TokenExpected {
92 TokenExpected::QuotedString | TokenExpected::Ident | TokenExpected::Hash
93 }
94}