Last active
December 12, 2023 21:15
-
-
Save reggi/a4bc79ec03b9cdb1ee9fd6c61ee8e081 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { WebComponent, html } from 'web-component-base' | |
class HFrag extends WebComponent { | |
static props = { | |
as: 'h1', | |
hover: false | |
} | |
text: string | |
constructor () { | |
super() | |
this.text = this.textContent | |
} | |
get template() { | |
const id = this.text | |
.match(/[A-Z]?[a-z]+|[0-9]+/g) | |
.join('-') | |
.toLowerCase() | |
const addWidth = this.props.hover ? 'width:40px;' : '' | |
return html` | |
<${this.props.as}> | |
<a | |
style="display:flex" | |
href="#${id}" | |
onMouseOver=${() => this.props.hover = true } | |
onMouseOut=${() => this.props.hover = false }> | |
<span style="overflow:hidden;width:0;transition: width 0.3s;${addWidth}">🔗</span> | |
<span>${this.text}</span> | |
</a> | |
</${this.props.as}> | |
`; | |
} | |
} | |
customElements.define('h-frag', HFrag) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment