Skip to content

Commit 53ddb96

Browse files
author
Harris Robin Kalash
committed
create Portal component
1 parent 8163568 commit 53ddb96

File tree

57 files changed

+94
-10
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+94
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"code":"/**\r\n * @class ExampleComponent\r\n */\r\nimport * as tslib_1 from \"tslib\";\r\nimport * as React from 'react';\r\nimport styles from './styles.css';\r\nvar ExampleComponent = /** @class */ (function (_super) {\r\n tslib_1.__extends(ExampleComponent, _super);\r\n function ExampleComponent() {\r\n return _super !== null && _super.apply(this, arguments) || this;\r\n }\r\n ExampleComponent.prototype.render = function () {\r\n var text = this.props.text;\r\n return (React.createElement(\"div\", { className: styles.test },\r\n \"Example Component: \",\r\n text));\r\n };\r\n return ExampleComponent;\r\n}(React.Component));\r\nexport default ExampleComponent;\r\n//# sourceMappingURL=index.js.map","map":"{\"version\":3,\"file\":\"index.js\",\"sourceRoot\":\"\",\"sources\":[\"src/index.tsx\"],\"names\":[],\"mappings\":\"AAAA;;GAEG;;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,MAAM,MAAM,cAAc,CAAA;AAIjC;IAA8C,4CAAsB;IAApE;;IAYA,CAAC;IAXC,iCAAM,GAAN;QAEI,IAAA,sBAAI,CACQ;QAEd,OAAO,CACL,6BAAK,SAAS,EAAE,MAAM,CAAC,IAAI;;YACL,IAAI,CACpB,CACP,CAAA;IACH,CAAC;IACH,uBAAC;AAAD,CAAC,AAZD,CAA8C,KAAK,CAAC,SAAS,GAY5D\"}","dts":{"name":"/Users/harrisrobin/Workspace/oss/react-sidesheet/index.d.ts","text":"/**\r\n * @class ExampleComponent\r\n */\r\nimport * as React from 'react';\r\nexport declare type Props = {\r\n text: string;\r\n};\r\nexport default class ExampleComponent extends React.Component<Props> {\r\n render(): JSX.Element;\r\n}\r\n"}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

.rpt2_cache/0f24665b162ac8ff3a3acb6e8570838e0f229e0b/types/cache/0c8d6b0779fc8dde9799c65e788028cff83373a4

Whitespace-only changes.

.rpt2_cache/0f24665b162ac8ff3a3acb6e8570838e0f229e0b/types/cache/1b8f57f67c79335f28773c6e47de33f164097d3f

Whitespace-only changes.

.rpt2_cache/0f24665b162ac8ff3a3acb6e8570838e0f229e0b/types/cache/1f0d3004567bfaf678d48a3ac7e0cd5ce4f833f3

Whitespace-only changes.

.rpt2_cache/0f24665b162ac8ff3a3acb6e8570838e0f229e0b/types/cache/81177a67853c1091552bdd4a46fbd646eb7bea80

Whitespace-only changes.

.rpt2_cache/0f24665b162ac8ff3a3acb6e8570838e0f229e0b/types/cache/8e67021bf05d92df6369c1fc280b133c3aa45ff1

Whitespace-only changes.

.rpt2_cache/0f24665b162ac8ff3a3acb6e8570838e0f229e0b/types/cache/92d5cfa90f7d396a5a68ddc5a8bc87a1c7ad415a

Whitespace-only changes.

.rpt2_cache/0f24665b162ac8ff3a3acb6e8570838e0f229e0b/types/cache/9fd7c61ee6cbf1c39f01ad78d9b5e68b63502b9e

Whitespace-only changes.

.rpt2_cache/0f24665b162ac8ff3a3acb6e8570838e0f229e0b/types/cache/c61ee26be027ba63dd5a056637c6521682912864

Whitespace-only changes.

