@colimuca123/nativewind 4.2.2-rc.1
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/LICENSE +21 -0
- package/README.OpenSource +11 -0
- package/babel.js +1 -0
- package/dist/doctor.d.ts +1 -0
- package/dist/doctor.js +21 -0
- package/dist/doctor.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/metro/common.d.ts +4 -0
- package/dist/metro/common.js +8 -0
- package/dist/metro/common.js.map +1 -0
- package/dist/metro/index.d.ts +15 -0
- package/dist/metro/index.js +47 -0
- package/dist/metro/index.js.map +1 -0
- package/dist/metro/picocolors.d.ts +26 -0
- package/dist/metro/picocolors.js +53 -0
- package/dist/metro/picocolors.js.map +1 -0
- package/dist/metro/tailwind/index.d.ts +5 -0
- package/dist/metro/tailwind/index.js +25 -0
- package/dist/metro/tailwind/index.js.map +1 -0
- package/dist/metro/tailwind/types.d.ts +8 -0
- package/dist/metro/tailwind/types.js +3 -0
- package/dist/metro/tailwind/types.js.map +1 -0
- package/dist/metro/tailwind/v3/child.d.ts +0 -0
- package/dist/metro/tailwind/v3/child.js +45 -0
- package/dist/metro/tailwind/v3/child.js.map +1 -0
- package/dist/metro/tailwind/v3/index.d.ts +6 -0
- package/dist/metro/tailwind/v3/index.js +81 -0
- package/dist/metro/tailwind/v3/index.js.map +1 -0
- package/dist/metro/typescript.d.ts +1 -0
- package/dist/metro/typescript.js +46 -0
- package/dist/metro/typescript.js.map +1 -0
- package/dist/stylesheet.d.ts +5 -0
- package/dist/stylesheet.js +25 -0
- package/dist/stylesheet.js.map +1 -0
- package/dist/tailwind/color.d.ts +4 -0
- package/dist/tailwind/color.js +25 -0
- package/dist/tailwind/color.js.map +1 -0
- package/dist/tailwind/common.d.ts +2 -0
- package/dist/tailwind/common.js +24 -0
- package/dist/tailwind/common.js.map +1 -0
- package/dist/tailwind/dark-mode.d.ts +4 -0
- package/dist/tailwind/dark-mode.js +48 -0
- package/dist/tailwind/dark-mode.js.map +1 -0
- package/dist/tailwind/index.d.ts +0 -0
- package/dist/tailwind/index.js +13 -0
- package/dist/tailwind/index.js.map +1 -0
- package/dist/tailwind/native.d.ts +3 -0
- package/dist/tailwind/native.js +265 -0
- package/dist/tailwind/native.js.map +1 -0
- package/dist/tailwind/prop-modifier.d.ts +4 -0
- package/dist/tailwind/prop-modifier.js +13 -0
- package/dist/tailwind/prop-modifier.js.map +1 -0
- package/dist/tailwind/safe-area.d.ts +4 -0
- package/dist/tailwind/safe-area.js +216 -0
- package/dist/tailwind/safe-area.js.map +1 -0
- package/dist/tailwind/shadows.d.ts +4 -0
- package/dist/tailwind/shadows.js +79 -0
- package/dist/tailwind/shadows.js.map +1 -0
- package/dist/tailwind/switch.d.ts +8 -0
- package/dist/tailwind/switch.js +51 -0
- package/dist/tailwind/switch.js.map +1 -0
- package/dist/tailwind/translate.d.ts +2 -0
- package/dist/tailwind/translate.js +40 -0
- package/dist/tailwind/translate.js.map +1 -0
- package/dist/tailwind/verify.d.ts +4 -0
- package/dist/tailwind/verify.js +22 -0
- package/dist/tailwind/verify.js.map +1 -0
- package/dist/tailwind/web.d.ts +3 -0
- package/dist/tailwind/web.js +40 -0
- package/dist/tailwind/web.js.map +1 -0
- package/dist/test.d.ts +373 -0
- package/dist/test.js +161 -0
- package/dist/test.js.map +1 -0
- package/dist/theme.d.ts +1 -0
- package/dist/theme.js +9 -0
- package/dist/theme.js.map +1 -0
- package/expo-snack.js +71 -0
- package/jsx-dev-runtime/index.d.ts +1 -0
- package/jsx-dev-runtime/index.js +1 -0
- package/jsx-runtime/index.d.ts +1 -0
- package/jsx-runtime/index.js +1 -0
- package/metro/package.json +1 -0
- package/package.json +75 -0
- package/preset/package.json +3 -0
- package/src/__tests__/README.md +3 -0
- package/src/__tests__/accessibility.tsx +41 -0
- package/src/__tests__/backgrounds.tsx +239 -0
- package/src/__tests__/borders.tsx +355 -0
- package/src/__tests__/container-queries.tsx +59 -0
- package/src/__tests__/custom-theme.tsx +45 -0
- package/src/__tests__/custom.tsx +17 -0
- package/src/__tests__/dark-mode.ios.tsx +251 -0
- package/src/__tests__/doctor.tsx +13 -0
- package/src/__tests__/effects.ios.tsx +230 -0
- package/src/__tests__/elevation.tsx +22 -0
- package/src/__tests__/filters.tsx +201 -0
- package/src/__tests__/flexbox-grid.tsx +670 -0
- package/src/__tests__/groups.tsx +134 -0
- package/src/__tests__/interactivity.tsx +547 -0
- package/src/__tests__/layout.tsx +854 -0
- package/src/__tests__/modifier-{}.tsx +71 -0
- package/src/__tests__/platform-modifiers-test.ios.tsx +34 -0
- package/src/__tests__/preset.tsx +9 -0
- package/src/__tests__/reusing-styles.tsx +44 -0
- package/src/__tests__/safe-area.test.ios.tsx +427 -0
- package/src/__tests__/sizing.tsx +241 -0
- package/src/__tests__/spacing.tsx +106 -0
- package/src/__tests__/states.tsx +145 -0
- package/src/__tests__/svg.tsx +25 -0
- package/src/__tests__/tables.tsx +103 -0
- package/src/__tests__/theme.tsx +245 -0
- package/src/__tests__/transforms.tsx +509 -0
- package/src/__tests__/transition-animations.tsx +254 -0
- package/src/__tests__/typography.tsx +657 -0
- package/src/__tests__/unofficial-plugins.test.ios.tsx +171 -0
- package/src/doctor.ts +28 -0
- package/src/index.tsx +16 -0
- package/src/metro/common.ts +11 -0
- package/src/metro/index.ts +77 -0
- package/src/metro/picocolors.ts +76 -0
- package/src/metro/tailwind/index.ts +22 -0
- package/src/metro/tailwind/types.ts +9 -0
- package/src/metro/tailwind/v3/child.ts +61 -0
- package/src/metro/tailwind/v3/index.ts +103 -0
- package/src/metro/typescript.ts +69 -0
- package/src/stylesheet.ts +31 -0
- package/src/tailwind/color.ts +23 -0
- package/src/tailwind/common.ts +26 -0
- package/src/tailwind/dark-mode.ts +46 -0
- package/src/tailwind/index.ts +15 -0
- package/src/tailwind/native.ts +374 -0
- package/src/tailwind/prop-modifier.ts +7 -0
- package/src/tailwind/safe-area.ts +262 -0
- package/src/tailwind/shadows.ts +100 -0
- package/src/tailwind/switch.ts +59 -0
- package/src/tailwind/translate.ts +51 -0
- package/src/tailwind/verify.ts +16 -0
- package/src/tailwind/web.ts +38 -0
- package/src/tailwindcss-internals.d.ts +7 -0
- package/src/test.tsx +224 -0
- package/src/theme.ts +15 -0
- package/test/package.json +4 -0
- package/theme/package.json +3 -0
- package/types.d.ts +1 -0
package/src/test.tsx
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/** @jsxImportSource nativewind */
|
|
2
|
+
import { Platform, View } from "react-native";
|
|
3
|
+
|
|
4
|
+
import tailwindcssContainerQueries from "@tailwindcss/container-queries";
|
|
5
|
+
import postcss from "postcss";
|
|
6
|
+
import {
|
|
7
|
+
getWarnings,
|
|
8
|
+
render as interopRender,
|
|
9
|
+
RenderOptions as InteropRenderOptions,
|
|
10
|
+
resetData,
|
|
11
|
+
screen,
|
|
12
|
+
setupAllComponents,
|
|
13
|
+
} from "react-native-css-interop/test";
|
|
14
|
+
import tailwind, { Config } from "tailwindcss";
|
|
15
|
+
|
|
16
|
+
import { cssToReactNativeRuntimeOptions } from "./metro/common";
|
|
17
|
+
|
|
18
|
+
export {
|
|
19
|
+
act,
|
|
20
|
+
createMockComponent,
|
|
21
|
+
screen,
|
|
22
|
+
fireEvent,
|
|
23
|
+
within,
|
|
24
|
+
native,
|
|
25
|
+
INTERNAL_SET,
|
|
26
|
+
} from "react-native-css-interop/test";
|
|
27
|
+
|
|
28
|
+
export * from "./index";
|
|
29
|
+
|
|
30
|
+
const testID = "nativewind";
|
|
31
|
+
|
|
32
|
+
beforeEach(() => {
|
|
33
|
+
resetData();
|
|
34
|
+
setupAllComponents();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// I don't know why I can't use Omit. It narrows the type too much?
|
|
38
|
+
export type ConfigWithoutContent = {
|
|
39
|
+
[K in keyof Config as K extends "content" ? never : K]: Config[K];
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export interface RenderOptions extends InteropRenderOptions {
|
|
43
|
+
config?: ConfigWithoutContent;
|
|
44
|
+
css?: string;
|
|
45
|
+
layers?: {
|
|
46
|
+
base?: boolean;
|
|
47
|
+
components?: boolean;
|
|
48
|
+
utilities?: boolean;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type RenderCurrentTestOptions = RenderOptions & {
|
|
53
|
+
className?: string;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
process.env.NATIVEWIND_OS = Platform.OS;
|
|
57
|
+
|
|
58
|
+
export async function renderCurrentTest({
|
|
59
|
+
className = expect.getState().currentTestName?.split(/\s+/).at(-1),
|
|
60
|
+
...options
|
|
61
|
+
}: RenderCurrentTestOptions = {}) {
|
|
62
|
+
if (!className) {
|
|
63
|
+
throw new Error(
|
|
64
|
+
"unable to detect className, please manually set a className",
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
await render(<View testID={testID} className={className} />, options);
|
|
69
|
+
const component = screen.getByTestId(testID, { hidden: true });
|
|
70
|
+
|
|
71
|
+
// Strip the testID and the children
|
|
72
|
+
const { testID: _testID, children, ...props } = component.props;
|
|
73
|
+
|
|
74
|
+
const invalid = getInvalid();
|
|
75
|
+
|
|
76
|
+
if (invalid) {
|
|
77
|
+
return { props, invalid };
|
|
78
|
+
} else {
|
|
79
|
+
return { props };
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
renderCurrentTest.debug = (options: RenderCurrentTestOptions = {}) => {
|
|
84
|
+
return renderCurrentTest({ ...options, debugCompiled: true });
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export async function render(
|
|
88
|
+
component: React.ReactElement<any>,
|
|
89
|
+
{
|
|
90
|
+
config,
|
|
91
|
+
css,
|
|
92
|
+
layers = {},
|
|
93
|
+
debugCompiled = process.env.NODE_OPTIONS?.includes("--inspect"),
|
|
94
|
+
...options
|
|
95
|
+
}: RenderOptions = {},
|
|
96
|
+
) {
|
|
97
|
+
// Compile the base CSS, e.g:
|
|
98
|
+
// @tailwind base
|
|
99
|
+
// @tailwind components
|
|
100
|
+
// @tailwind utilities
|
|
101
|
+
css ??= Object.entries({
|
|
102
|
+
base: true,
|
|
103
|
+
components: true,
|
|
104
|
+
utilities: true,
|
|
105
|
+
...layers,
|
|
106
|
+
}).reduce((acc, [layer, enabled]) => {
|
|
107
|
+
return enabled ? `${acc}@tailwind ${layer};` : acc;
|
|
108
|
+
}, "");
|
|
109
|
+
|
|
110
|
+
const content = getClassNames(component);
|
|
111
|
+
|
|
112
|
+
if (debugCompiled) {
|
|
113
|
+
const classNames = content.map(({ raw }) => ` ${raw}`);
|
|
114
|
+
console.log(`Detected classNames:\n${classNames.join("\n")}\n\n`);
|
|
115
|
+
|
|
116
|
+
if (config?.safelist) {
|
|
117
|
+
console.log(`Detected safelist:\n${config.safelist.join("\n")}\n\n`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Process the TailwindCSS
|
|
122
|
+
let { css: output } = await postcss([
|
|
123
|
+
tailwind({
|
|
124
|
+
theme: {},
|
|
125
|
+
...config,
|
|
126
|
+
presets: [require("./tailwind")],
|
|
127
|
+
plugins: [tailwindcssContainerQueries, ...(config?.plugins || [])],
|
|
128
|
+
content,
|
|
129
|
+
}),
|
|
130
|
+
]).process(css, { from: undefined });
|
|
131
|
+
|
|
132
|
+
return interopRender(component, {
|
|
133
|
+
...options,
|
|
134
|
+
css: output,
|
|
135
|
+
cssOptions: cssToReactNativeRuntimeOptions,
|
|
136
|
+
debugCompiled: debugCompiled,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
render.debug = (
|
|
141
|
+
component: React.ReactElement<any>,
|
|
142
|
+
options: RenderOptions = {},
|
|
143
|
+
) => {
|
|
144
|
+
return render(component, { ...options, debugCompiled: true });
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
render.noDebug = (
|
|
148
|
+
component: React.ReactElement<any>,
|
|
149
|
+
options: RenderOptions = {},
|
|
150
|
+
) => {
|
|
151
|
+
return render(component, { ...options, debugCompiled: false });
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
function getClassNames(
|
|
155
|
+
component: React.ReactElement<any>,
|
|
156
|
+
): Array<{ raw: string; extension?: string }> {
|
|
157
|
+
const classNames: Array<{ raw: string; extension?: string }> = [];
|
|
158
|
+
|
|
159
|
+
if (component.props?.className) {
|
|
160
|
+
classNames.push({ raw: component.props.className });
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (component.props?.children) {
|
|
164
|
+
const children: React.ReactElement<any>[] = Array.isArray(
|
|
165
|
+
component.props.children,
|
|
166
|
+
)
|
|
167
|
+
? component.props.children
|
|
168
|
+
: [component.props.children];
|
|
169
|
+
|
|
170
|
+
classNames.push(...children.flatMap((c) => getClassNames(c)));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return classNames;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function getInvalid() {
|
|
177
|
+
const style: Record<string, any> = {};
|
|
178
|
+
const properties: string[] = [];
|
|
179
|
+
|
|
180
|
+
let hasStyles = false;
|
|
181
|
+
|
|
182
|
+
for (const warnings of getWarnings().values()) {
|
|
183
|
+
for (const warning of warnings) {
|
|
184
|
+
switch (warning.type) {
|
|
185
|
+
case "IncompatibleNativeProperty":
|
|
186
|
+
properties.push(warning.property);
|
|
187
|
+
break;
|
|
188
|
+
case "IncompatibleNativeValue": {
|
|
189
|
+
hasStyles = true;
|
|
190
|
+
style[warning.property] = warning.value;
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
193
|
+
case "IncompatibleNativeFunctionValue":
|
|
194
|
+
// TODO
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (properties.length && hasStyles) {
|
|
200
|
+
return {
|
|
201
|
+
style,
|
|
202
|
+
properties,
|
|
203
|
+
};
|
|
204
|
+
} else if (properties.length) {
|
|
205
|
+
return { properties };
|
|
206
|
+
} else if (hasStyles) {
|
|
207
|
+
return { style };
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export function invalidProperty(...properties: string[]) {
|
|
212
|
+
return properties.map((property) => ({
|
|
213
|
+
type: "IncompatibleNativeProperty",
|
|
214
|
+
property,
|
|
215
|
+
}));
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export function invalidValue(value: Record<string, string>) {
|
|
219
|
+
return Object.entries(value).map(([property, value]) => ({
|
|
220
|
+
type: "IncompatibleNativeValue",
|
|
221
|
+
property,
|
|
222
|
+
value,
|
|
223
|
+
}));
|
|
224
|
+
}
|
package/src/theme.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const isNative = Boolean(process.env.NATIVEWIND_OS);
|
|
2
|
+
|
|
3
|
+
export const {
|
|
4
|
+
hairlineWidth,
|
|
5
|
+
platformSelect,
|
|
6
|
+
pixelScaleSelect,
|
|
7
|
+
fontScaleSelect,
|
|
8
|
+
pixelScale,
|
|
9
|
+
fontScale,
|
|
10
|
+
roundToNearestPixel,
|
|
11
|
+
platformColor,
|
|
12
|
+
getPixelSizeForLayoutSize,
|
|
13
|
+
} = isNative
|
|
14
|
+
? require("react-native-css-interop/css-to-rn/functions")
|
|
15
|
+
: require("react-native-css-interop/css-to-rn/functions-web");
|
package/types.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="react-native-css-interop/types" />
|