UNPKG

4.15 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', { value: true });
4
5function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
7var slicedToArray = require('./slicedToArray-ef426d0f.js');
8require('./unsupportedIterableToArray-8a00e599.js');
9var React = require('react');
10var React__default = _interopDefault(React);
11require('./_commonjsHelpers-72d386ba.js');
12var index = require('./index-b0606964.js');
13require('./defineProperty-0921a47c.js');
14require('./toConsumableArray-7f36359f.js');
15var _styled = require('styled-components');
16var _styled__default = _interopDefault(_styled);
17require('./getPrototypeOf-e2d1e599.js');
18require('./color.js');
19require('./components.js');
20require('./contains-component.js');
21require('./css.js');
22require('./dayjs.min-aa59a48e.js');
23require('./date.js');
24require('./miscellaneous.js');
25require('./environment.js');
26require('./font.js');
27require('./math-ecfd5d91.js');
28require('./characters.js');
29require('./format.js');
30require('./keycodes.js');
31require('./url.js');
32require('./web3.js');
33var constants = require('./constants.js');
34require('./breakpoints.js');
35require('./springs.js');
36require('./text-styles.js');
37require('./theme-dark.js');
38require('./theme-light.js');
39var Theme = require('./Theme.js');
40var _extends$1 = require('./extends-40571110.js');
41var objectWithoutProperties = require('./objectWithoutProperties-35db8ab0.js');
42var index$1 = require('./index-ecc57c9f.js');
43require('./FocusVisible.js');
44var ButtonBase = require('./ButtonBase.js');
45
46var DEFAULT_WIDTH = 35 * constants.GU;
47var DEFAULT_HEIGHT = 40 * constants.GU;
48
49function dimension(insideCardLayout, value, defaultValue) {
50 if (insideCardLayout) {
51 return '100%';
52 }
53
54 if (typeof value === 'number') {
55 value = "".concat(value, "px");
56 }
57
58 return value === undefined ? defaultValue : value;
59}
60
61var _StyledDiv = _styled__default("div").withConfig({
62 displayName: "Card___StyledDiv",
63 componentId: "sc-13r75gj-0"
64})(["position:relative;width:", ";height:", ";background:", ";border:1px solid ", ";border-radius:", "px;cursor:", ";display:flex;flex-direction:column;align-items:center;justify-content:center;", ""], function (p) {
65 return p._css;
66}, function (p) {
67 return p._css2;
68}, function (p) {
69 return p._css3;
70}, function (p) {
71 return p._css4;
72}, constants.RADIUS, function (p) {
73 return p._css5;
74}, function (p) {
75 return p._css6;
76});
77
78function Card(_ref) {
79 var children = _ref.children,
80 width = _ref.width,
81 height = _ref.height,
82 onClick = _ref.onClick,
83 props = objectWithoutProperties._objectWithoutProperties(_ref, ["children", "width", "height", "onClick"]);
84
85 var theme = Theme.useTheme();
86
87 var _useInside = index$1.o('CardLayout'),
88 _useInside2 = slicedToArray._slicedToArray(_useInside, 1),
89 insideCardLayout = _useInside2[0];
90
91 var interactive = Boolean(onClick);
92 var interactiveProps = interactive ? {
93 as: ButtonBase.default,
94 element: 'div',
95 focusRingRadius: constants.RADIUS,
96 onClick: onClick
97 } : {};
98 var cssWidth = dimension(insideCardLayout, width, "".concat(DEFAULT_WIDTH, "px"));
99 var cssHeight = dimension(insideCardLayout, height, "".concat(DEFAULT_HEIGHT, "px"));
100 return /*#__PURE__*/React__default.createElement(_StyledDiv, _extends$1._extends({}, interactiveProps, props, {
101 _css: cssWidth,
102 _css2: cssHeight,
103 _css3: theme.surface,
104 _css4: theme.border,
105 _css5: interactive ? 'pointer' : 'default',
106 _css6: interactive && _styled.css(["border:0;box-shadow:0px 1px 3px rgba(0,0,0,0.15);transition-property:transform,box-shadow;transition-duration:50ms;transition-timing-function:ease-in-out;text-align:left;white-space:normal;&:active{transform:translateY(1px);box-shadow:0px 1px 3px rgba(0,0,0,0.08);}"])
107 }), children);
108}
109
110Card.propTypes = {
111 children: index.PropTypes.node,
112 height: index.PropTypes.oneOfType([index.PropTypes.string, index.PropTypes.number]),
113 width: index.PropTypes.oneOfType([index.PropTypes.string, index.PropTypes.number]),
114 onClick: index.PropTypes.func
115};
116
117exports.default = Card;
118//# sourceMappingURL=Card.js.map