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

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.
@@ -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,8 +1,27 @@
1
1
  import type { FunctionComponent, Ref } from 'react';
2
- import type { BaseProps, ForwardProps, NoChildrenProp, TestIdProp } from '../../types';
2
+ import 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'> {
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,E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B,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,WAAW,CAAC,EAAE,gBAAgB,CAAC,aAAa,CAAC,CAAC;IAC9C,6GAA6G;IAC7G,IAAI,CAAC,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAChC,wEAAwE;IACxE,QAAQ,CAAC,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAC;IACxC,0DAA0D;IAC1D,QAAQ,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;;;;AAiZtF,wBAA2D"}
@@ -1,103 +1,41 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
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';
3
+ import { useConsolidatedRef, useI18n, useUID, useTestIds, usePrevious, useElement, useModalManager, useModalContext } from '../../hooks';
8
4
  import Flex from '../Flex';
9
5
  import Text from '../Text';
10
6
  import Icon, { registerIcon } from '../Icon';
11
7
  import * as paperClipIcon from '../Icon/icons/paper-clip.icon';
12
- import FormField from '../FormField';
13
8
  import Grid from '../Grid';
14
9
  import { getActiveElement, getFocusables, withTestIds } from '../../utils';
10
+ import Tooltip from '../Tooltip';
11
+ import Button from '../Button';
12
+ import Modal, {} from '../Modal';
15
13
  import { getFileInputTestIds } from './File.test-ids';
16
14
  import FileList from './FileList';
17
15
  import FileItem from './FileItem';
