@nestio/pam 2.0.5 → 2.0.7

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 (51) hide show
  1. package/README.md +26 -0
  2. package/examples/components/Select.jsx +38 -0
  3. package/examples/index.html +5 -0
  4. package/lib/components/Collapse.js +50 -0
  5. package/lib/components/MultiSelect.js +5 -1
  6. package/lib/components/MultiSelectOption.js +22 -3
  7. package/lib/components/OptionListSet.js +11 -3
  8. package/lib/components/SelectCore.js +84 -26
  9. package/lib/components/SelectOption.js +44 -11
  10. package/lib/components/SingleSelect.js +2 -0
  11. package/lib/components/TagBoxMenuSelect.js +2 -0
  12. package/lib/components/styles/MultiSelectOption.scss +4 -0
  13. package/lib/components/styles/SelectOption.scss +12 -0
  14. package/lib/components/styles/_variables.scss +1 -0
  15. package/lib/components/styles/icons/icons.css +1 -57
  16. package/lib/constants.js +7 -0
  17. package/package.json +3 -3
  18. package/src/components/Collapse.jsx +30 -0
  19. package/src/components/MultiSelect.jsx +4 -0
  20. package/src/components/MultiSelectOption.jsx +21 -3
  21. package/src/components/OptionListSet.jsx +9 -2
  22. package/src/components/SelectCore.jsx +62 -11
  23. package/src/components/SelectOption.jsx +27 -8
  24. package/src/components/SingleSelect.jsx +2 -0
  25. package/src/components/TagBoxMenuSelect.jsx +2 -0
  26. package/src/components/__tests__/Collapse.spec.js +26 -0
  27. package/src/components/__tests__/MultiSelect.spec.js +2 -0
  28. package/src/components/__tests__/MultiSelectOption.spec.js +42 -2
  29. package/src/components/__tests__/OptionListSet.spec.js +24 -1
  30. package/src/components/__tests__/SelectCore.spec.js +103 -0
  31. package/src/components/__tests__/SelectOption.spec.js +33 -2
  32. package/src/components/__tests__/SingleSelectOption.spec.js +2 -1
  33. package/src/components/styles/MultiSelectOption.scss +4 -0
  34. package/src/components/styles/SelectOption.scss +12 -0
  35. package/src/components/styles/_variables.scss +1 -0
  36. package/src/components/styles/icons/icons.css +1 -57
  37. package/src/constants.js +2 -0
  38. package/.idea/inspectionProfiles/profiles_settings.xml +0 -6
  39. package/.idea/misc.xml +0 -7
  40. package/.idea/modules.xml +0 -8
  41. package/.idea/pam.iml +0 -11
  42. package/.idea/vcs.xml +0 -6
  43. package/.idea/workspace.xml +0 -78
  44. package/lib/components/styles/icons/05a4d7fb.eot +0 -0
  45. package/lib/components/styles/icons/05a4d7fb.otf +0 -0
  46. package/lib/components/styles/icons/05a4d7fb.ttf +0 -0
  47. package/lib/components/styles/icons/05a4d7fb.woff +0 -0
  48. package/src/components/styles/icons/05a4d7fb.eot +0 -0
  49. package/src/components/styles/icons/05a4d7fb.otf +0 -0
  50. package/src/components/styles/icons/05a4d7fb.ttf +0 -0
  51. package/src/components/styles/icons/05a4d7fb.woff +0 -0
