@elliemae/ds-accordion 2.3.1 → 3.0.0-alpha.3

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 (93) hide show
  1. package/dist/cjs/DSAccordion.js +52 -0
  2. package/dist/cjs/DSAccordion.js.map +7 -0
  3. package/dist/cjs/DSAccordionCTX.js +46 -0
  4. package/dist/cjs/DSAccordionCTX.js.map +7 -0
  5. package/dist/cjs/DSAccordionDatatestid.js +42 -0
  6. package/dist/cjs/DSAccordionDatatestid.js.map +7 -0
  7. package/dist/cjs/DSAccordionTypes.js +27 -0
  8. package/dist/cjs/DSAccordionTypes.js.map +7 -0
  9. package/dist/cjs/config/useAccordion.js +73 -0
  10. package/dist/cjs/config/useAccordion.js.map +7 -0
  11. package/dist/cjs/config/useAccordionRefs.js +47 -0
  12. package/dist/cjs/config/useAccordionRefs.js.map +7 -0
  13. package/dist/cjs/defaultProps.js +64 -0
  14. package/dist/cjs/defaultProps.js.map +7 -0
  15. package/dist/cjs/index.js +37 -0
  16. package/dist/cjs/index.js.map +7 -0
  17. package/dist/cjs/parts/accordionContent/AccordionContent.js +66 -0
  18. package/dist/cjs/parts/accordionContent/AccordionContent.js.map +7 -0
  19. package/dist/cjs/parts/accordionItem/DSAccordionItem.js +211 -0
  20. package/dist/cjs/parts/accordionItem/DSAccordionItem.js.map +7 -0
  21. package/dist/cjs/parts/accordionItem/styles.js +143 -0
  22. package/dist/cjs/parts/accordionItem/styles.js.map +7 -0
  23. package/dist/cjs/parts/accordionItem/useAccordionItem.js +66 -0
  24. package/dist/cjs/parts/accordionItem/useAccordionItem.js.map +7 -0
  25. package/dist/cjs/propTypes.js +57 -0
  26. package/dist/cjs/propTypes.js.map +7 -0
  27. package/dist/esm/DSAccordion.js +23 -0
  28. package/dist/esm/DSAccordion.js.map +7 -0
  29. package/dist/esm/DSAccordionCTX.js +17 -0
  30. package/dist/esm/DSAccordionCTX.js.map +7 -0
  31. package/dist/esm/DSAccordionDatatestid.js +13 -0
  32. package/dist/esm/DSAccordionDatatestid.js.map +7 -0
  33. package/dist/esm/DSAccordionTypes.js +2 -0
  34. package/dist/esm/DSAccordionTypes.js.map +7 -0
  35. package/dist/esm/config/useAccordion.js +44 -0
  36. package/dist/esm/config/useAccordion.js.map +7 -0
  37. package/dist/esm/config/useAccordionRefs.js +18 -0
  38. package/dist/esm/config/useAccordionRefs.js.map +7 -0
  39. package/dist/esm/defaultProps.js +35 -0
  40. package/dist/esm/defaultProps.js.map +7 -0
  41. package/dist/esm/index.js +8 -0
  42. package/dist/esm/index.js.map +7 -0
  43. package/dist/esm/parts/accordionContent/AccordionContent.js +39 -0
  44. package/dist/esm/parts/accordionContent/AccordionContent.js.map +7 -0
  45. package/dist/esm/parts/accordionItem/DSAccordionItem.js +194 -0
  46. package/dist/esm/parts/accordionItem/DSAccordionItem.js.map +7 -0
  47. package/dist/esm/parts/accordionItem/styles.js +114 -0
  48. package/dist/esm/parts/accordionItem/styles.js.map +7 -0
  49. package/dist/esm/parts/accordionItem/useAccordionItem.js +37 -0
  50. package/dist/esm/parts/accordionItem/useAccordionItem.js.map +7 -0
  51. package/dist/esm/propTypes.js +28 -0
  52. package/dist/esm/propTypes.js.map +7 -0
  53. package/package.json +59 -49
  54. package/cjs/DSAccordion.js +0 -31
  55. package/cjs/DSAccordionCTX.js +0 -20
  56. package/cjs/DSAccordionDatatestid.js +0 -14
  57. package/cjs/DSAccordionTypes.js +0 -2
  58. package/cjs/config/useAccordion.js +0 -50
  59. package/cjs/config/useAccordionRefs.js +0 -40
  60. package/cjs/defaultProps.js +0 -54
  61. package/cjs/index.js +0 -14
  62. package/cjs/parts/accordionContent/AccordionContent.js +0 -41
  63. package/cjs/parts/accordionItem/DSAccordionItem.js +0 -206
  64. package/cjs/parts/accordionItem/styles.js +0 -149
  65. package/cjs/parts/accordionItem/useAccordionItem.js +0 -53
  66. package/cjs/propTypes.js +0 -26
  67. package/esm/DSAccordion.js +0 -21
  68. package/esm/DSAccordionCTX.js +0 -16
  69. package/esm/DSAccordionDatatestid.js +0 -10
  70. package/esm/DSAccordionTypes.js +0 -1
  71. package/esm/config/useAccordion.js +0 -46
  72. package/esm/config/useAccordionRefs.js +0 -32
  73. package/esm/defaultProps.js +0 -45
  74. package/esm/index.js +0 -2
  75. package/esm/parts/accordionContent/AccordionContent.js +0 -32
  76. package/esm/parts/accordionItem/DSAccordionItem.js +0 -193
  77. package/esm/parts/accordionItem/styles.js +0 -133
  78. package/esm/parts/accordionItem/useAccordionItem.js +0 -49
  79. package/esm/propTypes.js +0 -21
  80. package/types/DSAccordion.d.ts +0 -45
  81. package/types/DSAccordionCTX.d.ts +0 -3
  82. package/types/DSAccordionDatatestid.d.ts +0 -8
  83. package/types/DSAccordionTypes.d.ts +0 -137
  84. package/types/config/useAccordion.d.ts +0 -2
  85. package/types/config/useAccordionRefs.d.ts +0 -2
  86. package/types/defaultProps.d.ts +0 -3
  87. package/types/index.d.ts +0 -4
  88. package/types/parts/accordionContent/AccordionContent.d.ts +0 -2
  89. package/types/parts/accordionItem/DSAccordionItem.d.ts +0 -53
  90. package/types/parts/accordionItem/styles.d.ts +0 -10
  91. package/types/parts/accordionItem/useAccordionItem.d.ts +0 -2
  92. package/types/propTypes.d.ts +0 -73
  93. package/types/tests/Accordion.test.d.ts +0 -1
