etudes 3.7.0 → 3.8.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.
@@ -1,17 +1,26 @@
1
1
  import React, { type ComponentType, type HTMLAttributes, type PropsWithChildren, type ReactElement, type Ref } from 'react';
2
- import { type ListItemProps, type ListProps } from './List';
3
- export type AccordionItemProps<I> = ListItemProps<I>;
4
- export type AccordionHeaderProps<I, S extends AccordionSectionData<I> = AccordionSectionData<I>> = HTMLAttributes<HTMLElement> & PropsWithChildren<{
5
- section: S;
2
+ import { type ListItemProps, type ListOrientation, type ListProps, type ListSelectionMode } from './List';
3
+ export type AccordionSectionProps<I> = Omit<ListProps<I>, 'orientation' | 'selection' | 'selectionMode' | 'onActivateAt' | 'onSelectAt' | 'onDeselectAt' | 'onSelectionChange'> & {
4
+ /**
5
+ * Label for the header.
6
+ */
7
+ label: string;
8
+ /**
9
+ * Maximum number of visible rows (if section orientation is `vertical`) or
10
+ * columns (if section orientation is `horizontal`). If number of rows exceeds
11
+ * the number of visible, a scrollbar will be put in place.
12
+ */
13
+ maxVisible?: number;
14
+ };
15
+ export type AccordionSelection = Record<number, number[]>;
16
+ export type AccordionItemProps<T> = ListItemProps<T>;
17
+ export type AccordionHeaderProps<I, S extends AccordionSectionProps<I> = AccordionSectionProps<I>> = HTMLAttributes<HTMLElement> & PropsWithChildren<{
6
18
  index: number;
7
19
  isCollapsed: boolean;
20
+ section: S;
8
21
  onCustomEvent?: (name: string, info?: any) => void;
9
22
  }>;
10
- export type AccordionSectionData<I> = {
11
- label: string;
12
- items: I[];
13
- };
14
- export type AccordionProps<I, S extends AccordionSectionData<I> = AccordionSectionData<I>> = HTMLAttributes<HTMLDivElement> & Omit<ListProps<I>, 'data' | 'itemComponentType' | 'selectedIndices' | 'onActivateAt' | 'onSelectAt' | 'onDeselectAt' | 'onSelectionChange'> & PropsWithChildren<{
23
+ export type AccordionProps<I, S extends AccordionSectionProps<I> = AccordionSectionProps<I>> = HTMLAttributes<HTMLDivElement> & PropsWithChildren<{
15
24
  /**
16
25
  * Specifies if expanded sections should automatically collapse upon expanding
17
26
  * another section.
@@ -34,13 +43,9 @@ export type AccordionProps<I, S extends AccordionSectionData<I> = AccordionSecti
34
43
  */
35
44
  expandIconSvg?: string;
36
45
  /**
37
- * Maximum number of items that are viside when a section expands. When a
38
- * value greater than or equal to 0 is specified, only that number of items
39
- * will be visible at a time, and a scrollbar will appear to scroll to
40
- * remaining items. Any value less than 0 indicates that all items will be
41
- * visible when a section expands.
46
+ * Orientation of this component.
42
47
  */
43
- maxVisibleItems?: number;
48
+ orientation?: ListOrientation;
44
49
  /**
45
50
  * Padding (in pixels) between each section.
46
51
  */
@@ -48,16 +53,20 @@ export type AccordionProps<I, S extends AccordionSectionData<I> = AccordionSecti
48
53
  /**
49
54
  * Indices of selected items per section.
50
55
  */
51
- selectedItemIndices?: Record<number, number[]>;
56
+ selection?: AccordionSelection;
57
+ /**
58
+ * Selection mode of each section.
59
+ */
60
+ selectionMode?: ListSelectionMode;
52
61
  /**
53
62
  * React component type to be used for generating headers inside the
54
63
  * component. When absent, one will be generated automatically.
55
64
  */
56
65
  headerComponentType?: ComponentType<AccordionHeaderProps<I, S>>;
57
66
  /**
58
- * React component type to be used for generating items inside the component.
67
+ * Specifies if the component should use default styles.
59
68
  */
60
- itemComponentType: ComponentType<AccordionItemProps<I>>;
69
+ useDefaultStyles?: boolean;
61
70
  /**
62
71
  * Handler invoked when an item is activated in a section.
63
72
  *
@@ -87,11 +96,20 @@ export type AccordionProps<I, S extends AccordionSectionData<I> = AccordionSecti
87
96
  /**
88
97
  * Handler invoked when a custom event is dispatched from a section header.
89
98
  *
90
- * @param index Index of the section header.
99
+ * @param sectionIndex Index of the section which the header belongs.
100
+ * @param eventName Name of the dispatched event.
101
+ * @param eventInfo Optional info of the dispatched event.
102
+ */
103
+ onHeaderCustomEvent?: (sectionIndex: number, eventName: string, eventInfo?: any) => void;
104
+ /**
105
+ * Handler invoked when a custom event is dispatched from an item.
106
+ *
107
+ * @param itemIndex Item index.
108
+ * @param sectionIndex Section index.
91
109
  * @param eventName Name of the dispatched event.
92
110
  * @param eventInfo Optional info of the dispatched event.
93
111
  */
94
- onHeaderCustomEvent?: (index: number, eventName: string, eventInfo?: any) => void;
112
+ onItemCustomEvent?: (itemIndex: number, sectionIndex: number, eventName: string, eventInfo?: any) => void;
95
113
  /**
96
114
  * Handler invoked when an item is selected in a section.
97
115
  *
@@ -104,9 +122,9 @@ export type AccordionProps<I, S extends AccordionSectionData<I> = AccordionSecti
104
122
  *
105
123
  * @param selectedIndices Dictionary of indices of selected items per section.
106
124
  */
107
- onSelectionChange?: (selectedIndices: Record<number, number[]>) => void;
125
+ onSelectionChange?: (selection: AccordionSelection) => void;
108
126
  }>;
109
- declare const _default: <I, S extends AccordionSectionData<I> = AccordionSectionData<I>>(props: React.HTMLAttributes<HTMLDivElement> & Omit<ListProps<I>, "data" | "selectedIndices" | "itemComponentType" | "onActivateAt" | "onDeselectAt" | "onSelectAt" | "onSelectionChange"> & {
127
+ declare const _default: <I, S extends AccordionSectionProps<I> = AccordionSectionProps<I>>(props: React.HTMLAttributes<HTMLDivElement> & {
110
128
  /**
111
129
  * Specifies if expanded sections should automatically collapse upon expanding
112
130
  * another section.
@@ -129,13 +147,9 @@ declare const _default: <I, S extends AccordionSectionData<I> = AccordionSection
129
147
  */
130
148
  expandIconSvg?: string | undefined;
131
149
  /**
132
- * Maximum number of items that are viside when a section expands. When a
133
- * value greater than or equal to 0 is specified, only that number of items
134
- * will be visible at a time, and a scrollbar will appear to scroll to
135
- * remaining items. Any value less than 0 indicates that all items will be
136
- * visible when a section expands.
150
+ * Orientation of this component.
137
151
  */
138
- maxVisibleItems?: number | undefined;
152
+ orientation?: ListOrientation | undefined;
139
153
  /**
140
154
  * Padding (in pixels) between each section.
141
155
  */
@@ -143,16 +157,20 @@ declare const _default: <I, S extends AccordionSectionData<I> = AccordionSection
143
157
  /**
144
158
  * Indices of selected items per section.
145
159
  */
146
- selectedItemIndices?: Record<number, number[]> | undefined;
160
+ selection?: AccordionSelection | undefined;
161
+ /**
162
+ * Selection mode of each section.
163
+ */
164
+ selectionMode?: ListSelectionMode | undefined;
147
165
  /**
148
166
  * React component type to be used for generating headers inside the
149
167
  * component. When absent, one will be generated automatically.
150
168
  */
151
169
  headerComponentType?: React.ComponentType<AccordionHeaderProps<I, S>> | undefined;
152
170
  /**
153
- * React component type to be used for generating items inside the component.
171
+ * Specifies if the component should use default styles.
154
172
  */
155
- itemComponentType: React.ComponentType<AccordionItemProps<I>>;
173
+ useDefaultStyles?: boolean | undefined;
156
174
  /**
157
175
  * Handler invoked when an item is activated in a section.
158
176
  *
@@ -182,11 +200,20 @@ declare const _default: <I, S extends AccordionSectionData<I> = AccordionSection
182
200
  /**
183
201
  * Handler invoked when a custom event is dispatched from a section header.
184
202
  *
185
- * @param index Index of the section header.
203
+ * @param sectionIndex Index of the section which the header belongs.
204
+ * @param eventName Name of the dispatched event.
205
+ * @param eventInfo Optional info of the dispatched event.
206
+ */
207
+ onHeaderCustomEvent?: ((sectionIndex: number, eventName: string, eventInfo?: any) => void) | undefined;
208
+ /**
209
+ * Handler invoked when a custom event is dispatched from an item.
210
+ *
211
+ * @param itemIndex Item index.
212
+ * @param sectionIndex Section index.
186
213
  * @param eventName Name of the dispatched event.
187
214
  * @param eventInfo Optional info of the dispatched event.
188
215
  */
189
- onHeaderCustomEvent?: ((index: number, eventName: string, eventInfo?: any) => void) | undefined;
216
+ onItemCustomEvent?: ((itemIndex: number, sectionIndex: number, eventName: string, eventInfo?: any) => void) | undefined;
190
217
  /**
191
218
  * Handler invoked when an item is selected in a section.
192
219
  *
@@ -199,7 +226,7 @@ declare const _default: <I, S extends AccordionSectionData<I> = AccordionSection
199
226
  *
200
227
  * @param selectedIndices Dictionary of indices of selected items per section.
201
228
  */
202
- onSelectionChange?: ((selectedIndices: Record<number, number[]>) => void) | undefined;
229
+ onSelectionChange?: ((selection: AccordionSelection) => void) | undefined;
203
230
  } & {
204
231
  children?: React.ReactNode;
205
232
  } & {
package/lib/Accordion.js CHANGED
@@ -85,7 +85,7 @@ 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
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"]);
88
+ var children = _a.children, className = _a.className, style = _a.style, _b = _a.autoCollapseSections, autoCollapseSections = _b === void 0 ? false : _b, collapseIconSvg = _a.collapseIconSvg, data = _a.data, _c = _a.expandedSectionIndices, externalExpandedSectionIndices = _c === void 0 ? [] : _c, expandIconSvg = _a.expandIconSvg, _d = _a.orientation, orientation = _d === void 0 ? 'vertical' : _d, _e = _a.sectionPadding, sectionPadding = _e === void 0 ? 0 : _e, _f = _a.selection, externalSelection = _f === void 0 ? {} : _f, _g = _a.selectionMode, selectionMode = _g === void 0 ? 'single' : _g, _h = _a.useDefaultStyles, useDefaultStyles = _h === void 0 ? false : _h, HeaderComponent = _a.headerComponentType, onActivateAt = _a.onActivateAt, onCollapseSectionAt = _a.onCollapseSectionAt, onDeselectAt = _a.onDeselectAt, onExpandSectionAt = _a.onExpandSectionAt, onHeaderCustomEvent = _a.onHeaderCustomEvent, onItemCustomEvent = _a.onItemCustomEvent, onSelectAt = _a.onSelectAt, onSelectionChange = _a.onSelectionChange, props = __rest(_a, ["children", "className", "style", "autoCollapseSections", "collapseIconSvg", "data", "expandedSectionIndices", "expandIconSvg", "orientation", "sectionPadding", "selection", "selectionMode", "useDefaultStyles", "headerComponentType", "onActivateAt", "onCollapseSectionAt", "onDeselectAt", "onExpandSectionAt", "onHeaderCustomEvent", "onItemCustomEvent", "onSelectAt", "onSelectionChange"]);
89
89
  var isSectionIndexOutOfRange = function (sectionIndex) {
90
90
  if (sectionIndex >= data.length)
91
91
  return true;
@@ -96,7 +96,7 @@ exports.default = (0, react_2.forwardRef)(function (_a, ref) {
96
96
  var isItemIndexOutOfRange = function (itemIndex, sectionIndex) {
97
97
  if (isSectionIndexOutOfRange(sectionIndex))
98
98
  return true;
99
- var items = data[sectionIndex].items;
99
+ var items = data[sectionIndex].data;
100
100
  if (itemIndex >= items.length)
101
101
  return true;
102
102
  if (itemIndex < 0)
@@ -104,25 +104,22 @@ exports.default = (0, react_2.forwardRef)(function (_a, ref) {
104
104
  return false;
105
105
  };
106
106
  var sanitizeExpandedSectionIndices = function (sectionIndices) { return sectionIndices.sort().filter(function (t) { return !isSectionIndexOutOfRange(t); }); };
107
- var sanitizeSelectedItemIndices = function (itemIndices) {
107
+ var sanitizeSelection = function (selection) {
108
+ var _a;
108
109
  var newValue = {};
109
110
  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)
111
+ if (!Object.prototype.hasOwnProperty.call(data, sectionIndex))
114
112
  return "continue";
115
- newValue[sectionIndex] = indices.sort().filter(function (t) { return !isItemIndexOutOfRange(t, Number(sectionIndex)); });
113
+ var indices = __spreadArray([], __read((_a = selection[sectionIndex]) !== null && _a !== void 0 ? _a : []), false).sort();
114
+ newValue[Number(sectionIndex)] = indices.sort().filter(function (t) { return !isItemIndexOutOfRange(t, Number(sectionIndex)); });
116
115
  };
117
- for (var sectionIndex in itemIndices) {
116
+ for (var sectionIndex in data) {
118
117
  _loop_1(sectionIndex);
119
118
  }
120
119
  return newValue;
121
120
  };
122
121
  var isSectionExpandedAt = function (sectionIndex) { return expandedSectionIndices.indexOf(sectionIndex) >= 0; };
123
122
  var toggleSectionAt = function (sectionIndex) {
124
- if (isSectionIndexOutOfRange(sectionIndex))
125
- return;
126
123
  if (isSectionExpandedAt(sectionIndex)) {
127
124
  setExpandedSectionIndices(function (prev) { return prev.filter(function (t) { return t !== sectionIndex; }); });
128
125
  }
@@ -130,16 +127,14 @@ exports.default = (0, react_2.forwardRef)(function (_a, ref) {
130
127
  setExpandedSectionIndices([sectionIndex]);
131
128
  }
132
129
  else {
133
- setExpandedSectionIndices(function (prev) { return __spreadArray(__spreadArray([], __read(prev.filter(function (t) { return t !== sectionIndex; })), false), [sectionIndex], false).sort(); });
130
+ setExpandedSectionIndices(function (prev) { return __spreadArray(__spreadArray([], __read(prev.filter(function (t) { return t !== sectionIndex; })), false), [sectionIndex], false); });
134
131
  }
135
132
  };
136
133
  var selectAt = function (itemIndex, sectionIndex) {
137
134
  var _a;
138
- if (isItemIndexOutOfRange(itemIndex, sectionIndex))
139
- return;
140
135
  switch (selectionMode) {
141
136
  case 'multiple':
142
- setSelectedItemIndices(function (prev) {
137
+ setSelection(function (prev) {
143
138
  var _a;
144
139
  var _b;
145
140
  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)));
@@ -147,7 +142,7 @@ exports.default = (0, react_2.forwardRef)(function (_a, ref) {
147
142
  onSelectAt === null || onSelectAt === void 0 ? void 0 : onSelectAt(itemIndex, sectionIndex);
148
143
  break;
149
144
  case 'single':
150
- setSelectedItemIndices((_a = {},
145
+ setSelection((_a = {},
151
146
  _a[sectionIndex] = [itemIndex],
152
147
  _a));
153
148
  onSelectAt === null || onSelectAt === void 0 ? void 0 : onSelectAt(itemIndex, sectionIndex);
@@ -157,22 +152,18 @@ exports.default = (0, react_2.forwardRef)(function (_a, ref) {
157
152
  }
158
153
  };
159
154
  var deselectAt = function (itemIndex, sectionIndex) {
160
- if (isItemIndexOutOfRange(itemIndex, sectionIndex))
161
- return;
162
- setSelectedItemIndices(function (prev) {
163
- var _a;
164
- var _b = prev, _c = sectionIndex, indices = _b[_c], rest = __rest(_b, [typeof _c === "symbol" ? _c : _c + ""]);
165
- var newIndices = (indices !== null && indices !== void 0 ? indices : []).filter(function (t) { return t !== itemIndex; });
166
- return newIndices.length > 0 ? __assign(__assign({}, rest), (_a = {}, _a[sectionIndex] = newIndices, _a)) : __assign({}, rest);
155
+ setSelection(function (prev) {
156
+ var newValue = __assign({}, prev);
157
+ newValue[sectionIndex] = prev[sectionIndex].filter(function (t) { return t !== itemIndex; });
158
+ return newValue;
167
159
  });
168
160
  onDeselectAt === null || onDeselectAt === void 0 ? void 0 : onDeselectAt(itemIndex, sectionIndex);
169
161
  };
170
162
  var sanitizedExpandedSectionIndices = sanitizeExpandedSectionIndices(externalExpandedSectionIndices);
171
- var _o = __read((0, react_2.useState)(sanitizedExpandedSectionIndices), 2), expandedSectionIndices = _o[0], setExpandedSectionIndices = _o[1];
163
+ var _j = __read((0, react_2.useState)(sanitizedExpandedSectionIndices), 2), expandedSectionIndices = _j[0], setExpandedSectionIndices = _j[1];
172
164
  var prevExpandedSectionIndices = (0, usePrevious_1.default)(expandedSectionIndices);
173
- var sanitizedExternalSelectedItemIndices = sanitizeSelectedItemIndices(externalSelectedItemIndices);
174
- var _p = __read((0, react_2.useState)(sanitizedExternalSelectedItemIndices), 2), selectedItemIndices = _p[0], setSelectedItemIndices = _p[1];
175
- var prevSelectedItemIndices = (0, usePrevious_1.default)(selectedItemIndices);
165
+ var sanitizedExternalSelection = sanitizeSelection(externalSelection);
166
+ var _k = __read((0, react_2.useState)(sanitizedExternalSelection), 2), selection = _k[0], setSelection = _k[1];
176
167
  (0, react_2.useEffect)(function () {
177
168
  if ((0, react_1.default)(sanitizedExpandedSectionIndices, expandedSectionIndices))
178
169
  return;
@@ -180,7 +171,7 @@ exports.default = (0, react_2.forwardRef)(function (_a, ref) {
180
171
  }, [JSON.stringify(sanitizedExpandedSectionIndices)]);
181
172
  (0, react_2.useEffect)(function () {
182
173
  var _a;
183
- if ((0, react_1.default)(expandedSectionIndices, sanitizedExpandedSectionIndices))
174
+ if (!prevExpandedSectionIndices)
184
175
  return;
185
176
  var collapsed = (_a = prevExpandedSectionIndices === null || prevExpandedSectionIndices === void 0 ? void 0 : prevExpandedSectionIndices.filter(function (t) { return expandedSectionIndices.indexOf(t) === -1; })) !== null && _a !== void 0 ? _a : [];
186
177
  var expanded = expandedSectionIndices.filter(function (t) { return (prevExpandedSectionIndices === null || prevExpandedSectionIndices === void 0 ? void 0 : prevExpandedSectionIndices.indexOf(t)) === -1; });
@@ -188,22 +179,64 @@ exports.default = (0, react_2.forwardRef)(function (_a, ref) {
188
179
  expanded.map(function (t) { return onExpandSectionAt === null || onExpandSectionAt === void 0 ? void 0 : onExpandSectionAt(t); });
189
180
  }, [JSON.stringify(expandedSectionIndices)]);
190
181
  (0, react_2.useEffect)(function () {
191
- if ((0, react_1.default)(sanitizedExternalSelectedItemIndices, selectedItemIndices))
182
+ if ((0, react_1.default)(sanitizedExternalSelection, selection))
192
183
  return;
193
- setSelectedItemIndices(sanitizedExternalSelectedItemIndices);
194
- }, [JSON.stringify(sanitizedExternalSelectedItemIndices)]);
184
+ setSelection(sanitizedExternalSelection);
185
+ }, [JSON.stringify(sanitizedExternalSelection)]);
195
186
  (0, react_2.useEffect)(function () {
196
- if (prevSelectedItemIndices === undefined)
197
- return;
198
- onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange(selectedItemIndices);
199
- }, [JSON.stringify(selectedItemIndices)]);
200
- var fixedClassNames = (0, asClassNameDict_1.default)({
187
+ onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange(selection);
188
+ }, [JSON.stringify(selection)]);
189
+ var fixedClassNames = getFixedClassNames({ orientation: orientation });
190
+ var fixedStyles = getFixedStyles({ orientation: orientation });
191
+ var defaultStyles = useDefaultStyles ? getDefaultStyles({ orientation: orientation }) : {};
192
+ return (react_2.default.createElement("div", __assign({}, props, { className: (0, classnames_1.default)(className, fixedClassNames.root), style: (0, styles_1.default)(style, fixedStyles.root), ref: ref }),
193
+ react_2.default.createElement(Each_1.default, { in: data }, function (section, sectionIndex) {
194
+ var _a;
195
+ var sectionData = section.data, _b = section.itemLength, itemLength = _b === void 0 ? 50 : _b, _c = section.itemPadding, itemPadding = _c === void 0 ? 0 : _c, isSelectionTogglable = section.isSelectionTogglable, itemComponentType = section.itemComponentType, _d = section.layout, layout = _d === void 0 ? 'list' : _d, _e = section.maxVisible, maxVisible = _e === void 0 ? -1 : _e, _f = section.numSegments, numSegments = _f === void 0 ? 1 : _f;
196
+ var allVisible = layout === 'list' ? sectionData.length : Math.ceil(sectionData.length / numSegments);
197
+ var numVisible = maxVisible < 0 ? allVisible : Math.min(allVisible, maxVisible);
198
+ var maxLength = itemLength * numVisible + itemPadding * (numVisible - 1);
199
+ var isCollapsed = !isSectionExpandedAt(sectionIndex);
200
+ var expandIconComponent = expandIconSvg ? react_2.default.createElement(FlatSVG_1.default, { svg: expandIconSvg, style: defaultStyles.expandIcon }) : react_2.default.createElement(react_2.default.Fragment, null);
201
+ var collapseIconComponent = collapseIconSvg ? react_2.default.createElement(FlatSVG_1.default, { svg: collapseIconSvg, style: defaultStyles.collapseIcon }) : expandIconComponent;
202
+ return (react_2.default.createElement("div", { style: (0, styles_1.default)(fixedStyles.section, orientation === 'vertical' ? {
203
+ marginTop: sectionIndex === 0 ? '0px' : "".concat(sectionPadding, "px"),
204
+ } : {
205
+ marginLeft: sectionIndex === 0 ? '0px' : "".concat(sectionPadding, "px"),
206
+ }) },
207
+ HeaderComponent ? (react_2.default.createElement(HeaderComponent, { className: (0, classnames_1.default)(fixedClassNames.header, { collapsed: isCollapsed, expanded: !isCollapsed }), style: (0, styles_1.default)(fixedStyles.header), index: sectionIndex, isCollapsed: isCollapsed, section: section, 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); } },
208
+ react_2.default.createElement("label", { style: (0, styles_1.default)(defaultStyles.headerLabel), dangerouslySetInnerHTML: { __html: section.label } }),
209
+ (0, cloneStyledElement_1.default)(isCollapsed ? expandIconComponent : collapseIconComponent, {
210
+ className: (0, classnames_1.default)(isCollapsed ? fixedClassNames.expandIcon : fixedClassNames.collapseIcon),
211
+ style: (0, styles_1.default)(isCollapsed ? fixedStyles.expandIcon : fixedStyles.collapseIcon),
212
+ }))),
213
+ react_2.default.createElement(List_1.default, { style: (0, styles_1.default)(fixedStyles.list, defaultStyles.list, orientation === 'vertical' ? {
214
+ width: '100%',
215
+ top: '100%',
216
+ height: isCollapsed ? '0px' : "".concat(maxLength, "px"),
217
+ marginTop: isCollapsed ? '0px' : "".concat(itemPadding, "px"),
218
+ overflowY: maxVisible < 0 ? 'hidden' : maxVisible < allVisible ? 'scroll' : 'hidden',
219
+ } : {
220
+ marginLeft: isCollapsed ? '0px' : "".concat(itemPadding, "px"),
221
+ overflowX: maxVisible < 0 ? 'hidden' : maxVisible < allVisible ? 'scroll' : 'hidden',
222
+ width: isCollapsed ? '0px' : "".concat(maxLength, "px"),
223
+ height: '100%',
224
+ left: '100%',
225
+ }), data: sectionData, selectionMode: selectionMode, isSelectionTogglable: isSelectionTogglable, itemComponentType: itemComponentType, itemLength: itemLength, itemPadding: itemPadding, orientation: orientation, layout: layout, numSegments: numSegments, selection: (_a = selection[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); }, onItemCustomEvent: function (itemIndex, eventName, eventInfo) { return onItemCustomEvent === null || onItemCustomEvent === void 0 ? void 0 : onItemCustomEvent(itemIndex, sectionIndex, eventName, eventInfo); }, onSelectAt: function (itemIndex) { return selectAt(itemIndex, sectionIndex); } })));
226
+ })));
227
+ });
228
+ function getFixedClassNames(_a) {
229
+ var orientation = _a.orientation;
230
+ return (0, asClassNameDict_1.default)({
201
231
  root: (0, classnames_1.default)(orientation),
202
232
  header: (0, classnames_1.default)(orientation),
203
233
  expandIcon: (0, classnames_1.default)(orientation),
204
234
  collapseIcon: (0, classnames_1.default)(orientation),
205
235
  });
206
- var fixedStyles = (0, asStyleDict_1.default)({
236
+ }
237
+ function getFixedStyles(_a) {
238
+ var orientation = _a.orientation;
239
+ return (0, asStyleDict_1.default)({
207
240
  root: __assign({ alignItems: 'center', boxSizing: 'border-box', display: 'flex', flex: '0 0 auto', justifyContent: 'flex-start', padding: '0' }, orientation === 'vertical' ? {
208
241
  flexDirection: 'column',
209
242
  height: 'auto',
@@ -218,21 +251,12 @@ exports.default = (0, react_2.forwardRef)(function (_a, ref) {
218
251
  flexDirection: 'row',
219
252
  height: '100%',
220
253
  }),
221
- header: __assign({ borderWidth: "".concat(borderThickness, "px"), cursor: 'pointer', margin: '0', outline: 'none' }, orientation === 'vertical' ? {
254
+ list: {},
255
+ header: __assign({ border: 'none', cursor: 'pointer', margin: '0', outline: 'none' }, orientation === 'vertical' ? {
222
256
  width: '100%',
223
257
  } : {
224
258
  height: '100%',
225
259
  }),
226
- headerLabel: {
227
- color: 'inherit',
228
- fontFamily: 'inherit',
229
- fontSize: 'inherit',
230
- fontWeight: 'inherit',
231
- letterSpacing: 'inherit',
232
- lineHeight: 'inherit',
233
- pointerEvents: 'none',
234
- transition: 'inherit',
235
- },
236
260
  expandIcon: {
237
261
  margin: '0',
238
262
  padding: '0',
@@ -241,22 +265,31 @@ exports.default = (0, react_2.forwardRef)(function (_a, ref) {
241
265
  margin: '0',
242
266
  padding: '0',
243
267
  },
268
+ });
269
+ }
270
+ function getDefaultStyles(_a) {
271
+ var orientation = _a.orientation;
272
+ return (0, asStyleDict_1.default)({
244
273
  list: __assign({ transitionDuration: '100ms', transitionTimingFunction: 'ease-out' }, orientation === 'vertical' ? {
245
- width: '100%',
246
274
  transitionProperty: 'height, margin',
247
- top: '100%',
248
275
  } : {
249
- height: '100%',
250
276
  transitionProperty: 'width, margin',
251
- left: '100%',
252
277
  }),
253
- });
254
- var defaultStyles = (0, asStyleDict_1.default)({
255
- header: __assign({ alignItems: 'center', background: '#fff', borderStyle: 'solid', boxSizing: 'border-box', display: 'flex', flexDirection: 'row', justifyContent: 'space-between', padding: '0 10px', transitionDuration: '100ms', transitionProperty: 'transform, opacity, background, color', transitionTimingFunction: 'ease-out' }, orientation === 'vertical' ? {
278
+ header: __assign({ alignItems: 'center', background: '#fff', boxSizing: 'border-box', display: 'flex', flexDirection: 'row', justifyContent: 'space-between', padding: '0 10px', transitionDuration: '100ms', transitionProperty: 'transform, opacity, background, color', transitionTimingFunction: 'ease-out' }, orientation === 'vertical' ? {
256
279
  height: '50px',
257
280
  } : {
258
281
  width: '50px',
259
282
  }),
283
+ headerLabel: {
284
+ color: 'inherit',
285
+ fontFamily: 'inherit',
286
+ fontSize: 'inherit',
287
+ fontWeight: 'inherit',
288
+ letterSpacing: 'inherit',
289
+ lineHeight: 'inherit',
290
+ pointerEvents: 'none',
291
+ transition: 'inherit',
292
+ },
260
293
  expandIcon: {
261
294
  boxSizing: 'border-box',
262
295
  display: 'block',
@@ -280,35 +313,5 @@ exports.default = (0, react_2.forwardRef)(function (_a, ref) {
280
313
  width: '15px',
281
314
  },
282
315
  });
283
- return (react_2.default.createElement("div", __assign({}, props, { className: (0, classnames_1.default)(className, fixedClassNames.root), style: (0, styles_1.default)(style, fixedStyles.root) }),
284
- react_2.default.createElement(Each_1.default, { in: data }, function (section, sectionIndex) {
285
- var _a;
286
- var numItems = section.items.length;
287
- var numVisibleItems = maxVisibleItems < 0 ? numItems : Math.min(numItems, maxVisibleItems);
288
- var menuLength = (itemLength - borderThickness) * numVisibleItems + itemPadding * (numVisibleItems - 1) + borderThickness;
289
- var isCollapsed = !isSectionExpandedAt(sectionIndex);
290
- var expandIconComponent = expandIconSvg ? react_2.default.createElement(FlatSVG_1.default, { svg: expandIconSvg, style: defaultStyles.expandIcon }) : react_2.default.createElement(react_2.default.Fragment, null);
291
- var collapseIconComponent = collapseIconSvg ? react_2.default.createElement(FlatSVG_1.default, { svg: collapseIconSvg, style: defaultStyles.collapseIcon }) : expandIconComponent;
292
- return (react_2.default.createElement("div", { style: (0, styles_1.default)(fixedStyles.section, orientation === 'vertical' ? {
293
- marginTop: sectionIndex === 0 ? '0px' : "".concat(sectionPadding - borderThickness, "px"),
294
- } : {
295
- marginLeft: sectionIndex === 0 ? '0px' : "".concat(sectionPadding - borderThickness, "px"),
296
- }) },
297
- HeaderComponent ? (react_2.default.createElement(HeaderComponent, { className: (0, classnames_1.default)(fixedClassNames.header, { collapsed: isCollapsed, expanded: !isCollapsed }), style: (0, styles_1.default)(fixedStyles.header), index: sectionIndex, isCollapsed: isCollapsed, section: section, 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); } },
298
- react_2.default.createElement("label", { style: fixedStyles.headerLabel, dangerouslySetInnerHTML: { __html: section.label } }),
299
- (0, cloneStyledElement_1.default)(isCollapsed ? expandIconComponent : collapseIconComponent, {
300
- className: (0, classnames_1.default)(isCollapsed ? fixedClassNames.expandIcon : fixedClassNames.collapseIcon),
301
- style: (0, styles_1.default)(isCollapsed ? fixedStyles.expandIcon : fixedStyles.collapseIcon),
302
- }))),
303
- react_2.default.createElement(List_1.default, { style: (0, styles_1.default)(fixedStyles.list, orientation === 'vertical' ? {
304
- height: isCollapsed ? '0px' : "".concat(menuLength, "px"),
305
- marginTop: isCollapsed ? '0px' : "".concat(itemPadding - borderThickness, "px"),
306
- overflowY: maxVisibleItems === -1 ? 'hidden' : maxVisibleItems < numItems ? 'scroll' : 'hidden',
307
- } : {
308
- marginLeft: isCollapsed ? '0px' : "".concat(itemPadding - borderThickness, "px"),
309
- overflowX: maxVisibleItems === -1 ? 'hidden' : maxVisibleItems < numItems ? 'scroll' : 'hidden',
310
- width: isCollapsed ? '0px' : "".concat(menuLength, "px"),
311
- }), 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); } })));
312
- })));
313
- });
316
+ }
314
317
  //# sourceMappingURL=Accordion.js.map