diff --git a/packages/web/components/elements/LabelColorDropdown.tsx b/packages/web/components/elements/LabelColorDropdown.tsx index 763ee7289..f5aeee40e 100644 --- a/packages/web/components/elements/LabelColorDropdown.tsx +++ b/packages/web/components/elements/LabelColorDropdown.tsx @@ -1,9 +1,6 @@ import React, { useState } from 'react' import { styled } from '../tokens/stitches.config' -import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu' -import { HexColorPicker } from 'react-colorful' -import { HStack, SpanBox } from './LayoutPrimitives' -import { CaretDown } from 'phosphor-react' +import { Box, HStack, SpanBox } from './LayoutPrimitives' import { StyledText } from './StyledText' import { LabelColorDropdownProps, @@ -11,9 +8,10 @@ import { LabelOptionProps, } from '../../utils/settings-page/labels/types' import { labelColorObjects } from '../../utils/settings-page/labels/labelColorObjects' -import { DropdownOption } from './DropdownElements' import { isDarkTheme } from '../../lib/themeUpdater' import { LabelColor } from '../../lib/networking/fragments/labelFragment' +import { TwitterPicker } from 'react-color' +import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu' const DropdownMenuContent = styled(DropdownMenuPrimitive.Content, { borderRadius: 6, @@ -23,31 +21,6 @@ const DropdownMenuContent = styled(DropdownMenuPrimitive.Content, { '0px 10px 38px -10px rgba(22, 23, 24, 0.35), 0px 10px 20px -15px rgba(22, 23, 24, 0.2)', }) -const itemStyles = { - all: 'unset', - fontSize: '$3', - lineHeight: 1, - borderRadius: 3, - display: 'flex', - alignItems: 'center', - height: 25, - position: 'relative', - userSelect: 'none', -} - -const DropdownMenuTriggerItem = styled(DropdownMenuPrimitive.TriggerItem, { - '&[data-state="open"]': { - outline: 'none', - backgroundColor: '$grayBgHover', - }, - ...itemStyles, - padding: '$2 0', - '&:focus': { - outline: 'none', - backgroundColor: '$grayBgHover', - }, -}) - const DropdownMenu = DropdownMenuPrimitive.Root const DropdownMenuTrigger = styled(DropdownMenuPrimitive.Trigger, { @@ -56,64 +29,75 @@ const DropdownMenuTrigger = styled(DropdownMenuPrimitive.Trigger, { padding: 0, marginRight: '$2', }) -const Box = styled('div', {}) -const MainContainer = styled(Box, { - fontFamily: 'inter', - fontSize: '$2', - lineHeight: '1.25', - color: '$grayText', +// const MainContainer = styled(Box, { +// fontFamily: 'inter', +// fontSize: '$2', +// lineHeight: '1.25', +// color: '$grayText', +// display: 'flex', +// justifyContent: 'space-between', +// alignItems: 'center', +// backgroundColor: '$grayBg', +// border: '1px solid $grayBorder', +// width: '180px', +// borderRadius: '$3', +// px: '$3', +// py: '0px', +// cursor: 'pointer', +// '&:hover': { +// border: '1px solid $grayBorderHover', +// }, +// '@mdDown': { +// width: '100%', +// }, +// }) + +const StyledLabel = styled('label', { + position: 'relative', + width: '154px', + height: '40px', display: 'flex', - justifyContent: 'space-between', alignItems: 'center', - backgroundColor: '$grayBg', - border: '1px solid $grayBorder', - width: '180px', - borderRadius: '$3', - px: '$3', - py: '0px', - cursor: 'pointer', - '&:hover': { - border: '1px solid $grayBorderHover', - }, - '@mdDown': { - width: '100%', - }, -}) + justifyContent: 'center', + textAlign: 'center', + fontSize: '13px', + borderRadius: '50px', + overflow: 'hidden', -const CustomLabelWrapper = styled(Box, { - fontSize: 13, - padding: 24, - borderRadius: 3, - cursor: 'default', - color: '$grayText', + '>input': { + position: 'absolute', + width: '154px', + height: '40px', - '&:focus': { - outline: 'none', - backgroundColor: '$grayBgHover', + appearance: 'none', + '-moz-appearance': 'none', + '-webkit-appearance': 'none', + background: 'none', + border: 'none', + cursor: 'pointer', + }, + + '::-webkit-color-swatch': { + border: 0, + borderRadius: 0, + }, + + '::-moz-focus-inner': { + padding: 0, }, }) export const LabelColorDropdown = (props: LabelColorDropdownProps) => { - const { - isCreateMode, - canEdit, - labelColorHexRowId, - labelId, - labelColor, - labelColorHexValue, - setLabelColorHex, - } = props + const { isCreateMode, canEdit, labelId, labelColor, setLabelColor } = props const isDarkMode = isDarkTheme() const iconColor = isDarkMode ? '#FFFFFF' : '#0A0806' + const [colorPickerValue, setColorPickerValue] = useState(props.labelColor) const [open, setOpen] = useState(false) const handleCustomColorChange = (color: string) => { - setLabelColorHex({ - rowId: labelId, - value: color.toUpperCase() as LabelColor, - }) + setLabelColor(color.toUpperCase()) } const handleOpen = (open: boolean) => { @@ -134,86 +118,112 @@ export const LabelColorDropdown = (props: LabelColorDropdownProps) => { }, }} > - - - {labelId !== '' && labelId === labelColorHexRowId ? ( - - ) : ( - <> - {labelId ? ( - - ) : ( - - )} - - )} - - - - + + + - - {Object.keys(labelColorObjects) - .filter((labelColor) => labelColor !== 'custom color') - .map((labelColor) => ( - - setLabelColorHex({ - rowId: labelId, - value: labelColor as LabelColor, - }) - } - > - - - ))} - - - null}> - - - - - - - + + ) + + return ( + + + { + // setColorPickerValue(event.target.value) + handleCustomColorChange(event.target.value) + event.preventDefault() + }} + /> + + {labelId ? ( + + ) : ( + + )} + + + + ) + + // return ( + // + // + // + // + // {labelId !== '' && labelId === labelColorHexRowId ? ( + // + // ) : ( + // <> + // {labelId ? ( + // + // ) : ( + // + // )} + // + // )} + // + + // + // + // + + // + // + // + // + // ) } function LabelOption(props: LabelOptionProps): JSX.Element { @@ -265,26 +275,12 @@ function LabelOption(props: LabelOptionProps): JSX.Element { color: '$grayText', fontSize: '$3', whiteSpace: 'nowrap', - textTransform: 'capitalize', '@md': { display: 'unset', }, }} > - {colorNameText} - - - {colorNameText === 'custom color' ? '' : colorHex} + {colorHex} {isDropdownOption ? : null} diff --git a/packages/web/package.json b/packages/web/package.json index d87ed4a4a..5e7657691 100644 --- a/packages/web/package.json +++ b/packages/web/package.json @@ -51,6 +51,7 @@ "phosphor-react": "^1.4.0", "pspdfkit": "^2022.2.3", "react": "^17.0.2", + "react-color": "^2.19.3", "react-colorful": "^5.5.1", "react-dom": "^17.0.2", "react-dropzone": "^14.2.3", @@ -88,7 +89,9 @@ "@types/lodash.debounce": "^4.0.6", "@types/markdown-it": "^12.2.3", "@types/react": "17.0.2", + "@types/react-color": "^3.0.6", "@types/react-dom": "^17.0.2", + "@types/react-input-autosize": "^2.2.1", "@types/segment-analytics": "^0.0.34", "@types/uuid": "^8.3.1", "babel-jest": "^27.4.5", diff --git a/packages/web/pages/settings/labels.tsx b/packages/web/pages/settings/labels.tsx index 85e7649d0..24ffae4ce 100644 --- a/packages/web/pages/settings/labels.tsx +++ b/packages/web/pages/settings/labels.tsx @@ -146,10 +146,7 @@ const TextArea = styled('textarea', { ...inputStyles }) export default function LabelsPage(): JSX.Element { const { labels, revalidate } = useGetLabelsQuery() - const [labelColorHex, setLabelColorHex] = useState({ - rowId: '', - value: '#000000', - }) + const [labelColorHex, setLabelColorHex] = useState('#000000') const [editingLabelId, setEditingLabelId] = useState(null) const [nameInputText, setNameInputText] = useState('') const [descriptionInputText, setDescriptionInputText] = useState('') @@ -184,13 +181,13 @@ export default function LabelsPage(): JSX.Element { setEditingLabelId('') setNameInputText('') setDescriptionInputText('') - setLabelColorHex({ rowId: '', value: '#000000' }) + setLabelColorHex('#000000') } async function createLabel(): Promise { const res = await createLabelMutation( nameInputText.trim(), - labelColorHex.value, + labelColorHex, descriptionInputText ) if (res) { @@ -206,7 +203,7 @@ export default function LabelsPage(): JSX.Element { await updateLabelMutation({ labelId: id, name: nameInputText, - color: labelColorHex.value, + color: labelColorHex, description: descriptionInputText, }) revalidate() @@ -217,7 +214,7 @@ export default function LabelsPage(): JSX.Element { setEditingLabelId(label.id) setNameInputText(label.name) setDescriptionInputText(label.description || '') - setLabelColorHex({ rowId: '', value: label.color }) + setLabelColorHex(label.color) } else { resetLabelState() } @@ -244,11 +241,7 @@ export default function LabelsPage(): JSX.Element { ) as LabelColor[] const randomColorHex = colorHexes[Math.floor(Math.random() * colorHexes.length)] - setLabelColorHex((prevState) => ({ - ...prevState, - rowId: rowId || '', - value: randomColorHex, - })) + setLabelColorHex(randomColorHex) } return ( @@ -459,8 +452,7 @@ function GenericTableCard( resetState, } = props const showInput = editingLabelId === label?.id || (isCreateMode && !label) - const labelColor = - editingLabelId === label?.id ? labelColorHex.value : label?.color + const labelColor = editingLabelId === label?.id ? labelColorHex : label?.color const iconColor = isDarkTheme() ? '#D8D7D5' : '#5F5E58' const handleEdit = () => { @@ -649,11 +641,9 @@ function GenericTableCard( )} {showInput && ( @@ -809,7 +799,7 @@ function MobileEditCard(props: any) { {nameInputText && ( - + )}