Spaces:
Sleeping
Sleeping
hide controls
Browse files- src/components/ui-controls.tsx +54 -38
src/components/ui-controls.tsx
CHANGED
|
@@ -1,12 +1,14 @@
|
|
| 1 |
'use client';
|
| 2 |
|
| 3 |
import { Button, ButtonGroup, Card, CardBody, Slider } from '@heroui/react';
|
|
|
|
| 4 |
|
| 5 |
import { useControlContext } from '@/contexts/control-context';
|
| 6 |
|
| 7 |
import { Actions } from './consts';
|
| 8 |
|
| 9 |
export const UIControls = () => {
|
|
|
|
| 10 |
const { rubiksCubeRef, setBackground, cubeRoughness, setCubeRoughness, cubeSpeed, setCubeSpeed } =
|
| 11 |
useControlContext();
|
| 12 |
|
|
@@ -30,46 +32,60 @@ export const UIControls = () => {
|
|
| 30 |
return (
|
| 31 |
<div className="z-10 pointer-events-none">
|
| 32 |
<Card className="max-w-sm bg-white/30 border border-white/80 backdrop-blur-xl pointer-events-auto">
|
| 33 |
-
<CardBody className="flex flex-col
|
| 34 |
-
<div className="
|
| 35 |
-
|
| 36 |
-
<
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
<Button onPress={() => setBackground('sunset')}>Sunset</Button>
|
| 40 |
-
<Button onPress={() => setBackground('dawn')}>Dawn</Button>
|
| 41 |
-
<Button onPress={() => setBackground('forest')}>Forest</Button>
|
| 42 |
-
</ButtonGroup>
|
| 43 |
-
</div>
|
| 44 |
-
<Slider
|
| 45 |
-
size="sm"
|
| 46 |
-
label="Cube Roughness"
|
| 47 |
-
value={cubeRoughness}
|
| 48 |
-
onChange={(value) => setCubeRoughness(value as number)}
|
| 49 |
-
minValue={0.2}
|
| 50 |
-
maxValue={1}
|
| 51 |
-
step={0.01}
|
| 52 |
-
/>
|
| 53 |
-
<Slider
|
| 54 |
-
size="sm"
|
| 55 |
-
label="Cube Speed"
|
| 56 |
-
value={cubeSpeed}
|
| 57 |
-
onChange={(value) => setCubeSpeed(value as number)}
|
| 58 |
-
minValue={1}
|
| 59 |
-
maxValue={10}
|
| 60 |
-
step={1}
|
| 61 |
-
/>
|
| 62 |
</div>
|
| 63 |
-
<div
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
</div>
|
| 71 |
-
<div className="
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
</div>
|
| 74 |
</div>
|
| 75 |
</CardBody>
|
|
|
|
| 1 |
'use client';
|
| 2 |
|
| 3 |
import { Button, ButtonGroup, Card, CardBody, Slider } from '@heroui/react';
|
| 4 |
+
import { useState } from 'react';
|
| 5 |
|
| 6 |
import { useControlContext } from '@/contexts/control-context';
|
| 7 |
|
| 8 |
import { Actions } from './consts';
|
| 9 |
|
| 10 |
export const UIControls = () => {
|
| 11 |
+
const [isControlsOpen, setIsControlsOpen] = useState(true);
|
| 12 |
const { rubiksCubeRef, setBackground, cubeRoughness, setCubeRoughness, cubeSpeed, setCubeSpeed } =
|
| 13 |
useControlContext();
|
| 14 |
|
|
|
|
| 32 |
return (
|
| 33 |
<div className="z-10 pointer-events-none">
|
| 34 |
<Card className="max-w-sm bg-white/30 border border-white/80 backdrop-blur-xl pointer-events-auto">
|
| 35 |
+
<CardBody className="flex flex-col">
|
| 36 |
+
<div className="flex justify-between items-center">
|
| 37 |
+
<div className="text-2xl font-bold">Controls</div>
|
| 38 |
+
<Button variant="light" size="sm" onPress={() => setIsControlsOpen(!isControlsOpen)}>
|
| 39 |
+
{isControlsOpen ? 'Hide' : 'Show'}
|
| 40 |
+
</Button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
</div>
|
| 42 |
+
<div
|
| 43 |
+
className={`
|
| 44 |
+
flex flex-col gap-6 transition-all duration-500 ease-in-out
|
| 45 |
+
${isControlsOpen ? 'max-h-[1000px] opacity-100' : 'max-h-0 opacity-0 pointer-events-none'}
|
| 46 |
+
overflow-hidden
|
| 47 |
+
`}
|
| 48 |
+
style={{ willChange: 'max-height, opacity' }}
|
| 49 |
+
>
|
| 50 |
+
<div className="flex flex-col gap-2 mt-6">
|
| 51 |
+
<div className="flex items-center justify-between">
|
| 52 |
+
<div className="text-sm">Background</div>
|
| 53 |
+
<ButtonGroup size="sm">
|
| 54 |
+
<Button onPress={() => setBackground('sunset')}>Sunset</Button>
|
| 55 |
+
<Button onPress={() => setBackground('dawn')}>Dawn</Button>
|
| 56 |
+
<Button onPress={() => setBackground('forest')}>Forest</Button>
|
| 57 |
+
</ButtonGroup>
|
| 58 |
+
</div>
|
| 59 |
+
<Slider
|
| 60 |
+
size="sm"
|
| 61 |
+
label="Cube Roughness"
|
| 62 |
+
value={cubeRoughness}
|
| 63 |
+
onChange={(value) => setCubeRoughness(value as number)}
|
| 64 |
+
minValue={0.2}
|
| 65 |
+
maxValue={1}
|
| 66 |
+
step={0.01}
|
| 67 |
+
/>
|
| 68 |
+
<Slider
|
| 69 |
+
size="sm"
|
| 70 |
+
label="Cube Speed"
|
| 71 |
+
value={cubeSpeed}
|
| 72 |
+
onChange={(value) => setCubeSpeed(value as number)}
|
| 73 |
+
minValue={1}
|
| 74 |
+
maxValue={10}
|
| 75 |
+
step={1}
|
| 76 |
+
/>
|
| 77 |
</div>
|
| 78 |
+
<div className="flex flex-col gap-2">
|
| 79 |
+
<div className="flex gap-2">
|
| 80 |
+
<Button onPress={scramble}>Scramble</Button>
|
| 81 |
+
<Button onPress={reset}>Reset</Button>
|
| 82 |
+
<Button className="ms-auto" color="success" onPress={solve}>
|
| 83 |
+
Solve
|
| 84 |
+
</Button>
|
| 85 |
+
</div>
|
| 86 |
+
<div className="text-sm italic font-bold underline text-primary cursor-pointer" onClick={train}>
|
| 87 |
+
Train my own model!
|
| 88 |
+
</div>
|
| 89 |
</div>
|
| 90 |
</div>
|
| 91 |
</CardBody>
|