@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.
Files changed (56) hide show
  1. package/cjs/DSAccordion.js +14 -99
  2. package/cjs/DSAccordionCTX.js +20 -0
  3. package/cjs/DSAccordionDatatestid.js +14 -0
  4. package/cjs/DSAccordionTypes.js +2 -0
  5. package/cjs/config/useAccordion.js +50 -0
  6. package/cjs/config/useAccordionRefs.js +40 -0
  7. package/cjs/defaultProps.js +54 -0
  8. package/cjs/index.js +1 -1
  9. package/cjs/{DSAccordionHeaderActions.js → parts/accordionContent/AccordionContent.js} +24 -38
  10. package/cjs/parts/accordionItem/DSAccordionItem.js +206 -0
  11. package/cjs/parts/accordionItem/styles.js +133 -0
  12. package/cjs/parts/accordionItem/useAccordionItem.js +53 -0
  13. package/cjs/parts/accordionItem/useIsShowingEllipsis.js +37 -0
  14. package/cjs/propTypes.js +26 -0
  15. package/esm/DSAccordion.js +16 -98
  16. package/esm/DSAccordionCTX.js +16 -0
  17. package/esm/DSAccordionDatatestid.js +10 -0
  18. package/esm/DSAccordionTypes.js +1 -0
  19. package/esm/config/useAccordion.js +46 -0
  20. package/esm/config/useAccordionRefs.js +32 -0
  21. package/esm/defaultProps.js +45 -0
  22. package/esm/index.js +1 -1
  23. package/esm/{DSAccordionHeaderActions.js → parts/accordionContent/AccordionContent.js} +21 -35
  24. package/esm/parts/accordionItem/DSAccordionItem.js +193 -0
  25. package/esm/parts/accordionItem/styles.js +117 -0
  26. package/esm/parts/accordionItem/useAccordionItem.js +49 -0
  27. package/esm/parts/accordionItem/useIsShowingEllipsis.js +33 -0
  28. package/esm/propTypes.js +21 -0
  29. package/package.json +50 -22
  30. package/types/DSAccordion.d.ts +5 -35
  31. package/types/DSAccordionCTX.d.ts +3 -0
  32. package/types/DSAccordionDatatestid.d.ts +8 -0
  33. package/types/DSAccordionTypes.d.ts +134 -0
  34. package/types/config/useAccordion.d.ts +2 -0
  35. package/types/config/useAccordionRefs.d.ts +2 -0
  36. package/types/defaultProps.d.ts +3 -0
  37. package/types/index.d.ts +2 -1
  38. package/types/parts/accordionContent/AccordionContent.d.ts +2 -0
  39. package/types/parts/accordionItem/DSAccordionItem.d.ts +53 -0
  40. package/types/parts/accordionItem/styles.d.ts +10 -0
  41. package/types/parts/accordionItem/useAccordionItem.d.ts +2 -0
  42. package/types/parts/accordionItem/useIsShowingEllipsis.d.ts +5 -0
  43. package/types/propTypes.d.ts +73 -0
  44. package/cjs/DSAccordionHeader.js +0 -57
  45. package/cjs/DSAccordionHeaderTitle.js +0 -36
  46. package/cjs/DSAccordionItem.js +0 -174
  47. package/cjs/blocks.js +0 -23
  48. package/esm/DSAccordionHeader.js +0 -50
  49. package/esm/DSAccordionHeaderTitle.js +0 -29
  50. package/esm/DSAccordionItem.js +0 -162
  51. package/esm/blocks.js +0 -13
  52. package/types/DSAccordionHeader.d.ts +0 -9
  53. package/types/DSAccordionHeaderActions.d.ts +0 -5
  54. package/types/DSAccordionHeaderTitle.d.ts +0 -7
  55. package/types/DSAccordionItem.d.ts +0 -16
  56. package/types/blocks.d.ts +0 -7
