|
1 | 1 | import React, { useEffect, useState, MouseEvent, PropsWithChildren, useRef } from 'react' |
2 | | - |
| 2 | +import { IconContext } from 'react-icons' |
| 3 | +import { IoCloseCircle, IoCloseCircleOutline } from 'react-icons/io5' |
3 | 4 | import { ChromePicker } from 'react-color' |
4 | 5 | import { AppContextProvider, useAppContext } from './app-context' |
5 | 6 | import { GameRenderer } from './playback/GameRenderer' |
@@ -95,10 +96,9 @@ export function getDefaultConfig(): ClientConfig { |
95 | 96 | const ColorPicker = (props: { displayName: string; colorName: Colors }) => { |
96 | 97 | const context = useAppContext() |
97 | 98 | const value = context.state.config.colors[props.colorName] |
98 | | - //const wrapperRef = React.createRef() |
99 | 99 | const ref = useRef<HTMLDivElement>(null) |
100 | 100 | const buttonRef = useRef<HTMLButtonElement>(null) |
101 | | - //this.handleClickOutside = this.handleClickOutside.bind(this); |
| 101 | + const [hoveredClose, setHoveredClose] = useState(false) |
102 | 102 |
|
103 | 103 | const [displayColorPicker, setDisplayColorPicker] = useState(false) |
104 | 104 |
|
@@ -140,19 +140,43 @@ const ColorPicker = (props: { displayName: string; colorName: Colors }) => { |
140 | 140 | setTimeout(() => GameRenderer.render(), 10) |
141 | 141 | } |
142 | 142 |
|
| 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 | + |
143 | 150 | return ( |
144 | 151 | <> |
145 | 152 | <div className={'ml-2 mb-2 text-xs flex flex-start justify-start items-center'}> |
146 | 153 | {/*Background:*/} |
147 | 154 | {props.displayName}: |
148 | 155 | <button |
149 | 156 | 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'} |
151 | 158 | style={{ backgroundColor: value, border: '2px solid white' }} |
152 | 159 | onClick={handleClick} |
153 | 160 | ></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} />} |
154 | 179 | </div> |
155 | | - <div ref={ref}>{displayColorPicker && <ChromePicker color={value} onChange={onChange} />}</div> |
156 | 180 | </> |
157 | 181 | ) |
158 | 182 | } |
|
0 commit comments