@11thdeg/cn-d20-ability-score
Version:
A custom element for displaying D&D 5e ability scores.
45 lines (44 loc) • 1.61 kB
TypeScript
import { LitElement, type TemplateResult } from 'lit';
/**
* A D&D 5e ability score component that can be a display or an input.
*
* @element cn-d20-ability-score
* @prop {number} base - The base ability score. Defaults to 10.
* @prop {string} label - Optional label text displayed above the ability score (e.g., "STR", "DEX"). Defaults to empty.
* @prop {boolean} interactive - If true, renders as an input field. Defaults to false.
* @prop {number} min - The minimum allowed score in interactive mode. Defaults to 1.
* @prop {number} max - The maximum allowed score in interactive mode. Defaults to 30.
* @fires score-change - Dispatched when the score is changed in interactive mode, containing the base and modifier in the detail.
*/
export declare class CnD20AbilityScore extends LitElement {
base: number;
interactive: boolean;
min: number;
max: number;
label: string;
static styles: import("lit").CSSResult;
/**
* Calculates the D&D 5e ability modifier.
* @returns {number} The calculated modifier.
*/
private _calculateModifier;
/**
* Handles input changes, clamps the value, and dispatches a 'score-change' event.
* @param {Event} e - The input event.
*/
private _onInputChange;
/**
* Renders the display-only view with modifier and base score.
*/
private _renderDisplay;
/**
* Renders the interactive input field.
*/
private _renderInput;
render(): TemplateResult;
}
declare global {
interface HTMLElementTagNameMap {
'cn-d20-ability-score': CnD20AbilityScore;
}
}