pixel-react 1.4.3 → 1.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. package/.yarn/install-state.gz +0 -0
  2. package/lib/components/AddResourceButton/type.d.ts +1 -1
  3. package/lib/components/Drawer/Types.d.ts +4 -0
  4. package/lib/components/Excel/ExcelContextMenu/ExcelContextMenu.d.ts +13 -0
  5. package/lib/components/Excel/ExcelFile/ExcelFileComponents/Spreadsheet.d.ts +0 -13
  6. package/lib/components/Excel/ExcelFile/ExcelFileComponents/actions.d.ts +29 -1
  7. package/lib/components/Excel/ExcelFile/ExcelFileComponents/engine/engine.d.ts +3 -9
  8. package/lib/components/Excel/ExcelFile/ExcelFileComponents/engine/formula.d.ts +2 -10
  9. package/lib/components/Excel/ExcelFile/ExcelFileComponents/engine/point-graph.d.ts +0 -1
  10. package/lib/components/Excel/ExcelFile/ExcelFileComponents/types.d.ts +27 -2
  11. package/lib/components/Form/Forms.d.ts +4 -2
  12. package/lib/components/InputWithDropdown/InputWithDropdown.d.ts +1 -1
  13. package/lib/components/MenuOption/MenuOption.d.ts +1 -1
  14. package/lib/components/MenuOption/types.d.ts +49 -15
  15. package/lib/components/MultiSelect/MultiSelect.d.ts +1 -1
  16. package/lib/components/MultiSelect/MultiSelectTypes.d.ts +4 -5
  17. package/lib/components/MultiSelect/dropdownTypes.d.ts +2 -0
  18. package/lib/components/RadioButton/RadioButton.d.ts +1 -0
  19. package/lib/components/RadioButton/radioButtonTypes.d.ts +3 -1
  20. package/lib/components/Select/components/types.d.ts +4 -2
  21. package/lib/components/Table/Table.d.ts +1 -1
  22. package/lib/components/ToggleSwitch/ToggleSwitch.d.ts +10 -0
  23. package/lib/components/ToggleSwitch/index.d.ts +1 -0
  24. package/lib/index.d.ts +109 -23
  25. package/lib/index.esm.js +5711 -635
  26. package/lib/index.esm.js.map +1 -1
  27. package/lib/index.js +5707 -629
  28. package/lib/index.js.map +1 -1
  29. package/lib/tsconfig.tsbuildinfo +1 -1
  30. package/package.json +11 -11
  31. package/src/StyleGuide/ColorPalette/colorPaletteList.ts +10 -0
  32. package/src/assets/Themes/BaseTheme.scss +17 -23
  33. package/src/assets/Themes/DarkTheme.scss +25 -38
  34. package/src/assets/icons/apk_file_type.svg +4 -0
  35. package/src/assets/icons/compressed_file_type.svg +4 -0
  36. package/src/assets/icons/csv_file_type.svg +4 -0
  37. package/src/assets/icons/excel_corner_menu.svg +3 -0
  38. package/src/assets/icons/formula_icon.svg +3 -0
  39. package/src/assets/icons/gif_file_type.svg +4 -0
  40. package/src/assets/icons/html_file_type.svg +4 -0
  41. package/src/assets/icons/ipk_file_type.svg +4 -0
  42. package/src/assets/icons/jpg_file_type.svg +4 -0
  43. package/src/assets/icons/json_file_type.svg +4 -0
  44. package/src/assets/icons/pdf_file_type.svg +4 -0
  45. package/src/assets/icons/png_file_type.svg +4 -0
  46. package/src/assets/icons/quick_run_setting_icon.svg +5 -0
  47. package/src/assets/icons/run_automation_scripts_icon.svg +33 -0
  48. package/src/assets/icons/run_manual_testcase_icon.svg +4 -0
  49. package/src/assets/icons/search.svg +2 -2
  50. package/src/assets/icons/txt_file_type.svg +4 -0
  51. package/src/assets/icons/xls_file_type.svg +4 -0
  52. package/src/assets/icons/xlsx_file_type.svg +4 -0
  53. package/src/assets/icons/xml_file_type.svg +4 -0
  54. package/src/components/AddResourceButton/AddButton.tsx +7 -7
  55. package/src/components/AddResourceButton/type.ts +1 -1
  56. package/src/components/AttachmentButton/AttachmentButton.scss +1 -1
  57. package/src/components/AttachmentButton/AttachmentButton.stories.tsx +1 -0
  58. package/src/components/Button/Button.scss +22 -20
  59. package/src/components/Button/Button.tsx +8 -1
  60. package/src/components/Charts/DashboardDonutChart/DashboardDonutChart.tsx +2 -2
  61. package/src/components/Drawer/Drawer.scss +4 -3
  62. package/src/components/Drawer/Drawer.tsx +14 -18
  63. package/src/components/Drawer/Types.ts +4 -0
  64. package/src/components/Editor/Editor.tsx +9 -11
  65. package/src/components/Excel/ExcelContextMenu/ExcelContextMenu.scss +39 -0
  66. package/src/components/Excel/ExcelContextMenu/ExcelContextMenu.tsx +51 -0
  67. package/src/components/Excel/ExcelFile/ExcelFile.tsx +7 -8
  68. package/src/components/Excel/ExcelFile/ExcelFileComponents/Cell.tsx +35 -0
  69. package/src/components/Excel/ExcelFile/ExcelFileComponents/ColumnIndicator.tsx +44 -7
  70. package/src/components/Excel/ExcelFile/ExcelFileComponents/CornerIndicator.tsx +8 -1
  71. package/src/components/Excel/ExcelFile/ExcelFileComponents/RowIndicator.tsx +45 -6
  72. package/src/components/Excel/ExcelFile/ExcelFileComponents/Spreadsheet.scss +37 -2
  73. package/src/components/Excel/ExcelFile/ExcelFileComponents/Spreadsheet.tsx +69 -24
  74. package/src/components/Excel/ExcelFile/ExcelFileComponents/actions.ts +59 -0
  75. package/src/components/Excel/ExcelFile/ExcelFileComponents/engine/engine.ts +18 -65
  76. package/src/components/Excel/ExcelFile/ExcelFileComponents/engine/formula.ts +5 -110
  77. package/src/components/Excel/ExcelFile/ExcelFileComponents/engine/point-graph.ts +0 -2
  78. package/src/components/Excel/ExcelFile/ExcelFileComponents/reducer.ts +105 -1
  79. package/src/components/Excel/ExcelFile/ExcelFileComponents/reducerFunctions.ts +670 -673
  80. package/src/components/Excel/ExcelFile/ExcelFileComponents/types.ts +38 -2
  81. package/src/components/Excel/ExcelToolBar/ExcelToolBar.tsx +0 -4
  82. package/src/components/FileDropzone/FileDropzone.scss +4 -2
  83. package/src/components/FileDropzone/FileDropzone.tsx +1 -1
  84. package/src/components/FileDropzone/FilePreview.tsx +3 -1
  85. package/src/components/Form/Form.scss +2 -0
  86. package/src/components/Form/Form.stories.tsx +195 -6
  87. package/src/components/Form/Forms.tsx +15 -8
  88. package/src/components/Icon/iconList.ts +46 -0
  89. package/src/components/IconRadioGroup/IconRadioGroup.scss +3 -0
  90. package/src/components/IconRadioGroup/IconRadioGroup.tsx +20 -17
  91. package/src/components/Input/Input.scss +14 -15
  92. package/src/components/Input/Input.stories.tsx +2 -1
  93. package/src/components/InputWithDropdown/InputWithDropdown.scss +12 -13
  94. package/src/components/InputWithDropdown/InputWithDropdown.stories.tsx +3 -2
  95. package/src/components/InputWithDropdown/InputWithDropdown.tsx +22 -19
  96. package/src/components/MenuOption/MenuOption.scss +11 -10
  97. package/src/components/MenuOption/MenuOption.stories.tsx +51 -232
  98. package/src/components/MenuOption/MenuOption.tsx +131 -52
  99. package/src/components/MenuOption/types.ts +55 -14
  100. package/src/components/MiniModal/MiniModal.stories.tsx +2 -3
  101. package/src/components/MultiSelect/Dropdown.tsx +11 -12
  102. package/src/components/MultiSelect/MultiSelect.scss +1 -0
  103. package/src/components/MultiSelect/MultiSelect.stories.tsx +45 -10
  104. package/src/components/MultiSelect/MultiSelect.tsx +29 -13
  105. package/src/components/MultiSelect/MultiSelectTypes.ts +7 -5
  106. package/src/components/MultiSelect/dropdownTypes.ts +2 -0
  107. package/src/components/RadioButton/RadioButton.scss +3 -1
  108. package/src/components/RadioButton/RadioButton.tsx +3 -1
  109. package/src/components/RadioButton/radioButtonTypes.tsx +5 -1
  110. package/src/components/Search/Search.scss +25 -6
  111. package/src/components/Search/Search.tsx +45 -24
  112. package/src/components/Select/Select.scss +12 -12
  113. package/src/components/Select/Select.stories.tsx +2 -0
  114. package/src/components/Select/Select.tsx +11 -5
  115. package/src/components/Select/components/Dropdown.scss +2 -0
  116. package/src/components/Select/components/Dropdown.tsx +19 -4
  117. package/src/components/Select/components/types.ts +4 -2
  118. package/src/components/StatusButton/StatusButton.tsx +26 -20
  119. package/src/components/Table/Table.scss +1 -3
  120. package/src/components/Table/Table.stories.tsx +1 -0
  121. package/src/components/Table/Table.tsx +7 -3
  122. package/src/components/ToggleSwitch/ToggleSwitch.scss +59 -0
  123. package/src/components/ToggleSwitch/ToggleSwitch.stories.tsx +52 -0
  124. package/src/components/ToggleSwitch/ToggleSwitch.tsx +30 -0
  125. package/src/components/ToggleSwitch/index.ts +1 -0
  126. package/src/hooks/useFileDropzone.tsx +1 -0
  127. package/src/index.ts +4 -2
  128. package/src/components/Excel/ContextMenu/ContextMenu.scss +0 -99
  129. package/src/components/Excel/ContextMenu/ContextMenu.tsx +0 -103
