etudes 1.1.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 (121) 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 +5 -4
  21. package/lib/Each.js +5 -5
  22. package/lib/Each.js.map +1 -1
  23. package/lib/ExtractChild.d.ts +5 -4
  24. package/lib/ExtractChild.js +13 -11
  25. package/lib/ExtractChild.js.map +1 -1
  26. package/lib/ExtractChildren.d.ts +2 -2
  27. package/lib/ExtractChildren.js +7 -5
  28. package/lib/ExtractChildren.js.map +1 -1
  29. package/lib/FlatSVG.d.ts +30 -25
  30. package/lib/FlatSVG.js +28 -37
  31. package/lib/FlatSVG.js.map +1 -1
  32. package/lib/List.d.ts +97 -54
  33. package/lib/List.js +124 -63
  34. package/lib/List.js.map +1 -1
  35. package/lib/MasonryGrid.d.ts +27 -15
  36. package/lib/MasonryGrid.js +163 -148
  37. package/lib/MasonryGrid.js.map +1 -1
  38. package/lib/Panorama.d.ts +100 -21
  39. package/lib/Panorama.js +45 -44
  40. package/lib/Panorama.js.map +1 -1
  41. package/lib/PanoramaSlider.d.ts +65 -23
  42. package/lib/PanoramaSlider.js +150 -45
  43. package/lib/PanoramaSlider.js.map +1 -1
  44. package/lib/RangeSlider.d.ts +29 -89
  45. package/lib/RangeSlider.js +272 -286
  46. package/lib/RangeSlider.js.map +1 -1
  47. package/lib/Repeat.d.ts +6 -4
  48. package/lib/Repeat.js +4 -3
  49. package/lib/Repeat.js.map +1 -1
  50. package/lib/RotatingGallery.d.ts +38 -36
  51. package/lib/RotatingGallery.js +47 -17
  52. package/lib/RotatingGallery.js.map +1 -1
  53. package/lib/SelectableButton.d.ts +13 -4
  54. package/lib/SelectableButton.js +3 -14
  55. package/lib/SelectableButton.js.map +1 -1
  56. package/lib/Slider.d.ts +103 -41
  57. package/lib/Slider.js +182 -82
  58. package/lib/Slider.js.map +1 -1
  59. package/lib/StepwiseSlider.d.ts +146 -59
  60. package/lib/StepwiseSlider.js +248 -142
  61. package/lib/StepwiseSlider.js.map +1 -1
  62. package/lib/SwipeContainer.d.ts +13 -5
  63. package/lib/SwipeContainer.js +5 -15
  64. package/lib/SwipeContainer.js.map +1 -1
  65. package/lib/TextField.d.ts +1 -1
  66. package/lib/TextField.js +5 -15
  67. package/lib/TextField.js.map +1 -1
  68. package/lib/Video.d.ts +30 -51
  69. package/lib/Video.js +77 -119
  70. package/lib/Video.js.map +1 -1
  71. package/lib/WithTooltip.d.ts +16 -18
  72. package/lib/WithTooltip.js +167 -101
  73. package/lib/WithTooltip.js.map +1 -1
  74. package/lib/hooks/useDocumentTitle.d.ts +2 -1
  75. package/lib/hooks/useDocumentTitle.js +2 -1
  76. package/lib/hooks/useDocumentTitle.js.map +1 -1
  77. package/lib/hooks/useDragEffect.d.ts +25 -16
  78. package/lib/hooks/useDragEffect.js +30 -20
  79. package/lib/hooks/useDragEffect.js.map +1 -1
  80. package/lib/hooks/useElementRect.d.ts +2 -1
  81. package/lib/hooks/useElementRect.js +5 -4
  82. package/lib/hooks/useElementRect.js.map +1 -1
  83. package/lib/hooks/useInterval.d.ts +2 -2
  84. package/lib/hooks/useInterval.js +1 -1
  85. package/lib/hooks/useInterval.js.map +1 -1
  86. package/lib/hooks/useLoadImageEffect.d.ts +6 -6
  87. package/lib/hooks/useLoadImageEffect.js.map +1 -1
  88. package/lib/hooks/usePrevious.d.ts +6 -0
  89. package/lib/hooks/usePrevious.js +17 -0
  90. package/lib/hooks/usePrevious.js.map +1 -0
  91. package/lib/hooks/useResizeEffect.d.ts +2 -2
  92. package/lib/hooks/useResizeEffect.js +5 -8
  93. package/lib/hooks/useResizeEffect.js.map +1 -1
  94. package/lib/hooks/useSearchParamState.d.ts +10 -7
  95. package/lib/hooks/useSearchParamState.js +14 -10
  96. package/lib/hooks/useSearchParamState.js.map +1 -1
  97. package/lib/utils/asClassNameDict.d.ts +3 -0
  98. package/lib/utils/asClassNameDict.js +7 -0
  99. package/lib/utils/asClassNameDict.js.map +1 -0
  100. package/lib/utils/asComponentDict.d.ts +5 -0
  101. package/lib/utils/asComponentDict.js +23 -0
  102. package/lib/utils/asComponentDict.js.map +1 -0
  103. package/lib/utils/asStyleDict.d.ts +4 -0
  104. package/lib/utils/asStyleDict.js +7 -0
  105. package/lib/utils/asStyleDict.js.map +1 -0
  106. package/lib/utils/cloneStyledElement.d.ts +18 -0
  107. package/lib/utils/cloneStyledElement.js +63 -0
  108. package/lib/utils/cloneStyledElement.js.map +1 -0
  109. package/lib/utils/styles.d.ts +2 -0
  110. package/lib/utils/styles.js +22 -0
  111. package/lib/utils/styles.js.map +1 -0
  112. package/lib/utils/useDebug.d.ts +2 -0
  113. package/lib/utils/useDebug.js +46 -0
  114. package/lib/utils/useDebug.js.map +1 -0
  115. package/package.json +25 -33
  116. package/lib/AbstractSelectableCollection.d.ts +0 -94
  117. package/lib/AbstractSelectableCollection.js +0 -151
  118. package/lib/AbstractSelectableCollection.js.map +0 -1
  119. package/lib/types/index.d.ts +0 -7
  120. package/lib/types/index.js +0 -3
  121. package/lib/types/index.js.map +0 -1
