@stellar-expert/ui-framework 1.9.5 → 1.9.6

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.
@@ -3,27 +3,34 @@ import cn from 'classnames'
3
3
  import './accordion.scss'
4
4
 
5
5
  /**
6
- * @param {{title, content}[]} options
6
+ * Group of collapsible panels
7
+ * @param {{key: String, title: String|JSX.Element, content:*}[]} options - Accordion options
8
+ * @param {String} [collapsedSymbol] - Prefix to show for collapsed panels
9
+ * @param {String} [expandedSymbol] - Prefix to show for expanded panel
7
10
  */
8
- export function Accordion({options}) {
11
+ export function Accordion({options, collapsedSymbol = '+', expandedSymbol = '-', ...otherProps}) {
9
12
  const [selectedOption, setSelectedOption] = useState()
10
13
  useEffect(() => {
11
- setSelectedOption(options[0].title)
14
+ const firstOption = options[0]
15
+ setSelectedOption(firstOption.key || firstOption.title)
12
16
  }, [options])
13
- const changeSelected = useCallback(e => {
14
- const {title} = e.currentTarget.dataset
15
- setSelectedOption(title)
16
- }, [options])
17
- return <div className="accordion">
18
- {options.map(({title, content}) => <div key={title} className={cn('option', {open: selectedOption === title})}>
19
- <div className="accordion-header" data-title={title} onClick={changeSelected}>
20
- {title}
21
- </div>
22
- <div className="accordion-collapse">
23
- <div className="accordion-body">
24
- {content}
17
+ const changeSelected = useCallback(e => setSelectedOption(e.currentTarget.dataset.key), [options])
18
+ return <div className="accordion" {...otherProps}>
19
+ {options.map(({key, title, content}) => {
20
+ const expanded = key ?
21
+ selectedOption === key :
22
+ selectedOption === title
23
+ return <div key={key || title} className={cn('option', {expanded})}>
24
+ <div className="accordion-header" data-collapsed={collapsedSymbol} data-expanded={expandedSymbol} data-key={key || title}
25
+ onClick={changeSelected}>
26
+ {title || key}
27
+ </div>
28
+ <div className="accordion-collapse">
29
+ <div className="accordion-body">
30
+ {content}
31
+ </div>
25
32
  </div>
26
33
  </div>
27
- </div>)}
34
+ })}
28
35
  </div>
29
36
  }
@@ -5,7 +5,7 @@
5
5
  user-select: none;
6
6
 
7
7
  &:before {
8
- content: '+';
8
+ content: attr(data-collapsed);
9
9
  position: absolute;
10
10
  top: 50%;
11
11
  transform: translateY(-50%);
@@ -19,9 +19,9 @@
19
19
  }
20
20
 
21
21
  .option {
22
- &.open {
22
+ &.expanded {
23
23
  .accordion-header:before {
24
- content: '-';
24
+ content: attr(data-expanded);
25
25
  }
26
26
 
27
27
  .accordion-collapse {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stellar-expert/ui-framework",
3
- "version": "1.9.5",
3
+ "version": "1.9.6",
4
4
  "description": "StellarExpert shared UI components library",
5
5
  "main": "index.js",
6
6
  "module": "./index.js",