All Projects → fabbricadigitale → paper-chip

fabbricadigitale / paper-chip

Licence: MIT license
A chip web component made with Polymer 2 following Material Design guidelines

Programming Languages

HTML
75241 projects

Projects that are alternatives of or similar to paper-chip

toggle-icon
toggle-icon is a custom element created with Polymer. It provides an extremely powerful and customizable switch that looks like a paper-icon-button.
Stars: ✭ 21 (-30%)
Mutual labels:  polymer, webcomponents, custom-elements, polymer2
vaadin-text-field
The themable Web Component providing input controls. Part of the Vaadin components.
Stars: ✭ 29 (-3.33%)
Mutual labels:  polymer, webcomponents, input, custom-elements
vaadin-dialog
High quality web component for modal dialogs. Part of the Vaadin platform.
Stars: ✭ 15 (-50%)
Mutual labels:  polymer, webcomponents, polymer2
lego
🚀 Web-components made lightweight & Future-Proof.
Stars: ✭ 69 (+130%)
Mutual labels:  polymer, webcomponents, custom-elements
vaadin-split-layout
The Web Component which allows you to partition a layout into resizeable areas. Part of the Vaadin components.
Stars: ✭ 40 (+33.33%)
Mutual labels:  polymer, webcomponents, polymer2
mapbox-gl
Polymer 2.0 custom element for mapbox-gl-js. Uses WebGL to render interactive maps from vector tiles and Mapbox styles - compatible with deck-gl.
Stars: ✭ 24 (-20%)
Mutual labels:  polymer, webcomponents, polymer2
vaadin-context-menu
The responsive Web Component for showing context dependent items for any element on the page. Part of the Vaadin components.
Stars: ✭ 26 (-13.33%)
Mutual labels:  polymer, webcomponents, polymer2
vaadin-icons
Vaadin Icons is a collection of 600+ unique icons designed for web applications
Stars: ✭ 59 (+96.67%)
Mutual labels:  polymer, webcomponents, polymer2
Awesome Polymer
A collection of awesome Polymer resources.
Stars: ✭ 384 (+1180%)
Mutual labels:  polymer, webcomponents, custom-elements
identicon-avatar
👾 GitHub style identicon avatar
Stars: ✭ 15 (-50%)
Mutual labels:  polymer, webcomponents, polymer2
Vaadin Combo Box
The Web Component for displaying a list of items with filtering. Part of the Vaadin components.
Stars: ✭ 113 (+276.67%)
Mutual labels:  polymer, webcomponents, custom-elements
Redux Store Element
A custom element allowing a more declarative use of Redux.
Stars: ✭ 83 (+176.67%)
Mutual labels:  polymer, webcomponents, custom-elements
page-title
A Polymer element for easily updating a webpage's title, such as in a SPA.
Stars: ✭ 13 (-56.67%)
Mutual labels:  polymer, custom-elements, polymer2
React Selectrix
A beautiful, materialized and flexible React Select control
Stars: ✭ 166 (+453.33%)
Mutual labels:  autocomplete, input
Vue Places
Places component is based on places.js for Vue 2.x. Turn any <input> into an address autocomplete.
Stars: ✭ 106 (+253.33%)
Mutual labels:  autocomplete, input
Vue Cool Select
Select with autocomplete, slots, bootstrap and material design themes.
Stars: ✭ 195 (+550%)
Mutual labels:  autocomplete, input
pattern-library
AXA CH UI component library. Please share, comment, create issues and work with us!
Stars: ✭ 103 (+243.33%)
Mutual labels:  webcomponents, custom-elements
React Input Enhancements
Set of enhancements for input control
Stars: ✭ 1,375 (+4483.33%)
Mutual labels:  autocomplete, input
web-components
A set of high-quality standards based web components for enterprise web applications. Part of Vaadin 20+
Stars: ✭ 322 (+973.33%)
Mutual labels:  webcomponents, custom-elements
vaadin-select
Customizable Web Component similar to a native browser select. Part of the Vaadin components.
Stars: ✭ 18 (-40%)
Mutual labels:  webcomponents, polymer2

Published on webcomponents.org License Build Status

<paper-chip>

Material design: Chips.

A chip web component made with Polymer 2 following Material Design guidelines

This elements family may provide a icon or a photo, some line of text or a contact information with Material Design styling.

Browser Support Matrix

Elements

  • <paper-chip>
  • <paper-chip-input>

Table of contents

<paper-chip> usage

Minimal

A minimal chip.

<paper-chip single-line>Minimal chip</paper-chip>

Single or multi-line

It can show single-line or multi-line text.

You can open a multi-line chip tapping on it, showing some additional info.

<paper-chip>
    <iron-icon slot="icon" class="icon" icon="avatars:avatar-1"></iron-icon>
    <div slot="label" class="label">John Foo</div>
    <div slot="caption" class="caption">[email protected]</div>
</paper-chip>

Removable

Following snippet of code shows how to configure (via attributes) some basic behavior.

It may be removable or not.

<paper-chip removable>
    <div slot="label" class="label">Removable Chip</div>
</paper-chip>

Animated transition

Do you want to animated the chip when it is opening?

You can do it via attribute.

<paper-chip removable animated>
    <div slot="icon" class="icon">P</div>
    <div slot="label" class="label">John Foo</div>
    <div slot="caption" class="caption">[email protected]</div>
</paper-chip>

<paper-chip-input> usage

Use <paper-chip-input> when you desire an input field where the strings digited by the user are collected as paper-chips.

<paper-chip-input></paper-chip-input>

How to configure its presentation

