Coder Social home page Coder Social logo

polymerelements / iron-checked-element-behavior Goto Github PK

View Code? Open in Web Editor NEW
5.0 16.0 9.0 242 KB

Implements an element that has a checked attribute and can be added to a form

Home Page: https://webcomponents.org/element/PolymerElements/iron-checked-element-behavior

HTML 56.46% JavaScript 43.54%

iron-checked-element-behavior's Introduction

Published on NPM Build status Published on webcomponents.org

IronCheckedElementBehavior

Use IronCheckedElementBehavior to implement a custom element that has a checked property, which can be used for validation if the element is also required. Element instances implementing this behavior will also be registered for use in an iron-form element.

See: Documentation, Demo.

Usage

Installation

npm install --save @polymer/iron-checked-element-behavior

In a Polymer 3 element

import {PolymerElement} from '@polymer/polymer/polymer-element.js';
import {mixinBehaviors} from '@polymer/polymer/lib/legacy/class.js';
import {html} from '@polymer/polymer/lib/utils/html-tag.js';

import {IronCheckedElementBehavior} from '../iron-checked-element-behavior.js';

class SimpleCheckbox extends mixinBehaviors(IronCheckedElementBehavior, PolymerElement) {
  static get template() {
    return html`
      <style>
        :host([invalid]) {
          color: red;
        }
      </style>

      <button on-click="_checkValidity">validate</button>
      <input type="checkbox" id="checkbox" checked="{{checked::input}}">
      <span id="labelText">{{label}}</span>
    `;
  }

  static get properties() {
    return {label: {type: String, value: 'not validated'}};
  }

  _checkValidity() {
    this.validate();
    this.label = this.invalid ? 'is invalid' : 'is valid';
  }
}

customElements.define('simple-checkbox', SimpleCheckbox);

Contributing

If you want to send a PR to this element, here are the instructions for running the tests and demo locally:

Installation

git clone https://github.com/PolymerElements/iron-checked-element-behavior
cd iron-checked-element-behavior
npm install
npm install -g polymer-cli

Running the demo locally

polymer serve --npm
open http://127.0.0.1:<port>/demo/

Running the tests

polymer test --npm

iron-checked-element-behavior's People

Contributors

aomarks avatar bicknellr avatar dependabot[bot] avatar dfreedm avatar e111077 avatar garlicnation avatar notwaldorf avatar rictic avatar tedium-bot avatar valdrinkoshi avatar zecat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

iron-checked-element-behavior's Issues

Wrong Reference in bower file for 2.0 preview

Description

The reference for iron-form-element-behavior is pointing at 1.0.0

PolymerElements/iron-form-element-behavior#^1.0.0

Expected outcome

This should be pointing to the 2.0 preview branch

Merge into Polymer/iron-behaviors

Shouldn't this technically be a part of the iron-behaviors repository? It is an iron behavior and many elements have to use both this and iron-behaviors. In my opinion it's more semantically correct to merge the two.

iron-checked-element-behavior included in iron-elements

Just asking, iron-checked-element-behavior gonna be included either in the iron-elements package or in iron-behaviors right?
I saw it's been only one week since last update (as well as in the paper-toggle-button). So no hurry to include them but just to write down if I have to remove single dependancy afterwards or not, thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.