-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1c2bd89
Showing
3 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules | ||
npm-debug.log | ||
dist | ||
README.md | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"name": "preact-shadow-root", | ||
"amdName": "Shadow", | ||
"version": "1.0.0", | ||
"description": "Render a Preact subtree into the Shadow DOM.", | ||
"source": "preact-shadow-root.js", | ||
"main": "dist/preact-shadow-root.js", | ||
"module": "dist/preact-shadow-root.es.js", | ||
"umd:main": "dist/preact-shadow-root.umd.js", | ||
"scripts": { | ||
"build": "microbundle", | ||
"prepare": "npm run -s build", | ||
"test": "eslint src && npm run -s build" | ||
}, | ||
"eslintConfig": { | ||
"extends": "eslint-config-developit" | ||
}, | ||
"files": [ | ||
"preact-shadow-root.js", | ||
"dist" | ||
], | ||
"keywords": [ | ||
"preact", | ||
"component", | ||
"shadow root", | ||
"shadow dom" | ||
], | ||
"author": "Jason Miller <jason@developit.ca>", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"eslint": "^4.6.1", | ||
"eslint-config-developit": "^1.1.1", | ||
"microbundle": "^0.3.1" | ||
}, | ||
"peerDependencies": { | ||
"preact": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { render } from 'preact'; | ||
|
||
/* Shadow Root component */ | ||
export default class Shadow { | ||
shouldComponentUpdate(nextProps) { | ||
this.update(nextProps); | ||
return false; | ||
} | ||
componentDidMount() { | ||
let parent = this.base && this.base.parentNode; | ||
if (parent) { | ||
this.shadow = parent.attachShadow({ mode: 'open' }); | ||
this.update(this.props); | ||
} | ||
} | ||
update(props) { | ||
render(props.children[0], this.shadow, this.shadow.firstChild); | ||
} | ||
render() {} | ||
} |