@elliemae/ds-accordion 2.1.0-rc.6 → 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/cjs/DSAccordion.js +14 -99
- package/cjs/DSAccordionCTX.js +20 -0
- package/cjs/DSAccordionDatatestid.js +14 -0
- package/cjs/DSAccordionTypes.js +2 -0
- package/cjs/config/useAccordion.js +50 -0
- package/cjs/config/useAccordionRefs.js +40 -0
- package/cjs/defaultProps.js +54 -0
- package/cjs/index.js +1 -1
- package/cjs/{DSAccordionHeaderActions.js → parts/accordionContent/AccordionContent.js} +24 -38
- package/cjs/parts/accordionItem/DSAccordionItem.js +206 -0
- package/cjs/parts/accordionItem/styles.js +133 -0
- package/cjs/parts/accordionItem/useAccordionItem.js +53 -0
- package/cjs/parts/accordionItem/useIsShowingEllipsis.js +37 -0
- package/cjs/propTypes.js +26 -0
- package/esm/DSAccordion.js +16 -98
- package/esm/DSAccordionCTX.js +16 -0
- package/esm/DSAccordionDatatestid.js +10 -0
- package/esm/DSAccordionTypes.js +1 -0
- package/esm/config/useAccordion.js +46 -0
- package/esm/config/useAccordionRefs.js +32 -0
- package/esm/defaultProps.js +45 -0
- package/esm/index.js +1 -1
- package/esm/{DSAccordionHeaderActions.js → parts/accordionContent/AccordionContent.js} +21 -35
- package/esm/parts/accordionItem/DSAccordionItem.js +193 -0
- package/esm/parts/accordionItem/styles.js +117 -0
- package/esm/parts/accordionItem/useAccordionItem.js +49 -0
- package/esm/parts/accordionItem/useIsShowingEllipsis.js +33 -0
- package/esm/propTypes.js +21 -0
- package/package.json +50 -22
- package/types/DSAccordion.d.ts +5 -35
- package/types/DSAccordionCTX.d.ts +3 -0
- package/types/DSAccordionDatatestid.d.ts +8 -0
- package/types/DSAccordionTypes.d.ts +134 -0
- package/types/config/useAccordion.d.ts +2 -0
- package/types/config/useAccordionRefs.d.ts +2 -0
- package/types/defaultProps.d.ts +3 -0
- package/types/index.d.ts +2 -1
- package/types/parts/accordionContent/AccordionContent.d.ts +2 -0
- package/types/parts/accordionItem/DSAccordionItem.d.ts +53 -0
- package/types/parts/accordionItem/styles.d.ts +10 -0
- package/types/parts/accordionItem/useAccordionItem.d.ts +2 -0
- package/types/parts/accordionItem/useIsShowingEllipsis.d.ts +5 -0
- package/types/propTypes.d.ts +73 -0
- package/cjs/DSAccordionHeader.js +0 -57
- package/cjs/DSAccordionHeaderTitle.js +0 -36
- package/cjs/DSAccordionItem.js +0 -174
- package/cjs/blocks.js +0 -23
- package/esm/DSAccordionHeader.js +0 -50
- package/esm/DSAccordionHeaderTitle.js +0 -29
- package/esm/DSAccordionItem.js +0 -162
- package/esm/blocks.js +0 -13
- package/types/DSAccordionHeader.d.ts +0 -9
- package/types/DSAccordionHeaderActions.d.ts +0 -5
- package/types/DSAccordionHeaderTitle.d.ts +0 -7
- package/types/DSAccordionItem.d.ts +0 -16
- package/types/blocks.d.ts +0 -7
package/cjs/DSAccordion.js
CHANGED
|
@@ -2,114 +2,29 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
require('core-js/modules/esnext.async-iterator.map.js');
|
|
8
|
-
require('core-js/modules/esnext.iterator.map.js');
|
|
9
|
-
require('core-js/modules/esnext.async-iterator.filter.js');
|
|
10
|
-
require('core-js/modules/esnext.iterator.constructor.js');
|
|
11
|
-
require('core-js/modules/esnext.iterator.filter.js');
|
|
12
|
-
require('core-js/modules/esnext.async-iterator.for-each.js');
|
|
13
|
-
require('core-js/modules/esnext.iterator.for-each.js');
|
|
14
|
-
var React = require('react');
|
|
5
|
+
var _jsx2 = require('@babel/runtime/helpers/jsx');
|
|
6
|
+
require('react');
|
|
15
7
|
var reactDesc = require('react-desc');
|
|
16
|
-
var
|
|
17
|
-
var
|
|
18
|
-
var
|
|
19
|
-
var
|
|
20
|
-
var jsxRuntime = require('react/jsx-runtime');
|
|
8
|
+
var AccordionContent = require('./parts/accordionContent/AccordionContent.js');
|
|
9
|
+
var useAccordion = require('./config/useAccordion.js');
|
|
10
|
+
var DSAccordionCTX = require('./DSAccordionCTX.js');
|
|
11
|
+
var propTypes = require('./propTypes.js');
|
|
21
12
|
|
|
22
13
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
23
14
|
|
|
24
|
-
var
|
|
25
|
-
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
26
|
-
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
27
|
-
var Group__default = /*#__PURE__*/_interopDefaultLegacy(Group);
|
|
15
|
+
var _jsx2__default = /*#__PURE__*/_interopDefaultLegacy(_jsx2);
|
|
28
16
|
|
|
29
|
-
|
|
17
|
+
var _AccordionContent;
|
|
30
18
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
activeValue = '',
|
|
37
|
-
children,
|
|
38
|
-
allowMultipleOpen = false,
|
|
39
|
-
contentExpandable = false,
|
|
40
|
-
onChange = () => {}
|
|
41
|
-
} = _ref;
|
|
42
|
-
const {
|
|
43
|
-
cssClassName
|
|
44
|
-
} = dsClassnames.convertPropToCssClassName('accordion');
|
|
45
|
-
const tabsRef = {};
|
|
46
|
-
|
|
47
|
-
const handleKeyPress = (index, e) => {
|
|
48
|
-
if (e.keyCode === 39 || e.keyCode === 40) {
|
|
49
|
-
const nextTab = tabsRef[index + 1];
|
|
50
|
-
if (!nextTab) return;
|
|
51
|
-
tabsRef[index + 1].focus();
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (e.keyCode === 37 || e.keyCode === 38) {
|
|
55
|
-
const nextTab = tabsRef[index - 1];
|
|
56
|
-
if (!nextTab) return;
|
|
57
|
-
tabsRef[index - 1].focus();
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
return /*#__PURE__*/_jsx__default["default"](DSTruncatedTooltipText.TooltipTextProvider, {}, void 0, /*#__PURE__*/_jsx__default["default"](Group__default["default"], {
|
|
62
|
-
activeValue: activeValue,
|
|
63
|
-
multiple: allowMultipleOpen,
|
|
64
|
-
onChange: onChange
|
|
65
|
-
}, void 0, /*#__PURE__*/jsxRuntime.jsx("section", _objectSpread(_objectSpread({
|
|
66
|
-
className: cssClassName
|
|
67
|
-
}, containerProps), {}, {
|
|
68
|
-
children: React__default["default"].Children.map(children, (child, idx) => /*#__PURE__*/React__default["default"].cloneElement(child, {
|
|
69
|
-
key: idx,
|
|
70
|
-
idx,
|
|
71
|
-
expandable: contentExpandable,
|
|
72
|
-
setTabRef: ref => {
|
|
73
|
-
tabsRef[idx] = ref;
|
|
74
|
-
},
|
|
75
|
-
handleKeyPress
|
|
76
|
-
}), null)
|
|
77
|
-
}))));
|
|
19
|
+
const DSAccordion = props => {
|
|
20
|
+
const ctx = useAccordion.useAccordion(props);
|
|
21
|
+
return /*#__PURE__*/_jsx2__default["default"](DSAccordionCTX.DSAccordionContext.Provider, {
|
|
22
|
+
value: ctx
|
|
23
|
+
}, void 0, _AccordionContent || (_AccordionContent = /*#__PURE__*/_jsx2__default["default"](AccordionContent.AccordionContent, {})));
|
|
78
24
|
};
|
|
79
25
|
|
|
80
|
-
const props = {
|
|
81
|
-
/** inject props to wrapper */
|
|
82
|
-
containerProps: reactDesc.PropTypes.object.description('inject props to wrapper'),
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Selected default active value
|
|
86
|
-
*/
|
|
87
|
-
activeValue: reactDesc.PropTypes.oneOfType([reactDesc.PropTypes.arrayOf(reactDesc.PropTypes.oneOfType([reactDesc.PropTypes.string, reactDesc.PropTypes.number])), reactDesc.PropTypes.string, reactDesc.PropTypes.number]).description('Selected default active value'),
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Accordion items to show
|
|
91
|
-
*/
|
|
92
|
-
children: reactDesc.PropTypes.arrayOf(reactDesc.PropTypes.shape({
|
|
93
|
-
type: reactDesc.PropTypes.instanceOf(DSAccordionItem.DSAccordionItem)
|
|
94
|
-
})).isRequired.description('Accordion items to show'),
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Allows multiple accordion items to be open at the same time
|
|
98
|
-
*/
|
|
99
|
-
allowMultipleOpen: reactDesc.PropTypes.bool.description('Allows multiple accordion items to be open at the same time'),
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Whether content is expandable or not
|
|
103
|
-
*/
|
|
104
|
-
contentExpandable: reactDesc.PropTypes.bool.description('Whether content is expandable or not'),
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Allows a function that is triggered once the accordion changes
|
|
108
|
-
*/
|
|
109
|
-
onChange: reactDesc.PropTypes.func.description('Allows a function that is triggered once the accordion changes')
|
|
110
|
-
};
|
|
111
26
|
const DSAccordionWithSchema = reactDesc.describe(DSAccordion);
|
|
112
|
-
DSAccordionWithSchema.propTypes =
|
|
27
|
+
DSAccordionWithSchema.propTypes = propTypes.accordionPropTypes;
|
|
113
28
|
|
|
114
29
|
exports.DSAccordion = DSAccordion;
|
|
115
30
|
exports.DSAccordionWithSchema = DSAccordionWithSchema;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var defaultProps = require('./defaultProps.js');
|
|
7
|
+
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
9
|
+
const noop = () => {};
|
|
10
|
+
|
|
11
|
+
const defaultContext = {
|
|
12
|
+
props: defaultProps.defaultProps,
|
|
13
|
+
actualActiveValue: [],
|
|
14
|
+
setActiveValues: noop,
|
|
15
|
+
focusableChildrenReferences: [],
|
|
16
|
+
allChildrenReferences: {}
|
|
17
|
+
};
|
|
18
|
+
const DSAccordionContext = /*#__PURE__*/React.createContext(defaultContext);
|
|
19
|
+
|
|
20
|
+
exports.DSAccordionContext = DSAccordionContext;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const DSAccordionDataTestid = {
|
|
6
|
+
ITEM: {
|
|
7
|
+
CONTENT: 'ds-accordion_item-content',
|
|
8
|
+
HEADER: 'ds-accordion_item-header',
|
|
9
|
+
CONTAINER: 'ds-accordion_item'
|
|
10
|
+
},
|
|
11
|
+
GROUP: 'ds-accordion_group'
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
exports.DSAccordionDataTestid = DSAccordionDataTestid;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
require('core-js/modules/web.dom-collections.iterator.js');
|
|
6
|
+
require('core-js/modules/esnext.async-iterator.some.js');
|
|
7
|
+
require('core-js/modules/esnext.iterator.constructor.js');
|
|
8
|
+
require('core-js/modules/esnext.iterator.some.js');
|
|
9
|
+
require('core-js/modules/esnext.async-iterator.filter.js');
|
|
10
|
+
require('core-js/modules/esnext.iterator.filter.js');
|
|
11
|
+
var React = require('react');
|
|
12
|
+
var dsPropsHelpers = require('@elliemae/ds-props-helpers');
|
|
13
|
+
var useAccordionRefs = require('./useAccordionRefs.js');
|
|
14
|
+
var defaultProps = require('../defaultProps.js');
|
|
15
|
+
|
|
16
|
+
const useAccordion = props => {
|
|
17
|
+
const propsWithDefaults = dsPropsHelpers.useMemoMergePropsWithDefault(props, defaultProps.defaultProps);
|
|
18
|
+
const {
|
|
19
|
+
activeValue,
|
|
20
|
+
allowMultipleOpen,
|
|
21
|
+
onChange
|
|
22
|
+
} = propsWithDefaults;
|
|
23
|
+
const {
|
|
24
|
+
focusableChildrenReferences,
|
|
25
|
+
allChildrenReferences
|
|
26
|
+
} = useAccordionRefs.useAccordionRefs(propsWithDefaults);
|
|
27
|
+
const [internalActiveValue, setInternalActiveValue] = React.useState(activeValue);
|
|
28
|
+
const actualActiveValue = React.useMemo(() => {
|
|
29
|
+
if (activeValue === undefined) return internalActiveValue;
|
|
30
|
+
return activeValue;
|
|
31
|
+
}, [activeValue, internalActiveValue]);
|
|
32
|
+
const setActiveValues = React.useCallback((value, e) => {
|
|
33
|
+
let newState;
|
|
34
|
+
if (allowMultipleOpen && (actualActiveValue === undefined || actualActiveValue === null)) newState = [value];else if (allowMultipleOpen && Array.isArray(actualActiveValue)) {
|
|
35
|
+
if (!actualActiveValue.some(currentValues => currentValues === value)) newState = [...actualActiveValue, value];else newState = actualActiveValue.filter(currentValues => currentValues !== value);
|
|
36
|
+
} else if (actualActiveValue === value) newState = null;else newState = value;
|
|
37
|
+
setInternalActiveValue(newState);
|
|
38
|
+
return onChange(newState, e);
|
|
39
|
+
}, [actualActiveValue, allowMultipleOpen, onChange]);
|
|
40
|
+
const ctx = React.useMemo(() => ({
|
|
41
|
+
props: propsWithDefaults,
|
|
42
|
+
actualActiveValue,
|
|
43
|
+
setActiveValues,
|
|
44
|
+
focusableChildrenReferences,
|
|
45
|
+
allChildrenReferences
|
|
46
|
+
}), [actualActiveValue, allChildrenReferences, focusableChildrenReferences, propsWithDefaults, setActiveValues]);
|
|
47
|
+
return ctx;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
exports.useAccordion = useAccordion;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
require('core-js/modules/esnext.async-iterator.map.js');
|
|
6
|
+
require('core-js/modules/esnext.iterator.map.js');
|
|
7
|
+
var React = require('react');
|
|
8
|
+
|
|
9
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
|
+
|
|
11
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
12
|
+
|
|
13
|
+
const useAccordionRefs = _ref => {
|
|
14
|
+
let {
|
|
15
|
+
children
|
|
16
|
+
} = _ref;
|
|
17
|
+
return React.useMemo(() => {
|
|
18
|
+
const focusableChildrenReferences = [];
|
|
19
|
+
const allChildrenReferences = {};
|
|
20
|
+
React__default["default"].Children.map(children, (child, index) => {
|
|
21
|
+
const {
|
|
22
|
+
value,
|
|
23
|
+
disabled
|
|
24
|
+
} = child.props;
|
|
25
|
+
const currentRef = /*#__PURE__*/React__default["default"].createRef();
|
|
26
|
+
allChildrenReferences[index] = currentRef;
|
|
27
|
+
if (!disabled) focusableChildrenReferences.push({
|
|
28
|
+
index,
|
|
29
|
+
value,
|
|
30
|
+
ref: currentRef
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
return {
|
|
34
|
+
focusableChildrenReferences,
|
|
35
|
+
allChildrenReferences
|
|
36
|
+
};
|
|
37
|
+
}, [children]);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
exports.useAccordionRefs = useAccordionRefs;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _jsx2 = require('@babel/runtime/helpers/jsx');
|
|
6
|
+
var React = require('react');
|
|
7
|
+
var dsIcons = require('@elliemae/ds-icons');
|
|
8
|
+
|
|
9
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
|
+
|
|
11
|
+
var _jsx2__default = /*#__PURE__*/_interopDefaultLegacy(_jsx2);
|
|
12
|
+
|
|
13
|
+
var _ChevronRight, _ArrowheadRight, _ChevronDown, _ArrowheadDown;
|
|
14
|
+
const DefaultIconClosed = /*#__PURE__*/React.memo(_ref => {
|
|
15
|
+
let {
|
|
16
|
+
isDSMobile = false
|
|
17
|
+
} = _ref;
|
|
18
|
+
return isDSMobile ? _ChevronRight || (_ChevronRight = /*#__PURE__*/_jsx2__default["default"](dsIcons.ChevronRight, {
|
|
19
|
+
width: "20px"
|
|
20
|
+
})) : _ArrowheadRight || (_ArrowheadRight = /*#__PURE__*/_jsx2__default["default"](dsIcons.ArrowheadRight, {
|
|
21
|
+
width: "20px"
|
|
22
|
+
}));
|
|
23
|
+
});
|
|
24
|
+
const DefaultIconOpen = /*#__PURE__*/React.memo(_ref2 => {
|
|
25
|
+
let {
|
|
26
|
+
isDSMobile = false
|
|
27
|
+
} = _ref2;
|
|
28
|
+
return isDSMobile ? _ChevronDown || (_ChevronDown = /*#__PURE__*/_jsx2__default["default"](dsIcons.ChevronDown, {
|
|
29
|
+
width: "20px"
|
|
30
|
+
})) : _ArrowheadDown || (_ArrowheadDown = /*#__PURE__*/_jsx2__default["default"](dsIcons.ArrowheadDown, {
|
|
31
|
+
width: "20px"
|
|
32
|
+
}));
|
|
33
|
+
}); // eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
34
|
+
|
|
35
|
+
const noop = () => {};
|
|
36
|
+
|
|
37
|
+
const defaultProps = {
|
|
38
|
+
containerProps: {},
|
|
39
|
+
allowMultipleOpen: false,
|
|
40
|
+
contentExpandable: false,
|
|
41
|
+
onChange: noop,
|
|
42
|
+
children: [],
|
|
43
|
+
isDSMobile: false
|
|
44
|
+
};
|
|
45
|
+
const accordionItemDefaultProps = {
|
|
46
|
+
iconClosed: DefaultIconClosed,
|
|
47
|
+
iconOpened: DefaultIconOpen,
|
|
48
|
+
title: '',
|
|
49
|
+
customActions: [],
|
|
50
|
+
disabled: false
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
exports.accordionItemDefaultProps = accordionItemDefaultProps;
|
|
54
|
+
exports.defaultProps = defaultProps;
|
package/cjs/index.js
CHANGED
|
@@ -1,55 +1,41 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
4
5
|
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
5
|
-
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
|
6
|
-
require('core-js/modules/esnext.async-iterator.map.js');
|
|
7
|
-
require('core-js/modules/esnext.iterator.map.js');
|
|
8
|
-
require('core-js/modules/esnext.async-iterator.filter.js');
|
|
9
|
-
require('core-js/modules/esnext.iterator.constructor.js');
|
|
10
|
-
require('core-js/modules/esnext.iterator.filter.js');
|
|
11
6
|
require('core-js/modules/esnext.async-iterator.for-each.js');
|
|
7
|
+
require('core-js/modules/esnext.iterator.constructor.js');
|
|
12
8
|
require('core-js/modules/esnext.iterator.for-each.js');
|
|
13
|
-
require('
|
|
14
|
-
|
|
15
|
-
var
|
|
9
|
+
require('core-js/modules/esnext.async-iterator.filter.js');
|
|
10
|
+
require('core-js/modules/esnext.iterator.filter.js');
|
|
11
|
+
var React = require('react');
|
|
12
|
+
var DSAccordionCTX = require('../../DSAccordionCTX.js');
|
|
13
|
+
var DSAccordionDatatestid = require('../../DSAccordionDatatestid.js');
|
|
16
14
|
var jsxRuntime = require('react/jsx-runtime');
|
|
17
15
|
|
|
18
16
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
19
17
|
|
|
20
|
-
var _jsx__default = /*#__PURE__*/_interopDefaultLegacy(_jsx);
|
|
21
18
|
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
22
|
-
var
|
|
23
|
-
var DSButton__default = /*#__PURE__*/_interopDefaultLegacy(DSButton);
|
|
24
|
-
|
|
25
|
-
const _excluded = ["onClick"];
|
|
19
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
26
20
|
|
|
27
21
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
28
22
|
|
|
29
23
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return /*#__PURE__*/jsxRuntime.jsx(DSButton__default["default"], _objectSpread(_objectSpread({
|
|
45
|
-
onClick: e => {
|
|
46
|
-
e.stopPropagation();
|
|
47
|
-
if (onClick) onClick(e);
|
|
48
|
-
}
|
|
49
|
-
}, rest), {}, {
|
|
50
|
-
buttonType: DSButton.BUTTON_TYPE.SECONDARY
|
|
51
|
-
}), key);
|
|
24
|
+
const AccordionContent = () => {
|
|
25
|
+
const {
|
|
26
|
+
props: {
|
|
27
|
+
containerProps,
|
|
28
|
+
children
|
|
29
|
+
}
|
|
30
|
+
} = React.useContext(DSAccordionCTX.DSAccordionContext);
|
|
31
|
+
const childrenWithIndex = [];
|
|
32
|
+
React__default["default"].Children.forEach(children, (child, index) => childrenWithIndex.push( /*#__PURE__*/React__default["default"].cloneElement(child, {
|
|
33
|
+
dsIndex: index
|
|
34
|
+
})));
|
|
35
|
+
return /*#__PURE__*/jsxRuntime.jsx("div", _objectSpread(_objectSpread({}, containerProps), {}, {
|
|
36
|
+
"data-testid": DSAccordionDatatestid.DSAccordionDataTestid.GROUP,
|
|
37
|
+
children: childrenWithIndex
|
|
52
38
|
}));
|
|
53
39
|
};
|
|
54
40
|
|
|
55
|
-
|
|
41
|
+
exports.AccordionContent = AccordionContent;
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _jsx2 = require('@babel/runtime/helpers/jsx');
|
|
6
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
7
|
+
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
|
8
|
+
require('core-js/modules/web.dom-collections.iterator.js');
|
|
9
|
+
require('core-js/modules/esnext.async-iterator.map.js');
|
|
10
|
+
require('core-js/modules/esnext.iterator.map.js');
|
|
11
|
+
require('core-js/modules/esnext.async-iterator.filter.js');
|
|
12
|
+
require('core-js/modules/esnext.iterator.constructor.js');
|
|
13
|
+
require('core-js/modules/esnext.iterator.filter.js');
|
|
14
|
+
require('core-js/modules/esnext.async-iterator.for-each.js');
|
|
15
|
+
require('core-js/modules/esnext.iterator.for-each.js');
|
|
16
|
+
var React = require('react');
|
|
17
|
+
var reactDesc = require('react-desc');
|
|
18
|
+
var dsPropsHelpers = require('@elliemae/ds-props-helpers');
|
|
19
|
+
var DSButton = require('@elliemae/ds-button');
|
|
20
|
+
var dsPopperjs = require('@elliemae/ds-popperjs');
|
|
21
|
+
var defaultProps = require('../../defaultProps.js');
|
|
22
|
+
var styles = require('./styles.js');
|
|
23
|
+
var propTypes = require('../../propTypes.js');
|
|
24
|
+
var useAccordionItem = require('./useAccordionItem.js');
|
|
25
|
+
var DSAccordionCTX = require('../../DSAccordionCTX.js');
|
|
26
|
+
var DSAccordionDatatestid = require('../../DSAccordionDatatestid.js');
|
|
27
|
+
var useIsShowingEllipsis = require('./useIsShowingEllipsis.js');
|
|
28
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
29
|
+
|
|
30
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
31
|
+
|
|
32
|
+
var _jsx2__default = /*#__PURE__*/_interopDefaultLegacy(_jsx2);
|
|
33
|
+
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
34
|
+
var _objectWithoutProperties__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutProperties);
|
|
35
|
+
var DSButton__default = /*#__PURE__*/_interopDefaultLegacy(DSButton);
|
|
36
|
+
|
|
37
|
+
const _excluded = ["onClick", "id"];
|
|
38
|
+
|
|
39
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
40
|
+
|
|
41
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
42
|
+
|
|
43
|
+
const DSAccordionItem = props => {
|
|
44
|
+
const propsWithDefaults = dsPropsHelpers.useMemoMergePropsWithDefault(props, defaultProps.accordionItemDefaultProps);
|
|
45
|
+
const {
|
|
46
|
+
children,
|
|
47
|
+
title,
|
|
48
|
+
secondaryTitle,
|
|
49
|
+
customActions,
|
|
50
|
+
iconOpened: IconOpened,
|
|
51
|
+
iconClosed: IconClosed,
|
|
52
|
+
value,
|
|
53
|
+
disabled,
|
|
54
|
+
dsIndex,
|
|
55
|
+
renderCustomActions
|
|
56
|
+
} = propsWithDefaults;
|
|
57
|
+
const {
|
|
58
|
+
handleOnClick,
|
|
59
|
+
handleOnKeyDown,
|
|
60
|
+
selected
|
|
61
|
+
} = useAccordionItem.useAccordionItem({
|
|
62
|
+
value,
|
|
63
|
+
disabled
|
|
64
|
+
});
|
|
65
|
+
const {
|
|
66
|
+
allChildrenReferences,
|
|
67
|
+
actualActiveValue,
|
|
68
|
+
props: {
|
|
69
|
+
isDSMobile
|
|
70
|
+
}
|
|
71
|
+
} = React.useContext(DSAccordionCTX.DSAccordionContext);
|
|
72
|
+
const onKeyDownWithIndex = React.useCallback(e => {
|
|
73
|
+
handleOnKeyDown(e, dsIndex);
|
|
74
|
+
}, [dsIndex, handleOnKeyDown]);
|
|
75
|
+
const [showPopover, setShowPopover] = React.useState(false);
|
|
76
|
+
const [referenceElement, setReferenceElement] = React.useState();
|
|
77
|
+
const CustomActionsContent = React.useMemo(() => {
|
|
78
|
+
if (!isDSMobile && (customActions === null || customActions === void 0 ? void 0 : customActions.length) > 0) return /*#__PURE__*/_jsx2__default["default"](styles.StyledItemCustomActions, {}, void 0, customActions === null || customActions === void 0 ? void 0 : customActions.map(_ref => {
|
|
79
|
+
let {
|
|
80
|
+
onClick,
|
|
81
|
+
id
|
|
82
|
+
} = _ref,
|
|
83
|
+
rest = _objectWithoutProperties__default["default"](_ref, _excluded);
|
|
84
|
+
|
|
85
|
+
return /*#__PURE__*/jsxRuntime.jsx(DSButton__default["default"], _objectSpread(_objectSpread({
|
|
86
|
+
onClick: e => {
|
|
87
|
+
e.stopPropagation();
|
|
88
|
+
if (onClick) onClick(e);
|
|
89
|
+
}
|
|
90
|
+
}, rest), {}, {
|
|
91
|
+
buttonType: DSButton.BUTTON_TYPE.SECONDARY
|
|
92
|
+
}), id);
|
|
93
|
+
}));
|
|
94
|
+
if (!isDSMobile && renderCustomActions) return /*#__PURE__*/_jsx2__default["default"](styles.StyledItemCustomActions, {}, void 0, renderCustomActions({
|
|
95
|
+
allRefs: allChildrenReferences,
|
|
96
|
+
actualActiveValue
|
|
97
|
+
}));
|
|
98
|
+
return null;
|
|
99
|
+
}, [actualActiveValue, allChildrenReferences, customActions, isDSMobile, renderCustomActions]);
|
|
100
|
+
const {
|
|
101
|
+
isShowingEllipsis: isPrimaryShowingEllipsis,
|
|
102
|
+
setElement: setPrimaryElement
|
|
103
|
+
} = useIsShowingEllipsis.useIsShowingEllipsis();
|
|
104
|
+
const {
|
|
105
|
+
isShowingEllipsis: isSecondaryShowingEllipsis,
|
|
106
|
+
setElement: setSecondaryElement
|
|
107
|
+
} = useIsShowingEllipsis.useIsShowingEllipsis();
|
|
108
|
+
const handleOnFocus = React.useCallback(() => setShowPopover(isPrimaryShowingEllipsis || isSecondaryShowingEllipsis), [isPrimaryShowingEllipsis, isSecondaryShowingEllipsis]);
|
|
109
|
+
const handleOnBlur = React.useCallback(() => setShowPopover(false), []);
|
|
110
|
+
const Titles = React.useMemo(() => {
|
|
111
|
+
if (isPrimaryShowingEllipsis || isSecondaryShowingEllipsis) return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
112
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(styles.StyledPrimaryTitle, {
|
|
113
|
+
ref: setPrimaryElement,
|
|
114
|
+
id: "accordion_".concat(title, "id"),
|
|
115
|
+
disabled: disabled,
|
|
116
|
+
isDSMobile: isDSMobile,
|
|
117
|
+
children: title
|
|
118
|
+
}), !isDSMobile && secondaryTitle && /*#__PURE__*/jsxRuntime.jsx(styles.StyledSecondaryTitle, {
|
|
119
|
+
ref: setSecondaryElement,
|
|
120
|
+
disabled: disabled,
|
|
121
|
+
children: secondaryTitle
|
|
122
|
+
}), /*#__PURE__*/_jsx2__default["default"](dsPopperjs.DSPopperJS, {
|
|
123
|
+
referenceElement: referenceElement,
|
|
124
|
+
showPopover: showPopover
|
|
125
|
+
}, void 0, /*#__PURE__*/_jsx2__default["default"]("div", {
|
|
126
|
+
style: {
|
|
127
|
+
maxWidth: 260,
|
|
128
|
+
padding: 8,
|
|
129
|
+
background: 'white',
|
|
130
|
+
display: 'grid',
|
|
131
|
+
gap: 8
|
|
132
|
+
}
|
|
133
|
+
}, void 0, /*#__PURE__*/_jsx2__default["default"]("p", {
|
|
134
|
+
style: {
|
|
135
|
+
margin: 0
|
|
136
|
+
}
|
|
137
|
+
}, void 0, title), /*#__PURE__*/_jsx2__default["default"]("p", {
|
|
138
|
+
style: {
|
|
139
|
+
margin: 0
|
|
140
|
+
}
|
|
141
|
+
}, void 0, " ", secondaryTitle)))]
|
|
142
|
+
});
|
|
143
|
+
return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
144
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(styles.StyledPrimaryTitle, {
|
|
145
|
+
ref: setPrimaryElement,
|
|
146
|
+
id: "accordion_".concat(title, "id"),
|
|
147
|
+
disabled: disabled,
|
|
148
|
+
isDSMobile: isDSMobile,
|
|
149
|
+
children: title
|
|
150
|
+
}), !isDSMobile && secondaryTitle && /*#__PURE__*/jsxRuntime.jsx(styles.StyledSecondaryTitle, {
|
|
151
|
+
ref: setSecondaryElement,
|
|
152
|
+
disabled: disabled,
|
|
153
|
+
children: secondaryTitle
|
|
154
|
+
})]
|
|
155
|
+
});
|
|
156
|
+
}, [disabled, isDSMobile, isPrimaryShowingEllipsis, isSecondaryShowingEllipsis, referenceElement, secondaryTitle, setPrimaryElement, setSecondaryElement, showPopover, title]);
|
|
157
|
+
return /*#__PURE__*/_jsx2__default["default"](styles.StyledItemContainer, {
|
|
158
|
+
"data-testid": DSAccordionDatatestid.DSAccordionDataTestid.ITEM.CONTAINER
|
|
159
|
+
}, void 0, /*#__PURE__*/_jsx2__default["default"](styles.StyledItemHeaderContainer, {
|
|
160
|
+
disabled: disabled
|
|
161
|
+
}, void 0, /*#__PURE__*/jsxRuntime.jsxs(styles.StyledItemHeader, {
|
|
162
|
+
withCustomActions: ((customActions === null || customActions === void 0 ? void 0 : customActions.length) > 0 || renderCustomActions !== undefined) && !isDSMobile,
|
|
163
|
+
withSecondaryTitle: secondaryTitle,
|
|
164
|
+
onClick: handleOnClick,
|
|
165
|
+
tabIndex: !disabled ? 0 : undefined,
|
|
166
|
+
disabled: disabled,
|
|
167
|
+
"data-disabled": disabled,
|
|
168
|
+
ref: allChildrenReferences[dsIndex],
|
|
169
|
+
onKeyDown: onKeyDownWithIndex,
|
|
170
|
+
isDSMobile: isDSMobile,
|
|
171
|
+
"data-testid": DSAccordionDatatestid.DSAccordionDataTestid.ITEM.HEADER,
|
|
172
|
+
id: "ds-accordion-header-".concat(value),
|
|
173
|
+
"aria-expanded": selected,
|
|
174
|
+
"aria-disabled": disabled,
|
|
175
|
+
"aria-controls": "ds-accordion-content-".concat(value),
|
|
176
|
+
onFocus: handleOnFocus,
|
|
177
|
+
onBlur: handleOnBlur,
|
|
178
|
+
children: [/*#__PURE__*/_jsx2__default["default"](styles.StyledItemAddon, {
|
|
179
|
+
disabled: disabled,
|
|
180
|
+
isDSMobile: isDSMobile
|
|
181
|
+
}, void 0, selected ? /*#__PURE__*/_jsx2__default["default"](IconOpened, {
|
|
182
|
+
isDSMobile: isDSMobile
|
|
183
|
+
}) : /*#__PURE__*/_jsx2__default["default"](IconClosed, {
|
|
184
|
+
isDSMobile: isDSMobile
|
|
185
|
+
})), /*#__PURE__*/jsxRuntime.jsx(styles.StyledItemTitles, {
|
|
186
|
+
onMouseEnter: handleOnFocus,
|
|
187
|
+
onMouseLeave: handleOnBlur,
|
|
188
|
+
isDSMobile: isDSMobile,
|
|
189
|
+
ref: setReferenceElement,
|
|
190
|
+
children: Titles
|
|
191
|
+
})]
|
|
192
|
+
}), CustomActionsContent), selected && /*#__PURE__*/_jsx2__default["default"](styles.StyledItemContent, {
|
|
193
|
+
"data-testid": DSAccordionDatatestid.DSAccordionDataTestid.ITEM.CONTENT,
|
|
194
|
+
"aria-labelledby": "ds-accordion-header-".concat(value),
|
|
195
|
+
role: "region",
|
|
196
|
+
isDSMobile: isDSMobile,
|
|
197
|
+
id: "ds-accordion-content-".concat(value)
|
|
198
|
+
}, void 0, children));
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
const DSAccordionItemWithSchema = reactDesc.describe(DSAccordionItem);
|
|
202
|
+
DSAccordionItemWithSchema.propTypes = propTypes.accordionItemPropTypes;
|
|
203
|
+
|
|
204
|
+
exports.DSAccordionItem = DSAccordionItem;
|
|
205
|
+
exports.DSAccordionItemWithSchema = DSAccordionItemWithSchema;
|
|
206
|
+
exports["default"] = DSAccordionItem;
|