etudes 3.7.1 → 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,18 +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 AccordionSectionData<I> = {
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
+ */
4
7
  label: string;
5
- items: I[];
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;
6
14
  };
7
15
  export type AccordionSelection = Record<number, number[]>;
8
16
  export type AccordionItemProps<T> = ListItemProps<T>;
9
- export type AccordionHeaderProps<I, S extends AccordionSectionData<I> = AccordionSectionData<I>> = HTMLAttributes<HTMLElement> & PropsWithChildren<{
17
+ export type AccordionHeaderProps<I, S extends AccordionSectionProps<I> = AccordionSectionProps<I>> = HTMLAttributes<HTMLElement> & PropsWithChildren<{
10
18
  index: number;
11
19
  isCollapsed: boolean;
12
- sectionData: S;
20
+ section: S;
13
21
  onCustomEvent?: (name: string, info?: any) => void;
14
22
  }>;
15
- 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<{
16
24
  /**
17
25
  * Specifies if expanded sections should automatically collapse upon expanding
18
26
  * another section.
@@ -35,13 +43,9 @@ export type AccordionProps<I, S extends AccordionSectionData<I> = AccordionSecti
35
43
  */
36
44
  expandIconSvg?: string;
37
45
  /**
38
- * Maximum number of items that are viside per section when a section expands.
39
- * When a value greater than or equal to 0 is specified, only that number of
40
- * items will be visible at a time, and a scrollbar will appear to scroll to
41
- * remaining items. Any value less than 0 indicates that all items will be
42
- * visible when a section expands.
46
+ * Orientation of this component.
43
47
  */
44
- maxVisibleItems?: number[];
48
+ orientation?: ListOrientation;
45
49
  /**
46
50
  * Padding (in pixels) between each section.
47
51
  */
@@ -50,15 +54,15 @@ export type AccordionProps<I, S extends AccordionSectionData<I> = AccordionSecti
50
54
  * Indices of selected items per section.
51
55
  */
52
56
  selection?: AccordionSelection;
57
+ /**
58
+ * Selection mode of each section.
59
+ */
60
+ selectionMode?: ListSelectionMode;
53
61
  /**
54
62
  * React component type to be used for generating headers inside the
55
63
  * component. When absent, one will be generated automatically.
56
64
  */
57
65
  headerComponentType?: ComponentType<AccordionHeaderProps<I, S>>;
58
- /**
59
- * React component type to be used for generating items inside the component.
60
- */
61
- itemComponentType: ComponentType<AccordionItemProps<I>>;
62
66
  /**
63
67
  * Specifies if the component should use default styles.
64
68
  */
@@ -97,6 +101,15 @@ export type AccordionProps<I, S extends AccordionSectionData<I> = AccordionSecti
97
101
  * @param eventInfo Optional info of the dispatched event.
98
102
  */
99
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.
109
+ * @param eventName Name of the dispatched event.
110
+ * @param eventInfo Optional info of the dispatched event.
111
+ */
112
+ onItemCustomEvent?: (itemIndex: number, sectionIndex: number, eventName: string, eventInfo?: any) => void;
100
113
  /**
101
114
  * Handler invoked when an item is selected in a section.
102
115
  *
@@ -111,7 +124,7 @@ export type AccordionProps<I, S extends AccordionSectionData<I> = AccordionSecti
111
124
  */
112
125
  onSelectionChange?: (selection: AccordionSelection) => void;
113
126
  }>;
114
- 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> & {
115
128
  /**
116
129
  * Specifies if expanded sections should automatically collapse upon expanding
117
130
  * another section.
@@ -134,13 +147,9 @@ declare const _default: <I, S extends AccordionSectionData<I> = AccordionSection
134
147
  */
135
148
  expandIconSvg?: string | undefined;
136
149
  /**
137
- * Maximum number of items that are viside per section when a section expands.
138
- * When a value greater than or equal to 0 is specified, only that number of
139
- * items will be visible at a time, and a scrollbar will appear to scroll to
140
- * remaining items. Any value less than 0 indicates that all items will be
141
- * visible when a section expands.
150
+ * Orientation of this component.
142
151
  */
143
- maxVisibleItems?: number[] | undefined;
152
+ orientation?: ListOrientation | undefined;
144
153
  /**
145
154
  * Padding (in pixels) between each section.
146
155
  */
@@ -149,15 +158,15 @@ declare const _default: <I, S extends AccordionSectionData<I> = AccordionSection
149
158
  * Indices of selected items per section.
150
159
  */
151
160
  selection?: AccordionSelection | undefined;
161
+ /**
162
+ * Selection mode of each section.
163
+ */
164
+ selectionMode?: ListSelectionMode | undefined;
152
165
  /**
153
166
  * React component type to be used for generating headers inside the
154
167
  * component. When absent, one will be generated automatically.
155
168
  */
156
169
  headerComponentType?: React.ComponentType<AccordionHeaderProps<I, S>> | undefined;
157
- /**
158
- * React component type to be used for generating items inside the component.
159
- */
160
- itemComponentType: React.ComponentType<AccordionItemProps<I>>;
161
170
  /**
162
171
  * Specifies if the component should use default styles.
163
172
  */
@@ -196,6 +205,15 @@ declare const _default: <I, S extends AccordionSectionData<I> = AccordionSection
196
205
  * @param eventInfo Optional info of the dispatched event.
197
206
  */
198
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.
213
+ * @param eventName Name of the dispatched event.
214
+ * @param eventInfo Optional info of the dispatched event.
215
+ */
216
+ onItemCustomEvent?: ((itemIndex: number, sectionIndex: number, eventName: string, eventInfo?: any) => void) | undefined;
199
217
  /**
200
218
  * Handler invoked when an item is selected in a section.
201
219
  *
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, maxVisibleItems = _a.maxVisibleItems, _h = _a.orientation, orientation = _h === void 0 ? 'vertical' : _h, _j = _a.sectionPadding, sectionPadding = _j === void 0 ? 0 : _j, _k = _a.selection, externalSelection = _k === void 0 ? {} : _k, _l = _a.selectionMode, selectionMode = _l === void 0 ? 'single' : _l, _m = _a.useDefaultStyles, useDefaultStyles = _m === void 0 ? false : _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", "selection", "selectionMode", "useDefaultStyles", "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)
@@ -160,11 +160,10 @@ exports.default = (0, react_2.forwardRef)(function (_a, ref) {
160
160
  onDeselectAt === null || onDeselectAt === void 0 ? void 0 : onDeselectAt(itemIndex, sectionIndex);
161
161
  };
162
162
  var sanitizedExpandedSectionIndices = sanitizeExpandedSectionIndices(externalExpandedSectionIndices);
163
- 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];
164
164
  var prevExpandedSectionIndices = (0, usePrevious_1.default)(expandedSectionIndices);
165
165
  var sanitizedExternalSelection = sanitizeSelection(externalSelection);
166
- var _p = __read((0, react_2.useState)(sanitizedExternalSelection), 2), selection = _p[0], setSelection = _p[1];
167
- var prevSelection = (0, usePrevious_1.default)(selection);
166
+ var _k = __read((0, react_2.useState)(sanitizedExternalSelection), 2), selection = _k[0], setSelection = _k[1];
168
167
  (0, react_2.useEffect)(function () {
169
168
  if ((0, react_1.default)(sanitizedExpandedSectionIndices, expandedSectionIndices))
170
169
  return;
@@ -185,43 +184,45 @@ exports.default = (0, react_2.forwardRef)(function (_a, ref) {
185
184
  setSelection(sanitizedExternalSelection);
186
185
  }, [JSON.stringify(sanitizedExternalSelection)]);
187
186
  (0, react_2.useEffect)(function () {
188
- if (!prevSelection)
189
- return;
190
187
  onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange(selection);
191
188
  }, [JSON.stringify(selection)]);
192
189
  var fixedClassNames = getFixedClassNames({ orientation: orientation });
193
- var fixedStyles = getFixedStyles({ borderThickness: borderThickness, orientation: orientation });
190
+ var fixedStyles = getFixedStyles({ orientation: orientation });
194
191
  var defaultStyles = useDefaultStyles ? getDefaultStyles({ orientation: orientation }) : {};
195
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 }),
196
193
  react_2.default.createElement(Each_1.default, { in: data }, function (section, sectionIndex) {
197
- var _a, _b;
198
- var maxVisible = (_a = maxVisibleItems === null || maxVisibleItems === void 0 ? void 0 : maxVisibleItems[sectionIndex]) !== null && _a !== void 0 ? _a : -1;
199
- var numItems = section.items.length;
200
- var numVisibleItems = maxVisible < 0 ? numItems : Math.min(numItems, maxVisible);
201
- var menuLength = (itemLength - borderThickness) * numVisibleItems + itemPadding * (numVisibleItems - 1) + borderThickness;
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);
202
199
  var isCollapsed = !isSectionExpandedAt(sectionIndex);
203
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);
204
201
  var collapseIconComponent = collapseIconSvg ? react_2.default.createElement(FlatSVG_1.default, { svg: collapseIconSvg, style: defaultStyles.collapseIcon }) : expandIconComponent;
205
202
  return (react_2.default.createElement("div", { style: (0, styles_1.default)(fixedStyles.section, orientation === 'vertical' ? {
206
- marginTop: sectionIndex === 0 ? '0px' : "".concat(sectionPadding - borderThickness, "px"),
203
+ marginTop: sectionIndex === 0 ? '0px' : "".concat(sectionPadding, "px"),
207
204
  } : {
208
- marginLeft: sectionIndex === 0 ? '0px' : "".concat(sectionPadding - borderThickness, "px"),
205
+ marginLeft: sectionIndex === 0 ? '0px' : "".concat(sectionPadding, "px"),
209
206
  }) },
210
- 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, sectionData: 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); } },
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); } },
211
208
  react_2.default.createElement("label", { style: (0, styles_1.default)(defaultStyles.headerLabel), dangerouslySetInnerHTML: { __html: section.label } }),
212
209
  (0, cloneStyledElement_1.default)(isCollapsed ? expandIconComponent : collapseIconComponent, {
213
210
  className: (0, classnames_1.default)(isCollapsed ? fixedClassNames.expandIcon : fixedClassNames.collapseIcon),
214
211
  style: (0, styles_1.default)(isCollapsed ? fixedStyles.expandIcon : fixedStyles.collapseIcon),
215
212
  }))),
216
213
  react_2.default.createElement(List_1.default, { style: (0, styles_1.default)(fixedStyles.list, defaultStyles.list, orientation === 'vertical' ? {
217
- height: isCollapsed ? '0px' : "".concat(menuLength, "px"),
218
- marginTop: isCollapsed ? '0px' : "".concat(itemPadding - borderThickness, "px"),
219
- overflowY: maxVisible < 0 ? 'hidden' : maxVisible < numItems ? 'scroll' : 'hidden',
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',
220
219
  } : {
221
- marginLeft: isCollapsed ? '0px' : "".concat(itemPadding - borderThickness, "px"),
222
- overflowX: maxVisible < 0 ? 'hidden' : maxVisible < numItems ? 'scroll' : 'hidden',
223
- width: isCollapsed ? '0px' : "".concat(menuLength, "px"),
224
- }), borderThickness: borderThickness, data: section.items, selectionMode: selectionMode, isSelectionTogglable: isSelectionTogglable, itemComponentType: itemComponentType, itemLength: itemLength, itemPadding: itemPadding, orientation: orientation, selectedIndices: (_b = selection[sectionIndex]) !== null && _b !== void 0 ? _b : [], 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); } })));
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); } })));
225
226
  })));
226
227
  });
227
228
  function getFixedClassNames(_a) {
@@ -234,7 +235,7 @@ function getFixedClassNames(_a) {
234
235
  });
235
236
  }
236
237
  function getFixedStyles(_a) {
237
- var borderThickness = _a.borderThickness, orientation = _a.orientation;
238
+ var orientation = _a.orientation;
238
239
  return (0, asStyleDict_1.default)({
239
240
  root: __assign({ alignItems: 'center', boxSizing: 'border-box', display: 'flex', flex: '0 0 auto', justifyContent: 'flex-start', padding: '0' }, orientation === 'vertical' ? {
240
241
  flexDirection: 'column',
@@ -250,7 +251,8 @@ function getFixedStyles(_a) {
250
251
  flexDirection: 'row',
251
252
  height: '100%',
252
253
  }),
253
- 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' ? {
254
256
  width: '100%',
255
257
  } : {
256
258
  height: '100%',
@@ -263,13 +265,6 @@ function getFixedStyles(_a) {
263
265
  margin: '0',
264
266
  padding: '0',
265
267
  },
266
- list: __assign({}, orientation === 'vertical' ? {
267
- width: '100%',
268
- top: '100%',
269
- } : {
270
- height: '100%',
271
- left: '100%',
272
- }),
273
268
  });
274
269
  }
275
270
  function getDefaultStyles(_a) {
@@ -280,7 +275,7 @@ function getDefaultStyles(_a) {
280
275
  } : {
281
276
  transitionProperty: 'width, margin',
282
277
  }),
283
- 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' ? {
284
279
  height: '50px',
285
280
  } : {
286
281
  width: '50px',
@@ -1 +1 @@
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,gDAAuF;AACvF,oEAA6C;AAC7C,4EAAqD;AACrD,oEAA6C;AAC7C,kFAA2D;AAC3D,0DAAmC;AA4InC,kBAAe,IAAA,kBAAU,EAAC,UAAC,EA6B1B,EAAE,GAAG;IA5BJ,IAAA,QAAQ,cAAA,EACR,SAAS,eAAA,EACT,KAAK,WAAA,EACL,4BAA4B,EAA5B,oBAAoB,mBAAG,KAAK,KAAA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'\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 ListOrientation, 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 AccordionSectionData<I> = {\n label: string\n items: I[]\n}\n\nexport type AccordionSelection = Record<number, number[]>\n\nexport type AccordionItemProps<T> = ListItemProps<T>\n\nexport type AccordionHeaderProps<I, S extends AccordionSectionData<I> = AccordionSectionData<I>> = HTMLAttributes<HTMLElement> & PropsWithChildren<{\n index: number\n isCollapsed: boolean\n sectionData: S\n onCustomEvent?: (name: string, info?: any) => void\n}>\n\nexport type AccordionProps<I, S extends AccordionSectionData<I> = AccordionSectionData<I>> = HTMLAttributes<HTMLDivElement> & Omit<ListProps<I>, '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: S[]\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 per section when a section expands.\n * When a value greater than or equal to 0 is specified, only that number of\n * items 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 selection?: AccordionSelection\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<I, S>>\n\n /**\n * React component type to be used for generating items inside the component.\n */\n itemComponentType: ComponentType<AccordionItemProps<I>>\n\n /**\n * Specifies if the component should use default styles.\n */\n useDefaultStyles?: boolean\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 sectionIndex Index of the section which the header belongs.\n * @param eventName Name of the dispatched event.\n * @param eventInfo Optional info of the dispatched event.\n */\n onHeaderCustomEvent?: (sectionIndex: 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?: (selection: AccordionSelection) => void\n}>\n\ntype StylesProps = {\n borderThickness?: number\n orientation?: ListOrientation\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,\n orientation = 'vertical',\n sectionPadding = 0,\n selection: externalSelection = {},\n selectionMode = 'single',\n useDefaultStyles = false,\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 sanitizeSelection = (selection: AccordionSelection) => {\n const newValue: AccordionSelection = {}\n\n for (const sectionIndex in data) {\n if (!Object.prototype.hasOwnProperty.call(data, sectionIndex)) continue\n\n const indices = [...selection[sectionIndex] ?? []].sort()\n\n newValue[Number(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 (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])\n }\n }\n\n const selectAt = (itemIndex: number, sectionIndex: number) => {\n switch (selectionMode) {\n case 'multiple':\n setSelection(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 setSelection({\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 setSelection(prev => {\n const newValue = { ...prev }\n newValue[sectionIndex] = prev[sectionIndex].filter(t => t !== itemIndex)\n\n return newValue\n })\n\n onDeselectAt?.(itemIndex, sectionIndex)\n }\n\n const sanitizedExpandedSectionIndices = sanitizeExpandedSectionIndices(externalExpandedSectionIndices)\n const [expandedSectionIndices, setExpandedSectionIndices] = useState(sanitizedExpandedSectionIndices)\n const prevExpandedSectionIndices = usePrevious(expandedSectionIndices)\n\n const sanitizedExternalSelection = sanitizeSelection(externalSelection)\n const [selection, setSelection] = useState(sanitizedExternalSelection)\n const prevSelection = usePrevious(selection)\n\n useEffect(() => {\n if (isDeepEqual(sanitizedExpandedSectionIndices, expandedSectionIndices)) return\n\n setExpandedSectionIndices(sanitizedExpandedSectionIndices)\n }, [JSON.stringify(sanitizedExpandedSectionIndices)])\n\n useEffect(() => {\n if (!prevExpandedSectionIndices) return\n\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 if (isDeepEqual(sanitizedExternalSelection, selection)) return\n\n setSelection(sanitizedExternalSelection)\n }, [JSON.stringify(sanitizedExternalSelection)])\n\n useEffect(() => {\n if (!prevSelection) return\n\n onSelectionChange?.(selection)\n }, [JSON.stringify(selection)])\n\n const fixedClassNames = getFixedClassNames({ orientation })\n const fixedStyles = getFixedStyles({ borderThickness, orientation })\n const defaultStyles: Record<string, any> = useDefaultStyles ? getDefaultStyles({ orientation }) : {}\n\n return (\n <div\n {...props}\n className={classNames(className, fixedClassNames.root)}\n style={styles(style, fixedStyles.root)}\n ref={ref}\n >\n <Each in={data}>\n {(section, sectionIndex) => {\n const maxVisible = maxVisibleItems?.[sectionIndex] ?? -1\n const numItems = section.items.length\n const numVisibleItems = maxVisible < 0 ? numItems : Math.min(numItems, maxVisible)\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 index={sectionIndex}\n isCollapsed={isCollapsed}\n sectionData={section}\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={styles(defaultStyles.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, defaultStyles.list, orientation === 'vertical' ? {\n height: isCollapsed ? '0px' : `${menuLength}px`,\n marginTop: isCollapsed ? '0px' : `${itemPadding - borderThickness}px`,\n overflowY: maxVisible < 0 ? 'hidden' : maxVisible < numItems ? 'scroll' : 'hidden',\n } : {\n marginLeft: isCollapsed ? '0px' : `${itemPadding - borderThickness}px`,\n overflowX: maxVisible < 0 ? 'hidden' : maxVisible < 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={selection[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 <I, S extends AccordionSectionData<I> = AccordionSectionData<I>>(props: AccordionProps<I, S> & { ref?: Ref<HTMLDivElement> }) => ReactElement\n\nfunction getFixedClassNames({ orientation }: StylesProps) {\n return asClassNameDict({\n root: classNames(orientation),\n header: classNames(orientation),\n expandIcon: classNames(orientation),\n collapseIcon: classNames(orientation),\n })\n}\n\nfunction getFixedStyles({ borderThickness, orientation }: StylesProps) {\n return 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 expandIcon: {\n margin: '0',\n padding: '0',\n },\n collapseIcon: {\n margin: '0',\n padding: '0',\n },\n list: {\n ...orientation === 'vertical' ? {\n width: '100%',\n top: '100%',\n } : {\n height: '100%',\n left: '100%',\n },\n },\n })\n}\n\nfunction getDefaultStyles({ orientation }: StylesProps) {\n return asStyleDict({\n list: {\n transitionDuration: '100ms',\n transitionTimingFunction: 'ease-out',\n ...orientation === 'vertical' ? {\n transitionProperty: 'height, margin',\n } : {\n transitionProperty: 'width, margin',\n },\n },\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 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 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"]}
1
+ {"version":3,"file":"Accordion.js","sourceRoot":"/","sources":["Accordion.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AQ;YACzB,kBAAkB,EAAE,OAAO;YAC3B,kBAAkB,EAAE,WAAW;YAC/B,wBAAwB,EAAE,UAAU;YACpC,KAAK,EAAE,MAAM;SACd;QACD,YAAY,EAAE;YACZ,SAAS,EAAE,YAAY;YACvB,OAAO,EAAE,OAAO;YAChB,IAAI,EAAE,MAAM;YACZ,MAAM,EAAE,MAAM;YACd,eAAe,EAAE,QAAQ;YACzB,kBAAkB,EAAE,OAAO;YAC3B,kBAAkB,EAAE,WAAW;YAC/B,wBAAwB,EAAE,UAAU;YACpC,KAAK,EAAE,MAAM;SACd;KACF,CAAC,CAAA;AACJ,CAAC","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 ListOrientation, type ListProps, type ListSelectionMode } 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 AccordionSectionProps<I> = Omit<ListProps<I>, 'orientation' | 'selection' | 'selectionMode' | 'onActivateAt' | 'onSelectAt' | 'onDeselectAt' | 'onSelectionChange'> & {\n /**\n * Label for the header.\n */\n label: string\n\n /**\n * Maximum number of visible rows (if section orientation is `vertical`) or\n * columns (if section orientation is `horizontal`). If number of rows exceeds\n * the number of visible, a scrollbar will be put in place.\n */\n maxVisible?: number\n}\n\nexport type AccordionSelection = Record<number, number[]>\n\nexport type AccordionItemProps<T> = ListItemProps<T>\n\nexport type AccordionHeaderProps<I, S extends AccordionSectionProps<I> = AccordionSectionProps<I>> = HTMLAttributes<HTMLElement> & PropsWithChildren<{\n index: number\n isCollapsed: boolean\n section: S\n onCustomEvent?: (name: string, info?: any) => void\n}>\n\nexport type AccordionProps<I, S extends AccordionSectionProps<I> = AccordionSectionProps<I>> = HTMLAttributes<HTMLDivElement> & 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: S[]\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 * Orientation of this component.\n */\n orientation?: ListOrientation\n\n /**\n * Padding (in pixels) between each section.\n */\n sectionPadding?: number\n\n /**\n * Indices of selected items per section.\n */\n selection?: AccordionSelection\n\n /**\n * Selection mode of each section.\n */\n selectionMode?: ListSelectionMode\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<I, S>>\n\n /**\n * Specifies if the component should use default styles.\n */\n useDefaultStyles?: boolean\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 sectionIndex Index of the section which the header belongs.\n * @param eventName Name of the dispatched event.\n * @param eventInfo Optional info of the dispatched event.\n */\n onHeaderCustomEvent?: (sectionIndex: number, eventName: string, eventInfo?: any) => void\n\n /**\n * Handler invoked when a custom event is dispatched from an item.\n *\n * @param itemIndex Item index.\n * @param sectionIndex Section index.\n * @param eventName Name of the dispatched event.\n * @param eventInfo Optional info of the dispatched event.\n */\n onItemCustomEvent?: (itemIndex: number, sectionIndex: 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?: (selection: AccordionSelection) => void\n}>\n\nexport default forwardRef(({\n children,\n className,\n style,\n autoCollapseSections = false,\n collapseIconSvg,\n data,\n expandedSectionIndices: externalExpandedSectionIndices = [],\n expandIconSvg,\n orientation = 'vertical',\n sectionPadding = 0,\n selection: externalSelection = {},\n selectionMode = 'single',\n useDefaultStyles = false,\n headerComponentType: HeaderComponent,\n onActivateAt,\n onCollapseSectionAt,\n onDeselectAt,\n onExpandSectionAt,\n onHeaderCustomEvent,\n onItemCustomEvent,\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].data\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 sanitizeSelection = (selection: AccordionSelection) => {\n const newValue: AccordionSelection = {}\n\n for (const sectionIndex in data) {\n if (!Object.prototype.hasOwnProperty.call(data, sectionIndex)) continue\n\n const indices = [...selection[sectionIndex] ?? []].sort()\n\n newValue[Number(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 (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])\n }\n }\n\n const selectAt = (itemIndex: number, sectionIndex: number) => {\n switch (selectionMode) {\n case 'multiple':\n setSelection(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 setSelection({\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 setSelection(prev => {\n const newValue = { ...prev }\n newValue[sectionIndex] = prev[sectionIndex].filter(t => t !== itemIndex)\n\n return newValue\n })\n\n onDeselectAt?.(itemIndex, sectionIndex)\n }\n\n const sanitizedExpandedSectionIndices = sanitizeExpandedSectionIndices(externalExpandedSectionIndices)\n const [expandedSectionIndices, setExpandedSectionIndices] = useState(sanitizedExpandedSectionIndices)\n const prevExpandedSectionIndices = usePrevious(expandedSectionIndices)\n\n const sanitizedExternalSelection = sanitizeSelection(externalSelection)\n const [selection, setSelection] = useState(sanitizedExternalSelection)\n\n useEffect(() => {\n if (isDeepEqual(sanitizedExpandedSectionIndices, expandedSectionIndices)) return\n\n setExpandedSectionIndices(sanitizedExpandedSectionIndices)\n }, [JSON.stringify(sanitizedExpandedSectionIndices)])\n\n useEffect(() => {\n if (!prevExpandedSectionIndices) return\n\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 if (isDeepEqual(sanitizedExternalSelection, selection)) return\n\n setSelection(sanitizedExternalSelection)\n }, [JSON.stringify(sanitizedExternalSelection)])\n\n useEffect(() => {\n onSelectionChange?.(selection)\n }, [JSON.stringify(selection)])\n\n const fixedClassNames = getFixedClassNames({ orientation })\n const fixedStyles = getFixedStyles({ orientation })\n const defaultStyles: Record<string, any> = useDefaultStyles ? getDefaultStyles({ orientation }) : {}\n\n return (\n <div {...props} className={classNames(className, fixedClassNames.root)} style={styles(style, fixedStyles.root)} ref={ref}>\n <Each in={data}>\n {(section, sectionIndex) => {\n const { data: sectionData, itemLength = 50, itemPadding = 0, isSelectionTogglable, itemComponentType, layout = 'list', maxVisible = -1, numSegments = 1 } = section\n const allVisible = layout === 'list' ? sectionData.length : Math.ceil(sectionData.length / numSegments)\n const numVisible = maxVisible < 0 ? allVisible : Math.min(allVisible, maxVisible)\n const maxLength = itemLength * numVisible + itemPadding * (numVisible - 1)\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}px`,\n } : {\n marginLeft: sectionIndex === 0 ? '0px' : `${sectionPadding}px`,\n })}>\n {HeaderComponent ? (\n <HeaderComponent\n className={classNames(fixedClassNames.header, { collapsed: isCollapsed, expanded: !isCollapsed })}\n style={styles(fixedStyles.header)}\n index={sectionIndex}\n isCollapsed={isCollapsed}\n section={section}\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={styles(defaultStyles.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, defaultStyles.list, orientation === 'vertical' ? {\n width: '100%',\n top: '100%',\n height: isCollapsed ? '0px' : `${maxLength}px`,\n marginTop: isCollapsed ? '0px' : `${itemPadding}px`,\n overflowY: maxVisible < 0 ? 'hidden' : maxVisible < allVisible ? 'scroll' : 'hidden',\n } : {\n marginLeft: isCollapsed ? '0px' : `${itemPadding}px`,\n overflowX: maxVisible < 0 ? 'hidden' : maxVisible < allVisible ? 'scroll' : 'hidden',\n width: isCollapsed ? '0px' : `${maxLength}px`,\n height: '100%',\n left: '100%',\n })}\n data={sectionData}\n selectionMode={selectionMode}\n isSelectionTogglable={isSelectionTogglable}\n itemComponentType={itemComponentType}\n itemLength={itemLength}\n itemPadding={itemPadding}\n orientation={orientation}\n layout={layout}\n numSegments={numSegments}\n selection={selection[sectionIndex] ?? []}\n onActivateAt={itemIndex => onActivateAt?.(itemIndex, sectionIndex)}\n onDeselectAt={itemIndex => deselectAt(itemIndex, sectionIndex)}\n onItemCustomEvent={(itemIndex, eventName, eventInfo) => onItemCustomEvent?.(itemIndex, sectionIndex, eventName, eventInfo)}\n onSelectAt={itemIndex => selectAt(itemIndex, sectionIndex)}\n />\n </div>\n )\n }}\n </Each>\n </div>\n )\n}) as <I, S extends AccordionSectionProps<I> = AccordionSectionProps<I>>(props: AccordionProps<I, S> & { ref?: Ref<HTMLDivElement> }) => ReactElement\n\ntype StylesProps = {\n borderThickness?: number\n orientation?: ListOrientation\n}\n\nfunction getFixedClassNames({ orientation }: StylesProps) {\n return asClassNameDict({\n root: classNames(orientation),\n header: classNames(orientation),\n expandIcon: classNames(orientation),\n collapseIcon: classNames(orientation),\n })\n}\n\nfunction getFixedStyles({ orientation }: StylesProps) {\n return 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 list: {\n\n },\n header: {\n border: 'none',\n cursor: 'pointer',\n margin: '0',\n outline: 'none',\n ...orientation === 'vertical' ? {\n width: '100%',\n } : {\n height: '100%',\n },\n },\n expandIcon: {\n margin: '0',\n padding: '0',\n },\n collapseIcon: {\n margin: '0',\n padding: '0',\n },\n })\n}\n\nfunction getDefaultStyles({ orientation }: StylesProps) {\n return asStyleDict({\n list: {\n transitionDuration: '100ms',\n transitionTimingFunction: 'ease-out',\n ...orientation === 'vertical' ? {\n transitionProperty: 'height, margin',\n } : {\n transitionProperty: 'width, margin',\n },\n },\n header: {\n alignItems: 'center',\n background: '#fff',\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 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 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"]}
package/lib/Dropdown.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import React, { type ComponentType, type HTMLAttributes, type PropsWithChildren, type ReactElement, type Ref } from 'react';
2
- import { type ListItemProps, type ListOrientation, type ListProps } from './List';
2
+ import { type ListItemProps, type ListOrientation, type ListProps, type ListSelection } from './List';
3
3
  export type DropdownItemData = {
4
4
  label?: string;
5
5
  };
@@ -19,8 +19,10 @@ export type DropdownProps<T extends DropdownItemData = DropdownItemData> = HTMLA
19
19
  collapsesOnSelect?: boolean;
20
20
  /**
21
21
  * The label to appear on the dropdown toggle button.
22
+ *
23
+ * @param selection The current selection.
22
24
  */
23
- label?: (selectedIndices: number[]) => string;
25
+ label?: (selection: ListSelection) => string;
24
26
  /**
25
27
  * SVG markup to be put in the dropdown button as the expand icon.
26
28
  */
@@ -61,20 +63,23 @@ export type DropdownProps<T extends DropdownItemData = DropdownItemData> = HTMLA
61
63
  * component type to this component to automatically generate menu items.
62
64
  */
63
65
  declare const _default: <T extends DropdownItemData = DropdownItemData>(props: React.HTMLAttributes<HTMLDivElement> & {
64
- borderThickness?: number | undefined;
65
66
  data: T[];
66
- isSelectionTogglable?: boolean | undefined;
67
+ isSelectionTogglable?: boolean | undefined; /**
68
+ * SVG markup to be put in the dropdown button as the collapse icon.
69
+ */
67
70
  itemLength?: number | undefined;
68
71
  itemPadding?: number | undefined;
72
+ layout?: import("./List").ListLayout | undefined;
73
+ numSegments?: number | undefined;
69
74
  orientation?: ListOrientation | undefined;
70
- selectedIndices?: number[] | undefined;
71
- selectionMode?: "none" | "multiple" | "single" | undefined;
75
+ selection?: ListSelection | undefined;
76
+ selectionMode?: import("./List").ListSelectionMode | undefined;
72
77
  itemComponentType?: React.ComponentType<ListItemProps<T>> | undefined;
73
78
  onActivateAt?: ((index: number) => void) | undefined;
74
79
  onDeselectAt?: ((index: number) => void) | undefined;
75
80
  onItemCustomEvent?: ((index: number, eventName: string, eventInfo?: any) => void) | undefined;
76
81
  onSelectAt?: ((index: number) => void) | undefined;
77
- onSelectionChange?: ((indices: number[]) => void) | undefined;
82
+ onSelectionChange?: ((selection: ListSelection) => void) | undefined;
78
83
  } & {
79
84
  /**
80
85
  * SVG markup to be put in the dropdown button as the collapse icon.
@@ -87,8 +92,10 @@ declare const _default: <T extends DropdownItemData = DropdownItemData>(props: R
87
92
  collapsesOnSelect?: boolean | undefined;
88
93
  /**
89
94
  * The label to appear on the dropdown toggle button.
95
+ *
96
+ * @param selection The current selection.
90
97
  */
91
- label?: ((selectedIndices: number[]) => string) | undefined;
98
+ label?: ((selection: ListSelection) => string) | undefined;
92
99
  /**
93
100
  * SVG markup to be put in the dropdown button as the expand icon.
94
101
  */
package/lib/Dropdown.js CHANGED
@@ -82,7 +82,7 @@ var styles_1 = __importDefault(require("./utils/styles"));
82
82
  */
83
83
  exports.default = (0, react_2.forwardRef)(function (_a, ref) {
84
84
  var _b;
85
- var children = _a.children, className = _a.className, style = _a.style, _c = _a.borderThickness, borderThickness = _c === void 0 ? 0 : _c, collapseIconSvg = _a.collapseIconSvg, _d = _a.collapsesOnSelect, collapsesOnSelect = _d === void 0 ? true : _d, data = _a.data, label = _a.label, expandIconSvg = _a.expandIconSvg, _e = _a.isInverted, isInverted = _e === void 0 ? false : _e, _f = _a.isSelectionTogglable, isSelectionTogglable = _f === void 0 ? false : _f, itemComponentType = _a.itemComponentType, externalItemLength = _a.itemLength, _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.selectedIndices, externalSelectedIndices = _k === void 0 ? [] : _k, _l = _a.selectionMode, selectionMode = _l === void 0 ? 'single' : _l, _m = _a.useDefaultStyles, useDefaultStyles = _m === void 0 ? false : _m, ToggleComponent = _a.toggleComponentType, onActivateAt = _a.onActivateAt, onDeselectAt = _a.onDeselectAt, onSelectAt = _a.onSelectAt, onSelectionChange = _a.onSelectionChange, onToggleCustomEvent = _a.onToggleCustomEvent, props = __rest(_a, ["children", "className", "style", "borderThickness", "collapseIconSvg", "collapsesOnSelect", "data", "label", "expandIconSvg", "isInverted", "isSelectionTogglable", "itemComponentType", "itemLength", "itemPadding", "maxVisibleItems", "orientation", "selectedIndices", "selectionMode", "useDefaultStyles", "toggleComponentType", "onActivateAt", "onDeselectAt", "onSelectAt", "onSelectionChange", "onToggleCustomEvent"]);
85
+ var children = _a.children, className = _a.className, style = _a.style, collapseIconSvg = _a.collapseIconSvg, _c = _a.collapsesOnSelect, collapsesOnSelect = _c === void 0 ? true : _c, data = _a.data, label = _a.label, layout = _a.layout, expandIconSvg = _a.expandIconSvg, _d = _a.isInverted, isInverted = _d === void 0 ? false : _d, _e = _a.isSelectionTogglable, isSelectionTogglable = _e === void 0 ? false : _e, itemComponentType = _a.itemComponentType, externalItemLength = _a.itemLength, _f = _a.itemPadding, itemPadding = _f === void 0 ? 0 : _f, _g = _a.maxVisibleItems, maxVisibleItems = _g === void 0 ? -1 : _g, numSegments = _a.numSegments, _h = _a.orientation, orientation = _h === void 0 ? 'vertical' : _h, _j = _a.selection, externalSelection = _j === void 0 ? [] : _j, _k = _a.selectionMode, selectionMode = _k === void 0 ? 'single' : _k, _l = _a.useDefaultStyles, useDefaultStyles = _l === void 0 ? false : _l, ToggleComponent = _a.toggleComponentType, onActivateAt = _a.onActivateAt, onDeselectAt = _a.onDeselectAt, onSelectAt = _a.onSelectAt, onSelectionChange = _a.onSelectionChange, onToggleCustomEvent = _a.onToggleCustomEvent, props = __rest(_a, ["children", "className", "style", "collapseIconSvg", "collapsesOnSelect", "data", "label", "layout", "expandIconSvg", "isInverted", "isSelectionTogglable", "itemComponentType", "itemLength", "itemPadding", "maxVisibleItems", "numSegments", "orientation", "selection", "selectionMode", "useDefaultStyles", "toggleComponentType", "onActivateAt", "onDeselectAt", "onSelectAt", "onSelectionChange", "onToggleCustomEvent"]);
86
86
  var isIndexOutOfRange = function (index) {
87
87
  if (index >= data.length)
88
88
  return true;
@@ -90,7 +90,7 @@ exports.default = (0, react_2.forwardRef)(function (_a, ref) {
90
90
  return true;
91
91
  return false;
92
92
  };
93
- var sanitizeSelectedIndices = function (indices) { return indices.sort().filter(function (t) { return !isIndexOutOfRange(t); }); };
93
+ var sanitizedSelection = function (selection) { return selection.sort().filter(function (t) { return !isIndexOutOfRange(t); }); };
94
94
  var expand = function () {
95
95
  if (isCollapsed)
96
96
  setIsCollapsed(false);
@@ -112,11 +112,11 @@ exports.default = (0, react_2.forwardRef)(function (_a, ref) {
112
112
  if (selectionMode === 'single' && collapsesOnSelect)
113
113
  collapse();
114
114
  };
115
- var selectionChangeHandler = function (selection) {
116
- var newValue = selection.sort();
117
- if ((0, react_1.default)(newValue, selectedIndices))
115
+ var selectionChangeHandler = function (value) {
116
+ var newValue = value.sort();
117
+ if ((0, react_1.default)(newValue, selection))
118
118
  return;
119
- setSelectedIndices(newValue);
119
+ setSelection(newValue);
120
120
  };
121
121
  var clickOutsideHandler = function (event) {
122
122
  if (isCollapsed)
@@ -139,10 +139,10 @@ exports.default = (0, react_2.forwardRef)(function (_a, ref) {
139
139
  collapse();
140
140
  };
141
141
  var bodyRef = (0, react_2.useRef)(null);
142
- var sanitizedExternalSelectedIndices = sanitizeSelectedIndices(externalSelectedIndices);
143
- var _o = __read((0, react_2.useState)(sanitizedExternalSelectedIndices), 2), selectedIndices = _o[0], setSelectedIndices = _o[1];
144
- var prevSelectedIndices = (0, usePrevious_1.default)(selectedIndices);
145
- var _p = __read((0, react_2.useState)(true), 2), isCollapsed = _p[0], setIsCollapsed = _p[1];
142
+ var sanitizedExternalSelection = sanitizedSelection(externalSelection);
143
+ var _m = __read((0, react_2.useState)(sanitizedExternalSelection), 2), selection = _m[0], setSelection = _m[1];
144
+ var prevSelection = (0, usePrevious_1.default)(selection, { sanitizeDependency: JSON.stringify });
145
+ var _o = __read((0, react_2.useState)(true), 2), isCollapsed = _o[0], setIsCollapsed = _o[1];
146
146
  var rect = (0, useElementRect_1.default)(bodyRef);
147
147
  (0, react_2.useEffect)(function () {
148
148
  window.addEventListener('click', clickOutsideHandler);
@@ -151,33 +151,33 @@ exports.default = (0, react_2.forwardRef)(function (_a, ref) {
151
151
  };
152
152
  }, [isCollapsed]);
153
153
  (0, react_2.useEffect)(function () {
154
- if ((0, react_1.default)(sanitizedExternalSelectedIndices, selectedIndices))
154
+ if ((0, react_1.default)(sanitizedExternalSelection, selection))
155
155
  return;
156
- setSelectedIndices(sanitizedExternalSelectedIndices);
157
- }, [JSON.stringify(sanitizedExternalSelectedIndices)]);
156
+ setSelection(sanitizedExternalSelection);
157
+ }, [JSON.stringify(sanitizedExternalSelection)]);
158
158
  (0, react_2.useEffect)(function () {
159
- if (!prevSelectedIndices)
159
+ if (!prevSelection)
160
160
  return;
161
- onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange(selectedIndices);
162
- }, [JSON.stringify(sanitizeSelectedIndices(selectedIndices))]);
161
+ onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange(selection);
162
+ }, [JSON.stringify(selection)]);
163
163
  var itemLength = externalItemLength !== null && externalItemLength !== void 0 ? externalItemLength : (orientation === 'vertical' ? rect.height : rect.width);
164
164
  var numItems = data.length;
165
165
  var numVisibleItems = maxVisibleItems < 0 ? numItems : Math.min(numItems, maxVisibleItems);
166
- var menuLength = (itemLength - borderThickness) * numVisibleItems + itemPadding * (numVisibleItems - 1) + borderThickness;
166
+ var menuLength = itemLength * numVisibleItems + itemPadding * (numVisibleItems - 1);
167
167
  var fixedClassNames = getFixedClassNames({ isCollapsed: isCollapsed, isSelectionTogglable: isSelectionTogglable, orientation: orientation });
168
- var fixedStyles = getFixedStyles({ borderThickness: borderThickness, isCollapsed: isCollapsed, isInverted: isInverted, itemPadding: itemPadding, maxVisibleItems: maxVisibleItems, menuLength: menuLength, numItems: numItems, orientation: orientation });
168
+ var fixedStyles = getFixedStyles({ isCollapsed: isCollapsed, isInverted: isInverted, itemPadding: itemPadding, maxVisibleItems: maxVisibleItems, menuLength: menuLength, numItems: numItems, orientation: orientation });
169
169
  var defaultStyles = useDefaultStyles ? getDefaultStyles({}) : {};
170
170
  var expandIconComponent = expandIconSvg ? react_2.default.createElement(FlatSVG_1.default, { svg: expandIconSvg, style: defaultStyles.expandIcon }) : react_2.default.createElement(react_2.default.Fragment, null);
171
171
  var collapseIconComponent = collapseIconSvg ? react_2.default.createElement(FlatSVG_1.default, { svg: collapseIconSvg, style: defaultStyles.collapseIcon }) : expandIconComponent;
172
172
  return (react_2.default.createElement("div", __assign({}, props, { ref: ref, className: (0, classnames_1.default)(className, fixedClassNames.root), style: (0, styles_1.default)(style, fixedStyles.root) }),
173
173
  react_2.default.createElement("div", { ref: bodyRef, style: (0, styles_1.default)(fixedStyles.body) },
174
174
  ToggleComponent ? (react_2.default.createElement(ToggleComponent, { className: (0, classnames_1.default)(fixedClassNames.toggle), style: (0, styles_1.default)(fixedStyles.toggle), onClick: function () { return toggle(); }, onCustomEvent: function (name, info) { return onToggleCustomEvent === null || onToggleCustomEvent === void 0 ? void 0 : onToggleCustomEvent(name, info); } })) : (react_2.default.createElement("button", { className: (0, classnames_1.default)(fixedClassNames.toggle), style: (0, styles_1.default)(fixedStyles.toggle, defaultStyles.toggle), onClick: function () { return toggle(); } },
175
- react_2.default.createElement("label", { style: fixedStyles.toggleLabel, dangerouslySetInnerHTML: { __html: (_b = label === null || label === void 0 ? void 0 : label(selectedIndices)) !== null && _b !== void 0 ? _b : (selectedIndices.length > 0 ? selectedIndices.map(function (t) { return data[t].label; }).join(', ') : '') } }),
175
+ react_2.default.createElement("label", { style: fixedStyles.toggleLabel, dangerouslySetInnerHTML: { __html: (_b = label === null || label === void 0 ? void 0 : label(selection)) !== null && _b !== void 0 ? _b : (selection.length > 0 ? selection.map(function (t) { return data[t].label; }).join(', ') : '') } }),
176
176
  (0, cloneStyledElement_1.default)(isCollapsed ? expandIconComponent : collapseIconComponent, {
177
177
  className: (0, classnames_1.default)(isCollapsed ? fixedClassNames.expandIcon : fixedClassNames.collapseIcon),
178
178
  style: (0, styles_1.default)(isCollapsed ? fixedStyles.expandIcon : fixedStyles.collapseIcon),
179
179
  }))),
180
- react_2.default.createElement(List_1.default, { className: fixedClassNames.list, style: (0, styles_1.default)(fixedStyles.list), borderThickness: borderThickness, data: data, isSelectionTogglable: isSelectionTogglable, itemComponentType: itemComponentType, itemLength: itemLength, itemPadding: itemPadding, orientation: orientation, selectedIndices: selectedIndices, selectionMode: selectionMode, onActivateAt: onActivateAt, onDeselectAt: onDeselectAt, onSelectAt: selectAtHandler, onSelectionChange: selectionChangeHandler }))));
180
+ react_2.default.createElement(List_1.default, { className: fixedClassNames.list, style: (0, styles_1.default)(fixedStyles.list), data: data, isSelectionTogglable: isSelectionTogglable, itemComponentType: itemComponentType, itemLength: itemLength, itemPadding: itemPadding, layout: layout, numSegments: numSegments, orientation: orientation, selection: selection, selectionMode: selectionMode, onActivateAt: onActivateAt, onDeselectAt: onDeselectAt, onSelectAt: selectAtHandler, onSelectionChange: selectionChangeHandler }))));
181
181
  });
182
182
  function getFixedClassNames(_a) {
183
183
  var isCollapsed = _a.isCollapsed, isSelectionTogglable = _a.isSelectionTogglable, orientation = _a.orientation;
@@ -210,7 +210,7 @@ function getFixedClassNames(_a) {
210
210
  });
211
211
  }
212
212
  function getFixedStyles(_a) {
213
- var _b = _a.borderThickness, borderThickness = _b === void 0 ? 0 : _b, isCollapsed = _a.isCollapsed, isInverted = _a.isInverted, _c = _a.itemPadding, itemPadding = _c === void 0 ? 0 : _c, _d = _a.maxVisibleItems, maxVisibleItems = _d === void 0 ? 0 : _d, menuLength = _a.menuLength, _e = _a.numItems, numItems = _e === void 0 ? 0 : _e, orientation = _a.orientation;
213
+ var isCollapsed = _a.isCollapsed, isInverted = _a.isInverted, _b = _a.itemPadding, itemPadding = _b === void 0 ? 0 : _b, _c = _a.maxVisibleItems, maxVisibleItems = _c === void 0 ? 0 : _c, menuLength = _a.menuLength, _d = _a.numItems, numItems = _d === void 0 ? 0 : _d, orientation = _a.orientation;
214
214
  return (0, asStyleDict_1.default)({
215
215
  root: __assign({ alignItems: 'center', display: 'flex', justifyContent: 'flex-start', overflow: 'visible' }, orientation === 'vertical' ? {
216
216
  flexDirection: isInverted ? 'column-reverse' : 'column',
@@ -222,7 +222,6 @@ function getFixedStyles(_a) {
222
222
  width: '100%',
223
223
  },
224
224
  toggle: {
225
- borderWidth: "".concat(borderThickness, "px"),
226
225
  cursor: 'pointer',
227
226
  height: '100%',
228
227
  left: '0',
@@ -244,17 +243,17 @@ function getFixedStyles(_a) {
244
243
  expandIcon: {},
245
244
  collapseIcon: {},
246
245
  list: __assign({ position: 'absolute' }, orientation === 'vertical' ? __assign({ transition: 'height 100ms ease-out', width: '100%', height: isCollapsed ? '0px' : "".concat(menuLength, "px"), overflowY: maxVisibleItems === -1 ? 'hidden' : maxVisibleItems < numItems ? 'scroll' : 'hidden' }, isInverted ? {
247
- marginBottom: "".concat(itemPadding - borderThickness, "px"),
246
+ marginBottom: "".concat(itemPadding, "px"),
248
247
  bottom: '100%',
249
248
  } : {
250
249
  top: '100%',
251
- marginTop: "".concat(itemPadding - borderThickness, "px"),
250
+ marginTop: "".concat(itemPadding, "px"),
252
251
  }) : __assign({ transition: 'width 100ms ease-out', width: isCollapsed ? '0px' : "".concat(menuLength, "px"), height: '100%', overflowX: maxVisibleItems === -1 ? 'hidden' : maxVisibleItems < numItems ? 'scroll' : 'hidden' }, isInverted ? {
253
- marginRight: "".concat(itemPadding - borderThickness, "px"),
252
+ marginRight: "".concat(itemPadding, "px"),
254
253
  right: '100%',
255
254
  } : {
256
255
  left: '100%',
257
- marginLeft: "".concat(itemPadding - borderThickness, "px"),
256
+ marginLeft: "".concat(itemPadding, "px"),
258
257
  })),
259
258
  });
260
259
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Dropdown.js","sourceRoot":"/","sources":["Dropdown.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAAmC;AACnC,gEAA+C;AAC/C,6CAAoK;AACpK,sDAA+B;AAC/B,gDAAuF;AACvF,0EAAmD;AACnD,oEAA6C;AAC7C,4EAAqD;AACrD,oEAA6C;AAC7C,kFAA2D;AAC3D,0DAAmC;AAiFnC;;;;GAIG;AACH,kBAAe,IAAA,kBAAU,EAAC,UAAC,EA2B1B,EAAE,GAAG;;IA1BJ,IAAA,QAAQ,cAAA,EACR,SAAS,eAAA,EACT,KAAK,WAAA,EACL,uBAAmB,EAAnB,eAAe,mBAAG,CAAC,KAAA,EACnB,eAAe,qBAAA,EACf,yBAAwB,EAAxB,iBAAiB,mBAAG,IAAI,KAAA,EACxB,IAAI,UAAA,EACJ,KAAK,WAAA,EACL,aAAa,mBAAA,EACb,kBAAkB,EAAlB,UAAU,mBAAG,KAAK,KAAA,EAClB,4BAA4B,EAA5B,oBAAoB,mBAAG,KAAK,KAAA,EAC5B,iBAAiB,uBAAA,EACL,kBAAkB,gBAAA,EAC9B,mBAAe,EAAf,WAAW,mBAAG,CAAC,KAAA,EACf,uBAAoB,EAApB,eAAe,mBAAG,CAAC,CAAC,KAAA,EACpB,mBAAwB,EAAxB,WAAW,mBAAG,UAAU,KAAA,EACxB,uBAA6C,EAA5B,uBAAuB,mBAAG,EAAE,KAAA,EAC7C,qBAAwB,EAAxB,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B,QAAQ,EAAE,MAAM;YAChB,cAAc,EAAE,eAAe;YAC/B,MAAM,EAAE,GAAG;YACX,OAAO,EAAE,QAAQ;SAClB;QACD,UAAU,EAAE;YACV,MAAM,EAAE,MAAM;YACd,MAAM,EAAE,GAAG;YACX,OAAO,EAAE,GAAG;YACZ,KAAK,EAAE,MAAM;SACd;QACD,YAAY,EAAE;YACZ,MAAM,EAAE,MAAM;YACd,MAAM,EAAE,GAAG;YACX,OAAO,EAAE,GAAG;YACZ,KAAK,EAAE,MAAM;SACd;KACF,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import classNames from 'classnames'\nimport isDeepEqual from 'fast-deep-equal/react'\nimport React, { forwardRef, useEffect, useRef, useState, type ComponentType, type HTMLAttributes, type PropsWithChildren, type ReactElement, type Ref } from 'react'\nimport FlatSVG from './FlatSVG'\nimport List, { type ListItemProps, type ListOrientation, type ListProps } from './List'\nimport useElementRect from './hooks/useElementRect'\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 DropdownItemData = {\n label?: string\n}\n\nexport type DropdownToggleProps = HTMLAttributes<HTMLElement> & {\n onCustomEvent?: (name: string, info?: any) => void\n}\n\nexport type DropdownItemProps<T extends DropdownItemData = DropdownItemData> = ListItemProps<T>\n\nexport type DropdownProps<T extends DropdownItemData = DropdownItemData> = HTMLAttributes<HTMLDivElement> & ListProps<T> & PropsWithChildren<{\n /**\n * SVG markup to be put in the dropdown button as the collapse icon.\n */\n collapseIconSvg?: string\n\n /**\n * Specifies if the dropdown should be collapsed upon selection. This only\n * works if `selectionMode` is `single`.\n */\n collapsesOnSelect?: boolean\n\n /**\n * The label to appear on the dropdown toggle button.\n */\n label?: (selectedIndices: number[]) => string\n\n /**\n * SVG markup to be put in the dropdown button as the expand icon.\n */\n expandIconSvg?: string\n\n /**\n * Indicates if the component is inverted (i.e. \"dropup\" instead of dropdown).\n * Supports all orientations.\n */\n isInverted?: boolean\n\n /**\n * Maximum number of items that are viside when the component 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 the component expands.\n */\n maxVisibleItems?: number\n\n /**\n * Specifies if the component should use default styles.\n */\n useDefaultStyles?: boolean\n\n /**\n * React component type to be used for generating the toggle element inside\n * the component. When absent, one will be generated automatically.\n */\n toggleComponentType?: ComponentType<DropdownToggleProps>\n\n /**\n * Handler invoked when the toggle dispatches a custom event.\n *\n * @param eventName Name of the dispatched custom event.\n * @param eventInfo Optional info of the dispatched custom event.\n */\n onToggleCustomEvent?: (eventName: string, eventInfo?: any) => void\n}>\n\ntype StylesProps = {\n borderThickness?: number\n isCollapsed?: boolean\n isInverted?: boolean\n isSelectionTogglable?: boolean\n itemPadding?: number\n maxVisibleItems?: number\n menuLength?: number\n numItems?: number\n orientation?: ListOrientation\n}\n\n/**\n * A dropdown menu component that is invertible (i.e. can \"dropup\" instead) and\n * supports both horizontal and vertical orientations. Provide data and item\n * component type to this component to automatically generate menu items.\n */\nexport default forwardRef(({\n children,\n className,\n style,\n borderThickness = 0,\n collapseIconSvg,\n collapsesOnSelect = true,\n data,\n label,\n expandIconSvg,\n isInverted = false,\n isSelectionTogglable = false,\n itemComponentType,\n itemLength: externalItemLength,\n itemPadding = 0,\n maxVisibleItems = -1,\n orientation = 'vertical',\n selectedIndices: externalSelectedIndices = [],\n selectionMode = 'single',\n useDefaultStyles = false,\n toggleComponentType: ToggleComponent,\n onActivateAt,\n onDeselectAt,\n onSelectAt,\n onSelectionChange,\n onToggleCustomEvent,\n ...props\n}, ref) => {\n const isIndexOutOfRange = (index: number) => {\n if (index >= data.length) return true\n if (index < 0) return true\n\n return false\n }\n\n const sanitizeSelectedIndices = (indices: number[]) => indices.sort().filter(t => !isIndexOutOfRange(t))\n\n const expand = () => {\n if (isCollapsed) setIsCollapsed(false)\n }\n\n const collapse = () => {\n if (!isCollapsed) setIsCollapsed(true)\n }\n\n const toggle = () => {\n if (isCollapsed) {\n expand()\n }\n else {\n collapse()\n }\n }\n\n const selectAtHandler = (index: number) => {\n onSelectAt?.(index)\n\n if (selectionMode === 'single' && collapsesOnSelect) collapse()\n }\n\n const selectionChangeHandler = (selection: number[]) => {\n const newValue = selection.sort()\n\n if (isDeepEqual(newValue, selectedIndices)) return\n\n setSelectedIndices(newValue)\n }\n\n const clickOutsideHandler = (event: MouseEvent) => {\n if (isCollapsed) return\n if (!(event.target instanceof Node)) return\n\n let isOutside = true\n let node = event.target\n\n while (node) {\n if (node === bodyRef.current) {\n isOutside = false\n break\n }\n\n if (!node.parentNode) break\n\n node = node.parentNode\n }\n\n if (!isOutside) return\n\n collapse()\n }\n\n const bodyRef = useRef<HTMLDivElement>(null)\n const sanitizedExternalSelectedIndices = sanitizeSelectedIndices(externalSelectedIndices)\n const [selectedIndices, setSelectedIndices] = useState(sanitizedExternalSelectedIndices)\n const prevSelectedIndices = usePrevious(selectedIndices)\n const [isCollapsed, setIsCollapsed] = useState(true)\n const rect = useElementRect(bodyRef)\n\n useEffect(() => {\n window.addEventListener('click', clickOutsideHandler)\n\n return () => {\n window.removeEventListener('click', clickOutsideHandler)\n }\n }, [isCollapsed])\n\n useEffect(() => {\n if (isDeepEqual(sanitizedExternalSelectedIndices, selectedIndices)) return\n\n setSelectedIndices(sanitizedExternalSelectedIndices)\n }, [JSON.stringify(sanitizedExternalSelectedIndices)])\n\n useEffect(() => {\n if (!prevSelectedIndices) return\n\n onSelectionChange?.(selectedIndices)\n }, [JSON.stringify(sanitizeSelectedIndices(selectedIndices))])\n\n const itemLength = externalItemLength ?? (orientation === 'vertical' ? rect.height : rect.width)\n const numItems = data.length\n const numVisibleItems = maxVisibleItems < 0 ? numItems : Math.min(numItems, maxVisibleItems)\n const menuLength = (itemLength - borderThickness) * numVisibleItems + itemPadding * (numVisibleItems - 1) + borderThickness\n\n const fixedClassNames = getFixedClassNames({ isCollapsed, isSelectionTogglable, orientation })\n const fixedStyles = getFixedStyles({ borderThickness, isCollapsed, isInverted, itemPadding, maxVisibleItems, menuLength, numItems, orientation })\n const defaultStyles: Record<string, any> = useDefaultStyles ? getDefaultStyles({}) : {}\n\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\n {...props}\n ref={ref}\n className={classNames(className, fixedClassNames.root)}\n style={styles(style, fixedStyles.root)}\n >\n <div ref={bodyRef} style={styles(fixedStyles.body)}>\n {ToggleComponent ? (\n <ToggleComponent\n className={classNames(fixedClassNames.toggle)}\n style={styles(fixedStyles.toggle)}\n onClick={() => toggle()}\n onCustomEvent={(name, info) => onToggleCustomEvent?.(name, info)}\n />\n ) : (\n <button\n className={classNames(fixedClassNames.toggle)}\n style={styles(fixedStyles.toggle, defaultStyles.toggle)}\n onClick={() => toggle()}\n >\n <label style={fixedStyles.toggleLabel} dangerouslySetInnerHTML={{ __html: label?.(selectedIndices) ?? (selectedIndices.length > 0 ? selectedIndices.map(t => data[t].label).join(', ') : '') }}/>\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 className={fixedClassNames.list}\n style={styles(fixedStyles.list)}\n borderThickness={borderThickness}\n data={data}\n isSelectionTogglable={isSelectionTogglable}\n itemComponentType={itemComponentType}\n itemLength={itemLength}\n itemPadding={itemPadding}\n orientation={orientation}\n selectedIndices={selectedIndices}\n selectionMode={selectionMode}\n onActivateAt={onActivateAt}\n onDeselectAt={onDeselectAt}\n onSelectAt={selectAtHandler}\n onSelectionChange={selectionChangeHandler}\n />\n </div>\n </div>\n )\n}) as <T extends DropdownItemData = DropdownItemData>(props: DropdownProps<T> & { ref?: Ref<HTMLDivElement> }) => ReactElement\n\nfunction getFixedClassNames({ isCollapsed, isSelectionTogglable, orientation }: StylesProps) {\n return asClassNameDict({\n root: classNames(orientation, {\n togglable: isSelectionTogglable,\n collapsed: isCollapsed,\n expanded: !isCollapsed,\n }),\n toggle: classNames(orientation, {\n togglable: isSelectionTogglable,\n collapsed: isCollapsed,\n expanded: !isCollapsed,\n }),\n expandIcon: classNames(orientation, {\n togglable: isSelectionTogglable,\n collapsed: isCollapsed,\n expanded: !isCollapsed,\n }),\n collapseIcon: classNames(orientation, {\n togglable: isSelectionTogglable,\n collapsed: isCollapsed,\n expanded: !isCollapsed,\n }),\n list: classNames({\n togglable: isSelectionTogglable,\n collapsed: isCollapsed,\n expanded: !isCollapsed,\n }),\n })\n}\n\nfunction getFixedStyles({ borderThickness = 0, isCollapsed, isInverted, itemPadding = 0, maxVisibleItems = 0, menuLength, numItems = 0, orientation }: StylesProps) {\n return asStyleDict({\n root: {\n alignItems: 'center',\n display: 'flex',\n justifyContent: 'flex-start',\n overflow: 'visible',\n ...orientation === 'vertical' ? {\n flexDirection: isInverted ? 'column-reverse' : 'column',\n } : {\n flexDirection: isInverted ? 'row-reverse' : 'row',\n },\n },\n body: {\n height: '100%',\n width: '100%',\n },\n toggle: {\n borderWidth: `${borderThickness}px`,\n cursor: 'pointer',\n height: '100%',\n left: '0',\n margin: '0',\n outline: 'none',\n position: 'absolute',\n top: '0',\n width: '100%',\n zIndex: '1',\n },\n toggleLabel: {\n fontFamily: 'inherit',\n fontSize: 'inherit',\n fontWeight: 'inherit',\n letterSpacing: 'inherit',\n lineHeight: 'inherit',\n pointerEvents: 'none',\n },\n expandIcon: {\n\n },\n collapseIcon: {\n\n },\n list: {\n position: 'absolute',\n ...orientation === 'vertical' ? {\n transition: 'height 100ms ease-out',\n width: '100%',\n height: isCollapsed ? '0px' : `${menuLength}px`,\n overflowY: maxVisibleItems === -1 ? 'hidden' : maxVisibleItems < numItems ? 'scroll' : 'hidden',\n ...isInverted ? {\n marginBottom: `${itemPadding - borderThickness}px`,\n bottom: '100%',\n } : {\n top: '100%',\n marginTop: `${itemPadding - borderThickness}px`,\n },\n } : {\n transition: 'width 100ms ease-out',\n width: isCollapsed ? '0px' : `${menuLength}px`,\n height: '100%',\n overflowX: maxVisibleItems === -1 ? 'hidden' : maxVisibleItems < numItems ? 'scroll' : 'hidden',\n ...isInverted ? {\n marginRight: `${itemPadding - borderThickness}px`,\n right: '100%',\n } : {\n left: '100%',\n marginLeft: `${itemPadding - borderThickness}px`,\n },\n },\n },\n })\n}\n\nfunction getDefaultStyles({ ...props }: StylesProps) {\n return asStyleDict({\n toggle: {\n alignItems: 'center',\n background: '#fff',\n boxSizing: 'border-box',\n color: '#000',\n display: 'flex',\n flexDirection: 'row',\n fontSize: '16px',\n justifyContent: 'space-between',\n margin: '0',\n padding: '0 10px',\n },\n expandIcon: {\n height: '15px',\n margin: '0',\n padding: '0',\n width: '15px',\n },\n collapseIcon: {\n height: '15px',\n margin: '0',\n padding: '0',\n width: '15px',\n },\n })\n}\n"]}
1
+ {"version":3,"file":"Dropdown.js","sourceRoot":"/","sources":["Dropdown.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAAmC;AACnC,gEAA+C;AAC/C,6CAAoK;AACpK,sDAA+B;AAC/B,gDAA2G;AAC3G,0EAAmD;AACnD,oEAA6C;AAC7C,4EAAqD;AACrD,oEAA6C;AAC7C,kFAA2D;AAC3D,0DAAmC;AAuEnC;;;;GAIG;AACH,kBAAe,IAAA,kBAAU,EAAC,UAAC,EA4B1B,EAAE,GAAG;;IA3BJ,IAAA,QAAQ,cAAA,EACR,SAAS,eAAA,EACT,KAAK,WAAA,EACL,eAAe,qBAAA,EACf,yBAAwB,EAAxB,iBAAiB,mBAAG,I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AW,OAAI;SAC/B,CACF,CACF;KACF,CAAC,CAAA;AACJ,CAAC;AAED,SAAS,gBAAgB,CAAC,EAAyB;QAApB,KAAK,cAAV,EAAY,CAAF;IAClC,OAAO,IAAA,qBAAW,EAAC;QACjB,MAAM,EAAE;YACN,UAAU,EAAE,QAAQ;YACpB,UAAU,EAAE,MAAM;YAClB,SAAS,EAAE,YAAY;YACvB,KAAK,EAAE,MAAM;YACb,OAAO,EAAE,MAAM;YACf,aAAa,EAAE,KAAK;YACpB,QAAQ,EAAE,MAAM;YAChB,cAAc,EAAE,eAAe;YAC/B,MAAM,EAAE,GAAG;YACX,OAAO,EAAE,QAAQ;SAClB;QACD,UAAU,EAAE;YACV,MAAM,EAAE,MAAM;YACd,MAAM,EAAE,GAAG;YACX,OAAO,EAAE,GAAG;YACZ,KAAK,EAAE,MAAM;SACd;QACD,YAAY,EAAE;YACZ,MAAM,EAAE,MAAM;YACd,MAAM,EAAE,GAAG;YACX,OAAO,EAAE,GAAG;YACZ,KAAK,EAAE,MAAM;SACd;KACF,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import classNames from 'classnames'\nimport isDeepEqual from 'fast-deep-equal/react'\nimport React, { forwardRef, useEffect, useRef, useState, type ComponentType, type HTMLAttributes, type PropsWithChildren, type ReactElement, type Ref } from 'react'\nimport FlatSVG from './FlatSVG'\nimport List, { type ListItemProps, type ListOrientation, type ListProps, type ListSelection } from './List'\nimport useElementRect from './hooks/useElementRect'\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 DropdownItemData = {\n label?: string\n}\n\nexport type DropdownToggleProps = HTMLAttributes<HTMLElement> & {\n onCustomEvent?: (name: string, info?: any) => void\n}\n\nexport type DropdownItemProps<T extends DropdownItemData = DropdownItemData> = ListItemProps<T>\n\nexport type DropdownProps<T extends DropdownItemData = DropdownItemData> = HTMLAttributes<HTMLDivElement> & ListProps<T> & PropsWithChildren<{\n /**\n * SVG markup to be put in the dropdown button as the collapse icon.\n */\n collapseIconSvg?: string\n\n /**\n * Specifies if the dropdown should be collapsed upon selection. This only\n * works if `selectionMode` is `single`.\n */\n collapsesOnSelect?: boolean\n\n /**\n * The label to appear on the dropdown toggle button.\n *\n * @param selection The current selection.\n */\n label?: (selection: ListSelection) => string\n\n /**\n * SVG markup to be put in the dropdown button as the expand icon.\n */\n expandIconSvg?: string\n\n /**\n * Indicates if the component is inverted (i.e. \"dropup\" instead of dropdown).\n * Supports all orientations.\n */\n isInverted?: boolean\n\n /**\n * Maximum number of items that are viside when the component 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 the component expands.\n */\n maxVisibleItems?: number\n\n /**\n * Specifies if the component should use default styles.\n */\n useDefaultStyles?: boolean\n\n /**\n * React component type to be used for generating the toggle element inside\n * the component. When absent, one will be generated automatically.\n */\n toggleComponentType?: ComponentType<DropdownToggleProps>\n\n /**\n * Handler invoked when the toggle dispatches a custom event.\n *\n * @param eventName Name of the dispatched custom event.\n * @param eventInfo Optional info of the dispatched custom event.\n */\n onToggleCustomEvent?: (eventName: string, eventInfo?: any) => void\n}>\n\n/**\n * A dropdown menu component that is invertible (i.e. can \"dropup\" instead) and\n * supports both horizontal and vertical orientations. Provide data and item\n * component type to this component to automatically generate menu items.\n */\nexport default forwardRef(({\n children,\n className,\n style,\n collapseIconSvg,\n collapsesOnSelect = true,\n data,\n label,\n layout,\n expandIconSvg,\n isInverted = false,\n isSelectionTogglable = false,\n itemComponentType,\n itemLength: externalItemLength,\n itemPadding = 0,\n maxVisibleItems = -1,\n numSegments,\n orientation = 'vertical',\n selection: externalSelection = [],\n selectionMode = 'single',\n useDefaultStyles = false,\n toggleComponentType: ToggleComponent,\n onActivateAt,\n onDeselectAt,\n onSelectAt,\n onSelectionChange,\n onToggleCustomEvent,\n ...props\n}, ref) => {\n const isIndexOutOfRange = (index: number) => {\n if (index >= data.length) return true\n if (index < 0) return true\n\n return false\n }\n\n const sanitizedSelection = (selection: ListSelection) => selection.sort().filter(t => !isIndexOutOfRange(t))\n\n const expand = () => {\n if (isCollapsed) setIsCollapsed(false)\n }\n\n const collapse = () => {\n if (!isCollapsed) setIsCollapsed(true)\n }\n\n const toggle = () => {\n if (isCollapsed) {\n expand()\n }\n else {\n collapse()\n }\n }\n\n const selectAtHandler = (index: number) => {\n onSelectAt?.(index)\n\n if (selectionMode === 'single' && collapsesOnSelect) collapse()\n }\n\n const selectionChangeHandler = (value: ListSelection) => {\n const newValue = value.sort()\n\n if (isDeepEqual(newValue, selection)) return\n\n setSelection(newValue)\n }\n\n const clickOutsideHandler = (event: MouseEvent) => {\n if (isCollapsed) return\n if (!(event.target instanceof Node)) return\n\n let isOutside = true\n let node = event.target\n\n while (node) {\n if (node === bodyRef.current) {\n isOutside = false\n break\n }\n\n if (!node.parentNode) break\n\n node = node.parentNode\n }\n\n if (!isOutside) return\n\n collapse()\n }\n\n const bodyRef = useRef<HTMLDivElement>(null)\n const sanitizedExternalSelection = sanitizedSelection(externalSelection)\n const [selection, setSelection] = useState(sanitizedExternalSelection)\n const prevSelection = usePrevious(selection, { sanitizeDependency: JSON.stringify })\n const [isCollapsed, setIsCollapsed] = useState(true)\n const rect = useElementRect(bodyRef)\n\n useEffect(() => {\n window.addEventListener('click', clickOutsideHandler)\n\n return () => {\n window.removeEventListener('click', clickOutsideHandler)\n }\n }, [isCollapsed])\n\n useEffect(() => {\n if (isDeepEqual(sanitizedExternalSelection, selection)) return\n\n setSelection(sanitizedExternalSelection)\n }, [JSON.stringify(sanitizedExternalSelection)])\n\n useEffect(() => {\n if (!prevSelection) return\n\n onSelectionChange?.(selection)\n }, [JSON.stringify(selection)])\n\n const itemLength = externalItemLength ?? (orientation === 'vertical' ? rect.height : rect.width)\n const numItems = data.length\n const numVisibleItems = maxVisibleItems < 0 ? numItems : Math.min(numItems, maxVisibleItems)\n const menuLength = itemLength * numVisibleItems + itemPadding * (numVisibleItems - 1)\n\n const fixedClassNames = getFixedClassNames({ isCollapsed, isSelectionTogglable, orientation })\n const fixedStyles = getFixedStyles({ isCollapsed, isInverted, itemPadding, maxVisibleItems, menuLength, numItems, orientation })\n const defaultStyles: Record<string, any> = useDefaultStyles ? getDefaultStyles({}) : {}\n\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\n {...props}\n ref={ref}\n className={classNames(className, fixedClassNames.root)}\n style={styles(style, fixedStyles.root)}\n >\n <div ref={bodyRef} style={styles(fixedStyles.body)}>\n {ToggleComponent ? (\n <ToggleComponent\n className={classNames(fixedClassNames.toggle)}\n style={styles(fixedStyles.toggle)}\n onClick={() => toggle()}\n onCustomEvent={(name, info) => onToggleCustomEvent?.(name, info)}\n />\n ) : (\n <button\n className={classNames(fixedClassNames.toggle)}\n style={styles(fixedStyles.toggle, defaultStyles.toggle)}\n onClick={() => toggle()}\n >\n <label style={fixedStyles.toggleLabel} dangerouslySetInnerHTML={{ __html: label?.(selection) ?? (selection.length > 0 ? selection.map(t => data[t].label).join(', ') : '') }}/>\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 className={fixedClassNames.list}\n style={styles(fixedStyles.list)}\n data={data}\n isSelectionTogglable={isSelectionTogglable}\n itemComponentType={itemComponentType}\n itemLength={itemLength}\n itemPadding={itemPadding}\n layout={layout}\n numSegments={numSegments}\n orientation={orientation}\n selection={selection}\n selectionMode={selectionMode}\n onActivateAt={onActivateAt}\n onDeselectAt={onDeselectAt}\n onSelectAt={selectAtHandler}\n onSelectionChange={selectionChangeHandler}\n />\n </div>\n </div>\n )\n}) as <T extends DropdownItemData = DropdownItemData>(props: DropdownProps<T> & { ref?: Ref<HTMLDivElement> }) => ReactElement\n\ntype StylesProps = {\n isCollapsed?: boolean\n isInverted?: boolean\n isSelectionTogglable?: boolean\n itemPadding?: number\n maxVisibleItems?: number\n menuLength?: number\n numItems?: number\n orientation?: ListOrientation\n}\n\nfunction getFixedClassNames({ isCollapsed, isSelectionTogglable, orientation }: StylesProps) {\n return asClassNameDict({\n root: classNames(orientation, {\n togglable: isSelectionTogglable,\n collapsed: isCollapsed,\n expanded: !isCollapsed,\n }),\n toggle: classNames(orientation, {\n togglable: isSelectionTogglable,\n collapsed: isCollapsed,\n expanded: !isCollapsed,\n }),\n expandIcon: classNames(orientation, {\n togglable: isSelectionTogglable,\n collapsed: isCollapsed,\n expanded: !isCollapsed,\n }),\n collapseIcon: classNames(orientation, {\n togglable: isSelectionTogglable,\n collapsed: isCollapsed,\n expanded: !isCollapsed,\n }),\n list: classNames({\n togglable: isSelectionTogglable,\n collapsed: isCollapsed,\n expanded: !isCollapsed,\n }),\n })\n}\n\nfunction getFixedStyles({ isCollapsed, isInverted, itemPadding = 0, maxVisibleItems = 0, menuLength, numItems = 0, orientation }: StylesProps) {\n return asStyleDict({\n root: {\n alignItems: 'center',\n display: 'flex',\n justifyContent: 'flex-start',\n overflow: 'visible',\n ...orientation === 'vertical' ? {\n flexDirection: isInverted ? 'column-reverse' : 'column',\n } : {\n flexDirection: isInverted ? 'row-reverse' : 'row',\n },\n },\n body: {\n height: '100%',\n width: '100%',\n },\n toggle: {\n cursor: 'pointer',\n height: '100%',\n left: '0',\n margin: '0',\n outline: 'none',\n position: 'absolute',\n top: '0',\n width: '100%',\n zIndex: '1',\n },\n toggleLabel: {\n fontFamily: 'inherit',\n fontSize: 'inherit',\n fontWeight: 'inherit',\n letterSpacing: 'inherit',\n lineHeight: 'inherit',\n pointerEvents: 'none',\n },\n expandIcon: {\n\n },\n collapseIcon: {\n\n },\n list: {\n position: 'absolute',\n ...orientation === 'vertical' ? {\n transition: 'height 100ms ease-out',\n width: '100%',\n height: isCollapsed ? '0px' : `${menuLength}px`,\n overflowY: maxVisibleItems === -1 ? 'hidden' : maxVisibleItems < numItems ? 'scroll' : 'hidden',\n ...isInverted ? {\n marginBottom: `${itemPadding}px`,\n bottom: '100%',\n } : {\n top: '100%',\n marginTop: `${itemPadding}px`,\n },\n } : {\n transition: 'width 100ms ease-out',\n width: isCollapsed ? '0px' : `${menuLength}px`,\n height: '100%',\n overflowX: maxVisibleItems === -1 ? 'hidden' : maxVisibleItems < numItems ? 'scroll' : 'hidden',\n ...isInverted ? {\n marginRight: `${itemPadding}px`,\n right: '100%',\n } : {\n left: '100%',\n marginLeft: `${itemPadding}px`,\n },\n },\n },\n })\n}\n\nfunction getDefaultStyles({ ...props }: StylesProps) {\n return asStyleDict({\n toggle: {\n alignItems: 'center',\n background: '#fff',\n boxSizing: 'border-box',\n color: '#000',\n display: 'flex',\n flexDirection: 'row',\n fontSize: '16px',\n justifyContent: 'space-between',\n margin: '0',\n padding: '0 10px',\n },\n expandIcon: {\n height: '15px',\n margin: '0',\n padding: '0',\n width: '15px',\n },\n collapseIcon: {\n height: '15px',\n margin: '0',\n padding: '0',\n width: '15px',\n },\n })\n}\n"]}
package/lib/List.d.ts CHANGED
@@ -1,5 +1,8 @@
1
1
  import React, { type ComponentType, type HTMLAttributes, type ReactElement, type Ref } from 'react';
2
2
  export type ListOrientation = 'horizontal' | 'vertical';
3
+ export type ListLayout = 'list' | 'grid';
4
+ export type ListSelectionMode = 'none' | 'single' | 'multiple';
5
+ export type ListSelection = number[];
3
6
  export type ListItemProps<T> = HTMLAttributes<HTMLElement> & {
4
7
  data: T;
5
8
  index: number;
@@ -8,10 +11,6 @@ export type ListItemProps<T> = HTMLAttributes<HTMLElement> & {
8
11
  onCustomEvent?: (name: string, info?: any) => void;
9
12
  };
10
13
  export type ListProps<T> = HTMLAttributes<HTMLDivElement> & {
11
- /**
12
- * Thickness of item borders (in pixels). 0 indicates no borders.
13
- */
14
- borderThickness?: number;
15
14
  /**
16
15
  * Generically typed data of each item.
17
16
  */
@@ -30,6 +29,16 @@ export type ListProps<T> = HTMLAttributes<HTMLDivElement> & {
30
29
  * Padding between every item (in pixels).
31
30
  */
32
31
  itemPadding?: number;
32
+ /**
33
+ * Specifies the layout of this component.
34
+ */
35
+ layout?: ListLayout;
36
+ /**
37
+ * This property is only used if the layout is set to `grid`. Specifies the
38
+ * number of columns if orientation is `vertical` or number of rows if
39
+ * orientation is `horizontal`.
40
+ */
41
+ numSegments?: number;
33
42
  /**
34
43
  * Orientation of the component.
35
44
  */
@@ -38,14 +47,14 @@ export type ListProps<T> = HTMLAttributes<HTMLDivElement> & {
38
47
  * The selected indices. If `selectionMode` is `single`, only only the first
39
48
  * value will be used.
40
49
  */
41
- selectedIndices?: number[];
50
+ selection?: ListSelection;
42
51
  /**
43
52
  * Indicates the selection behavior:
44
53
  * - `none`: No selection at all.
45
54
  * - `single`: Only one item can be selected at a time.
46
55
  * - `multiple`: Multiple items can be selected at the same time.
47
56
  */
48
- selectionMode?: 'none' | 'single' | 'multiple';
57
+ selectionMode?: ListSelectionMode;
49
58
  /**
50
59
  * React component type to be used to generate items for this list.
51
60
  */
@@ -79,9 +88,9 @@ export type ListProps<T> = HTMLAttributes<HTMLDivElement> & {
79
88
  /**
80
89
  * Handler invoked when the selected items changed.
81
90
  *
82
- * @param indices Indices of selected items.
91
+ * @param selection Indices of selected items.
83
92
  */
84
- onSelectionChange?: (indices: number[]) => void;
93
+ onSelectionChange?: (selection: ListSelection) => void;
85
94
  };
86
95
  /**
87
96
  * A scrollable list of selectable items. Items are generated based on the
@@ -89,10 +98,6 @@ export type ListProps<T> = HTMLAttributes<HTMLDivElement> & {
89
98
  * generic. This component supports both horizontal and vertical orientations.
90
99
  */
91
100
  declare const _default: <T>(props: React.HTMLAttributes<HTMLDivElement> & {
92
- /**
93
- * Thickness of item borders (in pixels). 0 indicates no borders.
94
- */
95
- borderThickness?: number | undefined;
96
101
  /**
97
102
  * Generically typed data of each item.
98
103
  */
@@ -111,6 +116,16 @@ declare const _default: <T>(props: React.HTMLAttributes<HTMLDivElement> & {
111
116
  * Padding between every item (in pixels).
112
117
  */
113
118
  itemPadding?: number | undefined;
119
+ /**
120
+ * Specifies the layout of this component.
121
+ */
122
+ layout?: ListLayout | undefined;
123
+ /**
124
+ * This property is only used if the layout is set to `grid`. Specifies the
125
+ * number of columns if orientation is `vertical` or number of rows if
126
+ * orientation is `horizontal`.
127
+ */
128
+ numSegments?: number | undefined;
114
129
  /**
115
130
  * Orientation of the component.
116
131
  */
@@ -119,14 +134,14 @@ declare const _default: <T>(props: React.HTMLAttributes<HTMLDivElement> & {
119
134
  * The selected indices. If `selectionMode` is `single`, only only the first
120
135
  * value will be used.
121
136
  */
122
- selectedIndices?: number[] | undefined;
137
+ selection?: ListSelection | undefined;
123
138
  /**
124
139
  * Indicates the selection behavior:
125
140
  * - `none`: No selection at all.
126
141
  * - `single`: Only one item can be selected at a time.
127
142
  * - `multiple`: Multiple items can be selected at the same time.
128
143
  */
129
- selectionMode?: "none" | "multiple" | "single" | undefined;
144
+ selectionMode?: ListSelectionMode | undefined;
130
145
  /**
131
146
  * React component type to be used to generate items for this list.
132
147
  */
@@ -160,9 +175,9 @@ declare const _default: <T>(props: React.HTMLAttributes<HTMLDivElement> & {
160
175
  /**
161
176
  * Handler invoked when the selected items changed.
162
177
  *
163
- * @param indices Indices of selected items.
178
+ * @param selection Indices of selected items.
164
179
  */
165
- onSelectionChange?: ((indices: number[]) => void) | undefined;
180
+ onSelectionChange?: ((selection: ListSelection) => void) | undefined;
166
181
  } & {
167
182
  ref?: React.Ref<HTMLDivElement> | undefined;
168
183
  }) => ReactElement;
package/lib/List.js CHANGED
@@ -87,7 +87,7 @@ var styles_1 = __importDefault(require("./utils/styles"));
87
87
  * generic. This component supports both horizontal and vertical orientations.
88
88
  */
89
89
  exports.default = (0, react_2.forwardRef)(function (_a, ref) {
90
- var className = _a.className, style = _a.style, _b = _a.borderThickness, borderThickness = _b === void 0 ? 0 : _b, data = _a.data, _c = _a.selectionMode, selectionMode = _c === void 0 ? 'none' : _c, _d = _a.isSelectionTogglable, isSelectionTogglable = _d === void 0 ? false : _d, itemLength = _a.itemLength, _e = _a.itemPadding, itemPadding = _e === void 0 ? 0 : _e, _f = _a.orientation, orientation = _f === void 0 ? 'vertical' : _f, _g = _a.selectedIndices, externalSelectedIndices = _g === void 0 ? [] : _g, ItemComponent = _a.itemComponentType, onActivateAt = _a.onActivateAt, onDeselectAt = _a.onDeselectAt, onItemCustomEvent = _a.onItemCustomEvent, onSelectAt = _a.onSelectAt, onSelectionChange = _a.onSelectionChange, props = __rest(_a, ["className", "style", "borderThickness", "data", "selectionMode", "isSelectionTogglable", "itemLength", "itemPadding", "orientation", "selectedIndices", "itemComponentType", "onActivateAt", "onDeselectAt", "onItemCustomEvent", "onSelectAt", "onSelectionChange"]);
90
+ var className = _a.className, style = _a.style, data = _a.data, _b = _a.selectionMode, selectionMode = _b === void 0 ? 'none' : _b, _c = _a.isSelectionTogglable, isSelectionTogglable = _c === void 0 ? false : _c, _d = _a.itemLength, itemLength = _d === void 0 ? 50 : _d, _e = _a.itemPadding, itemPadding = _e === void 0 ? 0 : _e, _f = _a.layout, layout = _f === void 0 ? 'list' : _f, _g = _a.numSegments, numSegments = _g === void 0 ? 1 : _g, _h = _a.orientation, orientation = _h === void 0 ? 'vertical' : _h, _j = _a.selection, externalSelection = _j === void 0 ? [] : _j, ItemComponent = _a.itemComponentType, onActivateAt = _a.onActivateAt, onDeselectAt = _a.onDeselectAt, onItemCustomEvent = _a.onItemCustomEvent, onSelectAt = _a.onSelectAt, onSelectionChange = _a.onSelectionChange, props = __rest(_a, ["className", "style", "data", "selectionMode", "isSelectionTogglable", "itemLength", "itemPadding", "layout", "numSegments", "orientation", "selection", "itemComponentType", "onActivateAt", "onDeselectAt", "onItemCustomEvent", "onSelectAt", "onSelectionChange"]);
91
91
  var isIndexOutOfRange = function (index) {
92
92
  if (index >= data.length)
93
93
  return true;
@@ -95,8 +95,8 @@ exports.default = (0, react_2.forwardRef)(function (_a, ref) {
95
95
  return true;
96
96
  return false;
97
97
  };
98
- var sanitizeSelectedIndices = function (indices) { return indices.sort().filter(function (t) { return !isIndexOutOfRange(t); }); };
99
- var isSelectedAt = function (index) { return selectedIndices.indexOf(index) >= 0; };
98
+ var sanitizeSelection = function (indices) { return indices.sort().filter(function (t) { return !isIndexOutOfRange(t); }); };
99
+ var isSelectedAt = function (index) { return selection.indexOf(index) >= 0; };
100
100
  var toggleAt = function (index) {
101
101
  if (isSelectedAt(index)) {
102
102
  deselectAt(index);
@@ -110,10 +110,10 @@ exports.default = (0, react_2.forwardRef)(function (_a, ref) {
110
110
  return;
111
111
  switch (selectionMode) {
112
112
  case 'multiple':
113
- setSelectedIndices(function (prev) { return __spreadArray(__spreadArray([], __read(prev.filter(function (t) { return t !== index; })), false), [index], false).sort(); });
113
+ setSelection(function (prev) { return __spreadArray(__spreadArray([], __read(prev.filter(function (t) { return t !== index; })), false), [index], false).sort(); });
114
114
  break;
115
115
  case 'single':
116
- setSelectedIndices([index]);
116
+ setSelection([index]);
117
117
  break;
118
118
  default:
119
119
  break;
@@ -122,7 +122,7 @@ exports.default = (0, react_2.forwardRef)(function (_a, ref) {
122
122
  var deselectAt = function (index) {
123
123
  if (!isSelectedAt(index))
124
124
  return;
125
- setSelectedIndices(function (prev) { return prev.filter(function (t) { return t !== index; }); });
125
+ setSelection(function (prev) { return prev.filter(function (t) { return t !== index; }); });
126
126
  };
127
127
  var activateAt = function (index) {
128
128
  if (selectionMode !== 'none') {
@@ -135,70 +135,67 @@ exports.default = (0, react_2.forwardRef)(function (_a, ref) {
135
135
  }
136
136
  onActivateAt === null || onActivateAt === void 0 ? void 0 : onActivateAt(index);
137
137
  };
138
- var sanitizedExternalSelectedIndices = sanitizeSelectedIndices(externalSelectedIndices);
139
- var _h = __read((0, react_2.useState)(sanitizedExternalSelectedIndices), 2), selectedIndices = _h[0], setSelectedIndices = _h[1];
140
- var prevSelectedIndices = (0, usePrevious_1.default)(selectedIndices);
138
+ var sanitizedExternalSelection = sanitizeSelection(externalSelection);
139
+ var _k = __read((0, react_2.useState)(sanitizedExternalSelection), 2), selection = _k[0], setSelection = _k[1];
140
+ var prevSelection = (0, usePrevious_1.default)(selection, { sanitizeDependency: JSON.stringify });
141
141
  (0, react_2.useEffect)(function () {
142
- if ((0, react_1.default)(sanitizedExternalSelectedIndices, selectedIndices))
142
+ if ((0, react_1.default)(sanitizedExternalSelection, selection))
143
143
  return;
144
- setSelectedIndices(sanitizedExternalSelectedIndices);
145
- }, [JSON.stringify(sanitizedExternalSelectedIndices)]);
144
+ setSelection(sanitizedExternalSelection);
145
+ }, [JSON.stringify(sanitizedExternalSelection)]);
146
146
  (0, react_2.useEffect)(function () {
147
147
  var _a;
148
- if (prevSelectedIndices === undefined)
149
- return;
150
148
  if (selectionMode === 'none')
151
149
  return;
152
- var deselected = (_a = prevSelectedIndices === null || prevSelectedIndices === void 0 ? void 0 : prevSelectedIndices.filter(function (t) { return selectedIndices.indexOf(t) === -1; })) !== null && _a !== void 0 ? _a : [];
153
- var selected = selectedIndices.filter(function (t) { return (prevSelectedIndices === null || prevSelectedIndices === void 0 ? void 0 : prevSelectedIndices.indexOf(t)) === -1; });
150
+ if (!prevSelection)
151
+ return;
152
+ var deselected = (_a = prevSelection === null || prevSelection === void 0 ? void 0 : prevSelection.filter(function (t) { return selection.indexOf(t) === -1; })) !== null && _a !== void 0 ? _a : [];
153
+ var selected = selection.filter(function (t) { return (prevSelection === null || prevSelection === void 0 ? void 0 : prevSelection.indexOf(t)) === -1; });
154
154
  deselected.map(function (t) { return onDeselectAt === null || onDeselectAt === void 0 ? void 0 : onDeselectAt(t); });
155
155
  selected.map(function (t) { return onSelectAt === null || onSelectAt === void 0 ? void 0 : onSelectAt(t); });
156
- onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange(selectedIndices);
157
- }, [JSON.stringify(selectedIndices)]);
158
- var fixedClassNames = getFixedClassNames({ isSelectionTogglable: isSelectionTogglable, orientation: orientation });
159
- var fixedStyles = getFixedStyles({ borderThickness: borderThickness, orientation: orientation });
160
- return (react_2.default.createElement("div", __assign({}, props, { ref: ref, className: (0, classnames_1.default)(className, fixedClassNames.root), style: (0, styles_1.default)(style, fixedStyles.root) }), ItemComponent && (react_2.default.createElement(Each_1.default, { in: data }, function (val, idx) { return (react_2.default.createElement(ItemComponent, { className: (0, classnames_1.default)(fixedClassNames.item, {
156
+ onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange(selection);
157
+ }, [JSON.stringify(selection)]);
158
+ var fixedClassNames = getFixedClassNames({ orientation: orientation });
159
+ var fixedStyles = getFixedStyles({ itemLength: itemLength, itemPadding: itemPadding, layout: layout, numSegments: numSegments, orientation: orientation });
160
+ return (react_2.default.createElement("div", __assign({}, props, { ref: ref, className: (0, classnames_1.default)(className, fixedClassNames.root), style: (0, styles_1.default)(style, fixedStyles.root) }), ItemComponent && (react_2.default.createElement(Each_1.default, { in: data }, function (val, idx) { return (react_2.default.createElement(ItemComponent, { className: (0, classnames_1.default)({
161
161
  selected: isSelectedAt(idx),
162
- }), style: (0, styles_1.default)(fixedStyles.item, __assign(__assign({ pointerEvents: isSelectionTogglable !== true && isSelectedAt(idx) ? 'none' : 'auto' }, orientation === 'vertical' ? {
163
- height: itemLength !== undefined ? "".concat(itemLength, "px") : undefined,
164
- marginTop: "".concat(idx === 0 ? 0 : -borderThickness, "px"),
165
- } : {
166
- marginLeft: "".concat(idx === 0 ? 0 : -borderThickness, "px"),
167
- width: itemLength !== undefined ? "".concat(itemLength, "px") : undefined,
168
- }), idx >= data.length - 1 ? {} : __assign({}, orientation === 'vertical' ? {
162
+ }), style: (0, styles_1.default)(fixedStyles.item, __assign({ pointerEvents: isSelectionTogglable !== true && isSelectedAt(idx) ? 'none' : 'auto' }, idx >= data.length - 1 ? {} : __assign({}, layout === 'list' ? __assign({}, orientation === 'vertical' ? {
169
163
  marginBottom: "".concat(itemPadding, "px"),
170
164
  } : {
171
165
  marginRight: "".concat(itemPadding, "px"),
172
- }))), "data-index": idx, data: val, index: idx, isSelected: isSelectedAt(idx), orientation: orientation, onCustomEvent: function (name, info) { return onItemCustomEvent === null || onItemCustomEvent === void 0 ? void 0 : onItemCustomEvent(idx, name, info); }, onClick: function () { return activateAt(idx); } })); }))));
166
+ }) : {}))), "data-index": idx, data: val, index: idx, isSelected: isSelectedAt(idx), orientation: orientation, onCustomEvent: function (name, info) { return onItemCustomEvent === null || onItemCustomEvent === void 0 ? void 0 : onItemCustomEvent(idx, name, info); }, onClick: function () { return activateAt(idx); } })); }))));
173
167
  });
174
168
  function getFixedClassNames(_a) {
175
- var orientation = _a.orientation, isSelectionTogglable = _a.isSelectionTogglable;
169
+ var orientation = _a.orientation;
176
170
  return (0, asClassNameDict_1.default)({
177
- root: (0, classnames_1.default)(orientation, {
178
- togglable: isSelectionTogglable,
179
- }),
180
- item: (0, classnames_1.default)(orientation, {
181
- togglable: isSelectionTogglable,
182
- }),
171
+ root: (0, classnames_1.default)(orientation),
183
172
  });
184
173
  }
185
174
  function getFixedStyles(_a) {
186
- var _b = _a.borderThickness, borderThickness = _b === void 0 ? 0 : _b, orientation = _a.orientation;
175
+ var itemLength = _a.itemLength, _b = _a.itemPadding, itemPadding = _b === void 0 ? 0 : _b, layout = _a.layout, _c = _a.numSegments, numSegments = _c === void 0 ? 1 : _c, orientation = _a.orientation;
187
176
  return (0, asStyleDict_1.default)({
188
- root: {
177
+ root: __assign({ counterReset: 'item-counter', listStyle: 'none' }, layout === 'list' ? {
189
178
  alignItems: 'flex-start',
190
- counterReset: 'item-counter',
191
179
  display: 'flex',
192
180
  flex: '0 0 auto',
193
181
  flexDirection: orientation === 'horizontal' ? 'row' : 'column',
194
182
  justifyContent: 'flex-start',
195
- listStyle: 'none',
196
- },
197
- item: __assign({ borderWidth: "".concat(borderThickness, "px"), counterIncrement: 'item-counter', flex: '0 0 auto' }, orientation === 'vertical' ? {
183
+ } : __assign({ display: 'grid', gap: "".concat(itemPadding, "px") }, orientation === 'vertical' ? {
184
+ gridAutoRows: itemLength !== undefined ? "".concat(itemLength, "px") : undefined,
185
+ gridTemplateColumns: "repeat(".concat(numSegments, ", 1fr)"),
186
+ gridAutoFlow: 'row',
187
+ } : {
188
+ gridAutoColumns: itemLength !== undefined ? "".concat(itemLength, "px") : undefined,
189
+ gridTemplateRows: "repeat(".concat(numSegments, ", 1fr)"),
190
+ gridAutoFlow: 'column',
191
+ })),
192
+ item: __assign({ border: 'none', counterIncrement: 'item-counter', flex: '0 0 auto' }, layout === 'list' ? __assign({}, orientation === 'vertical' ? {
198
193
  width: '100%',
194
+ height: itemLength !== undefined ? "".concat(itemLength, "px") : undefined,
199
195
  } : {
196
+ width: itemLength !== undefined ? "".concat(itemLength, "px") : undefined,
200
197
  height: '100%',
201
- }),
198
+ }) : {}),
202
199
  });
203
200
  }
204
201
  //# sourceMappingURL=List.js.map
package/lib/List.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"List.js","sourceRoot":"/","sources":["List.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAAmC;AACnC,gEAA+C;AAC/C,6CAAoI;AACpI,gDAAyB;AACzB,oEAA6C;AAC7C,4EAAqD;AACrD,oEAA6C;AAC7C,0DAAmC;AA4GnC;;;;GAIG;AACH,kBAAe,IAAA,kBAAU,EAAC,UAAC,EAkB1B,EAAE,GAAG;IAjBJ,IAAA,SAAS,eAAA,EACT,KAAK,WAAA,EACL,uBAAmB,EAAnB,eAAe,mBAAG,CAAC,KAAA,EACnB,IAAI,UAAA,EACJ,qBAAsB,EAAtB,aAAa,mBAAG,MAAM,KAAA,EAC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IACb,WAAW,KAAK,UAAU,CAAC,CAAC,CAAC;YAC9B,KAAK,EAAE,MAAM;SACd,CAAC,CAAC,CAAC;YACF,MAAM,EAAE,MAAM;SACf,CACF;KACF,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import classNames from 'classnames'\nimport isDeepEqual from 'fast-deep-equal/react'\nimport React, { forwardRef, useEffect, useState, type ComponentType, type HTMLAttributes, type ReactElement, type Ref } from 'react'\nimport Each from './Each'\nimport usePrevious from './hooks/usePrevious'\nimport asClassNameDict from './utils/asClassNameDict'\nimport asStyleDict from './utils/asStyleDict'\nimport styles from './utils/styles'\n\nexport type ListOrientation = 'horizontal' | 'vertical'\n\nexport type ListItemProps<T> = HTMLAttributes<HTMLElement> & {\n data: T\n index: number\n isSelected: boolean\n orientation: ListOrientation\n onCustomEvent?: (name: string, info?: any) => void\n}\n\nexport type ListProps<T> = HTMLAttributes<HTMLDivElement> & {\n /**\n * Thickness of item borders (in pixels). 0 indicates no borders.\n */\n borderThickness?: number\n\n /**\n * Generically typed data of each item.\n */\n data: T[]\n\n /**\n * Indicates if item selection can be toggled, i.e. they can be deselected if\n * selected again.\n */\n isSelectionTogglable?: boolean\n\n /**\n * Optional length (in pixels) of each item. Length refers to the height in\n * vertical orientation and width in horizontal orientation.\n */\n itemLength?: number\n\n /**\n * Padding between every item (in pixels).\n */\n itemPadding?: number\n\n /**\n * Orientation of the component.\n */\n orientation?: ListOrientation\n\n /**\n * The selected indices. If `selectionMode` is `single`, only only the first\n * value will be used.\n */\n selectedIndices?: number[]\n\n /**\n * Indicates the selection behavior:\n * - `none`: No selection at all.\n * - `single`: Only one item can be selected at a time.\n * - `multiple`: Multiple items can be selected at the same time.\n */\n selectionMode?: 'none' | 'single' | 'multiple'\n\n /**\n * React component type to be used to generate items for this list.\n */\n itemComponentType?: ComponentType<ListItemProps<T>>\n\n /**\n * Handler invoked when an item is activated.\n *\n * @param index Item index.\n */\n onActivateAt?: (index: number) => void\n\n /**\n * Handler invoked when an item is deselected.\n *\n * @param index Item index.\n */\n onDeselectAt?: (index: number) => void\n\n /**\n * Handler invoked when a custom event is dispatched from the item.\n *\n * @param index Index of the item.\n * @param eventName Name of the dispatched custom event.\n * @param eventInfo Optional info of the dispatched custom event.\n */\n onItemCustomEvent?: (index: number, eventName: string, eventInfo?: any) => void\n\n /**\n * Handler invoked when an item is selected.\n *\n * @param index Item index.\n */\n onSelectAt?: (index: number) => void\n\n /**\n * Handler invoked when the selected items changed.\n *\n * @param indices Indices of selected items.\n */\n onSelectionChange?: (indices: number[]) => void\n}\n\ntype StylesProps = {\n borderThickness?: number\n isSelectionTogglable?: boolean\n orientation?: ListOrientation\n}\n\n/**\n * A scrollable list of selectable items. Items are generated based on the\n * provided React component type. The type of data passed to each item is\n * generic. This component supports both horizontal and vertical orientations.\n */\nexport default forwardRef(({\n className,\n style,\n borderThickness = 0,\n data,\n selectionMode = 'none',\n isSelectionTogglable = false,\n itemLength,\n itemPadding = 0,\n orientation = 'vertical',\n selectedIndices: externalSelectedIndices = [],\n itemComponentType: ItemComponent,\n onActivateAt,\n onDeselectAt,\n onItemCustomEvent,\n onSelectAt,\n onSelectionChange,\n ...props\n}, ref) => {\n const isIndexOutOfRange = (index: number) => {\n if (index >= data.length) return true\n if (index < 0) return true\n\n return false\n }\n\n const sanitizeSelectedIndices = (indices: number[]) => indices.sort().filter(t => !isIndexOutOfRange(t))\n\n const isSelectedAt = (index: number) => selectedIndices.indexOf(index) >= 0\n\n const toggleAt = (index: number) => {\n if (isSelectedAt(index)) {\n deselectAt(index)\n }\n else {\n selectAt(index)\n }\n }\n\n const selectAt = (index: number) => {\n if (isSelectedAt(index)) return\n\n switch (selectionMode) {\n case 'multiple':\n setSelectedIndices(prev => [...prev.filter(t => t !== index), index].sort())\n\n break\n case 'single':\n setSelectedIndices([index])\n\n break\n default:\n break\n }\n }\n\n const deselectAt = (index: number) => {\n if (!isSelectedAt(index)) return\n\n setSelectedIndices(prev => prev.filter(t => t !== index))\n }\n\n const activateAt = (index: number) => {\n if (selectionMode !== 'none') {\n if (isSelectionTogglable) {\n toggleAt(index)\n }\n else {\n selectAt(index)\n }\n }\n\n onActivateAt?.(index)\n }\n\n const sanitizedExternalSelectedIndices = sanitizeSelectedIndices(externalSelectedIndices)\n const [selectedIndices, setSelectedIndices] = useState(sanitizedExternalSelectedIndices)\n const prevSelectedIndices = usePrevious(selectedIndices)\n\n useEffect(() => {\n if (isDeepEqual(sanitizedExternalSelectedIndices, selectedIndices)) return\n\n setSelectedIndices(sanitizedExternalSelectedIndices)\n }, [JSON.stringify(sanitizedExternalSelectedIndices)])\n\n useEffect(() => {\n if (prevSelectedIndices === undefined) return\n if (selectionMode === 'none') return\n\n const deselected = prevSelectedIndices?.filter(t => selectedIndices.indexOf(t) === -1) ?? []\n const selected = selectedIndices.filter(t => prevSelectedIndices?.indexOf(t) === -1)\n\n deselected.map(t => onDeselectAt?.(t))\n selected.map(t => onSelectAt?.(t))\n\n onSelectionChange?.(selectedIndices)\n }, [JSON.stringify(selectedIndices)])\n\n const fixedClassNames = getFixedClassNames({ isSelectionTogglable, orientation })\n const fixedStyles = getFixedStyles({ borderThickness, orientation })\n\n return (\n <div\n {...props}\n ref={ref}\n className={classNames(className, fixedClassNames.root)}\n style={styles(style, fixedStyles.root)}\n >\n {ItemComponent && (\n <Each in={data}>\n {(val, idx) => (\n <ItemComponent\n className={classNames(fixedClassNames.item, {\n selected: isSelectedAt(idx),\n })}\n style={styles(fixedStyles.item, {\n pointerEvents: isSelectionTogglable !== true && isSelectedAt(idx) ? 'none' : 'auto',\n ...orientation === 'vertical' ? {\n height: itemLength !== undefined ? `${itemLength}px` : undefined,\n marginTop: `${idx === 0 ? 0 : -borderThickness}px`,\n } : {\n marginLeft: `${idx === 0 ? 0 : -borderThickness}px`,\n width: itemLength !== undefined ? `${itemLength}px` : undefined,\n },\n ...idx >= data.length - 1 ? {} : {\n ...orientation === 'vertical' ? {\n marginBottom: `${itemPadding}px`,\n } : {\n marginRight: `${itemPadding}px`,\n },\n },\n })}\n data-index={idx}\n data={val}\n index={idx}\n isSelected={isSelectedAt(idx)}\n orientation={orientation}\n onCustomEvent={(name, info) => onItemCustomEvent?.(idx, name, info)}\n onClick={() => activateAt(idx)}\n />\n )}\n </Each>\n )}\n </div>\n )\n}) as <T>(props: ListProps<T> & { ref?: Ref<HTMLDivElement> }) => ReactElement\n\nfunction getFixedClassNames({ orientation, isSelectionTogglable }: StylesProps) {\n return asClassNameDict({\n root: classNames(orientation, {\n togglable: isSelectionTogglable,\n }),\n item: classNames(orientation, {\n togglable: isSelectionTogglable,\n }),\n })\n}\n\nfunction getFixedStyles({ borderThickness = 0, orientation }: StylesProps) {\n return asStyleDict({\n root: {\n alignItems: 'flex-start',\n counterReset: 'item-counter',\n display: 'flex',\n flex: '0 0 auto',\n flexDirection: orientation === 'horizontal' ? 'row' : 'column',\n justifyContent: 'flex-start',\n listStyle: 'none',\n },\n item: {\n borderWidth: `${borderThickness}px`,\n counterIncrement: 'item-counter',\n flex: '0 0 auto',\n ...orientation === 'vertical' ? {\n width: '100%',\n } : {\n height: '100%',\n },\n },\n })\n}\n"]}
1
+ {"version":3,"file":"List.js","sourceRoot":"/","sources":["List.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAAmC;AACnC,gEAA+C;AAC/C,6CAAoI;AACpI,gDAAyB;AACzB,oEAA6C;AAC7C,4EAAqD;AACrD,oEAA6C;AAC7C,0DAAmC;AAmHnC;;;;GAIG;AACH,kBAAe,IAAA,kBAAU,EAAC,UAAC,EAmB1B,EAAE,GAAG;IAlBJ,IAAA,SAAS,eAAA,EACT,KAAK,WAAA,EACL,IAAI,UAAA,EACJ,qBAAsB,EAAtB,aAAa,mBAAG,MAAM,KAAA,EACtB,4BAA4B,EAA5B,oBAAoB,mBAAG,KAAK,KAAA,EAC5B,kBAAe,EAAf,UAAU,mBAAG,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,MAAM,EACd,gBAAgB,EAAE,cAAc,EAChC,IAAI,EAAE,UAAU,IACb,MAAM,KAAK,MAAM,CAAC,CAAC,cACjB,WAAW,KAAK,UAAU,CAAC,CAAC,CAAC;YAC9B,KAAK,EAAE,MAAM;YACb,MAAM,EAAE,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,UAAG,UAAU,OAAI,CAAC,CAAC,CAAC,SAAS;SACjE,CAAC,CAAC,CAAC;YACF,KAAK,EAAE,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,UAAG,UAAU,OAAI,CAAC,CAAC,CAAC,SAAS;YAC/D,MAAM,EAAE,MAAM;SACf,EACD,CAAC,CAAC,EAAE,CACP;KACF,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import classNames from 'classnames'\nimport isDeepEqual from 'fast-deep-equal/react'\nimport React, { forwardRef, useEffect, useState, type ComponentType, type HTMLAttributes, type ReactElement, type Ref } from 'react'\nimport Each from './Each'\nimport usePrevious from './hooks/usePrevious'\nimport asClassNameDict from './utils/asClassNameDict'\nimport asStyleDict from './utils/asStyleDict'\nimport styles from './utils/styles'\n\nexport type ListOrientation = 'horizontal' | 'vertical'\n\nexport type ListLayout = 'list' | 'grid'\n\nexport type ListSelectionMode = 'none' | 'single' | 'multiple'\n\nexport type ListSelection = number[]\n\nexport type ListItemProps<T> = HTMLAttributes<HTMLElement> & {\n data: T\n index: number\n isSelected: boolean\n orientation: ListOrientation\n onCustomEvent?: (name: string, info?: any) => void\n}\n\nexport type ListProps<T> = HTMLAttributes<HTMLDivElement> & {\n /**\n * Generically typed data of each item.\n */\n data: T[]\n\n /**\n * Indicates if item selection can be toggled, i.e. they can be deselected if\n * selected again.\n */\n isSelectionTogglable?: boolean\n\n /**\n * Optional length (in pixels) of each item. Length refers to the height in\n * vertical orientation and width in horizontal orientation.\n */\n itemLength?: number\n\n /**\n * Padding between every item (in pixels).\n */\n itemPadding?: number\n\n /**\n * Specifies the layout of this component.\n */\n layout?: ListLayout\n\n /**\n * This property is only used if the layout is set to `grid`. Specifies the\n * number of columns if orientation is `vertical` or number of rows if\n * orientation is `horizontal`.\n */\n numSegments?: number\n\n /**\n * Orientation of the component.\n */\n orientation?: ListOrientation\n\n /**\n * The selected indices. If `selectionMode` is `single`, only only the first\n * value will be used.\n */\n selection?: ListSelection\n\n /**\n * Indicates the selection behavior:\n * - `none`: No selection at all.\n * - `single`: Only one item can be selected at a time.\n * - `multiple`: Multiple items can be selected at the same time.\n */\n selectionMode?: ListSelectionMode\n\n /**\n * React component type to be used to generate items for this list.\n */\n itemComponentType?: ComponentType<ListItemProps<T>>\n\n /**\n * Handler invoked when an item is activated.\n *\n * @param index Item index.\n */\n onActivateAt?: (index: number) => void\n\n /**\n * Handler invoked when an item is deselected.\n *\n * @param index Item index.\n */\n onDeselectAt?: (index: number) => void\n\n /**\n * Handler invoked when a custom event is dispatched from the item.\n *\n * @param index Index of the item.\n * @param eventName Name of the dispatched custom event.\n * @param eventInfo Optional info of the dispatched custom event.\n */\n onItemCustomEvent?: (index: number, eventName: string, eventInfo?: any) => void\n\n /**\n * Handler invoked when an item is selected.\n *\n * @param index Item index.\n */\n onSelectAt?: (index: number) => void\n\n /**\n * Handler invoked when the selected items changed.\n *\n * @param selection Indices of selected items.\n */\n onSelectionChange?: (selection: ListSelection) => void\n}\n\n/**\n * A scrollable list of selectable items. Items are generated based on the\n * provided React component type. The type of data passed to each item is\n * generic. This component supports both horizontal and vertical orientations.\n */\nexport default forwardRef(({\n className,\n style,\n data,\n selectionMode = 'none',\n isSelectionTogglable = false,\n itemLength = 50,\n itemPadding = 0,\n layout = 'list',\n numSegments = 1,\n orientation = 'vertical',\n selection: externalSelection = [],\n itemComponentType: ItemComponent,\n onActivateAt,\n onDeselectAt,\n onItemCustomEvent,\n onSelectAt,\n onSelectionChange,\n ...props\n}, ref) => {\n const isIndexOutOfRange = (index: number) => {\n if (index >= data.length) return true\n if (index < 0) return true\n\n return false\n }\n\n const sanitizeSelection = (indices: ListSelection) => indices.sort().filter(t => !isIndexOutOfRange(t))\n\n const isSelectedAt = (index: number) => selection.indexOf(index) >= 0\n\n const toggleAt = (index: number) => {\n if (isSelectedAt(index)) {\n deselectAt(index)\n }\n else {\n selectAt(index)\n }\n }\n\n const selectAt = (index: number) => {\n if (isSelectedAt(index)) return\n\n switch (selectionMode) {\n case 'multiple':\n setSelection(prev => [...prev.filter(t => t !== index), index].sort())\n\n break\n case 'single':\n setSelection([index])\n\n break\n default:\n break\n }\n }\n\n const deselectAt = (index: number) => {\n if (!isSelectedAt(index)) return\n\n setSelection(prev => prev.filter(t => t !== index))\n }\n\n const activateAt = (index: number) => {\n if (selectionMode !== 'none') {\n if (isSelectionTogglable) {\n toggleAt(index)\n }\n else {\n selectAt(index)\n }\n }\n\n onActivateAt?.(index)\n }\n\n const sanitizedExternalSelection = sanitizeSelection(externalSelection)\n const [selection, setSelection] = useState(sanitizedExternalSelection)\n const prevSelection = usePrevious(selection, { sanitizeDependency: JSON.stringify })\n\n useEffect(() => {\n if (isDeepEqual(sanitizedExternalSelection, selection)) return\n\n setSelection(sanitizedExternalSelection)\n }, [JSON.stringify(sanitizedExternalSelection)])\n\n useEffect(() => {\n if (selectionMode === 'none') return\n if (!prevSelection) return\n\n const deselected = prevSelection?.filter(t => selection.indexOf(t) === -1) ?? []\n const selected = selection.filter(t => prevSelection?.indexOf(t) === -1)\n\n deselected.map(t => onDeselectAt?.(t))\n selected.map(t => onSelectAt?.(t))\n\n onSelectionChange?.(selection)\n }, [JSON.stringify(selection)])\n\n const fixedClassNames = getFixedClassNames({ orientation })\n const fixedStyles = getFixedStyles({ itemLength, itemPadding, layout, numSegments, orientation })\n\n return (\n <div\n {...props}\n ref={ref}\n className={classNames(className, fixedClassNames.root)}\n style={styles(style, fixedStyles.root)}\n >\n {ItemComponent && (\n <Each in={data}>\n {(val, idx) => (\n <ItemComponent\n className={classNames({\n selected: isSelectedAt(idx),\n })}\n style={styles(fixedStyles.item, {\n pointerEvents: isSelectionTogglable !== true && isSelectedAt(idx) ? 'none' : 'auto',\n ...idx >= data.length - 1 ? {} : {\n ...layout === 'list' ? {\n ...orientation === 'vertical' ? {\n marginBottom: `${itemPadding}px`,\n } : {\n marginRight: `${itemPadding}px`,\n },\n } : {},\n },\n })}\n data-index={idx}\n data={val}\n index={idx}\n isSelected={isSelectedAt(idx)}\n orientation={orientation}\n onCustomEvent={(name, info) => onItemCustomEvent?.(idx, name, info)}\n onClick={() => activateAt(idx)}\n />\n )}\n </Each>\n )}\n </div>\n )\n}) as <T>(props: ListProps<T> & { ref?: Ref<HTMLDivElement> }) => ReactElement\n\ntype StylesProps = {\n itemLength?: number\n itemPadding?: number\n layout?: ListLayout\n numSegments?: number\n orientation?: ListOrientation\n}\n\nfunction getFixedClassNames({ orientation }: StylesProps) {\n return asClassNameDict({\n root: classNames(orientation),\n })\n}\n\nfunction getFixedStyles({ itemLength, itemPadding = 0, layout, numSegments = 1, orientation }: StylesProps) {\n return asStyleDict({\n root: {\n counterReset: 'item-counter',\n listStyle: 'none',\n ...layout === 'list' ? {\n alignItems: 'flex-start',\n display: 'flex',\n flex: '0 0 auto',\n flexDirection: orientation === 'horizontal' ? 'row' : 'column',\n justifyContent: 'flex-start',\n } : {\n display: 'grid',\n gap: `${itemPadding}px`,\n ...orientation === 'vertical' ? {\n gridAutoRows: itemLength !== undefined ? `${itemLength}px` : undefined,\n gridTemplateColumns: `repeat(${numSegments}, 1fr)`,\n gridAutoFlow: 'row',\n } : {\n gridAutoColumns: itemLength !== undefined ? `${itemLength}px` : undefined,\n gridTemplateRows: `repeat(${numSegments}, 1fr)`,\n gridAutoFlow: 'column',\n },\n },\n },\n item: {\n border: 'none',\n counterIncrement: 'item-counter',\n flex: '0 0 auto',\n ...layout === 'list' ? {\n ...orientation === 'vertical' ? {\n width: '100%',\n height: itemLength !== undefined ? `${itemLength}px` : undefined,\n } : {\n width: itemLength !== undefined ? `${itemLength}px` : undefined,\n height: '100%',\n },\n } : {},\n },\n })\n}\n"]}
@@ -1,6 +1,19 @@
1
+ type Options<T> = {
2
+ /**
3
+ * Function to transform the dependency value in the dependency list, useful
4
+ * if the value is a reference.
5
+ *
6
+ * @param dependency The dependency value.
7
+ *
8
+ * @returns The transformed value to be used as the dependency value instead.
9
+ */
10
+ sanitizeDependency?: (dependency: T) => any;
11
+ };
1
12
  /**
2
- * Returns the previous value of a state or prop.
13
+ * Returns the previous value of a value.
3
14
  *
4
- * @param stateOrProp The state or prop.
15
+ * @param value The value.
16
+ * @param options See {@link Options}.
5
17
  */
6
- export default function usePrevious<T>(stateOrProp: T): T | undefined;
18
+ export default function usePrevious<T>(value: T, { sanitizeDependency }?: Options<T>): T | undefined;
19
+ export {};
@@ -2,15 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var react_1 = require("react");
4
4
  /**
5
- * Returns the previous value of a state or prop.
5
+ * Returns the previous value of a value.
6
6
  *
7
- * @param stateOrProp The state or prop.
7
+ * @param value The value.
8
+ * @param options See {@link Options}.
8
9
  */
9
- function usePrevious(stateOrProp) {
10
+ function usePrevious(value, _a) {
11
+ var _b = _a === void 0 ? {} : _a, _c = _b.sanitizeDependency, sanitizeDependency = _c === void 0 ? function (t) { return t; } : _c;
10
12
  var ref = (0, react_1.useRef)();
11
13
  (0, react_1.useEffect)(function () {
12
- ref.current = stateOrProp;
13
- }, [stateOrProp]);
14
+ ref.current = value;
15
+ }, [sanitizeDependency(value)]);
14
16
  return ref.current;
15
17
  }
16
18
  exports.default = usePrevious;
@@ -1 +1 @@
1
- {"version":3,"file":"usePrevious.js","sourceRoot":"/","sources":["hooks/usePrevious.ts"],"names":[],"mappings":";;AAAA,+BAAyC;AAEzC;;;;GAIG;AACH,SAAwB,WAAW,CAAI,WAAc;IACnD,IAAM,GAAG,GAAG,IAAA,cAAM,GAAK,CAAA;IAEvB,IAAA,iBAAS,EAAC;QACR,GAAG,CAAC,OAAO,GAAG,WAAW,CAAA;IAC3B,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,CAAA;IAEjB,OAAO,GAAG,CAAC,OAAO,CAAA;AACpB,CAAC;AARD,8BAQC","sourcesContent":["import { useEffect, useRef } from 'react'\n\n/**\n * Returns the previous value of a state or prop.\n *\n * @param stateOrProp The state or prop.\n */\nexport default function usePrevious<T>(stateOrProp: T): T | undefined {\n const ref = useRef<T>()\n\n useEffect(() => {\n ref.current = stateOrProp\n }, [stateOrProp])\n\n return ref.current\n}\n"]}
1
+ {"version":3,"file":"usePrevious.js","sourceRoot":"/","sources":["hooks/usePrevious.ts"],"names":[],"mappings":";;AAAA,+BAAyC;AAczC;;;;;GAKG;AACH,SAAwB,WAAW,CAAI,KAAQ,EAAE,EAAgD;QAAhD,qBAA8C,EAAE,KAAA,EAA9C,0BAA2B,EAA3B,kBAAkB,mBAAG,UAAA,CAAC,IAAI,OAAA,CAAC,EAAD,CAAC,KAAA;IAC5E,IAAM,GAAG,GAAG,IAAA,cAAM,GAAK,CAAA;IAEvB,IAAA,iBAAS,EAAC;QACR,GAAG,CAAC,OAAO,GAAG,KAAK,CAAA;IACrB,CAAC,EAAE,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IAE/B,OAAO,GAAG,CAAC,OAAO,CAAA;AACpB,CAAC;AARD,8BAQC","sourcesContent":["import { useEffect, useRef } from 'react'\n\ntype Options<T> = {\n /**\n * Function to transform the dependency value in the dependency list, useful\n * if the value is a reference.\n *\n * @param dependency The dependency value.\n *\n * @returns The transformed value to be used as the dependency value instead.\n */\n sanitizeDependency?: (dependency: T) => any\n}\n\n/**\n * Returns the previous value of a value.\n *\n * @param value The value.\n * @param options See {@link Options}.\n */\nexport default function usePrevious<T>(value: T, { sanitizeDependency = t => t }: Options<T> = {}): T | undefined {\n const ref = useRef<T>()\n\n useEffect(() => {\n ref.current = value\n }, [sanitizeDependency(value)])\n\n return ref.current\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "etudes",
3
- "version": "3.7.1",
3
+ "version": "3.8.0",
4
4
  "description": "A study of headless React components",
5
5
  "main": "lib",
6
6
  "scripts": {