2021-02-04 19:15:23 +01:00
|
|
|
import React, { useState } from 'react';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import Button from '../../ui/button';
|
|
|
|
import Checkbox from '../../ui/check-box';
|
|
|
|
import Tooltip from '../../ui/tooltip';
|
2023-05-09 19:34:58 +02:00
|
|
|
import { Icon, IconName } from '../../component-library';
|
|
|
|
import { IconColor } from '../../../helpers/constants/design-system';
|
2019-08-01 15:24:33 +02:00
|
|
|
|
2020-12-10 21:02:21 +01:00
|
|
|
const HomeNotification = ({
|
|
|
|
acceptText,
|
2020-12-11 00:40:29 +01:00
|
|
|
checkboxText,
|
|
|
|
checkboxTooltipText,
|
2020-12-10 21:02:21 +01:00
|
|
|
classNames = [],
|
|
|
|
descriptionText,
|
|
|
|
ignoreText,
|
|
|
|
infoText,
|
|
|
|
onAccept,
|
|
|
|
onIgnore,
|
|
|
|
}) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const [checkboxState, setCheckBoxState] = useState(false);
|
2020-12-11 00:40:29 +01:00
|
|
|
|
|
|
|
const checkboxElement = checkboxText && (
|
|
|
|
<Checkbox
|
|
|
|
id="homeNotification_checkbox"
|
|
|
|
checked={checkboxState}
|
|
|
|
className="home-notification__checkbox"
|
|
|
|
onClick={() => setCheckBoxState((checked) => !checked)}
|
|
|
|
/>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-12-11 00:40:29 +01:00
|
|
|
|
2020-12-10 21:02:21 +01:00
|
|
|
return (
|
|
|
|
<div className={classnames('home-notification', ...classNames)}>
|
|
|
|
<div className="home-notification__content">
|
|
|
|
<div className="home-notification__content-container">
|
|
|
|
<div className="home-notification__text">{descriptionText}</div>
|
2019-08-01 15:24:33 +02:00
|
|
|
</div>
|
2020-12-10 21:02:21 +01:00
|
|
|
{infoText ? (
|
|
|
|
<Tooltip
|
|
|
|
position="top"
|
|
|
|
title={infoText}
|
|
|
|
wrapperClassName="home-notification__tooltip-wrapper"
|
|
|
|
>
|
2023-05-09 19:34:58 +02:00
|
|
|
<Icon name={IconName.Info} color={IconColor.iconDefault} />
|
2020-12-10 21:02:21 +01:00
|
|
|
</Tooltip>
|
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
<div className="home-notification__buttons">
|
|
|
|
{onAccept && acceptText ? (
|
|
|
|
<Button
|
|
|
|
type="primary"
|
|
|
|
className="home-notification__accept-button"
|
|
|
|
onClick={onAccept}
|
|
|
|
>
|
|
|
|
{acceptText}
|
|
|
|
</Button>
|
|
|
|
) : null}
|
|
|
|
{onIgnore && ignoreText ? (
|
|
|
|
<Button
|
|
|
|
type="secondary"
|
|
|
|
className="home-notification__ignore-button"
|
2020-12-11 00:40:29 +01:00
|
|
|
// Some onIgnore handlers use the checkboxState to determine whether
|
|
|
|
// to disable the notification
|
|
|
|
onClick={() => onIgnore(checkboxState)}
|
2020-12-10 21:02:21 +01:00
|
|
|
>
|
|
|
|
{ignoreText}
|
|
|
|
</Button>
|
|
|
|
) : null}
|
2020-12-11 00:40:29 +01:00
|
|
|
{checkboxText ? (
|
|
|
|
<div className="home-notification__checkbox-wrapper">
|
|
|
|
{checkboxTooltipText ? (
|
|
|
|
<Tooltip
|
|
|
|
position="top"
|
|
|
|
title={checkboxTooltipText}
|
|
|
|
wrapperClassName="home-notification__checkbox-label-tooltip"
|
|
|
|
>
|
|
|
|
{checkboxElement}
|
|
|
|
</Tooltip>
|
|
|
|
) : (
|
|
|
|
checkboxElement
|
|
|
|
)}
|
|
|
|
<label
|
|
|
|
className="home-notification__checkbox-label"
|
|
|
|
htmlFor="homeNotification_checkbox"
|
|
|
|
>
|
|
|
|
{checkboxText}
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
) : null}
|
2019-08-01 15:24:33 +02:00
|
|
|
</div>
|
2020-12-10 21:02:21 +01:00
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
};
|
2020-12-10 21:02:21 +01:00
|
|
|
|
|
|
|
HomeNotification.propTypes = {
|
2021-12-10 19:17:43 +01:00
|
|
|
/**
|
|
|
|
* The text for the "Accept" button. This must be accompanied by the `onAccept` prop.
|
|
|
|
*
|
|
|
|
* The "Accept" button is only rendered if this prop is set.
|
|
|
|
*/
|
2020-12-10 21:02:21 +01:00
|
|
|
acceptText: PropTypes.node,
|
2021-12-10 19:17:43 +01:00
|
|
|
/**
|
|
|
|
* The text to display alongside the checkbox.
|
|
|
|
*
|
|
|
|
* The checkbox state is passed to the `onIgnore` handler, so this should only be used if the `onIgnore` prop is set.
|
|
|
|
*
|
|
|
|
* The checkbox is only rendered if this prop is set.
|
|
|
|
*/
|
2020-12-11 00:40:29 +01:00
|
|
|
checkboxText: PropTypes.node,
|
2021-12-10 19:17:43 +01:00
|
|
|
/**
|
|
|
|
* The text to display in the checkbox tooltip.
|
|
|
|
*
|
|
|
|
* The tooltip is only rendered if this prop is set.
|
|
|
|
*/
|
2020-12-11 00:40:29 +01:00
|
|
|
checkboxTooltipText: PropTypes.node,
|
2021-12-10 19:17:43 +01:00
|
|
|
/**
|
|
|
|
* Custom class names.
|
|
|
|
*/
|
2020-12-10 21:02:21 +01:00
|
|
|
classNames: PropTypes.array,
|
2021-12-10 19:17:43 +01:00
|
|
|
/**
|
|
|
|
* The notification description.
|
|
|
|
*/
|
2020-12-10 21:02:21 +01:00
|
|
|
descriptionText: PropTypes.node.isRequired,
|
2021-12-10 19:17:43 +01:00
|
|
|
/**
|
|
|
|
* The text for the "Ignore" button. This must be accompanied by the `onIgnore` prop.
|
|
|
|
*
|
|
|
|
* The "Ignore" button is only rendered if this prop is set.
|
|
|
|
*/
|
2020-12-10 21:02:21 +01:00
|
|
|
ignoreText: PropTypes.node,
|
2021-12-10 19:17:43 +01:00
|
|
|
/**
|
|
|
|
* The text for the info icon tooltip in the top-right of the notification.
|
|
|
|
*
|
|
|
|
* The info-icon is only rendered if this prop is set.
|
|
|
|
*/
|
2020-12-10 21:02:21 +01:00
|
|
|
infoText: PropTypes.node,
|
2021-12-10 19:17:43 +01:00
|
|
|
/**
|
|
|
|
* The handler for the "Accept" button. This must be accompanied by the `acceptText` prop.
|
|
|
|
*/
|
2020-12-10 21:02:21 +01:00
|
|
|
onAccept: PropTypes.func,
|
2021-12-10 19:17:43 +01:00
|
|
|
/**
|
|
|
|
* The handler for the "Ignore" button. This must be accompanied by the `ignoreText` prop.
|
|
|
|
*
|
|
|
|
* If `checkboxText` is set, the checkbox state will be passed to this function as a boolean.
|
|
|
|
*/
|
2020-12-10 21:02:21 +01:00
|
|
|
onIgnore: PropTypes.func,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-12-10 21:02:21 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
export default HomeNotification;
|