-
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.
added option to edit hex color and alpha picker
- Loading branch information
1 parent
fcea122
commit 874aba5
Showing
2 changed files
with
33 additions
and
13 deletions.
There are no files selected for viewing
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,17 +1,40 @@ | ||
import React from "react"; | ||
import { HexColorPicker } from "react-colorful"; | ||
import React from 'react' | ||
import { HexAlphaColorPicker, HexColorInput } from 'react-colorful' | ||
import { useTheme } from '../contexts/ThemeContext' | ||
|
||
interface ColorPickerProps { | ||
color: string; | ||
onChange: (color: string) => void; | ||
color: string | ||
onChange: (color: string) => void | ||
} | ||
|
||
const ColorPicker: React.FC<ColorPickerProps> = ({ color, onChange }) => { | ||
const { activeColor } = useTheme() | ||
const handleInputChange = (value: string) => { | ||
if (value.startsWith('#') && value.length > 6) { | ||
onChange(value) | ||
} | ||
} | ||
|
||
return ( | ||
<div className="color-picker"> | ||
<HexColorPicker color={color} onChange={onChange} /> | ||
<div className="color-picker flex flex-col gap-2 items-center justify-center"> | ||
<HexAlphaColorPicker color={color} onChange={onChange} /> | ||
|
||
<div className="flex gap-2 items-center"> | ||
<h3 className="text-lg font-semibold first-letter:uppercase"> | ||
{activeColor} | ||
</h3> | ||
<div className="w-[100px]"> | ||
<HexColorInput | ||
className="flex h-9 w-full rounded-md border border-input bg-transparent px-2 py-1 text-sm shadow-sm transition-colors text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50" | ||
color={color} | ||
prefixed | ||
alpha | ||
onChange={handleInputChange} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
) | ||
} | ||
|
||
export default ColorPicker; | ||
export default ColorPicker |