
Security News
PEP 810 Proposes Explicit Lazy Imports for Python 3.15
An opt-in lazy import keyword aims to speed up Python startups, especially CLIs, without the ecosystem-wide risks that sank PEP 690.
@simpozio/popup
Advanced tools
React component for Popup. Based on react-modal
component
npm i @simpozio/popup
import React, {useState} from 'react';
import {Popup, PopupClose} from '@simpozio/popup';
const Component = () => {
const [isOpen, setOpen] = useState();
const handleOpen = () => setOpen(true);
const handleClose = () => setOpen(false);
return (
<>
<button
type="button"
onClick={handleOpen}>
Open Popup
</button>
<Popup isOpen={isOpen} closePopup={handleClose}>
Popup Content
<PopupClose onClick={closePopup} />
</Popup>
</>
);
};
import {Popup, PopupState PopupClose} from '@simpozio/popup';
const Component = () => {
return (
<PopupState>
(({isOpen, openPopup, closePopup}) => (
<>
<button
type="button"
onClick={openPopup}>
Open Popup
</button>
<Popup isOpen={isOpen} closePopup={closePopup}>
Popup Content
<PopupClose onClick={closePopup} />
</Popup>
</>
)}
</>
);
};
Default styling with styled components:
import styled from 'styled-components';
import {Popup, PopupClose} from '@simpozio/popup';
const StyledClose = styled(PopupClose)`
font-size: 0.6rem;
`;
const StyledPopup = styled(Popup)`
.popup__overlay {
top: 0.5rem;
right: 0.5rem;
left: auto;
bottom: auto;
width: 180px;
height: 60px;
background: none;
}
.popup__content {
top: 0;
left: 0;
right: 0;
bottom: 0;
color: #fff;
background-color: #000;
}
${StyledClose} {
top: 0;
right: 0;
color: #fff;
}
`;
const Component = () => {
return (
<PopupState>
{({isOpen, openPopup, closePopup}) => (
<>
<Button
type="button"
variant="outlined"
color="secondary"
onClick={openPopup}>
Open Popup
</Button>
<StyledPopup isOpen={isOpen} closePopup={closePopup}>
<StyledClose onClick={closePopup} />
<Wrapper>Popup Content</Wrapper>
</StyledPopup>
</>
)}
</PopupState>
)
}
You can style Popup
component via styles
attribute by passing styled-component's interpolated string:
import {css} from 'styled-components';
import {Popup, PopupClose} from '@simpozio/popup';
const customStyles = css(
({Overlay, Content, Close, theme}) => css`
${Overlay} {
background: none;
}
${Content} {
top: 0;
left: 0;
bottom: 0;
right: 0;
color: ${theme.COLOR.INVERT};
font-size: 2rem;
background-color: ${theme.BACKGROUND.INVERT};
}
${Close} {
color: ${theme.COLOR.INVERT};
}
`
);
const Component = () => {
return (
<PopupState>
{({isOpen, openPopup, closePopup}) => (
<>
<Button
type="button"
variant="outlined"
color="secondary"
onClick={openPopup}>
Open Popup
</Button>
<Popup
styles={customStyles}
isOpen={isOpen}
closePopup={closePopup}>
<PopupClose onClick={closePopup} />
<Wrapper>Popup Content</Wrapper>
</Popup>
</>
)}
</PopupState>
)
}
You can change default popup transition for open/close by styling .ReactModal__Overlay--after-open
and .ReactModal__Overlay--before-close
classes, or OverlayAfterOpen
and OverlayBeforeClose
styled props on Popup component.
Also you can change transition duration, by specifying closeDelay prop on Popup component.
Don't forget to override default transition styles (opacity and visibility):
import {css} from 'styled-components';
import {Popup, PopupClose} from '@simpozio/popup';
const customStyles = css(
({Overlay, OverlayAfterOpen, OverlayBeforeClose}) => css`
${Overlay} {
/* overriding default transition styles */
opacity: 1;
visibility: visible;
/* specifying new transition styles */
transform: translateY(-1000px);
transition: transform ease-in-out 1s;
}
${OverlayAfterOpen} {
/* specifying new transition styles */
transform: translateY(0);
}
${OverlayBeforeClose} {
/* overriding default transition styles */
opacity: 1;
visibility: visible;
/* specifying new transition styles */
transform: translateY(-1000px);
}
`
);
const Component = () => {
return (
<PopupState>
{({isOpen, openPopup, closePopup}) => (
<>
<Button
type="button"
variant="outlined"
color="secondary"
onClick={openPopup}>
Open Popup
</Button>
<Popup
styles={customStyles}
isOpen={isOpen}
closeDelay={1000}
closePopup={closePopup}>
<PopupClose onClick={closePopup} />
<Wrapper>Popup Content</Wrapper>
</Popup>
</>
)}
</PopupState>
)
}
isOpen: boolean
- boolean controlling popup stateonOpen: function
- onOpen callback called after popup is openedonClose: function
- onClose callback called after popup is closedclassName: string
- className string applied to portal elementlabel: string
- aria-label proparia: object
- object with ARIA attributes, such as: aria-label, aria-labelledby, aria-describedby etc. A complete list of ARIA attributes you can see in the ARIA specificationclosePopup: function
- closing handler function, for handling close with ESC button and overlay click.appElement: string | HTMLElement
- selector or HTML element of app root element. Prop for screenreaders, it needed for set aria-hidden for other page content, while modal is open.shouldCloseOnOverlayClick: boolean
- prop specify should popup close on overlay click or notshouldCloseOnEsc: boolean
- prop specify should popup close on ESC button pressed or notcloseDelay: number
- popup closing delay for transitionFAQs
React popup component
We found that @simpozio/popup demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 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
An opt-in lazy import keyword aims to speed up Python startups, especially CLIs, without the ecosystem-wide risks that sank PEP 690.
Security News
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.