@@ -0,0 +1,133 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var styled = require('styled-components');
6
+
7
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
+
9
+ var styled__default = /*#__PURE__*/_interopDefaultLegacy(styled);
10
+
11
+ const StyledItemContainer = /*#__PURE__*/styled__default["default"].div.withConfig({
12
+ componentId: "sc-fnpjby-0"
13
+ })(["display:grid;grid-template-rows:auto auto;border-bottom:1px solid ", ";align-items:center;"], _ref => {
14
+ let {
15
+ theme
16
+ } = _ref;
17
+ return theme.colors.neutral[200];
18
+ });
19
+ const StyledItemHeader = /*#__PURE__*/styled__default["default"].button.withConfig({
20
+ componentId: "sc-fnpjby-1"
21
+ })(["display:grid;height:", ";grid-template-columns:", ";width:100%;align-items:center;border:none;outline:none;background:none;&:hover{cursor:", ";}padding:", ";", " &:focus{&:after{position:absolute;content:'';left:0;top:0;width:100%;height:100%;border-radius:2px;border:2px solid ", ";pointer-events:none;}}"], _ref2 => {
22
+ let {
23
+ withSecondaryTitle
24
+ } = _ref2;
25
+ return withSecondaryTitle ? '48px' : '32px';
26
+ }, _ref3 => {
27
+ let {
28
+ withCustomActions,
29
+ isDSMobile
30
+ } = _ref3;
31
+ return withCustomActions ? '32px auto' : "".concat(isDSMobile ? "auto 32px" : "32px auto");
32
+ }, _ref4 => {
33
+ let {
34
+ disabled
35
+ } = _ref4;
36
+ return disabled ? 'not-allowed' : 'pointer';
37
+ }, _ref5 => {
38
+ let {
39
+ isDSMobile
40
+ } = _ref5;
41
+ return isDSMobile ? "0 16px" : "0";
42
+ }, _ref6 => {
43
+ let {
44
+ isDSMobile
45
+ } = _ref6;
46
+ return isDSMobile ? "grid-template-areas: 'title addon';" : "";
47
+ }, _ref7 => {
48
+ let {
49
+ theme
50
+ } = _ref7;
51
+ return theme.colors.brand[700];
52
+ });
53
+ const StyledItemContent = /*#__PURE__*/styled__default["default"].div.withConfig({
54
+ componentId: "sc-fnpjby-2"
55
+ })(["margin:", ";grid-column:1/2;"], _ref8 => {
56
+ let {
57
+ isDSMobile
58
+ } = _ref8;
59
+ return isDSMobile ? "16px 16px 24px 16px" : "16px 16px 16px 32px";
60
+ });
61
+ const StyledItemAddon = /*#__PURE__*/styled__default["default"].div.withConfig({
62
+ componentId: "sc-fnpjby-3"
63
+ })(["", " height:100%;display:grid;place-items:center;& .em-ds-icon svg{fill:", ";}"], _ref9 => {
64
+ let {
65
+ isDSMobile
66
+ } = _ref9;
67
+ return !isDSMobile ? " padding: 0 8px;\n \n" : "\n grid-area: addon;\n ";
68
+ }, _ref10 => {
69
+ let {
70
+ disabled,
71
+ theme
72
+ } = _ref10;
73
+ return disabled ? theme.colors.neutral[200] : theme.colors.brand[800];
74
+ });
75
+ const StyledItemTitles = /*#__PURE__*/styled__default["default"].div.withConfig({
76
+ componentId: "sc-fnpjby-4"
77
+ })(["display:grid;grid-template-columns:100%;align-content:center;", ""], _ref11 => {
78
+ let {
79
+ isDSMobile
80
+ } = _ref11;
81
+ return isDSMobile ? "grid-area: title;" : "";
82
+ });
83
+ const StyledPrimaryTitle = /*#__PURE__*/styled__default["default"].div.withConfig({
84
+ componentId: "sc-fnpjby-5"
85
+ })(["margin:0;font-size:16px;color:", ";font-weight:", ";text-overflow:ellipsis;overflow:hidden;height:16px;width:100%;text-align:left;display:block;white-space:nowrap;"], _ref12 => {
86
+ let {
87
+ disabled,
88
+ theme
89
+ } = _ref12;
90
+ return disabled ? theme.colors.neutral[200] : theme.colors.neutral[700];
91
+ }, _ref13 => {
92
+ let {
93
+ theme,
94
+ isDSMobile
95
+ } = _ref13;
96
+ return isDSMobile ? theme.fontWeights.regular : theme.fontWeights.regular;
97
+ });
98
+ const StyledSecondaryTitle = /*#__PURE__*/styled__default["default"].span.withConfig({
99
+ componentId: "sc-fnpjby-6"
100
+ })(["margin:0;font-size:", ";text-align:left;color:", ";text-overflow:ellipsis;overflow:hidden;height:16px;width:100%;text-align:left;display:block;white-space:nowrap;"], _ref14 => {
101
+ let {
102
+ theme
103
+ } = _ref14;
104
+ return theme.fontSizes.label[200];
105
+ }, _ref15 => {
106
+ let {
107
+ disabled,
108
+ theme
109
+ } = _ref15;
110
+ return disabled ? theme.colors.neutral[200] : theme.colors.neutral[500];
111
+ });
112
+ const StyledItemCustomActions = /*#__PURE__*/styled__default["default"].div.withConfig({
113
+ componentId: "sc-fnpjby-7"
114
+ })(["display:grid;grid-auto-flow:column;grid-gap:8px;margin:0 16px;justify-content:flex-end;"]);
115
+ const StyledItemHeaderContainer = /*#__PURE__*/styled__default["default"].div.withConfig({
116
+ componentId: "sc-fnpjby-8"
117
+ })(["display:grid;grid-template-columns:auto max-content;place-items:center;position:relative;&:hover{", ";}"], _ref16 => {
118
+ let {
119
+ disabled,
120
+ theme
121
+ } = _ref16;
122
+ return !disabled ? "background: ".concat(theme.colors.brand[200]) : "";
123
+ });
124
+
125
+ exports.StyledItemAddon = StyledItemAddon;
126
+ exports.StyledItemContainer = StyledItemContainer;
127
+ exports.StyledItemContent = StyledItemContent;
128
+ exports.StyledItemCustomActions = StyledItemCustomActions;
129
+ exports.StyledItemHeader = StyledItemHeader;
130
+ exports.StyledItemHeaderContainer = StyledItemHeaderContainer;
131
+ exports.StyledItemTitles = StyledItemTitles;
132
+ exports.StyledPrimaryTitle = StyledPrimaryTitle;
133
+ exports.StyledSecondaryTitle = StyledSecondaryTitle;
@@ -0,0 +1,53 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ require('core-js/modules/esnext.async-iterator.some.js');
6
+ require('core-js/modules/esnext.iterator.constructor.js');
7
+ require('core-js/modules/esnext.iterator.some.js');
8
+ var React = require('react');
9
+ var DSAccordionCTX = require('../../DSAccordionCTX.js');
10
+
11
+ const useAccordionItem = _ref => {
12
+ let {
13
+ value,
14
+ disabled
15
+ } = _ref;
16
+ const {
17
+ actualActiveValue,
18
+ setActiveValues,
19
+ focusableChildrenReferences
20
+ } = React.useContext(DSAccordionCTX.DSAccordionContext);
21
+ const selected = React.useMemo(() => {
22
+ if (Array.isArray(actualActiveValue)) {
23
+ return actualActiveValue.some(currentValue => currentValue === value);
24
+ }
25
+
26
+ return value === actualActiveValue;
27
+ }, [actualActiveValue, value]);
28
+ const handleOnClick = React.useCallback(e => {
29
+ if (!disabled) setActiveValues(value, e);
30
+ }, [disabled, setActiveValues, value]);
31
+ const handleOnKeyDown = React.useCallback((e, _dsIndex) => {
32
+ if (!disabled && e.key === 'ArrowDown') {
33
+ var _focusableChildrenRef, _focusableChildrenRef2, _focusableChildrenRef3, _focusableChildrenRef4, _focusableChildrenRef5;
34
+
35
+ const currentIndex = focusableChildrenReferences.findIndex(item => item.index === _dsIndex);
36
+ if ((_focusableChildrenRef = focusableChildrenReferences[currentIndex + 1]) !== null && _focusableChildrenRef !== void 0 && (_focusableChildrenRef2 = _focusableChildrenRef.ref) !== null && _focusableChildrenRef2 !== void 0 && _focusableChildrenRef2.current) (_focusableChildrenRef3 = focusableChildrenReferences[currentIndex + 1]) === null || _focusableChildrenRef3 === void 0 ? void 0 : (_focusableChildrenRef4 = _focusableChildrenRef3.ref) === null || _focusableChildrenRef4 === void 0 ? void 0 : (_focusableChildrenRef5 = _focusableChildrenRef4.current) === null || _focusableChildrenRef5 === void 0 ? void 0 : _focusableChildrenRef5.focus();
37
+ }
38
+
39
+ if (!disabled && e.key === 'ArrowUp') {
40
+ var _focusableChildrenRef6, _focusableChildrenRef7, _focusableChildrenRef8, _focusableChildrenRef9, _focusableChildrenRef10;
41
+
42
+ const currentIndex = focusableChildrenReferences.findIndex(item => item.index === _dsIndex);
43
+ if ((_focusableChildrenRef6 = focusableChildrenReferences[currentIndex - 1]) !== null && _focusableChildrenRef6 !== void 0 && (_focusableChildrenRef7 = _focusableChildrenRef6.ref) !== null && _focusableChildrenRef7 !== void 0 && _focusableChildrenRef7.current) (_focusableChildrenRef8 = focusableChildrenReferences[currentIndex - 1]) === null || _focusableChildrenRef8 === void 0 ? void 0 : (_focusableChildrenRef9 = _focusableChildrenRef8.ref) === null || _focusableChildrenRef9 === void 0 ? void 0 : (_focusableChildrenRef10 = _focusableChildrenRef9.current) === null || _focusableChildrenRef10 === void 0 ? void 0 : _focusableChildrenRef10.focus();
44
+ }
45
+ }, [disabled, focusableChildrenReferences]);
46
+ return {
47
+ handleOnClick,
48
+ handleOnKeyDown,
49
+ selected
50
+ };
51
+ };
52
+
53
+ exports.useAccordionItem = useAccordionItem;
@@ -0,0 +1,37 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ require('core-js/modules/web.dom-collections.iterator.js');
6
+ var React = require('react');
7
+
8
+ const useIsShowingEllipsis = () => {
9
+ const [element, setElement] = React.useState();
10
+ const [isShowingEllipsis, setIsShowingEllipsis] = React.useState(false); // const isShowingEllipsis = element?.scrollWidth > primaryTitleWrapperEl?.clientWidth;
11
+
12
+ const resizeObserver = React.useMemo(() => new ResizeObserver(entries => {
13
+ if (entries.length) {
14
+ const [textWrapperEntry] = entries;
15
+ const el = textWrapperEntry.target;
16
+ setIsShowingEllipsis((el === null || el === void 0 ? void 0 : el.scrollWidth) > (el === null || el === void 0 ? void 0 : el.clientWidth));
17
+ }
18
+ }), []);
19
+ React.useEffect(() => {
20
+ if (element) {
21
+ setIsShowingEllipsis((element === null || element === void 0 ? void 0 : element.scrollWidth) > (element === null || element === void 0 ? void 0 : element.clientWidth));
22
+ resizeObserver.observe(element);
23
+ }
24
+
25
+ return () => {
26
+ if (element) {
27
+ resizeObserver.unobserve(element);
28
+ }
29
+ };
30
+ }, [resizeObserver, element]);
31
+ return {
32
+ setElement,
33
+ isShowingEllipsis
34
+ };
35
+ };
36
+
37
+ exports.useIsShowingEllipsis = useIsShowingEllipsis;
@@ -0,0 +1,26 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var reactDesc = require('react-desc');
6
+
7
+ const accordionItemPropTypes = {
8
+ children: reactDesc.PropTypes.node.description('Dimsum AccordionItem content.').isRequired,
9
+ title: reactDesc.PropTypes.string.description('Set a primary title.'),
10
+ value: reactDesc.PropTypes.oneOfType([reactDesc.PropTypes.string, reactDesc.PropTypes.number]).description('Dimsum AccordionItem value, this value should be unique.').isRequired,
11
+ iconClosed: reactDesc.PropTypes.node.description('Custom Dimsum Icon when it is closed.'),
12
+ iconOpened: reactDesc.PropTypes.node.description('Custom Dimsum Icon when it is open.'),
13
+ secondaryTitle: reactDesc.PropTypes.string.description('Set a secondary title'),
14
+ customActions: reactDesc.PropTypes.arrayOf(reactDesc.PropTypes.object).description('Set Dimsum AccordionItem custom actions.'),
15
+ renderCustomActions: reactDesc.PropTypes.func.description('This property will render any JSX in the custom actions area. You can access to all references and active values within the props.')
16
+ };
17
+ const accordionPropTypes = {
18
+ containerProps: reactDesc.PropTypes.object.description('Adds props to the container.'),
19
+ activeValue: reactDesc.PropTypes.oneOfType([reactDesc.PropTypes.arrayOf(reactDesc.PropTypes.oneOfType([reactDesc.PropTypes.string, reactDesc.PropTypes.number])), reactDesc.PropTypes.string, reactDesc.PropTypes.number]).description('Selected active value. This property makes the component a controlled one.'),
20
+ children: reactDesc.PropTypes.node.description('Dimsum AccordionItems to show.'),
21
+ allowMultipleOpen: reactDesc.PropTypes.bool.description('Allows multiple Dimsum AccordionItems to be open at the same time.'),
22
+ onChange: reactDesc.PropTypes.func.description('Callback function once the Dimsum Accordion changes.')
23
+ };
24
+
25
+ exports.accordionItemPropTypes = accordionItemPropTypes;
26
+ exports.accordionPropTypes = accordionPropTypes;
@@ -1,103 +1,21 @@
1
- import _jsx from '@babel/runtime/helpers/esm/jsx';
2
- import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
3
- import 'core-js/modules/esnext.async-iterator.map.js';
4
- import 'core-js/modules/esnext.iterator.map.js';
5
- import 'core-js/modules/esnext.async-iterator.filter.js';
6
- import 'core-js/modules/esnext.iterator.constructor.js';
7
- import 'core-js/modules/esnext.iterator.filter.js';
8
- import 'core-js/modules/esnext.async-iterator.for-each.js';
9
- import 'core-js/modules/esnext.iterator.for-each.js';
10
- import React from 'react';
11
- import { PropTypes, describe } from 'react-desc';
12
- import { convertPropToCssClassName } from '@elliemae/ds-classnames';
13
- import Group from '@elliemae/ds-shared/GroupContext/Group';
14
- import { TooltipTextProvider } from '@elliemae/ds-truncated-tooltip-text';
15
- import { DSAccordionItem } from './DSAccordionItem.js';
16
- import { jsx } from 'react/jsx-runtime';
17
-
18
- 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; }
19
-
20
- 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(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; }
21
-
22
- const DSAccordion = _ref => {
23
- let {
24
- containerProps = {},
25
- activeValue = '',
26
- children,
27
- allowMultipleOpen = false,
28
- contentExpandable = false,
29
- onChange = () => {}
30
- } = _ref;
31
- const {
32
- cssClassName
33
- } = convertPropToCssClassName('accordion');
34
- const tabsRef = {};
35
-
36
- const handleKeyPress = (index, e) => {
37
- if (e.keyCode === 39 || e.keyCode === 40) {
38
- const nextTab = tabsRef[index + 1];
39
- if (!nextTab) return;
40
- tabsRef[index + 1].focus();
41
- }
42
-
43
- if (e.keyCode === 37 || e.keyCode === 38) {
44
- const nextTab = tabsRef[index - 1];
45
- if (!nextTab) return;
46
- tabsRef[index - 1].focus();
47
- }
48
- };
49
-
50
- return /*#__PURE__*/_jsx(TooltipTextProvider, {}, void 0, /*#__PURE__*/_jsx(Group, {
51
- activeValue: activeValue,
52
- multiple: allowMultipleOpen,
53
- onChange: onChange
54
- }, void 0, /*#__PURE__*/jsx("section", _objectSpread(_objectSpread({
55
- className: cssClassName
56
- }, containerProps), {}, {
57
- children: React.Children.map(children, (child, idx) => /*#__PURE__*/React.cloneElement(child, {
58
- key: idx,
59
- idx,
60
- expandable: contentExpandable,
61
- setTabRef: ref => {
62
- tabsRef[idx] = ref;
63
- },
64
- handleKeyPress
65
- }), null)
66
- }))));
1
+ import _jsx2 from '@babel/runtime/helpers/esm/jsx';
2
+ import 'react';
3
+ import { describe } from 'react-desc';
4
+ import { AccordionContent } from './parts/accordionContent/AccordionContent.js';
5
+ import { useAccordion } from './config/useAccordion.js';
6
+ import { DSAccordionContext } from './DSAccordionCTX.js';
7
+ import { accordionPropTypes } from './propTypes.js';
8
+
9
+ var _AccordionContent;
10
+
11
+ const DSAccordion = props => {
12
+ const ctx = useAccordion(props);
13
+ return /*#__PURE__*/_jsx2(DSAccordionContext.Provider, {
14
+ value: ctx
15
+ }, void 0, _AccordionContent || (_AccordionContent = /*#__PURE__*/_jsx2(AccordionContent, {})));
67
16
  };
68
17
 
69
- const props = {
70
- /** inject props to wrapper */
71
- containerProps: PropTypes.object.description('inject props to wrapper'),
72
-
73
- /**
74
- * Selected default active value
75
- */
76
- activeValue: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number])), PropTypes.string, PropTypes.number]).description('Selected default active value'),
77
-
78
- /**
79
- * Accordion items to show
80
- */
81
- children: PropTypes.arrayOf(PropTypes.shape({
82
- type: PropTypes.instanceOf(DSAccordionItem)
83
- })).isRequired.description('Accordion items to show'),
84
-
85
- /**
86
- * Allows multiple accordion items to be open at the same time
87
- */
88
- allowMultipleOpen: PropTypes.bool.description('Allows multiple accordion items to be open at the same time'),
89
-
90
- /**
91
- * Whether content is expandable or not
92
- */
93
- contentExpandable: PropTypes.bool.description('Whether content is expandable or not'),
94
-
95
- /**
96
- * Allows a function that is triggered once the accordion changes
97
- */
98
- onChange: PropTypes.func.description('Allows a function that is triggered once the accordion changes')
99
- };
100
18
  const DSAccordionWithSchema = describe(DSAccordion);