@@ -1,4 +1,4 @@
1
- import { useState, useRef } from 'react';
1
+ import { useState, useRef, useContext, useEffect } from 'react';
2
2
  import './MenuOption.scss';
3
3
  import Icon from '../Icon';
4
4
  import classNames from 'classnames';
@@ -9,8 +9,10 @@ import {
9
9
  MenuOptionProps,
10
10
  OptionClick,
11
11
  } from './types';
12
- import useClickOutside from '../../hooks/useClickOutside';
13
12
  import Typography from '../Typography';
13
+ import { createPortal } from 'react-dom';
14
+ import { ThemeContext } from '../ThemeProvider/ThemeProvider';
15
+ import useClickOutside from '../../hooks/useClickOutside';
14
16
 
15
17
  const Option = ({ option, onClick }: OptionProps) => (
16
18
  <div
@@ -19,7 +21,14 @@ const Option = ({ option, onClick }: OptionProps) => (
19
21
  })}
20
22
  onClick={() => !option.disable && onClick(option)}
21
23
  >
22
- {option.icon && <Icon name={option.icon} height={16} width={16} />}
24
+ {option.icon && (
25
+ <Icon
26
+ name={option.icon}
27
+ color={option.iconColor}
28
+ height={16}
29
+ width={16}
30
+ />
31
+ )}
23
32
  <Typography
