feat(components): implement LangDropdown

This commit is contained in:
Walid 2023-05-04 16:13:24 +01:00
parent a2180bed42
commit 28ac1597c9
Signed by: Walidoux
GPG Key ID: CCF21881FE8BEBAF
2 changed files with 52 additions and 0 deletions

View File

@ -0,0 +1,51 @@
import type { Component } from 'solid-js'
import { createSignal, For } from 'solid-js'
import { Motion } from '@motionone/solid'
import { useLocalStorage } from '../../../hooks/useLocalStorage'
import { AnimateView, Flag } from '../../design'
import { OutSideEventHandler } from '../OutSideEventHandler'
import { Animation, SUPPORTED_LANGS } from '../../../config'
export const LangDropdown: Component = () => {
const { lang, setLang } = useLocalStorage()
let ref: HTMLDivElement | undefined
const [active, setActive] = createSignal(false)
return (
<OutSideEventHandler
class='relative text-sm'
onOutsideClick={() => {
return setActive(false)
}}>
<div
ref={ref}
class='cursor-pointer'
onclick={() => {
return setActive(!active())
}}>
Selected Lang: <Flag domain={lang()} />
</div>
<AnimateView condition={active()} class='absolute top-8 z-20' animation={Animation.fadeInOut()}>
<For each={SUPPORTED_LANGS}>
{(lang, index) => {
return (
<Motion.p
{...Animation.fadeInOut({ x: [50 / (index() + 1), 0, 0] })}
transition={{ delay: (index() + 1) / 15 }}
class='cursor-pointer'
onclick={() => {
setActive(false)
return setLang(lang.domain)
}}>
<Flag domain={lang.domain} label />
</Motion.p>
)
}}
</For>
</AnimateView>
</OutSideEventHandler>
)
}

View File

@ -0,0 +1 @@
export * from './LangDropdown'