Skip to content

Commit 37ee51c

Browse files
committed
reset button
1 parent 1ccad75 commit 37ee51c

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

client/src/client-config.tsx

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { useEffect, useState, MouseEvent, PropsWithChildren, useRef } from 'react'
2-
2+
import { IconContext } from 'react-icons'
3+
import { IoCloseCircle, IoCloseCircleOutline } from 'react-icons/io5'
34
import { ChromePicker } from 'react-color'
45
import { AppContextProvider, useAppContext } from './app-context'
56
import { GameRenderer } from './playback/GameRenderer'
@@ -95,10 +96,9 @@ export function getDefaultConfig(): ClientConfig {
9596
const ColorPicker = (props: { displayName: string; colorName: Colors }) => {
9697
const context = useAppContext()
9798
const value = context.state.config.colors[props.colorName]
98-
//const wrapperRef = React.createRef()
9999
const ref = useRef<HTMLDivElement>(null)
100100
const buttonRef = useRef<HTMLButtonElement>(null)
101-
//this.handleClickOutside = this.handleClickOutside.bind(this);
101+
const [hoveredClose, setHoveredClose] = useState(false)
102102

103103
const [displayColorPicker, setDisplayColorPicker] = useState(false)
104104

@@ -140,19 +140,43 @@ const ColorPicker = (props: { displayName: string; colorName: Colors }) => {
140140
setTimeout(() => GameRenderer.render(), 10)
141141
}
142142

143+
const resetColor = () => {
144+
console.log(DEFAULT_GLOBAL_COLORS)
145+
console.log(props.colorName as Colors)
146+
console.log(DEFAULT_GLOBAL_COLORS[props.colorName as Colors])
147+
onChange({ hex: DEFAULT_GLOBAL_COLORS[props.colorName as Colors] })
148+
}
149+
143150
return (
144151
<>
145152
<div className={'ml-2 mb-2 text-xs flex flex-start justify-start items-center'}>
146153
{/*Background:*/}
147154
{props.displayName}:
148155
<button
149156
ref={buttonRef}
150-
className={'text-xs ml-2 px-4 py-3 flex flex-row hover:bg-cyanDark rounded-md text-white'}
157+
className={'text-xs ml-2 px-4 py-3 mr-2 flex flex-row hover:bg-cyanDark rounded-md text-white'}
151158
style={{ backgroundColor: value, border: '2px solid white' }}
152159
onClick={handleClick}
153160
></button>
161+
<div
162+
className="rounded-full overflow-clip"
163+
onClick={() => resetColor()}
164+
onMouseEnter={() => setHoveredClose(true)}
165+
onMouseLeave={() => setHoveredClose(false)}
166+
>
167+
<IconContext.Provider
168+
value={{
169+
color: 'white',
170+
className: 'w-5 h-5'
171+
}}
172+
>
173+
{hoveredClose ? <IoCloseCircle /> : <IoCloseCircleOutline />}
174+
</IconContext.Provider>
175+
</div>
176+
</div>
177+
<div ref={ref} className={'width: w-min'}>
178+
{displayColorPicker && <ChromePicker color={value} onChange={onChange} />}
154179
</div>
155-
<div ref={ref}>{displayColorPicker && <ChromePicker color={value} onChange={onChange} />}</div>
156180
</>
157181
)
158182
}

0 commit comments

Comments
 (0)