Skip to content

Commit 1c2bd89

Browse files
committed
Initial commit
0 parents  commit 1c2bd89

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
npm-debug.log
3+
dist
4+
README.md
5+
package-lock.json

package.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "preact-shadow-root",
3+
"amdName": "Shadow",
4+
"version": "1.0.0",
5+
"description": "Render a Preact subtree into the Shadow DOM.",
6+
"source": "preact-shadow-root.js",
7+
"main": "dist/preact-shadow-root.js",
8+
"module": "dist/preact-shadow-root.es.js",
9+
"umd:main": "dist/preact-shadow-root.umd.js",
10+
"scripts": {
11+
"build": "microbundle",
12+
"prepare": "npm run -s build",
13+
"test": "eslint src && npm run -s build"
14+
},
15+
"eslintConfig": {
16+
"extends": "eslint-config-developit"
17+
},
18+
"files": [
19+
"preact-shadow-root.js",
20+
"dist"
21+
],
22+
"keywords": [
23+
"preact",
24+
"component",
25+
"shadow root",
26+
"shadow dom"
27+
],
28+
"author": "Jason Miller <[email protected]>",
29+
"license": "MIT",
30+
"devDependencies": {
31+
"eslint": "^4.6.1",
32+
"eslint-config-developit": "^1.1.1",
33+
"microbundle": "^0.3.1"
34+
},
35+
"peerDependencies": {
36+
"preact": "*"
37+
}
38+
}

preact-shadow-root.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { render } from 'preact';
2+
3+
/* Shadow Root component */
4+
export default class Shadow {
5+
shouldComponentUpdate(nextProps) {
6+
this.update(nextProps);
7+
return false;
8+
}
9+
componentDidMount() {
10+
let parent = this.base && this.base.parentNode;
11+
if (parent) {
12+
this.shadow = parent.attachShadow({ mode: 'open' });
13+
this.update(this.props);
14+
}
15+
}
16+
update(props) {
17+
render(props.children[0], this.shadow, this.shadow.firstChild);
18+
}
19+
render() {}
20+
}

0 commit comments

Comments
 (0)