Skip to content

Commit

Permalink
added option to edit hex color and alpha picker
Browse files Browse the repository at this point in the history
  • Loading branch information
RodrigoLuglio committed Oct 15, 2024
1 parent fcea122 commit 874aba5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
5 changes: 1 addition & 4 deletions src/components/ActiveColorPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@ const ActiveColorPicker: React.FC = () => {
}

return (
<div className="mb-4">
<div className="flex flex-col gap-2">
<ColorPicker
color={currentColor}
onChange={(newColor) => handleColorChange(activeColor, newColor)}
/>
<h3 className="text-lg font-semibold mt-2 text-center first-letter:uppercase">
{activeColor}
</h3>
</div>
)
}
Expand Down
41 changes: 32 additions & 9 deletions src/components/ColorPicker.tsx
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

0 comments on commit 874aba5

Please sign in to comment.