1.0.12 • Published 2 years ago

custom-modal-library v1.0.12

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

custom-modal-library

Made with create-react-library

NPM JavaScript Style Guide

Install

npm install --save custom-modal-library

Usage Standalone

import React, { useState } from 'react'

import { CustomModalComponent } from 'custom-modal-library'

function CustomModal() {
  const [showModal, setShowModal] = useState(false)

  const hideModal = () => showModal && setShowModal(false)

  return (
    <div>
      <button
        onClick={() => setShowModal(true)}
      >
       Show Modal
      </button>
      <CustomModalComponent show={showModal} hide={hideModal}>
      </CustomModalComponent>
    </div>
  )
}

export default CustomModal

Usage with react props

import React from 'react'

import { CustomModalComponent } from 'custom-modal-library'

function CustomModal(props) {
  return (
    <div>
      <CustomModalComponent show={props.show} hide={props.hide} >
      </CustomModalComponent>
    </div>
  )
}

export default CustomModal

Full Customization standalone

import React, { useState } from 'react'

import { CustomModalComponent } from 'custom-modal-library'

function CustomModal() {
  const [showModal, setShowModal] = useState(false)

  const hideModal = () => showModal && setShowModal(false)

  return (
    <div className={!showModal ? "fade" : "show fade"}>
      <button
        onClick={() => setShowModal(true)}
      >
       Show Modal
      </button>
      <CustomModalComponent
        className="modal-fade"
        color='white'
        overlayColor='blue'
        backgroundColor='#4b66b7'
        closeColor='white'
        modalTitle='Alert Modal has been triggrered'
        modalText='You can specify severals things here'
        width={800}
        height={250}
        x={'24vh'}
        y={undefined}
        show={showModal}
        ctaBtnShow={true}
        ctaText='Click Me!'
        ctaOnClick={()=> {console.log('Log from cta')}}
        hide={hideModal} >
      </CustomModalComponent>
    </div>
  )
}

export default CustomModal

Some CSS to add transition based on your choice

.fade {
  transition: opacity .15s linear;
}
.modal-fade {
  transition: -webkit-transform .3s ease-out;
  transition: transform .3s ease-out;
  transition: transform .3s ease-out,-webkit-transform .3s ease-out;
  -webkit-transform: translateY(-50px);
  transform: translateY(-50px);
}

Propreties List

PropretyTypeDefault ValueDescription
showBooleanfalseshow the modal
hideBooleanfalsehide the modal
widthIntnullwidth of the modal
heightIntnullheight of the modal
colorStringblackText color body modal
backgroundColorStringwhitebackground color of the modal
closeColorStringblackcolor of the close cross
modalTitleStringHellotitle of the modal
modalTextStringModal Clicked !title of the subtext
ctaBtnShowBooleannullenable the call to action button
ctaTextStringClose ButtonText of the call to action button
ctaOnClickFunction()=> console.logfunction that is triggered on click of the call to action button
xStringundefinedx position (from top)
yFunctionundefinedy position ( from left)

License

MIT © MathisZerbib

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago