@hero-design/rn 8.41.0 → 8.41.1-rc.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/.turbo/turbo-build.log +1 -1
- package/es/index.js +11 -4
- package/lib/index.js +11 -4
- package/package.json +7 -7
- package/src/components/Portal/__tests__/__snapshots__/index.spec.tsx.snap +29 -0
- package/src/components/Portal/__tests__/index.spec.tsx +19 -0
- package/src/components/Portal/index.tsx +18 -5
- package/types/components/Portal/index.d.ts +10 -5
package/.turbo/turbo-build.log
CHANGED
|
@@ -4,5 +4,5 @@ $ rollup -c
|
|
|
4
4
|
[1msrc/index.ts[22m → [1mlib/index.js, es/index.js[22m...[39m
|
|
5
5
|
[1m[33m(!) Plugin replace: @rollup/plugin-replace: 'preventAssignment' currently defaults to false. It is recommended to set this option to `true`, as the next major version will default this option to `true`.[39m[22m
|
|
6
6
|
[1m[33m(!) Plugin node-resolve: preferring built-in module 'events' over local alternative at '/root/hero-design/node_modules/events/events.js', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning[39m[22m
|
|
7
|
-
[32mcreated [1mlib/index.js, es/index.js[22m in [
|
|
7
|
+
[32mcreated [1mlib/index.js, es/index.js[22m in [1m29s[22m[39m
|
|
8
8
|
$ tsc --noEmit false --emitDeclarationOnly --project tsconfig.prod.json
|
package/es/index.js
CHANGED
|
@@ -14204,22 +14204,29 @@ var nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz0123456789', 10);
|
|
|
14204
14204
|
var PortalComponent = function PortalComponent(_ref) {
|
|
14205
14205
|
var name = _ref.name,
|
|
14206
14206
|
hostName = _ref.hostName,
|
|
14207
|
-
children = _ref.children
|
|
14207
|
+
children = _ref.children,
|
|
14208
|
+
theme = _ref.theme;
|
|
14209
|
+
var defaultTheme = useTheme();
|
|
14208
14210
|
var _usePortal = usePortal(hostName),
|
|
14209
14211
|
addUpdatePortal = _usePortal.addPortal,
|
|
14210
14212
|
removePortal = _usePortal.removePortal;
|
|
14211
14213
|
var nameOrRandom = useMemo(function () {
|
|
14212
14214
|
return name || nanoid();
|
|
14213
14215
|
}, [name]);
|
|
14216
|
+
var ChildrenComponent = useMemo(function () {
|
|
14217
|
+
return /*#__PURE__*/React.createElement(ThemeProvider, {
|
|
14218
|
+
theme: theme || defaultTheme
|
|
14219
|
+
}, children);
|
|
14220
|
+
}, [theme, children, defaultTheme]);
|
|
14214
14221
|
useLayoutEffect(function () {
|
|
14215
|
-
addUpdatePortal(nameOrRandom,
|
|
14222
|
+
addUpdatePortal(nameOrRandom, ChildrenComponent);
|
|
14216
14223
|
return function () {
|
|
14217
14224
|
removePortal(nameOrRandom);
|
|
14218
14225
|
};
|
|
14219
14226
|
}, [addUpdatePortal]);
|
|
14220
14227
|
useLayoutEffect(function () {
|
|
14221
|
-
addUpdatePortal(nameOrRandom,
|
|
14222
|
-
}, [
|
|
14228
|
+
addUpdatePortal(nameOrRandom, ChildrenComponent);
|
|
14229
|
+
}, [ChildrenComponent]);
|
|
14223
14230
|
return null;
|
|
14224
14231
|
};
|
|
14225
14232
|
var Portal = /*#__PURE__*/memo(PortalComponent);
|
package/lib/index.js
CHANGED
|
@@ -14235,22 +14235,29 @@ var nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz0123456789', 10);
|
|
|
14235
14235
|
var PortalComponent = function PortalComponent(_ref) {
|
|
14236
14236
|
var name = _ref.name,
|
|
14237
14237
|
hostName = _ref.hostName,
|
|
14238
|
-
children = _ref.children
|
|
14238
|
+
children = _ref.children,
|
|
14239
|
+
theme = _ref.theme;
|
|
14240
|
+
var defaultTheme = useTheme();
|
|
14239
14241
|
var _usePortal = usePortal(hostName),
|
|
14240
14242
|
addUpdatePortal = _usePortal.addPortal,
|
|
14241
14243
|
removePortal = _usePortal.removePortal;
|
|
14242
14244
|
var nameOrRandom = React.useMemo(function () {
|
|
14243
14245
|
return name || nanoid();
|
|
14244
14246
|
}, [name]);
|
|
14247
|
+
var ChildrenComponent = React.useMemo(function () {
|
|
14248
|
+
return /*#__PURE__*/React__default["default"].createElement(ThemeProvider, {
|
|
14249
|
+
theme: theme || defaultTheme
|
|
14250
|
+
}, children);
|
|
14251
|
+
}, [theme, children, defaultTheme]);
|
|
14245
14252
|
React.useLayoutEffect(function () {
|
|
14246
|
-
addUpdatePortal(nameOrRandom,
|
|
14253
|
+
addUpdatePortal(nameOrRandom, ChildrenComponent);
|
|
14247
14254
|
return function () {
|
|
14248
14255
|
removePortal(nameOrRandom);
|
|
14249
14256
|
};
|
|
14250
14257
|
}, [addUpdatePortal]);
|
|
14251
14258
|
React.useLayoutEffect(function () {
|
|
14252
|
-
addUpdatePortal(nameOrRandom,
|
|
14253
|
-
}, [
|
|
14259
|
+
addUpdatePortal(nameOrRandom, ChildrenComponent);
|
|
14260
|
+
}, [ChildrenComponent]);
|
|
14254
14261
|
return null;
|
|
14255
14262
|
};
|
|
14256
14263
|
var Portal = /*#__PURE__*/React.memo(PortalComponent);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hero-design/rn",
|
|
3
|
-
"version": "8.41.0",
|
|
3
|
+
"version": "8.41.1-rc.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "es/index.js",
|
|
@@ -21,14 +21,14 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@emotion/native": "^11.9.3",
|
|
23
23
|
"@emotion/react": "^11.9.3",
|
|
24
|
-
"@hero-design/colors": "8.41.0",
|
|
24
|
+
"@hero-design/colors": "8.41.1-rc.0",
|
|
25
25
|
"date-fns": "^2.16.1",
|
|
26
26
|
"events": "^3.2.0",
|
|
27
27
|
"hero-editor": "^1.9.21",
|
|
28
28
|
"nanoid": "^4.0.2"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"@hero-design/react-native-month-year-picker": "^8.41.0",
|
|
31
|
+
"@hero-design/react-native-month-year-picker": "^8.41.1-rc.0",
|
|
32
32
|
"@react-native-community/datetimepicker": "^3.5.2",
|
|
33
33
|
"@react-native-community/slider": "4.1.12",
|
|
34
34
|
"react": "18.0.0",
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"@babel/preset-typescript": "^7.17.12",
|
|
49
49
|
"@babel/runtime": "^7.18.9",
|
|
50
50
|
"@emotion/jest": "^11.11.0",
|
|
51
|
-
"@hero-design/eslint-plugin": "8.41.0",
|
|
52
|
-
"@hero-design/react-native-month-year-picker": "^8.41.0",
|
|
51
|
+
"@hero-design/eslint-plugin": "8.41.1-rc.0",
|
|
52
|
+
"@hero-design/react-native-month-year-picker": "^8.41.1-rc.0",
|
|
53
53
|
"@react-native-community/datetimepicker": "^3.5.2",
|
|
54
54
|
"@react-native-community/slider": "4.1.12",
|
|
55
55
|
"@rollup/plugin-babel": "^5.3.1",
|
|
@@ -65,12 +65,12 @@
|
|
|
65
65
|
"@types/react-native": "^0.67.7",
|
|
66
66
|
"@types/react-native-vector-icons": "^6.4.10",
|
|
67
67
|
"babel-plugin-inline-import": "^3.0.0",
|
|
68
|
-
"eslint-config-hd": "8.41.0",
|
|
68
|
+
"eslint-config-hd": "8.41.1-rc.0",
|
|
69
69
|
"eslint-plugin-import": "^2.27.5",
|
|
70
70
|
"jest": "^29.6.2",
|
|
71
71
|
"jest-environment-jsdom": "^29.6.2",
|
|
72
72
|
"jest-junit": "^16.0.0",
|
|
73
|
-
"prettier-config-hd": "8.41.0",
|
|
73
|
+
"prettier-config-hd": "8.41.1-rc.0",
|
|
74
74
|
"react": "18.0.0",
|
|
75
75
|
"react-native": "0.69.7",
|
|
76
76
|
"react-native-gesture-handler": "~2.5.0",
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`Portal allows rendering children with custom theme 1`] = `
|
|
4
|
+
<View
|
|
5
|
+
testID="portal-wrapper"
|
|
6
|
+
>
|
|
7
|
+
<Text
|
|
8
|
+
allowFontScaling={false}
|
|
9
|
+
style={
|
|
10
|
+
[
|
|
11
|
+
{
|
|
12
|
+
"color": "#001f23",
|
|
13
|
+
"fontFamily": "BeVietnamPro-Regular",
|
|
14
|
+
"fontSize": 16,
|
|
15
|
+
"letterSpacing": 0.48,
|
|
16
|
+
"lineHeight": 24,
|
|
17
|
+
},
|
|
18
|
+
undefined,
|
|
19
|
+
]
|
|
20
|
+
}
|
|
21
|
+
themeIntent="body"
|
|
22
|
+
themeTypeface="neutral"
|
|
23
|
+
themeVariant="regular"
|
|
24
|
+
>
|
|
25
|
+
portal
|
|
26
|
+
</Text>
|
|
27
|
+
;
|
|
28
|
+
</View>
|
|
29
|
+
`;
|
|
@@ -6,6 +6,8 @@ import { PortalHost } from '../PortalHost';
|
|
|
6
6
|
import { PortalProvider } from '../PortalProvider';
|
|
7
7
|
import Typography from '../../Typography';
|
|
8
8
|
import Portal from '..';
|
|
9
|
+
import { getTheme } from '../../../theme';
|
|
10
|
+
import { defaultScale, walletSystemPalette } from '../../../theme/global';
|
|
9
11
|
|
|
10
12
|
describe('Portal', () => {
|
|
11
13
|
it('should render Typography inside Portal.Host', async () => {
|
|
@@ -26,4 +28,21 @@ describe('Portal', () => {
|
|
|
26
28
|
).toBeDefined()
|
|
27
29
|
);
|
|
28
30
|
});
|
|
31
|
+
|
|
32
|
+
it('allows rendering children with custom theme', () => {
|
|
33
|
+
const customTheme = getTheme(defaultScale, walletSystemPalette);
|
|
34
|
+
|
|
35
|
+
const wrapper = renderWithTheme(
|
|
36
|
+
<PortalProvider>
|
|
37
|
+
<View testID="portal-wrapper">
|
|
38
|
+
<PortalHost name="host" />
|
|
39
|
+
</View>
|
|
40
|
+
<Portal theme={customTheme} hostName="host">
|
|
41
|
+
<Typography.Body>portal</Typography.Body>;
|
|
42
|
+
</Portal>
|
|
43
|
+
</PortalProvider>
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
expect(wrapper.toJSON()).toMatchSnapshot();
|
|
47
|
+
});
|
|
29
48
|
});
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { ReactNode, memo, useLayoutEffect, useMemo } from 'react';
|
|
1
|
+
import React, { ReactNode, memo, useLayoutEffect, useMemo } from 'react';
|
|
2
2
|
// Fix issue no crypto in react-native
|
|
3
3
|
// https://stackoverflow.com/a/66852908
|
|
4
4
|
import { customAlphabet } from 'nanoid/non-secure';
|
|
5
5
|
import { usePortal } from './usePortal';
|
|
6
6
|
import { PortalProvider } from './PortalProvider';
|
|
7
7
|
import { PortalHost } from './PortalHost';
|
|
8
|
+
import { Theme, ThemeProvider, useTheme } from '../../theme';
|
|
8
9
|
|
|
9
10
|
const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz0123456789', 10);
|
|
10
11
|
|
|
@@ -23,23 +24,35 @@ export interface PortalProps {
|
|
|
23
24
|
* Content of the portal.
|
|
24
25
|
*/
|
|
25
26
|
children?: ReactNode | ReactNode[];
|
|
27
|
+
/**
|
|
28
|
+
* Theme for portal children.
|
|
29
|
+
*/
|
|
30
|
+
theme?: Theme;
|
|
26
31
|
}
|
|
27
32
|
|
|
28
|
-
const PortalComponent = ({ name, hostName, children }: PortalProps) => {
|
|
33
|
+
const PortalComponent = ({ name, hostName, children, theme }: PortalProps) => {
|
|
34
|
+
const defaultTheme = useTheme();
|
|
29
35
|
const { addPortal: addUpdatePortal, removePortal } = usePortal(hostName);
|
|
30
36
|
|
|
31
37
|
const nameOrRandom = useMemo(() => name || nanoid(), [name]);
|
|
32
38
|
|
|
39
|
+
const ChildrenComponent = useMemo(
|
|
40
|
+
() => (
|
|
41
|
+
<ThemeProvider theme={theme || defaultTheme}>{children}</ThemeProvider>
|
|
42
|
+
),
|
|
43
|
+
[theme, children, defaultTheme]
|
|
44
|
+
);
|
|
45
|
+
|
|
33
46
|
useLayoutEffect(() => {
|
|
34
|
-
addUpdatePortal(nameOrRandom,
|
|
47
|
+
addUpdatePortal(nameOrRandom, ChildrenComponent);
|
|
35
48
|
return () => {
|
|
36
49
|
removePortal(nameOrRandom);
|
|
37
50
|
};
|
|
38
51
|
}, [addUpdatePortal]);
|
|
39
52
|
|
|
40
53
|
useLayoutEffect(() => {
|
|
41
|
-
addUpdatePortal(nameOrRandom,
|
|
42
|
-
}, [
|
|
54
|
+
addUpdatePortal(nameOrRandom, ChildrenComponent);
|
|
55
|
+
}, [ChildrenComponent]);
|
|
43
56
|
|
|
44
57
|
return null;
|
|
45
58
|
};
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import { Theme } from '../../theme';
|
|
2
3
|
export interface PortalProps {
|
|
3
4
|
name?: string;
|
|
4
5
|
hostName?: string;
|
|
5
6
|
children?: ReactNode | ReactNode[];
|
|
7
|
+
/**
|
|
8
|
+
* Theme for portal children.
|
|
9
|
+
*/
|
|
10
|
+
theme?: Theme;
|
|
6
11
|
}
|
|
7
|
-
declare const _default:
|
|
8
|
-
readonly type: ({ name, hostName, children }: PortalProps) => null;
|
|
12
|
+
declare const _default: React.NamedExoticComponent<PortalProps> & {
|
|
13
|
+
readonly type: ({ name, hostName, children, theme }: PortalProps) => null;
|
|
9
14
|
} & {
|
|
10
|
-
Provider:
|
|
11
|
-
Host:
|
|
15
|
+
Provider: React.MemoExoticComponent<({ rootHostName, children, }: import("./PortalProvider").PortalProviderProps) => JSX.Element>;
|
|
16
|
+
Host: React.MemoExoticComponent<({ name }: import("./PortalHost").PortalHostProps) => JSX.Element>;
|
|
12
17
|
};
|
|
13
18
|
export default _default;
|