16.0.7 • Published 1 month ago

@leafygreen-ui/modal v16.0.7

Weekly downloads
121
License
Apache-2.0
Repository
github
Last release
1 month ago

Modal

npm (scoped)

View on MongoDB.design

Installation

Yarn

yarn add @leafygreen-ui/modal

NPM

npm install @leafygreen-ui/modal

Example

import Modal from '@leafygreen-ui/modal';

function ExampleComponent() {
  const [open, setOpen] = useState(false);

  return (
    <>
      <button onClick={() => setOpen(curr => !curr)}>Open Modal</button>
      <Modal open={open} setOpen={setOpen}>
        Modal Content goes here.
      </Modal>
    </>
  );
}

Output HTML

<button>Open Modal</button>
<div aria-modal="true" role="dialog" tabindex="-1" class="leafygreen-ui-2e4yhj">
  <button
    tabindex="0"
    aria-disabled="false"
    aria-label="Close modal"
    class="leafygreen-ui-zndd6x"
  >
    <div class="leafygreen-ui-xhlipt">
      <svg
        class="leafygreen-ui-19fdo3o"
        height="20"
        width="20"
        viewBox="0 0 16 16"
        role="img"
      >
        <g
          id="X-Copy"
          stroke="none"
          stroke-width="1"
          fill="none"
          fill-rule="evenodd"
        >
          <path
            d="M9,7 L13.5,7 L13.5,9 L9,9 L9,13.5 L7,13.5 L7,9 L2.5,9 L2.5,7 L7,7 L7,2.5 L9,2.5 L9,7 Z"
            id="Combined-Shape-Copy"
            fill="currentColor"
            transform="translate(8.000000, 8.000000) rotate(45.000000) translate(-8.000000, -8.000000) "
          ></path>
        </g>
      </svg>
    </div></button
  >Modal Content goes here.
</div>

Notes

It is HIGHLY encouraged that any children inside of Modal should refrain from using usePortal={false} because this can cause stacking context/z-indexing issues since the popover element will render relative to the parent rather than rendering in a React portal which is automatically appended to the Modal. By default any component that can use a React portal, like Tooltip or Select, will have usePortal set to true.

Properties

PropTypeDescriptionDefault
openbooleanDetermines open state of Modal componentfalse
setOpenfunctionCallback to set open state of Modal component. setOpen accepts a boolean value, which will determine the open state of Modal component.() => {}
size'small', 'default', 'large'Determines Modal size.'default'
shouldClosefunctionCallback to determine whether or not Modal should close when user tries to close it.() => true
childrennodeChildren that will be rendered inside <Modal /> component.
classNamestringStyle to be applied to the container's root node.
contentClassNamestringStyle to be applied to the content div.
initialFocusstringA selector string for the element to move focus to when the modal is opened. The first focusable element in the modal will receive focus by default.
darkModebooleanDetermines if the component will appear in dark mode.false
closeIconColor'default', 'dark', 'light'Determines the color of the close icon.default

Using Clipboard.js inside Modal

To directly use the Clipboard.js library inside of Modal, rather than using the Copyable component, the reference value of the Modal should be used as the container when Clipboard.js is instantiated. You can get the reference value by consuming the usePopoverPortalContainer hook:

  const { portalContainer } = usePopoverPortalContainer();

  const clipboard = new ClipboardJS(buttonRef, {
    container: portalContainer,
  });
16.0.7

1 month ago

16.0.6

2 months ago

16.0.5

2 months ago

16.0.4

4 months ago

15.0.6

9 months ago

15.0.4

10 months ago

15.0.5

9 months ago

16.0.0-alpha.0

10 months ago

16.0.0-alpha.1

10 months ago

16.0.2

8 months ago

16.0.1

9 months ago

16.0.0

9 months ago

16.0.3

7 months ago

15.0.2

11 months ago

15.0.3

11 months ago

15.0.0

12 months ago

15.0.1

12 months ago

15.0.2-next.3

12 months ago

15.0.2-next.2

12 months ago

15.0.2-next.1

12 months ago

15.0.2-next.0

12 months ago

15.0.2-next.7

12 months ago

15.0.2-next.6

12 months ago

15.0.2-next.5

12 months ago

15.0.2-next.4

12 months ago

14.0.3

1 year ago

14.0.4

1 year ago

14.0.5

1 year ago

14.0.2

1 year ago

12.0.0

1 year ago

12.0.1

1 year ago

14.0.0

1 year ago

14.0.1

1 year ago

13.0.0

1 year ago

10.1.0-test.1

2 years ago

11.0.0

2 years ago

11.0.1

2 years ago

10.1.0

2 years ago

10.1.1

2 years ago

10.1.2

2 years ago

10.1.0-next.0

2 years ago

10.1.0-next.1

2 years ago

10.0.1

2 years ago

10.1.0-test.0

2 years ago

10.1.0-next.2

2 years ago

10.0.0

2 years ago

9.0.2

2 years ago

9.0.1

2 years ago

8.0.1

2 years ago

9.0.0

2 years ago

8.0.0

2 years ago

7.0.0

3 years ago

6.1.2

3 years ago

6.1.1

3 years ago

6.1.0

3 years ago

6.0.3

3 years ago

6.0.2

3 years ago

6.0.1

3 years ago

6.0.0

3 years ago

5.1.2

3 years ago

5.1.1

3 years ago

5.1.0

3 years ago

5.0.1

4 years ago

5.0.0

4 years ago

4.1.1

4 years ago

4.1.0

4 years ago

4.0.0

4 years ago

3.1.5

4 years ago

3.1.4

4 years ago

3.1.3

4 years ago

3.1.2

4 years ago

3.1.1

4 years ago

3.1.0

4 years ago

3.0.6

4 years ago

3.0.5

4 years ago

3.0.4

4 years ago

3.0.3

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.0.0

4 years ago

1.2.3

4 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago