@pega/cosmos-react-core 7.0.0-build.22.1 → 7.0.0-build.22.2

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 (141) hide show
  1. package/lib/components/Actions/Actions.d.ts +1 -1
  2. package/lib/components/Actions/Actions.d.ts.map +1 -1
  3. package/lib/components/Actions/Actions.js +3 -3
  4. package/lib/components/Actions/Actions.js.map +1 -1
  5. package/lib/components/AppShell/AppShell.styles.d.ts +1 -1
  6. package/lib/components/Avatar/Avatar.d.ts +2 -2
  7. package/lib/components/Avatar/Avatar.test-ids.d.ts +1 -1
  8. package/lib/components/Avatar/Avatar.test-ids.d.ts.map +1 -1
  9. package/lib/components/Backdrop/Backdrop.d.ts +1 -1
  10. package/lib/components/Backdrop/Backdrop.test-ids.d.ts +1 -1
  11. package/lib/components/Backdrop/Backdrop.test-ids.d.ts.map +1 -1
  12. package/lib/components/Badges/Alert.d.ts +1 -1
  13. package/lib/components/Badges/Badges.test-ids.d.ts +6 -6
  14. package/lib/components/Badges/Badges.test-ids.d.ts.map +1 -1
  15. package/lib/components/Badges/Count.d.ts +1 -1
  16. package/lib/components/Badges/Keyboard.d.ts +1 -1
  17. package/lib/components/Badges/Selection.d.ts +1 -1
  18. package/lib/components/Badges/Status.d.ts +1 -1
  19. package/lib/components/Badges/Tag.d.ts +1 -1
  20. package/lib/components/Banner/Banner.d.ts +1 -1
  21. package/lib/components/Banner/Banner.test-ids.d.ts +1 -1
  22. package/lib/components/Banner/Banner.test-ids.d.ts.map +1 -1
  23. package/lib/components/ColorPicker/ColorPicker.d.ts +1 -1
  24. package/lib/components/ColorPicker/ColorPicker.test-ids.d.ts +1 -1
  25. package/lib/components/ColorPicker/ColorPicker.test-ids.d.ts.map +1 -1
  26. package/lib/components/ComboBox/ComboBox.d.ts +1 -1
  27. package/lib/components/ComboBox/ComboxBox.test-ids.d.ts +1 -1
  28. package/lib/components/ComboBox/ComboxBox.test-ids.d.ts.map +1 -1
  29. package/lib/components/CompositeInput/CompositeInput.d.ts +1 -1
  30. package/lib/components/CompositeInput/CompositeInput.test-ids.d.ts +1 -1
  31. package/lib/components/CompositeInput/CompositeInput.test-ids.d.ts.map +1 -1
  32. package/lib/components/Currency/Currency.test-ids.d.ts +1 -1
  33. package/lib/components/Currency/Currency.test-ids.d.ts.map +1 -1
  34. package/lib/components/Currency/CurrencyInput.d.ts +1 -1
  35. package/lib/components/DateTime/DateTime.test-ids.d.ts +11 -11
  36. package/lib/components/DateTime/DateTime.test-ids.d.ts.map +1 -1
  37. package/lib/components/DateTime/Input/DateInput.d.ts +1 -1
  38. package/lib/components/DateTime/Input/DateRangeInput.d.ts +1 -1
  39. package/lib/components/DateTime/Input/DateTimeInput.d.ts +1 -1
  40. package/lib/components/DateTime/Input/DayOfWeekInput.d.ts +1 -1
  41. package/lib/components/DateTime/Input/Duration/DurationInput.d.ts +1 -1
  42. package/lib/components/DateTime/Input/MonthInput.d.ts +1 -1
  43. package/lib/components/DateTime/Input/QuarterInput.d.ts +1 -1
  44. package/lib/components/DateTime/Input/TimeInput.d.ts +1 -1
  45. package/lib/components/DateTime/Input/TimeRangeInput.d.ts +1 -1
  46. package/lib/components/DateTime/Input/WeekInput.d.ts +1 -1
  47. package/lib/components/DateTime/Picker/DatePicker.d.ts +1 -1
  48. package/lib/components/FieldValueList/FieldValueList.d.ts +2 -2
  49. package/lib/components/FieldValueList/FieldValueList.test-ids.d.ts +2 -2
  50. package/lib/components/FieldValueList/FieldValueList.test-ids.d.ts.map +1 -1
  51. package/lib/components/File/File.test-ids.d.ts +1 -1
  52. package/lib/components/File/File.test-ids.d.ts.map +1 -1
  53. package/lib/components/File/FileInput.d.ts +1 -1
  54. package/lib/components/File/FileInput.d.ts.map +1 -1
  55. package/lib/components/File/FileInput.js +22 -10
  56. package/lib/components/File/FileInput.js.map +1 -1
  57. package/lib/components/File/FileItem.d.ts +5 -0
  58. package/lib/components/File/FileItem.d.ts.map +1 -1
  59. package/lib/components/File/FileItem.js +14 -7
  60. package/lib/components/File/FileItem.js.map +1 -1
  61. package/lib/components/File/FileList.d.ts +2 -0
  62. package/lib/components/File/FileList.d.ts.map +1 -1
  63. package/lib/components/File/FileList.js +2 -2
  64. package/lib/components/File/FileList.js.map +1 -1
  65. package/lib/components/Form/Form.d.ts +1 -1
  66. package/lib/components/Form/Form.test-ids.d.ts +1 -1
  67. package/lib/components/Form/Form.test-ids.d.ts.map +1 -1
  68. package/lib/components/FormField/FormField.d.ts +1 -1
  69. package/lib/components/FormField/FormField.test-ids.d.ts +1 -1
  70. package/lib/components/FormField/FormField.test-ids.d.ts.map +1 -1
  71. package/lib/components/HTML/HTML.d.ts +1 -1
  72. package/lib/components/HTML/HTML.test-ids.d.ts +1 -1
  73. package/lib/components/HTML/HTML.test-ids.d.ts.map +1 -1
  74. package/lib/components/Input/Input.d.ts +1 -1
  75. package/lib/components/Input/Input.test-ids.d.ts +1 -1
  76. package/lib/components/Input/Input.test-ids.d.ts.map +1 -1
  77. package/lib/components/Lightbox/Lightbox.d.ts +1 -1
  78. package/lib/components/Lightbox/Lightbox.styles.d.ts +1 -1
  79. package/lib/components/Lightbox/Lightbox.test-ids.d.ts +1 -1
  80. package/lib/components/Lightbox/Lightbox.test-ids.d.ts.map +1 -1
  81. package/lib/components/Link/Link.d.ts +1 -1
  82. package/lib/components/Link/Link.test-ids.d.ts +1 -1
  83. package/lib/components/Link/Link.test-ids.d.ts.map +1 -1
  84. package/lib/components/ListToolbar/ListToolbar.d.ts +1 -1
  85. package/lib/components/ListToolbar/ListToolbar.test-ids.d.ts +1 -1
  86. package/lib/components/ListToolbar/ListToolbar.test-ids.d.ts.map +1 -1
  87. package/lib/components/Location/Location.test-ids.d.ts +1 -1
  88. package/lib/components/Location/Location.test-ids.d.ts.map +1 -1
  89. package/lib/components/Location/LocationInput.d.ts +1 -1
  90. package/lib/components/Location/LocationView.d.ts +1 -1
  91. package/lib/components/Menu/Menu.d.ts +1 -1
  92. package/lib/components/Menu/Menu.test-ids.d.ts +2 -2
  93. package/lib/components/Menu/Menu.test-ids.d.ts.map +1 -1
  94. package/lib/components/Menu/MenuItem.d.ts +1 -1
  95. package/lib/components/MenuButton/MenuButton.d.ts +1 -1
  96. package/lib/components/MenuButton/MenuButton.test-ids.d.ts +1 -1
  97. package/lib/components/MenuButton/MenuButton.test-ids.d.ts.map +1 -1
  98. package/lib/components/MetaList/MetaList.d.ts +1 -1
  99. package/lib/components/MetaList/MetaList.test-ids.d.ts +1 -1
  100. package/lib/components/MetaList/MetaList.test-ids.d.ts.map +1 -1
  101. package/lib/components/Number/Number.test-ids.d.ts +2 -2
  102. package/lib/components/Number/Number.test-ids.d.ts.map +1 -1
  103. package/lib/components/Number/NumberInput.d.ts +1 -1
  104. package/lib/components/Number/NumberRangeInput.d.ts +1 -1
  105. package/lib/components/Phone/Phone.test-ids.d.ts +1 -1
  106. package/lib/components/Phone/Phone.test-ids.d.ts.map +1 -1
  107. package/lib/components/Phone/PhoneInput.d.ts +1 -1
  108. package/lib/components/Progress/Progress.styles.d.ts +1 -1
  109. package/lib/components/SearchInput/SearchInput.styles.d.ts +2 -2
  110. package/lib/components/Select/Select.d.ts +1 -1
  111. package/lib/components/Select/Select.test-ids.d.ts +1 -1
  112. package/lib/components/Select/Select.test-ids.d.ts.map +1 -1
  113. package/lib/components/Slider/Slider.d.ts +1 -1
  114. package/lib/components/Slider/Slider.test-ids.d.ts +1 -1
  115. package/lib/components/Slider/Slider.test-ids.d.ts.map +1 -1
  116. package/lib/components/SummaryItem/SummaryItem.d.ts +1 -1
  117. package/lib/components/SummaryItem/SummaryItem.test-ids.d.ts +1 -1
  118. package/lib/components/SummaryItem/SummaryItem.test-ids.d.ts.map +1 -1
  119. package/lib/components/Tabs/Tabs.styles.d.ts +1 -1
  120. package/lib/components/TextArea/TextArea.d.ts +1 -1
  121. package/lib/components/TextArea/TextArea.test-ids.d.ts +1 -1
  122. package/lib/components/TextArea/TextArea.test-ids.d.ts.map +1 -1
  123. package/lib/components/Toaster/Toaster.d.ts +1 -1
  124. package/lib/components/Toaster/Toaster.test-ids.d.ts +1 -1
  125. package/lib/components/Toaster/Toaster.test-ids.d.ts.map +1 -1
  126. package/lib/components/Tooltip/Tooltip.d.ts +1 -1
  127. package/lib/components/Tooltip/Tooltip.test-ids.d.ts +1 -1
  128. package/lib/components/Tooltip/Tooltip.test-ids.d.ts.map +1 -1
  129. package/lib/components/Tree/StandardTree.styles.d.ts +1 -1
  130. package/lib/components/Tree/Tree.d.ts +1 -1
  131. package/lib/components/Tree/Tree.test-ids.d.ts +2 -2
  132. package/lib/components/Tree/Tree.test-ids.d.ts.map +1 -1
  133. package/lib/hooks/useTestIds.d.ts +1 -1
  134. package/lib/hooks/useTestIds.d.ts.map +1 -1
  135. package/lib/hooks/useTestIds.js +1 -1
  136. package/lib/hooks/useTestIds.js.map +1 -1
  137. package/lib/types/types.d.ts +1 -1
  138. package/lib/types/types.d.ts.map +1 -1
  139. package/lib/types/types.js.map +1 -1
  140. package/lib/utils/withTestIds.d.ts +1 -1
  141. package/package.json +1 -1
