UNPKG

preact-material-components

Version:
130 lines (98 loc) 3.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _preact = require("preact"); var _Icon = _interopRequireDefault(require("../Icon")); var _MaterialComponent = _interopRequireDefault(require("../MaterialComponent")); var _chips = require("@material/chips"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } class ChipSet extends _MaterialComponent.default { constructor() { super(); this.componentName = 'chip-set'; this._mdcProps = ['choice', 'filter', 'input']; } componentDidMount() { this.MDComponent = new _chips.MDCChipSet(this.control); } componentWillUnmount() { this.MDComponent.destroy && this.MDComponent.destroy(); } materialDom(allprops) { const children = allprops.children, props = _objectWithoutProperties(allprops, ["children"]); return (0, _preact.h)("div", _extends({}, props, { ref: this.setControlRef }), children); } } class Chip extends _MaterialComponent.default { constructor() { super(); this.componentName = 'chip'; this._mdcProps = ['selected']; } materialDom(allprops) { const children = allprops.children, props = _objectWithoutProperties(allprops, ["children"]); return (0, _preact.h)("div", _extends({}, props, { ref: this.setControlRef }), children); } } class ChipIcon extends _Icon.default { constructor() { super(); this.componentName = 'chip__icon'; this._mdcProps = ['leading', 'trailing']; } materialDom(allprops) { const children = allprops.children, props = _objectWithoutProperties(allprops, ["children"]); const otherprops = {}; if (props.trailing) { otherprops['tabindex'] = 0; otherprops['role'] = 'button'; } return (0, _preact.h)(_Icon.default, _extends({}, props, otherprops), children); } } class ChipCheckmark extends _Icon.default { constructor() { super(); this.componentName = 'chip__checkmark'; } materialDom(props) { return (0, _preact.h)("div", null, (0, _preact.h)("svg", { "class": "mdc-chip__checkmark-svg", viewBox: "-2 -3 30 30" }, (0, _preact.h)("path", { "class": "mdc-chip__checkmark-path", fill: "none", stroke: "black", d: "M1.73,12.91 8.1,19.28 22.79,4.59" }))); } } class ChipText extends _MaterialComponent.default { constructor() { super(); this.componentName = 'chip__text'; } materialDom(allprops) { const children = allprops.children, props = _objectWithoutProperties(allprops, ["children"]); return (0, _preact.h)("div", props, children); } } const chips = ChipSet; chips.Chip = Chip; chips.Icon = ChipIcon; chips.Text = ChipText; chips.Checkmark = ChipCheckmark; var _default = chips; exports.default = _default;