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:
parent
aa89bb189b
commit
261b066fc0
@ -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} />
|
|
||||||
|
|
@ -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,23 +19,15 @@ 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 (
|
return (
|
||||||
<div className="popover-container">
|
<Box {...headerProps} className="popover-header">
|
||||||
{CustomBackground ? (
|
|
||||||
<CustomBackground onClose={onClose} />
|
|
||||||
) : (
|
|
||||||
<div className="popover-bg" onClick={onClose} />
|
|
||||||
)}
|
|
||||||
<section
|
|
||||||
className={classnames('popover-wrap', className)}
|
|
||||||
ref={popoverRef}
|
|
||||||
>
|
|
||||||
{showArrow ? <div className="popover-arrow" /> : null}
|
|
||||||
{showHeader && (
|
|
||||||
<header className="popover-header">
|
|
||||||
<div
|
<div
|
||||||
className={classnames(
|
className={classnames(
|
||||||
'popover-header__title',
|
'popover-header__title',
|
||||||
@ -63,17 +56,38 @@ const Popover = ({
|
|||||||
{subtitle ? (
|
{subtitle ? (
|
||||||
<p className="popover-header__subtitle">{subtitle}</p>
|
<p className="popover-header__subtitle">{subtitle}</p>
|
||||||
) : null}
|
) : null}
|
||||||
</header>
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="popover-container">
|
||||||
|
{CustomBackground ? (
|
||||||
|
<CustomBackground onClose={onClose} />
|
||||||
|
) : (
|
||||||
|
<div className="popover-bg" onClick={onClose} />
|
||||||
)}
|
)}
|
||||||
|
<section
|
||||||
|
className={classnames('popover-wrap', className)}
|
||||||
|
ref={popoverRef}
|
||||||
|
>
|
||||||
|
{showArrow ? <div className="popover-arrow" /> : null}
|
||||||
|
{showHeader && <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 {
|
||||||
|
@ -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',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user