@xylabs/sdk-react 2.9.12 → 2.9.13

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
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,21 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { createPortal } from 'react-dom';
3
+ //TODO - Move into SDK
4
+ const Portal = ({ children, className, el = 'div', target = 'body' }) => {
5
+ const [container] = useState(document.createElement(el));
6
+ if (className) {
7
+ container.classList.add(className);
8
+ }
9
+ useEffect(() => {
10
+ const targetElement = document.querySelector(target);
11
+ if (!targetElement) {
12
+ console.warn(`Unable to find target element: ${target}`);
13
+ }
14
+ targetElement === null || targetElement === void 0 ? void 0 : targetElement.appendChild(container);
15
+ return () => {
16
+ targetElement === null || targetElement === void 0 ? void 0 : targetElement.removeChild(container);
17
+ };
18
+ }, [container, target]);
19
+ return createPortal(children, container);
20
+ };
21
+ //# sourceMappingURL=Portal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Portal.js","sourceRoot":"","sources":["../../src/components/Portal.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AASxC,sBAAsB;AACtB,MAAM,MAAM,GAA0B,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,GAAG,KAAK,EAAE,MAAM,GAAG,MAAM,EAAe,EAAE,EAAE;IAC1G,MAAM,CAAC,SAAS,CAAC,GAAG,QAAQ,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC,CAAA;IACxD,IAAI,SAAS,EAAE;QACb,SAAS,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;KACnC;IACD,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,aAAa,GAAG,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA;QACpD,IAAI,CAAC,aAAa,EAAE;YAClB,OAAO,CAAC,IAAI,CAAC,kCAAkC,MAAM,EAAE,CAAC,CAAA;SACzD;QACD,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,WAAW,CAAC,SAAS,CAAC,CAAA;QACrC,OAAO,GAAG,EAAE;YACV,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,WAAW,CAAC,SAAS,CAAC,CAAA;QACvC,CAAC,CAAA;IACH,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,CAAA;IAEvB,OAAO,YAAY,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAA;AAC1C,CAAC,CAAA"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -48,6 +48,7 @@
48
48
  "@types/node": "^17",
49
49
  "@types/numeral": "^2",
50
50
  "@types/react": "^17",
51
+ "@types/react-dom": "^17",
51
52
  "@xylabs/eslint-config-react": "^2",
52
53
  "@xylabs/pixel": "^1.3.6",
53
54
  "@xylabs/rollup-config": "^1.1.5",
@@ -123,5 +124,5 @@
123
124
  },
124
125
  "sideEffects": false,
125
126
  "types": "dist/index.d.ts",
126
- "version": "2.9.12"
127
+ "version": "2.9.13"
127
128
  }
@@ -0,0 +1,28 @@
1
+ import { useEffect, useState } from 'react'
2
+ import { createPortal } from 'react-dom'
3
+
4
+ interface PortalProps {
5
+ children: React.ReactNode
6
+ className?: string
7
+ el?: string
8
+ target?: string
9
+ }
10
+
11
+ export const Portal: React.FC<PortalProps> = ({ children, className, el = 'div', target = 'body' }: PortalProps) => {
12
+ const [container] = useState(document.createElement(el))
13
+ if (className) {
14
+ container.classList.add(className)
15
+ }
16
+ useEffect(() => {
17
+ const targetElement = document.querySelector(target)
18
+ if (!targetElement) {
19
+ console.warn(`Unable to find target element: ${target}`)
20
+ }
21
+ targetElement?.appendChild(container)
22
+ return () => {
23
+ targetElement?.removeChild(container)
24
+ }
25
+ }, [container, target])
26
+
27
+ return createPortal(children, container)
28
+ }
@@ -18,6 +18,7 @@ export * from './InvertableThemeProvider'
18
18
  export * from './LinkEx'
19
19
  export * from './NumberStatus'
20
20
  export * from './QuickTipButton'
21
+ export * from './Portal'
21
22
  export * from './RichResult'
22
23
  export * from './ScrollToTop'
23
24
  export * from './TokenAmount'