Skip to content

Commit 7c6c55c

Browse files
Set v4 as default docs (nativewind#1159)
* Set v4 as default docs This includes: • Configure docusaurus to use v4 as current • Update README with proper instructions to run the website locally • Add home page for v4 and set it as root directory • Address inconsistency in sidebar names * Prettified Code! * Add version switcher --------- Co-authored-by: danstepanov <[email protected]> Co-authored-by: Mark Lawlor <[email protected]>
1 parent 8690499 commit 7c6c55c

File tree

9 files changed

+193
-39
lines changed

9 files changed

+193
-39
lines changed

apps/website/README.md

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,30 @@
1-
# Website
1+
# NativeWind Website
22

3-
This website is built using [Docusaurus 2](https://docusaurus.io/), a modern static website generator.
3+
This website is built using [Docusaurus 3](https://docusaurus.io/), a modern static website generator.
44

55
### Installation
66

77
```
8-
$ yarn
8+
$ npm i
99
```
1010

1111
### Local Development
1212

13-
```
14-
$ yarn start
15-
```
16-
17-
This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server.
18-
19-
### Build
13+
Normally, you actually want to run this project from the root of this monorepo via
2014

2115
```
22-
$ yarn build
16+
$ npm run website
2317
```
2418

25-
This command generates static content into the `build` directory and can be served using any static contents hosting service.
26-
27-
### Deployment
28-
29-
Using SSH:
30-
19+
However, this is currently not working so, for now, run the following from anywhere in the monorepo
3120
```
32-
$ USE_SSH=true yarn deploy
21+
$ cd apps/website; npx docusaurus start
3322
```
3423

35-
Not using SSH:
24+
This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server.
25+
26+
### Structure
3627

37-
```
38-
$ GIT_USER=<Your GitHub username> yarn deploy
39-
```
28+
Most work on the NativeWind docs will pertain to the current version of NativeWind. Version 4 is the current version of NativeWind and the docs for it live in the `./docs` folder. The sidebar is configured via `./sidebars.js`. To use Docusaurus' nomenclature, version 4 is both the current version and the latest version. For previous versions, you can look to the directories prefixed with `./versioned_` and you'll be able to modify docs pertaining to older versions of NativeWind.
4029

41-
If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch.
30+
Docusaurus takes a bit of getting used to so I'd recommend you spend a little bit of time familiarizing with [their docs](https://docusaurus.io/docs/3.0.1/versioning) if you haven't already.

apps/website/docs/home.md

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
---
2+
title: Home
3+
slug: /
4+
pagination_prev: null
5+
pagination_next: null
6+
custom_edit_url: null
7+
---
8+
9+
# Overview
10+
11+
## What is NativeWind?
12+
13+
NativeWind allows you to use [Tailwind CSS](https://tailwindcss.com) to style your components in React Native. Styled components can be shared between all React Native platforms, using the best style engine for that platform; CSS StyleSheet on web and StyleSheet.create for native. It's goals are to provide a consistent styling experience across all platforms, improving Developer UX, component performance and code maintainability.
14+
15+
On native platforms, NativeWind performs two functions. First, at build time, it compiles your Tailwind CSS styles into `StyleSheet.create` objects and determines the conditional logic of styles (e.g. hover, focus, active, etc). Second, it has an efficient runtime system that applies the styles to your components. This means you can use the full power of Tailwind CSS, including media queries, container queries, and custom values, while still having the performance of a native style system.
16+
17+
On web, NativeWind is a small polyfill for adding `className` support to React Native Web.
18+
19+
## Key Features
20+
21+
🌐 **Universal** Uses the best style system for each platform.
22+
23+
🖥️ **DevUX** Plugins for simple setup and improving intellisense support
24+
25+
**Media & Container queries** Use modern mobile styling features like media and container queries [(docs)](../core-concepts/states#hover-focus-and-active)
26+
27+
👪 **Custom values (CSS Variables)** Create themes, sub-themes and dynamic styles using custom values
28+
29+
**Pseudo classes** hover / focus / active on compatible components [(docs)](../core-concepts/states#hover-focus-and-active)
30+
31+
👪 **Parent state styles** automatically style children based upon parent pseudo classes [(docs)](../core-concepts/states#hover-focus-and-active#styling-based-on-parent-state)
32+
33+
🔥 **Lots of other features**
34+
35+
- dark mode
36+
- arbitrary classes
37+
- platform selectors
38+
- plugins
39+
40+
## How is this different StyleSheet.create?
41+
42+
A full featured style system should have
43+
44+
- Static styles
45+
- UI state styles (active, hover, focus, etc)
46+
- Responsive styles (media queries, dynamic units)
47+
- Container queries (styling based upon parent appearance)
48+
- Device state styles (orientation, color scheme)
49+
- Use the best rendering engine available
50+
51+
React Native's StyleSheet system only provides static styles, with other features left for the user to implement. By using NativeWind you can focus on writing your system instead of building your own custom style system.
52+
53+
On the web, it avoids injecting a StyleSheet at runtime by reusing the existing Tailwind CSS stylesheet, allowing you to use Server Side Rendering and much better initial page load performance.
54+
55+
## In action
56+
57+
NativeWind handles both the Tailwind CSS compilation and the runtime styles. It works via a JSX transform, meaning there is no need for custom wrappers/boilerplate.
58+
59+
As all React components are transformed with JSX, it works with 3rd party modules.
60+
61+
```tsx
62+
import { CustomText } from "third-party-text-component";
63+
64+
export function BoldText(props) {
65+
// You just need to write `className="<your styles>"`
66+
return <CustomText className="text-bold" {...props} />;
67+
}
68+
```
69+
70+
Styling can by dynamic and you can perform conditional logic and built up complex style objects.
71+
72+
```tsx
73+
import { Text } from "react-native";
74+
75+
export function MyText({ bold, italic, lineThrough, ...props }) {
76+
const classNames = [];
77+
78+
if (bold) classNames.push("font-bold");
79+
if (italic) classNames.push("italic");
80+
if (lineThrough) classNames.push("line-through");
81+
82+
return <Text className={classNames.join(" ")} {...props} />;
83+
}
84+
```
85+
86+
By default NativeWind maps `className`->`style`, but it can handle the mapping of complex components.
87+
88+
```tsx
89+
remapProps(FlatList, {
90+
className: "style",
91+
ListFooterComponentClassName: "ListFooterComponentStyle",
92+
ListHeaderComponentClassName: "ListHeaderComponentStyle",
93+
columnWrapperClassName: "columnWrapperStyle",
94+
contentContainerClassName: "contentContainerStyle",
95+
});
96+
97+
<FlatList
98+
{...}
99+
className="bg-black"
100+
ListHeaderComponentClassName="bg-black text-white"
101+
ListFooterComponentClassName="bg-black text-white"
102+
columnWrapperClassName="bg-black"
103+
contentContainerClassName="bg-black"
104+
indicatorClassName="bg-black"
105+
/>
106+
```
107+
108+
And can even work with components that expect style attributes as props
109+
110+
```tsx
111+
import { Text } from "react-native";
112+
import { cssInterop } from "nativewind";
113+
import { Svg, Circle } from "react-native-svg";
114+
115+
/**
116+
* Circle uses `height`/`width` props on native and className on web
117+
*/
118+
const StyledSVG = cssInterop(Svg, {
119+
className: {
120+
target: "style",
121+
nativeStyleToProp: {
122+
height: true,
123+
width: true,
124+
},
125+
},
126+
});
127+
/**
128+
* Circle uses `fill`/`stroke`/`strokeWidth` props on native and className on web
129+
*/
130+
const StyledCircle = cssInterop(Circle, {
131+
className: {
132+
target: "style",
133+
nativeStyleToProp: {
134+
fill: true,
135+
stroke: true,
136+
strokeWidth: true,
137+
},
138+
},
139+
});
140+
141+
export function BoldText(props) {
142+
return (
143+
<Svg className="w-1/2 h-1/2" viewBox="0 0 100 100">
144+
<StyledCircle
145+
className="fill-green-500 stroke-blue-500 stroke-2"
146+
cx="50"
147+
cy="50"
148+
r="45"
149+
/>
150+
</Svg>
151+
);
152+
}
153+
```

apps/website/docs/tailwind/typography/text-decoration-style.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Compatibility from "../\_compatibility.mdx"
22
import Usage from "../\_usage.mdx"
33

4-
# Text Decoration style
4+
# Text Decoration Style
55

66
## Usage
77

apps/website/docusaurus.config.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const config = {
1313
onBrokenLinks: "throw",
1414
onBrokenMarkdownLinks: "warn",
1515
favicon: "img/favicon.ico",
16-
organizationName: "marklawlor", // Usually your GitHub org/user name.
16+
organizationName: "nativewind", // Usually your GitHub org/user name.
1717
projectName: "NativeWind", // Usually your repo name.
1818

1919
clientModules: [
@@ -34,19 +34,19 @@ const config = {
3434
({
3535
docs: {
3636
breadcrumbs: false,
37-
editUrl: `https://github.com/marklawlor/nativewind/edit/main/apps/website/`,
37+
editUrl: `https://github.com/nativewind/nativewind/edit/main/apps/website/`,
3838
remarkPlugins: [require("./src/remark-snackplayer")],
3939
routeBasePath: "/", // disable landing page
4040
sidebarPath: require.resolve("./sidebars.js"),
41-
lastVersion: "v2",
41+
lastVersion: "current",
4242
versions: {
4343
current: {
4444
label: "v4",
45-
path: "v4",
45+
path: "/",
4646
},
4747
v2: {
4848
label: "v2",
49-
path: "",
49+
path: "v2",
5050
},
5151
},
5252
},
@@ -83,7 +83,7 @@ const config = {
8383
},
8484
announcementBar: {
8585
content:
86-
'<a href="/v4/overview">NativeWind v4.0 is coming soon. Click here to see the docs</a>',
86+
'<a href="/v2">Looking for the NativeWind v2 docs? Click here</a>',
8787
isCloseable: true,
8888
},
8989
navbar: {
@@ -94,15 +94,20 @@ const config = {
9494
},
9595
items: [
9696
{
97-
href: "https://discord.gg/ypNakAFQ65",
97+
href: "https://nativewind.dev/discord",
9898
label: "Discord",
9999
position: "right",
100100
},
101101
{
102-
href: "https://github.com/marklawlor/nativewind",
102+
href: "https://github.com/nativewind/nativewind",
103103
label: "GitHub",
104104
position: "right",
105105
},
106+
{
107+
type: "docsVersionDropdown",
108+
position: "left",
109+
dropdownActiveClassDisabled: true,
110+
},
106111
],
107112
},
108113
footer: {
@@ -113,13 +118,12 @@ const config = {
113118
items: [
114119
{
115120
label: "GitHub",
116-
href: "https://github.com/marklawlor/nativewind",
121+
href: "https://github.com/nativewind/nativewind",
117122
},
118123
{
119124
label: "Discord",
120-
href: "https://discord.gg/ypNakAFQ65",
125+
href: "https://nativewind.dev/discord",
121126
},
122-
123127
],
124128
},
125129
],

apps/website/sidebars.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
/** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */
1515
const sidebars = {
1616
docs: [
17+
{
18+
type: "doc",
19+
id: "home",
20+
className: "home"
21+
},
1722
{
1823
type: "category",
1924
label: "Overview",

apps/website/versioned_docs/version-v2/_dependencies.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ yarn add --dev [email protected]
2727

2828
:::caution
2929

30-
NativeWind does not work with TailwindCSS >3.3.2. If you wish to use the most current version, please upgrade to [NativeWind v4](/v4/overview)
30+
NativeWind does not work with TailwindCSS >3.3.2. If you wish to use the most current version, please upgrade to [NativeWind v4](/overview)
3131

3232
:::

apps/website/versioned_docs/version-v2/_start-coding-components.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Start writing code!
44

5-
Without the Babel transform you will need to wrap your components in the [styled higher-order component](../api/styled)
5+
Without the Babel transform you will need to wrap your components in the [styled higher-order component](/v2/api/styled)
66

77
```diff
88
import { StatusBar } from 'expo-status-bar';

apps/website/versioned_docs/version-v2/api/StyledComponent.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: StyledComponent
44
sidebar_label: <StyledComponent />
55
---
66

7-
`StyledComponent` is the component version of [`styled`](/api/styled) accepts your component as a prop.
7+
`StyledComponent` is the component version of [`styled`](/v2//api/styled) accepts your component as a prop.
88

99
`StyledComponent` will pass all props to your component, except for `tw` and `className` which it will convert into StyledSheet objects and will pass them to your component via the `style` prop.
1010

apps/website/versions.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
["v2"]
1+
[
2+
"current",
3+
"v2"
4+
]

0 commit comments

Comments
 (0)