@anypoint-web-components/anypoint-form-mixins
TypeScript icon, indicating that this package has built-in type declarations

1.3.1 • Public • Published

Deprecated

This component has been moved to anypoint-web-components/awc.


checked-element-mixin

Use CheckedElementMixin to implement an element that can be checked like native checkbox.

Usage

Installation

npm install --save @anypoint-web-components/anypoint-form-mixins

In a LitElement

import { LitElement, html } from 'lit-element';
import { CheckedElementMixin } from '@anypoint-web-components/anypoint-form-mixins/anypoint-form-mixins.js';

class SimpleCheckbox extends CheckedElementMixin(LitElement) {
  static get styles() {
    return css`
    :host {
      display: block;
    }

    :host([invalid]) span {
      color: red;
    }

    #labelText {
      display: inline-block;
      width: 100px;
    }`;
  }

  render() {
    return html`
    <input type="checkbox" id="checkbox" @click="${this._onCheckClick}">
    <span id="labelText">${this.label}</span>
    <paper-button raised @click="${this._onClick}">validate</paper-button>`;
  }

  static get properties() {
    return {
      label: { type: String }
    };
  }

  constructor() {
    super();
    this.label = 'Not validated';
  }

  _onCheckClick(e) {
    this.checked = e.target.checked;
  }

  _onClick() {
    this.validate();
    this.label = this.invalid ? 'is invalid' : 'is valid';
  }
}
window.customElements.define('simple-checkbox', SimpleCheckbox);

Development

git clone https://github.com/anypoint-web-components/anypoint-form-mixins
cd anypoint-form-mixins
npm install

Running the demo locally

npm start

Running the tests

npm test

Package Sidebar

Install

npm i @anypoint-web-components/anypoint-form-mixins

Weekly Downloads

283

Version

1.3.1

License

Apache-2.0

Unpacked Size

16.3 kB

Total Files

14

Last publish

Collaborators

  • jarrodek
  • twoplustwoone
  • lbauret
  • carowright