Web Component
Define a custom element with defineElement.
tsx
import { defineElement, Host, Slot, state } from '@zeus-js/zeus'
defineElement(
'z-counter',
{
shadow: false,
props: {
initialCount: Number,
},
},
props => {
const count = state(props.initialCount ?? 0)
return (
<Host>
<button onClick={() => count.value++}>count: {count.value}</button>
<p>
<Slot />
</p>
</Host>
)
},
)Usage in HTML:
html
<z-counter initial-count="10"> This is slotted content </z-counter>
<script type="module" src="/src/main.tsx"></script>Key concepts
defineElementregisters a custom elementHostrepresents the custom element itselfSlotprojects light DOM or shadow DOM contentpropsare reactive and typed