-
Notifications
You must be signed in to change notification settings - Fork 0
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
<define-element> #60
Comments
I can't justify the amount of layout shift caused by this approach in bigger html, it just too much! Better to wait for declarative syntax being part of HTML5 engine. Otherwise, just use template engine or site generator. |
Still cause layout shift but I think this is cool alternative (inspired from strawberry framework) <awesome-button>singleton burton</awesome-button>
<render-scope>
<link let=animate href=random-animation.js css.var="random duration">
<template shadowrootmode=closed>
<cool-button instance=false>singleton Brrr</cool-button>
<awesome-button instance> instanced burton</awesome-button>
<cool-button>instanced Brrr</cool-button>
</template>
<template instance define=cool-button use=animate>
<button style="
padding: 0.5rem 1rem;
border: 2px solid black;
border-radius: 0px;
box-shadow: 4px 4px 0px gray;
animation: var(--animate\.random);
animation-duration: var(--animate\.duration);
"
disabled ~ !disabled
@click=animate.shuffle
><slot /></button>
</template>
<template global define=awesome-button>
<cool-button>
<slot /> is awesome with <span ~ #text=animate.random /> animation
</cool-button>
</template>
</render-scope> By default, each custom-element defined inside render-scope will use the same instance of all linked modules. To make each custom-element unique, I'm going to reopen this. |
Declarative <render-scope>
<link let=c href=counter.js>
<template shadowrootmode=closed>
<div ~ !hidden>loading...</div>
<my-counter hidden ~ !hidden count=0></my-counter>
</template>
<template instance define=my-counter>
<button ~ @click=c.increment>$count</button>
<input value=$count ~ @change=set:c.count .value=c.count>
</template>
</render-scope> Another alternative would be to use manual slot assignment on named slot.
<render-scope>
<link let=c href=counter.js>
<template shadowrootmode=closed>
<slot name=counter count=0></slot>
</template>
<div #instance slot=counter style=display:contents>
<button ~ @click=c.increment>$count</button>
<input value=$count ~ @change=set:c.count .value=c.count>
</div>
</render-scope> ⬇️ Downside:
Solution:
<render-scope>
<link let=c href=counter.js>
<template shadowrootmode=closed>
<slot name=counter $count=0 ~ .$suffix=c.count>Parent is</slot>
</template>
<div #instance slot=counter style=display:contents>
<slot></slot> <span ~ #text=$suffix></span>
<button ~ @click=c.increment #text=$count>loading...</button>
<input value="loading..." ~ @change=set:c.count .value="$count~>c.count">
</div>
</render-scope>
All children inside |
I guess layout shift bound to be inevitable due to engine limitation 😅 Let's keep the <render-scope>
<link let=c href=counter.js>
<template shadowrootmode=closed>
<my-counter count=0 hidden ~ !hidden .suffix=c.count>Parent is</my-counter>
</template>
<template -let=prop -instance -define=my-counter>
<slot></slot> <prop.suffix/>
<button ~ @click=c.increment><prop.count/></button>
<input value=prop.count ~ @change=set:c.count .value=c.count>
</template>
</render-scope> |
Has same signature as
<render-scope>
but for defining a custom-element.It only fetch then apply linked modules when the custom-element is in view.
TODO
extends
from existingHTML<*>Element
slotchange
Related
Declarative Syntax for Custom Elements (strawman proposal)
Maybe partially rewriting the current implementation as module 🤔
The text was updated successfully, but these errors were encountered: