@mgcrea/react-native-tailwind 0.5.2 → 0.6.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/README.md +141 -10
- package/dist/babel/index.cjs +625 -111
- package/dist/components/Pressable.d.ts +2 -0
- package/dist/components/TextInput.d.ts +2 -0
- package/dist/config/palettes.d.ts +302 -0
- package/dist/config/palettes.js +1 -0
- package/dist/parser/colors.js +1 -1
- package/dist/parser/colors.test.js +1 -1
- package/dist/parser/index.d.ts +1 -0
- package/dist/parser/index.js +1 -1
- package/dist/parser/layout.js +1 -1
- package/dist/parser/layout.test.js +1 -1
- package/dist/parser/transforms.d.ts +13 -0
- package/dist/parser/transforms.js +1 -0
- package/dist/parser/transforms.test.js +1 -0
- package/dist/parser/typography.js +1 -1
- package/dist/parser/typography.test.js +1 -1
- package/dist/types.d.ts +32 -2
- package/package.json +1 -1
- package/src/components/Pressable.tsx +1 -0
- package/src/components/TextInput.tsx +1 -0
- package/src/config/palettes.ts +304 -0
- package/src/parser/colors.test.ts +57 -31
- package/src/parser/colors.ts +34 -111
- package/src/parser/index.ts +3 -0
- package/src/parser/layout.test.ts +35 -0
- package/src/parser/layout.ts +26 -0
- package/src/parser/transforms.test.ts +318 -0
- package/src/parser/transforms.ts +406 -0
- package/src/parser/typography.test.ts +12 -0
- package/src/parser/typography.ts +8 -0
- package/src/types.ts +22 -1
package/README.md
CHANGED
|
@@ -1,13 +1,32 @@
|
|
|
1
|
-
# React Native Tailwind
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
<!-- # React Native Tailwind -->
|
|
2
|
+
|
|
3
|
+
<!-- markdownlint-disable MD033 -->
|
|
4
|
+
<p align="center">
|
|
5
|
+
<a href="https://mgcrea.github.io/react-native-swiftui">
|
|
6
|
+
<img src="./.github/assets/logo.png" alt="logo" width="480" height="300"/>
|
|
7
|
+
</a>
|
|
8
|
+
</p>
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a href="https://www.npmjs.com/package/@mgcrea/react-native-tailwind">
|
|
11
|
+
<img src="https://img.shields.io/npm/v/@mgcrea/react-native-tailwind.svg?style=for-the-badge" alt="npm version" />
|
|
12
|
+
</a>
|
|
13
|
+
<a href="https://www.npmjs.com/package/@mgcrea/react-native-tailwind">
|
|
14
|
+
<img src="https://img.shields.io/npm/dt/@mgcrea/react-native-tailwind.svg?style=for-the-badge" alt="npm total downloads" />
|
|
15
|
+
</a>
|
|
16
|
+
<a href="https://www.npmjs.com/package/@mgcrea/react-native-tailwind">
|
|
17
|
+
<img src="https://img.shields.io/npm/dm/@mgcrea/react-native-tailwind.svg?style=for-the-badge" alt="npm monthly downloads" />
|
|
18
|
+
</a>
|
|
19
|
+
<a href="https://www.npmjs.com/package/@mgcrea/react-native-tailwind">
|
|
20
|
+
<img src="https://img.shields.io/npm/l/@mgcrea/react-native-tailwind.svg?style=for-the-badge" alt="npm license" />
|
|
21
|
+
</a>
|
|
22
|
+
<br />
|
|
23
|
+
<a href="https://github.com/mgcrea/react-native-tailwind/actions/workflows/main.yaml">
|
|
24
|
+
<img src="https://img.shields.io/github/actions/workflow/status/mgcrea/react-native-tailwind/main.yaml?style=for-the-badge&branch=main" alt="build status" />
|
|
25
|
+
</a>
|
|
26
|
+
<a href="https://depfu.com/github/mgcrea/react-native-tailwind">
|
|
27
|
+
<img src="https://img.shields.io/depfu/dependencies/github/mgcrea/react-native-tailwind?style=for-the-badge" alt="dependencies status" />
|
|
28
|
+
</a>
|
|
29
|
+
</p>
|
|
11
30
|
|
|
12
31
|
## Overview
|
|
13
32
|
|
|
@@ -27,6 +46,10 @@ Compile-time Tailwind CSS for React Native with zero runtime overhead. Transform
|
|
|
27
46
|
- 🎯 **State modifiers** — `active:`, `hover:`, `focus:`, and `disabled:` modifiers for interactive components
|
|
28
47
|
- 📜 **Special style props** — Support for `contentContainerClassName`, `columnWrapperClassName`, and more
|
|
29
48
|
|
|
49
|
+
## Demo
|
|
50
|
+
|
|
51
|
+

