1.0.1 • Published 8 months ago

custom-modal-react-component v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
8 months ago

Custom Modal React Component

React component which allows to display a customizable modal with different themes and parameters.

Table of content

Installation

npm install custom-modal-react-component

Version

This package is in version 1.0.1

Technologies

  • JavaScript
  • SASS: 1.80.5
  • React: 18.3.1
  • React DOM: 18.3.1
  • Node: 18.16.1

Usage

import React, { useRef } from "react"
import Modal from "custom-modal-react-component"
import "custom-modal-react-component/dist/styles/modal-component.css"
import closeIcon from "custom-modal-react-component/dist/icons/close.svg" /* You can change the closeIcon path if it is different */

function App() {
	const modalRef = useRef() 

	/* Call modalRef.current.open() when you want the modal to open, for example after a form submission.
	   Only "if(modalRef.current)" and its content are mandatory, you can adapt this example for your own needs.
	*/
	const handleSubmit = (e) => {
		e.preventDefault()
		if (modalRef.current) {
			modalRef.current.open()
		}
	}

	return (
		<>
			{/* Only the <Modal /> component with its required props is mandatory here, you can adapt this example for your own needs. */}
			<Modal ref={modalRef} icon={Your icon path} title="Your title" message="Your message" theme="light" closeIconPath={closeIcon} />
			<form onSubmit={handleSubmit}>
			<label htmlFor="Field">Field</label>
				<input type="text" />
				<button>Submit</button>
			</form>	
		</>
	)
}

Props

Modal preview

A background is added behind the modal, preventing to interact with the back of the page.

Modal preview

Global settings

The modal is designed with a maximum height and width of 75% of its container.

A scrollbar appears if the content exceeds the modal height.

Customization

To apply default styles, import the component's CSS:

import "custom-modal-react-component/dist/styles/modal-component.css"

Several preset themes are available, go to the next section to check.

Available Classes for Custom Styling

  • .modal : Style the modal container (e.g., background, border)
  • .modal-title : Style the title text
  • .modal-message : Style the message content

Themes

Choose from multiple themes by setting the theme prop with one of the theme names below.

How to use it with the candy theme, for example :

<Modal ref={modalRef} title="Your title" message="Your message" theme="candy" closeIconPath={closeIcon} />

Light theme

Modal with light theme

Dark theme

Modal with dark theme

Minimal theme

Modal with minimal theme

Mystic theme

Modal with mystic theme

Candy theme

Modal with candy theme

Organic theme

Modal with organic theme

Coffee theme

Modal with coffee theme

Tech theme

Modal with tech theme

Urban theme

Modal with urban theme

Success theme

Modal with success theme

Warning theme

Modal with warning theme

Information theme

Modal with information theme

Contribution

This project was conducted as part of a training course and is not open to external contributions at this time.

Author

Mégane Navarro (navarromegane@gmail.com)

Changelog

1.0.1 - 2024-11-15

  • First stable version
  • Adding a declaration file
  • Documentation improvement

0.0.0 - 2024-11-10

  • First Beta Version

Licensing

This project was built under the ISC licence.

1.0.1

8 months ago

0.0.0

9 months ago

1.0.0

9 months ago