Switch to vite and preact

This commit is contained in:
Misode
2021-06-23 20:44:28 +02:00
parent e551b7ef75
commit 09c851914f
89 changed files with 6398 additions and 15531 deletions

View File

@@ -0,0 +1,34 @@
import type { ComponentChildren } from 'preact'
import { useEffect, useState } from 'preact/hooks'
import type { Octicon } from '.'
import { Btn } from '.'
type BtnMenuProps = {
icon?: keyof typeof Octicon,
label?: string,
relative?: boolean,
children: ComponentChildren,
}
export function BtnMenu({ icon, label, relative, children }: BtnMenuProps) {
const [active, setActive] = useState(false)
const hider = () => {
setActive(false)
}
useEffect(() => {
if (active) {
document.body.addEventListener('click', hider)
}
return () => {
document.body.removeEventListener('click', hider)
}
}, [active])
return <div class={`btn-menu${relative === false ? ' no-relative' : ''}`}>
<Btn icon={icon} label={label} onClick={() => setActive(true)} />
{active && <div class="btn-group">
{children}
</div>}
</div>
}