-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from tomhazledine/web-component
Web component
- Loading branch information
Showing
12 changed files
with
220 additions
and
15 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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,90 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<title>Picobel.js Test Page</title> | ||
|
||
<!-- Load the Picobel CSS --> | ||
<link | ||
rel="stylesheet" | ||
href="../src/css/picobel.all.css" | ||
type="text/css" | ||
/> | ||
</head> | ||
<body style="font-family: sans-serif"> | ||
<nav> | ||
<ul> | ||
<li><a href="index.html">Home</a></li> | ||
<li> | ||
<a href="composable.html">Composable</a> | ||
</li> | ||
<li><a href="types.html">Types</a></li> | ||
<li><a href="types.html">Manual</a></li> | ||
<li>Web Component</li> | ||
</ul> | ||
</nav> | ||
|
||
<div class="generic-wrapper"> | ||
<h1>Testing Picobel: web component</h1> | ||
<h2> | ||
<code><picobel-player></code> loaded with no inbuilt | ||
styles | ||
</h2> | ||
|
||
<picobel-player class="foo"> | ||
<audio | ||
src="https://eatenbymonsters.com/audio/christmas/web/MasterSlashSlave_AllIWantForChristmas.mp3" | ||
title="All I Want for Christmas" | ||
data-artist="Master Slash Slave" | ||
controls | ||
> | ||
Your browser does not support the | ||
<code>audio</code> element. | ||
</audio> | ||
</picobel-player> | ||
|
||
<h2> | ||
<code><picobel-player-default></code> loaded (the | ||
"default" theme) | ||
</h2> | ||
|
||
<picobel-player-default> | ||
<audio | ||
src="https://eatenbymonsters.com/audio/christmas/web/MasterSlashSlave_AllIWantForChristmas.mp3" | ||
title="All I Want for Christmas" | ||
data-artist="Master Slash Slave" | ||
controls | ||
> | ||
Your browser does not support the | ||
<code>audio</code> element. | ||
</audio> | ||
</picobel-player-default> | ||
|
||
<h2> | ||
<code><picobel-player></code> loaded with | ||
<code>data-theme="skeleton"</code> and external stylesheet | ||
</h2> | ||
|
||
<picobel-player data-theme="skeleton"> | ||
<audio | ||
src="https://eatenbymonsters.com/audio/christmas/web/MasterSlashSlave_AllIWantForChristmas.mp3" | ||
title="All I Want for Christmas" | ||
data-artist="Master Slash Slave" | ||
controls | ||
> | ||
Your browser does not support the | ||
<code>audio</code> element. | ||
</audio> | ||
</picobel-player> | ||
</div> | ||
|
||
<script | ||
type="text/javascript" | ||
src="../build/picobel-component.js" | ||
></script> | ||
<script | ||
type="text/javascript" | ||
src="../build/picobel-component-default.js" | ||
></script> | ||
</body> | ||
</html> |
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
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
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
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
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,36 @@ | ||
import { picobel } from "./Picobel.js"; | ||
|
||
import styles from "../../build/picobel.default.css"; | ||
|
||
// Create a class for the element | ||
class PicobelWC extends HTMLElement { | ||
constructor() { | ||
super(); | ||
} | ||
|
||
mountStyles(theme = "default") { | ||
const styleId = `picobel-styles-${theme}`; | ||
if (!document.getElementById(styleId)) { | ||
const styleEl = document.createElement("style"); | ||
styleEl.id = styleId; | ||
// styleEl.textContent = styles[theme]; | ||
styleEl.textContent = styles; | ||
document.head.appendChild(styleEl); | ||
} | ||
} | ||
|
||
connectedCallback() { | ||
const theme = this.getAttribute("data-theme") || "default"; | ||
const options = { theme, context: this }; | ||
const components = this.getAttribute("data-components"); | ||
if (components) { | ||
options.components = JSON.parse(components); | ||
} | ||
picobel(options); | ||
this.mountStyles(theme); | ||
} | ||
} | ||
|
||
if (typeof window !== "undefined" && "customElements" in window) { | ||
window.customElements.define("picobel-player-default", PicobelWC); | ||
} |
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,24 @@ | ||
import { picobel } from "./Picobel.js"; | ||
|
||
// Create a class for the element | ||
class PicobelWC extends HTMLElement { | ||
constructor() { | ||
super(); | ||
} | ||
|
||
connectedCallback() { | ||
const className = this.classList[0] || "default"; | ||
const theme = this.getAttribute("data-theme") || className; | ||
console.log({ theme }); | ||
const options = { theme, context: this }; | ||
const components = this.getAttribute("data-components"); | ||
if (components) { | ||
options.components = JSON.parse(components); | ||
} | ||
picobel(options); | ||
} | ||
} | ||
|
||
if (typeof window !== "undefined" && "customElements" in window) { | ||
window.customElements.define("picobel-player", PicobelWC); | ||
} |
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,36 @@ | ||
import { picobel } from "./Picobel.js"; | ||
|
||
import styles from "../../build/picobel.skeleton.css"; | ||
|
||
// Create a class for the element | ||
class PicobelWC extends HTMLElement { | ||
constructor() { | ||
super(); | ||
} | ||
|
||
mountStyles(theme = "skeleton") { | ||
const styleId = `picobel-styles-${theme}`; | ||
if (!document.getElementById(styleId)) { | ||
const styleEl = document.createElement("style"); | ||
styleEl.id = styleId; | ||
// styleEl.textContent = styles[theme]; | ||
styleEl.textContent = styles; | ||
document.head.appendChild(styleEl); | ||
} | ||
} | ||
|
||
connectedCallback() { | ||
const theme = this.getAttribute("data-theme") || "skeleton"; | ||
const options = { theme, context: this }; | ||
const components = this.getAttribute("data-components"); | ||
if (components) { | ||
options.components = JSON.parse(components); | ||
} | ||
picobel(options); | ||
this.mountStyles(theme); | ||
} | ||
} | ||
|
||
if (typeof window !== "undefined" && "customElements" in window) { | ||
window.customElements.define("picobel-player-skeleton", PicobelWC); | ||
} |