@@ -97,6 +97,7 @@ const FileInput = forwardRef(function FileInput(props, ref) {
97
97
  const fileItemListRef = useRef();
98
98
  const activeElement = getActiveElement();
99
99
  const activeElementInList = fileItemListRef.current?.contains(activeElement);
100
+ const isInputActiveElement = activeElement === inputRef.current;
100
101
  const onChange = useCallback((e) => {
101
102
  if (e.target.files) {
102
103
  onFilesAdded?.(Array.from(e.target.files));
@@ -118,25 +119,36 @@ const FileInput = forwardRef(function FileInput(props, ref) {
118
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: () => {
119
120
  inputRef.current?.focus();
120
121
  inputRef.current?.click();
121
- }, onDragOver: (e) => {
122
- e.preventDefault();
123
- }, onDragEnter: () => setDragOver(true), onDragLeave: () => setDragOver(false), onDrop: (e) => {
124
- e.preventDefault();
125
- setDragOver(false);
126
- onFilesAdded?.(Array.from(e.dataTransfer.files));
127
- }, 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', [
122
+ }, ...(!disabled
123
+ ? {
124
+ onDragOver: (e) => {
125
+ e.preventDefault();
126
+ },
127
+ onDragEnter: () => setDragOver(true),
128
+ onDragLeave: () => setDragOver(false),
129
+ onDrop: (e) => {
130
+ e.preventDefault();
131
+ setDragOver(false);
132
+ onFilesAdded?.(Array.from(e.dataTransfer.files));
133
+ }
134
+ }
135
+ : undefined), 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', [
128
136
  t(multiple ? 'file_upload_text_multiple' : 'file_upload_text_one')
129
137
  ]) }) }), _jsx(StyledIconWrapper, { container: { justify: 'center', alignItems: 'center' }, children: _jsx(Icon, { name: 'paper-clip' }) })] })] }));
130
138
  const fileItemList = hideFileInput ? (_jsx(StyledSingleFileWrapper, { "data-testid": testIds.files, ref: element => {
131
139
  if (element)
132
140
  fileItemListRef.current = element;
133
- }, children: _jsx(FileItem, { ...files[0] }) })) : (_jsx(FileList, { type: 'item', items: files ?? [], "data-testid": testIds.files, ref: element => {
141
+ }, children: _jsx(FileItem, { ...files[0], disabled: disabled }) })) : (_jsx(FileList, { type: 'item', disabled: disabled, items: files ?? [], "data-testid": testIds.files, ref: element => {
134
142
  if (element)
135
143
  fileItemListRef.current = element;
136
144
  } }));
137
145
  const prevFiles = usePrevious(files);
138
146
  useEffect(() => {
139
- if (!multiple && prevFiles?.length === 0 && files?.length === 1 && fileItemListRef.current) {
147
+ if (!multiple &&
148
+ prevFiles?.length === 0 &&
149
+ files?.length === 1 &&
150
+ fileItemListRef.current &&
151
+ isInputActiveElement) {
140
152
  getFocusables(fileItemListRef.current)[0]?.focus();
141
153
  }
142
154
  if (prevFiles?.length === 1 && files?.length === 0 && activeElementInList) {
@@ -144,7 +156,7 @@ const FileInput = forwardRef(function FileInput(props, ref) {
144
156
  }
145
157
  }, [files]);
146
158
  const renderElement = hideFileInput ? fileItemList : fileInput;
147
- 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] }));
159
+ 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: disabled, status: status, additionalInfo: additionalInfo, children: renderElement })) : (renderElement), !hideFileInput && fileItemList] }));
148
160
  });
149
161
  export default withTestIds(FileInput, getFileInputTestIds);
150
162
  //# sourceMappingURL=FileInput.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"FileInput.js","sourceRoot":"","sources":["../../../src/components/File/FileInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE7E,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AASxC,OAAO,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC3F,OAAO,WAAW,MAAM,gBAAgB,CAAC;AAEzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,I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,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC;IAE/D,OAAO,CACL,MAAC,IAAI,IAAC,SAAS,EAAE,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,aACvD,KAAK,CAAC,CAAC,CAAC,CACP,KAAC,SAAS,IACR,MAAM,EAAE,OAAO,EACf,KAAK,EAAE,KAAK,EACZ,WAAW,EAAE,WAAW,EACxB,EAAE,EAAE,EAAE,EACN,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,CAAC,aAAa,IAAI,QAAQ,EACpC,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,cAAc,YAE7B,aAAa,GACJ,CACb,CAAC,CAAC,CAAC,CACF,aAAa,CACd,EACA,CAAC,aAAa,IAAI,YAAY,IAC1B,CACR,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,eAAe,WAAW,CAAC,SAAS,EAAE,mBAAmB,CAAC,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\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 (!multiple && prevFiles?.length === 0 && files?.length === 1 && fileItemListRef.current) {\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,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE7E,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AASxC,OAAO,EAAE,kBAAkB,EA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S,EAAE,MAAM,KAAK,CAAC;YACvB,KAAK,EAAE,MAAM,KAAK,CAAC;YACnB,eAAe,CAAC,OAAO;YACvB,oBAAoB,EACpB;YACA,aAAa,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC;SACpD;QAED,IAAI,SAAS,EAAE,MAAM,KAAK,CAAC,IAAI,KAAK,EAAE,MAAM,KAAK,CAAC,IAAI,mBAAmB,EAAE;YACzE,QAAQ,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;SAC3B;IACH,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEZ,MAAM,aAAa,GAAG,aAAa,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC;IAE/D,OAAO,CACL,MAAC,IAAI,IAAC,SAAS,EAAE,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,aACvD,KAAK,CAAC,CAAC,CAAC,CACP,KAAC,SAAS,IACR,MAAM,EAAE,OAAO,EACf,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,YAE7B,aAAa,GACJ,CACb,CAAC,CAAC,CAAC,CACF,aAAa,CACd,EACA,CAAC,aAAa,IAAI,YAAY,IAC1B,CACR,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,eAAe,WAAW,CAAC,SAAS,EAAE,mBAAmB,CAAC,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 {...(!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 >\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]} disabled={disabled} />\n </StyledSingleFileWrapper>\n ) : (\n <FileList\n type='item'\n disabled={disabled}\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={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"]}
@@ -34,6 +34,11 @@ export interface FileItemProps extends BaseProps {
34
34
  progress?: number;
35
35
  /** Set if there is an error uploading the file. Applies error styling to the meta string passed. */
36
36
  error?: string;
37
+ /**
38
+ * Sets disabled state.
39
+ * @default false
40
+ */
41
+ disabled?: boolean;
37
42
  /** Ref for the wrapping element. */
38
43
  ref?: Ref<HTMLDivElement>;
39
44
  }
