@ttoss/components 1.29.31 → 1.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -1
- package/dist/esm/index.js +28 -1
- package/dist/index.d.ts +9 -2
- package/package.json +3 -1
- package/src/components/Search.tsx +36 -0
- package/src/index.ts +1 -0
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908
|
|
|
13
13
|
### Install @ttoss/components
|
|
14
14
|
|
|
15
15
|
```shell
|
|
16
|
-
pnpm add @ttoss/components @ttoss/ui @emotion/react
|
|
16
|
+
pnpm add @ttoss/components @ttoss/ui @emotion/react @ttoss/react-hooks
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
## Components
|
|
@@ -121,3 +121,37 @@ const Component = () => {
|
|
|
121
121
|
);
|
|
122
122
|
};
|
|
123
123
|
```
|
|
124
|
+
|
|
125
|
+
### Search
|
|
126
|
+
|
|
127
|
+
`Search` is a component that integrates an input field with debouncing functionality, making it ideal for search bars where you want to limit the rate of search queries based on user input.
|
|
128
|
+
|
|
129
|
+
It uses the `useDebounce` hook from `@ttoss/react-hooks` to delay the search action until the user has stopped typing for a specified duration, which helps to prevent unnecessary or excessive queries.
|
|
130
|
+
|
|
131
|
+
```tsx
|
|
132
|
+
import React, { useState } from 'react';
|
|
133
|
+
import { Search } from '@ttoss/components';
|
|
134
|
+
import { Box } from '@ttoss/ui';
|
|
135
|
+
|
|
136
|
+
const SearchComponent = () => {
|
|
137
|
+
const [searchText, setSearchText] = useState('');
|
|
138
|
+
|
|
139
|
+
const handleSearchChange = (newValue) => {
|
|
140
|
+
setSearchText(newValue);
|
|
141
|
+
// Perform search or update logic here
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
return (
|
|
145
|
+
<Box>
|
|
146
|
+
<Search
|
|
147
|
+
value={searchText}
|
|
148
|
+
onChange={handleSearchChange}
|
|
149
|
+
loading={/* loading state here */}
|
|
150
|
+
debounce={500} // Adjust the debounce time as needed
|
|
151
|
+
/>
|
|
152
|
+
</Box>
|
|
153
|
+
);
|
|
154
|
+
};
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
In this example, the `Search` component receives the current search text and a handler function to update this text. The `loading` prop can be used to display a loading indicator, and the `debounce` prop controls the debounce delay.
|
package/dist/esm/index.js
CHANGED
|
@@ -232,4 +232,31 @@ var Markdown = ({
|
|
|
232
232
|
})
|
|
233
233
|
});
|
|
234
234
|
};
|
|
235
|
-
|
|
235
|
+
|
|
236
|
+
// src/components/Search.tsx
|
|
237
|
+
import * as React4 from "react";
|
|
238
|
+
import { Input } from "@ttoss/ui";
|
|
239
|
+
import { useDebounce } from "@ttoss/react-hooks";
|
|
240
|
+
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
241
|
+
var Search = ({
|
|
242
|
+
value,
|
|
243
|
+
defaultValue,
|
|
244
|
+
loading,
|
|
245
|
+
onChange,
|
|
246
|
+
...props
|
|
247
|
+
}) => {
|
|
248
|
+
const [text, setText] = React4.useState(value ?? defaultValue);
|
|
249
|
+
const debouncedValue = useDebounce(text, 500);
|
|
250
|
+
React4.useEffect(() => {
|
|
251
|
+
onChange(debouncedValue);
|
|
252
|
+
}, [debouncedValue]);
|
|
253
|
+
return /* @__PURE__ */jsx6(Input, {
|
|
254
|
+
leadingIcon: loading ? "loading" : "search",
|
|
255
|
+
value: text,
|
|
256
|
+
onChange: e => {
|
|
257
|
+
return setText(e.target.value);
|
|
258
|
+
},
|
|
259
|
+
...props
|
|
260
|
+
});
|
|
261
|
+
};
|
|
262
|
+
export { Accordion, InstallPwa, InstallPwaUi, Markdown, Modal, Search, ToastContainer, toast };
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import * as react_accessible_accordion_dist_types_components_ItemContext from 'r
|
|
|
3
3
|
import * as react_accessible_accordion_dist_types_helpers_types from 'react-accessible-accordion/dist/types/helpers/types';
|
|
4
4
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
5
5
|
import * as React from 'react';
|
|
6
|
-
import { BoxProps, FlexProps } from '@ttoss/ui';
|
|
6
|
+
import { BoxProps, FlexProps, InputProps } from '@ttoss/ui';
|
|
7
7
|
import ReactModal from 'react-modal';
|
|
8
8
|
import { ToastContainerProps } from 'react-toastify';
|
|
9
9
|
export { ToastContainerProps, toast } from 'react-toastify';
|
|
@@ -319,4 +319,11 @@ type MarkdownProps = Options & {
|
|
|
319
319
|
};
|
|
320
320
|
declare const Markdown: ({ children, sx, ...props }: MarkdownProps) => react_jsx_runtime.JSX.Element;
|
|
321
321
|
|
|
322
|
-
|
|
322
|
+
type SearchProps = Omit<InputProps, 'onChange'> & {
|
|
323
|
+
loading?: boolean;
|
|
324
|
+
debounce?: number;
|
|
325
|
+
onChange: (value?: InputProps['value']) => void;
|
|
326
|
+
};
|
|
327
|
+
declare const Search: ({ value, defaultValue, loading, onChange, ...props }: SearchProps) => react_jsx_runtime.JSX.Element;
|
|
328
|
+
|
|
329
|
+
export { Accordion, type AccordionProps, InstallPwa, InstallPwaUi, type InstallPwaUiProps, Markdown, type MarkdownProps, Modal, type ModalProps, Search, type SearchProps, ToastContainer };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/components",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.30.0",
|
|
4
4
|
"description": "React components for ttoss ecosystem.",
|
|
5
5
|
"author": "ttoss",
|
|
6
6
|
"contributors": [
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"react": ">=16.8.0",
|
|
39
|
+
"@ttoss/react-hooks": "^1.25.1",
|
|
39
40
|
"@ttoss/ui": "^4.0.7"
|
|
40
41
|
},
|
|
41
42
|
"devDependencies": {
|
|
@@ -44,6 +45,7 @@
|
|
|
44
45
|
"jest": "^29.7.0",
|
|
45
46
|
"tsup": "^8.0.1",
|
|
46
47
|
"@ttoss/config": "^1.31.4",
|
|
48
|
+
"@ttoss/react-hooks": "^1.25.1",
|
|
47
49
|
"@ttoss/test-utils": "^2.0.4",
|
|
48
50
|
"@ttoss/ui": "^4.0.7"
|
|
49
51
|
},
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Input, type InputProps } from '@ttoss/ui';
|
|
3
|
+
import { useDebounce } from '@ttoss/react-hooks';
|
|
4
|
+
|
|
5
|
+
export type SearchProps = Omit<InputProps, 'onChange'> & {
|
|
6
|
+
loading?: boolean;
|
|
7
|
+
debounce?: number;
|
|
8
|
+
onChange: (value?: InputProps['value']) => void;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const Search = ({
|
|
12
|
+
value,
|
|
13
|
+
defaultValue,
|
|
14
|
+
loading,
|
|
15
|
+
onChange,
|
|
16
|
+
...props
|
|
17
|
+
}: SearchProps) => {
|
|
18
|
+
const [text, setText] = React.useState(value ?? defaultValue);
|
|
19
|
+
|
|
20
|
+
const debouncedValue = useDebounce(text, 500);
|
|
21
|
+
|
|
22
|
+
React.useEffect(() => {
|
|
23
|
+
onChange(debouncedValue);
|
|
24
|
+
}, [debouncedValue]);
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<Input
|
|
28
|
+
leadingIcon={loading ? 'loading' : 'search'}
|
|
29
|
+
value={text}
|
|
30
|
+
onChange={(e) => {
|
|
31
|
+
return setText(e.target.value);
|
|
32
|
+
}}
|
|
33
|
+
{...props}
|
|
34
|
+
/>
|
|
35
|
+
);
|
|
36
|
+
};
|
package/src/index.ts
CHANGED