@cloudscape-design/components 3.0.623 → 3.0.625
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.
- package/alert/index.d.ts.map +1 -1
- package/alert/index.js +9 -5
- package/alert/index.js.map +1 -1
- package/attribute-editor/interfaces.d.ts +4 -0
- package/attribute-editor/interfaces.d.ts.map +1 -1
- package/attribute-editor/interfaces.js.map +1 -1
- package/attribute-editor/row.d.ts.map +1 -1
- package/attribute-editor/row.js +4 -1
- package/attribute-editor/row.js.map +1 -1
- package/container/index.js +1 -1
- package/container/index.js.map +1 -1
- package/date-picker/index.d.ts.map +1 -1
- package/date-picker/index.js +2 -2
- package/date-picker/index.js.map +1 -1
- package/date-range-picker/index.d.ts.map +1 -1
- package/date-range-picker/index.js +2 -2
- package/date-range-picker/index.js.map +1 -1
- package/file-upload/interfaces.d.ts +14 -4
- package/file-upload/interfaces.d.ts.map +1 -1
- package/file-upload/interfaces.js.map +1 -1
- package/file-upload/internal.js +13 -7
- package/file-upload/internal.js.map +1 -1
- package/form/index.d.ts.map +1 -1
- package/form/index.js +17 -6
- package/form/index.js.map +1 -1
- package/form/internal.d.ts.map +1 -1
- package/form/internal.js +1 -14
- package/form/internal.js.map +1 -1
- package/form-field/index.d.ts.map +1 -1
- package/form-field/index.js +3 -2
- package/form-field/index.js.map +1 -1
- package/form-field/interfaces.d.ts +12 -1
- package/form-field/interfaces.d.ts.map +1 -1
- package/form-field/interfaces.js.map +1 -1
- package/form-field/internal.d.ts +9 -3
- package/form-field/internal.d.ts.map +1 -1
- package/form-field/internal.js +39 -13
- package/form-field/internal.js.map +1 -1
- package/form-field/styles.css.js +23 -19
- package/form-field/styles.scoped.css +45 -29
- package/form-field/styles.selectors.js +23 -19
- package/form-field/util.d.ts +3 -2
- package/form-field/util.d.ts.map +1 -1
- package/form-field/util.js +4 -3
- package/form-field/util.js.map +1 -1
- package/input/index.d.ts.map +1 -1
- package/input/index.js +2 -1
- package/input/index.js.map +1 -1
- package/input/internal.d.ts.map +1 -1
- package/input/internal.js +4 -1
- package/input/internal.js.map +1 -1
- package/input/styles.css.js +13 -12
- package/input/styles.scoped.css +46 -30
- package/input/styles.selectors.js +13 -12
- package/internal/analytics/components/analytics-funnel.d.ts +12 -12
- package/internal/analytics/components/analytics-funnel.d.ts.map +1 -1
- package/internal/analytics/components/analytics-funnel.js +38 -25
- package/internal/analytics/components/analytics-funnel.js.map +1 -1
- package/internal/analytics/context/analytics-context.d.ts +7 -2
- package/internal/analytics/context/analytics-context.d.ts.map +1 -1
- package/internal/analytics/context/analytics-context.js.map +1 -1
- package/internal/analytics/hooks/use-funnel.d.ts +5 -1
- package/internal/analytics/hooks/use-funnel.d.ts.map +1 -1
- package/internal/analytics/hooks/use-funnel.js +9 -5
- package/internal/analytics/hooks/use-funnel.js.map +1 -1
- package/internal/analytics/interfaces.d.ts +23 -37
- package/internal/analytics/interfaces.d.ts.map +1 -1
- package/internal/analytics/interfaces.js.map +1 -1
- package/internal/base-component/index.d.ts +1 -1
- package/internal/base-component/index.d.ts.map +1 -1
- package/internal/base-component/index.js +1 -1
- package/internal/base-component/index.js.map +1 -1
- package/internal/components/button-trigger/index.d.ts +1 -0
- package/internal/components/button-trigger/index.d.ts.map +1 -1
- package/internal/components/button-trigger/index.js +2 -2
- package/internal/components/button-trigger/index.js.map +1 -1
- package/internal/components/button-trigger/styles.css.js +11 -10
- package/internal/components/button-trigger/styles.scoped.css +35 -24
- package/internal/components/button-trigger/styles.selectors.js +11 -10
- package/internal/components/responsive-text/index.d.ts +1 -1
- package/internal/components/responsive-text/index.d.ts.map +1 -1
- package/internal/components/responsive-text/index.js +9 -4
- package/internal/components/responsive-text/index.js.map +1 -1
- package/internal/context/form-field-context.d.ts +14 -1
- package/internal/context/form-field-context.d.ts.map +1 -1
- package/internal/context/form-field-context.js +1 -1
- package/internal/context/form-field-context.js.map +1 -1
- package/internal/environment.js +1 -1
- package/internal/environment.json +1 -1
- package/internal/manifest.json +1 -1
- package/link/internal.d.ts.map +1 -1
- package/link/internal.js +9 -3
- package/link/internal.js.map +1 -1
- package/modal/body-scroll.d.ts.map +1 -1
- package/modal/body-scroll.js +5 -0
- package/modal/body-scroll.js.map +1 -1
- package/package.json +1 -1
- package/pie-chart/responsive-text.d.ts.map +1 -1
- package/pie-chart/responsive-text.js +5 -1
- package/pie-chart/responsive-text.js.map +1 -1
- package/select/parts/filter.d.ts +1 -1
- package/select/parts/filter.d.ts.map +1 -1
- package/select/parts/trigger.d.ts.map +1 -1
- package/select/parts/trigger.js +2 -2
- package/select/parts/trigger.js.map +1 -1
- package/test-utils/dom/file-upload/index.d.ts +2 -0
- package/test-utils/dom/file-upload/index.js +6 -0
- package/test-utils/dom/file-upload/index.js.map +1 -1
- package/test-utils/dom/form-field/index.d.ts +1 -0
- package/test-utils/dom/form-field/index.js +3 -0
- package/test-utils/dom/form-field/index.js.map +1 -1
- package/test-utils/selectors/file-upload/index.d.ts +2 -0
- package/test-utils/selectors/file-upload/index.js +6 -0
- package/test-utils/selectors/file-upload/index.js.map +1 -1
- package/test-utils/selectors/form-field/index.d.ts +1 -0
- package/test-utils/selectors/form-field/index.js +3 -0
- package/test-utils/selectors/form-field/index.js.map +1 -1
- package/test-utils/tsconfig.tsbuildinfo +1 -1
- package/textarea/index.d.ts.map +1 -1
- package/textarea/index.js +2 -1
- package/textarea/index.js.map +1 -1
- package/textarea/styles.css.js +5 -4
- package/textarea/styles.scoped.css +23 -12
- package/textarea/styles.selectors.js +5 -4
- package/token-group/styles.css.js +9 -8
- package/token-group/styles.scoped.css +27 -16
- package/token-group/styles.selectors.js +9 -8
- package/token-group/token.d.ts +3 -1
- package/token-group/token.d.ts.map +1 -1
- package/token-group/token.js +8 -5
- package/token-group/token.js.map +1 -1
- package/wizard/analytics.d.ts +2 -1
- package/wizard/analytics.d.ts.map +1 -1
- package/wizard/analytics.js +7 -3
- package/wizard/analytics.js.map +1 -1
- package/wizard/index.js +1 -1
- package/wizard/index.js.map +1 -1
- package/wizard/internal.d.ts.map +1 -1
- package/wizard/internal.js +2 -2
- package/wizard/internal.js.map +1 -1
- package/wizard/wizard-form.d.ts +4 -2
- package/wizard/wizard-form.d.ts.map +1 -1
- package/wizard/wizard-form.js +31 -19
- package/wizard/wizard-form.js.map +1 -1
package/file-upload/internal.js
CHANGED
|
@@ -14,7 +14,7 @@ import { Dropzone, useDropzoneVisible } from './dropzone';
|
|
|
14
14
|
import FileInput from './file-input';
|
|
15
15
|
import TokenList from '../internal/components/token-list';
|
|
16
16
|
import { Token } from '../token-group/token';
|
|
17
|
-
import { ConstraintText, FormFieldError } from '../form-field/internal';
|
|
17
|
+
import { ConstraintText, FormFieldError, FormFieldWarning } from '../form-field/internal';
|
|
18
18
|
import { useUniqueId } from '../internal/hooks/use-unique-id';
|
|
19
19
|
import { useMergeRefs } from '../internal/hooks/use-merge-refs';
|
|
20
20
|
import { joinStrings } from '../internal/utils/strings';
|
|
@@ -23,10 +23,11 @@ import InternalBox from '../box/internal';
|
|
|
23
23
|
export default React.forwardRef(InternalFileUpload);
|
|
24
24
|
function InternalFileUpload(_a, externalRef) {
|
|
25
25
|
var _b;
|
|
26
|
-
var { accept, ariaRequired, multiple = false, onChange, value, tokenLimit, showFileSize, showFileLastModified, showFileThumbnail, i18nStrings, __internalRootRef = null, constraintText, errorText, fileErrors } = _a, restProps = __rest(_a, ["accept", "ariaRequired", "multiple", "onChange", "value", "tokenLimit", "showFileSize", "showFileLastModified", "showFileThumbnail", "i18nStrings", "__internalRootRef", "constraintText", "errorText", "fileErrors"]);
|
|
26
|
+
var { accept, ariaRequired, multiple = false, onChange, value, tokenLimit, showFileSize, showFileLastModified, showFileThumbnail, i18nStrings, __internalRootRef = null, constraintText, errorText, warningText, fileErrors, fileWarnings } = _a, restProps = __rest(_a, ["accept", "ariaRequired", "multiple", "onChange", "value", "tokenLimit", "showFileSize", "showFileLastModified", "showFileThumbnail", "i18nStrings", "__internalRootRef", "constraintText", "errorText", "warningText", "fileErrors", "fileWarnings"]);
|
|
27
27
|
const baseProps = getBaseProps(restProps);
|
|
28
28
|
const metadata = { showFileSize, showFileLastModified, showFileThumbnail };
|
|
29
29
|
const errorId = useUniqueId('error-');
|
|
30
|
+
const warningId = useUniqueId('warning-');
|
|
30
31
|
const constraintTextId = useUniqueId('constraint-text-');
|
|
31
32
|
const fileInputRef = useRef(null);
|
|
32
33
|
const ref = useMergeRefs(fileInputRef, externalRef);
|
|
@@ -49,21 +50,26 @@ function InternalFileUpload(_a, externalRef) {
|
|
|
49
50
|
}
|
|
50
51
|
};
|
|
51
52
|
const isDropzoneVisible = useDropzoneVisible(multiple);
|
|
53
|
+
const showWarning = warningText && !errorText;
|
|
54
|
+
if (warningText && errorText) {
|
|
55
|
+
warnOnce('FileUpload', 'Both `errorText` and `warningText` exist. `warningText` will not be shown.');
|
|
56
|
+
}
|
|
52
57
|
const formFieldContext = useFormFieldContext(restProps);
|
|
53
|
-
const ariaDescribedBy = joinStrings((_b = restProps.ariaDescribedby) !== null && _b !== void 0 ? _b : formFieldContext.ariaDescribedby, errorText ? errorId : undefined, constraintText ? constraintTextId : undefined);
|
|
58
|
+
const ariaDescribedBy = joinStrings((_b = restProps.ariaDescribedby) !== null && _b !== void 0 ? _b : formFieldContext.ariaDescribedby, errorText ? errorId : undefined, showWarning ? warningId : undefined, constraintText ? constraintTextId : undefined);
|
|
54
59
|
const hasError = Boolean(errorText || (fileErrors === null || fileErrors === void 0 ? void 0 : fileErrors.filter(Boolean).length));
|
|
55
60
|
const invalid = restProps.invalid || formFieldContext.invalid || hasError;
|
|
56
61
|
return (React.createElement(InternalSpaceBetween, Object.assign({}, baseProps, { size: "xs", className: clsx(baseProps.className, styles.root), __internalRootRef: __internalRootRef }),
|
|
57
62
|
React.createElement(InternalBox, null,
|
|
58
63
|
isDropzoneVisible ? (React.createElement(Dropzone, { onChange: handleFilesChange }, i18nStrings.dropzoneText(multiple))) : (React.createElement(FileInput, Object.assign({ ref: ref, accept: accept, ariaRequired: ariaRequired, multiple: multiple, onChange: handleFilesChange, value: value }, restProps, { ariaDescribedby: ariaDescribedBy, invalid: invalid }), i18nStrings.uploadButtonText(multiple))),
|
|
59
|
-
(constraintText || errorText) && (React.createElement("div", { className: styles.hints },
|
|
64
|
+
(constraintText || errorText || warningText) && (React.createElement("div", { className: styles.hints },
|
|
60
65
|
errorText && (React.createElement(FormFieldError, { id: errorId, errorIconAriaLabel: i18nStrings === null || i18nStrings === void 0 ? void 0 : i18nStrings.errorIconAriaLabel }, errorText)),
|
|
61
|
-
|
|
66
|
+
showWarning && (React.createElement(FormFieldWarning, { id: warningId, warningIconAriaLabel: i18nStrings === null || i18nStrings === void 0 ? void 0 : i18nStrings.warningIconAriaLabel }, warningText)),
|
|
67
|
+
constraintText && (React.createElement(ConstraintText, { id: constraintTextId, hasValidationText: !!errorText || !!warningText }, constraintText))))),
|
|
62
68
|
!multiple && value.length > 0 ? (React.createElement(InternalBox, null,
|
|
63
|
-
React.createElement(Token, { ariaLabel: value[0].name, dismissLabel: i18nStrings.removeFileAriaLabel(0), onDismiss: () => onFileRemove(0), errorText: fileErrors === null || fileErrors === void 0 ? void 0 : fileErrors[0], errorIconAriaLabel: i18nStrings.errorIconAriaLabel, "data-index": 0 },
|
|
69
|
+
React.createElement(Token, { ariaLabel: value[0].name, dismissLabel: i18nStrings.removeFileAriaLabel(0), onDismiss: () => onFileRemove(0), errorText: fileErrors === null || fileErrors === void 0 ? void 0 : fileErrors[0], warningText: fileWarnings === null || fileWarnings === void 0 ? void 0 : fileWarnings[0], errorIconAriaLabel: i18nStrings.errorIconAriaLabel, warningIconAriaLabel: i18nStrings.warningIconAriaLabel, "data-index": 0 },
|
|
64
70
|
React.createElement(FileOption, { file: value[0], metadata: metadata, i18nStrings: i18nStrings })))) : null,
|
|
65
71
|
multiple && value.length > 0 ? (React.createElement(InternalBox, null,
|
|
66
|
-
React.createElement(TokenList, { alignment: "vertical", items: value, renderItem: (file, fileIndex) => (React.createElement(Token, { ariaLabel: file.name, dismissLabel: i18nStrings.removeFileAriaLabel(fileIndex), onDismiss: () => onFileRemove(fileIndex), errorText: fileErrors === null || fileErrors === void 0 ? void 0 : fileErrors[fileIndex], errorIconAriaLabel: i18nStrings.errorIconAriaLabel, "data-index": fileIndex },
|
|
72
|
+
React.createElement(TokenList, { alignment: "vertical", items: value, renderItem: (file, fileIndex) => (React.createElement(Token, { ariaLabel: file.name, dismissLabel: i18nStrings.removeFileAriaLabel(fileIndex), onDismiss: () => onFileRemove(fileIndex), errorText: fileErrors === null || fileErrors === void 0 ? void 0 : fileErrors[fileIndex], warningText: fileWarnings === null || fileWarnings === void 0 ? void 0 : fileWarnings[fileIndex], errorIconAriaLabel: i18nStrings.errorIconAriaLabel, warningIconAriaLabel: i18nStrings.warningIconAriaLabel, "data-index": fileIndex },
|
|
67
73
|
React.createElement(FileOption, { file: file, metadata: metadata, i18nStrings: i18nStrings }))), limit: tokenLimit, i18nStrings: {
|
|
68
74
|
limitShowFewer: i18nStrings.limitShowFewer,
|
|
69
75
|
limitShowMore: i18nStrings.limitShowMore,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/file-upload/internal.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;;AAEtC,OAAO,KAAK,EAAE,EAAgB,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAI9D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,oBAAoB,MAAM,2BAA2B,CAAC;AAC7D,OAAO,MAAM,MAAM,iBAAiB,CAAC;AACrC,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,eAAe,MAAM,oCAAoC,CAAC;AACjE,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,MAAM,+CAA+C,CAAC;A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B,gBACtC,SAAS;oBAErB,oBAAC,UAAU,IAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,WAAW,GAAI,CAClE,CACT,EACD,KAAK,EAAE,UAAU,EACjB,WAAW,EAAE;oBACX,cAAc,EAAE,WAAW,CAAC,cAAc;oBAC1C,aAAa,EAAE,WAAW,CAAC,aAAa;iBACzC,EACD,oBAAoB,EAAE,gBAAgB,GACtC,CACU,CACf,CAAC,CAAC,CAAC,IAAI,CACa,CACxB,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport React, { ForwardedRef, useRef, useState } from 'react';\nimport { FileUploadProps } from './interfaces';\nimport { InternalBaseComponentProps } from '../internal/hooks/use-base-component';\n\nimport { FileOption } from './file-option';\nimport { ButtonProps } from '../button/interfaces';\nimport InternalSpaceBetween from '../space-between/internal';\nimport styles from './styles.css.js';\nimport { fireNonCancelableEvent } from '../internal/events';\nimport { getBaseProps } from '../internal/base-component';\nimport checkControlled from '../internal/hooks/check-controlled';\nimport clsx from 'clsx';\nimport { warnOnce } from '@cloudscape-design/component-toolkit/internal';\nimport { Dropzone, useDropzoneVisible } from './dropzone';\nimport FileInput from './file-input';\nimport TokenList from '../internal/components/token-list';\nimport { Token } from '../token-group/token';\nimport { ConstraintText, FormFieldError } from '../form-field/internal';\nimport { useUniqueId } from '../internal/hooks/use-unique-id';\nimport { useMergeRefs } from '../internal/hooks/use-merge-refs';\nimport { joinStrings } from '../internal/utils/strings';\nimport { useFormFieldContext } from '../contexts/form-field';\nimport InternalBox from '../box/internal';\n\ntype InternalFileUploadProps = FileUploadProps & InternalBaseComponentProps;\n\nexport default React.forwardRef(InternalFileUpload);\n\nfunction InternalFileUpload(\n {\n accept,\n ariaRequired,\n multiple = false,\n onChange,\n value,\n tokenLimit,\n showFileSize,\n showFileLastModified,\n showFileThumbnail,\n i18nStrings,\n __internalRootRef = null,\n constraintText,\n errorText,\n fileErrors,\n ...restProps\n }: InternalFileUploadProps,\n externalRef: ForwardedRef<ButtonProps.Ref>\n) {\n const baseProps = getBaseProps(restProps);\n const metadata = { showFileSize, showFileLastModified, showFileThumbnail };\n\n const errorId = useUniqueId('error-');\n const constraintTextId = useUniqueId('constraint-text-');\n\n const fileInputRef = useRef<ButtonProps.Ref>(null);\n const ref = useMergeRefs(fileInputRef, externalRef);\n\n const [removedFileIndex, setRemovedFileIndex] = useState<null | number>(null);\n\n checkControlled('FileUpload', 'value', value, 'onChange', onChange);\n\n if (!multiple && value.length > 1) {\n warnOnce('FileUpload', 'Value must be an array of size 0 or 1 when `multiple=false`.');\n }\n\n const handleFilesChange = (newFiles: File[]) => {\n const newValue = multiple ? [...value, ...newFiles] : newFiles[0] ? newFiles : [...value];\n fireNonCancelableEvent(onChange, { value: newValue });\n };\n\n const onFileRemove = (removeFileIndex: number) => {\n const newValue = value.filter((_, fileIndex) => fileIndex !== removeFileIndex);\n fireNonCancelableEvent(onChange, { value: newValue });\n setRemovedFileIndex(removeFileIndex);\n if (value.length === 1) {\n fileInputRef.current?.focus();\n }\n };\n\n const isDropzoneVisible = useDropzoneVisible(multiple);\n\n const formFieldContext = useFormFieldContext(restProps);\n const ariaDescribedBy = joinStrings(\n restProps.ariaDescribedby ?? formFieldContext.ariaDescribedby,\n errorText ? errorId : undefined,\n constraintText ? constraintTextId : undefined\n );\n\n const hasError = Boolean(errorText || fileErrors?.filter(Boolean).length);\n const invalid = restProps.invalid || formFieldContext.invalid || hasError;\n\n return (\n <InternalSpaceBetween\n {...baseProps}\n size=\"xs\"\n className={clsx(baseProps.className, styles.root)}\n __internalRootRef={__internalRootRef}\n >\n <InternalBox>\n {isDropzoneVisible ? (\n <Dropzone onChange={handleFilesChange}>{i18nStrings.dropzoneText(multiple)}</Dropzone>\n ) : (\n <FileInput\n ref={ref}\n accept={accept}\n ariaRequired={ariaRequired}\n multiple={multiple}\n onChange={handleFilesChange}\n value={value}\n {...restProps}\n ariaDescribedby={ariaDescribedBy}\n invalid={invalid}\n >\n {i18nStrings.uploadButtonText(multiple)}\n </FileInput>\n )}\n\n {(constraintText || errorText) && (\n <div className={styles.hints}>\n {errorText && (\n <FormFieldError id={errorId} errorIconAriaLabel={i18nStrings?.errorIconAriaLabel}>\n {errorText}\n </FormFieldError>\n )}\n {constraintText && (\n <ConstraintText id={constraintTextId} hasError={!!errorText}>\n {constraintText}\n </ConstraintText>\n )}\n </div>\n )}\n </InternalBox>\n\n {!multiple && value.length > 0 ? (\n <InternalBox>\n <Token\n ariaLabel={value[0].name}\n dismissLabel={i18nStrings.removeFileAriaLabel(0)}\n onDismiss={() => onFileRemove(0)}\n errorText={fileErrors?.[0]}\n errorIconAriaLabel={i18nStrings.errorIconAriaLabel}\n data-index={0}\n >\n <FileOption file={value[0]} metadata={metadata} i18nStrings={i18nStrings} />\n </Token>\n </InternalBox>\n ) : null}\n\n {multiple && value.length > 0 ? (\n <InternalBox>\n <TokenList\n alignment=\"vertical\"\n items={value}\n renderItem={(file, fileIndex) => (\n <Token\n ariaLabel={file.name}\n dismissLabel={i18nStrings.removeFileAriaLabel(fileIndex)}\n onDismiss={() => onFileRemove(fileIndex)}\n errorText={fileErrors?.[fileIndex]}\n errorIconAriaLabel={i18nStrings.errorIconAriaLabel}\n data-index={fileIndex}\n >\n <FileOption file={file} metadata={metadata} i18nStrings={i18nStrings} />\n </Token>\n )}\n limit={tokenLimit}\n i18nStrings={{\n limitShowFewer: i18nStrings.limitShowFewer,\n limitShowMore: i18nStrings.limitShowMore,\n }}\n moveFocusNextToIndex={removedFileIndex}\n />\n </InternalBox>\n ) : null}\n </InternalSpaceBetween>\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/file-upload/internal.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;;AAEtC,OAAO,KAAK,EAAE,EAAgB,MAAM,EAAE,QAAQ,EAAE,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,KAAK,EAAE,UAAU,EACjB,WAAW,EAAE;oBACX,cAAc,EAAE,WAAW,CAAC,cAAc;oBAC1C,aAAa,EAAE,WAAW,CAAC,aAAa;iBACzC,EACD,oBAAoB,EAAE,gBAAgB,GACtC,CACU,CACf,CAAC,CAAC,CAAC,IAAI,CACa,CACxB,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport React, { ForwardedRef, useRef, useState } from 'react';\nimport { FileUploadProps } from './interfaces';\nimport { InternalBaseComponentProps } from '../internal/hooks/use-base-component';\n\nimport { FileOption } from './file-option';\nimport { ButtonProps } from '../button/interfaces';\nimport InternalSpaceBetween from '../space-between/internal';\nimport styles from './styles.css.js';\nimport { fireNonCancelableEvent } from '../internal/events';\nimport { getBaseProps } from '../internal/base-component';\nimport checkControlled from '../internal/hooks/check-controlled';\nimport clsx from 'clsx';\nimport { warnOnce } from '@cloudscape-design/component-toolkit/internal';\nimport { Dropzone, useDropzoneVisible } from './dropzone';\nimport FileInput from './file-input';\nimport TokenList from '../internal/components/token-list';\nimport { Token } from '../token-group/token';\nimport { ConstraintText, FormFieldError, FormFieldWarning } from '../form-field/internal';\nimport { useUniqueId } from '../internal/hooks/use-unique-id';\nimport { useMergeRefs } from '../internal/hooks/use-merge-refs';\nimport { joinStrings } from '../internal/utils/strings';\nimport { useFormFieldContext } from '../contexts/form-field';\nimport InternalBox from '../box/internal';\n\ntype InternalFileUploadProps = FileUploadProps & InternalBaseComponentProps;\n\nexport default React.forwardRef(InternalFileUpload);\n\nfunction InternalFileUpload(\n {\n accept,\n ariaRequired,\n multiple = false,\n onChange,\n value,\n tokenLimit,\n showFileSize,\n showFileLastModified,\n showFileThumbnail,\n i18nStrings,\n __internalRootRef = null,\n constraintText,\n errorText,\n warningText,\n fileErrors,\n fileWarnings,\n ...restProps\n }: InternalFileUploadProps,\n externalRef: ForwardedRef<ButtonProps.Ref>\n) {\n const baseProps = getBaseProps(restProps);\n const metadata = { showFileSize, showFileLastModified, showFileThumbnail };\n\n const errorId = useUniqueId('error-');\n const warningId = useUniqueId('warning-');\n const constraintTextId = useUniqueId('constraint-text-');\n\n const fileInputRef = useRef<ButtonProps.Ref>(null);\n const ref = useMergeRefs(fileInputRef, externalRef);\n\n const [removedFileIndex, setRemovedFileIndex] = useState<null | number>(null);\n\n checkControlled('FileUpload', 'value', value, 'onChange', onChange);\n\n if (!multiple && value.length > 1) {\n warnOnce('FileUpload', 'Value must be an array of size 0 or 1 when `multiple=false`.');\n }\n\n const handleFilesChange = (newFiles: File[]) => {\n const newValue = multiple ? [...value, ...newFiles] : newFiles[0] ? newFiles : [...value];\n fireNonCancelableEvent(onChange, { value: newValue });\n };\n\n const onFileRemove = (removeFileIndex: number) => {\n const newValue = value.filter((_, fileIndex) => fileIndex !== removeFileIndex);\n fireNonCancelableEvent(onChange, { value: newValue });\n setRemovedFileIndex(removeFileIndex);\n if (value.length === 1) {\n fileInputRef.current?.focus();\n }\n };\n\n const isDropzoneVisible = useDropzoneVisible(multiple);\n\n const showWarning = warningText && !errorText;\n\n if (warningText && errorText) {\n warnOnce('FileUpload', 'Both `errorText` and `warningText` exist. `warningText` will not be shown.');\n }\n\n const formFieldContext = useFormFieldContext(restProps);\n const ariaDescribedBy = joinStrings(\n restProps.ariaDescribedby ?? formFieldContext.ariaDescribedby,\n errorText ? errorId : undefined,\n showWarning ? warningId : undefined,\n constraintText ? constraintTextId : undefined\n );\n\n const hasError = Boolean(errorText || fileErrors?.filter(Boolean).length);\n const invalid = restProps.invalid || formFieldContext.invalid || hasError;\n\n return (\n <InternalSpaceBetween\n {...baseProps}\n size=\"xs\"\n className={clsx(baseProps.className, styles.root)}\n __internalRootRef={__internalRootRef}\n >\n <InternalBox>\n {isDropzoneVisible ? (\n <Dropzone onChange={handleFilesChange}>{i18nStrings.dropzoneText(multiple)}</Dropzone>\n ) : (\n <FileInput\n ref={ref}\n accept={accept}\n ariaRequired={ariaRequired}\n multiple={multiple}\n onChange={handleFilesChange}\n value={value}\n {...restProps}\n ariaDescribedby={ariaDescribedBy}\n invalid={invalid}\n >\n {i18nStrings.uploadButtonText(multiple)}\n </FileInput>\n )}\n\n {(constraintText || errorText || warningText) && (\n <div className={styles.hints}>\n {errorText && (\n <FormFieldError id={errorId} errorIconAriaLabel={i18nStrings?.errorIconAriaLabel}>\n {errorText}\n </FormFieldError>\n )}\n {showWarning && (\n <FormFieldWarning id={warningId} warningIconAriaLabel={i18nStrings?.warningIconAriaLabel}>\n {warningText}\n </FormFieldWarning>\n )}\n {constraintText && (\n <ConstraintText id={constraintTextId} hasValidationText={!!errorText || !!warningText}>\n {constraintText}\n </ConstraintText>\n )}\n </div>\n )}\n </InternalBox>\n\n {!multiple && value.length > 0 ? (\n <InternalBox>\n <Token\n ariaLabel={value[0].name}\n dismissLabel={i18nStrings.removeFileAriaLabel(0)}\n onDismiss={() => onFileRemove(0)}\n errorText={fileErrors?.[0]}\n warningText={fileWarnings?.[0]}\n errorIconAriaLabel={i18nStrings.errorIconAriaLabel}\n warningIconAriaLabel={i18nStrings.warningIconAriaLabel}\n data-index={0}\n >\n <FileOption file={value[0]} metadata={metadata} i18nStrings={i18nStrings} />\n </Token>\n </InternalBox>\n ) : null}\n\n {multiple && value.length > 0 ? (\n <InternalBox>\n <TokenList\n alignment=\"vertical\"\n items={value}\n renderItem={(file, fileIndex) => (\n <Token\n ariaLabel={file.name}\n dismissLabel={i18nStrings.removeFileAriaLabel(fileIndex)}\n onDismiss={() => onFileRemove(fileIndex)}\n errorText={fileErrors?.[fileIndex]}\n warningText={fileWarnings?.[fileIndex]}\n errorIconAriaLabel={i18nStrings.errorIconAriaLabel}\n warningIconAriaLabel={i18nStrings.warningIconAriaLabel}\n data-index={fileIndex}\n >\n <FileOption file={file} metadata={metadata} i18nStrings={i18nStrings} />\n </Token>\n )}\n limit={tokenLimit}\n i18nStrings={{\n limitShowFewer: i18nStrings.limitShowFewer,\n limitShowMore: i18nStrings.limitShowMore,\n }}\n moveFocusNextToIndex={removedFileIndex}\n />\n </InternalBox>\n ) : null}\n </InternalSpaceBetween>\n );\n}\n"]}
|
package/form/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/form/index.tsx"],"names":[],"mappings":";AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/form/index.tsx"],"names":[],"mappings":";AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAazC,OAAO,EAAE,SAAS,EAAE,CAAC;AA+CrB,MAAM,CAAC,OAAO,UAAU,IAAI,CAAC,EAAE,OAAqB,EAAE,GAAG,KAAK,EAAE,EAAE,SAAS,eAyB1E"}
|
package/form/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
2
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
import React from 'react';
|
|
4
|
+
import React, { useEffect } from 'react';
|
|
5
5
|
import { applyDisplayName } from '../internal/utils/apply-display-name';
|
|
6
6
|
import InternalForm from './internal';
|
|
7
7
|
import useBaseComponent from '../internal/hooks/use-base-component';
|
|
@@ -11,9 +11,10 @@ import { useFunnel, useFunnelNameSelector, useFunnelStep } from '../internal/ana
|
|
|
11
11
|
import formStyles from './styles.css.js';
|
|
12
12
|
import headerStyles from '../header/styles.css.js';
|
|
13
13
|
import { getAnalyticsMetadataProps } from '../internal/base-component';
|
|
14
|
+
import { FunnelMetrics } from '../internal/analytics';
|
|
14
15
|
const FormWithAnalytics = (_a) => {
|
|
15
|
-
var { variant = 'full-page', actions } = _a, props = __rest(_a, ["variant", "actions"]);
|
|
16
|
-
const { funnelProps, funnelSubmit, funnelNextOrSubmitAttempt } = useFunnel();
|
|
16
|
+
var { variant = 'full-page', actions, errorText } = _a, props = __rest(_a, ["variant", "actions", "errorText"]);
|
|
17
|
+
const { funnelIdentifier, funnelInteractionId, funnelProps, funnelSubmit, funnelNextOrSubmitAttempt, errorCount, submissionAttempt, funnelErrorContext, } = useFunnel();
|
|
17
18
|
const { funnelStepProps } = useFunnelStep();
|
|
18
19
|
const handleActionButtonClick = ({ variant }) => {
|
|
19
20
|
if (variant === 'primary') {
|
|
@@ -21,8 +22,18 @@ const FormWithAnalytics = (_a) => {
|
|
|
21
22
|
funnelSubmit();
|
|
22
23
|
}
|
|
23
24
|
};
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (funnelInteractionId && errorText) {
|
|
27
|
+
errorCount.current++;
|
|
28
|
+
FunnelMetrics.funnelError({ funnelInteractionId, funnelIdentifier, funnelErrorContext });
|
|
29
|
+
return () => {
|
|
30
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
31
|
+
errorCount.current--;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
}, [funnelInteractionId, funnelIdentifier, errorText, submissionAttempt, errorCount, funnelErrorContext]);
|
|
24
35
|
return (React.createElement(ButtonContext.Provider, { value: { onClick: handleActionButtonClick } },
|
|
25
|
-
React.createElement(InternalForm, Object.assign({ variant: variant, actions: actions }, props, funnelProps, funnelStepProps))));
|
|
36
|
+
React.createElement(InternalForm, Object.assign({ variant: variant, actions: actions, errorText: errorText }, props, funnelProps, funnelStepProps))));
|
|
26
37
|
};
|
|
27
38
|
export default function Form(_a) {
|
|
28
39
|
var { variant = 'full-page' } = _a, props = __rest(_a, ["variant"]);
|
|
@@ -30,8 +41,8 @@ export default function Form(_a) {
|
|
|
30
41
|
const baseComponentProps = useBaseComponent('Form', { props: { variant } }, analyticsMetadata);
|
|
31
42
|
const inheritedFunnelNameSelector = useFunnelNameSelector();
|
|
32
43
|
const funnelNameSelector = inheritedFunnelNameSelector || `.${headerStyles['heading-text']}`;
|
|
33
|
-
return (React.createElement(AnalyticsFunnel, {
|
|
34
|
-
React.createElement(AnalyticsFunnelStep, {
|
|
44
|
+
return (React.createElement(AnalyticsFunnel, { funnelIdentifier: analyticsMetadata === null || analyticsMetadata === void 0 ? void 0 : analyticsMetadata.instanceIdentifier, funnelFlowType: analyticsMetadata === null || analyticsMetadata === void 0 ? void 0 : analyticsMetadata.flowType, funnelErrorContext: analyticsMetadata === null || analyticsMetadata === void 0 ? void 0 : analyticsMetadata.errorContext, funnelType: "single-page", optionalStepNumbers: [], totalFunnelSteps: 1, funnelNameSelectors: [funnelNameSelector, `.${formStyles.header}`] },
|
|
45
|
+
React.createElement(AnalyticsFunnelStep, { stepIdentifier: analyticsMetadata === null || analyticsMetadata === void 0 ? void 0 : analyticsMetadata.instanceIdentifier, stepErrorContext: analyticsMetadata === null || analyticsMetadata === void 0 ? void 0 : analyticsMetadata.errorContext, stepNumber: 1 },
|
|
35
46
|
React.createElement(FormWithAnalytics, Object.assign({ variant: variant }, props, baseComponentProps)))));
|
|
36
47
|
}
|
|
37
48
|
applyDisplayName(Form, 'Form');
|
package/form/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/form/index.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/form/index.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AAExE,OAAO,YAAY,MAAM,YAAY,CAAC;AACtC,OAAO,gBAAgB,MAAM,sCAAsC,CAAC;AAEpE,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,mDAAmD,CAAC;AACzG,OAAO,EAAE,a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AAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,YAAY,EACjD,UAAU,EAAE,CAAC;YAEb,oBAAC,iBAAiB,kBAAC,OAAO,EAAE,OAAO,IAAM,KAAK,EAAM,kBAAkB,EAAI,CACtD,CACN,CACnB,CAAC;AACJ,CAAC;AAED,gBAAgB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { useEffect } from 'react';\nimport { applyDisplayName } from '../internal/utils/apply-display-name';\nimport { FormProps } from './interfaces';\nimport InternalForm from './internal';\nimport useBaseComponent from '../internal/hooks/use-base-component';\n\nimport { AnalyticsFunnel, AnalyticsFunnelStep } from '../internal/analytics/components/analytics-funnel';\nimport { ButtonContext, ButtonContextProps } from '../internal/context/button-context';\nimport { useFunnel, useFunnelNameSelector, useFunnelStep } from '../internal/analytics/hooks/use-funnel';\n\nimport formStyles from './styles.css.js';\nimport headerStyles from '../header/styles.css.js';\nimport { BasePropsWithAnalyticsMetadata, getAnalyticsMetadataProps } from '../internal/base-component';\nimport { FunnelMetrics } from '../internal/analytics';\n\nexport { FormProps };\n\nconst FormWithAnalytics = ({ variant = 'full-page', actions, errorText, ...props }: FormProps) => {\n const {\n funnelIdentifier,\n funnelInteractionId,\n funnelProps,\n funnelSubmit,\n funnelNextOrSubmitAttempt,\n errorCount,\n submissionAttempt,\n funnelErrorContext,\n } = useFunnel();\n const { funnelStepProps } = useFunnelStep();\n\n const handleActionButtonClick: ButtonContextProps['onClick'] = ({ variant }) => {\n if (variant === 'primary') {\n funnelNextOrSubmitAttempt();\n funnelSubmit();\n }\n };\n\n useEffect(() => {\n if (funnelInteractionId && errorText) {\n errorCount.current++;\n FunnelMetrics.funnelError({ funnelInteractionId, funnelIdentifier, funnelErrorContext });\n return () => {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n errorCount.current--;\n };\n }\n }, [funnelInteractionId, funnelIdentifier, errorText, submissionAttempt, errorCount, funnelErrorContext]);\n\n return (\n <ButtonContext.Provider value={{ onClick: handleActionButtonClick }}>\n <InternalForm\n variant={variant}\n actions={actions}\n errorText={errorText}\n {...props}\n {...funnelProps}\n {...funnelStepProps}\n />\n </ButtonContext.Provider>\n );\n};\n\nexport default function Form({ variant = 'full-page', ...props }: FormProps) {\n const analyticsMetadata = getAnalyticsMetadataProps(props as BasePropsWithAnalyticsMetadata);\n const baseComponentProps = useBaseComponent('Form', { props: { variant } }, analyticsMetadata);\n const inheritedFunnelNameSelector = useFunnelNameSelector();\n const funnelNameSelector = inheritedFunnelNameSelector || `.${headerStyles['heading-text']}`;\n\n return (\n <AnalyticsFunnel\n funnelIdentifier={analyticsMetadata?.instanceIdentifier}\n funnelFlowType={analyticsMetadata?.flowType}\n funnelErrorContext={analyticsMetadata?.errorContext}\n funnelType=\"single-page\"\n optionalStepNumbers={[]}\n totalFunnelSteps={1}\n funnelNameSelectors={[funnelNameSelector, `.${formStyles.header}`]}\n >\n <AnalyticsFunnelStep\n stepIdentifier={analyticsMetadata?.instanceIdentifier}\n stepErrorContext={analyticsMetadata?.errorContext}\n stepNumber={1}\n >\n <FormWithAnalytics variant={variant} {...props} {...baseComponentProps} />\n </AnalyticsFunnelStep>\n </AnalyticsFunnel>\n );\n}\n\napplyDisplayName(Form, 'Form');\n"]}
|
package/form/internal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../../src/form/internal.tsx"],"names":[],"mappings":";AASA,OAAO,EAAmB,SAAS,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../../src/form/internal.tsx"],"names":[],"mappings":";AASA,OAAO,EAAmB,SAAS,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAIlF,KAAK,iBAAiB,GAAG,SAAS,GAAG,0BAA0B,CAAC;AAEhE,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,EACnC,QAAQ,EACR,MAAM,EACN,SAAS,EACT,kBAAkB,EAAE,0BAA0B,EAC9C,OAAO,EACP,gBAAgB,EAChB,OAAO,EACP,iBAAiB,EACjB,GAAG,KAAK,EACT,EAAE,iBAAiB,eAqCnB"}
|
package/form/internal.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
2
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
import React
|
|
4
|
+
import React from 'react';
|
|
5
5
|
import clsx from 'clsx';
|
|
6
6
|
import { getBaseProps } from '../internal/base-component';
|
|
7
7
|
import InternalAlert from '../alert/internal';
|
|
@@ -10,24 +10,11 @@ import InternalContentLayout from '../content-layout/internal';
|
|
|
10
10
|
import styles from './styles.css.js';
|
|
11
11
|
import LiveRegion from '../internal/components/live-region';
|
|
12
12
|
import { useInternalI18n } from '../i18n/context';
|
|
13
|
-
import { useFunnel } from '../internal/analytics/hooks/use-funnel';
|
|
14
|
-
import { FunnelMetrics } from '../internal/analytics';
|
|
15
13
|
export default function InternalForm(_a) {
|
|
16
14
|
var { children, header, errorText, errorIconAriaLabel: errorIconAriaLabelOverride, actions, secondaryActions, variant, __internalRootRef } = _a, props = __rest(_a, ["children", "header", "errorText", "errorIconAriaLabel", "actions", "secondaryActions", "variant", "__internalRootRef"]);
|
|
17
15
|
const baseProps = getBaseProps(props);
|
|
18
16
|
const i18n = useInternalI18n('form');
|
|
19
17
|
const errorIconAriaLabel = i18n('errorIconAriaLabel', errorIconAriaLabelOverride);
|
|
20
|
-
const { funnelInteractionId, submissionAttempt, errorCount } = useFunnel();
|
|
21
|
-
useEffect(() => {
|
|
22
|
-
if (funnelInteractionId && errorText) {
|
|
23
|
-
errorCount.current++;
|
|
24
|
-
FunnelMetrics.funnelError({ funnelInteractionId });
|
|
25
|
-
return () => {
|
|
26
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
27
|
-
errorCount.current--;
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
}, [funnelInteractionId, errorText, submissionAttempt, errorCount]);
|
|
31
18
|
return (React.createElement("div", Object.assign({}, baseProps, { ref: __internalRootRef, className: clsx(styles.root, baseProps.className) }),
|
|
32
19
|
React.createElement(FormLayout, { header: header && React.createElement("div", { className: clsx(styles.header, variant === 'full-page' && styles['full-page']) }, header), variant: variant },
|
|
33
20
|
children && React.createElement("div", { className: styles.content }, children),
|
package/form/internal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/form/internal.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/form/internal.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,aAAa,MAAM,mBAAmB,CAAC;AAC9C,OAAO,WAAW,MAAM,iBAAiB,CAAC;AAC1C,OAAO,qBAAqB,MAAM,4BAA4B,CAAC;AAC/D,OAAO,MAAM,MAAM,iBAAiB,CAAC;AAGrC,OAAO,UAAU,MAAM,oCAAoC,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAIlD,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,EAUjB;QAViB,EACnC,QAAQ,EACR,MAAM,EACN,SAAS,EACT,kBAAkB,EAAE,0BAA0B,EAC9C,OAAO,EACP,gBAAgB,EACh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Z,oBAAC,UAAU,IAAC,SAAS,EAAE,IAAI;gBACxB,kBAAkB;;gBAAI,SAAS,CACrB,CACd,CACU,CACT,CACP,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAmB;IAChE,OAAO,OAAO,KAAK,WAAW,IAAI,MAAM,CAAC,CAAC,CAAC,CACzC,oBAAC,qBAAqB,IAAC,MAAM,EAAE,MAAM,IAAG,QAAQ,CAAyB,CAC1E,CAAC,CAAC,CAAC,CACF;QACG,MAAM;QACN,QAAQ,CACR,CACJ,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React from 'react';\nimport clsx from 'clsx';\nimport { getBaseProps } from '../internal/base-component';\nimport InternalAlert from '../alert/internal';\nimport InternalBox from '../box/internal';\nimport InternalContentLayout from '../content-layout/internal';\nimport styles from './styles.css.js';\nimport { FormLayoutProps, FormProps } from './interfaces';\nimport { InternalBaseComponentProps } from '../internal/hooks/use-base-component';\nimport LiveRegion from '../internal/components/live-region';\nimport { useInternalI18n } from '../i18n/context';\n\ntype InternalFormProps = FormProps & InternalBaseComponentProps;\n\nexport default function InternalForm({\n children,\n header,\n errorText,\n errorIconAriaLabel: errorIconAriaLabelOverride,\n actions,\n secondaryActions,\n variant,\n __internalRootRef,\n ...props\n}: InternalFormProps) {\n const baseProps = getBaseProps(props);\n const i18n = useInternalI18n('form');\n const errorIconAriaLabel = i18n('errorIconAriaLabel', errorIconAriaLabelOverride);\n\n return (\n <div {...baseProps} ref={__internalRootRef} className={clsx(styles.root, baseProps.className)}>\n <FormLayout\n header={\n header && <div className={clsx(styles.header, variant === 'full-page' && styles['full-page'])}>{header}</div>\n }\n variant={variant}\n >\n {children && <div className={styles.content}>{children}</div>}\n {errorText && (\n <InternalBox margin={{ top: 'l' }}>\n <InternalAlert type=\"error\" statusIconAriaLabel={errorIconAriaLabel}>\n <div className={styles.error}>{errorText}</div>\n </InternalAlert>\n </InternalBox>\n )}\n {(actions || secondaryActions) && (\n <div className={styles.footer}>\n <div className={styles['actions-section']}>\n {actions && <div className={styles.actions}>{actions}</div>}\n {secondaryActions && <div className={styles['secondary-actions']}>{secondaryActions}</div>}\n </div>\n </div>\n )}\n {errorText && (\n <LiveRegion assertive={true}>\n {errorIconAriaLabel}, {errorText}\n </LiveRegion>\n )}\n </FormLayout>\n </div>\n );\n}\n\nfunction FormLayout({ children, header, variant }: FormLayoutProps) {\n return variant === 'full-page' && header ? (\n <InternalContentLayout header={header}>{children}</InternalContentLayout>\n ) : (\n <>\n {header}\n {children}\n </>\n );\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/form-field/index.tsx"],"names":[],"mappings":";AAQA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EAAE,cAAc,EAAE,CAAC;AAE1B,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,EAAE,OAAe,EAAE,GAAG,KAAK,EAAE,EAAE,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/form-field/index.tsx"],"names":[],"mappings":";AAQA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EAAE,cAAc,EAAE,CAAC;AAE1B,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,EAAE,OAAe,EAAE,GAAG,KAAK,EAAE,EAAE,cAAc,eAa9E"}
|
package/form-field/index.js
CHANGED
|
@@ -8,8 +8,9 @@ import useBaseComponent from '../internal/hooks/use-base-component';
|
|
|
8
8
|
import { getAnalyticsMetadataProps } from '../internal/base-component';
|
|
9
9
|
export default function FormField(_a) {
|
|
10
10
|
var { stretch = false } = _a, props = __rest(_a, ["stretch"]);
|
|
11
|
-
const
|
|
12
|
-
|
|
11
|
+
const analyticsMetadata = getAnalyticsMetadataProps(props);
|
|
12
|
+
const baseComponentProps = useBaseComponent('FormField', { props: { stretch } }, analyticsMetadata);
|
|
13
|
+
return (React.createElement(InternalFormField, Object.assign({ stretch: stretch }, props, { __hideLabel: false, __analyticsMetadata: analyticsMetadata }, baseComponentProps)));
|
|
13
14
|
}
|
|
14
15
|
applyDisplayName(FormField, 'FormField');
|
|
15
16
|
//# sourceMappingURL=index.js.map
|
package/form-field/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/form-field/index.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,iBAAiB,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,gBAAgB,MAAM,sCAAsC,CAAC;AACpE,OAAO,EAAkC,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AAMvG,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,EAA6C;QAA7C,EAAE,OAAO,GAAG,KAAK,OAA4B,EAAvB,KAAK,cAA3B,WAA6B,CAAF;IAC3D,MAAM,kBAAkB,GAAG,gBAAgB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/form-field/index.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,iBAAiB,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,gBAAgB,MAAM,sCAAsC,CAAC;AACpE,OAAO,EAAkC,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AAMvG,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,EAA6C;QAA7C,EAAE,OAAO,GAAG,KAAK,OAA4B,EAAvB,KAAK,cAA3B,WAA6B,CAAF;IAC3D,MAAM,iBAAiB,GAAG,yBAAyB,CAAC,KAAuC,CAAC,CAAC;IAC7F,MAAM,kBAAkB,GAAG,gBAAgB,CAAC,WAAW,EAAE,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,iBAAiB,CAAC,CAAC;IAEpG,OAAO,CACL,oBAAC,iBAAiB,kBAChB,OAAO,EAAE,OAAO,IACZ,KAAK,IACT,WAAW,EAAE,KAAK,EAClB,mBAAmB,EAAE,iBAAiB,IAClC,kBAAkB,EACtB,CACH,CAAC;AACJ,CAAC;AAED,gBAAgB,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React from 'react';\nimport InternalFormField from './internal';\nimport { applyDisplayName } from '../internal/utils/apply-display-name';\nimport useBaseComponent from '../internal/hooks/use-base-component';\nimport { BasePropsWithAnalyticsMetadata, getAnalyticsMetadataProps } from '../internal/base-component';\n\nimport { FormFieldProps } from './interfaces';\n\nexport { FormFieldProps };\n\nexport default function FormField({ stretch = false, ...props }: FormFieldProps) {\n const analyticsMetadata = getAnalyticsMetadataProps(props as BasePropsWithAnalyticsMetadata);\n const baseComponentProps = useBaseComponent('FormField', { props: { stretch } }, analyticsMetadata);\n\n return (\n <InternalFormField\n stretch={stretch}\n {...props}\n __hideLabel={false}\n __analyticsMetadata={analyticsMetadata}\n {...baseComponentProps}\n />\n );\n}\n\napplyDisplayName(FormField, 'FormField');\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BaseComponentProps } from '../internal/base-component';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { InternalBaseComponentProps } from '../internal/hooks/use-base-component';
|
|
4
|
+
import { AnalyticsMetadata } from '../internal/analytics/interfaces';
|
|
4
5
|
export interface FormFieldProps extends BaseComponentProps {
|
|
5
6
|
/**
|
|
6
7
|
* The ID of the primary form control. You can use this to set the
|
|
@@ -55,10 +56,15 @@ export interface FormFieldProps extends BaseComponentProps {
|
|
|
55
56
|
*/
|
|
56
57
|
constraintText?: React.ReactNode;
|
|
57
58
|
/**
|
|
58
|
-
* Text that displays as a validation message. If this is set to a
|
|
59
|
+
* Text that displays as a validation error message. If this is set to a
|
|
59
60
|
* non-empty string, it will render the form field as invalid.
|
|
60
61
|
*/
|
|
61
62
|
errorText?: React.ReactNode;
|
|
63
|
+
/**
|
|
64
|
+
* Text that displays as a validation warning message. If this is set to a
|
|
65
|
+
* non-empty string, it will render the form field in a warning state.
|
|
66
|
+
*/
|
|
67
|
+
warningText?: React.ReactNode;
|
|
62
68
|
}
|
|
63
69
|
export declare namespace FormFieldProps {
|
|
64
70
|
interface I18nStrings {
|
|
@@ -66,6 +72,10 @@ export declare namespace FormFieldProps {
|
|
|
66
72
|
* Provides a text alternative for the error icon in the error message.
|
|
67
73
|
*/
|
|
68
74
|
errorIconAriaLabel?: string;
|
|
75
|
+
/**
|
|
76
|
+
* Provides a text alternative for the warning icon in the warning message.
|
|
77
|
+
*/
|
|
78
|
+
warningIconAriaLabel?: string;
|
|
69
79
|
}
|
|
70
80
|
}
|
|
71
81
|
export interface InternalFormFieldProps extends FormFieldProps, InternalBaseComponentProps<HTMLDivElement> {
|
|
@@ -77,5 +87,6 @@ export interface InternalFormFieldProps extends FormFieldProps, InternalBaseComp
|
|
|
77
87
|
* Disable the gutter applied by default.
|
|
78
88
|
*/
|
|
79
89
|
__disableGutters?: boolean;
|
|
90
|
+
__analyticsMetadata?: AnalyticsMetadata;
|
|
80
91
|
}
|
|
81
92
|
//# sourceMappingURL=interfaces.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../src/form-field/interfaces.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,O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uB,SAAQ,cAAc,EAAE,0BAA0B,CAAC,cAAc,CAAC;IACxG;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB;;OAEG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,mBAAmB,CAAC,EAAE,iBAAiB,CAAC;CACzC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/form-field/interfaces.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { BaseComponentProps } from '../internal/base-component';\nimport React from 'react';\nimport { InternalBaseComponentProps } from '../internal/hooks/use-base-component';\n\nexport interface FormFieldProps extends BaseComponentProps {\n /**\n * The ID of the primary form control. You can use this to set the\n * `for` attribute of a label for accessibility.\n *\n * If you don't set this property, the control group automatically sets\n * the label to the ID of an inner form control (for example, an [input](/components/input) component).\n * This only works well if you're using a single control in the form field.\n */\n controlId?: string;\n\n /**\n * Determines whether the primary control should expand to 12 columns.\n *\n * By default (or when this property is set to `false`), the primary control\n * occupies 9 columns. The secondary control uses the remaining 3 columns.\n * On smaller viewports, both components occupy 12 columns and stack on top of each other.\n *\n * If this property is set to `true`, the primary control uses the full\n * 12 columns. The secondary control (if present) also uses 12 columns, and the two\n * controls stack on top of each other.\n */\n stretch?: boolean;\n\n /**\n * The main label for the form field.\n */\n label?: React.ReactNode;\n\n /**\n * An object containing all the necessary localized strings required by the component.\n * @i18n\n */\n i18nStrings?: FormFieldProps.I18nStrings;\n\n /**\n * Use to display an 'Info' link next to the label.\n */\n info?: React.ReactNode;\n\n /**\n * The primary form control (for example, input, textarea, etc.).\n * @displayname control\n */\n children?: React.ReactNode;\n\n /**\n * A secondary control. You can use this for custom actions and content.\n */\n secondaryControl?: React.ReactNode;\n\n /**\n * Detailed information about the form field that's displayed below the label.\n */\n description?: React.ReactNode;\n\n /**\n * Constraint text that's displayed below the control. Use this to provide\n * additional information about valid formats, etc.\n */\n constraintText?: React.ReactNode;\n\n /**\n * Text that displays as a validation message. If this is set to a\n * non-empty string, it will render the form field as invalid.\n */\n errorText?: React.ReactNode;\n}\n\nexport namespace FormFieldProps {\n export interface I18nStrings {\n /**\n * Provides a text alternative for the error icon in the error message.\n */\n errorIconAriaLabel?: string;\n }\n}\n\nexport interface InternalFormFieldProps extends FormFieldProps, InternalBaseComponentProps<HTMLDivElement> {\n /**\n * Visually hide the label.\n */\n __hideLabel?: boolean;\n\n /**\n * Disable the gutter applied by default.\n */\n __disableGutters?: boolean;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/form-field/interfaces.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { BaseComponentProps } from '../internal/base-component';\nimport React from 'react';\nimport { InternalBaseComponentProps } from '../internal/hooks/use-base-component';\nimport { AnalyticsMetadata } from '../internal/analytics/interfaces';\n\nexport interface FormFieldProps extends BaseComponentProps {\n /**\n * The ID of the primary form control. You can use this to set the\n * `for` attribute of a label for accessibility.\n *\n * If you don't set this property, the control group automatically sets\n * the label to the ID of an inner form control (for example, an [input](/components/input) component).\n * This only works well if you're using a single control in the form field.\n */\n controlId?: string;\n\n /**\n * Determines whether the primary control should expand to 12 columns.\n *\n * By default (or when this property is set to `false`), the primary control\n * occupies 9 columns. The secondary control uses the remaining 3 columns.\n * On smaller viewports, both components occupy 12 columns and stack on top of each other.\n *\n * If this property is set to `true`, the primary control uses the full\n * 12 columns. The secondary control (if present) also uses 12 columns, and the two\n * controls stack on top of each other.\n */\n stretch?: boolean;\n\n /**\n * The main label for the form field.\n */\n label?: React.ReactNode;\n\n /**\n * An object containing all the necessary localized strings required by the component.\n * @i18n\n */\n i18nStrings?: FormFieldProps.I18nStrings;\n\n /**\n * Use to display an 'Info' link next to the label.\n */\n info?: React.ReactNode;\n\n /**\n * The primary form control (for example, input, textarea, etc.).\n * @displayname control\n */\n children?: React.ReactNode;\n\n /**\n * A secondary control. You can use this for custom actions and content.\n */\n secondaryControl?: React.ReactNode;\n\n /**\n * Detailed information about the form field that's displayed below the label.\n */\n description?: React.ReactNode;\n\n /**\n * Constraint text that's displayed below the control. Use this to provide\n * additional information about valid formats, etc.\n */\n constraintText?: React.ReactNode;\n\n /**\n * Text that displays as a validation error message. If this is set to a\n * non-empty string, it will render the form field as invalid.\n */\n errorText?: React.ReactNode;\n\n /**\n * Text that displays as a validation warning message. If this is set to a\n * non-empty string, it will render the form field in a warning state.\n */\n warningText?: React.ReactNode;\n}\n\nexport namespace FormFieldProps {\n export interface I18nStrings {\n /**\n * Provides a text alternative for the error icon in the error message.\n */\n errorIconAriaLabel?: string;\n\n /**\n * Provides a text alternative for the warning icon in the warning message.\n */\n warningIconAriaLabel?: string;\n }\n}\n\nexport interface InternalFormFieldProps extends FormFieldProps, InternalBaseComponentProps<HTMLDivElement> {\n /**\n * Visually hide the label.\n */\n __hideLabel?: boolean;\n\n /**\n * Disable the gutter applied by default.\n */\n __disableGutters?: boolean;\n __analyticsMetadata?: AnalyticsMetadata;\n}\n"]}
|
package/form-field/internal.d.ts
CHANGED
|
@@ -5,12 +5,18 @@ interface FormFieldErrorProps {
|
|
|
5
5
|
children?: React.ReactNode;
|
|
6
6
|
errorIconAriaLabel?: string;
|
|
7
7
|
}
|
|
8
|
+
interface FormFieldWarningProps {
|
|
9
|
+
id?: string;
|
|
10
|
+
children?: React.ReactNode;
|
|
11
|
+
warningIconAriaLabel?: string;
|
|
12
|
+
}
|
|
8
13
|
export declare function FormFieldError({ id, children, errorIconAriaLabel }: FormFieldErrorProps): JSX.Element;
|
|
9
|
-
export declare function
|
|
14
|
+
export declare function FormFieldWarning({ id, children, warningIconAriaLabel }: FormFieldWarningProps): JSX.Element;
|
|
15
|
+
export declare function ConstraintText({ id, hasValidationText, children, }: {
|
|
10
16
|
id?: string;
|
|
11
|
-
|
|
17
|
+
hasValidationText: boolean;
|
|
12
18
|
children: React.ReactNode;
|
|
13
19
|
}): JSX.Element;
|
|
14
|
-
export default function InternalFormField({ controlId, stretch, label, info, i18nStrings, children, secondaryControl, description, constraintText, errorText, __hideLabel, __internalRootRef, __disableGutters, ...rest }: InternalFormFieldProps): JSX.Element;
|
|
20
|
+
export default function InternalFormField({ controlId, stretch, label, info, i18nStrings, children, secondaryControl, description, constraintText, errorText, warningText, __hideLabel, __internalRootRef, __disableGutters, __analyticsMetadata, ...rest }: InternalFormFieldProps): JSX.Element;
|
|
15
21
|
export {};
|
|
16
22
|
//# sourceMappingURL=internal.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../../src/form-field/internal.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA4B,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../../src/form-field/internal.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA4B,MAAM,OAAO,CAAC;AAcjD,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAgBtD,UAAU,mBAAmB;IAC3B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,UAAU,qBAAqB;IAC7B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,wBAAgB,cAAc,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,kBAAkB,EAAE,EAAE,mBAAmB,eAqBvF;AAED,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,oBAAoB,EAAE,EAAE,qBAAqB,eAqB7F;AAED,wBAAgB,cAAc,CAAC,EAC7B,EAAE,EACF,iBAAiB,EACjB,QAAQ,GACT,EAAE;IACD,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,iBAAiB,EAAE,OAAO,CAAC;IAC3B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,eAMA;AAED,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,EACxC,SAAS,EACT,OAAe,EACf,KAAK,EACL,IAAI,EACJ,WAAW,EACX,QAAQ,EACR,gBAAgB,EAChB,WAAW,EACX,cAAc,EACd,SAAS,EACT,WAAW,EACX,WAAW,EACX,iBAAwB,EACxB,gBAAwB,EACxB,mBAA+B,EAC/B,GAAG,IAAI,EACR,EAAE,sBAAsB,eA0JxB"}
|
package/form-field/internal.js
CHANGED
|
@@ -7,6 +7,7 @@ import { getBaseProps } from '../internal/base-component';
|
|
|
7
7
|
import { FormFieldContext, useFormFieldContext } from '../internal/context/form-field-context';
|
|
8
8
|
import { useUniqueId } from '../internal/hooks/use-unique-id';
|
|
9
9
|
import { useVisualRefresh } from '../internal/hooks/use-visual-mode';
|
|
10
|
+
import { warnOnce } from '@cloudscape-design/component-toolkit/internal';
|
|
10
11
|
import InternalGrid from '../grid/internal';
|
|
11
12
|
import InternalIcon from '../icon/internal';
|
|
12
13
|
import { getAriaDescribedBy, getGridDefinition, getSlotIds } from './util';
|
|
@@ -21,35 +22,53 @@ import LiveRegion from '../internal/components/live-region';
|
|
|
21
22
|
export function FormFieldError({ id, children, errorIconAriaLabel }) {
|
|
22
23
|
const i18n = useInternalI18n('form-field');
|
|
23
24
|
const contentRef = useRef(null);
|
|
25
|
+
const i18nErrorIconAriaLabel = i18n('i18nStrings.errorIconAriaLabel', errorIconAriaLabel);
|
|
24
26
|
return (React.createElement(React.Fragment, null,
|
|
25
27
|
React.createElement("div", { id: id, className: styles.error },
|
|
26
28
|
React.createElement("div", { className: styles['error-icon-shake-wrapper'] },
|
|
27
|
-
React.createElement("div", { role: "img", "aria-label":
|
|
28
|
-
React.createElement(InternalIcon, { name: "status-
|
|
29
|
+
React.createElement("div", { role: "img", "aria-label": i18nErrorIconAriaLabel, className: styles['error-icon-scale-wrapper'] },
|
|
30
|
+
React.createElement(InternalIcon, { name: "status-negative", size: "small" }))),
|
|
29
31
|
React.createElement("span", { className: styles.error__message, ref: contentRef }, children)),
|
|
30
|
-
React.createElement(LiveRegion, { assertive: true, source: [
|
|
32
|
+
React.createElement(LiveRegion, { assertive: true, source: [i18nErrorIconAriaLabel, contentRef] })));
|
|
33
|
+
}
|
|
34
|
+
export function FormFieldWarning({ id, children, warningIconAriaLabel }) {
|
|
35
|
+
const i18n = useInternalI18n('form-field');
|
|
36
|
+
const contentRef = useRef(null);
|
|
37
|
+
const i18nWarningIconAriaLabel = i18n('i18nStrings.warningIconAriaLabel', warningIconAriaLabel);
|
|
38
|
+
return (React.createElement(React.Fragment, null,
|
|
39
|
+
React.createElement("div", { id: id, className: styles.warning },
|
|
40
|
+
React.createElement("div", { className: styles['warning-icon-shake-wrapper'] },
|
|
41
|
+
React.createElement("div", { role: "img", "aria-label": i18nWarningIconAriaLabel, className: styles['warning-icon-scale-wrapper'] },
|
|
42
|
+
React.createElement(InternalIcon, { name: "status-warning", size: "small" }))),
|
|
43
|
+
React.createElement("span", { className: styles.warning__message, ref: contentRef }, children)),
|
|
44
|
+
React.createElement(LiveRegion, { assertive: true, source: [i18nWarningIconAriaLabel, contentRef] })));
|
|
31
45
|
}
|
|
32
|
-
export function ConstraintText({ id,
|
|
33
|
-
return (React.createElement("div", { id: id, className: clsx(styles.constraint,
|
|
46
|
+
export function ConstraintText({ id, hasValidationText, children, }) {
|
|
47
|
+
return (React.createElement("div", { id: id, className: clsx(styles.constraint, hasValidationText && styles['constraint-has-validation-text']) }, children));
|
|
34
48
|
}
|
|
35
49
|
export default function InternalFormField(_a) {
|
|
36
|
-
var { controlId, stretch = false, label, info, i18nStrings, children, secondaryControl, description, constraintText, errorText, __hideLabel, __internalRootRef = null, __disableGutters = false } = _a, rest = __rest(_a, ["controlId", "stretch", "label", "info", "i18nStrings", "children", "secondaryControl", "description", "constraintText", "errorText", "__hideLabel", "__internalRootRef", "__disableGutters"]);
|
|
50
|
+
var { controlId, stretch = false, label, info, i18nStrings, children, secondaryControl, description, constraintText, errorText, warningText, __hideLabel, __internalRootRef = null, __disableGutters = false, __analyticsMetadata = undefined } = _a, rest = __rest(_a, ["controlId", "stretch", "label", "info", "i18nStrings", "children", "secondaryControl", "description", "constraintText", "errorText", "warningText", "__hideLabel", "__internalRootRef", "__disableGutters", "__analyticsMetadata"]);
|
|
37
51
|
const baseProps = getBaseProps(rest);
|
|
38
52
|
const isRefresh = useVisualRefresh();
|
|
39
53
|
const instanceUniqueId = useUniqueId('formField');
|
|
40
54
|
const generatedControlId = controlId || instanceUniqueId;
|
|
41
55
|
const formFieldId = controlId || generatedControlId;
|
|
42
|
-
const { funnelInteractionId, submissionAttempt, funnelState, errorCount } = useFunnel();
|
|
43
|
-
const { stepNumber, stepNameSelector } = useFunnelStep();
|
|
44
|
-
const { subStepSelector, subStepNameSelector } = useFunnelSubStep();
|
|
45
|
-
const
|
|
56
|
+
const { funnelIdentifier, funnelInteractionId, submissionAttempt, funnelState, errorCount } = useFunnel();
|
|
57
|
+
const { stepIdentifier, stepNumber, stepNameSelector } = useFunnelStep();
|
|
58
|
+
const { subStepErrorContext, subStepIdentifier, subStepSelector, subStepNameSelector } = useFunnelSubStep();
|
|
59
|
+
const showWarning = warningText && !errorText;
|
|
60
|
+
if (warningText && errorText) {
|
|
61
|
+
warnOnce('FileUpload', 'Both `errorText` and `warningText` exist. `warningText` will not be shown.');
|
|
62
|
+
}
|
|
63
|
+
const slotIds = getSlotIds(formFieldId, label, description, constraintText, errorText, showWarning ? warningText : undefined);
|
|
46
64
|
const ariaDescribedBy = getAriaDescribedBy(slotIds);
|
|
47
65
|
const gridDefinition = getGridDefinition(stretch, !!secondaryControl, isRefresh);
|
|
48
|
-
const { ariaLabelledby: parentAriaLabelledby, ariaDescribedby: parentAriaDescribedby, invalid: parentInvalid, } = useFormFieldContext({});
|
|
66
|
+
const { ariaLabelledby: parentAriaLabelledby, ariaDescribedby: parentAriaDescribedby, invalid: parentInvalid, warning: parentWarning, } = useFormFieldContext({});
|
|
49
67
|
const contextValuesWithoutControlId = {
|
|
50
68
|
ariaLabelledby: joinStrings(parentAriaLabelledby, slotIds.label) || undefined,
|
|
51
69
|
ariaDescribedby: joinStrings(parentAriaDescribedby, ariaDescribedBy) || undefined,
|
|
52
70
|
invalid: !!errorText || !!parentInvalid,
|
|
71
|
+
warning: (!!warningText && !errorText) || (!!parentWarning && !parentInvalid),
|
|
53
72
|
};
|
|
54
73
|
const analyticsAttributes = {
|
|
55
74
|
[DATA_ATTR_FIELD_LABEL]: slotIds.label ? getFieldSlotSeletor(slotIds.label) : undefined,
|
|
@@ -66,15 +85,21 @@ export default function InternalFormField(_a) {
|
|
|
66
85
|
if (errorIsVisible) {
|
|
67
86
|
FunnelMetrics.funnelSubStepError({
|
|
68
87
|
funnelInteractionId,
|
|
88
|
+
funnelIdentifier,
|
|
69
89
|
subStepSelector,
|
|
70
90
|
subStepName,
|
|
71
91
|
subStepNameSelector,
|
|
92
|
+
subStepIdentifier,
|
|
72
93
|
stepNumber,
|
|
73
94
|
stepName,
|
|
74
95
|
stepNameSelector,
|
|
96
|
+
stepIdentifier,
|
|
97
|
+
subStepErrorContext,
|
|
75
98
|
fieldErrorSelector: `${getFieldSlotSeletor(slotIds.error)} .${styles.error__message}`,
|
|
76
99
|
fieldLabelSelector: getFieldSlotSeletor(slotIds.label),
|
|
77
100
|
subStepAllSelector: getSubStepAllSelector(),
|
|
101
|
+
fieldIdentifier: __analyticsMetadata === null || __analyticsMetadata === void 0 ? void 0 : __analyticsMetadata.instanceIdentifier,
|
|
102
|
+
fieldErrorContext: __analyticsMetadata === null || __analyticsMetadata === void 0 ? void 0 : __analyticsMetadata.errorContext,
|
|
78
103
|
});
|
|
79
104
|
}
|
|
80
105
|
return () => {
|
|
@@ -94,8 +119,9 @@ export default function InternalFormField(_a) {
|
|
|
94
119
|
React.createElement(FormFieldContext.Provider, { value: Object.assign({ controlId: generatedControlId }, contextValuesWithoutControlId) }, children && React.createElement("div", { className: styles.control }, children)),
|
|
95
120
|
secondaryControl && (React.createElement(FormFieldContext.Provider, { value: contextValuesWithoutControlId },
|
|
96
121
|
React.createElement("div", { className: styles['secondary-control'] }, secondaryControl))))),
|
|
97
|
-
(constraintText || errorText) && (React.createElement("div", { className: styles.hints },
|
|
122
|
+
(constraintText || errorText || warningText) && (React.createElement("div", { className: styles.hints },
|
|
98
123
|
errorText && (React.createElement(FormFieldError, { id: slotIds.error, errorIconAriaLabel: i18nStrings === null || i18nStrings === void 0 ? void 0 : i18nStrings.errorIconAriaLabel }, errorText)),
|
|
99
|
-
|
|
124
|
+
showWarning && (React.createElement(FormFieldWarning, { id: slotIds.warning, warningIconAriaLabel: i18nStrings === null || i18nStrings === void 0 ? void 0 : i18nStrings.warningIconAriaLabel }, warningText)),
|
|
125
|
+
constraintText && (React.createElement(ConstraintText, { id: slotIds.constraint, hasValidationText: !!errorText || !!warningText }, constraintText))))));
|
|
100
126
|
}
|
|
101
127
|
//# sourceMappingURL=internal.js.map
|