4.4.9 • Published 8 months ago
@conectate/ct-lit v4.4.9
ct-lit
Enhanced wrapper for LitElement with additional utility methods.
Installation
npm install @conectate/ct-litUsage
ct-lit provides the CtLit class, which extends LitElement and adds useful utility methods. It also re-exports most commonly used functions and decorators from the lit library.
Basic Example
import { CtLit, html, customElement } from '@conectate/ct-lit';
@customElement('my-element')
export class MyElement extends CtLit {
render() {
return html`
<div>Hello World!</div>
`;
}
}Utility Methods Example
@customElement('my-element')
export class MyElement extends CtLit {
firstUpdated() {
// Select elements using simplified selectors
const button = this.$$('#myButton');
// Fire custom events easily
this.fire('element-ready', { status: 'ok' });
}
handleClick() {
// Helper for smooth scrolling
this.scrollToY(500, 800, 'easeInOutQuint');
}
render() {
return html`
<div>
<button id="myButton" @click=${this.handleClick}>Click me</button>
<!-- Conditional rendering helper -->
${If(this.showContent, html`<div>Additional content</div>`)}
</div>
`;
}
}API Reference
CtLit Class
Extends the LitElement class with additional utility methods.
Methods
| Method | Parameters | Return Type | Description |
|---|---|---|---|
$$ | name: string | HTMLElement \| Element \| undefined \| null | Returns the first element that matches the CSS selector |
$$$ | name: string | NodeListOf<HTMLElement \| Element> \| undefined | Returns all elements that match the CSS selector |
mapIDs | - | void | Maps all elements with IDs to this.$ (deprecated) |
deepClone | ob: T | T | Creates a deep clone of an object |
fire | name: string, value: any | void | Dispatches a CustomEvent with the given name and value |
scrollToY | scrollTargetY?: number, time?: number, easing?: string, target?: Element | void | Smoothly scrolls to a position on the page |
Helper Functions
| Function | Parameters | Return Type | Description |
|---|---|---|---|
If | condition: boolean, template: any | any | Conditionally renders a template |
Exports from Lit
The library re-exports the following from the lit library:
css,html,svg,unsafeCSSfromlitproperty,query,queryAll,queryAssignedNodes,queryAsync,statefromlit/decorators.jsunsafeHTMLfromlit/directives/unsafe-html.jsuntilfromlit/directives/until.jsLitElementfromlit
Decorators
| Decorator | Parameters | Description |
|---|---|---|
customElement | tagName: string | Defines a custom element |
License
MIT
4.4.9
8 months ago
4.3.0
11 months ago
4.0.0
1 year ago
3.9.0
2 years ago
3.8.1
2 years ago
3.11.0
2 years ago
3.8.0
2 years ago
3.10.0
2 years ago
3.12.0
2 years ago
3.7.5
3 years ago
3.7.4
3 years ago
3.7.3
3 years ago
3.7.1
3 years ago
3.7.0
3 years ago
3.6.0
4 years ago
3.5.0
4 years ago
3.4.0
4 years ago
3.2.1
5 years ago
3.2.0
5 years ago
3.1.0
5 years ago
3.0.0
5 years ago
1.4.0
5 years ago
1.1.1
5 years ago
1.1.0
6 years ago
1.0.3
6 years ago
1.0.2
6 years ago
1.0.1
6 years ago
1.0.0
7 years ago