@titan-design/react-ui 0.2.5 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/docs/WEB_SETUP.md +217 -0
  2. package/package.json +2 -1
@@ -0,0 +1,217 @@
1
+ # Web Consumer Setup
2
+
3
+ How to use `@titan-design/react-ui` in a Vite-based web application.
4
+
5
+ ## Prerequisites
6
+
7
+ - **Vite** 5+ with `@vitejs/plugin-react`
8
+ - **Tailwind CSS** 3.4+
9
+ - **react-native-web** 0.19+
10
+
11
+ ## Quick Start
12
+
13
+ ### 1. Install dependencies
14
+
15
+ ```bash
16
+ npm install @titan-design/react-ui react-native-web
17
+ npm install -D tailwindcss autoprefixer postcss nativewind
18
+ ```
19
+
20
+ > `nativewind` is an **optional peer dependency** and only needed at build time — it
21
+ > provides a Tailwind preset that adds React Native platform variants (`web:`,
22
+ > `native:`) used by titan components. It is NOT needed at runtime on web.
23
+ > Install it as a dev dependency so Tailwind can resolve the preset.
24
+
25
+ ### 2. Configure Vite
26
+
27
+ ```ts
28
+ // vite.config.ts
29
+ import { defineConfig } from 'vite'
30
+ import react from '@vitejs/plugin-react'
31
+
32
+ export default defineConfig({
33
+ plugins: [react()],
34
+ resolve: {
35
+ alias: {
36
+ 'react-native': 'react-native-web',
37
+ },
38
+ },
39
+ })
40
+ ```
41
+
42
+ That's it. No `jsxImportSource`, no `optimizeDeps`, no `resolve.dedupe`.
43
+
44
+ ### 3. Configure Tailwind CSS
45
+
46
+ ```js
47
+ // tailwind.config.js
48
+ const titanConfig = require('@titan-design/react-ui/tailwind.config.js')
49
+
50
+ /** @type {import('tailwindcss').Config} */
51
+ module.exports = {
52
+ content: [
53
+ './src/**/*.{js,jsx,ts,tsx}',
54
+ './node_modules/@titan-design/react-ui/dist/**/*.{js,mjs}',
55
+ ],
56
+ presets: [titanConfig],
57
+ darkMode: 'class',
58
+ }
59
+ ```
60
+
61
+ The `titanConfig` preset includes `nativewind/preset` which registers the `web:` and
62
+ `native:` Tailwind variants that titan components use (e.g., `web:hover:bg-gray-100`).
63
+
64
+ ### 4. Configure PostCSS
65
+
66
+ ```js
67
+ // postcss.config.js
68
+ module.exports = {
69
+ plugins: {
70
+ tailwindcss: {},
71
+ autoprefixer: {},
72
+ },
73
+ }
74
+ ```
75
+
76
+ ### 5. Import global CSS
77
+
78
+ ```tsx
79
+ // main.tsx or App.tsx
80
+ import '@titan-design/react-ui/theme/global.css'
81
+ ```
82
+
83
+ This loads the design token CSS custom properties (colors, typography, spacing, etc.).
84
+
85
+ ### 6. Use components
86
+
87
+ ```tsx
88
+ import { Button, ButtonText, Card, CardContent } from '@titan-design/react-ui'
89
+
90
+ function App() {
91
+ return (
92
+ <Card>
93
+ <CardContent>
94
+ <Button color="primary">
95
+ <ButtonText>Hello</ButtonText>
96
+ </Button>
97
+ </CardContent>
98
+ </Card>
99
+ )
100
+ }
101
+ ```
102
+
103
+ ---
104
+
105
+ ## How It Works
106
+
107
+ Titan's web distribution (the `dist/` you import) uses a custom JSX runtime
108
+ that converts `className` props to
109
+ [`$$css` style objects](https://github.com/nicholasxjy/styleq#compiled-styles)
110
+ at **build time**. react-native-web's `styleq` recognizes these objects and
111
+ applies their values as CSS class names on DOM elements.
112
+
113
+ This means:
114
+ - No NativeWind runtime needed on web
115
+ - No `interopComponents` Map lookup (which breaks under Vite module deduplication)
116
+ - No `jsxImportSource: 'nativewind'` configuration needed
117
+ - className and inline `style` work together correctly (inline style wins on conflicts)
118
+
119
+ ### Native React Native
120
+
121
+ On native (iOS/Android), Metro resolves the `react-native` export condition in
122
+ titan's `package.json`, which points to source files. NativeWind's Babel plugin
123
+ (configured in your Metro/Expo setup) handles `className` natively.
124
+
125
+ ---
126
+
127
+ ## Migration from NativeWind-based Setup
128
+
129
+ If you previously configured NativeWind's runtime interop, here's what to remove:
130
+
131
+ ### Remove from `vite.config.ts`
132
+
133
+ ```diff
134
+ plugins: [
135
+ - react({ jsxImportSource: 'nativewind' }),
136
+ + react(),
137
+ ],
138
+ resolve: {
139
+ alias: { 'react-native': 'react-native-web' },
140
+ - dedupe: ['react-native-web'],
141
+ },
142
+ - optimizeDeps: {
143
+ - esbuildOptions: {
144
+ - loader: { '.js': 'jsx' },
145
+ - },
146
+ - },
147
+ ```
148
+
149
+ ### Remove `setup-interop.ts`
150
+
151
+ Delete any file that re-registers `cssInterop` for View/Text/Pressable.
152
+ This was a workaround for Vite's module deduplication breaking
153
+ NativeWind's `interopComponents` Map. It is no longer needed.
154
+
155
+ ```diff
156
+ // main.tsx
157
+ - import './setup-interop'
158
+ import '@titan-design/react-ui/theme/global.css'
159
+ ```
160
+
161
+ ### Remove runtime dependencies
162
+
163
+ ```bash
164
+ npm uninstall nativewind react-native-css-interop
165
+ npm install -D nativewind # keep as dev dep for Tailwind preset only
166
+ ```
167
+
168
+ ### Remove `conditions` from Vite resolve
169
+
170
+ If you were using `conditions: ['react-native']` to resolve titan's source
171
+ files, remove it. The dist now handles className conversion internally.
172
+
173
+ ```diff
174
+ resolve: {
175
+ - conditions: ['react-native', 'import'],
176
+ alias: { 'react-native': 'react-native-web' },
177
+ },
178
+ ```
179
+
180
+ ---
181
+
182
+ ## Troubleshooting
183
+
184
+ ### Tailwind classes not appearing
185
+
186
+ 1. Verify your `tailwind.config.js` content array includes titan's dist:
187
+ ```js
188
+ content: [
189
+ './node_modules/@titan-design/react-ui/dist/**/*.{js,mjs}',
190
+ ]
191
+ ```
192
+ 2. Verify PostCSS is configured with the `tailwindcss` plugin
193
+ 3. Verify you imported `@titan-design/react-ui/theme/global.css`
194
+
195
+ ### Layout properties not applying (flexDirection, alignItems, etc.)
196
+
197
+ This was the original NativeWind interop issue. If you see this after upgrading,
198
+ ensure you've updated `@titan-design/react-ui` to a version with the custom
199
+ JSX runtime (0.3.0+). Older versions require the NativeWind runtime setup.
200
+
201
+ ### Your own `<View className="...">` components don't get styles
202
+
203
+ Titan's custom JSX runtime only applies to titan's pre-built dist. If your app
204
+ code directly uses React Native primitives with className, you have two options:
205
+
206
+ 1. **Use standard CSS/Tailwind on web**: Write `<div className="flex-row">` for
207
+ your own web-only components
208
+ 2. **Set up NativeWind for your app's JSX**: Add `jsxImportSource: 'nativewind'`
209
+ to your Vite React plugin config. This only affects your app's source files
210
+ (titan's dist is already handled)
211
+
212
+ ### Using titan with Webpack instead of Vite
213
+
214
+ The same principle applies. You need:
215
+ 1. `react-native` → `react-native-web` alias (via `resolve.alias` in webpack config)
216
+ 2. Tailwind CSS configured with titan's content paths
217
+ 3. No NativeWind runtime setup needed
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@titan-design/react-ui",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "description": "Cross-platform design system built on Gluestack UI",
5
5
  "author": "Henry Jewkes",
6
6
  "license": "MIT",
@@ -123,6 +123,7 @@
123
123
  "files": [
124
124
  "dist",
125
125
  "src",
126
+ "docs",
126
127
  "tailwind.config.js"
127
128
  ],
128
129
  "sideEffects": false,