preact-material-components
Version:
preact wrapper for "Material Components for the web"
348 lines (274 loc) • 11.7 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.GridList = exports.GridListSupportTextTile = exports.GridListTitleTile = exports.GridListSecondaryTile = exports.GridListPrimaryContentTile = exports.GridListPrimaryTile = exports.GridListTile = exports.GridListTiles = void 0;
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
var _bindDecorator = require("bind-decorator");
var _preact = require("preact");
var _MaterialComponent9 = _interopRequireDefault(require("../Base/MaterialComponent"));
var _Icon2 = _interopRequireDefault(require("../Icon"));
var __decorate = void 0 && (void 0).__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 === "undefined" ? "undefined" : (0, _typeof2.default)(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 = void 0 && (void 0).__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;
};
function notEmptyString(val) {
return val !== '';
}
var GridListTiles =
/*#__PURE__*/
function (_MaterialComponent) {
(0, _inherits2.default)(GridListTiles, _MaterialComponent);
function GridListTiles() {
var _this;
(0, _classCallCheck2.default)(this, GridListTiles);
_this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(GridListTiles).apply(this, arguments));
_this.componentName = 'grid-list__tiles';
_this.mdcProps = [];
return _this;
}
(0, _createClass2.default)(GridListTiles, [{
key: "materialDom",
value: function materialDom(props) {
return (0, _preact.h)("ul", Object.assign({}, props), props.children);
}
}]);
return GridListTiles;
}(_MaterialComponent9.default);
exports.GridListTiles = GridListTiles;
__decorate([_bindDecorator.bind], GridListTiles.prototype, "materialDom", null);
var GridListTile =
/*#__PURE__*/
function (_MaterialComponent2) {
(0, _inherits2.default)(GridListTile, _MaterialComponent2);
function GridListTile() {
var _this2;
(0, _classCallCheck2.default)(this, GridListTile);
_this2 = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(GridListTile).apply(this, arguments));
_this2.componentName = 'grid-tile';
_this2.mdcProps = [];
return _this2;
}
(0, _createClass2.default)(GridListTile, [{
key: "materialDom",
value: function materialDom(props) {
return (0, _preact.h)("li", Object.assign({}, props), props.children);
}
}]);
return GridListTile;
}(_MaterialComponent9.default);
exports.GridListTile = GridListTile;
__decorate([_bindDecorator.bind], GridListTile.prototype, "materialDom", null);
var GridListPrimaryTile =
/*#__PURE__*/
function (_MaterialComponent3) {
(0, _inherits2.default)(GridListPrimaryTile, _MaterialComponent3);
function GridListPrimaryTile() {
var _this3;
(0, _classCallCheck2.default)(this, GridListPrimaryTile);
_this3 = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(GridListPrimaryTile).apply(this, arguments));
_this3.componentName = 'grid-tile__primary';
_this3.mdcProps = [];
return _this3;
}
(0, _createClass2.default)(GridListPrimaryTile, [{
key: "materialDom",
value: function materialDom(props) {
return (0, _preact.h)("div", Object.assign({}, props), props.children);
}
}]);
return GridListPrimaryTile;
}(_MaterialComponent9.default);
exports.GridListPrimaryTile = GridListPrimaryTile;
__decorate([_bindDecorator.bind], GridListPrimaryTile.prototype, "materialDom", null);
var GridListPrimaryContentTile =
/*#__PURE__*/
function (_MaterialComponent4) {
(0, _inherits2.default)(GridListPrimaryContentTile, _MaterialComponent4);
function GridListPrimaryContentTile() {
var _this4;
(0, _classCallCheck2.default)(this, GridListPrimaryContentTile);
_this4 = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(GridListPrimaryContentTile).apply(this, arguments));
_this4.componentName = 'grid-tile__primary-content';
_this4.mdcProps = [];
return _this4;
}
(0, _createClass2.default)(GridListPrimaryContentTile, [{
key: "materialDom",
value: function materialDom(allprops) {
var src = allprops.src,
props = __rest(allprops, ["src"]);
return (0, _preact.h)("img", Object.assign({
src: src
}, props));
}
}]);
return GridListPrimaryContentTile;
}(_MaterialComponent9.default);
exports.GridListPrimaryContentTile = GridListPrimaryContentTile;
__decorate([_bindDecorator.bind], GridListPrimaryContentTile.prototype, "materialDom", null);
var GridListSecondaryTile =
/*#__PURE__*/
function (_MaterialComponent5) {
(0, _inherits2.default)(GridListSecondaryTile, _MaterialComponent5);
function GridListSecondaryTile() {
var _this5;
(0, _classCallCheck2.default)(this, GridListSecondaryTile);
_this5 = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(GridListSecondaryTile).apply(this, arguments));
_this5.componentName = 'grid-tile__secondary';
_this5.mdcProps = [];
return _this5;
}
(0, _createClass2.default)(GridListSecondaryTile, [{
key: "materialDom",
value: function materialDom(props) {
return (0, _preact.h)("span", Object.assign({}, props), props.children);
}
}]);
return GridListSecondaryTile;
}(_MaterialComponent9.default);
exports.GridListSecondaryTile = GridListSecondaryTile;
__decorate([_bindDecorator.bind], GridListSecondaryTile.prototype, "materialDom", null);
var GridListTitleTile =
/*#__PURE__*/
function (_MaterialComponent6) {
(0, _inherits2.default)(GridListTitleTile, _MaterialComponent6);
function GridListTitleTile() {
var _this6;
(0, _classCallCheck2.default)(this, GridListTitleTile);
_this6 = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(GridListTitleTile).apply(this, arguments));
_this6.componentName = 'grid-tile__title';
_this6.mdcProps = [];
return _this6;
}
(0, _createClass2.default)(GridListTitleTile, [{
key: "materialDom",
value: function materialDom(props) {
return (0, _preact.h)("span", Object.assign({}, props), props.children);
}
}]);
return GridListTitleTile;
}(_MaterialComponent9.default);
exports.GridListTitleTile = GridListTitleTile;
__decorate([_bindDecorator.bind], GridListTitleTile.prototype, "materialDom", null);
var GridListSupportTextTile =
/*#__PURE__*/
function (_MaterialComponent7) {
(0, _inherits2.default)(GridListSupportTextTile, _MaterialComponent7);
function GridListSupportTextTile() {
var _this7;
(0, _classCallCheck2.default)(this, GridListSupportTextTile);
_this7 = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(GridListSupportTextTile).apply(this, arguments));
_this7.componentName = 'grid-tile__support-text';
_this7.mdcProps = [];
return _this7;
}
(0, _createClass2.default)(GridListSupportTextTile, [{
key: "materialDom",
value: function materialDom(props) {
return (0, _preact.h)("span", Object.assign({}, props), props.children);
}
}]);
return GridListSupportTextTile;
}(_MaterialComponent9.default);
exports.GridListSupportTextTile = GridListSupportTextTile;
__decorate([_bindDecorator.bind], GridListSupportTextTile.prototype, "materialDom", null);
var GridListIconTile =
/*#__PURE__*/
function (_Icon) {
(0, _inherits2.default)(GridListIconTile, _Icon);
function GridListIconTile() {
var _this8;
(0, _classCallCheck2.default)(this, GridListIconTile);
_this8 = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(GridListIconTile).apply(this, arguments));
_this8.componentName = 'grid-tile__icon';
return _this8;
}
return GridListIconTile;
}(_Icon2.default);
var GridList =
/*#__PURE__*/
function (_MaterialComponent8) {
(0, _inherits2.default)(GridList, _MaterialComponent8);
function GridList() {
var _this9;
(0, _classCallCheck2.default)(this, GridList);
_this9 = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(GridList).apply(this, arguments));
_this9.componentName = 'grid-list';
_this9.mdcProps = ['header-caption', 'twoline-caption', 'tile-gutter-1'];
return _this9;
}
(0, _createClass2.default)(GridList, [{
key: "isValidValue",
value: function isValidValue(validationValues, testValue) {
return validationValues && validationValues.findIndex(function (val) {
return val === testValue;
}) >= 0;
}
}, {
key: "mapClassName",
value: function mapClassName(propKey, props) {
var propValue = props[propKey];
var validationValues = GridList.validationValuesByKey[propKey];
return this.isValidValue(validationValues, propValue) ? "mdc-".concat(this.componentName, "--").concat(propKey, "-").concat(propValue) : '';
}
}, {
key: "materialDom",
value: function materialDom(props) {
var _this10 = this;
var className = Object.keys(GridList.validationValuesByKey).map(function (key) {
return _this10.mapClassName(key, props);
}).filter(notEmptyString).join(' ');
return (0, _preact.h)("div", Object.assign({}, props, {
className: className
}), props.children);
}
}]);
return GridList;
}(_MaterialComponent9.default);
exports.GridList = GridList;
GridList.validationValuesByKey = {
'tile-aspect': ['1x1', '16x9', '2x3', '3x2', '4x3', '3x4'],
'with-icon-align': ['start', 'end']
};
var default_1 =
/*#__PURE__*/
function (_GridList) {
(0, _inherits2.default)(default_1, _GridList);
function default_1() {
(0, _classCallCheck2.default)(this, default_1);
return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(default_1).apply(this, arguments));
}
return default_1;
}(GridList);
exports.default = default_1;
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