forked from primeroIMS/primero
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomponent.jsx
85 lines (74 loc) · 1.89 KB
/
component.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright (c) 2014 - 2023 UNICEF. All rights reserved.
import PropTypes from "prop-types";
import isString from "lodash/isString";
import { useApp } from "../application";
import { useI18n } from "../i18n";
import { buttonType } from "./utils";
import { NAME, ACTION_BUTTON_TYPES } from "./constants";
function Component({
id = null,
icon,
cancel,
isTransparent,
pending,
text,
type,
outlined,
keepTextOnMobile,
tooltip,
noTranslate = false,
rest,
disabled,
...options
}) {
const { disabledApplication } = useApp();
const i18n = useI18n();
const ButtonType = buttonType(type);
const isDisabled = (disabledApplication || disabled) && { disabled: disabledApplication || disabled };
const isPending = Boolean(pending);
const buttonID = id || text;
const buttonText = !noTranslate && isString(text) ? i18n.t(text) : text;
const { hide, ...restBtnProps } = rest;
if (hide) {
return null;
}
return (
<ButtonType
data-testid="action-button"
id={buttonID}
icon={icon}
cancel={cancel}
isTransparent={isTransparent}
pending={isPending}
rest={{ ...restBtnProps, ...isDisabled }}
outlined={outlined}
text={buttonText}
tooltip={tooltip}
keepTextOnMobile={keepTextOnMobile}
role="button"
{...options}
/>
);
}
Component.displayName = NAME;
Component.defaultProps = {
outlined: false,
rest: {},
type: ACTION_BUTTON_TYPES.default
};
Component.propTypes = {
cancel: PropTypes.bool,
disabled: PropTypes.bool,
icon: PropTypes.oneOfType([PropTypes.object, PropTypes.bool]),
id: PropTypes.string,
isTransparent: PropTypes.bool,
keepTextOnMobile: PropTypes.bool,
noTranslate: PropTypes.bool,
outlined: PropTypes.bool,
pending: PropTypes.bool,
rest: PropTypes.object,
text: PropTypes.string,
tooltip: PropTypes.string,
type: PropTypes.string
};
export default Component;