1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 18:00:18 +01:00
metamask-extension/ui/components/component-library/modal-content
Garrett Bear 66292330fe
Feat/18890/button ts update (#20492)
* button to TS migration

working demo

style props

broken mapping - need switch

working types file

working types

fix dependent imports of Button

variant mapping

working types

fix lint

fix test

fix ButtonSize issue on QuizContent

box fix

test if this works

fix button being used on QuizContent

fix button_variant import

readme fix

* fix button import

* fix primary button as anchor hover

* deprecated

* button to TS migration

fix lint

fix test

* fix rebase issue

* fix rebase issue

* lint fix
2023-08-28 14:42:00 -07:00
..
__snapshots__ Replacing deprecated components and code for import tokens (#19559) 2023-07-26 08:48:31 -07:00
index.ts Adding ModalContent component (#18175) 2023-03-22 17:17:19 -07:00
modal-content.scss Adding Modal and updating ModalContent component (#19020) 2023-05-19 13:20:15 -07:00
modal-content.stories.tsx Feat/18890/button ts update (#20492) 2023-08-28 14:42:00 -07:00
modal-content.test.tsx Adding Modal and updating ModalContent component (#19020) 2023-05-19 13:20:15 -07:00
modal-content.tsx Replacing deprecated components and code for import tokens (#19559) 2023-07-26 08:48:31 -07:00
modal-content.types.ts Replacing deprecated components and code for import tokens (#19559) 2023-07-26 08:48:31 -07:00
README.mdx Feat/18890/button ts update (#20492) 2023-08-28 14:42:00 -07:00

import { Story, Canvas, ArgsTable } from '@storybook/addon-docs';

import { ModalContent } from './modal-content';

# ModalContent

`ModalContent` is the container for the modal dialog's content. It uses context supplied by the `Modal` component and cannot be used without it.

<Canvas>
  <Story id="components-componentlibrary-modalcontent--default-story" />
</Canvas>

## Props

<ArgsTable of={ModalContent} />

### Children

Use the `children` prop to render the content of `ModalContent`. The `ModalContent` should generally be used with the `ModalHeader` component.

<Canvas>
  <Story id="components-componentlibrary-modalcontent--children" />
</Canvas>

```jsx
import React, { useState } from 'react';
import { Modal, ModalContent, ModalHeader, Text, Button, ButtonVariant } from '../../component-library';

const [show, setShow] = useState(false);
const handleOnClick = () => {
  setShow(!show);
};

<Button variant={ButtonVariant.Primary} onClick={handleOnClick}>
  Open
</Button>
<Modal isOpen={show} onClose={handleOnClick}>
  <ModalContent {...args}>
    <ModalHeader marginBottom={4}>Modal Header</ModalHeader>
    <Text marginBottom={4}>Modal Content</Text>
    <Button variant={ButtonVariant.Primary} onClick={handleOnClick}>
      Close
    </Button>
    <LoremIpsum />
    <LoremIpsum />
    <LoremIpsum />
    <LoremIpsum />
    <LoremIpsum />
  </ModalContent>
</Modal>
```

### Size

Currently the `ModalContent` supports a single size, this decision was made after we ran an audit on all modal sizes in the extension codebase and found that all modals could be made to fit the `ModalContentSize.Sm`(360px) size.

If you do require a larger modal size you can use the `modalDialogProps` to add a className to override the default size.

<Canvas>
  <Story id="components-componentlibrary-modalcontent--size" />
</Canvas>

```jsx
import { DISPLAY } from '../../../helpers/constants/design-system';

import Box from '../../ui/box';

import { Modal, ModalContent, Text, Button, ButtonVariant } from '../../component-library';

enum ModalContentSizeStoryOption {
  Sm = 'sm',
  ClassName = 'className',
}

const [show, setShow] = useState({
  sm: false,
  className: false,
});
const handleOnClick = (size: ModalContentSizeStoryOption) => {
  setShow({ ...show, [size]: !show[size] });
};

<Box display={DISPLAY.FLEX} gap={4}>
  <Button
    variant={ButtonVariant.Secondary}
    onClick={() => handleOnClick(ModalContentSizeStoryOption.Sm)}
  >
    Show sm size
  </Button>
  <Button
    variant={ButtonVariant.Secondary}
    onClick={() => handleOnClick(ModalContentSizeStoryOption.ClassName)}
  >
    Show className
  </Button>
</Box>

<Modal
  isOpen={show.sm}
  onClose={() => handleOnClick(ModalContentSizeStoryOption.Sm)}
>
  <ModalContent {...args}>
    <Text marginBottom={4}>
      ModalContentSize.Sm default and only size 360px max-width
    </Text>
    <Button onClick={() => setShow({ ...show, sm: false })}>Close</Button>
  </ModalContent>
</Modal>

<Modal
  isOpen={show.className}
  onClose={() => handleOnClick(ModalContentSizeStoryOption.ClassName)}
>
  <ModalContent
    {...args}
    modalDialogProps={{
      style: { maxWidth: 800 },
    }}
  >
    <Text marginBottom={4}>
      Using modalDialogProps and adding a className setting a max width
      (max-width: 800px)
    </Text>
    <Button onClick={() => setShow({ ...show, className: false })}>
      Close
    </Button>
  </ModalContent>
</Modal>
```