.rpt2_cache/0f24665b162ac8ff3a3acb6e8570838e0f229e0b/types/cache/e73ed4c7ee96f40e4553ab3869d4ae5ffb8800fd

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"code":"/**\r\n * @class ExampleComponent\r\n */\r\nimport * as tslib_1 from \"tslib\";\r\nimport * as React from 'react';\r\nimport styles from './styles.css';\r\nvar ExampleComponent = /** @class */ (function (_super) {\r\n tslib_1.__extends(ExampleComponent, _super);\r\n function ExampleComponent() {\r\n return _super !== null && _super.apply(this, arguments) || this;\r\n }\r\n ExampleComponent.prototype.render = function () {\r\n var text = this.props.text;\r\n return (React.createElement(\"div\", { className: styles.test },\r\n \"Example Component: \",\r\n text));\r\n };\r\n return ExampleComponent;\r\n}(React.Component));\r\nexport default ExampleComponent;\r\n//# sourceMappingURL=index.js.map","map":"{\"version\":3,\"file\":\"index.js\",\"sourceRoot\":\"\",\"sources\":[\"src/index.tsx\"],\"names\":[],\"mappings\":\"AAAA;;GAEG;;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,MAAM,MAAM,cAAc,CAAA;AAIjC;IAA8C,4CAAsB;IAApE;;IAYA,CAAC;IAXC,iCAAM,GAAN;QAEI,IAAA,sBAAI,CACQ;QAEd,OAAO,CACL,6BAAK,SAAS,EAAE,MAAM,CAAC,IAAI;;YACL,IAAI,CACpB,CACP,CAAA;IACH,CAAC;IACH,uBAAC;AAAD,CAAC,AAZD,CAA8C,KAAK,CAAC,SAAS,GAY5D\"}","dts":{"name":"/Users/harrisrobin/Workspace/oss/react-sidesheet/index.d.ts","text":"/**\r\n * @class ExampleComponent\r\n */\r\nimport * as React from 'react';\r\nexport declare type Props = {\r\n text: string;\r\n};\r\nexport default class ExampleComponent extends React.Component<Props> {\r\n render(): JSX.Element;\r\n}\r\n"}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

.rpt2_cache/66bc3a737e31228403d968355a2e1ecd508ac1ab/types/cache/0c8d6b0779fc8dde9799c65e788028cff83373a4

Whitespace-only changes.

.rpt2_cache/66bc3a737e31228403d968355a2e1ecd508ac1ab/types/cache/1b8f57f67c79335f28773c6e47de33f164097d3f

Whitespace-only changes.

.rpt2_cache/66bc3a737e31228403d968355a2e1ecd508ac1ab/types/cache/1f0d3004567bfaf678d48a3ac7e0cd5ce4f833f3

Whitespace-only changes.

.rpt2_cache/66bc3a737e31228403d968355a2e1ecd508ac1ab/types/cache/38f3e04661adfddc7f478ea369f2f7c44bf70ad0

Whitespace-only changes.

.rpt2_cache/66bc3a737e31228403d968355a2e1ecd508ac1ab/types/cache/81177a67853c1091552bdd4a46fbd646eb7bea80

Whitespace-only changes.

.rpt2_cache/66bc3a737e31228403d968355a2e1ecd508ac1ab/types/cache/8e67021bf05d92df6369c1fc280b133c3aa45ff1

Whitespace-only changes.

.rpt2_cache/66bc3a737e31228403d968355a2e1ecd508ac1ab/types/cache/92d5cfa90f7d396a5a68ddc5a8bc87a1c7ad415a

Whitespace-only changes.

.rpt2_cache/66bc3a737e31228403d968355a2e1ecd508ac1ab/types/cache/9fd7c61ee6cbf1c39f01ad78d9b5e68b63502b9e

Whitespace-only changes.

.rpt2_cache/66bc3a737e31228403d968355a2e1ecd508ac1ab/types/cache/c61ee26be027ba63dd5a056637c6521682912864

Whitespace-only changes.

