/* ============================================================= * @whynot/design — form.js * ------------------------------------------------------------ * , , , * , * * Each wraps a real native element. Form participation works * because the native input is part of the light DOM via the * `name` attribute being copied through; for richer integration * use ElementInternals (deferred — see CHANGELOG). * ============================================================= */ import { LitElement, html, nothing } from "lit"; import { WnBase } from "./atoms.js"; /* ---------- ---------- */ export class WnInput extends WnBase { static properties = { name: { type: String, reflect: true }, type: { type: String, reflect: true }, value: { type: String }, placeholder: { type: String }, required: { type: Boolean, reflect: true }, disabled: { type: Boolean, reflect: true }, readonly: { type: Boolean, reflect: true }, autocomplete:{ type: String }, error: { type: Boolean, reflect: true }, help: { type: String }, errorText: { type: String, attribute: "error-text" }, }; constructor() { super(); this.type = "text"; this.value = ""; this.required = false; this.disabled = false; this.readonly = false; this.error = false; } _onInput(e) { this.value = e.target.value; this.dispatchEvent(new CustomEvent("wn-input", { detail: { value: this.value }, bubbles: true, composed: true })); } render() { const cls = "wn-input" + (this.error ? " wn-input--error" : ""); return html` ${this.error && this.errorText ? html`${this.errorText}` : this.help ? html`${this.help}` : nothing} `; } } /* ---------- ---------- */ export class WnTextarea extends WnBase { static properties = { name: { type: String, reflect: true }, value: { type: String }, placeholder: { type: String }, rows: { type: Number }, required: { type: Boolean, reflect: true }, disabled: { type: Boolean, reflect: true }, error: { type: Boolean, reflect: true }, help: { type: String }, errorText: { type: String, attribute: "error-text" }, }; constructor() { super(); this.value = ""; this.rows = 4; } _onInput(e) { this.value = e.target.value; this.dispatchEvent(new CustomEvent("wn-input", { detail: { value: this.value }, bubbles: true, composed: true })); } render() { const cls = "wn-textarea" + (this.error ? " wn-textarea--error" : ""); return html` ${this.error && this.errorText ? html`${this.errorText}` : this.help ? html`${this.help}` : nothing} `; } } /* ---------- ---------- * Slot