Migrating new components
All checks were successful
Deploy Docs to Synology / deploy (push) Successful in 3s
All checks were successful
Deploy Docs to Synology / deploy (push) Successful in 3s
This commit is contained in:
32
components/Dropdown.js
Normal file
32
components/Dropdown.js
Normal file
@@ -0,0 +1,32 @@
|
||||
// components/Dropdown.js
|
||||
import { Tag } from "sigpro";
|
||||
|
||||
let currentOpen = null;
|
||||
|
||||
if (typeof window !== 'undefined' && !window.__dropdownHandlerRegistered) {
|
||||
window.addEventListener('click', (e) => {
|
||||
if (currentOpen && !currentOpen.contains(e.target)) {
|
||||
currentOpen.open = false;
|
||||
currentOpen = null;
|
||||
}
|
||||
});
|
||||
window.__dropdownHandlerRegistered = true;
|
||||
}
|
||||
|
||||
export const Dropdown = (props) => {
|
||||
const { class: className, children, ...rest } = props;
|
||||
|
||||
return Tag("details", {
|
||||
...rest,
|
||||
class: `dropdown ${className || ''}`.trim(),
|
||||
onclick: (e) => {
|
||||
const details = e.currentTarget;
|
||||
if (currentOpen && currentOpen !== details) {
|
||||
currentOpen.open = false;
|
||||
}
|
||||
setTimeout(() => {
|
||||
currentOpen = details.open ? details : null;
|
||||
}, 0);
|
||||
}
|
||||
}, children);
|
||||
};
|
||||
Reference in New Issue
Block a user