views/mdc/assets/js/components/chips.js in voom-presenters-0.1.13 vs views/mdc/assets/js/components/chips.js in voom-presenters-0.2.0

- old
+ new

@@ -1,12 +1,45 @@ import {MDCChip} from '@material/chips'; +import {MDCChipSet} from '@material/chips'; +import {eventHandlerMixin} from "./mixins/event-handler"; +import {VBaseComponent, hookupComponents} from './base-component'; export function initChips() { console.log('\tChips'); - var components = document.querySelectorAll('.mdc-chip'); - for (var i = 0; i < components.length; i++) { - var component = components[i]; - if(!component.mdcComponent) { - component.mdcComponent = MDCChip.attachTo(component); + hookupComponents('.v-chip', VChip, MDCChip); + hookupComponents('.v-chip-set', VChipSet, MDCChipSet); +} + +export class VChip extends eventHandlerMixin(VBaseComponent) { + constructor(element, mdcComponent) { + super(element, mdcComponent); + } + + // Called to collect data for submission + prepareSubmit(params) { + if(this.value() !== ''){ + params.push([this.name(), this.value()]); } + } + + name(){ + return this.element.getAttribute('data-name'); + } + + value(){ + return this.element.getAttribute('data-value'); + } + + clear(){ + console.log('\tChip clear is a no-op'); + } + + setValue(value){ + this.element.setAttribute('data-value', value); + } +} + +export class VChipSet extends eventHandlerMixin(VBaseComponent) { + constructor(element, mdcComponent) { + super(element, mdcComponent); } }