0.2.3 • Published 2 months ago

react-relax-modal v0.2.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

react-relax-modal

A easy Modal system for Web React Apps

Table of Contents

Installation

To install, you can use npm or yarn:

$ npm install --save react-relax-modal
$ yarn add react-relax-modal

Examples

Here is a simple example of react-relax-modal being used in an app

import {RelaxModalProvider, useRelaxModal} from "react-relax-modal";

const modalStyle = {
  width: 200,
  height: 200,
  display: "flex",
  borderRadius: "5px",
  alignItems: "center",
  justifyContent: "center",
  backgroundColor: "white",
};

const MyModal = () => {
    return (
        <div style={modalStyle}>
            <span>Hello World!</span>
        </div>
    );
};

const Screen = () => {
    const {openModal} = useRelaxModal();
    return <button onClick={() => openModal(<MyModal />)}>Open My Modal</button>;
};

function App() {
    return (
        <RelaxModalProvider>
            <Screen />
        </RelaxModalProvider>
    );
}

export default App;

You can find examples in the examples directory, which you can run in a local development server using npm start or yarn run start.

RelaxModalProvider Props

RelaxModalProvider accepts props to set a global configuration and/or get a debug helper for your development process

function App() {
    return (
        <RelaxModalProvider {/**props */}>
            {...}
        </RelaxModalProvider>
    );
}
AttributesTypeDefaultDescription
debugbooleanfalseIf debug is true you will see on console the stack of modals and the active one
childrenJSX.Element or JSX.Element[]JSX.Element (required)The components that you want to get access to the Relax Modal Provider API
rootConfigRelaxModalConfigdefault ConfigSet an initial configuration for all your Modals

Modal Config

Each time that you call openModal to open a new modal component you can add configuration object that only will affect that Modal

<button onClick={() => openModal(<YourModalComponent />, {/**config */})}>
    Open Modal
</button>
AttributesTypeDefaultDescription
alignmentAlignmentcenterSet the screen location of your component that you are providing to the openModal() function
backgroundColorstringrgba(0,0,0, .6)The background color
closeOnBackdropbooleantrueSet if user can close the modal when click on the backdrop
autoCloseMSnumber or undefinedundefinedSet auto-close duration for your Modal
styleCSSProperties or undefinedundefinedSet styling for Modal container
closeKeystring or undefinedEscapeSet what keyboard key you want to use to close the Modal
onClosedfunctionundefinedSet a callback when user close the Modal
onBackdropfunctionundefinedSet a callback when user clicks on the backdrop
closeButtonCloseButton{show: false, icon: undefined, style: undefined, defaultIconColor: "#fff"}Personalize the Modal close Button
animationAnimation{initial: {transform: "translateY(4rem)", opacity: 0}, animate: {transform: "translateY(0)", opacity: 1}}Set animation when Modal is open
0.2.1

2 months ago

0.2.0

2 months ago

0.1.8

2 months ago

0.1.7

2 months ago

0.2.3

2 months ago

0.1.4

2 months ago

0.2.2

2 months ago

0.1.6

2 months ago

0.1.5

2 months ago

0.1.3

5 months ago

0.0.11

5 months ago

0.0.12

5 months ago

0.0.13

5 months ago

0.0.14

5 months ago

0.1.0

5 months ago

0.1.2

5 months ago

0.1.1

5 months ago

0.0.15

5 months ago

0.0.16

5 months ago

0.0.17

5 months ago

0.0.10

5 months ago

0.0.9

5 months ago

0.0.8

5 months ago

0.0.7

5 months ago

0.0.6

5 months ago

0.0.5

5 months ago

0.0.4

5 months ago

0.0.3

5 months ago

0.0.2

5 months ago

0.0.1

5 months ago