Tweak customizer styles and hide on non-jscad screens
This commit is contained in:
@@ -1,10 +1,12 @@
|
|||||||
import { useRender } from 'src/components/IdeWrapper/useRender'
|
import { useRender } from 'src/components/IdeWrapper/useRender'
|
||||||
import { useIdeContext } from 'src/helpers/hooks/useIdeContext'
|
import { useIdeContext } from 'src/helpers/hooks/useIdeContext'
|
||||||
import { genParams } from 'src/helpers/cadPackages/jsCad/jscadParams'
|
import { genParams } from 'src/helpers/cadPackages/jsCad/jscadParams'
|
||||||
|
import { Switch } from '@headlessui/react'
|
||||||
|
import Svg from 'src/components/Svg/Svg'
|
||||||
|
|
||||||
const Customizer = () => {
|
const Customizer = () => {
|
||||||
const [open, setOpen] = React.useState(true)
|
const [open, setOpen] = React.useState(false)
|
||||||
const [checked, setChecked] = React.useState(false)
|
const [shouldLiveUpdate, setShouldLiveUpdate] = React.useState(false)
|
||||||
const ref = React.useRef()
|
const ref = React.useRef()
|
||||||
const jsCadCustomizerElement = ref.current
|
const jsCadCustomizerElement = ref.current
|
||||||
const { state, thunkDispatch } = useIdeContext()
|
const { state, thunkDispatch } = useIdeContext()
|
||||||
@@ -20,14 +22,20 @@ const Customizer = () => {
|
|||||||
currentParameters || {},
|
currentParameters || {},
|
||||||
(values, source) => {
|
(values, source) => {
|
||||||
thunkDispatch({ type: 'setCurrentCustomizerParams', payload: values })
|
thunkDispatch({ type: 'setCurrentCustomizerParams', payload: values })
|
||||||
if (checked) {
|
if (shouldLiveUpdate) {
|
||||||
handleRender()
|
handleRender()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[]
|
[]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}, [jsCadCustomizerElement, customizerParams, currentParameters, checked])
|
}, [
|
||||||
|
jsCadCustomizerElement,
|
||||||
|
customizerParams,
|
||||||
|
currentParameters,
|
||||||
|
shouldLiveUpdate,
|
||||||
|
])
|
||||||
|
if (!state.customizerParams) return null
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={`absolute inset-x-0 bottom-0 bg-ch-gray-600 bg-opacity-60 text-ch-gray-300 text-lg font-fira-sans ${
|
className={`absolute inset-x-0 bottom-0 bg-ch-gray-600 bg-opacity-60 text-ch-gray-300 text-lg font-fira-sans ${
|
||||||
@@ -37,28 +45,46 @@ const Customizer = () => {
|
|||||||
<div className="flex justify-between px-6 py-2 items-center">
|
<div className="flex justify-between px-6 py-2 items-center">
|
||||||
<div className="flex gap-6 items-center">
|
<div className="flex gap-6 items-center">
|
||||||
<button className="px-2" onClick={() => setOpen(!open)}>
|
<button className="px-2" onClick={() => setOpen(!open)}>
|
||||||
{open ? '⬇' : '⬆'}
|
<Svg
|
||||||
|
name="chevron-down"
|
||||||
|
className={`h-8 w-8 ${!open && 'transform rotate-180'}`}
|
||||||
|
/>
|
||||||
</button>
|
</button>
|
||||||
<div>Parameters</div>
|
<div>Parameters</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center">
|
{open && (
|
||||||
<input
|
<>
|
||||||
className="mr-6"
|
<div className="flex items-center">
|
||||||
type="checkbox"
|
<div className="font-fira-sans text-sm mr-4">Auto Update</div>
|
||||||
checked={checked}
|
<Switch
|
||||||
onChange={() => {
|
checked={shouldLiveUpdate}
|
||||||
const newValue = !checked
|
onChange={(newValue) => {
|
||||||
if (newValue) handleRender()
|
setShouldLiveUpdate
|
||||||
setChecked(newValue)
|
if (newValue) handleRender()
|
||||||
}}
|
setShouldLiveUpdate(newValue)
|
||||||
/>
|
}}
|
||||||
<button
|
className={`${
|
||||||
className="px-4 py-1 rounded bg-ch-gray-300 text-ch-gray-800"
|
shouldLiveUpdate ? 'bg-ch-purple-600' : 'bg-ch-gray-300'
|
||||||
onClick={handleRender}
|
} relative inline-flex items-center h-6 rounded-full w-11 mr-6`}
|
||||||
>
|
>
|
||||||
Update
|
<span
|
||||||
</button>
|
className={`${
|
||||||
</div>
|
shouldLiveUpdate ? 'translate-x-6' : 'translate-x-1'
|
||||||
|
} inline-block w-4 h-4 transform bg-white rounded-full`}
|
||||||
|
/>
|
||||||
|
</Switch>
|
||||||
|
<button
|
||||||
|
className={`px-4 py-1 rounded bg-ch-gray-300 text-ch-gray-800 ${
|
||||||
|
shouldLiveUpdate && 'bg-opacity-30 cursor-default'
|
||||||
|
}`}
|
||||||
|
onClick={handleRender}
|
||||||
|
disabled={shouldLiveUpdate}
|
||||||
|
>
|
||||||
|
Update
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className={`${open ? 'h-full' : 'h-0'} overflow-y-auto px-12`}>
|
<div className={`${open ? 'h-full' : 'h-0'} overflow-y-auto px-12`}>
|
||||||
<div
|
<div
|
||||||
|
|||||||
Reference in New Issue
Block a user