@nextelco/common-ui 1.7.50 → 1.7.52
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/dist/bundle.js +1 -1
- package/dist/types/components/organisms/LazyLoader/LazyLoader.d.ts +18 -0
- package/dist/types/components/organisms/Profile/Profile.d.ts +2 -2
- package/dist/types/components/organisms/Selector/Selector.d.ts +4 -0
- package/dist/types/exports/organisms.d.ts +2 -1
- package/package.json +1 -1
- package/dist/types/components/organisms/LazyLoading/LazyLoading.d.ts +0 -77
@@ -0,0 +1,18 @@
|
|
1
|
+
import React, { ReactNode } from 'react';
|
2
|
+
interface LazyLoaderProps<T> {
|
3
|
+
endpoint: string;
|
4
|
+
params?: Record<string, unknown>;
|
5
|
+
children: (items: T[], loading: boolean, error: ReactNode | null) => ReactNode;
|
6
|
+
scrollableTarget?: string;
|
7
|
+
className?: string;
|
8
|
+
style?: React.CSSProperties;
|
9
|
+
height?: number | string;
|
10
|
+
scrollThreshold?: number | string;
|
11
|
+
pageSize?: number;
|
12
|
+
initialPage?: number;
|
13
|
+
responseType?: 'blob';
|
14
|
+
}
|
15
|
+
export declare const LazyLoader: <T extends {
|
16
|
+
id: string | number;
|
17
|
+
}>({ endpoint, params, children, scrollableTarget, className, style, height, scrollThreshold, pageSize, initialPage, responseType, }: LazyLoaderProps<T>) => React.JSX.Element;
|
18
|
+
export {};
|
@@ -6,5 +6,5 @@ type Props = {
|
|
6
6
|
handleLogout: () => void;
|
7
7
|
notifications?: ReactNode;
|
8
8
|
};
|
9
|
-
declare const Profile: ({ user, handleLogout, notifications }: Props) => React.JSX.Element;
|
10
|
-
export
|
9
|
+
export declare const Profile: ({ user, handleLogout, notifications }: Props) => React.JSX.Element;
|
10
|
+
export {};
|
@@ -1 +1,2 @@
|
|
1
|
-
export {
|
1
|
+
export { Profile } from '../components/organisms/Profile/Profile';
|
2
|
+
export { LazyLoader } from '../components/organisms/LazyLoader/LazyLoader';
|
package/package.json
CHANGED
@@ -1,77 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
import React, { useEffect } from 'react'
|
3
|
-
import InfiniteScroll from 'react-infinite-scroll-component'
|
4
|
-
import { useApi } from '../../../hooks/useApi'
|
5
|
-
|
6
|
-
interface LazyLoadListProps {
|
7
|
-
items: any[]
|
8
|
-
setItems: (items: any[]) => void
|
9
|
-
page: number
|
10
|
-
limit: number
|
11
|
-
setPage: (page: number) => void
|
12
|
-
hasMore: boolean
|
13
|
-
setHasMore: (hasMore: boolean) => void
|
14
|
-
filters: { [key: string]: string }
|
15
|
-
}
|
16
|
-
|
17
|
-
const LazyLoadList: React.FC<LazyLoadListProps> = ({
|
18
|
-
items,
|
19
|
-
setItems,
|
20
|
-
page,
|
21
|
-
limit,
|
22
|
-
setPage,
|
23
|
-
hasMore,
|
24
|
-
setHasMore,
|
25
|
-
filters,
|
26
|
-
}) => {
|
27
|
-
const { request, errors, loading } = useApi()
|
28
|
-
|
29
|
-
const fetchData = async (pageNum: number) => {
|
30
|
-
const response = await request({
|
31
|
-
method: 'get',
|
32
|
-
url: `/api/items`,
|
33
|
-
params: { page: pageNum, limit, ...filters },
|
34
|
-
})
|
35
|
-
|
36
|
-
if (response) {
|
37
|
-
if (response.length === 0) {
|
38
|
-
setHasMore(false)
|
39
|
-
return
|
40
|
-
}
|
41
|
-
setItems([...items, ...response])
|
42
|
-
}
|
43
|
-
}
|
44
|
-
|
45
|
-
useEffect(() => {
|
46
|
-
fetchData(page)
|
47
|
-
}, [page, filters])
|
48
|
-
|
49
|
-
const loadMore = () => {
|
50
|
-
setPage(page + 1)
|
51
|
-
}
|
52
|
-
|
53
|
-
return (
|
54
|
-
<div>
|
55
|
-
{errors && errors}
|
56
|
-
<InfiniteScroll
|
57
|
-
dataLength={items.length}
|
58
|
-
next={loadMore}
|
59
|
-
hasMore={hasMore}
|
60
|
-
loader={<h4>Loading...</h4>}
|
61
|
-
endMessage={<p>No more items to load</p>}
|
62
|
-
>
|
63
|
-
{items.map((item, index) => (
|
64
|
-
<div
|
65
|
-
key={index}
|
66
|
-
style={{ padding: '20px', borderBottom: '1px solid #ccc' }}
|
67
|
-
>
|
68
|
-
{item.name || `Item ${index}`}{' '}
|
69
|
-
</div>
|
70
|
-
))}
|
71
|
-
</InfiniteScroll>
|
72
|
-
</div>
|
73
|
-
)
|
74
|
-
}
|
75
|
-
|
76
|
-
export default LazyLoadList
|
77
|
-
*/
|