@medyll/idae-be
Version:
A modern, lightweight, and extensible DOM manipulation library built with TypeScript. Designed for precise element targeting and manipulation using a callback-based approach. Features include advanced DOM traversal, event handling, style management, attri
84 lines (83 loc) • 3.2 kB
TypeScript
import { Be } from '../be.js';
import type { CombineElements, CommonHandler, HandlerCallBackFn } from '../types.js';
declare enum classesMethods {
add = "add",
remove = "remove",
toggle = "toggle",
replace = "replace"
}
export type ClassHandlerHandler = {
add?: string | string[];
remove?: CombineElements<string> | string[];
toggle?: CombineElements<string> | string[];
replace?: `${string} ${string}` | [string, string][];
};
export type ClassHandlerHandlerHandle = {
add?: CombineElements<string> | string[];
callback?: HandlerCallBackFn;
} & {
remove?: CombineElements<string> | string[];
callback?: HandlerCallBackFn;
} & {
toggle?: CombineElements<string> | string[];
callback?: HandlerCallBackFn;
} & {
replace?: `${string} ${string}` | [string, string][];
callback?: HandlerCallBackFn;
};
/**
* Handles class operations for Be elements.
*/
export declare class ClassesHandler implements CommonHandler<ClassesHandler, ClassHandlerHandlerHandle> {
private beElement;
static methods: classesMethods[];
constructor(beElement: Be);
methods: string[] | keyof ClassesHandler;
valueOf(): string;
handle(actions: ClassHandlerHandlerHandle): Be;
/**
* Adds one or more classes to the element(s).
* @param className - The class or classes to add.
* @returns The Be instance for method chaining.
* @example
* // HTML: <div id="test"></div>
* const beInstance = be('#test');
* beInstance.addClass('highlight'); // Adds a single class
* beInstance.addClass(['highlight', 'active']); // Adds multiple classes
*/
add(className: string | string[]): Be;
/**
* Toggles a class on the element(s).
* @param className - The class or classes to toggle.
* @returns The Be instance for method chaining.
* @example
* // HTML: <div id="test" class="highlight"></div>
* const beInstance = be('#test');
* beInstance.toggleClass('highlight'); // Removes the "highlight" class
* beInstance.toggleClass('active'); // Adds the "active" class
*/
toggle(className: string | string[]): Be;
/**
* Replaces a class on the element(s) with another class.
* @param sourceClassName - The class to replace.
* @param targetClassName - The class to replace it with.
* @returns The Be instance for method chaining.
* @example
* // HTML: <div id="test" class="old-class"></div>
* const beInstance = be('#test');
* beInstance.replaceClass('old-class', 'new-class'); // Replaces "old-class" with "new-class"
*/
replace(sourceClassName: string, targetClassName: string): Be;
/**
* Removes one or more classes from the element(s).
* @param className - The class or classes to remove.
* @returns The Be instance for method chaining.
* @example
* // HTML: <div id="test" class="highlight active"></div>
* const beInstance = be('#test');
* beInstance.removeClass('highlight'); // Removes the "highlight" class
* beInstance.removeClass(['highlight', 'active']); // Removes multiple classes
*/
remove(className: string | string[]): Be;
}
export {};