UNPKG

@tempots/ui

Version:

Provides a higher level of renderables to help fast development with Tempo.

51 lines (50 loc) 2.53 kB
import { Merge } from '@tempots/std'; /** * Get the extension of a pathname. If the pathname has no extension, return undefined. * The path should not have query parameters or fragments. * * @param pathname - The pathname to get the extension from. * @returns The extension of the pathname or undefined if there is no extension. * @internal */ export declare const _getExtension: (pathname: string) => string | undefined; /** * @internal */ export declare const _checkExtensionCondition: (allowedExtensions: string[], pathname: string) => boolean; /** * Options for handling anchor click events. * @public */ export type HandleAnchorClickOptions = Merge<{ /** * A boolean indicating whether to check the anchor's href for a file extension. * If `true`, the click handler will be applied only if the anchor's href doesn't have a file extension or if the anchor's href has a file extension that is in the `allowedExtensions` array. */ ignoreUrlWithExtension?: true; /** * An array of allowed extensions to check for. If the anchor's href has a file extension that is not in the `allowedExtensions` array, the click handler will not be applied. * If the `allowedExtensions` array is empty, the click handler will only be applied if the anchor's href doesn't have a file extension. */ allowedExtensions?: string[]; } | { /** * A boolean indicating whether to check the anchor's href for a file extension. * If `true`, the click handler will be applied only if the anchor's href doesn't have a file extension or if the anchor's href has a file extension that is in the `allowedExtensions` array. */ ignoreUrlWithExtension: false; }, { /** * A boolean indicating whether to check if the anchor's href points to an external URL. */ ignoreExternalUrl?: boolean; }>; /** * Handles anchor click events, optionally checking for external URLs and file extensions. * * @param callback - A function that is called when the anchor click should be handled. The function should return a boolean indicating whether the default anchor click behavior should be prevented. * @param options - An optional object of type `HandleAnchorClickOptions`. * @returns A function that handles the anchor click event, calling the provided callback and preventing the default behavior if the callback returns `true`. * @public */ export declare const handleAnchorClick: (callback: () => boolean, options?: HandleAnchorClickOptions) => (e: MouseEvent) => void;