@mgcrea/react-native-tailwind 0.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 +576 -0
- package/dist/babel/config-loader.d.ts +25 -0
- package/dist/babel/config-loader.ts +134 -0
- package/dist/babel/index.cjs +1111 -0
- package/dist/babel/index.d.ts +16 -0
- package/dist/babel/index.ts +286 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +1 -0
- package/dist/parser/borders.d.ts +10 -0
- package/dist/parser/borders.js +1 -0
- package/dist/parser/colors.d.ts +9 -0
- package/dist/parser/colors.js +1 -0
- package/dist/parser/index.d.ts +25 -0
- package/dist/parser/index.js +1 -0
- package/dist/parser/layout.d.ts +8 -0
- package/dist/parser/layout.js +1 -0
- package/dist/parser/sizing.d.ts +10 -0
- package/dist/parser/sizing.js +1 -0
- package/dist/parser/spacing.d.ts +10 -0
- package/dist/parser/spacing.js +1 -0
- package/dist/parser/typography.d.ts +9 -0
- package/dist/parser/typography.js +1 -0
- package/dist/react-native.d.js +1 -0
- package/dist/react-native.d.ts +138 -0
- package/dist/types.d.ts +11 -0
- package/dist/types.js +1 -0
- package/dist/utils/styleKey.d.ts +9 -0
- package/dist/utils/styleKey.js +1 -0
- package/package.json +83 -0
- package/src/babel/config-loader.ts +134 -0
- package/src/babel/index.ts +286 -0
- package/src/index.ts +20 -0
- package/src/parser/borders.ts +198 -0
- package/src/parser/colors.ts +160 -0
- package/src/parser/index.ts +71 -0
- package/src/parser/layout.ts +114 -0
- package/src/parser/sizing.ts +239 -0
- package/src/parser/spacing.ts +222 -0
- package/src/parser/typography.ts +156 -0
- package/src/react-native.d.ts +138 -0
- package/src/types.ts +15 -0
- package/src/utils/styleKey.ts +23 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/consistent-type-definitions */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* TypeScript declarations to add className prop to React Native components
|
|
5
|
+
* This file provides module augmentation for react-native to add className prop support
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import "react-native";
|
|
9
|
+
|
|
10
|
+
declare module "react-native" {
|
|
11
|
+
interface ViewProps {
|
|
12
|
+
/**
|
|
13
|
+
* Tailwind-like class names for styling
|
|
14
|
+
* @example
|
|
15
|
+
* <View className="flex items-center justify-center m-4 p-2 bg-blue-500 rounded-lg" />
|
|
16
|
+
*/
|
|
17
|
+
className?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface TextProps {
|
|
21
|
+
/**
|
|
22
|
+
* Tailwind-like class names for styling
|
|
23
|
+
* @example
|
|
24
|
+
* <Text className="text-lg font-bold text-blue-500 text-center" />
|
|
25
|
+
*/
|
|
26
|
+
className?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface ImageProps {
|
|
30
|
+
/**
|
|
31
|
+
* Tailwind-like class names for styling
|
|
32
|
+
* @example
|
|
33
|
+
* <Image className="w-full h-64 rounded-lg" source={...} />
|
|
34
|
+
*/
|
|
35
|
+
className?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface ScrollViewProps {
|
|
39
|
+
/**
|
|
40
|
+
* Tailwind-like class names for styling
|
|
41
|
+
* @example
|
|
42
|
+
* <ScrollView className="flex-1 bg-gray-100 p-4" />
|
|
43
|
+
*/
|
|
44
|
+
className?: string;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Tailwind-like class names for styling the content container
|
|
48
|
+
* @example
|
|
49
|
+
* <ScrollView contentContainerClassName="items-center p-4 gap-4" />
|
|
50
|
+
*/
|
|
51
|
+
contentContainerClassName?: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
interface TouchableOpacityProps {
|
|
55
|
+
/**
|
|
56
|
+
* Tailwind-like class names for styling
|
|
57
|
+
* @example
|
|
58
|
+
* <TouchableOpacity className="px-4 py-2 bg-blue-500 rounded-lg items-center" />
|
|
59
|
+
*/
|
|
60
|
+
className?: string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
interface PressableProps {
|
|
64
|
+
/**
|
|
65
|
+
* Tailwind-like class names for styling
|
|
66
|
+
* @example
|
|
67
|
+
* <Pressable className="px-4 py-2 bg-blue-500 rounded-lg items-center" />
|
|
68
|
+
*/
|
|
69
|
+
className?: string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
interface FlatListProps<_ItemT> {
|
|
73
|
+
/**
|
|
74
|
+
* Tailwind-like class names for styling
|
|
75
|
+
* @example
|
|
76
|
+
* <FlatList className="flex-1 bg-gray-100" data={items} renderItem={...} />
|
|
77
|
+
*/
|
|
78
|
+
className?: string;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Tailwind-like class names for styling the content container
|
|
82
|
+
* @example
|
|
83
|
+
* <FlatList contentContainerClassName="p-4 gap-4" data={items} renderItem={...} />
|
|
84
|
+
*/
|
|
85
|
+
contentContainerClassName?: string;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Tailwind-like class names for styling the column wrapper (when numColumns > 1)
|
|
89
|
+
* @example
|
|
90
|
+
* <FlatList columnWrapperClassName="gap-4 mb-4" numColumns={2} data={items} renderItem={...} />
|
|
91
|
+
*/
|
|
92
|
+
columnWrapperClassName?: string;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Tailwind-like class names for styling the list header component
|
|
96
|
+
* @example
|
|
97
|
+
* <FlatList ListHeaderComponentClassName="p-4 bg-gray-200" data={items} renderItem={...} />
|
|
98
|
+
*/
|
|
99
|
+
ListHeaderComponentClassName?: string;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Tailwind-like class names for styling the list footer component
|
|
103
|
+
* @example
|
|
104
|
+
* <FlatList ListFooterComponentClassName="p-4 bg-gray-200" data={items} renderItem={...} />
|
|
105
|
+
*/
|
|
106
|
+
ListFooterComponentClassName?: string;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
interface SectionListProps<_ItemT, _SectionT> {
|
|
110
|
+
/**
|
|
111
|
+
* Tailwind-like class names for styling
|
|
112
|
+
* @example
|
|
113
|
+
* <SectionList className="flex-1 bg-gray-100" sections={sections} renderItem={...} />
|
|
114
|
+
*/
|
|
115
|
+
className?: string;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Tailwind-like class names for styling the content container
|
|
119
|
+
* @example
|
|
120
|
+
* <SectionList contentContainerClassName="p-4 gap-4" sections={sections} renderItem={...} />
|
|
121
|
+
*/
|
|
122
|
+
contentContainerClassName?: string;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Tailwind-like class names for styling the list header component
|
|
126
|
+
* @example
|
|
127
|
+
* <SectionList ListHeaderComponentClassName="p-4 bg-gray-200" sections={sections} renderItem={...} />
|
|
128
|
+
*/
|
|
129
|
+
ListHeaderComponentClassName?: string;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Tailwind-like class names for styling the list footer component
|
|
133
|
+
* @example
|
|
134
|
+
* <SectionList ListFooterComponentClassName="p-4 bg-gray-200" sections={sections} renderItem={...} />
|
|
135
|
+
*/
|
|
136
|
+
ListFooterComponentClassName?: string;
|
|
137
|
+
}
|
|
138
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core type definitions
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { ImageStyle, TextStyle, ViewStyle } from "react-native";
|
|
6
|
+
|
|
7
|
+
export type RNStyle = ViewStyle | TextStyle | ImageStyle;
|
|
8
|
+
|
|
9
|
+
export type StyleObject = {
|
|
10
|
+
[key: string]: string | number;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type SpacingValue = number;
|
|
14
|
+
export type ColorValue = string;
|
|
15
|
+
export type Parser = (className: string) => StyleObject | null;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility to generate unique, stable style keys from class names
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Generate a unique style key from a className string
|
|
7
|
+
* @param className - Space-separated class names
|
|
8
|
+
* @returns Unique style key suitable for use as JavaScript identifier
|
|
9
|
+
*/
|
|
10
|
+
export function generateStyleKey(className: string): string {
|
|
11
|
+
// Split, sort for consistency, and create stable key
|
|
12
|
+
const classes = className.split(/\s+/).filter(Boolean).sort(); // Sort to ensure same classes in different order produce same key
|
|
13
|
+
|
|
14
|
+
// Convert to valid JavaScript identifier
|
|
15
|
+
const key =
|
|
16
|
+
"_" +
|
|
17
|
+
classes
|
|
18
|
+
.join("_")
|
|
19
|
+
.replace(/[^a-zA-Z0-9_]/g, "_") // Replace non-alphanumeric with underscore
|
|
20
|
+
.replace(/_+/g, "_"); // Collapse multiple underscores
|
|
21
|
+
|
|
22
|
+
return key;
|
|
23
|
+
}
|