feat: create custom color picker component

This commit is contained in:
Ivana Andersson 2023-08-24 13:04:38 +03:00
parent 6048f5617d
commit edb5e3a64b
2 changed files with 68 additions and 25 deletions

View File

@ -0,0 +1,37 @@
.color-picker-button {
width: 40px;
height: 40px;
border-radius: 50%;
margin-bottom: 10px;
margin-right: 10px;
position: relative;
}
.color-picker-button::before ,
.color-picker-button::after {
display: block;
content: "";
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
transform-origin: center;
opacity: 0;
transition: 120ms opacity ease-in-out;
}
.color-picker-button::before {
width: 0.65em;
height: 0.65em;
box-shadow: inset 1em 1em white;
}
.color-picker-button::after {
width: 40px;
height: 40px;
border-radius: 50%;
border: 2px solid white;
}
.color-picker-button:focus::before,
.color-picker-button:hover::after {
opacity: 1;
}

View File

@ -1,33 +1,39 @@
import { useState } from 'react' import { useState } from 'react'
import { CirclePicker } from 'react-color'
import { XStack } from 'tamagui' import { XStack } from 'tamagui'
import { CustomPicker } from 'react-color'
import './ColorPicker.css'
const ColorPicker = () => { const ColorPicker = () => {
const [chosenColor, setChosenColor] = useState('#FFFFFF') const [chosenColor, setChosenColor] = useState('#2A4AF5')
const colors = [
'#2A4AF5',
'#F6B03C',
'#7140FD',
'#2A799B',
'#EC266C',
'#1992D7',
'#FF7D46',
'#216266',
'#F66F8F',
'#C78F67',
'#CB6256',
]
return ( return (
<XStack my={10}> <>
<CirclePicker <XStack my={10} width="80%" flexWrap="wrap">
width="80%" {colors.map((color, i) => (
circleSize={40} <button
circleSpacing={12} key={i}
colors={[ type="button"
'#2A4AF5', className="color-picker-button"
'#F6B03C', onClick={_e => setChosenColor(color)}
'#7140FD', style={{ background: color, color: color }}
'#2A799B', ></button>
'#EC266C', ))}
'#1992D7', </XStack>
'#FF7D46', </>
'#216266',
'#F66F8F',
'#C78F67',
'#CB6256',
]}
color={chosenColor}
onChange={color => setChosenColor(color.hex)}
/>
</XStack>
) )
} }
export default ColorPicker export default CustomPicker(ColorPicker)