Skip to content

Commit b667410

Browse files
committed
docs: improve clarity in state modifiers documentation and enhance code examples
1 parent 8d88b48 commit b667410

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

docs/src/content/docs/guides/state-modifiers.md

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ description: Apply styles based on component state with zero runtime overhead
55

66
Apply styles based on component state using modifiers like `active:`, `focus:`, and `disabled:`. The Babel plugin automatically generates optimized style functions.
77

8-
:::note[Enhanced Components Required]
9-
State modifiers require using the enhanced `Pressable` and `TextInput` components from `@mgcrea/react-native-tailwind`.
8+
:::note[Enhanced Components]
9+
Some state modifiers may require using the enhanced `Pressable` and `TextInput` components from `@mgcrea/react-native-tailwind`.
1010
:::
1111

1212
## Active Modifier (Pressable)
@@ -16,8 +16,7 @@ Use the `active:` modifier to apply styles when a Pressable component is pressed
1616
### Basic Example
1717

1818
```tsx
19-
import { Text } from "react-native";
20-
import { Pressable } from "@mgcrea/react-native-tailwind";
19+
import { Text, Pressable } from "react-native";
2120

2221
export function MyButton() {
2322
return (
@@ -32,10 +31,7 @@ export function MyButton() {
3231

3332
```tsx
3433
<Pressable
35-
style={({ pressed }) => [
36-
_twStyles._bg_blue_500_p_4_rounded_lg,
37-
pressed && _twStyles._active_bg_blue_700,
38-
]}
34+
style={({ pressed }) => [_twStyles._bg_blue_500_p_4_rounded_lg, pressed && _twStyles._active_bg_blue_700]}
3935
>
4036
<Text style={_twStyles._font_semibold_text_white}>Press Me</Text>
4137
</Pressable>
@@ -89,6 +85,10 @@ export function MyInput() {
8985

9086
Use the `disabled:` modifier to apply styles when a component is disabled.
9187

88+
:::note[How Pressable states are wired]
89+
`Pressable` gets its `active:` behavior for free from React Native's `style={({ pressed }) => ...}` API, but React Native does not pass `disabled` into that callback. The enhanced `Pressable` shipped by this library injects the `disabled` flag so `disabled:` modifiers work correctly.
90+
:::
91+
9292
### Pressable Example
9393

9494
```tsx
@@ -100,9 +100,7 @@ export function SubmitButton({ isLoading }) {
100100
disabled={isLoading}
101101
className="bg-blue-500 active:bg-blue-700 disabled:bg-gray-400 p-4 rounded-lg"
102102
>
103-
<Text className="text-white font-semibold">
104-
{isLoading ? "Loading..." : "Submit"}
105-
</Text>
103+
<Text className="text-white font-semibold">{isLoading ? "Loading..." : "Submit"}</Text>
106104
</Pressable>
107105
);
108106
}
@@ -139,10 +137,10 @@ The enhanced `TextInput` provides a convenient `disabled` prop:
139137

140138
## Supported Modifiers by Component
141139

142-
| Component | Supported Modifiers | Import From |
143-
|-----------|---------------------|-------------|
140+
| Component | Supported Modifiers | Import From |
141+
| ----------- | ------------------------------------------ | ------------------------------- |
144142
| `Pressable` | `active:`, `hover:`, `focus:`, `disabled:` | `@mgcrea/react-native-tailwind` |
145-
| `TextInput` | `focus:`, `disabled:` | `@mgcrea/react-native-tailwind` |
143+
| `TextInput` | `focus:`, `disabled:` | `@mgcrea/react-native-tailwind` |
146144

147145
## Key Features
148146

@@ -185,9 +183,7 @@ export function LoginForm() {
185183
className="bg-blue-500 active:bg-blue-700 disabled:bg-gray-400 p-4 rounded-lg items-center"
186184
onPress={() => setIsLoading(true)}
187185
>
188-
<Text className="text-white font-semibold">
189-
{isLoading ? "Loading..." : "Sign In"}
190-
</Text>
186+
<Text className="text-white font-semibold">{isLoading ? "Loading..." : "Sign In"}</Text>
191187
</Pressable>
192188
</View>
193189
);

0 commit comments

Comments
 (0)