etudes 1.2.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/Accordion.d.ts +80 -71
- package/lib/Accordion.js +173 -183
- package/lib/Accordion.js.map +1 -1
- package/lib/BurgerButton.d.ts +20 -7
- package/lib/BurgerButton.js +113 -20
- package/lib/BurgerButton.js.map +1 -1
- package/lib/Conditional.d.ts +2 -3
- package/lib/Conditional.js +0 -1
- package/lib/Conditional.js.map +1 -1
- package/lib/DebugConsole.d.ts +14 -23
- package/lib/DebugConsole.js +86 -87
- package/lib/DebugConsole.js.map +1 -1
- package/lib/Dial.d.ts +53 -16
- package/lib/Dial.js +121 -35
- package/lib/Dial.js.map +1 -1
- package/lib/Dropdown.d.ts +68 -83
- package/lib/Dropdown.js +226 -161
- package/lib/Dropdown.js.map +1 -1
- package/lib/Each.d.ts +2 -2
- package/lib/Each.js.map +1 -1
- package/lib/ExtractChild.d.ts +5 -4
- package/lib/ExtractChild.js +13 -11
- package/lib/ExtractChild.js.map +1 -1
- package/lib/ExtractChildren.d.ts +2 -2
- package/lib/ExtractChildren.js +7 -5
- package/lib/ExtractChildren.js.map +1 -1
- package/lib/FlatSVG.d.ts +30 -25
- package/lib/FlatSVG.js +28 -37
- package/lib/FlatSVG.js.map +1 -1
- package/lib/List.d.ts +97 -54
- package/lib/List.js +124 -63
- package/lib/List.js.map +1 -1
- package/lib/MasonryGrid.d.ts +27 -15
- package/lib/MasonryGrid.js +163 -148
- package/lib/MasonryGrid.js.map +1 -1
- package/lib/Panorama.d.ts +100 -21
- package/lib/Panorama.js +45 -44
- package/lib/Panorama.js.map +1 -1
- package/lib/PanoramaSlider.d.ts +65 -23
- package/lib/PanoramaSlider.js +150 -45
- package/lib/PanoramaSlider.js.map +1 -1
- package/lib/RangeSlider.d.ts +29 -89
- package/lib/RangeSlider.js +272 -286
- package/lib/RangeSlider.js.map +1 -1
- package/lib/Repeat.d.ts +4 -3
- package/lib/Repeat.js +3 -2
- package/lib/Repeat.js.map +1 -1
- package/lib/RotatingGallery.d.ts +38 -36
- package/lib/RotatingGallery.js +47 -17
- package/lib/RotatingGallery.js.map +1 -1
- package/lib/SelectableButton.d.ts +13 -4
- package/lib/SelectableButton.js +3 -14
- package/lib/SelectableButton.js.map +1 -1
- package/lib/Slider.d.ts +103 -41
- package/lib/Slider.js +182 -82
- package/lib/Slider.js.map +1 -1
- package/lib/StepwiseSlider.d.ts +146 -59
- package/lib/StepwiseSlider.js +248 -142
- package/lib/StepwiseSlider.js.map +1 -1
- package/lib/SwipeContainer.d.ts +13 -5
- package/lib/SwipeContainer.js +5 -15
- package/lib/SwipeContainer.js.map +1 -1
- package/lib/TextField.d.ts +1 -1
- package/lib/TextField.js +5 -15
- package/lib/TextField.js.map +1 -1
- package/lib/Video.d.ts +30 -51
- package/lib/Video.js +77 -119
- package/lib/Video.js.map +1 -1
- package/lib/WithTooltip.d.ts +16 -18
- package/lib/WithTooltip.js +167 -101
- package/lib/WithTooltip.js.map +1 -1
- package/lib/hooks/useDocumentTitle.d.ts +2 -1
- package/lib/hooks/useDocumentTitle.js +2 -1
- package/lib/hooks/useDocumentTitle.js.map +1 -1
- package/lib/hooks/useDragEffect.d.ts +26 -17
- package/lib/hooks/useDragEffect.js +30 -20
- package/lib/hooks/useDragEffect.js.map +1 -1
- package/lib/hooks/useElementRect.d.ts +2 -1
- package/lib/hooks/useElementRect.js +5 -4
- package/lib/hooks/useElementRect.js.map +1 -1
- package/lib/hooks/useInterval.d.ts +3 -3
- package/lib/hooks/useInterval.js +1 -1
- package/lib/hooks/useInterval.js.map +1 -1
- package/lib/hooks/useLoadImageEffect.d.ts +8 -8
- package/lib/hooks/useLoadImageEffect.js.map +1 -1
- package/lib/hooks/usePrevious.d.ts +6 -0
- package/lib/hooks/usePrevious.js +17 -0
- package/lib/hooks/usePrevious.js.map +1 -0
- package/lib/hooks/useResizeEffect.d.ts +3 -3
- package/lib/hooks/useResizeEffect.js +5 -8
- package/lib/hooks/useResizeEffect.js.map +1 -1
- package/lib/hooks/useSearchParamState.d.ts +11 -8
- package/lib/hooks/useSearchParamState.js +14 -10
- package/lib/hooks/useSearchParamState.js.map +1 -1
- package/lib/providers/I18nProvider.d.ts +179 -0
- package/lib/providers/I18nProvider.js +470 -0
- package/lib/providers/I18nProvider.js.map +1 -0
- package/lib/providers/ScrollPositionProvider.d.ts +15 -0
- package/lib/providers/ScrollPositionProvider.js +112 -0
- package/lib/providers/ScrollPositionProvider.js.map +1 -0
- package/lib/utils/asClassNameDict.d.ts +3 -0
- package/lib/utils/asClassNameDict.js +7 -0
- package/lib/utils/asClassNameDict.js.map +1 -0
- package/lib/utils/asComponentDict.d.ts +5 -0
- package/lib/utils/asComponentDict.js +23 -0
- package/lib/utils/asComponentDict.js.map +1 -0
- package/lib/utils/asStyleDict.d.ts +4 -0
- package/lib/utils/asStyleDict.js +7 -0
- package/lib/utils/asStyleDict.js.map +1 -0
- package/lib/utils/cloneStyledElement.d.ts +18 -0
- package/lib/utils/cloneStyledElement.js +63 -0
- package/lib/utils/cloneStyledElement.js.map +1 -0
- package/lib/utils/styles.d.ts +2 -0
- package/lib/utils/styles.js +22 -0
- package/lib/utils/styles.js.map +1 -0
- package/lib/utils/useDebug.d.ts +2 -0
- package/lib/utils/useDebug.js +46 -0
- package/lib/utils/useDebug.js.map +1 -0
- package/package.json +31 -38
- package/lib/AbstractSelectableCollection.d.ts +0 -94
- package/lib/AbstractSelectableCollection.js +0 -151
- package/lib/AbstractSelectableCollection.js.map +0 -1
- package/lib/types/index.d.ts +0 -7
- package/lib/types/index.js +0 -3
- package/lib/types/index.js.map +0 -1
package/lib/Dropdown.d.ts
CHANGED
|
@@ -1,38 +1,16 @@
|
|
|
1
|
-
import React, { ComponentType,
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { ExtendedCSSFunction, Orientation } from './types';
|
|
6
|
-
export declare type ButtonCSSProps = Readonly<{
|
|
7
|
-
borderColor: string;
|
|
8
|
-
borderThickness: number;
|
|
9
|
-
isActive: boolean;
|
|
10
|
-
}>;
|
|
11
|
-
/**
|
|
12
|
-
* Type constraint of the data passed to each item in the component.
|
|
13
|
-
*/
|
|
14
|
-
export declare type DataProps<T = Record<string, any>> = T & {
|
|
1
|
+
import React, { ComponentType, HTMLAttributes, PropsWithChildren, ReactElement, Ref } from 'react';
|
|
2
|
+
import { ListItemProps } from './List';
|
|
3
|
+
type Orientation = 'horizontal' | 'vertical';
|
|
4
|
+
export type DropdownData = {
|
|
15
5
|
label?: string;
|
|
16
6
|
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
* component. The data type is generic.
|
|
20
|
-
*/
|
|
21
|
-
export declare type ItemComponentProps<T = Record<string, any>> = ListItemComponentProps<DataProps<T>>;
|
|
22
|
-
export declare type Props<T = Record<string, any>> = {
|
|
23
|
-
/**
|
|
24
|
-
* Class attribute to the root element.
|
|
25
|
-
*/
|
|
26
|
-
className?: string;
|
|
27
|
-
/**
|
|
28
|
-
* Inline style attribute to the element.
|
|
29
|
-
*/
|
|
30
|
-
style?: CSSProperties;
|
|
7
|
+
export type DropdownItemProps<T extends DropdownData = DropdownData> = ListItemProps<T>;
|
|
8
|
+
export type DropdownProps<T extends DropdownData = DropdownData> = HTMLAttributes<HTMLDivElement> & PropsWithChildren<{
|
|
31
9
|
/**
|
|
32
10
|
* Data of every item in the component. This is used to generate individual
|
|
33
11
|
* menu items. Data type is generic.
|
|
34
12
|
*/
|
|
35
|
-
data:
|
|
13
|
+
data: T[];
|
|
36
14
|
/**
|
|
37
15
|
* Indicates if the component is inverted (i.e. "dropup" instead of dropdown).
|
|
38
16
|
* Supports all orientations.
|
|
@@ -51,7 +29,7 @@ export declare type Props<T = Record<string, any>> = {
|
|
|
51
29
|
/**
|
|
52
30
|
* The index of the default selected item.
|
|
53
31
|
*/
|
|
54
|
-
|
|
32
|
+
selectedIndex?: number;
|
|
55
33
|
/**
|
|
56
34
|
* Length (in pixels) of each item. This does not apply to the dropdown button
|
|
57
35
|
* itself. Length refers to the height in vertical orientation and width in
|
|
@@ -74,10 +52,6 @@ export declare type Props<T = Record<string, any>> = {
|
|
|
74
52
|
* Orientation of the component.
|
|
75
53
|
*/
|
|
76
54
|
orientation?: Orientation;
|
|
77
|
-
/**
|
|
78
|
-
* Color of the border of every item and the dropdown button itself.
|
|
79
|
-
*/
|
|
80
|
-
borderColor?: string;
|
|
81
55
|
/**
|
|
82
56
|
* The label to appear on the dropdown button when no items are selected.
|
|
83
57
|
*/
|
|
@@ -89,74 +63,85 @@ export declare type Props<T = Record<string, any>> = {
|
|
|
89
63
|
/**
|
|
90
64
|
* React component type to be used for generating items inside the component.
|
|
91
65
|
*/
|
|
92
|
-
itemComponentType: ComponentType<
|
|
66
|
+
itemComponentType: ComponentType<DropdownItemProps<T>>;
|
|
93
67
|
/**
|
|
94
68
|
* Handler invoked whenever the selected index changes.
|
|
95
69
|
*/
|
|
96
70
|
onIndexChange?: (index: number) => void;
|
|
71
|
+
}>;
|
|
72
|
+
/**
|
|
73
|
+
* A dropdown menu component that is invertible (i.e. can "dropup" instead) and
|
|
74
|
+
* supports both horizontal and vertical orientations. Provide data and item
|
|
75
|
+
* component type to this component to automatically generate menu items.
|
|
76
|
+
*/
|
|
77
|
+
declare const _default: <T extends DropdownData = DropdownData>(props: React.HTMLAttributes<HTMLDivElement> & {
|
|
97
78
|
/**
|
|
98
|
-
*
|
|
79
|
+
* Data of every item in the component. This is used to generate individual
|
|
80
|
+
* menu items. Data type is generic.
|
|
99
81
|
*/
|
|
100
|
-
|
|
101
|
-
};
|
|
102
|
-
export interface State {
|
|
82
|
+
data: T[];
|
|
103
83
|
/**
|
|
104
|
-
*
|
|
105
|
-
*
|
|
84
|
+
* Indicates if the component is inverted (i.e. "dropup" instead of dropdown).
|
|
85
|
+
* Supports all orientations.
|
|
106
86
|
*/
|
|
107
|
-
|
|
87
|
+
isInverted?: boolean | undefined;
|
|
108
88
|
/**
|
|
109
|
-
* Indicates if
|
|
89
|
+
* Indicates if items can be toggled, i.e. they can be deselected if selected
|
|
90
|
+
* again.
|
|
110
91
|
*/
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* A dropdown menu component that is invertible (i.e. can "dropup" instead) and
|
|
115
|
-
* supports both horizontal and vertical orientations. Provide data and item
|
|
116
|
-
* component type to this component to automatically generate menu items.
|
|
117
|
-
*/
|
|
118
|
-
export default class Dropdown<T = Record<string, any>> extends PureComponent<Props<T>, State> {
|
|
119
|
-
nodeRefs: {
|
|
120
|
-
root: React.RefObject<HTMLDivElement>;
|
|
121
|
-
};
|
|
122
|
-
constructor(props: Props<T>);
|
|
123
|
-
get rect(): Rect;
|
|
124
|
-
componentDidMount(): void;
|
|
125
|
-
componentWillUnmount(): void;
|
|
126
|
-
componentDidUpdate(prevProps: Props<T>, prevState: State): void;
|
|
127
|
-
render(): JSX.Element;
|
|
92
|
+
isTogglable?: boolean | undefined;
|
|
128
93
|
/**
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
* @param index - The index of the item.
|
|
132
|
-
*
|
|
133
|
-
* @returns `true` if the item at the specified index is selected, `false`
|
|
134
|
-
* otherwise.
|
|
94
|
+
* Thickness of the border (in pixels) of every item and the dropdown button
|
|
95
|
+
* itself. 0 indicates no borders.
|
|
135
96
|
*/
|
|
136
|
-
|
|
97
|
+
borderThickness?: number | undefined;
|
|
137
98
|
/**
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
* @param index - The index of the item to select.
|
|
99
|
+
* The index of the default selected item.
|
|
141
100
|
*/
|
|
142
|
-
|
|
101
|
+
selectedIndex?: number | undefined;
|
|
143
102
|
/**
|
|
144
|
-
*
|
|
103
|
+
* Length (in pixels) of each item. This does not apply to the dropdown button
|
|
104
|
+
* itself. Length refers to the height in vertical orientation and width in
|
|
105
|
+
* horizontal orientation.
|
|
145
106
|
*/
|
|
146
|
-
|
|
107
|
+
itemLength?: number | undefined;
|
|
147
108
|
/**
|
|
148
|
-
*
|
|
109
|
+
* Padding (in pixels) of each item.
|
|
149
110
|
*/
|
|
150
|
-
|
|
111
|
+
itemPadding?: number | undefined;
|
|
151
112
|
/**
|
|
152
|
-
*
|
|
113
|
+
* Maximum number of items that are viside when the component expands. When a
|
|
114
|
+
* value greater than or equal to 0 is specified, only that number of items
|
|
115
|
+
* will be visible at a time, and a scrollbar will appear to scroll to
|
|
116
|
+
* remaining items. Any value less than 0 indicates that all items will be
|
|
117
|
+
* visible when the component expands.
|
|
153
118
|
*/
|
|
154
|
-
|
|
119
|
+
maxVisibleItems?: number | undefined;
|
|
155
120
|
/**
|
|
156
|
-
*
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
121
|
+
* Orientation of the component.
|
|
122
|
+
*/
|
|
123
|
+
orientation?: Orientation | undefined;
|
|
124
|
+
/**
|
|
125
|
+
* The label to appear on the dropdown button when no items are selected.
|
|
126
|
+
*/
|
|
127
|
+
defaultLabel?: string | undefined;
|
|
128
|
+
/**
|
|
129
|
+
* SVG markup to be put in the dropdown button as the expand icon.
|
|
130
|
+
*/
|
|
131
|
+
expandIconSvg?: string | undefined;
|
|
132
|
+
/**
|
|
133
|
+
* React component type to be used for generating items inside the component.
|
|
134
|
+
*/
|
|
135
|
+
itemComponentType: React.ComponentType<DropdownItemProps<T>>;
|
|
136
|
+
/**
|
|
137
|
+
* Handler invoked whenever the selected index changes.
|
|
160
138
|
*/
|
|
161
|
-
|
|
162
|
-
}
|
|
139
|
+
onIndexChange?: ((index: number) => void) | undefined;
|
|
140
|
+
} & {
|
|
141
|
+
children?: React.ReactNode;
|
|
142
|
+
} & {
|
|
143
|
+
ref?: React.Ref<HTMLDivElement> | undefined;
|
|
144
|
+
}) => ReactElement;
|
|
145
|
+
export default _default;
|
|
146
|
+
export declare const DropdownToggle: ({ ...props }: HTMLAttributes<HTMLButtonElement>) => JSX.Element;
|
|
147
|
+
export declare const DropdownExpandIcon: ({ ...props }: HTMLAttributes<HTMLDivElement>) => JSX.Element;
|
package/lib/Dropdown.js
CHANGED
|
@@ -1,22 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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 __());
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
15
10
|
};
|
|
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;
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
20
12
|
};
|
|
21
13
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
22
14
|
if (k2 === undefined) k2 = k;
|
|
@@ -41,168 +33,241 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
41
33
|
__setModuleDefault(result, mod);
|
|
42
34
|
return result;
|
|
43
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
|
+
};
|
|
63
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
64
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
65
|
+
if (ar || !(i in from)) {
|
|
66
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
67
|
+
ar[i] = from[i];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
71
|
+
};
|
|
44
72
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
73
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
74
|
};
|
|
47
75
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
76
|
+
exports.DropdownExpandIcon = exports.DropdownToggle = void 0;
|
|
77
|
+
var classnames_1 = __importDefault(require("classnames"));
|
|
48
78
|
var react_1 = __importStar(require("react"));
|
|
49
|
-
var
|
|
50
|
-
var
|
|
79
|
+
var FlatSVG_1 = __importDefault(require("./FlatSVG"));
|
|
80
|
+
var useElementRect_1 = __importDefault(require("./hooks/useElementRect"));
|
|
51
81
|
var List_1 = __importDefault(require("./List"));
|
|
82
|
+
var asClassNameDict_1 = __importDefault(require("./utils/asClassNameDict"));
|
|
83
|
+
var asComponentDict_1 = __importDefault(require("./utils/asComponentDict"));
|
|
84
|
+
var asStyleDict_1 = __importDefault(require("./utils/asStyleDict"));
|
|
85
|
+
var cloneStyledElement_1 = __importDefault(require("./utils/cloneStyledElement"));
|
|
86
|
+
var styles_1 = __importDefault(require("./utils/styles"));
|
|
52
87
|
/**
|
|
53
88
|
* A dropdown menu component that is invertible (i.e. can "dropup" instead) and
|
|
54
89
|
* supports both horizontal and vertical orientations. Provide data and item
|
|
55
90
|
* component type to this component to automatically generate menu items.
|
|
56
91
|
*/
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
_this.nodeRefs = {
|
|
64
|
-
root: (0, react_1.createRef)(),
|
|
65
|
-
};
|
|
66
|
-
/**
|
|
67
|
-
* Handler invoked when click input is detected outside of the root element
|
|
68
|
-
* of the component.
|
|
69
|
-
*
|
|
70
|
-
* @param event - The MouseEvent passed to the handler.
|
|
71
|
-
*/
|
|
72
|
-
_this.onClickOutside = function (event) {
|
|
73
|
-
if (_this.state.isCollapsed)
|
|
74
|
-
return;
|
|
75
|
-
if (!(event.target instanceof Node))
|
|
76
|
-
return;
|
|
77
|
-
var isOutside = true;
|
|
78
|
-
var node = event.target;
|
|
79
|
-
while (node) {
|
|
80
|
-
if (node === _this.nodeRefs.root.current) {
|
|
81
|
-
isOutside = false;
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
if (!node.parentNode)
|
|
85
|
-
break;
|
|
86
|
-
node = node.parentNode;
|
|
87
|
-
}
|
|
88
|
-
if (!isOutside)
|
|
89
|
-
return;
|
|
90
|
-
_this.collapse();
|
|
91
|
-
};
|
|
92
|
-
_this.state = {
|
|
93
|
-
selectedItemIndex: (_a = _this.props.defaultSelectedItemIndex) !== null && _a !== void 0 ? _a : -1,
|
|
94
|
-
isCollapsed: true,
|
|
95
|
-
};
|
|
96
|
-
return _this;
|
|
97
|
-
}
|
|
98
|
-
Object.defineProperty(Dropdown.prototype, "rect", {
|
|
99
|
-
get: function () {
|
|
100
|
-
var _a;
|
|
101
|
-
return (_a = spase_1.Rect.from(this.nodeRefs.root.current)) !== null && _a !== void 0 ? _a : new spase_1.Rect();
|
|
102
|
-
},
|
|
103
|
-
enumerable: false,
|
|
104
|
-
configurable: true
|
|
105
|
-
});
|
|
106
|
-
Dropdown.prototype.componentDidMount = function () {
|
|
107
|
-
var _a, _b;
|
|
108
|
-
window.addEventListener('click', this.onClickOutside);
|
|
109
|
-
(_b = (_a = this.props).onIndexChange) === null || _b === void 0 ? void 0 : _b.call(_a, this.state.selectedItemIndex);
|
|
110
|
-
};
|
|
111
|
-
Dropdown.prototype.componentWillUnmount = function () {
|
|
112
|
-
window.removeEventListener('click', this.onClickOutside);
|
|
113
|
-
};
|
|
114
|
-
Dropdown.prototype.componentDidUpdate = function (prevProps, prevState) {
|
|
115
|
-
var _a, _b;
|
|
116
|
-
if (prevState.selectedItemIndex !== this.state.selectedItemIndex) {
|
|
117
|
-
(_b = (_a = this.props).onIndexChange) === null || _b === void 0 ? void 0 : _b.call(_a, this.state.selectedItemIndex);
|
|
118
|
-
}
|
|
119
|
-
if (prevProps.orientation !== this.props.orientation) {
|
|
120
|
-
this.forceUpdate();
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
Dropdown.prototype.render = function () {
|
|
124
|
-
var _this = this;
|
|
125
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
126
|
-
var borderColor = (_a = this.props.borderColor) !== null && _a !== void 0 ? _a : '#000';
|
|
127
|
-
var borderThickness = (_b = this.props.borderThickness) !== null && _b !== void 0 ? _b : 1;
|
|
128
|
-
var orientation = (_c = this.props.orientation) !== null && _c !== void 0 ? _c : 'vertical';
|
|
129
|
-
var itemLength = (_d = this.props.itemLength) !== null && _d !== void 0 ? _d : (orientation === 'vertical' ? this.rect.height : this.rect.width);
|
|
130
|
-
var maxVisibleItems = (_e = this.props.maxVisibleItems) !== null && _e !== void 0 ? _e : -1;
|
|
131
|
-
var isTogglable = (_f = this.props.isTogglable) !== null && _f !== void 0 ? _f : true;
|
|
132
|
-
var itemPadding = (_g = this.props.itemPadding) !== null && _g !== void 0 ? _g : 0;
|
|
133
|
-
var numItems = this.props.data.length;
|
|
134
|
-
var numVisibleItems = maxVisibleItems < 0 ? numItems : Math.min(numItems, maxVisibleItems);
|
|
135
|
-
var menuLength = (itemLength - borderThickness) * numVisibleItems + itemPadding * (numVisibleItems - 1) + borderThickness;
|
|
136
|
-
return (react_1.default.createElement(StyledRoot, { className: this.props.className, orientation: orientation, isInverted: (_h = this.props.isInverted) !== null && _h !== void 0 ? _h : false, ref: this.nodeRefs.root, style: (_j = this.props.style) !== null && _j !== void 0 ? _j : {} },
|
|
137
|
-
react_1.default.createElement(StyledToggle, { borderColor: borderColor, borderThickness: borderThickness, extendedCSS: (_k = this.props.buttonCSS) !== null && _k !== void 0 ? _k : (function () { return (0, styled_components_1.css)(templateObject_1 || (templateObject_1 = __makeTemplateObject([""], [""]))); }), isActive: !this.state.isCollapsed, onClick: function () { return _this.toggle(); } },
|
|
138
|
-
react_1.default.createElement("label", null, this.state.selectedItemIndex === -1 ? ((_l = this.props.defaultLabel) !== null && _l !== void 0 ? _l : 'Select') : this.props.data[this.state.selectedItemIndex].label),
|
|
139
|
-
this.props.expandIconSvg && react_1.default.createElement("span", { dangerouslySetInnerHTML: { __html: this.props.expandIconSvg } })),
|
|
140
|
-
react_1.default.createElement(StyledItemList, { borderColor: borderColor, borderThickness: borderThickness, data: this.props.data, defaultSelectedIndex: (_m = this.props.defaultSelectedItemIndex) !== null && _m !== void 0 ? _m : -1, isInverted: (_o = this.props.isInverted) !== null && _o !== void 0 ? _o : false, isTogglable: isTogglable, itemComponentType: this.props.itemComponentType, itemPadding: itemPadding, onDeselectAt: function (idx) { return _this.selectItemAt(-1); }, onSelectAt: function (idx) { return _this.selectItemAt(idx); }, orientation: orientation, shouldStaySelected: true, itemStyle: orientation === 'vertical' ? {
|
|
141
|
-
height: "".concat(itemLength, "px"),
|
|
142
|
-
} : {
|
|
143
|
-
width: "".concat(itemLength, "px"),
|
|
144
|
-
}, style: orientation === 'vertical' ? {
|
|
145
|
-
height: this.state.isCollapsed ? '0px' : "".concat(menuLength, "px"),
|
|
146
|
-
overflowY: (maxVisibleItems === -1) ? 'hidden' : (maxVisibleItems < numItems ? 'scroll' : 'hidden'),
|
|
147
|
-
} : {
|
|
148
|
-
width: this.state.isCollapsed ? '0px' : "".concat(menuLength, "px"),
|
|
149
|
-
overflowX: (maxVisibleItems === -1) ? 'hidden' : (maxVisibleItems < numItems ? 'scroll' : 'hidden'),
|
|
150
|
-
} })));
|
|
92
|
+
exports.default = (0, react_1.forwardRef)(function (_a, ref) {
|
|
93
|
+
var _b, _c, _d;
|
|
94
|
+
var children = _a.children, className = _a.className, style = _a.style, _e = _a.borderThickness, borderThickness = _e === void 0 ? 0 : _e, data = _a.data, _f = _a.defaultLabel, defaultLabel = _f === void 0 ? 'Select' : _f, expandIconSvg = _a.expandIconSvg, _g = _a.isInverted, isInverted = _g === void 0 ? false : _g, _h = _a.isTogglable, isTogglable = _h === void 0 ? false : _h, itemComponentType = _a.itemComponentType, externalItemLength = _a.itemLength, _j = _a.itemPadding, itemPadding = _j === void 0 ? 0 : _j, _k = _a.maxVisibleItems, maxVisibleItems = _k === void 0 ? -1 : _k, _l = _a.orientation, orientation = _l === void 0 ? 'vertical' : _l, _m = _a.selectedIndex, externalSelectedIndex = _m === void 0 ? -1 : _m, onIndexChange = _a.onIndexChange, props = __rest(_a, ["children", "className", "style", "borderThickness", "data", "defaultLabel", "expandIconSvg", "isInverted", "isTogglable", "itemComponentType", "itemLength", "itemPadding", "maxVisibleItems", "orientation", "selectedIndex", "onIndexChange"]);
|
|
95
|
+
var selectItemAt = function (index) {
|
|
96
|
+
setSelectedIndex(index);
|
|
97
|
+
setIsCollapsed(true);
|
|
151
98
|
};
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
*
|
|
155
|
-
* @param index - The index of the item.
|
|
156
|
-
*
|
|
157
|
-
* @returns `true` if the item at the specified index is selected, `false`
|
|
158
|
-
* otherwise.
|
|
159
|
-
*/
|
|
160
|
-
Dropdown.prototype.isItemSelectedAt = function (index) {
|
|
161
|
-
return (this.state.selectedItemIndex === index);
|
|
162
|
-
};
|
|
163
|
-
/**
|
|
164
|
-
* Selects the item at the specified index.
|
|
165
|
-
*
|
|
166
|
-
* @param index - The index of the item to select.
|
|
167
|
-
*/
|
|
168
|
-
Dropdown.prototype.selectItemAt = function (index) {
|
|
169
|
-
this.setState({
|
|
170
|
-
selectedItemIndex: index,
|
|
171
|
-
isCollapsed: true,
|
|
172
|
-
});
|
|
173
|
-
};
|
|
174
|
-
/**
|
|
175
|
-
* Expands the menu, revealing its items.
|
|
176
|
-
*/
|
|
177
|
-
Dropdown.prototype.expand = function () {
|
|
178
|
-
if (!this.state.isCollapsed)
|
|
99
|
+
var expand = function () {
|
|
100
|
+
if (!isCollapsed)
|
|
179
101
|
return;
|
|
180
|
-
|
|
102
|
+
setIsCollapsed(false);
|
|
181
103
|
};
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
*/
|
|
185
|
-
Dropdown.prototype.collapse = function () {
|
|
186
|
-
if (this.state.isCollapsed)
|
|
104
|
+
var collapse = function () {
|
|
105
|
+
if (isCollapsed)
|
|
187
106
|
return;
|
|
188
|
-
|
|
107
|
+
setIsCollapsed(true);
|
|
189
108
|
};
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
Dropdown.prototype.toggle = function () {
|
|
194
|
-
if (this.state.isCollapsed) {
|
|
195
|
-
this.expand();
|
|
109
|
+
var toggle = function () {
|
|
110
|
+
if (isCollapsed) {
|
|
111
|
+
expand();
|
|
196
112
|
}
|
|
197
113
|
else {
|
|
198
|
-
|
|
114
|
+
collapse();
|
|
199
115
|
}
|
|
200
116
|
};
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
var
|
|
207
|
-
var
|
|
117
|
+
var clickOutsideHandler = function (event) {
|
|
118
|
+
if (isCollapsed)
|
|
119
|
+
return;
|
|
120
|
+
if (!(event.target instanceof Node))
|
|
121
|
+
return;
|
|
122
|
+
var isOutside = true;
|
|
123
|
+
var node = event.target;
|
|
124
|
+
while (node) {
|
|
125
|
+
if (node === bodyRef.current) {
|
|
126
|
+
isOutside = false;
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
if (!node.parentNode)
|
|
130
|
+
break;
|
|
131
|
+
node = node.parentNode;
|
|
132
|
+
}
|
|
133
|
+
if (!isOutside)
|
|
134
|
+
return;
|
|
135
|
+
collapse();
|
|
136
|
+
};
|
|
137
|
+
var bodyRef = (0, react_1.useRef)(null);
|
|
138
|
+
var _o = __read((0, react_1.useState)(externalSelectedIndex), 2), selectedIndex = _o[0], setSelectedIndex = _o[1];
|
|
139
|
+
var _p = __read((0, react_1.useState)(true), 2), isCollapsed = _p[0], setIsCollapsed = _p[1];
|
|
140
|
+
var rect = (0, useElementRect_1.default)(bodyRef);
|
|
141
|
+
(0, react_1.useEffect)(function () {
|
|
142
|
+
window.addEventListener('click', clickOutsideHandler);
|
|
143
|
+
return function () {
|
|
144
|
+
window.removeEventListener('click', clickOutsideHandler);
|
|
145
|
+
};
|
|
146
|
+
}, [isCollapsed]);
|
|
147
|
+
(0, react_1.useEffect)(function () {
|
|
148
|
+
if (externalSelectedIndex === selectedIndex)
|
|
149
|
+
return;
|
|
150
|
+
setSelectedIndex(externalSelectedIndex);
|
|
151
|
+
}, [externalSelectedIndex]);
|
|
152
|
+
(0, react_1.useEffect)(function () {
|
|
153
|
+
onIndexChange === null || onIndexChange === void 0 ? void 0 : onIndexChange(selectedIndex);
|
|
154
|
+
}, [selectedIndex]);
|
|
155
|
+
var itemLength = externalItemLength !== null && externalItemLength !== void 0 ? externalItemLength : (orientation === 'vertical' ? rect.height : rect.width);
|
|
156
|
+
var numItems = data.length;
|
|
157
|
+
var numVisibleItems = maxVisibleItems < 0 ? numItems : Math.min(numItems, maxVisibleItems);
|
|
158
|
+
var menuLength = (itemLength - borderThickness) * numVisibleItems + itemPadding * (numVisibleItems - 1) + borderThickness;
|
|
159
|
+
var components = (0, asComponentDict_1.default)(children, {
|
|
160
|
+
toggle: exports.DropdownToggle,
|
|
161
|
+
expandIcon: exports.DropdownExpandIcon,
|
|
162
|
+
});
|
|
163
|
+
var fixedClassNames = (0, asClassNameDict_1.default)({
|
|
164
|
+
root: (0, classnames_1.default)(orientation, {
|
|
165
|
+
togglable: isTogglable,
|
|
166
|
+
collapsed: isCollapsed,
|
|
167
|
+
expanded: !isCollapsed,
|
|
168
|
+
}),
|
|
169
|
+
toggle: (0, classnames_1.default)(orientation, {
|
|
170
|
+
togglable: isTogglable,
|
|
171
|
+
collapsed: isCollapsed,
|
|
172
|
+
expanded: !isCollapsed,
|
|
173
|
+
}),
|
|
174
|
+
expandIcon: (0, classnames_1.default)(orientation, {
|
|
175
|
+
togglable: isTogglable,
|
|
176
|
+
collapsed: isCollapsed,
|
|
177
|
+
expanded: !isCollapsed,
|
|
178
|
+
}),
|
|
179
|
+
list: (0, classnames_1.default)({
|
|
180
|
+
togglable: isTogglable,
|
|
181
|
+
collapsed: isCollapsed,
|
|
182
|
+
expanded: !isCollapsed,
|
|
183
|
+
}),
|
|
184
|
+
});
|
|
185
|
+
var fixedStyles = (0, asStyleDict_1.default)({
|
|
186
|
+
root: __assign({ alignItems: 'center', display: 'flex', justifyContent: 'flex-start', overflow: 'visible' }, orientation === 'vertical' ? {
|
|
187
|
+
flexDirection: isInverted ? 'column-reverse' : 'column',
|
|
188
|
+
} : {
|
|
189
|
+
flexDirection: isInverted ? 'row-reverse' : 'row',
|
|
190
|
+
}),
|
|
191
|
+
body: {
|
|
192
|
+
height: '100%',
|
|
193
|
+
width: '100%',
|
|
194
|
+
},
|
|
195
|
+
toggle: {
|
|
196
|
+
borderWidth: "".concat(borderThickness, "px"),
|
|
197
|
+
height: '100%',
|
|
198
|
+
left: '0',
|
|
199
|
+
margin: '0',
|
|
200
|
+
outline: 'none',
|
|
201
|
+
position: 'absolute',
|
|
202
|
+
top: '0',
|
|
203
|
+
width: '100%',
|
|
204
|
+
zIndex: '1',
|
|
205
|
+
},
|
|
206
|
+
toggleLabel: {
|
|
207
|
+
fontFamily: 'inherit',
|
|
208
|
+
fontSize: 'inherit',
|
|
209
|
+
fontWeight: 'inherit',
|
|
210
|
+
letterSpacing: 'inherit',
|
|
211
|
+
lineHeight: 'inherit',
|
|
212
|
+
},
|
|
213
|
+
expandIcon: {},
|
|
214
|
+
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 ? {
|
|
215
|
+
marginBottom: "".concat(itemPadding - borderThickness, "px"),
|
|
216
|
+
bottom: '100%',
|
|
217
|
+
} : {
|
|
218
|
+
top: '100%',
|
|
219
|
+
marginTop: "".concat(itemPadding - borderThickness, "px"),
|
|
220
|
+
}) : __assign({ transition: 'width 100ms ease-out', width: isCollapsed ? '0px' : "".concat(menuLength, "px"), height: '100%', overflowX: maxVisibleItems === -1 ? 'hidden' : maxVisibleItems < numItems ? 'scroll' : 'hidden' }, isInverted ? {
|
|
221
|
+
marginRight: "".concat(itemPadding - borderThickness, "px"),
|
|
222
|
+
right: '100%',
|
|
223
|
+
} : {
|
|
224
|
+
left: '100%',
|
|
225
|
+
marginLeft: "".concat(itemPadding - borderThickness, "px"),
|
|
226
|
+
})),
|
|
227
|
+
});
|
|
228
|
+
var defaultStyles = (0, asStyleDict_1.default)({
|
|
229
|
+
toggle: {
|
|
230
|
+
alignItems: 'center',
|
|
231
|
+
background: '#fff',
|
|
232
|
+
boxSizing: 'border-box',
|
|
233
|
+
color: '#000',
|
|
234
|
+
display: 'flex',
|
|
235
|
+
flexDirection: 'row',
|
|
236
|
+
fontSize: '16px',
|
|
237
|
+
justifyContent: 'space-between',
|
|
238
|
+
margin: '0',
|
|
239
|
+
padding: '0 10px',
|
|
240
|
+
},
|
|
241
|
+
expandIcon: {
|
|
242
|
+
height: '15px',
|
|
243
|
+
margin: '0',
|
|
244
|
+
padding: '0',
|
|
245
|
+
width: '15px',
|
|
246
|
+
},
|
|
247
|
+
});
|
|
248
|
+
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) }),
|
|
249
|
+
react_1.default.createElement("div", { ref: bodyRef, style: (0, styles_1.default)(fixedStyles.body) },
|
|
250
|
+
cloneStyledElement_1.default.apply(void 0, __spreadArray([(_b = components.toggle) !== null && _b !== void 0 ? _b : react_1.default.createElement("button", { style: defaultStyles.toggle }), {
|
|
251
|
+
className: (0, classnames_1.default)(fixedClassNames.toggle),
|
|
252
|
+
style: (0, styles_1.default)(fixedStyles.toggle),
|
|
253
|
+
onClick: function () { return toggle(); },
|
|
254
|
+
}], [
|
|
255
|
+
react_1.default.createElement("label", { style: fixedStyles.toggleLabel, dangerouslySetInnerHTML: { __html: selectedIndex === -1 ? defaultLabel : (_c = data[selectedIndex].label) !== null && _c !== void 0 ? _c : '' } }),
|
|
256
|
+
(0, cloneStyledElement_1.default)((_d = components.expandIcon) !== null && _d !== void 0 ? _d : (expandIconSvg ? react_1.default.createElement(FlatSVG_1.default, { svg: expandIconSvg, style: defaultStyles.expandIcon }) : react_1.default.createElement(react_1.default.Fragment, null)), {
|
|
257
|
+
className: (0, classnames_1.default)(fixedClassNames.expandIcon),
|
|
258
|
+
style: (0, styles_1.default)(fixedStyles.expandIcon),
|
|
259
|
+
}),
|
|
260
|
+
], false)),
|
|
261
|
+
react_1.default.createElement(List_1.default, { className: fixedClassNames.list, style: (0, styles_1.default)(fixedStyles.list), borderThickness: borderThickness, data: data, isSelectable: true, isTogglable: false, itemComponentType: itemComponentType, itemLength: itemLength, itemPadding: itemPadding, orientation: orientation, selectedIndex: selectedIndex, onDeselectAt: function (idx) { return selectItemAt(-1); }, onSelectAt: function (idx) { return selectItemAt(idx); } }))));
|
|
262
|
+
});
|
|
263
|
+
var DropdownToggle = function (_a) {
|
|
264
|
+
var props = __rest(_a, []);
|
|
265
|
+
return react_1.default.createElement("button", __assign({}, props));
|
|
266
|
+
};
|
|
267
|
+
exports.DropdownToggle = DropdownToggle;
|
|
268
|
+
var DropdownExpandIcon = function (_a) {
|
|
269
|
+
var props = __rest(_a, []);
|
|
270
|
+
return react_1.default.createElement("div", __assign({}, props));
|
|
271
|
+
};
|
|
272
|
+
exports.DropdownExpandIcon = DropdownExpandIcon;
|
|
208
273
|
//# sourceMappingURL=Dropdown.js.map
|