rmwc
Version:
A thin React wrapper for Material Design (Web) Components
198 lines (146 loc) • 8.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.CardAction = exports.CardActionIcons = exports.CardActionButtons = exports.CardActions = exports.CardPrimaryAction = exports.CardMediaContent = exports.CardMedia = exports.Card = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
var _react = require('react');
var React = _interopRequireWildcard(_react);
var _Button = require('../Button');
var _Base = require('../Base');
var _IconButton = require('../IconButton');
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
/** A Card Component */
/****************************************************************
* Public
****************************************************************/
var Card = exports.Card = function (_simpleTag) {
_inherits(Card, _simpleTag);
function Card() {
_classCallCheck(this, Card);
return _possibleConstructorReturn(this, (Card.__proto__ || Object.getPrototypeOf(Card)).apply(this, arguments));
}
_createClass(Card, [{
key: 'render',
value: function render() {
return _get(Card.prototype.__proto__ || Object.getPrototypeOf(Card.prototype), 'render', this).call(this);
}
}]);
return Card;
}((0, _Base.simpleTag)({
displayName: 'Card',
classNames: function classNames(props) {
return ['mdc-card', {
'mdc-card--outlined': props.outlined
}];
},
consumeProps: ['outlined']
}));
/** Media area that displays a custom background-image with background-size: cover */
var CardMedia = exports.CardMedia = function (_simpleTag2) {
_inherits(CardMedia, _simpleTag2);
function CardMedia() {
_classCallCheck(this, CardMedia);
return _possibleConstructorReturn(this, (CardMedia.__proto__ || Object.getPrototypeOf(CardMedia)).apply(this, arguments));
}
_createClass(CardMedia, [{
key: 'render',
value: function render() {
return _get(CardMedia.prototype.__proto__ || Object.getPrototypeOf(CardMedia.prototype), 'render', this).call(this);
}
}]);
return CardMedia;
}((0, _Base.simpleTag)({
displayName: 'CardMedia',
tag: 'section',
classNames: function classNames(props) {
return ['mdc-card__media', {
'mdc-card__media--square': props.square,
'mdc-card__media--16-9': props.sixteenByNine
}];
},
consumeProps: ['square', 'sixteenByNine']
}));
/** An absolutely-positioned box the same size as the media area, for displaying a title or icon on top of the background-image */
var CardMediaContent = exports.CardMediaContent = (0, _Base.simpleTag)({
displayName: 'CardMediaContent',
classNames: 'mdc-card__media-content'
});
/** The main clickable area for the primary content of the card */
var CardPrimaryAction = exports.CardPrimaryAction = (0, _Base.withRipple)({ surface: false })((0, _Base.simpleTag)({
displayName: 'CardPrimaryAction',
classNames: 'mdc-card__primary-action'
}));
/** Row containing action buttons and/or icons */
var CardActions = exports.CardActions = function (_simpleTag3) {
_inherits(CardActions, _simpleTag3);
function CardActions() {
_classCallCheck(this, CardActions);
return _possibleConstructorReturn(this, (CardActions.__proto__ || Object.getPrototypeOf(CardActions)).apply(this, arguments));
}
_createClass(CardActions, [{
key: 'render',
value: function render() {
return _get(CardActions.prototype.__proto__ || Object.getPrototypeOf(CardActions.prototype), 'render', this).call(this);
}
}]);
return CardActions;
}((0, _Base.simpleTag)({
displayName: 'CardActions',
tag: 'section',
classNames: function classNames(props) {
return ['mdc-card__actions', { 'mdc-card__actions--full-bleed': props.fullBleed }];
},
consumeProps: ['fullBleed']
}));
/** A group of action buttons, displayed on the left side of the card (in LTR), adjacent to CardActionIcons */
var CardActionButtons = exports.CardActionButtons = (0, _Base.simpleTag)({
displayName: 'CardActionButtons',
classNames: 'mdc-card__action-buttons'
});
/** A group of supplemental action icons, displayed on the right side of the card (in LTR), adjacent to CardActionButtons */
var CardActionIcons = exports.CardActionIcons = (0, _Base.simpleTag)({
displayName: 'CardActionIcons',
classNames: 'mdc-card__action-icons'
});
var CardActionIcon = (0, _Base.simpleTag)({
tag: _IconButton.IconButton,
classNames: ['mdc-card__action', 'mdc-card__action--icon']
});
var CardActionButton = (0, _Base.simpleTag)({
tag: _Button.Button,
classNames: ['mdc-card__action', 'mdc-card__action--button']
});
/** A Card action Button. Depending on the props that are passed, this will either render an instance of the Button component, or the IconButton component. */
var CardAction = exports.CardAction = function (_React$Component) {
_inherits(CardAction, _React$Component);
function CardAction() {
_classCallCheck(this, CardAction);
return _possibleConstructorReturn(this, (CardAction.__proto__ || Object.getPrototypeOf(CardAction)).apply(this, arguments));
}
_createClass(CardAction, [{
key: 'render',
value: function render() {
var _props = this.props,
isIcon = _props.isIcon,
rest = _objectWithoutProperties(_props, ['isIcon']);
var _props2 = this.props,
onContent = _props2.onContent,
offContent = _props2.offContent,
use = _props2.use;
return isIcon || onContent || offContent || use ? React.createElement(CardActionIcon, rest) : React.createElement(CardActionButton, rest);
}
}]);
return CardAction;
}(React.Component);
Object.defineProperty(CardAction, 'displayName', {
enumerable: true,
writable: true,
value: 'CardAction'
});
CardAction.displayName = 'CardAction';