etudes 1.2.0 → 2.0.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.
Files changed (120) hide show
  1. package/README.md +1 -1
  2. package/lib/Accordion.d.ts +80 -71
  3. package/lib/Accordion.js +173 -183
  4. package/lib/Accordion.js.map +1 -1
  5. package/lib/BurgerButton.d.ts +20 -7
  6. package/lib/BurgerButton.js +113 -20
  7. package/lib/BurgerButton.js.map +1 -1
  8. package/lib/Conditional.d.ts +2 -3
  9. package/lib/Conditional.js +0 -1
  10. package/lib/Conditional.js.map +1 -1
  11. package/lib/DebugConsole.d.ts +14 -23
  12. package/lib/DebugConsole.js +86 -87
  13. package/lib/DebugConsole.js.map +1 -1
  14. package/lib/Dial.d.ts +53 -16
  15. package/lib/Dial.js +121 -35
  16. package/lib/Dial.js.map +1 -1
  17. package/lib/Dropdown.d.ts +68 -83
  18. package/lib/Dropdown.js +226 -161
  19. package/lib/Dropdown.js.map +1 -1
  20. package/lib/Each.d.ts +2 -2
  21. package/lib/Each.js.map +1 -1
  22. package/lib/ExtractChild.d.ts +5 -4
  23. package/lib/ExtractChild.js +13 -11
  24. package/lib/ExtractChild.js.map +1 -1
  25. package/lib/ExtractChildren.d.ts +2 -2
  26. package/lib/ExtractChildren.js +7 -5
  27. package/lib/ExtractChildren.js.map +1 -1
  28. package/lib/FlatSVG.d.ts +30 -25
  29. package/lib/FlatSVG.js +28 -37
  30. package/lib/FlatSVG.js.map +1 -1
  31. package/lib/List.d.ts +97 -54
  32. package/lib/List.js +124 -63
  33. package/lib/List.js.map +1 -1
  34. package/lib/MasonryGrid.d.ts +27 -15
  35. package/lib/MasonryGrid.js +163 -148
  36. package/lib/MasonryGrid.js.map +1 -1
  37. package/lib/Panorama.d.ts +100 -21
  38. package/lib/Panorama.js +45 -44
  39. package/lib/Panorama.js.map +1 -1
  40. package/lib/PanoramaSlider.d.ts +65 -23
  41. package/lib/PanoramaSlider.js +150 -45
  42. package/lib/PanoramaSlider.js.map +1 -1
  43. package/lib/RangeSlider.d.ts +29 -89
  44. package/lib/RangeSlider.js +272 -286
  45. package/lib/RangeSlider.js.map +1 -1
  46. package/lib/Repeat.d.ts +4 -3
  47. package/lib/Repeat.js +3 -2
  48. package/lib/Repeat.js.map +1 -1
  49. package/lib/RotatingGallery.d.ts +38 -36
  50. package/lib/RotatingGallery.js +47 -17
  51. package/lib/RotatingGallery.js.map +1 -1
  52. package/lib/SelectableButton.d.ts +13 -4
  53. package/lib/SelectableButton.js +3 -14
  54. package/lib/SelectableButton.js.map +1 -1
  55. package/lib/Slider.d.ts +103 -41
  56. package/lib/Slider.js +182 -82
  57. package/lib/Slider.js.map +1 -1
  58. package/lib/StepwiseSlider.d.ts +146 -59
  59. package/lib/StepwiseSlider.js +248 -142
  60. package/lib/StepwiseSlider.js.map +1 -1
  61. package/lib/SwipeContainer.d.ts +13 -5
  62. package/lib/SwipeContainer.js +5 -15
  63. package/lib/SwipeContainer.js.map +1 -1
  64. package/lib/TextField.d.ts +1 -1
  65. package/lib/TextField.js +5 -15
  66. package/lib/TextField.js.map +1 -1
  67. package/lib/Video.d.ts +30 -51
  68. package/lib/Video.js +77 -119
  69. package/lib/Video.js.map +1 -1
  70. package/lib/WithTooltip.d.ts +16 -18
  71. package/lib/WithTooltip.js +167 -101
  72. package/lib/WithTooltip.js.map +1 -1
  73. package/lib/hooks/useDocumentTitle.d.ts +2 -1
  74. package/lib/hooks/useDocumentTitle.js +2 -1
  75. package/lib/hooks/useDocumentTitle.js.map +1 -1
  76. package/lib/hooks/useDragEffect.d.ts +25 -16
  77. package/lib/hooks/useDragEffect.js +30 -20
  78. package/lib/hooks/useDragEffect.js.map +1 -1
  79. package/lib/hooks/useElementRect.d.ts +2 -1
  80. package/lib/hooks/useElementRect.js +5 -4
  81. package/lib/hooks/useElementRect.js.map +1 -1
  82. package/lib/hooks/useInterval.d.ts +2 -2
  83. package/lib/hooks/useInterval.js +1 -1
  84. package/lib/hooks/useInterval.js.map +1 -1
  85. package/lib/hooks/useLoadImageEffect.d.ts +6 -6
  86. package/lib/hooks/useLoadImageEffect.js.map +1 -1
  87. package/lib/hooks/usePrevious.d.ts +6 -0
  88. package/lib/hooks/usePrevious.js +17 -0
  89. package/lib/hooks/usePrevious.js.map +1 -0
  90. package/lib/hooks/useResizeEffect.d.ts +2 -2
  91. package/lib/hooks/useResizeEffect.js +5 -8
  92. package/lib/hooks/useResizeEffect.js.map +1 -1
  93. package/lib/hooks/useSearchParamState.d.ts +10 -7
  94. package/lib/hooks/useSearchParamState.js +14 -10
  95. package/lib/hooks/useSearchParamState.js.map +1 -1
  96. package/lib/utils/asClassNameDict.d.ts +3 -0
  97. package/lib/utils/asClassNameDict.js +7 -0
  98. package/lib/utils/asClassNameDict.js.map +1 -0
  99. package/lib/utils/asComponentDict.d.ts +5 -0
  100. package/lib/utils/asComponentDict.js +23 -0
  101. package/lib/utils/asComponentDict.js.map +1 -0
  102. package/lib/utils/asStyleDict.d.ts +4 -0
  103. package/lib/utils/asStyleDict.js +7 -0
  104. package/lib/utils/asStyleDict.js.map +1 -0
  105. package/lib/utils/cloneStyledElement.d.ts +18 -0
  106. package/lib/utils/cloneStyledElement.js +63 -0
  107. package/lib/utils/cloneStyledElement.js.map +1 -0
  108. package/lib/utils/styles.d.ts +2 -0
  109. package/lib/utils/styles.js +22 -0
  110. package/lib/utils/styles.js.map +1 -0
  111. package/lib/utils/useDebug.d.ts +2 -0
  112. package/lib/utils/useDebug.js +46 -0
  113. package/lib/utils/useDebug.js.map +1 -0
  114. package/package.json +25 -33
  115. package/lib/AbstractSelectableCollection.d.ts +0 -94
  116. package/lib/AbstractSelectableCollection.js +0 -151
  117. package/lib/AbstractSelectableCollection.js.map +0 -1
  118. package/lib/types/index.d.ts +0 -7
  119. package/lib/types/index.js +0 -3
  120. package/lib/types/index.js.map +0 -1