@@ -1,57 +1 @@
1
- @font-face {
2
- font-family: 'Pam';
3
- src: url('./05a4d7fb.eot');
4
- src: url('./05a4d7fb.eot?#iefix') format('embedded-opentype'),
5
- url('./05a4d7fb.woff') format('woff'),
6
- url('./05a4d7fb.ttf') format('truetype'),
7
- url('./05a4d7fb.otf') format('opentype');
8
- font-weight: normal;
9
- font-style: normal;
10
- }
11
-
12
- .pamicon {
13
- display: inline-block;
14
- font: normal normal normal 14px/1 'Pam';
15
- font-size: inherit;
16
- text-rendering: auto;
17
- -webkit-font-smoothing: antialiased;
18
- -moz-osx-font-smoothing: grayscale;
19
- }
20
-
21
- .pamicon-lg {
22
- font-size: 1.33333333em;
23
- line-height: 0.75em;
24
- vertical-align: -15%;
25
- }
26
-
27
- .pamicon-2x {
28
- font-size: 2em;
29
- }
30
-
31
- .pamicon-3x {
32
- font-size: 3em;
33
- }
34
-
35
- .pamicon-4x {
36
- font-size: 4em;
37
- }
38
-
39
- .pamicon-5x {
40
- font-size: 5em;
41
- }
42
-
43
- .pamicon-checkbox-checked:before {
44
- content: '\f000';
45
- }
46
-
47
- .pamicon-checkbox-unchecked:before {
48
- content: '\f001';
49
- }
50
-
51
- .pamicon-triangle-down:before {
52
- content: '\f002';
53
- }
54
-
55
- .pamicon-checkbox-intermediate:before {
56
- content: '\f003';
57
- }
1
+ @font-face{font-family:Pam;src:url(data:application/font-woff;charset=utf-8;base64,d09GRgABAAAAAATQAA0AAAAABsgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABGRlRNAAAEtAAAABoAAAAcks96/k9TLzIAAAGgAAAARQAAAGAQ+ZEfY21hcAAAAggAAABRAAABWuAdGx9jdnQgAAACXAAAAAQAAAAEACECf2dhc3AAAASsAAAACAAAAAj//wADZ2x5ZgAAAngAAADxAAABNEdgU4hoZWFkAAABMAAAADAAAAA2HSPkrWhoZWEAAAFgAAAAHgAAACQHrQSMaG10eAAAAegAAAAeAAAAMCG7ACFsb2NhAAACYAAAABgAAAAaAfQBvG1heHAAAAGAAAAAHwAAACAAUAA7bmFtZQAAA2wAAAD1AAABlVlRUkBwb3N0AAAEZAAAAEgAAAByU/Amd3jaY2BkYGAAYsH2usp4fpuvDNzMH4AiDHe5AioQ9P8C5g/MCUAuBwMTSBQAI7oKXHjaY2BkYGBOYJjAEM38gYHh/38gCRRBATwAeuwFQQAAeNpjYGRgYOBh4GJgYgABEMnIABJzYNADCQAABYsAjAB42mNgYS5knMDAysDA1M90kIGBoRdCMz5mMGJkAYoysDIzwACjAAMaaGBg+MDKnPC/gCGaOYFhApDLiCSrwMAIADXCCrEAAAB42mPMYVBkAALGAAYG5g+YmOkzgmasZGAAAMeCCPYAAHjaY2BgYGaAYBkGRgYQCAHyGMF8FgYLIM3FwMHABIQMDLwMCh9Y//8HqwKxGYBs5v/f/z8VYIPqhQJGNoiRYDZIJwsDKgCqZmUY3gAAnJMLMAAAAAAhAn942mNgYNBCgm4MMQxZDA0MfQyzAB+6A7F42m2OsUrDYBSFz7nXNEQc8gvFjv2REnBQsLhlcMxTlAwdM3TOA3Ry6CMEJ9fkCcSlL+EgDkUEpUPGJPX/oYKDw4XLOfc750JgAV5JBUWI65q4SZvwBF+39Sh4TRsVt6JWLwdebsIRu7Sh1+fGmmRuLi2jj+1Wqj63sgAEOKx0rzkCRMCMCZOQ7pYvfCiGt8dC0y7OjrucdrHugb+c/wUX1tiZozLNu0qfHKF59ntLN4W03HnKWEo7rLkb1v/k8M6OfbtO+meddDGnm43cH4N8zqe0svRURMuSZX8mS5/kvMM3S3n33tiQ5bmv+QHc5E1JAAAAeNpVjjFqw0AQRZ8s2SEQUocUYbtUcqQN2GDSmICbNMaFexVCGGwJVjI+Q26SKqTIOXKBlLlIvqxpvMvsvpnZ+X+BWz6JGNYN98YRMU/GI654NY554N04UfZlPNbsj/FE9T9FlFwruztP9Ryp82g8ku+zccwLb8aJ3nwYjzX7bTzR/mVFQ6DDseRESav8oJtVEzq3PJVtc1C2plCZdaFjo3bFkb1qQWlZHfeFoJeqJTVIVnrl8EzJdC8Ug8bAM1LmCq+uJ+/t6k6WVen8NHMLJyeds3Se+sznlx/YSjrop7uzodP4YMK2DO2uqV0uiYuRf+FJNRMAAAB42mNgYgCD/00MRgzYAA8QMzIwMTIxMjMwM7IwsjKyMbIzcjBysviF+vgwOQexl+ZluhkYGEBpQyhtBKWNobQJlDYFAGghENcAAAAB//8AAnjaY2BgYGQAghu7bvGC6LtcARUwGgBF4AXZAAA=) format('woff');font-weight:400;font-style:normal}.pamicon{display:inline-block;font:normal normal normal 14px/1 Pam;font-size:inherit;text-rendering:auto;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.pamicon-lg{font-size:1.33333333em;line-height:.75em;vertical-align:-15%}.pamicon-2x{font-size:2em}.pamicon-3x{font-size:3em}.pamicon-4x{font-size:4em}.pamicon-5x{font-size:5em}.pamicon-checkbox-checked:before{content:'\f000'}.pamicon-checkbox-unchecked:before{content:'\f001'}.pamicon-triangle-down:before{content:'\f002'}.pamicon-checkbox-intermediate:before{content:'\f003'}.pamicon-triangle-up:before{content:'\f004'}.pamicon-triangle-right:before{content:'\f005'}.sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);border:0}.sr-only-focusable:active,.sr-only-focusable:focus{position:static;width:auto;height:auto;margin:0;overflow:visible;clip:auto}
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var OPTION_COLLAPSED = exports.OPTION_COLLAPSED = 'option-collapsed';
7
+ var OPTION_NOT_COLLAPSED = exports.OPTION_NOT_COLLAPSED = 'option-not-collapsed';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestio/pam",
3
- "version": "2.0.5",
3
+ "version": "2.0.7",
4
4
  "description": "Nestio UI modules",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -23,8 +23,8 @@
23
23
  "front-end",
24
24
  "elements"
25
25
  ],
26
- "author": "Nestio",
27
- "license": "UNLICENSED",
26
+ "author": "Funnel Leasing, Inc.",
27
+ "license": "MIT",
28
28
  "bugs": {
29
29
  "url": "https://github.com/Nestio/pam/issues"
30
30
  },
@@ -0,0 +1,30 @@
1
+ import cn from 'classnames';
2
+ import PropTypes from 'prop-types';
3
+ import React from 'react';
4
+
5
+ import { OPTION_COLLAPSED } from '../constants';
6
+ import icons from './styles/icons/icons.css';
7
+ import styles from './styles/SelectOption.scss';
8
+
9
+ export default function Collapse ({onClick, collapsibleState}) {
10
+ return (
11
+ <span
12
+ onClick={onClick}
13
+ className={styles['collapse']}
14
+ role="button"
15
+ >
16
+ <i className={
17
+ cn(
18
+ icons.pamicon,
19
+ collapsibleState == OPTION_COLLAPSED ? icons['pamicon-triangle-right'] : icons['pamicon-triangle-down'],
20
+ styles['collapse-icon']
21
+ )
22
+ } />
23
+ </span>
24
+ );
25
+ }
26
+
27
+ Collapse.propTypes = {
28
+ onClick: PropTypes.func,
29
+ collapsibleState: PropTypes.string
30
+ };
@@ -30,17 +30,20 @@ export default function MultiSelect (props){
30
30
  onClose={props.onClose}
31
31
  onOpen={props.onOpen}
32
32
  options={props.options}
33
+ optionSets={props.optionSets}
33
34
  renderOptionLabel={props.renderOptionLabel}
34
35
  renderValueLabel={props.renderValueLabel}
35
36
  value={props.value}
36
37
  valueAdapter={valueAdapter}
37
38
  ValueComponent={props.ValueComponent}
39
+ collapsibleOptions={props.collapsibleOptions}
38
40
  />
39
41
  );
40
42
  }
