This repository contains a simple React component that can be used to render a modal.
npm install hrnet-react-modal-101
or
yarn add hrnet-react-modal-101
import { Modal } from "hrnet-react-modal-101"
You can then render the Modal
component like any other React component in JSX.
import React, { useState } from 'react';
import { Modal } from 'hrnet-react-modal-101';
function App() {
const [isOpen, setIsOpen] = useState(false);
const openModal = () => {
setIsOpen(true);
};
const closeModal = () => {
setIsOpen(false);
};
return (
<div>
<button onClick={openModal}>Open Modal</button>
<Modal isOpen={isOpen} onClose={closeModal}>
<h2>Modal Content</h2>
<p>This is the content of the modal.</p>
</Modal>
</div>
);
}
export default App;
Prop | Type | Description |
---|---|---|
isOpen |
boolean |
Determines if the modal is open or closed |
onClose |
function |
Function used to close the modal |
modalCustomStyle |
Object |
Custom styles for the modal |
children |
React.ReactNode |
Content to be displayed within the modal |
The modalCustomStyle
prop allows you to apply custom styles to the modal. You can pass an object with CSS properties to this prop to achieve the desired look and feel. Here's an example:
import React, { useState } from 'react';
import { Modal } from 'hrnet-react-modal-101';
function App() {
const [isOpen, setIsOpen] = useState(false);
const openModal = () => {
setIsOpen(true);
};
const closeModal = () => {
setIsOpen(false);
};
const customModalStyle = {
backgroundColor: 'lightblue',
border: '2px solid blue',
borderRadius: '10px',
padding: '20px'
};
return (
<div>
<button onClick={openModal}>Open Modal</button>
<Modal isOpen={isOpen} onClose={closeModal} modalCustomStyle={customModalStyle}>
<h2>Custom Styled Modal</h2>
<p>This modal has a custom style applied.</p>
</Modal>
</div>
);
}
export default App;
In this example, we're passing a customModalStyle object to the modalCustomStyle
prop. This prop allows you to provide custom styles for the modal according to your needs.
The HRnet React Modal is available as an npm package. You can find it here.
This project is licensed under the ISC License.