rmwc
Version:
A thin React wrapper for Material Design (Web) Components
196 lines (147 loc) • 8.13 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 _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
var _Button = require('../Button');
var _Ripple = require('../Ripple');
var _Icon = require('../Icon');
var _IconToggle = require('../IconToggle');
var _Base = require('../Base');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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'
});
/** A Card action Button. Will return a Button component by default. */
var CardAction = function CardAction(_ref) {
var icon = _ref.icon,
iconToggle = _ref.iconToggle,
className = _ref.className,
rest = _objectWithoutProperties(_ref, ['icon', 'iconToggle', 'className']);
if (icon) {
return React.createElement(
_Ripple.Ripple,
{ unbounded: true },
React.createElement(_Icon.Icon, Object.assign({}, rest, {
use: rest.use,
className: (0, _classnames2.default)(className, 'mdc-card__action', 'mdc-card__action--icon')
}))
);
}
if (iconToggle) {
if (!rest.on || !rest.off) {
throw Error('You must specify `on` and `off` when using the IconToggle');
}
return React.createElement(_IconToggle.IconToggle, Object.assign({}, rest, {
on: rest.on,
off: rest.off,
className: (0, _classnames2.default)(className, 'mdc-card__action', 'mdc-card__action--icon')
}));
}
return React.createElement(_Button.Button, Object.assign({}, rest, {
className: (0, _classnames2.default)(className, 'mdc-card__action', 'mdc-card__action--button')
}));
};
exports.CardAction = CardAction;
CardAction.displayName = 'CardAction';