diff --git a/src/leaf/map/fullscreen/state/use-boolean.ts b/src/leaf/map/fullscreen/state/use-boolean.ts new file mode 100644 index 0000000..02eebfa --- /dev/null +++ b/src/leaf/map/fullscreen/state/use-boolean.ts @@ -0,0 +1,16 @@ +export type UseBoolean = { + get: () => boolean + toggle: () => void +} + +export function useBoolean(initialValue: boolean): UseBoolean { + let state: boolean = initialValue + return { + get(): boolean { + return state + }, + toggle(): void { + state = !state + }, + } +} diff --git a/src/leaf/map/fullscreen/state/use-link.ts b/src/leaf/map/fullscreen/state/use-link.ts new file mode 100644 index 0000000..b3aa704 --- /dev/null +++ b/src/leaf/map/fullscreen/state/use-link.ts @@ -0,0 +1,34 @@ +import { DomEvent } from 'leaflet' + +export type UseLinkOptions = { + element: HTMLAnchorElement + initialProps: Record +} + +export type UseLink = { + onClick: (handler: (event: Event) => Promise) => void + assign: (props: Record) => HTMLAnchorElement +} + +const domEventOn = < + ( + el: HTMLElement, + types: string, + fn: (event: Event) => Promise, + ) => typeof DomEvent +>DomEvent.on + +export function useLink({ element, initialProps }: UseLinkOptions): UseLink { + function assign(props: Record): HTMLAnchorElement { + return Object.assign(element, props) + } + + assign(initialProps) + + return { + assign, + onClick(handler: (event: Event) => Promise): void { + domEventOn(element, 'click', handler) + }, + } +}