0.1.5 • Published 3 years ago

thx-modal v0.1.5

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

thx-modal

Description

A React modal created for developers, with easy configuration and styling.

Table of Contents

Installation

To install, you can use npm or yarn:

    $ npm install thx-modal
    $ yarn add thx-modal

Minimal exemple

Here is a simple example of thx-modal being used in an app with some custom styles and focusable input elements within the modal content:

import React from "react";
import ReactDOM from "react-dom";
import Modal, { useModal } from "thx-modal";

const App = () => {
	// modal hook that's allow you to toggle modal by Id
	const { openedModals, toggleModal } = useModal();

	return (
		<div>
			<button onClick={() => toggleModal("id_of_modal")}>Display modal</button>
			<Modal
				id={"id_of_modal"}
				isOpen={openedModals["id_of_modal"]}
				onClose={() => toggleModal("id_of_modal")}>

                    <h1>My modal</h1>
                    <blockquote>The cake is a lie !</blockquote>
			</Modal>
		</div>
	);
};

You can find more examples in the examples section.

Exemples

All props you can pass to the modal

Base props

PropsRequiretypeDescription
id✔️stringId of modal, used to identify modal
isOpen✔️BooleanFor better integration, use theopenedModals property of useModal() hook, state will contain in openedModalsid
onClose✔️functionFunction that toggle oppened state of modal. For better integration, usetoggleModals() of the useModal() hook
classNamestringModal class default is__thxModal__. Add classes through this props

All other props are optionnal.

Content

PropstypeDescription
titlestringTitle of modal
headerHtmlElement, string, customComponentWill be placed into <header>exemple: header={<h1>This is a modal</h1>}
contentHtmlElement, string, customComponentContent of the modalexemple: header={"This is a content"}
footerHtmlElement, string, customComponentWill be placed into <footer>exemple: footer={"End of modal"}
closeTextstringText into close button
closeBtnHtmlElement, customComponentCustom close button, trigger close function on click
childrenHtmlElement, string, customComponentUse modal as a container

You must have at least one of content or children props or anything in children of modal !

Styles

PropstypeDescription
themestringChoose the theme color ! theme must be a color in hexadecimal ("#262626")
modalSizestringSize of the modal (accepted values: "sm", "lg", "xl")
widthstringChose width of modal (ex: 25% )
heightstringChose height of modal (ex: 520px )
textColorObjectChange color of text
backgroundStyleObject, boolStyle of background, if false, it remove the background
modalStyleObjectStyle of modal, will override all default styles
headerStyleObjectStyle of header, will override all default styles
contentStyleObjectStyle of content, will override all default styles
footerStyleObjectStyle of footer, will override all default styles
animationOpenstringChoose animation when modal appear ("slide-up", "slide-down", "slide-left", "slide-right", "fade-in", "scale-up")
animationClosestringChoose animation when modal disappear ("slide-up", "slide-down", "slide-left", "slide-right", "fade-out", "scale-down")

Behaviors

PropstypeDescription
exitExistingBoolIf true, close all open modals
exitOnEscapeBoolClose modal if user type on "Escape" key
exitOnClickBoolClose modal if user click out of modal
isDialogBoolIf isDialog true, a close event must be triggered to close the modal
indexIntegerIndex of modal, if you open multiple modals, you can choose order with index

Callbacks

PropstypeDescription
asyncContentFunctionAsynchronous content will replace content already in place in the modal
whenRenderFunctionFunction called when the modal is closing

Dependencies

  • "prop-types": "^15.8.1"
  • "react": "^18.2.0",
  • "react-dom": "^18.2.0"
0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.103

3 years ago

0.0.102

3 years ago

0.0.101

3 years ago

0.0.100

3 years ago

0.0.31

3 years ago

0.0.30

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago