refactor: enhance color utility and type definitions
- Updated `getDefaultColorForCustomObject` to return `ThemeColorName` for better type safety. - Introduced `ThemeColorName` type in `MainColorNames.ts` to standardize color references. - Adjusted imports and exports across relevant modules to incorporate the new type, improving consistency and maintainability.
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
import { MAIN_COLOR_NAMES } from '../../constants/MainColorNames';
|
||||
import {
|
||||
MAIN_COLOR_NAMES,
|
||||
type ThemeColorName,
|
||||
} from '../../constants/MainColorNames';
|
||||
|
||||
export const getDefaultColorForCustomObject = (
|
||||
nameSingular: string,
|
||||
): string => {
|
||||
): ThemeColorName => {
|
||||
const customObjectColors = MAIN_COLOR_NAMES.filter(
|
||||
(color): color is Exclude<(typeof MAIN_COLOR_NAMES)[number], 'gray'> =>
|
||||
color !== 'gray',
|
||||
|
||||
@@ -25,3 +25,5 @@ export const MAIN_COLOR_NAMES = [
|
||||
'brown',
|
||||
'gray',
|
||||
] as const;
|
||||
|
||||
export type ThemeColorName = (typeof MAIN_COLOR_NAMES)[number];
|
||||
|
||||
@@ -29,6 +29,7 @@ export { FILES_FIELD_MAX_NUMBER_OF_VALUES } from './FilesFieldMaxNumberOfValues'
|
||||
export { GROUP_BY_DATE_GRANULARITY_THAT_REQUIRE_TIME_ZONE } from './GroupByDateGranularityThatRequireTimeZone';
|
||||
export { IANA_TIME_ZONES } from './IanaTimeZones';
|
||||
export { LABEL_IDENTIFIER_FIELD_METADATA_TYPES } from './LabelIdentifierFieldMetadataTypes';
|
||||
export type { ThemeColorName } from './MainColorNames';
|
||||
export { MAIN_COLOR_NAMES } from './MainColorNames';
|
||||
export { MULTI_ITEM_FIELD_DEFAULT_MAX_VALUES } from './MultiItemFieldDefaultMaxValues';
|
||||
export { MULTI_ITEM_FIELD_MIN_MAX_VALUES } from './MultiItemFieldMinMaxValues';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { MAIN_COLORS_LIGHT } from './MainColorsLight';
|
||||
import { MAIN_COLOR_NAMES, type ThemeColorName } from 'twenty-shared/constants';
|
||||
|
||||
export const MAIN_COLOR_NAMES = Object.keys(MAIN_COLORS_LIGHT) as ThemeColor[];
|
||||
export { MAIN_COLOR_NAMES };
|
||||
|
||||
export type ThemeColor = keyof typeof MAIN_COLORS_LIGHT;
|
||||
export type ThemeColor = ThemeColorName;
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import * as RadixColors from '@radix-ui/colors';
|
||||
import type { ThemeColorName } from 'twenty-shared/constants';
|
||||
import { GRAY_SCALE_LIGHT } from './GrayScaleLight';
|
||||
|
||||
export const MAIN_COLORS_LIGHT = {
|
||||
export const MAIN_COLORS_LIGHT: Record<ThemeColorName, string> = {
|
||||
// Reds
|
||||
red: RadixColors.redP3.red9,
|
||||
ruby: RadixColors.rubyP3.ruby9,
|
||||
|
||||
Reference in New Issue
Block a user