mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Update ModalOverlay to use TS Box version (#20203)
* Update ModalOverlay to use TS Box version * fix jest error * lint error fix * Fix lint errors and improve ModalOverlay's TypeScript typings * Some small updates to story and docs --------- Co-authored-by: georgewrmarshall <george.marshall@consensys.net>
This commit is contained in:
parent
d375dc550d
commit
d879f08763
@ -12,7 +12,7 @@ import { ModalOverlay } from './modal-overlay';
|
|||||||
|
|
||||||
## Props
|
## Props
|
||||||
|
|
||||||
The `ModalOverlay` accepts all props below as well as all [Box](/docs/components-ui-box--default-story#props) component props
|
The `ModalOverlay` accepts all props below as well as all [Box](/docs/components-componentlibrary-box--docs#props) component props
|
||||||
|
|
||||||
<ArgsTable of={ModalOverlay} />
|
<ArgsTable of={ModalOverlay} />
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ exports[`ModalOverlay should match snapshot 1`] = `
|
|||||||
<div>
|
<div>
|
||||||
<div
|
<div
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
class="box mm-modal-overlay box--flex-direction-row box--width-full box--height-full box--background-color-overlay-default"
|
class="mm-box mm-modal-overlay mm-box--width-full mm-box--height-full mm-box--background-color-overlay-default"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
@ -1,2 +1,6 @@
|
|||||||
export { ModalOverlay } from './modal-overlay';
|
export { ModalOverlay } from './modal-overlay';
|
||||||
export type { ModalOverlayProps } from './modal-overlay.types';
|
export type {
|
||||||
|
ModalOverlayProps,
|
||||||
|
ModalOverlayComponent,
|
||||||
|
ModalOverlayStyleUtilityProps,
|
||||||
|
} from './modal-overlay.types';
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { ComponentStory, ComponentMeta } from '@storybook/react';
|
import { StoryFn, Meta } from '@storybook/react';
|
||||||
|
|
||||||
import { ModalOverlay } from './modal-overlay';
|
import { ModalOverlay } from './modal-overlay';
|
||||||
|
|
||||||
@ -21,16 +21,16 @@ export default {
|
|||||||
action: 'onClick',
|
action: 'onClick',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
} as ComponentMeta<typeof ModalOverlay>;
|
} as Meta<typeof ModalOverlay>;
|
||||||
|
|
||||||
const Template: ComponentStory<typeof ModalOverlay> = (args) => (
|
const Template: StoryFn<typeof ModalOverlay> = (args) => (
|
||||||
<ModalOverlay {...args} />
|
<ModalOverlay {...args} />
|
||||||
);
|
);
|
||||||
|
|
||||||
export const DefaultStory = Template.bind({});
|
export const DefaultStory = Template.bind({});
|
||||||
DefaultStory.storyName = 'Default';
|
DefaultStory.storyName = 'Default';
|
||||||
|
|
||||||
export const OnClick: ComponentStory<typeof ModalOverlay> = (args) => {
|
export const OnClick: StoryFn<typeof ModalOverlay> = (args) => {
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const handleOnClick = () => {
|
const handleOnClick = () => {
|
||||||
setOpen(!open);
|
setOpen(!open);
|
||||||
|
@ -3,27 +3,33 @@ import classnames from 'classnames';
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
BackgroundColor,
|
BackgroundColor,
|
||||||
BLOCK_SIZES,
|
BlockSize,
|
||||||
} from '../../../helpers/constants/design-system';
|
} from '../../../helpers/constants/design-system';
|
||||||
|
|
||||||
import Box from '../../ui/box/box';
|
import { Box, BoxProps } from '../box';
|
||||||
|
import type { PolymorphicRef } from '../box';
|
||||||
|
|
||||||
import { ModalOverlayProps } from './modal-overlay.types';
|
import {
|
||||||
|
ModalOverlayProps,
|
||||||
|
ModalOverlayComponent,
|
||||||
|
} from './modal-overlay.types';
|
||||||
|
|
||||||
export const ModalOverlay: React.FC<ModalOverlayProps> = ({
|
export const ModalOverlay: ModalOverlayComponent = React.forwardRef(
|
||||||
onClick,
|
<C extends React.ElementType = 'div'>(
|
||||||
className = '',
|
{ onClick, className = '', ...props }: ModalOverlayProps<C>,
|
||||||
...props
|
ref?: PolymorphicRef<C>,
|
||||||
}) => (
|
) => (
|
||||||
<Box
|
<Box
|
||||||
className={classnames('mm-modal-overlay', className)}
|
className={classnames('mm-modal-overlay', className)}
|
||||||
|
ref={ref}
|
||||||
backgroundColor={BackgroundColor.overlayDefault}
|
backgroundColor={BackgroundColor.overlayDefault}
|
||||||
width={BLOCK_SIZES.FULL}
|
width={BlockSize.Full}
|
||||||
height={BLOCK_SIZES.FULL}
|
height={BlockSize.Full}
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
{...props}
|
{...(props as BoxProps<C>)}
|
||||||
/>
|
/>
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
export default ModalOverlay;
|
export default ModalOverlay;
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
import { BoxProps } from '../../ui/box/box.d';
|
import React from 'react';
|
||||||
|
import type {
|
||||||
|
StyleUtilityProps,
|
||||||
|
PolymorphicComponentPropWithRef,
|
||||||
|
} from '../box';
|
||||||
|
|
||||||
export interface ModalOverlayProps extends BoxProps {
|
export interface ModalOverlayStyleUtilityProps extends StyleUtilityProps {
|
||||||
/**
|
/**
|
||||||
* onClick handler for the overlay
|
* onClick handler for the overlay
|
||||||
* Not necessary when used with Modal and closeOnClickOutside is true
|
* Not necessary when used with Modal and closeOnClickOutside is true
|
||||||
@ -11,3 +15,10 @@ export interface ModalOverlayProps extends BoxProps {
|
|||||||
*/
|
*/
|
||||||
className?: string;
|
className?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type ModalOverlayProps<C extends React.ElementType> =
|
||||||
|
PolymorphicComponentPropWithRef<C, ModalOverlayStyleUtilityProps>;
|
||||||
|
|
||||||
|
export type ModalOverlayComponent = <C extends React.ElementType = 'div'>(
|
||||||
|
props: ModalOverlayProps<C>,
|
||||||
|
) => React.ReactElement | null;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user