@innovaccer/design-system 2.6.0 → 2.7.0-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (287) hide show
  1. package/.eslintrc.json +10 -9
  2. package/.github/workflows/chromatic.yml +5 -0
  3. package/.github/workflows/pull_request.yml +1 -1
  4. package/.storybook/main.js +4 -0
  5. package/.vscode/settings.json +11 -0
  6. package/CHANGELOG.md +36 -0
  7. package/CONTRIBUTING.md +7 -1
  8. package/core/accessibility/utils/useAccessibilityProps.ts +4 -2
  9. package/core/common.type.tsx +22 -0
  10. package/core/components/atoms/_chip/__tests__/__snapshots__/_chip.test.tsx.snap +9 -9
  11. package/core/components/atoms/_chip/index.tsx +17 -3
  12. package/core/components/atoms/avatar/Avatar.tsx +4 -14
  13. package/core/components/atoms/avatar/__stories__/variants/Appearance.story.tsx +3 -2
  14. package/core/components/atoms/avatar/__tests__/Avatar.test.tsx +14 -9
  15. package/core/components/atoms/avatarGroup/AvatarGroup.tsx +3 -5
  16. package/core/components/atoms/badge/Badge.tsx +2 -12
  17. package/core/components/atoms/badge/__tests__/Badge.test.tsx +22 -7
  18. package/core/components/atoms/badge/_stories_/variants/Appearance.story.tsx +3 -2
  19. package/core/components/atoms/badge/_stories_/variants/Subtle.story.tsx +3 -2
  20. package/core/components/atoms/button/Button.tsx +10 -7
  21. package/core/components/atoms/button/__stories__/index.story.tsx +1 -1
  22. package/core/components/atoms/button/__stories__/variants/Appearance.story.tsx +2 -2
  23. package/core/components/atoms/button/__stories__/variants/Expanded.story.tsx +2 -2
  24. package/core/components/atoms/button/__stories__/variants/icon/IconLeft.story.tsx +2 -2
  25. package/core/components/atoms/button/__stories__/variants/icon/IconRight.story.tsx +2 -2
  26. package/core/components/atoms/button/__tests__/Button.test.tsx +1 -1
  27. package/core/components/atoms/button/__tests__/__snapshots__/Button.test.tsx.snap +0 -137
  28. package/core/components/atoms/card/__stories__/empty.story.tsx +1 -1
  29. package/core/components/atoms/card/__stories__/nested.story.tsx +1 -1
  30. package/core/components/atoms/card/__stories__/scroll.story.tsx +1 -1
  31. package/core/components/atoms/checkbox/Checkbox.tsx +8 -9
  32. package/core/components/atoms/checkbox/__stories__/variants/Size.story.tsx +2 -2
  33. package/core/components/atoms/chip/Chip.tsx +3 -2
  34. package/core/components/atoms/chip/__stories__/variants/Selection.story.tsx +17 -0
  35. package/core/components/atoms/chip/__stories__/variants/Type.story.tsx +2 -2
  36. package/core/components/atoms/chip/__tests__/Chip.test.tsx +7 -0
  37. package/core/components/atoms/chipGroup/__tests__/__snapshots__/chipGroup.test.tsx.snap +5 -5
  38. package/core/components/atoms/chipGroup/__tests__/chipGroup.test.tsx +2 -2
  39. package/core/components/atoms/chipGroup/_stories_/index.story.tsx +2 -2
  40. package/core/components/atoms/dropdown/Dropdown.tsx +18 -17
  41. package/core/components/atoms/dropdown/DropdownButton.tsx +2 -2
  42. package/core/components/atoms/dropdown/DropdownList.tsx +10 -5
  43. package/core/components/atoms/dropdown/Loading.tsx +1 -1
  44. package/core/components/atoms/dropdown/__stories__/CustomSearchPlaceholder.story.tsx +45 -0
  45. package/core/components/atoms/dropdown/__stories__/_common_/types.tsx +3 -0
  46. package/core/components/atoms/dropdown/__stories__/variants/Size.story.tsx +2 -2
  47. package/core/components/atoms/dropdown/__stories__/variants/controlledDropdown/MultiSelect.story.tsx +1 -1
  48. package/core/components/atoms/dropdown/__tests__/Dropdown.test.tsx +12 -1
  49. package/core/components/atoms/dropdown/__tests__/Loading.test.tsx +0 -1
  50. package/core/components/atoms/dropdown/option/index.tsx +1 -1
  51. package/core/components/atoms/heading/Heading.tsx +4 -4
  52. package/core/components/atoms/heading/__stories__/variants/Appearance.story.tsx +3 -2
  53. package/core/components/atoms/heading/__tests__/Heading.test.tsx +4 -3
  54. package/core/components/atoms/icon/Icon.tsx +3 -3
  55. package/core/components/atoms/input/Input.tsx +3 -3
  56. package/core/components/atoms/input/__stories__/InputWithCaption.story.tsx +62 -0
  57. package/core/components/atoms/input/__stories__/LabelPosition.story.tsx +38 -0
  58. package/core/components/atoms/input/__stories__/variants/controlledInput.story.tsx +46 -0
  59. package/core/components/atoms/input/__stories__/variants/types/BasicInput.story.tsx +2 -2
  60. package/core/components/atoms/input/__stories__/variants/types/IconLeft.story.tsx +2 -10
  61. package/core/components/atoms/input/__stories__/variants/types/WithLabel.story.tsx +1 -9
  62. package/core/components/atoms/label/Label.tsx +1 -1
  63. package/core/components/atoms/legend/Legend.tsx +2 -2
  64. package/core/components/atoms/legend/__stories__/variants/labelAppearance.story.tsx +2 -2
  65. package/core/components/atoms/link/Link.tsx +4 -4
  66. package/core/components/atoms/message/Message.tsx +12 -12
  67. package/core/components/atoms/message/__stories__/index.story.tsx +1 -1
  68. package/core/components/atoms/message/__stories__/variants/Appearance.story.tsx +1 -1
  69. package/core/components/atoms/message/__stories__/variants/AppearanceTitle.story.tsx +1 -1
  70. package/core/components/atoms/message/__tests__/Message.test.tsx +1 -6
  71. package/core/components/atoms/message/__tests__/__snapshots__/Message.test.tsx.snap +0 -45
  72. package/core/components/atoms/metaList/__tests__/MetaList.test.tsx +2 -2
  73. package/core/components/atoms/metricInput/MetricInput.tsx +5 -5
  74. package/core/components/atoms/multiSlider/SliderUtils.tsx +1 -4
  75. package/core/components/atoms/multiSlider/index.tsx +3 -4
  76. package/core/components/atoms/outsideClick/OutsideClick.tsx +1 -2
  77. package/core/components/atoms/paragraph/Paragraph.tsx +2 -2
  78. package/core/components/atoms/paragraph/__stories__/variants/Appearance.story.tsx +2 -2
  79. package/core/components/atoms/paragraph/__tests__/Paragraph.test.tsx +2 -2
  80. package/core/components/atoms/pills/Pills.tsx +2 -12
  81. package/core/components/atoms/pills/__stories__/variants/Appearance.story.tsx +3 -2
  82. package/core/components/atoms/pills/__stories__/variants/Subtle.story.tsx +3 -2
  83. package/core/components/atoms/pills/__tests__/Pills.test.tsx +3 -2
  84. package/core/components/atoms/placeholderImage/PlaceholderImage.tsx +2 -2
  85. package/core/components/atoms/placeholderImage/__stories__/variants/Size.story.tsx +2 -2
  86. package/core/components/atoms/placeholderParagraph/PlaceholderParagraph.tsx +2 -2
  87. package/core/components/atoms/placeholderParagraph/__stories__/variants/Size.story.tsx +2 -2
  88. package/core/components/atoms/popperWrapper/PopperWrapper.tsx +2 -6
  89. package/core/components/atoms/progressRing/ProgressRing.tsx +2 -2
  90. package/core/components/atoms/progressRing/__stories__/variants/Size.story.tsx +1 -1
  91. package/core/components/atoms/radio/Radio.tsx +4 -5
  92. package/core/components/atoms/rangeSlider/RangeSlider.tsx +1 -2
  93. package/core/components/atoms/rangeSlider/__stories__/index.story.tsx +1 -2
  94. package/core/components/atoms/rangeSlider/__stories__/variants/Controlled.story.tsx +1 -2
  95. package/core/components/atoms/rangeSlider/__stories__/variants/CustomLabels.story.tsx +1 -2
  96. package/core/components/atoms/spinner/Spinner.tsx +4 -4
  97. package/core/components/atoms/spinner/__stories__/variants/Appearance.story.tsx +2 -2
  98. package/core/components/atoms/spinner/__stories__/variants/Size.story.tsx +1 -1
  99. package/core/components/atoms/statusHint/StatusHint.tsx +2 -3
  100. package/core/components/atoms/statusHint/__stories__/variants/Appearance.story.tsx +3 -2
  101. package/core/components/atoms/statusHint/__tests__/StatusHint.test.tsx +3 -2
  102. package/core/components/atoms/subheading/Subheading.tsx +2 -2
  103. package/core/components/atoms/subheading/__stories__/variants/Appearance.story.tsx +3 -2
  104. package/core/components/atoms/subheading/__tests__/Subheading.test.tsx +3 -2
  105. package/core/components/atoms/switchInput/Switch.tsx +7 -8
  106. package/core/components/atoms/text/Text.tsx +4 -4
  107. package/core/components/atoms/text/__stories__/variants/Appearance.story.tsx +2 -2
  108. package/core/components/atoms/text/__tests__/Text.test.tsx +2 -3
  109. package/core/components/atoms/toast/ActionButton.tsx +2 -2
  110. package/core/components/atoms/toast/Toast.tsx +11 -6
  111. package/core/components/atoms/toast/__stories__/index.story.tsx +2 -6
  112. package/core/components/atoms/toast/__stories__/variants/Appearance.story.tsx +3 -2
  113. package/core/components/atoms/toast/__stories__/variants/ToastMessage.story.tsx +3 -2
  114. package/core/components/atoms/toast/__stories__/variants/ToastWithAction.story.tsx +3 -2
  115. package/core/components/atoms/toast/__tests__/Toast.test.tsx +1 -1
  116. package/core/components/atoms/toast/__tests__/__snapshots__/Toast.test.tsx.snap +0 -131
  117. package/core/components/css-utilities/Schema.tsx +1 -1
  118. package/core/components/css-utilities/Spacing/Schema.tsx +1 -1
  119. package/core/components/molecules/chipInput/__tests__/__snapshots__/ChipInput.test.tsx.snap +2 -2
  120. package/core/components/molecules/dropzone/Dropzone.tsx +3 -3
  121. package/core/components/molecules/dropzone/DropzoneBase.tsx +22 -38
  122. package/core/components/molecules/dropzone/__stories__/index.story.tsx +151 -41
  123. package/core/components/molecules/dropzone/__tests__/Dropzone.test.tsx +2 -2
  124. package/core/components/molecules/dropzone/utils.tsx +6 -4
  125. package/core/components/molecules/editableChipInput/__tests__/__snapshots__/EditableChipInput.test.tsx.snap +4 -4
  126. package/core/components/molecules/emptyState/EmptyState.tsx +4 -4
  127. package/core/components/molecules/emptyState/__stories__/pageNotLoadedWithSVG.story.tsx +26 -26
  128. package/core/components/molecules/fileList/FileListItem.tsx +1 -2
  129. package/core/components/molecules/fileUploader/FileUploaderItem.tsx +1 -2
  130. package/core/components/molecules/fileUploader/FileUploaderStatus.tsx +1 -1
  131. package/core/components/molecules/fileUploader/__stories__/_common_/types.tsx +3 -0
  132. package/core/components/molecules/fileUploader/__stories__/index.story.tsx +3 -222
  133. package/core/components/molecules/fullscreenModal/FullscreenModal.tsx +5 -7
  134. package/core/components/molecules/inputMask/InputMask.tsx +212 -146
  135. package/core/components/molecules/inputMask/__stories__/index.story.tsx +24 -0
  136. package/core/components/molecules/modal/Modal.tsx +4 -6
  137. package/core/components/molecules/modal/__stories__/Confirmation.story.tsx +1 -1
  138. package/core/components/molecules/placeholder/Placeholder.tsx +2 -2
  139. package/core/components/molecules/popover/Popover.tsx +2 -9
  140. package/core/components/molecules/sidesheet/Sidesheet.tsx +5 -7
  141. package/core/components/molecules/sidesheet/__stories__/variants/CustomHeader.story.tsx +172 -0
  142. package/core/components/molecules/tooltip/Tooltip.tsx +4 -4
  143. package/core/components/organisms/calendar/__stories__/variants/firstDayOfWeek.story.tsx +2 -2
  144. package/core/components/organisms/calendar/utility.ts +3 -3
  145. package/core/components/organisms/choiceList/ChoiceList.tsx +11 -11
  146. package/core/components/organisms/datePicker/DatePicker.tsx +1 -1
  147. package/core/components/organisms/datePicker/Trigger.tsx +1 -5
  148. package/core/components/organisms/dateRangePicker/DateRangePicker.tsx +9 -10
  149. package/core/components/organisms/dateRangePicker/SingleInputTrigger.tsx +0 -1
  150. package/core/components/organisms/dateRangePicker/Trigger.tsx +2 -2
  151. package/core/components/organisms/dateRangePicker/__stories__/variants/monthsInView.story.tsx +2 -2
  152. package/core/components/organisms/dateRangePicker/__tests__/__snapshots__/DateRangePicker.test.tsx.snap +16 -16
  153. package/core/components/organisms/grid/Cell.tsx +19 -19
  154. package/core/components/organisms/grid/Grid.tsx +3 -4
  155. package/core/components/organisms/grid/GridBody.tsx +0 -1
  156. package/core/components/organisms/grid/GridContext.ts +1 -1
  157. package/core/components/organisms/grid/__stories__/_common_/editableSchema.tsx +1 -3
  158. package/core/components/organisms/grid/__stories__/_common_/fetchData.ts +1 -1
  159. package/core/components/organisms/grid/__stories__/_common_/loaderSchema.ts +0 -2
  160. package/core/components/organisms/grid/__stories__/_common_/schema.tsx +1 -3
  161. package/core/components/organisms/grid/__stories__/_common_/simpleLoaderSchema.ts +0 -2
  162. package/core/components/organisms/grid/__stories__/_common_/statusSchema.ts +0 -2
  163. package/core/components/organisms/inlineMessage/InlineMessage.tsx +2 -2
  164. package/core/components/organisms/inlineMessage/__tests__/InlineMessage.test.tsx +3 -2
  165. package/core/components/organisms/list/__stories__/_common_/types.tsx +3 -0
  166. package/core/components/organisms/list/__stories__/index.story.tsx +0 -16
  167. package/core/components/organisms/table/Table.tsx +2 -2
  168. package/core/components/organisms/table/__stories__/CompressedTable.story.tsx +1 -1
  169. package/core/components/organisms/table/__stories__/DataTable.story.tsx +1 -1
  170. package/core/components/organisms/table/__stories__/NestedTableWithNestedCard.story.tsx +1 -1
  171. package/core/components/organisms/table/__stories__/PinnedColumn.story.tsx +1 -1
  172. package/core/components/organisms/table/__stories__/ResourceTable.story.tsx +1 -1
  173. package/core/components/organisms/table/__stories__/StandardTable.story.tsx +1 -1
  174. package/core/components/organisms/table/__stories__/TableAsDescriptionList.story.tsx +1 -1
  175. package/core/components/organisms/table/__stories__/TableAsOptionList.story.tsx +1 -1
  176. package/core/components/organisms/table/__stories__/TightStory.story.tsx +1 -1
  177. package/core/components/organisms/table/__stories__/_common_/types.tsx +3 -0
  178. package/core/components/organisms/table/__stories__/variants/showHead.story.tsx +2 -2
  179. package/core/components/organisms/table/__stories__/variants/showMenu.story.tsx +2 -2
  180. package/core/components/organisms/table/__stories__/variants/size.story.tsx +2 -2
  181. package/core/components/organisms/table/__stories__/variants/type.story.tsx +2 -2
  182. package/core/components/organisms/table/__stories__/variants/withCheckbox.story.tsx +2 -2
  183. package/core/components/organisms/table/__stories__/variants/withPagination.story.tsx +2 -2
  184. package/core/components/organisms/timePicker/TimePicker.tsx +3 -7
  185. package/core/components/organisms/verticalNav/__stories__/schema.tsx +0 -2
  186. package/core/components/organisms/verticalNav/__tests__/VerticalNav.test.tsx +1 -2
  187. package/core/global.d.ts +9 -0
  188. package/core/index.tsx +1 -1
  189. package/core/utils/__tests__/__snapshots__/TS.test.tsx.snap +18 -5
  190. package/core/utils/docPage/generateImports.tsx +2 -3
  191. package/core/utils/docPage/index.tsx +30 -20
  192. package/core/utils/docPage/sandbox.tsx +14 -7
  193. package/core/utils/overlayHelper.ts +7 -3
  194. package/core/utils/testHelper.ts +1 -1
  195. package/core/utils/types.tsx +1 -1
  196. package/css/dist/index.css +48 -30
  197. package/css/dist/index.css.map +1 -1
  198. package/css/src/components/button.css +5 -5
  199. package/css/src/components/calendar.css +1 -1
  200. package/css/src/components/chip.css +6 -4
  201. package/css/src/components/fullscreenModal.css +4 -3
  202. package/css/src/components/message.css +0 -5
  203. package/css/src/components/switch.css +23 -2
  204. package/css/src/components/toast.css +0 -5
  205. package/css/src/variables/index.css +5 -2
  206. package/dist/core/accessibility/utils/useAccessibilityProps.d.ts +4 -1
  207. package/dist/core/common.type.d.ts +12 -0
  208. package/dist/core/components/atoms/avatar/Avatar.d.ts +4 -4
  209. package/dist/core/components/atoms/avatarGroup/AvatarGroup.d.ts +2 -3
  210. package/dist/core/components/atoms/badge/Badge.d.ts +2 -2
  211. package/dist/core/components/atoms/button/Button.d.ts +6 -6
  212. package/dist/core/components/atoms/checkbox/Checkbox.d.ts +3 -3
  213. package/dist/core/components/atoms/chip/Chip.d.ts +2 -2
  214. package/dist/core/components/atoms/dropdown/Dropdown.d.ts +18 -17
  215. package/dist/core/components/atoms/dropdown/DropdownButton.d.ts +2 -2
  216. package/dist/core/components/atoms/dropdown/DropdownList.d.ts +4 -3
  217. package/dist/core/components/atoms/dropdown/option/index.d.ts +1 -1
  218. package/dist/core/components/atoms/heading/Heading.d.ts +4 -4
  219. package/dist/core/components/atoms/icon/Icon.d.ts +2 -2
  220. package/dist/core/components/atoms/input/Input.d.ts +3 -3
  221. package/dist/core/components/atoms/legend/Legend.d.ts +2 -2
  222. package/dist/core/components/atoms/link/Link.d.ts +4 -4
  223. package/dist/core/components/atoms/message/Message.d.ts +2 -2
  224. package/dist/core/components/atoms/metricInput/MetricInput.d.ts +3 -3
  225. package/dist/core/components/atoms/multiSlider/SliderUtils.d.ts +1 -1
  226. package/dist/core/components/atoms/multiSlider/index.d.ts +3 -3
  227. package/dist/core/components/atoms/paragraph/Paragraph.d.ts +2 -2
  228. package/dist/core/components/atoms/pills/Pills.d.ts +2 -2
  229. package/dist/core/components/atoms/placeholderImage/PlaceholderImage.d.ts +2 -2
  230. package/dist/core/components/atoms/placeholderParagraph/PlaceholderParagraph.d.ts +2 -2
  231. package/dist/core/components/atoms/popperWrapper/PopperWrapper.d.ts +1 -2
  232. package/dist/core/components/atoms/progressRing/ProgressRing.d.ts +2 -2
  233. package/dist/core/components/atoms/radio/Radio.d.ts +4 -4
  234. package/dist/core/components/atoms/rangeSlider/RangeSlider.d.ts +1 -1
  235. package/dist/core/components/atoms/spinner/Spinner.d.ts +4 -4
  236. package/dist/core/components/atoms/statusHint/StatusHint.d.ts +2 -2
  237. package/dist/core/components/atoms/subheading/Subheading.d.ts +2 -2
  238. package/dist/core/components/atoms/switchInput/Switch.d.ts +6 -6
  239. package/dist/core/components/atoms/text/Text.d.ts +4 -4
  240. package/dist/core/components/atoms/toast/ActionButton.d.ts +2 -2
  241. package/dist/core/components/atoms/toast/Toast.d.ts +2 -2
  242. package/dist/core/components/molecules/dropzone/Dropzone.d.ts +3 -3
  243. package/dist/core/components/molecules/dropzone/DropzoneBase.d.ts +1 -1
  244. package/dist/core/components/molecules/dropzone/utils.d.ts +5 -3
  245. package/dist/core/components/molecules/emptyState/EmptyState.d.ts +4 -4
  246. package/dist/core/components/molecules/fileList/FileListItem.d.ts +1 -1
  247. package/dist/core/components/molecules/fileUploader/FileUploaderItem.d.ts +1 -1
  248. package/dist/core/components/molecules/fileUploader/FileUploaderStatus.d.ts +1 -1
  249. package/dist/core/components/molecules/fullscreenModal/FullscreenModal.d.ts +4 -7
  250. package/dist/core/components/molecules/inputMask/InputMask.d.ts +10 -2
  251. package/dist/core/components/molecules/modal/Modal.d.ts +3 -6
  252. package/dist/core/components/molecules/placeholder/Placeholder.d.ts +2 -2
  253. package/dist/core/components/molecules/popover/Popover.d.ts +0 -1
  254. package/dist/core/components/molecules/sidesheet/Sidesheet.d.ts +3 -6
  255. package/dist/core/components/molecules/tooltip/Tooltip.d.ts +3 -3
  256. package/dist/core/components/organisms/choiceList/ChoiceList.d.ts +5 -6
  257. package/dist/core/components/organisms/dateRangePicker/DateRangePicker.d.ts +24 -0
  258. package/dist/core/components/organisms/grid/Cell.d.ts +1 -1
  259. package/dist/core/components/organisms/grid/Grid.d.ts +3 -3
  260. package/dist/core/components/organisms/grid/GridContext.d.ts +1 -1
  261. package/dist/core/components/organisms/inlineMessage/InlineMessage.d.ts +2 -2
  262. package/dist/core/components/organisms/table/Table.d.ts +2 -2
  263. package/dist/core/components/patterns/dateRangePicker/withCustomPopover.story.d.ts +5 -1
  264. package/dist/core/utils/docPage/generateImports.d.ts +1 -1
  265. package/dist/core/utils/overlayHelper.d.ts +1 -1
  266. package/dist/core/utils/types.d.ts +1 -1
  267. package/dist/index.esm.js +221 -245
  268. package/dist/index.js +225 -233
  269. package/dist/index.js.map +1 -1
  270. package/dist/index.umd.js +1 -1
  271. package/dist/index.umd.js.br +0 -0
  272. package/dist/index.umd.js.gz +0 -0
  273. package/dts.config.js +11 -2
  274. package/package.json +20 -18
  275. package/tsconfig.json +3 -16
  276. package/tsconfig.type.json +2 -1
  277. package/types/index.d.ts +2217 -0
  278. package/types/{innovaccer-design-system/tsconfig.json → tsconfig.json} +1 -1
  279. package/types/{innovaccer-design-system/tslint.json → tslint.json} +0 -0
  280. package/types/types-tests.tsx +936 -0
  281. package/core/components/atoms/button/__stories__/variants/state/Success.story.tsx +0 -89
  282. package/core/components/atoms/message/__stories__/default.story.tsx +0 -16
  283. package/core/components/atoms/toast/__stories__/DefaultToast.story.tsx +0 -16
  284. package/core/components/molecules/dropzone/__stories__/variants/DropzoneWithFileList.story.tsx +0 -176
  285. package/core/components/molecules/fileUploader/__stories__/variants/FileUploaderList.story.tsx +0 -80
  286. package/types/innovaccer-design-system/index.d.ts +0 -39
  287. package/types/innovaccer-design-system/innovaccer-design-system-tests.ts +0 -0
