Skip to content

Commit

Permalink
control/anchor with semantic type names replace state/useAnchor
Browse files Browse the repository at this point in the history
Stassi committed Nov 15, 2024
1 parent c99fed1 commit a9e99f1
Showing 2 changed files with 45 additions and 40 deletions.
45 changes: 45 additions & 0 deletions src/leaf/map/fullscreen/control/anchor/anchor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { DomEvent } from 'leaflet'

export type ControlAnchorAttributes = Record<string, string>
export type ControlAnchorOptions = {
attributes: ControlAnchorAttributes
element: HTMLElement
}

type ControlAnchorOnClickHandler = (event: Event) => Promise<void>
export type ControlAnchorOnClick = (
handler: ControlAnchorOnClickHandler,
) => void
export type ControlAnchorAssign = (
props: ControlAnchorAttributes,
) => HTMLElement
export type ControlAnchor = {
assign: ControlAnchorAssign
onClick: ControlAnchorOnClick
}

const domEventOn = <
(
el: HTMLElement,
types: string,
fn: ControlAnchorOnClickHandler,
) => typeof DomEvent
>DomEvent.on

export function controlAnchor({
attributes,
element,
}: ControlAnchorOptions): ControlAnchor {
function assign(anchorAttributes: ControlAnchorAttributes): HTMLElement {
return Object.assign(element, anchorAttributes)
}

assign(attributes)

return {
assign,
onClick(handler: ControlAnchorOnClickHandler): void {
domEventOn(element, 'click', handler)
},
}
}
40 changes: 0 additions & 40 deletions src/leaf/map/fullscreen/state/use-anchor.ts

This file was deleted.

0 comments on commit a9e99f1

Please sign in to comment.