24
33
  as="label"
25
34
  color={option.icon === 'delete' ? 'var(--delete-text-color)' : ''}
@@ -29,13 +38,72 @@ const Option = ({ option, onClick }: OptionProps) => (
29
38
  </div>
30
39
  );
31
40
 
32
- const OptionCard = ({ options, onClick, styles }: OptionCardProps) => {
33
- return (
34
- <div className="ff-option-card" style={styles}>
35
- {options.map((opt) => (
36
- <Option key={opt.label} option={opt} onClick={onClick} />
37
- ))}
38
- </div>
41
+ const OptionCard = ({
42
+ options,
43
+ onClick,
44
+ menuPosition,
45
+ menuRef,
46
+ closeDropdown,
47
+ zIndex,
48
+ dropdownPosition,
49
+ }: OptionCardProps) => {
50
+ const themeContext = useContext(ThemeContext);
51
+ const currentTheme = themeContext?.currentTheme;
52
+ const [optionsHeight, setOptionsHeight] = useState(0);
53
+ const optionCardRef = useRef<HTMLDivElement>(null);
54
+
55
+ useEffect(() => {
56
+ if (optionCardRef?.current) {
57
+ const rect = optionCardRef?.current?.getBoundingClientRect();
58
+ setOptionsHeight(rect?.height);
59
+ }
60
+ }, []);
61
+
62
+ useClickOutside(menuRef, closeDropdown, [optionCardRef]);
63
+
64
+ const style = (() => {
65
+ switch (dropdownPosition) {
66
+ case 'top':
67
+ return {
68
+ top: menuPosition.top - optionsHeight - 7,
69
+ left: menuPosition.rightSpaceAvailable + 12,
70
+ };
71
+ case 'down':
72
+ return {
73
+ top: menuPosition.bottom,
74
+ left: menuPosition.rightSpaceAvailable + 12,
75
+ };
76
+ case 'left':
77
+ return {
78
+ top: menuPosition.top,
79
+ right: menuPosition.rightSpaceAvailable + 35,
80
+ };
81
+ case 'right':
82
+ return {
83
+ top: menuPosition.top,
84
+ left: menuPosition.rightSpaceAvailable + 35,
85
+ };
86
+ default:
87
+ return {
88
+ top: menuPosition.bottom,
89
+ left: menuPosition.rightSpaceAvailable + 12,
90
+ };
91
+ }
92
+ })();
93
+
94
+ return createPortal(
95
+ <div
96
+ className={classNames('ff-option-card', currentTheme)}
97
+ ref={optionCardRef}
98
+ style={{ ...style, zIndex }}
99
+ >
100
+ <div className="ff-option-wrapper">
101
+ {options.map((opt) => (
102
+ <Option key={opt.label} option={opt} onClick={onClick} />
103
+ ))}
104
+ </div>
105
+ </div>,
106
+ document.body
39
107
  );
40
108
  };
41
109
 
@@ -45,18 +113,27 @@ const MenuOption = ({
45
113
  tooltipTitle,
46
114
  tooltipPlacement = 'bottom',
47
115
  options = [],
48
- dropdownPlacement = 'down',
49
116
  onClick = () => {},
50
117
  onOptionClick = () => {},
51
118
  iconButtonSize = 20,
52
119
  iconButtonBorderRadius = 7,
53
120
  iconSize = 16,
54
121
  variant = 'light',
55
- zIndex=1000,
122
+ zIndex = 99,
123
+ dropdownPlacement = 'down',
56
124
  }: MenuOptionProps) => {
57
125
  const [isClicked, setIsClicked] = useState(false);
58
126
  const menuRef = useRef<HTMLDivElement>(null);
59
-
127
+ const [menuPosition, setMenuPosition] = useState({
128
+ top: 0,
129
+ bottom: 0,
130
+ height: 0,
131
+ fromBottom: 0,
132
+ rightSpaceAvailable: 0,
133
+ });
134
+ useEffect(() => {
135
+ calculateDims();
136
+ });
60
137
  const closeDropDown = () => setIsClicked(false);
61
138
 
62
139
  const onIconClickHandler = () => {
@@ -69,59 +146,61 @@ const MenuOption = ({
69
146
  closeDropDown();
70
147
  };
71
148
 
72
- const dropdownPositionStyles = () => {
73
- switch (dropdownPlacement) {
74
- case 'top':
75
- return { bottom: '100%', left: -2 ,zIndex};
76
- case 'left':
77
- return { top: -2, right: '100%' ,zIndex};
78
- case 'right':
79
- return { top: -2, left: '100%' ,zIndex};
80
- case 'down':
81
- default:
82
- return { top: '100%', left: -2 ,zIndex};
149
+ const calculateDims = () => {
150
+ if (menuRef?.current) {
151
+ const rect = menuRef.current.getBoundingClientRect();
152
+
153
+ setMenuPosition({
154
+ top: rect.top,
155
+ height: rect.height,
156
+ rightSpaceAvailable: document.body.clientWidth - rect.right,
157
+ bottom: rect.bottom,
158
+ fromBottom: window.innerHeight - rect.bottom,
159
+ });
83
160
  }
84
161
  };
85
162
 
86
- useClickOutside(menuRef, closeDropDown);
87
-
88
163
  return (
89
164
  <div className="ff-menu-option-container" ref={menuRef}>
90
165
  <Tooltip title={tooltipTitle} placement={tooltipPlacement}>
91
166
  <div className="ff-icon-label">
92
- <div
93
- className={classNames('ff-menuicon-container', {
94
- 'ff-menuicon-container-clicked': isClicked,
95
- dark: variant === 'dark',
96
- })}
97
- onClick={onIconClickHandler}
98
- style={{
99
- width: `${iconButtonSize}px`,
100
- height: `${iconButtonSize}px`,
101
- borderRadius: `${iconButtonBorderRadius}px`,
102
- display: 'flex',
103
- flexDirection: 'column',
104
- }}
105
- >
106
- <Icon
107
- height={iconSize}
108
- width={iconSize}
109
- name={iconName}
110
- color={
111
- isClicked === (variant === 'dark')
112
- ? 'var(--menu-option-icon-clicked)'
113
- : 'var(--menu-option-icon-color)'
114
- }
115
- />
167
+ <div
168
+ className={classNames('ff-menuicon-container', {
169
+ 'ff-menuicon-container-clicked': isClicked,
170
+ dark: variant === 'dark',
171
+ })}
172
+ onClick={onIconClickHandler}
173
+ style={{
174
+ width: `${iconButtonSize}px`,
175
+ height: `${iconButtonSize}px`,
176
+ borderRadius: `${iconButtonBorderRadius}px`,
177
+ display: 'flex',
178
+ flexDirection: 'column',
179
+ }}
180
+ >
181
+ <Icon
182
+ height={iconSize}
183
+ width={iconSize}
184
+ name={iconName}
185
+ color={
186
+ isClicked === (variant === 'dark')
187
+ ? 'var(--menu-option-icon-clicked)'
188
+ : 'var(--menu-option-icon-color)'
189
+ }
190
+ />
116
191
  </div>
117
- {labelName && <Typography as="label">{labelName} </Typography>}
192
+ {labelName && <Typography as="label">{labelName}</Typography>}
118
193
  </div>
119
194
  </Tooltip>
120
195
  {isClicked && (
121
196
  <OptionCard
122
197
  options={options}
123
198
  onClick={handleOptionClick}
124
- styles={dropdownPositionStyles()}
199
+ menuPosition={menuPosition}
200
+ menuRef={menuRef}
201
+ closeDropdown={closeDropDown}
202
+ zIndex={zIndex}
203
+ dropdownPosition={dropdownPlacement}
125
204
  />
126
205
  )}
127
206
  </div>
@@ -11,17 +11,21 @@ interface OptionClick {
11
11
  * @type {Array<string> | string}
12
12
  * @required
13
13
  */
14
- value: Array<string> | string;
14
+ value: any;
15
15
  }
16
16
 
17
17
  interface OptionType extends OptionClick {
18
18
  /**
19
19
  * The name of the icon associated with the option.
20
20
  * @type {string}
21
- * @required
21
+ * @optional
22
22
  */
23
23
  icon?: string;
24
24
 
25
+ iconColor?: string;
26
+
27
+ name?: string;
28
+
25
29
  /**
26
30
  * Indicates whether the option is disabled.
27
31
  * @type {boolean}
@@ -40,11 +44,11 @@ interface OptionCardProps {
40
44
 
41
45
  /**
42
46
  * Callback function triggered when an option is clicked.
43
- * @param {any} data - The data associated with the clicked option.
47
+ * @param {OptionClick} data - The data associated with the clicked option.
44
48
  * @type {function}
45
49
  * @required
46
50
  */
47
- onClick: (data?: any) => void;
51
+ onClick: (data: OptionClick) => void;
48
52
 
49
53
  /**
50
54
  * Optional styles applied to the card.
@@ -52,6 +56,41 @@ interface OptionCardProps {
52
56
  * @optional
53
57
  */
54
58
  styles?: React.CSSProperties;
59
+
60
+ /**
61
+ * The z-index of the option card.
62
+ * @type {number}
63
+ * @optional
64
+ */
65
+ zIndex?: number;
66
+
67
+ /**
68
+ * The position of the menu relative to the triggering element.
69
+ * @type {dropdownPosition}
70
+ * @required
71
+ */
72
+ menuPosition: any;
73
+
74
+ /**
75
+ * Reference to the menu DOM element.
76
+ * @type {React.RefObject<HTMLElement>}
77
+ * @required
78
+ */
79
+ menuRef: React.RefObject<HTMLElement>;
80
+
81
+ /**
82
+ * Callback function to close the dropdown.
83
+ * @type {() => void}
84
+ * @required
85
+ */
86
+ closeDropdown: () => void;
87
+
88
+ /**
89
+ * Placement of the dropdown menu relative to the icon.
90
+ * @type {dropdownPosition}
91
+ * @optional
92
+ */
93
+ dropdownPosition?: 'top' | 'down' | 'left' | 'right';
55
94
  }
56
95
 
57
96
  interface MenuOptionProps {
@@ -100,35 +139,34 @@ interface MenuOptionProps {
100
139
 
101
140
  /**
102
141
  * The placement of the dropdown menu relative to the icon.
103
- * @type {'top' | 'left' | 'right' | 'bottom'}
142
+ * @type {dropdownPosition}
104
143
  * @optional
105
144
  */
106
- dropdownPlacement?: string | 'top' | 'left' | 'right' | 'down';
145
+ dropdownPlacement?: 'top' | 'down' | 'left' | 'right';
107
146
 
108
- /**
147
+ /**
109
148
  * The variant of the menu option, either 'dark' or 'light'.
110
149
  * @type {'dark' | 'light'}
111
150
  * @default 'light'
112
151
  * @optional
113
152
  */
114
-
115
153
  variant?: 'dark' | 'light';
116
-
154
+
117
155
  /**
118
156
  * Callback function triggered when the icon is clicked.
119
- * @type {function}
157
+ * @type {() => void}
120
158
  * @optional
121
159
  */
122
-
123
160
  onClick?: () => void;
124
161
 
125
162
  /**
126
163
  * Callback function triggered when an option is clicked.
127
164
  * @param {OptionClick} option - The option that was clicked.
128
- * @type {function}
165
+ * @type {(option: OptionClick) => void}
129
166
  * @optional
130
167
  */
131
168
  onOptionClick?: (option: OptionClick) => void;
169
+
132
170
  /**
133
171
  * The size of the icon button.
134
172
  * @type {number}
@@ -144,13 +182,16 @@ interface MenuOptionProps {
144
182
  iconSize?: number;
145
183
 
146
184
  /**
147
- * The border radius of the icon.
185
+ * The border radius of the icon button.
148
186
  * @type {number}
149
187
  * @default 7
150
188
  */
151
189
  iconButtonBorderRadius?: number;
190
+
152
191
  /**
153
192
  * Providing z-index for the options card.
193
+ * @type {number}
194
+ * @optional
154
195
  */
155
196
  zIndex?: number;
156
197
  }
@@ -166,7 +207,7 @@ interface OptionProps {
166
207
  /**
167
208
  * Callback function triggered when the option is clicked.
168
209
  * @param {OptionClick} option - The clicked option.
169
- * @type {function}
210
+ * @type {(option: OptionClick) => void}
170
211
  * @required
171
212
  */
172
213
  onClick: (option: OptionClick) => void;
@@ -42,7 +42,7 @@ const BasicModalComponent = () => {
42
42
  <div className="ff-mini-modal-buttons-flex ff-mini-modal-gap-10">
43
43
  <Button
44
44
  onClick={() => openModal(1)}
45
- id='112233'
45
+ id="112233"
46
46
  ref={btnRef1}
47
47
  label="122"
48
48
  variant={currentModal === 1 ? 'primary' : 'secondary'}
@@ -241,7 +241,6 @@ export const BasicModal: Story = {
241
241
  };
242
242
 
243
243
  export const CustomModalWithArrow = () => {
244
- const btnRef1 = useRef<HTMLButtonElement>(null);
245
244
  const btnRef2 = useRef<HTMLButtonElement>(null);
246
245
  const btnRef3 = useRef<HTMLButtonElement>(null);
247
246
  const btnRef4 = useRef<HTMLButtonElement>(null);
@@ -263,7 +262,7 @@ export const CustomModalWithArrow = () => {
263
262
 
264
263
  {currentModal === 1 && (
265
264
  <MiniModal
266
- anchorRef='1a2b'
265
+ anchorRef="1a2b"
267
266
  modalProperties={{ width: 300, height: 250 }}
268
267
  headerProps={
269
268
  <>
@@ -9,6 +9,7 @@ import Typography from '../Typography';
9
9
  import Checkbox from '../Checkbox';
10
10
  import Tooltip from '../Tooltip';
11
11
  import { truncateText } from '../../utils/truncateText/truncateText';
12
+ import { getLabel } from '../../utils/getSelectOptionValue/getSelectOptionValue';
12
13
 
13
14
  const Dropdown = forwardRef<HTMLDivElement, DropdownProps>(
14
15
  (
@@ -19,12 +20,15 @@ const Dropdown = forwardRef<HTMLDivElement, DropdownProps>(
19
20
  dropdownPosition = {},
20
21
  zIndex,
21
22
  withSelectButton,
23
+ labelAccessor,
22
24
  },
23
25
  ref
24
26
  ) => {
25
27
  const filteredOptions = options
26
28
  ? options.filter((option) =>
27
- option.label?.toLowerCase().includes(searchedKeyword.toLowerCase())
29
+ getLabel(option, labelAccessor)
30
+ ?.toLowerCase()
31
+ .includes(searchedKeyword.toLowerCase())
28
32
  )
29
33
  : [];
30
34
  const { verticalMargin, optionHeight, maxDropdownHeight } =
@@ -56,12 +60,7 @@ const Dropdown = forwardRef<HTMLDivElement, DropdownProps>(
56
60
 
57
61
  return topPosition;
58
62
  }, [filteredOptions.length, withSelectButton, dropdownPosition]);
59
- const renderOption = (optionLabel: string | undefined) => {
60
- if (typeof optionLabel === 'string') {
61
- return truncateText(optionLabel, 25);
62
- }
63
- return optionLabel;
64
- };
63
+
65
64
  const themeContext = useContext(ThemeContext);
66
65
  const currentTheme = themeContext?.currentTheme;
67
66
  return (
@@ -91,7 +90,7 @@ const Dropdown = forwardRef<HTMLDivElement, DropdownProps>(
91
90
  <div
92
91
  role="option"
93
92
  className={`dropdown-option-container`}
94
- key={info.label}
93
+ key={getLabel(info, labelAccessor)}
95
94
  onClick={() =>
96
95
  !info?.isDisabled && handleOptionChange(info, !info.isChecked)
97
96
  }
@@ -104,14 +103,14 @@ const Dropdown = forwardRef<HTMLDivElement, DropdownProps>(
104
103
  <Tooltip
105
104
  zIndex={zIndex + 1}
106
105
  title={
107
- info.label && info.label.length > 25
108
- ? info.label
109
- : undefined
106
+ getLabel(info, labelAccessor).length > 25
107
+ ? getLabel(info, labelAccessor)
108
+ : ''
110
109
  }
111
110
  children={
112
111
  <Typography
113
112
  className="dropdown-option-label"
114
- children={`${renderOption(info.label)}`}
113
+ children={truncateText(getLabel(info, labelAccessor), 25)}
115
114
  />
116
115
  }
117
116
  />
@@ -90,6 +90,7 @@
90
90
  border: 0.5px solid #f1ebf2;
91
91
  padding: 0 1px 0 4px;
92
92
  gap: 4px;
93
+ height: 16px;
93
94
  border-radius: 15px;
94
95
  .ff-multiselect-chip-label {
95
96
  @extend .fontXs;
@@ -2,6 +2,7 @@ import type { Meta, StoryObj } from '@storybook/react';
2
2
  import MultiSelect from './MultiSelect';
3
3
  import { useEffect, useState } from 'react';
4
4
  import { Option } from './MultiSelectTypes';
5
+ import React from 'react';
5
6
 
6
7
  const meta: Meta<typeof MultiSelect> = {
7
8
  title: 'Components/MultiSelect',
@@ -31,21 +32,54 @@ export const Default: Story = {
31
32
  { label: 'Cherry', value: 'cherry' },
32
33
  { label: 'Date', value: 'date' },
33
34
  { label: 'Grape', value: 'grape' },
34
- // { label: 'Kiwi', value: 'kiwi' },
35
- // { label: 'Mango', value: 'mango' },
36
- // { label: 'Orange', value: 'orange' },
37
- // { label: 'Peach', value: 'peach' },
38
- // { label: 'Strawberry', value: 'strawberry' },
35
+ { label: 'Kiwi', value: 'kiwi' },
36
+ { label: 'Mango', value: 'mango' },
37
+ { label: 'Orange', value: 'orange' },
38
+ { label: 'Peach', value: 'peach' },
39
+ { label: 'Strawberry', value: 'strawberry' },
39
40
  ],
40
- // selectedOptions: [{ label: 'Apple', value: 'apple' }],
41
41
  },
42
42
  };
43
43
 
44
- export const Default2: Story = {
45
- args: {
46
- ...defaultArgs,
44
+ export const NameAccessor: Story = {
45
+ render: () => {
46
+ const [options, setOptions] = useState<Option[]>([]);
47
+ const [selectedOptions, setSelectedOptions] = useState<Option[]>([
48
+ { name: 'Apple', fruit: 'apple' },
49
+ ]);
50
+ const onChange = (options: Option[]) => {
51
+ setSelectedOptions(options);
52
+ };
53
+ useEffect(() => {
54
+ setOptions([
55
+ { name: 'Apple', fruit: 'apple' },
56
+ { name: 'Banana', fruit: 'banana' },
57
+ {
58
+ name: 'CherryCherryCherryCherryCherryCherryCherryCherryCherryCherry',
59
+ fruit: 'cherry',
60
+ },
61
+ { name: 'Date', fruit: 'date' },
62
+ { name: 'Kiwi', fruit: 'kiwi' },
63
+ { name: 'Mango', fruit: 'mango' },
64
+ { name: 'Orange', fruit: 'orange' },
65
+ { name: 'Peach', fruit: 'peach' },
66
+ { name: 'Strawberry', fruit: 'strawberry' },
67
+ ]);
68
+ }, []);
69
+ return (
70
+ <MultiSelect
71
+ labelAccessor="name"
72
+ label={'Fruits'}
73
+ required
74
+ options={options}
75
+ selectedOptions={selectedOptions}
76
+ onChange={onChange}
77
+ valueAccessor="fruit"
78
+ />
79
+ );
47
80
  },
48
81
  };
82
+
49
83
  export const Default3: Story = {
50
84
  args: {
51
85
  ...defaultArgs,
@@ -85,6 +119,7 @@ export const EmailGroup: Story = {
85
119
  onChange={onChange}
86
120
  acceptNewOption={true}
87
121
  displayCount={true}
122
+ labelAccessor="label"
88
123
  />
89
124
  );
90
125
  },
@@ -158,6 +193,7 @@ export const Labels: Story = {
158
193
  return (
159
194
  <div style={{ width: '250px' }}>
160
195
  <MultiSelect
196
+ required
161
197
  label={'Labels'}
162
198
  variant="labels"
163
199
  options={options}
@@ -199,7 +235,6 @@ export const Machines: Story = {
199
235
  const [selectedOptions, setSelectedOptions] = useState<Option[]>([]);
200
236
 
201
237
  const handleSelectChange = (machines: Option[]) => {
202
- console.log('Updated machines:', machines);
203
238
  setSelectedOptions(machines);
204
239
  };
205
240