101
- DSAccordionWithSchema.propTypes = props;
19
+ DSAccordionWithSchema.propTypes = accordionPropTypes;
102
20
 
103
21
  export { DSAccordion, DSAccordionWithSchema, DSAccordion as default };
@@ -0,0 +1,16 @@
1
+ import { createContext } from 'react';
2
+ import { defaultProps } from './defaultProps.js';
3
+
4
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
5
+ const noop = () => {};
6
+
7
+ const defaultContext = {
8
+ props: defaultProps,
9
+ actualActiveValue: [],
10
+ setActiveValues: noop,
11
+ focusableChildrenReferences: [],
12
+ allChildrenReferences: {}
13
+ };
14
+ const DSAccordionContext = /*#__PURE__*/createContext(defaultContext);
15
+
16
+ export { DSAccordionContext };
@@ -0,0 +1,10 @@
1
+ const DSAccordionDataTestid = {
2
+ ITEM: {
3
+ CONTENT: 'ds-accordion_item-content',
4
+ HEADER: 'ds-accordion_item-header',
5
+ CONTAINER: 'ds-accordion_item'
6
+ },
7
+ GROUP: 'ds-accordion_group'
8
+ };
9
+
10
+ export { DSAccordionDataTestid };
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,46 @@
1
+ import 'core-js/modules/web.dom-collections.iterator.js';
2
+ import 'core-js/modules/esnext.async-iterator.some.js';
3
+ import 'core-js/modules/esnext.iterator.constructor.js';
4
+ import 'core-js/modules/esnext.iterator.some.js';
5
+ import 'core-js/modules/esnext.async-iterator.filter.js';
6
+ import 'core-js/modules/esnext.iterator.filter.js';
7
+ import { useState, useMemo, useCallback } from 'react';
8
+ import { useMemoMergePropsWithDefault } from '@elliemae/ds-props-helpers';
9
+ import { useAccordionRefs } from './useAccordionRefs.js';
10
+ import { defaultProps } from '../defaultProps.js';
11
+
12
+ const useAccordion = props => {
13
+ const propsWithDefaults = useMemoMergePropsWithDefault(props, defaultProps);
14
+ const {
15
+ activeValue,
16
+ allowMultipleOpen,
17
+ onChange
18
+ } = propsWithDefaults;
19
+ const {
20
+ focusableChildrenReferences,
21
+ allChildrenReferences
22
+ } = useAccordionRefs(propsWithDefaults);
23
+ const [internalActiveValue, setInternalActiveValue] = useState(activeValue);
24
+ const actualActiveValue = useMemo(() => {
25
+ if (activeValue === undefined) return internalActiveValue;
26
+ return activeValue;
27
+ }, [activeValue, internalActiveValue]);
28
+ const setActiveValues = useCallback((value, e) => {
29
+ let newState;
30
+ if (allowMultipleOpen && (actualActiveValue === undefined || actualActiveValue === null)) newState = [value];else if (allowMultipleOpen && Array.isArray(actualActiveValue)) {
31
+ if (!actualActiveValue.some(currentValues => currentValues === value)) newState = [...actualActiveValue, value];else newState = actualActiveValue.filter(currentValues => currentValues !== value);
32
+ } else if (actualActiveValue === value) newState = null;else newState = value;
33
+ setInternalActiveValue(newState);
34
+ return onChange(newState, e);
35
+ }, [actualActiveValue, allowMultipleOpen, onChange]);
36
+ const ctx = useMemo(() => ({
37
+ props: propsWithDefaults,
38
+ actualActiveValue,
39
+ setActiveValues,
40
+ focusableChildrenReferences,
41
+ allChildrenReferences
42
+ }), [actualActiveValue, allChildrenReferences, focusableChildrenReferences, propsWithDefaults, setActiveValues]);
43
+ return ctx;
44
+ };
45
+
46
+ export { useAccordion };
@@ -0,0 +1,32 @@
1
+ import 'core-js/modules/esnext.async-iterator.map.js';
2
+ import 'core-js/modules/esnext.iterator.map.js';
3
+ import React, { useMemo } from 'react';
4
+
5
+ const useAccordionRefs = _ref => {
6
+ let {
7
+ children
8
+ } = _ref;
9
+ return useMemo(() => {
10
+ const focusableChildrenReferences = [];
11
+ const allChildrenReferences = {};
12
+ React.Children.map(children, (child, index) => {
13
+ const {
14
+ value,
15
+ disabled
16
+ } = child.props;
17
+ const currentRef = /*#__PURE__*/React.createRef();
18
+ allChildrenReferences[index] = currentRef;
19
+ if (!disabled) focusableChildrenReferences.push({
20
+ index,
21
+ value,
22
+ ref: currentRef
23
+ });
24
+ });
25
+ return {
26
+ focusableChildrenReferences,
27
+ allChildrenReferences
28
+ };
29
+ }, [children]);
30
+ };
31
+
32
+ export { useAccordionRefs };
@@ -0,0 +1,45 @@
1
+ import _jsx2 from '@babel/runtime/helpers/esm/jsx';
2
+ import { memo } from 'react';
3
+ import { ChevronRight, ArrowheadRight, ChevronDown, ArrowheadDown } from '@elliemae/ds-icons';
4
+
5
+ var _ChevronRight, _ArrowheadRight, _ChevronDown, _ArrowheadDown;
6
+ const DefaultIconClosed = /*#__PURE__*/memo(_ref => {
7
+ let {
8
+ isDSMobile = false
9
+ } = _ref;
10
+ return isDSMobile ? _ChevronRight || (_ChevronRight = /*#__PURE__*/_jsx2(ChevronRight, {
11
+ width: "20px"
12
+ })) : _ArrowheadRight || (_ArrowheadRight = /*#__PURE__*/_jsx2(ArrowheadRight, {
13
+ width: "20px"
14
+ }));
15
+ });
16
+ const DefaultIconOpen = /*#__PURE__*/memo(_ref2 => {
17
+ let {
18
+ isDSMobile = false
19
+ } = _ref2;
20
+ return isDSMobile ? _ChevronDown || (_ChevronDown = /*#__PURE__*/_jsx2(ChevronDown, {
21
+ width: "20px"
22
+ })) : _ArrowheadDown || (_ArrowheadDown = /*#__PURE__*/_jsx2(ArrowheadDown, {
23
+ width: "20px"
24
+ }));
25
+ }); // eslint-disable-next-line @typescript-eslint/no-empty-function
26
+
27
+ const noop = () => {};
28
+
29
+ const defaultProps = {
30
+ containerProps: {},
31
+ allowMultipleOpen: false,
32
+ contentExpandable: false,
33
+ onChange: noop,
34
+ children: [],
35
+ isDSMobile: false
36
+ };
37
+ const accordionItemDefaultProps = {
38
+ iconClosed: DefaultIconClosed,
39
+ iconOpened: DefaultIconOpen,
40
+ title: '',
41
+ customActions: [],
42
+ disabled: false
43
+ };
44
+
45
+ export { accordionItemDefaultProps, defaultProps };
package/esm/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  export { DSAccordion, DSAccordionWithSchema, DSAccordion as default } from './DSAccordion.js';
2
- export { DSAccordionItem, DSAccordionItemWithSchema } from './DSAccordionItem.js';
2
+ export { DSAccordionItem, DSAccordionItemWithSchema } from './parts/accordionItem/DSAccordionItem.js';
@@ -1,46 +1,32 @@
1
- import _jsx from '@babel/runtime/helpers/esm/jsx';
2
1
  import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
