1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-04 23:14:56 +01:00
metamask-extension/ui/app/pages/swaps/actionable-message/actionable-message.js

86 lines
2.3 KiB
JavaScript
Raw Normal View History

import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import InfoTooltip from '../../../components/ui/info-tooltip';
const CLASSNAME_WARNING = 'actionable-message--warning';
const CLASSNAME_DANGER = 'actionable-message--danger';
const CLASSNAME_WITH_RIGHT_BUTTON = 'actionable-message--with-right-button';
const typeHash = {
warning: CLASSNAME_WARNING,
danger: CLASSNAME_DANGER,
};
2020-11-03 00:41:28 +01:00
export default function ActionableMessage({
message = '',
primaryAction = null,
secondaryAction = null,
className = '',
infoTooltipText = '',
withRightButton = false,
type = false,
}) {
const actionableMessageClassName = classnames(
'actionable-message',
typeHash[type],
withRightButton ? CLASSNAME_WITH_RIGHT_BUTTON : null,
className,
);
return (
<div className={actionableMessageClassName}>
{infoTooltipText && (
<InfoTooltip
position="left"
contentText={infoTooltipText}
wrapperClassName="actionable-message__info-tooltip-wrapper"
/>
)}
2020-11-03 00:41:28 +01:00
<div className="actionable-message__message">{message}</div>
{(primaryAction || secondaryAction) && (
<div className="actionable-message__actions">
{primaryAction && (
<button
2020-11-03 00:41:28 +01:00
className={classnames(
'actionable-message__action',
'actionable-message__action--primary',
)}
onClick={primaryAction.onClick}
>
{primaryAction.label}
</button>
)}
{secondaryAction && (
<button
2020-11-03 00:41:28 +01:00
className={classnames(
'actionable-message__action',
'actionable-message__action--secondary',
)}
onClick={secondaryAction.onClick}
>
{secondaryAction.label}
</button>
)}
</div>
)}
</div>
);
}
ActionableMessage.propTypes = {
message: PropTypes.node.isRequired,
primaryAction: PropTypes.shape({
label: PropTypes.string,
onClick: PropTypes.func,
}),
secondaryAction: PropTypes.shape({
label: PropTypes.string,
onClick: PropTypes.func,
}),
className: PropTypes.string,
type: PropTypes.string,
withRightButton: PropTypes.boolean,
infoTooltipText: PropTypes.string,
};