0.0.7 โ€ข Published 1 year ago

@jaymyong66/simple-modal v0.0.7

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

Modal

Displays a dialog with a custom content that requires attention or provides additional information. It also provides three modal components that utilize base-modal.

  • Alert Modal
  • Confirm Modal
  • Prompt Modal

installation

npm install @jaymyong66/simple-modal

Component spec

๐ŸŽฏ Base Modal

The main component to display a modal.

prop nametypedefault valuedescription
childrenReactNodechildrens of modal component
isOpenbooleanThe state of the modal being open or closed
onToggle() => voidthe handler function to toggle modal
position'center' \| 'bottom'centerposition of modal on display

ModalHeader

The header of the modal.

prop nametypedefault valuedescription
childrenReactNodechildrens of Modal component
titlestringtitle of modal

ModalContent

The body of the modal. (example - checkbox, input, textarea)

prop nametypedefault valuedescription
childrenReactNodechildrens of ModalContent component

ModalFooter

The footer of the modal. (example - buttons)

prop nametypedefault valuedescription
childrenReactNodechildrens of ModalFooter component

use example

import { Modal } from '@jaymyong66/simple-modal';

const OtherModal = () => {
  const [isOpen, setIsOpen] = useState(false);
  const handleToggle = () => setIsOpen((prev) => !prev);

  return (
    <Modal position="center" isOpen={isOpen} onToggle={handleToggle}>
      <Modal.ModalHeader title="์นด๋“œ์‚ฌ ์„ ํƒ"></Modal.ModalHeader>
      <Modal.ModalContent>
        <CheckBoxField />
      </Modal.ModalContent>
      <Modal.ModalFooter>
        <ConfirmButton />
      </Modal.ModalFooter>
    </Modal>
  );
};

Features

When the modal opens

  • Dimmed outside the modal
  • Content behind a modal is inert, meaning that users cannot interact with it.

When the modal closes

  • Pressing ESC key closes the modal
  • Click dimmed to close

๐ŸŽฏ Alert Modal

A modal that informs the user of a message and has a confirmation button.

prop nametypedefault valuedescription
isOpenbooleanThe state of the modal being open or closed
onToggle() => voidThe handler function to toggle modal
onConfirm() => voidThe handler function to click event of confirm button
position'center' \| 'bottom'centerPosition of modal on display
size'large' \| 'medium' \| 'small'largeSize of modal on display
titlestringTitle of modal header
captionstringCaption of modal header
confirmButtonLabelstringCaption of confirm button

use example

import { AlertModal } from '@jaymyong66/simple-modal';

const OtherModal = () => {
  const [isOpen, setIsOpen] = useState(false);
  const handleToggle = () => setIsOpen((prev) => !prev);
  const handleConfirm = () => {
    console.log('confirm');
    handleToggle();
  };

  return (
    <AlertModal
      position="center"
      size="small"
      isOpen={isOpen}
      onToggle={handleToggle}
      onConfirm={handleConfirm}
      title="์•„์ด๋””๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."
      caption="์•„์ด๋””๋Š” ํ•„์ˆ˜๋กœ ์ž…๋ ฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค."
      confirmButtonLabel="ํ™•์ธ"
    />
  );
};

๐ŸŽฏ Confirm Modal

A modal that gives the user a choice and has confirm and cancel buttons

prop nametypedefault valuedescription
isOpenbooleanThe state of the modal being open or closed
onToggle() => voidThe handler function to toggle modal
onConfirm() => voidThe handler function to click event of confirm button
position'center' \| 'bottom'centerPosition of modal on display
size'large' \| 'medium' \| 'small'largeSize of modal on display
titlestringTitle of modal header
captionstringCaption of modal header
confirmButtonLabelstringCaption of confirm button
cancelButtonLabelstringCaption of cancel button

use example

import { ConfirmModal } from '@jaymyong66/simple-modal';

const OtherModal = () => {
  const [isOpen, setIsOpen] = useState(false);
  const handleToggle = () => setIsOpen((prev) => !prev);
  const handleConfirm = () => {
    console.log('confirm');
    handleToggle();
  };

  return (
    <ConfirmModal
      position="center"
      size="small"
      isOpen={isOpen}
      onToggle={handleToggle}
      onConfirm={handleConfirm}
      title="์นด๋“œ๋ฅผ ์‚ญ์ œํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?"
      caption="์‚ญ์ œํ•˜๋ฉด ๋ณต๊ตฌํ•˜์‹ค ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."
      confirmButtonLabel="ํ™•์ธ"
      confirmButtonLabel="์ทจ์†Œ"
    />
  );
};

๐ŸŽฏ Prompt Modal

A modal with an input field to receive input from the user and an OK/Cancel button.

prop nametypedefault valuedescription
isOpenbooleanThe state of the modal being open or closed
onToggle() => voidThe handler function to toggle modal
onChange() => voidA handler function that receives the value of the change event.
onSubmit(value: string) => voidA handler function that receives the value of the submit event.
position'center' \| 'bottom'centerPosition of modal on display
size'large' \| 'medium' \| 'small'largeSize of modal on display
titlestringTitle of modal header
valuestringValue received from user
confirmButtonLabelstringCaption of confirm button
cancelButtonLabelstringCaption of cancel button

use example

import { PromptModal } from '@jaymyong66/simple-modal';

const OtherModal = () => {
  const [isOpen, setIsOpen] = useState(false);
  const [value, setValue] = useState('');
  const handleToggle = () => setIsOpen((prev) => !prev);
  const handleChange = (e: ChangeEvent<HTMLInputElement>) => setValue(e.target.value);
  const handleSubmit = (value: string) => {
    console.log(value);
    handleToggle();
  }

  return (
    <PromptModal
      position="bottom"
      size="medium"
      isOpen={isOpen}
      onToggle={handleToggle}
      title="์ฟ ํฐ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."
      value={value}
      onChange={handleChange}
      onSubmit={handleSubmit}
      confirmButtonLabel="ํ™•์ธ"
      confirmButtonLabel="์ทจ์†Œ"
    />
  );
};
0.0.7

1 year ago

0.0.5

1 year ago

0.0.6

1 year ago

0.0.3

1 year ago

0.0.4

1 year ago

0.0.2

1 year ago

0.0.0

1 year ago