Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Etch-a-sketch theme #454

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions examples/themes/etch.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width" />
<title>Media Chrome Etch-a-Sketch Theme</title>
<script type="module" src="../../dist/index.js"></script>
<script type="module" src="../../src/js/themes/media-theme-etch-a-sketch.js"></script>
</head>
<body>

<main>
<h1>Media Chrome Etch-a-Sketch Theme</h1>

<media-theme-etch-a-sketch>
<video
slot="media"
src="https://stream.mux.com/DS00Spx1CV902MCtPj5WknGlR102V5HFkDe/high.mp4"
crossorigin
muted
playsinline
></video>
</media-theme-etch-a-sketch>


</main>
</body>
</html>
11 changes: 9 additions & 2 deletions src/js/media-chrome-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,16 @@ class MediaChromeButton extends window.HTMLElement {
const mediaControllerId = this.getAttribute(
MediaStateReceiverAttributes.MEDIA_CONTROLLER
);

if (mediaControllerId) {
const mediaControllerEl = document.getElementById(mediaControllerId);
mediaControllerEl?.associateElement?.(this);
const rootNode = this.getRootNode();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to remember if there's any specific downsides to getRootNode. The TS parser at least doesn't like it when trying to use properties on it, so it needs to be ignored.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we'll need to replace document.getElementById with this.getRootNode().getElementById for themes to work nicely with a decoupled media controller


// @ts-ignore
if (rootNode?.getElementById) {
// @ts-ignore
const mediaControllerEl = rootNode.getElementById(mediaControllerId);
mediaControllerEl?.associateElement?.(this);
}
}
}

Expand Down
99 changes: 99 additions & 0 deletions src/js/themes/media-theme-etch-a-sketch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
<media-theme-etch-a-sketch>
<video
slot="media"
src="https://stream.mux.com/DS00Spx1CV902MCtPj5WknGlR102V5HFkDe/high.mp4"
></video>
</media-theme-etch-a-sketch>
*/

import { window } from '../utils/server-safe-globals.js';
import { MediaThemeElement } from '../media-theme-element.js';

const template = document.createElement('template');
template.innerHTML = `
<style>
* {
box-sizing: border-box;
}

.examples {
margin-top: 20px;
}

#playerContainer {
width: 1120px;
padding: 95px 80px 0 80px;
background-color: #FE5F5F;
border-radius: 24px;
box-shadow: 10px 5px 0px #900;
}

media-controller {
width: 960px;
height: 540px;
margin: 0px auto;
}

media-control-bar {
height: 35px;
padding: 0;
}

media-time-range, media-volume-range {
--media-range-padding: 0;

--media-range-bar-color: #ccc;
--thumb-height: 0;
--thumb-width: 0;
--track-height: 100%;
--track-width: 100%;
}

#knobs {
display: flex;
justify-content: space-between;
padding: 20px 0;
margin: 0 -50px 0 -50px;
}

.knob {
background-color: #DED9D9;
height: 95px;
width: 95px;
color: #000;
border-radius: 50px;
--media-icon-color: #000;
--media-button-icon-height: 35px;
box-shadow: 5px 5px 0px rgba(0,0,0,0.25);
}
</style>

<div id="playerContainer">
<media-controller id="etchController1">
<slot name="media" slot="media"></slot>
<media-control-bar>
<media-play-button></media-play-button>
<media-time-range></media-time-range>
<media-mute-button></media-mute-button>
<media-volume-range></media-volume-range>
</media-control-bar>
</media-controller>

<div id="knobs">
<media-play-button media-controller="etchController1" id="leftKnob" class="knob"></media-play-button>
<div id="title"></div>
<media-mute-button media-controller="etchController1" id="rightKnob" class="knob"></media-mute-button>
</div>
</div>
`;

class MediaThemeEtchASketch extends MediaThemeElement {
static template = template;
}

if (!window.customElements.get('media-theme-etch-a-sketch')) {
window.customElements.define('media-theme-etch-a-sketch', MediaThemeEtchASketch);
}

export default MediaThemeEtchASketch;