1.0.1 • Published 9 months ago

oc14-simple-react-modal-plugin v1.0.1

Weekly downloads
-
License
-
Repository
github
Last release
9 months ago

simple-react-modal-plugin

Modal dialog component for ReactJS.

screenshot

Installation

To install, you can use npm or yarn:

$ npm i oc14-simple-react-modal-plugin
$ yarn add oc14-simple-react-modal-plugin

To use oc14-simple-react-modal-plugin in a React app:

  • In a react app, import the component:
import { HrnetModal } from "oc14-simple-react-modal-plugin"
  • To setup the component's state, add:
const [openModal, setOpenModal] = useState(false)

To use the component's state, pass it as prop:

<HrnetModal setOpen={setOpenModal} />
  • To custom the composant (...or not), take a look below and add what you need with props:
<HrnetModal
    open={openModal}
    setOpen={setOpenModal}
    // Customization
    title={''}
    titleColor={''}
    message={hrnetModalMessage}
    // ...
/>

Usage

You can use it like a simple React component in your React project

import { HrnetModal } from "./lib"

const [openModal, setOpenModal] = useState(false)

{
    <HrnetModal
        setOpen={setOpenModal}
        // Set your Props here to custom the component //
    />
}

Props

PropsTypeDescription
openbooleanif true, the modal is shown and hidden if false
setOpenbooleantoggle the state of the modal - set openModal to true or false
titlestringtitle of your modal (i.e 'Hello world')
titleColorstringcolor value of your modal's title (i.e '#0000FF')
messagestringmessage of your modal (i.e 'Welcome')
backdropBgstringcolor value of your page background (i.e '#ffffff')
modalBgstringcolor value of your modal's background (i.e '#ffffff')
xCloseColorstringcolor value of the x close (i.e '#ffffff')
modalWidthstringwidth value of your modal (i.e '400')
okButtonbooleantrue ou false if you want an ok button
okButtonColorstringcolor value of the button text (i.e '#ffffff')
okButtonColorHoverstringcolor value of the button text on hover (i.e '#ffffff')
okButtonBgstringcolor value of the button background (i.e '#ffffff')
okButtonBgHoverstringcolor value of the button background on hover (i.e '#ffffff')
okButtonActionstringDispatch a function on submit
cancelButtonbooleantrue ou false if you want a cancel button
cancelButtonColorstringcolor value of the button text (i.e '#ffffff')
cancelButtonColorHoverstringcolor value of the button text on hover (i.e '#ffffff')
cancelButtonBgstringcolor value of the button background (i.e '#ffffff')
cancelButtonBgHoverstringcolor value of the button background on hover (i.e '#ffffff')

Exemple

Here is a simple example of oc14-simple-react-modal-plugin being used:

import { HrnetModal } from "oc14-simple-react-modal-plugin"
import { useState } from "react"
import styled from 'styled-components'

export default function App() {
    const [openModal, setOpenModal] = useState(false)
    const [isHover, setIsHover] = useState(false)
    const handleMouseEnter = () => setIsHover(true)
    const handleMouseLeave = () => setIsHover(false)
    const handleModal = () => setOpenModal((toggle) => !toggle)
    const handleOkButtonAction = () => console.log('Dispatch a function on submit')

    const hrnetModalMessage = 'Employee successfully created!'

    return (
        <BodyMain>
            <HomeButton
                style={{
                    backgroundColor: isHover ? '#25b3f5' : '#169de0'
                }}
                onClick={(e) => handleModal(e)}
                onMouseEnter={handleMouseEnter}
                onMouseLeave={handleMouseLeave}
            >
                Open modal
            </HomeButton>

            <HrnetModal
                open={openModal}
                setOpen={setOpenModal}
                title={''}
                titleColor={''}
                message={hrnetModalMessage}
                backdropBg={'rgba(15,19,26,.8)'}
                modalBg={'#292d33'}
                xCloseColor={'#a4a9b3'}
                modalWidth={'400'}
                okButton={true}
                okButtonColor={'#fff'}
                okButtonColorHover={'#fff'}
                okButtonBg={'#169de0'}
                okButtonBgHover={'#25b3f5'}
                okButtonAction={handleOkButtonAction}
                cancelButton={true}
                cancelButtonColor={'#a4a9b3'}
                cancelButtonColorHover={'#e9ebf0'}
                cancelButtonBg={'transparent'}
                cancelButtonBgHover={'#5c6066'}
            />
        </BodyMain>
    )
}

const BodyMain = styled.main`
    margin: 20vh auto;
    text-align: center;
`
const HomeButton= styled.button`
    align-items: center;
    border: none;
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    font-size: 14px;
    font-weight: 400;
    justify-content: center;
    line-height: 20px;
    margin-bottom: 0;
    overflow: hidden;
    padding: 8px 12px;
    position: relative;
    text-align: center;
    text-decoration: none;
    transition: color .15s ease-out;background-color .15s ease-out;
    user-sselect: none;
    vertical-align: middle;
    white-space: nowrap;
`
1.0.1

9 months ago

1.0.0

9 months ago