From db8b71d010d222facf1dfc15ae1dfdf7a812c3c4 Mon Sep 17 00:00:00 2001 From: Pedro Pablo Aste Kompen Date: Mon, 18 Dec 2023 17:41:25 -0300 Subject: [PATCH] refactor(ds): make onPressClearButton required when showClearButton (#8150) --- .../TextFieldSearch/TextFieldSearch.types.ts | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/app/component-library/components/Form/TextFieldSearch/TextFieldSearch.types.ts b/app/component-library/components/Form/TextFieldSearch/TextFieldSearch.types.ts index 00a121c6b90..68b7aa2da18 100644 --- a/app/component-library/components/Form/TextFieldSearch/TextFieldSearch.types.ts +++ b/app/component-library/components/Form/TextFieldSearch/TextFieldSearch.types.ts @@ -2,21 +2,39 @@ import { TextFieldProps } from '../TextField/TextField.types'; import { ButtonIconProps } from '../../Buttons/ButtonIcon/ButtonIcon.types'; -/** - * TextFieldSearch component props. - */ -export interface TextFieldSearchProps extends TextFieldProps { +interface BaseTextFieldSearchProps extends TextFieldProps { + /** + * Optional prop to pass any additional props to the clear button. + */ + clearButtonProps?: ButtonIconProps; +} + +interface HideClearButtonTextFieldSearchProps extends BaseTextFieldSearchProps { /** * Optional boolean to show the Clear button. * @default false */ - showClearButton?: boolean; + showClearButton?: false; /** * Function to trigger when pressing the clear button. */ onPressClearButton?: () => void; +} + +interface ShowClearButtonTextFieldSearchProps extends BaseTextFieldSearchProps { /** - * Optional prop to pass any additional props to the clear button. + * Show the Clear button. */ - clearButtonProps?: ButtonIconProps; + showClearButton: true; + /** + * Function to trigger when pressing the clear button. + */ + onPressClearButton: () => void; } + +/** + * TextFieldSearch component props. + */ +export type TextFieldSearchProps = + | HideClearButtonTextFieldSearchProps + | ShowClearButtonTextFieldSearchProps;