mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
update banner base component (#17582)
* update banner base component * add description to story controls
This commit is contained in:
parent
41d3dcc8a3
commit
0465263d3e
@ -5,7 +5,7 @@ import { BannerBase } from './banner-base';
|
|||||||
|
|
||||||
# BannerBase
|
# BannerBase
|
||||||
|
|
||||||
The `BannerBase` is the base component for banners
|
`BannerBase` serves as a base for all banner variants. It contains standard props such as information and related actions.
|
||||||
|
|
||||||
<Canvas style={{ background: 'var(--color-background-alternative)' }}>
|
<Canvas style={{ background: 'var(--color-background-alternative)' }}>
|
||||||
<Story id="components-componentlibrary-bannerbase--default-story" />
|
<Story id="components-componentlibrary-bannerbase--default-story" />
|
||||||
@ -33,9 +33,28 @@ import { BannerBase } from '../../component-library';
|
|||||||
</BannerBase>;
|
</BannerBase>;
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Description
|
||||||
|
|
||||||
|
The `description` is the content area of the `BannerBase` that must be a string. Description shouldn't repeat title and only 1-3 lines.
|
||||||
|
|
||||||
|
If content requires more than a string, see `children` prop below.
|
||||||
|
|
||||||
|
<Canvas style={{ background: 'var(--color-background-alternative)' }}>
|
||||||
|
<Story id="components-componentlibrary-bannerbase--description" />
|
||||||
|
</Canvas>
|
||||||
|
|
||||||
|
```jsx
|
||||||
|
import { BannerBase } from '../../component-library';
|
||||||
|
|
||||||
|
<BannerBase
|
||||||
|
title="Description vs children"
|
||||||
|
description="Pass only a string through the description prop or you can use children if the contents require more"
|
||||||
|
/>;
|
||||||
|
```
|
||||||
|
|
||||||
### Children
|
### Children
|
||||||
|
|
||||||
The `children` is the description area of the `BannerBase` that can be a text or react node. Description shouldn't repeat title and only 1-3 lines.
|
The `children` prop is an alternative to `description` for `BannerBase` when more than a string is needed. Children content shouldn't repeat title and only 1-3 lines.
|
||||||
|
|
||||||
<Canvas style={{ background: 'var(--color-background-alternative)' }}>
|
<Canvas style={{ background: 'var(--color-background-alternative)' }}>
|
||||||
<Story id="components-componentlibrary-bannerbase--children" />
|
<Story id="components-componentlibrary-bannerbase--children" />
|
||||||
@ -47,7 +66,7 @@ import { BannerBase } from '../../component-library';
|
|||||||
|
|
||||||
<BannerBase>
|
<BannerBase>
|
||||||
{`Description shouldn't repeat title. 1-3 lines. Can contain a `}
|
{`Description shouldn't repeat title. 1-3 lines. Can contain a `}
|
||||||
<ButtonLink size={Size.auto} href="https://metamask.io/" target="_blank">
|
<ButtonLink size={Size.inherit} href="https://metamask.io/" target="_blank">
|
||||||
hyperlink.
|
hyperlink.
|
||||||
</ButtonLink>
|
</ButtonLink>
|
||||||
</BannerBase>;
|
</BannerBase>;
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
exports[`BannerBase should render bannerbase element correctly 1`] = `
|
exports[`BannerBase should render bannerbase element correctly 1`] = `
|
||||||
<div>
|
<div>
|
||||||
<div
|
<div
|
||||||
class="box mm-banner-base box--padding-3 box--padding-left-2 box--display-flex box--gap-2 box--flex-direction-row box--background-color-background-default box--rounded-sm"
|
class="box mm-banner-base box--padding-3 box--display-flex box--gap-2 box--flex-direction-row box--background-color-background-default box--rounded-sm"
|
||||||
data-testid="banner-base"
|
data-testid="banner-base"
|
||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
|
@ -18,6 +18,8 @@ export const BannerBase = ({
|
|||||||
className,
|
className,
|
||||||
title,
|
title,
|
||||||
titleProps,
|
titleProps,
|
||||||
|
description,
|
||||||
|
descriptionProps,
|
||||||
children,
|
children,
|
||||||
actionButtonLabel,
|
actionButtonLabel,
|
||||||
actionButtonOnClick,
|
actionButtonOnClick,
|
||||||
@ -35,7 +37,6 @@ export const BannerBase = ({
|
|||||||
backgroundColor={BackgroundColor.backgroundDefault}
|
backgroundColor={BackgroundColor.backgroundDefault}
|
||||||
borderRadius={BorderRadius.SM}
|
borderRadius={BorderRadius.SM}
|
||||||
padding={3}
|
padding={3}
|
||||||
paddingLeft={2}
|
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
{startAccessory && <>{startAccessory}</>}
|
{startAccessory && <>{startAccessory}</>}
|
||||||
@ -51,6 +52,7 @@ export const BannerBase = ({
|
|||||||
{title}
|
{title}
|
||||||
</Text>
|
</Text>
|
||||||
)}
|
)}
|
||||||
|
{description && <Text {...descriptionProps}>{description}</Text>}
|
||||||
{children && typeof children === 'object' ? (
|
{children && typeof children === 'object' ? (
|
||||||
children
|
children
|
||||||
) : (
|
) : (
|
||||||
@ -91,7 +93,15 @@ BannerBase.propTypes = {
|
|||||||
*/
|
*/
|
||||||
titleProps: PropTypes.shape(Text.PropTypes),
|
titleProps: PropTypes.shape(Text.PropTypes),
|
||||||
/**
|
/**
|
||||||
* The children is the description area of the BannerBase below the title
|
* 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
|
||||||
|
*/
|
||||||
|
descriptionProps: PropTypes.shape(Text.PropTypes),
|
||||||
|
/**
|
||||||
|
* The children is an alternative to using the description prop for BannerBase content below the title
|
||||||
*/
|
*/
|
||||||
children: PropTypes.node,
|
children: PropTypes.node,
|
||||||
/**
|
/**
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
.mm-banner-base {
|
|
||||||
border-left: 4px solid var(--color-icon-default);
|
|
||||||
}
|
|
||||||
|
|
@ -39,6 +39,9 @@ export default {
|
|||||||
title: {
|
title: {
|
||||||
control: 'text',
|
control: 'text',
|
||||||
},
|
},
|
||||||
|
description: {
|
||||||
|
control: 'text',
|
||||||
|
},
|
||||||
children: {
|
children: {
|
||||||
control: 'text',
|
control: 'text',
|
||||||
},
|
},
|
||||||
@ -106,11 +109,25 @@ Title.args = {
|
|||||||
children: 'Pass only a string through the title prop',
|
children: 'Pass only a string through the title prop',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const Description = (args) => {
|
||||||
|
return <BannerBase {...args} />;
|
||||||
|
};
|
||||||
|
|
||||||
|
Description.args = {
|
||||||
|
title: 'Description vs children',
|
||||||
|
description:
|
||||||
|
'Pass only a string through the description prop or you can use children if the contents require more',
|
||||||
|
};
|
||||||
|
|
||||||
export const Children = (args) => {
|
export const Children = (args) => {
|
||||||
return (
|
return (
|
||||||
<BannerBase {...args}>
|
<BannerBase {...args}>
|
||||||
{`Description shouldn't repeat title. 1-3 lines. Can contain a `}
|
{`Description shouldn't repeat title. 1-3 lines. Can contain a `}
|
||||||
<ButtonLink size={Size.auto} href="https://metamask.io/" target="_blank">
|
<ButtonLink
|
||||||
|
size={Size.inherit}
|
||||||
|
href="https://metamask.io/"
|
||||||
|
target="_blank"
|
||||||
|
>
|
||||||
hyperlink.
|
hyperlink.
|
||||||
</ButtonLink>
|
</ButtonLink>
|
||||||
</BannerBase>
|
</BannerBase>
|
||||||
|
@ -40,11 +40,18 @@ describe('BannerBase', () => {
|
|||||||
|
|
||||||
it('should render bannerbase description', () => {
|
it('should render bannerbase description', () => {
|
||||||
const { getByText } = render(
|
const { getByText } = render(
|
||||||
<BannerBase>Bannerbase description test</BannerBase>,
|
<BannerBase description="Bannerbase description test" />,
|
||||||
);
|
);
|
||||||
expect(getByText('Bannerbase description test')).toBeDefined();
|
expect(getByText('Bannerbase description test')).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should render bannerbase children', () => {
|
||||||
|
const { getByText } = render(
|
||||||
|
<BannerBase>Bannerbase children test</BannerBase>,
|
||||||
|
);
|
||||||
|
expect(getByText('Bannerbase children test')).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
it('should render bannerbase action button', () => {
|
it('should render bannerbase action button', () => {
|
||||||
const { getByTestId } = render(
|
const { getByTestId } = render(
|
||||||
<BannerBase
|
<BannerBase
|
||||||
|
@ -62,6 +62,7 @@ export const Banner = ({
|
|||||||
<BannerBase
|
<BannerBase
|
||||||
startAccessory={<Icon size={Size.LG} {...severityIcon()} />}
|
startAccessory={<Icon size={Size.LG} {...severityIcon()} />}
|
||||||
backgroundColor={severityBackground()}
|
backgroundColor={severityBackground()}
|
||||||
|
paddingLeft={2}
|
||||||
className={classnames(
|
className={classnames(
|
||||||
'mm-banner',
|
'mm-banner',
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
.mm-banner {
|
.mm-banner {
|
||||||
border-left-color: var(--color-primary-default);
|
border-left: 4px solid var(--color-primary-default);
|
||||||
|
|
||||||
&--severity-danger {
|
&--severity-danger {
|
||||||
border-left-color: var(--color-error-default);
|
border-left-color: var(--color-error-default);
|
||||||
|
@ -26,5 +26,4 @@
|
|||||||
@import 'text-field-base/text-field-base';
|
@import 'text-field-base/text-field-base';
|
||||||
@import 'text-field-search/text-field-search';
|
@import 'text-field-search/text-field-search';
|
||||||
@import 'form-text-field/form-text-field';
|
@import 'form-text-field/form-text-field';
|
||||||
@import 'banner-base/banner-base';
|
|
||||||
@import 'banner/banner';
|
@import 'banner/banner';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user