@cloudflare/component-card 4.0.9 → 4.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,38 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [4.0.13](http://stash.cfops.it:7999/fe/stratus/compare/@cloudflare/component-card@4.0.12...@cloudflare/component-card@4.0.13) (2021-11-16)
7
+
8
+ **Note:** Version bump only for package @cloudflare/component-card
9
+
10
+
11
+
12
+
13
+
14
+ ## [4.0.12](http://stash.cfops.it:7999/fe/stratus/compare/@cloudflare/component-card@4.0.11...@cloudflare/component-card@4.0.12) (2021-11-15)
15
+
16
+ **Note:** Version bump only for package @cloudflare/component-card
17
+
18
+
19
+
20
+
21
+
22
+ ## [4.0.11](http://stash.cfops.it:7999/fe/stratus/compare/@cloudflare/component-card@4.0.10...@cloudflare/component-card@4.0.11) (2021-11-15)
23
+
24
+ **Note:** Version bump only for package @cloudflare/component-card
25
+
26
+
27
+
28
+
29
+
30
+ ## [4.0.10](http://stash.cfops.it:7999/fe/stratus/compare/@cloudflare/component-card@4.0.9...@cloudflare/component-card@4.0.10) (2021-11-05)
31
+
32
+ **Note:** Version bump only for package @cloudflare/component-card
33
+
34
+
35
+
36
+
37
+
6
38
  ## [4.0.9](http://stash.cfops.it:7999/fe/stratus/compare/@cloudflare/component-card@4.0.8...@cloudflare/component-card@4.0.9) (2021-11-05)
7
39
 
8
40
  **Note:** Version bump only for package @cloudflare/component-card
@@ -4162,7 +4194,7 @@ references ([fe1d8b5](http://stash.cfops.it:7999/www/cf-ux/commits/fe1d8b5))
4162
4194
 
4163
4195
  ### Bug Fixes
4164
4196
 
4165
- * **cf-component-card:** UI-164 Add missing CardToolbarLink component to type
4197
+ * **cf-component-card:** UI-164 Add missing CardToolbarTrigger component to type
4166
4198
  definitions ([cfe8e21](http://stash.cfops.it:7999/www/cf-ux/commits/cfe8e21))
4167
4199
 
4168
4200
  <a name="4.1.1"></a>
package/README.md CHANGED
@@ -78,14 +78,9 @@ class CardComponent extends React.Component {
78
78
  />
79
79
  <CardToolbar
80
80
  controls={[]}
81
- links={[
81
+ triggers={[
82
82
  <CardToolbarLink
83
- key="ToolBarLink"
84
- expandable={false}
85
- isActive={false}
86
- onClick={() =>
87
- window.open('https://en.wikipedia.org/wiki/Main_Page')
88
- }
83
+ href="https://en.wikipedia.org/wiki/Main_Page"
89
84
  >
90
85
  Wikipedia
91
86
  </CardToolbarLink>
package/es/CardDrawer.js CHANGED
@@ -1,3 +1,4 @@
1
+ import PropTypes from 'prop-types';
1
2
  import { createStyledComponent } from '@cloudflare/style-container';
2
3
  const CardDrawer = createStyledComponent(({
3
4
  theme,
@@ -5,5 +6,16 @@ const CardDrawer = createStyledComponent(({
5
6
  }) => ({
6
7
  borderTop: isActive ? `1px solid ${theme.colors.gray[7]}` : 'initial',
7
8
  padding: isActive ? 3 : 'initial'
8
- }));
9
+ }), 'div', ['role', 'aria-labelledby']);
10
+ CardDrawer.propTypes = {
11
+ id: PropTypes.string.isRequired,
12
+ key: PropTypes.string.isRequired,
13
+ 'aria-labelledby': PropTypes.string.isRequired,
14
+ isActive: PropTypes.bool.isRequired,
15
+ addToggleFunction: PropTypes.func.isRequired,
16
+ role: PropTypes.string
17
+ };
18
+ CardDrawer.defaultProps = {
19
+ role: 'region'
20
+ };
9
21
  export default CardDrawer;
package/es/CardDrawers.js CHANGED
@@ -8,9 +8,10 @@ import React from 'react';
8
8
  import PropTypes from 'prop-types';
9
9
  import CardSection from './CardSection';
10
10
  import CardToolbar from './CardToolbar';
11
- import CardToolbarLink from './CardToolbarLink';
11
+ import CardToolbarDrawerTrigger from './CardToolbarDrawerTrigger';
12
12
  import CardPropTypes from './CardPropTypes';
13
13
  import CardDrawer from './CardDrawer';
14
+ import CardToolbarLink from './CardToolbarLink';
14
15
  let UNIQUE_ID = 0;
15
16
 
16
17
  class CardDrawers extends React.Component {
@@ -52,40 +53,52 @@ class CardDrawers extends React.Component {
52
53
 
53
54
  render() {
54
55
  const active = this.props.hasOwnProperty('active') ? this.props.active : this.state.active;
55
- const links = [];
56
+ const triggers = [];
56
57
  const drawers = [];
57
58
  this.props.drawers.forEach((_ref) => {
58
- let drawerId = _ref.id,
59
+ let drawerIdProps = _ref.id,
59
60
  name = _ref.name,
60
61
  content = _ref.content,
61
62
  drawerComponent = _ref.drawerComponent,
62
63
  onClick = _ref.onClick,
63
- rest = _objectWithoutProperties(_ref, ["id", "name", "content", "drawerComponent", "onClick"]);
64
+ href = _ref.href,
65
+ rest = _objectWithoutProperties(_ref, ["id", "name", "content", "drawerComponent", "onClick", "href"]);
64
66
 
65
67
  // The component used for the drawer can be overridden
66
68
  const Drawer = drawerComponent || CardDrawer;
69
+ const triggerId = `trigger-${this._cardId}-${drawerIdProps}`;
70
+ const drawerId = `drawer-${this._cardId}-${drawerIdProps}`;
67
71
  const isActive = drawerId === active;
68
- const id = `card-${this._cardId}-drawer-${drawerId}`;
69
72
  onClick && this.addToggleFunction(drawerId, onClick);
70
- links.push( /*#__PURE__*/React.createElement(CardToolbarLink, {
71
- key: drawerId,
72
- id: id,
73
- isActive: isActive,
74
- onClick: () => this.handleLinkClick(drawerId),
75
- expandable: content ? true : false
76
- }, name));
77
- content && drawers.push( /*#__PURE__*/React.createElement(Drawer, _extends({
78
- key: drawerId,
79
- role: "tabpanel",
80
- "aria-labelledby": id,
81
- "aria-hidden": isActive ? 'false' : 'true',
82
- isActive: isActive,
83
- addToggleFunction: this.addToggleFunction.bind(this, drawerId)
84
- }, rest), isActive && content));
73
+
74
+ if (!content && !href) {
75
+ console.error('Drawer items must have either `content` or `href` property.');
76
+ } else if (content && href) {
77
+ console.error('Drawer items must have either `content` or `href` property, but not both.');
78
+ } else {
79
+ triggers.push(content ? /*#__PURE__*/React.createElement(CardToolbarDrawerTrigger, {
80
+ key: triggerId,
81
+ id: triggerId,
82
+ isActive: isActive,
83
+ onClick: () => this.handleLinkClick(drawerId),
84
+ ariaControls: drawerId,
85
+ ariaExpanded: isActive
86
+ }, name) : /*#__PURE__*/React.createElement(CardToolbarLink, {
87
+ id: triggerId,
88
+ href: href
89
+ }, name));
90
+ content && drawers.push( /*#__PURE__*/React.createElement(Drawer, _extends({
91
+ key: drawerId,
92
+ id: drawerId,
93
+ "aria-labelledby": triggerId,
94
+ isActive: isActive,
95
+ addToggleFunction: this.addToggleFunction.bind(this, drawerId)
96
+ }, rest), isActive && content));
97
+ }
85
98
  });
86
99
  return /*#__PURE__*/React.createElement(CardSection, null, /*#__PURE__*/React.createElement(CardToolbar, {
87
100
  controls: this.props.controls,
88
- links: links
101
+ triggers: triggers
89
102
  }), /*#__PURE__*/React.createElement("div", null, drawers));
90
103
  }
91
104
 
package/es/CardToolbar.js CHANGED
@@ -16,7 +16,7 @@ const styles = ({
16
16
  }
17
17
  });
18
18
 
19
- const Links = createComponent(() => ({
19
+ const Triggers = createComponent(() => ({
20
20
  float: 'right',
21
21
  position: 'relative'
22
22
  }), 'div');
@@ -24,17 +24,15 @@ const Links = createComponent(() => ({
24
24
  const CardToolbar = ({
25
25
  className,
26
26
  controls,
27
- links
27
+ triggers
28
28
  }) => /*#__PURE__*/React.createElement("div", {
29
29
  className: className
30
- }, /*#__PURE__*/React.createElement("div", null, controls), /*#__PURE__*/React.createElement(Links, {
31
- role: "tablist"
32
- }, links));
30
+ }, /*#__PURE__*/React.createElement("div", null, controls), /*#__PURE__*/React.createElement(Triggers, null, triggers));
33
31
 
34
32
  CardToolbar.propTypes = {
35
33
  className: PropTypes.string,
36
34
  controls: PropTypes.any,
37
- links: PropTypes.any
35
+ triggers: PropTypes.any
38
36
  };
39
37
  CardToolbar.displayName = 'CardToolbar';
40
38
  export default createStyledComponent(styles, CardToolbar);
@@ -0,0 +1,52 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { TextButton } from '@cloudflare/component-button';
4
+ import { ArrowSwivel } from '@cloudflare/component-arrow-swivel';
5
+
6
+ class CardToolbarDrawerTrigger extends React.Component {
7
+ constructor(props) {
8
+ super(props);
9
+ this.handleClick = this.handleClick.bind(this);
10
+ }
11
+
12
+ handleClick(e) {
13
+ e.preventDefault();
14
+ this.props.onClick();
15
+ }
16
+
17
+ render() {
18
+ const _this$props = this.props,
19
+ id = _this$props.id,
20
+ children = _this$props.children,
21
+ isActive = _this$props.isActive,
22
+ ariaControls = _this$props.ariaControls,
23
+ ariaExpanded = _this$props.ariaExpanded;
24
+ return /*#__PURE__*/React.createElement(TextButton, {
25
+ id: id,
26
+ onClick: this.handleClick,
27
+ isActive: isActive,
28
+ px: 3,
29
+ py: 2,
30
+ fontSize: 3,
31
+ "aria-controls": ariaControls,
32
+ "aria-expanded": ariaExpanded
33
+ }, children, /*#__PURE__*/React.createElement(ArrowSwivel, {
34
+ isActive: isActive,
35
+ duration: 50
36
+ }));
37
+ }
38
+
39
+ }
40
+
41
+ CardToolbarDrawerTrigger.propTypes = {
42
+ onClick: PropTypes.func.isRequired,
43
+ isActive: PropTypes.bool.isRequired,
44
+ id: PropTypes.string.isRequired,
45
+ children: PropTypes.node,
46
+ ariaControls: PropTypes.string.isRequired,
47
+ ariaExpanded: PropTypes.bool.isRequired
48
+ };
49
+ CardToolbarDrawerTrigger.defaultProps = {
50
+ isActive: false
51
+ };
52
+ export default CardToolbarDrawerTrigger;
@@ -1,47 +1,25 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { Link } from '@cloudflare/component-link';
4
-
5
- class CardToolbarLink extends React.Component {
6
- constructor(props) {
7
- super(props);
8
- this.handleClick = this.handleClick.bind(this);
9
- }
10
-
11
- handleClick(e) {
12
- e.preventDefault();
13
- this.props.onClick();
14
- }
15
-
16
- render() {
17
- const _this$props = this.props,
18
- id = _this$props.id,
19
- children = _this$props.children,
20
- expandable = _this$props.expandable,
21
- isActive = _this$props.isActive;
22
- return /*#__PURE__*/React.createElement(Link, {
23
- role: expandable ? 'tab' : 'link',
24
- id: id,
25
- onClick: this.handleClick,
26
- isActive: isActive,
27
- expandable: expandable,
28
- px: 3,
29
- py: 2,
30
- fontSize: 3
31
- }, children);
32
- }
33
-
34
- }
35
-
4
+ import { createComponent } from '@cloudflare/style-container';
5
+ const CardToolbarLink = createComponent({}, ({
6
+ id,
7
+ href,
8
+ children
9
+ }) => {
10
+ return /*#__PURE__*/React.createElement(Link, {
11
+ px: 3,
12
+ py: 2,
13
+ fontSize: 3,
14
+ target: "_blank",
15
+ rel: "noopener noreferrer",
16
+ id: id ? id : null,
17
+ href: href
18
+ }, children);
19
+ });
36
20
  CardToolbarLink.propTypes = {
37
- onClick: PropTypes.func.isRequired,
38
- isActive: PropTypes.bool.isRequired,
39
21
  id: PropTypes.string,
40
- children: PropTypes.node,
41
- expandable: PropTypes.bool
42
- };
43
- CardToolbarLink.defaultProps = {
44
- expandable: true,
45
- isActive: false
22
+ href: PropTypes.string.isRequired,
23
+ children: PropTypes.node.isRequired
46
24
  };
47
25
  export default CardToolbarLink;
package/es/index.js CHANGED
@@ -8,7 +8,8 @@ import CardSection from './CardSection';
8
8
  import CardTitle from './CardTitle';
9
9
  import CardFooter from './CardFooter';
10
10
  import CardToolbar from './CardToolbar';
11
+ import CardToolbarDrawerTrigger from './CardToolbarDrawerTrigger';
11
12
  import CardToolbarLink from './CardToolbarLink';
12
13
  import CardPropTypes from './CardPropTypes';
13
14
  import CardDrawer from './CardDrawer';
14
- export { Card, CardContent, CardControl, CardDrawer, CardDrawers, CardMessages, CardPropTypes, CardSection, CardBlock, CardTitle, CardFooter, CardToolbar, CardToolbarLink };
15
+ export { Card, CardContent, CardControl, CardDrawer, CardDrawers, CardMessages, CardPropTypes, CardSection, CardBlock, CardTitle, CardFooter, CardToolbar, CardToolbarDrawerTrigger, CardToolbarLink };
package/index.d.ts CHANGED
@@ -107,20 +107,32 @@ export const CardTitle: typeof CardTitleUnstyled;
107
107
  ////////////////////////////////////////////////////////////////////////
108
108
  export type TCardToolbarProps = {
109
109
  controls?: any;
110
- links?: React.ReactElement<TCardToolbarLinkProps>[];
110
+ triggers?:
111
+ | React.ReactElement<TCardToolbarDrawerTriggerProps>[]
112
+ | React.ReactElement<TCardToolbarLinkProps>[];
111
113
  };
112
114
  export type TCardToolbarRule = TRule<{}>;
113
115
  export const CardToolbarTheme: TCardToolbarRule;
114
116
  export const CardToolbarUnstyled: React.StatelessComponent<TCardToolbarProps>;
115
117
  export const CardToolbar: typeof CardToolbarUnstyled;
116
118
 
117
- // <CardToolbarLink>
119
+ // <CardToolbarDrawerTrigger>
118
120
  ////////////////////////////////////////////////////////////////////////
119
- export type TCardToolbarLinkProps = {
120
- to?: string;
121
+ export type TCardToolbarDrawerTriggerProps = {
121
122
  onClick: () => void;
122
123
  isActive: boolean;
123
124
  id?: string;
124
125
  expandable?: boolean;
126
+ ariaControls?: string;
127
+ ariaExpanded?: boolean;
128
+ };
129
+ export const CardToolbarDrawerTrigger: React.StatelessComponent<TCardToolbarDrawerTriggerProps>;
130
+
131
+ // <CardToolbarLink>
132
+ ////////////////////////////////////////////////////////////////////////
133
+ export type TCardToolbarLinkProps = {
134
+ id?: string;
135
+ href: string;
136
+ children: React.ReactNode;
125
137
  };
126
138
  export const CardToolbarLink: React.StatelessComponent<TCardToolbarLinkProps>;
package/lib/CardDrawer.js CHANGED
@@ -5,8 +5,12 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
+ var _propTypes = _interopRequireDefault(require("prop-types"));
9
+
8
10
  var _styleContainer = require("@cloudflare/style-container");
9
11
 
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
10
14
  var CardDrawer = (0, _styleContainer.createStyledComponent)(function (_ref) {
11
15
  var theme = _ref.theme,
12
16
  isActive = _ref.isActive;
@@ -14,6 +18,17 @@ var CardDrawer = (0, _styleContainer.createStyledComponent)(function (_ref) {
14
18
  borderTop: isActive ? "1px solid ".concat(theme.colors.gray[7]) : 'initial',
15
19
  padding: isActive ? 3 : 'initial'
16
20
  };
17
- });
21
+ }, 'div', ['role', 'aria-labelledby']);
22
+ CardDrawer.propTypes = {
23
+ id: _propTypes.default.string.isRequired,
24
+ key: _propTypes.default.string.isRequired,
25
+ 'aria-labelledby': _propTypes.default.string.isRequired,
26
+ isActive: _propTypes.default.bool.isRequired,
27
+ addToggleFunction: _propTypes.default.func.isRequired,
28
+ role: _propTypes.default.string
29
+ };
30
+ CardDrawer.defaultProps = {
31
+ role: 'region'
32
+ };
18
33
  var _default = CardDrawer;
19
34
  exports.default = _default;
@@ -15,12 +15,14 @@ var _CardSection = _interopRequireDefault(require("./CardSection"));
15
15
 
16
16
  var _CardToolbar = _interopRequireDefault(require("./CardToolbar"));
17
17
 
18
- var _CardToolbarLink = _interopRequireDefault(require("./CardToolbarLink"));
18
+ var _CardToolbarDrawerTrigger = _interopRequireDefault(require("./CardToolbarDrawerTrigger"));
19
19
 
20
20
  var _CardPropTypes = _interopRequireDefault(require("./CardPropTypes"));
21
21
 
22
22
  var _CardDrawer = _interopRequireDefault(require("./CardDrawer"));
23
23
 
24
+ var _CardToolbarLink = _interopRequireDefault(require("./CardToolbarLink"));
25
+
24
26
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
27
 
26
28
  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); }
@@ -107,42 +109,54 @@ var CardDrawers = /*#__PURE__*/function (_React$Component) {
107
109
  var _this3 = this;
108
110
 
109
111
  var active = this.props.hasOwnProperty('active') ? this.props.active : this.state.active;
110
- var links = [];
112
+ var triggers = [];
111
113
  var drawers = [];
112
114
  this.props.drawers.forEach(function (_ref2) {
113
- var drawerId = _ref2.id,
115
+ var drawerIdProps = _ref2.id,
114
116
  name = _ref2.name,
115
117
  content = _ref2.content,
116
118
  drawerComponent = _ref2.drawerComponent,
117
119
  onClick = _ref2.onClick,
118
- rest = _objectWithoutProperties(_ref2, ["id", "name", "content", "drawerComponent", "onClick"]);
120
+ href = _ref2.href,
121
+ rest = _objectWithoutProperties(_ref2, ["id", "name", "content", "drawerComponent", "onClick", "href"]);
119
122
 
120
123
  // The component used for the drawer can be overridden
121
124
  var Drawer = drawerComponent || _CardDrawer.default;
125
+ var triggerId = "trigger-".concat(_this3._cardId, "-").concat(drawerIdProps);
126
+ var drawerId = "drawer-".concat(_this3._cardId, "-").concat(drawerIdProps);
122
127
  var isActive = drawerId === active;
123
- var id = "card-".concat(_this3._cardId, "-drawer-").concat(drawerId);
124
128
  onClick && _this3.addToggleFunction(drawerId, onClick);
125
- links.push( /*#__PURE__*/_react.default.createElement(_CardToolbarLink.default, {
126
- key: drawerId,
127
- id: id,
128
- isActive: isActive,
129
- onClick: function onClick() {
130
- return _this3.handleLinkClick(drawerId);
131
- },
132
- expandable: content ? true : false
133
- }, name));
134
- content && drawers.push( /*#__PURE__*/_react.default.createElement(Drawer, _extends({
135
- key: drawerId,
136
- role: "tabpanel",
137
- "aria-labelledby": id,
138
- "aria-hidden": isActive ? 'false' : 'true',
139
- isActive: isActive,
140
- addToggleFunction: _this3.addToggleFunction.bind(_this3, drawerId)
141
- }, rest), isActive && content));
129
+
130
+ if (!content && !href) {
131
+ console.error('Drawer items must have either `content` or `href` property.');
132
+ } else if (content && href) {
133
+ console.error('Drawer items must have either `content` or `href` property, but not both.');
134
+ } else {
135
+ triggers.push(content ? /*#__PURE__*/_react.default.createElement(_CardToolbarDrawerTrigger.default, {
136
+ key: triggerId,
137
+ id: triggerId,
138
+ isActive: isActive,
139
+ onClick: function onClick() {
140
+ return _this3.handleLinkClick(drawerId);
141
+ },
142
+ ariaControls: drawerId,
143
+ ariaExpanded: isActive
144
+ }, name) : /*#__PURE__*/_react.default.createElement(_CardToolbarLink.default, {
145
+ id: triggerId,
146
+ href: href
147
+ }, name));
148
+ content && drawers.push( /*#__PURE__*/_react.default.createElement(Drawer, _extends({
149
+ key: drawerId,
150
+ id: drawerId,
151
+ "aria-labelledby": triggerId,
152
+ isActive: isActive,
153
+ addToggleFunction: _this3.addToggleFunction.bind(_this3, drawerId)
154
+ }, rest), isActive && content));
155
+ }
142
156
  });
143
157
  return /*#__PURE__*/_react.default.createElement(_CardSection.default, null, /*#__PURE__*/_react.default.createElement(_CardToolbar.default, {
144
158
  controls: this.props.controls,
145
- links: links
159
+ triggers: triggers
146
160
  }), /*#__PURE__*/_react.default.createElement("div", null, drawers));
147
161
  }
148
162
  }]);
@@ -28,7 +28,7 @@ var styles = function styles(_ref) {
28
28
  };
29
29
  };
30
30
 
31
- var Links = (0, _styleContainer.createComponent)(function () {
31
+ var Triggers = (0, _styleContainer.createComponent)(function () {
32
32
  return {
33
33
  float: 'right',
34
34
  position: 'relative'
@@ -38,18 +38,16 @@ var Links = (0, _styleContainer.createComponent)(function () {
38
38
  var CardToolbar = function CardToolbar(_ref2) {
39
39
  var className = _ref2.className,
40
40
  controls = _ref2.controls,
41
- links = _ref2.links;
41
+ triggers = _ref2.triggers;
42
42
  return /*#__PURE__*/_react.default.createElement("div", {
43
43
  className: className
44
- }, /*#__PURE__*/_react.default.createElement("div", null, controls), /*#__PURE__*/_react.default.createElement(Links, {
45
- role: "tablist"
46
- }, links));
44
+ }, /*#__PURE__*/_react.default.createElement("div", null, controls), /*#__PURE__*/_react.default.createElement(Triggers, null, triggers));
47
45
  };
48
46
 
49
47
  CardToolbar.propTypes = {
50
48
  className: _propTypes.default.string,
51
49
  controls: _propTypes.default.any,
52
- links: _propTypes.default.any
50
+ triggers: _propTypes.default.any
53
51
  };
54
52
  CardToolbar.displayName = 'CardToolbar';
55
53
 
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _react = _interopRequireDefault(require("react"));
11
+
12
+ var _propTypes = _interopRequireDefault(require("prop-types"));
13
+
14
+ var _componentButton = require("@cloudflare/component-button");
15
+
16
+ var _componentArrowSwivel = require("@cloudflare/component-arrow-swivel");
17
+
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+
20
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
21
+
22
+ 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); } }
23
+
24
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
25
+
26
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
27
+
28
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
29
+
30
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
31
+
32
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
33
+
34
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
35
+
36
+ var CardToolbarDrawerTrigger = /*#__PURE__*/function (_React$Component) {
37
+ _inherits(CardToolbarDrawerTrigger, _React$Component);
38
+
39
+ function CardToolbarDrawerTrigger(props) {
40
+ var _this;
41
+
42
+ _classCallCheck(this, CardToolbarDrawerTrigger);
43
+
44
+ _this = _possibleConstructorReturn(this, _getPrototypeOf(CardToolbarDrawerTrigger).call(this, props));
45
+ _this.handleClick = _this.handleClick.bind(_assertThisInitialized(_assertThisInitialized(_this)));
46
+ return _this;
47
+ }
48
+
49
+ _createClass(CardToolbarDrawerTrigger, [{
50
+ key: "handleClick",
51
+ value: function handleClick(e) {
52
+ e.preventDefault();
53
+ this.props.onClick();
54
+ }
55
+ }, {
56
+ key: "render",
57
+ value: function render() {
58
+ var _this$props = this.props,
59
+ id = _this$props.id,
60
+ children = _this$props.children,
61
+ isActive = _this$props.isActive,
62
+ ariaControls = _this$props.ariaControls,
63
+ ariaExpanded = _this$props.ariaExpanded;
64
+ return /*#__PURE__*/_react.default.createElement(_componentButton.TextButton, {
65
+ id: id,
66
+ onClick: this.handleClick,
67
+ isActive: isActive,
68
+ px: 3,
69
+ py: 2,
70
+ fontSize: 3,
71
+ "aria-controls": ariaControls,
72
+ "aria-expanded": ariaExpanded
73
+ }, children, /*#__PURE__*/_react.default.createElement(_componentArrowSwivel.ArrowSwivel, {
74
+ isActive: isActive,
75
+ duration: 50
76
+ }));
77
+ }
78
+ }]);
79
+
80
+ return CardToolbarDrawerTrigger;
81
+ }(_react.default.Component);
82
+
83
+ CardToolbarDrawerTrigger.propTypes = {
84
+ onClick: _propTypes.default.func.isRequired,
85
+ isActive: _propTypes.default.bool.isRequired,
86
+ id: _propTypes.default.string.isRequired,
87
+ children: _propTypes.default.node,
88
+ ariaControls: _propTypes.default.string.isRequired,
89
+ ariaExpanded: _propTypes.default.bool.isRequired
90
+ };
91
+ CardToolbarDrawerTrigger.defaultProps = {
92
+ isActive: false
93
+ };
94
+ var _default = CardToolbarDrawerTrigger;
95
+ exports.default = _default;
@@ -1,7 +1,5 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
4
-
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
@@ -13,77 +11,28 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
13
11
 
14
12
  var _componentLink = require("@cloudflare/component-link");
15
13
 
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
19
-
20
- 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); } }
21
-
22
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
23
-
24
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
25
-
26
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
27
-
28
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
29
-
30
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
14
+ var _styleContainer = require("@cloudflare/style-container");
31
15
 
32
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
33
-
34
- var CardToolbarLink = /*#__PURE__*/function (_React$Component) {
35
- _inherits(CardToolbarLink, _React$Component);
36
-
37
- function CardToolbarLink(props) {
38
- var _this;
39
-
40
- _classCallCheck(this, CardToolbarLink);
41
-
42
- _this = _possibleConstructorReturn(this, _getPrototypeOf(CardToolbarLink).call(this, props));
43
- _this.handleClick = _this.handleClick.bind(_assertThisInitialized(_assertThisInitialized(_this)));
44
- return _this;
45
- }
46
-
47
- _createClass(CardToolbarLink, [{
48
- key: "handleClick",
49
- value: function handleClick(e) {
50
- e.preventDefault();
51
- this.props.onClick();
52
- }
53
- }, {
54
- key: "render",
55
- value: function render() {
56
- var _this$props = this.props,
57
- id = _this$props.id,
58
- children = _this$props.children,
59
- expandable = _this$props.expandable,
60
- isActive = _this$props.isActive;
61
- return /*#__PURE__*/_react.default.createElement(_componentLink.Link, {
62
- role: expandable ? 'tab' : 'link',
63
- id: id,
64
- onClick: this.handleClick,
65
- isActive: isActive,
66
- expandable: expandable,
67
- px: 3,
68
- py: 2,
69
- fontSize: 3
70
- }, children);
71
- }
72
- }]);
73
-
74
- return CardToolbarLink;
75
- }(_react.default.Component);
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
76
17
 
18
+ var CardToolbarLink = (0, _styleContainer.createComponent)({}, function (_ref) {
19
+ var id = _ref.id,
20
+ href = _ref.href,
21
+ children = _ref.children;
22
+ return /*#__PURE__*/_react.default.createElement(_componentLink.Link, {
23
+ px: 3,
24
+ py: 2,
25
+ fontSize: 3,
26
+ target: "_blank",
27
+ rel: "noopener noreferrer",
28
+ id: id ? id : null,
29
+ href: href
30
+ }, children);
31
+ });
77
32
  CardToolbarLink.propTypes = {
78
- onClick: _propTypes.default.func.isRequired,
79
- isActive: _propTypes.default.bool.isRequired,
80
33
  id: _propTypes.default.string,
81
- children: _propTypes.default.node,
82
- expandable: _propTypes.default.bool
83
- };
84
- CardToolbarLink.defaultProps = {
85
- expandable: true,
86
- isActive: false
34
+ href: _propTypes.default.string.isRequired,
35
+ children: _propTypes.default.node.isRequired
87
36
  };
88
37
  var _default = CardToolbarLink;
89
38
  exports.default = _default;
package/lib/index.js CHANGED
@@ -63,6 +63,12 @@ Object.defineProperty(exports, "CardToolbar", {
63
63
  return _CardToolbar.default;
64
64
  }
65
65
  });
66
+ Object.defineProperty(exports, "CardToolbarDrawerTrigger", {
67
+ enumerable: true,
68
+ get: function get() {
69
+ return _CardToolbarDrawerTrigger.default;
70
+ }
71
+ });
66
72
  Object.defineProperty(exports, "CardToolbarLink", {
67
73
  enumerable: true,
68
74
  get: function get() {
@@ -102,6 +108,8 @@ var _CardFooter = _interopRequireDefault(require("./CardFooter"));
102
108
 
103
109
  var _CardToolbar = _interopRequireDefault(require("./CardToolbar"));
104
110
 
111
+ var _CardToolbarDrawerTrigger = _interopRequireDefault(require("./CardToolbarDrawerTrigger"));
112
+
105
113
  var _CardToolbarLink = _interopRequireDefault(require("./CardToolbarLink"));
106
114
 
107
115
  var _CardPropTypes = _interopRequireDefault(require("./CardPropTypes"));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudflare/component-card",
3
3
  "description": "Cloudflare Card Component",
4
- "version": "4.0.9",
4
+ "version": "4.0.13",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
7
7
  "author": "James Kyle <jkyle@cloudflare.com>",
@@ -11,8 +11,10 @@
11
11
  "access": "public"
12
12
  },
13
13
  "dependencies": {
14
- "@cloudflare/component-link": "^4.0.9",
15
- "@cloudflare/style-container": "^7.5.14",
14
+ "@cloudflare/component-arrow-swivel": "^2.4.90",
15
+ "@cloudflare/component-button": "^2.11.11",
16
+ "@cloudflare/component-link": "^4.0.12",
17
+ "@cloudflare/style-container": "^7.5.17",
16
18
  "prop-types": "^15.6.0"
17
19
  },
18
20
  "peerDependencies": {
@@ -29,5 +31,5 @@
29
31
  "test-coverage": "stratus test --coverage",
30
32
  "test-watch": "stratus test --watch"
31
33
  },
32
- "gitHead": "2553517ca3fc04fb5545a5a4432f1d0a1579620c"
34
+ "gitHead": "737c0d5801ce0a460ef414075e1de979c645ade4"
33
35
  }
package/src/CardDrawer.js CHANGED
@@ -1,8 +1,26 @@
1
+ import PropTypes from 'prop-types';
1
2
  import { createStyledComponent } from '@cloudflare/style-container';
2
3
 
3
- const CardDrawer = createStyledComponent(({ theme, isActive }) => ({
4
- borderTop: isActive ? `1px solid ${theme.colors.gray[7]}` : 'initial',
5
- padding: isActive ? 3 : 'initial'
6
- }));
4
+ const CardDrawer = createStyledComponent(
5
+ ({ theme, isActive }) => ({
6
+ borderTop: isActive ? `1px solid ${theme.colors.gray[7]}` : 'initial',
7
+ padding: isActive ? 3 : 'initial'
8
+ }),
9
+ 'div',
10
+ ['role', 'aria-labelledby']
11
+ );
12
+
13
+ CardDrawer.propTypes = {
14
+ id: PropTypes.string.isRequired,
15
+ key: PropTypes.string.isRequired,
16
+ 'aria-labelledby': PropTypes.string.isRequired,
17
+ isActive: PropTypes.bool.isRequired,
18
+ addToggleFunction: PropTypes.func.isRequired,
19
+ role: PropTypes.string
20
+ };
21
+
22
+ CardDrawer.defaultProps = {
23
+ role: 'region'
24
+ };
7
25
 
8
26
  export default CardDrawer;
@@ -3,9 +3,10 @@ import PropTypes from 'prop-types';
3
3
 
4
4
  import CardSection from './CardSection';
5
5
  import CardToolbar from './CardToolbar';
6
- import CardToolbarLink from './CardToolbarLink';
6
+ import CardToolbarDrawerTrigger from './CardToolbarDrawerTrigger';
7
7
  import CardPropTypes from './CardPropTypes';
8
8
  import CardDrawer from './CardDrawer';
9
+ import CardToolbarLink from './CardToolbarLink';
9
10
 
10
11
  let UNIQUE_ID = 0;
11
12
 
@@ -54,50 +55,74 @@ class CardDrawers extends React.Component {
54
55
  ? this.props.active
55
56
  : this.state.active;
56
57
 
57
- const links = [];
58
+ const triggers = [];
58
59
  const drawers = [];
59
60
 
60
61
  this.props.drawers.forEach(
61
- ({ id: drawerId, name, content, drawerComponent, onClick, ...rest }) => {
62
+ ({
63
+ id: drawerIdProps,
64
+ name,
65
+ content,
66
+ drawerComponent,
67
+ onClick,
68
+ href,
69
+ ...rest
70
+ }) => {
62
71
  // The component used for the drawer can be overridden
63
72
  const Drawer = drawerComponent || CardDrawer;
73
+ const triggerId = `trigger-${this._cardId}-${drawerIdProps}`;
74
+ const drawerId = `drawer-${this._cardId}-${drawerIdProps}`;
64
75
  const isActive = drawerId === active;
65
- const id = `card-${this._cardId}-drawer-${drawerId}`;
66
76
 
67
77
  onClick && this.addToggleFunction(drawerId, onClick);
68
-
69
- links.push(
70
- <CardToolbarLink
71
- key={drawerId}
72
- id={id}
73
- isActive={isActive}
74
- onClick={() => this.handleLinkClick(drawerId)}
75
- expandable={content ? true : false}
76
- >
77
- {name}
78
- </CardToolbarLink>
79
- );
80
-
81
- content &&
82
- drawers.push(
83
- <Drawer
84
- key={drawerId}
85
- role="tabpanel"
86
- aria-labelledby={id}
87
- aria-hidden={isActive ? 'false' : 'true'}
88
- isActive={isActive}
89
- addToggleFunction={this.addToggleFunction.bind(this, drawerId)}
90
- {...rest}
91
- >
92
- {isActive && content}
93
- </Drawer>
78
+ if (!content && !href) {
79
+ console.error(
80
+ 'Drawer items must have either `content` or `href` property.'
94
81
  );
82
+ } else if (content && href) {
83
+ console.error(
84
+ 'Drawer items must have either `content` or `href` property, but not both.'
85
+ );
86
+ } else {
87
+ triggers.push(
88
+ content ? (
89
+ <CardToolbarDrawerTrigger
90
+ key={triggerId}
91
+ id={triggerId}
92
+ isActive={isActive}
93
+ onClick={() => this.handleLinkClick(drawerId)}
94
+ ariaControls={drawerId}
95
+ ariaExpanded={isActive}
96
+ >
97
+ {name}
98
+ </CardToolbarDrawerTrigger>
99
+ ) : (
100
+ <CardToolbarLink id={triggerId} href={href}>
101
+ {name}
102
+ </CardToolbarLink>
103
+ )
104
+ );
105
+
106
+ content &&
107
+ drawers.push(
108
+ <Drawer
109
+ key={drawerId}
110
+ id={drawerId}
111
+ aria-labelledby={triggerId}
112
+ isActive={isActive}
113
+ addToggleFunction={this.addToggleFunction.bind(this, drawerId)}
114
+ {...rest}
115
+ >
116
+ {isActive && content}
117
+ </Drawer>
118
+ );
119
+ }
95
120
  }
96
121
  );
97
122
 
98
123
  return (
99
124
  <CardSection>
100
- <CardToolbar controls={this.props.controls} links={links} />
125
+ <CardToolbar controls={this.props.controls} triggers={triggers} />
101
126
  <div>{drawers}</div>
102
127
  </CardSection>
103
128
  );
@@ -19,7 +19,7 @@ const styles = ({ theme }) => ({
19
19
  }
20
20
  });
21
21
 
22
- const Links = createComponent(
22
+ const Triggers = createComponent(
23
23
  () => ({
24
24
  float: 'right',
25
25
  position: 'relative'
@@ -27,17 +27,17 @@ const Links = createComponent(
27
27
  'div'
28
28
  );
29
29
 
30
- const CardToolbar = ({ className, controls, links }) => (
30
+ const CardToolbar = ({ className, controls, triggers }) => (
31
31
  <div className={className}>
32
32
  <div>{controls}</div>
33
- <Links role="tablist">{links}</Links>
33
+ <Triggers>{triggers}</Triggers>
34
34
  </div>
35
35
  );
36
36
 
37
37
  CardToolbar.propTypes = {
38
38
  className: PropTypes.string,
39
39
  controls: PropTypes.any,
40
- links: PropTypes.any
40
+ triggers: PropTypes.any
41
41
  };
42
42
  CardToolbar.displayName = 'CardToolbar';
43
43
  export default createStyledComponent(styles, CardToolbar);
@@ -0,0 +1,51 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { TextButton } from '@cloudflare/component-button';
4
+ import { ArrowSwivel } from '@cloudflare/component-arrow-swivel';
5
+
6
+ class CardToolbarDrawerTrigger extends React.Component {
7
+ constructor(props) {
8
+ super(props);
9
+ this.handleClick = this.handleClick.bind(this);
10
+ }
11
+
12
+ handleClick(e) {
13
+ e.preventDefault();
14
+ this.props.onClick();
15
+ }
16
+
17
+ render() {
18
+ const { id, children, isActive, ariaControls, ariaExpanded } = this.props;
19
+
20
+ return (
21
+ <TextButton
22
+ id={id}
23
+ onClick={this.handleClick}
24
+ isActive={isActive}
25
+ px={3}
26
+ py={2}
27
+ fontSize={3}
28
+ aria-controls={ariaControls}
29
+ aria-expanded={ariaExpanded}
30
+ >
31
+ {children}
32
+ <ArrowSwivel isActive={isActive} duration={50} />
33
+ </TextButton>
34
+ );
35
+ }
36
+ }
37
+
38
+ CardToolbarDrawerTrigger.propTypes = {
39
+ onClick: PropTypes.func.isRequired,
40
+ isActive: PropTypes.bool.isRequired,
41
+ id: PropTypes.string.isRequired,
42
+ children: PropTypes.node,
43
+ ariaControls: PropTypes.string.isRequired,
44
+ ariaExpanded: PropTypes.bool.isRequired
45
+ };
46
+
47
+ CardToolbarDrawerTrigger.defaultProps = {
48
+ isActive: false
49
+ };
50
+
51
+ export default CardToolbarDrawerTrigger;
@@ -1,48 +1,28 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { Link } from '@cloudflare/component-link';
4
+ import { createComponent } from '@cloudflare/style-container';
4
5
 
5
- class CardToolbarLink extends React.Component {
6
- constructor(props) {
7
- super(props);
8
- this.handleClick = this.handleClick.bind(this);
9
- }
10
-
11
- handleClick(e) {
12
- e.preventDefault();
13
- this.props.onClick();
14
- }
15
-
16
- render() {
17
- const { id, children, expandable, isActive } = this.props;
18
- return (
19
- <Link
20
- role={expandable ? 'tab' : 'link'}
21
- id={id}
22
- onClick={this.handleClick}
23
- isActive={isActive}
24
- expandable={expandable}
25
- px={3}
26
- py={2}
27
- fontSize={3}
28
- >
29
- {children}
30
- </Link>
31
- );
32
- }
33
- }
6
+ const CardToolbarLink = createComponent({}, ({ id, href, children }) => {
7
+ return (
8
+ <Link
9
+ px={3}
10
+ py={2}
11
+ fontSize={3}
12
+ target="_blank"
13
+ rel="noopener noreferrer"
14
+ id={id ? id : null}
15
+ href={href}
16
+ >
17
+ {children}
18
+ </Link>
19
+ );
20
+ });
34
21
 
35
22
  CardToolbarLink.propTypes = {
36
- onClick: PropTypes.func.isRequired,
37
- isActive: PropTypes.bool.isRequired,
38
23
  id: PropTypes.string,
39
- children: PropTypes.node,
40
- expandable: PropTypes.bool
41
- };
42
-
43
- CardToolbarLink.defaultProps = {
44
- expandable: true,
45
- isActive: false
24
+ href: PropTypes.string.isRequired,
25
+ children: PropTypes.node.isRequired
46
26
  };
47
27
 
48
28
  export default CardToolbarLink;
package/src/index.js CHANGED
@@ -8,6 +8,7 @@ import CardSection from './CardSection';
8
8
  import CardTitle from './CardTitle';
9
9
  import CardFooter from './CardFooter';
10
10
  import CardToolbar from './CardToolbar';
11
+ import CardToolbarDrawerTrigger from './CardToolbarDrawerTrigger';
11
12
  import CardToolbarLink from './CardToolbarLink';
12
13
  import CardPropTypes from './CardPropTypes';
13
14
  import CardDrawer from './CardDrawer';
@@ -25,5 +26,6 @@ export {
25
26
  CardTitle,
26
27
  CardFooter,
27
28
  CardToolbar,
29
+ CardToolbarDrawerTrigger,
28
30
  CardToolbarLink
29
31
  };