@jetshop/ui 5.12.4 → 5.13.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/Pagination/Pagination.js +6 -21
- package/Pagination/Pagination.js.map +1 -1
- package/Pagination/usePagination.d.ts +15 -0
- package/Pagination/usePagination.js +46 -0
- package/Pagination/usePagination.js.map +1 -0
- package/fuzzySearch/fuzzySearch.d.ts +1 -11
- package/fuzzySearch/fuzzySearch.js +1 -1
- package/fuzzySearch/fuzzySearch.js.map +1 -1
- package/package.json +1 -1
package/Pagination/Pagination.js
CHANGED
|
@@ -1,38 +1,23 @@
|
|
|
1
|
-
import PaginationContext from '@jetshop/core/components/Pagination/PaginationContext';
|
|
2
1
|
import formatMessage from '@jetshop/intl';
|
|
3
2
|
import { styled } from 'linaria/react';
|
|
4
|
-
import qs from 'qs';
|
|
5
3
|
import * as React from 'react';
|
|
6
|
-
import
|
|
4
|
+
import usePagination from './usePagination';
|
|
7
5
|
export const PaginationWrapper = styled('div') `
|
|
8
6
|
display: flex;
|
|
9
7
|
width: 100%;
|
|
10
8
|
justify-content: space-between;
|
|
11
9
|
align-items: center;
|
|
12
10
|
`;
|
|
13
|
-
const Pagination = (
|
|
14
|
-
const {
|
|
15
|
-
const
|
|
16
|
-
const currentLocation = qs.parse(typeof window === 'undefined' ? location.search : window.location.search, {
|
|
17
|
-
ignoreQueryPrefix: true
|
|
18
|
-
});
|
|
19
|
-
const nextHref = location.pathname +
|
|
20
|
-
qs.stringify(Object.assign(Object.assign({}, currentLocation), { [queryParam]: isLastPage ? currentPage : currentPage + 1 }), { addQueryPrefix: true, encodeValuesOnly: true, skipNulls: true });
|
|
21
|
-
const prevHref = location.pathname +
|
|
22
|
-
qs.stringify(Object.assign(Object.assign({}, currentLocation), { [queryParam]: isFirstPage ? currentPage : currentPage - 1 }), { addQueryPrefix: true, encodeValuesOnly: true, skipNulls: true });
|
|
11
|
+
const Pagination = (props) => {
|
|
12
|
+
const { hasPages, totalPages, className, currentPage } = props;
|
|
13
|
+
const { prevHref, nextHref, prevOnClick, nextOnClick, isPrevDisabled, isNextDisabled } = usePagination(props);
|
|
23
14
|
return hasPages && !isNaN(totalPages) ? (React.createElement(PaginationWrapper, { className: className },
|
|
24
|
-
React.createElement("a", { href: prevHref, onClick: (
|
|
25
|
-
e.preventDefault();
|
|
26
|
-
prevPage();
|
|
27
|
-
}, "data-disabled": isFirstPage ? true : null }, formatMessage('Prev')),
|
|
15
|
+
React.createElement("a", { href: prevHref, onClick: prevOnClick, "data-disabled": isPrevDisabled }, formatMessage('Prev')),
|
|
28
16
|
React.createElement("div", null, formatMessage(`Page {currentPage} of {totalPages}`, {
|
|
29
17
|
currentPage,
|
|
30
18
|
totalPages
|
|
31
19
|
})),
|
|
32
|
-
React.createElement("a", { href: nextHref, onClick: (
|
|
33
|
-
e.preventDefault();
|
|
34
|
-
nextPage();
|
|
35
|
-
}, "data-disabled": isLastPage ? true : null }, formatMessage('Next')))) : null;
|
|
20
|
+
React.createElement("a", { href: nextHref, onClick: nextOnClick, "data-disabled": isNextDisabled }, formatMessage('Next')))) : null;
|
|
36
21
|
};
|
|
37
22
|
export default Pagination;
|
|
38
23
|
//# sourceMappingURL=Pagination.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Pagination.js","sourceRoot":"","sources":["Pagination.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"Pagination.js","sourceRoot":"","sources":["Pagination.tsx"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,eAAe,CAAC;AAE1C,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAE5C,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA;;;;;CAK7C,CAAC;AAEF,MAAM,UAAU,GAA8C,CAAC,KAAK,EAAE,EAAE;IACtE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,GAAG,KAAK,CAAC;IAE/D,MAAM,EACJ,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,WAAW,EACX,cAAc,EACd,cAAc,EACf,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;IAEzB,OAAO,QAAQ,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CACtC,oBAAC,iBAAiB,IAAC,SAAS,EAAE,SAAS;QACrC,2BAAG,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,WAAW,mBAAiB,cAAc,IACnE,aAAa,CAAC,MAAM,CAAC,CACpB;QACJ,iCACG,aAAa,CAAC,oCAAoC,EAAE;YACnD,WAAW;YACX,UAAU;SACX,CAAC,CACE;QACN,2BAAG,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,WAAW,mBAAiB,cAAc,IACnE,aAAa,CAAC,MAAM,CAAC,CACpB,CACc,CACrB,CAAC,CAAC,CAAC,IAAI,CAAC;AACX,CAAC,CAAC;AAEF,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PaginationBehaviourRenderProps } from '@jetshop/ui/Pagination/PaginationBehaviour';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
export declare const PaginationWrapper: import("linaria/lib/StyledMeta").StyledMeta & React.FunctionComponent<React.ClassAttributes<HTMLDivElement> & React.HTMLAttributes<HTMLDivElement> & {
|
|
4
|
+
as?: React.ElementType<any>;
|
|
5
|
+
}>;
|
|
6
|
+
declare function usePagination({ prevPage, nextPage, currentPage, isFirstPage, isLastPage }: Partial<PaginationBehaviourRenderProps>): {
|
|
7
|
+
prevHref: string;
|
|
8
|
+
nextHref: string;
|
|
9
|
+
goToHref: (page: number) => string;
|
|
10
|
+
prevOnClick: (e: React.MouseEvent<HTMLElement>) => void;
|
|
11
|
+
nextOnClick: (e: React.MouseEvent<HTMLElement>) => void;
|
|
12
|
+
isPrevDisabled: boolean;
|
|
13
|
+
isNextDisabled: boolean;
|
|
14
|
+
};
|
|
15
|
+
export default usePagination;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import PaginationContext from '@jetshop/core/components/Pagination/PaginationContext';
|
|
2
|
+
import { styled } from 'linaria/react';
|
|
3
|
+
import qs from 'qs';
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import { useLocation } from 'react-router';
|
|
6
|
+
export const PaginationWrapper = styled('div') `
|
|
7
|
+
display: flex;
|
|
8
|
+
width: 100%;
|
|
9
|
+
justify-content: space-between;
|
|
10
|
+
align-items: center;
|
|
11
|
+
`;
|
|
12
|
+
function usePagination({ prevPage, nextPage, currentPage, isFirstPage, isLastPage }) {
|
|
13
|
+
const { queryParam } = React.useContext(PaginationContext);
|
|
14
|
+
const location = useLocation();
|
|
15
|
+
const currentLocation = qs.parse(typeof window === 'undefined' ? location.search : window.location.search, {
|
|
16
|
+
ignoreQueryPrefix: true
|
|
17
|
+
});
|
|
18
|
+
const nextHref = location.pathname +
|
|
19
|
+
qs.stringify(Object.assign(Object.assign({}, currentLocation), { [queryParam]: isLastPage ? currentPage : currentPage + 1 }), { addQueryPrefix: true, encodeValuesOnly: true, skipNulls: true });
|
|
20
|
+
const prevHref = location.pathname +
|
|
21
|
+
qs.stringify(Object.assign(Object.assign({}, currentLocation), { [queryParam]: isFirstPage ? currentPage : currentPage - 1 }), { addQueryPrefix: true, encodeValuesOnly: true, skipNulls: true });
|
|
22
|
+
const goToHref = (page) => {
|
|
23
|
+
const href = location.pathname +
|
|
24
|
+
qs.stringify(Object.assign(Object.assign({}, currentLocation), { [queryParam]: page }), { addQueryPrefix: true, encodeValuesOnly: true, skipNulls: true });
|
|
25
|
+
return href;
|
|
26
|
+
};
|
|
27
|
+
function prevOnClick(e) {
|
|
28
|
+
e.preventDefault();
|
|
29
|
+
prevPage();
|
|
30
|
+
}
|
|
31
|
+
function nextOnClick(e) {
|
|
32
|
+
e.preventDefault();
|
|
33
|
+
nextPage();
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
prevHref,
|
|
37
|
+
nextHref,
|
|
38
|
+
goToHref,
|
|
39
|
+
prevOnClick,
|
|
40
|
+
nextOnClick,
|
|
41
|
+
isPrevDisabled: isFirstPage ? true : null,
|
|
42
|
+
isNextDisabled: isLastPage ? true : null
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export default usePagination;
|
|
46
|
+
//# sourceMappingURL=usePagination.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePagination.js","sourceRoot":"","sources":["usePagination.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,MAAM,uDAAuD,CAAC;AAEtF,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA;;;;;CAK7C,CAAC;AAEF,SAAS,aAAa,CAAC,EACrB,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,WAAW,EACX,UAAU,EAC8B;IACxC,MAAM,EAAE,UAAU,EAAE,GAAG,KAAK,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC;IAC3D,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAC;IAE/B,MAAM,eAAe,GAAG,EAAE,CAAC,KAAK,CAC9B,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,EACxE;QACE,iBAAiB,EAAE,IAAI;KACxB,CACF,CAAC;IAEF,MAAM,QAAQ,GACZ,QAAQ,CAAC,QAAQ;QACjB,EAAE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C,CAAC;AACJ,CAAC;AAED,eAAe,aAAa,CAAC"}
|
|
@@ -1,18 +1,8 @@
|
|
|
1
|
-
interface Match {
|
|
2
|
-
arrayIndex: number;
|
|
3
|
-
indices: [number, number][];
|
|
4
|
-
key: string;
|
|
5
|
-
value: string;
|
|
6
|
-
}
|
|
7
|
-
interface Result<T> {
|
|
8
|
-
item: T;
|
|
9
|
-
matches: Match[];
|
|
10
|
-
}
|
|
11
1
|
export interface FuzzySearchProps<T> {
|
|
12
2
|
data: T[];
|
|
13
3
|
keys: string[];
|
|
14
4
|
searchTerm: string;
|
|
15
5
|
rest: any;
|
|
16
6
|
}
|
|
17
|
-
declare const fuzzySearch: <T>({ data, keys, searchTerm, ...rest }: FuzzySearchProps<T>) =>
|
|
7
|
+
declare const fuzzySearch: <T>({ data, keys, searchTerm, ...rest }: FuzzySearchProps<T>) => T[];
|
|
18
8
|
export { fuzzySearch };
|
|
@@ -28,7 +28,7 @@ const highlight = (text, indices) => {
|
|
|
28
28
|
return content;
|
|
29
29
|
};
|
|
30
30
|
const highlightResults = (results) => {
|
|
31
|
-
return results.map(result => (Object.assign(Object.assign({}, result.item), result.matches.reduce((acc, match) => (Object.assign(Object.assign({}, acc), { [match.key]: highlight(match.value, match.indices) })), {}))));
|
|
31
|
+
return results.map((result) => (Object.assign(Object.assign({}, result.item), result.matches.reduce((acc, match) => (Object.assign(Object.assign({}, acc), { [match.key]: highlight(match.value, match.indices) })), {}))));
|
|
32
32
|
};
|
|
33
33
|
const fuzzySearch = (_a) => {
|
|
34
34
|
var { data, keys, searchTerm } = _a, rest = __rest(_a, ["data", "keys", "searchTerm"]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fuzzySearch.js","sourceRoot":"","sources":["fuzzySearch.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,IAAoB,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"fuzzySearch.js","sourceRoot":"","sources":["fuzzySearch.ts"],"names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