1 | import { __assign, __extends } from "tslib";
|
2 | import * as React from 'react';
|
3 | import { classNamesFunction, KeyCodes, getNativeProps, divProperties, warnDeprecations, initializeComponentRef, } from '../../Utilities';
|
4 | import { DocumentCardType, } from './DocumentCard.types';
|
5 | var getClassNames = classNamesFunction();
|
6 | var COMPONENT_NAME = 'DocumentCard';
|
7 |
|
8 |
|
9 |
|
10 | var DocumentCardBase = (function (_super) {
|
11 | __extends(DocumentCardBase, _super);
|
12 | function DocumentCardBase(props) {
|
13 | var _this = _super.call(this, props) || this;
|
14 | _this._rootElement = React.createRef();
|
15 | _this._onClick = function (ev) {
|
16 | _this._onAction(ev);
|
17 | };
|
18 | _this._onKeyDown = function (ev) {
|
19 | if (ev.which === KeyCodes.enter || ev.which === KeyCodes.space) {
|
20 | _this._onAction(ev);
|
21 | }
|
22 | };
|
23 | _this._onAction = function (ev) {
|
24 | var _a = _this.props, onClick = _a.onClick, onClickHref = _a.onClickHref, onClickTarget = _a.onClickTarget;
|
25 | if (onClick) {
|
26 | onClick(ev);
|
27 | }
|
28 | else if (!onClick && onClickHref) {
|
29 |
|
30 | if (onClickTarget) {
|
31 | window.open(onClickHref, onClickTarget, 'noreferrer noopener nofollow');
|
32 | }
|
33 | else {
|
34 | window.location.href = onClickHref;
|
35 | }
|
36 | ev.preventDefault();
|
37 | ev.stopPropagation();
|
38 | }
|
39 | };
|
40 | initializeComponentRef(_this);
|
41 | warnDeprecations(COMPONENT_NAME, props, {
|
42 | accentColor: undefined,
|
43 | });
|
44 | return _this;
|
45 | }
|
46 | DocumentCardBase.prototype.render = function () {
|
47 |
|
48 | var _a = this.props, onClick = _a.onClick, onClickHref = _a.onClickHref, children = _a.children, type = _a.type, accentColor = _a.accentColor, styles = _a.styles, theme = _a.theme, className = _a.className;
|
49 | var nativeProps = getNativeProps(this.props, divProperties, [
|
50 | 'className',
|
51 | 'onClick',
|
52 | 'type',
|
53 | 'role',
|
54 | ]);
|
55 | var actionable = onClick || onClickHref ? true : false;
|
56 | this._classNames = getClassNames(styles, {
|
57 | theme: theme,
|
58 | className: className,
|
59 | actionable: actionable,
|
60 | compact: type === DocumentCardType.compact ? true : false,
|
61 | });
|
62 |
|
63 | var style;
|
64 | if (type === DocumentCardType.compact && accentColor) {
|
65 | style = {
|
66 | borderBottomColor: accentColor,
|
67 | };
|
68 | }
|
69 |
|
70 | var role = this.props.role || (actionable ? (onClick ? 'button' : 'link') : undefined);
|
71 | var tabIndex = actionable ? 0 : undefined;
|
72 | return (React.createElement("div", __assign({ ref: this._rootElement, tabIndex: tabIndex, "data-is-focusable": actionable, role: role, className: this._classNames.root, onKeyDown: actionable ? this._onKeyDown : undefined, onClick: actionable ? this._onClick : undefined, style: style }, nativeProps), children));
|
73 | };
|
74 | DocumentCardBase.prototype.focus = function () {
|
75 | if (this._rootElement.current) {
|
76 | this._rootElement.current.focus();
|
77 | }
|
78 | };
|
79 | DocumentCardBase.defaultProps = {
|
80 | type: DocumentCardType.normal,
|
81 | };
|
82 | return DocumentCardBase;
|
83 | }(React.Component));
|
84 | export { DocumentCardBase };
|
85 |
|
\ | No newline at end of file |