UNPKG

preact-material-components

Version:
164 lines 5.71 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; 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 { bind } from 'bind-decorator'; import { h } from 'preact'; import MaterialComponent from '../Base/MaterialComponent'; import Icon from '../Icon'; function notEmptyString(val) { return val !== ''; } export class GridListTiles extends MaterialComponent { constructor() { super(...arguments); this.componentName = 'grid-list__tiles'; this.mdcProps = []; } materialDom(props) { return h("ul", Object.assign({}, props), props.children); } } __decorate([ bind ], GridListTiles.prototype, "materialDom", null); export class GridListTile extends MaterialComponent { constructor() { super(...arguments); this.componentName = 'grid-tile'; this.mdcProps = []; } materialDom(props) { return h("li", Object.assign({}, props), props.children); } } __decorate([ bind ], GridListTile.prototype, "materialDom", null); export class GridListPrimaryTile extends MaterialComponent { constructor() { super(...arguments); this.componentName = 'grid-tile__primary'; this.mdcProps = []; } materialDom(props) { return h("div", Object.assign({}, props), props.children); } } __decorate([ bind ], GridListPrimaryTile.prototype, "materialDom", null); export class GridListPrimaryContentTile extends MaterialComponent { constructor() { super(...arguments); this.componentName = 'grid-tile__primary-content'; this.mdcProps = []; } materialDom(allprops) { const { src } = allprops, props = __rest(allprops, ["src"]); return h("img", Object.assign({ src: src }, props)); } } __decorate([ bind ], GridListPrimaryContentTile.prototype, "materialDom", null); export class GridListSecondaryTile extends MaterialComponent { constructor() { super(...arguments); this.componentName = 'grid-tile__secondary'; this.mdcProps = []; } materialDom(props) { return h("span", Object.assign({}, props), props.children); } } __decorate([ bind ], GridListSecondaryTile.prototype, "materialDom", null); export class GridListTitleTile extends MaterialComponent { constructor() { super(...arguments); this.componentName = 'grid-tile__title'; this.mdcProps = []; } materialDom(props) { return h("span", Object.assign({}, props), props.children); } } __decorate([ bind ], GridListTitleTile.prototype, "materialDom", null); export class GridListSupportTextTile extends MaterialComponent { constructor() { super(...arguments); this.componentName = 'grid-tile__support-text'; this.mdcProps = []; } materialDom(props) { return h("span", Object.assign({}, props), props.children); } } __decorate([ bind ], GridListSupportTextTile.prototype, "materialDom", null); class GridListIconTile extends Icon { constructor() { super(...arguments); this.componentName = 'grid-tile__icon'; } } export class GridList extends MaterialComponent { constructor() { super(...arguments); this.componentName = 'grid-list'; this.mdcProps = ['header-caption', 'twoline-caption', 'tile-gutter-1']; } isValidValue(validationValues, testValue) { return (validationValues && validationValues.findIndex(val => val === testValue) >= 0); } mapClassName(propKey, props) { const propValue = props[propKey]; const validationValues = GridList.validationValuesByKey[propKey]; return this.isValidValue(validationValues, propValue) ? `mdc-${this.componentName}--${propKey}-${propValue}` : ''; } materialDom(props) { const className = Object.keys(GridList.validationValuesByKey) .map(key => { return this.mapClassName(key, props); }) .filter(notEmptyString) .join(' '); return (h("div", Object.assign({}, props, { className: className }), props.children)); } } GridList.validationValuesByKey = { 'tile-aspect': ['1x1', '16x9', '2x3', '3x2', '4x3', '3x4'], 'with-icon-align': ['start', 'end'] }; export default class default_1 extends GridList { } default_1.Tiles = GridListTiles; default_1.Tile = GridListTile; default_1.PrimaryTile = GridListPrimaryTile; default_1.PrimaryContentTile = GridListPrimaryContentTile; default_1.SecondaryTile = GridListSecondaryTile; default_1.TitleTile = GridListTitleTile; default_1.SupportTextTile = GridListSupportTextTile; default_1.IconTile = GridListIconTile; //# sourceMappingURL=index.js.map