multiple-select-vanilla
Version:
This lib allows you to select multiple elements with checkboxes
75 lines • 3.71 kB
TypeScript
import type { HtmlStruct, InferDOMType } from '../models/interfaces.js';
export interface HtmlElementPosition {
top: number;
bottom: number;
left: number;
right: number;
}
/** calculate available space for each side of the DOM element */
export declare function calculateAvailableSpace(element: HTMLElement): {
top: number;
bottom: number;
left: number;
right: number;
};
/**
* Accepts string containing the class or space-separated list of classes, and
* returns list of individual classes.
* Method properly takes into account extra whitespaces in the `className`
* e.g.: " class1 class2 " => will result in `['class1', 'class2']`.
* @param {String} className - space separated list of class names
*/
export declare function classNameToList(className?: string): string[];
/**
* Create a DOM Element with any optional attributes or properties.
* It will only accept valid DOM element properties that `createElement` would accept.
* For example: `createDomElement('div', { className: 'my-css-class' })`,
* for style or dataset you need to use nested object `{ style: { display: 'none' }}
* The last argument is to optionally append the created element to a parent container element.
* @param {String} tagName - html tag
* @param {Object} options - element properties
* @param {[HTMLElement]} appendToParent - parent element to append to
*/
export declare function createDomElement<T extends keyof HTMLElementTagNameMap, K extends keyof HTMLElementTagNameMap[T]>(tagName: T, elementOptions?: {
[P in K]: InferDOMType<HTMLElementTagNameMap[T][P]>;
}, appendToParent?: HTMLElement): HTMLElementTagNameMap[T];
/**
* From an HtmlBlock, create the DOM structure and append it to dedicated DOM element, for example:
* `{ tagName: 'li', props: { className: 'some-class' }, attrs: { 'aria-label': 'some label' }, children: [] }`
* @param item
* @param appendToElm
*/
export declare function createDomStructure(item: HtmlStruct, appendToElm?: HTMLElement, parentElm?: HTMLElement): HTMLElement;
/** takes an html block object and converts to a real HTMLElement */
export declare function convertItemRowToHtml(item: HtmlStruct): HTMLElement;
/**
* Empty a DOM element by removing all of its DOM element children leaving with an empty element (basically an empty shell)
* @return {object} element - updated element
*/
export declare function emptyElement<T extends Element = Element>(element?: T | null): T | undefined | null;
/** Get HTML element offset with pure JS */
export declare function getElementOffset(element?: HTMLElement): HtmlElementPosition | undefined;
export declare function getElementSize(elm: HTMLElement | undefined, mode: 'inner' | 'outer' | 'scroll', type: 'height' | 'width'): number;
/**
* Find a single parent by a simple selector, it only works with a simple selector
* for example: "input.some-class", ".some-class", "input#some-id"
* Note: it won't work with complex selector like "div.some-class input.my-class"
* @param elm
* @param selector
* @returns
*/
export declare function findParent(elm: HTMLElement, selector: string): HTMLElement | null;
export declare function insertAfter(referenceNode: HTMLElement, newNode: HTMLElement): void;
export declare function omitProp(obj: any, key: string): any;
/** Display or hide matched element */
export declare function toggleElement(elm?: HTMLElement | null, display?: boolean): void;
export declare function toggleElementClass(elm?: HTMLElement | null, state?: boolean): void;
/**
* Get the Window Scroll top/left Position
* @returns
*/
export declare function windowScrollPosition(): {
left: number;
top: number;
};
//# sourceMappingURL=domUtils.d.ts.map