1.1.14 • Published 1 year ago

@lokkotara/custom-modal v1.1.14

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

Important information about this package

This package is meant to be used for educational purpose. It is not intended to be maintained and could be deleted in the future.

About this package

It's a simple, lightweight, and customizable modal component for React. It is built using Storybook and fortawesome as dependencies.

-> Storybook allows us to isolate the package from the business logic and context of our application.

-> Fortawesome is a package developed by Font Awesome and provides an easy way to use icons in our component.

Installation

To install this package, type

 npm install @lokkotara/custom-modal

Usage

First, import the component with

import { Modal } from "@lokkotara/custom-modal";

Then, you can use it like this :

import React,{ useState } from "react";
import { Modal } from "@lokkotara/custom-modal";

const SomeComponent = () => {

  const [isModal, setIsModal] = useState(false);

  const customModalBody = (
    <span>An interesting text</span>
  );

  return (
    <div>
      <Modal
        closeButton={false} // Display the close button
        closeButtonStyle={{color: purple}} // Style for the close button
        icon="success" // The icon to display
        iconStyle={{color: purple}} // Style for the icon
        isOpen={isModal} // Whether the modal is open or closed
        message={customModalBody} //The content inside the body of the modal
        messageStyle={{fontSize: 1.2rem}} //Style applied to the message
        modalContainerStyle={{ backgroundColor: "rgba(164, 137, 178, 0.9)" }} // Style applied to the container behind the modal
        modalStyle={{backgroundColor: #f1f2f3, maxWidth: 500px, minHeight: 250px}} // Style for the modal window
        modalMode={true} // If true, it can't be closed by clicking on the background behind the modal
        onClose={() => setIsModal(false)} // Called when the modal is closed
        title="An awesome title" // The title of the modal
        titleStyle={{color: grey, fontSize: 1.5rem}} // Style applied to the title
      />
    </div>
  )
};

PropTypes

There is a couple of props that we can pass to our component to customise its appearance. Below is an explanation of what we can do :

NameTypeRequiredExample
closeButtonvoid or BooleannoNothing if you want the close button and closeButton={false} if you want to remove it
closeButtonStylevoid or ObjectnocloseButtonStyle={{color: purple, fontSize: 1.5rem}}
iconvoid or StringnoNothing if you don't want any icon. Else, one of these : success, error, info, danger
iconStylevoid or ObjectnoIcons have a size and their own color by default. However, you can change it by passing an object of properties iconStyle={{color: purple, fontSize: 1.5rem}}
isOpenBooleanyesisOpen should be linked to a useState with false as default value ans set to true to open the modal
messageString/JSX.elementyesmessage="My first message" or an element like message={<span>My first message in a span</span>}
messageStylevoid or ObjectnomessageStyle={{fontSize: 1.2rem, color:grey, fontWeight: bold}}
modalStylevoid or ObjectnomodalStyle={{backgroundColor: #f1f2f3, maxWidth: 500px, minHeight: 250px}}
modalModevoid or BooleannoNothing if you want to close by clicking outside. Else modalMode={true}
onCloseFunctionyesShould set the useState to false like this : onClose={() => setIsModal(false)}
titlevoid or Stringnotitle="An awesome title"
titleStylevoid or ObjectnotitleStyle={{color: grey, fontSize: 1.5rem}}

Examples

Here are a few screenshots of what we can do with customisation :

TypeExample
Success messageSuccessful example
Error messageerror example
Info messageinfo example
Danger messagedanger example
Long messagelong example
Custom modal colorscustom colors example
Custom background colorcustom background example