package/README.md CHANGED
@@ -1,3 +1,3 @@
1
1
  # Études [![npm](https://img.shields.io/npm/v/etudes.svg)](https://www.npmjs.com/package/etudes) [![CI](https://github.com/andrewscwei/etudes/workflows/CI/badge.svg)](https://github.com/andrewscwei/etudes/actions?query=workflow%3ACI) [![CD](https://github.com/andrewscwei/etudes/workflows/CD/badge.svg)](https://github.com/andrewscwei/etudes/actions?query=workflow%3ACD)
2
2
 
3
- A study of styled React components.
3
+ A study of headless React components.
@@ -1,38 +1,16 @@
1
- import React, { ComponentType, CSSProperties, PureComponent } from 'react';
2
- import List, { ItemComponentProps as ListItemComponentProps } from './List';
3
- import { ExtendedCSSFunction, Orientation } from './types';
4
- /**
5
- * Interface defining the props of the item component type to be provided to the
6
- * component. The data type is generic.
7
- */
8
- export declare type ItemComponentProps<T = Record<string, never>> = ListItemComponentProps<T>;
9
- export declare type SectionHeaderCSSProps = Readonly<{
10
- borderColor: string;
11
- borderThickness: number;
12
- isCollapsed: boolean;
13
- orientation: Orientation;
14
- }>;
15
- export declare type SectionCSSProps = Readonly<{
16
- isCollapsed: boolean;
17
- orientation: Orientation;
18
- }>;
19
- export interface SectionProps<T = Record<string, never>> {
1
+ import React, { ComponentType, HTMLAttributes, PropsWithChildren, ReactElement, Ref } from 'react';
2
+ import { ListItemProps } from './List';
3
+ declare type Orientation = 'horizontal' | 'vertical';
4
+ export declare type AccordionItemProps<T> = ListItemProps<T>;
5
+ export declare type SectionData<T> = {
20
6
  label: string;
21
7
  items: T[];
22
- }
23
- export interface Props<T = Record<string, never>> {
24
- /**
25
- * Class attribute to the root element.
26
- */
27
- className?: string;
28
- /**
29
- * Inline style attribute to the element.
30
- */
31
- style?: CSSProperties;
8
+ };
9
+ export declare type AccordionProps<T> = HTMLAttributes<HTMLDivElement> & PropsWithChildren<{
32
10
  /**
33
11
  * Data provided to each section.
34
12
  */
35
- data: SectionProps<T>[];
13
+ data: SectionData<T>[];
36
14
  /**
37
15
  * Indicates if sections can be toggled, as in, once a section is expanded,
38
16
  * it collapses when being selected again.
@@ -42,7 +20,7 @@ export interface Props<T = Record<string, never>> {
42
20
  * Index of the section that is selected by default. Any value less than 0
43
21
  * indicates that no section is selected by default.
44
22
  */
45
- defaultSelectedSectionIndex?: number;
23
+ defaultExpandedSectionIndex?: number;
46
24
  /**
47
25
  * Length (in pixels) of each item. This does not apply to the section hedaer
48
26
  * itself. Length refers to the height in vertical orientation and width in
@@ -69,10 +47,6 @@ export interface Props<T = Record<string, never>> {
69
47
  * Orientation of the component.
70
48
  */
71
49
  orientation?: Orientation;
72
- /**
73
- * Color of the border of every item and the section header itself.
74
- */
75
- borderColor?: string;
76
50
  /**
77
51
  * Thickness of the border (in pixels) of every item and the section header
78
52
  * itself. 0 indicates no borders.
@@ -85,7 +59,7 @@ export interface Props<T = Record<string, never>> {
85
59
  /**
86
60
  * React component type to be used for generating items inside the component.
87
61
  */
88
- itemComponentType: ComponentType<ItemComponentProps<T>>;
62
+ itemComponentType: ComponentType<AccordionItemProps<T>>;
89
63
  /**
90
64
  * Handler invoked when the selected item index of any section changes.
91
65
  */
@@ -94,39 +68,74 @@ export interface Props<T = Record<string, never>> {
94
68
  * Handler invoked when the selected section index changes.
95
69
  */
96
70
  onSectionIndexChange?: (index: number) => void;
71
+ }>;
72
+ declare const _default: <T>(props: React.HTMLAttributes<HTMLDivElement> & {
73
+ /**
74
+ * Data provided to each section.
75
+ */
76
+ data: SectionData<T>[];
77
+ /**
78
+ * Indicates if sections can be toggled, as in, once a section is expanded,
79
+ * it collapses when being selected again.
80
+ */
81
+ isTogglable?: boolean | undefined;
82
+ /**
83
+ * Index of the section that is selected by default. Any value less than 0
84
+ * indicates that no section is selected by default.
85
+ */
86
+ defaultExpandedSectionIndex?: number | undefined;
87
+ /**
88
+ * Length (in pixels) of each item. This does not apply to the section hedaer
89
+ * itself. Length refers to the height in vertical orientation and width in
90
+ * horizontal orientation.
91
+ */
92
+ itemLength?: number | undefined;
93
+ /**
94
+ * Padding (in pixels) between each item.
95
+ */
96
+ itemPadding?: number | undefined;
97
97
  /**
98
- * Additional CSS to be provided to each section element.
99
- */
100
- sectionCSS?: ExtendedCSSFunction<SectionCSSProps>;
101
- /**
102
- * Additional CSS to be provided to each section header element.
103
- */
104
- sectionHeaderCSS?: ExtendedCSSFunction<SectionHeaderCSSProps>;
105
- }
106
- export interface State {
107
- /**
108
- * Current selected section index.
109
- */
110
- selectedSectionIndex: number;
111
- /**
112
- * Current selected item index of the expanded section.
113
- */
114
- selectedItemIndex: number;
115
- }
116
- export default class Accordion<T = Record<string, never>> extends PureComponent<Props<T>, State> {
117
- nodeRefs: {
118
- lists: React.RefObject<List<T>>[];
119
- };
120
- constructor(props: Props<T>);
121
- componentDidMount(): void;
122
- componentDidUpdate(prevProps: Props<T>, prevState: State): void;
123
- render(): JSX.Element;
124
- private isSectionSelectedAt;
125
- private toggleSectionAt;
126
- private selectSectionAt;
127
- private deselectSectionAt;
128
- private isItemSelectedAt;
129
- private toggleItemAt;
130
- private selectItemAt;
131
- private deselectItemAt;
132
- }
98
+ * Padding (in pixels) between each section.
99
+ */
100
+ sectionPadding?: number | undefined;
101
+ /**
102
+ * Maximum number of items that are viside when a section expands. When a
103
+ * value greater than or equal to 0 is specified, only that number of items
104
+ * will be visible at a time, and a scrollbar will appear to scroll to
105
+ * remaining items. Any value less than 0 indicates that all items will be
106
+ * visible when a section expands.
107
+ */
108
+ maxVisibleItems?: number | undefined;
109
+ /**
110
+ * Orientation of the component.
111
+ */
112
+ orientation?: Orientation | undefined;
113
+ /**
114
+ * Thickness of the border (in pixels) of every item and the section header
115
+ * itself. 0 indicates no borders.
116
+ */
117
+ borderThickness?: number | undefined;
118
+ /**
119
+ * SVG markup to be put in the section header as the expand icon.
120
+ */
121
+ expandIconSvg?: string | undefined;
122
+ /**
123
+ * React component type to be used for generating items inside the component.
124
+ */
125
+ itemComponentType: React.ComponentType<AccordionItemProps<T>>;
126
+ /**
127
+ * Handler invoked when the selected item index of any section changes.
128
+ */
129
+ onItemIndexChange?: ((index: number) => void) | undefined;
130
+ /**
131
+ * Handler invoked when the selected section index changes.
132
+ */
133
+ onSectionIndexChange?: ((index: number) => void) | undefined;
134
+ } & {
135
+ children?: React.ReactNode;
136
+ } & {
137
+ ref?: React.Ref<HTMLDivElement> | undefined;
138
+ }) => ReactElement;
139
+ export default _default;
140
+ export declare const AccordionHeader: ({ ...props }: HTMLAttributes<HTMLButtonElement>) => JSX.Element;
141
+ export declare const AccordionExpandIcon: ({ ...props }: HTMLAttributes<HTMLDivElement>) => JSX.Element;
package/lib/Accordion.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,191 +33,200 @@ var __importStar = (this && this.__importStar) || function (mod) {
52
33
  __setModuleDefault(result, mod);
53
34
  return result;
54
35
  };
55
- var __values = (this && this.__values) || function(o) {
56
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
57
- if (m) return m.call(o);
58
- if (o && typeof o.length === "number") return {
59
- next: function () {
60
- if (o && i >= o.length) o = void 0;
61
- return { value: o && o[i++], done: !o };
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]];
62
44
  }
63
- };
64
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
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));
65
71
  };
