preact-material-components
Version:
preact wrapper for "Material Components for the web"
117 lines (91 loc) • 3.1 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _preact = require("preact");
var _MaterialComponent = _interopRequireDefault(require("../MaterialComponent"));
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); }
class LayoutGrid extends _MaterialComponent.default {
constructor() {
super();
this.componentName = 'layout-grid';
}
materialDom(props) {
return (0, _preact.h)("div", _extends({
ref: this.setControlRef
}, props), props.children);
}
}
class LayoutGridInner extends _MaterialComponent.default {
constructor() {
super();
this.componentName = 'layout-grid__inner';
}
materialDom(props) {
return (0, _preact.h)("div", _extends({
ref: this.setControlRef
}, props), props.children);
}
}
/**
* @prop cols = 0
* @prop desktopCols = 0
* @prop tabletCols = 0
* @prop phoneCols = 0
* @prop order = 0
* @prop align = ''
*/
class LayoutGridCell extends _MaterialComponent.default {
constructor() {
super();
this.componentName = 'layout-grid__cell';
this._propsDict = {
cols: 'cols',
desktop: 'desktopCols',
tablet: 'tabletCols',
phone: 'phoneCols',
order: 'order',
align: 'align'
};
}
createClassName(props) {
const baseClass = 'mdc-layout-grid__cell--';
const classes = [];
if (props[this._propsDict.cols]) {
classes.push(baseClass + 'span-' + props[this._propsDict.cols]);
}
if (props[this._propsDict.desktop]) {
classes.push(baseClass + 'span-' + props[this._propsDict.desktop] + '-desktop');
}
if (props[this._propsDict.tablet]) {
classes.push(baseClass + 'span-' + props[this._propsDict.tablet] + '-tablet');
}
if (props[this._propsDict.phone]) {
classes.push(baseClass + 'span-' + props[this._propsDict.phone] + '-phone');
}
if (props[this._propsDict.order]) {
classes.push(baseClass + 'order-' + props[this._propsDict.order]);
}
if (props[this._propsDict.align]) {
classes.push(baseClass + 'align-' + props[this._propsDict.align]);
}
return classes.join(' ');
}
materialDom(props) {
return (0, _preact.h)("div", _extends({}, props, {
className: this.createClassName(props),
ref: this.setControlRef
}), props.children);
}
render() {
const element = super.render(); // remove the extra attributes used for customising this element - keep the DOM clean
Object.keys(this._propsDict).forEach(key => delete element.attributes[this._propsDict[key]]);
return element;
}
}
LayoutGrid.Cell = LayoutGridCell;
LayoutGrid.Inner = LayoutGridInner;
var _default = LayoutGrid;
exports.default = _default;