Render 🚧 if input has an invalid value

This commit is contained in:
Aditya Thakral 2021-07-27 07:45:36 -04:00
parent 9db930d9e2
commit 18ed931f4c
1 changed files with 12 additions and 1 deletions

View File

@ -29,13 +29,22 @@ export default function Themer() {
</div>
<div className={styles.palette}>
{Object.entries(palette).map(([key, value]) => {
const color =
value.length === 4 && value.startsWith("#")
? `#${value[1].repeat(2)}${value[2].repeat(2)}${value[3].repeat(
2
)}`
: value;
const isValidColor = color.startsWith("#") && color.length === 7;
return (
<div key={key}>
<Input
id={`color-${key}`}
type="color"
className={styles.colorSelector}
value={value}
value={color}
onChange={(event) =>
context?.setTheme({ [key]: event.target.value })
}
@ -50,11 +59,13 @@ export default function Themer() {
</Button>
<code className={styles.colorName}>
<label htmlFor={`color-${key}`}>
{!isValidColor && "🚧 "}
{key
.slice(2)
.split("-")
.map((word) => word[0].toUpperCase() + word.slice(1))
.join(" ")}
{!isValidColor && " 🚧"}
</label>
</code>
</div>