etudes 3.3.1 → 3.4.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/lib/Accordion.d.ts +52 -34
- package/lib/Accordion.js +89 -46
- package/lib/Accordion.js.map +1 -1
- package/lib/Dropdown.d.ts +21 -14
- package/lib/Dropdown.js +42 -24
- package/lib/Dropdown.js.map +1 -1
- package/lib/List.d.ts +31 -14
- package/lib/List.js +24 -22
- package/lib/List.js.map +1 -1
- package/lib/RangeSlider.js +32 -32
- package/lib/RangeSlider.js.map +1 -1
- package/lib/hooks/useDragEffect.js +11 -11
- package/lib/hooks/useDragEffect.js.map +1 -1
- package/package.json +1 -1
package/lib/Accordion.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import React, { type ComponentType, type HTMLAttributes, type PropsWithChildren, type ReactElement, type Ref } from 'react';
|
|
2
2
|
import { type ListItemProps, type ListProps } from './List';
|
|
3
3
|
export type AccordionItemProps<T> = ListItemProps<T>;
|
|
4
|
-
export type AccordionHeaderProps<T> = HTMLAttributes<HTMLElement> & PropsWithChildren<{
|
|
4
|
+
export type AccordionHeaderProps<T, A = never> = HTMLAttributes<HTMLElement> & PropsWithChildren<{
|
|
5
|
+
attributes?: A;
|
|
5
6
|
data: AccordionSectionData<T>;
|
|
6
7
|
index: number;
|
|
7
8
|
isCollapsed: boolean;
|
|
9
|
+
onCustomEvent?: (name: string, info?: any) => void;
|
|
8
10
|
}>;
|
|
9
11
|
export type AccordionSectionData<T> = {
|
|
10
12
|
label: string;
|
|
@@ -15,7 +17,7 @@ export type AccordionProps<T> = HTMLAttributes<HTMLDivElement> & Omit<ListProps<
|
|
|
15
17
|
* Specifies if expanded sections should automatically collapse upon expanding
|
|
16
18
|
* another section.
|
|
17
19
|
*/
|
|
18
|
-
|
|
20
|
+
autoCollapseSections?: boolean;
|
|
19
21
|
/**
|
|
20
22
|
* SVG markup to be put in the section header as the collapse icon.
|
|
21
23
|
*/
|
|
@@ -32,15 +34,6 @@ export type AccordionProps<T> = HTMLAttributes<HTMLDivElement> & Omit<ListProps<
|
|
|
32
34
|
* SVG markup to be put in the section header as the expand icon.
|
|
33
35
|
*/
|
|
34
36
|
expandIconSvg?: string;
|
|
35
|
-
/**
|
|
36
|
-
* React component type to be used for generating headers inside the
|
|
37
|
-
* component. When absent, one will be generated automatically.
|
|
38
|
-
*/
|
|
39
|
-
headerComponentType?: ComponentType<AccordionHeaderProps<T>>;
|
|
40
|
-
/**
|
|
41
|
-
* React component type to be used for generating items inside the component.
|
|
42
|
-
*/
|
|
43
|
-
itemComponentType: ComponentType<AccordionItemProps<T>>;
|
|
44
37
|
/**
|
|
45
38
|
* Maximum number of items that are viside when a section expands. When a
|
|
46
39
|
* value greater than or equal to 0 is specified, only that number of items
|
|
@@ -57,13 +50,22 @@ export type AccordionProps<T> = HTMLAttributes<HTMLDivElement> & Omit<ListProps<
|
|
|
57
50
|
* Indices of selected items per section.
|
|
58
51
|
*/
|
|
59
52
|
selectedItemIndices?: Record<number, number[]>;
|
|
53
|
+
/**
|
|
54
|
+
* React component type to be used for generating headers inside the
|
|
55
|
+
* component. When absent, one will be generated automatically.
|
|
56
|
+
*/
|
|
57
|
+
headerComponentType?: ComponentType<AccordionHeaderProps<T>>;
|
|
58
|
+
/**
|
|
59
|
+
* React component type to be used for generating items inside the component.
|
|
60
|
+
*/
|
|
61
|
+
itemComponentType: ComponentType<AccordionItemProps<T>>;
|
|
60
62
|
/**
|
|
61
63
|
* Handler invoked when an item is activated in a section.
|
|
62
64
|
*
|
|
63
|
-
* @param sectionIndex Section index.
|
|
64
65
|
* @param itemIndex Item index.
|
|
66
|
+
* @param sectionIndex Section index.
|
|
65
67
|
*/
|
|
66
|
-
onActivateAt?: (
|
|
68
|
+
onActivateAt?: (itemIndex: number, sectionIndex: number) => void;
|
|
67
69
|
/**
|
|
68
70
|
* Handler invoked when a section is collapsed.
|
|
69
71
|
*
|
|
@@ -73,23 +75,31 @@ export type AccordionProps<T> = HTMLAttributes<HTMLDivElement> & Omit<ListProps<
|
|
|
73
75
|
/**
|
|
74
76
|
* Handler invoked when an item is deselected in a section.
|
|
75
77
|
*
|
|
76
|
-
* @param sectionIndex Section index.
|
|
77
78
|
* @param itemIndex Item index.
|
|
79
|
+
* @param sectionIndex Section index.
|
|
78
80
|
*/
|
|
79
|
-
onDeselectAt?: (
|
|
81
|
+
onDeselectAt?: (itemIndex: number, sectionIndex: number) => void;
|
|
80
82
|
/**
|
|
81
83
|
* Handler invoked when a section is expanded.
|
|
82
84
|
*
|
|
83
85
|
* @param sectionIndex Section index.
|
|
84
86
|
*/
|
|
85
87
|
onExpandSectionAt?: (sectionIndex: number) => void;
|
|
88
|
+
/**
|
|
89
|
+
* Handler invoked when a custom event is dispatched from a section header.
|
|
90
|
+
*
|
|
91
|
+
* @param index Index of the section header.
|
|
92
|
+
* @param eventName Name of the dispatched event.
|
|
93
|
+
* @param eventInfo Optional info of the dispatched event.
|
|
94
|
+
*/
|
|
95
|
+
onHeaderCustomEvent?: (index: number, eventName: string, eventInfo?: any) => void;
|
|
86
96
|
/**
|
|
87
97
|
* Handler invoked when an item is selected in a section.
|
|
88
98
|
*
|
|
89
|
-
* @param sectionIndex Section index.
|
|
90
99
|
* @param itemIndex Item index.
|
|
100
|
+
* @param sectionIndex Section index.
|
|
91
101
|
*/
|
|
92
|
-
onSelectAt?: (
|
|
102
|
+
onSelectAt?: (itemIndex: number, sectionIndex: number) => void;
|
|
93
103
|
/**
|
|
94
104
|
* Handler invoked when selected items have changed.
|
|
95
105
|
*
|
|
@@ -97,12 +107,12 @@ export type AccordionProps<T> = HTMLAttributes<HTMLDivElement> & Omit<ListProps<
|
|
|
97
107
|
*/
|
|
98
108
|
onSelectionChange?: (selectedIndices: Record<number, number[]>) => void;
|
|
99
109
|
}>;
|
|
100
|
-
declare const _default: <T>(props: React.HTMLAttributes<HTMLDivElement> & Omit<ListProps<T>, "data" | "
|
|
110
|
+
declare const _default: <T>(props: React.HTMLAttributes<HTMLDivElement> & Omit<ListProps<T>, "data" | "selectedIndices" | "itemComponentType" | "onActivateAt" | "onDeselectAt" | "onSelectAt" | "onSelectionChange"> & {
|
|
101
111
|
/**
|
|
102
112
|
* Specifies if expanded sections should automatically collapse upon expanding
|
|
103
113
|
* another section.
|
|
104
114
|
*/
|
|
105
|
-
|
|
115
|
+
autoCollapseSections?: boolean | undefined;
|
|
106
116
|
/**
|
|
107
117
|
* SVG markup to be put in the section header as the collapse icon.
|
|
108
118
|
*/
|
|
@@ -119,15 +129,6 @@ declare const _default: <T>(props: React.HTMLAttributes<HTMLDivElement> & Omit<L
|
|
|
119
129
|
* SVG markup to be put in the section header as the expand icon.
|
|
120
130
|
*/
|
|
121
131
|
expandIconSvg?: string | undefined;
|
|
122
|
-
/**
|
|
123
|
-
* React component type to be used for generating headers inside the
|
|
124
|
-
* component. When absent, one will be generated automatically.
|
|
125
|
-
*/
|
|
126
|
-
headerComponentType?: React.ComponentType<AccordionHeaderProps<T>> | undefined;
|
|
127
|
-
/**
|
|
128
|
-
* React component type to be used for generating items inside the component.
|
|
129
|
-
*/
|
|
130
|
-
itemComponentType: React.ComponentType<AccordionItemProps<T>>;
|
|
131
132
|
/**
|
|
132
133
|
* Maximum number of items that are viside when a section expands. When a
|
|
133
134
|
* value greater than or equal to 0 is specified, only that number of items
|
|
@@ -144,13 +145,22 @@ declare const _default: <T>(props: React.HTMLAttributes<HTMLDivElement> & Omit<L
|
|
|
144
145
|
* Indices of selected items per section.
|
|
145
146
|
*/
|
|
146
147
|
selectedItemIndices?: Record<number, number[]> | undefined;
|
|
148
|
+
/**
|
|
149
|
+
* React component type to be used for generating headers inside the
|
|
150
|
+
* component. When absent, one will be generated automatically.
|
|
151
|
+
*/
|
|
152
|
+
headerComponentType?: React.ComponentType<AccordionHeaderProps<T, never>> | undefined;
|
|
153
|
+
/**
|
|
154
|
+
* React component type to be used for generating items inside the component.
|
|
155
|
+
*/
|
|
156
|
+
itemComponentType: React.ComponentType<AccordionItemProps<T>>;
|
|
147
157
|
/**
|
|
148
158
|
* Handler invoked when an item is activated in a section.
|
|
149
159
|
*
|
|
150
|
-
* @param sectionIndex Section index.
|
|
151
160
|
* @param itemIndex Item index.
|
|
161
|
+
* @param sectionIndex Section index.
|
|
152
162
|
*/
|
|
153
|
-
onActivateAt?: ((
|
|
163
|
+
onActivateAt?: ((itemIndex: number, sectionIndex: number) => void) | undefined;
|
|
154
164
|
/**
|
|
155
165
|
* Handler invoked when a section is collapsed.
|
|
156
166
|
*
|
|
@@ -160,23 +170,31 @@ declare const _default: <T>(props: React.HTMLAttributes<HTMLDivElement> & Omit<L
|
|
|
160
170
|
/**
|
|
161
171
|
* Handler invoked when an item is deselected in a section.
|
|
162
172
|
*
|
|
163
|
-
* @param sectionIndex Section index.
|
|
164
173
|
* @param itemIndex Item index.
|
|
174
|
+
* @param sectionIndex Section index.
|
|
165
175
|
*/
|
|
166
|
-
onDeselectAt?: ((
|
|
176
|
+
onDeselectAt?: ((itemIndex: number, sectionIndex: number) => void) | undefined;
|
|
167
177
|
/**
|
|
168
178
|
* Handler invoked when a section is expanded.
|
|
169
179
|
*
|
|
170
180
|
* @param sectionIndex Section index.
|
|
171
181
|
*/
|
|
172
182
|
onExpandSectionAt?: ((sectionIndex: number) => void) | undefined;
|
|
183
|
+
/**
|
|
184
|
+
* Handler invoked when a custom event is dispatched from a section header.
|
|
185
|
+
*
|
|
186
|
+
* @param index Index of the section header.
|
|
187
|
+
* @param eventName Name of the dispatched event.
|
|
188
|
+
* @param eventInfo Optional info of the dispatched event.
|
|
189
|
+
*/
|
|
190
|
+
onHeaderCustomEvent?: ((index: number, eventName: string, eventInfo?: any) => void) | undefined;
|
|
173
191
|
/**
|
|
174
192
|
* Handler invoked when an item is selected in a section.
|
|
175
193
|
*
|
|
176
|
-
* @param sectionIndex Section index.
|
|
177
194
|
* @param itemIndex Item index.
|
|
195
|
+
* @param sectionIndex Section index.
|
|
178
196
|
*/
|
|
179
|
-
onSelectAt?: ((
|
|
197
|
+
onSelectAt?: ((itemIndex: number, sectionIndex: number) => void) | undefined;
|
|
180
198
|
/**
|
|
181
199
|
* Handler invoked when selected items have changed.
|
|
182
200
|
*
|
package/lib/Accordion.js
CHANGED
|
@@ -74,8 +74,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
74
74
|
};
|
|
75
75
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
76
76
|
var classnames_1 = __importDefault(require("classnames"));
|
|
77
|
-
var
|
|
78
|
-
var
|
|
77
|
+
var react_1 = __importDefault(require("fast-deep-equal/react"));
|
|
78
|
+
var react_2 = __importStar(require("react"));
|
|
79
79
|
var Each_1 = __importDefault(require("./Each"));
|
|
80
80
|
var FlatSVG_1 = __importDefault(require("./FlatSVG"));
|
|
81
81
|
var List_1 = __importDefault(require("./List"));
|
|
@@ -84,70 +84,113 @@ var asClassNameDict_1 = __importDefault(require("./utils/asClassNameDict"));
|
|
|
84
84
|
var asStyleDict_1 = __importDefault(require("./utils/asStyleDict"));
|
|
85
85
|
var cloneStyledElement_1 = __importDefault(require("./utils/cloneStyledElement"));
|
|
86
86
|
var styles_1 = __importDefault(require("./utils/styles"));
|
|
87
|
-
exports.default = (0,
|
|
88
|
-
var children = _a.children, className = _a.className, style = _a.style, _b = _a.
|
|
89
|
-
var
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
87
|
+
exports.default = (0, react_2.forwardRef)(function (_a, ref) {
|
|
88
|
+
var children = _a.children, className = _a.className, style = _a.style, _b = _a.autoCollapseSections, autoCollapseSections = _b === void 0 ? false : _b, _c = _a.borderThickness, borderThickness = _c === void 0 ? 0 : _c, collapseIconSvg = _a.collapseIconSvg, data = _a.data, _d = _a.expandedSectionIndices, externalExpandedSectionIndices = _d === void 0 ? [] : _d, expandIconSvg = _a.expandIconSvg, _e = _a.isSelectionTogglable, isSelectionTogglable = _e === void 0 ? false : _e, _f = _a.itemLength, itemLength = _f === void 0 ? 50 : _f, _g = _a.itemPadding, itemPadding = _g === void 0 ? 0 : _g, _h = _a.maxVisibleItems, maxVisibleItems = _h === void 0 ? -1 : _h, _j = _a.orientation, orientation = _j === void 0 ? 'vertical' : _j, _k = _a.sectionPadding, sectionPadding = _k === void 0 ? 0 : _k, _l = _a.selectedItemIndices, externalSelectedItemIndices = _l === void 0 ? {} : _l, _m = _a.selectionMode, selectionMode = _m === void 0 ? 'single' : _m, HeaderComponent = _a.headerComponentType, itemComponentType = _a.itemComponentType, onActivateAt = _a.onActivateAt, onCollapseSectionAt = _a.onCollapseSectionAt, onDeselectAt = _a.onDeselectAt, onExpandSectionAt = _a.onExpandSectionAt, onHeaderCustomEvent = _a.onHeaderCustomEvent, onSelectAt = _a.onSelectAt, onSelectionChange = _a.onSelectionChange, props = __rest(_a, ["children", "className", "style", "autoCollapseSections", "borderThickness", "collapseIconSvg", "data", "expandedSectionIndices", "expandIconSvg", "isSelectionTogglable", "itemLength", "itemPadding", "maxVisibleItems", "orientation", "sectionPadding", "selectedItemIndices", "selectionMode", "headerComponentType", "itemComponentType", "onActivateAt", "onCollapseSectionAt", "onDeselectAt", "onExpandSectionAt", "onHeaderCustomEvent", "onSelectAt", "onSelectionChange"]);
|
|
89
|
+
var isSectionIndexOutOfRange = function (sectionIndex) {
|
|
90
|
+
if (sectionIndex >= data.length)
|
|
91
|
+
return true;
|
|
92
|
+
if (sectionIndex < 0)
|
|
93
|
+
return true;
|
|
94
|
+
return false;
|
|
95
|
+
};
|
|
96
|
+
var isItemIndexOutOfRange = function (itemIndex, sectionIndex) {
|
|
97
|
+
if (isSectionIndexOutOfRange(sectionIndex))
|
|
98
|
+
return true;
|
|
99
|
+
var items = data[sectionIndex].items;
|
|
100
|
+
if (itemIndex >= items.length)
|
|
101
|
+
return true;
|
|
102
|
+
if (itemIndex < 0)
|
|
103
|
+
return true;
|
|
104
|
+
return false;
|
|
105
|
+
};
|
|
106
|
+
var sanitizeExpandedSectionIndices = function (sectionIndices) { return sectionIndices.sort().filter(function (t) { return !isSectionIndexOutOfRange(t); }); };
|
|
107
|
+
var sanitizeSelectedItemIndices = function (itemIndices) {
|
|
108
|
+
var newValue = {};
|
|
109
|
+
var _loop_1 = function (sectionIndex) {
|
|
110
|
+
if (!Object.prototype.hasOwnProperty.call(itemIndices, sectionIndex))
|
|
111
|
+
return "continue";
|
|
112
|
+
var indices = itemIndices[sectionIndex];
|
|
113
|
+
if (!indices || !(indices instanceof Array) || indices.length === 0)
|
|
114
|
+
return "continue";
|
|
115
|
+
newValue[sectionIndex] = indices.sort().filter(function (t) { return !isItemIndexOutOfRange(t, Number(sectionIndex)); });
|
|
116
|
+
};
|
|
117
|
+
for (var sectionIndex in itemIndices) {
|
|
118
|
+
_loop_1(sectionIndex);
|
|
119
|
+
}
|
|
120
|
+
return newValue;
|
|
121
|
+
};
|
|
122
|
+
var isSectionExpandedAt = function (sectionIndex) { return expandedSectionIndices.indexOf(sectionIndex) >= 0; };
|
|
123
|
+
var toggleSectionAt = function (sectionIndex) {
|
|
124
|
+
if (isSectionIndexOutOfRange(sectionIndex))
|
|
125
|
+
return;
|
|
126
|
+
if (isSectionExpandedAt(sectionIndex)) {
|
|
127
|
+
setExpandedSectionIndices(function (prev) { return prev.filter(function (t) { return t !== sectionIndex; }); });
|
|
93
128
|
}
|
|
94
|
-
else if (
|
|
95
|
-
setExpandedSectionIndices([
|
|
129
|
+
else if (autoCollapseSections) {
|
|
130
|
+
setExpandedSectionIndices([sectionIndex]);
|
|
96
131
|
}
|
|
97
132
|
else {
|
|
98
|
-
setExpandedSectionIndices(function (prev) { return __spreadArray(__spreadArray([], __read(prev.filter(function (t) { return t !==
|
|
133
|
+
setExpandedSectionIndices(function (prev) { return __spreadArray(__spreadArray([], __read(prev.filter(function (t) { return t !== sectionIndex; })), false), [sectionIndex], false).sort(); });
|
|
99
134
|
}
|
|
100
135
|
};
|
|
101
|
-
var selectAt = function (
|
|
136
|
+
var selectAt = function (itemIndex, sectionIndex) {
|
|
102
137
|
var _a;
|
|
138
|
+
if (isItemIndexOutOfRange(itemIndex, sectionIndex))
|
|
139
|
+
return;
|
|
103
140
|
switch (selectionMode) {
|
|
104
141
|
case 'multiple':
|
|
105
142
|
setSelectedItemIndices(function (prev) {
|
|
106
143
|
var _a;
|
|
107
144
|
var _b;
|
|
108
|
-
return (__assign(__assign({}, prev), (_a = {}, _a[
|
|
145
|
+
return (__assign(__assign({}, prev), (_a = {}, _a[sectionIndex] = __spreadArray(__spreadArray([], __read(((_b = prev[sectionIndex]) !== null && _b !== void 0 ? _b : []).filter(function (t) { return t !== itemIndex; })), false), [itemIndex], false).sort(), _a)));
|
|
109
146
|
});
|
|
110
|
-
onSelectAt === null || onSelectAt === void 0 ? void 0 : onSelectAt(
|
|
147
|
+
onSelectAt === null || onSelectAt === void 0 ? void 0 : onSelectAt(itemIndex, sectionIndex);
|
|
111
148
|
break;
|
|
112
149
|
case 'single':
|
|
113
|
-
setSelectedItemIndices((_a = {},
|
|
114
|
-
|
|
150
|
+
setSelectedItemIndices((_a = {},
|
|
151
|
+
_a[sectionIndex] = [itemIndex],
|
|
152
|
+
_a));
|
|
153
|
+
onSelectAt === null || onSelectAt === void 0 ? void 0 : onSelectAt(itemIndex, sectionIndex);
|
|
115
154
|
break;
|
|
116
155
|
default:
|
|
117
156
|
break;
|
|
118
157
|
}
|
|
119
158
|
};
|
|
120
|
-
var deselectAt = function (
|
|
159
|
+
var deselectAt = function (itemIndex, sectionIndex) {
|
|
160
|
+
if (isItemIndexOutOfRange(itemIndex, sectionIndex))
|
|
161
|
+
return;
|
|
121
162
|
setSelectedItemIndices(function (prev) {
|
|
122
163
|
var _a;
|
|
123
164
|
var _b;
|
|
124
|
-
return (__assign(__assign({}, prev), (_a = {}, _a[
|
|
165
|
+
return (__assign(__assign({}, prev), (_a = {}, _a[sectionIndex] = ((_b = prev[sectionIndex]) !== null && _b !== void 0 ? _b : []).filter(function (t) { return t !== itemIndex; }), _a)));
|
|
125
166
|
});
|
|
126
|
-
onDeselectAt === null || onDeselectAt === void 0 ? void 0 : onDeselectAt(
|
|
167
|
+
onDeselectAt === null || onDeselectAt === void 0 ? void 0 : onDeselectAt(itemIndex, sectionIndex);
|
|
127
168
|
};
|
|
128
|
-
var
|
|
169
|
+
var _o = __read((0, react_2.useState)(sanitizeExpandedSectionIndices(externalExpandedSectionIndices)), 2), expandedSectionIndices = _o[0], setExpandedSectionIndices = _o[1];
|
|
129
170
|
var prevExpandedSectionIndices = (0, usePrevious_1.default)(expandedSectionIndices);
|
|
130
|
-
var
|
|
131
|
-
(0,
|
|
132
|
-
|
|
171
|
+
var _p = __read((0, react_2.useState)(externalSelectedItemIndices), 2), selectedItemIndices = _p[0], setSelectedItemIndices = _p[1];
|
|
172
|
+
(0, react_2.useEffect)(function () {
|
|
173
|
+
var newValue = sanitizeExpandedSectionIndices(externalExpandedSectionIndices);
|
|
174
|
+
if ((0, react_1.default)(newValue, expandedSectionIndices))
|
|
133
175
|
return;
|
|
134
|
-
setExpandedSectionIndices(
|
|
135
|
-
}, [JSON.stringify(externalExpandedSectionIndices)]);
|
|
136
|
-
(0,
|
|
137
|
-
if ((0, fast_deep_equal_1.default)(externalSelectedItemIndices, selectedItemIndices))
|
|
138
|
-
return;
|
|
139
|
-
setSelectedItemIndices(externalSelectedItemIndices);
|
|
140
|
-
}, [JSON.stringify(externalSelectedItemIndices)]);
|
|
141
|
-
(0, react_1.useEffect)(function () {
|
|
176
|
+
setExpandedSectionIndices(newValue);
|
|
177
|
+
}, [JSON.stringify(sanitizeExpandedSectionIndices(externalExpandedSectionIndices))]);
|
|
178
|
+
(0, react_2.useEffect)(function () {
|
|
142
179
|
var _a;
|
|
143
180
|
var collapsed = (_a = prevExpandedSectionIndices === null || prevExpandedSectionIndices === void 0 ? void 0 : prevExpandedSectionIndices.filter(function (t) { return expandedSectionIndices.indexOf(t) === -1; })) !== null && _a !== void 0 ? _a : [];
|
|
144
181
|
var expanded = expandedSectionIndices.filter(function (t) { return (prevExpandedSectionIndices === null || prevExpandedSectionIndices === void 0 ? void 0 : prevExpandedSectionIndices.indexOf(t)) === -1; });
|
|
145
182
|
collapsed.map(function (t) { return onCollapseSectionAt === null || onCollapseSectionAt === void 0 ? void 0 : onCollapseSectionAt(t); });
|
|
146
183
|
expanded.map(function (t) { return onExpandSectionAt === null || onExpandSectionAt === void 0 ? void 0 : onExpandSectionAt(t); });
|
|
147
|
-
}, [JSON.stringify(expandedSectionIndices)]);
|
|
148
|
-
(0,
|
|
184
|
+
}, [JSON.stringify(sanitizeExpandedSectionIndices(expandedSectionIndices))]);
|
|
185
|
+
(0, react_2.useEffect)(function () {
|
|
186
|
+
var newValue = sanitizeSelectedItemIndices(externalSelectedItemIndices);
|
|
187
|
+
if ((0, react_1.default)(newValue, selectedItemIndices))
|
|
188
|
+
return;
|
|
189
|
+
setSelectedItemIndices(newValue);
|
|
190
|
+
}, [JSON.stringify(sanitizeSelectedItemIndices(externalSelectedItemIndices))]);
|
|
191
|
+
(0, react_2.useEffect)(function () {
|
|
149
192
|
onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange(selectedItemIndices);
|
|
150
|
-
}, [JSON.stringify(selectedItemIndices)]);
|
|
193
|
+
}, [JSON.stringify(sanitizeSelectedItemIndices(selectedItemIndices))]);
|
|
151
194
|
var fixedClassNames = (0, asClassNameDict_1.default)({
|
|
152
195
|
root: (0, classnames_1.default)(orientation),
|
|
153
196
|
header: (0, classnames_1.default)(orientation),
|
|
@@ -231,27 +274,27 @@ exports.default = (0, react_1.forwardRef)(function (_a, ref) {
|
|
|
231
274
|
width: '15px',
|
|
232
275
|
},
|
|
233
276
|
});
|
|
234
|
-
return (
|
|
235
|
-
|
|
277
|
+
return (react_2.default.createElement("div", __assign({}, props, { className: (0, classnames_1.default)(className, fixedClassNames.root), style: (0, styles_1.default)(style, fixedStyles.root) }),
|
|
278
|
+
react_2.default.createElement(Each_1.default, { in: data }, function (section, sectionIndex) {
|
|
236
279
|
var _a;
|
|
237
280
|
var numItems = section.items.length;
|
|
238
281
|
var numVisibleItems = maxVisibleItems < 0 ? numItems : Math.min(numItems, maxVisibleItems);
|
|
239
282
|
var menuLength = (itemLength - borderThickness) * numVisibleItems + itemPadding * (numVisibleItems - 1) + borderThickness;
|
|
240
|
-
var isCollapsed = !isSectionExpandedAt(
|
|
241
|
-
var expandIconComponent = expandIconSvg ?
|
|
242
|
-
var collapseIconComponent = collapseIconSvg ?
|
|
243
|
-
return (
|
|
244
|
-
marginTop:
|
|
283
|
+
var isCollapsed = !isSectionExpandedAt(sectionIndex);
|
|
284
|
+
var expandIconComponent = expandIconSvg ? react_2.default.createElement(FlatSVG_1.default, { svg: expandIconSvg, style: defaultStyles.expandIcon }) : react_2.default.createElement(react_2.default.Fragment, null);
|
|
285
|
+
var collapseIconComponent = collapseIconSvg ? react_2.default.createElement(FlatSVG_1.default, { svg: collapseIconSvg, style: defaultStyles.collapseIcon }) : expandIconComponent;
|
|
286
|
+
return (react_2.default.createElement("div", { style: (0, styles_1.default)(fixedStyles.section, orientation === 'vertical' ? {
|
|
287
|
+
marginTop: sectionIndex === 0 ? '0px' : "".concat(sectionPadding - borderThickness, "px"),
|
|
245
288
|
} : {
|
|
246
|
-
marginLeft:
|
|
289
|
+
marginLeft: sectionIndex === 0 ? '0px' : "".concat(sectionPadding - borderThickness, "px"),
|
|
247
290
|
}) },
|
|
248
|
-
HeaderComponent ? (
|
|
249
|
-
|
|
291
|
+
HeaderComponent ? (react_2.default.createElement(HeaderComponent, { className: (0, classnames_1.default)(fixedClassNames.header, { collapsed: isCollapsed, expanded: !isCollapsed }), style: (0, styles_1.default)(fixedStyles.header), data: section, index: sectionIndex, isCollapsed: isCollapsed, onClick: function () { return toggleSectionAt(sectionIndex); }, onCustomEvent: function (name, info) { return onHeaderCustomEvent === null || onHeaderCustomEvent === void 0 ? void 0 : onHeaderCustomEvent(sectionIndex, name, info); } })) : (react_2.default.createElement("button", { className: (0, classnames_1.default)(fixedClassNames.header, { collapsed: isCollapsed, expanded: !isCollapsed }), style: (0, styles_1.default)(fixedStyles.header, defaultStyles.header), onClick: function () { return toggleSectionAt(sectionIndex); } },
|
|
292
|
+
react_2.default.createElement("label", { style: fixedStyles.headerLabel, dangerouslySetInnerHTML: { __html: section.label } }),
|
|
250
293
|
(0, cloneStyledElement_1.default)(isCollapsed ? expandIconComponent : collapseIconComponent, {
|
|
251
294
|
className: (0, classnames_1.default)(isCollapsed ? fixedClassNames.expandIcon : fixedClassNames.collapseIcon),
|
|
252
295
|
style: (0, styles_1.default)(isCollapsed ? fixedStyles.expandIcon : fixedStyles.collapseIcon),
|
|
253
296
|
}))),
|
|
254
|
-
|
|
297
|
+
react_2.default.createElement(List_1.default, { style: (0, styles_1.default)(fixedStyles.list, orientation === 'vertical' ? {
|
|
255
298
|
height: isCollapsed ? '0px' : "".concat(menuLength, "px"),
|
|
256
299
|
marginTop: isCollapsed ? '0px' : "".concat(itemPadding - borderThickness, "px"),
|
|
257
300
|
overflowY: maxVisibleItems === -1 ? 'hidden' : maxVisibleItems < numItems ? 'scroll' : 'hidden',
|
|
@@ -259,7 +302,7 @@ exports.default = (0, react_1.forwardRef)(function (_a, ref) {
|
|
|
259
302
|
marginLeft: isCollapsed ? '0px' : "".concat(itemPadding - borderThickness, "px"),
|
|
260
303
|
overflowX: maxVisibleItems === -1 ? 'hidden' : maxVisibleItems < numItems ? 'scroll' : 'hidden',
|
|
261
304
|
width: isCollapsed ? '0px' : "".concat(menuLength, "px"),
|
|
262
|
-
}), borderThickness: borderThickness, data: section.items, selectionMode: selectionMode,
|
|
305
|
+
}), borderThickness: borderThickness, data: section.items, selectionMode: selectionMode, isSelectionTogglable: isSelectionTogglable, itemComponentType: itemComponentType, itemLength: itemLength, itemPadding: itemPadding, orientation: orientation, selectedIndices: (_a = selectedItemIndices[sectionIndex]) !== null && _a !== void 0 ? _a : [], onActivateAt: function (itemIndex) { return onActivateAt === null || onActivateAt === void 0 ? void 0 : onActivateAt(itemIndex, sectionIndex); }, onDeselectAt: function (itemIndex) { return deselectAt(itemIndex, sectionIndex); }, onSelectAt: function (itemIndex) { return selectAt(itemIndex, sectionIndex); } })));
|
|
263
306
|
})));
|
|
264
307
|
});
|
|
265
308
|
//# sourceMappingURL=Accordion.js.map
|
package/lib/Accordion.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Accordion.js","sourceRoot":"/","sources":["Accordion.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAAmC;AACnC,oEAAqC;AACrC,6CAA4J;AAC5J,gDAAyB;AACzB,sDAA+B;AAC/B,gDAAiE;AACjE,oEAA6C;AAC7C,4EAAqD;AACrD,oEAA6C;AAC7C,kFAA2D;AAC3D,0DAAmC;AAsHnC,kBAAe,IAAA,kBAAU,EAAC,UAAC,EA2B1B,EAAE,GAAG;IA1BJ,IAAA,QAAQ,cAAA,EACR,SAAS,eAAA,EACT,KAAK,WAAA,EACL,oBAAoB,EAApB,YAAY,mBAAG,KAAK,KAAA,EACpB,uBAAmB,EAAnB,eAAe,mBAAG,CAAC,KAAA,EACnB,eAAe,qBAAA,EACf,IAAI,UAAA,EACJ,8BAA2D,EAAnC,8BAA8B,mBAAG,EAAE,KAAA,EAC3D,aAAa,mBAAA,EACQ,eAAe,yBAAA,EACpC,WAAW,iBAAA,EACX,iBAAiB,uBAAA,EACjB,kBAAe,EAAf,UAAU,mBAAG,EAAE,KAAA,EACf,mBAAe,EAAf,WAAW,mBAAG,CAAC,KAAA,EACf,uBAAoB,EAApB,eAAe,mBAAG,CAAC,CAAC,KAAA,EACpB,mBAAwB,EAAxB,WAAW,mBAAG,UAAU,KAAA,EACxB,sBAAkB,EAAlB,cAAc,mBAAG,CAAC,KAAA,EAClB,2BAAqD,EAAhC,2BAA2B,mBAAG,EAAE,KAAA,EACrD,qBAAwB,EAAxB,aAAa,mBAAG,QAAQ,KAAA,EACxB,YA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BAAiB,EACpC,UAAU,EAAE,UAAU,EACtB,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,WAAW,EACxB,eAAe,EAAE,MAAA,mBAAmB,CAAC,UAAU,CAAC,mCAAI,EAAE,EACtD,YAAY,EAAE,UAAA,OAAO,IAAI,OAAA,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAG,UAAU,EAAE,OAAO,CAAC,EAAnC,CAAmC,EAC5D,YAAY,EAAE,UAAA,OAAO,IAAI,OAAA,UAAU,CAAC,UAAU,EAAE,OAAO,CAAC,EAA/B,CAA+B,EACxD,UAAU,EAAE,UAAA,OAAO,IAAI,OAAA,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC,EAA7B,CAA6B,GACpD,CACE,CACP,CAAA;QACH,CAAC,CACI,CACH,CACP,CAAA;AACH,CAAC,CAAkF,CAAA","sourcesContent":["import classNames from 'classnames'\nimport isEqual from 'fast-deep-equal'\nimport React, { forwardRef, useEffect, useState, type ComponentType, type HTMLAttributes, type PropsWithChildren, type ReactElement, type Ref } from 'react'\nimport Each from './Each'\nimport FlatSVG from './FlatSVG'\nimport List, { type ListItemProps, type ListProps } from './List'\nimport usePrevious from './hooks/usePrevious'\nimport asClassNameDict from './utils/asClassNameDict'\nimport asStyleDict from './utils/asStyleDict'\nimport cloneStyledElement from './utils/cloneStyledElement'\nimport styles from './utils/styles'\n\nexport type AccordionItemProps<T> = ListItemProps<T>\n\nexport type AccordionHeaderProps<T> = HTMLAttributes<HTMLElement> & PropsWithChildren<{\n data: AccordionSectionData<T>\n index: number\n isCollapsed: boolean\n}>\n\nexport type AccordionSectionData<T> = {\n label: string\n items: T[]\n}\n\nexport type AccordionProps<T> = HTMLAttributes<HTMLDivElement> & Omit<ListProps<T>, 'data' | 'itemComponentType' | 'selectedIndices' | 'onActivateAt' | 'onSelectAt' | 'onDeselectAt' | 'onSelectionChange'> & PropsWithChildren<{\n /**\n * Specifies if expanded sections should automatically collapse upon expanding\n * another section.\n */\n autoCollapse?: boolean\n\n /**\n * SVG markup to be put in the section header as the collapse icon.\n */\n collapseIconSvg?: string\n\n /**\n * Data provided to each section.\n */\n data: AccordionSectionData<T>[]\n\n /**\n * Indices of sections that are expanded.\n */\n expandedSectionIndices?: number[]\n\n /**\n * SVG markup to be put in the section header as the expand icon.\n */\n expandIconSvg?: string\n\n /**\n * React component type to be used for generating headers inside the\n * component. When absent, one will be generated automatically.\n */\n headerComponentType?: ComponentType<AccordionHeaderProps<T>>\n\n /**\n * React component type to be used for generating items inside the component.\n */\n itemComponentType: ComponentType<AccordionItemProps<T>>\n\n /**\n * Maximum number of items that are viside when a section expands. When a\n * value greater than or equal to 0 is specified, only that number of items\n * will be visible at a time, and a scrollbar will appear to scroll to\n * remaining items. Any value less than 0 indicates that all items will be\n * visible when a section expands.\n */\n maxVisibleItems?: number\n\n /**\n * Padding (in pixels) between each section.\n */\n sectionPadding?: number\n\n /**\n * Indices of selected items per section.\n */\n selectedItemIndices?: Record<number, number[]>\n\n /**\n * Handler invoked when an item is activated in a section.\n *\n * @param sectionIndex Section index.\n * @param itemIndex Item index.\n */\n onActivateAt?: (sectionIndex: number, itemIndex: number) => void\n\n /**\n * Handler invoked when a section is collapsed.\n *\n * @param sectionIndex Section index.\n */\n onCollapseSectionAt?: (sectionIndex: number) => void\n\n /**\n * Handler invoked when an item is deselected in a section.\n *\n * @param sectionIndex Section index.\n * @param itemIndex Item index.\n */\n onDeselectAt?: (sectionIndex: number, itemIndex: number) => void\n\n /**\n * Handler invoked when a section is expanded.\n *\n * @param sectionIndex Section index.\n */\n onExpandSectionAt?: (sectionIndex: number) => void\n\n /**\n * Handler invoked when an item is selected in a section.\n *\n * @param sectionIndex Section index.\n * @param itemIndex Item index.\n */\n onSelectAt?: (sectionIndex: number, itemIndex: number) => void\n\n /**\n * Handler invoked when selected items have changed.\n *\n * @param selectedIndices Dictionary of indices of selected items per section.\n */\n onSelectionChange?: (selectedIndices: Record<number, number[]>) => void\n}>\n\nexport default forwardRef(({\n children,\n className,\n style,\n autoCollapse = false,\n borderThickness = 0,\n collapseIconSvg,\n data,\n expandedSectionIndices: externalExpandedSectionIndices = [],\n expandIconSvg,\n headerComponentType: HeaderComponent,\n isTogglable,\n itemComponentType,\n itemLength = 50,\n itemPadding = 0,\n maxVisibleItems = -1,\n orientation = 'vertical',\n sectionPadding = 0,\n selectedItemIndices: externalSelectedItemIndices = {},\n selectionMode = 'single',\n onActivateAt,\n onCollapseSectionAt,\n onDeselectAt,\n onExpandSectionAt,\n onSelectAt,\n onSelectionChange,\n ...props\n}, ref) => {\n const isSectionExpandedAt = (idx: number) => expandedSectionIndices.indexOf(idx) >= 0\n\n const toggleSectionAt = (idx: number) => {\n if (isSectionExpandedAt(idx)) {\n setExpandedSectionIndices(prev => prev.filter(t => t !== idx))\n }\n else if (autoCollapse) {\n setExpandedSectionIndices([idx])\n }\n else {\n setExpandedSectionIndices(prev => [...prev.filter(t => t !== idx), idx])\n }\n }\n\n const selectAt = (sectionIdx: number, itemIdx: number) => {\n switch (selectionMode) {\n case 'multiple':\n setSelectedItemIndices(prev => ({\n ...prev,\n [sectionIdx]: [...(prev[sectionIdx] ?? []).filter(t => t !== itemIdx), itemIdx],\n }))\n\n onSelectAt?.(sectionIdx, itemIdx)\n\n break\n case 'single':\n setSelectedItemIndices({ [sectionIdx]: [itemIdx] })\n onSelectAt?.(sectionIdx, itemIdx)\n\n break\n default:\n break\n }\n }\n\n const deselectAt = (sectionIdx: number, itemIdx: number) => {\n setSelectedItemIndices(prev => ({\n ...prev,\n [sectionIdx]: (prev[sectionIdx] ?? []).filter(t => t !== itemIdx),\n }))\n\n onDeselectAt?.(sectionIdx, itemIdx)\n }\n\n const [expandedSectionIndices, setExpandedSectionIndices] = useState(externalExpandedSectionIndices)\n const prevExpandedSectionIndices = usePrevious(expandedSectionIndices)\n const [selectedItemIndices, setSelectedItemIndices] = useState(externalSelectedItemIndices)\n\n useEffect(() => {\n if (isEqual(externalExpandedSectionIndices, expandedSectionIndices)) return\n\n setExpandedSectionIndices(externalExpandedSectionIndices)\n }, [JSON.stringify(externalExpandedSectionIndices)])\n\n useEffect(() => {\n if (isEqual(externalSelectedItemIndices, selectedItemIndices)) return\n\n setSelectedItemIndices(externalSelectedItemIndices)\n }, [JSON.stringify(externalSelectedItemIndices)])\n\n useEffect(() => {\n const collapsed = prevExpandedSectionIndices?.filter(t => expandedSectionIndices.indexOf(t) === -1) ?? []\n const expanded = expandedSectionIndices.filter(t => prevExpandedSectionIndices?.indexOf(t) === -1)\n\n collapsed.map(t => onCollapseSectionAt?.(t))\n expanded.map(t => onExpandSectionAt?.(t))\n }, [JSON.stringify(expandedSectionIndices)])\n\n useEffect(() => {\n onSelectionChange?.(selectedItemIndices)\n }, [JSON.stringify(selectedItemIndices)])\n\n const fixedClassNames = asClassNameDict({\n root: classNames(orientation),\n header: classNames(orientation),\n expandIcon: classNames(orientation),\n collapseIcon: classNames(orientation),\n })\n\n const fixedStyles = asStyleDict({\n root: {\n alignItems: 'center',\n boxSizing: 'border-box',\n display: 'flex',\n flex: '0 0 auto',\n justifyContent: 'flex-start',\n padding: '0',\n ...orientation === 'vertical' ? {\n flexDirection: 'column',\n height: 'auto',\n } : {\n flexDirection: 'row',\n width: 'auto',\n },\n },\n section: {\n alignItems: 'flex-start',\n display: 'flex',\n flex: '0 0 auto',\n justifyContent: 'flex-start',\n margin: '0',\n padding: '0',\n ...orientation === 'vertical' ? {\n flexDirection: 'column',\n width: '100%',\n } : {\n flexDirection: 'row',\n height: '100%',\n },\n },\n header: {\n borderWidth: `${borderThickness}px`,\n cursor: 'pointer',\n margin: '0',\n outline: 'none',\n ...orientation === 'vertical' ? {\n width: '100%',\n } : {\n height: '100%',\n },\n },\n headerLabel: {\n color: 'inherit',\n fontFamily: 'inherit',\n fontSize: 'inherit',\n fontWeight: 'inherit',\n letterSpacing: 'inherit',\n lineHeight: 'inherit',\n pointerEvents: 'none',\n transition: 'inherit',\n },\n expandIcon: {\n margin: '0',\n padding: '0',\n },\n collapseIcon: {\n margin: '0',\n padding: '0',\n },\n list: {\n transitionDuration: '100ms',\n transitionTimingFunction: 'ease-out',\n ...orientation === 'vertical' ? {\n width: '100%',\n transitionProperty: 'height, margin',\n top: '100%',\n } : {\n height: '100%',\n transitionProperty: 'width, margin',\n left: '100%',\n },\n },\n })\n\n const defaultStyles = asStyleDict({\n header: {\n alignItems: 'center',\n background: '#fff',\n borderStyle: 'solid',\n boxSizing: 'border-box',\n display: 'flex',\n flexDirection: 'row',\n justifyContent: 'space-between',\n padding: '0 10px',\n transitionDuration: '100ms',\n transitionProperty: 'transform, opacity, background, color',\n transitionTimingFunction: 'ease-out',\n ...orientation === 'vertical' ? {\n height: '50px',\n } : {\n width: '50px',\n },\n },\n expandIcon: {\n boxSizing: 'border-box',\n display: 'block',\n fill: '#000',\n height: '15px',\n transformOrigin: 'center',\n transitionDuration: '100ms',\n transitionProperty: 'transform',\n transitionTimingFunction: 'ease-out',\n width: '15px',\n },\n collapseIcon: {\n boxSizing: 'border-box',\n display: 'block',\n fill: '#000',\n height: '15px',\n transformOrigin: 'center',\n transitionDuration: '100ms',\n transitionProperty: 'transform',\n transitionTimingFunction: 'ease-out',\n width: '15px',\n },\n })\n\n return (\n <div\n {...props}\n className={classNames(className, fixedClassNames.root)}\n style={styles(style, fixedStyles.root)}\n >\n <Each in={data}>\n {(section, sectionIdx) => {\n const numItems = section.items.length\n const numVisibleItems = maxVisibleItems < 0 ? numItems : Math.min(numItems, maxVisibleItems)\n const menuLength = (itemLength - borderThickness) * numVisibleItems + itemPadding * (numVisibleItems - 1) + borderThickness\n const isCollapsed = !isSectionExpandedAt(sectionIdx)\n const expandIconComponent = expandIconSvg ? <FlatSVG svg={expandIconSvg} style={defaultStyles.expandIcon}/> : <></>\n const collapseIconComponent = collapseIconSvg ? <FlatSVG svg={collapseIconSvg} style={defaultStyles.collapseIcon}/> : expandIconComponent\n\n return (\n <div style={styles(fixedStyles.section, orientation === 'vertical' ? {\n marginTop: sectionIdx === 0 ? '0px' : `${sectionPadding - borderThickness}px`,\n } : {\n marginLeft: sectionIdx === 0 ? '0px' : `${sectionPadding - borderThickness}px`,\n })}>\n {HeaderComponent ? (\n <HeaderComponent\n className={classNames(fixedClassNames.header, { collapsed: isCollapsed, expanded: !isCollapsed })}\n style={styles(fixedStyles.header)}\n data={section}\n index={sectionIdx}\n isCollapsed={isCollapsed}\n onClick={() => toggleSectionAt(sectionIdx)}\n />\n ) : (\n <button\n className={classNames(fixedClassNames.header, { collapsed: isCollapsed, expanded: !isCollapsed })}\n style={styles(fixedStyles.header, defaultStyles.header)}\n onClick={() => toggleSectionAt(sectionIdx)}\n >\n <label style={fixedStyles.headerLabel} dangerouslySetInnerHTML={{ __html: section.label }}/>\n {cloneStyledElement(isCollapsed ? expandIconComponent : collapseIconComponent, {\n className: classNames(isCollapsed ? fixedClassNames.expandIcon : fixedClassNames.collapseIcon),\n style: styles(isCollapsed ? fixedStyles.expandIcon : fixedStyles.collapseIcon),\n })}\n </button>\n )}\n <List\n style={styles(fixedStyles.list, orientation === 'vertical' ? {\n height: isCollapsed ? '0px' : `${menuLength}px`,\n marginTop: isCollapsed ? '0px' : `${itemPadding - borderThickness}px`,\n overflowY: maxVisibleItems === -1 ? 'hidden' : maxVisibleItems < numItems ? 'scroll' : 'hidden',\n } : {\n marginLeft: isCollapsed ? '0px' : `${itemPadding - borderThickness}px`,\n overflowX: maxVisibleItems === -1 ? 'hidden' : maxVisibleItems < numItems ? 'scroll' : 'hidden',\n width: isCollapsed ? '0px' : `${menuLength}px`,\n })}\n borderThickness={borderThickness}\n data={section.items}\n selectionMode={selectionMode}\n isTogglable={isTogglable}\n itemComponentType={itemComponentType}\n itemLength={itemLength}\n itemPadding={itemPadding}\n orientation={orientation}\n selectedIndices={selectedItemIndices[sectionIdx] ?? []}\n onActivateAt={itemIdx => onActivateAt?.(sectionIdx, itemIdx)}\n onDeselectAt={itemIdx => deselectAt(sectionIdx, itemIdx)}\n onSelectAt={itemIdx => selectAt(sectionIdx, itemIdx)}\n />\n </div>\n )\n }}\n </Each>\n </div>\n )\n}) as <T>(props: AccordionProps<T> & { ref?: Ref<HTMLDivElement> }) => ReactElement\n"]}
|
|
1
|
+
{"version":3,"file":"Accordion.js","sourceRoot":"/","sources":["Accordion.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAAmC;AACnC,gEAA+C;AAC/C,6CAA4J;AAC5J,gDAAyB;AACzB,sDAA+B;AAC/B,gDAAiE;AACjE,oEAA6C;AAC7C,4EAAqD;AACrD,oEAA6C;AAC7C,kFAA2D;AAC3D,0DAAmC;AAiInC,kBAAe,IAAA,kBAAU,EAAC,UAAC,EA4B1B,EAAE,GAAG;IA3BJ,IAAA,QAAQ,cAAA,EACR,SAAS,eAAA,EACT,KAAK,WAAA,EACL,4BAA4B,EAA5B,oBAAoB,mBAAG,KAAK,KAAA,EAC5B,uBAAmB,EAAnB,eAAe,mBAAG,CAAC,KAAA,EACnB,eAAe,qBAAA,EACf,IAAI,UAAA,EACJ,8BAA2D,EAAnC,8BAA8B,mBAAG,EAAE,KAAA,EAC3D,aAAa,mBAAA,EACb,4BAA4B,EAA5B,oBAAoB,mBAAG,KAAK,KAAA,EAC5B,kBAAe,EAAf,UAAU,mBAAG,EAAE,KAAA,EACf,mBAAe,EAAf,WAAW,mBAAG,CAAC,KAAA,EACf,uBAAoB,EAApB,eAAe,mBAAG,CAAC,CAAC,KAAA,EACpB,mBAAwB,EAAxB,WAAW,mBAAG,UAAU,KAAA,EACxB,sBAAkB,EAAlB,cAAc,mBAAG,CAAC,KAAA,EAClB,2BAAqD,EAAhC,2BAA2B,mBAAG,EAAE,KAAA,EACrD,qBAAwB,EAAxB,aAAa,mBAAG,QAAQ,KAAA,EACH,eAAe,yBAAA,EACpC,iBAAiB,uBAAA,EACjB,YAAY,kBAAA,EACZ,mBAAmB,yBAAA,EACnB,YAAY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AAC,CACI,CACH,CACP,CAAA;AACH,CAAC,CAAkF,CAAA","sourcesContent":["import classNames from 'classnames'\nimport isDeepEqual from 'fast-deep-equal/react'\nimport React, { forwardRef, useEffect, useState, type ComponentType, type HTMLAttributes, type PropsWithChildren, type ReactElement, type Ref } from 'react'\nimport Each from './Each'\nimport FlatSVG from './FlatSVG'\nimport List, { type ListItemProps, type ListProps } from './List'\nimport usePrevious from './hooks/usePrevious'\nimport asClassNameDict from './utils/asClassNameDict'\nimport asStyleDict from './utils/asStyleDict'\nimport cloneStyledElement from './utils/cloneStyledElement'\nimport styles from './utils/styles'\n\nexport type AccordionItemProps<T> = ListItemProps<T>\n\nexport type AccordionHeaderProps<T, A = never> = HTMLAttributes<HTMLElement> & PropsWithChildren<{\n attributes?: A\n data: AccordionSectionData<T>\n index: number\n isCollapsed: boolean\n onCustomEvent?: (name: string, info?: any) => void\n}>\n\nexport type AccordionSectionData<T> = {\n label: string\n items: T[]\n}\n\nexport type AccordionProps<T> = HTMLAttributes<HTMLDivElement> & Omit<ListProps<T>, 'data' | 'itemComponentType' | 'selectedIndices' | 'onActivateAt' | 'onSelectAt' | 'onDeselectAt' | 'onSelectionChange'> & PropsWithChildren<{\n /**\n * Specifies if expanded sections should automatically collapse upon expanding\n * another section.\n */\n autoCollapseSections?: boolean\n\n /**\n * SVG markup to be put in the section header as the collapse icon.\n */\n collapseIconSvg?: string\n\n /**\n * Data provided to each section.\n */\n data: AccordionSectionData<T>[]\n\n /**\n * Indices of sections that are expanded.\n */\n expandedSectionIndices?: number[]\n\n /**\n * SVG markup to be put in the section header as the expand icon.\n */\n expandIconSvg?: string\n\n /**\n * Maximum number of items that are viside when a section expands. When a\n * value greater than or equal to 0 is specified, only that number of items\n * will be visible at a time, and a scrollbar will appear to scroll to\n * remaining items. Any value less than 0 indicates that all items will be\n * visible when a section expands.\n */\n maxVisibleItems?: number\n\n /**\n * Padding (in pixels) between each section.\n */\n sectionPadding?: number\n\n /**\n * Indices of selected items per section.\n */\n selectedItemIndices?: Record<number, number[]>\n\n /**\n * React component type to be used for generating headers inside the\n * component. When absent, one will be generated automatically.\n */\n headerComponentType?: ComponentType<AccordionHeaderProps<T>>\n\n /**\n * React component type to be used for generating items inside the component.\n */\n itemComponentType: ComponentType<AccordionItemProps<T>>\n\n /**\n * Handler invoked when an item is activated in a section.\n *\n * @param itemIndex Item index.\n * @param sectionIndex Section index.\n */\n onActivateAt?: (itemIndex: number, sectionIndex: number) => void\n\n /**\n * Handler invoked when a section is collapsed.\n *\n * @param sectionIndex Section index.\n */\n onCollapseSectionAt?: (sectionIndex: number) => void\n\n /**\n * Handler invoked when an item is deselected in a section.\n *\n * @param itemIndex Item index.\n * @param sectionIndex Section index.\n */\n onDeselectAt?: (itemIndex: number, sectionIndex: number) => void\n\n /**\n * Handler invoked when a section is expanded.\n *\n * @param sectionIndex Section index.\n */\n onExpandSectionAt?: (sectionIndex: number) => void\n\n /**\n * Handler invoked when a custom event is dispatched from a section header.\n *\n * @param index Index of the section header.\n * @param eventName Name of the dispatched event.\n * @param eventInfo Optional info of the dispatched event.\n */\n onHeaderCustomEvent?: (index: number, eventName: string, eventInfo?: any) => void\n\n /**\n * Handler invoked when an item is selected in a section.\n *\n * @param itemIndex Item index.\n * @param sectionIndex Section index.\n */\n onSelectAt?: (itemIndex: number, sectionIndex: number) => void\n\n /**\n * Handler invoked when selected items have changed.\n *\n * @param selectedIndices Dictionary of indices of selected items per section.\n */\n onSelectionChange?: (selectedIndices: Record<number, number[]>) => void\n}>\n\nexport default forwardRef(({\n children,\n className,\n style,\n autoCollapseSections = false,\n borderThickness = 0,\n collapseIconSvg,\n data,\n expandedSectionIndices: externalExpandedSectionIndices = [],\n expandIconSvg,\n isSelectionTogglable = false,\n itemLength = 50,\n itemPadding = 0,\n maxVisibleItems = -1,\n orientation = 'vertical',\n sectionPadding = 0,\n selectedItemIndices: externalSelectedItemIndices = {},\n selectionMode = 'single',\n headerComponentType: HeaderComponent,\n itemComponentType,\n onActivateAt,\n onCollapseSectionAt,\n onDeselectAt,\n onExpandSectionAt,\n onHeaderCustomEvent,\n onSelectAt,\n onSelectionChange,\n ...props\n}, ref) => {\n const isSectionIndexOutOfRange = (sectionIndex: number) => {\n if (sectionIndex >= data.length) return true\n if (sectionIndex < 0) return true\n\n return false\n }\n\n const isItemIndexOutOfRange = (itemIndex: number, sectionIndex: number) => {\n if (isSectionIndexOutOfRange(sectionIndex)) return true\n\n const items = data[sectionIndex].items\n\n if (itemIndex >= items.length) return true\n if (itemIndex < 0) return true\n\n return false\n }\n\n const sanitizeExpandedSectionIndices = (sectionIndices: number[]) => sectionIndices.sort().filter(t => !isSectionIndexOutOfRange(t))\n\n const sanitizeSelectedItemIndices = (itemIndices: Record<number, number[]>) => {\n const newValue: Record<number, number[]> = {}\n\n for (const sectionIndex in itemIndices) {\n if (!Object.prototype.hasOwnProperty.call(itemIndices, sectionIndex)) continue\n\n const indices = itemIndices[sectionIndex]\n\n if (!indices || !(indices instanceof Array) || indices.length === 0) continue\n\n newValue[sectionIndex] = indices.sort().filter(t => !isItemIndexOutOfRange(t, Number(sectionIndex)))\n }\n\n return newValue\n }\n\n const isSectionExpandedAt = (sectionIndex: number) => expandedSectionIndices.indexOf(sectionIndex) >= 0\n\n const toggleSectionAt = (sectionIndex: number) => {\n if (isSectionIndexOutOfRange(sectionIndex)) return\n\n if (isSectionExpandedAt(sectionIndex)) {\n setExpandedSectionIndices(prev => prev.filter(t => t !== sectionIndex))\n }\n else if (autoCollapseSections) {\n setExpandedSectionIndices([sectionIndex])\n }\n else {\n setExpandedSectionIndices(prev => [...prev.filter(t => t !== sectionIndex), sectionIndex].sort())\n }\n }\n\n const selectAt = (itemIndex: number, sectionIndex: number) => {\n if (isItemIndexOutOfRange(itemIndex, sectionIndex)) return\n\n switch (selectionMode) {\n case 'multiple':\n setSelectedItemIndices(prev => ({\n ...prev,\n [sectionIndex]: [...(prev[sectionIndex] ?? []).filter(t => t !== itemIndex), itemIndex].sort(),\n }))\n\n onSelectAt?.(itemIndex, sectionIndex)\n\n break\n case 'single':\n setSelectedItemIndices({\n [sectionIndex]: [itemIndex],\n })\n\n onSelectAt?.(itemIndex, sectionIndex)\n\n break\n default:\n break\n }\n }\n\n const deselectAt = (itemIndex: number, sectionIndex: number) => {\n if (isItemIndexOutOfRange(itemIndex, sectionIndex)) return\n\n setSelectedItemIndices(prev => ({\n ...prev,\n [sectionIndex]: (prev[sectionIndex] ?? []).filter(t => t !== itemIndex),\n }))\n\n onDeselectAt?.(itemIndex, sectionIndex)\n }\n\n const [expandedSectionIndices, setExpandedSectionIndices] = useState(sanitizeExpandedSectionIndices(externalExpandedSectionIndices))\n const prevExpandedSectionIndices = usePrevious(expandedSectionIndices)\n const [selectedItemIndices, setSelectedItemIndices] = useState(externalSelectedItemIndices)\n\n useEffect(() => {\n const newValue = sanitizeExpandedSectionIndices(externalExpandedSectionIndices)\n\n if (isDeepEqual(newValue, expandedSectionIndices)) return\n\n setExpandedSectionIndices(newValue)\n }, [JSON.stringify(sanitizeExpandedSectionIndices(externalExpandedSectionIndices))])\n\n useEffect(() => {\n const collapsed = prevExpandedSectionIndices?.filter(t => expandedSectionIndices.indexOf(t) === -1) ?? []\n const expanded = expandedSectionIndices.filter(t => prevExpandedSectionIndices?.indexOf(t) === -1)\n\n collapsed.map(t => onCollapseSectionAt?.(t))\n expanded.map(t => onExpandSectionAt?.(t))\n }, [JSON.stringify(sanitizeExpandedSectionIndices(expandedSectionIndices))])\n\n useEffect(() => {\n const newValue = sanitizeSelectedItemIndices(externalSelectedItemIndices)\n\n if (isDeepEqual(newValue, selectedItemIndices)) return\n\n setSelectedItemIndices(newValue)\n }, [JSON.stringify(sanitizeSelectedItemIndices(externalSelectedItemIndices))])\n\n useEffect(() => {\n onSelectionChange?.(selectedItemIndices)\n }, [JSON.stringify(sanitizeSelectedItemIndices(selectedItemIndices))])\n\n const fixedClassNames = asClassNameDict({\n root: classNames(orientation),\n header: classNames(orientation),\n expandIcon: classNames(orientation),\n collapseIcon: classNames(orientation),\n })\n\n const fixedStyles = asStyleDict({\n root: {\n alignItems: 'center',\n boxSizing: 'border-box',\n display: 'flex',\n flex: '0 0 auto',\n justifyContent: 'flex-start',\n padding: '0',\n ...orientation === 'vertical' ? {\n flexDirection: 'column',\n height: 'auto',\n } : {\n flexDirection: 'row',\n width: 'auto',\n },\n },\n section: {\n alignItems: 'flex-start',\n display: 'flex',\n flex: '0 0 auto',\n justifyContent: 'flex-start',\n margin: '0',\n padding: '0',\n ...orientation === 'vertical' ? {\n flexDirection: 'column',\n width: '100%',\n } : {\n flexDirection: 'row',\n height: '100%',\n },\n },\n header: {\n borderWidth: `${borderThickness}px`,\n cursor: 'pointer',\n margin: '0',\n outline: 'none',\n ...orientation === 'vertical' ? {\n width: '100%',\n } : {\n height: '100%',\n },\n },\n headerLabel: {\n color: 'inherit',\n fontFamily: 'inherit',\n fontSize: 'inherit',\n fontWeight: 'inherit',\n letterSpacing: 'inherit',\n lineHeight: 'inherit',\n pointerEvents: 'none',\n transition: 'inherit',\n },\n expandIcon: {\n margin: '0',\n padding: '0',\n },\n collapseIcon: {\n margin: '0',\n padding: '0',\n },\n list: {\n transitionDuration: '100ms',\n transitionTimingFunction: 'ease-out',\n ...orientation === 'vertical' ? {\n width: '100%',\n transitionProperty: 'height, margin',\n top: '100%',\n } : {\n height: '100%',\n transitionProperty: 'width, margin',\n left: '100%',\n },\n },\n })\n\n const defaultStyles = asStyleDict({\n header: {\n alignItems: 'center',\n background: '#fff',\n borderStyle: 'solid',\n boxSizing: 'border-box',\n display: 'flex',\n flexDirection: 'row',\n justifyContent: 'space-between',\n padding: '0 10px',\n transitionDuration: '100ms',\n transitionProperty: 'transform, opacity, background, color',\n transitionTimingFunction: 'ease-out',\n ...orientation === 'vertical' ? {\n height: '50px',\n } : {\n width: '50px',\n },\n },\n expandIcon: {\n boxSizing: 'border-box',\n display: 'block',\n fill: '#000',\n height: '15px',\n transformOrigin: 'center',\n transitionDuration: '100ms',\n transitionProperty: 'transform',\n transitionTimingFunction: 'ease-out',\n width: '15px',\n },\n collapseIcon: {\n boxSizing: 'border-box',\n display: 'block',\n fill: '#000',\n height: '15px',\n transformOrigin: 'center',\n transitionDuration: '100ms',\n transitionProperty: 'transform',\n transitionTimingFunction: 'ease-out',\n width: '15px',\n },\n })\n\n return (\n <div\n {...props}\n className={classNames(className, fixedClassNames.root)}\n style={styles(style, fixedStyles.root)}\n >\n <Each in={data}>\n {(section, sectionIndex) => {\n const numItems = section.items.length\n const numVisibleItems = maxVisibleItems < 0 ? numItems : Math.min(numItems, maxVisibleItems)\n const menuLength = (itemLength - borderThickness) * numVisibleItems + itemPadding * (numVisibleItems - 1) + borderThickness\n const isCollapsed = !isSectionExpandedAt(sectionIndex)\n const expandIconComponent = expandIconSvg ? <FlatSVG svg={expandIconSvg} style={defaultStyles.expandIcon}/> : <></>\n const collapseIconComponent = collapseIconSvg ? <FlatSVG svg={collapseIconSvg} style={defaultStyles.collapseIcon}/> : expandIconComponent\n\n return (\n <div style={styles(fixedStyles.section, orientation === 'vertical' ? {\n marginTop: sectionIndex === 0 ? '0px' : `${sectionPadding - borderThickness}px`,\n } : {\n marginLeft: sectionIndex === 0 ? '0px' : `${sectionPadding - borderThickness}px`,\n })}>\n {HeaderComponent ? (\n <HeaderComponent\n className={classNames(fixedClassNames.header, { collapsed: isCollapsed, expanded: !isCollapsed })}\n style={styles(fixedStyles.header)}\n data={section}\n index={sectionIndex}\n isCollapsed={isCollapsed}\n onClick={() => toggleSectionAt(sectionIndex)}\n onCustomEvent={(name, info) => onHeaderCustomEvent?.(sectionIndex, name, info)}\n />\n ) : (\n <button\n className={classNames(fixedClassNames.header, { collapsed: isCollapsed, expanded: !isCollapsed })}\n style={styles(fixedStyles.header, defaultStyles.header)}\n onClick={() => toggleSectionAt(sectionIndex)}\n >\n <label style={fixedStyles.headerLabel} dangerouslySetInnerHTML={{ __html: section.label }}/>\n {cloneStyledElement(isCollapsed ? expandIconComponent : collapseIconComponent, {\n className: classNames(isCollapsed ? fixedClassNames.expandIcon : fixedClassNames.collapseIcon),\n style: styles(isCollapsed ? fixedStyles.expandIcon : fixedStyles.collapseIcon),\n })}\n </button>\n )}\n <List\n style={styles(fixedStyles.list, orientation === 'vertical' ? {\n height: isCollapsed ? '0px' : `${menuLength}px`,\n marginTop: isCollapsed ? '0px' : `${itemPadding - borderThickness}px`,\n overflowY: maxVisibleItems === -1 ? 'hidden' : maxVisibleItems < numItems ? 'scroll' : 'hidden',\n } : {\n marginLeft: isCollapsed ? '0px' : `${itemPadding - borderThickness}px`,\n overflowX: maxVisibleItems === -1 ? 'hidden' : maxVisibleItems < numItems ? 'scroll' : 'hidden',\n width: isCollapsed ? '0px' : `${menuLength}px`,\n })}\n borderThickness={borderThickness}\n data={section.items}\n selectionMode={selectionMode}\n isSelectionTogglable={isSelectionTogglable}\n itemComponentType={itemComponentType}\n itemLength={itemLength}\n itemPadding={itemPadding}\n orientation={orientation}\n selectedIndices={selectedItemIndices[sectionIndex] ?? []}\n onActivateAt={itemIndex => onActivateAt?.(itemIndex, sectionIndex)}\n onDeselectAt={itemIndex => deselectAt(itemIndex, sectionIndex)}\n onSelectAt={itemIndex => selectAt(itemIndex, sectionIndex)}\n />\n </div>\n )\n }}\n </Each>\n </div>\n )\n}) as <T>(props: AccordionProps<T> & { ref?: Ref<HTMLDivElement> }) => ReactElement\n"]}
|
package/lib/Dropdown.d.ts
CHANGED
|
@@ -3,7 +3,9 @@ import { type ListItemProps, type ListProps } from './List';
|
|
|
3
3
|
export type DropdownData = {
|
|
4
4
|
label?: string;
|
|
5
5
|
};
|
|
6
|
-
export type DropdownToggleProps = HTMLAttributes<HTMLElement> &
|
|
6
|
+
export type DropdownToggleProps = HTMLAttributes<HTMLElement> & {
|
|
7
|
+
onCustomEvent?: (name: string, info?: any) => void;
|
|
8
|
+
};
|
|
7
9
|
export type DropdownItemProps<T extends DropdownData = DropdownData> = ListItemProps<T>;
|
|
8
10
|
export type DropdownProps<T extends DropdownData = DropdownData> = HTMLAttributes<HTMLDivElement> & ListProps<T> & PropsWithChildren<{
|
|
9
11
|
/**
|
|
@@ -41,6 +43,13 @@ export type DropdownProps<T extends DropdownData = DropdownData> = HTMLAttribute
|
|
|
41
43
|
* the component. When absent, one will be generated automatically.
|
|
42
44
|
*/
|
|
43
45
|
toggleComponentType?: ComponentType<DropdownToggleProps>;
|
|
46
|
+
/**
|
|
47
|
+
* Handler invoked when the toggle dispatches a custom event.
|
|
48
|
+
*
|
|
49
|
+
* @param eventName Name of the dispatched custom event.
|
|
50
|
+
* @param eventInfo Optional info of the dispatched custom event.
|
|
51
|
+
*/
|
|
52
|
+
onToggleCustomEvent?: (eventName: string, eventInfo?: any) => void;
|
|
44
53
|
}>;
|
|
45
54
|
/**
|
|
46
55
|
* A dropdown menu component that is invertible (i.e. can "dropup" instead) and
|
|
@@ -50,25 +59,16 @@ export type DropdownProps<T extends DropdownData = DropdownData> = HTMLAttribute
|
|
|
50
59
|
declare const _default: <T extends DropdownData = DropdownData>(props: React.HTMLAttributes<HTMLDivElement> & {
|
|
51
60
|
borderThickness?: number | undefined;
|
|
52
61
|
data: T[];
|
|
53
|
-
|
|
54
|
-
itemComponentType?: React.ComponentType<ListItemProps<T>> | undefined;
|
|
62
|
+
isSelectionTogglable?: boolean | undefined;
|
|
55
63
|
itemLength?: number | undefined;
|
|
56
64
|
itemPadding?: number | undefined;
|
|
57
|
-
orientation?: ("horizontal" | "vertical") | undefined;
|
|
58
|
-
* Indicates if the component is inverted (i.e. "dropup" instead of dropdown).
|
|
59
|
-
* Supports all orientations.
|
|
60
|
-
*/
|
|
65
|
+
orientation?: ("horizontal" | "vertical") | undefined;
|
|
61
66
|
selectedIndices?: number[] | undefined;
|
|
62
|
-
/**
|
|
63
|
-
* Maximum number of items that are viside when the component expands. When a
|
|
64
|
-
* value greater than or equal to 0 is specified, only that number of items
|
|
65
|
-
* will be visible at a time, and a scrollbar will appear to scroll to
|
|
66
|
-
* remaining items. Any value less than 0 indicates that all items will be
|
|
67
|
-
* visible when the component expands.
|
|
68
|
-
*/
|
|
69
67
|
selectionMode?: "none" | "multiple" | "single" | undefined;
|
|
68
|
+
itemComponentType?: React.ComponentType<ListItemProps<T>> | undefined;
|
|
70
69
|
onActivateAt?: ((index: number) => void) | undefined;
|
|
71
70
|
onDeselectAt?: ((index: number) => void) | undefined;
|
|
71
|
+
onItemCustomEvent?: ((index: number, eventName: string, eventInfo?: any) => void) | undefined;
|
|
72
72
|
onSelectAt?: ((index: number) => void) | undefined;
|
|
73
73
|
onSelectionChange?: ((indices: number[]) => void) | undefined;
|
|
74
74
|
} & {
|
|
@@ -107,6 +107,13 @@ declare const _default: <T extends DropdownData = DropdownData>(props: React.HTM
|
|
|
107
107
|
* the component. When absent, one will be generated automatically.
|
|
108
108
|
*/
|
|
109
109
|
toggleComponentType?: React.ComponentType<DropdownToggleProps> | undefined;
|
|
110
|
+
/**
|
|
111
|
+
* Handler invoked when the toggle dispatches a custom event.
|
|
112
|
+
*
|
|
113
|
+
* @param eventName Name of the dispatched custom event.
|
|
114
|
+
* @param eventInfo Optional info of the dispatched custom event.
|
|
115
|
+
*/
|
|
116
|
+
onToggleCustomEvent?: ((eventName: string, eventInfo?: any) => void) | undefined;
|
|
110
117
|
} & {
|
|
111
118
|
children?: React.ReactNode;
|
|
112
119
|
} & {
|