.rpt2_cache/66bc3a737e31228403d968355a2e1ecd508ac1ab/types/cache/e73ed4c7ee96f40e4553ab3869d4ae5ffb8800fd

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"code":"/**\r\n * @class ExampleComponent\r\n */\r\nimport * as tslib_1 from \"tslib\";\r\nimport * as React from 'react';\r\nimport styles from './styles.css';\r\nvar ExampleComponent = /** @class */ (function (_super) {\r\n tslib_1.__extends(ExampleComponent, _super);\r\n function ExampleComponent() {\r\n return _super !== null && _super.apply(this, arguments) || this;\r\n }\r\n ExampleComponent.prototype.render = function () {\r\n var text = this.props.text;\r\n return (React.createElement(\"div\", { className: styles.test },\r\n \"Example Component: \",\r\n text));\r\n };\r\n return ExampleComponent;\r\n}(React.Component));\r\nexport default ExampleComponent;\r\n//# sourceMappingURL=index.js.map","map":"{\"version\":3,\"file\":\"index.js\",\"sourceRoot\":\"\",\"sources\":[\"src/index.tsx\"],\"names\":[],\"mappings\":\"AAAA;;GAEG;;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,MAAM,MAAM,cAAc,CAAA;AAIjC;IAA8C,4CAAsB;IAApE;;IAYA,CAAC;IAXC,iCAAM,GAAN;QAEI,IAAA,sBAAI,CACQ;QAEd,OAAO,CACL,6BAAK,SAAS,EAAE,MAAM,CAAC,IAAI;;YACL,IAAI,CACpB,CACP,CAAA;IACH,CAAC;IACH,uBAAC;AAAD,CAAC,AAZD,CAA8C,KAAK,CAAC,SAAS,GAY5D\"}","dts":{"name":"/Users/harrisrobin/Workspace/oss/react-sidesheet/index.d.ts","text":"/**\r\n * @class ExampleComponent\r\n */\r\nimport * as React from 'react';\r\nexport declare type Props = {\r\n text: string;\r\n};\r\nexport default class ExampleComponent extends React.Component<Props> {\r\n render(): JSX.Element;\r\n}\r\n"}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

.rpt2_cache/8a3a4b8794f010f6c396d85fe83d7c1eb5e8265d/types/cache/0c8d6b0779fc8dde9799c65e788028cff83373a4

Whitespace-only changes.

.rpt2_cache/8a3a4b8794f010f6c396d85fe83d7c1eb5e8265d/types/cache/1b8f57f67c79335f28773c6e47de33f164097d3f

Whitespace-only changes.

.rpt2_cache/8a3a4b8794f010f6c396d85fe83d7c1eb5e8265d/types/cache/1f0d3004567bfaf678d48a3ac7e0cd5ce4f833f3

Whitespace-only changes.

.rpt2_cache/8a3a4b8794f010f6c396d85fe83d7c1eb5e8265d/types/cache/81177a67853c1091552bdd4a46fbd646eb7bea80

Whitespace-only changes.

.rpt2_cache/8a3a4b8794f010f6c396d85fe83d7c1eb5e8265d/types/cache/8e67021bf05d92df6369c1fc280b133c3aa45ff1

Whitespace-only changes.

.rpt2_cache/8a3a4b8794f010f6c396d85fe83d7c1eb5e8265d/types/cache/92d5cfa90f7d396a5a68ddc5a8bc87a1c7ad415a

Whitespace-only changes.

.rpt2_cache/8a3a4b8794f010f6c396d85fe83d7c1eb5e8265d/types/cache/9fd7c61ee6cbf1c39f01ad78d9b5e68b63502b9e

Whitespace-only changes.

.rpt2_cache/8a3a4b8794f010f6c396d85fe83d7c1eb5e8265d/types/cache/c61ee26be027ba63dd5a056637c6521682912864

Whitespace-only changes.

