Skip to content

Commit

Permalink
fixup! feat(suite-native): Create generic picker header component
Browse files Browse the repository at this point in the history
  • Loading branch information
jbazant committed Jan 28, 2025
1 parent ef0ecb8 commit 2fbdc22
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions suite-native/module-trading/src/components/general/PickerHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,40 @@ import { ReactNode } from 'react';

import { HStack, SearchInput, Text, VStack } from '@suite-native/atoms';

type PickerHeaderSearchInputProps = {
onSearchInputChange: (value: string) => void;
searchInputPlaceholder?: string;
isSearchInputDisabled?: boolean;
maxSearchInputLength?: number;
};

export type PickerHeaderProps = {
title: ReactNode;
children?: ReactNode;
} & (
| {
isSearchInputVisible?: false;
onSearchInputChange?: never;
searchInputPlaceholder?: never;
isSearchInputDisabled?: never;
maxSearchInputLength?: never;
}
| {
isSearchInputVisible: true;
onSearchInputChange: (value: string) => void;
searchInputPlaceholder?: string;
isSearchInputDisabled?: boolean;
maxSearchInputLength?: number;
}
| { isSearchInputVisible?: false }
| ({ isSearchInputVisible: true } & PickerHeaderSearchInputProps)
);

const PickerHeaderSearchInput = ({
onSearchInputChange,
searchInputPlaceholder,
isSearchInputDisabled,
maxSearchInputLength,
}: PickerHeaderSearchInputProps) => (
<SearchInput
onChange={onSearchInputChange}
maxLength={maxSearchInputLength}
placeholder={searchInputPlaceholder}
isDisabled={isSearchInputDisabled}
/>
);

export const PickerHeader = ({
title,
isSearchInputVisible,
children,
maxSearchInputLength,
searchInputPlaceholder,
isSearchInputDisabled,
onSearchInputChange,
...searchInputProps
}: PickerHeaderProps) => (
<VStack spacing="sp16">
<HStack justifyContent="space-between" alignItems="center">
Expand All @@ -39,12 +45,7 @@ export const PickerHeader = ({
{children}
</HStack>
{isSearchInputVisible && (
<SearchInput
onChange={onSearchInputChange}
maxLength={maxSearchInputLength}
placeholder={searchInputPlaceholder}
isDisabled={isSearchInputDisabled}
/>
<PickerHeaderSearchInput {...(searchInputProps as PickerHeaderSearchInputProps)} />
)}
</VStack>
);

0 comments on commit 2fbdc22

Please sign in to comment.