@pega/cosmos-react-core 7.0.0-build.22.3 → 7.0.0-build.22.30

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 (173) hide show
  1. package/lib/components/AIButton/AIButton.d.ts +30 -2
  2. package/lib/components/AIButton/AIButton.d.ts.map +1 -1
  3. package/lib/components/AIButton/AIButton.js +4 -3
  4. package/lib/components/AIButton/AIButton.js.map +1 -1
  5. package/lib/components/AppShell/AppHeader.d.ts.map +1 -1
  6. package/lib/components/AppShell/AppHeader.js +4 -6
  7. package/lib/components/AppShell/AppHeader.js.map +1 -1
  8. package/lib/components/AppShell/AppHeader.styles.d.ts.map +1 -1
  9. package/lib/components/AppShell/AppHeader.styles.js +6 -2
  10. package/lib/components/AppShell/AppHeader.styles.js.map +1 -1
  11. package/lib/components/AppShell/AppShell.d.ts.map +1 -1
  12. package/lib/components/AppShell/AppShell.js +2 -1
  13. package/lib/components/AppShell/AppShell.js.map +1 -1
  14. package/lib/components/AppShell/AppShell.styles.d.ts +3 -0
  15. package/lib/components/AppShell/AppShell.styles.d.ts.map +1 -1
  16. package/lib/components/AppShell/AppShell.styles.js +12 -0
  17. package/lib/components/AppShell/AppShell.styles.js.map +1 -1
  18. package/lib/components/AppShell/AppShell.types.d.ts +4 -0
  19. package/lib/components/AppShell/AppShell.types.d.ts.map +1 -1
  20. package/lib/components/AppShell/AppShell.types.js.map +1 -1
  21. package/lib/components/AppShell/NavigationList.d.ts.map +1 -1
  22. package/lib/components/AppShell/NavigationList.js +3 -3
  23. package/lib/components/AppShell/NavigationList.js.map +1 -1
  24. package/lib/components/AppShell/NavigationListItemWrapper.d.ts.map +1 -1
  25. package/lib/components/AppShell/NavigationListItemWrapper.js +1 -0
  26. package/lib/components/AppShell/NavigationListItemWrapper.js.map +1 -1
  27. package/lib/components/Banner/Banner.d.ts.map +1 -1
  28. package/lib/components/Banner/Banner.js +1 -1
  29. package/lib/components/Banner/Banner.js.map +1 -1
  30. package/lib/components/Button/Button.d.ts.map +1 -1
  31. package/lib/components/Button/Button.js +67 -35
  32. package/lib/components/Button/Button.js.map +1 -1
  33. package/lib/components/Card/Card.d.ts.map +1 -1
  34. package/lib/components/Card/Card.js +8 -0
  35. package/lib/components/Card/Card.js.map +1 -1
  36. package/lib/components/ColorPicker/ColorPicker.js +1 -1
  37. package/lib/components/ColorPicker/ColorPicker.js.map +1 -1
  38. package/lib/components/ComboBox/ComboBox.styles.d.ts.map +1 -1
  39. package/lib/components/ComboBox/ComboBox.styles.js +4 -0
  40. package/lib/components/ComboBox/ComboBox.styles.js.map +1 -1
  41. package/lib/components/Configuration/Configuration.d.ts +1 -0
  42. package/lib/components/Configuration/Configuration.d.ts.map +1 -1
  43. package/lib/components/Configuration/Configuration.js +58 -30
  44. package/lib/components/Configuration/Configuration.js.map +1 -1
  45. package/lib/components/Configuration/connected-watcher.d.ts +17 -0
  46. package/lib/components/Configuration/connected-watcher.d.ts.map +1 -0
  47. package/lib/components/Configuration/connected-watcher.js +13 -0
  48. package/lib/components/Configuration/connected-watcher.js.map +1 -0
  49. package/lib/components/DateTime/Input/MonthInput.d.ts.map +1 -1
  50. package/lib/components/DateTime/Input/MonthInput.js +21 -10
  51. package/lib/components/DateTime/Input/MonthInput.js.map +1 -1
  52. package/lib/components/DateTime/Picker/DatePicker.d.ts.map +1 -1
  53. package/lib/components/DateTime/Picker/DatePicker.js +5 -32
  54. package/lib/components/DateTime/Picker/DatePicker.js.map +1 -1
  55. package/lib/components/DateTime/Picker/utils.d.ts +9 -0
  56. package/lib/components/DateTime/Picker/utils.d.ts.map +1 -1
  57. package/lib/components/DateTime/Picker/utils.js +16 -0
  58. package/lib/components/DateTime/Picker/utils.js.map +1 -1
  59. package/lib/components/File/CompactList.js +1 -1
  60. package/lib/components/File/CompactList.js.map +1 -1
  61. package/lib/components/File/FileDisplayList.d.ts +2 -1
  62. package/lib/components/File/FileDisplayList.d.ts.map +1 -1
  63. package/lib/components/File/FileDisplayList.js +3 -2
  64. package/lib/components/File/FileDisplayList.js.map +1 -1
  65. package/lib/components/File/FileInput.d.ts +30 -6
  66. package/lib/components/File/FileInput.d.ts.map +1 -1
  67. package/lib/components/File/FileInput.js +135 -96
  68. package/lib/components/File/FileInput.js.map +1 -1
  69. package/lib/components/File/FileInput.styles.d.ts +24 -0
  70. package/lib/components/File/FileInput.styles.d.ts.map +1 -0
  71. package/lib/components/File/FileInput.styles.js +154 -0
  72. package/lib/components/File/FileInput.styles.js.map +1 -0
  73. package/lib/components/File/FileItem.d.ts +3 -0
  74. package/lib/components/File/FileItem.d.ts.map +1 -1
  75. package/lib/components/File/FileItem.js +3 -4
  76. package/lib/components/File/FileItem.js.map +1 -1
  77. package/lib/components/File/FileList.d.ts +6 -3
  78. package/lib/components/File/FileList.d.ts.map +1 -1
  79. package/lib/components/File/FileList.js +25 -7
  80. package/lib/components/File/FileList.js.map +1 -1
  81. package/lib/components/Fullscreen/Fullscreen.d.ts +18 -0
  82. package/lib/components/Fullscreen/Fullscreen.d.ts.map +1 -0
  83. package/lib/components/Fullscreen/Fullscreen.js +51 -0
  84. package/lib/components/Fullscreen/Fullscreen.js.map +1 -0
  85. package/lib/components/Fullscreen/Fullscreen.test-ids.d.ts +2 -0
  86. package/lib/components/Fullscreen/Fullscreen.test-ids.d.ts.map +1 -0
  87. package/lib/components/Fullscreen/Fullscreen.test-ids.js +3 -0
  88. package/lib/components/Fullscreen/Fullscreen.test-ids.js.map +1 -0
  89. package/lib/components/Fullscreen/FullscreenButton.d.ts +6 -0
  90. package/lib/components/Fullscreen/FullscreenButton.d.ts.map +1 -0
  91. package/lib/components/Fullscreen/FullscreenButton.js +33 -0
  92. package/lib/components/Fullscreen/FullscreenButton.js.map +1 -0
  93. package/lib/components/Fullscreen/index.d.ts +4 -0
  94. package/lib/components/Fullscreen/index.d.ts.map +1 -0
  95. package/lib/components/Fullscreen/index.js +4 -0
  96. package/lib/components/Fullscreen/index.js.map +1 -0
  97. package/lib/components/Icon/streamline-icons/dock.icon.d.ts +5 -0
  98. package/lib/components/Icon/streamline-icons/dock.icon.d.ts.map +1 -0
  99. package/lib/components/Icon/streamline-icons/dock.icon.js +7 -0
  100. package/lib/components/Icon/streamline-icons/dock.icon.js.map +1 -0
  101. package/lib/components/Icon/streamline-icons/undock.icon.d.ts +5 -0
  102. package/lib/components/Icon/streamline-icons/undock.icon.d.ts.map +1 -0
  103. package/lib/components/Icon/streamline-icons/undock.icon.js +7 -0
  104. package/lib/components/Icon/streamline-icons/undock.icon.js.map +1 -0
  105. package/lib/components/Icon/streamlineIconNames.d.ts +1 -1
  106. package/lib/components/Icon/streamlineIconNames.d.ts.map +1 -1
  107. package/lib/components/Icon/streamlineIconNames.js +2 -0
  108. package/lib/components/Icon/streamlineIconNames.js.map +1 -1
  109. package/lib/components/ListToolbar/ListToolbar.d.ts.map +1 -1
  110. package/lib/components/ListToolbar/ListToolbar.js +3 -2
  111. package/lib/components/ListToolbar/ListToolbar.js.map +1 -1
  112. package/lib/components/Location/Location.types.d.ts +1 -0
  113. package/lib/components/Location/Location.types.d.ts.map +1 -1
  114. package/lib/components/Location/Location.types.js.map +1 -1
  115. package/lib/components/Location/LocationView.d.ts.map +1 -1
  116. package/lib/components/Location/LocationView.js +31 -7
  117. package/lib/components/Location/LocationView.js.map +1 -1
  118. package/lib/components/Location/utils.d.ts.map +1 -1
  119. package/lib/components/Location/utils.js +23 -21
  120. package/lib/components/Location/utils.js.map +1 -1
  121. package/lib/components/Modal/ModalManager.d.ts.map +1 -1
  122. package/lib/components/Modal/ModalManager.js +5 -1
  123. package/lib/components/Modal/ModalManager.js.map +1 -1
  124. package/lib/components/PageTemplates/PageTemplates.d.ts +1 -0
  125. package/lib/components/PageTemplates/PageTemplates.d.ts.map +1 -1
  126. package/lib/components/PageTemplates/PageTemplates.js +82 -29
  127. package/lib/components/PageTemplates/PageTemplates.js.map +1 -1
  128. package/lib/components/Popover/modifiers.js +4 -4
  129. package/lib/components/Popover/modifiers.js.map +1 -1
  130. package/lib/components/Tabs/Tab.d.ts.map +1 -1
  131. package/lib/components/Tabs/Tab.js +4 -0
  132. package/lib/components/Tabs/Tab.js.map +1 -1
  133. package/lib/components/Toaster/Toaster.d.ts +1 -1
  134. package/lib/components/Toaster/Toaster.d.ts.map +1 -1
  135. package/lib/components/Toaster/Toaster.js +79 -19
  136. package/lib/components/Toaster/Toaster.js.map +1 -1
  137. package/lib/components/Toaster/Toaster.types.d.ts +17 -4
  138. package/lib/components/Toaster/Toaster.types.d.ts.map +1 -1
  139. package/lib/components/Toaster/Toaster.types.js.map +1 -1
  140. package/lib/components/Tooltip/Tooltip.d.ts.map +1 -1
  141. package/lib/components/Tooltip/Tooltip.js +3 -1
  142. package/lib/components/Tooltip/Tooltip.js.map +1 -1
  143. package/lib/hooks/useArrows.d.ts.map +1 -1
  144. package/lib/hooks/useArrows.js +3 -1
  145. package/lib/hooks/useArrows.js.map +1 -1
  146. package/lib/hooks/useI18n.d.ts +27 -0
  147. package/lib/hooks/useI18n.d.ts.map +1 -1
  148. package/lib/hooks/useScrollToggle.d.ts.map +1 -1
  149. package/lib/hooks/useScrollToggle.js +1 -0
  150. package/lib/hooks/useScrollToggle.js.map +1 -1
  151. package/lib/i18n/default.d.ts +27 -0
  152. package/lib/i18n/default.d.ts.map +1 -1
  153. package/lib/i18n/default.js +31 -1
  154. package/lib/i18n/default.js.map +1 -1
  155. package/lib/i18n/i18n.d.ts +27 -0
  156. package/lib/i18n/i18n.d.ts.map +1 -1
  157. package/lib/index.d.ts +2 -0
  158. package/lib/index.d.ts.map +1 -1
  159. package/lib/index.js +2 -0
  160. package/lib/index.js.map +1 -1
  161. package/lib/theme/theme.d.ts +6 -0
  162. package/lib/theme/theme.d.ts.map +1 -1
  163. package/lib/theme/themeDefinition.json +5 -1
  164. package/lib/theme/themeOverrides.schema.json +3 -0
  165. package/lib/utils/index.d.ts +1 -0
  166. package/lib/utils/index.d.ts.map +1 -1
  167. package/lib/utils/index.js +1 -0
  168. package/lib/utils/index.js.map +1 -1
  169. package/lib/utils/isPositionWithinRect.d.ts +12 -0
  170. package/lib/utils/isPositionWithinRect.d.ts.map +1 -0
  171. package/lib/utils/isPositionWithinRect.js +11 -0
  172. package/lib/utils/isPositionWithinRect.js.map +1 -0
  173. package/package.json +7 -4
