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
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { CSSProperties, PureComponent } from 'react';
|
|
2
|
-
export interface Props {
|
|
3
|
-
/**
|
|
4
|
-
* Class attribute of the root element.
|
|
5
|
-
*/
|
|
6
|
-
className?: string;
|
|
7
|
-
/**
|
|
8
|
-
* Inline style attribute of the root element.
|
|
9
|
-
*/
|
|
10
|
-
style?: CSSProperties;
|
|
11
|
-
/**
|
|
12
|
-
* Indicates whether selections can be toggled. For example, in the case of
|
|
13
|
-
* a vertical list of selectable rows, being able to toggle a row means it
|
|
14
|
-
* gets deselected when selected again. Being unable to toggle the row means
|
|
15
|
-
* it does not get deselected when selected again.
|
|
16
|
-
*/
|
|
17
|
-
isTogglable?: boolean;
|
|
18
|
-
/**
|
|
19
|
-
* Indicates whether selections are retained. For example, in the case of
|
|
20
|
-
* a vertical list of clickable rows, being able to retain a selection means
|
|
21
|
-
* when the row is clicked, it becomes and stays selected. Being unable to
|
|
22
|
-
* retain a selection means when the row is clicked, it does not become
|
|
23
|
-
* selected. It is simply clicked and the subsequent event is dispatched.
|
|
24
|
-
*/
|
|
25
|
-
shouldStaySelected?: boolean;
|
|
26
|
-
/**
|
|
27
|
-
* The default selected index. Any value below 0 indicates that nothing is
|
|
28
|
-
* selected.
|
|
29
|
-
*/
|
|
30
|
-
defaultSelectedIndex?: number;
|
|
31
|
-
/**
|
|
32
|
-
* Handler invoked when an index is deselected.
|
|
33
|
-
*/
|
|
34
|
-
onDeselectAt?: (index: number) => void;
|
|
35
|
-
/**
|
|
36
|
-
* Handler invoked when an index is selected.
|
|
37
|
-
*/
|
|
38
|
-
onSelectAt?: (index: number) => void;
|
|
39
|
-
}
|
|
40
|
-
export interface State {
|
|
41
|
-
/**
|
|
42
|
-
* The current selected index. Any value less than 0 indicates that no index
|
|
43
|
-
* is selected.
|
|
44
|
-
*/
|
|
45
|
-
selectedIndex?: number;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* An abstract component that mimics and handles index selection in an abstract
|
|
49
|
-
* collection.
|
|
50
|
-
*/
|
|
51
|
-
export default class AbstractSelectableCollection<P extends Props = Props, S extends State = State> extends PureComponent<P, S> {
|
|
52
|
-
constructor(props: P);
|
|
53
|
-
componentDidMount(): void;
|
|
54
|
-
componentDidUpdate(prevProps: P, prevState: S): void;
|
|
55
|
-
render(): JSX.Element;
|
|
56
|
-
/**
|
|
57
|
-
* Checks if an index is out of range.
|
|
58
|
-
*
|
|
59
|
-
* @param index - The index to check.
|
|
60
|
-
*
|
|
61
|
-
* @returns `true` if the index is out of range, `false` otherwise.
|
|
62
|
-
*/
|
|
63
|
-
isIndexOutOfRange(index: number): boolean;
|
|
64
|
-
/**
|
|
65
|
-
* Checks if an index is selected.
|
|
66
|
-
*
|
|
67
|
-
* @param index - The index to check.
|
|
68
|
-
*
|
|
69
|
-
* @returns `true` if the index is selected, `false` otherwise.
|
|
70
|
-
*/
|
|
71
|
-
isSelectedAt(index: number): boolean;
|
|
72
|
-
/**
|
|
73
|
-
* Toggles an index, i.e. reverses its selected state.
|
|
74
|
-
*
|
|
75
|
-
* @param index - The index to toggle.
|
|
76
|
-
*/
|
|
77
|
-
toggleAt(index: number): void;
|
|
78
|
-
/**
|
|
79
|
-
* Selects an index.
|
|
80
|
-
*
|
|
81
|
-
* @param index - The index to select.
|
|
82
|
-
*/
|
|
83
|
-
selectAt(index: number): void;
|
|
84
|
-
/**
|
|
85
|
-
* Deselects an index if it is currently selected.
|
|
86
|
-
*
|
|
87
|
-
* @param index - The index to deselect.
|
|
88
|
-
*/
|
|
89
|
-
deselectAt(index: number): void;
|
|
90
|
-
/**
|
|
91
|
-
* Deselects the currently selected index.
|
|
92
|
-
*/
|
|
93
|
-
deselectCurrent(): void;
|
|
94
|
-
}
|
|
@@ -1,151 +0,0 @@
|
|
|
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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
-
if (k2 === undefined) k2 = k;
|
|
19
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
20
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
21
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
22
|
-
}
|
|
23
|
-
Object.defineProperty(o, k2, desc);
|
|
24
|
-
}) : (function(o, m, k, k2) {
|
|
25
|
-
if (k2 === undefined) k2 = k;
|
|
26
|
-
o[k2] = m[k];
|
|
27
|
-
}));
|
|
28
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
29
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
-
}) : function(o, v) {
|
|
31
|
-
o["default"] = v;
|
|
32
|
-
});
|
|
33
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
34
|
-
if (mod && mod.__esModule) return mod;
|
|
35
|
-
var result = {};
|
|
36
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
37
|
-
__setModuleDefault(result, mod);
|
|
38
|
-
return result;
|
|
39
|
-
};
|
|
40
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
-
var react_1 = __importStar(require("react"));
|
|
42
|
-
var debug = process.env.NODE_ENV === 'development' ? require('debug')('etudes:asc') : function () { };
|
|
43
|
-
/**
|
|
44
|
-
* An abstract component that mimics and handles index selection in an abstract
|
|
45
|
-
* collection.
|
|
46
|
-
*/
|
|
47
|
-
var AbstractSelectableCollection = /** @class */ (function (_super) {
|
|
48
|
-
__extends(AbstractSelectableCollection, _super);
|
|
49
|
-
function AbstractSelectableCollection(props) {
|
|
50
|
-
var _this = this;
|
|
51
|
-
var _a;
|
|
52
|
-
_this = _super.call(this, props) || this;
|
|
53
|
-
_this.state = {
|
|
54
|
-
selectedIndex: (_a = _this.props.defaultSelectedIndex) !== null && _a !== void 0 ? _a : -1,
|
|
55
|
-
};
|
|
56
|
-
return _this;
|
|
57
|
-
}
|
|
58
|
-
AbstractSelectableCollection.prototype.componentDidMount = function () {
|
|
59
|
-
var _a, _b, _c;
|
|
60
|
-
if (this.state.selectedIndex !== undefined && this.state.selectedIndex > -1) {
|
|
61
|
-
(_b = (_a = this.props).onSelectAt) === null || _b === void 0 ? void 0 : _b.call(_a, (_c = this.state.selectedIndex) !== null && _c !== void 0 ? _c : -1);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
AbstractSelectableCollection.prototype.componentDidUpdate = function (prevProps, prevState) {
|
|
65
|
-
var _a, _b;
|
|
66
|
-
var _c = this.props, shouldStaySelected = _c.shouldStaySelected, onSelectAt = _c.onSelectAt, onDeselectAt = _c.onDeselectAt;
|
|
67
|
-
var prevSelectedIndex = (_a = prevState.selectedIndex) !== null && _a !== void 0 ? _a : -1;
|
|
68
|
-
var selectedIndex = (_b = this.state.selectedIndex) !== null && _b !== void 0 ? _b : -1;
|
|
69
|
-
if (prevState.selectedIndex !== selectedIndex) {
|
|
70
|
-
debug("Selected index changed: ".concat(selectedIndex));
|
|
71
|
-
if (shouldStaySelected === true) {
|
|
72
|
-
if (!this.isIndexOutOfRange(prevSelectedIndex))
|
|
73
|
-
onDeselectAt === null || onDeselectAt === void 0 ? void 0 : onDeselectAt(prevSelectedIndex);
|
|
74
|
-
if (!this.isIndexOutOfRange(selectedIndex))
|
|
75
|
-
onSelectAt === null || onSelectAt === void 0 ? void 0 : onSelectAt(selectedIndex);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
AbstractSelectableCollection.prototype.render = function () {
|
|
80
|
-
return react_1.default.createElement(react_1.Fragment, null);
|
|
81
|
-
};
|
|
82
|
-
/**
|
|
83
|
-
* Checks if an index is out of range.
|
|
84
|
-
*
|
|
85
|
-
* @param index - The index to check.
|
|
86
|
-
*
|
|
87
|
-
* @returns `true` if the index is out of range, `false` otherwise.
|
|
88
|
-
*/
|
|
89
|
-
AbstractSelectableCollection.prototype.isIndexOutOfRange = function (index) {
|
|
90
|
-
if (index < 0)
|
|
91
|
-
return true;
|
|
92
|
-
return false;
|
|
93
|
-
};
|
|
94
|
-
/**
|
|
95
|
-
* Checks if an index is selected.
|
|
96
|
-
*
|
|
97
|
-
* @param index - The index to check.
|
|
98
|
-
*
|
|
99
|
-
* @returns `true` if the index is selected, `false` otherwise.
|
|
100
|
-
*/
|
|
101
|
-
AbstractSelectableCollection.prototype.isSelectedAt = function (index) {
|
|
102
|
-
return (this.state.selectedIndex === index);
|
|
103
|
-
};
|
|
104
|
-
/**
|
|
105
|
-
* Toggles an index, i.e. reverses its selected state.
|
|
106
|
-
*
|
|
107
|
-
* @param index - The index to toggle.
|
|
108
|
-
*/
|
|
109
|
-
AbstractSelectableCollection.prototype.toggleAt = function (index) {
|
|
110
|
-
if (this.props.isTogglable === true && this.isSelectedAt(index)) {
|
|
111
|
-
this.deselectAt(index);
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
this.selectAt(index);
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
/**
|
|
118
|
-
* Selects an index.
|
|
119
|
-
*
|
|
120
|
-
* @param index - The index to select.
|
|
121
|
-
*/
|
|
122
|
-
AbstractSelectableCollection.prototype.selectAt = function (index) {
|
|
123
|
-
if (this.props.shouldStaySelected === true) {
|
|
124
|
-
if (this.isSelectedAt(index))
|
|
125
|
-
return;
|
|
126
|
-
this.setState({ selectedIndex: index });
|
|
127
|
-
}
|
|
128
|
-
else if (this.props.onSelectAt) {
|
|
129
|
-
this.props.onSelectAt(index);
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
/**
|
|
133
|
-
* Deselects an index if it is currently selected.
|
|
134
|
-
*
|
|
135
|
-
* @param index - The index to deselect.
|
|
136
|
-
*/
|
|
137
|
-
AbstractSelectableCollection.prototype.deselectAt = function (index) {
|
|
138
|
-
if (!this.isSelectedAt(index))
|
|
139
|
-
return;
|
|
140
|
-
this.setState({ selectedIndex: -1 });
|
|
141
|
-
};
|
|
142
|
-
/**
|
|
143
|
-
* Deselects the currently selected index.
|
|
144
|
-
*/
|
|
145
|
-
AbstractSelectableCollection.prototype.deselectCurrent = function () {
|
|
146
|
-
this.setState({ selectedIndex: -1 });
|
|
147
|
-
};
|
|
148
|
-
return AbstractSelectableCollection;
|
|
149
|
-
}(react_1.PureComponent));
|
|
150
|
-
exports.default = AbstractSelectableCollection;
|
|
151
|
-
//# sourceMappingURL=AbstractSelectableCollection.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AbstractSelectableCollection.js","sourceRoot":"/","sources":["AbstractSelectableCollection.tsx"],"names":[],"mappings":"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","sourcesContent":["import React, { CSSProperties, Fragment, PureComponent } from 'react'\n\nconst debug = process.env.NODE_ENV === 'development' ? require('debug')('etudes:asc') : () => {}\n\nexport interface Props {\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 * Indicates whether selections can be toggled. For example, in the case of\n * a vertical list of selectable rows, being able to toggle a row means it\n * gets deselected when selected again. Being unable to toggle the row means\n * it does not get deselected when selected again.\n */\n isTogglable?: boolean\n\n /**\n * Indicates whether selections are retained. For example, in the case of\n * a 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 shouldStaySelected?: boolean\n\n /**\n * The default selected index. Any value below 0 indicates that nothing is\n * selected.\n */\n defaultSelectedIndex?: number\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\nexport interface State {\n /**\n * The current selected index. Any value less than 0 indicates that no index\n * is selected.\n */\n selectedIndex?: number\n}\n\n/**\n * An abstract component that mimics and handles index selection in an abstract\n * collection.\n */\nexport default class AbstractSelectableCollection<P extends Props = Props, S extends State = State> extends PureComponent<P, S> {\n constructor(props: P) {\n super(props)\n\n this.state = {\n selectedIndex: this.props.defaultSelectedIndex ?? -1,\n } as any\n }\n\n componentDidMount() {\n if (this.state.selectedIndex !== undefined && this.state.selectedIndex > -1) {\n this.props.onSelectAt?.(this.state.selectedIndex ?? -1)\n }\n }\n\n componentDidUpdate(prevProps: P, prevState: S) {\n const { shouldStaySelected, onSelectAt, onDeselectAt } = this.props\n const prevSelectedIndex = prevState.selectedIndex ?? -1\n const selectedIndex = this.state.selectedIndex ?? -1\n\n if (prevState.selectedIndex !== selectedIndex) {\n debug(`Selected index changed: ${selectedIndex}`)\n\n if (shouldStaySelected === true) {\n if (!this.isIndexOutOfRange(prevSelectedIndex)) onDeselectAt?.(prevSelectedIndex)\n if (!this.isIndexOutOfRange(selectedIndex)) onSelectAt?.(selectedIndex)\n }\n }\n }\n\n render() {\n return <Fragment/>\n }\n\n /**\n * Checks if an index is out of range.\n *\n * @param index - The index to check.\n *\n * @returns `true` if the index is out of range, `false` otherwise.\n */\n isIndexOutOfRange(index: number): boolean {\n if (index < 0) return true\n return false\n }\n\n /**\n * Checks if an index is selected.\n *\n * @param index - The index to check.\n *\n * @returns `true` if the index is selected, `false` otherwise.\n */\n isSelectedAt(index: number): boolean {\n return (this.state.selectedIndex === index)\n }\n\n /**\n * Toggles an index, i.e. reverses its selected state.\n *\n * @param index - The index to toggle.\n */\n toggleAt(index: number) {\n if (this.props.isTogglable === true && this.isSelectedAt(index)) {\n this.deselectAt(index)\n }\n else {\n this.selectAt(index)\n }\n }\n\n /**\n * Selects an index.\n *\n * @param index - The index to select.\n */\n selectAt(index: number) {\n if (this.props.shouldStaySelected === true) {\n if (this.isSelectedAt(index)) return\n this.setState({ selectedIndex: index })\n }\n else if (this.props.onSelectAt) {\n this.props.onSelectAt(index)\n }\n }\n\n /**\n * Deselects an index if it is currently selected.\n *\n * @param index - The index to deselect.\n */\n deselectAt(index: number) {\n if (!this.isSelectedAt(index)) return\n this.setState({ selectedIndex: -1 })\n }\n\n /**\n * Deselects the currently selected index.\n */\n deselectCurrent() {\n this.setState({ selectedIndex: -1 })\n }\n}\n"]}
|
package/lib/types/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { FlattenSimpleInterpolation } from 'styled-components';
|
|
2
|
-
export declare type ExtendedCSSFunction<P = Record<string, never>> = (props: P) => FlattenSimpleInterpolation;
|
|
3
|
-
export declare type ExtendedCSSProps<P = Record<string, never>> = Readonly<{
|
|
4
|
-
extendedCSS: ExtendedCSSFunction<P>;
|
|
5
|
-
}>;
|
|
6
|
-
export declare type Range = Readonly<[number, number]>;
|
|
7
|
-
export declare type Orientation = 'horizontal' | 'vertical';
|
package/lib/types/index.js
DELETED
package/lib/types/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["types/index.ts"],"names":[],"mappings":"","sourcesContent":["import { FlattenSimpleInterpolation } from 'styled-components'\n\nexport type ExtendedCSSFunction<P = Record<string, never>> = (props: P) => FlattenSimpleInterpolation\n\nexport type ExtendedCSSProps<P = Record<string, never>> = Readonly<{ extendedCSS: ExtendedCSSFunction<P> }>\n\nexport type Range = Readonly<[number, number]>\n\nexport type Orientation = 'horizontal' | 'vertical'\n"]}
|