@codeleap/mobile 4.2.4 → 4.2.6
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/components/SectionFilters/context.d.ts +46 -0
- package/dist/components/SectionFilters/context.js +10 -0
- package/dist/components/SectionFilters/context.js.map +1 -0
- package/dist/components/SectionFilters/index.d.ts +10 -0
- package/dist/components/SectionFilters/index.js +84 -0
- package/dist/components/SectionFilters/index.js.map +1 -0
- package/dist/components/SectionFilters/types.d.ts +19 -0
- package/dist/components/SectionFilters/types.js +3 -0
- package/dist/components/SectionFilters/types.js.map +1 -0
- package/dist/components/SectionFilters/useSectionFilters.d.ts +35 -0
- package/dist/components/SectionFilters/useSectionFilters.js +133 -0
- package/dist/components/SectionFilters/useSectionFilters.js.map +1 -0
- package/dist/components/Sections/index.d.ts +11 -3
- package/dist/components/Sections/index.js +54 -38
- package/dist/components/Sections/index.js.map +1 -1
- package/dist/components/Sections/styles.d.ts +5 -1
- package/dist/components/Sections/types.d.ts +26 -12
- package/dist/components/components.d.ts +1 -0
- package/dist/components/components.js +1 -0
- package/dist/components/components.js.map +1 -1
- package/package.json +5 -5
- package/package.json.bak +1 -1
- package/src/components/SectionFilters/context.tsx +15 -0
- package/src/components/SectionFilters/index.tsx +80 -0
- package/src/components/SectionFilters/types.ts +29 -0
- package/src/components/SectionFilters/useSectionFilters.tsx +166 -0
- package/src/components/Sections/index.tsx +99 -57
- package/src/components/Sections/styles.ts +6 -1
- package/src/components/Sections/types.ts +33 -16
- package/src/components/components.ts +1 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { SectionFiltersProps } from './types';
|
|
3
|
+
import { TSectionFilterItem, useSectionFilters } from './useSectionFilters';
|
|
4
|
+
export type SectionFiltersContextProps<T = TSectionFilterItem> = React.PropsWithChildren<SectionFiltersProps<T> & {
|
|
5
|
+
handle?: ReturnType<typeof useSectionFilters<T>>;
|
|
6
|
+
}>;
|
|
7
|
+
export declare const SectionsFilterContext: import("react").Context<{
|
|
8
|
+
isSelected: (item: TSectionFilterItem) => boolean;
|
|
9
|
+
toggleItem: (item: TSectionFilterItem) => void;
|
|
10
|
+
findItemSection: (item: TSectionFilterItem) => {
|
|
11
|
+
sectionIndex: number;
|
|
12
|
+
section: {
|
|
13
|
+
data: TSectionFilterItem[];
|
|
14
|
+
title: string;
|
|
15
|
+
selectionLimit?: number;
|
|
16
|
+
disableItemsOnLimitReached?: boolean;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
selectedItems: {
|
|
20
|
+
[X: number]: TSectionFilterItem[];
|
|
21
|
+
};
|
|
22
|
+
sectionLimitReached: (sectionIndex: number) => boolean;
|
|
23
|
+
limitReached: () => boolean;
|
|
24
|
+
disableItemsOnLimitReached: boolean;
|
|
25
|
+
clearSelectedItemsWithSection: (sectionIndex: number) => void;
|
|
26
|
+
}>;
|
|
27
|
+
export declare function useSectionFiltersContext<T = TSectionFilterItem>(): {
|
|
28
|
+
isSelected: (item: T) => boolean;
|
|
29
|
+
toggleItem: (item: T) => void;
|
|
30
|
+
findItemSection: (item: T) => {
|
|
31
|
+
sectionIndex: number;
|
|
32
|
+
section: {
|
|
33
|
+
data: T[];
|
|
34
|
+
title: string;
|
|
35
|
+
selectionLimit?: number;
|
|
36
|
+
disableItemsOnLimitReached?: boolean;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
selectedItems: {
|
|
40
|
+
[X: number]: T[];
|
|
41
|
+
};
|
|
42
|
+
sectionLimitReached: (sectionIndex: number) => boolean;
|
|
43
|
+
limitReached: () => boolean;
|
|
44
|
+
disableItemsOnLimitReached: boolean;
|
|
45
|
+
clearSelectedItemsWithSection: (sectionIndex: number) => void;
|
|
46
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useSectionFiltersContext = exports.SectionsFilterContext = void 0;
|
|
4
|
+
var react_1 = require("react");
|
|
5
|
+
exports.SectionsFilterContext = (0, react_1.createContext)({});
|
|
6
|
+
function useSectionFiltersContext() {
|
|
7
|
+
return (0, react_1.useContext)(exports.SectionsFilterContext);
|
|
8
|
+
}
|
|
9
|
+
exports.useSectionFiltersContext = useSectionFiltersContext;
|
|
10
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../../src/components/SectionFilters/context.tsx"],"names":[],"mappings":";;;AAAA,+BAAiD;AAUpC,QAAA,qBAAqB,GAAG,IAAA,qBAAa,EAAC,EAA4B,CAAC,CAAA;AAEhF,SAAgB,wBAAwB;IACtC,OAAO,IAAA,kBAAU,EAAC,6BAAqB,CAA8B,CAAA;AACvE,CAAC;AAFD,4DAEC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { SectionFiltersProps } from './types';
|
|
3
|
+
import { TSectionFilterItem } from './useSectionFilters';
|
|
4
|
+
export * from './types';
|
|
5
|
+
export * from './context';
|
|
6
|
+
export * from './useSectionFilters';
|
|
7
|
+
export declare function SectionFilters<T extends TSectionFilterItem = TSectionFilterItem>(props: SectionFiltersProps<T>): JSX.Element;
|
|
8
|
+
export declare namespace SectionFilters {
|
|
9
|
+
var defaultProps: Partial<SectionFiltersProps>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}) : (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
o[k2] = m[k];
|
|
23
|
+
}));
|
|
24
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
25
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
26
|
+
};
|
|
27
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
28
|
+
var t = {};
|
|
29
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
30
|
+
t[p] = s[p];
|
|
31
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
32
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
33
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
34
|
+
t[p[i]] = s[p[i]];
|
|
35
|
+
}
|
|
36
|
+
return t;
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.SectionFilters = void 0;
|
|
40
|
+
var common_1 = require("@codeleap/common");
|
|
41
|
+
var Button_1 = require("../Button");
|
|
42
|
+
var Sections_1 = require("../Sections");
|
|
43
|
+
var Text_1 = require("../Text");
|
|
44
|
+
var context_1 = require("./context");
|
|
45
|
+
var useSectionFilters_1 = require("./useSectionFilters");
|
|
46
|
+
__exportStar(require("./types"), exports);
|
|
47
|
+
__exportStar(require("./context"), exports);
|
|
48
|
+
__exportStar(require("./useSectionFilters"), exports);
|
|
49
|
+
var SectionComponent = (0, common_1.memoBy)(function (props) {
|
|
50
|
+
var _a;
|
|
51
|
+
var Component = props.renderWith, index = props.index;
|
|
52
|
+
var handle = (0, context_1.useSectionFiltersContext)();
|
|
53
|
+
if (!Component)
|
|
54
|
+
return null;
|
|
55
|
+
return (<Component {...props} selectedItems={(_a = handle.selectedItems[index]) !== null && _a !== void 0 ? _a : []} clearSelectedItems={function () { return handle.clearSelectedItemsWithSection(index); }}/>);
|
|
56
|
+
}, ['renderWith']);
|
|
57
|
+
function SectionFilters(props) {
|
|
58
|
+
var _a;
|
|
59
|
+
var _b = __assign(__assign({}, SectionFilters.defaultProps), props), sections = _b.sections, RenderItem = _b.renderItem, renderSectionHeader = _b.renderSectionHeader, renderSectionFooter = _b.renderSectionFooter, rest = __rest(_b, ["sections", "renderItem", "renderSectionHeader", "renderSectionFooter"]);
|
|
60
|
+
var handle = (_a = props.handle) !== null && _a !== void 0 ? _a : (0, useSectionFilters_1.useSectionFilters)(props);
|
|
61
|
+
var renderItem = function (section) {
|
|
62
|
+
var _a;
|
|
63
|
+
var hasSection = !common_1.TypeGuards.isNil(section === null || section === void 0 ? void 0 : section.index) && !common_1.TypeGuards.isNil(section);
|
|
64
|
+
var sectionLimitReached = hasSection && handle.sectionLimitReached(section === null || section === void 0 ? void 0 : section.index);
|
|
65
|
+
var limitReached = handle.limitReached();
|
|
66
|
+
var disableOnReachLimit = handle.disableItemsOnLimitReached;
|
|
67
|
+
var disableNonSelectedItems = (limitReached || sectionLimitReached) && disableOnReachLimit;
|
|
68
|
+
var isSelected = handle.isSelected(section === null || section === void 0 ? void 0 : section.item);
|
|
69
|
+
var isDisabled = disableNonSelectedItems && !isSelected;
|
|
70
|
+
return (<RenderItem {...section} onPress={function () { return handle.toggleItem(section === null || section === void 0 ? void 0 : section.item); }} selected={isSelected} disabled={isDisabled} text={(_a = section === null || section === void 0 ? void 0 : section.item) === null || _a === void 0 ? void 0 : _a.label}/>);
|
|
71
|
+
};
|
|
72
|
+
return (<context_1.SectionsFilterContext.Provider value={handle}>
|
|
73
|
+
<Sections_1.Sections {...rest} sections={sections} renderItem={renderItem} renderSectionHeader={function (props) { return <SectionComponent {...props} renderWith={renderSectionHeader}/>; }} renderSectionFooter={function (props) { return <SectionComponent {...props} renderWith={renderSectionFooter}/>; }}/>
|
|
74
|
+
</context_1.SectionsFilterContext.Provider>);
|
|
75
|
+
}
|
|
76
|
+
exports.SectionFilters = SectionFilters;
|
|
77
|
+
SectionFilters.defaultProps = {
|
|
78
|
+
renderItem: Button_1.Button,
|
|
79
|
+
renderSectionHeader: function (_a) {
|
|
80
|
+
var title = _a.title;
|
|
81
|
+
return <Text_1.Text text={title}/>;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/SectionFilters/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAqD;AACrD,oCAAkC;AAClC,wCAA6F;AAC7F,gCAA8B;AAC9B,qCAA2E;AAE3E,yDAA2E;AAE3E,0CAAuB;AACvB,4CAAyB;AACzB,sDAAmC;AAEnC,IAAM,gBAAgB,GAAG,IAAA,eAAM,EAAC,UAAC,KAA0I;;IACjK,IAAY,SAAS,GAAY,KAAK,WAAjB,EAAE,KAAK,GAAK,KAAK,MAAV,CAAU;IAE9C,IAAM,MAAM,GAAG,IAAA,kCAAwB,GAAE,CAAA;IAEzC,IAAI,CAAC,SAAS;QAAE,OAAO,IAAI,CAAA;IAE3B,OAAO,CACL,CAAC,SAAS,CACR,IAAI,KAAK,CAAC,CACV,aAAa,CAAC,CAAC,MAAA,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,mCAAI,EAAE,CAAC,CACjD,kBAAkB,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AO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,CAAC,EAAhC,CAAgC,CAAC,CAChD,QAAQ,CAAC,CAAC,UAAU,CAAC,CACrB,QAAQ,CAAC,CAAC,UAAU,CAAC,CACrB,IAAI,CAAC,CAAC,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,0CAAE,KAAK,CAAC,EAC3B,CACH,CAAA;IACH,CAAC,CAAA;IAED,OAAO,CACL,CAAC,+BAAqB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAC5C;MAAA,CAAC,mBAAQ,CACP,IAAI,IAAI,CAAC,CACT,QAAQ,CAAC,CAAC,QAAQ,CAAC,CACnB,UAAU,CAAC,CAAC,UAAU,CAAC,CACvB,mBAAmB,CAAC,CAAC,UAAC,KAAK,IAAK,OAAA,CAAC,gBAAgB,CAAC,IAAI,KAAK,CAAC,CAAC,UAAU,CAAC,CAAC,mBAAmB,CAAC,EAAG,EAAhE,CAAgE,CAAC,CACjG,mBAAmB,CAAC,CAAC,UAAC,KAAK,IAAK,OAAA,CAAC,gBAAgB,CAAC,IAAI,KAAK,CAAC,CAAC,UAAU,CAAC,CAAC,mBAAmB,CAAC,EAAG,EAAhE,CAAgE,CAAC,EAErG;IAAA,EAAE,+BAAqB,CAAC,QAAQ,CAAC,CAClC,CAAA;AACH,CAAC;AA9CD,wCA8CC;AAED,cAAc,CAAC,YAAY,GAAG;IAC5B,UAAU,EAAE,eAAiB;IAC7B,mBAAmB,EAAE,UAAC,EAAS;YAAP,KAAK,WAAA;QAAO,OAAA,CAAC,WAAI,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,EAAG;IAArB,CAAqB;CAC1B,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
import { AugmentedSectionRenderItemInfo, SectionComponentProps, SectionProps } from '../Sections';
|
|
3
|
+
import { TSectionFilterItem, UseSectionFilters, useSectionFilters } from './useSectionFilters';
|
|
4
|
+
export type SectionFilterItemProps<T> = AugmentedSectionRenderItemInfo<T> & {
|
|
5
|
+
onPress: () => void;
|
|
6
|
+
selected: boolean;
|
|
7
|
+
disabled: boolean;
|
|
8
|
+
text: string;
|
|
9
|
+
};
|
|
10
|
+
export type SectionFilterComponentProps<T> = SectionComponentProps<T> & {
|
|
11
|
+
selectedItems: TSectionFilterItem[];
|
|
12
|
+
clearSelectedItems: () => void;
|
|
13
|
+
};
|
|
14
|
+
export type SectionFiltersProps<T = any> = UseSectionFilters & Omit<SectionProps<T>, 'renderItem' | 'renderSectionFooter' | 'renderSectionHeader'> & {
|
|
15
|
+
handle?: ReturnType<typeof useSectionFilters<T>>;
|
|
16
|
+
renderItem?: (props: SectionFilterItemProps<T>) => ReactElement;
|
|
17
|
+
renderSectionFooter?: (props: SectionFilterComponentProps<T>) => ReactElement;
|
|
18
|
+
renderSectionHeader?: (props: SectionFilterComponentProps<T>) => ReactElement;
|
|
19
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/components/SectionFilters/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type TSectionFilterItem = {
|
|
2
|
+
value?: string | number;
|
|
3
|
+
label?: string;
|
|
4
|
+
};
|
|
5
|
+
type Section<T = TSectionFilterItem> = {
|
|
6
|
+
data: T[];
|
|
7
|
+
title: string;
|
|
8
|
+
selectionLimit?: number;
|
|
9
|
+
disableItemsOnLimitReached?: boolean;
|
|
10
|
+
};
|
|
11
|
+
type SelectedItemsPerSection<T = TSectionFilterItem> = {
|
|
12
|
+
[X: number]: T[];
|
|
13
|
+
};
|
|
14
|
+
export type UseSectionFilters<T = TSectionFilterItem> = {
|
|
15
|
+
sections: Section<T>[];
|
|
16
|
+
areItemsEqual?: (a: T, b: T) => boolean;
|
|
17
|
+
selectionLimit?: number;
|
|
18
|
+
sectionSelectionLimit?: number;
|
|
19
|
+
disableItemsOnLimitReached?: boolean;
|
|
20
|
+
initialSelectedItems?: SelectedItemsPerSection<T>;
|
|
21
|
+
};
|
|
22
|
+
export declare function useSectionFilters<T = TSectionFilterItem>(props: UseSectionFilters<T>): {
|
|
23
|
+
isSelected: (item: T) => boolean;
|
|
24
|
+
toggleItem: (item: T) => void;
|
|
25
|
+
findItemSection: (item: T) => {
|
|
26
|
+
sectionIndex: number;
|
|
27
|
+
section: Section<T>;
|
|
28
|
+
};
|
|
29
|
+
selectedItems: SelectedItemsPerSection<T>;
|
|
30
|
+
sectionLimitReached: (sectionIndex: number) => boolean;
|
|
31
|
+
limitReached: () => boolean;
|
|
32
|
+
disableItemsOnLimitReached: boolean;
|
|
33
|
+
clearSelectedItemsWithSection: (sectionIndex: number) => void;
|
|
34
|
+
};
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
14
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
15
|
+
if (ar || !(i in from)) {
|
|
16
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
17
|
+
ar[i] = from[i];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
21
|
+
};
|
|
22
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.useSectionFilters = void 0;
|
|
27
|
+
var common_1 = require("@codeleap/common");
|
|
28
|
+
var react_1 = __importDefault(require("react"));
|
|
29
|
+
function useSectionFilters(props) {
|
|
30
|
+
var sections = props.sections, _a = props.areItemsEqual, areItemsEqual = _a === void 0 ? common_1.deepEqual : _a, _b = props.selectionLimit, selectionLimit = _b === void 0 ? 1 : _b, _c = props.sectionSelectionLimit, sectionSelectionLimit = _c === void 0 ? null : _c, _d = props.disableItemsOnLimitReached, disableItemsOnLimitReached = _d === void 0 ? selectionLimit > 1 && !sectionSelectionLimit : _d, _e = props.initialSelectedItems, initialSelectedItems = _e === void 0 ? [] : _e;
|
|
31
|
+
var _f = react_1.default.useState(function () {
|
|
32
|
+
if (common_1.TypeGuards.isArray(initialSelectedItems)) {
|
|
33
|
+
return {
|
|
34
|
+
0: initialSelectedItems,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
return initialSelectedItems !== null && initialSelectedItems !== void 0 ? initialSelectedItems : {};
|
|
38
|
+
}), selectedItems = _f[0], setSelectedItems = _f[1];
|
|
39
|
+
var findItemSection = function (item) {
|
|
40
|
+
if (!sections) {
|
|
41
|
+
return {
|
|
42
|
+
sectionIndex: 0,
|
|
43
|
+
section: null,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
var sectionIndex = sections === null || sections === void 0 ? void 0 : sections.findIndex(function (section) {
|
|
47
|
+
return section.data.some(function (i) { return areItemsEqual(item, i); });
|
|
48
|
+
});
|
|
49
|
+
if (sectionIndex === -1) {
|
|
50
|
+
return {
|
|
51
|
+
sectionIndex: null,
|
|
52
|
+
section: null,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
var section = sections[sectionIndex];
|
|
56
|
+
return {
|
|
57
|
+
sectionIndex: sectionIndex,
|
|
58
|
+
section: section,
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
var isSelected = function (item) {
|
|
62
|
+
var _a, _b;
|
|
63
|
+
if (sections) {
|
|
64
|
+
var sectionIndex = findItemSection(item).sectionIndex;
|
|
65
|
+
return (_a = selectedItems[sectionIndex]) === null || _a === void 0 ? void 0 : _a.some(function (i) { return areItemsEqual(i, item); });
|
|
66
|
+
}
|
|
67
|
+
return (_b = selectedItems[0]) === null || _b === void 0 ? void 0 : _b.some(function (i) { return areItemsEqual(i, item); });
|
|
68
|
+
};
|
|
69
|
+
var toggleItem = function (item) {
|
|
70
|
+
var _a;
|
|
71
|
+
var _b, _c;
|
|
72
|
+
var sectionIndex = -1;
|
|
73
|
+
var limit = selectionLimit;
|
|
74
|
+
if (sections) {
|
|
75
|
+
var _d = findItemSection(item), si = _d.sectionIndex, section = _d.section;
|
|
76
|
+
if (si === null) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
sectionIndex = si;
|
|
80
|
+
limit = (_b = section.selectionLimit) !== null && _b !== void 0 ? _b : selectionLimit;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
sectionIndex = 0;
|
|
84
|
+
}
|
|
85
|
+
var currentItems = (_c = selectedItems[sectionIndex]) !== null && _c !== void 0 ? _c : [];
|
|
86
|
+
var isItemSelected = currentItems.some(function (i) { return areItemsEqual(i, item); });
|
|
87
|
+
var newItems = __spreadArray([], currentItems, true);
|
|
88
|
+
if (isItemSelected) {
|
|
89
|
+
var index = newItems.findIndex(function (i) { return areItemsEqual(i, item); });
|
|
90
|
+
newItems.splice(index, 1);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
if (newItems.length >= limit) {
|
|
94
|
+
newItems.shift();
|
|
95
|
+
}
|
|
96
|
+
newItems.push(item);
|
|
97
|
+
}
|
|
98
|
+
setSelectedItems(__assign(__assign({}, selectedItems), (_a = {}, _a[sectionIndex] = newItems, _a)));
|
|
99
|
+
};
|
|
100
|
+
function sectionLimitReached(sectionIndex) {
|
|
101
|
+
var _a, _b, _c;
|
|
102
|
+
var section = sections[sectionIndex];
|
|
103
|
+
if (!section) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
var limit = (_b = (_a = section.selectionLimit) !== null && _a !== void 0 ? _a : sectionSelectionLimit) !== null && _b !== void 0 ? _b : selectionLimit;
|
|
107
|
+
if (!limit) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
var nItems = (_c = selectedItems[sectionIndex]) === null || _c === void 0 ? void 0 : _c.length;
|
|
111
|
+
return nItems >= limit;
|
|
112
|
+
}
|
|
113
|
+
function limitReached() {
|
|
114
|
+
var nItems = Object.values(selectedItems).flatMap(function (i) { return i; }).length;
|
|
115
|
+
return nItems >= selectionLimit;
|
|
116
|
+
}
|
|
117
|
+
function clearSelectedItemsWithSection(sectionIndex) {
|
|
118
|
+
var _a;
|
|
119
|
+
setSelectedItems(__assign(__assign({}, selectedItems), (_a = {}, _a[sectionIndex] = [], _a)));
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
isSelected: isSelected,
|
|
123
|
+
toggleItem: toggleItem,
|
|
124
|
+
findItemSection: findItemSection,
|
|
125
|
+
selectedItems: selectedItems,
|
|
126
|
+
sectionLimitReached: sectionLimitReached,
|
|
127
|
+
limitReached: limitReached,
|
|
128
|
+
disableItemsOnLimitReached: disableItemsOnLimitReached,
|
|
129
|
+
clearSelectedItemsWithSection: clearSelectedItemsWithSection,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
exports.useSectionFilters = useSectionFilters;
|
|
133
|
+
//# sourceMappingURL=useSectionFilters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSectionFilters.js","sourceRoot":"","sources":["../../../src/components/SectionFilters/useSectionFilters.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAwD;AACxD,gDAAyB;AAyBzB,SAAgB,iBAAiB,CAAyB,KAA2B;IAEjF,IAAA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AmB,qBAAA;QACnB,YAAY,cAAA;QACZ,0BAA0B,4BAAA;QAC1B,6BAA6B,+BAAA;KAC9B,CAAA;AACH,CAAC;AA3ID,8CA2IC"}
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { SectionProps } from './types';
|
|
3
|
+
import { AnyRecord, IJSX, StyledComponentProps } from '@codeleap/styles';
|
|
3
4
|
export * from './styles';
|
|
4
5
|
export * from './types';
|
|
5
|
-
export declare const Sections:
|
|
6
|
+
export declare const Sections: {
|
|
7
|
+
<T extends unknown>(sectionsProps: SectionProps<T>): JSX.Element;
|
|
8
|
+
styleRegistryName: string;
|
|
9
|
+
elements: string[];
|
|
10
|
+
rootElement: string;
|
|
11
|
+
withVariantTypes<S extends AnyRecord>(styles: S): <T_1>(props: StyledComponentProps<SectionProps<T_1>, S>) => IJSX;
|
|
12
|
+
defaultProps: Partial<SectionProps>;
|
|
13
|
+
};
|
|
@@ -53,65 +53,81 @@ var react_1 = __importStar(require("react"));
|
|
|
53
53
|
var common_1 = require("@codeleap/common");
|
|
54
54
|
var react_native_1 = require("react-native");
|
|
55
55
|
var View_1 = require("../View");
|
|
56
|
+
var RefreshControl_1 = require("../RefreshControl");
|
|
56
57
|
var utils_1 = require("../../utils");
|
|
57
58
|
var Registry_1 = require("../../Registry");
|
|
58
59
|
var hooks_1 = require("../../hooks");
|
|
60
|
+
var EmptyPlaceholder_1 = require("../EmptyPlaceholder");
|
|
59
61
|
__exportStar(require("./styles"), exports);
|
|
60
62
|
__exportStar(require("./types"), exports);
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
63
|
+
var RenderSeparator = function (props) {
|
|
64
|
+
return <View_1.View style={props.separatorStyles}/>;
|
|
65
|
+
};
|
|
66
|
+
var Sections = function (sectionsProps) {
|
|
67
|
+
var _a = __assign(__assign({}, exports.Sections.defaultProps), sectionsProps), style = _a.style, onRefresh = _a.onRefresh, component = _a.component, refreshing = _a.refreshing, placeholder = _a.placeholder, refreshControlProps = _a.refreshControlProps, loading = _a.loading, keyboardAware = _a.keyboardAware, _b = _a.fakeEmpty, fakeEmpty = _b === void 0 ? loading : _b, contentContainerStyle = _a.contentContainerStyle, refreshControl = _a.refreshControl, RenderItem = _a.renderItem, data = _a.sections, RenderSectionHeader = _a.renderSectionHeader, RenderSectionFooter = _a.renderSectionFooter, props = __rest(_a, ["style", "onRefresh", "component", "refreshing", "placeholder", "refreshControlProps", "loading", "keyboardAware", "fakeEmpty", "contentContainerStyle", "refreshControl", "renderItem", "sections", "renderSectionHeader", "renderSectionFooter"]);
|
|
68
|
+
var sections = (0, react_1.useMemo)(function () {
|
|
69
|
+
return data === null || data === void 0 ? void 0 : data.map(function (section, index) { return (__assign(__assign({}, section), { index: index })); });
|
|
70
|
+
}, [JSON.stringify(data)]);
|
|
64
71
|
var styles = (0, hooks_1.useStylesFor)(exports.Sections.styleRegistryName, style);
|
|
65
|
-
var
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
var
|
|
72
|
-
var
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
var getSectionPosition = function (data) {
|
|
76
|
-
var _a;
|
|
77
|
-
var listLength = ((_a = props.sections) === null || _a === void 0 ? void 0 : _a.length) || 0;
|
|
78
|
-
var isFirst = data.section.key === props.sections[0].key;
|
|
79
|
-
var isLast = data.section.key === props.sections[listLength - 1].key;
|
|
72
|
+
var separator = (0, common_1.useCallback)(function () {
|
|
73
|
+
if (!(props === null || props === void 0 ? void 0 : props.separators))
|
|
74
|
+
return null;
|
|
75
|
+
return <RenderSeparator separatorStyles={styles.separator}/>;
|
|
76
|
+
}, []);
|
|
77
|
+
var getSectionProps = function (data) {
|
|
78
|
+
var _a, _b, _c, _d, _e, _f;
|
|
79
|
+
var listLength = (sections === null || sections === void 0 ? void 0 : sections.length) || 0;
|
|
80
|
+
var isFirst = ((_a = data === null || data === void 0 ? void 0 : data.section) === null || _a === void 0 ? void 0 : _a.index) === ((_b = sections === null || sections === void 0 ? void 0 : sections[0]) === null || _b === void 0 ? void 0 : _b.index);
|
|
81
|
+
var isLast = ((_c = data === null || data === void 0 ? void 0 : data.section) === null || _c === void 0 ? void 0 : _c.index) === ((_d = sections === null || sections === void 0 ? void 0 : sections[listLength - 1]) === null || _d === void 0 ? void 0 : _d.index);
|
|
80
82
|
var isOnly = isFirst && isLast;
|
|
81
|
-
|
|
83
|
+
var title = (_e = data === null || data === void 0 ? void 0 : data.section) === null || _e === void 0 ? void 0 : _e.title;
|
|
84
|
+
var index = (_f = data === null || data === void 0 ? void 0 : data.section) === null || _f === void 0 ? void 0 : _f.index;
|
|
85
|
+
return { isFirst: isFirst, isLast: isLast, isOnly: isOnly, title: title, index: index };
|
|
82
86
|
};
|
|
83
87
|
var renderSectionHeader = (0, common_1.useCallback)(function (data) {
|
|
84
|
-
if (!
|
|
88
|
+
if (!RenderSectionHeader)
|
|
85
89
|
return null;
|
|
86
|
-
|
|
87
|
-
|
|
90
|
+
var positionProps = getSectionProps(data);
|
|
91
|
+
return <RenderSectionHeader {...data.section} {...positionProps}/>;
|
|
92
|
+
}, [RenderSectionHeader, sections === null || sections === void 0 ? void 0 : sections.length]);
|
|
88
93
|
var renderSectionFooter = (0, common_1.useCallback)(function (data) {
|
|
89
|
-
if (!
|
|
94
|
+
if (!RenderSectionFooter)
|
|
90
95
|
return null;
|
|
91
|
-
|
|
92
|
-
|
|
96
|
+
var positionProps = getSectionProps(data);
|
|
97
|
+
return <RenderSectionFooter {...data.section} {...positionProps}/>;
|
|
98
|
+
}, [RenderSectionFooter, sections === null || sections === void 0 ? void 0 : sections.length]);
|
|
93
99
|
var renderItem = (0, common_1.useCallback)(function (data) {
|
|
94
|
-
var _a;
|
|
95
|
-
if (!
|
|
100
|
+
var _a, _b;
|
|
101
|
+
if (!RenderItem)
|
|
96
102
|
return null;
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
103
|
+
var listLength = ((_b = (_a = data === null || data === void 0 ? void 0 : data.section) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.length) || 0;
|
|
104
|
+
var isFirst = (data === null || data === void 0 ? void 0 : data.index) === 0;
|
|
105
|
+
var isLast = (data === null || data === void 0 ? void 0 : data.index) === listLength - 1;
|
|
106
|
+
var isOnly = isFirst && isLast;
|
|
107
|
+
return (<RenderItem {...data} isFirst={isFirst} isLast={isLast} isOnly={isOnly}/>);
|
|
108
|
+
}, [RenderItem]);
|
|
109
|
+
var isEmpty = !sections || !(sections === null || sections === void 0 ? void 0 : sections.length);
|
|
110
|
+
var _placeholder = __assign(__assign({}, placeholder), { loading: common_1.TypeGuards.isBoolean(placeholder === null || placeholder === void 0 ? void 0 : placeholder.loading) ? placeholder.loading : loading });
|
|
111
|
+
var keyboardStyle = (0, utils_1.useKeyboardPaddingStyle)([
|
|
112
|
+
styles.content,
|
|
113
|
+
contentContainerStyle,
|
|
114
|
+
isEmpty && styles['content:empty'],
|
|
115
|
+
loading && styles['content:loading'],
|
|
116
|
+
], keyboardAware && !props.horizontal);
|
|
117
|
+
var wrapperStyle = [styles.wrapper, isEmpty && styles['wrapper:empty'], loading && styles['wrapper:loading']];
|
|
118
|
+
return (<react_native_1.SectionList ItemSeparatorComponent={separator} refreshControl={!!onRefresh && (<RefreshControl_1.RefreshControl refreshing={refreshing} onRefresh={onRefresh} {...refreshControlProps}/>)} ListEmptyComponent={<EmptyPlaceholder_1.EmptyPlaceholder {..._placeholder}/>} showsVerticalScrollIndicator={false} showsHorizontalScrollIndicator={false} {...props} ListHeaderComponentStyle={styles.header} style={wrapperStyle} contentContainerStyle={keyboardStyle} sections={sections} renderItem={renderItem} renderSectionHeader={renderSectionHeader} renderSectionFooter={renderSectionFooter}/>);
|
|
119
|
+
};
|
|
120
|
+
exports.Sections = Sections;
|
|
107
121
|
exports.Sections.styleRegistryName = 'Sections';
|
|
108
|
-
exports.Sections.elements = ['wrapper', 'content', 'separator'];
|
|
122
|
+
exports.Sections.elements = ['wrapper', 'content', 'separator', 'header', 'refreshControl'];
|
|
109
123
|
exports.Sections.rootElement = 'wrapper';
|
|
110
124
|
exports.Sections.withVariantTypes = function (styles) {
|
|
111
125
|
return exports.Sections;
|
|
112
126
|
};
|
|
113
127
|
exports.Sections.defaultProps = {
|
|
114
128
|
keyboardShouldPersistTaps: 'handled',
|
|
129
|
+
fakeEmpty: false,
|
|
130
|
+
loading: false,
|
|
115
131
|
keyboardAware: true,
|
|
116
132
|
};
|
|
117
133
|
Registry_1.MobileStyleRegistry.registerComponent(exports.Sections);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/Sections/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/Sections/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAsC;AACtC,2CAA0D;AAC1D,6CAA8E;AAC9E,gCAAyC;AACzC,oDAAkD;AAClD,qCAAqD;AAGrD,2CAAoD;AACpD,qCAA0C;AAC1C,wDAAsD;AAEtD,2CAAwB;AACxB,0CAAuB;AAEvB,IAAM,eAAe,GAAG,UAAC,KAA8C;IACrE,OAAO,CAAC,WAAI,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,eAAe,CAAC,EAAG,CAAA;AAC/C,CAAC,CAAA;AAEM,IAAM,QAAQ,GAAG,UAAgB,aAA8B;IACpE,IAAM,2BAkBD,gBAAQ,CAAC,YAAY,GACrB,aAAa,CACjB,EAnBC,KAAK,WAAA,EACL,SAAS,eAAA,EACT,SA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,SAAS,CAAA;AAEhC,gBAAQ,CAAC,gBAAgB,GAAG,UAAsB,MAAS;IACzD,OAAO,gBAAoF,CAAA;AAC7F,CAAC,CAAA;AAED,gBAAQ,CAAC,YAAY,GAAG;IACtB,yBAAyB,EAAE,SAAS;IACpC,SAAS,EAAE,KAAK;IAChB,OAAO,EAAE,KAAK;IACd,aAAa,EAAE,IAAI;CACK,CAAA;AAE1B,8BAAmB,CAAC,iBAAiB,CAAC,gBAAQ,CAAC,CAAA"}
|
|
@@ -1 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { ScrollComposition } from '../Scroll/styles';
|
|
2
|
+
type SectionsStates = 'empty' | 'loading';
|
|
3
|
+
type SectionsParts = ScrollComposition | 'separator' | 'header' | 'refreshControl';
|
|
4
|
+
export type SectionsComposition = `${SectionsParts}:${SectionsStates}` | SectionsParts;
|
|
5
|
+
export {};
|
|
@@ -1,34 +1,48 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { StyledProp } from '@codeleap/styles';
|
|
3
|
-
import { SectionListRenderItemInfo } from 'react-native';
|
|
4
3
|
import { SectionsComposition } from './styles';
|
|
5
|
-
import { SectionListProps as RNSectionListProps } from 'react-native';
|
|
4
|
+
import { SectionListRenderItemInfo, SectionListProps as RNSectionListProps } from 'react-native';
|
|
6
5
|
import { ViewProps } from '../View';
|
|
7
6
|
import { EmptyPlaceholderProps } from '../EmptyPlaceholder';
|
|
8
7
|
import { RefreshControlProps } from '../RefreshControl';
|
|
9
|
-
export type DataboundSectionListPropsTypes = '
|
|
10
|
-
export type
|
|
8
|
+
export type DataboundSectionListPropsTypes = 'sections' | 'renderItem' | 'keyExtractor' | 'style' | 'renderSectionFooter' | 'renderSectionHeader';
|
|
9
|
+
export type SectionInfo = {
|
|
11
10
|
isFirst: boolean;
|
|
12
11
|
isLast: boolean;
|
|
13
12
|
isOnly: boolean;
|
|
14
13
|
};
|
|
14
|
+
export type AugmentedSectionRenderItemInfo<T> = SectionListRenderItemInfo<T> & SectionInfo;
|
|
15
|
+
export type SectionComponentProps<T> = SectionInfo & {
|
|
16
|
+
title: string;
|
|
17
|
+
index: number;
|
|
18
|
+
data: T[];
|
|
19
|
+
};
|
|
20
|
+
export type SectionRenderComponentProps<T> = {
|
|
21
|
+
section: {
|
|
22
|
+
title: string;
|
|
23
|
+
index: number;
|
|
24
|
+
data: T[];
|
|
25
|
+
};
|
|
26
|
+
};
|
|
15
27
|
export type ReplaceSectionListProps<P, T> = Omit<P, DataboundSectionListPropsTypes> & {
|
|
16
|
-
sections:
|
|
28
|
+
sections: Array<{
|
|
29
|
+
title: string;
|
|
30
|
+
data: T[];
|
|
31
|
+
}>;
|
|
17
32
|
keyExtractor?: (item: T, index: number) => string;
|
|
18
|
-
renderItem: (
|
|
33
|
+
renderItem: (props: AugmentedSectionRenderItemInfo<T>) => React.ReactElement;
|
|
19
34
|
onRefresh?: () => void;
|
|
20
|
-
getItemLayout?: ((data: T, index: number) => {
|
|
21
|
-
length: number;
|
|
22
|
-
offset: number;
|
|
23
|
-
index: number;
|
|
24
|
-
});
|
|
25
35
|
fakeEmpty?: boolean;
|
|
36
|
+
loading?: boolean;
|
|
37
|
+
renderSectionHeader?: (props: SectionComponentProps<T>) => React.ReactElement;
|
|
38
|
+
renderSectionFooter?: (props: SectionComponentProps<T>) => React.ReactElement;
|
|
26
39
|
};
|
|
27
|
-
export type
|
|
40
|
+
export type SectionProps<T = any> = ReplaceSectionListProps<RNSectionListProps<T>, T> & Omit<ViewProps, 'style'> & {
|
|
28
41
|
separators?: boolean;
|
|
29
42
|
placeholder?: EmptyPlaceholderProps;
|
|
30
43
|
refreshControlProps?: Partial<RefreshControlProps>;
|
|
31
44
|
fakeEmpty?: boolean;
|
|
45
|
+
loading?: boolean;
|
|
32
46
|
keyboardAware?: boolean;
|
|
33
47
|
style?: StyledProp<SectionsComposition>;
|
|
34
48
|
};
|