|
|
52
|
+
|
|
30
53
|
## Installation
|
|
31
54
|
|
|
32
55
|
```bash
|
|
@@ -858,6 +881,108 @@ Use `aspect-[width/height]` for custom ratios:
|
|
|
858
881
|
|
|
859
882
|
> **Note:** The aspect ratio is calculated as `width / height`. When combined with `w-full`, the height will be automatically calculated to maintain the ratio.
|
|
860
883
|
|
|
884
|
+
### Transforms
|
|
885
|
+
|
|
886
|
+
Apply 2D and 3D transformations to views with React Native's transform API. All transforms compile to optimized transform arrays at build time:
|
|
887
|
+
|
|
888
|
+
**Scale:**
|
|
889
|
+
|
|
890
|
+
- `scale-{value}` — Scale uniformly (both X and Y)
|
|
891
|
+
- `scale-x-{value}`, `scale-y-{value}` — Scale on specific axis
|
|
892
|
+
- **Values:** `0`, `50`, `75`, `90`, `95`, `100`, `105`, `110`, `125`, `150`, `200`
|
|
893
|
+
- **Arbitrary:** `scale-[1.23]`, `scale-x-[0.5]`, `scale-y-[2.5]`
|
|
894
|
+
|
|
895
|
+
**Rotate:**
|
|
896
|
+
|
|
897
|
+
- `rotate-{degrees}`, `-rotate-{degrees}` — Rotate in 2D
|
|
898
|
+
- `rotate-x-{degrees}`, `rotate-y-{degrees}`, `rotate-z-{degrees}` — Rotate on specific axis
|
|
899
|
+
- **Values:** `0`, `1`, `2`, `3`, `6`, `12`, `45`, `90`, `180`
|
|
900
|
+
- **Arbitrary:** `rotate-[37deg]`, `-rotate-[15deg]`, `rotate-x-[30deg]`
|
|
901
|
+
|
|
902
|
+
**Translate:**
|
|
903
|
+
|
|
904
|
+
- `translate-x-{spacing}`, `translate-y-{spacing}` — Move on specific axis
|
|
905
|
+
- `-translate-x-{spacing}`, `-translate-y-{spacing}` — Negative translation
|
|
906
|
+
- **Values:** Uses spacing scale (same as `m-*`, `p-*`)
|
|
907
|
+
- **Arbitrary:** `translate-x-[50px]`, `translate-y-[100px]`, `translate-x-[50%]`
|
|
908
|
+
|
|
909
|
+
**Skew:**
|
|
910
|
+
|
|
911
|
+
- `skew-x-{degrees}`, `skew-y-{degrees}` — Skew on specific axis
|
|
912
|
+
- `-skew-x-{degrees}`, `-skew-y-{degrees}` — Negative skew
|
|
913
|
+
- **Values:** `0`, `1`, `2`, `3`, `6`, `12`
|
|
914
|
+
- **Arbitrary:** `skew-x-[15deg]`, `-skew-y-[8deg]`
|
|
915
|
+
|
|
916
|
+
**Perspective:**
|
|
917
|
+
|
|
918
|
+
- `perspective-{value}` — Apply perspective transformation
|
|
919
|
+
- **Values:** `0`, `100`, `200`, `300`, `400`, `500`, `600`, `700`, `800`, `900`, `1000`
|
|
920
|
+
- **Arbitrary:** `perspective-[1500]`, `perspective-[2000]`
|
|
921
|
+
|
|
922
|
+
**Examples:**
|
|
923
|
+
|
|
924
|
+
```tsx
|
|
925
|
+
// Scale
|
|
926
|
+
<View className="scale-110 p-4">
|
|
927
|
+
{/* 110% scale (1.1x larger) */}
|
|
928
|
+
<Text>Scaled content</Text>
|
|
929
|
+
</View>
|
|
930
|
+
|
|
931
|
+
// Rotate
|
|
932
|
+
<View className="rotate-45 w-16 h-16 bg-blue-500" />
|
|
933
|
+
|
|
934
|
+
// Translate
|
|
935
|
+
<View className="translate-x-4 translate-y-2 bg-red-500 p-4">
|
|
936
|
+
{/* Moved 16px right, 8px down */}
|
|
937
|
+
</View>
|
|
938
|
+
|
|
939
|
+
// Arbitrary values
|
|
940
|
+
<View className="scale-[1.23] w-16 h-16 bg-green-500" />
|
|
941
|
+
<View className="rotate-[37deg] w-16 h-16 bg-purple-500" />
|
|
942
|
+
<View className="translate-x-[50px] bg-orange-500 p-4" />
|
|
943
|
+
|
|
944
|
+
// Negative values
|
|
945
|
+
<View className="-rotate-45 w-16 h-16 bg-pink-500" />
|
|
946
|
+
<View className="-translate-x-4 -translate-y-2 bg-indigo-500 p-4" />
|
|
947
|
+
|
|
948
|
+
// 3D rotation
|
|
949
|
+
<View className="rotate-x-45 w-16 h-16 bg-yellow-500" />
|
|
950
|
+
<View className="rotate-y-30 w-16 h-16 bg-teal-500" />
|
|
951
|
+
|
|
952
|
+
// Skew
|
|
953
|
+
<View className="skew-x-6 w-16 h-16 bg-cyan-500" />
|
|
954
|
+
|
|
955
|
+
// Perspective
|
|
956
|
+
<View className="perspective-500">
|
|
957
|
+
<View className="rotate-x-45 w-16 h-16 bg-blue-500" />
|
|
958
|
+
</View>
|
|
959
|
+
```
|
|
960
|
+
|
|
961
|
+
**Multiple Transforms Limitation:**
|
|
962
|
+
|
|
963
|
+
Due to the current architecture, multiple transform classes on the same element will overwrite each other. For example:
|
|
964
|
+
|
|
965
|
+
```tsx
|
|
966
|
+
// ❌ Only rotate-45 will apply (overwrites scale-110)
|
|
967
|
+
<View className="scale-110 rotate-45 w-16 h-16 bg-blue-500" />
|
|
968
|
+
|
|
969
|
+
// ✅ Workaround: Use nested Views for multiple transforms
|
|
970
|
+
<View className="scale-110">
|
|
971
|
+
<View className="rotate-45">
|
|
972
|
+
<View className="w-16 h-16 bg-blue-500" />
|
|
973
|
+
</View>
|
|
974
|
+
</View>
|
|
975
|
+
```
|
|
976
|
+
|
|
977
|
+
This limitation exists because the current parser architecture uses `Object.assign()` which overwrites the `transform` property when multiple transform classes are present. This will be addressed in a future update by modifying the Babel plugin to detect multiple transform classes and generate style arrays.
|
|
978
|
+
|
|
979
|
+
**What's Not Supported:**
|
|
980
|
+
|
|
981
|
+
- `transform-origin` — Not available in React Native (transforms always use center as origin)
|
|
982
|
+
- Multiple transforms on one element — Use nested Views (see workaround above)
|
|
983
|
+
|
|
984
|
+
> **Note:** All transform parsing happens at compile-time with zero runtime overhead. Each transform compiles to a React Native transform array: `transform: [{ scale: 1.1 }]`, `transform: [{ rotate: '45deg' }]`, etc.
|
|
985
|
+
|
|
861
986
|
### Sizing
|
|
862
987
|
|
|
863
988
|
- `w-{size}`, `h-{size}` — Width/height
|
|
@@ -889,6 +1014,12 @@ Use arbitrary values for custom sizes, spacing, and borders not in the preset sc
|
|
|
889
1014
|
- **Sizing:** `w-[...]`, `h-[...]`, `min-w-[...]`, `min-h-[...]`, `max-w-[...]`, `max-h-[...]` (px and %)
|
|
890
1015
|
- **Border width:** `border-[...]`, `border-t-[...]`, `border-r-[...]`, `border-b-[...]`, `border-l-[...]` (px only)
|
|
891
1016
|
- **Border radius:** `rounded-[...]`, `rounded-t-[...]`, `rounded-tl-[...]`, etc. (px only)
|
|
1017
|
+
- **Transforms:**
|
|
1018
|
+
- **Scale:** `scale-[...]`, `scale-x-[...]`, `scale-y-[...]` (number only, e.g., `[1.23]`)
|
|
1019
|
+
- **Rotate:** `rotate-[...]`, `rotate-x-[...]`, `rotate-y-[...]`, `rotate-z-[...]` (deg only, e.g., `[37deg]`)
|
|
1020
|
+
- **Translate:** `translate-x-[...]`, `translate-y-[...]` (px or %, e.g., `[50px]` or `[50%]`)
|
|
1021
|
+
- **Skew:** `skew-x-[...]`, `skew-y-[...]` (deg only, e.g., `[15deg]`)
|
|
1022
|
+
- **Perspective:** `perspective-[...]` (number only, e.g., `[1500]`)
|
|
892
1023
|
|
|
893
1024
|
**Formats:**
|
|
894
1025
|
|