3
- import _objectWithoutProperties from '@babel/runtime/helpers/esm/objectWithoutProperties';
4
- import 'core-js/modules/esnext.async-iterator.map.js';
5
- import 'core-js/modules/esnext.iterator.map.js';
6
- import 'core-js/modules/esnext.async-iterator.filter.js';
7
- import 'core-js/modules/esnext.iterator.constructor.js';
8
- import 'core-js/modules/esnext.iterator.filter.js';
9
2
  import 'core-js/modules/esnext.async-iterator.for-each.js';
3
+ import 'core-js/modules/esnext.iterator.constructor.js';
10
4
  import 'core-js/modules/esnext.iterator.for-each.js';
11
- import 'react';
12
- import DSButton, { BUTTON_TYPE } from '@elliemae/ds-button';
13
- import { accordionActions } from './blocks.js';
5
+ import 'core-js/modules/esnext.async-iterator.filter.js';
6
+ import 'core-js/modules/esnext.iterator.filter.js';
7
+ import React, { useContext } from 'react';
8
+ import { DSAccordionContext } from '../../DSAccordionCTX.js';
9
+ import { DSAccordionDataTestid } from '../../DSAccordionDatatestid.js';
14
10
  import { jsx } from 'react/jsx-runtime';
15
11
 
16
- const _excluded = ["onClick"];
17
-
18
12
  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; }
