Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
react-modal-component-hw
Advanced tools
A simple, modular and customizable modal window component for React applications, compatible with Tailwind CSS, allowing easy management of modal windows with styling and accessibility options
A simple, modular and customizable modal window component for React applications, compatible with Tailwind CSS, allowing easy management of modal windows with styling and accessibility options
To install the Modal component in your React project, use npm or yarn:
npm install react-modal-component-hw clsx lucide-react
or
yarn add react-modal-component-hw clsx lucide-react
The Modal component relies on certain external dependencies to function properly. Here are the minimum required versions of these libraries:
clsx
: Used to conditionally manage CSS classes. You can combine CSS or Tailwind classes via clsx
.
^2.1.1
npm install clsx@^2.1.1
Or
yarn add clsx@^2.1.1
lucide-react
: Used for SVG icons, including the close icon in the modal.
^0.446.0
npm install lucide-react@^0.446.0
Or
yarn add lucide-react@^0.446.0
clsx
package allows you to use Tailwind for class and style management if you wish.Make sure you have installed these dependencies for the component to function properly in your project.
This should cover the minimum requirements for clsx
, lucide-react
and other aspects related to the component's compatibility.
To use the Modal component and its sub-components, import it into your file and incorporate it into your JSX code:
import React, { useState } from 'react';
import { Modal, ModalContent, ModalHeader, ModalTitle, ModalDescription, ModalFooter } from 'react-modal-component-hw';
const App = () => {
const [isOpen, setIsOpen] = useState(false);
const toggleModal = () => {
setIsOpen(!isOpen);
};
return (
<div>
<button onClick={toggleModal}>Open Modal</button>
<Modal open={isOpen}>
<ModalContent onClose={toggleModal}>
<ModalHeader>
<ModalTitle>Title of Modal</ModalTitle>
</ModalHeader>
<ModalDescription>This is the content of the modal.</ModalDescription>
<ModalFooter>
<button onClick={toggleModal}>Close Modal</button>
</ModalFooter>
</ModalContent>
</Modal>
</div>
);
};
export default App;
The Modal component and its sub-components accept the following properties:
Property | Type | Required | Description |
---|---|---|---|
className | string | Optional | Custom CSS class(es) for the modal. |
open | boolean | Yes | Indicates if the modal is open or closed. |
children | ReactNode | Yes | Content to display inside the modal. |
ariaLabelledBy | string | Optional | ID of the element defining the modal title for the aria-labelledby attribute. |
ariaDescribedBy | string | Optional | ID of the element defining the modal description for the aria-describedby attribute. |
Property | Type | Required | Description |
---|---|---|---|
className | string | Optional | Custom CSS class(es) for the modal content. |
onClose | function | Yes | Callback function called to close the modal (used for the close button). |
size | number | Optional | Size of the close icon. Default: 25 . |
stroke | string | Optional | Color of the close icon. Default: '#000000' . |
ariaLabel | string | Optional | Label for the aria-label attribute of the close icon. |
Property | Type | Required | Description |
---|---|---|---|
className | string | Optional | Custom CSS class(es) for the modal header. |
children | ReactNode | Yes | Content to display inside the modal header. |
Property | Type | Required | Description |
---|---|---|---|
className | string | Optional | Custom CSS class(es) for the modal title. |
children | ReactNode | Yes | Title to display inside the modal. |
id | string | Optional | ID used for the aria-labelledby attribute to link the title to the modal. |
Property | Type | Required | Description |
---|---|---|---|
className | string | Optional | Custom CSS class(es) for the modal description. |
children | ReactNode | Yes | Description to display inside the modal. |
id | string | Optional | ID used for the aria-describedby attribute to link the description to the modal. |
Property | Type | Required | Description |
---|---|---|---|
className | string | Optional | Custom CSS class(es) for the modal footer. |
children | ReactNode | Yes | Content to display inside the modal footer. |
The Modal component includes several features to improve accessibility:
role="dialog"
attribute to identify the modal window as a dialogue, enhancing the experience for screen reader users.aria-modal="true"
attribute signals to assistive technologies that the background content is not accessible while the modal is open.aria-labelledby
and aria-describedby
attributes are used to provide contextual descriptions of the modal:
aria-labelledby
associates an element, such as a modal title, with the dialogue so that the title is announced.aria-describedby
associates a description with the dialogue, offering additional context to users.tabIndex="-1"
attribute to ensure the modal is focused when the user navigates via the keyboard.aria-label
attribute to describe its function to screen reader users.These best practices enable better interaction with the modal for users utilizing assistive technologies.
The Modal component allows you to add custom styles using the clsx
package, which allows you to easily combine Tailwind classes or your own CSS classes. You don't need to use the component's base classes, you can directly apply your own styles via the className properties of the different sub-components.
Here is an example of using the component with custom styles:
import { useState } from 'react';
import { Modal, ModalContent, ModalHeader, ModalTitle, ModalDescription, ModalFooter } from 'react-modal-component-hw';
import './styles/main.css';
const App = () => {
const [isOpen, setIsOpen] = useState(false);
const toggleModal = () => {
setIsOpen(!isOpen);
};
return (
<div>
<button className="btn" onClick={toggleModal}>
Open modal
</button>
<Modal className="custom-modal" open={isOpen}>
<ModalContent className="custom-modal-container" onClose={toggleModal} stroke="#dfdfdf" size={32}>
<ModalHeader className="custom-modal-header">
<img className="custom-modal-img" src="./hero.svg" alt="hero" />
<ModalTitle className="custom-modal-title">Title of Modal</ModalTitle>
<ModalDescription className="custom-modal-description">This is the content of the modal.</ModalDescription>
</ModalHeader>
<ModalFooter className="custom-modal-footer">
<button
className="custom-modal-button"
onClick={toggleModal}
>
Close Modal
</button>
</ModalFooter>
</ModalContent>
</Modal>
);
};
export default App;
This project is licensed under the MIT.
FAQs
A simple, modular and customizable modal window component for React applications, compatible with Tailwind CSS, allowing easy management of modal windows with styling and accessibility options
The npm package react-modal-component-hw receives a total of 1 weekly downloads. As such, react-modal-component-hw popularity was classified as not popular.
We found that react-modal-component-hw demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.