2023-01-11 18:42:18 +01:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
|
|
|
|
import {
|
2023-02-02 21:15:26 +01:00
|
|
|
BackgroundColor,
|
|
|
|
BorderRadius,
|
2023-05-19 19:33:02 +02:00
|
|
|
Display,
|
2023-02-02 21:15:26 +01:00
|
|
|
Size,
|
|
|
|
TextVariant,
|
2023-01-11 18:42:18 +01:00
|
|
|
} from '../../../helpers/constants/design-system';
|
|
|
|
|
2023-05-19 19:33:02 +02:00
|
|
|
import Box from '../../ui/box';
|
|
|
|
|
2023-07-17 23:00:16 +02:00
|
|
|
import { ButtonLink, IconName, ButtonIcon, Text } from '..';
|
2023-05-19 19:33:02 +02:00
|
|
|
|
2023-01-11 18:42:18 +01:00
|
|
|
export const BannerBase = ({
|
|
|
|
className,
|
|
|
|
title,
|
|
|
|
titleProps,
|
2023-02-03 09:12:53 +01:00
|
|
|
description,
|
|
|
|
descriptionProps,
|
2023-01-11 18:42:18 +01:00
|
|
|
children,
|
|
|
|
actionButtonLabel,
|
|
|
|
actionButtonOnClick,
|
|
|
|
actionButtonProps,
|
|
|
|
startAccessory,
|
|
|
|
onClose,
|
|
|
|
closeButtonProps,
|
|
|
|
...props
|
|
|
|
}) => {
|
|
|
|
return (
|
|
|
|
<Box
|
|
|
|
className={classnames('mm-banner-base', className)}
|
2023-05-19 19:33:02 +02:00
|
|
|
display={Display.Flex}
|
2023-01-11 18:42:18 +01:00
|
|
|
gap={2}
|
2023-02-02 21:15:26 +01:00
|
|
|
backgroundColor={BackgroundColor.backgroundDefault}
|
|
|
|
borderRadius={BorderRadius.SM}
|
2023-01-11 18:42:18 +01:00
|
|
|
padding={3}
|
|
|
|
{...props}
|
|
|
|
>
|
|
|
|
{startAccessory && <>{startAccessory}</>}
|
|
|
|
|
|
|
|
<div>
|
|
|
|
{title && (
|
|
|
|
<Text
|
|
|
|
className="mm-banner-base__title"
|
2023-02-02 21:15:26 +01:00
|
|
|
variant={TextVariant.bodyLgMedium}
|
2023-06-15 20:17:21 +02:00
|
|
|
data-testid="mm-banner-base-title"
|
2023-01-11 18:42:18 +01:00
|
|
|
as="h5"
|
|
|
|
{...titleProps}
|
|
|
|
>
|
|
|
|
{title}
|
|
|
|
</Text>
|
|
|
|
)}
|
2023-02-03 09:12:53 +01:00
|
|
|
{description && <Text {...descriptionProps}>{description}</Text>}
|
2023-01-11 18:42:18 +01:00
|
|
|
{children && typeof children === 'object' ? (
|
|
|
|
children
|
|
|
|
) : (
|
|
|
|
<Text>{children}</Text>
|
|
|
|
)}
|
|
|
|
{actionButtonLabel && (
|
|
|
|
<ButtonLink
|
2023-02-02 21:15:26 +01:00
|
|
|
size={Size.auto}
|
2023-01-11 18:42:18 +01:00
|
|
|
onClick={actionButtonOnClick}
|
|
|
|
{...actionButtonProps}
|
|
|
|
>
|
|
|
|
{actionButtonLabel}
|
|
|
|
</ButtonLink>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
{onClose && (
|
|
|
|
<ButtonIcon
|
|
|
|
className="mm-banner-base__close-button"
|
2023-01-25 19:39:49 +01:00
|
|
|
marginLeft="auto"
|
2023-05-19 19:33:02 +02:00
|
|
|
iconName={IconName.Close}
|
2023-02-02 21:15:26 +01:00
|
|
|
size={Size.SM}
|
2023-01-11 18:42:18 +01:00
|
|
|
ariaLabel="Close" // TODO: i18n
|
|
|
|
onClick={onClose}
|
|
|
|
{...closeButtonProps}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
BannerBase.propTypes = {
|
|
|
|
/**
|
|
|
|
* The title of the BannerBase
|
|
|
|
*/
|
|
|
|
title: PropTypes.string,
|
|
|
|
/**
|
|
|
|
* Additional props to pass to the `Text` component used for the `title` text
|
|
|
|
*/
|
2023-07-17 23:00:16 +02:00
|
|
|
titleProps: PropTypes.object,
|
2023-01-11 18:42:18 +01:00
|
|
|
/**
|
2023-02-03 09:12:53 +01:00
|
|
|
* The description is the content area below BannerBase title
|
|
|
|
*/
|
|
|
|
description: PropTypes.string,
|
|
|
|
/**
|
|
|
|
* Additional props to pass to the `Text` component used for the `description` text
|
|
|
|
*/
|
2023-07-17 23:00:16 +02:00
|
|
|
descriptionProps: PropTypes.object,
|
2023-02-03 09:12:53 +01:00
|
|
|
/**
|
|
|
|
* The children is an alternative to using the description prop for BannerBase content below the title
|
2023-01-11 18:42:18 +01:00
|
|
|
*/
|
|
|
|
children: PropTypes.node,
|
|
|
|
/**
|
|
|
|
* Label for action button (ButtonLink) of the BannerBase below the children
|
|
|
|
*/
|
|
|
|
actionButtonLabel: PropTypes.string,
|
|
|
|
/**
|
|
|
|
* Props for action button (ButtonLink) of the BannerBase below the children
|
|
|
|
*/
|
2023-07-17 23:00:16 +02:00
|
|
|
actionButtonProps: PropTypes.object,
|
2023-01-11 18:42:18 +01:00
|
|
|
/**
|
|
|
|
* The onClick handler for the action button (ButtonLink)
|
|
|
|
*/
|
|
|
|
actionButtonOnClick: PropTypes.func,
|
|
|
|
/**
|
|
|
|
* The start(defualt left) content area of BannerBase
|
|
|
|
*/
|
|
|
|
startAccessory: PropTypes.node,
|
|
|
|
/**
|
|
|
|
* The onClick handler for the close button
|
|
|
|
* When passed this will allow for the close button to show
|
|
|
|
*/
|
|
|
|
onClose: PropTypes.func,
|
|
|
|
/**
|
|
|
|
* The props to pass to the close button
|
|
|
|
*/
|
2023-07-17 23:00:16 +02:00
|
|
|
closeButtonProps: PropTypes.object,
|
2023-01-11 18:42:18 +01:00
|
|
|
/**
|
|
|
|
* An additional className to apply to the BannerBase
|
|
|
|
*/
|
|
|
|
className: PropTypes.string,
|
|
|
|
/**
|
|
|
|
* BannerBase accepts all the props from Box
|
|
|
|
*/
|
|
|
|
...Box.propTypes,
|
|
|
|
};
|