.rpt2_cache/8a3a4b8794f010f6c396d85fe83d7c1eb5e8265d/types/cache/e73ed4c7ee96f40e4553ab3869d4ae5ffb8800fd

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"code":"/**\r\n * @class ExampleComponent\r\n */\r\nimport * as tslib_1 from \"tslib\";\r\nimport * as React from 'react';\r\nimport styles from './styles.css';\r\nvar ExampleComponent = /** @class */ (function (_super) {\r\n tslib_1.__extends(ExampleComponent, _super);\r\n function ExampleComponent() {\r\n return _super !== null && _super.apply(this, arguments) || this;\r\n }\r\n ExampleComponent.prototype.render = function () {\r\n var text = this.props.text;\r\n return (React.createElement(\"div\", { className: styles.test },\r\n \"Example Component: \",\r\n text));\r\n };\r\n return ExampleComponent;\r\n}(React.Component));\r\nexport default ExampleComponent;\r\n//# sourceMappingURL=index.js.map","map":"{\"version\":3,\"file\":\"index.js\",\"sourceRoot\":\"\",\"sources\":[\"src/index.tsx\"],\"names\":[],\"mappings\":\"AAAA;;GAEG;;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,MAAM,MAAM,cAAc,CAAA;AAIjC;IAA8C,4CAAsB;IAApE;;IAYA,CAAC;IAXC,iCAAM,GAAN;QAEI,IAAA,sBAAI,CACQ;QAEd,OAAO,CACL,6BAAK,SAAS,EAAE,MAAM,CAAC,IAAI;;YACL,IAAI,CACpB,CACP,CAAA;IACH,CAAC;IACH,uBAAC;AAAD,CAAC,AAZD,CAA8C,KAAK,CAAC,SAAS,GAY5D\"}","dts":{"name":"/Users/harrisrobin/Workspace/oss/react-sidesheet/index.d.ts","text":"/**\r\n * @class ExampleComponent\r\n */\r\nimport * as React from 'react';\r\nexport declare type Props = {\r\n text: string;\r\n};\r\nexport default class ExampleComponent extends React.Component<Props> {\r\n render(): JSX.Element;\r\n}\r\n"}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

.rpt2_cache/8dd609e57f801ecec0471d32e66fdffd75123f0e/types/cache/0c8d6b0779fc8dde9799c65e788028cff83373a4

Whitespace-only changes.

.rpt2_cache/8dd609e57f801ecec0471d32e66fdffd75123f0e/types/cache/1b8f57f67c79335f28773c6e47de33f164097d3f

Whitespace-only changes.

.rpt2_cache/8dd609e57f801ecec0471d32e66fdffd75123f0e/types/cache/1f0d3004567bfaf678d48a3ac7e0cd5ce4f833f3

Whitespace-only changes.

.rpt2_cache/8dd609e57f801ecec0471d32e66fdffd75123f0e/types/cache/81177a67853c1091552bdd4a46fbd646eb7bea80

Whitespace-only changes.

.rpt2_cache/8dd609e57f801ecec0471d32e66fdffd75123f0e/types/cache/92d5cfa90f7d396a5a68ddc5a8bc87a1c7ad415a

Whitespace-only changes.

.rpt2_cache/8dd609e57f801ecec0471d32e66fdffd75123f0e/types/cache/9fd7c61ee6cbf1c39f01ad78d9b5e68b63502b9e

Whitespace-only changes.

.rpt2_cache/8dd609e57f801ecec0471d32e66fdffd75123f0e/types/cache/c61ee26be027ba63dd5a056637c6521682912864

Whitespace-only changes.

.rpt2_cache/8dd609e57f801ecec0471d32e66fdffd75123f0e/types/cache/d79a3262d126fdddb1f16d3adbee6f26c4b232c1

Whitespace-only changes.

.rpt2_cache/8dd609e57f801ecec0471d32e66fdffd75123f0e/types/cache/e73ed4c7ee96f40e4553ab3869d4ae5ffb8800fd

Whitespace-only changes.

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"editor.formatOnSave": true
3+
}

