@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,193 @@
1
+ import _jsx2 from '@babel/runtime/helpers/esm/jsx';
2
+ import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
3
+ import _objectWithoutProperties from '@babel/runtime/helpers/esm/objectWithoutProperties';
4
+ import 'core-js/modules/web.dom-collections.iterator.js';
5
+ import 'core-js/modules/esnext.async-iterator.map.js';
6
+ import 'core-js/modules/esnext.iterator.map.js';
7
+ import 'core-js/modules/esnext.async-iterator.filter.js';
8
+ import 'core-js/modules/esnext.iterator.constructor.js';
9
+ import 'core-js/modules/esnext.iterator.filter.js';
10
+ import 'core-js/modules/esnext.async-iterator.for-each.js';
11
+ import 'core-js/modules/esnext.iterator.for-each.js';
12
+ import { useContext, useCallback, useState, useMemo } from 'react';
13
+ import { describe } from 'react-desc';
14
+ import { useMemoMergePropsWithDefault } from '@elliemae/ds-props-helpers';
15
+ import DSButton, { BUTTON_TYPE } from '@elliemae/ds-button';
16
+ import { DSPopperJS } from '@elliemae/ds-popperjs';
17
+ import { accordionItemDefaultProps } from '../../defaultProps.js';
18
+ import { StyledItemCustomActions, StyledPrimaryTitle, StyledSecondaryTitle, StyledItemContainer, StyledItemHeaderContainer, StyledItemHeader, StyledItemAddon, StyledItemTitles, StyledItemContent } from './styles.js';
19
+ import { accordionItemPropTypes } from '../../propTypes.js';
20
+ import { useAccordionItem } from './useAccordionItem.js';
21
+ import { DSAccordionContext } from '../../DSAccordionCTX.js';
22
+ import { DSAccordionDataTestid } from '../../DSAccordionDatatestid.js';
23
+ import { useIsShowingEllipsis } from './useIsShowingEllipsis.js';
24
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
25
+
26
+ const _excluded = ["onClick", "id"];
27
+
28
+ 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; }
29
+
30
+ 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; }
31
+
32
+ const DSAccordionItem = props => {
33
+ const propsWithDefaults = useMemoMergePropsWithDefault(props, accordionItemDefaultProps);
34
+ const {
35
+ children,
36
+ title,
37
+ secondaryTitle,
38
+ customActions,
39
+ iconOpened: IconOpened,
40
+ iconClosed: IconClosed,
41
+ value,
42
+ disabled,
43
+ dsIndex,
44
+ renderCustomActions
45
+ } = propsWithDefaults;
46
+ const {
47
+ handleOnClick,
48
+ handleOnKeyDown,
49
+ selected
50
+ } = useAccordionItem({
51
+ value,
52
+ disabled
53
+ });
54
+ const {
55
+ allChildrenReferences,
56
+ actualActiveValue,
57
+ props: {
58
+ isDSMobile
59
+ }
60
+ } = useContext(DSAccordionContext);
61
+ const onKeyDownWithIndex = useCallback(e => {
62
+ handleOnKeyDown(e, dsIndex);
63
+ }, [dsIndex, handleOnKeyDown]);
64
+ const [showPopover, setShowPopover] = useState(false);
65
+ const [referenceElement, setReferenceElement] = useState();
66
+ const CustomActionsContent = useMemo(() => {
67
+ if (!isDSMobile && (customActions === null || customActions === void 0 ? void 0 : customActions.length) > 0) return /*#__PURE__*/_jsx2(StyledItemCustomActions, {}, void 0, customActions === null || customActions === void 0 ? void 0 : customActions.map(_ref => {
68
+ let {
69
+ onClick,
70
+ id
71
+ } = _ref,
72
+ rest = _objectWithoutProperties(_ref, _excluded);
73
+
74
+ return /*#__PURE__*/jsx(DSButton, _objectSpread(_objectSpread({
75
+ onClick: e => {
76
+ e.stopPropagation();
77
+ if (onClick) onClick(e);
78
+ }
79
+ }, rest), {}, {
80
+ buttonType: BUTTON_TYPE.SECONDARY
81
+ }), id);
82
+ }));
83
+ if (!isDSMobile && renderCustomActions) return /*#__PURE__*/_jsx2(StyledItemCustomActions, {}, void 0, renderCustomActions({
84
+ allRefs: allChildrenReferences,
85
+ actualActiveValue
86
+ }));
87
+ return null;
88
+ }, [actualActiveValue, allChildrenReferences, customActions, isDSMobile, renderCustomActions]);
89
+ const {
90
+ isShowingEllipsis: isPrimaryShowingEllipsis,
91
+ setElement: setPrimaryElement
92
+ } = useIsShowingEllipsis();
93
+ const {
94
+ isShowingEllipsis: isSecondaryShowingEllipsis,
95
+ setElement: setSecondaryElement
96
+ } = useIsShowingEllipsis();
97
+ const handleOnFocus = useCallback(() => setShowPopover(isPrimaryShowingEllipsis || isSecondaryShowingEllipsis), [isPrimaryShowingEllipsis, isSecondaryShowingEllipsis]);
98
+ const handleOnBlur = useCallback(() => setShowPopover(false), []);
99
+ const Titles = useMemo(() => {
100
+ if (isPrimaryShowingEllipsis || isSecondaryShowingEllipsis) return /*#__PURE__*/jsxs(Fragment, {
101
+ children: [/*#__PURE__*/jsx(StyledPrimaryTitle, {
102
+ ref: setPrimaryElement,
103
+ id: "accordion_".concat(title, "id"),
104
+ disabled: disabled,
105
+ isDSMobile: isDSMobile,
106
+ children: title
107
+ }), !isDSMobile && secondaryTitle && /*#__PURE__*/jsx(StyledSecondaryTitle, {
108
+ ref: setSecondaryElement,
109
+ disabled: disabled,
110
+ children: secondaryTitle
111
+ }), /*#__PURE__*/_jsx2(DSPopperJS, {
112
+ referenceElement: referenceElement,
113
+ showPopover: showPopover
114
+ }, void 0, /*#__PURE__*/_jsx2("div", {
115
+ style: {
116
+ maxWidth: 260,
117
+ padding: 8,
118
+ background: 'white',
119
+ display: 'grid',
120
+ gap: 8
121
+ }
122
+ }, void 0, /*#__PURE__*/_jsx2("p", {
123
+ style: {
124
+ margin: 0
125
+ }
126
+ }, void 0, title), /*#__PURE__*/_jsx2("p", {
127
+ style: {
128
+ margin: 0
129
+ }
130
+ }, void 0, " ", secondaryTitle)))]
131
+ });
132
+ return /*#__PURE__*/jsxs(Fragment, {
133
+ children: [/*#__PURE__*/jsx(StyledPrimaryTitle, {
134
+ ref: setPrimaryElement,
135
+ id: "accordion_".concat(title, "id"),
136
+ disabled: disabled,
137
+ isDSMobile: isDSMobile,
138
+ children: title
139
+ }), !isDSMobile && secondaryTitle && /*#__PURE__*/jsx(StyledSecondaryTitle, {
140
+ ref: setSecondaryElement,
141
+ disabled: disabled,
142
+ children: secondaryTitle
143
+ })]
144
+ });
145
+ }, [disabled, isDSMobile, isPrimaryShowingEllipsis, isSecondaryShowingEllipsis, referenceElement, secondaryTitle, setPrimaryElement, setSecondaryElement, showPopover, title]);
146
+ return /*#__PURE__*/_jsx2(StyledItemContainer, {
147
+ "data-testid": DSAccordionDataTestid.ITEM.CONTAINER
148
+ }, void 0, /*#__PURE__*/_jsx2(StyledItemHeaderContainer, {
149
+ disabled: disabled
150
+ }, void 0, /*#__PURE__*/jsxs(StyledItemHeader, {
151
+ withCustomActions: ((customActions === null || customActions === void 0 ? void 0 : customActions.length) > 0 || renderCustomActions !== undefined) && !isDSMobile,
152
+ withSecondaryTitle: secondaryTitle,
153
+ onClick: handleOnClick,
154
+ tabIndex: !disabled ? 0 : undefined,
155
+ disabled: disabled,
156
+ "data-disabled": disabled,
157
+ ref: allChildrenReferences[dsIndex],
158
+ onKeyDown: onKeyDownWithIndex,
159
+ isDSMobile: isDSMobile,
160
+ "data-testid": DSAccordionDataTestid.ITEM.HEADER,
161
+ id: "ds-accordion-header-".concat(value),
162
+ "aria-expanded": selected,
163
+ "aria-disabled": disabled,
164
+ "aria-controls": "ds-accordion-content-".concat(value),
165
+ onFocus: handleOnFocus,
166
+ onBlur: handleOnBlur,
167
+ children: [/*#__PURE__*/_jsx2(StyledItemAddon, {
168
+ disabled: disabled,
169
+ isDSMobile: isDSMobile
170
+ }, void 0, selected ? /*#__PURE__*/_jsx2(IconOpened, {
171
+ isDSMobile: isDSMobile
172
+ }) : /*#__PURE__*/_jsx2(IconClosed, {
173
+ isDSMobile: isDSMobile
174
+ })), /*#__PURE__*/jsx(StyledItemTitles, {
175
+ onMouseEnter: handleOnFocus,
176
+ onMouseLeave: handleOnBlur,
177
+ isDSMobile: isDSMobile,
178
+ ref: setReferenceElement,
179
+ children: Titles
180
+ })]
181
+ }), CustomActionsContent), selected && /*#__PURE__*/_jsx2(StyledItemContent, {
182
+ "data-testid": DSAccordionDataTestid.ITEM.CONTENT,
183
+ "aria-labelledby": "ds-accordion-header-".concat(value),
184
+ role: "region",
185
+ isDSMobile: isDSMobile,
186
+ id: "ds-accordion-content-".concat(value)
187
+ }, void 0, children));
188
+ };
189
+
190
+ const DSAccordionItemWithSchema = describe(DSAccordionItem);
191
+ DSAccordionItemWithSchema.propTypes = accordionItemPropTypes;
192
+
193
+ export { DSAccordionItem, DSAccordionItemWithSchema, DSAccordionItem as default };
@@ -0,0 +1,117 @@
1
+ import styled from 'styled-components';
2
+
3
+ const StyledItemContainer = /*#__PURE__*/styled.div.withConfig({
4
+ componentId: "sc-fnpjby-0"
5
+ })(["display:grid;grid-template-rows:auto auto;border-bottom:1px solid ", ";align-items:center;"], _ref => {
6
+ let {
7
+ theme
8
+ } = _ref;
9
+ return theme.colors.neutral[200];
10
+ });
11
+ const StyledItemHeader = /*#__PURE__*/styled.button.withConfig({
12
+ componentId: "sc-fnpjby-1"
13
+ })(["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 => {
14
+ let {
15
+ withSecondaryTitle
16
+ } = _ref2;
17
+ return withSecondaryTitle ? '48px' : '32px';
18
+ }, _ref3 => {
19
+ let {
20
+ withCustomActions,
21
+ isDSMobile
22
+ } = _ref3;
23
+ return withCustomActions ? '32px auto' : "".concat(isDSMobile ? "auto 32px" : "32px auto");
24
+ }, _ref4 => {
25
+ let {
26
+ disabled
27
+ } = _ref4;
28
+ return disabled ? 'not-allowed' : 'pointer';
29
+ }, _ref5 => {
30
+ let {
31
+ isDSMobile
32
+ } = _ref5;
33
+ return isDSMobile ? "0 16px" : "0";
34
+ }, _ref6 => {
35
+ let {
36
+ isDSMobile
37
+ } = _ref6;
38
+ return isDSMobile ? "grid-template-areas: 'title addon';" : "";
39
+ }, _ref7 => {
40
+ let {
41
+ theme
42
+ } = _ref7;
43
+ return theme.colors.brand[700];
44
+ });
45
+ const StyledItemContent = /*#__PURE__*/styled.div.withConfig({
46
+ componentId: "sc-fnpjby-2"
47
+ })(["margin:", ";grid-column:1/2;"], _ref8 => {
48
+ let {
49
+ isDSMobile
50
+ } = _ref8;
51
+ return isDSMobile ? "16px 16px 24px 16px" : "16px 16px 16px 32px";
52
+ });
53
+ const StyledItemAddon = /*#__PURE__*/styled.div.withConfig({
54
+ componentId: "sc-fnpjby-3"
55
+ })(["", " height:100%;display:grid;place-items:center;& .em-ds-icon svg{fill:", ";}"], _ref9 => {
56
+ let {
57
+ isDSMobile
58
+ } = _ref9;
59
+ return !isDSMobile ? " padding: 0 8px;\n \n" : "\n grid-area: addon;\n ";
60
+ }, _ref10 => {
61
+ let {
62
+ disabled,
63
+ theme
64
+ } = _ref10;
65
+ return disabled ? theme.colors.neutral[200] : theme.colors.brand[800];
66
+ });
67
+ const StyledItemTitles = /*#__PURE__*/styled.div.withConfig({
68
+ componentId: "sc-fnpjby-4"
69
+ })(["display:grid;grid-template-columns:100%;align-content:center;", ""], _ref11 => {
70
+ let {
71
+ isDSMobile
72
+ } = _ref11;
73
+ return isDSMobile ? "grid-area: title;" : "";
74
+ });
75
+ const StyledPrimaryTitle = /*#__PURE__*/styled.div.withConfig({
76
+ componentId: "sc-fnpjby-5"
77
+ })(["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 => {
78
+ let {
79
+ disabled,
80
+ theme
81
+ } = _ref12;
82
+ return disabled ? theme.colors.neutral[200] : theme.colors.neutral[700];
83
+ }, _ref13 => {
84
+ let {
85
+ theme,
86
+ isDSMobile
87
+ } = _ref13;
88
+ return isDSMobile ? theme.fontWeights.regular : theme.fontWeights.regular;
89
+ });
90
+ const StyledSecondaryTitle = /*#__PURE__*/styled.span.withConfig({
91
+ componentId: "sc-fnpjby-6"
92
+ })(["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 => {
93
+ let {
94
+ theme
95
+ } = _ref14;
96
+ return theme.fontSizes.label[200];
97
+ }, _ref15 => {
98
+ let {
99
+ disabled,
100
+ theme
101
+ } = _ref15;
102
+ return disabled ? theme.colors.neutral[200] : theme.colors.neutral[500];
103
+ });
104
+ const StyledItemCustomActions = /*#__PURE__*/styled.div.withConfig({
105
+ componentId: "sc-fnpjby-7"
106
+ })(["display:grid;grid-auto-flow:column;grid-gap:8px;margin:0 16px;justify-content:flex-end;"]);
107
+ const StyledItemHeaderContainer = /*#__PURE__*/styled.div.withConfig({
108
+ componentId: "sc-fnpjby-8"
109
+ })(["display:grid;grid-template-columns:auto max-content;place-items:center;position:relative;&:hover{", ";}"], _ref16 => {
110
+ let {
111
+ disabled,
112
+ theme
113
+ } = _ref16;
114
+ return !disabled ? "background: ".concat(theme.colors.brand[200]) : "";
115
+ });
116
+
117
+ export { StyledItemAddon, StyledItemContainer, StyledItemContent, StyledItemCustomActions, StyledItemHeader, StyledItemHeaderContainer, StyledItemTitles, StyledPrimaryTitle, StyledSecondaryTitle };
@@ -0,0 +1,49 @@
1
+ import 'core-js/modules/esnext.async-iterator.some.js';
2
+ import 'core-js/modules/esnext.iterator.constructor.js';
3
+ import 'core-js/modules/esnext.iterator.some.js';
4
+ import { useContext, useMemo, useCallback } from 'react';
5
+ import { DSAccordionContext } from '../../DSAccordionCTX.js';
6
+
7
+ const useAccordionItem = _ref => {
8
+ let {
9
+ value,
10
+ disabled
11
+ } = _ref;
12
+ const {
13
+ actualActiveValue,
14
+ setActiveValues,
15
+ focusableChildrenReferences
16
+ } = useContext(DSAccordionContext);
17
+ const selected = useMemo(() => {
18
+ if (Array.isArray(actualActiveValue)) {
19
+ return actualActiveValue.some(currentValue => currentValue === value);
20
+ }
21
+
22
+ return value === actualActiveValue;
23
+ }, [actualActiveValue, value]);
24
+ const handleOnClick = useCallback(e => {
25
+ if (!disabled) setActiveValues(value, e);
26
+ }, [disabled, setActiveValues, value]);
27
+ const handleOnKeyDown = useCallback((e, _dsIndex) => {
28
+ if (!disabled && e.key === 'ArrowDown') {
29
+ var _focusableChildrenRef, _focusableChildrenRef2, _focusableChildrenRef3, _focusableChildrenRef4, _focusableChildrenRef5;
30
+
31
+ const currentIndex = focusableChildrenReferences.findIndex(item => item.index === _dsIndex);
32
+ 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();
33
+ }
34
+
35
+ if (!disabled && e.key === 'ArrowUp') {
36
+ var _focusableChildrenRef6, _focusableChildrenRef7, _focusableChildrenRef8, _focusableChildrenRef9, _focusableChildrenRef10;
37
+
38
+ const currentIndex = focusableChildrenReferences.findIndex(item => item.index === _dsIndex);
39
+ 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();
40
+ }
41
+ }, [disabled, focusableChildrenReferences]);
42
+ return {
43
+ handleOnClick,
44
+ handleOnKeyDown,
45
+ selected
46
+ };
47
+ };
48
+
49
+ export { useAccordionItem };
@@ -0,0 +1,33 @@
1
+ import 'core-js/modules/web.dom-collections.iterator.js';
2
+ import { useState, useMemo, useEffect } from 'react';
3
+
4
+ const useIsShowingEllipsis = () => {
5
+ const [element, setElement] = useState();
6
+ const [isShowingEllipsis, setIsShowingEllipsis] = useState(false); // const isShowingEllipsis = element?.scrollWidth > primaryTitleWrapperEl?.clientWidth;
7
+
8
+ const resizeObserver = useMemo(() => new ResizeObserver(entries => {
9
+ if (entries.length) {
10
+ const [textWrapperEntry] = entries;
11
+ const el = textWrapperEntry.target;
12
+ setIsShowingEllipsis((el === null || el === void 0 ? void 0 : el.scrollWidth) > (el === null || el === void 0 ? void 0 : el.clientWidth));
13
+ }
14
+ }), []);
15
+ useEffect(() => {
16
+ if (element) {
17
+ setIsShowingEllipsis((element === null || element === void 0 ? void 0 : element.scrollWidth) > (element === null || element === void 0 ? void 0 : element.clientWidth));
18
+ resizeObserver.observe(element);
19
+ }
20
+
21
+ return () => {
22
+ if (element) {
23
+ resizeObserver.unobserve(element);
24
+ }
25
+ };
26
+ }, [resizeObserver, element]);
27
+ return {
28
+ setElement,
29
+ isShowingEllipsis
30
+ };
31
+ };
32
+
33
+ export { useIsShowingEllipsis };
@@ -0,0 +1,21 @@
1
+ import { PropTypes } from 'react-desc';
2
+
3
+ const accordionItemPropTypes = {
4
+ children: PropTypes.node.description('Dimsum AccordionItem content.').isRequired,
5
+ title: PropTypes.string.description('Set a primary title.'),
6
+ value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).description('Dimsum AccordionItem value, this value should be unique.').isRequired,
7
+ iconClosed: PropTypes.node.description('Custom Dimsum Icon when it is closed.'),
8
+ iconOpened: PropTypes.node.description('Custom Dimsum Icon when it is open.'),
9
+ secondaryTitle: PropTypes.string.description('Set a secondary title'),
10
+ customActions: PropTypes.arrayOf(PropTypes.object).description('Set Dimsum AccordionItem custom actions.'),
11
+ renderCustomActions: 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.')
12
+ };
13
+ const accordionPropTypes = {
14
+ containerProps: PropTypes.object.description('Adds props to the container.'),
15
+ activeValue: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number])), PropTypes.string, PropTypes.number]).description('Selected active value. This property makes the component a controlled one.'),
16
+ children: PropTypes.node.description('Dimsum AccordionItems to show.'),
17
+ allowMultipleOpen: PropTypes.bool.description('Allows multiple Dimsum AccordionItems to be open at the same time.'),
18
+ onChange: PropTypes.func.description('Callback function once the Dimsum Accordion changes.')
19
+ };
20
+
21
+ export { accordionItemPropTypes, accordionPropTypes };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elliemae/ds-accordion",
3
- "version": "2.1.0-rc.6",
3
+ "version": "2.1.0",
4
4
  "license": "MIT",
