Marie
2024-08-23 12:13:49 +02:00
committed by GitHub
parent 4c5fc2311f
commit 981f311ed0
3 changed files with 11 additions and 2 deletions

View File

@ -11,7 +11,7 @@ export const generateNewSelectOption = (
const newOptionLabel = generateNewSelectOptionLabel(options);
return {
color: getNextThemeColor(options[options.length - 1].color),
color: getNextThemeColor(options[options.length - 1]?.color),
id: v4(),
label: newOptionLabel,
position: options.length,

View File

@ -20,4 +20,9 @@ describe('getNextThemeColor', () => {
expect(getNextThemeColor(currentColor)).toBe(nextColor);
});
it('returns the first color when currentColorIsUndefined', () => {
const firstColor: ThemeColor = MAIN_COLOR_NAMES[0];
expect(getNextThemeColor(undefined)).toBe(firstColor);
});
});

View File

@ -1,6 +1,10 @@
import { MAIN_COLOR_NAMES, ThemeColor } from '@ui/theme';
import { isDefined } from '@ui/utilities';
export const getNextThemeColor = (currentColor: ThemeColor): ThemeColor => {
export const getNextThemeColor = (currentColor?: ThemeColor): ThemeColor => {
if (!isDefined(currentColor)) {
return MAIN_COLOR_NAMES[0];
}
const currentColorIndex = MAIN_COLOR_NAMES.findIndex(
(color) => color === currentColor,
);