diff --git a/docs/storybook/SearchInput.md b/docs/storybook/SearchInput.md new file mode 100644 index 00000000..72a5efa2 --- /dev/null +++ b/docs/storybook/SearchInput.md @@ -0,0 +1,34 @@ +### Overview + +- The SearchInput component is a versatile input field that supports both controlled and uncontrolled modes with debounce functionality. + +### Interaction + +- Users can enter search terms into the input field. If the `type` prop is not specified, it defaults to a search field, which browsers style differently to indicate its purpose. +- When the input is having search term, a clear icon appears to help users reset their search. + +### Context and Usage + +The SearchInput component supports both controlled and uncontrolled modes: +- It provides flexible input functionality with debounce support and can be used in both controlled and uncontrolled modes. +- Use the `onSearch` handler to manage API calls, which will be triggered based on the specified debounce timeout. + +#### Common Behavior + +- The `onChange` handler triggers on every character change. +- The debounce feature, with a default delay of 0 milliseconds, can be customized using the `debounceTimeout` prop. +- The `onSearch` function is called after the debounce delay, allowing for API calls. + +#### Controlled Mode + +- Use the `value` prop to control the input. + +#### Uncontrolled Mode + +- Use the `defaultValue` prop to set the initial input value. + +### Guidance + +- The `onChange` handler functions the same as in a standard input field. +- All props related to the MUI TextField component are supported. +- New props added for managing the debounce feature: `debounceTimeout` and `onSearch`. \ No newline at end of file diff --git a/src/components/basic/SearchInput/SearchInput.stories.tsx b/src/components/basic/SearchInput/SearchInput.stories.tsx index e0ad457e..2462d92c 100644 --- a/src/components/basic/SearchInput/SearchInput.stories.tsx +++ b/src/components/basic/SearchInput/SearchInput.stories.tsx @@ -22,12 +22,18 @@ import { useState } from 'react' import { ComponentStory } from '@storybook/react' import { SearchInput as Component } from '.' +import searchInputDoc from '../../../../docs/storybook/SearchInput.md?raw' export default { - title: 'Form', + title: 'Form/SearchInput', component: Component, tags: ['autodocs'], argTypes: {}, + parameters: { + docs: { + description: { component: searchInputDoc }, + }, + }, } const Template: ComponentStory = (args: any) => ( diff --git a/src/components/basic/SearchInput/SearchInput.test.tsx b/src/components/basic/SearchInput/SearchInput.test.tsx index ddff66f7..2de7a209 100644 --- a/src/components/basic/SearchInput/SearchInput.test.tsx +++ b/src/components/basic/SearchInput/SearchInput.test.tsx @@ -1,7 +1,7 @@ import { useState } from 'react' import { fireEvent, screen, waitFor } from '@testing-library/react' import { SearchInput } from '.' -import { render } from '../../../test/test-utils' +import { render } from '../../../test/testUtils' jest.useFakeTimers() diff --git a/src/test/test-utils.tsx b/src/test/testUtils.tsx similarity index 100% rename from src/test/test-utils.tsx rename to src/test/testUtils.tsx