pixel-react 1.2.7 → 1.2.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (219) hide show
  1. package/lib/components/Drawer/Types.d.ts +23 -12
  2. package/lib/components/Editor/Editor.d.ts +5 -0
  3. package/lib/components/Editor/Editor.stories.d.ts +6 -0
  4. package/lib/components/Editor/VariableDropdown.d.ts +5 -0
  5. package/lib/components/Editor/constants.d.ts +3 -0
  6. package/lib/components/Editor/index.d.ts +1 -0
  7. package/lib/components/Editor/types.d.ts +71 -0
  8. package/lib/components/Excel/ContextMenu/ContextMenu.d.ts +4 -0
  9. package/lib/components/Excel/ExcelFile/ExcelFile.d.ts +20 -0
  10. package/lib/components/Excel/ExcelFile/ExcelFileComponents/ActiveCell.d.ts +7 -0
  11. package/lib/components/Excel/ExcelFile/ExcelFileComponents/Cell.d.ts +4 -0
  12. package/lib/components/Excel/ExcelFile/ExcelFileComponents/ColumnIndicator.d.ts +5 -0
  13. package/lib/components/Excel/ExcelFile/ExcelFileComponents/Copied.d.ts +3 -0
  14. package/lib/components/Excel/ExcelFile/ExcelFileComponents/CornerIndicator.d.ts +5 -0
  15. package/lib/components/Excel/ExcelFile/ExcelFileComponents/DataEditor.d.ts +5 -0
  16. package/lib/components/Excel/ExcelFile/ExcelFileComponents/DataViewer.d.ts +8 -0
  17. package/lib/components/Excel/ExcelFile/ExcelFileComponents/FloatingRect.d.ts +10 -0
  18. package/lib/components/Excel/ExcelFile/ExcelFileComponents/HeaderRow.d.ts +3 -0
  19. package/lib/components/Excel/ExcelFile/ExcelFileComponents/Row.d.ts +3 -0
  20. package/lib/components/Excel/ExcelFile/ExcelFileComponents/RowIndicator.d.ts +5 -0
  21. package/lib/components/Excel/ExcelFile/ExcelFileComponents/Selected.d.ts +3 -0
  22. package/lib/components/Excel/ExcelFile/ExcelFileComponents/Spreadsheet.d.ts +80 -0
  23. package/lib/components/Excel/ExcelFile/ExcelFileComponents/Table.d.ts +3 -0
  24. package/lib/components/Excel/ExcelFile/ExcelFileComponents/actions.d.ts +203 -0
  25. package/lib/components/Excel/ExcelFile/ExcelFileComponents/areModelsEqual.d.ts +1 -0
  26. package/lib/components/Excel/ExcelFile/ExcelFileComponents/context.d.ts +8 -0
  27. package/lib/components/Excel/ExcelFile/ExcelFileComponents/engine/engine.d.ts +22 -0
  28. package/lib/components/Excel/ExcelFile/ExcelFileComponents/engine/formula.d.ts +17 -0
  29. package/lib/components/Excel/ExcelFile/ExcelFileComponents/engine/index.d.ts +2 -0
  30. package/lib/components/Excel/ExcelFile/ExcelFileComponents/engine/point-graph.d.ts +21 -0
  31. package/lib/components/Excel/ExcelFile/ExcelFileComponents/engine/point-hash.d.ts +3 -0
  32. package/lib/components/Excel/ExcelFile/ExcelFileComponents/engine/point-set.d.ts +24 -0
  33. package/lib/components/Excel/ExcelFile/ExcelFileComponents/index.d.ts +13 -0
  34. package/lib/components/Excel/ExcelFile/ExcelFileComponents/matrix.d.ts +67 -0
  35. package/lib/components/Excel/ExcelFile/ExcelFileComponents/point-range.d.ts +22 -0
  36. package/lib/components/Excel/ExcelFile/ExcelFileComponents/point.d.ts +11 -0
  37. package/lib/components/Excel/ExcelFile/ExcelFileComponents/reducer.d.ts +4 -0
  38. package/lib/components/Excel/ExcelFile/ExcelFileComponents/reducerFunctions.d.ts +40 -0
  39. package/lib/components/Excel/ExcelFile/ExcelFileComponents/selection.d.ts +95 -0
  40. package/lib/components/Excel/ExcelFile/ExcelFileComponents/types.d.ts +178 -0
  41. package/lib/components/Excel/ExcelFile/ExcelFileComponents/use-dispatch.d.ts +3 -0
  42. package/lib/components/Excel/ExcelFile/ExcelFileComponents/use-selector.d.ts +3 -0
  43. package/lib/components/Excel/ExcelFile/ExcelFileComponents/util.d.ts +44 -0
  44. package/lib/components/Excel/ExcelFile.stories.d.ts +6 -0
  45. package/lib/components/Excel/ExcelToolBar/ExcelToolBar.d.ts +19 -0
  46. package/lib/components/Excel/Types.d.ts +129 -0
  47. package/lib/components/Excel/index.d.ts +1 -0
  48. package/lib/components/ExcelFile/ColorBarselector/ColorBarSelector.d.ts +8 -0
  49. package/lib/components/ExcelFile/ExcelFile/Excel/ActiveCell.d.ts +2 -2
  50. package/lib/components/ExcelFile/ExcelFile/Excel/ColumnIndicator.d.ts +2 -2
  51. package/lib/components/ExcelFile/ExcelFile/Excel/Copied.d.ts +1 -1
  52. package/lib/components/ExcelFile/ExcelFile/Excel/CornerIndicator.d.ts +2 -2
  53. package/lib/components/ExcelFile/ExcelFile/Excel/DataEditor.d.ts +2 -2
  54. package/lib/components/ExcelFile/ExcelFile/Excel/DataViewer.d.ts +2 -2
  55. package/lib/components/ExcelFile/ExcelFile/Excel/FloatingRect.d.ts +2 -2
  56. package/lib/components/ExcelFile/ExcelFile/Excel/HeaderRow.d.ts +1 -1
  57. package/lib/components/ExcelFile/ExcelFile/Excel/Row.d.ts +1 -1
  58. package/lib/components/ExcelFile/ExcelFile/Excel/RowIndicator.d.ts +2 -2
  59. package/lib/components/ExcelFile/ExcelFile/Excel/Selected.d.ts +1 -1
  60. package/lib/components/ExcelFile/ExcelFile/Excel/Spreadsheet.d.ts +7 -6
  61. package/lib/components/ExcelFile/ExcelFile/Excel/Table.d.ts +1 -1
  62. package/lib/components/ExcelFile/ExcelFile/Excel/actions.d.ts +5 -49
  63. package/lib/components/ExcelFile/ExcelFile/Excel/context.d.ts +3 -3
  64. package/lib/components/ExcelFile/ExcelFile/Excel/engine/engine.d.ts +5 -5
  65. package/lib/components/ExcelFile/ExcelFile/Excel/engine/formula.d.ts +6 -6
  66. package/lib/components/ExcelFile/ExcelFile/Excel/engine/index.d.ts +2 -2
  67. package/lib/components/ExcelFile/ExcelFile/Excel/engine/point-graph.d.ts +2 -2
  68. package/lib/components/ExcelFile/ExcelFile/Excel/engine/point-hash.d.ts +1 -1
  69. package/lib/components/ExcelFile/ExcelFile/Excel/engine/point-set.d.ts +1 -1
  70. package/lib/components/ExcelFile/ExcelFile/Excel/index.d.ts +11 -11
  71. package/lib/components/ExcelFile/ExcelFile/Excel/matrix.d.ts +1 -1
  72. package/lib/components/ExcelFile/ExcelFile/Excel/point-range.d.ts +1 -1
  73. package/lib/components/ExcelFile/ExcelFile/Excel/reducer.d.ts +5 -5
  74. package/lib/components/ExcelFile/ExcelFile/Excel/selection.d.ts +3 -3
  75. package/lib/components/ExcelFile/ExcelFile/Excel/types.d.ts +48 -11
  76. package/lib/components/ExcelFile/ExcelFile/Excel/use-dispatch.d.ts +1 -1
  77. package/lib/components/ExcelFile/ExcelFile/Excel/use-selector.d.ts +1 -1
  78. package/lib/components/ExcelFile/ExcelFile/Excel/util.d.ts +12 -11
  79. package/lib/components/ExcelFile/ExcelFile/ExcelFile.d.ts +0 -16
  80. package/lib/components/ExcelFile/ExcelSheetBar/ExcelSheetBar.d.ts +3 -0
  81. package/lib/components/ExcelFile/ExcelToolBar/ExcelToolBar.d.ts +0 -12
  82. package/lib/components/ExcelFile/Types.d.ts +49 -2
  83. package/lib/components/InputWithDropdown/InputWithDropdown.d.ts +1 -1
  84. package/lib/components/InputWithDropdown/types.d.ts +3 -1
  85. package/lib/components/MenuOption/MenuOption.d.ts +1 -1
  86. package/lib/components/MenuOption/types.d.ts +4 -0
  87. package/lib/components/Select/Select.d.ts +3 -2
  88. package/lib/components/Select/Select.stories.d.ts +1 -0
  89. package/lib/components/Select/components/Dropdown.d.ts +5 -0
  90. package/lib/components/Select/components/types.d.ts +18 -0
  91. package/lib/components/Select/types.d.ts +2 -42
  92. package/lib/components/Toastify/Toastify.d.ts +5 -4
  93. package/lib/components/Toastify/types.d.ts +1 -0
  94. package/lib/index.d.ts +75 -30
  95. package/lib/index.esm.js +1734 -1441
  96. package/lib/index.esm.js.map +1 -1
  97. package/lib/index.js +1734 -1440
  98. package/lib/index.js.map +1 -1
  99. package/lib/tsconfig.tsbuildinfo +1 -1
  100. package/lib/utils/getSequentialPayload/getSequentialPayload.d.ts +2 -0
  101. package/lib/utils/getSequentialPayload/getSequentialPayload.stories.d.ts +10 -0
  102. package/lib/utils/getSequentialPayload/types.d.ts +30 -0
  103. package/package.json +1 -1
  104. package/src/assets/Themes/BaseTheme.scss +5 -0
  105. package/src/assets/Themes/DarkTheme.scss +2 -0
  106. package/src/assets/icons/maximize_icon.svg +5 -0
  107. package/src/assets/styles/_fonts.scss +1 -1
  108. package/src/components/AllProjectsDropdown/AllProjectsDropdown.scss +15 -6
  109. package/src/components/AllProjectsDropdown/AllProjectsDropdown.stories.tsx +0 -5
  110. package/src/components/AllProjectsDropdown/AllProjectsDropdown.tsx +20 -10
  111. package/src/components/Drawer/Drawer.scss +1 -0
  112. package/src/components/Drawer/Types.ts +24 -13
  113. package/src/components/Excel/ExcelFile/ExcelFile.scss +62 -0
  114. package/src/components/Excel/ExcelFile/ExcelFile.tsx +312 -0
  115. package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/ActiveCell.tsx +2 -2
  116. package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/Cell.tsx +3 -3
  117. package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/ColumnIndicator.tsx +4 -4
  118. package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/CornerIndicator.tsx +2 -2
  119. package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/DataEditor.tsx +1 -1
  120. package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/DataViewer.tsx +3 -3
  121. package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/FloatingRect.tsx +4 -4
  122. package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/RowIndicator.tsx +4 -4
  123. package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/Spreadsheet.scss +26 -24
  124. package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/Spreadsheet.tsx +13 -45
  125. package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/Table.tsx +1 -1
  126. package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/actions.ts +88 -20
  127. package/src/components/Excel/ExcelFile/ExcelFileComponents/reducer.ts +495 -0
  128. package/src/components/Excel/ExcelFile/ExcelFileComponents/reducerFunctions.ts +758 -0
  129. package/src/components/{ExcelFile → Excel}/ExcelFile.stories.tsx +45 -0
  130. package/src/components/Excel/ExcelToolBar/ExcelToolBar.scss +36 -0
  131. package/src/components/Excel/ExcelToolBar/ExcelToolBar.tsx +346 -0
  132. package/src/components/Form/Form.scss +54 -35
  133. package/src/components/Form/Form.stories.tsx +264 -225
  134. package/src/components/Icon/Icons.scss +4 -0
  135. package/src/components/Icon/iconList.ts +2 -1
  136. package/src/components/Input/Input.tsx +0 -1
  137. package/src/components/InputWithDropdown/InputWithDropdown.scss +30 -1
  138. package/src/components/InputWithDropdown/InputWithDropdown.tsx +45 -16
  139. package/src/components/InputWithDropdown/types.ts +5 -1
  140. package/src/components/MenuOption/MenuOption.scss +0 -1
  141. package/src/components/MenuOption/MenuOption.stories.tsx +3 -0
  142. package/src/components/MenuOption/MenuOption.tsx +5 -4
  143. package/src/components/MenuOption/types.ts +4 -0
  144. package/src/components/MultiSelect/MultiSelect.scss +5 -1
  145. package/src/components/MultiSelect/MultiSelect.stories.tsx +17 -13
  146. package/src/components/MultiSelect/MultiSelect.tsx +27 -14
  147. package/src/components/Select/Select.scss +121 -188
  148. package/src/components/Select/Select.stories.tsx +164 -18
  149. package/src/components/Select/Select.tsx +142 -290
  150. package/src/components/Select/components/Dropdown.scss +50 -0
  151. package/src/components/Select/components/Dropdown.tsx +94 -0
  152. package/src/components/Select/components/types.ts +20 -0
  153. package/src/components/Select/types.ts +15 -39
  154. package/src/components/Table/Table.scss +6 -5
  155. package/src/components/Table/Table.stories.tsx +0 -9
  156. package/src/components/Table/Table.tsx +2 -2
  157. package/src/components/TableTree/TableTree.scss +1 -1
  158. package/src/components/TableTree/TableTree.tsx +3 -1
  159. package/src/components/Toastify/Toastify.stories.tsx +29 -10
  160. package/src/components/Toastify/Toastify.tsx +42 -16
  161. package/src/components/Toastify/types.ts +2 -0
  162. package/src/index.ts +4 -2
  163. package/src/utils/getSelectOptionValue/getSelectOptionValue.ts +1 -1
  164. package/src/utils/getSequentialPayload/getSequentialPayload.stories.tsx +75 -0
  165. package/src/utils/getSequentialPayload/getSequentialPayload.ts +29 -0
  166. package/src/utils/getSequentialPayload/types.ts +35 -0
  167. package/src/components/ExcelFile/ExcelFile/Excel/reducer.ts +0 -952
  168. package/src/components/ExcelFile/ExcelFile/ExcelFile.scss +0 -24
  169. package/src/components/ExcelFile/ExcelFile/ExcelFile.tsx +0 -162
  170. package/src/components/ExcelFile/ExcelSheetBar/ExcelSheetBar.scss +0 -16
  171. package/src/components/ExcelFile/ExcelSheetBar/ExcelSheetBar.tsx +0 -68
  172. package/src/components/ExcelFile/ExcelToolBar/ExcelToolBar.scss +0 -19
  173. package/src/components/ExcelFile/ExcelToolBar/ExcelToolBar.tsx +0 -291
  174. package/src/fonts/Montserrat/Montserrat-Medium.ttf +0 -0
  175. package/src/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
  176. package/src/fonts/Montserrat/Montserrat-SemiBold.ttf +0 -0
  177. package/src/fonts/Poppins/Poppins-Black.ttf +0 -0
  178. package/src/fonts/Poppins/Poppins-BlackItalic.ttf +0 -0
  179. package/src/fonts/Poppins/Poppins-BoldItalic.ttf +0 -0
  180. package/src/fonts/Poppins/Poppins-ExtraBold.ttf +0 -0
  181. package/src/fonts/Poppins/Poppins-ExtraBoldItalic.ttf +0 -0
  182. package/src/fonts/Poppins/Poppins-ExtraLight.ttf +0 -0
  183. package/src/fonts/Poppins/Poppins-ExtraLightItalic.ttf +0 -0
  184. package/src/fonts/Poppins/Poppins-Italic.ttf +0 -0
  185. package/src/fonts/Poppins/Poppins-Light.ttf +0 -0
  186. package/src/fonts/Poppins/Poppins-LightItalic.ttf +0 -0
  187. package/src/fonts/Poppins/Poppins-MediumItalic.ttf +0 -0
  188. package/src/fonts/Poppins/Poppins-SemiBoldItalic.ttf +0 -0
  189. package/src/fonts/Poppins/Poppins-Thin.ttf +0 -0
  190. package/src/fonts/Poppins/Poppins-ThinItalic.ttf +0 -0
  191. /package/lib/components/{ExcelFile → Excel}/ColorBarSelector/ColorBarSelector.d.ts +0 -0
  192. /package/src/components/{ExcelFile/ColorBarselector → Excel/ColorBarSelector}/ColorBarSelector.scss +0 -0
  193. /package/src/components/{ExcelFile/ColorBarselector → Excel/ColorBarSelector}/ColorBarSelector.tsx +0 -0
  194. /package/src/components/{ExcelFile → Excel}/ContextMenu/ContextMenu.scss +0 -0
  195. /package/src/components/{ExcelFile → Excel}/ContextMenu/ContextMenu.tsx +0 -0
  196. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/Copied.tsx +0 -0
  197. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/HeaderRow.tsx +0 -0
  198. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/Row.tsx +0 -0
  199. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/Selected.tsx +0 -0
  200. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/areModelsEqual.ts +0 -0
  201. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/context.ts +0 -0
  202. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/engine/engine.ts +0 -0
  203. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/engine/formula.ts +0 -0
  204. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/engine/index.ts +0 -0
  205. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/engine/point-graph.ts +0 -0
  206. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/engine/point-hash.ts +0 -0
  207. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/engine/point-set.ts +0 -0
  208. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/index.ts +0 -0
  209. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/matrix.ts +0 -0
  210. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/point-range.ts +0 -0
  211. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/point.ts +0 -0
  212. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/selection.ts +0 -0
  213. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/types.ts +0 -0
  214. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/typings/fast-formula-parser.d.ts +0 -0
  215. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/use-dispatch.ts +0 -0
  216. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/use-selector.ts +0 -0
  217. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/util.ts +0 -0
  218. /package/src/components/{ExcelFile → Excel}/Types.ts +0 -0
  219. /package/src/components/{ExcelFile → Excel}/index.ts +0 -0
