-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathOfflineTooltip.js
More file actions
54 lines (48 loc) · 1.47 KB
/
OfflineTooltip.js
File metadata and controls
54 lines (48 loc) · 1.47 KB
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
import { useDhis2ConnectionStatus } from '@dhis2/app-runtime'
import { Tooltip } from '@dhis2/ui'
import cx from 'classnames'
import PropTypes from 'prop-types'
import React from 'react'
import i18n from '../locales/index.js'
import { styles } from './styles/OfflineTooltip.style.js'
const OfflineTooltip = ({
disabledWhenOffline,
disabled,
content,
children,
}) => {
const { isDisconnected: offline } = useDhis2ConnectionStatus()
const notAllowed = disabled || (disabledWhenOffline && offline)
return (
<>
<Tooltip
content={content || i18n.t('Not available offline')}
openDelay={200}
closeDelay={100}
>
{({ onMouseOver, onMouseOut, ref }) => (
<span
className={cx('tooltip', { notAllowed })}
onMouseOver={() => notAllowed && onMouseOver()}
onMouseOut={() => notAllowed && onMouseOut()}
ref={ref}
>
{children}
</span>
)}
</Tooltip>
<style jsx>{styles}</style>
</>
)
}
OfflineTooltip.propTypes = {
children: PropTypes.node,
content: PropTypes.string,
disabled: PropTypes.bool,
disabledWhenOffline: PropTypes.bool,
}
OfflineTooltip.defaultProps = {
disabled: false,
disabledWhenOffline: true,
}
export { OfflineTooltip }