Skip to content

Commit d98a8a6

Browse files
committed
docs: update readme
1 parent 40fc17b commit d98a8a6

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

README.md

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ const Status = ({ isActive, labelColor }) => {
7575

7676
`ios:bg-blue-800 android:bg-purple-800`
7777

78+
- 🖥   Web only selectors
79+
80+
`focus:bg-blue-400 active:bg-indigo-400`
81+
7882
- 🕺   Stackable selectors
7983

8084
`ios:md:font-bold android:(text-blue-800 sm:dark:text-blue-100)`
@@ -107,7 +111,7 @@ Add babel-plugin-macros to your `.babelrc` or `babel.config.js` and you're all s
107111

108112
### Using the `tw` prop
109113

110-
The best and easiest usage is to simply use the `tw` prop that is artificially added to all JSX elements. Under the hood, the macro removes the `tw` prop completely and instead applies or extends a `style` prop and also adds a web-only media id used to apply CSS-based media queries.
114+
The best and easiest usage is to simply use the `tw` prop that is artificially added to all JSX elements. Under the hood, the macro removes the `tw` prop completely and instead applies or extends a `style` prop and also adds a web-only data-tw id used to apply CSS-based media queries.
111115

112116
All you have to do is have _any_ import of react-native-tailwind.macro in your file, either `import "react-native-tailwind.macro"` or `import { /* whatever import you need */ } from "react-native-tailwind.macro"`.
113117

@@ -197,7 +201,7 @@ const Example = ({ rounded, backgroundColor }) => {
197201
<Animated.View
198202
style={styles.box}
199203
{/* Required for responsive styles on the web, hence it's preferred to apply all responsive styles through the `tw` prop */}
200-
dataSet={{ media: styles.box.id }}
204+
dataSet={{ tw: styles.box.id }}
201205
/>
202206
<TouchableOpacity
203207
{/* Mix and match tw prop and styles in your code */}
@@ -228,20 +232,31 @@ const styles = useTailwindStyles(
228232

229233
By default, the device's color scheme preference is used to enable dark mode. If you want to dynamically change whether dark mode is enabled, you can wrap your App with `TailwindProvider` and pass in your dark mode preference.
230234

235+
On the web, the set value will automatically be persisted in a cookie to enable SSR and SSG without flashes on load.
236+
231237
```ts
232-
import { Appearance } from "react-native"
233-
import { TailwindProvider } from "react-native-tailwind.macro"
238+
import {
239+
TailwindProvider,
240+
getInitialColorScheme,
241+
} from "react-native-tailwind.macro"
234242

235243
const App = () => {
236-
const [darkMode, setDarkMode] = useState(
237-
// Use device preference as default
238-
Appearance.getColorScheme() === "dark"
239-
)
244+
const [darkMode, setDarkMode] = useState(getInitialColorScheme() === "dark")
240245

241246
return <TailwindProvider dark={darkMode}>{/* ... */}</TailwindProvider>
242247
}
243248
```
244249

250+
### `getInitialColorScheme`
251+
252+
Returns either the cookie-persisted preference on web or falls back to the system preference.
253+
254+
```ts
255+
import { getInitialColorScheme } from "react-native-tailwind.macro"
256+
257+
getInitialColorScheme() // returns "light" or "dark"
258+
```
259+
245260
### Macro Options
246261

247262
You can apply options to the macro by adding a `babel-plugin-macros.config.js` or specifying them in your `package.json` like below:
@@ -282,9 +297,10 @@ Alternatively:
282297

283298
In order to enable SSR support via media queries on Next.js, update your [custom document](https://nextjs.org/docs/advanced-features/custom-document) as follows:
284299

285-
```ts
286-
// Add the flush import
287-
import { flush } from "react-native-tailwind.macro"
300+
```diff
301+
// pages/_document.js
302+
303+
+ import { flush } from "react-native-tailwind.macro"
288304

289305
/* ... */
290306

@@ -295,7 +311,7 @@ export class Document extends NextDocument {
295311
const page = renderPage()
296312
const styles = [
297313
getStyleElement(),
298-
flush(), // Add this call
314+
+ flush(),
299315
]
300316
return { ...page, styles: React.Children.toArray(styles) }
301317
}
@@ -369,8 +385,8 @@ const Example = () => {
369385
<View
370386
// Apply the memoized style
371387
style={tailwindStyles["a7gsbs"]}
372-
// Apply media id for CSS-based media queries
373-
dataSet={{ media: tailwindStyles["a7gsbs"].id }}
388+
// Apply data-tw id for CSS-based media queries
389+
dataSet={{ tw: tailwindStyles["a7gsbs"].id }}
374390
/>
375391
)
376392
}

0 commit comments

Comments
 (0)