Add open state

This commit is contained in:
Jeremy Thomas 2024-06-27 01:03:51 +01:00
parent 068b93a878
commit bb62f531e1
2 changed files with 45 additions and 1 deletions

View File

@ -138,6 +138,7 @@ const PAGE_IDS = {
}; };
export const CustomizerContext = createContext({ export const CustomizerContext = createContext({
isOpen: false,
cssvars: {}, cssvars: {},
currentTab: "", currentTab: "",
currentPage: "", currentPage: "",
@ -150,6 +151,7 @@ export const CustomizerContext = createContext({
function App() { function App() {
const styleRef = useRef(); const styleRef = useRef();
const initialContext = { const initialContext = {
isOpen: true,
cssvars: {}, cssvars: {},
currentTab: "Global Variables", currentTab: "Global Variables",
currentPage: "delete", currentPage: "delete",
@ -201,6 +203,17 @@ function App() {
context.changePage(pageId); context.changePage(pageId);
}; };
const handleOpening = (event) => {
event.preventDefault();
setContext((context) => {
return {
...context,
isOpen: !context.isOpen,
};
});
};
useEffect(() => { useEffect(() => {
const styles = { const styles = {
root: window.getComputedStyle(document.documentElement), root: window.getComputedStyle(document.documentElement),
@ -400,10 +413,21 @@ function App() {
"--bulma-tabs-link-active-color": "var(--bulma-primary)", "--bulma-tabs-link-active-color": "var(--bulma-primary)",
}; };
const appClass = classNames({
[cn.app]: true,
[cn.open]: context.isOpen,
});
const buttonClass = classNames({
[cn.button]: true,
"button is-primary": true,
});
return ( return (
<CustomizerContext.Provider value={context}> <CustomizerContext.Provider value={context}>
<style ref={styleRef} /> <style ref={styleRef} />
<div className={cn.app}>
<div className={appClass}>
<div className={cn.controls}> <div className={cn.controls}>
<div className="select" style={tabsStyle}> <div className="select" style={tabsStyle}>
<select onChange={handleTabChange} value={context.currentTab}> <select onChange={handleTabChange} value={context.currentTab}>
@ -437,6 +461,10 @@ function App() {
{PAGE_TO_COMPONENT[context.currentPage]} {PAGE_TO_COMPONENT[context.currentPage]}
</div> </div>
<button className={buttonClass} onClick={handleOpening}>
{context.isOpen ? "Close Customizer" : "Open Customizer"}
</button>
</CustomizerContext.Provider> </CustomizerContext.Provider>
); );
} }

View File

@ -3,6 +3,16 @@
--var-item-slider-width: 30rem; --var-item-slider-width: 30rem;
--var-item-padding: 1rem; --var-item-padding: 1rem;
--var-item-gap: 1rem; --var-item-gap: 1rem;
transform-origin: bottom right;
transition-duration: 300ms;
transition-property: opacity, transform;
transform: scale(0.9);
opacity: 0;
}
.open {
opacity: 1;
transform: none;
} }
.controls { .controls {
@ -11,3 +21,9 @@
gap: 0.5rem; gap: 0.5rem;
padding: 1.5rem; padding: 1.5rem;
} }
.button {
bottom: 1rem;
right: 1rem;
position: fixed;
}