Skip to content
New issue

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

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

Already on GitHub? # to your account

HMILayout via slotchange #41

Draft
wants to merge 3 commits into
base: feature/add-tmplits-hmilayout
Choose a base branch
from

Conversation

shanereetz
Copy link
Contributor

What

This a proof of concept / alternative strategy for Sanh's project, for learning and discussion purposes.

This demo shows how to change which content goes into a slot dynamically, by changing the slot attribute's value on various content fed into the component.

Content is put into the component, representing tabbed content. These divs are marked with the attribute/value slot="list". Selecting on this yields a list of pages to make navigation for.

The component's template has a content slot set aside for the active page ( slot="content" ). When the buttons for various pages are selected, that then reassigns the slot attributes for the tabbed areas.

This concept is based on MDN Web Components example "slotchange" https://github.com/mdn/web-components-examples/blob/main/slotchange/main.js

Why

Exploring other ways to "swap" what content goes into a given slot.

});

if (+templatesIndex < divs.length) {
divs[templatesIndex].setAttribute('slot', 'content')
Copy link
Contributor Author

@shanereetz shanereetz Jan 24, 2024

Choose a reason for hiding this comment

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

The crux of this approach: setting this attribute causes this div to be displayed inside <div class="tmplit-main-content">, because that div contains the content slot.


<template title="Button 2">
<div slot="list" title="Button 1">
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are some downsides to using divs here instead of templates (harder to of select only visible things)

{{!-- <h1>Cosntent 3</h1> --}}
</div>

<footer slot="footer">
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using footer tag here for readability, and convenience of selection

navBarLoc ==='right' ? 'tmplit-navBar-container-right tmplit-navBar-container-width-size' :
navBarLoc ==='top' ? 'tmplit-navBar-container-top tmplit-navBar-container-height-size' :
navBarLoc ==='bottom' ? 'tmplit-navBar-container-bottom tmplit-navBar-container-height-size' :
${navBarLoc === 'left' ? 'tmplit-navBar-container-left tmplit-navBar-container-width-size' :
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These lines are my auto-formatter's doing, sorry.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant