Skip to content

Commit

Permalink
Merge pull request #523 from luwes/template-prop
Browse files Browse the repository at this point in the history
fix: allow setting theme template via property
  • Loading branch information
luwes authored Dec 15, 2022
2 parents 29f41f3 + 721aefb commit 607dba1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
16 changes: 15 additions & 1 deletion packages/mux-player/src/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,19 @@ export function processPropertyIdentity(part: Part, value: unknown): boolean {
return true;
}

export function processElementAttribute(part: Part, value: unknown): boolean {
// This allows us to set the media-theme template property directly.
if (part instanceof AttrPart && value instanceof Element) {
const element = part.element as any;
if (element[part.attributeName] !== value) {
part.element.removeAttributeNS(part.attributeNamespace, part.attributeName);
element[part.attributeName] = value;
}
return true;
}
return false;
}

export function processBooleanAttribute(part: Part, value: unknown): boolean {
if (
typeof value === 'boolean' &&
Expand All @@ -100,7 +113,8 @@ export function processBooleanNode(part: Part, value: unknown): boolean {
}

export function processPart(part: Part, value: unknown): void {
processBooleanAttribute(part, value) ||
processElementAttribute(part, value) ||
processBooleanAttribute(part, value) ||
processEvent(part, value) ||
processBooleanNode(part, value) ||
processSubTemplate(part, value) ||
Expand Down
3 changes: 1 addition & 2 deletions packages/mux-player/src/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export const template = (props: MuxTemplateProps) => html`
<style>
${cssStr}
</style>
${muxTemplate.content.cloneNode(true)}
${content(props)}
`;

Expand Down Expand Up @@ -50,7 +49,7 @@ const getHotKeys = (props: MuxTemplateProps) => {

export const content = (props: MuxTemplateProps) => html`
<media-theme
template="${props.theme ?? 'media-theme-mux'}"
template="${props.theme ?? muxTemplate.content.children[0]}"
class="size-${props.playerSize}${props.secondaryColor ? ' two-tone' : ''}"
player-size="${props.playerSize ?? false}"
layout="${getLayout(props)}"
Expand Down
8 changes: 4 additions & 4 deletions packages/mux-player/test/template.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('<mux-player> template render', () => {
assert.equal(
normalizeAttributes(minify(div.innerHTML)),
normalizeAttributes(
`<media-theme template="media-theme-mux" class="size-" default-showing-captions="" disabled="" nohotkeys="" layout="on-demand" exportparts="${exportParts}"><mux-video slot="media" crossorigin="" playsinline="" exportparts="video"></mux-video><mxp-dialog no-auto-hide=""><p></p></mxp-dialog></media-theme>`
`<media-theme class="size-" default-showing-captions="" disabled="" nohotkeys="" layout="on-demand" exportparts="${exportParts}"><mux-video slot="media" crossorigin="" playsinline="" exportparts="video"></mux-video><mxp-dialog no-auto-hide=""><p></p></mxp-dialog></media-theme>`
)
);
});
Expand All @@ -36,7 +36,7 @@ describe('<mux-player> template render', () => {
assert.equal(
normalizeAttributes(minify(div.innerHTML)),
normalizeAttributes(
`<media-theme hotkeys=" noarrowleft noarrowright" template="media-theme-mux" class="size-extra-small" layout="live extra-small" player-size="extra-small" default-showing-captions="" disabled="" nohotkeys="" exportparts="${exportParts}"><mux-video slot="media" crossorigin="" playsinline="" stream-type="live" cast-stream-type="live" exportparts="video"></mux-video><button aria-disabled="true" disabled="" slot="seek-live" part="top seek-live button">\n \n Live\n </button><mxp-dialog no-auto-hide="" open=""><h3>Errr</h3><p></p></mxp-dialog></media-theme>`
`<media-theme hotkeys=" noarrowleft noarrowright" class="size-extra-small" layout="live extra-small" player-size="extra-small" default-showing-captions="" disabled="" nohotkeys="" exportparts="${exportParts}"><mux-video slot="media" crossorigin="" playsinline="" stream-type="live" cast-stream-type="live" exportparts="video"></mux-video><button aria-disabled="true" disabled="" slot="seek-live" part="top seek-live button">\n \n Live\n </button><mxp-dialog no-auto-hide="" open=""><h3>Errr</h3><p></p></mxp-dialog></media-theme>`
)
);
});
Expand All @@ -54,7 +54,7 @@ describe('<mux-player> template render', () => {
assert.equal(
normalizeAttributes(minify(div.innerHTML)),
normalizeAttributes(
`<media-theme template="media-theme-mux" class="size-large" default-showing-captions="" disabled="" nohotkeys="" layout="on-demand large" player-size="large" exportparts="${exportParts}"><mux-video slot="media" crossorigin="" playsinline="" stream-type="on-demand" exportparts="video"></mux-video><mxp-dialog no-auto-hide=""><p></p></mxp-dialog></media-theme>`
`<media-theme class="size-large" default-showing-captions="" disabled="" nohotkeys="" layout="on-demand large" player-size="large" exportparts="${exportParts}"><mux-video slot="media" crossorigin="" playsinline="" stream-type="on-demand" exportparts="video"></mux-video><mxp-dialog no-auto-hide=""><p></p></mxp-dialog></media-theme>`
)
);
});
Expand All @@ -76,7 +76,7 @@ describe('<mux-player> template render', () => {
assert.equal(
normalizeAttributes(minify(div.innerHTML)),
normalizeAttributes(
`<media-theme template="media-theme-mux" class="size-large" layout="on-demand large" player-size="large" default-showing-captions="" disabled="" nohotkeys="" exportparts="${exportParts}"><mux-video slot="media" crossorigin="" playsinline="" stream-type="on-demand" exportparts="video"></mux-video><mxp-dialog no-auto-hide="" open=""><h3>Errr</h3><p></p></mxp-dialog></media-theme>`
`<media-theme class="size-large" layout="on-demand large" player-size="large" default-showing-captions="" disabled="" nohotkeys="" exportparts="${exportParts}"><mux-video slot="media" crossorigin="" playsinline="" stream-type="on-demand" exportparts="video"></mux-video><mxp-dialog no-auto-hide="" open=""><h3>Errr</h3><p></p></mxp-dialog></media-theme>`
)
);
});
Expand Down

4 comments on commit 607dba1

@vercel
Copy link

@vercel vercel bot commented on 607dba1 Dec 15, 2022

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

elements-demo-vanilla – ./examples/vanilla-ts-esm

elements-demo-vanilla-mux.vercel.app
elements-demo-vanilla-git-main-mux.vercel.app
elements-demo-vanilla.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 607dba1 Dec 15, 2022

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

elements-demo-create-react-app – ./examples/create-react-app-with-typescript

elements-demo-create-react-app-git-main-mux.vercel.app
elements-demo-create-react-app.vercel.app
elements-demo-create-react-app-mux.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 607dba1 Dec 15, 2022

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

elements-demo-nextjs – ./examples/nextjs-with-typescript

elements-demo-nextjs.vercel.app
elements-demo-nextjs-git-main-mux.vercel.app
elements-demo-nextjs-mux.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 607dba1 Dec 15, 2022

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

elements-demo-vue – ./examples/vue-with-typescript

elements-demo-vue-git-main-mux.vercel.app
elements-demo-vue-mux.vercel.app
elements-demo-vue.vercel.app

Please sign in to comment.