From 5eca1d870b4678125c416d019daebf35f525ee00 Mon Sep 17 00:00:00 2001 From: Floris List Date: Tue, 12 Nov 2024 15:33:59 +0000 Subject: [PATCH] chore: typescript magic --- .../src/components/TextArea/TextArea.types.ts | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/packages/core/src/components/TextArea/TextArea.types.ts b/packages/core/src/components/TextArea/TextArea.types.ts index e8c0fa9630..71af3feb40 100644 --- a/packages/core/src/components/TextArea/TextArea.types.ts +++ b/packages/core/src/components/TextArea/TextArea.types.ts @@ -7,7 +7,23 @@ type TextAreaNativeInputProps = Omit< "role" | "aria-describedby" | "aria-invalid" >; -export interface TextAreaProps extends TextAreaNativeInputProps, VibeComponentProps { +/** + * This type ensures that allowExceedingMaxLength is only used when maxLength is provided. + */ +type MaxLengthProps = + | { + /** + * The allowed number of characters. + */ + maxLength?: number; + /** + * If true, the TextArea will allow the user to exceed the character limit. + */ + allowExceedingMaxLength?: false; + } + | { allowExceedingMaxLength: true; maxLength: number }; + +interface TextAreaInterface extends TextAreaNativeInputProps, VibeComponentProps { /** * The current value of the textarea. */ @@ -50,16 +66,10 @@ export interface TextAreaProps extends TextAreaNativeInputProps, VibeComponentPr * Placeholder text to display when the textarea is empty. */ placeholder?: string; - /** - * The allowed number of characters. - */ - maxLength?: number; - /** - * If true, the TextArea will allow the user to exceed the character limit. - */ - allowExceedingMaxLength?: boolean; /** * If true, the character count and limit will be displayed below the textarea. */ showCharCount?: boolean; } + +export type TextAreaProps = TextAreaInterface & MaxLengthProps;