@cloudflare/component-card 4.0.10 → 4.0.11
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 +9 -1
- package/README.md +2 -7
- package/es/CardDrawer.js +13 -1
- package/es/CardDrawers.js +31 -19
- package/es/CardToolbar.js +4 -6
- package/es/CardToolbarDrawerTrigger.js +52 -0
- package/es/CardToolbarLink.js +18 -40
- package/es/index.js +2 -1
- package/index.d.ts +16 -4
- package/lib/CardDrawer.js +16 -1
- package/lib/CardDrawers.js +34 -21
- package/lib/CardToolbar.js +4 -6
- package/lib/CardToolbarDrawerTrigger.js +95 -0
- package/lib/CardToolbarLink.js +18 -69
- package/lib/index.js +8 -0
- package/package.json +6 -4
- package/src/CardDrawer.js +22 -4
- package/src/CardDrawers.js +54 -30
- package/src/CardToolbar.js +4 -4
- package/src/CardToolbarDrawerTrigger.js +51 -0
- package/src/CardToolbarLink.js +18 -38
- package/src/index.js +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
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.11](http://stash.cfops.it:7999/fe/stratus/compare/@cloudflare/component-card@4.0.10...@cloudflare/component-card@4.0.11) (2021-11-15)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @cloudflare/component-card
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
## [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)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @cloudflare/component-card
|
|
@@ -4170,7 +4178,7 @@ references ([fe1d8b5](http://stash.cfops.it:7999/www/cf-ux/commits/fe1d8b5))
|
|
|
4170
4178
|
|
|
4171
4179
|
### Bug Fixes
|
|
4172
4180
|
|
|
4173
|
-
* **cf-component-card:** UI-164 Add missing
|
|
4181
|
+
* **cf-component-card:** UI-164 Add missing CardToolbarTrigger component to type
|
|
4174
4182
|
definitions ([cfe8e21](http://stash.cfops.it:7999/www/cf-ux/commits/cfe8e21))
|
|
4175
4183
|
|
|
4176
4184
|
<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
|
-
|
|
81
|
+
triggers={[
|
|
82
82
|
<CardToolbarLink
|
|
83
|
-
|
|
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
|
|
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,7 +53,7 @@ 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
|
|
56
|
+
const triggers = [];
|
|
56
57
|
const drawers = [];
|
|
57
58
|
this.props.drawers.forEach((_ref) => {
|
|
58
59
|
let drawerId = _ref.id,
|
|
@@ -60,32 +61,43 @@ class CardDrawers extends React.Component {
|
|
|
60
61
|
content = _ref.content,
|
|
61
62
|
drawerComponent = _ref.drawerComponent,
|
|
62
63
|
onClick = _ref.onClick,
|
|
63
|
-
|
|
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;
|
|
67
69
|
const isActive = drawerId === active;
|
|
68
70
|
const id = `card-${this._cardId}-drawer-${drawerId}`;
|
|
69
71
|
onClick && this.addToggleFunction(drawerId, onClick);
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
72
|
+
|
|
73
|
+
if (!content && !href) {
|
|
74
|
+
console.error('Drawer items must have either `content` or `href` property.');
|
|
75
|
+
} else if (content && href) {
|
|
76
|
+
console.error('Drawer items must have either `content` or `href` property, but not both.');
|
|
77
|
+
} else {
|
|
78
|
+
triggers.push(content ? /*#__PURE__*/React.createElement(CardToolbarDrawerTrigger, {
|
|
79
|
+
key: drawerId,
|
|
80
|
+
id: id,
|
|
81
|
+
isActive: isActive,
|
|
82
|
+
onClick: () => this.handleLinkClick(drawerId),
|
|
83
|
+
ariaControls: drawerId,
|
|
84
|
+
ariaExpanded: isActive
|
|
85
|
+
}, name) : /*#__PURE__*/React.createElement(CardToolbarLink, {
|
|
86
|
+
id: id,
|
|
87
|
+
href: href
|
|
88
|
+
}, name));
|
|
89
|
+
content && drawers.push( /*#__PURE__*/React.createElement(Drawer, _extends({
|
|
90
|
+
id: drawerId,
|
|
91
|
+
key: drawerId,
|
|
92
|
+
"aria-labelledby": id,
|
|
93
|
+
isActive: isActive,
|
|
94
|
+
addToggleFunction: this.addToggleFunction.bind(this, drawerId)
|
|
95
|
+
}, rest), isActive && content));
|
|
96
|
+
}
|
|
85
97
|
});
|
|
86
98
|
return /*#__PURE__*/React.createElement(CardSection, null, /*#__PURE__*/React.createElement(CardToolbar, {
|
|
87
99
|
controls: this.props.controls,
|
|
88
|
-
|
|
100
|
+
triggers: triggers
|
|
89
101
|
}), /*#__PURE__*/React.createElement("div", null, drawers));
|
|
90
102
|
}
|
|
91
103
|
|
package/es/CardToolbar.js
CHANGED
|
@@ -16,7 +16,7 @@ const styles = ({
|
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
|
|
19
|
-
const
|
|
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
|
-
|
|
27
|
+
triggers
|
|
28
28
|
}) => /*#__PURE__*/React.createElement("div", {
|
|
29
29
|
className: className
|
|
30
|
-
}, /*#__PURE__*/React.createElement("div", null, controls), /*#__PURE__*/React.createElement(
|
|
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
|
-
|
|
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;
|
package/es/CardToolbarLink.js
CHANGED
|
@@ -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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
41
|
-
|
|
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
|
-
|
|
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
|
-
// <
|
|
119
|
+
// <CardToolbarDrawerTrigger>
|
|
118
120
|
////////////////////////////////////////////////////////////////////////
|
|
119
|
-
export type
|
|
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;
|
package/lib/CardDrawers.js
CHANGED
|
@@ -15,12 +15,14 @@ var _CardSection = _interopRequireDefault(require("./CardSection"));
|
|
|
15
15
|
|
|
16
16
|
var _CardToolbar = _interopRequireDefault(require("./CardToolbar"));
|
|
17
17
|
|
|
18
|
-
var
|
|
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,7 +109,7 @@ 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
|
|
112
|
+
var triggers = [];
|
|
111
113
|
var drawers = [];
|
|
112
114
|
this.props.drawers.forEach(function (_ref2) {
|
|
113
115
|
var drawerId = _ref2.id,
|
|
@@ -115,34 +117,45 @@ var CardDrawers = /*#__PURE__*/function (_React$Component) {
|
|
|
115
117
|
content = _ref2.content,
|
|
116
118
|
drawerComponent = _ref2.drawerComponent,
|
|
117
119
|
onClick = _ref2.onClick,
|
|
118
|
-
|
|
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;
|
|
122
125
|
var isActive = drawerId === active;
|
|
123
126
|
var id = "card-".concat(_this3._cardId, "-drawer-").concat(drawerId);
|
|
124
127
|
onClick && _this3.addToggleFunction(drawerId, onClick);
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
128
|
+
|
|
129
|
+
if (!content && !href) {
|
|
130
|
+
console.error('Drawer items must have either `content` or `href` property.');
|
|
131
|
+
} else if (content && href) {
|
|
132
|
+
console.error('Drawer items must have either `content` or `href` property, but not both.');
|
|
133
|
+
} else {
|
|
134
|
+
triggers.push(content ? /*#__PURE__*/_react.default.createElement(_CardToolbarDrawerTrigger.default, {
|
|
135
|
+
key: drawerId,
|
|
136
|
+
id: id,
|
|
137
|
+
isActive: isActive,
|
|
138
|
+
onClick: function onClick() {
|
|
139
|
+
return _this3.handleLinkClick(drawerId);
|
|
140
|
+
},
|
|
141
|
+
ariaControls: drawerId,
|
|
142
|
+
ariaExpanded: isActive
|
|
143
|
+
}, name) : /*#__PURE__*/_react.default.createElement(_CardToolbarLink.default, {
|
|
144
|
+
id: id,
|
|
145
|
+
href: href
|
|
146
|
+
}, name));
|
|
147
|
+
content && drawers.push( /*#__PURE__*/_react.default.createElement(Drawer, _extends({
|
|
148
|
+
id: drawerId,
|
|
149
|
+
key: drawerId,
|
|
150
|
+
"aria-labelledby": id,
|
|
151
|
+
isActive: isActive,
|
|
152
|
+
addToggleFunction: _this3.addToggleFunction.bind(_this3, drawerId)
|
|
153
|
+
}, rest), isActive && content));
|
|
154
|
+
}
|
|
142
155
|
});
|
|
143
156
|
return /*#__PURE__*/_react.default.createElement(_CardSection.default, null, /*#__PURE__*/_react.default.createElement(_CardToolbar.default, {
|
|
144
157
|
controls: this.props.controls,
|
|
145
|
-
|
|
158
|
+
triggers: triggers
|
|
146
159
|
}), /*#__PURE__*/_react.default.createElement("div", null, drawers));
|
|
147
160
|
}
|
|
148
161
|
}]);
|
package/lib/CardToolbar.js
CHANGED
|
@@ -28,7 +28,7 @@ var styles = function styles(_ref) {
|
|
|
28
28
|
};
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
var
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
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;
|
package/lib/CardToolbarLink.js
CHANGED
|
@@ -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
|
-
|
|
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
|
|
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
|
-
|
|
82
|
-
|
|
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.
|
|
4
|
+
"version": "4.0.11",
|
|
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-
|
|
15
|
-
"@cloudflare/
|
|
14
|
+
"@cloudflare/component-arrow-swivel": "^2.4.89",
|
|
15
|
+
"@cloudflare/component-button": "^2.11.10",
|
|
16
|
+
"@cloudflare/component-link": "^4.0.11",
|
|
17
|
+
"@cloudflare/style-container": "^7.5.16",
|
|
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": "
|
|
34
|
+
"gitHead": "2ee21b47b66137477e1ae4798a440e90319bfe2d"
|
|
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(
|
|
4
|
-
|
|
5
|
-
|
|
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;
|
package/src/CardDrawers.js
CHANGED
|
@@ -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
|
|
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,73 @@ class CardDrawers extends React.Component {
|
|
|
54
55
|
? this.props.active
|
|
55
56
|
: this.state.active;
|
|
56
57
|
|
|
57
|
-
const
|
|
58
|
+
const triggers = [];
|
|
58
59
|
const drawers = [];
|
|
59
60
|
|
|
60
61
|
this.props.drawers.forEach(
|
|
61
|
-
({
|
|
62
|
+
({
|
|
63
|
+
id: drawerId,
|
|
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;
|
|
64
73
|
const isActive = drawerId === active;
|
|
65
74
|
const id = `card-${this._cardId}-drawer-${drawerId}`;
|
|
66
75
|
|
|
67
76
|
onClick && this.addToggleFunction(drawerId, onClick);
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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>
|
|
77
|
+
if (!content && !href) {
|
|
78
|
+
console.error(
|
|
79
|
+
'Drawer items must have either `content` or `href` property.'
|
|
94
80
|
);
|
|
81
|
+
} else if (content && href) {
|
|
82
|
+
console.error(
|
|
83
|
+
'Drawer items must have either `content` or `href` property, but not both.'
|
|
84
|
+
);
|
|
85
|
+
} else {
|
|
86
|
+
triggers.push(
|
|
87
|
+
content ? (
|
|
88
|
+
<CardToolbarDrawerTrigger
|
|
89
|
+
key={drawerId}
|
|
90
|
+
id={id}
|
|
91
|
+
isActive={isActive}
|
|
92
|
+
onClick={() => this.handleLinkClick(drawerId)}
|
|
93
|
+
ariaControls={drawerId}
|
|
94
|
+
ariaExpanded={isActive}
|
|
95
|
+
>
|
|
96
|
+
{name}
|
|
97
|
+
</CardToolbarDrawerTrigger>
|
|
98
|
+
) : (
|
|
99
|
+
<CardToolbarLink id={id} href={href}>
|
|
100
|
+
{name}
|
|
101
|
+
</CardToolbarLink>
|
|
102
|
+
)
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
content &&
|
|
106
|
+
drawers.push(
|
|
107
|
+
<Drawer
|
|
108
|
+
id={drawerId}
|
|
109
|
+
key={drawerId}
|
|
110
|
+
aria-labelledby={id}
|
|
111
|
+
isActive={isActive}
|
|
112
|
+
addToggleFunction={this.addToggleFunction.bind(this, drawerId)}
|
|
113
|
+
{...rest}
|
|
114
|
+
>
|
|
115
|
+
{isActive && content}
|
|
116
|
+
</Drawer>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
95
119
|
}
|
|
96
120
|
);
|
|
97
121
|
|
|
98
122
|
return (
|
|
99
123
|
<CardSection>
|
|
100
|
-
<CardToolbar controls={this.props.controls}
|
|
124
|
+
<CardToolbar controls={this.props.controls} triggers={triggers} />
|
|
101
125
|
<div>{drawers}</div>
|
|
102
126
|
</CardSection>
|
|
103
127
|
);
|
package/src/CardToolbar.js
CHANGED
|
@@ -19,7 +19,7 @@ const styles = ({ theme }) => ({
|
|
|
19
19
|
}
|
|
20
20
|
});
|
|
21
21
|
|
|
22
|
-
const
|
|
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,
|
|
30
|
+
const CardToolbar = ({ className, controls, triggers }) => (
|
|
31
31
|
<div className={className}>
|
|
32
32
|
<div>{controls}</div>
|
|
33
|
-
<
|
|
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
|
-
|
|
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;
|
package/src/CardToolbarLink.js
CHANGED
|
@@ -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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
40
|
-
|
|
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
|
};
|