@elliemae/ds-accordion 2.3.0-alpha.9 → 2.3.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/DSAccordion.js +31 -0
- package/cjs/DSAccordionCTX.js +20 -0
- package/cjs/DSAccordionDatatestid.js +14 -0
- package/cjs/DSAccordionTypes.js +2 -0
- package/cjs/config/useAccordion.js +50 -0
- package/cjs/config/useAccordionRefs.js +40 -0
- package/cjs/defaultProps.js +54 -0
- package/cjs/index.js +14 -0
- package/cjs/parts/accordionContent/AccordionContent.js +41 -0
- package/cjs/parts/accordionItem/DSAccordionItem.js +206 -0
- package/cjs/parts/accordionItem/styles.js +149 -0
- package/cjs/parts/accordionItem/useAccordionItem.js +53 -0
- package/cjs/propTypes.js +26 -0
- package/esm/DSAccordion.js +21 -0
- package/esm/DSAccordionCTX.js +16 -0
- package/esm/DSAccordionDatatestid.js +10 -0
- package/esm/DSAccordionTypes.js +1 -0
- package/esm/config/useAccordion.js +46 -0
- package/esm/config/useAccordionRefs.js +32 -0
- package/esm/defaultProps.js +45 -0
- package/esm/index.js +2 -0
- package/esm/parts/accordionContent/AccordionContent.js +32 -0
- package/esm/parts/accordionItem/DSAccordionItem.js +193 -0
- package/esm/parts/accordionItem/styles.js +133 -0
- package/esm/parts/accordionItem/useAccordionItem.js +49 -0
- package/esm/propTypes.js +21 -0
- package/package.json +47 -52
- package/{dist/types → types}/DSAccordion.d.ts +0 -0
- package/{dist/types → types}/DSAccordionCTX.d.ts +0 -0
- package/{dist/types → types}/DSAccordionDatatestid.d.ts +0 -0
- package/{dist/types → types}/DSAccordionTypes.d.ts +0 -0
- package/{dist/types → types}/config/useAccordion.d.ts +0 -0
- package/{dist/types → types}/config/useAccordionRefs.d.ts +0 -0
- package/{dist/types → types}/defaultProps.d.ts +0 -0
- package/{dist/types → types}/index.d.ts +0 -0
- package/{dist/types → types}/parts/accordionContent/AccordionContent.d.ts +0 -0
- package/{dist/types → types}/parts/accordionItem/DSAccordionItem.d.ts +0 -0
- package/{dist/types → types}/parts/accordionItem/styles.d.ts +0 -0
- package/{dist/types → types}/parts/accordionItem/useAccordionItem.d.ts +0 -0
- package/{dist/types → types}/propTypes.d.ts +0 -0
- package/{dist/types → types}/tests/Accordion.test.d.ts +0 -0
- package/dist/cjs/DSAccordion.js +0 -52
- package/dist/cjs/DSAccordion.js.map +0 -7
- package/dist/cjs/DSAccordionCTX.js +0 -46
- package/dist/cjs/DSAccordionCTX.js.map +0 -7
- package/dist/cjs/DSAccordionDatatestid.js +0 -42
- package/dist/cjs/DSAccordionDatatestid.js.map +0 -7
- package/dist/cjs/DSAccordionTypes.js +0 -27
- package/dist/cjs/DSAccordionTypes.js.map +0 -7
- package/dist/cjs/config/useAccordion.js +0 -73
- package/dist/cjs/config/useAccordion.js.map +0 -7
- package/dist/cjs/config/useAccordionRefs.js +0 -47
- package/dist/cjs/config/useAccordionRefs.js.map +0 -7
- package/dist/cjs/defaultProps.js +0 -64
- package/dist/cjs/defaultProps.js.map +0 -7
- package/dist/cjs/index.js +0 -37
- package/dist/cjs/index.js.map +0 -7
- package/dist/cjs/parts/accordionContent/AccordionContent.js +0 -50
- package/dist/cjs/parts/accordionContent/AccordionContent.js.map +0 -7
- package/dist/cjs/parts/accordionItem/DSAccordionItem.js +0 -179
- package/dist/cjs/parts/accordionItem/DSAccordionItem.js.map +0 -7
- package/dist/cjs/parts/accordionItem/styles.js +0 -143
- package/dist/cjs/parts/accordionItem/styles.js.map +0 -7
- package/dist/cjs/parts/accordionItem/useAccordionItem.js +0 -66
- package/dist/cjs/parts/accordionItem/useAccordionItem.js.map +0 -7
- package/dist/cjs/propTypes.js +0 -57
- package/dist/cjs/propTypes.js.map +0 -7
- package/dist/esm/DSAccordion.js +0 -23
- package/dist/esm/DSAccordion.js.map +0 -7
- package/dist/esm/DSAccordionCTX.js +0 -17
- package/dist/esm/DSAccordionCTX.js.map +0 -7
- package/dist/esm/DSAccordionDatatestid.js +0 -13
- package/dist/esm/DSAccordionDatatestid.js.map +0 -7
- package/dist/esm/DSAccordionTypes.js +0 -2
- package/dist/esm/DSAccordionTypes.js.map +0 -7
- package/dist/esm/config/useAccordion.js +0 -44
- package/dist/esm/config/useAccordion.js.map +0 -7
- package/dist/esm/config/useAccordionRefs.js +0 -18
- package/dist/esm/config/useAccordionRefs.js.map +0 -7
- package/dist/esm/defaultProps.js +0 -35
- package/dist/esm/defaultProps.js.map +0 -7
- package/dist/esm/index.js +0 -8
- package/dist/esm/index.js.map +0 -7
- package/dist/esm/parts/accordionContent/AccordionContent.js +0 -21
- package/dist/esm/parts/accordionContent/AccordionContent.js.map +0 -7
- package/dist/esm/parts/accordionItem/DSAccordionItem.js +0 -160
- package/dist/esm/parts/accordionItem/DSAccordionItem.js.map +0 -7
- package/dist/esm/parts/accordionItem/styles.js +0 -114
- package/dist/esm/parts/accordionItem/styles.js.map +0 -7
- package/dist/esm/parts/accordionItem/useAccordionItem.js +0 -37
- package/dist/esm/parts/accordionItem/useAccordionItem.js.map +0 -7
- package/dist/esm/propTypes.js +0 -28
- package/dist/esm/propTypes.js.map +0 -7
|
@@ -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;
|
package/cjs/propTypes.js
ADDED
|
@@ -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;
|
|
@@ -0,0 +1,21 @@
|
|
|
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 };
|
|
@@ -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 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
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 };
|
|
@@ -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 { 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 };
|
|
@@ -0,0 +1,133 @@
|
|
|
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: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 => {
|
|
14
|
+
let {
|
|
15
|
+
theme,
|
|
16
|
+
withSecondaryTitle
|
|
17
|
+
} = _ref2;
|
|
18
|
+
return withSecondaryTitle ? theme.space.m : theme.space.s;
|
|
19
|
+
}, _ref3 => {
|
|
20
|
+
let {
|
|
21
|
+
disabled
|
|
22
|
+
} = _ref3;
|
|
23
|
+
return disabled ? 'not-allowed' : 'pointer';
|
|
24
|
+
}, _ref4 => {
|
|
25
|
+
let {
|
|
26
|
+
isDSMobile
|
|
27
|
+
} = _ref4;
|
|
28
|
+
return isDSMobile ? "0 16px" : "0";
|
|
29
|
+
}, _ref5 => {
|
|
30
|
+
let {
|
|
31
|
+
isDSMobile
|
|
32
|
+
} = _ref5;
|
|
33
|
+
return isDSMobile ? "flex-direction: row-reverse;" : "";
|
|
34
|
+
}, _ref6 => {
|
|
35
|
+
let {
|
|
36
|
+
theme
|
|
37
|
+
} = _ref6;
|
|
38
|
+
return theme.colors.brand[700];
|
|
39
|
+
});
|
|
40
|
+
const StyledItemContent = /*#__PURE__*/styled.div.withConfig({
|
|
41
|
+
componentId: "sc-fnpjby-2"
|
|
42
|
+
})(["margin:", ";grid-column:1/2;"], _ref7 => {
|
|
43
|
+
let {
|
|
44
|
+
isDSMobile
|
|
45
|
+
} = _ref7;
|
|
46
|
+
return isDSMobile ? "16px 16px 24px 16px" : "16px 16px 16px 32px";
|
|
47
|
+
});
|
|
48
|
+
const StyledItemAddon = /*#__PURE__*/styled.div.withConfig({
|
|
49
|
+
componentId: "sc-fnpjby-3"
|
|
50
|
+
})(["", " height:100%;width:", ";display:grid;place-items:center;& .em-ds-icon svg{fill:", ";}"], _ref8 => {
|
|
51
|
+
let {
|
|
52
|
+
theme,
|
|
53
|
+
isDSMobile
|
|
54
|
+
} = _ref8;
|
|
55
|
+
return !isDSMobile ? "padding: 0 ".concat(theme.space.xxs, ";") : "";
|
|
56
|
+
}, _ref9 => {
|
|
57
|
+
let {
|
|
58
|
+
theme
|
|
59
|
+
} = _ref9;
|
|
60
|
+
return theme.space.s;
|
|
61
|
+
}, _ref10 => {
|
|
62
|
+
let {
|
|
63
|
+
disabled,
|
|
64
|
+
theme
|
|
65
|
+
} = _ref10;
|
|
66
|
+
return disabled ? theme.colors.neutral[200] : theme.colors.brand[800];
|
|
67
|
+
});
|
|
68
|
+
const StyledItemTitles = /*#__PURE__*/styled.div.withConfig({
|
|
69
|
+
componentId: "sc-fnpjby-4"
|
|
70
|
+
})(["display:grid;grid-template-columns:100%;width:100%;align-content:center;"]);
|
|
71
|
+
const StyledPrimaryTitle = /*#__PURE__*/styled.div.withConfig({
|
|
72
|
+
componentId: "sc-fnpjby-5"
|
|
73
|
+
})(["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 => {
|
|
74
|
+
let {
|
|
75
|
+
disabled,
|
|
76
|
+
theme
|
|
77
|
+
} = _ref11;
|
|
78
|
+
return disabled ? theme.colors.neutral[200] : theme.colors.neutral[700];
|
|
79
|
+
}, _ref12 => {
|
|
80
|
+
let {
|
|
81
|
+
theme,
|
|
82
|
+
isDSMobile
|
|
83
|
+
} = _ref12;
|
|
84
|
+
return isDSMobile ? theme.fontWeights.regular : theme.fontWeights.regular;
|
|
85
|
+
}, _ref13 => {
|
|
86
|
+
let {
|
|
87
|
+
theme
|
|
88
|
+
} = _ref13;
|
|
89
|
+
return theme.space.xs;
|
|
90
|
+
});
|
|
91
|
+
const StyledSecondaryTitle = /*#__PURE__*/styled.span.withConfig({
|
|
92
|
+
componentId: "sc-fnpjby-6"
|
|
93
|
+
})(["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 => {
|
|
94
|
+
let {
|
|
95
|
+
theme
|
|
96
|
+
} = _ref14;
|
|
97
|
+
return theme.fontSizes.label[200];
|
|
98
|
+
}, _ref15 => {
|
|
99
|
+
let {
|
|
100
|
+
disabled,
|
|
101
|
+
theme
|
|
102
|
+
} = _ref15;
|
|
103
|
+
return disabled ? theme.colors.neutral[200] : theme.colors.neutral[500];
|
|
104
|
+
}, _ref16 => {
|
|
105
|
+
let {
|
|
106
|
+
theme
|
|
107
|
+
} = _ref16;
|
|
108
|
+
return theme.space.xs;
|
|
109
|
+
});
|
|
110
|
+
const StyledItemCustomActions = /*#__PURE__*/styled.div.withConfig({
|
|
111
|
+
componentId: "sc-fnpjby-7"
|
|
112
|
+
})(["display:grid;grid-auto-flow:column;grid-gap:", ";margin:0 ", ";justify-content:flex-end;"], _ref17 => {
|
|
113
|
+
let {
|
|
114
|
+
theme
|
|
115
|
+
} = _ref17;
|
|
116
|
+
return theme.space.xxs;
|
|
117
|
+
}, _ref18 => {
|
|
118
|
+
let {
|
|
119
|
+
theme
|
|
120
|
+
} = _ref18;
|
|
121
|
+
return theme.space.xs;
|
|
122
|
+
});
|
|
123
|
+
const StyledItemHeaderContainer = /*#__PURE__*/styled.div.withConfig({
|
|
124
|
+
componentId: "sc-fnpjby-8"
|
|
125
|
+
})(["display:grid;grid-template-columns:auto max-content;place-items:center;position:relative;&:hover{", "}"], _ref19 => {
|
|
126
|
+
let {
|
|
127
|
+
disabled,
|
|
128
|
+
theme
|
|
129
|
+
} = _ref19;
|
|
130
|
+
return !disabled ? "background: ".concat(theme.colors.brand[200], ";") : "";
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
export { StyledItemAddon, StyledItemContainer, StyledItemContent, StyledItemCustomActions, StyledItemHeader, StyledItemHeaderContainer, StyledItemTitles, StyledPrimaryTitle, StyledSecondaryTitle };
|