41
43
 
42
44
  MultiSelect.propTypes = {
43
45
  ariaLabel: PropTypes.string,
46
+ collapsibleOptions: PropTypes.array,
44
47
  filterable: PropTypes.bool,
45
48
  menuContainerClassName: PropTypes.string,
46
49
  menuContainerText: PropTypes.string,
@@ -50,6 +53,7 @@ MultiSelect.propTypes = {
50
53
  onClose: PropTypes.func,
51
54
  onOpen: PropTypes.func,
52
55
  options: PropTypes.array.isRequired,
56
+ optionSets: PropTypes.array,
53
57
  renderOptionLabel: PropTypes.func,
54
58
  renderValueLabel: PropTypes.func,
55
59
  value: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
@@ -10,11 +10,27 @@ import styles from './styles/MultiSelectOption.scss';
10
10
  OptionComponent designed for use in MultiSelects
11
11
  */
12
12
  export default function MultiSelectOption (props) {
13
- const { isSelected, isHighlighted, option } = props;
13
+ const { isSelected, isHighlighted, option, currentText, collapsibleOptions } = props;
14
+
15
+ function _getCollapsibleClassName(){
16
+ if (currentText) {
17
+ return null;
18
+ }
19
+
20
+ if (collapsibleOptions && collapsibleOptions.length) {
21
+ if (option.collapsedBy && collapsibleOptions.indexOf(option.collapsedBy) > -1) {
22
+ return styles['option__indented'];
23
+ }
24
+ }
25
+
26
+ return null;
27
+ }
28
+
14
29
  const optionClass = classnames(
15
30
  styles.option,
16
31
  option.disabled && styles.disabled,
17
- isHighlighted && styles.highlighted
32
+ isHighlighted && styles.highlighted,
33
+ _getCollapsibleClassName()
18
34
  );
19
35
 
20
36
  const checkboxClass = classnames({[styles.checked]: isSelected}, {[styles.unchecked]: !isSelected});
@@ -35,7 +51,9 @@ MultiSelectOption.propTypes = {
35
51
  isHighlighted: PropTypes.bool.isRequired,
36
52
  isSelected: PropTypes.bool.isRequired,
37
53
  option: PropTypes.object.isRequired,
38
- renderOptionLabel: PropTypes.func
54
+ renderOptionLabel: PropTypes.func,
55
+ collapsibleOptions: PropTypes.array,
56
+ currentText: PropTypes.string
39
57
  };
40
58
 
41
59
  MultiSelectOption.defaultProps = {
@@ -81,13 +81,13 @@ export default class OptionListSet extends Component {
81
81
  }
82
82
 
83
83
  renderOptionSet(options, label) {
84
- const { OptionComponent, EmptyOptionComponent, renderOptionLabel, optionIndex, valueIsSelected, optionSets } = this.props;
85
-
84
+ const { OptionComponent, EmptyOptionComponent, renderOptionLabel, optionIndex, valueIsSelected, optionSets, getCollapsibleState } = this.props;
86
85
  let renderedOptions;
87
86
 
88
87
  if (options.length) {
89
88
  renderedOptions = options.map((option, index) => {
90
89
  index += option.groupIndex || 0;
90
+
91
91
  const rendered = (
92
92
  <OptionComponent
93
93
  id={this.getOptionId(option, index)}
@@ -97,6 +97,7 @@ export default class OptionListSet extends Component {
97
97
  isSelected={valueIsSelected(option)}
98
98
  renderOptionLabel={renderOptionLabel}
99
99
  isHighlighted={index === optionIndex}
100
+ collapsibleState={getCollapsibleState(option.value)}
100
101
  {...this.props}
101
102
  />
102
103
  );
@@ -206,6 +207,7 @@ OptionListSet.propTypes = {
206
207
  OptionComponent
207
208
  */
208
209
  renderOptionLabel: PropTypes.func,
210
+
209
211
  /**
210
212
  Currently highlighted option
211
213
  */
@@ -214,6 +216,11 @@ OptionListSet.propTypes = {
214
216
  OptionComponent to be rendered in OptionList
215
217
  */
216
218
  OptionComponent: PropTypes.func,
219
+ /**
220
+ Function used to determine if an option is collapsed and can be collapsed
221
+ */
222
+
223
+ getCollapsibleState: PropTypes.func,
217
224
  /**
218
225
  Function used to determine if individual options are selected
219
226
  */
@@ -10,6 +10,8 @@ import uniqueId from 'lodash/uniqueId';
10
10
 
11
11
  import styles from './styles/SelectCore.scss';
12
12
 
13
+ import { OPTION_COLLAPSED, OPTION_NOT_COLLAPSED } from '../constants';
14
+
13
15
  /**
14
16
  The primary Select component which manages the state for the entire select and renders subcomponents. It controls
15
17
  whether the dropdown is opened/closed, which option is currently selected, which open has focus, filtering options
@@ -28,6 +30,7 @@ class SelectCore extends Component {
28
30
  this.changeValue = this.changeValue.bind(this);
29
31
  this.clearValue = this.clearValue.bind(this);
30
32
  this.closeMenu = this.closeMenu.bind(this);
33
+ this.getCollapsibleState = this.getCollapsibleState.bind(this);
31
34
  this.onBackspace = this.onBackspace.bind(this);
32
35
  this.onDown = this.onDown.bind(this);
33
36
  this.onEnter = this.onEnter.bind(this);
@@ -37,6 +40,7 @@ class SelectCore extends Component {
37
40
  this.onEscape = this.onEscape.bind(this);
38
41
  this.openMenu = this.openMenu.bind(this);
39
42
  this.setIndex = this.setIndex.bind(this);
43
+ this.toggleCollapsedValue = this.toggleCollapsedValue.bind(this);
40
44
  this.toggleValue = this.toggleValue.bind(this);
41
45
  this.valueIsSelected = this.valueIsSelected.bind(this);
42
46
 
@@ -48,7 +52,8 @@ class SelectCore extends Component {
48
52
  isOpen: false,
49
53
  optionIndex: this._getInitialOptionIndex(props),
50
54
  options: props.options || null,
51
- loading: false
55
+ loading: false,
56
+ collapsedOptions: {}
52
57
  };
53
58
 
54
59
  this.menuRef = React.createRef();
@@ -102,10 +107,16 @@ class SelectCore extends Component {
102
107
  }
103
108
 
104
109
  componentDidUpdate(prevProps, prevState) {
105
- const { onOptionsFiltered } = this.props;
110
+ const { onOptionsFiltered, onChangeText } = this.props;
111
+
112
+ if (prevState.currentText !== this.state.currentText) {
113
+ if (onOptionsFiltered) {
114
+ onOptionsFiltered(this._getFilteredOptions());
115
+ }
106
116
 
107
- if (onOptionsFiltered && prevState.currentText !== this.state.currentText) {
108
- onOptionsFiltered(this._getFilteredOptions());
117
+ if (onChangeText) {
118
+ onChangeText(this.state.currentText);
119
+ }
109
120
  }
110
121
  }
111
122
 
@@ -351,6 +362,17 @@ class SelectCore extends Component {
351
362
  });
352
363
  }
353
364
 
365
+ toggleCollapsedValue(value){
366
+ this.setState(currentState => {
367
+ const currentCollapsedState = !!currentState.collapsedOptions[value];
368
+ const newValue = Object.assign({}, currentState.collapsedOptions, {[value]: !currentCollapsedState});
369
+
370
+ return {
371
+ collapsedOptions: newValue
372
+ };
373
+ });
374
+ }
375
+
354
376
  // Async functions
355
377
  /**
356
378
  * This is typically triggered when the select gets passed a new value and is used to populate the select with the
@@ -400,6 +422,29 @@ class SelectCore extends Component {
400
422
  return this.props.valueAdapter.valueIsSelected(this.state.currentValue, newValue);
401
423
  }
402
424
 
425
+ getCollapsibleState(value){
426
+ if (!this.props.collapsibleOptions) {
427
+ return null;
428
+ }
429
+
430
+ if (this.state.currentText) {
431
+ return null;
432
+ }
433
+
434
+ const isCollapsible = this.props.collapsibleOptions.indexOf(value) > -1;
435
+
436
+ if (!isCollapsible) {
437
+ return null;
438
+ }
439
+
440
+
441
+ if (this.state.collapsedOptions[value]) {
442
+ return OPTION_COLLAPSED;
443
+ }
444
+
445
+ return OPTION_NOT_COLLAPSED;
446
+ }
447
+
403
448
  // Private methods and helpers
404
449
  /**
405
450
  * Returns options filtered by props.filterOption and currentText. Is memoized to reduce repeating same computation
@@ -415,13 +460,19 @@ class SelectCore extends Component {
415
460
  return this.state.options;
416
461
  }
417
462
 
418
- const args = [this.state.options, this.props.filterOption, text];
419
- if (this._cachedArgs && this._cachedArgs[0] == args[0] && this._cachedArgs[1] == args[1] && this._cachedArgs[2] == args[2]) {
463
+ const args = [this.state.options, this.props.filterOption, text, this.state.collapsedOptions];
464
+ if (this._cachedArgs && this._cachedArgs.every((arg, i) => args[i] === arg)) {
420
465
  return this._cachedResult;
421
466
  }
422
467
 
423
468
  this._cachedArgs = args;
424
469
  this._cachedResult = this.state.options.filter((option) => {
470
+ if (!text && option.hasOwnProperty('collapsedBy')) {
471
+ const isHidden = this.getCollapsibleState(option.collapsedBy) === OPTION_COLLAPSED;
472
+ if (isHidden) {
473
+ return false;
474
+ }
475
+ }
425
476
  return this.props.filterOption(option, text);
426
477
  });
427
478
 
@@ -540,6 +591,7 @@ class SelectCore extends Component {
540
591
  setIndex: this.setIndex,
541
592
  shouldShowOptionList: this._shouldShowOptionList(),
542
593
  toggleValue: this.toggleValue,
594
+ toggleCollapsedValue: this.toggleCollapsedValue
543
595
  });
544
596
  }
545
597
 
@@ -552,6 +604,7 @@ class SelectCore extends Component {
552
604
  <MenuComponent
553
605
  options={options}
554
606
  valueIsSelected={this.valueIsSelected}
607
+ getCollapsibleState={this.getCollapsibleState}
555
608
  OptionComponent={OptionComponent}
556
609
  renderOptionLabel={renderOptionLabel}
557
610
  onUp={this.onUp}
@@ -626,11 +679,6 @@ SelectCore.propTypes = {
626
679
  */
627
680
  filterOption: PropTypes.func,
628
681
  /**
629
- Function intercepts input value change
630
- * @param {string} str
631
- */
632
- handleValueChange: PropTypes.func,
633
- /**
634
682
  Function used to fetch async options. Is invoked with currentText and should return a promise with the options
635
683
  * @param {string} str
636
684
  * @returns {Promise}
@@ -733,6 +781,9 @@ SelectCore.propTypes = {
733
781
  disabled: PropTypes.bool,
734
782
  filterable: PropTypes.bool,
735
783
  onOptionsFiltered: PropTypes.func,
784
+ onChangeText: PropTypes.func,
785
+ collapsibleOptions: PropTypes.array
786
+
736
787
  };
737
788
 
738
789
  SelectCore.defaultProps = {
@@ -1,7 +1,9 @@
1
- import React, { Component } from 'react';
1
+ import cn from 'classnames';
2
+ import isEqual from 'lodash/isEqual';
2
3
  import PropTypes from 'prop-types';
4
+ import React, { Component } from 'react';
3
5
 
4
- import isEqual from 'lodash/isEqual';
6
+ import Collapse from './Collapse';
5
7
 
6
8
  /**
7
9
  * Generic component for rendering an option in a select. Contains functionality for handling clicking and focusing.
@@ -11,12 +13,13 @@ export default class SelectOption extends Component {
11
13
  super();
12
14
  this.onClick = this.onClick.bind(this);
13
15
  this.onMouseEnter = this.onMouseEnter.bind(this);
16
+ this.onCollapseClick = this.onCollapseClick.bind(this);
14
17
  }
15
18
 
16
19
  shouldComponentUpdate(nextProps) {
17
20
  // check only interesting props
18
21
  const currentProps = this.props;
19
- const propsToCheck = ['isSelected', 'option', 'disabled', 'isHighlighted'];
22
+ const propsToCheck = ['isSelected', 'option', 'disabled', 'isHighlighted', 'collapsibleState', 'currentText'];
20
23
 
21
24
  return propsToCheck
22
25
  .map((val) => isEqual( currentProps[val], nextProps[val]) )
@@ -42,19 +45,32 @@ export default class SelectOption extends Component {
42
45
  }
43
46
  }
44
47
 
48
+ onCollapseClick(e){
49
+ e.stopPropagation();
50
+ e.nativeEvent.stopImmediatePropagation();
51
+ const { toggleCollapsedValue, option } = this.props;
52
+ toggleCollapsedValue(option.value);
53
+ }
54
+
45
55
  render() {
56
+ const { isSelected, option, id, className, collapsibleState, renderOptionLabel } = this.props;
57
+
46
58
  return (
47
59
  <li
48
- aria-selected={this.props.isSelected}
49
- aria-disabled={this.props.option.disabled}
50
- aria-label={this.props.renderOptionLabel(this.props.option)}
51
- className={this.props.className}
52
- id={this.props.id}
60
+ aria-selected={isSelected}
61
+ aria-disabled={option.disabled}
62
+ aria-label={renderOptionLabel(this.props.option)}
63
+ className={cn(className, option.optionClassName)}
64
+ id={id}
53
65
  onClick={this.onClick}
54
66
  onMouseEnter={this.onMouseEnter}
55
67
  role="option"
56
68
  tabIndex="-1"
57
69
  >
70
+ {
71
+ collapsibleState &&
72
+ <Collapse collapsibleState={collapsibleState} onClick={this.onCollapseClick} />
73
+ }
58
74
  { this.props.children }
59
75
  </li>
60
76
  );
@@ -73,4 +89,7 @@ SelectOption.propTypes = {
73
89
  toggleValue: PropTypes.func.isRequired,
74
90
  unselectOnClick: PropTypes.bool,
75
91
  id: PropTypes.string,
92
+ toggleCollapsedValue: PropTypes.func.isRequired,
93
+ collapsibleState: PropTypes.string,
94
+ currentText: PropTypes.string
76
95
  };
@@ -40,6 +40,7 @@ export default function SingleSelect (props){
40
40
  onClose={props.onClose}
41
41
  options={props.options}
42
42
  optionSets={props.optionSets}
43
+ onChangeText={props.onChangeText}
43
44
  placeholder={props.placeholder}
44
45
  renderValueLabel={props.renderValueLabel}
45
46
  renderOptionLabel={props.renderOptionLabel}
@@ -63,6 +64,7 @@ SingleSelect.propTypes = {
63
64
  onChange: PropTypes.func,
64
65
  onClose: PropTypes.func,
65
66
  onOpen: PropTypes.func,
67
+ onChangeText: PropTypes.func,
66
68
  OptionComponent: PropTypes.func,
67
69
  renderOptionLabel: PropTypes.func,
68
70
  renderValueLabel: PropTypes.func,
@@ -22,6 +22,7 @@ export default function TagBoxMenuSelect (props) {
22
22
  closeOnSelect={false}
23
23
 
24
24
  ariaLabel={props.ariaLabel}
25
+ collapsibleOptions={props.collapsibleOptions}
25
26
  filterable={props.filterable}
26
27
  disabled={props.disabled}
27
28
  onChange={props.onChange}
@@ -39,6 +40,7 @@ export default function TagBoxMenuSelect (props) {
39
40
 
40
41
  TagBoxMenuSelect.propTypes = {
41
42
  ariaLabel: PropTypes.string,
43
+ collapsibleOptions: PropTypes.array,
42
44
  filterable: PropTypes.bool,
43
45
  disabled: PropTypes.bool,
44
46
  options: PropTypes.array.isRequired,
@@ -0,0 +1,26 @@
1
+ import React from 'react';
2
+ import { shallow } from 'enzyme';
3
+
4
+ import { whereClassName } from 'test/utils/enzyme-utils';
5
+
6
+ import Collapse from '../Collapse';
7
+ import icons from '../styles/icons/icons.css';
8
+
9
+ import { OPTION_NOT_COLLAPSED, OPTION_COLLAPSED } from '../../constants';
10
+
11
+ it('passes onClick handler', function(){
12
+ const onClick = jest.fn();
13
+ const wrapper = shallow(<Collapse collapsibleState={OPTION_NOT_COLLAPSED} onClick={onClick} />);
14
+ wrapper.find('[role="button"]').simulate('click');
15
+ expect(onClick).toHaveBeenCalled();
16
+ });
17
+
18
+ it('renders correct class based on collapsibleState', function(){
19
+ const onClick = jest.fn();
20
+ const wrapper = shallow(<Collapse collapsibleState={OPTION_NOT_COLLAPSED} onClick={onClick} />);
21
+ expect(wrapper.findWhere(whereClassName(icons['pamicon-triangle-right'])).length).toEqual(0);
22
+ expect(wrapper.findWhere(whereClassName(icons['pamicon-triangle-down'])).length).toEqual(1);
23
+ wrapper.setProps({collapsibleState: OPTION_COLLAPSED});
24
+ expect(wrapper.findWhere(whereClassName(icons['pamicon-triangle-right'])).length).toEqual(1);
25
+ expect(wrapper.findWhere(whereClassName(icons['pamicon-triangle-down'])).length).toEqual(0);
26
+ });
@@ -14,6 +14,7 @@ const defaultProps = {
14
14
  onOpen: () => {},
15
15
  onClose: () => {},
16
16
  options: [],
17
+ optionSets: [],
17
18
  renderOptionLabel: () => {},
18
19
  renderValueLabel: () => {}
19
20
  };
@@ -30,6 +31,7 @@ test('it passes on correct props', () => {
30
31
  expect(selectCore.prop('onOpen')).toEqual(props.onOpen);
31
32
  expect(selectCore.prop('onClose')).toEqual(props.onClose);
32
33
  expect(selectCore.prop('options')).toEqual(props.options);
34
+ expect(selectCore.prop('optionSets')).toEqual(props.optionSets);
33
35
  expect(selectCore.prop('renderOptionLabel')).toEqual(props.renderOptionLabel);
34
36
  expect(selectCore.prop('renderValueLabel')).toEqual(props.renderValueLabel);
35
37
  expect(selectCore.prop('ValueComponent')).toEqual(props.ValueComponent);
@@ -16,7 +16,10 @@ const getDefaultProps = () => ({
16
16
  toggleValue: sinon.spy(),
17
17
  option: {value: 1, label: 'one'},
18
18
  index: 0,
19
- setIndex: sinon.spy()
19
+ setIndex: sinon.spy(),
20
+ toggleCollapsedValue: jest.fn(),
21
+ collapsibleOptions: null,
22
+ currentText: ''
20
23
  });
21
24
 
22
25
  test('it renders checkbox based on isSelected', () => {
@@ -45,7 +48,7 @@ test('it renders custom label if passed in', () => {
45
48
  expect(wrapper.findWhere(whereClassName(styles.label)).text()).toEqual(label);
46
49
  });
47
50
 
48
- test('it pases classes to SelectOption based on props', () => {
51
+ test('it passes classes to SelectOption based on props', () => {
49
52
  const props = getDefaultProps();
50
53
  const wrapper = shallow(<MultiSelectOption {...props} />);
51
54
  expect(wrapper.find(SelectOption).prop('className')).toEqual(styles['option']);
@@ -58,3 +61,40 @@ test('it pases classes to SelectOption based on props', () => {
58
61
  classnames(styles.option, styles.disabled, styles.highlighted)
59
62
  );
60
63
  });
64
+
65
+ describe('collapsibleOption classname', function(){
66
+ it('renders indented class when option has collapsedBy is a part of collapsibleOption', function(){
67
+ const props = getDefaultProps();
68
+ const wrapper = shallow(<MultiSelectOption {...props} />);
69
+
70
+ // no collapsedOptions and no collapsible -> no class
71
+ expect(wrapper.find(SelectOption).prop('className').includes(styles['option__indented'])).toBe(false);
72
+
73
+
74
+ // collapsedOptions set but no collapsible -> no class
75
+ wrapper.setProps({collapsibleOptions: [3, 4]});
76
+ expect(wrapper.find(SelectOption).prop('className').includes(styles['option__indented'])).toBe(false);
77
+
78
+ // collapsedOptions set and collapsedBy -> has class
79
+ wrapper.setProps({
80
+ option: { value: 1, label: 'One', collapsedBy: 3}
81
+ });
82
+ expect(wrapper.find(SelectOption).prop('className').includes(styles['option__indented'])).toBe(true);
83
+
84
+ // collapsedOptions set and collapsedBy, but options are filtered -> no class
85
+ wrapper.setProps({
86
+ currentText: 'asdf'
87
+ });
88
+
89
+ // collapsedOptions set but doesnt match collapsedBy -> no class
90
+ wrapper.setProps({
91
+ currentText: '',
92
+ option: { value: 1, label: 'One', collapsedBy: 6}
93
+ });
94
+ expect(wrapper.find(SelectOption).prop('className').includes(styles['option__indented'])).toBe(false);
95
+
96
+ // collapsedOptions empty -> no class
97
+ wrapper.setProps({collapsibleOptions: []});
98
+ expect(wrapper.find(SelectOption).prop('className').includes(styles['option__indented'])).toBe(false);
99
+ });
100
+ });
@@ -7,6 +7,7 @@ import SingleSelectOption from '../SingleSelectOption';
7
7
  import BasicMinLengthComponent from '../BasicMinLengthComponent';
8
8
  import BasicEmptyOptionComponent from '../BasicEmptyOptionComponent';
9
9
  import KEYS from '../../utils/keys';
10
+ import { OPTION_COLLAPSED, OPTION_NOT_COLLAPSED } from '../../constants';
10
11
 
11
12
  let defaultProps;
12
13
 
@@ -24,7 +25,9 @@ beforeEach(function(){
24
25
  toggleValue: jest.fn(),
25
26
  setIndex: jest.fn(),
26
27
  reference: React.createRef(),
27
- menuId: 'menu-1'
28
+ menuId: 'menu-1',
29
+ getCollapsibleState: () => null,
30
+ toggleCollapsedValue: jest.fn()
28
31
  };
29
32
  });
30
33
 
@@ -190,3 +193,23 @@ describe('move scrollbar position', function() {
190
193
 
191
194
  });
192
195
 
196
+
197
+ describe('collapsibleState', function(){
198
+ it('calls getCollapsibleState with the options and passes the result to the components', function(){
199
+ const getCollapsibleState = jest.fn().mockImplementation((value) => {
200
+ return value % 2 == 0 ? OPTION_COLLAPSED : OPTION_NOT_COLLAPSED;
201
+ });
202
+
203
+ const wrapper = mount(<OptionListSet {...defaultProps} getCollapsibleState={getCollapsibleState}/>);
204
+ expect(getCollapsibleState).toHaveBeenCalledTimes(2);
205
+ expect(getCollapsibleState).toHaveBeenCalledWith(basicOptions[0].value);
206
+ expect(getCollapsibleState).toHaveBeenCalledWith(basicOptions[1].value);
207
+
208
+ expect(
209
+ wrapper.find(SingleSelectOption).at(0).prop('collapsibleState')
210
+ ).toEqual(OPTION_NOT_COLLAPSED);
211
+ expect(
212
+ wrapper.find(SingleSelectOption).at(1).prop('collapsibleState')
213
+ ).toEqual(OPTION_COLLAPSED);
214
+ });
215
+ });