feat: UI color picker component (#189)

* wip: color picker styled

* chore: color picker

* style: alight color picker

* style: align color picker
This commit is contained in:
Camila Sosa Morales 2023-03-27 17:53:02 -03:00 committed by GitHub
parent 33d1d53118
commit 9df1791c72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 85 additions and 14 deletions

View File

@ -0,0 +1,17 @@
import { IconStyles as IS } from '../icon.styles';
export const ChevronDownIcon: React.FC<IS.CustomProps> = (props) => (
<IS.Custom
{...props}
viewBox="0 0 12 6"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
fill-rule="evenodd"
clip-rule="evenodd"
d="M0.96967 0.21967C1.26256 -0.0732233 1.73744 -0.0732233 2.03033 0.21967L6 4.18934L9.96967 0.21967C10.2626 -0.0732233 10.7374 -0.0732233 11.0303 0.21967C11.3232 0.512563 11.3232 0.987437 11.0303 1.28033L6.53033 5.78033C6.23744 6.07322 5.76256 6.07322 5.46967 5.78033L0.96967 1.28033C0.676777 0.987437 0.676777 0.512563 0.96967 0.21967Z"
fill="currentColor"
/>
</IS.Custom>
);

View File

@ -1,5 +1,6 @@
export * from './metamask-icon'; export * from './metamask-icon';
export * from './ethereum-icon'; export * from './ethereum-icon';
export * from './chevron-down-icon';
export * from './fleek-name-icon'; export * from './fleek-name-icon';
export * from './beta-tag-icon'; export * from './beta-tag-icon';
export * from './error-icon'; export * from './error-icon';

View File

@ -2,10 +2,10 @@ import { IoLogoGithub } from '@react-icons/all-files/io5/IoLogoGithub';
import { IoArrowBackCircleSharp } from '@react-icons/all-files/io5/IoArrowBackCircleSharp'; import { IoArrowBackCircleSharp } from '@react-icons/all-files/io5/IoArrowBackCircleSharp';
import { IoInformationCircleSharp } from '@react-icons/all-files/io5/IoInformationCircleSharp'; import { IoInformationCircleSharp } from '@react-icons/all-files/io5/IoInformationCircleSharp';
import { AiOutlineCheck } from '@react-icons/all-files/ai/AiOutlineCheck'; import { AiOutlineCheck } from '@react-icons/all-files/ai/AiOutlineCheck';
import { AiOutlineDown } from '@react-icons/all-files/ai/AiOutlineDown';
import { BiSearch } from '@react-icons/all-files/bi/BiSearch'; import { BiSearch } from '@react-icons/all-files/bi/BiSearch';
import { IoCloudUploadSharp } from '@react-icons/all-files/io5/IoCloudUploadSharp'; import { IoCloudUploadSharp } from '@react-icons/all-files/io5/IoCloudUploadSharp';
import { import {
ChevronDownIcon,
MetamaskIcon, MetamaskIcon,
EthereumIcon, EthereumIcon,
ErrorIcon, ErrorIcon,
@ -18,6 +18,7 @@ import { AiOutlineTwitter } from '@react-icons/all-files/ai/AiOutlineTwitter';
import { IoClose } from '@react-icons/all-files/io5/IoClose'; import { IoClose } from '@react-icons/all-files/io5/IoClose';
import { AiFillCheckCircle } from '@react-icons/all-files/ai/AiFillCheckCircle'; import { AiFillCheckCircle } from '@react-icons/all-files/ai/AiFillCheckCircle';
import { BiGitBranch } from '@react-icons/all-files/bi/BiGitBranch'; import { BiGitBranch } from '@react-icons/all-files/bi/BiGitBranch';
import { BsFillSquareFill } from '@react-icons/all-files/bs/BsFillSquareFill';
export const IconLibrary = Object.freeze({ export const IconLibrary = Object.freeze({
back: IoArrowBackCircleSharp, back: IoArrowBackCircleSharp,
@ -25,7 +26,7 @@ export const IconLibrary = Object.freeze({
branch: BiGitBranch, branch: BiGitBranch,
check: AiOutlineCheck, check: AiOutlineCheck,
'check-circle': IoCheckmarkCircleSharp, 'check-circle': IoCheckmarkCircleSharp,
'chevron-down': AiOutlineDown, 'chevron-down': ChevronDownIcon,
close: IoClose, close: IoClose,
error: ErrorIcon, error: ErrorIcon,
ethereum: EthereumIcon, ethereum: EthereumIcon,
@ -36,6 +37,7 @@ export const IconLibrary = Object.freeze({
upload: IoCloudUploadSharp, upload: IoCloudUploadSharp,
metamask: MetamaskIcon, //remove if not used metamask: MetamaskIcon, //remove if not used
search: BiSearch, search: BiSearch,
square: BsFillSquareFill,
success: AiFillCheckCircle, success: AiFillCheckCircle,
twitter: AiOutlineTwitter, twitter: AiOutlineTwitter,
}); });

View File

@ -34,6 +34,10 @@ export const StyledInputFile = forwardRef<HTMLDivElement, InputFileProps>(
onChange(e); onChange(e);
}; };
const handleInputClick = () => {
inputFileRef.current?.click();
};
return ( return (
<> <>
<Flex <Flex
@ -45,7 +49,7 @@ export const StyledInputFile = forwardRef<HTMLDivElement, InputFileProps>(
}} }}
ref={ref} ref={ref}
{...props} {...props}
onClick={() => inputFileRef.current?.click()} onClick={handleInputClick}
> >
{file !== '' ? ( {file !== '' ? (
<img className="absolute w-14 h-14" src={file} alt="logo" /> <img className="absolute w-14 h-14" src={file} alt="logo" />

View File

@ -13,7 +13,6 @@ export abstract class PageStyles {
minHeight: '85vh', minHeight: '85vh',
maxWidth: '$7xl', maxWidth: '$7xl',
margin: '0 auto', margin: '0 auto',
padding: '$10',
display: 'grid', display: 'grid',
}); });
} }

View File

@ -0,0 +1,15 @@
import { Button, Flex, Icon } from '@/components';
export const ColorPickerTest = () => {
return (
<Flex css={{ margin: '$22', gap: '$5', width: '$8' }}>
<Button
leftIcon={<Icon name="square" css={{ color: '#FFFFFF' }} />}
rightIcon={<Icon name="chevron-down" css={{ fontSize: '0.625rem' }} />}
css={{ py: '$1', height: '$5', borderRadius: '$md', color: '$slate12' }}
>
#FFFFFF
</Button>
</Flex>
);
};

View File

@ -1,10 +1,12 @@
import { Flex } from '@/components'; import { Flex } from '@/components';
import { ColorPickerTest } from './color-picker';
import { ComboboxTest } from './combobox-test'; import { ComboboxTest } from './combobox-test';
import { ToastTest } from './toast-test'; import { ToastTest } from './toast-test';
export const ComponentsTest = () => { export const ComponentsTest = () => {
return ( return (
<Flex css={{ flexDirection: 'column' }}> <Flex css={{ flexDirection: 'column' }}>
<ColorPickerTest />
<ToastTest /> <ToastTest />
<ComboboxTest /> <ComboboxTest />
</Flex> </Flex>

View File

@ -1,4 +1,4 @@
import { Card, Flex } from '@/components'; import { Button, Card, Flex, Icon } from '@/components';
import { useRef } from 'react'; import { useRef } from 'react';
// @ts-ignore // @ts-ignore
import ColorThief from 'colorthief'; import ColorThief from 'colorthief';
@ -6,6 +6,7 @@ import { Mint } from '../../../../mint.context';
export const ColorPicker = () => { export const ColorPicker = () => {
const { appLogo, logoColor, setLogoColor } = Mint.useContext(); const { appLogo, logoColor, setLogoColor } = Mint.useContext();
const inputColorRef = useRef<HTMLInputElement>(null);
const imageRef = useRef<HTMLImageElement>(null); const imageRef = useRef<HTMLImageElement>(null);
const handleLogoLoad = (e: React.SyntheticEvent<HTMLImageElement>) => { const handleLogoLoad = (e: React.SyntheticEvent<HTMLImageElement>) => {
@ -16,17 +17,47 @@ export const ColorPicker = () => {
setLogoColor(hexColor); setLogoColor(hexColor);
}; };
const handleColorPickerClick = () => {
inputColorRef.current?.click();
};
return ( return (
<Card.Text css={{ height: '$22', mt: '$6' }}> <Card.Text css={{ height: '$22', mt: '$6' }}>
<Flex css={{ gap: '$3h' }}> <div className="relative">
<span>Primary Color</span> <Flex css={{ gap: '$3h', alignItems: 'center' }}>
{/* TODO crate color picker component */} <span>Primary Color</span>
<input {/* TODO crate color picker component */}
type="color" <Button
value={logoColor} leftIcon={
onChange={(e) => setLogoColor(e.target.value)} <Icon
/> name="square"
</Flex> css={{ color: `${logoColor || '#000000'}` }}
/>
}
rightIcon={
<Icon name="chevron-down" css={{ fontSize: '0.625rem' }} />
}
css={{
py: '$1',
height: '$5',
borderRadius: '$md',
color: '$slate12',
zIndex: '$dropdown',
}}
onClick={handleColorPickerClick}
>
{logoColor.toUpperCase() || '#000000'}
</Button>
<input
ref={inputColorRef}
className="absolute right-16"
type="color"
value={logoColor}
onChange={(e) => setLogoColor(e.target.value)}
/>
</Flex>
</div>
<img <img
className="hidden" className="hidden"
src={appLogo} src={appLogo}