optimizely-oui
Version:
Optimizely's Component Library.
67 lines (56 loc) • 3.09 kB
JavaScript
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); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import React from "react";
import PropTypes from "prop-types";
import classNames from "classnames";
import Button from "../Button";
import Icon from "react-oui-icons";
var Card = function Card(_ref) {
var children = _ref.children,
className = _ref.className,
onClose = _ref.onClose,
_ref$shadow = _ref.shadow,
shadow = _ref$shadow === void 0 ? false : _ref$shadow,
testSection = _ref.testSection,
title = _ref.title,
props = _objectWithoutProperties(_ref, ["children", "className", "onClose", "shadow", "testSection", "title"]);
var closer = React.createElement(Button, {
style: "unstyled",
onClick: onClose,
testSection: "".concat(testSection, "-close")
}, React.createElement(Icon, {
name: "close"
}));
var classes = classNames({
"push--bottom border--all": true,
"oui-shadow--light": shadow
}, className);
return React.createElement("div", _extends({
"data-oui-component": true,
className: classes
}, props), title && React.createElement("div", {
className: "flex border--bottom background--faint soft soft-half--ends"
}, React.createElement("h4", {
className: "flex--1",
"data-test-section": "".concat(testSection, "-title")
}, title), React.createElement("div", null, onClose && closer)), React.createElement("div", {
className: "soft",
"data-test-section": "".concat(testSection, "-body")
}, children));
};
Card.propTypes = {
/** Elements that appears within the component */
children: PropTypes.oneOfType([PropTypes.string, PropTypes.node]).isRequired,
/** CSS class names. */
className: PropTypes.string,
/** method to invoke when a close element is clicked */
onClose: PropTypes.func,
/** Display a subtle shadow around card. */
shadow: PropTypes.bool,
/** For automated testing only. */
testSection: PropTypes.string,
/** What is the card title */
title: PropTypes.string.isRequired
};
export default Card;