-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split color pickers into single and multiple
The single color picker binds to the user input unlike the multiple one.
- Loading branch information
Showing
13 changed files
with
125 additions
and
62 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { Resettable } from "../../structures/resettable/Resettable"; | ||
import { validateColor } from "../../utils/validators"; | ||
|
||
interface Props { | ||
/** | ||
* The title of the input. | ||
*/ | ||
title: string; | ||
|
||
/** | ||
* The description of the input. | ||
*/ | ||
description?: string; | ||
|
||
/** | ||
* The configuration that the input is responsible for. | ||
*/ | ||
resettable: Resettable<string | undefined>; | ||
} | ||
|
||
export default function SingleColorEditor(props: Props) { | ||
const { title, description, resettable } = props; | ||
|
||
return ( | ||
<div className="json-item-editor"> | ||
<div className="json-item-editor-title">{title}</div> | ||
{description ? ( | ||
<div className="json-item-editor-description"> | ||
{description} | ||
</div> | ||
) : null} | ||
|
||
<div className="json-item-editor-flex-container"> | ||
<input | ||
type="color" | ||
// The default color of a color input is black. | ||
// (ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/color#providing_a_default_color) | ||
value={ | ||
resettable.value && validateColor(resettable.value) | ||
? resettable.value | ||
: "#000000" | ||
} | ||
onChange={(event) => { | ||
resettable.setValue( | ||
event.target.value.toUpperCase() || undefined | ||
); | ||
}} | ||
/> | ||
|
||
<input | ||
className="json-item-editor-input" | ||
type="text" | ||
value={resettable.value ?? ""} | ||
maxLength={7} | ||
onChange={(event) => { | ||
const value = event.target.value; | ||
|
||
if (value) { | ||
resettable.setValue( | ||
validateColor(value) | ||
? value.toUpperCase() | ||
: value | ||
); | ||
} else { | ||
resettable.reset(); | ||
} | ||
}} | ||
/> | ||
|
||
<input | ||
className="json-item-editor-input" | ||
type="reset" | ||
onClick={() => { | ||
resettable.reset(); | ||
}} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/components/groups/skin/Color/MenuItemDefaultTextColor.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/components/groups/skin/Color/MenuItemSelectedTextColor.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/components/groups/skin/Color/MenuItemVersionsDefaultColor.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/components/groups/skin/Color/MenuItemVersionsSelectedColor.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,16 @@ | ||
import { useContext, useState } from "react"; | ||
import { useContext } from "react"; | ||
import { ComboColorsContext } from "../../../../hooks/ComboColor/ComboColorsContext"; | ||
import ColorEditor from "../../../editors/ColorEditor"; | ||
import MultipleColorEditor from "../../../editors/MultipleColorEditor"; | ||
|
||
export default function ColorList() { | ||
const ctx = useContext(ComboColorsContext); | ||
|
||
// Introduce additional hooks to convert the value from an array. | ||
const defaultValue = ctx.defaultValue[0]; | ||
const [value, setValue] = useState(defaultValue); | ||
|
||
const modifyValue = (value = defaultValue) => { | ||
setValue(value); | ||
|
||
ctx.setValue(value.split(",").map((v) => v.trim())); | ||
}; | ||
|
||
const resetValue = () => { | ||
setValue(defaultValue); | ||
|
||
ctx.reset(); | ||
}; | ||
|
||
return ( | ||
<ColorEditor | ||
<MultipleColorEditor | ||
title="Combo Colors" | ||
description="The color order will determine the color appearance order in-game." | ||
inputLabel="Colors" | ||
acceptMultipleColors={true} | ||
resettable={{ | ||
defaultValue, | ||
value, | ||
reset: resetValue, | ||
isDefault: ctx.isDefault, | ||
setValue: modifyValue, | ||
saveToJSON: (json) => { | ||
ctx.saveToJSON(json); | ||
}, | ||
}} | ||
resettable={ctx} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import { useContext } from "react"; | ||
import { SliderBodyColorContext } from "../../../../hooks/Slider/SliderBodyColorContext"; | ||
import ColorEditor from "../../../editors/ColorEditor"; | ||
import SingleColorEditor from "../../../editors/SingleColorEditor"; | ||
|
||
export default function SliderBodyColor() { | ||
const ctx = useContext(SliderBodyColorContext); | ||
|
||
return <ColorEditor title="Color" resettable={ctx} />; | ||
return <SingleColorEditor title="Color" resettable={ctx} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import { useContext } from "react"; | ||
import { SliderBorderColorContext } from "../../../../hooks/Slider/SliderBorderColorContext"; | ||
import ColorEditor from "../../../editors/ColorEditor"; | ||
import SingleColorEditor from "../../../editors/SingleColorEditor"; | ||
|
||
export default function SliderBorderColor() { | ||
const ctx = useContext(SliderBorderColorContext); | ||
|
||
return <ColorEditor title="Color" resettable={ctx} />; | ||
return <SingleColorEditor title="Color" resettable={ctx} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import { useContext } from "react"; | ||
import { SliderHintColorContext } from "../../../../hooks/Slider/SliderHintColorContext"; | ||
import ColorEditor from "../../../editors/ColorEditor"; | ||
import SingleColorEditor from "../../../editors/SingleColorEditor"; | ||
|
||
export default function SliderHintColor() { | ||
const ctx = useContext(SliderHintColorContext); | ||
|
||
return <ColorEditor title="Color" resettable={ctx} />; | ||
return <SingleColorEditor title="Color" resettable={ctx} />; | ||
} |