@tamagui/portal 1.0.1-beta.56 → 1.0.1-beta.60

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/portal",
3
- "version": "1.0.1-beta.56",
3
+ "version": "1.0.1-beta.60",
4
4
  "sideEffects": true,
5
5
  "source": "src/index.ts",
6
6
  "types": "./types/index.d.ts",
@@ -8,6 +8,7 @@
8
8
  "module": "dist/esm",
9
9
  "module:jsx": "dist/jsx",
10
10
  "files": [
11
+ "src",
11
12
  "types",
12
13
  "dist"
13
14
  ],
@@ -18,7 +19,7 @@
18
19
  "clean:build": "tamagui-build clean:build"
19
20
  },
20
21
  "dependencies": {
21
- "@tamagui/stacks": "^1.0.1-beta.56"
22
+ "@tamagui/stacks": "^1.0.1-beta.60"
22
23
  },
23
24
  "peerDependencies": {
24
25
  "react": "*",
@@ -26,7 +27,7 @@
26
27
  "react-native": "*"
27
28
  },
28
29
  "devDependencies": {
29
- "@tamagui/build": "^1.0.1-beta.56",
30
+ "@tamagui/build": "^1.0.1-beta.60",
30
31
  "@types/react-native": "^0.67.3",
31
32
  "react": "*",
32
33
  "react-dom": "*",
package/src/Portal.tsx ADDED
@@ -0,0 +1,35 @@
1
+ import '@tamagui/polyfill-dev'
2
+
3
+ import { isWeb, useIsomorphicLayoutEffect } from '@tamagui/core'
4
+ import { YStack, YStackProps } from '@tamagui/stacks'
5
+ import * as React from 'react'
6
+ import { createPortal } from 'react-dom'
7
+ import { Modal } from 'react-native'
8
+
9
+ export type PortalProps = YStackProps
10
+
11
+ export const Portal = (props: PortalProps) => {
12
+ const contents = <YStack pointerEvents="none" fullscreen {...props} />
13
+
14
+ if (!isWeb) {
15
+ // check if theme stays in context here
16
+ return (
17
+ <Modal visible transparent pointerEvents="none">
18
+ {contents}
19
+ </Modal>
20
+ )
21
+ }
22
+
23
+ const [hostElement, setHostElement] = React.useState<any>(null)
24
+
25
+ useIsomorphicLayoutEffect(() => {
26
+ setHostElement(globalThis.document?.body)
27
+ }, [])
28
+
29
+ if (hostElement) {
30
+ return createPortal(contents, hostElement)
31
+ }
32
+
33
+ // ssr return null
34
+ return null
35
+ }
package/src/index.tsx ADDED
@@ -0,0 +1 @@
1
+ export * from './Portal'