preact-material-components
Version:
preact wrapper for "Material Components for the web"
95 lines • 3.31 kB
JavaScript
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
import { MDCChipSet } from '@material/chips';
import { h } from 'preact';
import MaterialComponent from '../Base/MaterialComponent';
import Icon from '../Icon';
export class Chip extends MaterialComponent {
constructor() {
super(...arguments);
this.componentName = 'chip';
this.mdcProps = ['selected'];
}
materialDom(allprops) {
const { children } = allprops, props = __rest(allprops, ["children"]);
return (h("div", Object.assign({}, props, { ref: this.setControlRef }), children));
}
}
export class ChipIcon extends Icon {
constructor() {
super(...arguments);
this.componentName = 'chip__icon';
this.mdcProps = ['leading', 'trailing'];
}
materialDom(allprops) {
const { children } = allprops, props = __rest(allprops, ["children"]);
const otherprops = {};
if (props.trailing) {
otherprops.tabindex = 0;
otherprops.role = 'button';
}
return (h(Icon, Object.assign({}, props, otherprops), children));
}
}
export class ChipCheckmark extends Icon {
constructor() {
super(...arguments);
this.componentName = 'chip__checkmark';
this.mdcProps = [];
}
materialDom(props) {
return (h("div", Object.assign({}, props),
h("svg", { class: "mdc-chip__checkmark-svg", viewBox: "-2 -3 30 30" },
h("path", { class: "mdc-chip__checkmark-path", fill: "none", stroke: "black", d: "M1.73,12.91 8.1,19.28 22.79,4.59" }))));
}
}
export class ChipText extends MaterialComponent {
constructor() {
super(...arguments);
this.componentName = 'chip__text';
this.mdcProps = [];
}
materialDom(allprops) {
const { children } = allprops, props = __rest(allprops, ["children"]);
return h("div", Object.assign({}, props), children);
}
}
export class ChipSet extends MaterialComponent {
constructor() {
super(...arguments);
this.componentName = 'chip-set';
this.mdcProps = ['choice', 'filter', 'input'];
}
componentDidMount() {
super.componentDidMount();
if (this.control) {
this.MDComponent = new MDCChipSet(this.control);
}
}
componentWillUnmount() {
super.componentWillUnmount();
if (this.MDComponent) {
this.MDComponent.destroy();
}
}
materialDom(allprops) {
const { children } = allprops, props = __rest(allprops, ["children"]);
return (h("div", Object.assign({}, props, { ref: this.setControlRef }), children));
}
}
export default class default_1 extends ChipSet {
}
default_1.Chip = Chip;
default_1.Icon = ChipIcon;
default_1.Text = ChipText;
default_1.Checkmark = ChipCheckmark;
//# sourceMappingURL=index.js.map