Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@diotoborg/quaerat-dicta
Advanced tools
[![style: styled-components](https://img.shields.io/badge/style-%F0%9F%92%85%20styled--components-orange.svg?colorB=daa357&colorA=db748e)](https://github.com/styled-components/styled-components) [![code style: prettier](https://img.shields.io/badge/code_s
For support for react <16.9, please use @diotoborg/quaerat-dicta@1.2.4.
For support for create-react-app <5.0.0, please import from
@diotoborg/quaerat-dicta/build/umd
.
Styled React Modal is built with styled-components. It uses the latest React 17.x features and exposes a familiar, easy to use API. It supports beforeOpen()
, afterOpen()
, and other lifecycle hooks so that animations can be handled easily. Unlike several other modal implementations in React, it does not pollute the DOM with excessive nodes.
npm i -s @diotoborg/quaerat-dicta # or use yarn
Add the <ModalProvider>
component near the top of your application's tree.
import React from 'react'
import { ModalProvider } from '@diotoborg/quaerat-dicta'
...
export default function App() {
return (
<ThemeProvider theme={theme}>
<ModalProvider>
<FancyModalButton />
</ModalProvider>
</ThemeProvider>
)
}
Use the <Modal>
component.
For instructions on how the make your modal accessible according to the WAI-ARIA spec, see this CodeSandbox.
import Modal from '@diotoborg/quaerat-dicta'
...
const StyledModal = Modal.styled`
width: 20rem;
height: 20rem;
display: flex;
align-items: center;
justify-content: center;
background-color: ${props => props.theme.colors.white};
`
function FancyModalButton() {
const [isOpen, setIsOpen] = useState(false)
function toggleModal(e) {
setIsOpen(!isOpen)
}
return (
<div>
<button onClick={toggleModal}>Click me</button>
<StyledModal
isOpen={isOpen}
onBackgroundClick={toggleModal}
onEscapeKeydown={toggleModal}>
<span>I am a modal!</span>
<button onClick={toggleModal}>Close me</button>
</StyledModal>
</div>
)
}
<ModalProvider>
Modal
(Default)
Modal.styled(styles)
<Modal>
<BaseModalBackground>
<ModalProvider>
Sets the root portal where <Modal>
s will be rendered.
Props
backgroundComponent
] (Component): A styled component to be used as the default modal background. If not provided, library defaults will be used.Example:
import { ModalProvider } from '@diotoborg/quaerat-dicta'
const SpecialModalBackground = styled.div`
display: flex;
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
z-index: 30;
opacity: ${props => props.opacity};
background-color: green;
`
export default function App() {
return (
<ThemeProvider theme={theme}>
<ModalProvider backgroundComponent={SpecialModalBackground}>
<FancyModalButton />
</ModalProvider>
</ThemeProvider>
)
}
Modal.styled(styles)
Factory method that accepts a tagged template literal and returns a <Modal>
component with styles included.
Arguments
styles
(Tagged Template Literal): styled-components compatible css styles.Example:
const StyledModal = Modal.styled`
width: 20rem;
height: 20rem;
display: flex;
align-items: center;
justify-content: center;
background-color: ${props => props.theme.colors.white};
`
<Modal>
Renders its children in a modal when open, nothing when not open.
Props
isOpen
(Boolean): A boolean that indicates whether the modal is to be open or closed.onBackgroundClick
] (Function): A function that is called when the modal background is clicked.onEscapeKeydown
] (Function): A function that is called when the escape key is pressed while the modal is open.backgroundProps
] (Object): A props object that is spread over the backgroundComponent
when included.allowScroll
] (Boolean): When true, scrolling in the document body is not disabled when the modal is open.beforeOpen
] (Function): A function that is called before the modal opens. If this function returns a promise, then the modal is opened after the promise is resolved.afterOpen
] (Function): A function that is called after the modal opens.beforeClose
] (Function): A function that is called before the modal closes. If this function returns a promise, then the modal is closed after the promise is resolved.afterClose
] (Function): A function that is called after the modal closes.Example:
import Modal from '@diotoborg/quaerat-dicta'
function FancyModalButton() {
const [isOpen, setIsOpen] = useState(false)
function toggleModal(e) {
setIsOpen(!isOpen)
}
return (
<div>
<button onClick={toggleModal}>Click me</button>
<Modal
isOpen={isOpen}
onBackgroundClick={toggleModal}
onEscapeKeydown={toggleModal}>
<span>I am a modal!</span>
<button onClick={toggleModal}>Close me</button>
</Modal>
</div>
)
}
<BaseModalBackground>
A convenience base component for making default background styles with <ModalProvider>
.
Example:
const SpecialModalBackground = styled(BaseModalBackground)`
background-color: green;
`
FAQs
[![style: styled-components](https://img.shields.io/badge/style-%F0%9F%92%85%20styled--components-orange.svg?colorB=daa357&colorA=db748e)](https://github.com/styled-components/styled-components) [![code style: prettier](https://img.shields.io/badge/code_s
We found that @diotoborg/quaerat-dicta 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.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.