From 657a2c0f5f9b9e974af67ecc8a271b6ba6c0d94a Mon Sep 17 00:00:00 2001 From: SutuSebastian Date: Wed, 24 Jan 2024 18:57:32 +0200 Subject: [PATCH 1/2] fix: proper type inference from `FlowbiteColors` derriving into `color` map prop for `theme` and `color` value prop for the component (prototype idea) --- src/components/Flowbite/FlowbiteTheme.ts | 9 +++++++-- src/components/Flowbite/index.ts | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/components/Flowbite/FlowbiteTheme.ts b/src/components/Flowbite/FlowbiteTheme.ts index 2a1d4b66..87881262 100644 --- a/src/components/Flowbite/FlowbiteTheme.ts +++ b/src/components/Flowbite/FlowbiteTheme.ts @@ -100,7 +100,6 @@ export interface FlowbiteStateColors { } export interface FlowbiteColors extends FlowbiteStateColors { - [key: string]: string; blue: string; cyan: string; dark: string; @@ -117,7 +116,6 @@ export interface FlowbiteColors extends FlowbiteStateColors { } export interface FlowbiteGradientColors extends Omit { - [key: string]: string; cyan: string; lime: string; pink: string; @@ -166,3 +164,10 @@ export interface FlowbiteSizes { export interface FlowbiteContentPositions { center: string; } + +type LooseString = string & NonNullable; +export type LooseValue = keyof T | LooseString; +export type LooseMap = Record; + +export type FlowbiteColorMap = LooseMap; +export type FlowbiteColorValue = LooseValue; diff --git a/src/components/Flowbite/index.ts b/src/components/Flowbite/index.ts index 3c8a5a52..d025c4ae 100644 --- a/src/components/Flowbite/index.ts +++ b/src/components/Flowbite/index.ts @@ -3,6 +3,8 @@ export type { ThemeProps } from './Flowbite'; export type { CustomFlowbiteTheme, FlowbiteBoolean, + FlowbiteColorMap, + FlowbiteColorValue, FlowbiteColors, FlowbiteContentPositions, FlowbiteGradientColors, From 2f68262b34034c0c7b34ec3fb6f0fae78bbbcd37 Mon Sep 17 00:00:00 2001 From: SutuSebastian Date: Wed, 24 Jan 2024 18:57:51 +0200 Subject: [PATCH 2/2] fix(components): types for `Alert` --- src/components/Alert/Alert.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/Alert/Alert.tsx b/src/components/Alert/Alert.tsx index 7eea6a79..99d0dcc6 100644 --- a/src/components/Alert/Alert.tsx +++ b/src/components/Alert/Alert.tsx @@ -4,13 +4,13 @@ import { twMerge } from 'tailwind-merge'; import { mergeDeep } from '../../helpers/merge-deep'; import { getTheme } from '../../theme-store'; import type { DeepPartial } from '../../types'; -import type { FlowbiteColors } from '../Flowbite'; +import type { FlowbiteColorMap, FlowbiteColorValue } from '../Flowbite'; export interface FlowbiteAlertTheme { base: string; borderAccent: string; closeButton: FlowbiteAlertCloseButtonTheme; - color: FlowbiteColors; + color: FlowbiteColorMap; icon: string; rounded: string; wrapper: string; @@ -18,13 +18,13 @@ export interface FlowbiteAlertTheme { export interface FlowbiteAlertCloseButtonTheme { base: string; - color: FlowbiteColors; + color: FlowbiteColorMap; icon: string; } export interface AlertProps extends Omit, 'color'> { additionalContent?: ReactNode; - color?: keyof FlowbiteColors; + color?: FlowbiteColorValue; icon?: FC>; onDismiss?: boolean | (() => void); rounded?: boolean;