16
+ import { StyledBareButton, StyledDropZone, StyledFileInput, StyledIconWrapper, StyledAttachedFileCount, StyledSingleFileWrapper, StyledUploadStatus, StyledFlex, StyledFormField } from './FileInput.styles';
18
17
  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) {
18
+ const Component = props => {
19
+ const { compact, multiple, status, count, dragOver = false } = props;
20
+ const t = useI18n();
21
+ const attachedFileCount = multiple && count ? (_jsx(StyledAttachedFileCount, { children: t('number_of_items', [count], { count }) })) : undefined;
22
+ 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
23
+ ? attachedFileCount
24
+ : t('file_upload_text_main', [
25
+ t(multiple ? 'file_upload_text_multiple' : 'file_upload_text_one')
26
+ ]) }) }), _jsx(StyledIconWrapper, { container: { justify: 'center', alignItems: 'center' }, children: _jsx(Icon, { name: 'paper-clip' }) })] }));
27
+ };
28
+ const BaseFileInput = forwardRef(function FileInput(props, ref) {
93
29
  const uid = useUID();
94
- const { testId, id = uid, label, labelHidden, info, required = false, disabled = false, files, onFilesAdded, multiple = false, status, additionalInfo, accept, ...restProps } = props;
30
+ const { testId, id = uid, label, labelHidden, info, required = false, disabled = false, files, onFilesAdded, multiple = false, status, additionalInfo, accept, compact = false, previewFromActions = false, ...restProps } = props;
95
31
  const testIds = useTestIds(testId, getFileInputTestIds);
32
+ const [target, setTarget] = useElement();
96
33
  const inputRef = useConsolidatedRef(ref);
97
34
  const fileItemListRef = useRef();
98
35
  const activeElement = getActiveElement();
99
36
  const activeElementInList = fileItemListRef.current?.contains(activeElement);
100
37
  const isInputActiveElement = activeElement === inputRef.current;
38
+ const compactWithSingleAttach = compact && !multiple;
101
39
  const onChange = useCallback((e) => {
102
40
  if (e.target.files) {
103
41
  onFilesAdded?.(Array.from(e.target.files));
@@ -116,22 +54,35 @@ const FileInput = forwardRef(function FileInput(props, ref) {
116
54
  const t = useI18n();
117
55
  const [dragOver, setDragOver] = useState(false);
118
56
  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: () => {
57
+ 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: () => {
58
+ if (target) {
59
+ target.dispatchEvent(new Event('focusin'));
60
+ }
61
+ }, onBlur: () => {
62
+ if (target) {
63
+ target.dispatchEvent(new Event('focusout'));
64
+ }
65
+ }, multiple: multiple, accept: Array.isArray(accept) ? accept.join(',') : accept }), _jsx(Flex, { container: true, as: StyledDropZone, onClick: () => {
120
66
  inputRef.current?.focus();
121
67
  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 => {
68
+ }, ...(!disabled
69
+ ? {
70
+ onDragOver: (e) => {
71
+ e.preventDefault();
72
+ },
73
+ onDragEnter: () => setDragOver(true),
74
+ onDragLeave: () => setDragOver(false),
75
+ onDrop: (e) => {
76
+ e.preventDefault();
77
+ setDragOver(false);
78
+ onFilesAdded?.(Array.from(e.dataTransfer.files));
79
+ }
80
+ }
81
+ : 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')]) }))] }));
82
+ const fileItemList = hideFileInput ? (_jsx(StyledSingleFileWrapper, { "data-testid": testIds.files, compact: compact, ref: element => {
132
83
  if (element)
133
84
  fileItemListRef.current = element;
134
- }, children: _jsx(FileItem, { ...files[0] }) })) : (_jsx(FileList, { type: 'item', items: files ?? [], "data-testid": testIds.files, ref: element => {
85
+ }, children: _jsx(FileItem, { ...files[0], compact: compact, previewFromActions: compactWithSingleAttach && previewFromActions }) })) : (_jsx(FileList, { type: 'item', items: files ?? [], "data-testid": testIds.files, ref: element => {
135
86
  if (element)
136
87
  fileItemListRef.current = element;
137
88
  } }));
@@ -149,7 +100,79 @@ const FileInput = forwardRef(function FileInput(props, ref) {
149
100
  }
150
101
  }, [files]);
151
102
  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] }));
103
+ return (_jsxs(Grid, { container: { rowGap: hideFileInput ? undefined : 1 }, children: [label ? (_jsx(StyledFormField, { testId: testIds, label: label, labelHidden: labelHidden, id: id, info: info, required: required, disabled: !hideFileInput && disabled, status: status, additionalInfo: additionalInfo, compactMode: compactWithSingleAttach, children: renderElement })) : (renderElement), multiple && !compact && files && files.length > 0 && fileItemList] }));
104
+ });
105
+ const AttachFilesModal = ({ modalContent, modal }) => {
106
+ const t = useI18n();
107
+ const { dismiss } = useModalContext();
108
+ const formActions = (_jsxs(_Fragment, { children: [_jsx(Button, { disabled: modal?.loading, onClick: () => {
109
+ if (modal?.onCancel)
110
+ modal.onCancel({ close: dismiss });
111
+ }, children: t('cancel') }), _jsx(Button, { disabled: modal?.loading, type: 'submit', variant: 'primary', onClick: () => {
112
+ if (modal?.onSubmit)
113
+ modal.onSubmit({ close: dismiss });
114
+ }, children: t('submit') })] }));
115
+ return (_jsx(Modal, { progress: modal?.loading, heading: t('attach_files'), actions: formActions, onBeforeOpen: modal?.onBeforeOpen, children: modalContent }));
116
+ };
117
+ const FileInput = forwardRef(function FileInput(props, ref) {
118
+ const uid = useUID();
119
+ const { modal, count, ...baseFileInputProps } = props;
120
+ const { id = uid, label, labelHidden, info, required = false, disabled = false, onFilesAdded, multiple = false, status, additionalInfo, compact = false } = baseFileInputProps;
121
+ const t = useI18n();
122
+ const [dragOver, setDragOver] = useState(false);
123
+ const [buttonEl, setButtonEl] = useElement();
124
+ const { create } = useModalManager();
125
+ const modalMethods = useRef();
126
+ let modalContent;
127
+ if (compact && multiple) {
128
+ modalContent = (_jsx(BaseFileInput, { ...baseFileInputProps, multiple: true, compact: false, labelHidden: false, ref: ref }));
129
+ }
130
+ const modalProps = {
131
+ modal,
132
+ modalContent
133
+ };
134
+ useEffect(() => {
135
+ if (compact && multiple && modal) {
136
+ modalMethods.current?.update({
137
+ modal,
138
+ modalContent
139
+ });
140
+ }
141
+ }, [compact, multiple, modal, modalProps]);
142
+ useEffect(() => {
143
+ return () => {
144
+ if (modalMethods.current) {
145
+ modalMethods.current?.dismiss();
146
+ modalMethods.current?.unmount();
147
+ }
148
+ };
149
+ }, []);
150
+ if (compact && multiple) {
151
+ const render = (_jsxs(Flex, { container: true, children: [_jsx(StyledBareButton, { id: id, onClick: () => {
152
+ modalMethods.current = create(AttachFilesModal, { ...modalProps }, { dismissible: false });
153
+ }, "aria-label": count && count > 0
154
+ ? `${t('attach_review')} ${t('number_of_items', [count], { count })}`
155
+ : undefined, disabled: disabled, ...(!disabled
156
+ ? {
157
+ onDragOver: (e) => {
158
+ e.preventDefault();
159
+ },
160
+ onDragEnter: () => setDragOver(true),
161
+ onDragLeave: () => setDragOver(false),
162
+ onDrop: (e) => {
163
+ e.preventDefault();
164
+ setDragOver(false);
165
+ onFilesAdded?.(Array.from(e.dataTransfer.files));
166
+ if (buttonEl)
167
+ buttonEl.click();
168
+ }
169
+ }
170
+ : 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
171
+ ? t('attach_review')
172
+ : t('file_upload_text_main', [t('file_upload_text_multiple')]) }))] }));
173
+ 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);
174
+ }
175
+ return _jsx(BaseFileInput, { ...baseFileInputProps, ref: ref });
153
176
  });
154
177
  export default withTestIds(FileInput, getFileInputTestIds);
155
178
  //# sourceMappingURL=FileInput.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"FileInput.js","sourceRoot":"","sources":["../../../src/components/File/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ef, 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,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAM7E,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,QAAQ,MAAM,YAAY,CAAC;AAClC,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,uBAAuB,EACvB,uBAAu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,CAAC,SAAS,CAAC,EACd,GAAG,EAAE,WAAW,YAEhB,KAAC,UAAU,IAAC,SAAS,kBACnB,KAAC,SAAS,IACR,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,QAAQ,GAClB,GACS,GACI,EAClB,QAAQ,IAAI,CACX,KAAC,OAAO,IAAC,MAAM,EAAE,QAAQ,EAAE,cAAc,EAAE,KAAK,KAAK,CAAC,YACnD,KAAK,IAAI,KAAK,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, useRef, useState } from 'react';\nimport type { FunctionComponent, Ref, ChangeEvent, PropsWithoutRef, DragEvent } from 'react';\n\nimport 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} 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 /** 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 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 return (\n <Grid container={{ rowGap: hideFileInput ? undefined : 1 }}>\n {label ? (\n <StyledFormField\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 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"]}
@@ -0,0 +1,23 @@
1
+ import { type FormControlProps } from '../FormControl';
2
+ import type { FileInputProps } from './FileInput';
3
+ export declare const StyledDropZone: import("styled-components").StyledComponent<import("react").FunctionComponent<FormControlProps & import("../..").ForwardProps>, import("styled-components").DefaultTheme, {
4
+ compactMode: FileInputProps['compact'];
5
+ }, never>;
6
+ export declare const StyledUploadStatus: import("styled-components").StyledComponent<import("react").FunctionComponent<import("../Flex").FlexProps & import("../..").ForwardProps>, import("styled-components").DefaultTheme, {
7
+ status: FormControlProps['status'];
8
+ dragOver: boolean;
9
+ }, never>;
10
+ export declare const StyledIconWrapper: import("styled-components").StyledComponent<import("react").FunctionComponent<import("../Flex").FlexProps & import("../..").ForwardProps>, import("styled-components").DefaultTheme, {}, never>;
11
+ export declare const StyledFileInput: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
12
+ export declare const StyledSingleFileWrapper: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {
13
+ compact: FileInputProps['compact'];
14
+ }, never>;
15
+ export declare const StyledAttachedFileCount: import("styled-components").StyledComponent<"span", import("styled-components").DefaultTheme, {}, never>;
16
+ export declare const StyledFlex: import("styled-components").StyledComponent<import("react").FunctionComponent<import("../Flex").FlexProps & import("../..").ForwardProps>, import("styled-components").DefaultTheme, {}, never>;
17
+ export declare const StyledBareButton: import("styled-components").StyledComponent<import("react").FunctionComponent<import("../Button/BareButton").BareButtonProps & import("../..").ForwardProps>, import("styled-components").DefaultTheme, {}, never>;
18
+ export declare const StyledFormField: import("styled-components").StyledComponent<import("react").FC<import("../FormField").FormFieldProps & import("../..").ForwardProps> & {
19
+ getTestIds: (testIdProp?: string | null | undefined) => import("../..").TestIdsRecord<readonly ["label", "info", "additional-info", "suggestion-accept", "suggestion-reject"]>;
20
+ }, import("styled-components").DefaultTheme, {
21
+ compactMode: FileInputProps['compact'];
22
+ }, never>;
23
+ //# sourceMappingURL=FileInput.styles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FileInput.styles.d.ts","sourceRoot":"","sources":["../../../src/components/File/FileInput.styles.ts"],"names":[],"mappings":"AAGA,OAAoB,EAAE,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAMpE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAGlD,eAAO,MAAM,cAAc;iBAAsC,cAAc,CAAC,SAAS,CAAC;SAuBxF,CAAC;AAIH,eAAO,MAAM,kBAAkB;YACrB,gBAAgB,CAAC,QAAQ,CAAC;cACxB,OAAO;SAqCjB,CAAC;AAIH,eAAO,MAAM,iBAAiB,iMAa5B,CAAC;AAIH,eAAO,MAAM,eAAe,yGAgC3B,CAAC;AAIF,eAAO,MAAM,uBAAuB;aAAyB,cAAc,CAAC,SAAS,CAAC;SAarF,CAAC;AAEF,eAAO,MAAM,uBAAuB,0GAWnC,CAAC;AAIF,eAAO,MAAM,UAAU,iMAEtB,CAAC;AAEF,eAAO,MAAM,gBAAgB,oNAwC3B,CAAC;AAIH,eAAO,MAAM,eAAe;;;iBAAoC,cAAc,CAAC,SAAS,CAAC;SASvF,CAAC"}
@@ -0,0 +1,141 @@
1
+ import styled, { css } from 'styled-components';
2
+ import { hideVisually } from 'polished';
3
+ import FormControl, {} from '../FormControl';
4
+ import { defaultThemeProp } from '../../theme';
5
+ import Flex from '../Flex';
6
+ import BareButton from '../Button/BareButton';
7
+ import FormField from '../FormField';
8
+ import { StyledFileItem } from './FileItem';
9
+ export const StyledDropZone = styled(FormControl)(({ compactMode, theme: { base: { 'hit-area': { 'finger-min': fingerMin, compact } }, components } }) => {
10
+ return css `
11
+ height: ${components.input.height};
12
+ border: none;
13
+ cursor: pointer;
14
+
15
+ ${compactMode &&
16
+ css `
17
+ height: ${compact};
18
+ `}
19
+
20
+ @media (pointer: coarse) {
21
+ height: ${fingerMin};
22
+ }
23
+ `;
24
+ });
25
+ StyledDropZone.defaultProps = defaultThemeProp;
26
+ export const StyledUploadStatus = styled(Flex)(({ dragOver, status, theme: { base: { 'border-radius': borderRadius }, components: { 'form-field': formField, 'form-control': { 'border-color': borderColor, ':hover': { 'border-color': hoverBorderColor } } } } }) => {
27
+ return css `
28
+ border: 0.0625rem dashed ${borderColor};
29
+ border-start-start-radius: calc(0.5 * ${borderRadius});
30
+ border-end-start-radius: calc(0.5 * ${borderRadius});
31
+
32
+ ${status &&
33
+ css `
34
+ border-color: ${formField[status]['status-color']};
35
+ `};
36
+
37
+ ${dragOver &&
38
+ css `
39
+ border-style: solid;
40
+ `}
41
+
42
+ &:hover:not([disabled]):not(:focus, :focus-within) {
43
+ ${!status &&
44
+ css `
45
+ border-color: ${hoverBorderColor};
46
+ `}
47
+ }
48
+ `;
49
+ });
50
+ StyledUploadStatus.defaultProps = defaultThemeProp;
51
+ export const StyledIconWrapper = styled(Flex)(({ theme: { base: { 'border-radius': borderRadius }, components } }) => {
52
+ return css `
53
+ border: 0.0625rem solid ${components['form-control']['border-color']};
54
+ border-start-end-radius: calc(0.5 * ${borderRadius});
55
+ border-end-end-radius: calc(0.5 * ${borderRadius});
56
+ border-inline-start: none;
57
+ aspect-ratio: 1 / 1;
58
+ `;
59
+ });
60
+ StyledIconWrapper.defaultProps = defaultThemeProp;
61
+ export const StyledFileInput = styled.div(({ theme: { components: { 'form-control': { 'border-color': borderColor, ':focus': { 'box-shadow': boxShadow } } } } }) => {
62
+ return css `
63
+ position: relative;
64
+
65
+ input {
66
+ ${hideVisually}
67
+ }
68
+
69
+ input:enabled:focus + ${StyledDropZone} {
70
+ box-shadow: ${boxShadow};
71
+
72
+ > ${StyledIconWrapper} {
73
+ border: none;
74
+ }
75
+ > ${StyledUploadStatus} {
76
+ border-block: none;
77
+ border-inline-start: none;
78
+ border-inline-end: 0.0625rem dashed ${borderColor};
79
+ }
80
+ }
81
+ `;
82
+ });
83
+ StyledFileInput.defaultProps = defaultThemeProp;
84
+ export const StyledSingleFileWrapper = styled.div(({ compact }) => {
85
+ return css `
86
+ display: contents;
87
+
88
+ ${compact &&
89
+ css `
90
+ > ${StyledFileItem} {
91
+ width: 25ch;
92
+ }
93
+ `};
94
+ `;
95
+ });
96
+ export const StyledAttachedFileCount = styled.span(({ theme: { base: { palette, spacing } } }) => {
97
+ return css `
98
+ padding-inline-start: ${spacing};
99
+ color: ${palette.interactive};
100
+ `;
101
+ });
102
+ StyledAttachedFileCount.defaultProps = defaultThemeProp;
103
+ export const StyledFlex = styled(Flex) `
104
+ height: inherit;
105
+ `;
106
+ export const StyledBareButton = styled(BareButton)(({ theme: { base: { palette, 'hit-area': { 'finger-min': fingerMin, compact }, 'border-radius': baseRadius }, components: { 'form-control': { 'border-color': borderColor, 'border-radius': radius, ':focus': { 'box-shadow': boxShadow } } } } }) => {
107
+ return css `
108
+ height: ${compact};
109
+ width: 25ch;
110
+ cursor: pointer;
111
+ border-radius: calc(${baseRadius} * ${radius});
112
+ background-color: ${palette['primary-background']};
113
+
114
+ @media (pointer: coarse) {
115
+ height: ${fingerMin};
116
+ }
117
+
118
+ &:focus {
119
+ box-shadow: ${boxShadow};
120
+
121
+ ${StyledIconWrapper} {
122
+ border: none;
123
+ }
124
+ ${StyledUploadStatus} {
125
+ border-block: none;
126
+ border-inline-start: none;
127
+ border-inline-end: 0.0625rem dashed ${borderColor};
128
+ }
129
+ }
130
+ `;
131
+ });
132
+ StyledBareButton.defaultProps = defaultThemeProp;
133
+ export const StyledFormField = styled(FormField)(({ compactMode }) => {
134
+ return css `
135
+ ${compactMode &&
136
+ css `
137
+ width: 25ch;
138
+ `};
139
+ `;
140
+ });
141
+ //# sourceMappingURL=FileInput.styles.js.map