5
5
  "description": "ICE MT - Dimsum - Accordion",
6
6
  "module": "./esm/index.js",
@@ -11,29 +11,57 @@
11
11
  "import": "./esm/index.js",
12
12
  "require": "./cjs/index.js"
13
13
  },
14
- "./DSAccordionItem": {
15
- "import": "./esm/DSAccordionItem.js",
16
- "require": "./cjs/DSAccordionItem.js"
14
+ "./propTypes": {
15
+ "import": "./esm/propTypes.js",
16
+ "require": "./cjs/propTypes.js"
17
17
  },
18
- "./DSAccordionHeaderTitle": {
19
- "import": "./esm/DSAccordionHeaderTitle.js",
20
- "require": "./cjs/DSAccordionHeaderTitle.js"
18
+ "./parts/accordionItem/useIsShowingEllipsis": {
19
+ "import": "./esm/parts/accordionItem/useIsShowingEllipsis.js",
20
+ "require": "./cjs/parts/accordionItem/useIsShowingEllipsis.js"
21
21
  },
22
- "./DSAccordionHeaderActions": {
23
- "import": "./esm/DSAccordionHeaderActions.js",
24
- "require": "./cjs/DSAccordionHeaderActions.js"
22
+ "./parts/accordionItem/useAccordionItem": {
23
+ "import": "./esm/parts/accordionItem/useAccordionItem.js",
24
+ "require": "./cjs/parts/accordionItem/useAccordionItem.js"
25
25
  },
26
- "./DSAccordionHeader": {
27
- "import": "./esm/DSAccordionHeader.js",
28
- "require": "./cjs/DSAccordionHeader.js"
26
+ "./parts/accordionItem/styles": {
27
+ "import": "./esm/parts/accordionItem/styles.js",
28
+ "require": "./cjs/parts/accordionItem/styles.js"
29
+ },
30
+ "./parts/accordionItem/DSAccordionItem": {
31
+ "import": "./esm/parts/accordionItem/DSAccordionItem.js",
32
+ "require": "./cjs/parts/accordionItem/DSAccordionItem.js"
33
+ },
34
+ "./parts/accordionContent/AccordionContent": {
35
+ "import": "./esm/parts/accordionContent/AccordionContent.js",
36
+ "require": "./cjs/parts/accordionContent/AccordionContent.js"
37
+ },
38
+ "./DSAccordionTypes": {
39
+ "import": "./esm/DSAccordionTypes.js",
40
+ "require": "./cjs/DSAccordionTypes.js"
41
+ },
42
+ "./DSAccordionDatatestid": {
43
+ "import": "./esm/DSAccordionDatatestid.js",
44
+ "require": "./cjs/DSAccordionDatatestid.js"
45
+ },
46
+ "./DSAccordionCTX": {
47
+ "import": "./esm/DSAccordionCTX.js",
48
+ "require": "./cjs/DSAccordionCTX.js"
29
49
  },
30
50
  "./DSAccordion": {
31
51
  "import": "./esm/DSAccordion.js",
32
52
  "require": "./cjs/DSAccordion.js"
33
53
  },
34
- "./blocks": {
35
- "import": "./esm/blocks.js",
36
- "require": "./cjs/blocks.js"
54
+ "./defaultProps": {
55
+ "import": "./esm/defaultProps.js",
56
+ "require": "./cjs/defaultProps.js"
57
+ },
58
+ "./config/useAccordionRefs": {
59
+ "import": "./esm/config/useAccordionRefs.js",
60
+ "require": "./cjs/config/useAccordionRefs.js"
61
+ },
62
+ "./config/useAccordion": {
63
+ "import": "./esm/config/useAccordion.js",
64
+ "require": "./cjs/config/useAccordion.js"
37
65
  }
38
66
  },
39
67
  "sideEffects": [
@@ -56,12 +84,12 @@
56
84
  "build": "node ../../scripts/build/build.js"
57
85
  },
58
86
  "dependencies": {
59
- "@elliemae/ds-button": "2.1.0-rc.6",
60
- "@elliemae/ds-classnames": "2.1.0-rc.6",
61
- "@elliemae/ds-icons": "2.1.0-rc.6",
62
- "@elliemae/ds-shared": "2.1.0-rc.6",
63
- "@elliemae/ds-system": "2.1.0-rc.6",
64
- "@elliemae/ds-truncated-tooltip-text": "2.1.0-rc.6",
87
+ "@elliemae/ds-button": "2.1.0",
88
+ "@elliemae/ds-classnames": "2.1.0",
89
+ "@elliemae/ds-icons": "2.1.0",
90
+ "@elliemae/ds-shared": "2.1.0",
91
+ "@elliemae/ds-system": "2.1.0",
92
+ "@elliemae/ds-truncated-tooltip-text": "2.1.0",
65
93
  "react-desc": "^4.1.3"
66
94
  },
67
95
  "devDependencies": {
@@ -1,56 +1,33 @@
1
1
  /// <reference path="../../../../shared/typings/react-desc.d.ts" />
2
2
  /// <reference types="react" />
3
+ import type { DSAccordionPropsT } from './DSAccordionTypes';
3
4
  declare const DSAccordion: {
4
- ({ containerProps, activeValue, children, allowMultipleOpen, contentExpandable, onChange, }: {
5
- containerProps?: {} | undefined;
6
- activeValue?: string | undefined;
7
- children: any;
8
- allowMultipleOpen?: boolean | undefined;
9
- contentExpandable?: boolean | undefined;
10
- onChange?: (() => void) | undefined;
11
- }): JSX.Element;
5
+ (props: DSAccordionPropsT): JSX.Element;
12
6
  propTypes: {
13
- /** inject props to wrapper */
14
7
  containerProps: {
15
8
  defaultValue(arg: import("react-desc").ReactDescPossibleDefaultValues): {
16
9
  deprecated: import("react-desc").PropTypesDescValidator;
17
10
  };
18
11
  isRequired: import("react-desc").PropTypesDescValue;
19
12
  };
20
- /**
21
- * Selected default active value
22
- */
23
13
  activeValue: {
24
14
  defaultValue(arg: import("react-desc").ReactDescPossibleDefaultValues): {
25
15
  deprecated: import("react-desc").PropTypesDescValidator;
26
16
  };
27
17
  isRequired: import("react-desc").PropTypesDescValue;
28
18
  };
29
- /**
30
- * Accordion items to show
31
- */
32
- children: any;
33
- /**
34
- * Allows multiple accordion items to be open at the same time
35
- */
36
- allowMultipleOpen: {
19
+ children: {
37
20
  defaultValue(arg: import("react-desc").ReactDescPossibleDefaultValues): {
38
21
  deprecated: import("react-desc").PropTypesDescValidator;
39
22
  };
40
23
  isRequired: import("react-desc").PropTypesDescValue;
41
24
  };
42
- /**
43
- * Whether content is expandable or not
44
- */
45
- contentExpandable: {
25
+ allowMultipleOpen: {
46
26
  defaultValue(arg: import("react-desc").ReactDescPossibleDefaultValues): {
47
27
  deprecated: import("react-desc").PropTypesDescValidator;
48
28
  };
49
29
  isRequired: import("react-desc").PropTypesDescValue;
50
30
  };
51
- /**
52
- * Allows a function that is triggered once the accordion changes
53
- */
54
31
  onChange: {
55
32
  defaultValue(arg: import("react-desc").ReactDescPossibleDefaultValues): {
56
33
  deprecated: import("react-desc").PropTypesDescValidator;
@@ -60,14 +37,7 @@ declare const DSAccordion: {
60
37
  };
61
38
  };
62
39
  declare const DSAccordionWithSchema: {
63
- (props?: {
64
- containerProps?: {} | undefined;
65
- activeValue?: string | undefined;
66
- children: any;
67
- allowMultipleOpen?: boolean | undefined;
68
- contentExpandable?: boolean | undefined;
69
- onChange?: (() => void) | undefined;
70
- } | undefined): JSX.Element;
40
+ (props?: DSAccordionPropsT | undefined): JSX.Element;
71
41
  propTypes: unknown;
72
42
  toTypescript: () => import("react-desc").TypescriptSchema;
73
43
  };
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ import type { DSAccordionContextT } from './DSAccordionTypes';
3
+ export declare const DSAccordionContext: import("react").Context<DSAccordionContextT>;
@@ -0,0 +1,8 @@
1
+ export declare const DSAccordionDataTestid: {
2
+ ITEM: {
3
+ CONTENT: string;
4
+ HEADER: string;
5
+ CONTAINER: string;
6
+ };
7
+ GROUP: string;
8
+ };