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.
@threespot/modal
Advanced tools
A progressively enhanced modal window that supports multiple toggles, multiple close buttons, and works with pure CSS thanks to `:target` pseudo selector.
A progressively enhanced modal window that supports multiple toggles, multiple close buttons, and works with pure CSS thanks to :target
pseudo selector.
yarn add @threespot/modal
import Modal from "@threespot/modal";
const container = document.getElementById("modal");
new Modal(container, opts);
// If you have more than one modal on the page
const containers = document.querySelectorAll(".Modal");
// ES6
containers.forEach(container => new Modal(container));
// ES5
for (var i = 0, len = containers.length; i < len; i+=1) {
new Modal(containers[i]);
}
Styles needed
//------------------------------------------------------------------------
// Modal windows (required by modals.js)
//
// Content is shown by default and hidden once JS runs
//------------------------------------------------------------------------
.Modal {
$selector: &;
$open-speed: 250ms;
$close-speed: 500ms;
$z-index: 900;
$bg-default: #fff; // This can be whatever you want the modal color to be
background-color: rgba(#000, 0.5);// overlay color
bottom: 0;
left: 0;
margin: 0 !important; // reset u-richtext div styles
max-height: 0; // iOS fix
opacity: 0;
overflow: auto; // allows scrollig when content exceeds viewport height
-webkit-overflow-scrolling: touch; // iOS “momentum” scrolling
position: fixed;
right: 0;
top: 0;
transition: max-height 0s linear $close-speed,
visibility 0s linear $close-speed,
opacity $close-speed;
visibility: hidden; // hide from screen readers and keyboards until active
z-index: $z-index; // must be greater than overlay
// Styles will be applied when URL hash matches modal ID attribute
&:not([aria-hidden]):target,
&[aria-hidden="false"] {
max-height: 100vh; // can’t set to “none” because that can't be transitioned
opacity: 1;
transition: max-height 0s linear 0s, visibility 0s linear 0s, opacity $open-speed;
visibility: visible;
}
// Modal content wrapper
&-content {
@include fs-print-hide;
background-color: $bg-default;
opacity: 0;
position: relative;
transform: scale(0.95);
transition: all $close-speed fs-easing('easeOutCubic');
visibility: hidden;
width: 100%;
z-index: $z-index + 1;
#{$selector}:not([aria-hidden]):target &,
#{$selector}[aria-hidden="false"] & {
opacity: 1;
transform: scale(1);
transition: all $open-speed fs-easing('easeOutCubic');
visibility: visible;
}
}// end content
// Close button
&-close {
padding: fs-rem(15px);
position: fixed;
right: 0;
top: 0;
transition: all 150ms ease-in-out;
z-index: $z-index + 2;
}// end close
// if you want the modal window to take up the entire screen (optional)
&--fullWidth {
#{$selector}-content {
min-height: 100%;
}
}
}// end Modal
Minimum markup needed
<!-- you can have multiple toggle buttons -->
<a data-modal="foo">Open</a>
<!-- Div container -->
<!-- Modal must have an aria-label / aria-labelledby attribute -->
<!-- This modal window adds aria-hidden & role='dialog' out of the box -->
<div class="Modal" id="foo">
<!-- It doesn't matter where this is located -->
<!-- Codebase stores this by data-modal -->
<!-- We add role="button" to the close button automatically -->
<a class="Modal-close" href="#nav-modal-toggle" data-modal-close>Close</a>
<!-- codebase stores this too by class name-->
<div class="Modal-content">
</div>
</div>
Required Data Attributes for markup
data-modal-close
tells Modal what button(s) can close the modal window. This can be anywhere inside of the .Modal
data-modal="{YOUR_MODAL_ID_GOES_HERE}"
- toggle button(s) for the modal button must have this attribute with the .Modal
corresponding ID as its value. This allow us to toggle the .Modal
on and off.
new Modal(el, [opts])
// This is the Modal that wraps everything except for the toggle/open button(s).
const el = document.querySelector('.Modal');
// Opts Config (optional)
{
// {string} CSS transition speed to delay focus
// Default value: 100
transitionSpeed: "100",
// {string} Class(es) to apply on open modal
// Multiples classes are stored inside a string delimited by a space
// Default value: ''
activeClasses: "is-active is-privacy-modal",
// {string} Class of modal content wrapper
// default value: "Modal-content"
modalContentClass: "Modal-content",
// {function} Once Modal object is constructed, this function will be called
// default value: null
onReady: function() {
console.log('Success!')
}
}
This is free software and may be redistributed under the terms of the MIT license.
Threespot is an independent digital agency hell-bent on helping those, and only those, who are committed to helping others. Find out more at https://www.threespot.com.
FAQs
A progressively enhanced modal window that supports multiple toggles, multiple close buttons, and works with pure CSS thanks to `:target` pseudo selector.
We found that @threespot/modal demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 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.