@@ -1,149 +0,0 @@
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:flex;height:", ";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
- theme,
24
- withSecondaryTitle
25
- } = _ref2;
26
- return withSecondaryTitle ? theme.space.m : theme.space.s;
27
- }, _ref3 => {
28
- let {
29
- disabled
30
- } = _ref3;
31
- return disabled ? 'not-allowed' : 'pointer';
32
- }, _ref4 => {
33
- let {
34
- isDSMobile
35
- } = _ref4;
36
- return isDSMobile ? "0 16px" : "0";
37
- }, _ref5 => {
38
- let {
39
- isDSMobile
40
- } = _ref5;
41
- return isDSMobile ? "flex-direction: row-reverse;" : "";
42
- }, _ref6 => {
43
- let {
44
- theme
45
- } = _ref6;
46
- return theme.colors.brand[700];
47
- });
48
- const StyledItemContent = /*#__PURE__*/styled__default["default"].div.withConfig({
49
- componentId: "sc-fnpjby-2"
50
- })(["margin:", ";grid-column:1/2;"], _ref7 => {
51
- let {
52
- isDSMobile
53
- } = _ref7;
54
- return isDSMobile ? "16px 16px 24px 16px" : "16px 16px 16px 32px";
55
- });
56
- const StyledItemAddon = /*#__PURE__*/styled__default["default"].div.withConfig({
57
- componentId: "sc-fnpjby-3"
58
- })(["", " height:100%;width:", ";display:grid;place-items:center;& .em-ds-icon svg{fill:", ";}"], _ref8 => {
59
- let {
60
- theme,
61
- isDSMobile
62
- } = _ref8;
63
- return !isDSMobile ? "padding: 0 ".concat(theme.space.xxs, ";") : "";
64
- }, _ref9 => {
65
- let {
66
- theme
67
- } = _ref9;
68
- return theme.space.s;
69
- }, _ref10 => {
70
- let {
71
- disabled,
72
- theme
73
- } = _ref10;
74
- return disabled ? theme.colors.neutral[200] : theme.colors.brand[800];
75
- });
76
- const StyledItemTitles = /*#__PURE__*/styled__default["default"].div.withConfig({
77
- componentId: "sc-fnpjby-4"
78
- })(["display:grid;grid-template-columns:100%;width:100%;align-content:center;"]);
79
- const StyledPrimaryTitle = /*#__PURE__*/styled__default["default"].div.withConfig({
80
- componentId: "sc-fnpjby-5"
81
- })(["margin:0;font-size:16px;color:", ";font-weight:", ";text-overflow:ellipsis;overflow:hidden;height:", ";width:100%;text-align:left;display:block;white-space:nowrap;"], _ref11 => {
82
- let {
83
- disabled,
84
- theme
85
- } = _ref11;
86
- return disabled ? theme.colors.neutral[200] : theme.colors.neutral[700];
87
- }, _ref12 => {
88
- let {
89
- theme,
90
- isDSMobile
91
- } = _ref12;
92
- return isDSMobile ? theme.fontWeights.regular : theme.fontWeights.regular;
93
- }, _ref13 => {
94
- let {
95
- theme
96
- } = _ref13;
97
- return theme.space.xs;
98
- });
99
- const StyledSecondaryTitle = /*#__PURE__*/styled__default["default"].span.withConfig({
100
- componentId: "sc-fnpjby-6"
101
- })(["margin:0;font-size:", ";text-align:left;color:", ";text-overflow:ellipsis;overflow:hidden;height:", ";width:100%;text-align:left;display:block;white-space:nowrap;"], _ref14 => {
102
- let {
103
- theme
104
- } = _ref14;
105
- return theme.fontSizes.label[200];
106
- }, _ref15 => {
107
- let {
108
- disabled,
109
- theme
110
- } = _ref15;
111
- return disabled ? theme.colors.neutral[200] : theme.colors.neutral[500];
112
- }, _ref16 => {
113
- let {
114
- theme
115
- } = _ref16;
116
- return theme.space.xs;
117
- });
118
- const StyledItemCustomActions = /*#__PURE__*/styled__default["default"].div.withConfig({
119
- componentId: "sc-fnpjby-7"
120
- })(["display:grid;grid-auto-flow:column;grid-gap:", ";margin:0 ", ";justify-content:flex-end;"], _ref17 => {
121
- let {
122
- theme
123
- } = _ref17;
124
- return theme.space.xxs;
125
- }, _ref18 => {
126
- let {
127
- theme
128
- } = _ref18;
129
- return theme.space.xs;
130
- });
131
- const StyledItemHeaderContainer = /*#__PURE__*/styled__default["default"].div.withConfig({
132
- componentId: "sc-fnpjby-8"
133
- })(["display:grid;grid-template-columns:auto max-content;place-items:center;position:relative;&:hover{", "}"], _ref19 => {
134
- let {
135
- disabled,
136
- theme
137
- } = _ref19;
138
- return !disabled ? "background: ".concat(theme.colors.brand[200], ";") : "";
139
- });
140
-
141
- exports.StyledItemAddon = StyledItemAddon;
142
- exports.StyledItemContainer = StyledItemContainer;
143
- exports.StyledItemContent = StyledItemContent;
144
- exports.StyledItemCustomActions = StyledItemCustomActions;
145
- exports.StyledItemHeader = StyledItemHeader;
146
- exports.StyledItemHeaderContainer = StyledItemHeaderContainer;
147
- exports.StyledItemTitles = StyledItemTitles;
148
- exports.StyledPrimaryTitle = StyledPrimaryTitle;
149
- exports.StyledSecondaryTitle = StyledSecondaryTitle;
@@ -1,53 +0,0 @@
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;
package/cjs/propTypes.js DELETED
@@ -1,26 +0,0 @@
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,21 +0,0 @@
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, {})));
16
- };
17
-
18
- const DSAccordionWithSchema = describe(DSAccordion);
19
- DSAccordionWithSchema.propTypes = accordionPropTypes;
20
-
21
- export { DSAccordion, DSAccordionWithSchema, DSAccordion as default };
@@ -1,16 +0,0 @@
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 };
@@ -1,10 +0,0 @@
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 };
@@ -1 +0,0 @@
1
-
@@ -1,46 +0,0 @@
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 };
@@ -1,32 +0,0 @@
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 };
@@ -1,45 +0,0 @@
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 DELETED
@@ -1,2 +0,0 @@
1
- export { DSAccordion, DSAccordionWithSchema, DSAccordion as default } from './DSAccordion.js';
2
- export { DSAccordionItem, DSAccordionItemWithSchema } from './parts/accordionItem/DSAccordionItem.js';
@@ -1,32 +0,0 @@
1
- import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
2
- import 'core-js/modules/esnext.async-iterator.for-each.js';
3
- import 'core-js/modules/esnext.iterator.constructor.js';
4
- import 'core-js/modules/esnext.iterator.for-each.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';
10
- import { jsx } from 'react/jsx-runtime';
11
-
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; }
13
-
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; }
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
29
- }));
30
- };
31
-
32
- export { AccordionContent };
@@ -1,193 +0,0 @@
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 { useIsShowingEllipsis } from '@elliemae/ds-utilities';
18
- import { accordionItemDefaultProps } from '../../defaultProps.js';
19
- import { StyledItemCustomActions, StyledPrimaryTitle, StyledSecondaryTitle, StyledItemContainer, StyledItemHeaderContainer, StyledItemHeader, StyledItemAddon, StyledItemTitles, StyledItemContent } from './styles.js';
20
- import { accordionItemPropTypes } from '../../propTypes.js';
21
- import { useAccordionItem } from './useAccordionItem.js';
22
- import { DSAccordionContext } from '../../DSAccordionCTX.js';
23
- import { DSAccordionDataTestid } from '../../DSAccordionDatatestid.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 };