1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 18:00:18 +01:00

Add custom CSS to Popover (#13740)

* add boxes to popover sections for custom css

* updated doc strings

* added default props

* render Boxes only if the props are not empty

* possible fix

* second fix

* removed prop check function, converted header, footer and div elements to Box components and updated storybook and readme.mdx

* remove non existing prop

* fixed export issue

* updated storybook
This commit is contained in:
Hassan Malik 2022-03-04 12:00:51 -05:00 committed by GitHub
parent aa89bb189b
commit 261b066fc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 77 additions and 58 deletions

View File

@ -1,16 +0,0 @@
import { Story, Canvas, ArgsTable } from '@storybook/addon-docs';
import Popover from './popover.component';
# Popover
A modal component to show info
<Canvas>
<Story id="ui-components-ui-popover-popover-stories-js--default-story" />
</Canvas>
## Component API
<ArgsTable of={Popover} />

View File

@ -3,6 +3,7 @@ import ReactDOM from 'react-dom';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import classnames from 'classnames'; import classnames from 'classnames';
import { useI18nContext } from '../../../hooks/useI18nContext'; import { useI18nContext } from '../../../hooks/useI18nContext';
import Box from '../box';
const Popover = ({ const Popover = ({
title, title,
@ -18,9 +19,47 @@ const Popover = ({
CustomBackground, CustomBackground,
popoverRef, popoverRef,
centerTitle, centerTitle,
headerProps = {},
contentProps = {},
footerProps = {},
}) => { }) => {
const t = useI18nContext(); const t = useI18nContext();
const showHeader = title || onBack || subtitle || onClose; const showHeader = title || onBack || subtitle || onClose;
const Header = () => {
return (
<Box {...headerProps} className="popover-header">
<div
className={classnames(
'popover-header__title',
centerTitle ? 'center' : '',
)}
>
<h2 title="popover">
{onBack ? (
<button
className="fas fa-chevron-left popover-header__button"
title={t('back')}
onClick={onBack}
/>
) : null}
{title}
</h2>
{onClose ? (
<button
className="fas fa-times popover-header__button"
title={t('close')}
data-testid="popover-close"
onClick={onClose}
/>
) : null}
</div>
{subtitle ? (
<p className="popover-header__subtitle">{subtitle}</p>
) : null}
</Box>
);
};
return ( return (
<div className="popover-container"> <div className="popover-container">
{CustomBackground ? ( {CustomBackground ? (
@ -33,47 +72,22 @@ const Popover = ({
ref={popoverRef} ref={popoverRef}
> >
{showArrow ? <div className="popover-arrow" /> : null} {showArrow ? <div className="popover-arrow" /> : null}
{showHeader && ( {showHeader && <Header />}
<header className="popover-header">
<div
className={classnames(
'popover-header__title',
centerTitle ? 'center' : '',
)}
>
<h2 title="popover">
{onBack ? (
<button
className="fas fa-chevron-left popover-header__button"
title={t('back')}
onClick={onBack}
/>
) : null}
{title}
</h2>
{onClose ? (
<button
className="fas fa-times popover-header__button"
title={t('close')}
data-testid="popover-close"
onClick={onClose}
/>
) : null}
</div>
{subtitle ? (
<p className="popover-header__subtitle">{subtitle}</p>
) : null}
</header>
)}
{children ? ( {children ? (
<div className={classnames('popover-content', contentClassName)}> <Box
className={classnames('popover-content', contentClassName)}
{...contentProps}
>
{children} {children}
</div> </Box>
) : null} ) : null}
{footer ? ( {footer ? (
<footer className={classnames('popover-footer', footerClassName)}> <Box
className={classnames('popover-footer', footerClassName)}
{...footerProps}
>
{footer} {footer}
</footer> </Box>
) : null} ) : null}
</section> </section>
</div> </div>
@ -132,6 +146,18 @@ Popover.propTypes = {
* Check if use centered title * Check if use centered title
*/ */
centerTitle: PropTypes.bool, centerTitle: PropTypes.bool,
/**
* Box props for the header
*/
headerProps: PropTypes.shape({ ...Box.propTypes }),
/**
* Box props for the content
*/
contentProps: PropTypes.shape({ ...Box.propTypes }),
/**
* Box props for the footer
*/
footerProps: PropTypes.shape({ ...Box.propTypes }),
}; };
export default class PopoverPortal extends PureComponent { export default class PopoverPortal extends PureComponent {

View File

@ -1,18 +1,12 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import Button from '../button'; import Button from '../button';
import Box from '../box'; import Box from '../box';
import README from './README.mdx';
import Popover from './popover.component'; import Popover from './popover.component';
export default { export default {
title: 'Components/UI/Popover', title: 'Components/UI/Popover',
id: __filename, id: __filename,
component: Popover, component: Popover,
parameters: {
docs: {
page: README,
},
},
argTypes: { argTypes: {
title: { control: 'text' }, title: { control: 'text' },
subtitle: { control: 'text' }, subtitle: { control: 'text' },
@ -26,6 +20,21 @@ export default {
showArrow: { control: 'boolean' }, showArrow: { control: 'boolean' },
popoverRef: { control: 'object' }, popoverRef: { control: 'object' },
centerTitle: { control: 'boolean' }, centerTitle: { control: 'boolean' },
headerProps: {
control: 'object',
description:
'Box component props used to add container CSS for the header',
},
contentProps: {
control: 'object',
description:
'Box component props used to add container CSS for the content',
},
footerProps: {
control: 'object',
description:
'Box component props used to add container CSS for the footer',
},
}, },
}; };