bunch of things that should have been commits

This commit is contained in:
Víctor Losada Hernández committed 2026-10-10 20:21:38 +02:00
1 parent 7b1edb889c
commit 428b018835
10 files changed
+73 -168

No files matched your search

+7 -46
View File
@@ -25,7 +25,7 @@ const Nav = {
</div>;
},
item : ({ icon, kbd,href, newTab, onClick, color, children, className, disabled, ...props })=>{
item : ({ icon, kbd,href, newTab, onClick, color, children, className, disabled, noDismiss, ...props })=>{
const classes = cx('navItem', color, className);
if(disabled) {
return <button className={classes} disabled>{children}{icon && <i className={icon}></i>}</button>
@@ -36,57 +36,18 @@ const Nav = {
{icon && <i className={icon}></i>}
</a>;
} else {
return <button {...props} className={classes} onClick={onClick} >
return <button {...props} no-dismiss={noDismiss ? 'true' : 'false'} className={classes} onClick={onClick} >
{children}
{icon && <i className={icon}></i>}
{kbd && <kbd>{kbd}</kbd>}
</button>;
}
},
dropdown : function dropdown(props) {
props = Object.assign({}, props, {
trigger : 'hover click'
});
const myRef = useRef(null);
const [showDropdown, setShowDropdown] = useState(false);
useEffect(()=>{
document.addEventListener('click', handleClickOutside);
return ()=>{
document.removeEventListener('click', handleClickOutside);
};
}, []);
function handleClickOutside(e) {
// Close dropdown when clicked outside
if(!myRef.current?.contains(e.target)) {
handleDropdown(false);
}
}
function handleDropdown(show) {
setShowDropdown(show ?? !showDropdown);
}
const dropdownChildren = React.Children.map(props.children, (child, i)=>{
if(i < 1) return;
return child;
});
return (
<div className={`navDropdownContainer ${props.className ?? ''}`}
ref={myRef}
onMouseEnter = { props.trigger.includes('hover') ? ()=>handleDropdown(true) : undefined }
onMouseLeave = { props.trigger.includes('hover') ? ()=>handleDropdown(false) : undefined }
onClick = { props.trigger.includes('click') ? ()=>handleDropdown(true) : undefined }
>
{props.children[0] || props.children /*children is not an array when only one child*/}
{showDropdown && <div className='navDropdown'>{dropdownChildren}</div>}
</div>
);
}
header: ({span, className, children, ...props})=>{
return <li className={cx([`navItem header`, className])} no-dismiss='true'>
{children}
</li>;
},
};