preact-material-components
Version:
preact wrapper for "Material Components for the web"
44 lines • 1.76 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 { MDCSwitch } from '@material/switch';
import { h } from 'preact';
import MaterialComponent from '../Base/MaterialComponent';
export class Switch extends MaterialComponent {
constructor() {
super(...arguments);
this.componentName = 'switch';
this.mdcProps = ['disabled', 'checked'];
this.mdcNotifyProps = ['disabled', 'checked'];
}
componentDidMount() {
super.componentDidMount();
if (this.control) {
this.MDComponent = new MDCSwitch(this.control);
}
}
componentWillUnmount() {
super.componentWillUnmount();
if (this.MDComponent) {
this.MDComponent.destroy();
}
}
materialDom(allprops) {
const { className } = allprops, props = __rest(allprops, ["className"]);
return (h("div", { className: className, ref: this.setControlRef },
h("div", { class: "mdc-switch__track" }),
h("div", { class: "mdc-switch__thumb-underlay" },
h("div", { class: "mdc-switch__thumb" },
h("input", Object.assign({ type: "checkbox", id: "basic-switch", class: "mdc-switch__native-control", role: "switch" }, props))))));
}
}
export default Switch;
//# sourceMappingURL=index.js.map