8
8
)
9
9
10
10
type (
11
+ // Props represents the standard CSS properties that can be applied to a CSS rule.
11
12
Props struct {
12
13
AlignItems props.AlignItems `css:"align-items"`
13
14
Appearance props.Appearance `css:"appearance"`
@@ -74,9 +75,20 @@ type (
74
75
WhiteSpace props.WhiteSpace `css:"white-space"`
75
76
Width props.Unit `css:"width"`
76
77
}
78
+ // Style represents a CSS style rule.
77
79
Style struct {
80
+ // Selector is the CSS selector to which the properties will be applied.
81
+ // It can be any valid CSS selector like class, id, element type, etc.
78
82
Selector string
79
- Props Props
83
+
84
+ // Props contains the standard CSS properties that will be applied to the selector.
85
+ // These properties are represented by the Props struct and are validated.
86
+ Props Props
87
+
88
+ // CustomProps contains any additional CSS properties that are not covered by the Props struct.
89
+ // These properties are not validated and are directly added to the CSS rule.
90
+ // The keys of the map are the CSS property names and the values are the CSS property values.
91
+ CustomProps map [string ]string
80
92
}
81
93
)
82
94
@@ -89,6 +101,7 @@ func (s *Style) CSS(w io.Writer) error {
89
101
return err
90
102
}
91
103
104
+ // Iterate over the fields of the Props struct and write the CSS properties to the writer.
92
105
for i := 0 ; i < propsValue .NumField (); i ++ {
93
106
fieldValue := propsValue .Field (i )
94
107
fieldType := propsType .Field (i )
@@ -106,6 +119,13 @@ func (s *Style) CSS(w io.Writer) error {
106
119
}
107
120
}
108
121
122
+ // Write the custom properties to the writer.
123
+ for prop , value := range s .CustomProps {
124
+ if _ , err := fmt .Fprintf (w , "%s:%s;" , prop , value ); err != nil {
125
+ return err
126
+ }
127
+ }
128
+
109
129
if _ , err := fmt .Fprint (w , "}" ); err != nil {
110
130
return err
111
131
}
0 commit comments