1.0.9 • Published 3 years ago

@irfanismail/mon-modal v1.0.9

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

mon-modal

MonModal a feature-rich modal Vue2 component. It focuses on bringing the best of Vue's features to achieve common & advanced behavior patterns while giving you the freedom to style the component to your liking. Built-to-work with TailwindCSS.

mon-modal-gif

Demo

Getting Started

// npm
npm i @irfanismail/mon-modal


// yarn
yarn add @irfanismail/mon-modal

Usage

  1. Table of Props
PropsTypeDefaultDescription
titlestring-Title of the modal
labelstring-Button label for default modal implementation
titleClassstring'mon-modal-title'Class for title (Tailwind compatible)
labelClassstring-Class for button label for default modal implementation (Tailwind compatible)
backdropClassstring'mon-modal'Class for modal backdrop (Tailwind compatible)
modalClassstring'mon-modal-container'Class for modal container (Tailwind compatible)
headerClassstring'mon-modal-header'Class for modal header (Tailwind compatible)
bodyClassstring'mon-modal-body'Class for modal body (Tailwind compatible)
footerClassstring'mon-modal-footer'Class for modal footer (Tailwind compatible)
persistentbooleanfalseContent rendered inside modal persists even when modal is closed. By default, the content rendered will be destroyed once user closes the modal
disableClickAwaybooleanfalseDisables modal close behavior when user interacts with out of modal content. By default, modal will close when user clicks away.
disableEscbooleanfalseDisables modal close behavior when user presses Esc key. By default, modal will close when user presses Esc key.
openOnMountbooleanfalseModal will open on mounted(). Refer to Vue's mounted lifecycle for more information
enterstring'mon-modal-enter'Custom transition class for modal enter phase
enterActivestring'mon-modal-enter-active'Custom transition class for modal enter-active phase
enterTostring'mon-modal-enter-to'Custom transition class for modal enter-to phase
leavestring'mon-modal-leave'Custom transition class for modal leave phase
leaveActivestring'mon-modal-leave-active'Custom transition class for modal leave-active phase
leaveToboolean'mon-modal-leave-to'Custom transition class for modal leave-to phase
  1. Combinations of Slots & Props
<!-- Basic Modal -->
props: 
* title
* label 
  <mon-modal [...props]>
      <template #body>...</template>
      <template #footer="{ close }">...</template>
  </mon-modal>
  
<!-- Custom Header & Content -->
props: 
* label 
  <mon-modal [...props]>
    <template #header="{ close }">...</template>
    <template #custom="{ open, close }">...</template>
  </mon-modal>

<!-- Custom Trigger -->
props: 
 * title
  <mon-modal [...props]>
    <template #trigger="{ open }"></template>
    <template #body>...</template>
  </mon-modal>


<!-- Custom Transition Class -->
props: 
 * title
 * enter
 * enter-active
 * enter-to
 * leave
 * leave-active
 * leave-to
  <mon-modal [...props]>
   ...
  </mon-modal>
  1. Component Lifecycle Hooks

If you need to do logic based on the modal's lifecycle, you can utilize the predefined hooks given below!

HooksTypeDescription
before-openfunctionCalled before the modal opens
after-openfunctionCalled after the modal opens
before-closefunctionCalled before the modal closes
after-closefunctionCalled after modal closes

Example Implementation

<mon-modal 
    @before-open="..."
    @after-open="..."
    @before-close="..."
    @after-close="...">
    ...
</mon-modal>

Check the Demo on how to use modal lifecycle hooks

  1. Handling Modal Behavior outside Usual Scope

There will be times, you will find yourselves needing to trigger modal behaviors outside of the normal scope (eg. clicking a button). MonModal provides two (2) internal functions that can be accessed through Vue's ref="..." & $refs.

The two functions are:

  • openModal()
  • closeModal()

Check the Demo on how to use modal's internal functions

License

MIT License

Author

Irfan Ismail - @irfancoder - irfan.ismail96@gmail.com

1.0.9

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.2

3 years ago

1.0.3

3 years ago

1.0.1

3 years ago