forked from primeroIMS/primero
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomponent.jsx
49 lines (39 loc) · 1.2 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
// Copyright (c) 2014 - 2023 UNICEF. All rights reserved.
import { cloneElement } from "react";
import PropTypes from "prop-types";
import { Tooltip } from "@material-ui/core";
import clsx from "clsx";
import { useApp } from "../application";
import { useI18n } from "../i18n";
import css from "./styles.css";
const Component = ({ overrideCondition, children, button, offlineTextKey }) => {
const { online } = useApp();
const i18n = useI18n();
const classes = clsx(css.disabledLink, {
[css.disabled]: !button
});
if (overrideCondition || !online) {
return (
<Tooltip title={i18n.t(offlineTextKey || "offline")} enterTouchDelay={20}>
<div className={classes} data-testid="disable-offline">
{!button && <div className={css.disabledElement} />}
{cloneElement(children, { disabled: true })}
</div>
</Tooltip>
);
}
return children;
};
Component.defaultProps = {
button: false,
offlineTextKey: null,
overrideCondition: false
};
Component.propTypes = {
button: PropTypes.bool,
children: PropTypes.node,
offlineTextKey: PropTypes.string,
overrideCondition: PropTypes.bool
};
Component.displayName = "DisableOffline";
export default Component;