From c18f7f02dd2360cf6531d0b1b2de83a050c8972b Mon Sep 17 00:00:00 2001 From: Jan-Gerke Salomon Date: Wed, 4 Oct 2023 13:05:04 +0200 Subject: [PATCH] fix(color and icon picker): add remove icon btn & adjust styles according to specs --- .../ColorAndIconPicker/ColorAndIconPicker.tsx | 1 - .../ColorAndIconPicker/ColorPicker.module.css | 5 +- .../ColorAndIconPicker/ColorPicker.tsx | 57 ++----------------- .../ColorAndIconPicker/IconPicker.module.css | 14 +++-- .../ColorAndIconPicker/IconPicker.tsx | 4 +- .../ColorAndIconPicker/IconPickerModal.tsx | 12 +++- .../ColorAndIconPicker/availableColors.ts | 41 +++++++++++++ 7 files changed, 67 insertions(+), 67 deletions(-) create mode 100644 src/components/ColorAndIconPicker/availableColors.ts diff --git a/src/components/ColorAndIconPicker/ColorAndIconPicker.tsx b/src/components/ColorAndIconPicker/ColorAndIconPicker.tsx index cf0321c5..8260e559 100644 --- a/src/components/ColorAndIconPicker/ColorAndIconPicker.tsx +++ b/src/components/ColorAndIconPicker/ColorAndIconPicker.tsx @@ -17,7 +17,6 @@ export function ColorAndIconPicker({ return (
-
) diff --git a/src/components/ColorAndIconPicker/ColorPicker.module.css b/src/components/ColorAndIconPicker/ColorPicker.module.css index 77075001..3ffea902 100644 --- a/src/components/ColorAndIconPicker/ColorPicker.module.css +++ b/src/components/ColorAndIconPicker/ColorPicker.module.css @@ -3,7 +3,7 @@ gap: var(--spacers-dp8); padding: var(--spacers-dp8); border-radius: 3px; - border: 1px solid var(--colors-grey600); + border: 1px solid var(--colors-grey500); background: var(--colors-white); width: 68px; cursor: pointer; @@ -15,7 +15,8 @@ justify-content: center; height: 26px; width: 26px; - border: 1px solid var(--colors-black); + border: 1px dashed var(--colors-grey400); + border-radius: 2px; } .hasColor .chosenColor { diff --git a/src/components/ColorAndIconPicker/ColorPicker.tsx b/src/components/ColorAndIconPicker/ColorPicker.tsx index 36857731..34ee79e9 100644 --- a/src/components/ColorAndIconPicker/ColorPicker.tsx +++ b/src/components/ColorAndIconPicker/ColorPicker.tsx @@ -1,57 +1,10 @@ -import { - IconChevronDown16, - IconChevronUp16, - IconEmptyFrame24, - Layer, - Popper, -} from '@dhis2/ui' +import { IconChevronDown16, IconChevronUp16, Layer, Popper } from '@dhis2/ui' import cx from 'classnames' import React, { useRef, useState } from 'react' import { SwatchesPicker } from 'react-color' +import { AVAILABLE_COLORS } from './availableColors' import classes from './ColorPicker.module.css' -const COLORS = [ - [ - '#ffcdd2', - '#e57373', - '#d32f2f', - '#f06292', - '#c2185b', - '#880e4f', - '#f50057', - ], - [ - '#e1bee7', - '#ba68c8', - '#8e24aa', - '#aa00ff', - '#7e57c2', - '#4527a0', - '#7c4dff', - '#6200ea', - ], - ['#c5cae9', '#7986cb', '#3949ab', '#304ffe'], - ['#e3f2fd', '#64b5f6', '#1976d2', '#0288d1'], - ['#40c4ff', '#00b0ff', '#80deea'], - ['#00acc1', '#00838f', '#006064'], - ['#e0f2f1', '#80cbc4', '#00695c', '#64ffda'], - ['#c8e6c9', '#66bb6a', '#2e7d32', '#1b5e20'], - ['#00e676', '#aed581', '#689f38', '#33691e'], - ['#76ff03', '#64dd17', '#cddc39', '#9e9d24', '#827717'], - [ - '#fff9c4', - '#fbc02d', - '#f57f17', - '#ffff00', - '#ffcc80', - '#ffccbc', - '#ffab91', - ], - ['#bcaaa4', '#8d6e63', '#4e342e'], - ['#fafafa', '#bdbdbd', '#757575', '#424242'], - ['#cfd8dc', '#b0bec5', '#607d8b', '#37474f'], -] - export function ColorPicker({ onColorPick, color = '', @@ -74,9 +27,7 @@ export function ColorPicker({
- {!color && } -
+ />
{showPicker ? : } @@ -88,7 +39,7 @@ export function ColorPicker({
- {!icon && } {selectedIcon && ( setShowPicker(false)} onChange={({ icon }) => { onIconPick({ icon }) diff --git a/src/components/ColorAndIconPicker/IconPickerModal.tsx b/src/components/ColorAndIconPicker/IconPickerModal.tsx index 00227bff..7cc1fd39 100644 --- a/src/components/ColorAndIconPicker/IconPickerModal.tsx +++ b/src/components/ColorAndIconPicker/IconPickerModal.tsx @@ -19,15 +19,17 @@ import { useIconsQuery, Icon } from './useIconsQuery' type TabName = 'all' | 'positive' | 'negative' | 'outline' export function IconPickerModal({ + selected, onChange, onCancel, }: { + selected: string onChange: ({ icon }: { icon: string }) => void onCancel: () => void }) { const [searchValue, setSearchValue] = useState('') const [activeTab, setActiveTab] = useState('all') - const [icon, setIcon] = useState('') + const [icon, setIcon] = useState(selected) const icons = useIconsQuery() const displayIcons = searchValue ? filterIcons(icons.data[activeTab], searchValue) @@ -107,11 +109,15 @@ export function IconPickerModal({ disabled={!icon} onClick={() => onChange({ icon })} > - Select + {i18n.t('Select')} + + + diff --git a/src/components/ColorAndIconPicker/availableColors.ts b/src/components/ColorAndIconPicker/availableColors.ts new file mode 100644 index 00000000..81b1977c --- /dev/null +++ b/src/components/ColorAndIconPicker/availableColors.ts @@ -0,0 +1,41 @@ +export const AVAILABLE_COLORS = [ + [ + '#ffcdd2', + '#e57373', + '#d32f2f', + '#f06292', + '#c2185b', + '#880e4f', + '#f50057', + ], + [ + '#e1bee7', + '#ba68c8', + '#8e24aa', + '#aa00ff', + '#7e57c2', + '#4527a0', + '#7c4dff', + '#6200ea', + ], + ['#c5cae9', '#7986cb', '#3949ab', '#304ffe'], + ['#e3f2fd', '#64b5f6', '#1976d2', '#0288d1'], + ['#40c4ff', '#00b0ff', '#80deea'], + ['#00acc1', '#00838f', '#006064'], + ['#e0f2f1', '#80cbc4', '#00695c', '#64ffda'], + ['#c8e6c9', '#66bb6a', '#2e7d32', '#1b5e20'], + ['#00e676', '#aed581', '#689f38', '#33691e'], + ['#76ff03', '#64dd17', '#cddc39', '#9e9d24', '#827717'], + [ + '#fff9c4', + '#fbc02d', + '#f57f17', + '#ffff00', + '#ffcc80', + '#ffccbc', + '#ffab91', + ], + ['#bcaaa4', '#8d6e63', '#4e342e'], + ['#fafafa', '#bdbdbd', '#757575', '#424242'], + ['#cfd8dc', '#b0bec5', '#607d8b', '#37474f'], +]