@@ -24,10 +24,12 @@ const Card = tasty({
24
24
border: true ,
25
25
radius: true ,
26
26
},
27
+ styleProps: [' padding' , ' fill' ], // Expose styles as props
27
28
});
28
29
29
30
// Usage
30
31
< Card> Hello World< / Card>
32
+ < Card padding= " 6x" fill= " #gray.05" > Custom Card< / Card>
31
33
```
32
34
33
35
### Extending Existing Components
@@ -108,6 +110,64 @@ const GlobalHeading = tasty('.heading', {
108
110
});
109
111
```
110
112
113
+ ### Style Props - Direct Style Access
114
+
115
+ Use ` styleProps ` to expose style properties as direct component props:
116
+
117
+ ``` jsx
118
+ const FlexibleBox = tasty ({
119
+ as: ' div' ,
120
+ styles: {
121
+ display: ' flex' ,
122
+ padding: ' 2x' ,
123
+ },
124
+ styleProps: [' gap' , ' align' , ' placeContent' , ' fill' ],
125
+ });
126
+
127
+ // Usage - style properties become direct props
128
+ < FlexibleBox
129
+ gap= " 2x"
130
+ align= " center"
131
+ placeContent= " space-between"
132
+ fill= " #surface"
133
+ >
134
+ Content
135
+ < / FlexibleBox>
136
+
137
+ // Equivalent to using styles prop:
138
+ < FlexibleBox styles= {{
139
+ gap: ' 2x' ,
140
+ align: ' center' ,
141
+ placeContent: ' space-between' ,
142
+ fill: ' #surface'
143
+ }}>
144
+ Content
145
+ < / FlexibleBox>
146
+ ```
147
+
148
+ ** Benefits of ` styleProps ` :**
149
+ - ** Cleaner API** - No need for ` styles ` prop wrapper
150
+ - ** Better TypeScript support** - Props are properly typed
151
+ - ** Component-specific styling** - Expose only relevant properties
152
+ - ** Responsive support** - Works with arrays: ` gap={['2x', '1x']} `
153
+ - ** State-based styling** - Works with objects: ` fill={{ '': '#white', hovered: '#gray' }} `
154
+
155
+ ** Style Prop Priority:**
156
+ ``` jsx
157
+ // Direct props override styles prop
158
+ < FlexibleBox
159
+ styles= {{ gap: ' 1x' }}
160
+ gap= " 3x" // This takes priority
161
+ / >
162
+
163
+ // Both direct props and styles can be used together
164
+ < FlexibleBox
165
+ styles= {{ padding: ' 2x' , border: true }}
166
+ gap= " 2x"
167
+ align= " center"
168
+ / >
169
+ ```
170
+
111
171
### Style System Overview
112
172
113
173
Tasty enhances CSS with:
@@ -560,7 +620,8 @@ const Component = tasty({
560
620
``` jsx
561
621
// ✅ Use styled wrappers instead of styles prop
562
622
const StyledButton = tasty (Button, {
563
- styles: { fill: ' #purple' }
623
+ styles: { fill: ' #purple' },
624
+ styleProps: [' fill' , ' color' ], // Expose common styles as props
564
625
});
565
626
566
627
// ✅ Use design tokens and custom units
@@ -590,6 +651,13 @@ styles: {
590
651
hovered: ' #gray.05' ,
591
652
},
592
653
}
654
+
655
+ // ✅ Use styleProps for component APIs
656
+ const Container = tasty ({
657
+ styles: { display: ' flex' },
658
+ styleProps: [' gap' , ' padding' , ' align' , ' justify' ],
659
+ });
660
+ // Enables: <Container gap="2x" align="center" />
593
661
```
594
662
595
663
### Don'ts ❌
0 commit comments