Skip to content

Commit

Permalink
fix color picker in safari
Browse files Browse the repository at this point in the history
  • Loading branch information
brandon-pereira committed Feb 8, 2024
1 parent cffb1e0 commit d8b40d1
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 22 deletions.
8 changes: 8 additions & 0 deletions src/components/ColorPicker/ColorPicker.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ export const Color = styled.button.attrs(props => ({
`};
`;

export const TooltipContainer = styled.div`
position: relative;
height: 1rem;
display: flex;
align-items: center;
justify-content: center;
`;

export const LabelContainer = styled.div`
display: flex;
margin-bottom: 0.5rem;
Expand Down
65 changes: 43 additions & 22 deletions src/components/ColorPicker/ColorPicker.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { useState, useEffect, useCallback, useRef } from 'react';
import randomColor from 'randomcolor';

import { Icon, Container, Color, LabelContainer } from './ColorPicker.styles';
import {
Icon,
Container,
Color,
LabelContainer,
TooltipContainer
} from './ColorPicker.styles';

import Refresh from '@components/Icon/svgs/refresh.svg';
import Eyedropper from '@components/Icon/svgs/eyedropper.svg';
Expand Down Expand Up @@ -67,6 +73,8 @@ function ColorPicker({ value, onChange }: Props) {
e.preventDefault();
}
if (inputColorRef.current) {
console.log('HERE');
inputColorRef.current.focus();
inputColorRef.current.click();
}
},
Expand Down Expand Up @@ -99,28 +107,41 @@ function ColorPicker({ value, onChange }: Props) {
>
Refresh Palette
</Icon>
<Icon
size="1rem"
icon={Eyedropper}
color="currentColor"
onClick={onLaunchPicker}
>
Pick a colour
</Icon>
<TooltipContainer>
<Icon
size="1rem"
icon={Eyedropper}
color="currentColor"
onClick={onLaunchPicker}
>
Pick a colour
</Icon>
<input
ref={inputColorRef}
value={palette[index]}
onChange={e => {
e.preventDefault();
e.stopPropagation();
if (
inputColorRef.current &&
inputColorRef.current.value
) {
onChangeColorFromPicker(
inputColorRef.current.value
);
}
}}
type="color"
style={{
position: 'absolute',
visibility: 'hidden',
left: '50%',
transform: 'translateX(-50%)'
}}
/>
</TooltipContainer>
</LabelContainer>
<input
ref={inputColorRef}
value={palette[index]}
onChange={e => {
e.preventDefault();
e.stopPropagation();
if (inputColorRef.current && inputColorRef.current.value) {
onChangeColorFromPicker(inputColorRef.current.value);
}
}}
type="color"
style={{ display: 'none' }}
/>

<Container ref={colorPaletteRef}>
{palette.map((color, idx) => (
<Color
Expand Down

0 comments on commit d8b40d1

Please sign in to comment.