package/lib/List.d.ts CHANGED
@@ -1,89 +1,132 @@
1
- import { ComponentType, CSSProperties } from 'react';
2
- import AbstractSelectableCollection, { Props as AbstractSelectableCollectionProps } from './AbstractSelectableCollection';
3
- import { Orientation } from './types';
4
- /**
5
- * Interface defining the props of the item component type to be provided to the
6
- * list. The data type is generic.
7
- */
8
- export interface ItemComponentProps<T = Record<string, never>> {
1
+ import React, { ComponentType, HTMLAttributes, ReactElement, Ref } from 'react';
2
+ declare type Orientation = 'horizontal' | 'vertical';
3
+ export declare type ListItemProps<T> = HTMLAttributes<HTMLElement> & {
4
+ data: T;
5
+ index: number;
6
+ isSelected: boolean;
7
+ orientation: Orientation;
8
+ };
9
+ export declare type ListProps<T> = HTMLAttributes<HTMLDivElement> & {
9
10
  /**
10
- * Class attribute of the root element.
11
+ * Thickness of item borders (in pixels). 0 indicates no borders.
11
12
  */
12
- className?: string;
13
+ borderThickness?: number;
13
14
  /**
14
- * Inline style attribute of the root element.
15
+ * Generically typed data of each item.
15
16
  */
16
- style: CSSProperties;
17
+ data: T[];
17
18
  /**
18
- * Data passed to the item component.
19
+ * The selected index. Any value below 0 indicates that nothing is
20
+ * selected.
19
21
  */
20
- data: T;
22
+ selectedIndex?: number;
23
+ /**
24
+ * React component type to be used to generate items for this list.
25
+ */
26
+ itemComponentType?: ComponentType<ListItemProps<T>>;
27
+ /**
28
+ * Optional length of each item.
29
+ */
30
+ itemLength?: number;
31
+ /**
32
+ * Padding between every item (in pixels).
33
+ */
34
+ itemPadding?: number;
35
+ /**
36
+ * Indicates whether selections are retained. For example, in the case of a
37
+ * vertical list of clickable rows, being able to retain a selection means
38
+ * when the row is clicked, it becomes and stays selected. Being unable to
39
+ * retain a selection means when the row is clicked, it does not become
40
+ * selected. It is simply clicked and the subsequent event is dispatched.
41
+ */
42
+ isSelectable?: boolean;
21
43
  /**
22
- * Indicates if the item is selected.
44
+ * Indicates whether selections can be toggled. For example, in the case of a
45
+ * vertical list of selectable rows, being able to toggle a row means it gets
46
+ * deselected when selected again. Being unable to toggle the row means it
47
+ * does not get deselected when selected again.
23
48
  */
24
- isSelected?: boolean;
49
+ isTogglable?: boolean;
25
50
  /**
26
51
  * Orientation of the list.
27
52
  */
28
- orientation: Orientation;
53
+ orientation?: Orientation;
54
+ /**
55
+ * Handler invoked when an index is activated.
56
+ */
57
+ onActivate?: (index: number) => void;
29
58
  /**
30
- * Handler invoked when the item is clicked.
59
+ * Handler invoked when an index is deselected.
31
60
  */
32
- onClick?: () => void;
33
- }
34
- export interface Props<T = Record<string, never>> extends AbstractSelectableCollectionProps {
61
+ onDeselectAt?: (index: number) => void;
62
+ /**
63
+ * Handler invoked when an index is selected.
64
+ */
65
+ onSelectAt?: (index: number) => void;
66
+ };
67
+ /**
68
+ * A scrollable list of selectable items. Items are generated based on the
69
+ * provided React component type. The type of data passed to each item is
70
+ * generic. This component supports both horizontal and vertical orientations.
71
+ */
72
+ declare const _default: <T>(props: React.HTMLAttributes<HTMLDivElement> & {
73
+ /**
74
+ * Thickness of item borders (in pixels). 0 indicates no borders.
75
+ */
76
+ borderThickness?: number | undefined;
35
77
  /**
36
78
  * Generically typed data of each item.
37
79
  */
38
80
  data: T[];
39
81
  /**
40
- * Maximum length (in pixels) of this component. The definition of length here
41
- * is dependent on the orientation of the component. If the orientation is
42
- * horizontal, length means width. If the orientation is vertical, length
43
- * means height. If specified, the length will be capped at this value and the
44
- * component becomes scrollable.
82
+ * The selected index. Any value below 0 indicates that nothing is
83
+ * selected.
45
84
  */
46
- maxLength?: number;
85
+ selectedIndex?: number | undefined;
47
86
  /**
48
- * Padding between every item (in pixels).
87
+ * React component type to be used to generate items for this list.
49
88
  */
50
- itemPadding?: number;
89
+ itemComponentType?: React.ComponentType<ListItemProps<T>> | undefined;
51
90
  /**
52
- * Thickness of item borders (in pixels). 0 indicates no borders.
91
+ * Optional length of each item.
53
92
  */
54
- borderThickness?: number;
93
+ itemLength?: number | undefined;
55
94
  /**
56
- * Orientation of the list.
95
+ * Padding between every item (in pixels).
57
96
  */
58
- orientation?: Orientation;
97
+ itemPadding?: number | undefined;
59
98
  /**
60
- * Color of item borders.
99
+ * Indicates whether selections are retained. For example, in the case of a
100
+ * vertical list of clickable rows, being able to retain a selection means
101
+ * when the row is clicked, it becomes and stays selected. Being unable to
102
+ * retain a selection means when the row is clicked, it does not become
103
+ * selected. It is simply clicked and the subsequent event is dispatched.
61
104
  */
62
- borderColor?: string;
105
+ isSelectable?: boolean | undefined;
63
106
  /**
64
- * React component type to be used to generate items for this list.
107
+ * Indicates whether selections can be toggled. For example, in the case of a
108
+ * vertical list of selectable rows, being able to toggle a row means it gets
109
+ * deselected when selected again. Being unable to toggle the row means it
110
+ * does not get deselected when selected again.
65
111
  */
66
- itemComponentType: ComponentType<ItemComponentProps<T>>;
112
+ isTogglable?: boolean | undefined;
67
113
  /**
68
- * Class attribute of the root element of the item component.
114
+ * Orientation of the list.
69
115
  */
70
- itemClassName?: string;
116
+ orientation?: Orientation | undefined;
71
117
  /**
72
- * Inline style attribute of the root element of the item component.
118
+ * Handler invoked when an index is activated.
73
119
  */
74
- itemStyle?: CSSProperties;
120
+ onActivate?: ((index: number) => void) | undefined;
75
121
  /**
76
- * Padding (in pixels) between the items and the scrollbar. Note that this is
77
- * unused if there is no scrollbar (i.e. max length is not specified).
122
+ * Handler invoked when an index is deselected.
78
123
  */
79
- scrollBarPadding?: number;
80
- }
81
- /**
82
- * A scrollable list of selectable items. Items are generated based on the
83
- * provided React component type. The type of data passed to each item is
84
- * generic. This component supports both horizontal and vertical orientations.
85
- */
86
- export default class List<T = Record<string, never>> extends AbstractSelectableCollection<Props<T>> {
87
- render(): JSX.Element;
88
- isIndexOutOfRange(index: number): boolean;
89
- }
124
+ onDeselectAt?: ((index: number) => void) | undefined;
125
+ /**
126
+ * Handler invoked when an index is selected.
127
+ */
128
+ onSelectAt?: ((index: number) => void) | undefined;
129
+ } & {
130
+ ref?: React.Ref<HTMLDivElement> | undefined;
131
+ }) => ReactElement;
132
+ export default _default;
package/lib/List.js CHANGED
@@ -1,23 +1,4 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
18
- if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
19
- return cooked;
20
- };
21
2
  var __assign = (this && this.__assign) || function () {
22
3
  __assign = Object.assign || function(t) {
23
4
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -52,59 +33,139 @@ var __importStar = (this && this.__importStar) || function (mod) {
52
33
  __setModuleDefault(result, mod);
53
34
  return result;
54
35
  };
36
+ var __rest = (this && this.__rest) || function (s, e) {
37
+ var t = {};
38
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
39
+ t[p] = s[p];
40
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
41
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
42
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
43
+ t[p[i]] = s[p[i]];
44
+ }
45
+ return t;
46
+ };
47
+ var __read = (this && this.__read) || function (o, n) {
48
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
49
+ if (!m) return o;
50
+ var i = m.call(o), r, ar = [], e;
51
+ try {
52
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
53
+ }
54
+ catch (error) { e = { error: error }; }
55
+ finally {
56
+ try {
57
+ if (r && !r.done && (m = i["return"])) m.call(i);
58
+ }
59
+ finally { if (e) throw e.error; }
60
+ }
61
+ return ar;
62
+ };
55
63
  var __importDefault = (this && this.__importDefault) || function (mod) {
56
64
  return (mod && mod.__esModule) ? mod : { "default": mod };
57
65
  };
58
66
  Object.defineProperty(exports, "__esModule", { value: true });
59
- var react_1 = __importDefault(require("react"));
60
- var styled_components_1 = __importStar(require("styled-components"));
61
- var AbstractSelectableCollection_1 = __importDefault(require("./AbstractSelectableCollection"));
67
+ var classnames_1 = __importDefault(require("classnames"));
68
+ var react_1 = __importStar(require("react"));
69
+ var Each_1 = __importDefault(require("./Each"));
70
+ var usePrevious_1 = __importDefault(require("./hooks/usePrevious"));
71
+ var asClassNameDict_1 = __importDefault(require("./utils/asClassNameDict"));
72
+ var asStyleDict_1 = __importDefault(require("./utils/asStyleDict"));
73
+ var styles_1 = __importDefault(require("./utils/styles"));
62
74
  /**
63
75
  * A scrollable list of selectable items. Items are generated based on the
64
76
  * provided React component type. The type of data passed to each item is
65
77
  * generic. This component supports both horizontal and vertical orientations.
66
78
  */
67
- var List = /** @class */ (function (_super) {
68
- __extends(List, _super);
69
- function List() {
70
- return _super !== null && _super.apply(this, arguments) || this;
71
- }
72
- List.prototype.render = function () {
73
- var _this = this;
74
- var _a, _b, _c, _d, _e, _f, _g;
75
- var ItemComponentType = this.props.itemComponentType;
76
- var borderColor = (_a = this.props.borderColor) !== null && _a !== void 0 ? _a : '#000';
77
- var borderThickness = (_b = this.props.borderThickness) !== null && _b !== void 0 ? _b : 0;
78
- var maxLength = (_c = this.props.maxLength) !== null && _c !== void 0 ? _c : -1;
79
- var scrollBarPadding = maxLength < 0 ? 0 : ((_d = this.props.scrollBarPadding) !== null && _d !== void 0 ? _d : 0);
80
- var orientation = (_e = this.props.orientation) !== null && _e !== void 0 ? _e : 'vertical';
81
- return (react_1.default.createElement(StyledRoot, { className: this.props.className, orientation: orientation, itemPadding: (_f = this.props.itemPadding) !== null && _f !== void 0 ? _f : 0, style: __assign(__assign({}, (_g = this.props.style) !== null && _g !== void 0 ? _g : {}), (maxLength < 0 ? {} : (orientation === 'vertical' ? {
82
- height: "".concat(maxLength, "px"),
83
- overflowY: 'scroll',
84
- paddingRight: "".concat(scrollBarPadding, "px"),
85
- WebkitOverflowScrolling: 'touch',
86
- } : {
87
- overflowX: 'scroll',
88
- paddingBottom: "".concat(scrollBarPadding, "px"),
89
- width: "".concat(maxLength, "px"),
90
- WebkitOverflowScrolling: 'touch',
91
- }))) }, this.props.data.map(function (t, i) {
92
- var _a;
93
- return (react_1.default.createElement(ItemComponentType, { className: _this.props.itemClassName, data: t, isSelected: _this.isSelectedAt(i), key: "item-".concat(i), onClick: function () { return _this.toggleAt(i); }, orientation: orientation, style: __assign(__assign(__assign({}, (_a = _this.props.itemStyle) !== null && _a !== void 0 ? _a : {}), { borderColor: borderColor, borderWidth: "".concat(borderThickness, "px"), counterIncrement: 'item-counter', pointerEvents: _this.props.isTogglable !== true && _this.isSelectedAt(i) ? 'none' : 'auto' }), (orientation === 'vertical' ? {
94
- marginTop: "".concat(i === 0 ? 0 : -borderThickness, "px"),
95
- } : {
96
- marginLeft: "".concat(i === 0 ? 0 : -borderThickness, "px"),
97
- })) }));
98
- })));
99
- };
100
- List.prototype.isIndexOutOfRange = function (index) {
101
- if (index >= this.props.data.length)
79
+ exports.default = (0, react_1.forwardRef)(function (_a, ref) {
80
+ var className = _a.className, style = _a.style, _b = _a.borderThickness, borderThickness = _b === void 0 ? 0 : _b, data = _a.data, isSelectable = _a.isSelectable, isTogglable = _a.isTogglable, ItemComponentType = _a.itemComponentType, itemLength = _a.itemLength, _c = _a.itemPadding, itemPadding = _c === void 0 ? 0 : _c, _d = _a.orientation, orientation = _d === void 0 ? 'vertical' : _d, _e = _a.selectedIndex, externalSelectedIndex = _e === void 0 ? -1 : _e, onActivate = _a.onActivate, onDeselectAt = _a.onDeselectAt, onSelectAt = _a.onSelectAt, props = __rest(_a, ["className", "style", "borderThickness", "data", "isSelectable", "isTogglable", "itemComponentType", "itemLength", "itemPadding", "orientation", "selectedIndex", "onActivate", "onDeselectAt", "onSelectAt"]);
81
+ var isIndexOutOfRange = function (index) {
82
+ if (index >= data.length)
83
+ return true;
84
+ if (index < 0)
102
85
  return true;
103
- return _super.prototype.isIndexOutOfRange.call(this, index);
86
+ return false;
87
+ };
88
+ var isSelectedAt = function (index) { return selectedIndex === index; };
89
+ var toggleAt = function (index) {
90
+ if (isSelectedAt(index)) {
91
+ deselectAt(index);
92
+ }
93
+ else {
94
+ selectAt(index);
95
+ }
104
96
  };
105
- return List;
106
- }(AbstractSelectableCollection_1.default));
107
- exports.default = List;
108
- var StyledRoot = styled_components_1.default.ol(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n counter-reset: item-counter;\n list-style: none;\n align-items: flex-start;\n box-sizing: border-box;\n display: flex;\n flex-direction: ", ";\n flex: 0 0 auto;\n justify-content: flex-start;\n overflow-x: visible;\n overflow-y: visible;\n width: ", ";\n height: ", ";\n\n > * {\n flex: 0 0 auto;\n\n &:not(:last-child) {\n ", "\n }\n }\n"], ["\n counter-reset: item-counter;\n list-style: none;\n align-items: flex-start;\n box-sizing: border-box;\n display: flex;\n flex-direction: ", ";\n flex: 0 0 auto;\n justify-content: flex-start;\n overflow-x: visible;\n overflow-y: visible;\n width: ", ";\n height: ", ";\n\n > * {\n flex: 0 0 auto;\n\n &:not(:last-child) {\n ", "\n }\n }\n"])), function (props) { return props.orientation === 'horizontal' ? 'row' : 'column'; }, function (props) { return props.orientation === 'horizontal' ? 'auto' : '100%'; }, function (props) { return props.orientation === 'horizontal' ? '100%' : 'auto'; }, function (props) { return props.orientation === 'horizontal' ? (0, styled_components_1.css)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n margin-right: ", "px;\n "], ["\n margin-right: ", "px;\n "])), props.itemPadding) : (0, styled_components_1.css)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n margin-bottom: ", "px;\n "], ["\n margin-bottom: ", "px;\n "])), props.itemPadding); });
109
- var templateObject_1, templateObject_2, templateObject_3;
97
+ var selectAt = function (index) {
98
+ if (isSelectedAt(index))
99
+ return;
100
+ setSelectedIndex(index);
101
+ };
102
+ var deselectAt = function (index) {
103
+ if (!isSelectedAt(index))
104
+ return;
105
+ setSelectedIndex(-1);
106
+ };
107
+ var onClick = function (index) {
108
+ if (isSelectable) {
109
+ if (isTogglable) {
110
+ toggleAt(index);
111
+ }
112
+ else {
113
+ selectAt(index);
114
+ }
115
+ }
116
+ onActivate === null || onActivate === void 0 ? void 0 : onActivate(index);
117
+ };
118
+ var _f = __read((0, react_1.useState)(externalSelectedIndex), 2), selectedIndex = _f[0], setSelectedIndex = _f[1];
119
+ var prevSelectedIndex = (0, usePrevious_1.default)(selectedIndex);
120
+ (0, react_1.useEffect)(function () {
121
+ if (externalSelectedIndex === selectedIndex)
122
+ return;
123
+ setSelectedIndex(externalSelectedIndex);
124
+ }, [externalSelectedIndex]);
125
+ (0, react_1.useEffect)(function () {
126
+ if (!isSelectable)
127
+ return;
128
+ if (!isIndexOutOfRange(prevSelectedIndex !== null && prevSelectedIndex !== void 0 ? prevSelectedIndex : -1))
129
+ onDeselectAt === null || onDeselectAt === void 0 ? void 0 : onDeselectAt(prevSelectedIndex !== null && prevSelectedIndex !== void 0 ? prevSelectedIndex : -1);
130
+ if (!isIndexOutOfRange(selectedIndex))
131
+ onSelectAt === null || onSelectAt === void 0 ? void 0 : onSelectAt(selectedIndex);
132
+ }, [selectedIndex]);
133
+ var fixedClassNames = (0, asClassNameDict_1.default)({
134
+ root: (0, classnames_1.default)(orientation, {
135
+ togglable: isTogglable,
136
+ }),
137
+ item: (0, classnames_1.default)(orientation, {
138
+ togglable: isTogglable,
139
+ }),
140
+ });
141
+ var fixedStyles = (0, asStyleDict_1.default)({
142
+ root: {
143
+ alignItems: 'flex-start',
144
+ counterReset: 'item-counter',
145
+ display: 'flex',
146
+ flex: '0 0 auto',
147
+ flexDirection: orientation === 'horizontal' ? 'row' : 'column',
148
+ justifyContent: 'flex-start',
149
+ listStyle: 'none',
150
+ },
151
+ item: __assign({ borderWidth: "".concat(borderThickness, "px"), counterIncrement: 'item-counter', flex: '0 0 auto' }, orientation === 'vertical' ? {
152
+ width: '100%',
153
+ } : {
154
+ height: '100%',
155
+ }),
156
+ });
157
+ return (react_1.default.createElement("div", __assign({}, props, { ref: ref, className: (0, classnames_1.default)(className, fixedClassNames.root), style: (0, styles_1.default)(style, fixedStyles.root) }), ItemComponentType && (react_1.default.createElement(Each_1.default, { in: data }, function (val, idx) { return (react_1.default.createElement(ItemComponentType, { className: (0, classnames_1.default)(fixedClassNames.item, {
158
+ selected: isSelectedAt(idx),
159
+ }), style: (0, styles_1.default)(fixedStyles.item, __assign(__assign({ pointerEvents: isTogglable !== true && isSelectedAt(idx) ? 'none' : 'auto' }, orientation === 'vertical' ? {
160
+ height: itemLength !== undefined ? "".concat(itemLength, "px") : undefined,
161
+ marginTop: "".concat(idx === 0 ? 0 : -borderThickness, "px"),
162
+ } : {
163
+ marginLeft: "".concat(idx === 0 ? 0 : -borderThickness, "px"),
164
+ width: itemLength !== undefined ? "".concat(itemLength, "px") : undefined,
165
+ }), idx >= data.length - 1 ? {} : __assign({}, orientation === 'vertical' ? {
166
+ marginBottom: "".concat(itemPadding, "px"),
167
+ } : {
168
+ marginRight: "".concat(itemPadding, "px"),
169
+ }))), "data-index": idx, data: val, index: idx, isSelected: isSelectedAt(idx), orientation: orientation, onClick: function () { return onClick(idx); } })); }))));
170
+ });
110
171
  //# 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,gDAA2D;AAC3D,qEAA+C;AAC/C,gGAAyH;AAgGzH;;;;GAIG;AACH;IAA6D,wBAAsC;IAAnG;;IA6DA,CAAC;IA5DC,qBAA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CAAC,AA7DD,CAA6D,sCAA4B,GA6DxF;;AAED,IAAM,UAAU,GAAG,2BAAM,CAAC,EAAE,sbAG1B,oJAMkB,EAA8D,iHAKvE,EAA6D,eAC5D,EAA6D,uEAMjE,EAID,gBAGN,KAnBmB,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,WAAW,KAAK,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,EAArD,CAAqD,EAKvE,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,WAAW,KAAK,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAApD,CAAoD,EAC5D,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,WAAW,KAAK,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAApD,CAAoD,EAMjE,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,WAAW,KAAK,YAAY,CAAC,CAAC,KAAC,uBAAG,6GAAA,0BACjC,EAAiB,aAClC,KADiB,KAAK,CAAC,WAAW,EACjC,CAAC,KAAC,uBAAG,8GAAA,2BACY,EAAiB,aACnC,KADkB,KAAK,CAAC,WAAW,CACnC,EAJU,CAIV,CAGN,CAAA","sourcesContent":["import React, { ComponentType, CSSProperties } from 'react'\nimport styled, { css } from 'styled-components'\nimport AbstractSelectableCollection, { Props as AbstractSelectableCollectionProps } from './AbstractSelectableCollection'\nimport { Orientation } from './types'\n\n/**\n * Interface defining the props of the item component type to be provided to the\n * list. The data type is generic.\n */\nexport interface ItemComponentProps<T = Record<string, never>> {\n /**\n * Class attribute of the root element.\n */\n className?: string\n\n /**\n * Inline style attribute of the root element.\n */\n style: CSSProperties\n\n /**\n * Data passed to the item component.\n */\n data: T\n\n /**\n * Indicates if the item is selected.\n */\n isSelected?: boolean\n\n /**\n * Orientation of the list.\n */\n orientation: Orientation\n\n /**\n * Handler invoked when the item is clicked.\n */\n onClick?: () => void\n}\n\nexport interface Props<T = Record<string, never>> extends AbstractSelectableCollectionProps {\n /**\n * Generically typed data of each item.\n */\n data: T[]\n\n /**\n * Maximum length (in pixels) of this component. The definition of length here\n * is dependent on the orientation of the component. If the orientation is\n * horizontal, length means width. If the orientation is vertical, length\n * means height. If specified, the length will be capped at this value and the\n * component becomes scrollable.\n */\n maxLength?: number\n\n /**\n * Padding between every item (in pixels).\n */\n itemPadding?: number\n\n /**\n * Thickness of item borders (in pixels). 0 indicates no borders.\n */\n borderThickness?: number\n\n /**\n * Orientation of the list.\n */\n orientation?: Orientation\n\n /**\n * Color of item borders.\n */\n borderColor?: string\n\n /**\n * React component type to be used to generate items for this list.\n */\n itemComponentType: ComponentType<ItemComponentProps<T>>\n\n /**\n * Class attribute of the root element of the item component.\n */\n itemClassName?: string\n\n /**\n * Inline style attribute of the root element of the item component.\n */\n itemStyle?: CSSProperties\n\n /**\n * Padding (in pixels) between the items and the scrollbar. Note that this is\n * unused if there is no scrollbar (i.e. max length is not specified).\n */\n scrollBarPadding?: number\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 class List<T = Record<string, never>> extends AbstractSelectableCollection<Props<T>> {\n render() {\n const ItemComponentType = this.props.itemComponentType\n const borderColor = this.props.borderColor ?? '#000'\n const borderThickness = this.props.borderThickness ?? 0\n const maxLength = this.props.maxLength ?? -1\n const scrollBarPadding = maxLength < 0 ? 0 : (this.props.scrollBarPadding ?? 0)\n const orientation = this.props.orientation ?? 'vertical'\n\n return (\n <StyledRoot\n className={this.props.className}\n orientation={orientation}\n itemPadding={this.props.itemPadding ?? 0}\n style={{\n ...this.props.style ?? {},\n ...(maxLength < 0 ? {} : (\n orientation === 'vertical' ? {\n height: `${maxLength}px`,\n overflowY: 'scroll',\n paddingRight: `${scrollBarPadding}px`,\n WebkitOverflowScrolling: 'touch',\n } : {\n overflowX: 'scroll',\n paddingBottom: `${scrollBarPadding}px`,\n width: `${maxLength}px`,\n WebkitOverflowScrolling: 'touch',\n }\n )),\n }}\n >\n {this.props.data.map((t, i) => (\n <ItemComponentType\n className={this.props.itemClassName}\n data={t}\n isSelected={this.isSelectedAt(i)}\n key={`item-${i}`}\n onClick={() => this.toggleAt(i)}\n orientation={orientation}\n style={{\n ...this.props.itemStyle ?? {},\n borderColor,\n borderWidth: `${borderThickness}px`,\n counterIncrement: 'item-counter',\n pointerEvents: this.props.isTogglable !== true && this.isSelectedAt(i) ? 'none' : 'auto',\n ...(orientation === 'vertical' ? {\n marginTop: `${i === 0 ? 0 : -borderThickness}px`,\n } : {\n marginLeft: `${i === 0 ? 0 : -borderThickness}px`,\n }),\n }}\n />\n ))}\n </StyledRoot>\n )\n }\n\n isIndexOutOfRange(index: number): boolean {\n if (index >= this.props.data.length) return true\n return super.isIndexOutOfRange(index)\n }\n}\n\nconst StyledRoot = styled.ol<{\n itemPadding: number\n orientation: Props['orientation']\n}>`\n counter-reset: item-counter;\n list-style: none;\n align-items: flex-start;\n box-sizing: border-box;\n display: flex;\n flex-direction: ${props => props.orientation === 'horizontal' ? 'row' : 'column'};\n flex: 0 0 auto;\n justify-content: flex-start;\n overflow-x: visible;\n overflow-y: visible;\n width: ${props => props.orientation === 'horizontal' ? 'auto' : '100%'};\n height: ${props => props.orientation === 'horizontal' ? '100%' : 'auto'};\n\n > * {\n flex: 0 0 auto;\n\n &:not(:last-child) {\n ${props => props.orientation === 'horizontal' ? css`\n margin-right: ${props.itemPadding}px;\n ` : css`\n margin-bottom: ${props.itemPadding}px;\n `}\n }\n }\n`\n"]}