Configure paper-chip-input presentation using attribute.

Disable the input underline

If you do not want the input underline use noline attribute.

<paper-chip-input noline></paper-chip-input>

How to fix the input label at the top

Use always-float-label attribute to fix the the label at the top.

<paper-chip-input always-float-label></paper-chip-input>

Non floating label

Use no-label-float attribute to disable floating label. So the input label will be inside the input.

<paper-chip-input no-label-float></paper-chip-input>

Input field feature

Inputs can have different types, and be disabled.

<paper-chip-input label="text input" staged-value="pre-filled"></paper-chip-input>

Inputs can have character counters.

<paper-chip-input label="simple character counter" char-counter></paper-chip-input>

Or you can limit chip text's max length.

<paper-chip-input label="input with at most 10 characters" char-counter maxlength="10"></paper-chip-input>

Inputs can validate automatically or on demand, and can have custom error messages.

<paper-chip-input label="this input requires letters only" auto-validate pattern="[a-zA-Z]*" error-message="letters only!"></paper-chip-input>

You can configure your favorite allowed pattern.

<paper-chip-input label="this input will only let you type letters" auto-validate allowed-pattern="[a-zA-Z]"></paper-chip-input>

You can run validation manually

<paper-chip-input id="inputForValidation" required label="this input is manually validated" pattern="[a-zA-Z]*" error-message="letters only!"></paper-chip-input>

<button onclick="validate()">Validate!</button>
<script>
function validate() {
    document.getElementById('inputForValidation').validate();
}
</script>

paper-chip-input can have custom prefix and suffix.

<paper-chip-input no-label-float label="">
    <iron-icon icon="mail" slot="prefix"></iron-icon>
    <paper-icon-button slot="suffix" icon="clear"></paper-icon-button>
</paper-chip-input>

Chip-added and chip-removed event

paper-chip-input fires custom events chip-added/chip-removed event when a chip is added or removed to paper-chip-input.

<paper-chip-input id="custom-event"></paper-chip-input>
<span id="log"></span>
<script>
document.querySelector('#custom-event').addEventListener('chip-added', function (e) {
    document.querySelector("#log").textContent="Chip added!"
})
document.querySelector('#custom-event').addEventListener('chip-removed', function (e) {
    document.querySelector("#log").textContent="Chip removed!"
})
</script>

Configure your favorite submit keys

Do you want to change the keys that automatically submit chips?

No worries, we support it!

Configure them with the enter-keys property adding the keys.

We support the Polymer.IronA11yKeysBehavior format.

Following example should clarify the usage of this feature.

<paper-chip-input enter-keys='["enter", "space"]'></paper-chip-input>

Autocomplete

Do you need autocomplete ?

When you have a predefined and finite set of input values you can set the predefined values with datasource property. Don't forget to add the autocomplete attribute.

<paper-chip-input autocomplete label="Weekdays" datasource='[{"value": "1", "label": "monday" },{"value": "2", "label": "tuesday"}, {"value": "3", "label": "wednesday"}, {"value": "4", "label": "thursday"}, {"value": "5", "label": "friday"}, {"value": "6", "label": "saturday"}, {"value": "7", "label": "sunday"}]'  placeholder="Add day"></paper-chip-input>

Configure custom datasource properties

The default properties for datasource are label and value, but you can configure it from outside by the properties display-property and value-property.

<paper-chip-input display-property="val" value-property="key">
</paper-chip-input>
[
  { "val": "apple", "key": "0" },
  { "val": "apricot", "key": "1" }
]

Custom filter logic

Autocomplete uses a startWith filter as default logic.

Do you need to implement a custom filter logic? You can do it!

Set filter property with your custom function. The following lines of code will show you how to do it.

<paper-chip-input autocomplete id="weekdays" label="Weekdays" datasource='[{"value": "1", "label": "monday" },{"value": "2", "label": "tuesday"}, {"value": "3", "label": "wednesday"}, {"value": "4", "label": "thursday"}, {"value": "5", "label": "friday"}, {"value": "6", "label": "saturday"}, {"value": "7", "label": "sunday"}]' placeholder="Add day"></paper-chip-input>
<script>
let weekdays = document.querySelector("#weekdays")
weekdays.filter = (data, value) => {
    return data.filter((item) => item[weekdays.displayProperty].toLowerCase().includes(value.toLowerCase()))
}
</script>

How to insert chips

You can insert <paper-chip> elements inside the <paper-chip-input> declaratively - ie., putting the within the Light DOM.

<paper-chip-input>
  <paper-chip value="light">Light</paper-chip>
  <paper-chip value="dom">DOm</paper-chip>
</paper-chip-input>

Styling

The following custom properties and mixins are available for styling:

Custom property Description Default
--paper-chip-secondary-text-color The paper-chip label-color --secondary-text-color
--paper-chip-background-color The paper-chip background-color --paper-grey-200
--paper-chip-icon-background-color The paper-chip avatar background-color --paper-grey-500
--paper-chip-icon-text-color The paper-chip icon color --text-primary-color
--paper-chip-closed-label-max-width The paper-chip label max-width when is closed 80px

Testing

If you are using polyserve navigate to the test/ directory of your element to run its tests.

You can view results in the browser console.

WCT

The tests are run via web-component-tester.

To run them locally execute:

npm test

Contributing

Thanks for your interest in this project!

We are really glad you are reading this. External contributions are very welcome by our team. We know that we need volunteer developers to help this project come (and mantain) to fruition.

There are many ways to contribute to this project. Get started reading the contributing guide.

License

MIT © fabbricadigitale

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].