66
72
  var __importDefault = (this && this.__importDefault) || function (mod) {
67
73
  return (mod && mod.__esModule) ? mod : { "default": mod };
68
74
  };
69
75
  Object.defineProperty(exports, "__esModule", { value: true });
76
+ exports.AccordionExpandIcon = exports.AccordionHeader = void 0;
77
+ var classnames_1 = __importDefault(require("classnames"));
70
78
  var react_1 = __importStar(require("react"));
71
- var styled_components_1 = __importStar(require("styled-components"));
79
+ var Each_1 = __importDefault(require("./Each"));
80
+ var FlatSVG_1 = __importDefault(require("./FlatSVG"));
72
81
  var List_1 = __importDefault(require("./List"));
73
- var debug = process.env.NODE_ENV === 'development' ? require('debug')('etudes:accordion') : function () { };
74
- var Accordion = /** @class */ (function (_super) {
75
- __extends(Accordion, _super);
76
- function Accordion(props) {
77
- var _this = this;
78
- var _a;
79
- _this = _super.call(this, props) || this;
80
- _this.nodeRefs = {
81
- lists: [],
82
- };
83
- _this.state = {
84
- selectedSectionIndex: (_a = props.defaultSelectedSectionIndex) !== null && _a !== void 0 ? _a : -1,
85
- selectedItemIndex: -1,
86
- };
87
- return _this;
88
- }
89
- Accordion.prototype.componentDidMount = function () {
90
- var _a, _b, _c, _d;
91
- (_b = (_a = this.props).onSectionIndexChange) === null || _b === void 0 ? void 0 : _b.call(_a, this.state.selectedSectionIndex);
92
- (_d = (_c = this.props).onItemIndexChange) === null || _d === void 0 ? void 0 : _d.call(_c, this.state.selectedItemIndex);
93
- };
94
- Accordion.prototype.componentDidUpdate = function (prevProps, prevState) {
95
- var _a, _b, _c, _d;
96
- if (prevState.selectedSectionIndex !== this.state.selectedSectionIndex) {
97
- debug("Changing section index to ".concat(this.state.selectedSectionIndex, "... OK"));
98
- (_b = (_a = this.props).onSectionIndexChange) === null || _b === void 0 ? void 0 : _b.call(_a, this.state.selectedSectionIndex);
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"));
87
+ exports.default = (0, react_1.forwardRef)(function (_a, ref) {
88
+ var children = _a.children, className = _a.className, style = _a.style, _b = _a.borderThickness, borderThickness = _b === void 0 ? 0 : _b, data = _a.data, _c = _a.defaultExpandedSectionIndex, defaultExpandedSectionIndex = _c === void 0 ? -1 : _c, expandIconSvg = _a.expandIconSvg, _d = _a.isTogglable, isTogglable = _d === void 0 ? true : _d, itemComponentType = _a.itemComponentType, _e = _a.itemLength, itemLength = _e === void 0 ? 50 : _e, _f = _a.itemPadding, itemPadding = _f === void 0 ? 0 : _f, _g = _a.maxVisibleItems, maxVisibleItems = _g === void 0 ? -1 : _g, _h = _a.orientation, orientation = _h === void 0 ? 'vertical' : _h, _j = _a.sectionPadding, sectionPadding = _j === void 0 ? 0 : _j, onItemIndexChange = _a.onItemIndexChange, onSectionIndexChange = _a.onSectionIndexChange, props = __rest(_a, ["children", "className", "style", "borderThickness", "data", "defaultExpandedSectionIndex", "expandIconSvg", "isTogglable", "itemComponentType", "itemLength", "itemPadding", "maxVisibleItems", "orientation", "sectionPadding", "onItemIndexChange", "onSectionIndexChange"]);
89
+ var isSectionSelectedAt = function (index) { return expandedSectionIndex === index; };
90
+ var toggleSectionAt = function (index) {
91
+ if (isTogglable && isSectionSelectedAt(index)) {
92
+ setExpandedSectionIndex(-1);
99
93
  }
100
- if (prevState.selectedItemIndex !== this.state.selectedItemIndex) {
101
- debug("Changing item index to ".concat(this.state.selectedItemIndex, "... OK"));
102
- (_d = (_c = this.props).onItemIndexChange) === null || _d === void 0 ? void 0 : _d.call(_c, this.state.selectedItemIndex);
94
+ else {
95
+ setExpandedSectionIndex(index);
103
96
  }
104
97
  };
105
- Accordion.prototype.render = function () {
106
- var _this = this;
107
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
108
- var borderColor = (_a = this.props.borderColor) !== null && _a !== void 0 ? _a : '#000';
109
- var borderThickness = (_b = this.props.borderThickness) !== null && _b !== void 0 ? _b : 0;
110
- var isTogglable = (_c = this.props.isTogglable) !== null && _c !== void 0 ? _c : true;
111
- var itemLength = (_d = this.props.itemLength) !== null && _d !== void 0 ? _d : 50;
112
- var itemPadding = (_e = this.props.itemPadding) !== null && _e !== void 0 ? _e : 0;
113
- var sectionPadding = (_f = this.props.sectionPadding) !== null && _f !== void 0 ? _f : 0;
114
- var maxVisibleItems = (_g = this.props.maxVisibleItems) !== null && _g !== void 0 ? _g : -1;
115
- var orientation = (_h = this.props.orientation) !== null && _h !== void 0 ? _h : 'vertical';
116
- this.nodeRefs.lists = [];
117
- return (react_1.default.createElement(StyledRoot, { className: this.props.className, orientation: orientation, style: __assign(__assign({}, (_j = this.props.style) !== null && _j !== void 0 ? _j : {}), (orientation === 'vertical' ? {
118
- height: 'auto',
119
- } : {
120
- width: 'auto',
121
- })) }, this.props.data.map(function (section, i) {
98
+ var _k = __read((0, react_1.useState)(defaultExpandedSectionIndex), 2), expandedSectionIndex = _k[0], setExpandedSectionIndex = _k[1];
99
+ var _l = __read((0, react_1.useState)(-1), 2), selectedSectionIndex = _l[0], setSelectedSectionIndex = _l[1];
100
+ var _m = __read((0, react_1.useState)(-1), 2), selectedItemIndex = _m[0], setSelectedItemIndex = _m[1];
101
+ (0, react_1.useEffect)(function () {
102
+ onSectionIndexChange === null || onSectionIndexChange === void 0 ? void 0 : onSectionIndexChange(expandedSectionIndex);
103
+ }, [expandedSectionIndex]);
104
+ (0, react_1.useEffect)(function () {
105
+ onItemIndexChange === null || onItemIndexChange === void 0 ? void 0 : onItemIndexChange(selectedItemIndex);
106
+ }, [selectedItemIndex]);
107
+ var components = (0, asComponentDict_1.default)(children, {
108
+ header: exports.AccordionHeader,
109
+ expandIcon: exports.AccordionExpandIcon,
110
+ });
111
+ var fixedClassNames = (0, asClassNameDict_1.default)({
112
+ root: (0, classnames_1.default)(orientation),
113
+ header: (0, classnames_1.default)(orientation),
114
+ expandIcon: (0, classnames_1.default)(orientation),
115
+ });
116
+ var fixedStyles = (0, asStyleDict_1.default)({
117
+ root: __assign({ alignItems: 'center', boxSizing: 'border-box', display: 'flex', flex: '0 0 auto', justifyContent: 'flex-start', padding: '0' }, orientation === 'vertical' ? {
118
+ flexDirection: 'column',
119
+ height: 'auto',
120
+ } : {
121
+ flexDirection: 'row',
122
+ width: 'auto',
123
+ }),
124
+ section: __assign({ alignItems: 'flex-start', display: 'flex', flex: '0 0 auto', justifyContent: 'flex-start', margin: '0', padding: '0' }, orientation === 'vertical' ? {
125
+ flexDirection: 'column',
126
+ width: '100%',
127
+ } : {
128
+ flexDirection: 'row',
129
+ height: '100%',
130
+ }),
131
+ header: __assign({ borderWidth: "".concat(borderThickness, "px"), margin: '0', outline: 'none' }, orientation === 'vertical' ? {
132
+ width: '100%',
133
+ } : {
134
+ height: '100%',
135
+ }),
136
+ headerLabel: {
137
+ color: 'inherit',
138
+ fontFamily: 'inherit',
139
+ fontSize: 'inherit',
140
+ fontWeight: 'inherit',
141
+ letterSpacing: 'inherit',
142
+ lineHeight: 'inherit',
143
+ transition: 'inherit',
144
+ },
145
+ expandIcon: {
146
+ margin: '0',
147
+ padding: '0',
148
+ },
149
+ list: __assign({ transitionDuration: '100ms', transitionTimingFunction: 'ease-out' }, orientation === 'vertical' ? {
150
+ width: '100%',
151
+ transitionProperty: 'height, margin',
152
+ top: '100%',
153
+ } : {
154
+ height: '100%',
155
+ transitionProperty: 'width, margin',
156
+ left: '100%',
157
+ }),
158
+ });
159
+ var defaultStyles = (0, asStyleDict_1.default)({
160
+ header: __assign({ alignItems: 'center', background: '#fff', borderStyle: 'solid', boxSizing: 'border-box', display: 'flex', flexDirection: 'row', justifyContent: 'space-between', padding: '0 10px', transitionDuration: '100ms', transitionProperty: 'transform, opacity, background, color', transitionTimingFunction: 'ease-out' }, orientation === 'vertical' ? {
161
+ height: '50px',
162
+ } : {
163
+ width: '50px',
164
+ }),
165
+ expandIcon: {
166
+ boxSizing: 'border-box',
167
+ display: 'block',
168
+ fill: '#000',
169
+ height: '15px',
170
+ transformOrigin: 'center',
171
+ transitionDuration: '100ms',
172
+ transitionProperty: 'transform',
173
+ transitionTimingFunction: 'ease-out',
174
+ width: '15px',
175
+ },
176
+ });
177
+ return (react_1.default.createElement("div", __assign({}, props, { className: (0, classnames_1.default)(className, fixedClassNames.root), style: (0, styles_1.default)(style, fixedStyles.root) }),
178
+ react_1.default.createElement(Each_1.default, { in: data }, function (section, sectionIdx) {
122
179
  var _a, _b;
123
180
  var numItems = section.items.length;
124
181
  var numVisibleItems = maxVisibleItems < 0 ? numItems : Math.min(numItems, maxVisibleItems);
125
182
  var menuLength = (itemLength - borderThickness) * numVisibleItems + itemPadding * (numVisibleItems - 1) + borderThickness;
126
- var isCollapsed = !_this.isSectionSelectedAt(i);
127
- var ref = (0, react_1.createRef)();
128
- _this.nodeRefs.lists.push(ref);
129
- return (react_1.default.createElement(StyledSection, { key: "section-".concat(i), isCollapsed: isCollapsed, orientation: orientation, extendedCSS: (_a = _this.props.sectionCSS) !== null && _a !== void 0 ? _a : (function () { return (0, styled_components_1.css)(templateObject_1 || (templateObject_1 = __makeTemplateObject([""], [""]))); }), style: orientation === 'vertical' ? {
130
- marginTop: i === 0 ? '0px' : "".concat(sectionPadding - borderThickness, "px"),
183
+ var isCollapsed = !isSectionSelectedAt(sectionIdx);
184
+ return (react_1.default.createElement("div", { style: (0, styles_1.default)(fixedStyles.section, orientation === 'vertical' ? {
185
+ marginTop: sectionIdx === 0 ? '0px' : "".concat(sectionPadding - borderThickness, "px"),
131
186
  } : {
132
- marginLeft: i === 0 ? '0px' : "".concat(sectionPadding - borderThickness, "px"),
133
- } },
134
- react_1.default.createElement(StyledSectionHeader, { borderColor: borderColor, borderThickness: borderThickness, orientation: orientation, isCollapsed: isCollapsed, onClick: function () { return _this.toggleSectionAt(i); }, extendedCSS: (_b = _this.props.sectionHeaderCSS) !== null && _b !== void 0 ? _b : (function () { return (0, styled_components_1.css)(templateObject_2 || (templateObject_2 = __makeTemplateObject([""], [""]))); }) },
135
- react_1.default.createElement("label", null, section.label),
136
- _this.props.expandIconSvg && react_1.default.createElement("span", { dangerouslySetInnerHTML: { __html: _this.props.expandIconSvg } })),
137
- react_1.default.createElement(StyledItemList, { ref: ref, borderColor: borderColor, borderThickness: borderThickness, data: section.items, defaultSelectedIndex: -1, isTogglable: isTogglable, itemComponentType: _this.props.itemComponentType, itemPadding: itemPadding, onDeselectAt: function (idx) { return _this.deselectItemAt(idx); }, onSelectAt: function (idx) { return _this.selectItemAt(idx); }, orientation: orientation, shouldStaySelected: true, itemStyle: orientation === 'vertical' ? {
138
- height: "".concat(itemLength, "px"),
139
- } : {
140
- width: "".concat(itemLength, "px"),
141
- }, style: orientation === 'vertical' ? {
187
+ marginLeft: sectionIdx === 0 ? '0px' : "".concat(sectionPadding - borderThickness, "px"),
188
+ }) },
189
+ cloneStyledElement_1.default.apply(void 0, __spreadArray([(_a = components.header) !== null && _a !== void 0 ? _a : react_1.default.createElement(exports.AccordionHeader, { style: defaultStyles.header }), {
190
+ className: (0, classnames_1.default)(fixedClassNames.header, {
191
+ collapsed: isCollapsed,
192
+ expanded: !isCollapsed,
193
+ }),
194
+ style: (0, styles_1.default)(fixedStyles.header),
195
+ onClick: function () { return toggleSectionAt(sectionIdx); },
196
+ }], [
197
+ react_1.default.createElement("label", { style: fixedStyles.headerLabel, dangerouslySetInnerHTML: { __html: section.label } }),
198
+ (0, cloneStyledElement_1.default)((_b = components.expandIcon) !== null && _b !== void 0 ? _b : (expandIconSvg ? react_1.default.createElement(FlatSVG_1.default, { svg: expandIconSvg, style: defaultStyles.expandIcon }) : react_1.default.createElement(react_1.default.Fragment, null)), {
199
+ className: (0, classnames_1.default)(fixedClassNames.expandIcon),
200
+ style: (0, styles_1.default)(fixedStyles.expandIcon),
201
+ }),
202
+ ], false)),
203
+ react_1.default.createElement(List_1.default, { style: (0, styles_1.default)(fixedStyles.list, orientation === 'vertical' ? {
142
204
  height: isCollapsed ? '0px' : "".concat(menuLength, "px"),
143
205
  marginTop: isCollapsed ? '0px' : "".concat(itemPadding - borderThickness, "px"),
144
- overflowY: (maxVisibleItems === -1) ? 'hidden' : (maxVisibleItems < numItems ? 'scroll' : 'hidden'),
206
+ overflowY: maxVisibleItems === -1 ? 'hidden' : maxVisibleItems < numItems ? 'scroll' : 'hidden',
145
207
  } : {
146
208
  marginLeft: isCollapsed ? '0px' : "".concat(itemPadding - borderThickness, "px"),
147
- overflowX: (maxVisibleItems === -1) ? 'hidden' : (maxVisibleItems < numItems ? 'scroll' : 'hidden'),
209
+ overflowX: maxVisibleItems === -1 ? 'hidden' : maxVisibleItems < numItems ? 'scroll' : 'hidden',
148
210
  width: isCollapsed ? '0px' : "".concat(menuLength, "px"),
211
+ }), borderThickness: borderThickness, data: section.items, isSelectable: true, isTogglable: isTogglable, itemComponentType: itemComponentType, itemLength: itemLength, itemPadding: itemPadding, orientation: orientation, selectedIndex: selectedSectionIndex === sectionIdx ? selectedItemIndex : -1, onDeselectAt: function () {
212
+ if (selectedSectionIndex !== sectionIdx)
213
+ return;
214
+ setSelectedSectionIndex(-1);
215
+ setSelectedItemIndex(-1);
216
+ }, onSelectAt: function (itemIdx) {
217
+ setSelectedSectionIndex(sectionIdx);
218
+ setSelectedItemIndex(itemIdx);
149
219
  } })));
150
220
  })));
151
- };
152
- Accordion.prototype.isSectionSelectedAt = function (index) {
153
- return this.state.selectedSectionIndex === index;
154
- };
155
- Accordion.prototype.toggleSectionAt = function (index) {
156
- var _a;
157
- if (((_a = this.props.isTogglable) !== null && _a !== void 0 ? _a : true) && this.isSectionSelectedAt(index)) {
158
- this.deselectSectionAt(index);
159
- }
160
- else {
161
- this.selectSectionAt(index);
162
- }
163
- };
164
- Accordion.prototype.selectSectionAt = function (index) {
165
- var e_1, _a;
166
- var _b;
167
- if (this.isSectionSelectedAt(index))
168
- return;
169
- try {
170
- for (var _c = __values(this.nodeRefs.lists), _d = _c.next(); !_d.done; _d = _c.next()) {
171
- var ref = _d.value;
172
- (_b = ref.current) === null || _b === void 0 ? void 0 : _b.setState({ selectedIndex: -1 });
173
- }
174
- }
175
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
176
- finally {
177
- try {
178
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
179
- }
180
- finally { if (e_1) throw e_1.error; }
181
- }
182
- this.setState({
183
- selectedSectionIndex: index,
184
- });
185
- };
186
- Accordion.prototype.deselectSectionAt = function (index) {
187
- var e_2, _a;
188
- var _b;
189
- if (!this.isSectionSelectedAt(index))
190
- return;
191
- try {
192
- for (var _c = __values(this.nodeRefs.lists), _d = _c.next(); !_d.done; _d = _c.next()) {
193
- var ref = _d.value;
194
- (_b = ref.current) === null || _b === void 0 ? void 0 : _b.setState({ selectedIndex: -1 });
195
- }
196
- }
197
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
198
- finally {
199
- try {
200
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
201
- }
202
- finally { if (e_2) throw e_2.error; }
203
- }
204
- this.setState({
205
- selectedSectionIndex: -1,
206
- });
207
- };
208
- Accordion.prototype.isItemSelectedAt = function (index) {
209
- return (this.state.selectedItemIndex === index);
210
- };
211
- Accordion.prototype.toggleItemAt = function (index) {
212
- var _a;
213
- if (((_a = this.props.isTogglable) !== null && _a !== void 0 ? _a : true) && this.isItemSelectedAt(index)) {
214
- this.deselectItemAt(index);
215
- }
216
- else {
217
- this.selectItemAt(index);
218
- }
219
- };
220
- Accordion.prototype.selectItemAt = function (index) {
221
- if (this.isItemSelectedAt(index))
222
- return;
223
- this.setState({
224
- selectedItemIndex: index,
225
- });
226
- };
227
- Accordion.prototype.deselectItemAt = function (index) {
228
- if (!this.isItemSelectedAt(index))
229
- return;
230
- this.setState({
231
- selectedItemIndex: -1,
232
- });
233
- };
234
- return Accordion;
235
- }(react_1.PureComponent));
236
- exports.default = Accordion;
237
- var StyledItemList = (0, styled_components_1.default)(List_1.default)(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n transition-duration: 100ms;\n transition-timing-function: ease-out;\n\n ", "\n"], ["\n transition-duration: 100ms;\n transition-timing-function: ease-out;\n\n ", "\n"])), function (props) { return props.orientation === 'vertical' ? (0, styled_components_1.css)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n width: 100%;\n transition-property: height, margin;\n will-change: height, margin;\n top: 100%;\n "], ["\n width: 100%;\n transition-property: height, margin;\n will-change: height, margin;\n top: 100%;\n "]))) : (0, styled_components_1.css)(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n height: 100%;\n transition-property: width, margin;\n will-change: width, margin;\n left: 100%;\n "], ["\n height: 100%;\n transition-property: width, margin;\n will-change: width, margin;\n left: 100%;\n "]))); });
238
- var StyledSectionHeader = styled_components_1.default.button(templateObject_8 || (templateObject_8 = __makeTemplateObject(["\n align-items: center;\n background: #fff;\n border-color: ", ";\n border-style: solid;\n border-width: ", ";\n box-sizing: border-box;\n display: flex;\n flex-direction: row;\n justify-content: space-between;\n margin: 0;\n padding: 0 10px;\n transition-duration: 100ms;\n transition-property: transform, opacity, background, color;\n transition-timing-function: ease-out;\n will-change: transform, opacity, background, color;\n\n label {\n color: #000;\n transition-duration: 100ms;\n transition-property: color;\n transition-timing-function: ease-out;\n will-change: color;\n }\n\n span {\n box-sizing: border-box;\n display: block;\n fill: #000;\n height: 15px;\n transform-origin: center;\n transition-duration: 100ms;\n transition-property: transform;\n transition-timing-function: ease-out;\n width: 15px;\n will-change: transform;\n\n svg {\n width: 100%;\n height: 100%;\n fill: inherit;\n\n * {\n fill: inherit;\n transition-duration: 100ms;\n transition-property: fill;\n transition-timing-function: ease-out;\n }\n }\n }\n\n ", "\n\n ", "\n"], ["\n align-items: center;\n background: #fff;\n border-color: ", ";\n border-style: solid;\n border-width: ", ";\n box-sizing: border-box;\n display: flex;\n flex-direction: row;\n justify-content: space-between;\n margin: 0;\n padding: 0 10px;\n transition-duration: 100ms;\n transition-property: transform, opacity, background, color;\n transition-timing-function: ease-out;\n will-change: transform, opacity, background, color;\n\n label {\n color: #000;\n transition-duration: 100ms;\n transition-property: color;\n transition-timing-function: ease-out;\n will-change: color;\n }\n\n span {\n box-sizing: border-box;\n display: block;\n fill: #000;\n height: 15px;\n transform-origin: center;\n transition-duration: 100ms;\n transition-property: transform;\n transition-timing-function: ease-out;\n width: 15px;\n will-change: transform;\n\n svg {\n width: 100%;\n height: 100%;\n fill: inherit;\n\n * {\n fill: inherit;\n transition-duration: 100ms;\n transition-property: fill;\n transition-timing-function: ease-out;\n }\n }\n }\n\n ", "\n\n ", "\n"])), function (props) { return props.borderColor; }, function (props) { return props.borderThickness; }, function (props) { return props.orientation === 'vertical' ? (0, styled_components_1.css)(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n height: 50px;\n width: 100%;\n "], ["\n height: 50px;\n width: 100%;\n "]))) : (0, styled_components_1.css)(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n height: 100%;\n width: 50px;\n "], ["\n height: 100%;\n width: 50px;\n "]))); }, function (props) { return props.extendedCSS(props); });
239
- var StyledSection = styled_components_1.default.section(templateObject_11 || (templateObject_11 = __makeTemplateObject(["\n align-items: flex-start;\n box-sizing: border-box;\n display: flex;\n flex: 0 0 auto;\n justify-content: flex-start;\n margin: 0;\n padding: 0;\n position: relative;\n\n ", "\n\n ", "\n"], ["\n align-items: flex-start;\n box-sizing: border-box;\n display: flex;\n flex: 0 0 auto;\n justify-content: flex-start;\n margin: 0;\n padding: 0;\n position: relative;\n\n ", "\n\n ", "\n"])), function (props) { return props.orientation === 'vertical' ? (0, styled_components_1.css)(templateObject_9 || (templateObject_9 = __makeTemplateObject(["\n width: 100%;\n flex-direction: column;\n "], ["\n width: 100%;\n flex-direction: column;\n "]))) : (0, styled_components_1.css)(templateObject_10 || (templateObject_10 = __makeTemplateObject(["\n height: 100%;\n flex-direction: row;\n "], ["\n height: 100%;\n flex-direction: row;\n "]))); }, function (props) { return props.extendedCSS(props); });
240
- var StyledRoot = styled_components_1.default.div(templateObject_14 || (templateObject_14 = __makeTemplateObject(["\n align-items: center;\n box-sizing: border-box;\n display: flex;\n flex: 0 0 auto;\n justify-content: flex-start;\n padding: 0;\n position: relative;\n\n ", "\n"], ["\n align-items: center;\n box-sizing: border-box;\n display: flex;\n flex: 0 0 auto;\n justify-content: flex-start;\n padding: 0;\n position: relative;\n\n ", "\n"])), function (props) { return props.orientation === 'vertical' ? (0, styled_components_1.css)(templateObject_12 || (templateObject_12 = __makeTemplateObject(["\n flex-direction: column;\n "], ["\n flex-direction: column;\n "]))) : (0, styled_components_1.css)(templateObject_13 || (templateObject_13 = __makeTemplateObject(["\n flex-direction: row;\n "], ["\n flex-direction: row;\n "]))); });
241
- var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9, templateObject_10, templateObject_11, templateObject_12, templateObject_13, templateObject_14;
221
+ });
222
+ var AccordionHeader = function (_a) {
223
+ var props = __rest(_a, []);
224
+ return react_1.default.createElement("button", __assign({}, props));
225
+ };
226
+ exports.AccordionHeader = AccordionHeader;
227
+ var AccordionExpandIcon = function (_a) {
228
+ var props = __rest(_a, []);
229
+ return react_1.default.createElement("div", __assign({}, props));
230
+ };
231
+ exports.AccordionExpandIcon = AccordionExpandIcon;
242
232
  //# sourceMappingURL=Accordion.js.map