2.8.0 • Published 2 years ago
@stool/dom v2.8.0
@stool/dom
DOM helpers.
Install
npm install @stool/dom
Using
ready()
Waiting for DOM ready.
declare function ready(): Promise<void>;
import { ready } from '@stool/dom';
async function boot(){
await ready();
// ...
}
classNames()
Conditionally joining classNames together.
declare function findParent(element: HTMLElement, selector: string): HTMLElement | null;
classNames('foo', 'bar'); // 'foo bar'
classNames('foo', { bar: true }); // 'foo bar'
classNames({ 'foo-bar': false }); // ''
classNames({ 'foo-bar': true }); // 'foo-bar'
classNames({ foo: true }, { bar: true }); // 'foo bar'
classNames(null, false, 'foo', undefined, 0, 1, { baz: null }, ''); // 'foo 1'
findParentNode()
Find parent of element using selector.
declare function findParent(element: HTMLElement, selector: string): HTMLElement|null;
const container = findParent(element, '.container');
fromEvent()
Create event stream base on Observable.
function fromEvent(element: HTMLElement, eventName: string): Observable
cosnt subscription = fromEvent(element, "keydown").subscribe(event => {
console.log(event);
});
// ...
subscription.unsubscribe();
@see: proposal-observable zen-observer
Import style(s) to
document
.
function importStyles(styles: string[] | string, name: string = '@stool/dom'): () => void
License
MIT