@react-native-styled-system/core 1.2.2 → 1.3.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/lib/commonjs/@types/SxProps.js.map +1 -1
- package/lib/commonjs/index.js +11 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/internal/util/mutateShortcutPropToOriginalKeys.js.map +1 -1
- package/lib/commonjs/util/createSxComponent.js +47 -0
- package/lib/commonjs/util/createSxComponent.js.map +1 -0
- package/lib/module/@types/SxProps.js.map +1 -1
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/internal/util/mutateShortcutPropToOriginalKeys.js.map +1 -1
- package/lib/module/util/createSxComponent.js +38 -0
- package/lib/module/util/createSxComponent.js.map +1 -0
- package/lib/typescript/src/@types/SxProps.d.ts +18 -18
- package/lib/typescript/src/@types/SxProps.d.ts.map +1 -1
- package/lib/typescript/src/hook/useSx.d.ts +1 -287
- package/lib/typescript/src/hook/useSx.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/internal/util/mutateShortcutPropToOriginalKeys.d.ts +1 -620
- package/lib/typescript/src/internal/util/mutateShortcutPropToOriginalKeys.d.ts.map +1 -1
- package/lib/typescript/src/util/createSxComponent.d.ts +6 -0
- package/lib/typescript/src/util/createSxComponent.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/@types/SxProps.ts +20 -16
- package/src/index.ts +1 -0
- package/src/internal/util/mutateShortcutPropToOriginalKeys.ts +3 -1
- package/src/util/createSxComponent.tsx +33 -0
package/src/@types/SxProps.ts
CHANGED
|
@@ -114,18 +114,18 @@ export const _textStylePropList = [
|
|
|
114
114
|
'typography',
|
|
115
115
|
't',
|
|
116
116
|
] satisfies (Omit<TextSxPropsKey, keyof TextSxPropsKey> | 'style')[];
|
|
117
|
-
|
|
117
|
+
interface ThemedColorTokenProps {
|
|
118
118
|
backgroundColor: Token<'colors'>;
|
|
119
119
|
bg: Token<'colors'>; // backgroundColor
|
|
120
120
|
borderColor: Token<'colors'>;
|
|
121
|
-
}
|
|
122
|
-
|
|
121
|
+
}
|
|
122
|
+
interface ThemedColorTokenTextProps {
|
|
123
123
|
color: Token<'colors'>;
|
|
124
124
|
textDecorationColor: Token<'colors'>;
|
|
125
125
|
textShadowColor: Token<'colors'>;
|
|
126
|
-
}
|
|
126
|
+
}
|
|
127
127
|
|
|
128
|
-
|
|
128
|
+
interface ThemedSpaceTokenProps {
|
|
129
129
|
margin: Token<'space'>;
|
|
130
130
|
m: Token<'space'>; // margin
|
|
131
131
|
marginTop: Token<'space'>;
|
|
@@ -161,9 +161,9 @@ type ThemedSpaceTokenProps = {
|
|
|
161
161
|
gap: Token<'space'>; // only works if parsed result is number
|
|
162
162
|
gapX: Token<'space'>; // only works if parsed result is number
|
|
163
163
|
gapY: Token<'space'>; // only works if parsed result is number
|
|
164
|
-
}
|
|
164
|
+
}
|
|
165
165
|
|
|
166
|
-
|
|
166
|
+
interface ThemedSizeTokenProps {
|
|
167
167
|
width: Token<'sizes'>;
|
|
168
168
|
w: Token<'sizes'>; // width
|
|
169
169
|
minWidth: Token<'sizes'>;
|
|
@@ -176,9 +176,9 @@ type ThemedSizeTokenProps = {
|
|
|
176
176
|
minH: Token<'sizes'>; // minHeight
|
|
177
177
|
maxHeight: Token<'sizes'>;
|
|
178
178
|
maxH: Token<'sizes'>; // maxHeight
|
|
179
|
-
}
|
|
179
|
+
}
|
|
180
180
|
|
|
181
|
-
|
|
181
|
+
interface ThemedRadiiTokenProps {
|
|
182
182
|
borderRadius: Token<'radii'>;
|
|
183
183
|
radius: Token<'radii'>; // borderRadius
|
|
184
184
|
borderTopLeftRadius: Token<'radii'>;
|
|
@@ -189,9 +189,9 @@ type ThemedRadiiTokenProps = {
|
|
|
189
189
|
bottomLeftRadius: Token<'radii'>; // borderBottomLeftRadius
|
|
190
190
|
borderBottomRightRadius: Token<'radii'>;
|
|
191
191
|
bottomRightRadius: Token<'radii'>; // borderBottomRightRadius
|
|
192
|
-
}
|
|
192
|
+
}
|
|
193
193
|
|
|
194
|
-
|
|
194
|
+
interface ThemedViewStyleProps {
|
|
195
195
|
flex: ViewStyle['flex'];
|
|
196
196
|
alignItems: ViewStyle['alignItems'];
|
|
197
197
|
alignContent: ViewStyle['alignContent'];
|
|
@@ -218,9 +218,9 @@ type ThemedViewStyleProps = {
|
|
|
218
218
|
zIndex: ViewStyle['zIndex'];
|
|
219
219
|
absoluteFill?: boolean; // shortcut - position: absoulte, t,r,b,l: 0
|
|
220
220
|
center?: boolean; // shortcut - justifyContent, alignItems: center
|
|
221
|
-
}
|
|
221
|
+
}
|
|
222
222
|
|
|
223
|
-
|
|
223
|
+
interface ThemedTextStyleProps {
|
|
224
224
|
fontFamily: TextStyle['fontFamily'];
|
|
225
225
|
fontSize: TextStyle['fontSize'];
|
|
226
226
|
fontStyle: TextStyle['fontStyle'];
|
|
@@ -239,7 +239,7 @@ type ThemedTextStyleProps = {
|
|
|
239
239
|
includeFontPadding: TextStyle['includeFontPadding'];
|
|
240
240
|
typography: Token<'typography'>;
|
|
241
241
|
t: Token<'typography'>; // typography
|
|
242
|
-
}
|
|
242
|
+
}
|
|
243
243
|
|
|
244
244
|
type BaseSxProps = Partial<
|
|
245
245
|
ThemedViewStyleProps &
|
|
@@ -251,8 +251,12 @@ type BaseSxProps = Partial<
|
|
|
251
251
|
|
|
252
252
|
type BaseTextSxProps = BaseSxProps & Partial<ThemedColorTokenTextProps & ThemedTextStyleProps>;
|
|
253
253
|
|
|
254
|
-
export
|
|
255
|
-
|
|
254
|
+
export interface SxProps extends BaseSxProps {
|
|
255
|
+
sx?: BaseSxProps;
|
|
256
|
+
}
|
|
257
|
+
export interface TextSxProps extends BaseTextSxProps {
|
|
258
|
+
sx?: BaseTextSxProps;
|
|
259
|
+
}
|
|
256
260
|
|
|
257
261
|
export const SHORTCUT_NAME_MAP: Record<string, string> = {
|
|
258
262
|
bg: 'backgroundColor',
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { TextSxProps } from '../../@types/SxProps';
|
|
2
2
|
import { SHORTCUT_NAME_MAP } from '../../@types/SxProps';
|
|
3
3
|
|
|
4
|
-
export function mutateShortcutPropToOriginalKeys(
|
|
4
|
+
export function mutateShortcutPropToOriginalKeys(
|
|
5
|
+
sx?: TextSxProps | null,
|
|
6
|
+
): TextSxProps | undefined | null {
|
|
5
7
|
if (!sx) {
|
|
6
8
|
return sx;
|
|
7
9
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ComponentType } from 'react';
|
|
2
|
+
import React, { forwardRef } from 'react';
|
|
3
|
+
|
|
4
|
+
import type { SxProps, TextSxProps } from '../@types/SxProps';
|
|
5
|
+
import { useSx } from '../hook/useSx';
|
|
6
|
+
|
|
7
|
+
export function createSxComponent<Props extends object, Ref>(Base: ComponentType<Props>) {
|
|
8
|
+
return () => {
|
|
9
|
+
const Transformed = forwardRef<Ref, Props & SxProps>(function (props, ref) {
|
|
10
|
+
const { filteredProps, getStyle } = useSx(props);
|
|
11
|
+
|
|
12
|
+
return <Base {...(filteredProps as any)} style={getStyle()} ref={ref as any} />;
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
Transformed.displayName = `Sx.${Base.displayName || Base.name || 'NoName'}`;
|
|
16
|
+
|
|
17
|
+
return Transformed;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function createSxTextComponent<Props extends object, Ref>(Base: ComponentType<Props>) {
|
|
22
|
+
return () => {
|
|
23
|
+
const Transformed = forwardRef<Ref, Props & TextSxProps>(function (props, ref) {
|
|
24
|
+
const { filteredProps, getStyle } = useSx(props, { styleType: 'TextStyle' });
|
|
25
|
+
|
|
26
|
+
return <Base {...(filteredProps as any)} style={getStyle()} ref={ref as any} />;
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
Transformed.displayName = `Sx.${Base.displayName || Base.name || 'NoName'}`;
|
|
30
|
+
|
|
31
|
+
return Transformed;
|
|
32
|
+
};
|
|
33
|
+
}
|