1
+ {"version":3,"file":"List.js","sourceRoot":"/","sources":["List.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAAmC;AACnC,6CAAgH;AAChH,gDAAyB;AACzB,oEAA6C;AAC7C,4EAAqD;AACrD,oEAA6C;AAC7C,0DAAmC;AAiFnC;;;;GAI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;YAC9B,MAAM,EAAE,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,UAAG,UAAU,OAAI,CAAC,CAAC,CAAC,SAAS;YAChE,SAAS,EAAE,UAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,eAAe,OAAI;SACnD,CAAC,CAAC,CAAC;YACF,UAAU,EAAE,UAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,eAAe,OAAI;YACnD,KAAK,EAAE,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,UAAG,UAAU,OAAI,CAAC,CAAC,CAAC,SAAS;SAChE,GACE,GAAG,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,cAC3B,WAAW,KAAK,UAAU,CAAC,CAAC,CAAC;YAC9B,YAAY,EAAE,UAAG,WAAW,OAAI;SACjC,CAAC,CAAC,CAAC;YACF,WAAW,EAAE,UAAG,WAAW,OAAI;SAChC,CACF,EACD,gBACU,GAAG,EACf,IAAI,EAAE,GAAG,EACT,KAAK,EAAE,GAAG,EACV,UAAU,EAAE,YAAY,CAAC,GAAG,CAAC,EAC7B,WAAW,EAAE,WAAW,EACxB,OAAO,EAAE,cAAM,OAAA,OAAO,CAAC,GAAG,CAAC,EAAZ,CAAY,GAC3B,CACH,EA7Bc,CA6Bd,CACI,CACR,CACG,CACP,CAAA;AACH,CAAC,CAA6E,CAAA","sourcesContent":["import classNames from 'classnames'\nimport React, { ComponentType, forwardRef, HTMLAttributes, ReactElement, Ref, useEffect, useState } 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\ntype Orientation = 'horizontal' | 'vertical'\n\nexport type ListItemProps<T> = HTMLAttributes<HTMLElement> & {\n data: T\n index: number\n isSelected: boolean\n orientation: Orientation\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 * The selected index. Any value below 0 indicates that nothing is\n * selected.\n */\n selectedIndex?: number\n\n /**\n * React component type to be used to generate items for this list.\n */\n itemComponentType?: ComponentType<ListItemProps<T>>\n\n /**\n * Optional length of each item.\n */\n itemLength?: number\n\n /**\n * Padding between every item (in pixels).\n */\n itemPadding?: number\n\n /**\n * Indicates whether selections are retained. For example, in the case of a\n * vertical list of clickable rows, being able to retain a selection means\n * when the row is clicked, it becomes and stays selected. Being unable to\n * retain a selection means when the row is clicked, it does not become\n * selected. It is simply clicked and the subsequent event is dispatched.\n */\n isSelectable?: boolean\n\n /**\n * Indicates whether selections can be toggled. For example, in the case of a\n * vertical list of selectable rows, being able to toggle a row means it gets\n * deselected when selected again. Being unable to toggle the row means it\n * does not get deselected when selected again.\n */\n isTogglable?: boolean\n\n /**\n * Orientation of the list.\n */\n orientation?: Orientation\n\n /**\n * Handler invoked when an index is activated.\n */\n onActivate?: (index: number) => void\n\n /**\n * Handler invoked when an index is deselected.\n */\n onDeselectAt?: (index: number) => void\n\n /**\n * Handler invoked when an index is selected.\n */\n onSelectAt?: (index: number) => 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 borderThickness = 0,\n data,\n isSelectable,\n isTogglable,\n itemComponentType: ItemComponentType,\n itemLength,\n itemPadding = 0,\n orientation = 'vertical',\n selectedIndex: externalSelectedIndex = -1,\n onActivate,\n onDeselectAt,\n onSelectAt,\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 isSelectedAt = (index: number) => selectedIndex === index\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 setSelectedIndex(index)\n }\n\n const deselectAt = (index: number) => {\n if (!isSelectedAt(index)) return\n setSelectedIndex(-1)\n }\n\n const onClick = (index: number) => {\n if (isSelectable) {\n if (isTogglable) {\n toggleAt(index)\n }\n else {\n selectAt(index)\n }\n }\n\n onActivate?.(index)\n }\n\n const [selectedIndex, setSelectedIndex] = useState(externalSelectedIndex)\n const prevSelectedIndex = usePrevious(selectedIndex)\n\n useEffect(() => {\n if (externalSelectedIndex === selectedIndex) return\n setSelectedIndex(externalSelectedIndex)\n }, [externalSelectedIndex])\n\n useEffect(() => {\n if (!isSelectable) return\n\n if (!isIndexOutOfRange(prevSelectedIndex ?? -1)) onDeselectAt?.(prevSelectedIndex ?? -1)\n if (!isIndexOutOfRange(selectedIndex)) onSelectAt?.(selectedIndex)\n }, [selectedIndex])\n\n const fixedClassNames = asClassNameDict({\n root: classNames(orientation, {\n togglable: isTogglable,\n }),\n item: classNames(orientation, {\n togglable: isTogglable,\n }),\n })\n\n const fixedStyles = 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 return (\n <div\n {...props}\n ref={ref}\n className={classNames(className, fixedClassNames.root)}\n style={styles(style, fixedStyles.root)}\n >\n {ItemComponentType && (\n <Each in={data}>\n {(val, idx) => (\n <ItemComponentType\n className={classNames(fixedClassNames.item, {\n selected: isSelectedAt(idx),\n })}\n style={styles(fixedStyles.item, {\n pointerEvents: isTogglable !== 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 onClick={() => onClick(idx)}\n />\n )}\n </Each>\n )}\n </div>\n )\n}) as <T>(props: ListProps<T> & { ref?: Ref<HTMLDivElement> }) => ReactElement\n"]}
@@ -1,6 +1,6 @@
1
- import { HTMLAttributes } from 'react';
2
- import { Orientation } from './types';
3
- export declare type Props = HTMLAttributes<HTMLDivElement> & {
1
+ import React, { HTMLAttributes } from 'react';
2
+ declare type Orientation = 'horizontal' | 'vertical';
3
+ export declare type MasonryGridProps = HTMLAttributes<HTMLDivElement> & {
4
4
  areSectionsAligned?: boolean;
5
5
  horizontalSpacing?: number;
6
6
  isReversed?: boolean;
@@ -9,16 +9,28 @@ export declare type Props = HTMLAttributes<HTMLDivElement> & {
9
9
  verticalSpacing?: number;
10
10
  };
11
11
  /**
12
- * This is a React component that arranges all of its immediate children in a masonry grid. Refrain
13
- * from assigning CSS styles to it via `className` or `style` property, though they are still
14
- * handled if absolutely necessary. Customize the grid via its supported properties. The grid can be
15
- * in either vertical or horizontal orientation. The length of every child element *parallel to the
16
- * direction of the orientation* is automatically set according to the number of sections specified
17
- * for the grid. This means that in an horizontally oriented grid, the *width* of each child element
18
- * is automatically set, whereas in a vertically oriented grid the *height* of each child element is
19
- * automatically set. Additionally, the *number of sections* corresponds to the maximum the number
20
- * of child elements present in the direction that is parallel to the orientation of the grid.
21
- * Hence, in a vertically oriented grid, *number of secitons* refers to the *number of rows*,
22
- * whereas in a horizontally oriented grid, *number of sections* refers to the *number of columns*.
12
+ * This is a React component that arranges all of its immediate children in a
13
+ * masonry grid. Refrain from assigning CSS styles to it via `className` or
14
+ * `style` property, though they are still handled if absolutely necessary.
15
+ * Customize the grid via its supported properties. The grid can be in either
16
+ * vertical or horizontal orientation. The length of every child element
17
+ * *parallel to the direction of the orientation* is automatically set according
18
+ * to the number of sections specified for the grid. This means that in an
19
+ * horizontally oriented grid, the *width* of each child element is
20
+ * automatically set, whereas in a vertically oriented grid the *height* of each
21
+ * child element is automatically set. Additionally, the *number of sections*
22
+ * corresponds to the maximum the number of child elements present in the
23
+ * direction that is parallel to the orientation of the grid. Hence, in a
24
+ * vertically oriented grid, *number of secitons* refers to the *number of
25
+ * rows*, whereas in a horizontally oriented grid, *number of sections* refers
26
+ * to the *number of columns*.
23
27
  */
24
- export default function MasonryGrid({ areSectionsAligned, children, horizontalSpacing, isReversed, orientation, sections, style, verticalSpacing, ...props }: Props): JSX.Element;
28
+ declare const _default: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & {
29
+ areSectionsAligned?: boolean | undefined;
30
+ horizontalSpacing?: number | undefined;
31
+ isReversed?: boolean | undefined;
32
+ orientation?: Orientation | undefined;
33
+ sections?: number | undefined;
34
+ verticalSpacing?: number | undefined;
35
+ } & React.RefAttributes<HTMLDivElement>>;
36
+ export default _default;