Skip to content

Commit 000bbb7

Browse files
committed
readme and contributions
1 parent 78e4dc5 commit 000bbb7

File tree

2 files changed

+0
-262
lines changed

2 files changed

+0
-262
lines changed

CONTRIBUTIONS.md

Lines changed: 0 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -1,137 +0,0 @@
1-
# Contributing to React SearchBar Component
2-
3-
Thank you for considering contributing to the **Type Search Api**! We welcome contributions from the community and appreciate your interest in improving this project.
4-
5-
## How to Contribute
6-
7-
There are several ways you can contribute to this project:
8-
9-
1. **Report Bugs**
10-
2. **Suggest Features**
11-
3. **Fix Bugs or Implement Features**
12-
4. **Update Documentation**
13-
5. **Improve Tests**
14-
15-
## Prerequisites
16-
17-
Before you start, make sure you have the following installed:
18-
19-
- [Node.js](https://nodejs.org/) (LTS version recommended)
20-
- [npm](https://www.npmjs.com/) (comes with Node.js)
21-
22-
If you're new to this project, fork the repository and clone your fork to your local machine:
23-
24-
```bash
25-
# Fork the repository on GitHub and clone it
26-
git clone https://github.com/YOUR-USERNAME/react-searchbar-component.git
27-
cd react-searchbar-component
28-
```
29-
30-
## Setting Up the Development Environment
31-
32-
1. Install dependencies:
33-
34-
```bash
35-
npm install
36-
```
37-
38-
2. Start the development server:
39-
40-
```bash
41-
npm start
42-
```
43-
44-
This will run the app in development mode. Open `http://localhost:3000` to view the project.
45-
46-
3. To run tests:
47-
48-
```bash
49-
npm test
50-
```
51-
52-
## Making Changes
53-
54-
1. **Create a new branch**:
55-
Always create a new branch for your changes. Use a descriptive name for the branch that reflects the feature or bug you're working on.
56-
57-
```bash
58-
git checkout -b feature-name
59-
```
60-
61-
2. **Make your changes**:
62-
Edit the necessary files, and follow the existing code style and conventions.
63-
64-
3. **Write tests** (if applicable):
65-
If your change involves new functionality or fixes a bug, please add tests. We use [Jest](https://jestjs.io/) for testing, and it's important to ensure that your changes are covered by tests.
66-
67-
4. **Commit your changes**:
68-
Commit your changes with a clear, concise message that explains the purpose of your modification.
69-
70-
```bash
71-
git add .
72-
git commit -m "Add feature XYZ"
73-
```
74-
75-
5. **Push your changes**:
76-
Push your branch to your forked repository.
77-
78-
```bash
79-
git push origin feature-name
80-
```
81-
82-
6. **Open a Pull Request**:
83-
Go to the [GitHub repository](https://github.com/YOUR-USERNAME/react-searchbar-component) and open a pull request (PR). Describe the changes you've made and the reason for them.
84-
85-
## Code Style
86-
87-
To ensure a consistent code style throughout the project, please follow these guidelines:
88-
89-
- Use **ESLint** and **Prettier** for linting and formatting (both are set up in this project).
90-
- Use **TypeScript** for type safety.
91-
- Follow the established pattern of functional components and hooks.
92-
- Keep code clean and well-commented.
93-
94-
## Writing Tests
95-
96-
The project uses [Jest](https://jestjs.io/) for testing. If you are adding new features or fixing bugs, please write tests to cover those changes.
97-
98-
- **Unit tests**: For testing individual functions or components.
99-
- **Integration tests**: For testing how components work together.
100-
101-
To run tests:
102-
103-
```bash
104-
npm test
105-
```
106-
107-
## Commit Messages
108-
109-
We follow the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) convention for commit messages. This makes it easier to generate changelogs and understand the history of the project.
110-
111-
Example commit message format:
112-
113-
- **feat**: Add new search result feature
114-
- **fix**: Fix error handling in search results
115-
- **docs**: Update documentation for new features
116-
- **chore**: Update dependencies
117-
118-
## Reporting Issues
119-
120-
If you find a bug or issue, please report it by opening a new issue in the [Issues section](https://github.com/YOUR-USERNAME/react-searchbar-component/issues) of the repository. When submitting an issue, please provide:
121-
122-
- A clear description of the problem.
123-
- Steps to reproduce the issue.
124-
- Expected vs. actual behavior.
125-
- Any relevant error messages or logs.
126-
127-
## Code of Conduct
128-
129-
By participating in this project, you agree to adhere to our [Code of Conduct](CODE_OF_CONDUCT.md). We expect all contributors to treat others with respect and kindness.
130-
131-
## License
132-
133-
By contributing to this project, you agree that your contributions will be licensed under the project’s [MIT License](LICENSE).
134-
135-
---
136-
137-
Thank you for contributing! Together, we can make the **React SearchBar Component** even better. 🚀

README.md

Lines changed: 0 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -1,125 +0,0 @@
1-
# React SearchBar Component
2-
3-
A highly customizable, debounce-enabled, and fully-featured React SearchBar component designed to fetch and display search results asynchronously. Ideal for scenarios where the search query is used to fetch data from APIs or databases, with built-in support for loading, error handling, and no-result states.
4-
5-
## Features
6-
7-
- **Debounced Search**: Customizable debounce delay to prevent excessive API calls while typing.
8-
- **Loading & Error States**: Display loading spinners or error messages while fetching data.
9-
- **Dropdown Menu**: A dropdown menu that displays search results, with full control over its visibility.
10-
- **Customizable Styles**: Easily apply custom styles to the container, input field, results list, items, and icons.
11-
- **Flexible Data Fetching**: Works with any asynchronous data-fetching method.
12-
- **TypeScript Support**: Fully typed for better development experience and safety.
13-
14-
## Installation
15-
16-
```bash
17-
npm install type-search-api
18-
```
19-
20-
or
21-
22-
```bash
23-
yarn add type-search-api
24-
```
25-
26-
## Usage
27-
28-
```tsx
29-
import React, { useState } from 'react';
30-
import SearchBar from 'react-searchbar-component';
31-
32-
const MyComponent = () => {
33-
const [selectedItem, setSelectedItem] = useState(null);
34-
35-
const fetchSearchResults = async (query: string) => {
36-
const response = await fetch(\`https://api.example.com/search?q=\${query}\`);
37-
const data = await response.json();
38-
return data.results; // return an array of results
39-
};
40-
41-
const renderSearchResult = (item: any) => <div>{item.name}</div>;
42-
43-
const handleItemSelect = (item: any) => {
44-
setSelectedItem(item);
45-
};
46-
47-
return (
48-
<div>
49-
<SearchBar
50-
fetchData={fetchSearchResults}
51-
renderItem={renderSearchResult}
52-
onSelect={handleItemSelect}
53-
placeholder="Search for items..."
54-
debounceDelay={300}
55-
/>
56-
{selectedItem && <div>You selected: {selectedItem.name}</div>}
57-
</div>
58-
);
59-
};
60-
61-
export default MyComponent;
62-
```
63-
64-
## Props
65-
66-
| Prop | Type | Description | Default Value |
67-
| --------------------- | --------------------------------- | ---------------------------------------------------------- | --------------------------------- |
68-
| `placeholder` | `string` | Placeholder text for the input field. | `'Search...'` |
69-
| `fetchData` | `(query: string) => Promise<T[]>` | A function that fetches data based on the search query. | N/A |
70-
| `renderItem` | `(item: T) => JSX.Element` | A function to render each search result item. | N/A |
71-
| `onSelect` | `(item: T) => void` | A callback function triggered when a user selects an item. | `undefined` |
72-
| `loadingElement` | `JSX.Element` | JSX to display while results are loading. | `<div>Loading...</div>` |
73-
| `emptyElement` | `JSX.Element` | JSX to display when no results are found. | `<div>No results found</div>` |
74-
| `errorElement` | `JSX.Element` | JSX to display when an error occurs. | `<div>Something went wrong</div>` |
75-
| `debounceDelay` | `number` | The debounce delay in milliseconds. | `500` |
76-
| `containerClassName` | `string` | Custom class for the search bar container. | `undefined` |
77-
| `inputClassName` | `string` | Custom class for the input field. | `undefined` |
78-
| `dropdownClassName` | `string` | Custom class for the dropdown containing search results. | `undefined` |
79-
| `itemClassName` | `string` | Custom class for each search result item. | `undefined` |
80-
| `hideSearchIcon` | `boolean` | Whether to hide the search icon. | `false` |
81-
| `searchIconClassName` | `string` | Custom class for the search icon. | `undefined` |
82-
| `closeIconClassName` | `string` | Custom class for the close icon. | `undefined` |
83-
84-
## Example
85-
86-
### Basic Example
87-
88-
```tsx
89-
<SearchBar
90-
fetchData={async (query: string) => {
91-
const response = await fetch(\`https://api.example.com/search?q=\${query}\`);
92-
return response.json();
93-
}}
94-
renderItem={(item) => <div>{item.name}</div>}
95-
onSelect={(item) => console.log('Selected:', item)}
96-
placeholder="Search for items..."
97-
loadingElement={<div>Loading...</div>}
98-
emptyElement={<div>No results found</div>}
99-
/>
100-
```
101-
102-
### Customizing the Appearance
103-
104-
You can customize the appearance of the search bar using the following props:
105-
106-
- `containerClassName`
107-
- `inputClassName`
108-
- `dropdownClassName`
109-
- `itemClassName`
110-
- `searchIconClassName`
111-
- `closeIconClassName`
112-
113-
These props allow you to apply your custom styles or use CSS modules.
114-
115-
## License
116-
117-
MIT License. © Karl 2024
118-
119-
## Contributing
120-
121-
We welcome contributions to the project. Please fork the repository, create a new branch, make your changes, and open a pull request.
122-
123-
---
124-
125-
**Note**: This component uses TypeScript and provides full type safety. It can be easily integrated into any TypeScript or JavaScript-based React project.

0 commit comments

Comments
 (0)