styledwind-native 1.1.3 → 1.2.0
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.
- package/README.md +121 -4
- package/dist/color-scheme.d.ts +9 -0
- package/dist/color-scheme.d.ts.map +1 -0
- package/dist/color-scheme.js +93 -0
- package/dist/color-scheme.js.map +1 -0
- package/dist/components.d.ts +4 -0
- package/dist/components.d.ts.map +1 -0
- package/dist/components.js +66 -0
- package/dist/components.js.map +1 -0
- package/dist/create.d.ts +3 -0
- package/dist/create.d.ts.map +1 -0
- package/dist/create.js +10 -0
- package/dist/create.js.map +1 -0
- package/dist/index.d.ts +7 -52
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -187
- package/dist/index.js.map +1 -1
- package/dist/safe-area.d.ts +25 -0
- package/dist/safe-area.d.ts.map +1 -0
- package/dist/safe-area.js +29 -0
- package/dist/safe-area.js.map +1 -0
- package/dist/types.d.ts +77 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +20 -1
- package/tailwind.cjs +110 -0
- package/tailwind.d.cts +17 -0
package/README.md
CHANGED
|
@@ -57,6 +57,62 @@ const MyComponent = () => {
|
|
|
57
57
|
export default MyComponent;
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
+
## Safe Areas
|
|
61
|
+
|
|
62
|
+
Use the `safe:*` utilities to read insets from
|
|
63
|
+
[`react-native-safe-area-context`](https://github.com/AppAndFlow/react-native-safe-area-context)
|
|
64
|
+
without wrapping anything:
|
|
65
|
+
|
|
66
|
+
```tsx
|
|
67
|
+
const Screen = tw.View`
|
|
68
|
+
flex-1
|
|
69
|
+
safe:pt
|
|
70
|
+
safe:pb
|
|
71
|
+
`;
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
| Utility | Sets |
|
|
75
|
+
| --- | --- |
|
|
76
|
+
| `safe:pt` `safe:pb` `safe:pl` `safe:pr` | padding to the matching inset |
|
|
77
|
+
| `safe:mt` `safe:mb` `safe:ml` `safe:mr` | margin to the matching inset |
|
|
78
|
+
| `safe:top` `safe:bottom` `safe:left` `safe:right` | position offset to the matching inset |
|
|
79
|
+
| `safe:h-top` `safe:h-bottom` | height to the top / bottom inset |
|
|
80
|
+
| `safe:w-left` `safe:w-right` | width to the left / right inset |
|
|
81
|
+
|
|
82
|
+
> `tw.SafeAreaView` wraps React Native's `SafeAreaView`, which
|
|
83
|
+
> [was deprecated in React Native 0.81](https://reactnative.dev/blog/2025/08/12/react-native-0.81)
|
|
84
|
+
> and will be removed. It is marked `@deprecated` here too. Prefer `tw.View` with
|
|
85
|
+
> `safe:*` utilities, or pass `react-native-safe-area-context`'s `SafeAreaView` via
|
|
86
|
+
> the `component` prop.
|
|
87
|
+
|
|
88
|
+
## Loading Your Tailwind Config
|
|
89
|
+
|
|
90
|
+
By default, `styledwind-native` tries to load `tailwind.config.{js,ts,tsx,json}`
|
|
91
|
+
from your app's root. That lookup is path-based and only works when the package is
|
|
92
|
+
hoisted flat into your app's `node_modules` (plain npm or yarn). It does **not** work
|
|
93
|
+
with pnpm, in hoisted monorepos, or when your config lives somewhere else.
|
|
94
|
+
|
|
95
|
+
For those setups, or whenever you want to be explicit, create your own instance
|
|
96
|
+
and import it everywhere instead of the default export:
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
// src/tw.ts
|
|
100
|
+
import { createStyledwind } from 'styledwind-native';
|
|
101
|
+
import config from '../tailwind.config'; // .js or .ts, Metro resolves either
|
|
102
|
+
|
|
103
|
+
export const { tw, Provider, useColorScheme } = createStyledwind(config);
|
|
104
|
+
export default tw;
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
```tsx
|
|
108
|
+
import tw, { Provider, useColorScheme } from './tw';
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
`Provider` and `useColorScheme` returned by `createStyledwind` are bound to that
|
|
112
|
+
instance, so always use the ones from your own `tw` module rather than the ones
|
|
113
|
+
exported from the package root. Every instance is independent, which also makes
|
|
114
|
+
it easy to have more than one config or to test components in isolation.
|
|
115
|
+
|
|
60
116
|
## Provider Setup
|
|
61
117
|
|
|
62
118
|
To enable color scheme management, wrap your app with the `Provider` component:
|
|
@@ -149,11 +205,51 @@ const Text = tw.Text`
|
|
|
149
205
|
|
|
150
206
|
When set to `'device'` mode, the library automatically detects system color scheme changes and updates all styled components accordingly.
|
|
151
207
|
|
|
152
|
-
##
|
|
208
|
+
## Editor Autocomplete
|
|
153
209
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
210
|
+
Tailwind's language server only knows the classes in your Tailwind config, so
|
|
211
|
+
`ios:`, `android:`, `safe:pt` and friends don't autocomplete out of the box.
|
|
212
|
+
`styledwind-native` ships a Tailwind preset that adds them. Add it to your config:
|
|
213
|
+
|
|
214
|
+
```js
|
|
215
|
+
// tailwind.config.js
|
|
216
|
+
module.exports = {
|
|
217
|
+
presets: [require('styledwind-native/tailwind')],
|
|
218
|
+
// ...your theme
|
|
219
|
+
};
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
```ts
|
|
223
|
+
// tailwind.config.ts
|
|
224
|
+
import type { Config } from 'tailwindcss';
|
|
225
|
+
import styledwind from 'styledwind-native/tailwind';
|
|
226
|
+
|
|
227
|
+
export default {
|
|
228
|
+
presets: [styledwind],
|
|
229
|
+
// ...your theme
|
|
230
|
+
} satisfies Config;
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
The preset registers:
|
|
234
|
+
|
|
235
|
+
- the device prefixes `twrnc` evaluates at runtime: `ios:`, `android:`, `web:`,
|
|
236
|
+
`windows:`, `macos:`, `portrait:`, `landscape:` and `retina:`
|
|
237
|
+
- the safe-area utilities: `safe:pt`, `safe:pb`, `safe:pl`, `safe:pr`, `safe:mt`,
|
|
238
|
+
`safe:mb`, `safe:ml`, `safe:mr`, `safe:top`, `safe:bottom`, `safe:left`,
|
|
239
|
+
`safe:right`, `safe:h-top`, `safe:h-bottom`, `safe:w-left` and `safe:w-right`
|
|
240
|
+
|
|
241
|
+
It's safe to leave the preset in the config you pass to `createStyledwind` or that
|
|
242
|
+
`twrnc` picks up: at runtime it only marks the `safe:*` classes as known so `twrnc`
|
|
243
|
+
never warns about them.
|
|
244
|
+
|
|
245
|
+
Then teach the language server where your classes live. Both editors use the
|
|
246
|
+
[same language server](https://github.com/tailwindlabs/tailwindcss-intellisense),
|
|
247
|
+
only the settings key differs.
|
|
248
|
+
|
|
249
|
+
### VS Code
|
|
250
|
+
|
|
251
|
+
Add to your settings for the
|
|
252
|
+
[official Tailwind extension](https://marketplace.visualstudio.com/items?itemName=bradlc.vscode-tailwindcss):
|
|
157
253
|
|
|
158
254
|
```jsonc
|
|
159
255
|
// ...
|
|
@@ -174,6 +270,27 @@ for VS Code.
|
|
|
174
270
|
],
|
|
175
271
|
```
|
|
176
272
|
|
|
273
|
+
### Zed
|
|
274
|
+
|
|
275
|
+
Zed ships [Tailwind support](https://zed.dev/docs/languages/tailwindcss) for
|
|
276
|
+
TypeScript and JavaScript out of the box. Add to your project's
|
|
277
|
+
`.zed/settings.json` (or your global `settings.json`):
|
|
278
|
+
|
|
279
|
+
```json
|
|
280
|
+
{
|
|
281
|
+
"lsp": {
|
|
282
|
+
"tailwindcss-language-server": {
|
|
283
|
+
"settings": {
|
|
284
|
+
"classAttributes": ["style"],
|
|
285
|
+
"experimental": {
|
|
286
|
+
"classRegex": ["tw`([^`]*)", "tw\\.[^`]+`([^`]*)`"]
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
```
|
|
293
|
+
|
|
177
294
|
More detailed instructions, including how to add snippets, are available
|
|
178
295
|
[here](https://github.com/jaredh159/tailwind-react-native-classnames/discussions/124).
|
|
179
296
|
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type TailwindFn } from 'twrnc';
|
|
3
|
+
import type { ColorSchemeContextValue, ProviderProps } from './types';
|
|
4
|
+
/** Build a `Provider` and `useColorScheme` pair bound to one twrnc instance. */
|
|
5
|
+
export declare function createColorScheme(twrnc: TailwindFn): {
|
|
6
|
+
Provider: ({ children, initialColorScheme, storage, }: ProviderProps) => React.JSX.Element;
|
|
7
|
+
useColorScheme: () => ColorSchemeContextValue;
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=color-scheme.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color-scheme.d.ts","sourceRoot":"","sources":["../src/color-scheme.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA+C,MAAM,OAAO,CAAC;AAEpE,OAAO,EAAuC,KAAK,UAAU,EAAE,MAAM,OAAO,CAAC;AAC7E,OAAO,KAAK,EAEV,uBAAuB,EAEvB,aAAa,EACd,MAAM,SAAS,CAAC;AAUjB,gFAAgF;AAChF,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,UAAU;2DAS9C,aAAa;0BAkFW,uBAAuB;EAkBnD"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import React, { useEffect, createContext, useContext } from 'react';
|
|
2
|
+
import { useColorScheme as useDeviceColorScheme } from 'react-native';
|
|
3
|
+
import { useAppColorScheme, useDeviceContext } from 'twrnc';
|
|
4
|
+
const STORAGE_KEY = 'tw:color-scheme';
|
|
5
|
+
function isColorSchemePreference(value) {
|
|
6
|
+
return value === 'light' || value === 'dark' || value === 'device';
|
|
7
|
+
}
|
|
8
|
+
/** Build a `Provider` and `useColorScheme` pair bound to one twrnc instance. */
|
|
9
|
+
export function createColorScheme(twrnc) {
|
|
10
|
+
const ColorSchemeContext = createContext(null);
|
|
11
|
+
function Provider({ children, initialColorScheme = 'device', storage, }) {
|
|
12
|
+
const [userColorScheme, setUserColorScheme] = React.useState(initialColorScheme);
|
|
13
|
+
const [twrnColorScheme, , twrnSetColorScheme] = useAppColorScheme(twrnc);
|
|
14
|
+
const deviceColorScheme = useDeviceColorScheme();
|
|
15
|
+
useDeviceContext(twrnc, userColorScheme === 'device'
|
|
16
|
+
? undefined
|
|
17
|
+
: {
|
|
18
|
+
observeDeviceColorSchemeChanges: false,
|
|
19
|
+
initialColorScheme: userColorScheme,
|
|
20
|
+
});
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (userColorScheme === 'device' && deviceColorScheme) {
|
|
23
|
+
if (twrnColorScheme !== deviceColorScheme) {
|
|
24
|
+
twrnSetColorScheme(deviceColorScheme);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}, [
|
|
28
|
+
deviceColorScheme,
|
|
29
|
+
userColorScheme,
|
|
30
|
+
twrnColorScheme,
|
|
31
|
+
twrnSetColorScheme,
|
|
32
|
+
]);
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (storage) {
|
|
35
|
+
storage.getItem(STORAGE_KEY).then(value => {
|
|
36
|
+
if (isColorSchemePreference(value)) {
|
|
37
|
+
setUserColorScheme(value);
|
|
38
|
+
if (value !== 'device') {
|
|
39
|
+
twrnSetColorScheme(value);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}, []);
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (storage) {
|
|
47
|
+
if (userColorScheme === 'device') {
|
|
48
|
+
storage.removeItem(STORAGE_KEY);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
storage.setItem(STORAGE_KEY, userColorScheme);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}, [userColorScheme, storage]);
|
|
55
|
+
const toggleColorScheme = () => {
|
|
56
|
+
const current = userColorScheme === 'device' ? twrnColorScheme : userColorScheme;
|
|
57
|
+
const newScheme = current === 'dark' ? 'light' : 'dark';
|
|
58
|
+
setUserColorScheme(newScheme);
|
|
59
|
+
twrnSetColorScheme(newScheme);
|
|
60
|
+
};
|
|
61
|
+
const setColorScheme = (scheme) => {
|
|
62
|
+
setUserColorScheme(scheme);
|
|
63
|
+
if (scheme !== 'device') {
|
|
64
|
+
twrnSetColorScheme(scheme);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
return (<ColorSchemeContext.Provider value={{
|
|
68
|
+
colorScheme: twrnColorScheme !== null && twrnColorScheme !== void 0 ? twrnColorScheme : 'light',
|
|
69
|
+
internalColorScheme: userColorScheme,
|
|
70
|
+
toggleColorScheme,
|
|
71
|
+
setColorScheme,
|
|
72
|
+
}}>
|
|
73
|
+
{children}
|
|
74
|
+
</ColorSchemeContext.Provider>);
|
|
75
|
+
}
|
|
76
|
+
function useColorScheme() {
|
|
77
|
+
const ctx = useContext(ColorSchemeContext);
|
|
78
|
+
const [twrnColorScheme, twrnToggleColorScheme, twrnSetColorScheme] = useAppColorScheme(twrnc);
|
|
79
|
+
if (ctx)
|
|
80
|
+
return ctx;
|
|
81
|
+
return {
|
|
82
|
+
colorScheme: twrnColorScheme !== null && twrnColorScheme !== void 0 ? twrnColorScheme : 'light',
|
|
83
|
+
internalColorScheme: 'device',
|
|
84
|
+
toggleColorScheme: twrnToggleColorScheme,
|
|
85
|
+
setColorScheme: scheme => {
|
|
86
|
+
if (scheme !== 'device')
|
|
87
|
+
twrnSetColorScheme(scheme);
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
return { Provider, useColorScheme };
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=color-scheme.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color-scheme.js","sourceRoot":"","sources":["../src/color-scheme.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACpE,OAAO,EAAE,cAAc,IAAI,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAmB,MAAM,OAAO,CAAC;AAQ7E,MAAM,WAAW,GAAG,iBAAiB,CA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AAc;aACf,CAAC,CAEF;QAAA,CAAC,QAAQ,CACX;MAAA,EAAE,kBAAkB,CAAC,QAAQ,CAAC,CAC/B,CAAC;IACJ,CAAC;IAED,SAAS,cAAc;QACrB,MAAM,GAAG,GAAG,UAAU,CAAC,kBAAkB,CAAC,CAAC;QAC3C,MAAM,CAAC,eAAe,EAAE,qBAAqB,EAAE,kBAAkB,CAAC,GAChE,iBAAiB,CAAC,KAAK,CAAC,CAAC;QAE3B,IAAI,GAAG;YAAE,OAAO,GAAG,CAAC;QAEpB,OAAO;YACL,WAAW,EAAE,eAAe,aAAf,eAAe,cAAf,eAAe,GAAI,OAAO;YACvC,mBAAmB,EAAE,QAAQ;YAC7B,iBAAiB,EAAE,qBAAqB;YACxC,cAAc,EAAE,MAAM,CAAC,EAAE;gBACvB,IAAI,MAAM,KAAK,QAAQ;oBAAE,kBAAkB,CAAC,MAAM,CAAC,CAAC;YACtD,CAAC;SACF,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components.d.ts","sourceRoot":"","sources":["../src/components.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAqB,KAAK,UAAU,EAAc,MAAM,OAAO,CAAC;AAGvE,OAAO,KAAK,EAIV,kBAAkB,EACnB,MAAM,SAAS,CAAC;AAkFjB,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,UAAU,GAChB,kBAAkB,CASpB"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import RN from 'react-native';
|
|
3
|
+
import { useAppColorScheme } from 'twrnc';
|
|
4
|
+
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
5
|
+
import { parseTemplate, SAFE_AREA_UTILITIES } from './safe-area';
|
|
6
|
+
const baseComponents = {
|
|
7
|
+
ActivityIndicator: RN.ActivityIndicator,
|
|
8
|
+
AnimatedFlatList: RN.Animated.FlatList,
|
|
9
|
+
AnimatedImage: RN.Animated.Image,
|
|
10
|
+
AnimatedScrollView: RN.Animated.ScrollView,
|
|
11
|
+
AnimatedSectionList: RN.Animated.SectionList,
|
|
12
|
+
AnimatedText: RN.Animated.Text,
|
|
13
|
+
AnimatedView: RN.Animated.View,
|
|
14
|
+
Button: RN.Button,
|
|
15
|
+
FlatList: RN.FlatList,
|
|
16
|
+
Image: RN.Image,
|
|
17
|
+
Modal: RN.Modal,
|
|
18
|
+
SafeAreaView: RN.SafeAreaView,
|
|
19
|
+
ScrollView: RN.ScrollView,
|
|
20
|
+
SectionList: RN.SectionList,
|
|
21
|
+
StatusBar: RN.StatusBar,
|
|
22
|
+
Switch: RN.Switch,
|
|
23
|
+
Text: RN.Text,
|
|
24
|
+
TextInput: RN.TextInput,
|
|
25
|
+
TouchableHighlight: RN.TouchableHighlight,
|
|
26
|
+
TouchableNativeFeedback: RN.TouchableNativeFeedback,
|
|
27
|
+
TouchableOpacity: RN.TouchableOpacity,
|
|
28
|
+
View: RN.View,
|
|
29
|
+
};
|
|
30
|
+
function createTailwindComponent(twrnc, Component, styles, ...interpolations) {
|
|
31
|
+
const { classNames, safeArea } = parseTemplate(styles);
|
|
32
|
+
return React.forwardRef(function TailwindComponent({ children, component, ...props }, ref) {
|
|
33
|
+
var _a;
|
|
34
|
+
// Subscribes this component to color scheme changes.
|
|
35
|
+
useAppColorScheme(twrnc);
|
|
36
|
+
let BaseComponent = Component;
|
|
37
|
+
let baseStyle = null;
|
|
38
|
+
if (typeof component === 'function') {
|
|
39
|
+
baseStyle = (_a = component.defaultProps) === null || _a === void 0 ? void 0 : _a.style;
|
|
40
|
+
BaseComponent = component;
|
|
41
|
+
}
|
|
42
|
+
const insets = useSafeAreaInsets();
|
|
43
|
+
let style = { ...twrnc `${classNames}` };
|
|
44
|
+
interpolations.forEach(interpolation => {
|
|
45
|
+
const interpolatedStyle = interpolation(props);
|
|
46
|
+
if (interpolatedStyle) {
|
|
47
|
+
style = { ...style, ...interpolatedStyle };
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
for (const className of safeArea) {
|
|
51
|
+
const [prop, edge] = SAFE_AREA_UTILITIES[className];
|
|
52
|
+
style[prop] = insets[edge];
|
|
53
|
+
}
|
|
54
|
+
return (<BaseComponent {...props} ref={ref} style={[baseStyle, style, props.style]}>
|
|
55
|
+
{children}
|
|
56
|
+
</BaseComponent>);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
export function attachComponentFactories(twrnc) {
|
|
60
|
+
const factories = {};
|
|
61
|
+
for (const [name, Component] of Object.entries(baseComponents)) {
|
|
62
|
+
factories[name] = (styles, ...interpolations) => createTailwindComponent(twrnc, Component, styles, ...interpolations);
|
|
63
|
+
}
|
|
64
|
+
return Object.assign(twrnc, factories);
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=components.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components.js","sourceRoot":"","sources":["../src/components.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,cAAc,CAAC;AAC9B,OAAO,EAAE,iBAAiB,EAA+B,MAAM,OAAO,CAAC;AACvE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAQjE,MAAM,cAAc,GAAG;IACrB,iBAAiB,EAAE,EAAE,CAAC,iBAAiB;IACvC,gBAAgB,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ;IACtC,aAAa,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK;IAChC,kBAAkB,EAAE,EAAE,CAAC,QAAQ,CAAC,UAAU;IAC1C,mBAAmB,EAAE,EAAE,CAAC,QAAQ,CAAC,WAAW;IAC5C,YAAY,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI;IAC9B,YAAY,EA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.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAEpE,wBAAgB,gBAAgB,CAAC,MAAM,CAAC,EAAE,gBAAgB,GAAG,kBAAkB,CAM9E"}
|
package/dist/create.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { create as createTwrnc } from 'twrnc';
|
|
2
|
+
import { attachComponentFactories } from './components';
|
|
3
|
+
import { createColorScheme } from './color-scheme';
|
|
4
|
+
export function createStyledwind(config) {
|
|
5
|
+
const twrnc = createTwrnc(config);
|
|
6
|
+
const tw = attachComponentFactories(twrnc);
|
|
7
|
+
const { Provider, useColorScheme } = createColorScheme(twrnc);
|
|
8
|
+
return { tw, Provider, useColorScheme };
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=create.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,WAAW,EAAE,MAAM,OAAO,CAAC;AAC9C,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAGnD,MAAM,UAAU,gBAAgB,CAAC,MAAyB;IACxD,MAAM,KAAK,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;IAClC,MAAM,EAAE,GAAG,wBAAwB,CAAC,KAAK,CAAC,CAAC;IAC3C,MAAM,EAAE,QAAQ,EAAE,cAAc,EAAE,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC;IAE9D,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,cAAc,EAAE,CAAC;AAC1C,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,54 +1,9 @@
|
|
|
1
|
-
import React
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
colorScheme: 'light' | 'dark';
|
|
7
|
-
internalColorScheme: ColorSchemeType;
|
|
8
|
-
toggleColorScheme: () => void;
|
|
9
|
-
setColorScheme: (scheme: ColorSchemeType) => void;
|
|
10
|
-
}
|
|
11
|
-
interface AsyncStorage {
|
|
12
|
-
clear(): Promise<void>;
|
|
13
|
-
getItem(key: string): Promise<string | null>;
|
|
14
|
-
removeItem(key: string): Promise<void>;
|
|
15
|
-
setItem(key: string, value: string): Promise<void>;
|
|
16
|
-
}
|
|
17
|
-
interface ProviderProps {
|
|
18
|
-
children: React.ReactNode;
|
|
19
|
-
initialColorScheme?: 'light' | 'dark' | 'device';
|
|
20
|
-
storage?: AsyncStorage;
|
|
21
|
-
}
|
|
22
|
-
interface ImageProps extends RN.ImageProps {
|
|
23
|
-
tintColor?: string;
|
|
24
|
-
}
|
|
25
|
-
type TailwindComponents = TailwindFn & {
|
|
26
|
-
ActivityIndicator: <T = object>(styles: TemplateStringsArray, ...interpolations: ((props: T) => false | Style | undefined)[]) => React.FC<RN.ActivityIndicatorProps & T>;
|
|
27
|
-
AnimatedFlatList: <T = object>(styles: TemplateStringsArray, ...interpolations: ((props: T) => false | Style | undefined)[]) => React.FC<RN.Animated.AnimatedProps<RN.FlatListProps<any>> & T>;
|
|
28
|
-
AnimatedImage: <T = object>(styles: TemplateStringsArray, ...interpolations: ((props: T) => false | Style | undefined)[]) => React.FC<RN.Animated.AnimatedProps<ImageProps> & T>;
|
|
29
|
-
AnimatedScrollView: <T = object>(styles: TemplateStringsArray, ...interpolations: ((props: T) => false | Style | undefined)[]) => React.FC<RN.Animated.AnimatedProps<RN.ScrollViewProps> & T>;
|
|
30
|
-
AnimatedSectionList: <T = object>(styles: TemplateStringsArray, ...interpolations: ((props: T) => false | Style | undefined)[]) => React.FC<RN.Animated.AnimatedProps<RN.SectionListProps<any>> & T>;
|
|
31
|
-
AnimatedText: <T = object>(styles: TemplateStringsArray, ...interpolations: ((props: T) => false | Style | undefined)[]) => React.FC<RN.Animated.AnimatedProps<RN.TextProps> & T>;
|
|
32
|
-
AnimatedView: <T = object>(styles: TemplateStringsArray, ...interpolations: ((props: T) => false | Style | undefined)[]) => React.FC<RN.Animated.AnimatedProps<RN.ViewProps> & T>;
|
|
33
|
-
Button: <T = object>(styles: TemplateStringsArray, ...interpolations: ((props: T) => false | Style | undefined)[]) => React.FC<RN.ButtonProps & T>;
|
|
34
|
-
FlatList: <T = object>(styles: TemplateStringsArray, ...interpolations: ((props: T) => false | Style | undefined)[]) => React.FC<RN.FlatListProps<any> & T>;
|
|
35
|
-
Image: <T = object>(styles: TemplateStringsArray, ...interpolations: ((props: T) => false | Style | undefined)[]) => React.FC<ImageProps & T>;
|
|
36
|
-
Modal: <T = object>(styles: TemplateStringsArray, ...interpolations: ((props: T) => false | Style | undefined)[]) => React.FC<RN.ModalProps & T>;
|
|
37
|
-
SafeAreaView: <T = object>(styles: TemplateStringsArray, ...interpolations: ((props: T) => false | Style | undefined)[]) => React.FC<RN.ViewProps & T>;
|
|
38
|
-
ScrollView: <T = object>(styles: TemplateStringsArray, ...interpolations: ((props: T) => false | Style | undefined)[]) => React.FC<RN.ScrollViewProps & T>;
|
|
39
|
-
SectionList: <T = object>(styles: TemplateStringsArray, ...interpolations: ((props: T) => false | Style | undefined)[]) => React.FC<RN.SectionListProps<any> & T>;
|
|
40
|
-
StatusBar: <T = object>(styles: TemplateStringsArray, ...interpolations: ((props: T) => false | Style | undefined)[]) => React.FC<RN.StatusBarProps & T>;
|
|
41
|
-
Switch: <T = object>(styles: TemplateStringsArray, ...interpolations: ((props: T) => false | Style | undefined)[]) => React.FC<RN.SwitchProps & T>;
|
|
42
|
-
Text: <T = object>(styles: TemplateStringsArray, ...interpolations: ((props: T) => false | Style | undefined)[]) => React.FC<RN.TextProps & T>;
|
|
43
|
-
TextInput: <T = object>(styles: TemplateStringsArray, ...interpolations: ((props: T) => false | Style | undefined)[]) => React.FC<RN.TextInputProps & T>;
|
|
44
|
-
TouchableHighlight: <T = object>(styles: TemplateStringsArray, ...interpolations: ((props: T) => false | Style | undefined)[]) => React.FC<RN.TouchableHighlightProps & T>;
|
|
45
|
-
TouchableNativeFeedback: <T = object>(styles: TemplateStringsArray, ...interpolations: ((props: T) => false | Style | undefined)[]) => React.FC<RN.TouchableNativeFeedbackProps & T>;
|
|
46
|
-
TouchableOpacity: <T = object>(styles: TemplateStringsArray, ...interpolations: ((props: T) => false | Style | undefined)[]) => React.FC<RN.TouchableOpacityProps & T>;
|
|
47
|
-
View: <T = object>(styles: TemplateStringsArray, ...interpolations: ((props: T) => false | Style | undefined)[]) => React.FC<RN.ViewProps & T>;
|
|
48
|
-
};
|
|
49
|
-
export declare function Provider({ children, initialColorScheme, storage, }: ProviderProps): React.JSX.Element;
|
|
50
|
-
declare const tw: TailwindComponents;
|
|
51
|
-
export declare function useColorScheme(): ColorSchemeContextValue;
|
|
1
|
+
export declare const Provider: (props: import("./types").ProviderProps) => React.JSX.Element;
|
|
2
|
+
export declare const useColorScheme: () => import("./types").ColorSchemeContextValue;
|
|
3
|
+
export { createStyledwind } from './create';
|
|
4
|
+
export { SAFE_AREA_CLASSES, type SafeAreaClass } from './safe-area';
|
|
5
|
+
export type { ColorScheme, ColorSchemeContextValue, ColorSchemePreference, ColorSchemeStorage, ColorSchemeType, ComponentPropsMap, Interpolation, ProviderProps, StyledFactory, StyledwindConfig, StyledwindInstance, TailwindComponents, } from './types';
|
|
52
6
|
export * from 'twrnc';
|
|
53
|
-
|
|
7
|
+
declare const _default: import("./types").TailwindComponents;
|
|
8
|
+
export default _default;
|
|
54
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAqBA,eAAO,MAAM,QAAQ,8CAsB+gF,MAAO,GAAG,CAAC,OAAO,AAtBtgF,CAAC;AACjD,eAAO,MAAM,cAAc,iDAAiC,CAAC;AAE7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AACpE,YAAY,EACV,WAAW,EACX,uBAAuB,EACvB,qBAAqB,EACrB,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,SAAS,CAAC;AAEjB,cAAc,OAAO,CAAC;;AACtB,wBAAkC"}
|
package/dist/index.js
CHANGED
|
@@ -1,190 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
'AnimatedText',
|
|
19
|
-
'AnimatedView',
|
|
20
|
-
'Button',
|
|
21
|
-
'FlatList',
|
|
22
|
-
'Image',
|
|
23
|
-
'Modal',
|
|
24
|
-
'SafeAreaView',
|
|
25
|
-
'ScrollView',
|
|
26
|
-
'SectionList',
|
|
27
|
-
'StatusBar',
|
|
28
|
-
'Switch',
|
|
29
|
-
'Text',
|
|
30
|
-
'TextInput',
|
|
31
|
-
'TouchableHighlight',
|
|
32
|
-
'TouchableNativeFeedback',
|
|
33
|
-
'TouchableOpacity',
|
|
34
|
-
'View',
|
|
35
|
-
];
|
|
36
|
-
function createTailwindComponent(Component, styles, ...interpolations) {
|
|
37
|
-
const classNames = styles
|
|
38
|
-
.filter(style => !['', ','].includes(style.trim()))
|
|
39
|
-
.join();
|
|
40
|
-
return React.forwardRef(function TailwindComponent({ children, component, ...props }, ref) {
|
|
41
|
-
var _a;
|
|
42
|
-
const [__colorScheme] = useAppColorScheme(twrnc);
|
|
43
|
-
let BaseComponent = Component;
|
|
44
|
-
let baseStyle = null;
|
|
45
|
-
if (typeof component === 'function') {
|
|
46
|
-
const CustomComponent = component;
|
|
47
|
-
baseStyle = (_a = CustomComponent.defaultProps) === null || _a === void 0 ? void 0 : _a.style;
|
|
48
|
-
BaseComponent = CustomComponent;
|
|
49
|
-
}
|
|
50
|
-
const insets = useSafeAreaInsets();
|
|
51
|
-
let style = { ...twrnc `${classNames}` };
|
|
52
|
-
interpolations.forEach(interpolation => {
|
|
53
|
-
const interpolatedStyle = interpolation(props);
|
|
54
|
-
if (interpolatedStyle) {
|
|
55
|
-
style = { ...style, ...interpolatedStyle };
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
if (classNames.includes('safe:pt'))
|
|
59
|
-
style.paddingTop = insets.top;
|
|
60
|
-
if (classNames.includes('safe:pb'))
|
|
61
|
-
style.paddingBottom = insets.bottom;
|
|
62
|
-
if (classNames.includes('safe:pl'))
|
|
63
|
-
style.paddingLeft = insets.left;
|
|
64
|
-
if (classNames.includes('safe:pr'))
|
|
65
|
-
style.paddingRight = insets.right;
|
|
66
|
-
if (classNames.includes('safe:mt'))
|
|
67
|
-
style.marginTop = insets.top;
|
|
68
|
-
if (classNames.includes('safe:mb'))
|
|
69
|
-
style.marginBottom = insets.bottom;
|
|
70
|
-
if (classNames.includes('safe:ml'))
|
|
71
|
-
style.marginLeft = insets.left;
|
|
72
|
-
if (classNames.includes('safe:mr'))
|
|
73
|
-
style.marginRight = insets.right;
|
|
74
|
-
if (classNames.includes('safe:top'))
|
|
75
|
-
style.top = insets.top;
|
|
76
|
-
if (classNames.includes('safe:bottom'))
|
|
77
|
-
style.bottom = insets.bottom;
|
|
78
|
-
if (classNames.includes('safe:left'))
|
|
79
|
-
style.left = insets.left;
|
|
80
|
-
if (classNames.includes('safe:right'))
|
|
81
|
-
style.right = insets.right;
|
|
82
|
-
if (classNames.includes('safe:h-top'))
|
|
83
|
-
style.height = insets.top;
|
|
84
|
-
if (classNames.includes('safe:h-bottom'))
|
|
85
|
-
style.height = insets.bottom;
|
|
86
|
-
if (classNames.includes('safe:w-left'))
|
|
87
|
-
style.width = insets.left;
|
|
88
|
-
if (classNames.includes('safe:w-right'))
|
|
89
|
-
style.width = insets.right;
|
|
90
|
-
return (<BaseComponent {...props} ref={ref} style={[baseStyle, style, props.style]}>
|
|
91
|
-
{children}
|
|
92
|
-
</BaseComponent>);
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
function generateTailwindStyledComponents() {
|
|
96
|
-
return allowedComponents.reduce((acc, componentName) => {
|
|
97
|
-
const animatedComponentName = componentName.startsWith('Animated')
|
|
98
|
-
? componentName.split('Animated')[1]
|
|
99
|
-
: null;
|
|
100
|
-
const Component = animatedComponentName
|
|
101
|
-
? RN.Animated[animatedComponentName]
|
|
102
|
-
: RN[componentName];
|
|
103
|
-
acc[componentName] = (styles, ...interpolations) => createTailwindComponent(Component, styles, ...interpolations);
|
|
104
|
-
return acc;
|
|
105
|
-
}, twrnc);
|
|
106
|
-
}
|
|
107
|
-
export function Provider({ children, initialColorScheme = 'device', storage, }) {
|
|
108
|
-
const [userColorScheme, setUserColorScheme] = React.useState(initialColorScheme);
|
|
109
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
110
|
-
const [twrnColorScheme, twrnToggleColorScheme, twrnSetColorScheme] = useAppColorScheme(twrnc);
|
|
111
|
-
const deviceColorScheme = useDeviceColorScheme();
|
|
112
|
-
useDeviceContext(twrnc, userColorScheme === 'device'
|
|
113
|
-
? undefined
|
|
114
|
-
: {
|
|
115
|
-
observeDeviceColorSchemeChanges: false,
|
|
116
|
-
initialColorScheme: userColorScheme,
|
|
117
|
-
});
|
|
118
|
-
useEffect(() => {
|
|
119
|
-
if (userColorScheme === 'device' && deviceColorScheme) {
|
|
120
|
-
if (twrnColorScheme !== deviceColorScheme) {
|
|
121
|
-
twrnSetColorScheme(deviceColorScheme);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}, [deviceColorScheme, userColorScheme, twrnColorScheme, twrnSetColorScheme]);
|
|
125
|
-
useEffect(() => {
|
|
126
|
-
if (storage) {
|
|
127
|
-
storage.getItem('tw:color-scheme').then(value => {
|
|
128
|
-
if (value &&
|
|
129
|
-
(value === 'light' || value === 'dark' || value === 'device')) {
|
|
130
|
-
setUserColorScheme(value);
|
|
131
|
-
if (value !== 'device') {
|
|
132
|
-
twrnSetColorScheme(value);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
}, []);
|
|
138
|
-
useEffect(() => {
|
|
139
|
-
if (storage) {
|
|
140
|
-
if (userColorScheme === 'device') {
|
|
141
|
-
storage.removeItem('tw:color-scheme');
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
storage.setItem('tw:color-scheme', userColorScheme);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}, [userColorScheme, storage]);
|
|
148
|
-
const toggleColorScheme = () => {
|
|
149
|
-
if (userColorScheme === 'device') {
|
|
150
|
-
const newScheme = twrnColorScheme === 'dark' ? 'light' : 'dark';
|
|
151
|
-
setUserColorScheme(newScheme);
|
|
152
|
-
twrnSetColorScheme(newScheme);
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
155
|
-
const newScheme = userColorScheme === 'dark' ? 'light' : 'dark';
|
|
156
|
-
setUserColorScheme(newScheme);
|
|
157
|
-
twrnSetColorScheme(newScheme);
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
const setColorScheme = (scheme) => {
|
|
161
|
-
setUserColorScheme(scheme);
|
|
162
|
-
if (scheme !== 'device') {
|
|
163
|
-
twrnSetColorScheme(scheme);
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
|
-
return (<ColorSchemeContext.Provider value={{
|
|
167
|
-
colorScheme: twrnColorScheme || 'light',
|
|
168
|
-
internalColorScheme: userColorScheme,
|
|
169
|
-
toggleColorScheme,
|
|
170
|
-
setColorScheme,
|
|
171
|
-
}}>
|
|
172
|
-
{children}
|
|
173
|
-
</ColorSchemeContext.Provider>);
|
|
174
|
-
}
|
|
175
|
-
const tw = generateTailwindStyledComponents();
|
|
176
|
-
export function useColorScheme() {
|
|
177
|
-
const ctx = useContext(ColorSchemeContext);
|
|
178
|
-
const [twrnColorScheme, twrnToggleColorScheme, twrnSetColorScheme] = useAppColorScheme(twrnc);
|
|
179
|
-
if (ctx)
|
|
180
|
-
return ctx;
|
|
181
|
-
return {
|
|
182
|
-
colorScheme: twrnColorScheme || 'light',
|
|
183
|
-
internalColorScheme: 'device',
|
|
184
|
-
toggleColorScheme: twrnToggleColorScheme,
|
|
185
|
-
setColorScheme: twrnSetColorScheme,
|
|
186
|
-
};
|
|
1
|
+
import { createStyledwind } from './create';
|
|
2
|
+
/**
|
|
3
|
+
* Legacy config discovery for the default instance. Resolves relative to the
|
|
4
|
+
* built file, which only lands on `<app>/tailwind.config.*` when the package is
|
|
5
|
+
* hoisted flat into the app's node_modules. Prefer `createStyledwind(config)`.
|
|
6
|
+
*
|
|
7
|
+
* @deprecated
|
|
8
|
+
*/
|
|
9
|
+
function loadAppConfig() {
|
|
10
|
+
var _a;
|
|
11
|
+
try {
|
|
12
|
+
const mod = require('../../../tailwind.config'); // eslint-disable-line @typescript-eslint/no-require-imports
|
|
13
|
+
return (_a = mod === null || mod === void 0 ? void 0 : mod.default) !== null && _a !== void 0 ? _a : mod;
|
|
14
|
+
}
|
|
15
|
+
catch (_b) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
187
18
|
}
|
|
19
|
+
const defaultInstance = createStyledwind(loadAppConfig());
|
|
20
|
+
export const Provider = defaultInstance.Provider;
|
|
21
|
+
export const useColorScheme = defaultInstance.useColorScheme;
|
|
22
|
+
export { createStyledwind } from './create';
|
|
23
|
+
export { SAFE_AREA_CLASSES } from './safe-area';
|
|
188
24
|
export * from 'twrnc';
|
|
189
|
-
export default tw;
|
|
25
|
+
export default defaultInstance.tw;
|
|
190
26
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAG5C;;;;;;GAMG;AACH,SAAS,aAAa;;IACpB,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAC,CAAC,4DAA4D;QAC7G,OAAO,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,OAAO,mCAAI,GAAG,CAAC;IAC7B,CAAC;IAAC,WAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,MAAM,eAAe,GAAG,gBAAgB,CAAC,aAAa,EAAE,CAAC,CAAC;AAE1D,MAAM,CAAC,MAAM,QAAQ,GAAG,eAAe,CAAC,QAAQ,CAAC;AACjD,MAAM,CAAC,MAAM,cAAc,GAAG,eAAe,CAAC,cAAc,CAAC;AAE7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAsB,MAAM,aAAa,CAAC;AAgBpE,cAAc,OAAO,CAAC;AACtB,eAAe,eAAe,CAAC,EAAE,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare const SAFE_AREA_UTILITIES: {
|
|
2
|
+
readonly 'safe:pt': readonly ["paddingTop", "top"];
|
|
3
|
+
readonly 'safe:pb': readonly ["paddingBottom", "bottom"];
|
|
4
|
+
readonly 'safe:pl': readonly ["paddingLeft", "left"];
|
|
5
|
+
readonly 'safe:pr': readonly ["paddingRight", "right"];
|
|
6
|
+
readonly 'safe:mt': readonly ["marginTop", "top"];
|
|
7
|
+
readonly 'safe:mb': readonly ["marginBottom", "bottom"];
|
|
8
|
+
readonly 'safe:ml': readonly ["marginLeft", "left"];
|
|
9
|
+
readonly 'safe:mr': readonly ["marginRight", "right"];
|
|
10
|
+
readonly 'safe:top': readonly ["top", "top"];
|
|
11
|
+
readonly 'safe:bottom': readonly ["bottom", "bottom"];
|
|
12
|
+
readonly 'safe:left': readonly ["left", "left"];
|
|
13
|
+
readonly 'safe:right': readonly ["right", "right"];
|
|
14
|
+
readonly 'safe:h-top': readonly ["height", "top"];
|
|
15
|
+
readonly 'safe:h-bottom': readonly ["height", "bottom"];
|
|
16
|
+
readonly 'safe:w-left': readonly ["width", "left"];
|
|
17
|
+
readonly 'safe:w-right': readonly ["width", "right"];
|
|
18
|
+
};
|
|
19
|
+
export type SafeAreaClass = keyof typeof SAFE_AREA_UTILITIES;
|
|
20
|
+
export declare const SAFE_AREA_CLASSES: readonly SafeAreaClass[];
|
|
21
|
+
export declare function parseTemplate(styles: TemplateStringsArray): {
|
|
22
|
+
classNames: string;
|
|
23
|
+
safeArea: ("safe:pt" | "safe:pb" | "safe:pl" | "safe:pr" | "safe:mt" | "safe:mb" | "safe:ml" | "safe:mr" | "safe:top" | "safe:bottom" | "safe:left" | "safe:right" | "safe:h-top" | "safe:h-bottom" | "safe:w-left" | "safe:w-right")[];
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=safe-area.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safe-area.d.ts","sourceRoot":"","sources":["../src/safe-area.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;CAiBwC,CAAC;AAEzE,MAAM,MAAM,aAAa,GAAG,MAAM,OAAO,mBAAmB,CAAC;AAE7D,eAAO,MAAM,iBAAiB,EAEzB,SAAS,aAAa,EAAE,CAAC;AAI9B,wBAAgB,aAAa,CAAC,MAAM,EAAE,oBAAoB;;;EAQzD"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export const SAFE_AREA_UTILITIES = {
|
|
2
|
+
'safe:pt': ['paddingTop', 'top'],
|
|
3
|
+
'safe:pb': ['paddingBottom', 'bottom'],
|
|
4
|
+
'safe:pl': ['paddingLeft', 'left'],
|
|
5
|
+
'safe:pr': ['paddingRight', 'right'],
|
|
6
|
+
'safe:mt': ['marginTop', 'top'],
|
|
7
|
+
'safe:mb': ['marginBottom', 'bottom'],
|
|
8
|
+
'safe:ml': ['marginLeft', 'left'],
|
|
9
|
+
'safe:mr': ['marginRight', 'right'],
|
|
10
|
+
'safe:top': ['top', 'top'],
|
|
11
|
+
'safe:bottom': ['bottom', 'bottom'],
|
|
12
|
+
'safe:left': ['left', 'left'],
|
|
13
|
+
'safe:right': ['right', 'right'],
|
|
14
|
+
'safe:h-top': ['height', 'top'],
|
|
15
|
+
'safe:h-bottom': ['height', 'bottom'],
|
|
16
|
+
'safe:w-left': ['width', 'left'],
|
|
17
|
+
'safe:w-right': ['width', 'right'],
|
|
18
|
+
};
|
|
19
|
+
export const SAFE_AREA_CLASSES = Object.keys(SAFE_AREA_UTILITIES);
|
|
20
|
+
const SAFE_AREA_CLASS_SET = new Set(SAFE_AREA_CLASSES);
|
|
21
|
+
export function parseTemplate(styles) {
|
|
22
|
+
const tokens = new Set(styles.join(' ').split(/\s+/).filter(Boolean));
|
|
23
|
+
const safeArea = SAFE_AREA_CLASSES.filter(className => tokens.has(className));
|
|
24
|
+
const classNames = [...tokens]
|
|
25
|
+
.filter(token => !SAFE_AREA_CLASS_SET.has(token))
|
|
26
|
+
.join(' ');
|
|
27
|
+
return { classNames, safeArea };
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=safe-area.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safe-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AM,QAAQ,GAAG,iBAAiB,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC;IAC9E,MAAM,UAAU,GAAG,CAAC,GAAG,MAAM,CAAC;SAC3B,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,mBAAmB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;SAChD,IAAI,CAAC,GAAG,CAAC,CAAC;IAEb,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC;AAClC,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type RN from 'react-native';
|
|
3
|
+
import type { TailwindFn, TwConfig, Style } from 'twrnc';
|
|
4
|
+
export type ColorScheme = 'light' | 'dark';
|
|
5
|
+
export type ColorSchemePreference = ColorScheme | 'device';
|
|
6
|
+
/** @deprecated Use `ColorSchemePreference`. */
|
|
7
|
+
export type ColorSchemeType = ColorSchemePreference;
|
|
8
|
+
export interface ColorSchemeContextValue {
|
|
9
|
+
colorScheme: ColorScheme;
|
|
10
|
+
internalColorScheme: ColorSchemePreference;
|
|
11
|
+
toggleColorScheme: () => void;
|
|
12
|
+
setColorScheme: (scheme: ColorSchemePreference) => void;
|
|
13
|
+
}
|
|
14
|
+
export interface ColorSchemeStorage {
|
|
15
|
+
getItem(key: string): Promise<string | null>;
|
|
16
|
+
removeItem(key: string): Promise<void>;
|
|
17
|
+
setItem(key: string, value: string): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
export interface ProviderProps {
|
|
20
|
+
children: React.ReactNode;
|
|
21
|
+
initialColorScheme?: ColorSchemePreference;
|
|
22
|
+
storage?: ColorSchemeStorage;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A twrnc config, optionally extended with Tailwind presets. Presets are merged
|
|
26
|
+
* by Tailwind's own `resolveConfig`, which twrnc runs internally, so
|
|
27
|
+
* `presets: [require('styledwind-native/tailwind')]` works at runtime too.
|
|
28
|
+
*/
|
|
29
|
+
export interface StyledwindConfig extends TwConfig {
|
|
30
|
+
presets?: StyledwindConfig[];
|
|
31
|
+
}
|
|
32
|
+
export interface ImageProps extends RN.ImageProps {
|
|
33
|
+
tintColor?: string;
|
|
34
|
+
}
|
|
35
|
+
/** Base props for every component created by `tw.X`. */
|
|
36
|
+
export type ComponentPropsMap = {
|
|
37
|
+
ActivityIndicator: RN.ActivityIndicatorProps;
|
|
38
|
+
AnimatedFlatList: RN.Animated.AnimatedProps<RN.FlatListProps<any>>;
|
|
39
|
+
AnimatedImage: RN.Animated.AnimatedProps<ImageProps>;
|
|
40
|
+
AnimatedScrollView: RN.Animated.AnimatedProps<RN.ScrollViewProps>;
|
|
41
|
+
AnimatedSectionList: RN.Animated.AnimatedProps<RN.SectionListProps<any>>;
|
|
42
|
+
AnimatedText: RN.Animated.AnimatedProps<RN.TextProps>;
|
|
43
|
+
AnimatedView: RN.Animated.AnimatedProps<RN.ViewProps>;
|
|
44
|
+
Button: RN.ButtonProps;
|
|
45
|
+
FlatList: RN.FlatListProps<any>;
|
|
46
|
+
Image: ImageProps;
|
|
47
|
+
Modal: RN.ModalProps;
|
|
48
|
+
/**
|
|
49
|
+
* @deprecated React Native deprecated `SafeAreaView` in 0.81 and will remove
|
|
50
|
+
* it. Use the `safe:*` utilities on `tw.View` (for example
|
|
51
|
+
* `tw.View\`safe:pt safe:pb\``) or `SafeAreaView` from
|
|
52
|
+
* `react-native-safe-area-context` via the `component` prop instead.
|
|
53
|
+
*/
|
|
54
|
+
SafeAreaView: RN.ViewProps;
|
|
55
|
+
ScrollView: RN.ScrollViewProps;
|
|
56
|
+
SectionList: RN.SectionListProps<any>;
|
|
57
|
+
StatusBar: RN.StatusBarProps;
|
|
58
|
+
Switch: RN.SwitchProps;
|
|
59
|
+
Text: RN.TextProps;
|
|
60
|
+
TextInput: RN.TextInputProps;
|
|
61
|
+
TouchableHighlight: RN.TouchableHighlightProps;
|
|
62
|
+
TouchableNativeFeedback: RN.TouchableNativeFeedbackProps;
|
|
63
|
+
TouchableOpacity: RN.TouchableOpacityProps;
|
|
64
|
+
View: RN.ViewProps;
|
|
65
|
+
};
|
|
66
|
+
export type Interpolation<T> = (props: T) => false | Style | undefined;
|
|
67
|
+
export type StyledFactory<P> = <T = object>(styles: TemplateStringsArray, ...interpolations: Interpolation<T>[]) => React.FC<P & T>;
|
|
68
|
+
export type TailwindComponents = TailwindFn & {
|
|
69
|
+
[K in keyof ComponentPropsMap]: StyledFactory<ComponentPropsMap[K]>;
|
|
70
|
+
};
|
|
71
|
+
/** Everything `createStyledwind` returns, bound to one twrnc instance. */
|
|
72
|
+
export interface StyledwindInstance {
|
|
73
|
+
tw: TailwindComponents;
|
|
74
|
+
Provider: (props: ProviderProps) => React.JSX.Element;
|
|
75
|
+
useColorScheme: () => ColorSchemeContextValue;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAMzD,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,MAAM,CAAC;AAC3C,MAAM,MAAM,qBAAqB,GAAG,WAAW,GAAG,QAAQ,CAAC;AAC3D,+CAA+C;AAC/C,MAAM,MAAM,eAAe,GAAG,qBAAqB,CAAC;AAEpD,MAAM,WAAW,uBAAuB;IACtC,WAAW,EAAE,WAAW,CAAC;IACzB,mBAAmB,EAAE,qBAAqB,CAAC;IAC3C,iBAAiB,EAAE,MAAM,IAAI,CAAC;IAC9B,cAAc,EAAE,CAAC,MAAM,EAAE,qBAA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;CACpE,CAAC;AAEF,0EAA0E;AAC1E,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,kBAAkB,CAAC;IACvB,QAAQ,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC;IACtD,cAAc,EAAE,MAAM,uBAAuB,CAAC;CAC/C"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,9 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "styledwind-native",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "A lightweight utility for applying dynamic Tailwind CSS styles in React Native",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./tailwind": {
|
|
13
|
+
"types": "./tailwind.d.cts",
|
|
14
|
+
"default": "./tailwind.cjs"
|
|
15
|
+
},
|
|
16
|
+
"./package.json": "./package.json"
|
|
17
|
+
},
|
|
18
|
+
"typesVersions": {
|
|
19
|
+
"*": {
|
|
20
|
+
"tailwind": [
|
|
21
|
+
"./tailwind.d.cts"
|
|
22
|
+
]
|
|
23
|
+
}
|
|
24
|
+
},
|
|
7
25
|
"type": "module",
|
|
8
26
|
"repository": {
|
|
9
27
|
"type": "git",
|
|
@@ -49,6 +67,7 @@
|
|
|
49
67
|
"metro-react-native-babel-preset": "^0.77.0",
|
|
50
68
|
"react-test-renderer": "^18.3.1",
|
|
51
69
|
"rimraf": "^6.0.1",
|
|
70
|
+
"tailwindcss": "^3.4.13",
|
|
52
71
|
"ts-jest": "^29.2.5",
|
|
53
72
|
"typescript": "^5.6.2"
|
|
54
73
|
}
|
package/tailwind.cjs
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Tailwind preset for styledwind-native.
|
|
5
|
+
*
|
|
6
|
+
* Teaches editor tooling (Tailwind CSS IntelliSense in VS Code, Zed, and any
|
|
7
|
+
* other tailwindcss-language-server client) about the class names that twrnc
|
|
8
|
+
* and styledwind-native add on top of Tailwind:
|
|
9
|
+
*
|
|
10
|
+
* - device prefixes evaluated by twrnc at runtime:
|
|
11
|
+
* ios: android: web: windows: macos: portrait: landscape: retina:
|
|
12
|
+
* - safe-area utilities evaluated by styledwind-native at runtime:
|
|
13
|
+
* safe:pt safe:pb safe:pl safe:pr safe:mt safe:mb safe:ml safe:mr
|
|
14
|
+
* safe:top safe:bottom safe:left safe:right
|
|
15
|
+
* safe:h-top safe:h-bottom safe:w-left safe:w-right
|
|
16
|
+
*
|
|
17
|
+
* Usage, in the app's tailwind.config.{js,cjs,ts}:
|
|
18
|
+
*
|
|
19
|
+
* module.exports = {
|
|
20
|
+
* presets: [require('styledwind-native/tailwind')],
|
|
21
|
+
* // ...your theme
|
|
22
|
+
* };
|
|
23
|
+
*
|
|
24
|
+
* The preset is also safe in the config twrnc receives at runtime. twrnc runs
|
|
25
|
+
* config plugins with a reduced API (no `addVariant`), so under twrnc the plugin
|
|
26
|
+
* only registers the safe-area classes as no-op utilities and leaves prefix
|
|
27
|
+
* handling to twrnc itself.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
const DEVICE_VARIANTS = [
|
|
31
|
+
'ios',
|
|
32
|
+
'android',
|
|
33
|
+
'web',
|
|
34
|
+
'windows',
|
|
35
|
+
'macos',
|
|
36
|
+
'portrait',
|
|
37
|
+
'landscape',
|
|
38
|
+
'retina',
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
/** Bare utility name -> CSS shown in editor previews. Order matters: it mirrors src/index.tsx. */
|
|
42
|
+
const SAFE_AREA_UTILITIES = {
|
|
43
|
+
pt: { paddingTop: 'env(safe-area-inset-top)' },
|
|
44
|
+
pb: { paddingBottom: 'env(safe-area-inset-bottom)' },
|
|
45
|
+
pl: { paddingLeft: 'env(safe-area-inset-left)' },
|
|
46
|
+
pr: { paddingRight: 'env(safe-area-inset-right)' },
|
|
47
|
+
mt: { marginTop: 'env(safe-area-inset-top)' },
|
|
48
|
+
mb: { marginBottom: 'env(safe-area-inset-bottom)' },
|
|
49
|
+
ml: { marginLeft: 'env(safe-area-inset-left)' },
|
|
50
|
+
mr: { marginRight: 'env(safe-area-inset-right)' },
|
|
51
|
+
top: { top: 'env(safe-area-inset-top)' },
|
|
52
|
+
bottom: { bottom: 'env(safe-area-inset-bottom)' },
|
|
53
|
+
left: { left: 'env(safe-area-inset-left)' },
|
|
54
|
+
right: { right: 'env(safe-area-inset-right)' },
|
|
55
|
+
'h-top': { height: 'env(safe-area-inset-top)' },
|
|
56
|
+
'h-bottom': { height: 'env(safe-area-inset-bottom)' },
|
|
57
|
+
'w-left': { width: 'env(safe-area-inset-left)' },
|
|
58
|
+
'w-right': { width: 'env(safe-area-inset-right)' },
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const safeAreaClasses = Object.keys(SAFE_AREA_UTILITIES).map(
|
|
62
|
+
utility => `safe:${utility}`
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* twrnc calls plugin handlers with `postcss: null`; Tailwind passes the postcss
|
|
67
|
+
* module (v3) or nothing at all (v4). Only an explicit null means twrnc.
|
|
68
|
+
*/
|
|
69
|
+
function isTwrnc(api) {
|
|
70
|
+
return api.postcss === null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function handler(api) {
|
|
74
|
+
if (isTwrnc(api)) {
|
|
75
|
+
// Register the safe-area classes as empty utilities so twrnc never treats
|
|
76
|
+
// them as unknown. styledwind-native applies the real insets at render.
|
|
77
|
+
api.addUtilities(
|
|
78
|
+
Object.fromEntries(safeAreaClasses.map(className => [className, {}]))
|
|
79
|
+
);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
for (const variant of DEVICE_VARIANTS) {
|
|
84
|
+
api.addVariant(variant, '&');
|
|
85
|
+
}
|
|
86
|
+
api.addVariant('safe', '&');
|
|
87
|
+
|
|
88
|
+
api.addUtilities(
|
|
89
|
+
Object.fromEntries(
|
|
90
|
+
Object.entries(SAFE_AREA_UTILITIES).map(([utility, css]) => [
|
|
91
|
+
`.${utility}`,
|
|
92
|
+
css,
|
|
93
|
+
])
|
|
94
|
+
)
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const preset = {
|
|
99
|
+
plugins: [{ handler, config: undefined }],
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
// Exposed for tests and tooling without taking part in Tailwind's preset merge.
|
|
103
|
+
Object.defineProperty(preset, 'safeAreaClasses', {
|
|
104
|
+
value: Object.freeze(safeAreaClasses),
|
|
105
|
+
});
|
|
106
|
+
Object.defineProperty(preset, 'deviceVariants', {
|
|
107
|
+
value: Object.freeze(DEVICE_VARIANTS.slice()),
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
module.exports = preset;
|
package/tailwind.d.cts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Subset of the Tailwind / twrnc plugin API this preset touches. */
|
|
2
|
+
export interface StyledwindPluginApi {
|
|
3
|
+
addUtilities(utilities: Record<string, Record<string, string | number>>): void;
|
|
4
|
+
addVariant?(name: string, definition: string | string[]): void;
|
|
5
|
+
postcss?: unknown;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface StyledwindTailwindPreset {
|
|
9
|
+
plugins: Array<{ handler: (api: StyledwindPluginApi) => void; config?: undefined }>;
|
|
10
|
+
/** `safe:pt` … `safe:w-right`, in the order styledwind-native applies them. */
|
|
11
|
+
readonly safeAreaClasses: readonly string[];
|
|
12
|
+
/** Prefixes twrnc evaluates at runtime: `ios`, `android`, `portrait`, … */
|
|
13
|
+
readonly deviceVariants: readonly string[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare const preset: StyledwindTailwindPreset;
|
|
17
|
+
export = preset;
|