@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.
@@ -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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+BAYtF;AAED,wBAAgB,qBAAqB,CAAC,KAAK,SAAS,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,aAAa,CAAC,KAAK,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+BAY1F"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-styled-system/core",
3
- "version": "1.2.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": "b8feacc50e72c139be6d7a68de6cb6cfce54c67e"
70
+ "gitHead": "d8939b5cb012a3d68bca99530c1c392f0ac1a477"
71
71
  }
@@ -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,3 +6,4 @@ export * from './hook/useSxStyle';
6
6
  export * from './hook/useSxTokens';
7
7
  export * from './provider/StyledSystemProvider';
8
8
  export * from './util/propsToThemedStyle';
9
+ export * from './util/createSxComponent';
@@ -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 sx)) {
12
- sx[SHORTCUT_NAME_MAP[key]] = sx[key];
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 sx;
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
+ }