zrmc
Version:
ZRMC is an ES7 React wrapper for Material Components Web.
101 lines (82 loc) • 2.62 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _objectWithoutProperties2 = require("babel-runtime/helpers/objectWithoutProperties");
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
var _react = require("react");
var _react2 = _interopRequireDefault(_react);
var _propTypes = require("prop-types");
var _propTypes2 = _interopRequireDefault(_propTypes);
var _primary = require("./primary");
var _primary2 = _interopRequireDefault(_primary);
var _ = require("../");
var _2 = _interopRequireDefault(_);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* mdc-card
* See
* https://material.io/components/web/catalog/cards/
* https://material-components-web.appspot.com/card.html
*
*/
/**
* Copyright (c) 2015-present, CWB SAS
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var MDC_CARD = "mdc-card";
var Card = function Card(_ref) {
var children = _ref.children,
title = _ref.title,
subTitle = _ref.subTitle,
largeTitle = _ref.largeTitle,
horizontalBlock = _ref.horizontalBlock,
props = (0, _objectWithoutProperties3.default)(_ref, ["children", "title", "subTitle", "largeTitle", "horizontalBlock"]);
var classes = MDC_CARD;
var primary = "";
if (title || subTitle) {
primary = _react2.default.createElement(_primary2.default, { title: title, subTitle: subTitle, largeTitle: largeTitle });
}
var ca = children;
if (horizontalBlock) {
// Extract other sections without CardActions from children
var sections = _react.Children.map(children, function (child) {
if (child.props && child.props.isactions !== "true") {
return child;
}
ca = _react2.default.cloneElement(child);
return null;
});
primary = _react2.default.createElement(
"div",
{ className: "mdc-card__horizontal-block" },
primary,
sections
);
}
return _2.default.render(_react2.default.createElement(
"div",
{ className: classes },
primary,
ca
), props);
};
Card.defaultProps = {
mdcElement: MDC_CARD,
children: null,
title: null,
subTitle: null,
largeTitle: false,
horizontalBlock: false
};
Card.propTypes = {
mdcElement: _propTypes2.default.string,
children: _propTypes2.default.node,
title: _propTypes2.default.string,
subTitle: _propTypes2.default.string,
largeTitle: _propTypes2.default.bool,
horizontalBlock: _propTypes2.default.bool
};
exports.default = Card;