package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,19 @@
2121
"predeploy": "cd example && yarn install && yarn run build",
2222
"deploy": "gh-pages -d example/build"
2323
},
24-
"dependencies": {},
24+
"dependencies": {
25+
"dom-helpers": "^3.3.1"
26+
},
2527
"peerDependencies": {
2628
"prop-types": "^15.5.4",
2729
"react": "^15.0.0 || ^16.0.0",
2830
"react-dom": "^15.0.0 || ^16.0.0"
2931
},
3032
"devDependencies": {
33+
"@cw-types/dom-helpers": "^3.0.0",
3134
"@types/jest": "^23.1.5",
3235
"@types/react": "^16.3.13",
33-
"@types/react-dom": "^16.0.5",
36+
"@types/react-dom": "^16.0.7",
3437
"babel-core": "^6.26.3",
3538
"babel-runtime": "^6.26.0",
3639
"cross-env": "^5.1.4",

src/portal.tsx

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import * as React from "react";
2+
import * as canUseDom from "dom-helpers/util/inDOM";
3+
import * as ReactDOM from "react-dom";
4+
5+
let portalContainer: HTMLElement;
6+
7+
interface Props {
8+
children: React.ReactNode;
9+
}
10+
11+
class Portal extends React.PureComponent<Props> {
12+
constructor(props: Props) {
13+
super(props);
14+
// This fixes SSR
15+
if (!canUseDom) return;
16+
17+
if (!portalContainer) {
18+
portalContainer = document.createElement("div");
19+
portalContainer.setAttribute("evergreen-portal-container", "");
20+
document.body.appendChild(portalContainer);
21+
}
22+
}
23+
24+
public static defaultProps: Props = {
25+
children: () => {}
26+
};
27+
28+
public static displayName = "react-sidesheet-portal";
29+
30+
el: HTMLElement = document.createElement("div");
31+
32+
public componentDidMount() {
33+
portalContainer.appendChild(this.el);
34+
}
35+
36+
public componentWillUnmount() {
37+
portalContainer.removeChild(this.el);
38+
}
39+
40+
public render() {
41+
// this fixes ssr
42+
if (!canUseDom) return null;
43+
44+
if (!this.props.children) throw new Error("children are mandatory!");
45+
46+
return ReactDOM.createPortal(this.props.children, this.el);
47+
}
48+
}
49+
50+
export default Portal;

src/side-sheet-manager.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import * as React from "react";

src/test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import ExampleComponent from './'
1+
import ExampleComponent from "./";
22

3-
describe('ExampleComponent', () => {
4-
it('is truthy', () => {
5-
expect(ExampleComponent).toBeTruthy()
6-
})
7-
})
3+
describe("ExampleComponent", () => {
4+
it("is truthy", () => {
5+
expect(ExampleComponent).toBeTruthy();
6+
});
7+
});

src/types/dom-helpers.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare module "dom-helpers/util/inDOM" {
2+
3+
}

tsconfig.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,9 @@
1919
"noUnusedParameters": true
2020
},
2121
"include": ["src"],
22-
"exclude": ["node_modules", "build", "dist", "example", "rollup.config.js"]
22+
"exclude": ["node_modules", "build", "dist", "example", "rollup.config.js"],
23+
"typeRoots": [
24+
"node_modules/@cw-types",
25+
"node_modules/@types"
26+
]
2327
}

yarn.lock

+9-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
esutils "^2.0.2"
1717
js-tokens "^4.0.0"
1818

19+
"@cw-types/dom-helpers@^3.0.0":
20+
version "3.0.0"
21+
resolved "https://registry.yarnpkg.com/@cw-types/dom-helpers/-/dom-helpers-3.0.0.tgz#6c6a0bb468af302849cde3b18576f924e88916fb"
22+
1923
"@types/estree@0.0.39":
2024
version "0.0.39"
2125
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f"
@@ -38,7 +42,7 @@
3842
dependencies:
3943
"@types/react" "*"
4044

41-
"@types/react-dom@^16.0.5":
45+
"@types/react-dom@^16.0.7":
4246
version "16.0.7"
4347
resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-16.0.7.tgz#54d0f867a76b90597e8432030d297982f25c20ba"
4448
dependencies:
@@ -2126,6 +2130,10 @@ dom-converter@~0.1:
21262130
dependencies:
21272131
utila "~0.3"
21282132

2133+
dom-helpers@^3.3.1:
2134+
version "3.3.1"
2135+
resolved "https://registry.yarnpkg.com/dom-helpers/-/dom-helpers-3.3.1.tgz#fc1a4e15ffdf60ddde03a480a9c0fece821dd4a6"
2136+
21292137
dom-serializer@0:
21302138
version "0.1.0"
21312139
resolved "https://registry.yarnpkg.com/dom-serializer/-/dom-serializer-0.1.0.tgz#073c697546ce0780ce23be4a28e293e40bc30c82"

0 commit comments

Comments
 (0)