@@ -59,4 +59,20 @@ export const toDateTimeString = (date, mode = 'date') => {
59
59
  : { dateStyle: 'medium', timeZone: 'UTC' })
60
60
  : undefined;
61
61
  };
62
+ /**
63
+ * Shifts date forward or backward. It sets the day of month
64
+ * to the last day of the resulted month if it does not contain the calculated day,
65
+ * ie. 2022-01-31 -> 2022-02-28.
66
+ * @param currentDate a date to advance by month
67
+ * @param shift determines whether it is the next month or the previous month
68
+ * @returns new Date object with advanced month
69
+ */
70
+ export const shiftDateByMonth = (currentDate, shift) => {
71
+ const result = new Date(currentDate);
72
+ result.setMonth(result.getMonth() + shift);
73
+ if (result.getMonth() !== (currentDate.getMonth() + shift + 12) % 12) {
74
+ result.setDate(0);
75
+ }
76
+ return result;
77
+ };
62
78
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/components/DateTime/Picker/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAIpE,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,YAAoB,EAAE,SAAkB,EAAE,EAAE;IAC3E,OAAO,WAAW,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE;QACjD,OAAO;YACL,GAAG,CAAC,WAAW,CAAC,cAAc,CAAC,SAAS,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;YAC/D,GAAG,CAAC,WAAW,CAAC,cAAc,CAAC,SAAS,EAAE,EAAE,OAAO,EAAE,O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CAAC,CAAC;QACxB,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,QAAQ,CAAC,CAAC;KAC/C;AACH,CAAC;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,IAAsB,EACtB,OAAgC,MAAM,EACtC,EAAE;IACF,OAAO,IAAI;QACT,CAAC,CAAC,IAAI,CAAC,cAAc,CACjB,SAAS,EACT,IAAI,KAAK,UAAU;YACjB,CAAC,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE;YAC/D,CAAC,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,CAC7C;QACH,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC,CAAC","sourcesContent":["import { cap, range } from '../../../utils';\nimport { getDayOfWeek, getWeek, getWeekdays } from '../Input/utils';\n\nimport type DatePickerProps from './DatePicker.types';\n\nexport const getLocalizedDays = (calendarType: string, localeTag?: string) => {\n return getWeekdays(calendarType).map(weekdayDate => {\n return [\n cap(weekdayDate.toLocaleString(localeTag, { weekday: 'long' })),\n cap(weekdayDate.toLocaleString(localeTag, { weekday: 'short' }))\n ];\n });\n};\n\nexport const isValidDate = (date: Date) => {\n return date.toString() !== 'Invalid Date';\n};\n\nexport const getDaysOfMonth = (date: Date, calendarType: string): Date[] => {\n const firstDayInMonth = new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), 1));\n const startingWeekDay = getDayOfWeek(firstDayInMonth, calendarType);\n\n // 6 rows * 7 days = 42\n return range(1 - startingWeekDay, 42 - startingWeekDay).map((day: number) => {\n return new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), day));\n });\n};\n\nexport const getWeeksOfMonth = (date: Date, calendarType: string): number[] => {\n const weekdays = [];\n const year = date.getUTCFullYear();\n const month = date.getUTCMonth();\n const dayInLastWeek = new Date(Date.UTC(year, month, 36));\n const lastWeek = getWeek(dayInLastWeek, calendarType);\n\n let day;\n let currentWeek;\n let iterator = 1;\n\n do {\n day = new Date(Date.UTC(year, month, iterator));\n currentWeek = getWeek(day, calendarType);\n weekdays.push(currentWeek);\n iterator += 7;\n } while (currentWeek !== lastWeek);\n\n return weekdays;\n};\n\nexport const getNextMonth = (date: Date) => {\n const next = new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth() + 1, 1));\n return next.getUTCMonth();\n};\n\nexport const getPreviousMonth = (date: Date) => {\n const prev = new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth() - 1, 1));\n return prev.getUTCMonth();\n};\n\nconst DAY_IN_MILLISECONDS = 86400000;\n\nexport function* getIntervalGenerator(interval: number) {\n const current = new Date(0);\n while (current.getTime() < DAY_IN_MILLISECONDS) {\n yield new Date(current);\n current.setTime(current.getTime() + interval);\n }\n}\n\nexport const toDateTimeString = (\n date: Date | undefined,\n mode: DatePickerProps['mode'] = 'date'\n) => {\n return date\n ? date.toLocaleString(\n undefined,\n mode === 'datetime'\n ? { dateStyle: 'medium', timeStyle: 'medium', timeZone: 'UTC' }\n : { dateStyle: 'medium', timeZone: 'UTC' }\n )\n : undefined;\n};\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/components/DateTime/Picker/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAIpE,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,YAAoB,EAAE,SAAkB,EAAE,EAAE;IAC3E,OAAO,WAAW,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE;QACjD,OAAO;YACL,GAAG,CAAC,WAAW,CAAC,cAAc,CAAC,SAAS,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;YAC/D,GAAG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AAE,GAAG,mBAAmB,EAAE;QAC9C,MAAM,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC;QACxB,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,QAAQ,CAAC,CAAC;KAC/C;AACH,CAAC;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,IAAsB,EACtB,OAAgC,MAAM,EACtC,EAAE;IACF,OAAO,IAAI;QACT,CAAC,CAAC,IAAI,CAAC,cAAc,CACjB,SAAS,EACT,IAAI,KAAK,UAAU;YACjB,CAAC,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE;YAC/D,CAAC,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,CAC7C;QACH,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,WAAiB,EAAE,KAAa,EAAE,EAAE;IACnE,MAAM,MAAM,GAAG,IAAI,IAAI,CAAC,WAAW,CAAC,CAAC;IACrC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,GAAG,KAAK,CAAC,CAAC;IAE3C,IAAI,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,WAAW,CAAC,QAAQ,EAAE,GAAG,KAAK,GAAG,EAAE,CAAC,GAAG,EAAE,EAAE;QACpE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;KACnB;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC","sourcesContent":["import { cap, range } from '../../../utils';\nimport { getDayOfWeek, getWeek, getWeekdays } from '../Input/utils';\n\nimport type DatePickerProps from './DatePicker.types';\n\nexport const getLocalizedDays = (calendarType: string, localeTag?: string) => {\n return getWeekdays(calendarType).map(weekdayDate => {\n return [\n cap(weekdayDate.toLocaleString(localeTag, { weekday: 'long' })),\n cap(weekdayDate.toLocaleString(localeTag, { weekday: 'short' }))\n ];\n });\n};\n\nexport const isValidDate = (date: Date) => {\n return date.toString() !== 'Invalid Date';\n};\n\nexport const getDaysOfMonth = (date: Date, calendarType: string): Date[] => {\n const firstDayInMonth = new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), 1));\n const startingWeekDay = getDayOfWeek(firstDayInMonth, calendarType);\n\n // 6 rows * 7 days = 42\n return range(1 - startingWeekDay, 42 - startingWeekDay).map((day: number) => {\n return new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), day));\n });\n};\n\nexport const getWeeksOfMonth = (date: Date, calendarType: string): number[] => {\n const weekdays = [];\n const year = date.getUTCFullYear();\n const month = date.getUTCMonth();\n const dayInLastWeek = new Date(Date.UTC(year, month, 36));\n const lastWeek = getWeek(dayInLastWeek, calendarType);\n\n let day;\n let currentWeek;\n let iterator = 1;\n\n do {\n day = new Date(Date.UTC(year, month, iterator));\n currentWeek = getWeek(day, calendarType);\n weekdays.push(currentWeek);\n iterator += 7;\n } while (currentWeek !== lastWeek);\n\n return weekdays;\n};\n\nexport const getNextMonth = (date: Date) => {\n const next = new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth() + 1, 1));\n return next.getUTCMonth();\n};\n\nexport const getPreviousMonth = (date: Date) => {\n const prev = new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth() - 1, 1));\n return prev.getUTCMonth();\n};\n\nconst DAY_IN_MILLISECONDS = 86400000;\n\nexport function* getIntervalGenerator(interval: number) {\n const current = new Date(0);\n while (current.getTime() < DAY_IN_MILLISECONDS) {\n yield new Date(current);\n current.setTime(current.getTime() + interval);\n }\n}\n\nexport const toDateTimeString = (\n date: Date | undefined,\n mode: DatePickerProps['mode'] = 'date'\n) => {\n return date\n ? date.toLocaleString(\n undefined,\n mode === 'datetime'\n ? { dateStyle: 'medium', timeStyle: 'medium', timeZone: 'UTC' }\n : { dateStyle: 'medium', timeZone: 'UTC' }\n )\n : undefined;\n};\n\n/**\n * Shifts date forward or backward. It sets the day of month\n * to the last day of the resulted month if it does not contain the calculated day,\n * ie. 2022-01-31 -> 2022-02-28.\n * @param currentDate a date to advance by month\n * @param shift determines whether it is the next month or the previous month\n * @returns new Date object with advanced month\n */\nexport const shiftDateByMonth = (currentDate: Date, shift: 1 | -1) => {\n const result = new Date(currentDate);\n result.setMonth(result.getMonth() + shift);\n\n if (result.getMonth() !== (currentDate.getMonth() + shift + 12) % 12) {\n result.setDate(0);\n }\n\n return result;\n};\n"]}
@@ -11,7 +11,7 @@ const CompactList = forwardRef(function CompactList({ count, onDialogOpen, onDia
11
11
  if (onDialogOpen && !target)
12
12
  onDialogOpen();
13
13
  setTarget(e.currentTarget);
14
- }, children: t('number_of_items', [count]) }), target && (_jsx(InfoDialog, { heading: heading, progress: progress, target: target, onDismiss: () => {
14
+ }, children: t('number_of_items', [count], { count }) }), target && (_jsx(InfoDialog, { heading: heading, progress: progress, target: target, onDismiss: () => {
15
15
  if (onDialogClose)
16
16
  onDialogClose();
17
17
  setTarget(null);
@@ -1 +1 @@
1
- {"version":3,"file":"CompactList.js","sourceRoot":"","sources":["../../../src/components/File/CompactList.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAInC,OAAO,MAAM,MAAM,WAAW,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,UAAU,MAAM,sBAAsB,CAAC;AAE9C,OAAO,OAAO,MAAM,YAAY,CAAC;AAiBjC,MAAM,WAAW,GAAG,UAAU,CAC5B,SAAS,WAAW,CAClB,EAAE,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,SAAS,EAAE,EAChF,GAAG;IAEH,MAAM,CAAC,GAAG,OAAO,EAAE,CAAC;IACpB,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,UAAU,CAAoB,IAAI,CAAC,CAAC;IAEhE,OAAO,CACL,iBAAS,SAAS,EAAE,GAAG,EAAE,GAAG,YACzB,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CACb,KAAC,OAAO,KAAG,CACZ,CAAC,CAAC,CAAC,CACF,8BACE,KAAC,MAAM,IACL,OAAO,EAAC,MAAM,EACd,OAAO,EAAE,CAAC,CAAgC,EAAE,EAAE;wBAC5C,IAAI,YAAY,IAAI,CAAC,MAAM;4BAAE,YAAY,EAAE,CAAC;wBAC5C,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC;oBAC7B,CAAC,YAEA,CAAC,CAAC,iBAAiB,EAAE,CAAC,KAAK,CAAC,CAAC,GACvB,EAER,MAAM,IAAI,CACT,KAAC,UAAU,IACT,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,GAAG,EAAE;wBACd,IAAI,aAAa;4BAAE,aAAa,EAAE,CAAC;wBACnC,SAAS,CAAC,IAAI,CAAC,CAAC;oBAClB,CAAC,YAEA,OAAO,GACG,CACd,IACA,CACJ,GACG,CACP,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,WAAW,CAAC","sourcesContent":["import { forwardRef } from 'react';\nimport type { PropsWithoutRef, MouseEvent } from 'react';\n\nimport type { NoChildrenProp, RefElement, WithAttributes } from '../../types';\nimport Button from '../Button';\nimport { useElement, useI18n } from '../../hooks';\nimport InfoDialog from '../Dialog/InfoDialog';\nimport type { InfoDialogProps } from '../Dialog';\nimport NoValue from '../NoValue';\n\nexport type CompactListProps = WithAttributes<\n 'div',\n NoChildrenProp &\n Pick<InfoDialogProps, 'progress'> & {\n /** number representing the total count of items */\n count: number;\n heading: InfoDialogProps['heading'];\n /** Callback that triggers when the dialog is open */\n onDialogOpen?: () => void;\n /** Callback that triggers when the dialog is closed */\n onDialogClose?: () => void;\n content?: InfoDialogProps['children'];\n }\n>;\n\nconst CompactList = forwardRef<RefElement<CompactListProps>, PropsWithoutRef<CompactListProps>>(\n function CompactList(\n { count, onDialogOpen, onDialogClose, progress, heading, content, ...restProps },\n ref\n ) {\n const t = useI18n();\n const [target, setTarget] = useElement<HTMLButtonElement>(null);\n\n return (\n <div {...restProps} ref={ref}>\n {count === 0 ? (\n <NoValue />\n ) : (\n <>\n <Button\n variant='link'\n onClick={(e: MouseEvent<HTMLButtonElement>) => {\n if (onDialogOpen && !target) onDialogOpen();\n setTarget(e.currentTarget);\n }}\n >\n {t('number_of_items', [count])}\n </Button>\n\n {target && (\n <InfoDialog\n heading={heading}\n progress={progress}\n target={target}\n onDismiss={() => {\n if (onDialogClose) onDialogClose();\n setTarget(null);\n }}\n >\n {content}\n </InfoDialog>\n )}\n </>\n )}\n </div>\n );\n }\n);\n\nexport default CompactList;\n"]}
1
+ {"version":3,"file":"CompactList.js","sourceRoot":"","sources":["../../../src/components/File/CompactList.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAInC,OAAO,MAAM,MAAM,WAAW,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,UAAU,MAAM,sBAAsB,CAAC;AAE9C,OAAO,OAAO,MAAM,YAAY,CAAC;AAiBjC,MAAM,WAAW,GAAG,UAAU,CAC5B,SAAS,WAAW,CAClB,EAAE,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,SAAS,EAAE,EAChF,GAAG;IAEH,MAAM,CAAC,GAAG,OAAO,EAAE,CAAC;IACpB,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,UAAU,CAAoB,IAAI,CAAC,CAAC;IAEhE,OAAO,CACL,iBAAS,SAAS,EAAE,GAAG,EAAE,GAAG,YACzB,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CACb,KAAC,OAAO,KAAG,CACZ,CAAC,CAAC,CAAC,CACF,8BACE,KAAC,MAAM,IACL,OAAO,EAAC,MAAM,EACd,OAAO,EAAE,CAAC,CAAgC,EAAE,EAAE;wBAC5C,IAAI,YAAY,IAAI,CAAC,MAAM;4BAAE,YAAY,EAAE,CAAC;wBAC5C,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC;oBAC7B,CAAC,YAEA,CAAC,CAAC,iBAAiB,EAAE,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,GAClC,EAER,MAAM,IAAI,CACT,KAAC,UAAU,IACT,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,GAAG,EAAE;wBACd,IAAI,aAAa;4BAAE,aAAa,EAAE,CAAC;wBACnC,SAAS,CAAC,IAAI,CAAC,CAAC;oBAClB,CAAC,YAEA,OAAO,GACG,CACd,IACA,CACJ,GACG,CACP,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,WAAW,CAAC","sourcesContent":["import { forwardRef } from 'react';\nimport type { PropsWithoutRef, MouseEvent } from 'react';\n\nimport type { NoChildrenProp, RefElement, WithAttributes } from '../../types';\nimport Button from '../Button';\nimport { useElement, useI18n } from '../../hooks';\nimport InfoDialog from '../Dialog/InfoDialog';\nimport type { InfoDialogProps } from '../Dialog';\nimport NoValue from '../NoValue';\n\nexport type CompactListProps = WithAttributes<\n 'div',\n NoChildrenProp &\n Pick<InfoDialogProps, 'progress'> & {\n /** number representing the total count of items */\n count: number;\n heading: InfoDialogProps['heading'];\n /** Callback that triggers when the dialog is open */\n onDialogOpen?: () => void;\n /** Callback that triggers when the dialog is closed */\n onDialogClose?: () => void;\n content?: InfoDialogProps['children'];\n }\n>;\n\nconst CompactList = forwardRef<RefElement<CompactListProps>, PropsWithoutRef<CompactListProps>>(\n function CompactList(\n { count, onDialogOpen, onDialogClose, progress, heading, content, ...restProps },\n ref\n ) {\n const t = useI18n();\n const [target, setTarget] = useElement<HTMLButtonElement>(null);\n\n return (\n <div {...restProps} ref={ref}>\n {count === 0 ? (\n <NoValue />\n ) : (\n <>\n <Button\n variant='link'\n onClick={(e: MouseEvent<HTMLButtonElement>) => {\n if (onDialogOpen && !target) onDialogOpen();\n setTarget(e.currentTarget);\n }}\n >\n {t('number_of_items', [count], { count })}\n </Button>\n\n {target && (\n <InfoDialog\n heading={heading}\n progress={progress}\n target={target}\n onDismiss={() => {\n if (onDialogClose) onDialogClose();\n setTarget(null);\n }}\n >\n {content}\n </InfoDialog>\n )}\n </>\n )}\n </div>\n );\n }\n);\n\nexport default CompactList;\n"]}
@@ -1,7 +1,8 @@
1
1
  import type { NoChildrenProp, OmitStrict, WithAttributes } from '../../types';
2
2
  import type { FileDisplayProps } from './FileDisplay';
3
+ import { type FileListProps } from './FileList';
3
4
  import { type CompactListProps } from './CompactList';
4
- export type FileDisplayListProps = WithAttributes<'div', Pick<FileDisplayProps, 'variant' | 'compact'> & NoChildrenProp & Partial<Pick<CompactListProps, 'count' | 'onDialogOpen' | 'onDialogClose' | 'heading' | 'progress'>> & {
5
+ export type FileDisplayListProps = WithAttributes<'div', Pick<FileDisplayProps, 'variant' | 'compact'> & NoChildrenProp & Partial<Pick<CompactListProps, 'count' | 'onDialogOpen' | 'onDialogClose' | 'heading' | 'progress'>> & Pick<FileListProps, 'onDownloadAll'> & {
5
6
  items?: OmitStrict<FileDisplayProps, 'variant'>[];
6
7
  }>;
7
8
  declare const FileDisplayList: import("react").ForwardRefExoticComponent<Omit<FileDisplayListProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
@@ -1 +1 @@
1
- {"version":3,"file":"FileDisplayList.d.ts","sourceRoot":"","sources":["../../../src/components/File/FileDisplayList.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAc,cAAc,EAAE,MAAM,aAAa,CAAC;AAE1F,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAA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e,CAAC"}
@@ -2,10 +2,11 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { forwardRef } from 'react';
3
3
  import FileList, {} from './FileList';
4
4
  import CompactList, {} from './CompactList';
5
- const FileDisplayList = forwardRef(function FileDisplayList({ variant, items = [], compact = false, heading, progress, count, onDialogOpen, onDialogClose, ...restProps }, ref) {
5
+ const FileDisplayList = forwardRef(function FileDisplayList({ variant, items = [], compact = false, heading, progress, count, onDialogOpen, onDialogClose, onDownloadAll, ...restProps }, ref) {
6
6
  const fileListProps = {
7
7
  type: 'display',
8
- items: items.map(item => ({ ...item, variant }))
8
+ items: items.map(item => ({ ...item, variant })),
9
+ onDownloadAll
9
10
  };
10
11
  return compact ? (_jsx(CompactList, { ...restProps, count: count ?? items.length, onDialogOpen: onDialogOpen, onDialogClose: onDialogClose, heading: heading, progress: progress, content: progress ? undefined : _jsx(FileList, { ...fileListProps }), ref: ref })) : (_jsx(FileList, { ...restProps, ...fileListProps, ref: ref }));
11
12
  });
@@ -1 +1 @@
1
- {"version":3,"file":"FileDisplayList.js","sourceRoot":"","sources":["../../../src/components/File/FileDisplayList.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAMnC,OAAO,QAAQ,EAAE,EAAsB,MAAM,YAAY,CAAC;AAC1D,OAAO,WAAW,EAAE,EAAyB,MAAM,eAAe,CAAC;AAanE,MAAM,eAAe,GAAG,UAAU,CAGhC,SAAS,eAAe,CACxB,EACE,OAAO,EACP,KAAK,GAAG,EAAE,EACV,OAAO,GAAG,KAAK,EACf,OAAO,EACP,QAAQ,EACR,KAAK,EACL,YAAY,EACZ,aAAa,EACb,GAAG,SAAS,EACb,EACD,GAAG;IAEH,MAAM,aAAa,GAAkB;QACnC,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;KACjD,CAAC;IAEF,OAAO,OAAO,CAAC,CAAC,CAAC,CACf,KAAC,WAAW,OACN,SAAS,EACb,KAAK,EAAE,KAAK,IAAI,KAAK,CAAC,MAAM,EAC5B,YAAY,EAAE,YAAY,EAC1B,aAAa,EAAE,aAAa,EAC5B,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAC,QAAQ,OAAK,aAAa,GAAI,EAC/D,GAAG,EAAE,GAAG,GACR,CACH,CAAC,CAAC,CAAC,CACF,KAAC,QAAQ,OAAK,SAAS,KAAM,aAAa,EAAE,GAAG,EAAE,GAAG,GAAI,CACzD,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,eAAe,eAAe,CAAC","sourcesContent":["import { forwardRef } from 'react';\nimport type { PropsWithoutRef } from 'react';\n\nimport type { NoChildrenProp, OmitStrict, RefElement, WithAttributes } from '../../types';\n\nimport type { FileDisplayProps } from './FileDisplay';\nimport FileList, { type FileListProps } from './FileList';\nimport CompactList, { type CompactListProps } from './CompactList';\n\nexport type FileDisplayListProps = WithAttributes<\n 'div',\n Pick<FileDisplayProps, 'variant' | 'compact'> &\n NoChildrenProp &\n Partial<\n Pick<CompactListProps, 'count' | 'onDialogOpen' | 'onDialogClose' | 'heading' | 'progress'>\n > & {\n items?: OmitStrict<FileDisplayProps, 'variant'>[];\n }\n>;\n\nconst FileDisplayList = forwardRef<\n RefElement<FileDisplayListProps>,\n PropsWithoutRef<FileDisplayListProps>\n>(function FileDisplayList(\n {\n variant,\n items = [],\n compact = false,\n heading,\n progress,\n count,\n onDialogOpen,\n onDialogClose,\n ...restProps\n },\n ref\n) {\n const fileListProps: FileListProps = {\n type: 'display',\n items: items.map(item => ({ ...item, variant }))\n };\n\n return compact ? (\n <CompactList\n {...restProps}\n count={count ?? items.length}\n onDialogOpen={onDialogOpen}\n onDialogClose={onDialogClose}\n heading={heading}\n progress={progress}\n content={progress ? undefined : <FileList {...fileListProps} />}\n ref={ref}\n />\n ) : (\n <FileList {...restProps} {...fileListProps} ref={ref} />\n );\n});\n\nexport default FileDisplayList;\n"]}
1
+ {"version":3,"file":"FileDisplayList.js","sourceRoot":"","sources":["../../../src/components/File/FileDisplayList.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAMnC,OAAO,QAAQ,EAAE,EAAsB,MAAM,YAAY,CAAC;AAC1D,OAAO,WAAW,EAAE,EAAyB,MAAM,eAAe,CAAC;AAcnE,MAAM,eAAe,GAAG,UAAU,CAGhC,SAAS,eAAe,CACxB,EACE,OAAO,EACP,KAAK,GAAG,EAAE,EACV,OAAO,GAAG,KAAK,EACf,OAAO,EACP,QAAQ,EACR,KAAK,EACL,YAAY,EACZ,aAAa,EACb,aAAa,EACb,GAAG,SAAS,EACb,EACD,GAAG;IAEH,MAAM,aAAa,GAAkB;QACnC,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;QAChD,aAAa;KACd,CAAC;IAEF,OAAO,OAAO,CAAC,CAAC,CAAC,CACf,KAAC,WAAW,OACN,SAAS,EACb,KAAK,EAAE,KAAK,IAAI,KAAK,CAAC,MAAM,EAC5B,YAAY,EAAE,YAAY,EAC1B,aAAa,EAAE,aAAa,EAC5B,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAC,QAAQ,OAAK,aAAa,GAAI,EAC/D,GAAG,EAAE,GAAG,GACR,CACH,CAAC,CAAC,CAAC,CACF,KAAC,QAAQ,OAAK,SAAS,KAAM,aAAa,EAAE,GAAG,EAAE,GAAG,GAAI,CACzD,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,eAAe,eAAe,CAAC","sourcesContent":["import { forwardRef } from 'react';\nimport type { PropsWithoutRef } from 'react';\n\nimport type { NoChildrenProp, OmitStrict, RefElement, WithAttributes } from '../../types';\n\nimport type { FileDisplayProps } from './FileDisplay';\nimport FileList, { type FileListProps } from './FileList';\nimport CompactList, { type CompactListProps } from './CompactList';\n\nexport type FileDisplayListProps = WithAttributes<\n 'div',\n Pick<FileDisplayProps, 'variant' | 'compact'> &\n NoChildrenProp &\n Partial<\n Pick<CompactListProps, 'count' | 'onDialogOpen' | 'onDialogClose' | 'heading' | 'progress'>\n > &\n Pick<FileListProps, 'onDownloadAll'> & {\n items?: OmitStrict<FileDisplayProps, 'variant'>[];\n }\n>;\n\nconst FileDisplayList = forwardRef<\n RefElement<FileDisplayListProps>,\n PropsWithoutRef<FileDisplayListProps>\n>(function FileDisplayList(\n {\n variant,\n items = [],\n compact = false,\n heading,\n progress,\n count,\n onDialogOpen,\n onDialogClose,\n onDownloadAll,\n ...restProps\n },\n ref\n) {\n const fileListProps: FileListProps = {\n type: 'display',\n items: items.map(item => ({ ...item, variant })),\n onDownloadAll\n };\n\n return compact ? (\n <CompactList\n {...restProps}\n count={count ?? items.length}\n onDialogOpen={onDialogOpen}\n onDialogClose={onDialogClose}\n heading={heading}\n progress={progress}\n content={progress ? undefined : <FileList {...fileListProps} />}\n ref={ref}\n />\n ) : (\n <FileList {...restProps} {...fileListProps} ref={ref} />\n );\n});\n\nexport default FileDisplayList;\n"]}
@@ -1,8 +1,27 @@
1
1
  import type { FunctionComponent, Ref } from 'react';
2
- import type { BaseProps, ForwardProps, NoChildrenProp, TestIdProp } from '../../types';
2
+ import { type FileListProps, type ModalProps } from '@pega/cosmos-react-core';
3
+ import type { BaseProps, ForwardProps, NoChildrenProp, OmitStrict, TestIdProp } from '../../types';
3
4
  import type { FormControlProps } from '../FormControl';
4
5
  import type { FileItemProps } from './FileItem';
5
- export interface FileInputProps extends BaseProps, NoChildrenProp, TestIdProp {
6
+ /** Props to be used when rendering compact variant for multiple FileInput. */
7
+ interface MultiAttachCompactProps {
8
+ /** Modal props */
9
+ modal?: Pick<ModalProps, 'onBeforeOpen'> & {
10
+ /** Callback for cancel button */
11
+ onCancel: ({ close }: {
12
+ close: () => void;
13
+ }) => void;
14
+ /** Callback for submit button */
15
+ onSubmit: ({ close }: {
16
+ close: () => void;
17
+ }) => void;
18
+ /** If true renders loading indicator inside Modal. */
19
+ loading?: boolean;
20
+ };
21
+ /** Conveys the number of files attached */
22
+ count?: number;
23
+ }
24
+ interface BaseFileInputProps extends BaseProps, NoChildrenProp, TestIdProp, Pick<FileItemProps, 'previewFromActions'>, Pick<FileListProps, 'onDownloadAll'> {
6
25
  /** Called when files are added either via the input or drop zone. */
7
26
  onFilesAdded?: (files: File[]) => void;
8
27
  /**
@@ -12,8 +31,13 @@ export interface FileInputProps extends BaseProps, NoChildrenProp, TestIdProp {
12
31
  * @default false
13
32
  */
14
33
  multiple?: boolean;
34
+ /**
35
+ * Renders compact variant.
36
+ * @default false
37
+ */
38
+ compact?: boolean;
15
39
  /** An array of files that have been uploaded. */
16
- files?: FileItemProps[];
40
+ files?: OmitStrict<FileItemProps, 'previewFromActions'>[];
17
41
  /**
18
42
  * Specify allowed file types.
19
43
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/accept}
@@ -43,10 +67,10 @@ export interface FileInputProps extends BaseProps, NoChildrenProp, TestIdProp {
43
67
  /** Ref for the input element within the component's dom structure. */
44
68
  ref?: Ref<HTMLInputElement>;
45
69
  }
46
- export declare const StyledDropZone: import("styled-components").StyledComponent<FunctionComponent<FormControlProps & ForwardProps>, import("styled-components").DefaultTheme, {}, never>;
47
- export declare const StyledFileInput: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, Pick<FileInputProps, keyof FileInputProps> & Required<Pick<FileInputProps, never>> & ForwardProps, never>;
70
+ export interface FileInputProps extends BaseFileInputProps, MultiAttachCompactProps {
71
+ }
48
72
  declare const _default: FunctionComponent<FileInputProps & ForwardProps> & {
49
- getTestIds: (testIdProp?: string | null | undefined) => import("../../types").TestIdsRecord<readonly ["control", "files", "label", "info", "additional-info", "suggestion-accept", "suggestion-reject"]>;
73
+ getTestIds: (testIdProp?: string | null | undefined) => import("@pega/cosmos-react-core").TestIdsRecord<readonly ["control", "files", "label", "info", "additional-info", "suggestion-accept", "suggestion-reject"]>;
50
74
  };
51
75
  export default _default;
52
76
  //# sourceMappingURL=FileInput.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FileInput.d.ts","sourceRoot":"","sources":["../../../src/components/File/FileInput.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,GAAG,EAA2C,MAAM,OAAO,CAAC;AAI7F,OAAO,KAAK,EACV,SAAS,EACT,YAAY,EACZ,cAAc,EAEd,UAAU,EACX,MAAM,aAAa,CAAC;AAGrB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAUvD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAShD,MAAM,WAAW,cAAe,SAAQ,SAAS,EAAE,cAAc,EAAE,UAAU;IAC3E,qEAAqE;IACrE,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,IAAI,CAAC;IACvC;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,iDAAiD;IACjD,KAAK,CAAC,EAAE,aAAa,EAAE,CAAC;IACxB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC3B;;;OAGG;IACH,EAAE,CAAC,EAAE,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAC5B,oDAAoD;IACpD,MAAM,CAAC,EAAE,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IACpC,2DAA2D;IAC3D,KAAK,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAClC,uCAAuC;IACvC,WA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AAQ,CAAC,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAC;IACxC,+FAA+F;IAC/F,IAAI,CAAC,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAChC,8EAA8E;IAC9E,cAAc,CAAC,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;IACpD,sEAAsE;IACtE,GAAG,CAAC,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAC;CAC7B;AAED,MAAM,WAAW,cAAe,SAAQ,kBAAkB,EAAE,uBAAuB;CAAG;;;;AA6atF,wBAA2D"}
@@ -1,103 +1,42 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { forwardRef, useCallback, useEffect, useRef, useState } from 'react';
3
- import styled, { css } from 'styled-components';
4
- import { hideVisually } from 'polished';
5
- import { useConsolidatedRef, useI18n, useUID, useTestIds, usePrevious } from '../../hooks';
6
- import FormControl from '../FormControl';
7
- import { defaultThemeProp } from '../../theme';
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { forwardRef, useCallback, useEffect, useMemo, useRef, useState } from 'react';
3
+ import { MetaList } from '@pega/cosmos-react-core';
4
+ import { useConsolidatedRef, useI18n, useUID, useTestIds, usePrevious, useElement, useModalManager, useModalContext } from '../../hooks';
8
5
  import Flex from '../Flex';
9
6
  import Text from '../Text';
10
7
  import Icon, { registerIcon } from '../Icon';
11
8
  import * as paperClipIcon from '../Icon/icons/paper-clip.icon';
12
- import FormField from '../FormField';
13
9
  import Grid from '../Grid';
14
10
  import { getActiveElement, getFocusables, withTestIds } from '../../utils';
11
+ import Tooltip from '../Tooltip';
12
+ import Button from '../Button';
13
+ import Modal, {} from '../Modal';
15
14
  import { getFileInputTestIds } from './File.test-ids';
16
15
  import FileList from './FileList';
17
16
  import FileItem from './FileItem';
17
+ import { StyledBareButton, StyledDropZone, StyledFileInput, StyledIconWrapper, StyledAttachedFileCount, StyledSingleFileWrapper, StyledUploadStatus, StyledFlex, StyledFormField, StyledFileInputControl } from './FileInput.styles';
18
18
  registerIcon(paperClipIcon);
19
- export const StyledDropZone = styled(FormControl)(({ theme: { base: { 'hit-area': { 'finger-min': fingerMin } }, components } }) => {
20
- return css `
21
- height: ${components.input.height};
22
- border: none;
23
- cursor: pointer;
24
-
25
- @media (pointer: coarse) {
26
- height: ${fingerMin};
27
- }
28
- `;
29
- });
30
- StyledDropZone.defaultProps = defaultThemeProp;
31
- const StyledTextWrapper = styled(Flex)(({ dragOver, status, theme: { base: { 'border-radius': borderRadius }, components: { 'form-field': formField, 'form-control': { 'border-color': borderColor, ':hover': { 'border-color': hoverBorderColor } } } } }) => {
32
- return css `
33
- border: 0.0625rem dashed ${borderColor};
34
- border-start-start-radius: calc(0.5 * ${borderRadius});
35
- border-end-start-radius: calc(0.5 * ${borderRadius});
36
-
37
- ${status &&
38
- css `
39
- border-color: ${formField[status]['status-color']};
40
- `};
41
-
42
- ${dragOver &&
43
- css `
44
- border-style: solid;
45
- `}
46
-
47
- &:hover:not([disabled]):not(:focus, :focus-within) {
48
- ${!status &&
49
- css `
50
- border-color: ${hoverBorderColor};
51
- `}
52
- }
53
- `;
54
- });
55
- StyledTextWrapper.defaultProps = defaultThemeProp;
56
- const StyledIconWrapper = styled(Flex)(({ theme: { base: { 'border-radius': borderRadius }, components } }) => {
57
- return css `
58
- border: 0.0625rem solid ${components['form-control']['border-color']};
59
- border-start-end-radius: calc(0.5 * ${borderRadius});
60
- border-end-end-radius: calc(0.5 * ${borderRadius});
61
- border-inline-start: none;
62
- aspect-ratio: 1 / 1;
63
- `;
64
- });
65
- StyledIconWrapper.defaultProps = defaultThemeProp;
66
- export const StyledFileInput = styled.div(({ theme: { components: { 'form-control': { 'border-color': borderColor, ':focus': { 'box-shadow': boxShadow } } } } }) => {
67
- return css `
68
- position: relative;
69
-
70
- input {
71
- ${hideVisually}
72
- }
73
-
74
- input:enabled:focus + ${StyledDropZone} {
75
- box-shadow: ${boxShadow};
76
-
77
- > ${StyledIconWrapper} {
78
- border: none;
79
- }
80
- > ${StyledTextWrapper} {
81
- border-block: none;
82
- border-inline-start: none;
83
- border-inline-end: 0.0625rem dashed ${borderColor};
84
- }
85
- }
86
- `;
87
- });
88
- StyledFileInput.defaultProps = defaultThemeProp;
89
- const StyledSingleFileWrapper = styled.div `
90
- display: contents;
91
- `;
92
- const FileInput = forwardRef(function FileInput(props, ref) {
19
+ const Component = props => {
20
+ const { compact, multiple, status, count, dragOver = false } = props;
21
+ const t = useI18n();
22
+ const attachedFileCount = multiple && count ? (_jsx(StyledAttachedFileCount, { children: t('number_of_items', [count], { count }) })) : undefined;
23
+ return (_jsxs(_Fragment, { children: [_jsx(StyledUploadStatus, { item: { grow: 1 }, container: { justify: compact && multiple ? 'start' : 'center', alignItems: 'center' }, status: status, dragOver: dragOver, children: _jsx(Text, { variant: 'secondary', children: compact
24
+ ? attachedFileCount
25
+ : t('file_upload_text_main', [
26
+ t(multiple ? 'file_upload_text_multiple' : 'file_upload_text_one')
27
+ ]) }) }), _jsx(StyledIconWrapper, { container: { justify: 'center', alignItems: 'center' }, children: _jsx(Icon, { name: 'paper-clip' }) })] }));
28
+ };
29
+ const BaseFileInput = forwardRef(function FileInput(props, ref) {
93
30
  const uid = useUID();
94
- const { testId, id = uid, label, labelHidden, info, required = false, disabled = false, files, onFilesAdded, multiple = false, status, additionalInfo, accept, ...restProps } = props;
31
+ const { testId, id = uid, label, labelHidden, info, required = false, disabled = false, files, onDownloadAll, onFilesAdded, multiple = false, status, additionalInfo, accept, compact = false, previewFromActions = false, ...restProps } = props;
95
32
  const testIds = useTestIds(testId, getFileInputTestIds);
33
+ const [target, setTarget] = useElement();
96
34
  const inputRef = useConsolidatedRef(ref);
97
35
  const fileItemListRef = useRef();
98
36
  const activeElement = getActiveElement();
99
37
  const activeElementInList = fileItemListRef.current?.contains(activeElement);
100
38
  const isInputActiveElement = activeElement === inputRef.current;
39
+ const compactWithSingleAttach = compact && !multiple;
101
40
  const onChange = useCallback((e) => {
102
41
  if (e.target.files) {
103
42
  onFilesAdded?.(Array.from(e.target.files));
@@ -116,22 +55,35 @@ const FileInput = forwardRef(function FileInput(props, ref) {
116
55
  const t = useI18n();
117
56
  const [dragOver, setDragOver] = useState(false);
118
57
  const hideFileInput = !multiple && files && files.length > 0;
119
- const fileInput = (_jsxs(StyledFileInput, { children: [_jsx("input", { "data-testid": testIds.control, ...restProps, ref: inputRef, type: 'file', id: id, required: required, disabled: disabled, onChange: onChange, multiple: multiple, accept: Array.isArray(accept) ? accept.join(',') : accept }), _jsxs(Flex, { container: true, as: StyledDropZone, onClick: () => {
58
+ const fileInput = (_jsxs(StyledFileInput, { children: [_jsx("input", { "data-testid": testIds.control, ...restProps, ref: inputRef, type: 'file', id: id, required: required, disabled: disabled, onChange: onChange, onFocus: () => {
59
+ if (target) {
60
+ target.dispatchEvent(new Event('focusin'));
61
+ }
62
+ }, onBlur: () => {
63
+ if (target) {
64
+ target.dispatchEvent(new Event('focusout'));
65
+ }
66
+ }, multiple: multiple, accept: Array.isArray(accept) ? accept.join(',') : accept }), _jsx(Flex, { container: true, as: StyledDropZone, onClick: () => {
120
67
  inputRef.current?.focus();
121
68
  inputRef.current?.click();
122
- }, onDragOver: (e) => {
123
- e.preventDefault();
124
- }, onDragEnter: () => setDragOver(true), onDragLeave: () => setDragOver(false), onDrop: (e) => {
125
- e.preventDefault();
126
- setDragOver(false);
127
- onFilesAdded?.(Array.from(e.dataTransfer.files));
128
- }, children: [_jsx(StyledTextWrapper, { item: { grow: 1 }, container: { justify: 'center', alignItems: 'center' }, status: status, dragOver: dragOver, children: _jsx(Text, { variant: 'secondary', children: t('file_upload_text_main', [
129
- t(multiple ? 'file_upload_text_multiple' : 'file_upload_text_one')
130
- ]) }) }), _jsx(StyledIconWrapper, { container: { justify: 'center', alignItems: 'center' }, children: _jsx(Icon, { name: 'paper-clip' }) })] })] }));
131
- const fileItemList = hideFileInput ? (_jsx(StyledSingleFileWrapper, { "data-testid": testIds.files, ref: element => {
69
+ }, ...(!disabled
70
+ ? {
71
+ onDragOver: (e) => {
72
+ e.preventDefault();
73
+ },
74
+ onDragEnter: () => setDragOver(true),
75
+ onDragLeave: () => setDragOver(false),
76
+ onDrop: (e) => {
77
+ e.preventDefault();
78
+ setDragOver(false);
79
+ onFilesAdded?.(Array.from(e.dataTransfer.files));
80
+ }
81
+ }
82
+ : undefined), compactMode: compact, ref: setTarget, children: _jsx(Component, { compact: compact, multiple: multiple, status: status, dragOver: dragOver }) }), compactWithSingleAttach && target && (_jsx(Tooltip, { target: target, describeTarget: true, children: t('file_upload_text_main', [t('file_upload_text_one')]) }))] }));
83
+ const fileItemList = hideFileInput ? (_jsx(StyledSingleFileWrapper, { "data-testid": testIds.files, compact: compact, ref: element => {
132
84
  if (element)
133
85
  fileItemListRef.current = element;
134
- }, children: _jsx(FileItem, { ...files[0] }) })) : (_jsx(FileList, { type: 'item', items: files ?? [], "data-testid": testIds.files, ref: element => {
86
+ }, children: _jsx(FileItem, { ...files[0], compact: compact, previewFromActions: compactWithSingleAttach && previewFromActions }) })) : (_jsx(FileList, { type: 'item', items: files ?? [], "data-testid": testIds.files, ref: element => {
135
87
  if (element)
136
88
  fileItemListRef.current = element;
137
89
  } }));
@@ -149,7 +101,94 @@ const FileInput = forwardRef(function FileInput(props, ref) {
149
101
  }
150
102
  }, [files]);
151
103
  const renderElement = hideFileInput ? fileItemList : fileInput;
152
- return (_jsxs(Grid, { container: { rowGap: hideFileInput ? undefined : 1 }, children: [label ? (_jsx(FormField, { testId: testIds, label: label, labelHidden: labelHidden, id: id, info: info, required: required, disabled: !hideFileInput && disabled, status: status, additionalInfo: additionalInfo, children: renderElement })) : (renderElement), !hideFileInput && fileItemList] }));
104
+ const fileInputInfoActions = useMemo(() => {
105
+ if (info && !onDownloadAll) {
106
+ return info;
107
+ }
108
+ const downloadAllButton = (_jsx(Button, { onClick: onDownloadAll, variant: 'link', children: t('download_all') }));
109
+ if (onDownloadAll && !info && files && files.length > 1 && multiple) {
110
+ return downloadAllButton;
111
+ }
112
+ if (info && onDownloadAll) {
113
+ if (files && files.length > 1 && multiple) {
114
+ return _jsx(MetaList, { items: [info, downloadAllButton] });
115
+ }
116
+ return info;
117
+ }
118
+ }, [info, onDownloadAll]);
119
+ return (_jsxs(Grid, { container: { rowGap: hideFileInput ? undefined : 1 }, as: StyledFileInputControl, status: status, children: [label ? (_jsx(StyledFormField, { testId: testIds, label: label, labelHidden: labelHidden, id: id, info: fileInputInfoActions, required: required, disabled: !hideFileInput && disabled, status: status, additionalInfo: additionalInfo, compactMode: compactWithSingleAttach, children: renderElement })) : (renderElement), multiple && !compact && files && files.length > 0 && fileItemList] }));
120
+ });
121
+ const AttachFilesModal = ({ modalContent, modal }) => {
122
+ const t = useI18n();
123
+ const { dismiss } = useModalContext();
124
+ const formActions = (_jsxs(_Fragment, { children: [_jsx(Button, { disabled: modal?.loading, onClick: () => {
125
+ if (modal?.onCancel)
126
+ modal.onCancel({ close: dismiss });
127
+ }, children: t('cancel') }), _jsx(Button, { disabled: modal?.loading, type: 'submit', variant: 'primary', onClick: () => {
128
+ if (modal?.onSubmit)
129
+ modal.onSubmit({ close: dismiss });
130
+ }, children: t('submit') })] }));
131
+ return (_jsx(Modal, { progress: modal?.loading, heading: t('attach_files'), actions: formActions, onBeforeOpen: modal?.onBeforeOpen, children: modalContent }));
132
+ };
133
+ const FileInput = forwardRef(function FileInput(props, ref) {
134
+ const uid = useUID();
135
+ const { modal, count, ...baseFileInputProps } = props;
136
+ const { id = uid, label, labelHidden, info, required = false, disabled = false, onFilesAdded, multiple = false, status, additionalInfo, compact = false } = baseFileInputProps;
137
+ const t = useI18n();
138
+ const [dragOver, setDragOver] = useState(false);
139
+ const [buttonEl, setButtonEl] = useElement();
140
+ const { create } = useModalManager();
141
+ const modalMethods = useRef();
142
+ let modalContent;
143
+ if (compact && multiple) {
144
+ modalContent = (_jsx(BaseFileInput, { ...baseFileInputProps, multiple: true, compact: false, labelHidden: false, ref: ref }));
145
+ }
146
+ const modalProps = {
147
+ modal,
148
+ modalContent
149
+ };
150
+ useEffect(() => {
151
+ if (compact && multiple && modal) {
152
+ modalMethods.current?.update({
153
+ modal,
154
+ modalContent
155
+ });
156
+ }
157
+ }, [compact, multiple, modal, modalProps]);
158
+ useEffect(() => {
159
+ return () => {
160
+ if (modalMethods.current) {
161
+ modalMethods.current?.dismiss();
162
+ modalMethods.current?.unmount();
163
+ }
164
+ };
165
+ }, []);
166
+ if (compact && multiple) {
167
+ const render = (_jsxs(Flex, { container: true, children: [_jsx(StyledBareButton, { id: id, onClick: () => {
168
+ modalMethods.current = create(AttachFilesModal, { ...modalProps }, { dismissible: false });
169
+ }, "aria-label": count && count > 0
170
+ ? `${t('attach_review')} ${t('number_of_items', [count], { count })}`
171
+ : undefined, disabled: disabled, ...(!disabled
172
+ ? {
173
+ onDragOver: (e) => {
174
+ e.preventDefault();
175
+ },
176
+ onDragEnter: () => setDragOver(true),
177
+ onDragLeave: () => setDragOver(false),
178
+ onDrop: (e) => {
179
+ e.preventDefault();
180
+ setDragOver(false);
181
+ onFilesAdded?.(Array.from(e.dataTransfer.files));
182
+ if (buttonEl)
183
+ buttonEl.click();
184
+ }
185
+ }
186
+ : undefined), ref: setButtonEl, children: _jsx(StyledFlex, { container: true, children: _jsx(Component, { compact: compact, multiple: multiple, status: status, count: count, dragOver: dragOver }) }) }), buttonEl && (_jsx(Tooltip, { target: buttonEl, describeTarget: count === 0, children: count && count > 0
187
+ ? t('attach_review')
188
+ : t('file_upload_text_main', [t('file_upload_text_multiple')]) }))] }));
189
+ return label ? (_jsx(StyledFormField, { label: label, labelHidden: labelHidden, id: id, info: info, required: required, disabled: disabled, status: status, additionalInfo: additionalInfo, compactMode: true, children: render })) : (render);
190
+ }
191
+ return _jsx(BaseFileInput, { ...baseFileInputProps, ref: ref });
153
192
  });
154
193
  export default withTestIds(FileInput, getFileInputTestIds);
155
194
  //# sourceMappingURL=FileInput.js.map
@@ -1 +1 @@
1
- {"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AAC,CAAC","sourcesContent":["import { forwardRef, useCallback, useEffect, useRef, useState } from 'react';\nimport type { FunctionComponent, Ref, ChangeEvent, PropsWithoutRef, DragEvent } from 'react';\nimport styled, { css } from 'styled-components';\nimport { hideVisually } from 'polished';\n\nimport type {\n BaseProps,\n ForwardProps,\n NoChildrenProp,\n PropsWithDefaults,\n TestIdProp\n} from '../../types';\nimport { useConsolidatedRef, useI18n, useUID, useTestIds, usePrevious } from '../../hooks';\nimport FormControl from '../FormControl';\nimport type { FormControlProps } from '../FormControl';\nimport { defaultThemeProp } from '../../theme';\nimport Flex from '../Flex';\nimport Text from '../Text';\nimport Icon, { registerIcon } from '../Icon';\nimport * as paperClipIcon from '../Icon/icons/paper-clip.icon';\nimport FormField from '../FormField';\nimport Grid from '../Grid';\nimport { getActiveElement, getFocusables, withTestIds } from '../../utils';\n\nimport type { FileItemProps } from './FileItem';\nimport { getFileInputTestIds } from './File.test-ids';\nimport FileList from './FileList';\nimport FileItem from './FileItem';\n\nregisterIcon(paperClipIcon);\n\ntype FileInputPropsWithDefaults = PropsWithDefaults<FileInputProps>;\n\nexport interface FileInputProps extends BaseProps, NoChildrenProp, TestIdProp {\n /** Called when files are added either via the input or drop zone. */\n onFilesAdded?: (files: File[]) => void;\n /**\n * Allow multiple files to be selected from the OS specific file browser.\n * NOTE: This does not restrict multiple files from being added via drag and drop.\n * Restrict multi file drag and drop via onFilesAdded and custom info message.\n * @default false\n */\n multiple?: boolean;\n /** An array of files that have been uploaded. */\n files?: FileItemProps[];\n /**\n * Specify allowed file types.\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/accept}\n */\n accept?: string | string[];\n /**\n * Sets DOM id for the control and associates label element via 'for' attribute.\n * If an id is not pass, a random id will be generated for any render.\n */\n id?: FormControlProps['id'];\n /** Set visual state based on a validation state. */\n status?: FormControlProps['status'];\n /** Pass a string or a fragment with an Icon and string. */\n label?: FormControlProps['label'];\n /** Visually hides the label region. */\n labelHidden?: FormControlProps['labelHidden'];\n /** It is recommended to pass a simple string to offer guidance. Text will be styled based on status prop. */\n info?: FormControlProps['info'];\n /** Indicate if the field is required. The browser defaults to false. */\n required?: FormControlProps['required'];\n /** Disable the control. The browser defaults to false. */\n disabled?: FormControlProps['disabled'];\n /** Sets html name attribute for the underlying control. Useful for mapping to a data field. */\n name?: FormControlProps['name'];\n /** Pass a heading and content to show additional information on the field. */\n additionalInfo?: FormControlProps['additionalInfo'];\n /** Ref for the input element within the component's dom structure. */\n ref?: Ref<HTMLInputElement>;\n}\n\nexport const StyledDropZone = styled(FormControl)(({\n theme: {\n base: {\n 'hit-area': { 'finger-min': fingerMin }\n },\n components\n }\n}) => {\n return css`\n height: ${components.input.height};\n border: none;\n cursor: pointer;\n\n @media (pointer: coarse) {\n height: ${fingerMin};\n }\n `;\n});\n\nStyledDropZone.defaultProps = defaultThemeProp;\n\nconst StyledTextWrapper = styled(Flex)<{\n status: FormControlProps['status'];\n dragOver: boolean;\n}>(({\n dragOver,\n status,\n theme: {\n base: { 'border-radius': borderRadius },\n components: {\n 'form-field': formField,\n 'form-control': {\n 'border-color': borderColor,\n ':hover': { 'border-color': hoverBorderColor }\n }\n }\n }\n}) => {\n return css`\n border: 0.0625rem dashed ${borderColor};\n border-start-start-radius: calc(0.5 * ${borderRadius});\n border-end-start-radius: calc(0.5 * ${borderRadius});\n\n ${status &&\n css`\n border-color: ${formField[status]['status-color']};\n `};\n\n ${dragOver &&\n css`\n border-style: solid;\n `}\n\n &:hover:not([disabled]):not(:focus, :focus-within) {\n ${!status &&\n css`\n border-color: ${hoverBorderColor};\n `}\n }\n `;\n});\n\nStyledTextWrapper.defaultProps = defaultThemeProp;\n\nconst StyledIconWrapper = styled(Flex)(({\n theme: {\n base: { 'border-radius': borderRadius },\n components\n }\n}) => {\n return css`\n border: 0.0625rem solid ${components['form-control']['border-color']};\n border-start-end-radius: calc(0.5 * ${borderRadius});\n border-end-end-radius: calc(0.5 * ${borderRadius});\n border-inline-start: none;\n aspect-ratio: 1 / 1;\n `;\n});\n\nStyledIconWrapper.defaultProps = defaultThemeProp;\n\nexport const StyledFileInput = styled.div<FileInputPropsWithDefaults & ForwardProps>(\n ({\n theme: {\n components: {\n 'form-control': {\n 'border-color': borderColor,\n ':focus': { 'box-shadow': boxShadow }\n }\n }\n }\n }) => {\n return css`\n position: relative;\n\n input {\n ${hideVisually}\n }\n\n input:enabled:focus + ${StyledDropZone} {\n box-shadow: ${boxShadow};\n\n > ${StyledIconWrapper} {\n border: none;\n }\n > ${StyledTextWrapper} {\n border-block: none;\n border-inline-start: none;\n border-inline-end: 0.0625rem dashed ${borderColor};\n }\n }\n `;\n }\n);\n\nStyledFileInput.defaultProps = defaultThemeProp;\n\nconst StyledSingleFileWrapper = styled.div`\n display: contents;\n`;\n\nconst FileInput: FunctionComponent<FileInputProps & ForwardProps> = forwardRef(function FileInput(\n props: PropsWithoutRef<FileInputProps>,\n ref: FileInputProps['ref']\n) {\n const uid = useUID();\n const {\n testId,\n id = uid,\n label,\n labelHidden,\n info,\n required = false,\n disabled = false,\n files,\n onFilesAdded,\n multiple = false,\n status,\n additionalInfo,\n accept,\n ...restProps\n } = props;\n\n const testIds = useTestIds(testId, getFileInputTestIds);\n\n const inputRef = useConsolidatedRef(ref);\n const fileItemListRef = useRef<HTMLDivElement>();\n const activeElement = getActiveElement();\n const activeElementInList = fileItemListRef.current?.contains(activeElement);\n const isInputActiveElement = activeElement === inputRef.current;\n\n const onChange = useCallback(\n (e: ChangeEvent<HTMLInputElement>) => {\n if (e.target.files) {\n onFilesAdded?.(Array.from(e.target.files));\n }\n /**\n * WHY are we doing this?\n * We are not working with the \"value\" prop of the input but rather the File instances that are created.\n * The consumer of this component should manage an array or File(s) and allow for a user to remove a selected file.\n * Since we can not modify the input value of files for browser security reasons,\n * and since setting the files property is less than ideal, we reset/toggle the input to a fresh state after a render.\n * This enables onChange to fire even if the user had just previously selected a file, removed it, and selected it again.\n */\n if (inputRef.current) inputRef.current.value = '';\n },\n [onFilesAdded]\n );\n\n const t = useI18n();\n const [dragOver, setDragOver] = useState(false);\n const hideFileInput = !multiple && files && files.length > 0;\n\n const fileInput = (\n <StyledFileInput>\n <input\n data-testid={testIds.control}\n {...restProps}\n ref={inputRef}\n type='file'\n id={id}\n required={required}\n disabled={disabled}\n onChange={onChange}\n multiple={multiple}\n accept={Array.isArray(accept) ? accept.join(',') : accept}\n />\n <Flex\n container\n as={StyledDropZone}\n onClick={() => {\n inputRef.current?.focus();\n inputRef.current?.click();\n }}\n onDragOver={(e: DragEvent<HTMLDivElement>) => {\n e.preventDefault();\n }}\n onDragEnter={() => setDragOver(true)}\n onDragLeave={() => setDragOver(false)}\n onDrop={(e: DragEvent<HTMLDivElement>) => {\n e.preventDefault();\n setDragOver(false);\n onFilesAdded?.(Array.from(e.dataTransfer.files));\n }}\n >\n <StyledTextWrapper\n item={{ grow: 1 }}\n container={{ justify: 'center', alignItems: 'center' }}\n status={status}\n dragOver={dragOver}\n >\n <Text variant='secondary'>\n {t('file_upload_text_main', [\n t(multiple ? 'file_upload_text_multiple' : 'file_upload_text_one')\n ])}\n </Text>\n </StyledTextWrapper>\n <StyledIconWrapper container={{ justify: 'center', alignItems: 'center' }}>\n <Icon name='paper-clip' />\n </StyledIconWrapper>\n </Flex>\n </StyledFileInput>\n );\n\n const fileItemList = hideFileInput ? (\n <StyledSingleFileWrapper\n data-testid={testIds.files}\n ref={element => {\n if (element) fileItemListRef.current = element;\n }}\n >\n <FileItem {...files[0]} />\n </StyledSingleFileWrapper>\n ) : (\n <FileList\n type='item'\n items={files ?? []}\n data-testid={testIds.files}\n ref={element => {\n if (element) fileItemListRef.current = element;\n }}\n />\n );\n\n const prevFiles = usePrevious(files);\n useEffect(() => {\n if (\n !multiple &&\n prevFiles?.length === 0 &&\n files?.length === 1 &&\n fileItemListRef.current &&\n isInputActiveElement\n ) {\n getFocusables(fileItemListRef.current)[0]?.focus();\n }\n\n if (prevFiles?.length === 1 && files?.length === 0 && activeElementInList) {\n inputRef.current?.focus();\n }\n }, [files]);\n\n const renderElement = hideFileInput ? fileItemList : fileInput;\n\n return (\n <Grid container={{ rowGap: hideFileInput ? undefined : 1 }}>\n {label ? (\n <FormField\n testId={testIds}\n label={label}\n labelHidden={labelHidden}\n id={id}\n info={info}\n required={required}\n disabled={!hideFileInput && disabled}\n status={status}\n additionalInfo={additionalInfo}\n >\n {renderElement}\n </FormField>\n ) : (\n renderElement\n )}\n {!hideFileInput && fileItemList}\n </Grid>\n );\n});\n\nexport default withTestIds(FileInput, getFileInputTestIds);\n"]}
1
+ {"version":3,"file":"FileInput.js","sourceRoot":"","sources":["../../../src/components/File/FileInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAGtF,OAAO,EAAE,QAAQ,EAAuC,MAAM,yBAAyB,CAAC;AAGxF,OAAO,EACL,kBAAkB,EAClB,OAAO,EACP,MAAM,EACN,UAAU,EACV,WAAW,EACX,UAAU,EACV,eAAe,EACf,eAAe,EAChB,MAAM,aAAa,CAAC;AAErB,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,IAAI,EAAE,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,KAAK,aAAa,MAAM,+BAA+B,CAAC;AAC/D,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC3E,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,MAAM,MAAM,WAAW,CAAC;AAC/B,OAAO,KAAK,EAAE,EAAqB,MAAM,UAAU,CAAC;AAGpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,QAAQ,MAAM,YAAY,CAAC;AAClC,OAAO,QA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GAAG,CAAC;wBACjB,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC;wBACpB,CAAC,CAAC,CAAC,CAAC,uBAAuB,EAAE,CAAC,CAAC,CAAC,2BAA2B,CAAC,CAAC,CAAC,GACxD,CACX,IACI,CACR,CAAC;QAEF,OAAO,KAAK,CAAC,CAAC,CAAC,CACb,KAAC,eAAe,IACd,KAAK,EAAE,KAAK,EACZ,WAAW,EAAE,WAAW,EACxB,EAAE,EAAE,EAAE,EACN,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,cAAc,EAC9B,WAAW,kBAEV,MAAM,GACS,CACnB,CAAC,CAAC,CAAC,CACF,MAAM,CACP,CAAC;KACH;IAED,OAAO,KAAC,aAAa,OAAK,kBAAkB,EAAE,GAAG,EAAE,GAAG,GAAI,CAAC;AAC7D,CAAC,CAAC,CAAC;AAEH,eAAe,WAAW,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAAC","sourcesContent":["import { forwardRef, useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport type { FunctionComponent, Ref, ChangeEvent, PropsWithoutRef, DragEvent } from 'react';\n\nimport { MetaList, type FileListProps, type ModalProps } from '@pega/cosmos-react-core';\n\nimport type { BaseProps, ForwardProps, NoChildrenProp, OmitStrict, TestIdProp } from '../../types';\nimport {\n useConsolidatedRef,\n useI18n,\n useUID,\n useTestIds,\n usePrevious,\n useElement,\n useModalManager,\n useModalContext\n} from '../../hooks';\nimport type { FormControlProps } from '../FormControl';\nimport Flex from '../Flex';\nimport Text from '../Text';\nimport Icon, { registerIcon } from '../Icon';\nimport * as paperClipIcon from '../Icon/icons/paper-clip.icon';\nimport Grid from '../Grid';\nimport { getActiveElement, getFocusables, withTestIds } from '../../utils';\nimport Tooltip from '../Tooltip';\nimport Button from '../Button';\nimport Modal, { type ModalMethods } from '../Modal';\n\nimport type { FileItemProps } from './FileItem';\nimport { getFileInputTestIds } from './File.test-ids';\nimport FileList from './FileList';\nimport FileItem from './FileItem';\nimport {\n StyledBareButton,\n StyledDropZone,\n StyledFileInput,\n StyledIconWrapper,\n StyledAttachedFileCount,\n StyledSingleFileWrapper,\n StyledUploadStatus,\n StyledFlex,\n StyledFormField,\n StyledFileInputControl\n} from './FileInput.styles';\n\nregisterIcon(paperClipIcon);\n\n/** Props to be used when rendering compact variant for multiple FileInput. */\ninterface MultiAttachCompactProps {\n /** Modal props */\n modal?: Pick<ModalProps, 'onBeforeOpen'> & {\n /** Callback for cancel button */\n onCancel: ({ close }: { close: () => void }) => void;\n /** Callback for submit button */\n onSubmit: ({ close }: { close: () => void }) => void;\n /** If true renders loading indicator inside Modal. */\n loading?: boolean;\n };\n /** Conveys the number of files attached */\n count?: number;\n}\n\ninterface ComponentProps\n extends Pick<BaseFileInputProps, 'compact' | 'multiple' | 'status'>,\n Pick<MultiAttachCompactProps, 'count'> {\n dragOver?: boolean;\n}\n\ninterface BaseFileInputProps\n extends BaseProps,\n NoChildrenProp,\n TestIdProp,\n Pick<FileItemProps, 'previewFromActions'>,\n Pick<FileListProps, 'onDownloadAll'> {\n /** Called when files are added either via the input or drop zone. */\n onFilesAdded?: (files: File[]) => void;\n /**\n * Allow multiple files to be selected from the OS specific file browser.\n * NOTE: This does not restrict multiple files from being added via drag and drop.\n * Restrict multi file drag and drop via onFilesAdded and custom info message.\n * @default false\n */\n multiple?: boolean;\n /**\n * Renders compact variant.\n * @default false\n */\n compact?: boolean;\n /** An array of files that have been uploaded. */\n files?: OmitStrict<FileItemProps, 'previewFromActions'>[];\n /**\n * Specify allowed file types.\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/accept}\n */\n accept?: string | string[];\n /**\n * Sets DOM id for the control and associates label element via 'for' attribute.\n * If an id is not pass, a random id will be generated for any render.\n */\n id?: FormControlProps['id'];\n /** Set visual state based on a validation state. */\n status?: FormControlProps['status'];\n /** Pass a string or a fragment with an Icon and string. */\n label?: FormControlProps['label'];\n /** Visually hides the label region. */\n labelHidden?: FormControlProps['labelHidden'];\n /** It is recommended to pass a simple string to offer guidance. Text will be styled based on status prop. */\n info?: FormControlProps['info'];\n /** Indicate if the field is required. The browser defaults to false. */\n required?: FormControlProps['required'];\n /** Disable the control. The browser defaults to false. */\n disabled?: FormControlProps['disabled'];\n /** Sets html name attribute for the underlying control. Useful for mapping to a data field. */\n name?: FormControlProps['name'];\n /** Pass a heading and content to show additional information on the field. */\n additionalInfo?: FormControlProps['additionalInfo'];\n /** Ref for the input element within the component's dom structure. */\n ref?: Ref<HTMLInputElement>;\n}\n\nexport interface FileInputProps extends BaseFileInputProps, MultiAttachCompactProps {}\n\nconst Component: FunctionComponent<ComponentProps> = props => {\n const { compact, multiple, status, count, dragOver = false } = props;\n const t = useI18n();\n\n const attachedFileCount =\n multiple && count ? (\n <StyledAttachedFileCount>{t('number_of_items', [count], { count })}</StyledAttachedFileCount>\n ) : undefined;\n\n return (\n <>\n <StyledUploadStatus\n item={{ grow: 1 }}\n container={{ justify: compact && multiple ? 'start' : 'center', alignItems: 'center' }}\n status={status}\n dragOver={dragOver}\n >\n <Text variant='secondary'>\n {compact\n ? attachedFileCount\n : t('file_upload_text_main', [\n t(multiple ? 'file_upload_text_multiple' : 'file_upload_text_one')\n ])}\n </Text>\n </StyledUploadStatus>\n\n <StyledIconWrapper container={{ justify: 'center', alignItems: 'center' }}>\n <Icon name='paper-clip' />\n </StyledIconWrapper>\n </>\n );\n};\n\nconst BaseFileInput: FunctionComponent<BaseFileInputProps & ForwardProps> = forwardRef(\n function FileInput(props: PropsWithoutRef<BaseFileInputProps>, ref: BaseFileInputProps['ref']) {\n const uid = useUID();\n const {\n testId,\n id = uid,\n label,\n labelHidden,\n info,\n required = false,\n disabled = false,\n files,\n onDownloadAll,\n onFilesAdded,\n multiple = false,\n status,\n additionalInfo,\n accept,\n compact = false,\n previewFromActions = false,\n ...restProps\n } = props;\n\n const testIds = useTestIds(testId, getFileInputTestIds);\n const [target, setTarget] = useElement<HTMLElement>();\n\n const inputRef = useConsolidatedRef(ref);\n const fileItemListRef = useRef<HTMLDivElement>();\n const activeElement = getActiveElement();\n const activeElementInList = fileItemListRef.current?.contains(activeElement);\n const isInputActiveElement = activeElement === inputRef.current;\n const compactWithSingleAttach = compact && !multiple;\n\n const onChange = useCallback(\n (e: ChangeEvent<HTMLInputElement>) => {\n if (e.target.files) {\n onFilesAdded?.(Array.from(e.target.files));\n }\n /**\n * WHY are we doing this?\n * We are not working with the \"value\" prop of the input but rather the File instances that are created.\n * The consumer of this component should manage an array or File(s) and allow for a user to remove a selected file.\n * Since we can not modify the input value of files for browser security reasons,\n * and since setting the files property is less than ideal, we reset/toggle the input to a fresh state after a render.\n * This enables onChange to fire even if the user had just previously selected a file, removed it, and selected it again.\n */\n if (inputRef.current) inputRef.current.value = '';\n },\n [onFilesAdded]\n );\n\n const t = useI18n();\n const [dragOver, setDragOver] = useState(false);\n const hideFileInput = !multiple && files && files.length > 0;\n\n const fileInput = (\n <StyledFileInput>\n <input\n data-testid={testIds.control}\n {...restProps}\n ref={inputRef}\n type='file'\n id={id}\n required={required}\n disabled={disabled}\n onChange={onChange}\n onFocus={() => {\n if (target) {\n target.dispatchEvent(new Event('focusin'));\n }\n }}\n onBlur={() => {\n if (target) {\n target.dispatchEvent(new Event('focusout'));\n }\n }}\n multiple={multiple}\n accept={Array.isArray(accept) ? accept.join(',') : accept}\n />\n <Flex\n container\n as={StyledDropZone}\n onClick={() => {\n inputRef.current?.focus();\n inputRef.current?.click();\n }}\n {...(!disabled\n ? {\n onDragOver: (e: DragEvent<HTMLDivElement>) => {\n e.preventDefault();\n },\n onDragEnter: () => setDragOver(true),\n onDragLeave: () => setDragOver(false),\n onDrop: (e: DragEvent<HTMLDivElement>) => {\n e.preventDefault();\n setDragOver(false);\n onFilesAdded?.(Array.from(e.dataTransfer.files));\n }\n }\n : undefined)}\n compactMode={compact}\n ref={setTarget}\n >\n <Component compact={compact} multiple={multiple} status={status} dragOver={dragOver} />\n </Flex>\n {compactWithSingleAttach && target && (\n <Tooltip target={target} describeTarget>\n {t('file_upload_text_main', [t('file_upload_text_one')])}\n </Tooltip>\n )}\n </StyledFileInput>\n );\n\n const fileItemList = hideFileInput ? (\n <StyledSingleFileWrapper\n data-testid={testIds.files}\n compact={compact}\n ref={element => {\n if (element) fileItemListRef.current = element;\n }}\n >\n <FileItem\n {...files[0]}\n compact={compact}\n previewFromActions={compactWithSingleAttach && previewFromActions}\n />\n </StyledSingleFileWrapper>\n ) : (\n <FileList\n type='item'\n items={files ?? []}\n data-testid={testIds.files}\n ref={element => {\n if (element) fileItemListRef.current = element;\n }}\n />\n );\n\n const prevFiles = usePrevious(files);\n useEffect(() => {\n if (\n !multiple &&\n prevFiles?.length === 0 &&\n files?.length === 1 &&\n fileItemListRef.current &&\n isInputActiveElement\n ) {\n getFocusables(fileItemListRef.current)[0]?.focus();\n }\n\n if (prevFiles?.length === 1 && files?.length === 0 && activeElementInList) {\n inputRef.current?.focus();\n }\n }, [files]);\n\n const renderElement = hideFileInput ? fileItemList : fileInput;\n\n const fileInputInfoActions = useMemo(() => {\n if (info && !onDownloadAll) {\n return info;\n }\n\n const downloadAllButton = (\n <Button onClick={onDownloadAll} variant='link'>\n {t('download_all')}\n </Button>\n );\n\n if (onDownloadAll && !info && files && files.length > 1 && multiple) {\n return downloadAllButton;\n }\n\n if (info && onDownloadAll) {\n if (files && files.length > 1 && multiple) {\n return <MetaList items={[info, downloadAllButton]} />;\n }\n return info;\n }\n }, [info, onDownloadAll]);\n\n return (\n <Grid\n container={{ rowGap: hideFileInput ? undefined : 1 }}\n as={StyledFileInputControl}\n status={status}\n >\n {label ? (\n <StyledFormField\n testId={testIds}\n label={label}\n labelHidden={labelHidden}\n id={id}\n info={fileInputInfoActions}\n required={required}\n disabled={!hideFileInput && disabled}\n status={status}\n additionalInfo={additionalInfo}\n compactMode={compactWithSingleAttach}\n >\n {renderElement}\n </StyledFormField>\n ) : (\n renderElement\n )}\n {multiple && !compact && files && files.length > 0 && fileItemList}\n </Grid>\n );\n }\n);\n\nconst AttachFilesModal: FunctionComponent<\n {\n modalContent?: JSX.Element;\n } & Pick<MultiAttachCompactProps, 'modal'>\n> = ({ modalContent, modal }) => {\n const t = useI18n();\n const { dismiss } = useModalContext();\n\n const formActions = (\n <>\n <Button\n disabled={modal?.loading}\n onClick={() => {\n if (modal?.onCancel) modal.onCancel({ close: dismiss });\n }}\n >\n {t('cancel')}\n </Button>\n <Button\n disabled={modal?.loading}\n type='submit'\n variant='primary'\n onClick={() => {\n if (modal?.onSubmit) modal.onSubmit({ close: dismiss });\n }}\n >\n {t('submit')}\n </Button>\n </>\n );\n\n return (\n <Modal\n progress={modal?.loading}\n heading={t('attach_files')}\n actions={formActions}\n onBeforeOpen={modal?.onBeforeOpen}\n >\n {modalContent}\n </Modal>\n );\n};\n\nconst FileInput: FunctionComponent<FileInputProps & ForwardProps> = forwardRef(function FileInput(\n props: PropsWithoutRef<FileInputProps>,\n ref: FileInputProps['ref']\n) {\n const uid = useUID();\n const { modal, count, ...baseFileInputProps } = props;\n\n const {\n id = uid,\n label,\n labelHidden,\n info,\n required = false,\n disabled = false,\n onFilesAdded,\n multiple = false,\n status,\n additionalInfo,\n compact = false\n } = baseFileInputProps;\n\n const t = useI18n();\n const [dragOver, setDragOver] = useState(false);\n const [buttonEl, setButtonEl] = useElement<HTMLButtonElement>();\n const { create } = useModalManager();\n const modalMethods = useRef<ModalMethods>();\n\n let modalContent: JSX.Element | undefined;\n\n if (compact && multiple) {\n modalContent = (\n <BaseFileInput\n {...baseFileInputProps}\n multiple\n compact={false}\n labelHidden={false}\n ref={ref}\n />\n );\n }\n\n const modalProps = {\n modal,\n modalContent\n };\n\n useEffect(() => {\n if (compact && multiple && modal) {\n modalMethods.current?.update({\n modal,\n modalContent\n });\n }\n }, [compact, multiple, modal, modalProps]);\n\n useEffect(() => {\n return () => {\n if (modalMethods.current) {\n modalMethods.current?.dismiss();\n modalMethods.current?.unmount();\n }\n };\n }, []);\n\n if (compact && multiple) {\n const render = (\n <Flex container>\n <StyledBareButton\n id={id}\n onClick={() => {\n modalMethods.current = create(\n AttachFilesModal,\n { ...modalProps },\n { dismissible: false }\n );\n }}\n aria-label={\n count && count > 0\n ? `${t('attach_review')} ${t('number_of_items', [count], { count })}`\n : undefined\n }\n disabled={disabled}\n {...(!disabled\n ? {\n onDragOver: (e: DragEvent<HTMLDivElement>) => {\n e.preventDefault();\n },\n onDragEnter: () => setDragOver(true),\n onDragLeave: () => setDragOver(false),\n onDrop: (e: DragEvent<HTMLDivElement>) => {\n e.preventDefault();\n setDragOver(false);\n onFilesAdded?.(Array.from(e.dataTransfer.files));\n if (buttonEl) buttonEl.click();\n }\n }\n : undefined)}\n ref={setButtonEl}\n >\n <StyledFlex container>\n <Component\n compact={compact}\n multiple={multiple}\n status={status}\n count={count}\n dragOver={dragOver}\n />\n </StyledFlex>\n </StyledBareButton>\n {buttonEl && (\n <Tooltip target={buttonEl} describeTarget={count === 0}>\n {count && count > 0\n ? t('attach_review')\n : t('file_upload_text_main', [t('file_upload_text_multiple')])}\n </Tooltip>\n )}\n </Flex>\n );\n\n return label ? (\n <StyledFormField\n label={label}\n labelHidden={labelHidden}\n id={id}\n info={info}\n required={required}\n disabled={disabled}\n status={status}\n additionalInfo={additionalInfo}\n compactMode\n >\n {render}\n </StyledFormField>\n ) : (\n render\n );\n }\n\n return <BaseFileInput {...baseFileInputProps} ref={ref} />;\n});\n\nexport default withTestIds(FileInput, getFileInputTestIds);\n"]}