Skip to content

Commit efc1805

Browse files
committed
feat: enable minification and standardize API syntax
1 parent c538ae7 commit efc1805

22 files changed

Lines changed: 313 additions & 223 deletions

File tree

packages/docs/docs/api.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,13 @@ A new React component with the specified styles applied.
2727

2828
```tsx
2929
import { styled } from 'kstyled';
30-
import { View, Text } from 'react-native';
3130

32-
const Container = styled(View)`
31+
const Container = styled.View`
3332
flex: 1;
3433
padding: 20px;
3534
`;
3635

37-
const Title = styled(Text)<{ $large?: boolean }>`
36+
const Title = styled.Text<{ $large?: boolean }>`
3837
font-size: ${p => p.$large ? '32px' : '24px'};
3938
font-weight: bold;
4039
`;
@@ -185,15 +184,15 @@ A styled component factory with attrs applied.
185184
### Example
186185

187186
```tsx
188-
const Input = styled(TextInput).attrs({
187+
const Input = styled.TextInput.attrs({
189188
placeholderTextColor: '#999',
190189
autoCapitalize: 'none',
191190
})`
192191
padding: 12px;
193192
border-radius: 8px;
194193
`;
195194

196-
const Button = styled(Pressable).attrs<{ $size?: 'small' | 'large' }>(
195+
const Button = styled.Pressable.attrs<{ $size?: 'small' | 'large' }>(
197196
(props) => ({
198197
hitSlop: props.$size === 'small' ? 8 : 16,
199198
})

packages/docs/docs/getting-started/basic-usage.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,20 @@ Use the `styled` function with template literals:
1010

1111
```tsx
1212
import { styled } from 'kstyled';
13-
import { View, Text, Pressable } from 'react-native';
1413

15-
const Container = styled(View)`
14+
const Container = styled.View`
1615
flex: 1;
1716
padding: 20px;
1817
background-color: #f0f0f0;
1918
`;
2019

21-
const Title = styled(Text)`
20+
const Title = styled.Text`
2221
font-size: 24px;
2322
font-weight: bold;
2423
color: #000;
2524
`;
2625

27-
const Button = styled(Pressable)`
26+
const Button = styled.Pressable`
2827
padding: 12px 24px;
2928
background-color: #007AFF;
3029
border-radius: 8px;
@@ -53,7 +52,7 @@ export default function App() {
5352
kstyled supports standard CSS property names (kebab-case):
5453

5554
```tsx
56-
const Card = styled(View)`
55+
const Card = styled.View`
5756
background-color: white;
5857
border-radius: 12px;
5958
shadow-color: #000;
@@ -78,11 +77,11 @@ Properties are automatically converted to React Native's camelCase format (`back
7877
### Nesting components
7978

8079
```tsx
81-
const Card = styled(View)`
80+
const Card = styled.View`
8281
padding: 16px;
8382
`;
8483

85-
const CardTitle = styled(Text)`
84+
const CardTitle = styled.Text`
8685
font-size: 18px;
8786
font-weight: 600;
8887
`;

packages/docs/docs/getting-started/installation.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@ Create a simple component to test:
6161

6262
```tsx
6363
import { styled } from 'kstyled';
64-
import { Text } from 'react-native';
6564

66-
const Title = styled(Text)`
65+
const Title = styled.Text`
6766
font-size: 24px;
6867
color: #007AFF;
6968
`;

packages/docs/docs/guides/attrs.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The `.attrs()` method lets you attach default props or computed props to styled
1111
Set default props for your components:
1212

1313
```tsx
14-
const Input = styled(TextInput).attrs({
14+
const Input = styled.TextInput.attrs({
1515
placeholderTextColor: '#999',
1616
autoCapitalize: 'none',
1717
autoCorrect: false,
@@ -32,7 +32,7 @@ const Input = styled(TextInput).attrs({
3232
Use a function to compute props dynamically:
3333

3434
```tsx
35-
const Button = styled(Pressable).attrs<{ $size?: 'small' | 'large' }>(
35+
const Button = styled.Pressable.attrs<{ $size?: 'small' | 'large' }>(
3636
(props) => ({
3737
hitSlop: props.$size === 'small' ? 8 : 16,
3838
accessible: true,
@@ -50,7 +50,7 @@ const Button = styled(Pressable).attrs<{ $size?: 'small' | 'large' }>(
5050
Use attrs to set accessibility properties:
5151

5252
```tsx
53-
const Card = styled(View).attrs({
53+
const Card = styled.View.attrs({
5454
accessible: true,
5555
accessibilityRole: 'button' as const,
5656
})`
@@ -59,7 +59,7 @@ const Card = styled(View).attrs({
5959
border-radius: 12px;
6060
`;
6161

62-
const Heading = styled(Text).attrs({
62+
const Heading = styled.Text.attrs({
6363
accessible: true,
6464
accessibilityRole: 'header' as const,
6565
})`
@@ -73,7 +73,7 @@ const Heading = styled(Text).attrs({
7373
Props passed to the component override attrs:
7474

7575
```tsx
76-
const Input = styled(TextInput).attrs({
76+
const Input = styled.TextInput.attrs({
7777
placeholderTextColor: '#999',
7878
})`
7979
padding: 12px;
@@ -93,7 +93,7 @@ const Input = styled(TextInput).attrs({
9393
```tsx
9494
import { Platform } from 'react-native';
9595

96-
const Input = styled(TextInput).attrs({
96+
const Input = styled.TextInput.attrs({
9797
placeholderTextColor: '#999',
9898
...(Platform.OS === 'ios' ? {
9999
keyboardAppearance: 'dark' as const,
@@ -109,7 +109,7 @@ const Input = styled(TextInput).attrs({
109109
You can chain multiple `.attrs()` calls:
110110

111111
```tsx
112-
const BaseButton = styled(Pressable).attrs({
112+
const BaseButton = styled.Pressable.attrs({
113113
accessible: true,
114114
accessibilityRole: 'button' as const,
115115
})`

packages/docs/docs/guides/css-inline.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,14 @@ The `css` helper is processed at **runtime**, unlike `styled` which is compile-t
278278

279279
```tsx
280280
// ✅ Reusable components with static styles
281-
const Card = styled(View)`
281+
const Card = styled.View`
282282
padding: 16px;
283283
border-radius: 12px;
284284
background-color: white;
285285
`;
286286

287287
// ✅ Component library
288-
const PrimaryButton = styled(Pressable)`
288+
const PrimaryButton = styled.Pressable`
289289
padding: 12px 24px;
290290
background-color: #007AFF;
291291
border-radius: 8px;

packages/docs/docs/guides/dynamic-props.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ sidebar_position: 2
99
Use props prefixed with `$` to pass values to your styles. These props won't be passed to the underlying component:
1010

1111
```tsx
12-
const Button = styled(Pressable)<{ $primary?: boolean }>`
12+
const Button = styled.Pressable<{ $primary?: boolean }>`
1313
padding: 12px 24px;
1414
background-color: ${p => p.$primary ? '#007AFF' : '#ccc'};
1515
border-radius: 8px;
@@ -31,7 +31,7 @@ interface BoxProps {
3131
$color?: string;
3232
}
3333

34-
const Box = styled(View)<BoxProps>`
34+
const Box = styled.View<BoxProps>`
3535
background-color: ${p => p.$color || '#007AFF'};
3636
width: ${p => {
3737
switch (p.$size) {
@@ -58,7 +58,7 @@ const Box = styled(View)<BoxProps>`
5858
### Boolean props
5959

6060
```tsx
61-
const Badge = styled(View)<{ $active?: boolean }>`
61+
const Badge = styled.View<{ $active?: boolean }>`
6262
padding: 4px 8px;
6363
border-radius: 4px;
6464
background-color: ${p => p.$active ? '#34C759' : '#8E8E93'};
@@ -70,7 +70,7 @@ const Badge = styled(View)<{ $active?: boolean }>`
7070
```tsx
7171
type Variant = 'primary' | 'secondary' | 'success' | 'danger';
7272

73-
const Button = styled(Pressable)<{ $variant?: Variant }>`
73+
const Button = styled.Pressable<{ $variant?: Variant }>`
7474
padding: 12px 24px;
7575
border-radius: 8px;
7676
background-color: ${p => {
@@ -90,7 +90,7 @@ const Button = styled(Pressable)<{ $variant?: Variant }>`
9090
Static styles are compiled, dynamic styles computed at runtime:
9191

9292
```tsx
93-
const Card = styled(View)<{ $highlighted?: boolean }>`
93+
const Card = styled.View<{ $highlighted?: boolean }>`
9494
/* Static - compiled */
9595
padding: 16px;
9696
border-radius: 12px;
@@ -108,7 +108,7 @@ For best performance, keep dynamic styles minimal. More static styles = better p
108108

109109
```tsx
110110
// Good - mostly static
111-
const Button = styled(Pressable)<{ $primary?: boolean }>`
111+
const Button = styled.Pressable<{ $primary?: boolean }>`
112112
padding: 12px 24px;
113113
border-radius: 8px;
114114
font-size: 16px;
@@ -117,7 +117,7 @@ const Button = styled(Pressable)<{ $primary?: boolean }>`
117117
`;
118118

119119
// Less optimal - everything dynamic
120-
const Button = styled(Pressable)<{ $size?: number; $radius?: number }>`
120+
const Button = styled.Pressable<{ $size?: number; $radius?: number }>`
121121
padding: ${p => p.$size || 12}px;
122122
border-radius: ${p => p.$radius || 8}px;
123123
font-size: ${p => (p.$size || 12) + 4}px;
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
sidebar_position: 5
3+
---
4+
5+
# Extending Styles
6+
7+
You can extend existing styled components to inherit and override their styles.
8+
9+
## Basic inheritance
10+
11+
```tsx
12+
const BaseButton = styled.Pressable`
13+
padding: 12px 24px;
14+
border-radius: 8px;
15+
align-items: center;
16+
`;
17+
18+
const PrimaryButton = styled(BaseButton)`
19+
background-color: #007AFF;
20+
`;
21+
22+
const SecondaryButton = styled(BaseButton)`
23+
background-color: #6c757d;
24+
`;
25+
```
26+
27+
## Overriding styles
28+
29+
Child components can override parent styles:
30+
31+
```tsx
32+
const Card = styled.View`
33+
padding: 16px;
34+
background-color: white;
35+
border-radius: 8px;
36+
`;
37+
38+
const HighlightCard = styled(Card)`
39+
background-color: #fff3cd;
40+
border-width: 2px;
41+
border-color: #ffc107;
42+
`;
43+
```
44+
45+
## Adding dynamic props
46+
47+
```tsx
48+
const BaseText = styled.Text`
49+
font-size: 16px;
50+
color: #000;
51+
`;
52+
53+
const DynamicText = styled(BaseText)<{ $bold?: boolean }>`
54+
font-weight: ${p => p.$bold ? 'bold' : 'normal'};
55+
`;
56+
```
57+
58+
## Combining with attrs
59+
60+
```tsx
61+
const BaseInput = styled.TextInput`
62+
padding: 12px;
63+
border-width: 1px;
64+
border-radius: 8px;
65+
`;
66+
67+
const EmailInput = styled(BaseInput).attrs({
68+
keyboardType: 'email-address',
69+
autoCapitalize: 'none',
70+
})`
71+
border-color: #007AFF;
72+
`;
73+
```
74+
75+
## Style priority
76+
77+
When combining styled components with inline styles, inline `style` prop and `css` prop have higher priority:
78+
79+
```tsx
80+
const Button = styled.Pressable`
81+
background-color: #007AFF;
82+
padding: 12px;
83+
`;
84+
85+
// Inline style overrides styled component styles
86+
<Button style={{ backgroundColor: '#ff0000' }}>
87+
Red Button
88+
</Button>
89+
90+
// css prop also has higher priority
91+
<Button style={css`background-color: #00ff00;`}>
92+
Green Button
93+
</Button>
94+
```

0 commit comments

Comments
 (0)