19
13
 
20
14
  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(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; }
21
-
22
- const DSAccordionHeaderActions = _ref => {
23
- let {
24
- customActions
25
- } = _ref;
26
- if (!customActions) return null;
27
- return /*#__PURE__*/_jsx("div", {
28
- className: "".concat(accordionActions)
29
- }, void 0, customActions.map((_ref2, key) => {
30
- let {
31
- onClick
32
- } = _ref2,
33
- rest = _objectWithoutProperties(_ref2, _excluded);
34
-
35
- return /*#__PURE__*/jsx(DSButton, _objectSpread(_objectSpread({
36
- onClick: e => {
37
- e.stopPropagation();
38
- if (onClick) onClick(e);
39
- }
40
- }, rest), {}, {
41
- buttonType: BUTTON_TYPE.SECONDARY
42
- }), key);
15
+ const AccordionContent = () => {
16
+ const {
17
+ props: {
18
+ containerProps,
19
+ children
20
+ }
21
+ } = useContext(DSAccordionContext);
22
+ const childrenWithIndex = [];
23
+ React.Children.forEach(children, (child, index) => childrenWithIndex.push( /*#__PURE__*/React.cloneElement(child, {
24
+ dsIndex: index
25
+ })));
26
+ return /*#__PURE__*/jsx("div", _objectSpread(_objectSpread({}, containerProps), {}, {
27
+ "data-testid": DSAccordionDataTestid.GROUP,
28
+ children: childrenWithIndex
43
29
  }));
44
30
  };
45
31
 
46
- export { DSAccordionHeaderActions as default };
32
+ export { AccordionContent };