@@ -1 +1 @@
1
- {"version":3,"file":"FileItem.d.ts","sourceRoot":"","sources":["../../../src/components/File/FileItem.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAmB,EAAE,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAYtD,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAU,MAAM,aAAa,CAAC;AAcnE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAIpD,MAAM,WAAW,aAAc,SAAQ,SAAS;IAC9C,0BAA0B;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,wBAAwB;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,oIAAoI;IACpI,SAAS,CAAC,EAAE,eAAe,CAAC,WAAW,CAAC,CAAC;IACzC,yCAAyC;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,8IAA8I;IAC9I,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,aAAa,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC;IAC7C,yGAAyG;IACzG,MAAM,CAAC,EAAE,CAAC,EAAE,EAAE,aAAa,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC;IAC3C,yFAAyF;IACzF,SAAS,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E,aAAa,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC;IAC7C,yGAAyG;IACzG,MAAM,CAAC,EAAE,CAAC,EAAE,EAAE,aAAa,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC;IAC3C,yFAAyF;IACzF,SAAS,CAAC,EAAE,CAAC,EAAE,EAAE,aAAa,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC;IAC9C;;;OAGG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,0IAA0I;IAC1I,UAAU,CAAC,EAAE,CAAC,EAAE,EAAE,aAAa,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC;IAC/C,yGAAyG;IACzG,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,aAAa,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC;IAC7C,gIAAgI;IAChI,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oGAAoG;IACpG,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,oCAAoC;IACpC,GAAG,CAAC,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC;CAC3B;AAoID,QAAA,MAAM,QAAQ,EAAE,EAAE,CAAC,aAAa,GAAG,YAAY,CAuL7C,CAAC;AAEH,eAAe,QAAQ,CAAC"}
@@ -61,13 +61,13 @@ const StyledActionsWrapper = styled.div(({ meta }) => {
61
61
  `;
62
62
  });
63
63
  StyledActionsWrapper.defaultProps = defaultThemeProp;
64
- const StyledFileItem = styled.div(({ theme: { base: { palette, 'border-radius': borderRadius, spacing, 'hit-area': { compact } }, components }, compactMode }) => {
64
+ const StyledFileItem = styled.div(({ theme: { base: { palette, 'border-radius': borderRadius, spacing, 'hit-area': { compact }, 'disabled-opacity': disabledOpacity }, components: { input, 'form-control': { ':disabled': { 'background-color': disabledBackgroundColor, 'border-color': disabledBorderColor } } } }, compactMode, isDisabled }) => {
65
65
  return css `
66
66
  border-radius: calc(0.5 * ${borderRadius});
67
67
  border: 0.0625rem solid ${palette['border-line']};
68
68
  background-color: ${palette['primary-background']};
69
- height: ${components.input.height};
70
- min-width: calc(${components.input.height} + 12ch + 1.5 * ${spacing} + ${compact});
69
+ height: ${input.height};
70
+ min-width: calc(${input.height} + 12ch + 1.5 * ${spacing} + ${compact});
71
71
 
72
72
  ${compactMode &&
73
73
  css `
@@ -97,7 +97,7 @@ const StyledFileItem = styled.div(({ theme: { base: { palette, 'border-radius':
97
97
  border-end-start-radius: inherit;
98
98
  border-start-end-radius: 0;
99
99
  border-end-end-radius: 0;
100
- width: ${components.input.height};
100
+ width: ${input.height};
101
101
  flex-shrink: 0;
102
102
 
103
103
  ${compactMode &&
@@ -106,11 +106,18 @@ const StyledFileItem = styled.div(({ theme: { base: { palette, 'border-radius':
106
106
  width: ${compact};
107
107
  `}
108
108
  }
109
+
110
+ ${isDisabled &&
111
+ css `
112
+ background-color: ${disabledBackgroundColor};
113
+ border-color: ${disabledBorderColor};
114
+ opacity: ${disabledOpacity};
115
+ `}
109
116
  `;
110
117
  });
111
118
  StyledFileItem.defaultProps = defaultThemeProp;
112
119
  const FileItem = forwardRef(function FileItem(props, ref) {
113
- const { id, name, thumbnail, format, error, onCancel, onEdit, onPreview, onDownload, onDelete, progress, compact = false, previewFromActions = false, ...restProps } = props;
120
+ const { id, name, thumbnail, format, error, onCancel, onEdit, onPreview, onDownload, onDelete, progress, compact = false, previewFromActions = false, disabled = false, ...restProps } = props;
114
121
  const [thumbnailError, setThumbnailError] = useState(false);
115
122
  const [textTarget, setTextTarget] = useElement();
116
123
  const [metaTarget, setMetaTarget] = useElement();
@@ -181,9 +188,9 @@ const FileItem = forwardRef(function FileItem(props, ref) {
181
188
  alignItems: 'center',
182
189
  justify: 'start',
183
190
  gap: 1
184
- }, compactMode: compact, ref: itemRef, children: [visual, !previewFromActions && onPreview && !(error || uploading) ? (_jsxs(Button, { ...restProps, as: StyledPreviewTitle, variant: 'link', ref: setTextTarget, onClick: () => {
191
+ }, isDisabled: disabled, compactMode: compact, ref: itemRef, children: [visual, !previewFromActions && onPreview && !(error || uploading) ? (_jsxs(Button, { ...restProps, as: StyledPreviewTitle, variant: 'link', ref: setTextTarget, onClick: () => {
185
192
  onPreview(id);
186
- }, "aria-label": t('preview_file', [name]), children: [name, format === 'url' && _jsx(Icon, { name: 'open' })] })) : (_jsx(Text, { ...restProps, as: StyledTextTitle, ref: setTextTarget, children: name })), metaMessage && (_jsxs(_Fragment, { children: [_jsx(Text, { as: StyledMeta, variant: 'secondary', error: error && !uploading, ref: setMetaTarget, children: metaMessage }), metaTarget && (_jsx(Tooltip, { target: metaTarget, describeTarget: false, smart: true, children: metaMessage }))] })), (error || uploading) && onCancel && (_jsx(StyledActionsWrapper, { meta: !!metaMessage, children: _jsx(Button, { label: t('cancel'), "aria-label": `${t('cancel')} - ${contextualLabel}`, variant: 'simple', compact: true, icon: true, onClick: () => onCancel(id), children: _jsx(Icon, { name: 'times' }) }) })), !(error || uploading) && !!definedActions.length && (_jsx(StyledActionsWrapper, { meta: !!metaMessage, children: _jsx(Actions, { items: definedActions, compact: true, iconOnly: true, contextualLabel: name }) })), textTarget && (_jsx(Tooltip, { target: textTarget, smart: true, describeTarget: false, children: name }))] }));
193
+ }, "aria-label": t('preview_file', [name]), disabled: disabled, children: [name, format === 'url' && _jsx(Icon, { name: 'open' })] })) : (_jsx(Text, { ...restProps, as: StyledTextTitle, ref: setTextTarget, children: name })), metaMessage && (_jsxs(_Fragment, { children: [_jsx(Text, { as: StyledMeta, variant: 'secondary', error: error && !uploading, ref: setMetaTarget, children: metaMessage }), metaTarget && (_jsx(Tooltip, { target: metaTarget, describeTarget: false, smart: true, children: metaMessage }))] })), (error || uploading) && onCancel && (_jsx(StyledActionsWrapper, { meta: !!metaMessage, children: _jsx(Button, { label: t('cancel'), "aria-label": `${t('cancel')} - ${contextualLabel}`, variant: 'simple', compact: true, icon: true, onClick: () => onCancel(id), disabled: disabled, children: _jsx(Icon, { name: 'times' }) }) })), !(error || uploading) && !!definedActions.length && (_jsx(StyledActionsWrapper, { meta: !!metaMessage, children: _jsx(Actions, { items: definedActions, compact: true, iconOnly: true, contextualLabel: name, disabled: disabled }) })), textTarget && (_jsx(Tooltip, { target: textTarget, smart: true, describeTarget: false, children: name }))] }));
187
194
  });
188
195
  export default FileItem;
189
196
  //# sourceMappingURL=FileItem.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"FileItem.js","sourceRoot":"","sources":["../../../src/components/File/FileItem.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAExD,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,IAAI,EAAE,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,KAAK,QAAQ,MAAM,yBAAyB,CAAC;AACpD,OAAO,KAAK,SAAS,MAAM,0BAA0B,CAAC;AACtD,OAAO,KAAK,WAAW,MAAM,4BAA4B,CAAC;AAC1D,OAAO,KAAK,QAAQ,MAAM,2BAA2B,CAAC;AACtD,OAAO,KAAK,YAAY,MAAM,6BAA6B,CAAC;AAC5D,OAAO,KAAK,UAAU,MAAM,0BAA0B,CAAC;AACvD,OAAO,IAAI,EAAE,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,OAAO,MAAM,YAAY,CAAC;AAEjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,MAAM,EAAE,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACxF,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,QAAQ,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAA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M,EAAE,UAAU,EAAE,KAAK,QAAC,cAAc,EAAE,KAAK,YACrD,IAAI,GACG,CACX,IACI,CACR,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,eAAe,QAAQ,CAAC","sourcesContent":["import { forwardRef, useEffect, useState } from 'react';\nimport type { PropsWithoutRef, FC, Ref } from 'react';\nimport styled, { css } from 'styled-components';\n\nimport Icon, { registerIcon } from '../Icon';\nimport * as openIcon from '../Icon/icons/open.icon';\nimport * as timesIcon from '../Icon/icons/times.icon';\nimport * as previewIcon from '../Icon/icons/preview.icon';\nimport * as editIcon from '../Icon/icons/pencil.icon';\nimport * as downloadIcon from '../Icon/icons/download.icon';\nimport * as deleteIcon from '../Icon/icons/trash.icon';\nimport Text, { StyledText } from '../Text';\nimport Tooltip from '../Tooltip';\nimport type { ForwardProps, BaseProps, Action } from '../../types';\nimport { defaultThemeProp } from '../../theme';\nimport Button, { StyledButton } from '../Button';\nimport { useI18n, useElement, useConfiguration, useConsolidatedRef } from '../../hooks';\nimport Actions from '../Actions';\nimport Progress from '../Progress';\nimport { StyledProgressRing } from '../Progress/Progress.styles';\nimport { formatNumber } from '../Number';\nimport Flex from '../Flex';\nimport { StyledIconShape } from '../Icon/Icon';\nimport { getActiveElement, getFocusables } from '../../utils';\n\nimport { getKindFromMimeType, getMimeTypeFromFile } from './utils';\nimport FileVisual, { StyledFileVisual } from './FileVisual';\nimport type { FileVisualProps } from './FileVisual';\n\nregisterIcon(openIcon, timesIcon, previewIcon, editIcon, downloadIcon, deleteIcon);\n\nexport interface FileItemProps extends BaseProps {\n /** Unique id for item. */\n id: string;\n /** Name of the file. */\n name: string;\n /** A string to be used as an image src for a attachment thumbnail. Falls back to a provided icon or the default attachment icon. */\n thumbnail?: FileVisualProps['thumbnail'];\n /** File extension. Use 'url' for link */\n format?: string;\n /**\n * Used for a smaller sized FileItem.\n * @default false\n */\n compact?: boolean;\n /** When passed, will render a single icon button for yet to be or in progress uploads. Use this action to trigger xhr request termination. */\n onCancel?: (id: FileItemProps['id']) => void;\n /** When passed, will render a single icon button or within a MenuButton if other actions are defined. */\n onEdit?: (id: FileItemProps['id']) => void;\n /** When passed, will be called on click of the name. Passes file id as the parameter. */\n onPreview?: (id: FileItemProps['id']) => void;\n /**\n * Moves preview option to actions menu.\n * To be used only in compact mode of single file input when rendered in a table\n */\n previewFromActions?: boolean;\n /** When passed, will render a single icon button or within a MenuButton if other actions are defined. Passes file id as the parameter. */\n onDownload?: (id: FileItemProps['id']) => void;\n /** When passed, will render a single icon button or within a MenuButton if other actions are defined. */\n onDelete?: (id: FileItemProps['id']) => void;\n /** If the attachment is in an upload state, pass progress as a number between 0-100 representing the percentage of progress. */\n progress?: number;\n /** Set if there is an error uploading the file. Applies error styling to the meta string passed. */\n error?: string;\n /** Ref for the wrapping element. */\n ref?: Ref<HTMLDivElement>;\n}\n\nconst StyledErrorIcon = styled(Icon)(({ theme }) => {\n return css`\n color: ${theme.base.palette.urgent};\n margin-inline-start: calc(0.5 * ${theme.base.spacing});\n `;\n});\n\nStyledErrorIcon.defaultProps = defaultThemeProp;\n\nconst titleEllipsisStyle = css`\n flex-shrink: 1;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n`;\n\nconst StyledPreviewTitle = styled(Button)`\n ${titleEllipsisStyle}\n`;\n\nconst StyledTextTitle = styled(Text)`\n ${titleEllipsisStyle}\n`;\n\nconst StyledMeta = styled(StyledText)<{ error: boolean }>(({ theme, error }) => {\n return css`\n /* min width to show percentage in full */\n min-width: 4ch;\n margin-inline-start: auto;\n ${titleEllipsisStyle}\n ${error &&\n css`\n color: ${theme.base.palette.urgent};\n `}\n `;\n});\n\nStyledMeta.defaultProps = defaultThemeProp;\n\nconst StyledActionsWrapper = styled.div<{ meta: boolean }>(({ meta }) => {\n return css`\n margin-inline-start: ${meta ? 'unset' : 'auto'};\n `;\n});\n\nStyledActionsWrapper.defaultProps = defaultThemeProp;\n\nconst StyledFileItem = styled.div<{ compactMode: FileItemProps['compact'] }>(\n ({\n theme: {\n base: {\n palette,\n 'border-radius': borderRadius,\n spacing,\n 'hit-area': { compact }\n },\n components\n },\n compactMode\n }) => {\n return css`\n border-radius: calc(0.5 * ${borderRadius});\n border: 0.0625rem solid ${palette['border-line']};\n background-color: ${palette['primary-background']};\n height: ${components.input.height};\n min-width: calc(${components.input.height} + 12ch + 1.5 * ${spacing} + ${compact});\n\n ${compactMode &&\n css`\n height: ${compact};\n min-width: calc(${compact} + 12ch + 2 * ${spacing});\n width: fit-content;\n max-width: 25ch;\n\n ${StyledPreviewTitle}, ${StyledTextTitle} {\n min-width: 12ch;\n max-width: calc(25ch - (${compact} + 2 * ${spacing}));\n }\n\n ${StyledActionsWrapper} > ${StyledButton} {\n min-height: 100%;\n min-width: 100%;\n margin-block: ${spacing};\n }\n `}\n\n > ${StyledProgressRing} {\n margin-inline-start: calc(0.5 * ${spacing});\n }\n\n > ${StyledFileVisual}, > ${StyledIconShape} {\n border-start-start-radius: inherit;\n border-end-start-radius: inherit;\n border-start-end-radius: 0;\n border-end-end-radius: 0;\n width: ${components.input.height};\n flex-shrink: 0;\n\n ${compactMode &&\n css`\n height: ${compact};\n width: ${compact};\n `}\n }\n `;\n }\n);\n\nStyledFileItem.defaultProps = defaultThemeProp;\n\nconst FileItem: FC<FileItemProps & ForwardProps> = forwardRef(function FileItem(\n props: PropsWithoutRef<FileItemProps>,\n ref: FileItemProps['ref']\n) {\n const {\n id,\n name,\n thumbnail,\n format,\n error,\n onCancel,\n onEdit,\n onPreview,\n onDownload,\n onDelete,\n progress,\n compact = false,\n previewFromActions = false,\n ...restProps\n } = props;\n\n const [thumbnailError, setThumbnailError] = useState(false);\n const [textTarget, setTextTarget] = useElement();\n const [metaTarget, setMetaTarget] = useElement();\n const { locale } = useConfiguration();\n const t = useI18n();\n const uploading = typeof progress === 'number' && progress < 100;\n const itemRef = useConsolidatedRef(ref);\n\n const activeElement = getActiveElement();\n const activeElementInItem = itemRef.current?.contains(activeElement);\n\n let metaMessage;\n\n if (uploading) {\n metaMessage = formatNumber(progress, {\n locale,\n options: {\n style: 'unit',\n unit: 'percent',\n maximumFractionDigits: 0\n }\n });\n } else if (error) {\n metaMessage = error;\n }\n\n const definedActions: Action[] = [\n previewFromActions ? { onClick: onPreview, text: t('preview'), icon: 'preview' } : undefined,\n { onClick: onEdit, text: t('edit'), icon: 'pencil' },\n { onClick: onDownload, text: t('download'), icon: 'download' },\n { onClick: onDelete, text: t('delete'), icon: 'trash' }\n ].flatMap(action => {\n if (!action || !action.onClick) return [];\n\n const { text, icon, onClick } = action;\n return [\n {\n id: text,\n text,\n icon,\n onClick: () => {\n if (onClick) onClick(id);\n }\n }\n ];\n });\n\n let visual;\n let contextualLabel;\n\n if (uploading) {\n visual = <Progress variant='ring' placement='inline' value={progress} />;\n contextualLabel = t('uploading_file', [name]);\n } else if (error) {\n visual = <StyledErrorIcon name='warn-solid' />;\n contextualLabel = t('upload_failed', [name, error]);\n } else {\n visual = (\n <FileVisual\n type={\n format === 'url' ? 'link' : getKindFromMimeType(getMimeTypeFromFile(format ?? '') ?? '')\n }\n thumbnail={thumbnailError ? undefined : thumbnail}\n onThumbnailError={() => {\n setThumbnailError(true);\n }}\n />\n );\n contextualLabel = name;\n }\n\n useEffect(() => {\n if (!activeElement?.isConnected && activeElementInItem && itemRef.current) {\n getFocusables(itemRef.current)[0]?.focus();\n }\n }, [progress, error, onCancel, onDelete, onPreview, onEdit, onDownload]);\n\n return (\n <Flex\n as={StyledFileItem}\n container={{\n pad: [undefined, 0.5, undefined, undefined],\n alignItems: 'center',\n justify: 'start',\n gap: 1\n }}\n compactMode={compact}\n ref={itemRef}\n >\n {visual}\n\n {!previewFromActions && onPreview && !(error || uploading) ? (\n <Button\n {...restProps}\n as={StyledPreviewTitle}\n variant='link'\n ref={setTextTarget}\n onClick={() => {\n onPreview(id);\n }}\n aria-label={t('preview_file', [name])}\n >\n {name}\n {format === 'url' && <Icon name='open' />}\n </Button>\n ) : (\n <Text {...restProps} as={StyledTextTitle} ref={setTextTarget}>\n {name}\n </Text>\n )}\n {metaMessage && (\n <>\n <Text as={StyledMeta} variant='secondary' error={error && !uploading} ref={setMetaTarget}>\n {metaMessage}\n </Text>\n\n {metaTarget && (\n <Tooltip target={metaTarget} describeTarget={false} smart>\n {metaMessage}\n </Tooltip>\n )}\n </>\n )}\n\n {(error || uploading) && onCancel && (\n <StyledActionsWrapper meta={!!metaMessage}>\n <Button\n label={t('cancel')}\n aria-label={`${t('cancel')} - ${contextualLabel}`}\n variant='simple'\n compact\n icon\n onClick={() => onCancel(id)}\n >\n <Icon name='times' />\n </Button>\n </StyledActionsWrapper>\n )}\n\n {!(error || uploading) && !!definedActions.length && (\n <StyledActionsWrapper meta={!!metaMessage}>\n <Actions items={definedActions} compact iconOnly contextualLabel={name} />\n </StyledActionsWrapper>\n )}\n\n {textTarget && (\n <Tooltip target={textTarget} smart describeTarget={false}>\n {name}\n </Tooltip>\n )}\n </Flex>\n );\n});\n\nexport default FileItem;\n"]}
1
+ {"version":3,"file":"FileItem.js","sourceRoot":"","sources":["../../../src/components/File/FileItem.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAExD,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,IAAI,EAAE,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,KAAK,QAAQ,MAAM,yBAAyB,CAAC;AACpD,OAAO,KAAK,SAAS,MAAM,0BAA0B,CAAC;AACtD,OAAO,KAAK,WAAW,MAAM,4BAA4B,CAAC;AAC1D,OAAO,KAAK,QAAQ,MAAM,2BAA2B,CAAC;AACtD,OAAO,KAAK,YAAY,MAAM,6BAA6B,CAAC;AAC5D,OAAO,KAAK,UAAU,MAAM,0BAA0B,CAAC;AACvD,OAAO,IAAI,EAAE,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC3C,OAA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AAI,CACnC,KAAC,oBAAoB,IAAC,IAAI,EAAE,CAAC,CAAC,WAAW,YACvC,KAAC,MAAM,IACL,KAAK,EAAE,CAAC,CAAC,QAAQ,CAAC,gBACN,GAAG,CAAC,CAAC,QAAQ,CAAC,MAAM,eAAe,EAAE,EACjD,OAAO,EAAC,QAAQ,EAChB,OAAO,QACP,IAAI,QACJ,OAAO,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,EAC3B,QAAQ,EAAE,QAAQ,YAElB,KAAC,IAAI,IAAC,IAAI,EAAC,OAAO,GAAG,GACd,GACY,CACxB,EAEA,CAAC,CAAC,KAAK,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC,cAAc,CAAC,MAAM,IAAI,CACnD,KAAC,oBAAoB,IAAC,IAAI,EAAE,CAAC,CAAC,WAAW,YACvC,KAAC,OAAO,IACN,KAAK,EAAE,cAAc,EACrB,OAAO,QACP,QAAQ,QACR,eAAe,EAAE,IAAI,EACrB,QAAQ,EAAE,QAAQ,GAClB,GACmB,CACxB,EAEA,UAAU,IAAI,CACb,KAAC,OAAO,IAAC,MAAM,EAAE,UAAU,EAAE,KAAK,QAAC,cAAc,EAAE,KAAK,YACrD,IAAI,GACG,CACX,IACI,CACR,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,eAAe,QAAQ,CAAC","sourcesContent":["import { forwardRef, useEffect, useState } from 'react';\nimport type { PropsWithoutRef, FC, Ref } from 'react';\nimport styled, { css } from 'styled-components';\n\nimport Icon, { registerIcon } from '../Icon';\nimport * as openIcon from '../Icon/icons/open.icon';\nimport * as timesIcon from '../Icon/icons/times.icon';\nimport * as previewIcon from '../Icon/icons/preview.icon';\nimport * as editIcon from '../Icon/icons/pencil.icon';\nimport * as downloadIcon from '../Icon/icons/download.icon';\nimport * as deleteIcon from '../Icon/icons/trash.icon';\nimport Text, { StyledText } from '../Text';\nimport Tooltip from '../Tooltip';\nimport type { ForwardProps, BaseProps, Action } from '../../types';\nimport { defaultThemeProp } from '../../theme';\nimport Button, { StyledButton } from '../Button';\nimport { useI18n, useElement, useConfiguration, useConsolidatedRef } from '../../hooks';\nimport Actions from '../Actions';\nimport Progress from '../Progress';\nimport { StyledProgressRing } from '../Progress/Progress.styles';\nimport { formatNumber } from '../Number';\nimport Flex from '../Flex';\nimport { StyledIconShape } from '../Icon/Icon';\nimport { getActiveElement, getFocusables } from '../../utils';\n\nimport { getKindFromMimeType, getMimeTypeFromFile } from './utils';\nimport FileVisual, { StyledFileVisual } from './FileVisual';\nimport type { FileVisualProps } from './FileVisual';\n\nregisterIcon(openIcon, timesIcon, previewIcon, editIcon, downloadIcon, deleteIcon);\n\nexport interface FileItemProps extends BaseProps {\n /** Unique id for item. */\n id: string;\n /** Name of the file. */\n name: string;\n /** A string to be used as an image src for a attachment thumbnail. Falls back to a provided icon or the default attachment icon. */\n thumbnail?: FileVisualProps['thumbnail'];\n /** File extension. Use 'url' for link */\n format?: string;\n /**\n * Used for a smaller sized FileItem.\n * @default false\n */\n compact?: boolean;\n /** When passed, will render a single icon button for yet to be or in progress uploads. Use this action to trigger xhr request termination. */\n onCancel?: (id: FileItemProps['id']) => void;\n /** When passed, will render a single icon button or within a MenuButton if other actions are defined. */\n onEdit?: (id: FileItemProps['id']) => void;\n /** When passed, will be called on click of the name. Passes file id as the parameter. */\n onPreview?: (id: FileItemProps['id']) => void;\n /**\n * Moves preview option to actions menu.\n * To be used only in compact mode of single file input when rendered in a table\n */\n previewFromActions?: boolean;\n /** When passed, will render a single icon button or within a MenuButton if other actions are defined. Passes file id as the parameter. */\n onDownload?: (id: FileItemProps['id']) => void;\n /** When passed, will render a single icon button or within a MenuButton if other actions are defined. */\n onDelete?: (id: FileItemProps['id']) => void;\n /** If the attachment is in an upload state, pass progress as a number between 0-100 representing the percentage of progress. */\n progress?: number;\n /** Set if there is an error uploading the file. Applies error styling to the meta string passed. */\n error?: string;\n /**\n * Sets disabled state.\n * @default false\n */\n disabled?: boolean;\n /** Ref for the wrapping element. */\n ref?: Ref<HTMLDivElement>;\n}\n\nconst StyledErrorIcon = styled(Icon)(({ theme }) => {\n return css`\n color: ${theme.base.palette.urgent};\n margin-inline-start: calc(0.5 * ${theme.base.spacing});\n `;\n});\n\nStyledErrorIcon.defaultProps = defaultThemeProp;\n\nconst titleEllipsisStyle = css`\n flex-shrink: 1;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n`;\n\nconst StyledPreviewTitle = styled(Button)`\n ${titleEllipsisStyle}\n`;\n\nconst StyledTextTitle = styled(Text)`\n ${titleEllipsisStyle}\n`;\n\nconst StyledMeta = styled(StyledText)<{ error: boolean }>(({ theme, error }) => {\n return css`\n /* min width to show percentage in full */\n min-width: 4ch;\n margin-inline-start: auto;\n ${titleEllipsisStyle}\n ${error &&\n css`\n color: ${theme.base.palette.urgent};\n `}\n `;\n});\n\nStyledMeta.defaultProps = defaultThemeProp;\n\nconst StyledActionsWrapper = styled.div<{ meta: boolean }>(({ meta }) => {\n return css`\n margin-inline-start: ${meta ? 'unset' : 'auto'};\n `;\n});\n\nStyledActionsWrapper.defaultProps = defaultThemeProp;\n\nconst StyledFileItem = styled.div<{\n compactMode: FileItemProps['compact'];\n isDisabled?: FileItemProps['disabled'];\n}>(\n ({\n theme: {\n base: {\n palette,\n 'border-radius': borderRadius,\n spacing,\n 'hit-area': { compact },\n 'disabled-opacity': disabledOpacity\n },\n components: {\n input,\n 'form-control': {\n ':disabled': {\n 'background-color': disabledBackgroundColor,\n 'border-color': disabledBorderColor\n }\n }\n }\n },\n compactMode,\n isDisabled\n }) => {\n return css`\n border-radius: calc(0.5 * ${borderRadius});\n border: 0.0625rem solid ${palette['border-line']};\n background-color: ${palette['primary-background']};\n height: ${input.height};\n min-width: calc(${input.height} + 12ch + 1.5 * ${spacing} + ${compact});\n\n ${compactMode &&\n css`\n height: ${compact};\n min-width: calc(${compact} + 12ch + 2 * ${spacing});\n width: fit-content;\n max-width: 25ch;\n\n ${StyledPreviewTitle}, ${StyledTextTitle} {\n min-width: 12ch;\n max-width: calc(25ch - (${compact} + 2 * ${spacing}));\n }\n\n ${StyledActionsWrapper} > ${StyledButton} {\n min-height: 100%;\n min-width: 100%;\n margin-block: ${spacing};\n }\n `}\n\n > ${StyledProgressRing} {\n margin-inline-start: calc(0.5 * ${spacing});\n }\n\n > ${StyledFileVisual}, > ${StyledIconShape} {\n border-start-start-radius: inherit;\n border-end-start-radius: inherit;\n border-start-end-radius: 0;\n border-end-end-radius: 0;\n width: ${input.height};\n flex-shrink: 0;\n\n ${compactMode &&\n css`\n height: ${compact};\n width: ${compact};\n `}\n }\n\n ${isDisabled &&\n css`\n background-color: ${disabledBackgroundColor};\n border-color: ${disabledBorderColor};\n opacity: ${disabledOpacity};\n `}\n `;\n }\n);\n\nStyledFileItem.defaultProps = defaultThemeProp;\n\nconst FileItem: FC<FileItemProps & ForwardProps> = forwardRef(function FileItem(\n props: PropsWithoutRef<FileItemProps>,\n ref: FileItemProps['ref']\n) {\n const {\n id,\n name,\n thumbnail,\n format,\n error,\n onCancel,\n onEdit,\n onPreview,\n onDownload,\n onDelete,\n progress,\n compact = false,\n previewFromActions = false,\n disabled = false,\n ...restProps\n } = props;\n\n const [thumbnailError, setThumbnailError] = useState(false);\n const [textTarget, setTextTarget] = useElement();\n const [metaTarget, setMetaTarget] = useElement();\n const { locale } = useConfiguration();\n const t = useI18n();\n const uploading = typeof progress === 'number' && progress < 100;\n const itemRef = useConsolidatedRef(ref);\n\n const activeElement = getActiveElement();\n const activeElementInItem = itemRef.current?.contains(activeElement);\n\n let metaMessage;\n\n if (uploading) {\n metaMessage = formatNumber(progress, {\n locale,\n options: {\n style: 'unit',\n unit: 'percent',\n maximumFractionDigits: 0\n }\n });\n } else if (error) {\n metaMessage = error;\n }\n\n const definedActions: Action[] = [\n previewFromActions ? { onClick: onPreview, text: t('preview'), icon: 'preview' } : undefined,\n { onClick: onEdit, text: t('edit'), icon: 'pencil' },\n { onClick: onDownload, text: t('download'), icon: 'download' },\n { onClick: onDelete, text: t('delete'), icon: 'trash' }\n ].flatMap(action => {\n if (!action || !action.onClick) return [];\n\n const { text, icon, onClick } = action;\n return [\n {\n id: text,\n text,\n icon,\n onClick: () => {\n if (onClick) onClick(id);\n }\n }\n ];\n });\n\n let visual;\n let contextualLabel;\n\n if (uploading) {\n visual = <Progress variant='ring' placement='inline' value={progress} />;\n contextualLabel = t('uploading_file', [name]);\n } else if (error) {\n visual = <StyledErrorIcon name='warn-solid' />;\n contextualLabel = t('upload_failed', [name, error]);\n } else {\n visual = (\n <FileVisual\n type={\n format === 'url' ? 'link' : getKindFromMimeType(getMimeTypeFromFile(format ?? '') ?? '')\n }\n thumbnail={thumbnailError ? undefined : thumbnail}\n onThumbnailError={() => {\n setThumbnailError(true);\n }}\n />\n );\n contextualLabel = name;\n }\n\n useEffect(() => {\n if (!activeElement?.isConnected && activeElementInItem && itemRef.current) {\n getFocusables(itemRef.current)[0]?.focus();\n }\n }, [progress, error, onCancel, onDelete, onPreview, onEdit, onDownload]);\n\n return (\n <Flex\n as={StyledFileItem}\n container={{\n pad: [undefined, 0.5, undefined, undefined],\n alignItems: 'center',\n justify: 'start',\n gap: 1\n }}\n isDisabled={disabled}\n compactMode={compact}\n ref={itemRef}\n >\n {visual}\n\n {!previewFromActions && onPreview && !(error || uploading) ? (\n <Button\n {...restProps}\n as={StyledPreviewTitle}\n variant='link'\n ref={setTextTarget}\n onClick={() => {\n onPreview(id);\n }}\n aria-label={t('preview_file', [name])}\n disabled={disabled}\n >\n {name}\n {format === 'url' && <Icon name='open' />}\n </Button>\n ) : (\n <Text {...restProps} as={StyledTextTitle} ref={setTextTarget}>\n {name}\n </Text>\n )}\n {metaMessage && (\n <>\n <Text as={StyledMeta} variant='secondary' error={error && !uploading} ref={setMetaTarget}>\n {metaMessage}\n </Text>\n\n {metaTarget && (\n <Tooltip target={metaTarget} describeTarget={false} smart>\n {metaMessage}\n </Tooltip>\n )}\n </>\n )}\n\n {(error || uploading) && onCancel && (\n <StyledActionsWrapper meta={!!metaMessage}>\n <Button\n label={t('cancel')}\n aria-label={`${t('cancel')} - ${contextualLabel}`}\n variant='simple'\n compact\n icon\n onClick={() => onCancel(id)}\n disabled={disabled}\n >\n <Icon name='times' />\n </Button>\n </StyledActionsWrapper>\n )}\n\n {!(error || uploading) && !!definedActions.length && (\n <StyledActionsWrapper meta={!!metaMessage}>\n <Actions\n items={definedActions}\n compact\n iconOnly\n contextualLabel={name}\n disabled={disabled}\n />\n </StyledActionsWrapper>\n )}\n\n {textTarget && (\n <Tooltip target={textTarget} smart describeTarget={false}>\n {name}\n </Tooltip>\n )}\n </Flex>\n );\n});\n\nexport default FileItem;\n"]}
@@ -5,9 +5,11 @@ import type { FileItemProps } from './FileItem';
5
5
  export type FileListProps = WithAttributes<'div', {
6
6
  type: 'display';
7
7
  items: FileDisplayProps[];
8
+ disabled?: never;
8
9
  } | {
9
10
  type: 'item';
10
11
  items: FileItemProps[];
12
+ disabled?: boolean;
11
13
  }>;
12
14
  declare const FileList: import("react").ForwardRefExoticComponent<PropsWithoutRef<FileListProps> & import("react").RefAttributes<HTMLDivElement>>;
13
15
  export default FileList;
@@ -1 +1 @@
1
- {"version":3,"file":"FileList.d.ts","sourceRoot":"","sources":["../../../src/components/File/FileList.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAG7C,OAAO,KAAK,EAAc,cAAc,EAAE,MAAM,aAAa,CAAC;AAM9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAIhD,MAAM,MAAM,aAAa,GAAG,cAAc,CACxC,KAAK,EACH;IACE,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,gBAAgB,EAAE,CAAC;CAC3B,GACD;IACE,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,aAAa,EAAE,CAAC;CACxB,CACJ,CAAC;AAQF,QAAA,MAAM,QAAQ,2HAgDb,CAAC;AAEF,eAAe,QAAQ,CAAC"}
1
+ {"version":3,"file":"FileList.d.ts","sourceRoot":"","sources":["../../../src/components/File/FileList.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAG7C,OAAO,KAAK,EAAc,cAAc,EAAE,MAAM,aAAa,CAAC;AAM9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAIhD,MAAM,MAAM,aAAa,GAAG,cAAc,CACxC,KAAK,EACH;IACE,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,gBAAgB,EAAE,CAAC;IAC1B,QAAQ,CAAC,EAAE,KAAK,CAAC;CAClB,GACD;IACE,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,aAAa,EAAE,CAAC;IACvB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CACJ,CAAC;AAQF,QAAA,MAAM,QAAQ,2HAgDb,CAAC;AAEF,eAAe,QAAQ,CAAC"}
@@ -12,7 +12,7 @@ const StyledFileList = styled(Grid) `
12
12
  margin-inline-start: unset;
13
13
  }
14
14
  `;
15
- const FileList = forwardRef(function FileList({ type, items, ...restProps }, ref) {
15
+ const FileList = forwardRef(function FileList({ type, items, disabled, ...restProps }, ref) {
16
16
  const listRef = useConsolidatedRef(ref);
17
17
  const isSmallOrAbove = useBreakpoint('sm', { breakpointRef: listRef });
18
18
  const prevItems = usePrevious(items);
@@ -42,7 +42,7 @@ const FileList = forwardRef(function FileList({ type, items, ...restProps }, ref
42
42
  }, [items]);
43
43
  return (_jsx(Grid, { ...restProps, ref: listRef, container: { gap: 0.5, cols: isSmallOrAbove ? 'repeat(2, 1fr)' : '1fr' }, as: StyledFileList, children: type === 'display'
44
44
  ? items.map(item => _jsx(FileDisplay, { ...item }, item.id))
45
- : items.map(item => _jsx(FileItem, { ...item }, item.id)) }));
45
+ : items.map(item => _jsx(FileItem, { ...item, disabled: disabled }, item.id)) }));
46
46
  });
47
47
  export default FileList;
48
48
  //# sourceMappingURL=FileList.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"FileList.js","sourceRoot":"","sources":["../../../src/components/File/FileList.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAE9C,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAGvC,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC7E,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAI9D,OAAO,WAAW,MAAM,eAAe,CAAC;AACxC,OAAO,QAAQ,MAAM,YAAY,CAAC;AAclC,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;IAC/B,UAAU,MAAM,UAAU;;;CAG7B,CAAC;AAEF,MAAM,QAAQ,GAAG,UAAU,CACzB,SAAS,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,SAAS,EAAE,EAAE,GAAG;IAClD,MAAM,OAAO,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAC;IACxC,MAAM,cAAc,GAAG,aAAa,CAAC,IAAI,EAAE,EAAE,aAAa,EAAE,OAAO,EAAE,CAAC,CAAC;IAEvE,MAAM,SAAS,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;IACrC,MAAM,sBAAsB,GAAG,OAAO,CAAC,OAAO,EAAE,QAAQ,CAAC,gBAAgB,EAAE,CAAC,CAAC;IAE7E,SAAS,CAAC,GAAG,EAAE;QACb,mDAAmD;QACnD,IACE,KAAK,CAAC,MAAM,KAAK,CAAC;YAClB,CAAC,sBAAs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,IAAI,CAAC,EAAE,CAAC,KAAC,QAAQ,OAAmB,IAAI,IAAjB,IAAI,CAAC,EAAE,CAAc,CAAC,GACtD,CACR,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,QAAQ,CAAC","sourcesContent":["import { forwardRef, useEffect } from 'react';\nimport type { PropsWithoutRef } from 'react';\nimport styled from 'styled-components';\n\nimport type { RefElement, WithAttributes } from '../../types';\nimport { useBreakpoint, useConsolidatedRef, usePrevious } from '../../hooks';\nimport Grid from '../Grid';\nimport { StyledLink } from '../Link';\nimport { getActiveElement, getFocusables } from '../../utils';\n\nimport type { FileDisplayProps } from './FileDisplay';\nimport type { FileItemProps } from './FileItem';\nimport FileDisplay from './FileDisplay';\nimport FileItem from './FileItem';\n\nexport type FileListProps = WithAttributes<\n 'div',\n | {\n type: 'display';\n items: FileDisplayProps[];\n }\n | {\n type: 'item';\n items: FileItemProps[];\n }\n>;\n\nconst StyledFileList = styled(Grid)`\n ${StyledLink} + ${StyledLink} {\n margin-inline-start: unset;\n }\n`;\n\nconst FileList = forwardRef<RefElement<FileListProps>, PropsWithoutRef<FileListProps>>(\n function FileList({ type, items, ...restProps }, ref) {\n const listRef = useConsolidatedRef(ref);\n const isSmallOrAbove = useBreakpoint('sm', { breakpointRef: listRef });\n\n const prevItems = usePrevious(items);\n const activeElementContained = listRef.current?.contains(getActiveElement());\n\n useEffect(() => {\n // Early exit when focus doesn't need to be grabbed\n if (\n items.length === 0 ||\n !activeElementContained ||\n listRef.current?.contains(getActiveElement())\n ) {\n return;\n }\n\n prevItems?.forEach((item, oldIndex) => {\n const newIndex = items.findIndex(newItem => {\n return item.id === newItem.id;\n });\n\n if (newIndex === -1 && listRef.current) {\n if (oldIndex === prevItems.length - 1) {\n // Move the focus to previous element when last element is removed\n getFocusables(listRef.current.children[items.length - 1])[0]?.focus();\n } else {\n // Otherwise, Move the focus to next element\n getFocusables(listRef.current.children[oldIndex])[0]?.focus();\n }\n }\n });\n }, [items]);\n\n return (\n <Grid\n {...restProps}\n ref={listRef}\n container={{ gap: 0.5, cols: isSmallOrAbove ? 'repeat(2, 1fr)' : '1fr' }}\n as={StyledFileList}\n >\n {type === 'display'\n ? items.map(item => <FileDisplay key={item.id} {...item} />)\n : items.map(item => <FileItem key={item.id} {...item} />)}\n </Grid>\n );\n }\n);\n\nexport default FileList;\n"]}
1
+ {"version":3,"file":"FileList.js","sourceRoot":"","sources":["../../../src/components/File/FileList.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAE9C,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAGvC,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC7E,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAI9D,OAAO,WAAW,MAAM,eAAe,CAAC;AACxC,OAAO,QAAQ,MAAM,YAAY,CAAC;AAgBlC,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;IAC/B,UAAU,MAAM,UAAU;;;CAG7B,CAAC;AAEF,MAAM,QAAQ,GAAG,UAAU,CACzB,SAAS,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,SAAS,EAAE,EAAE,GAAG;IAC5D,MAAM,OAAO,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAC;IACxC,MAAM,cAAc,GAAG,aAAa,CAAC,IAAI,EAAE,EAAE,aAAa,EAAE,OAAO,EAAE,CAAC,CAAC;IAEvE,MAAM,SAAS,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;IACrC,MAAM,sBAAsB,GAAG,OAAO,CAAC,OAAO,EAAE,QAAQ,CAAC,gBAAgB,EAAE,CAAC,CAAC;IAE7E,SAAS,CAA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,IAAI,IAAjB,IAAI,CAAC,EAAE,CAAc,CAAC;YAC5D,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,KAAC,QAAQ,OAAmB,IAAI,EAAE,QAAQ,EAAE,QAAQ,IAArC,IAAI,CAAC,EAAE,CAAkC,CAAC,GAC1E,CACR,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,QAAQ,CAAC","sourcesContent":["import { forwardRef, useEffect } from 'react';\nimport type { PropsWithoutRef } from 'react';\nimport styled from 'styled-components';\n\nimport type { RefElement, WithAttributes } from '../../types';\nimport { useBreakpoint, useConsolidatedRef, usePrevious } from '../../hooks';\nimport Grid from '../Grid';\nimport { StyledLink } from '../Link';\nimport { getActiveElement, getFocusables } from '../../utils';\n\nimport type { FileDisplayProps } from './FileDisplay';\nimport type { FileItemProps } from './FileItem';\nimport FileDisplay from './FileDisplay';\nimport FileItem from './FileItem';\n\nexport type FileListProps = WithAttributes<\n 'div',\n | {\n type: 'display';\n items: FileDisplayProps[];\n disabled?: never;\n }\n | {\n type: 'item';\n items: FileItemProps[];\n disabled?: boolean;\n }\n>;\n\nconst StyledFileList = styled(Grid)`\n ${StyledLink} + ${StyledLink} {\n margin-inline-start: unset;\n }\n`;\n\nconst FileList = forwardRef<RefElement<FileListProps>, PropsWithoutRef<FileListProps>>(\n function FileList({ type, items, disabled, ...restProps }, ref) {\n const listRef = useConsolidatedRef(ref);\n const isSmallOrAbove = useBreakpoint('sm', { breakpointRef: listRef });\n\n const prevItems = usePrevious(items);\n const activeElementContained = listRef.current?.contains(getActiveElement());\n\n useEffect(() => {\n // Early exit when focus doesn't need to be grabbed\n if (\n items.length === 0 ||\n !activeElementContained ||\n listRef.current?.contains(getActiveElement())\n ) {\n return;\n }\n\n prevItems?.forEach((item, oldIndex) => {\n const newIndex = items.findIndex(newItem => {\n return item.id === newItem.id;\n });\n\n if (newIndex === -1 && listRef.current) {\n if (oldIndex === prevItems.length - 1) {\n // Move the focus to previous element when last element is removed\n getFocusables(listRef.current.children[items.length - 1])[0]?.focus();\n } else {\n // Otherwise, Move the focus to next element\n getFocusables(listRef.current.children[oldIndex])[0]?.focus();\n }\n }\n });\n }, [items]);\n\n return (\n <Grid\n {...restProps}\n ref={listRef}\n container={{ gap: 0.5, cols: isSmallOrAbove ? 'repeat(2, 1fr)' : '1fr' }}\n as={StyledFileList}\n >\n {type === 'display'\n ? items.map(item => <FileDisplay key={item.id} {...item} />)\n : items.map(item => <FileItem key={item.id} {...item} disabled={disabled} />)}\n </Grid>\n );\n }\n);\n\nexport default FileList;\n"]}
@@ -6,7 +6,7 @@ export interface FormProps extends OmitStrict<BaseFormProps, 'content'>, TestIdP
6
6
  children: BaseFormProps['content'];
7
7
  }
8
8
  declare const _default: FC<FormProps & ForwardProps> & {
9
- getTestIds: (testIdProp?: string | undefined) => import("../../types").TestIdsRecord<readonly []>;
9
+ getTestIds: (testIdProp?: string | null | undefined) => import("../../types").TestIdsRecord<readonly []>;
10
10
  };
11
11
  export default _default;
12
12
  //# sourceMappingURL=Form.d.ts.map
@@ -1,2 +1,2 @@
1
- export declare const getFormTestIds: (testIdProp?: string | undefined) => import("../..").TestIdsRecord<readonly []>;
1
+ export declare const getFormTestIds: (testIdProp?: string | null | undefined) => import("../..").TestIdsRecord<readonly []>;
2
2
  //# sourceMappingURL=Form.test-ids.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Form.test-ids.d.ts","sourceRoot":"","sources":["../../../src/components/Form/Form.test-ids.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc,iFAAqC,CAAC"}
1
+ {"version":3,"file":"Form.test-ids.d.ts","sourceRoot":"","sources":["../../../src/components/Form/Form.test-ids.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc,wFAAqC,CAAC"}
@@ -71,7 +71,7 @@ export declare const StyledFormField: import("styled-components").StyledComponen
71
71
  showAdditionalInfo: boolean;
72
72
  }, never>;
73
73
  declare const _default: FC<FormFieldProps & ForwardProps> & {
74
- getTestIds: (testIdProp?: string | undefined) => import("../../types").TestIdsRecord<readonly ["label", "info", "additional-info", "suggestion-accept", "suggestion-reject"]>;
74
+ getTestIds: (testIdProp?: string | null | undefined) => import("../../types").TestIdsRecord<readonly ["label", "info", "additional-info", "suggestion-accept", "suggestion-reject"]>;
75
75
  };
76
76
  export default _default;
77
77
  //# sourceMappingURL=FormField.d.ts.map
@@ -1,3 +1,3 @@
1
1
  export declare const elements: readonly ["label", "info", "additional-info", "suggestion-accept", "suggestion-reject"];
2
- export declare const getFormFieldTestIds: (testIdProp?: string | undefined) => import("../..").TestIdsRecord<readonly ["label", "info", "additional-info", "suggestion-accept", "suggestion-reject"]>;
2
+ export declare const getFormFieldTestIds: (testIdProp?: string | null | undefined) => import("../..").TestIdsRecord<readonly ["label", "info", "additional-info", "suggestion-accept", "suggestion-reject"]>;
3
3
  //# sourceMappingURL=FormField.test-ids.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FormField.test-ids.d.ts","sourceRoot":"","sources":["../../../src/components/FormField/FormField.test-ids.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,QAAQ,yFAMX,CAAC;AAEX,eAAO,MAAM,mBAAmB,6JAAwC,CAAC"}
1
+ {"version":3,"file":"FormField.test-ids.d.ts","sourceRoot":"","sources":["../../../src/components/FormField/FormField.test-ids.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,QAAQ,yFAMX,CAAC;AAEX,eAAO,MAAM,mBAAmB,oKAAwC,CAAC"}
@@ -11,7 +11,7 @@ export declare const getTableStyles: (theme: DefaultTheme) => import("styled-com
11
11
  export declare const getHtmlStyles: (theme: DefaultTheme) => string;
12
12
  export declare const StyledHTML: import("styled-components").StyledComponent<"div", DefaultTheme, {}, never>;
13
13
  declare const _default: FunctionComponent<HTMLProps & ForwardProps> & {
14
- getTestIds: (testIdProp?: string | undefined) => import("../../types").TestIdsRecord<readonly []>;
14
+ getTestIds: (testIdProp?: string | null | undefined) => import("../../types").TestIdsRecord<readonly []>;
15
15
  };
16
16
  export default _default;
17
17
  //# sourceMappingURL=HTML.d.ts.map
@@ -1,2 +1,2 @@
1
- export declare const getHTMLTestIds: (testIdProp?: string | undefined) => import("../..").TestIdsRecord<readonly []>;
1
+ export declare const getHTMLTestIds: (testIdProp?: string | null | undefined) => import("../..").TestIdsRecord<readonly []>;
2
2
  //# sourceMappingURL=HTML.test-ids.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"HTML.test-ids.d.ts","sourceRoot":"","sources":["../../../src/components/HTML/HTML.test-ids.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc,iFAAqC,CAAC"}
1
+ {"version":3,"file":"HTML.test-ids.d.ts","sourceRoot":"","sources":["../../../src/components/HTML/HTML.test-ids.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc,wFAAqC,CAAC"}
@@ -13,7 +13,7 @@ export interface InputProps extends FormControlProps, BaseProps, NoChildrenProp,
13
13
  readOnly?: FormControlProps['readOnly'];
14
14
  }
15
15
  declare const _default: FC<InputProps & ForwardProps> & {
16
- getTestIds: (testIdProp?: string | undefined) => import("../../types").TestIdsRecord<readonly ["control", "label", "info", "additional-info", "suggestion-accept", "suggestion-reject"]>;
16
+ getTestIds: (testIdProp?: string | null | undefined) => import("../../types").TestIdsRecord<readonly ["control", "label", "info", "additional-info", "suggestion-accept", "suggestion-reject"]>;
17
17
  };
18
18
  export default _default;
19
19
  //# sourceMappingURL=Input.d.ts.map
@@ -1,2 +1,2 @@
1
- export declare const getInputTestIds: (testIdProp?: string | undefined) => import("../..").TestIdsRecord<readonly ["control", "label", "info", "additional-info", "suggestion-accept", "suggestion-reject"]>;
1
+ export declare const getInputTestIds: (testIdProp?: string | null | undefined) => import("../..").TestIdsRecord<readonly ["control", "label", "info", "additional-info", "suggestion-accept", "suggestion-reject"]>;
2
2
  //# sourceMappingURL=Input.test-ids.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Input.test-ids.d.ts","sourceRoot":"","sources":["../../../src/components/Input/Input.test-ids.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,eAAe,wKAA4D,CAAC"}
1
+ {"version":3,"file":"Input.test-ids.d.ts","sourceRoot":"","sources":["../../../src/components/Input/Input.test-ids.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,eAAe,+KAA4D,CAAC"}
@@ -2,7 +2,7 @@ import type { FunctionComponent } from 'react';
2
2
  import type { ForwardProps } from '../../types';
3
3
  import type { LightboxProps } from './Lightbox.types';
4
4
  declare const _default: FunctionComponent<LightboxProps & ForwardProps> & {
5
- getTestIds: (testIdProp?: string | undefined) => import("../../types").TestIdsRecord<readonly ["content", "name", "metadata", "download", "close", "prev", "next", "pagination", "non-previewable-download", "link"]>;
5
+ getTestIds: (testIdProp?: string | null | undefined) => import("../../types").TestIdsRecord<readonly ["content", "name", "metadata", "download", "close", "prev", "next", "pagination", "non-previewable-download", "link"]>;
6
6
  };
7
7
  export default _default;
8
8
  //# sourceMappingURL=Lightbox.d.ts.map
@@ -8,6 +8,6 @@ export declare const StyledObject: import("styled-components").StyledComponent<"
8
8
  export declare const StyledPreviewRegion: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
9
9
  export declare const StyledLiveRegion: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
10
10
  export declare const StyledLightbox: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<Omit<import("../Backdrop").BackdropProps, "ref"> & import("react").RefAttributes<HTMLDivElement>> & {
11
- getTestIds: (testIdProp?: string | undefined) => import("../..").TestIdsRecord<readonly []>;
11
+ getTestIds: (testIdProp?: string | null | undefined) => import("../..").TestIdsRecord<readonly []>;
12
12
  }, import("styled-components").DefaultTheme, {}, never>;
13
13
  //# sourceMappingURL=Lightbox.styles.d.ts.map
@@ -1,2 +1,2 @@
1
- export declare const getLightboxTestIds: (testIdProp?: string | undefined) => import("../..").TestIdsRecord<readonly ["content", "name", "metadata", "download", "close", "prev", "next", "pagination", "non-previewable-download", "link"]>;
1
+ export declare const getLightboxTestIds: (testIdProp?: string | null | undefined) => import("../..").TestIdsRecord<readonly ["content", "name", "metadata", "download", "close", "prev", "next", "pagination", "non-previewable-download", "link"]>;
2
2
  //# sourceMappingURL=Lightbox.test-ids.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Lightbox.test-ids.d.ts","sourceRoot":"","sources":["../../../src/components/Lightbox/Lightbox.test-ids.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kBAAkB,qMAWpB,CAAC"}
1
+ {"version":3,"file":"Lightbox.test-ids.d.ts","sourceRoot":"","sources":["../../../src/components/Lightbox/Lightbox.test-ids.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kBAAkB,4MAWpB,CAAC"}
@@ -34,7 +34,7 @@ export declare const StyledLinkPopoverBtn: import("styled-components").StyledCom
34
34
  export declare const StyledLinkPreviewPopoverBtn: import("styled-components").StyledComponent<FunctionComponent<import("../Button/BareButton").BareButtonProps & ForwardProps>, import("styled-components").DefaultTheme, {}, never>;
35
35
  export declare const StyledLink: import("styled-components").StyledComponent<FunctionComponent<ButtonProps & ForwardProps>, import("styled-components").DefaultTheme, {}, never>;
36
36
  declare const _default: FunctionComponent<LinkProps & ForwardProps> & {
37
- getTestIds: (testIdProp?: string | undefined) => import("../../types").TestIdsRecord<readonly ["preview-popover", "preview", "new-tab"]>;
37
+ getTestIds: (testIdProp?: string | null | undefined) => import("../../types").TestIdsRecord<readonly ["preview-popover", "preview", "new-tab"]>;
38
38
  };
39
39
  export default _default;
40
40
  //# sourceMappingURL=Link.d.ts.map
@@ -1,2 +1,2 @@
1
- export declare const getLinkTestIds: (testIdProp?: string | undefined) => import("../..").TestIdsRecord<readonly ["preview-popover", "preview", "new-tab"]>;
1
+ export declare const getLinkTestIds: (testIdProp?: string | null | undefined) => import("../..").TestIdsRecord<readonly ["preview-popover", "preview", "new-tab"]>;
2
2
  //# sourceMappingURL=Link.test-ids.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Link.test-ids.d.ts","sourceRoot":"","sources":["../../../src/components/Link/Link.test-ids.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc,wHAIhB,CAAC"}
1
+ {"version":3,"file":"Link.test-ids.d.ts","sourceRoot":"","sources":["../../../src/components/Link/Link.test-ids.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc,+HAIhB,CAAC"}
@@ -2,7 +2,7 @@ import type { FunctionComponent } from 'react';
2
2
  import type { ForwardProps } from '../../types';
3
3
  import type { ListToolbarProps } from './ListToolbar.types';
4
4
  declare const _default: FunctionComponent<ListToolbarProps & ForwardProps> & {
5
- getTestIds: (testIdProp?: string | undefined) => import("../../types").TestIdsRecord<readonly ["view-selector", "count", "heading", "info", "create-new", "search-input", "search-button"]>;
5
+ getTestIds: (testIdProp?: string | null | undefined) => import("../../types").TestIdsRecord<readonly ["view-selector", "count", "heading", "info", "create-new", "search-input", "search-button"]>;
6
6
  };
7
7
  export default _default;
8
8
  //# sourceMappingURL=ListToolbar.d.ts.map
@@ -1,2 +1,2 @@
1
- export declare const getListToolbarTestIds: (testIdProp?: string | undefined) => import("../..").TestIdsRecord<readonly ["view-selector", "count", "heading", "info", "create-new", "search-input", "search-button"]>;
1
+ export declare const getListToolbarTestIds: (testIdProp?: string | null | undefined) => import("../..").TestIdsRecord<readonly ["view-selector", "count", "heading", "info", "create-new", "search-input", "search-button"]>;
2
2
  //# sourceMappingURL=ListToolbar.test-ids.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ListToolbar.test-ids.d.ts","sourceRoot":"","sources":["../../../src/components/ListToolbar/ListToolbar.test-ids.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,qBAAqB,2KAQvB,CAAC"}
1
+ {"version":3,"file":"ListToolbar.test-ids.d.ts","sourceRoot":"","sources":["../../../src/components/ListToolbar/ListToolbar.test-ids.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,qBAAqB,kLAQvB,CAAC"}
@@ -1,2 +1,2 @@
1
- export declare const getLocationInputTestIds: (testIdProp?: string | undefined) => import("../..").TestIdsRecord<readonly ["control", "label", "info", "additional-info", "suggestion-accept", "suggestion-reject"]>;
1
+ export declare const getLocationInputTestIds: (testIdProp?: string | null | undefined) => import("../..").TestIdsRecord<readonly ["control", "label", "info", "additional-info", "suggestion-accept", "suggestion-reject"]>;
2
2
  //# sourceMappingURL=Location.test-ids.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Location.test-ids.d.ts","sourceRoot":"","sources":["../../../src/components/Location/Location.test-ids.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,uBAAuB,wKAGzB,CAAC"}
1
+ {"version":3,"file":"Location.test-ids.d.ts","sourceRoot":"","sources":["../../../src/components/Location/Location.test-ids.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,uBAAuB,+KAGzB,CAAC"}
@@ -50,7 +50,7 @@ export interface LocationInputProps extends BaseProps, FormControlProps, TestIdP
50
50
  onError?: (error: Error) => void;
51
51
  }
52
52
  declare const _default: FC<LocationInputProps & ForwardProps> & {
53
- getTestIds: (testIdProp?: string | undefined) => import("../../types").TestIdsRecord<readonly ["control", "label", "info", "additional-info", "suggestion-accept", "suggestion-reject"]>;
53
+ getTestIds: (testIdProp?: string | null | undefined) => import("../../types").TestIdsRecord<readonly ["control", "label", "info", "additional-info", "suggestion-accept", "suggestion-reject"]>;
54
54
  };
55
55
  export default _default;
56
56
  //# sourceMappingURL=LocationInput.d.ts.map