@@ -51,12 +51,18 @@ type SelectionPos = {
51
51
  end: number;
52
52
  };
53
53
 
54
+ type InputMaskType = React.ForwardRefExoticComponent<InputProps & MaskProps & React.RefAttributes<HTMLInputElement>> & {
55
+ utils: {
56
+ getDefaultValue: typeof getDefaultValue;
57
+ };
58
+ };
59
+
54
60
  /**
55
61
  * It works as Uncontrolled Input
56
62
  *
57
63
  * **Updated value can be passed**
58
64
  */
59
- export const InputMask = React.forwardRef<HTMLInputElement, InputMaskProps>((props, forwardRef) => {
65
+ const InputMask = React.forwardRef<HTMLInputElement, InputMaskProps>((props, forwardRef) => {
60
66
  const {
61
67
  mask: maskProp,
62
68
  value: valueProp,
@@ -76,39 +82,46 @@ export const InputMask = React.forwardRef<HTMLInputElement, InputMaskProps>((pro
76
82
  ...rest
77
83
  } = props;
78
84
 
79
- const getNewCursorPosition = (type: 'left' | 'right', position: number): number => {
80
- if (type === 'right') {
81
- for (let i = position; i < mask.length; i++) {
82
- if (isEditable(i)) return i;
85
+ const isEditable = React.useCallback((pos: number) => typeof mask[pos] === 'object', [mask]);
86
+
87
+ const getNewCursorPosition = React.useCallback(
88
+ (type: 'left' | 'right', position: number): number => {
89
+ if (type === 'right') {
90
+ for (let i = position; i < mask.length; i++) {
91
+ if (isEditable(i)) return i;
92
+ }
93
+ return mask.length;
83
94
  }
84
- return mask.length;
85
- }
86
- if (type === 'left') {
87
- for (let i = position; i >= 0; i--) {
88
- if (isEditable(i - 1)) return i;
95
+ if (type === 'left') {
96
+ for (let i = position; i >= 0; i--) {
97
+ if (isEditable(i - 1)) return i;
98
+ }
99
+ return 0;
89
100
  }
90
- return 0;
91
- }
92
- return position;
93
- };
101
+ return position;
102
+ },
103
+ [mask, isEditable]
104
+ );
94
105
 
95
- const getDefaultSelection = () => {
106
+ const getDefaultSelection = React.useCallback(() => {
96
107
  const pos = getNewCursorPosition('right', 0);
97
108
  return { start: pos, end: pos };
98
- };
109
+ }, [getNewCursorPosition]);
99
110
 
100
- const getPlaceholderValue = (start: number = 0, end: number = mask.length - 1) =>
101
- getDefaultValue(mask, placeholderChar).slice(start, end + 1);
102
-
103
- const getSelectionLength = (val: SelectionPos) => Math.abs(val.end - val.start);
111
+ const getPlaceholderValue = React.useCallback(
112
+ (start = 0, end: number = mask.length - 1) => getDefaultValue(mask, placeholderChar).slice(start, end + 1),
113
+ [mask, placeholderChar]
114
+ );
104
115
 
105
- const isEditable = (pos: number) => typeof mask[pos] === 'object';
116
+ const defaultPlaceholderValue = React.useMemo(() => getPlaceholderValue(), [getPlaceholderValue]);
117
+ const defaultSelection = React.useMemo(() => getDefaultSelection(), [getDefaultSelection]);
106
118
 
119
+ const ref = React.useRef<HTMLInputElement>(null);
107
120
  const deferId = React.useRef<number | undefined>();
108
- const selectionRef = React.useRef<number>(0);
121
+ const selectionPos = React.useRef<SelectionPos>(defaultSelection);
122
+ const newSelectionPos = React.useRef<number>(0);
123
+
109
124
  const [value, setValue] = React.useState<string>(defaultValue || valueProp || '');
110
- const [selection, setSelection] = React.useState<SelectionPos>(getDefaultSelection());
111
- const ref = React.useRef<HTMLInputElement>(null);
112
125
 
113
126
  React.useImperativeHandle(forwardRef, () => ref.current as HTMLInputElement);
114
127
 
@@ -116,149 +129,195 @@ export const InputMask = React.forwardRef<HTMLInputElement, InputMaskProps>((pro
116
129
  setValue(valueProp || '');
117
130
  }, [valueProp]);
118
131
 
119
- const setCursorPosition = (val: number) => setSelectionPos({ start: val, end: val });
132
+ React.useEffect(() => {
133
+ setCursorPosition(newSelectionPos.current);
134
+ }, [value]);
120
135
 
121
- const getCurrSelection = () => ({
122
- start: ref.current?.selectionStart || 0,
123
- end: ref.current?.selectionEnd || 0,
124
- });
136
+ const getSelectionLength = React.useCallback((val: SelectionPos) => Math.abs(val.end - val.start), []);
125
137
 
126
- const setSelectionPos = (pos: SelectionPos): void => {
127
- if (ref.current) {
128
- const el = ref.current;
129
- const start = Math.min(pos.start, pos.end);
130
- const end = Math.max(pos.start, pos.end);
131
- el.setSelectionRange(start, end);
132
- }
133
- };
138
+ const getCurrSelection = React.useCallback(
139
+ () => ({
140
+ start: ref.current?.selectionStart || 0,
141
+ end: ref.current?.selectionEnd || 0,
142
+ }),
143
+ [ref.current]
144
+ );
134
145
 
135
- const updateSelection = () => {
136
- setSelection(getCurrSelection());
146
+ const setSelectionPos = React.useCallback(
147
+ (pos: SelectionPos): void => {
148
+ if (ref.current) {
149
+ const el = ref.current;
150
+ const start = Math.min(pos.start, pos.end);
151
+ const end = Math.max(pos.start, pos.end);
152
+ el.setSelectionRange(start, end);
153
+ }
154
+ },
155
+ [ref.current]
156
+ );
137
157
 
138
- deferId.current = window.requestAnimationFrame(updateSelection);
139
- };
158
+ const setCursorPosition = React.useCallback(
159
+ (val: number) => setSelectionPos({ start: val, end: val }),
160
+ [setSelectionPos]
161
+ );
140
162
 
141
- const insertAtIndex = (currValue: string, index: number, iterator: number = 0) => {
142
- let newValue = '';
143
- const newIndex = index + 1;
144
- let newIterator = iterator;
163
+ const insertAtIndex = React.useCallback(
164
+ (currValue: string, index: number, iterator = 0) => {
165
+ let newValue = '';
166
+ const newIndex = index + 1;
167
+ let newIterator = iterator;
145
168
 
146
- if (index >= mask.length) {
147
- return newValue;
148
- }
169
+ if (index >= mask.length) {
170
+ return newValue;
171
+ }
149
172
 
150
- if (iterator >= currValue.length) {
151
- selectionRef.current = index;
152
- return newValue;
153
- }
173
+ if (iterator >= currValue.length) {
174
+ selectionPos.current = { start: index, end: index };
175
+ return newValue;
176
+ }
154
177
 
155
- const m = mask[index];
156
- if (isEditable(index)) {
157
- if (currValue[iterator].match(m)) {
158
- newValue += currValue[iterator];
178
+ const m = mask[index];
179
+ if (isEditable(index)) {
180
+ if (currValue[iterator].match(m)) {
181
+ newValue += currValue[iterator];
182
+ } else {
183
+ newValue += placeholderChar;
184
+ }
185
+ newIterator++;
159
186
  } else {
160
- newValue += placeholderChar;
187
+ newValue += m;
161
188
  }
162
- newIterator++;
163
- } else {
164
- newValue += m;
165
- }
166
189
 
167
- newValue += insertAtIndex(currValue, newIndex, newIterator);
190
+ newValue += insertAtIndex(currValue, newIndex, newIterator);
168
191
 
169
- return newValue;
170
- };
192
+ return newValue;
193
+ },
194
+ [mask, placeholderChar, isEditable]
195
+ );
171
196
 
172
- const onChangeHandler = (e: React.ChangeEvent<HTMLInputElement>) => {
173
- const inputVal = e.currentTarget.value;
174
-
175
- const currSelection = getCurrSelection();
176
- const start = Math.min(selection.start, currSelection.start);
177
- const end = currSelection.end;
178
-
179
- let cursorPosition = start;
180
- let enteredVal = '';
181
- let updatedVal = '';
182
- let removedLength = 0;
183
- let insertedStringLength = 0;
184
-
185
- enteredVal = inputVal.slice(start, end);
186
- updatedVal = insertAtIndex(enteredVal, start);
187
- insertedStringLength = updatedVal.length;
188
- if (currSelection.end > selection.end) {
189
- removedLength = insertedStringLength ? getSelectionLength(selection) : 0;
190
- } else if (inputVal.length < value.length) {
191
- removedLength = value.length - inputVal.length;
192
- }
193
-
194
- cursorPosition += insertedStringLength;
195
-
196
- const maskedVal = value.split('');
197
- for (let i = 0; i < insertedStringLength; i++) {
198
- maskedVal[start + i] = updatedVal[i];
199
- }
200
- for (let i = 0; i < removedLength; i++) {
201
- const index = start + insertedStringLength + i;
202
- maskedVal[index] = getPlaceholderValue(index, index);
203
- }
204
-
205
- const newCursorPosition = getNewCursorPosition(removedLength ? 'left' : 'right', cursorPosition);
206
- if (removedLength === 1 && !updatedVal.length && !isEditable(cursorPosition) && newCursorPosition > 0) {
207
- cursorPosition = newCursorPosition;
208
- cursorPosition--;
209
- maskedVal[cursorPosition] = placeholderChar;
210
- } else if (removedLength !== 1) {
211
- cursorPosition = newCursorPosition;
212
- }
213
-
214
- const newValue = maskedVal.slice(0, mask.length).join('');
215
- window.requestAnimationFrame(() => setCursorPosition(cursorPosition));
216
-
217
- if (Utils.validators.isValid(validators, newValue) && newValue !== value) {
218
- setValue(newValue);
219
- if (onChange) onChange(e, newValue);
220
- }
221
- };
197
+ const updateSelection = React.useCallback(() => {
198
+ selectionPos.current = getCurrSelection();
222
199
 
223
- const onBlurHandler = (e: React.ChangeEvent<HTMLInputElement>) => {
224
- let inputVal = e.currentTarget.value;
200
+ deferId.current = window.requestAnimationFrame(updateSelection);
201
+ }, [selectionPos.current, getCurrSelection]);
202
+
203
+ const onChangeHandler = React.useCallback(
204
+ (e: React.ChangeEvent<HTMLInputElement>) => {
205
+ const inputVal = e.currentTarget.value;
206
+
207
+ const currSelection = getCurrSelection();
208
+ const start = Math.min(selectionPos.current.start, currSelection.start);
209
+ const end = currSelection.end;
210
+
211
+ let cursorPosition = start;
212
+ let enteredVal = '';
213
+ let updatedVal = '';
214
+ let removedLength = 0;
215
+ let insertedStringLength = 0;
216
+
217
+ enteredVal = inputVal.slice(start, end);
218
+ updatedVal = insertAtIndex(enteredVal, start);
219
+ insertedStringLength = updatedVal.length;
220
+ if (currSelection.end > selectionPos.current.end) {
221
+ removedLength = insertedStringLength ? getSelectionLength(selectionPos.current) : 0;
222
+ } else if (inputVal.length < value.length) {
223
+ removedLength = value.length - inputVal.length;
224
+ }
225
225
 
226
- if (clearOnEmptyBlur) {
227
- if (inputVal === getPlaceholderValue()) {
228
- setValue('');
229
- inputVal = '';
226
+ cursorPosition += insertedStringLength;
227
+
228
+ const maskedVal = value.split('');
229
+ for (let i = 0; i < insertedStringLength; i++) {
230
+ maskedVal[start + i] = updatedVal[i];
231
+ }
232
+ for (let i = 0; i < removedLength; i++) {
233
+ const index = start + insertedStringLength + i;
234
+ maskedVal[index] = getPlaceholderValue(index, index);
230
235
  }
231
- }
232
236
 
233
- if (onBlur) onBlur(e, inputVal);
237
+ const newCursorPosition = getNewCursorPosition(removedLength ? 'left' : 'right', cursorPosition);
238
+ if (removedLength === 1 && !updatedVal.length && !isEditable(cursorPosition) && newCursorPosition > 0) {
239
+ cursorPosition = newCursorPosition;
240
+ cursorPosition--;
241
+ maskedVal[cursorPosition] = placeholderChar;
242
+ } else if (removedLength !== 1) {
243
+ cursorPosition = newCursorPosition;
244
+ }
234
245
 
235
- if (deferId.current) window.cancelAnimationFrame(deferId.current);
236
- };
246
+ const newValue = maskedVal.slice(0, mask.length).join('');
247
+ newSelectionPos.current = cursorPosition;
237
248
 
238
- const onClearHandler = (e: React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>) => {
239
- // setValue('');
240
- // window.requestAnimationFrame(() => ref.current!.blur());
241
- setValue(getPlaceholderValue());
242
- window.requestAnimationFrame(() => setCursorPosition(getDefaultSelection().start));
249
+ if (newValue !== value && Utils.validators.isValid(validators, newValue)) {
250
+ setValue(newValue);
251
+ onChange?.(e, newValue);
252
+ } else {
253
+ window.requestAnimationFrame(() => setCursorPosition(newSelectionPos.current));
254
+ }
255
+ },
256
+ [
257
+ selectionPos.current,
258
+ validators,
259
+ getCurrSelection,
260
+ insertAtIndex,
261
+ getSelectionLength,
262
+ getPlaceholderValue,
263
+ getNewCursorPosition,
264
+ isEditable,
265
+ setCursorPosition,
266
+ setValue,
267
+ onChange,
268
+ ]
269
+ );
243
270
 
244
- if (onClear) onClear(e);
245
- };
271
+ const onBlurHandler = React.useCallback(
272
+ (e: React.ChangeEvent<HTMLInputElement>) => {
273
+ let inputVal = e.currentTarget.value;
246
274
 
247
- const onFocusHandler = (e: React.FocusEvent<HTMLInputElement>) => {
248
- deferId.current = window.requestAnimationFrame(updateSelection);
249
- if (!value) {
250
- setValue(getPlaceholderValue());
251
- window.requestAnimationFrame(() => setSelectionPos(getDefaultSelection()));
252
- }
275
+ if (clearOnEmptyBlur) {
276
+ if (inputVal === defaultPlaceholderValue) {
277
+ setValue('');
278
+ inputVal = '';
279
+ }
280
+ }
253
281
 
254
- if (onFocus) onFocus(e);
255
- };
282
+ onBlur?.(e, inputVal);
283
+
284
+ if (deferId.current) window.cancelAnimationFrame(deferId.current);
285
+ },
286
+ [clearOnEmptyBlur, deferId.current, getPlaceholderValue, setValue, onBlur]
287
+ );
288
+
289
+ const onClearHandler = React.useCallback(
290
+ (e: React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>) => {
291
+ newSelectionPos.current = defaultSelection.start;
292
+ setValue(defaultPlaceholderValue);
293
+
294
+ onClear?.(e);
295
+ },
296
+ [setValue, getPlaceholderValue, setCursorPosition, getDefaultSelection, onClear]
297
+ );
298
+
299
+ const onFocusHandler = React.useCallback(
300
+ (e: React.FocusEvent<HTMLInputElement>) => {
301
+ deferId.current = window.requestAnimationFrame(updateSelection);
302
+ if (!value) {
303
+ newSelectionPos.current = defaultSelection.start;
304
+ setValue(getPlaceholderValue());
305
+ }
256
306
 
257
- const classes = classNames(
258
- {
259
- 'd-flex flex-column flex-grow-1': true,
307
+ onFocus?.(e);
260
308
  },
261
- className
309
+ [deferId.current, value, updateSelection, setValue, setSelectionPos, onFocus]
310
+ );
311
+
312
+ const classes = React.useMemo(
313
+ () =>
314
+ classNames(
315
+ {
316
+ 'd-flex flex-column flex-grow-1': true,
317
+ },
318
+ className
319
+ ),
320
+ [className]
262
321
  );
263
322
 
264
323
  return (
@@ -283,9 +342,16 @@ export const InputMask = React.forwardRef<HTMLInputElement, InputMaskProps>((pro
283
342
  });
284
343
 
285
344
  InputMask.displayName = 'InputMask';
286
- // @ts-ignore
287
- InputMask.utils = {
345
+ // we are adding a new property which is not present in default interface
346
+ // we could have explicitly added the interface above with definition
347
+ // but then it would force us to marks utils as optional
348
+ // as we cannot add new properties by defining the InputMask
349
+ // that would cause user to use `!` everywhere or check for utils
350
+ (InputMask as InputMaskType).utils = {
288
351
  getDefaultValue,
289
352
  };
290
353
 
291
- export default InputMask;
354
+ const X = InputMask as InputMaskType;
355
+
356
+ export { X as InputMask };
357
+ export default X as InputMaskType;
@@ -59,7 +59,31 @@ export const all = () => {
59
59
  );
60
60
  };
61
61
 
62
+ const customCode = `// import { Utils } from '@innovaccer/design-system';
63
+
64
+ () => {
65
+ const dateMask = Utils.masks.date['mm/dd/yyyy'];
66
+ const dateValidator = (val) => Utils.validators.date(val, 'mm/dd/yyyy');
67
+
68
+ return (
69
+ <div className="w-25">
70
+ <InputMask
71
+ mask={dateMask}
72
+ validators={dateValidator}
73
+ />
74
+ </div>
75
+ );
76
+ };
77
+ `;
78
+
62
79
  export default {
63
80
  title: 'Components/InputMask/All',
64
81
  component: InputMask,
82
+ parameters: {
83
+ docs: {
84
+ docPage: {
85
+ customCode,
86
+ },
87
+ },
88
+ },
65
89
  };
@@ -2,18 +2,16 @@ import * as React from 'react';
2
2
  import * as ReactDOM from 'react-dom';
3
3
  import classNames from 'classnames';
4
4
  import { BaseProps, extractBaseProps } from '@/utils/types';
5
- import { OverlayFooter, OverlayFooterProps } from '@/components/molecules/overlayFooter';
5
+ import { OverlayFooter } from '@/components/molecules/overlayFooter';
6
6
  import { OverlayHeader, OverlayHeaderProps } from '@/components/molecules/overlayHeader';
7
7
  import { OverlayBody } from '@/components/molecules/overlayBody';
8
8
  import { Row, Column, Backdrop, OutsideClick, Button } from '@/index';
9
9
  import { ColumnProps } from '@/index.type';
10
10
  import { getWrapperElement, getUpdatedZIndex, closeOnEscapeKeypress } from '@/utils/overlayHelper';
11
11
  import OverlayManager from '@/utils/OverlayManager';
12
+ import { FooterOptions } from '@/common.type';
13
+ export type ModalDimension = 'small' | 'medium' | 'large';
12
14
 
13
- export type Dimension = 'small' | 'medium' | 'large';
14
- type FooterOptions = {
15
- actions: OverlayFooterProps['actions'];
16
- };
17
15
  export interface ModalProps extends BaseProps {
18
16
  /**
19
17
  * Callback for `Modal` close event on backdrop click
@@ -26,7 +24,7 @@ export interface ModalProps extends BaseProps {
26
24
  /**
27
25
  * Dimension of `Modal`
28
26
  */
29
- dimension: Dimension;
27
+ dimension: ModalDimension;
30
28
  /**
31
29
  * Handles open/close state
32
30
  */
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { action } from '@storybook/addon-actions';
3
- import { Modal, ModalDescription, Button, Paragraph, Text } from '@/index';
3
+ import { Modal, Button, Paragraph, Text } from '@/index';
4
4
 
5
5
  export const confirmations = () => {
6
6
  const [open, setOpen] = React.useState(true);
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import classNames from 'classnames';
3
3
  import { BaseProps, extractBaseProps } from '@/utils/types';
4
- import PlaceholderImage, { Size } from '@/components/atoms/placeholderImage';
4
+ import PlaceholderImage, { PlaceholderImageSize } from '@/components/atoms/placeholderImage';
5
5
  import { PlaceholderParagraphProps } from '@/components/atoms/placeholderParagraph';
6
6
 
7
7
  export interface PlaceholderProps extends BaseProps {
@@ -16,7 +16,7 @@ export interface PlaceholderProps extends BaseProps {
16
16
  /**
17
17
  * Specifies dimension of `Placeholder`
18
18
  */
19
- imageSize: Size;
19
+ imageSize: PlaceholderImageSize;
20
20
  /**
21
21
  * To be rendered in `Placeholder` wrapper
22
22
  */
@@ -86,7 +86,7 @@ export const Popover = (props: PopoverProps) => {
86
86
  onToggle,
87
87
  className,
88
88
  hideOnReferenceEscape,
89
- boundaryElement,
89
+ boundaryElement = document.body,
90
90
  ...rest
91
91
  } = props;
92
92
 
@@ -140,19 +140,12 @@ export const Popover = (props: PopoverProps) => {
140
140
  };
141
141
 
142
142
  Popover.displayName = 'Popover';
143
- // Popover.defaultProps = {
144
- // ...filterProps(PopperWrapper.defaultProps, propsList, true),
145
- // offset: 'large',
146
- // position: 'bottom',
147
- // hideOnReferenceEscape: true,
148
- // customStyle: {},
149
- // }
143
+
150
144
  Popover.defaultProps = Object.assign({}, filterProps(PopperWrapper.defaultProps, propsList, true), {
151
145
  offset: 'large',
152
146
  position: 'bottom',
153
147
  hideOnReferenceEscape: true,
154
148
  customStyle: {},
155
- boundaryElement: document.body,
156
149
  });
157
150
 
158
151
  export default Popover;
@@ -3,17 +3,15 @@ import * as ReactDOM from 'react-dom';
3
3
  import classNames from 'classnames';
4
4
  import { Row, Column, Backdrop, OutsideClick, Button } from '@/index';
5
5
  import { ColumnProps } from '@/index.type';
6
- import { OverlayFooter, OverlayFooterProps } from '@/components/molecules/overlayFooter';
6
+ import { OverlayFooter } from '@/components/molecules/overlayFooter';
7
7
  import { OverlayHeader, OverlayHeaderProps } from '@/components/molecules/overlayHeader';
8
8
  import { OverlayBody } from '@/components/molecules/overlayBody';
9
9
  import { BaseProps, extractBaseProps } from '@/utils/types';
10
10
  import { getWrapperElement, getUpdatedZIndex, closeOnEscapeKeypress } from '@/utils/overlayHelper';
11
11
  import OverlayManager from '@/utils/OverlayManager';
12
+ import { FooterOptions } from '@/common.type';
12
13
 
13
- export type Dimension = 'regular' | 'large';
14
- type FooterOptions = {
15
- actions: OverlayFooterProps['actions'];
16
- };
14
+ export type SidesheetDimension = 'regular' | 'large';
17
15
 
18
16
  export interface SidesheetProps extends BaseProps {
19
17
  /**
@@ -55,7 +53,7 @@ export interface SidesheetProps extends BaseProps {
55
53
  *
56
54
  * Dimension: `large` | `regular`
57
55
  */
58
- dimension: Dimension;
56
+ dimension: SidesheetDimension;
59
57
  /**
60
58
  * Handles open/close state
61
59
  */
@@ -108,7 +106,7 @@ interface SidesheetState {
108
106
  zIndex?: number;
109
107
  }
110
108
 
111
- const sidesheetWidth: Record<Dimension, ColumnProps['size']> = {
109
+ const sidesheetWidth: Record<SidesheetDimension, ColumnProps['size']> = {
112
110
  regular: '6',
113
111
  large: '10',
114
112
  };