2.8.0 • Published 2 years ago

@stool/dom v2.8.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@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

2.8.0

2 years ago

2.7.0

2 years ago

2.7.1

2 years ago

2.4.2

5 years ago

2.4.1

5 years ago

2.5.0

6 years ago

2.4.0

6 years ago

2.2.0

6 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago