0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-30 06:42:45 +00:00

Add View Mode Options

Adds a new AnchoredBox component that is functionally a clone of the "saving error" notifications, but drops a lot of the JS in favor of the new (chrome-only!) CSS Anchor Positioning API.  In subsequent commits, either alternate styling or a polyfill will be added non-supported browsers.

The box contains a few inputs that modify the CSS applied to `.pages`, most critically a "start on right" toggle for the Facing Pages mode.
This commit is contained in:
Gazook89
2024-10-06 21:51:44 -05:00
parent 9fce94af63
commit d6d6cc1e29
5 changed files with 148 additions and 5 deletions

View File

@@ -0,0 +1,55 @@
require('./anchoredBox.less');
import React, { useState, useRef, useEffect } from 'react';
const AnchoredBox = ({ anchorPoint = 'center', className, children, ...props })=>{
const [visible, setVisible] = useState(false);
const triggerRef = useRef(null);
const boxRef = useRef(null);
useEffect(()=>{
const handleClickOutside = (evt)=>{
if(boxRef.current &&
!boxRef.current.contains(evt.target) &&
triggerRef.current &&
!triggerRef.current.contains(evt.target)){
setVisible(false);
}
};
window.addEventListener('click', handleClickOutside);
const iframe = document.querySelector('iframe');
if(iframe) {
iframe.addEventListener('load', ()=>{
const iframeDoc = iframe.contentWindow.document;
if(iframeDoc) {
iframeDoc.addEventListener('click', handleClickOutside);
}
});
}
return ()=>{
window.removeEventListener('click', handleClickOutside);
if(iframe?.contentWindow?.document) {
iframe.contentWindow.document.removeEventListener('click', handleClickOutside);
}
};
}, []); // Empty dependency array to run effect on mount only
const handleClick = ()=>{
setVisible(!visible);
};
return (
<>
<button className={`${className} anchored-trigger${visible ? ' active' : ''}`} onClick={handleClick} ref={triggerRef}>
<i className='fas fa-gear' />
</button>
<div className={`anchored-box${visible ? ' active' : ''}`} ref={boxRef}>
<h1>{props.title}</h1>
{children}
</div>
</>
);
};
export default AnchoredBox;

View File

@@ -0,0 +1,57 @@
.anchored-trigger {
anchor-name: --view-settings;
&.active {
background-color: #444444;
}
}
.anchored-box {
position-anchor: --view-settings;
position:absolute;
inset-block-start: anchor(bottom);
justify-self: anchor-center;
visibility: hidden;
&.active {
visibility: visible;
}
padding : 15px;
color : white;
background-color : #555555;
border-radius : 5px;
font-size : .8em;
margin-top : 10px;
h1 {
border-bottom: 1px solid currentColor;
margin-bottom: 0.5em;
padding-bottom: 0.3em;
}
h2 {
color: lightgray;
border-bottom: 1px solid currentColor;
margin: 1em 0 0.5em 0;
padding-bottom: 0.3em;
}
label {
display: flex;
align-items: center;
justify-content: space-between;
gap: 6px;
}
&:before {
content: "";
width: 0px;
height: 0px;
position: absolute;
border: 10px solid transparent;
border-bottom: 10px solid #555555;
left: 50%;
transform: translateX(-50%);
top: -20px;
pointer-events: none;
}
}