@@ -1,109 +1,17 @@
1
- import { useReducer, useRef, useEffect, useMemo } from 'react';
2
- import { Option, SelectAction, SelectProps, SelectState } from './types';
3
- import { checkEmpty } from '../../utils/checkEmpty/checkEmpty';
4
- import { createPortal } from 'react-dom';
5
- import classNames from 'classnames';
6
- import Dropdown from './components/Dropdown/Dropdown';
7
- import Icon from '../Icon';
1
+ import { ChangeEvent, FC, useEffect, useRef, useState } from 'react';
8
2
  import './Select.scss';
9
- import usePortalPosition from '../../hooks/usePortalPosition';
3
+ import Icon from '../Icon';
10
4
  import Typography from '../Typography';
5
+ import { DrowdownPosition, Option, SelectProps } from './types';
6
+ import classNames from 'classnames';
7
+ import { createPortal } from 'react-dom';
8
+ import Dropdown from './components/Dropdown';
11
9
  import { getValue } from '../../utils/getSelectOptionValue/getSelectOptionValue';
10
+ import usePortalPosition from '../../hooks/usePortalPosition';
11
+ import { checkEmpty } from '../../utils/checkEmpty/checkEmpty';
12
12
 
13
- const selectReducer = (
14
- state: SelectState,
15
- action: SelectAction
16
- ): SelectState => {
17
- switch (action.type) {
18
- case 'FOCUS_INPUT':
19
- return {
20
- ...state,
21
- isInputFocused: true,
22
- iconColor: 'var(--ff-select-brand-color)',
23
- isIconClick: true,
24
- showOptions: true,
25
- };
26
- case 'BLUR_INPUT':
27
- return {
28
- ...state,
29
- isInputFocused: false,
30
- options: action.payload.optionsList,
31
- option: action.payload.option,
32
-
33
- // todo color need to be add in style guide
34
- iconColor: 'var(--ff-select-default-color)',
35
- isIconClick: false,
36
- showOptions: false,
37
- dropdownPosition: {
38
- positionX: 0,
39
- positionY: 0,
40
- width: 0,
41
- fromBottom: 0,
42
- },
43
- };
44
- case 'MOUSE_ENTER':
45
- return state.isInputFocused
46
- ? state
47
- : { ...state, iconColor: 'var(--ff-select-text-hover-color)' };
48
- case 'MOUSE_LEAVE':
49
- return state.isInputFocused
50
- ? state
51
- : // todo color need to be add in style guide
52
- {
53
- ...state,
54
- iconColor: 'var(--ff-select-default-color)',
55
- isIconClick: false,
56
- };
57
-
58
- case 'UPDATE_DROPDOWN_POSITION':
59
- const { positionX, positionY, width, fromBottom } = action.payload || {};
60
- return {
61
- ...state,
62
- dropdownPosition: {
63
- positionX,
64
- positionY,
65
- width,
66
- fromBottom,
67
- },
68
- };
69
-
70
- case 'UPDATE_OPTION':
71
- return {
72
- ...state,
73
- option: action.payload,
74
- };
75
-
76
- case 'UPDATE_OPTION_LIST':
77
- return {
78
- ...state,
79
- options: action.payload,
80
- };
81
- case 'SHOW_ERROR':
82
- return {
83
- ...state,
84
- isInputFocused: true,
85
- isIconClick: false,
86
- showOptions: false,
87
- options: action.payload.optionsList,
88
- option: action.payload.option,
89
-
90
- // todo color need to be add in style guide
91
- iconColor: 'var(--ff-select-default-color)',
92
- dropdownPosition: {
93
- positionX: 0,
94
- positionY: 0,
95
- width: 0,
96
- fromBottom: 0,
97
- },
98
- };
99
-
100
- default:
101
- return state;
102
- }
103
- };
104
-
105
- const Select = ({
106
- label = '',
13
+ const Select: FC<SelectProps> = ({
14
+ label = 'Default Label',
107
15
  showLabel = true,
108
16
  optionsList = [],
109
17
  selectedOption = { label: '', value: '' },
@@ -112,263 +20,207 @@ const Select = ({
112
20
  className = '',
113
21
  optionZIndex = 100,
114
22
  disabled = false,
115
- borderRadius = true,
116
23
  showBorder = true,
117
- required = false,
24
+ required = true,
118
25
  optionsRequired = true,
119
26
  selectedOptionColor = 'var(--ff-select-text-color)',
120
- labelAccessor,
121
- valueAccessor,
122
- }: SelectProps) => {
123
- const initialState: SelectState = useMemo(
124
- () => ({
125
- isInputFocused: false,
126
-
127
- // todo color need to be added in style guide
128
- iconColor: 'var(--ff-select-default-color)',
129
- isIconClick: false,
130
- showOptions: false,
131
- options: optionsList,
132
- option: checkEmpty(selectedOption) ? '' : selectedOption?.value,
133
- dropdownPosition: { positionX: 0, positionY: 0, width: 0, fromBottom: 0 },
134
- }),
135
- [optionsList, selectedOption]
136
- );
137
-
138
- const [selectControlState, dispatch] = useReducer(
139
- selectReducer,
140
- initialState
141
- );
142
-
143
- const DropDownRef = useRef<HTMLDivElement>(null);
144
- const InputRef = useRef<HTMLInputElement>(null);
145
-
146
- const {
147
- isInputFocused,
148
- iconColor,
149
- isIconClick,
150
- showOptions,
151
- dropdownPosition,
152
- options,
153
- option,
154
- } = selectControlState;
155
-
156
- const calculatePosition = usePortalPosition(DropDownRef, showOptions);
157
-
158
- const handleSelectAction = (
159
- actionType:
160
- | 'FOCUS_INPUT'
161
- | 'MOUSE_ENTER'
162
- | 'MOUSE_LEAVE'
163
- | 'SHOW_ERROR'
164
- | 'BLUR_INPUT'
165
- ) => {
166
- if (!disabled) {
167
- if (actionType === 'SHOW_ERROR' || actionType === 'BLUR_INPUT') {
168
- dispatch({
169
- type: actionType,
170
- payload: { optionsList, option: getValue(selectedOption) },
171
- });
172
- } else {
173
- dispatch({ type: actionType });
174
- }
175
- }
27
+ labelAccessor = '',
28
+ valueAccessor = '',
29
+ height = 32,
30
+ width = 300,
31
+ }) => {
32
+ const [showDropdownOptions, setShowDropdownOptions] = useState(false);
33
+ const [searchedOption, setSearchedOption] = useState('');
34
+ const [selectOptionList, setSelectOptionList] = useState(optionsList);
35
+ const [dropdownPosition, setDropdownPosition] = useState<DrowdownPosition>({
36
+ positionX: 0,
37
+ positionY: 0,
38
+ width: 0,
39
+ fromBottom: 0,
40
+ });
41
+
42
+ const DropdownRef = useRef<HTMLDivElement>(null);
43
+ const selectWrapperRef = useRef<HTMLDivElement>(null);
44
+ const inputRef = useRef<HTMLInputElement>(null);
45
+ const selectArrowRef = useRef<HTMLDivElement>(null);
46
+
47
+ const calculatePosition = usePortalPosition(DropdownRef, showDropdownOptions);
48
+
49
+ const handleIconClick = () => {
50
+ setShowDropdownOptions(!showDropdownOptions);
176
51
  };
177
52
 
178
- const onSelectInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
53
+ const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
179
54
  if (disabled) return;
180
- const { value } = e.target;
55
+ const { value } = event.target;
56
+
181
57
  const filteredOptions = optionsList.filter((option) => {
182
58
  const valueData = getValue(option, valueAccessor);
183
59
  return typeof valueData === 'string'
184
60
  ? valueData.toLowerCase().includes(value.toLowerCase().trim())
185
61
  : valueData === Number(value);
186
62
  });
187
- dispatch({ type: 'UPDATE_OPTION_LIST', payload: filteredOptions });
188
- dispatch({ type: 'UPDATE_OPTION', payload: value });
63
+
64
+ setSelectOptionList(filteredOptions);
65
+ setSearchedOption(value);
189
66
  };
190
67
 
191
- const onSelectBlur = () => {
192
- if (disabled) return;
68
+ const onSelectUpdatePosition = () => {
69
+ if (!showDropdownOptions || !DropdownRef?.current || disabled) return;
70
+ setDropdownPosition(calculatePosition(DropdownRef));
71
+ };
72
+
73
+ const onSelectToggleScroll = (isEnabled: boolean): void => {
74
+ const scrollWidth =
75
+ window.innerWidth - document.documentElement.clientWidth;
193
76
 
194
- if (errorMsg) {
195
- handleSelectAction('SHOW_ERROR');
77
+ if (isEnabled) {
78
+ document.body.style.paddingRight = '';
79
+ document.body.style.overflow = '';
196
80
  } else {
197
- handleSelectAction('BLUR_INPUT');
81
+ document.body.style.paddingRight = `${scrollWidth}px`;
82
+ document.body.style.overflow = 'hidden';
198
83
  }
199
84
  };
200
85
 
201
- const onSelectOptionSelector = (option: Option) => {
202
- if (!disabled) {
203
- onSelectBlur();
204
- dispatch({
205
- type: 'UPDATE_OPTION',
206
- payload: getValue(option, valueAccessor),
207
- });
208
- if (onChange) {
209
- onChange(option);
210
- }
211
- }
86
+ const handleFocus = () => {
87
+ if (disabled) return;
88
+ setShowDropdownOptions(true);
212
89
  };
213
90
 
214
- const onSelectUpdatePosition = () => {
215
- if (!showOptions || !DropDownRef?.current || disabled) return;
216
- const { positionX, positionY, width, fromBottom } =
217
- calculatePosition(DropDownRef);
218
- dispatch({
219
- type: 'UPDATE_DROPDOWN_POSITION',
220
- payload: { positionX, positionY, width, fromBottom },
91
+ const onSelectBlur = () => {
92
+ setShowDropdownOptions(false);
93
+ setDropdownPosition({
94
+ positionX: 0,
95
+ positionY: 0,
96
+ fromBottom: 0,
97
+ width: 0,
221
98
  });
99
+ setSearchedOption(getValue(selectedOption, valueAccessor));
100
+ setSelectOptionList(optionsList);
222
101
  };
223
102
 
224
- const onSelectToggleScroll = (isEnabled: boolean) => {
225
- const bodyScrollWidth = window.innerWidth - document.body.clientWidth;
226
- document.body.style.paddingRight = isEnabled ? '' : `${bodyScrollWidth}px`;
227
- document.body.style.overflow = isEnabled ? '' : 'hidden';
103
+ const onSelectOptionSelector = (option: Option): void => {
104
+ if (disabled) return;
105
+ onSelectBlur();
106
+ setSearchedOption(getValue(option, valueAccessor));
107
+ if (onChange) {
108
+ onChange(option);
109
+ }
228
110
  };
229
111
 
230
- useEffect(() => {
112
+ const handleResizeOrScroll = () => onSelectUpdatePosition();
113
+
114
+ const hideShowScrollbar = () => {
231
115
  if (disabled) return;
232
- if (showOptions) {
233
- onSelectToggleScroll(!showOptions);
116
+ if (showDropdownOptions && optionsRequired) {
117
+ onSelectToggleScroll(!showDropdownOptions);
234
118
  }
235
119
  onSelectUpdatePosition();
236
120
 
237
- const handleResizeOrScroll = () => onSelectUpdatePosition();
238
-
239
121
  window.addEventListener('resize', handleResizeOrScroll);
240
122
  window.addEventListener('scroll', handleResizeOrScroll);
123
+ };
124
+
125
+ useEffect(() => {
126
+ hideShowScrollbar();
241
127
  return () => {
242
128
  onSelectToggleScroll(true);
243
129
  window.removeEventListener('resize', handleResizeOrScroll);
244
130
  window.removeEventListener('scroll', handleResizeOrScroll);
245
131
  };
246
- }, [showOptions]);
132
+ }, [showDropdownOptions]);
247
133
 
248
134
  useEffect(() => {
249
- if (errorMsg) {
250
- handleSelectAction('SHOW_ERROR');
251
- }
252
- }, []);
253
-
254
- const applyActiveOptionClasses = !isInputFocused && Boolean(option);
135
+ if (checkEmpty(getValue(selectedOption, valueAccessor))) return;
136
+ setSearchedOption(getValue(selectedOption, valueAccessor));
137
+ }, [selectedOption]);
255
138
 
256
139
  return (
257
- <div className={classNames(`ff-select-wrapper`)}>
258
- <div className={`ff-select ${className}`}>
140
+ <div
141
+ className={`ff-select-wrapper ${className}`}
142
+ ref={selectWrapperRef}
143
+ style={{ height: `${height}px`, width: `${width}px` }}
144
+ >
145
+ <div
146
+ className={classNames('ff-select', {
147
+ 'ff-select__focus': showDropdownOptions,
148
+ 'ff-select__disabled': disabled,
149
+ 'ff-select__error': !!errorMsg,
150
+ 'ff-select__error__focused': !!errorMsg && showDropdownOptions,
151
+ 'ff-select__no_border': !showBorder,
152
+ })}
153
+ >
259
154
  <input
260
155
  type="text"
156
+ ref={inputRef}
157
+ id="select-input-element"
261
158
  className={classNames('ff-select-input', {
262
- 'ff-select-input--default': !isInputFocused,
263
- 'ff-select-input--active': applyActiveOptionClasses,
264
- 'ff-select-input--no-label': !showLabel,
265
- 'ff-select-input--error':
266
- errorMsg && !isInputFocused && !Boolean(option),
267
- 'ff-select-input--border-radius': !borderRadius,
268
- 'ff-select-input--disable': disabled,
269
- 'ff-select-input--no-border': !showBorder,
159
+ 'ff-select-input__disabled': disabled,
270
160
  })}
271
- // inline css required due to multiple overlay scenarios are present
272
- style={{ zIndex: optionZIndex, color: selectedOptionColor }}
273
- onFocus={() => handleSelectAction('FOCUS_INPUT')}
274
- onMouseEnter={() => handleSelectAction('MOUSE_ENTER')}
275
- onMouseLeave={() => handleSelectAction('MOUSE_LEAVE')}
276
- onChange={onSelectInputChange}
277
- value={option}
278
- disabled={disabled}
161
+ onFocus={handleFocus}
162
+ value={searchedOption}
163
+ autoCorrect="off"
279
164
  autoComplete="off"
280
165
  spellCheck="false"
281
- ref={InputRef}
166
+ style={{ zIndex: optionZIndex, color: selectedOptionColor }}
167
+ disabled={disabled}
168
+ onChange={handleChange}
282
169
  />
283
-
284
- {showLabel && (
170
+ {optionsRequired && (
285
171
  <div
286
- className={classNames('ff-select-label', {
287
- 'ff-select-label--default': !isInputFocused,
288
- 'ff-select-label--active': isInputFocused || Boolean(option),
289
- 'ff-select-label--error': errorMsg,
172
+ ref={selectArrowRef}
173
+ className={classNames('ff-select-arrow-wrapper', {
174
+ 'ff-select-arrow-wrapper__disabled': disabled,
290
175
  })}
176
+ onClick={handleIconClick}
291
177
  >
292
- {required && (
293
- <Typography
294
- color="var(--error-light)"
295
- className="ff-select-label--required"
296
- >
297
- *
298
- </Typography>
299
- )}
300
- {label}
178
+ <Icon
179
+ name="arrow_down"
180
+ className="ff-select-arrow"
181
+ height={8}
182
+ width={12}
183
+ />
301
184
  </div>
302
185
  )}
303
- {optionsRequired && (
304
- <Icon
305
- name="arrow_up"
306
- height={7}
307
- width={12}
308
- className={classNames('ff-select-arrow', {
309
- 'ff-select-arrow--down': isIconClick,
310
- 'ff-select-arrow--no-label': !showLabel,
186
+ {showLabel && (
187
+ <Typography
188
+ as="span"
189
+ className={classNames('ff-select-label', {
190
+ 'ff-select-label__active': searchedOption,
311
191
  })}
312
- color={iconColor}
313
- />
192
+ fontSize={searchedOption && 8}
193
+ required={required}
194
+ >
195
+ {label}
196
+ </Typography>
314
197
  )}
315
- <fieldset
316
- className={classNames('ff-select-fieldset', {
317
- 'ff-select-fieldset--no-label': !showLabel,
318
- 'ff-select-fieldset--default': !isInputFocused,
319
- 'ff-select-fieldset--active': isInputFocused,
320
- 'ff-select-fieldset--option': applyActiveOptionClasses,
321
- 'ff-select-fieldset--error': errorMsg,
322
- 'ff-select-fieldset--border-radius': !borderRadius,
323
- 'ff-select-fieldset--no-border': !showBorder,
324
- })}
325
- >
326
- {showLabel && (
327
- <legend
328
- className={classNames('ff-select-legend', {
329
- 'ff-select-legend--default': !isInputFocused,
330
- 'ff-select-legend--active': isInputFocused,
331
- 'ff-select-legend--option': applyActiveOptionClasses,
332
- 'ff-select-legend--error': errorMsg,
333
- })}
334
- >
335
- {required && (
336
- <Typography
337
- fontSize={8}
338
- color={'var(--error-light)'}
339
- className="ff-select-legend--required"
340
- >
341
- *
342
- </Typography>
343
- )}
344
- {label}
345
- </legend>
346
- )}
347
- </fieldset>
348
198
  </div>
349
-
350
199
  {errorMsg && (
351
200
  <Typography
352
- className="ff-select-wrapper-error-text"
201
+ as="div"
202
+ lineHeight="12px"
353
203
  fontSize={8}
354
- color={'var(--error-light)'}
204
+ color="var(--error_light)"
205
+ className="ff-select-error-msg"
355
206
  >
356
207
  {errorMsg}
357
208
  </Typography>
358
209
  )}
359
210
 
360
211
  {optionsRequired && (
361
- <div ref={DropDownRef}>
362
- {showOptions &&
212
+ <div ref={DropdownRef}>
213
+ {showDropdownOptions &&
363
214
  createPortal(
364
215
  <Dropdown
365
- onSelectBlur={onSelectBlur}
366
- onSelectOptionSelector={onSelectOptionSelector}
216
+ options={selectOptionList}
367
217
  dropdownPosition={dropdownPosition}
368
- options={options}
369
- optionZIndex={optionZIndex}
370
- inputRef={InputRef}
371
218
  labelAccessor={labelAccessor}
219
+ optionZIndex={optionZIndex}
220
+ inputRef={inputRef}
221
+ selectArrowRef={selectArrowRef}
222
+ onSelectBlur={onSelectBlur}
223
+ onSelectOptionSelector={onSelectOptionSelector}
372
224
  />,
373
225
  document.body
374
226
  )}
@@ -0,0 +1,50 @@
1
+ .ff-select-dropdown-wrapper {
2
+ max-height: 160px;
3
+ z-index: 999999;
4
+ position: absolute;
5
+ min-width: 50px;
6
+ border-radius: 4px;
7
+ border: 1px solid var(--ff-select-option-border-color);
8
+ margin-top: 4px;
9
+ box-shadow: 0px 1px 4px 0px var(--ff-select-option-wrapper-box-shadow);
10
+ background-color: var(--ff-select-background-color);
11
+ overflow: hidden auto;
12
+
13
+ &::-webkit-scrollbar {
14
+ width: 4px;
15
+ height: 12px;
16
+ &-thumb {
17
+ background-color: var(--ff-select-scroll-thumb-color);
18
+ border-radius: 4px;
19
+ }
20
+
21
+ &-track {
22
+ background: var(--ff-select-scroll-track-bg);
23
+ border-radius: 4px;
24
+ }
25
+ }
26
+
27
+ .ff-select-dropdown-option {
28
+ box-sizing: border-box;
29
+ cursor: pointer;
30
+ padding: 0px 8px;
31
+ border-radius: 4px;
32
+ min-height: 32px;
33
+ white-space: nowrap;
34
+ text-overflow: ellipsis;
35
+ overflow: hidden;
36
+
37
+ &:hover {
38
+ background-color: var(--ff-select-option-hover-color);
39
+ }
40
+ }
41
+
42
+ .ff-select-no-option {
43
+ box-sizing: border-box;
44
+ padding: 0px 8px;
45
+ overflow: hidden;
46
+ white-space: nowrap;
47
+ text-overflow: ellipsis;
48
+ cursor: not-allowed;
49
+ }
50
+ }
@@ -0,0 +1,94 @@
1
+ import { useContext, useRef, type FC } from 'react';
2
+ import { dropdownDefaultCSSData, DropdownProps } from './types';
3
+ import './Dropdown.scss';
4
+ import { checkEmpty } from '../../../utils/checkEmpty/checkEmpty';
5
+ import Typography from '../../Typography';
6
+ import { ffid } from '../../../utils/ffID/ffid';
7
+ import { ThemeContext } from '../../ThemeProvider/ThemeProvider';
8
+ import classNames from 'classnames';
9
+ import { getLabel } from '../../../utils/getSelectOptionValue/getSelectOptionValue';
10
+ import useClickOutside from '../../../hooks/useClickOutside';
11
+
12
+ const Dropdown: FC<DropdownProps> = ({
13
+ options = [],
14
+ optionZIndex = 10000000,
15
+ dropdownPosition,
16
+ labelAccessor,
17
+ onSelectOptionSelector,
18
+ onSelectBlur,
19
+ inputRef,
20
+ selectArrowRef,
21
+ }) => {
22
+ const themeContext = useContext(ThemeContext);
23
+ const currentTheme = themeContext?.currentTheme;
24
+
25
+ const optionsWrapperRef = useRef<HTMLDivElement>(null);
26
+ useClickOutside(optionsWrapperRef, onSelectBlur, [inputRef, selectArrowRef]);
27
+
28
+ const { positionX, positionY, width, fromBottom } = dropdownPosition;
29
+ const { margin, optionHeight, selectInputHeight, dropDownWrapperPadding } =
30
+ dropdownDefaultCSSData;
31
+
32
+ const updateDropdownPosition = () => {
33
+ let dropdownContainerHeight;
34
+
35
+ if (checkEmpty(options)) {
36
+ dropdownContainerHeight = 32 + 2 * dropDownWrapperPadding;
37
+ } else if (options?.length > 5) {
38
+ dropdownContainerHeight = 160;
39
+ } else {
40
+ dropdownContainerHeight =
41
+ options.length * optionHeight + 2 * dropDownWrapperPadding;
42
+ }
43
+
44
+ if (fromBottom > dropdownContainerHeight + margin) {
45
+ return {
46
+ left: positionX,
47
+ top: positionY,
48
+ width: width,
49
+ zIndex: optionZIndex,
50
+ };
51
+ }
52
+ return {
53
+ zIndex: optionZIndex,
54
+ left: positionX,
55
+ width: width,
56
+ top: positionY - selectInputHeight - dropdownContainerHeight - margin,
57
+ };
58
+ };
59
+
60
+ return (
61
+ <div
62
+ className={classNames('ff-select-dropdown-wrapper', currentTheme)}
63
+ ref={optionsWrapperRef}
64
+ style={updateDropdownPosition()}
65
+ >
66
+ {!checkEmpty(options) ? (
67
+ options.map((option) => (
68
+ <Typography
69
+ key={ffid()}
70
+ as="div"
71
+ lineHeight="30px"
72
+ className={classNames('ff-select-dropdown-option', currentTheme)}
73
+ color="var(--ff-select-text-color)"
74
+ onClick={() => onSelectOptionSelector(option)}
75
+ >
76
+ {getLabel(option, labelAccessor)}
77
+ </Typography>
78
+ ))
79
+ ) : (
80
+ <Typography
81
+ textAlign="center"
82
+ as="div"
83
+ lineHeight="32px"
84
+ color="var(--ff-select-text-color)"
85
+ className={classNames('ff-select-no-option', currentTheme)}
86
+ >
87
+ No Results found
88
+ </Typography>
89
+ )}
90
+ </div>
91
+ );
92
+ };
93
+
94
+ export default Dropdown;
@@ -0,0 +1,20 @@
1
+ import { DrowdownPosition, Option } from '../types';
2
+
3
+ export interface DropdownProps {
4
+ options: Option[];
5
+ dropdownPosition: DrowdownPosition;
6
+ optionZIndex: number;
7
+ labelAccessor?: string;
8
+ valueAccessor?: string;
9
+ onSelectBlur: () => void;
10
+ onSelectOptionSelector: (option: Option) => void;
11
+ inputRef?: React.RefObject<HTMLInputElement>;
12
+ selectArrowRef?: React.RefObject<HTMLDivElement>;
13
+ }
14
+
15
+ export const dropdownDefaultCSSData = {
16
+ margin: 6,
17
+ optionHeight: 32,
18
+ selectInputHeight: 38,
19
+ dropDownWrapperPadding: 0,
20
+ };