@react-native-styled-system/core 1.2.1 → 1.3.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/lib/commonjs/index.js +11 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/internal/util/mutateShortcutPropToOriginalKeys.js +6 -3
- 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/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/internal/util/mutateShortcutPropToOriginalKeys.js +6 -3
- 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/index.d.ts +1 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/internal/util/mutateShortcutPropToOriginalKeys.d.ts +620 -1
- package/lib/typescript/src/internal/util/mutateShortcutPropToOriginalKeys.d.ts.map +1 -1
- package/lib/typescript/src/util/createSxComponent.d.ts +1205 -0
- package/lib/typescript/src/util/createSxComponent.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/hook/useSx.test.ts +23 -0
- package/src/index.ts +1 -0
- package/src/internal/util/mutateShortcutPropToOriginalKeys.ts +5 -3
- package/src/util/createSxComponent.tsx +33 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createSxComponent.d.ts","sourceRoot":"","sources":["../../../../src/util/createSxComponent.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,KAAqB,MAAM,OAAO,CAAC;AAK1C,wBAAgB,iBAAiB,CAAC,KAAK,SAAS,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,aAAa,CAAC,KAAK,CAAC;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+BAY1F"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-native-styled-system/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "React Native Styled System",
|
|
5
5
|
"main": "lib/commonjs/index.js",
|
|
6
6
|
"types": "lib/typescript/src/index.d.ts",
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
"**/*.test.*"
|
|
68
68
|
]
|
|
69
69
|
},
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "d8939b5cb012a3d68bca99530c1c392f0ac1a477"
|
|
71
71
|
}
|
package/src/hook/useSx.test.ts
CHANGED
|
@@ -74,6 +74,12 @@ const baseTheme: ThemedDict = {
|
|
|
74
74
|
fontStyle: 'normal',
|
|
75
75
|
fontWeight: '400',
|
|
76
76
|
},
|
|
77
|
+
body: {
|
|
78
|
+
fontFamily: 'Noto Sans',
|
|
79
|
+
fontSize: 12,
|
|
80
|
+
fontStyle: 'normal',
|
|
81
|
+
fontWeight: '400',
|
|
82
|
+
},
|
|
77
83
|
},
|
|
78
84
|
};
|
|
79
85
|
|
|
@@ -241,6 +247,23 @@ describe('style parse priority', () => {
|
|
|
241
247
|
{ fallback: { width: 1, marginX: 5 }, expectation: { width: 2, marginHorizontal: 4 } },
|
|
242
248
|
);
|
|
243
249
|
});
|
|
250
|
+
|
|
251
|
+
it('sx typography > fallback', () => {
|
|
252
|
+
expectResult(
|
|
253
|
+
baseTheme,
|
|
254
|
+
{ t: 'title' },
|
|
255
|
+
{
|
|
256
|
+
fallback: { typography: 'body' },
|
|
257
|
+
expectation: {
|
|
258
|
+
fontFamily: 'Noto Sans',
|
|
259
|
+
fontSize: 14,
|
|
260
|
+
fontStyle: 'normal',
|
|
261
|
+
fontWeight: '400',
|
|
262
|
+
},
|
|
263
|
+
styleType: 'TextStyle',
|
|
264
|
+
},
|
|
265
|
+
);
|
|
266
|
+
});
|
|
244
267
|
});
|
|
245
268
|
|
|
246
269
|
describe('radii', () => {
|
package/src/index.ts
CHANGED
|
@@ -6,13 +6,15 @@ export function mutateShortcutPropToOriginalKeys(sx?: TextSxProps | null) {
|
|
|
6
6
|
return sx;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
const ret = { ...sx };
|
|
10
|
+
|
|
9
11
|
for (const key of Object.keys(sx)) {
|
|
10
12
|
if (SHORTCUT_NAME_MAP[key]) {
|
|
11
|
-
if (!(SHORTCUT_NAME_MAP[key] in
|
|
12
|
-
|
|
13
|
+
if (!(SHORTCUT_NAME_MAP[key] in ret)) {
|
|
14
|
+
ret[SHORTCUT_NAME_MAP[key]] = sx[key];
|
|
13
15
|
}
|
|
14
16
|
}
|
|
15
17
|
}
|
|
16
18
|
|
|
17
|
-
return
|
|
19
|
+
return ret;
|
|
18
20
|
}
|
|
@@ -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
|
+
}
|