import { tag, WeElement, h, extractClass, classNames } from 'omi' import * as css from './index.scss' import { MDCRipple } from '@material/ripple' import { MDCChipSet, MDCChip } from '@material/chips' import '../icon' //@ts-ignore import '../theme.ts' interface Props { chips: [{ text: string, selected?: boolean, leading?: { icon: object | string }, trailing?: { icon: object | string, role?: string, tabindex?: number }, checkmark: boolean }], input?: boolean, choice?: boolean, filter?: boolean, ripple?: boolean } interface Data { } @tag('m-chips') export default class Chips extends WeElement{ static css = css static defaultProps = { ripple: true } static propTypes = { ripple: Boolean, chips: Object, input: Boolean, choice: Boolean, filter: Boolean } trailingClickHandle = (index) => { this.fire('trailingIconInteraction', index) } chipClickHandle = (index) => { this.fire('interaction', index) } installed() { if (this.props.ripple) { this.shadowRoot.querySelectorAll('.mdc-chip').forEach(item => { new MDCRipple(item) }) } } render(props) { return (
{ props.chips.map((item, index) => { return
this.chipClickHandle(index)}> {(item.leading) && { (item.leading.icon && typeof item.leading.icon === 'object') && } { (item.leading.icon && typeof item.leading.icon === 'string') && item.leading.icon } } {(props.filter && item.checkmark) &&
}
{ item.text }
{(item.trailing) && this.trailingClickHandle(index) }> {(item.trailing.icon && typeof item.trailing.icon === 'object') && } { (item.trailing.icon && typeof item.trailing.icon === 'string') && item.trailing.icon } }
}) }
) } }