Skip to content

Commit

Permalink
feat: table search can detect text values on change (#888)
Browse files Browse the repository at this point in the history
  • Loading branch information
moby-101 authored Oct 31, 2023
1 parent dd6c8bc commit b0b2d79
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { TableSearchField } from './TableSearchField';
import { TableSearchOption } from './TableSearchOption';
import type { TableSearchProps } from './TableSearchProps';

export const TableSearch = ({ children, testId = 'table-search', onSubmit }: TableSearchProps) => {
export const TableSearch = ({ children, testId = 'table-search', onSubmit, onTextChange }: TableSearchProps) => {
const [optionValue, setOptionValue] = useState<string>();
const searchFieldRef = useRef<TextInputRef>(null);

Expand All @@ -21,7 +21,12 @@ export const TableSearch = ({ children, testId = 'table-search', onSubmit }: Tab
};

return (
<TableSearchProvider searchFieldRef={searchFieldRef} onOptionChange={changeOption} onSubmit={submit}>
<TableSearchProvider
searchFieldRef={searchFieldRef}
onOptionChange={changeOption}
onSubmit={submit}
onTextChange={onTextChange}
>
<HStack width="100%" alignVertical="center" spacing={4} data-testid={testId}>
{children}
</HStack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,43 @@ type TableSearchContextValue = {
searchFieldRef: RefObject<TextInputRef> | null;
onSubmit?: (value: string) => void;
onOptionChange?: (value?: string) => void;
onTextChange?: ({ value, prevent }: { value: string; prevent: () => void }) => void;
};

const TableSearchContext = createContext<TableSearchContextValue>({
searchFieldRef: null,
onSubmit: () => {},
onOptionChange: () => {},
onTextChange: () => {},
});

type TableSearchProviderProps = {
children: ReactElement | ReactElement[];
searchFieldRef: RefObject<TextInputRef> | null;
onSubmit?: (value: string) => void;
onOptionChange?: (value?: string) => void;
onTextChange?: ({ value, prevent }: { value: string; prevent: () => void }) => void;
};

export const TableSearchProvider: FC<TableSearchProviderProps> = ({
children,
searchFieldRef,
onOptionChange,
onTextChange,
onSubmit,
}) => (
<TableSearchContext.Provider value={{ searchFieldRef, onOptionChange, onSubmit }}>
<TableSearchContext.Provider value={{ searchFieldRef, onOptionChange, onSubmit, onTextChange }}>
{children}
</TableSearchContext.Provider>
);

export const useTableSearch = () => {
const { searchFieldRef, onOptionChange, onSubmit } = useContext(TableSearchContext);
const { searchFieldRef, onOptionChange, onSubmit, onTextChange } = useContext(TableSearchContext);

return {
searchFieldRef,
onOptionChange,
onTextChange,
onSubmit,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { withTableSearchFieldVariation } from './TableSearchFieldProps';

export const TableSearchField = withTableSearchFieldVariation(
({ maxWidth, testId = 'table-search-field', ...restProps }) => {
const { searchFieldRef, onSubmit } = useTableSearch();
const { searchFieldRef, onSubmit, onTextChange } = useTableSearch();

return (
<Box width="100%" maxWidth={maxWidth} data-testid={testId}>
Expand All @@ -17,6 +17,7 @@ export const TableSearchField = withTableSearchFieldVariation(
clearable={true}
renderStart={() => <Icon.Search.Thin size={20} fill="onView2" />}
onSubmit={onSubmit}
onValueChange={onTextChange}
{...restProps}
/>
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export type TableSearchProps = {
children: ReactElement | ReactElement[];
testId?: string;
onSubmit?: (fieldValue: string, optionValue?: string) => void;
onTextChange?: ({ value, prevent }: { value: string; prevent: () => void }) => void;
};

export const withTableSearchVariation = withVariation<TableSearchProps>('TableSearch')();

1 comment on commit b0b2d79

@vercel
Copy link

@vercel vercel bot commented on b0b2d79 Oct 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@moby-101 is attempting to deploy a commit to the Class101 Team on Vercel.

To accomplish this, @moby-101 needs to request access to the Team.

Afterwards, an owner of the Team is required to accept their membership request.

If you're already a member of the respective Vercel Team, make sure that your Personal Vercel Account is connected to your GitHub account.

Please sign in to comment.