-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
control/anchor
with semantic type names replace state/useAnchor
Showing
2 changed files
with
45 additions
and
40 deletions.
There are no files selected for viewing
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
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) | ||
}, | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.