Modal

Modal is used to display a dialog box that provides custom content.

Import

import { Modal, ModalHeader, ModalFooter, useModal } from '@ma9pie/lite-ui';

Source

components/modal

Examples

import {
  Button,
  Modal,
  ModalFooter,
  ModalHeader,
  useModal,
} from '@ma9pie/lite-ui';
import React from 'react';

const App = () => {
  const { isOpen, setIsOpen, openModal } = useModal();

  return (
    <div>
      <Button color="primary" onClick={openModal}>
        openModal
      </Button>

      <Modal isOpen={isOpen} setIsOpen={setIsOpen}>
        <ModalHeader>Info</ModalHeader>

        <p>Hello Lite UI</p>

        <ModalFooter></ModalFooter>
      </Modal>
    </div>
  );
};

export default App;

Custom

import {
  Button,
  Flex,
  Modal,
  ModalFooter,
  ModalHeader,
  useModal,
} from '@ma9pie/lite-ui';
import React from 'react';

const App = () => {
  const { isOpen, setIsOpen, openModal } = useModal();

  return (
    <div>
      <Button color="primary" onClick={openModal}>
        openModal
      </Button>

      <Modal
        overlay={{
          style: {
            background:
              'linear-gradient(to top, rgba(0, 0, 0, 0.9), rgba(0, 0, 0, 0.1))',
          },
        }}
        content={{
          style: {
            width: 400,
            height: 200,
          },
        }}
        duration={200}
        isOpen={isOpen}
        setIsOpen={setIsOpen}
        onChangeOpen={(value) => {
          if (value) {
            console.log('[modal] opened');
          } else {
            console.log('[modal] closed');
          }
        }}
      >
        <ModalHeader hideCloseIcon={false} closeIcon={<p>X</p>}>
          Info
        </ModalHeader>

        <Flex flex={1}>Hello Lite UI</Flex>

        <ModalFooter
          cancelBtnText="Close"
          confirmBtnText="OK"
          onCancel={() => {
            console.log('[footer] cancel clicked');
          }}
          onConfirm={() => {
            console.log('[footer] confirm clicked');
          }}
        ></ModalFooter>
      </Modal>
    </div>
  );
};

export default App;

API

Modal props

Property
Type
Description
Default
overlay
StyleProps
Modal overlay style.
-
content
StyleProps
Modal content style.
-
duration
number
Modal animation-duration property.
200
zIndex
number
Modal z-index property.
1000
children
ReactNode
Modal content.
-
isOpen
IsOpen
Modal isOpen state.
-
setIsOpen
SetStateAction<IsOpen>
Modal isOpen setState.
-
onChangeOpen
(value: boolean) => void
Modal open change event.
-

ModalHeader props

Property
Type
Description
Default
hideCloseIcon
boolean
Hide close icon.
false
closeIcon
ReactNode
Custom close icon.
-
children
ReactNode
Title content.
-

ModalFooter props

Property
Type
Description
Default
cancelBtnText
string
Cancel button text.
"Cancel"
confirmBtnText
string
Confirm button text.
"Confirm"
onCancel
() => void
Cancel button click event.
-
onConfirm
() => void
Confirm button click event.
-

Default props

Property
Type
Description
Default
key
string
Unique key that identifies repeated elements.
-
className
string
Attribute used to add classes to HTML elements.
-
style
CSSProperties
Attribute used to apply CSS styles directly to HTML elements.
-

Types

StyleProps

export interface StyleProps {
  className?: string;
  style?: CSSProperties;
}

IsOpen

export type IsOpen = boolean | undefined;

Made by ma9pie

Deployed on

vercel