2019-12-06 22:12:48 +01:00
|
|
|
// @flow
|
2020-02-21 22:05:20 +01:00
|
|
|
import type { Node } from 'react';
|
2019-12-06 22:12:48 +01:00
|
|
|
import * as ICONS from 'constants/icons';
|
2020-02-26 19:39:03 +01:00
|
|
|
import classnames from 'classnames';
|
2019-12-06 22:12:48 +01:00
|
|
|
import React from 'react';
|
|
|
|
import Button from 'component/button';
|
|
|
|
|
|
|
|
type Props = {
|
2020-02-21 22:05:20 +01:00
|
|
|
message: string | Node,
|
2022-03-02 15:44:01 +01:00
|
|
|
action?: Node,
|
|
|
|
closeTitle?: string,
|
2020-04-13 21:16:07 +02:00
|
|
|
actionText?: string,
|
2019-12-06 22:12:48 +01:00
|
|
|
href?: string,
|
2020-02-26 19:39:03 +01:00
|
|
|
type?: string,
|
2020-04-01 20:43:50 +02:00
|
|
|
inline?: boolean,
|
2020-04-13 21:16:07 +02:00
|
|
|
relative?: boolean,
|
2019-12-06 22:12:48 +01:00
|
|
|
onClick?: () => void,
|
|
|
|
onClose?: () => void,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default function Nag(props: Props) {
|
2022-03-02 15:44:01 +01:00
|
|
|
const {
|
|
|
|
message,
|
|
|
|
action: customAction,
|
|
|
|
closeTitle,
|
|
|
|
actionText,
|
|
|
|
href,
|
|
|
|
onClick,
|
|
|
|
onClose,
|
|
|
|
type,
|
|
|
|
inline,
|
|
|
|
relative,
|
|
|
|
} = props;
|
2019-12-06 22:12:48 +01:00
|
|
|
|
2022-03-02 15:44:01 +01:00
|
|
|
const buttonProps = onClick ? { onClick } : href ? { href } : null;
|
2019-12-06 22:12:48 +01:00
|
|
|
|
|
|
|
return (
|
2020-04-01 20:43:50 +02:00
|
|
|
<div
|
|
|
|
className={classnames('nag', {
|
|
|
|
'nag--helpful': type === 'helpful',
|
|
|
|
'nag--error': type === 'error',
|
|
|
|
'nag--inline': inline,
|
2020-04-13 21:16:07 +02:00
|
|
|
'nag--relative': relative,
|
2020-04-01 20:43:50 +02:00
|
|
|
})}
|
|
|
|
>
|
2020-03-26 16:18:05 +01:00
|
|
|
<div className="nag__message">{message}</div>
|
2022-03-02 15:44:01 +01:00
|
|
|
|
|
|
|
{customAction}
|
|
|
|
|
|
|
|
{buttonProps && (
|
2020-04-13 21:16:07 +02:00
|
|
|
<Button
|
|
|
|
className={classnames('nag__button', {
|
|
|
|
'nag__button--helpful': type === 'helpful',
|
|
|
|
'nag__button--error': type === 'error',
|
|
|
|
})}
|
|
|
|
{...buttonProps}
|
|
|
|
>
|
|
|
|
{actionText}
|
|
|
|
</Button>
|
|
|
|
)}
|
2022-03-02 15:44:01 +01:00
|
|
|
|
2020-03-12 18:47:40 +01:00
|
|
|
{onClose && (
|
|
|
|
<Button
|
|
|
|
className={classnames('nag__button nag__close', {
|
|
|
|
'nag__button--helpful': type === 'helpful',
|
|
|
|
'nag__button--error': type === 'error',
|
|
|
|
})}
|
2022-03-02 15:44:01 +01:00
|
|
|
title={closeTitle}
|
2020-03-12 18:47:40 +01:00
|
|
|
icon={ICONS.REMOVE}
|
|
|
|
onClick={onClose}
|
|
|
|
/>
|
|
|
|
)}
|
2019-12-06 22:12:48 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|