@hitachivantara/uikit-react-core 5.83.0 → 5.84.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/CheckBoxGroup/CheckBoxGroup.cjs +1 -0
- package/dist/cjs/CheckBoxGroup/CheckBoxGroup.styles.cjs +1 -1
- package/dist/cjs/ColorPicker/ColorPicker.cjs +1 -0
- package/dist/cjs/ColorPicker/ColorPicker.styles.cjs +1 -5
- package/dist/cjs/DatePicker/DatePicker.cjs +1 -0
- package/dist/cjs/DatePicker/DatePicker.styles.cjs +1 -4
- package/dist/cjs/Dropdown/Dropdown.cjs +1 -0
- package/dist/cjs/Dropdown/Dropdown.styles.cjs +1 -1
- package/dist/cjs/FileUploader/DropZone/DropZone.cjs +30 -14
- package/dist/cjs/FileUploader/DropZone/DropZone.styles.cjs +15 -29
- package/dist/cjs/FileUploader/FileUploader.cjs +12 -12
- package/dist/cjs/FileUploader/FileUploader.styles.cjs +8 -0
- package/dist/cjs/FileUploader/utils.cjs +0 -1
- package/dist/cjs/FilterGroup/FilterGroup.cjs +1 -0
- package/dist/cjs/FilterGroup/FilterGroup.styles.cjs +1 -4
- package/dist/cjs/FormElement/Label/Label.cjs +3 -2
- package/dist/cjs/FormElement/Label/Label.styles.cjs +1 -1
- package/dist/cjs/FormElement/Suggestions/Suggestions.cjs +1 -1
- package/dist/cjs/FormElement/Suggestions/Suggestions.styles.cjs +1 -0
- package/dist/cjs/Input/Input.cjs +1 -0
- package/dist/cjs/Input/Input.styles.cjs +1 -1
- package/dist/cjs/RadioGroup/RadioGroup.cjs +1 -0
- package/dist/cjs/RadioGroup/RadioGroup.styles.cjs +1 -1
- package/dist/cjs/Select/Select.cjs +6 -3
- package/dist/cjs/Select/Select.styles.cjs +8 -5
- package/dist/cjs/SelectionList/SelectionList.cjs +1 -0
- package/dist/cjs/SelectionList/SelectionList.styles.cjs +1 -1
- package/dist/cjs/Slider/utils.cjs +3 -3
- package/dist/cjs/Switch/Switch.cjs +1 -0
- package/dist/cjs/Switch/Switch.styles.cjs +1 -1
- package/dist/cjs/TagsInput/TagsInput.cjs +1 -0
- package/dist/cjs/TagsInput/TagsInput.styles.cjs +1 -1
- package/dist/cjs/TextArea/TextArea.cjs +1 -0
- package/dist/cjs/TextArea/TextArea.styles.cjs +1 -1
- package/dist/cjs/TimePicker/TimePicker.cjs +1 -0
- package/dist/cjs/TimePicker/TimePicker.styles.cjs +1 -4
- package/dist/cjs/index.cjs +2 -0
- package/dist/esm/CheckBoxGroup/CheckBoxGroup.js +1 -0
- package/dist/esm/CheckBoxGroup/CheckBoxGroup.js.map +1 -1
- package/dist/esm/CheckBoxGroup/CheckBoxGroup.styles.js +1 -1
- package/dist/esm/CheckBoxGroup/CheckBoxGroup.styles.js.map +1 -1
- package/dist/esm/ColorPicker/ColorPicker.js +1 -0
- package/dist/esm/ColorPicker/ColorPicker.js.map +1 -1
- package/dist/esm/ColorPicker/ColorPicker.styles.js +1 -5
- package/dist/esm/ColorPicker/ColorPicker.styles.js.map +1 -1
- package/dist/esm/DatePicker/DatePicker.js +1 -0
- package/dist/esm/DatePicker/DatePicker.js.map +1 -1
- package/dist/esm/DatePicker/DatePicker.styles.js +1 -4
- package/dist/esm/DatePicker/DatePicker.styles.js.map +1 -1
- package/dist/esm/Dropdown/Dropdown.js +1 -0
- package/dist/esm/Dropdown/Dropdown.js.map +1 -1
- package/dist/esm/Dropdown/Dropdown.styles.js +1 -1
- package/dist/esm/Dropdown/Dropdown.styles.js.map +1 -1
- package/dist/esm/FileUploader/DropZone/DropZone.js +31 -15
- package/dist/esm/FileUploader/DropZone/DropZone.js.map +1 -1
- package/dist/esm/FileUploader/DropZone/DropZone.styles.js +15 -29
- package/dist/esm/FileUploader/DropZone/DropZone.styles.js.map +1 -1
- package/dist/esm/FileUploader/FileUploader.js +14 -13
- package/dist/esm/FileUploader/FileUploader.js.map +1 -1
- package/dist/esm/FileUploader/FileUploader.styles.js +8 -0
- package/dist/esm/FileUploader/FileUploader.styles.js.map +1 -0
- package/dist/esm/FileUploader/utils.js +1 -2
- package/dist/esm/FileUploader/utils.js.map +1 -1
- package/dist/esm/FilterGroup/FilterGroup.js +1 -0
- package/dist/esm/FilterGroup/FilterGroup.js.map +1 -1
- package/dist/esm/FilterGroup/FilterGroup.styles.js +1 -4
- package/dist/esm/FilterGroup/FilterGroup.styles.js.map +1 -1
- package/dist/esm/FormElement/Label/Label.js +3 -2
- package/dist/esm/FormElement/Label/Label.js.map +1 -1
- package/dist/esm/FormElement/Label/Label.styles.js +1 -1
- package/dist/esm/FormElement/Label/Label.styles.js.map +1 -1
- package/dist/esm/FormElement/Suggestions/Suggestions.js +2 -2
- package/dist/esm/FormElement/Suggestions/Suggestions.js.map +1 -1
- package/dist/esm/FormElement/Suggestions/Suggestions.styles.js +1 -0
- package/dist/esm/FormElement/Suggestions/Suggestions.styles.js.map +1 -1
- package/dist/esm/Input/Input.js +1 -0
- package/dist/esm/Input/Input.js.map +1 -1
- package/dist/esm/Input/Input.styles.js +1 -1
- package/dist/esm/Input/Input.styles.js.map +1 -1
- package/dist/esm/ListContainer/ListItem/ListItem.js.map +1 -1
- package/dist/esm/RadioGroup/RadioGroup.js +1 -0
- package/dist/esm/RadioGroup/RadioGroup.js.map +1 -1
- package/dist/esm/RadioGroup/RadioGroup.styles.js +1 -1
- package/dist/esm/RadioGroup/RadioGroup.styles.js.map +1 -1
- package/dist/esm/Select/Select.js +6 -3
- package/dist/esm/Select/Select.js.map +1 -1
- package/dist/esm/Select/Select.styles.js +8 -5
- package/dist/esm/Select/Select.styles.js.map +1 -1
- package/dist/esm/SelectionList/SelectionList.js +1 -0
- package/dist/esm/SelectionList/SelectionList.js.map +1 -1
- package/dist/esm/SelectionList/SelectionList.styles.js +1 -1
- package/dist/esm/SelectionList/SelectionList.styles.js.map +1 -1
- package/dist/esm/Slider/utils.js +3 -3
- package/dist/esm/Slider/utils.js.map +1 -1
- package/dist/esm/Switch/Switch.js +1 -0
- package/dist/esm/Switch/Switch.js.map +1 -1
- package/dist/esm/Switch/Switch.styles.js +1 -1
- package/dist/esm/Switch/Switch.styles.js.map +1 -1
- package/dist/esm/TagsInput/TagsInput.js +1 -0
- package/dist/esm/TagsInput/TagsInput.js.map +1 -1
- package/dist/esm/TagsInput/TagsInput.styles.js +1 -1
- package/dist/esm/TagsInput/TagsInput.styles.js.map +1 -1
- package/dist/esm/TextArea/TextArea.js +1 -0
- package/dist/esm/TextArea/TextArea.js.map +1 -1
- package/dist/esm/TextArea/TextArea.styles.js +1 -1
- package/dist/esm/TextArea/TextArea.styles.js.map +1 -1
- package/dist/esm/TimePicker/TimePicker.js +1 -0
- package/dist/esm/TimePicker/TimePicker.js.map +1 -1
- package/dist/esm/TimePicker/TimePicker.styles.js +1 -4
- package/dist/esm/TimePicker/TimePicker.styles.js.map +1 -1
- package/dist/esm/index.js +128 -126
- package/dist/esm/index.js.map +1 -1
- package/dist/types/index.d.ts +313 -252
- package/package.json +6 -6
|
@@ -1,16 +1,36 @@
|
|
|
1
1
|
import { jsxs, Fragment, jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useState, useRef } from "react";
|
|
2
|
+
import { useContext, useState, useRef } from "react";
|
|
3
3
|
import { Doc } from "@hitachivantara/uikit-react-icons";
|
|
4
4
|
import { useDefaultProps } from "@hitachivantara/uikit-react-utils";
|
|
5
|
+
import { useLabels } from "../../hooks/useLabels.js";
|
|
5
6
|
import { useUniqueId } from "../../hooks/useUniqueId.js";
|
|
6
7
|
import { uniqueId } from "../../utils/helpers.js";
|
|
7
8
|
import { setId } from "../../utils/setId.js";
|
|
8
9
|
import { convertUnits } from "../utils.js";
|
|
9
10
|
import { useClasses } from "./DropZone.styles.js";
|
|
10
11
|
import { staticClasses } from "./DropZone.styles.js";
|
|
12
|
+
import { HvFormElementContext } from "../../FormElement/context.js";
|
|
11
13
|
import { HvLabel } from "../../FormElement/Label/Label.js";
|
|
12
14
|
import { HvInfoMessage } from "../../FormElement/InfoMessage/InfoMessage.js";
|
|
13
|
-
|
|
15
|
+
const DEFAULT_LABELS = {
|
|
16
|
+
/** Extensions of the accepted file types */
|
|
17
|
+
acceptedFiles: "",
|
|
18
|
+
/** Dropzone area label. @deprecated use `label` prop instead */
|
|
19
|
+
dropzone: "Label",
|
|
20
|
+
/** Size file warning label. */
|
|
21
|
+
sizeWarning: "Max. file size:",
|
|
22
|
+
/** Size file warning label. */
|
|
23
|
+
drag: "Drop files here or",
|
|
24
|
+
/** Size file warning label. */
|
|
25
|
+
selectFiles: "click to upload",
|
|
26
|
+
/** Theming sheet used to style components */
|
|
27
|
+
dropFiles: "Drop files here",
|
|
28
|
+
/** Message to display when file size is greater than allowed */
|
|
29
|
+
fileSizeError: "The file exceeds the maximum upload size",
|
|
30
|
+
/** Message to display when file type is greater than allowed */
|
|
31
|
+
fileTypeError: "File type not allowed for upload",
|
|
32
|
+
removeFileButtonLabel: "Remove File"
|
|
33
|
+
};
|
|
14
34
|
function validateAccept(file, acceptAttr) {
|
|
15
35
|
if (!file || !acceptAttr) return true;
|
|
16
36
|
const acceptEntries = acceptAttr.split(",");
|
|
@@ -32,17 +52,19 @@ const HvDropZone = (props) => {
|
|
|
32
52
|
const {
|
|
33
53
|
id: idProp,
|
|
34
54
|
classes: classesProp,
|
|
35
|
-
|
|
55
|
+
label,
|
|
56
|
+
labels: labelsProp,
|
|
36
57
|
accept,
|
|
37
58
|
maxFileSize,
|
|
38
59
|
inputProps,
|
|
39
60
|
hideLabels,
|
|
40
61
|
multiple = true,
|
|
41
|
-
disabled = false,
|
|
42
62
|
onFilesAdded
|
|
43
63
|
} = useDefaultProps("HvDropZone", props);
|
|
44
64
|
const id = useUniqueId(idProp);
|
|
65
|
+
const labels = useLabels(DEFAULT_LABELS, labelsProp);
|
|
45
66
|
const { classes, cx } = useClasses(classesProp);
|
|
67
|
+
const { disabled } = useContext(HvFormElementContext);
|
|
46
68
|
const [dragState, setDragState] = useState(false);
|
|
47
69
|
const inputRef = useRef(null);
|
|
48
70
|
const handleDragLeave = () => {
|
|
@@ -81,9 +103,10 @@ const HvDropZone = (props) => {
|
|
|
81
103
|
/* @__PURE__ */ jsx(
|
|
82
104
|
HvLabel,
|
|
83
105
|
{
|
|
106
|
+
showGutter: true,
|
|
84
107
|
id: setId(id, "input-file-label"),
|
|
85
108
|
htmlFor: setId(id, "input-file"),
|
|
86
|
-
label: labels?.dropzone,
|
|
109
|
+
label: label ?? labels?.dropzone,
|
|
87
110
|
className: classes.dropZoneLabel
|
|
88
111
|
}
|
|
89
112
|
),
|
|
@@ -138,16 +161,9 @@ const HvDropZone = (props) => {
|
|
|
138
161
|
...inputProps
|
|
139
162
|
}
|
|
140
163
|
),
|
|
141
|
-
/* @__PURE__ */ jsx("div", { className: classes?.dropArea, children: dragState ? /* @__PURE__ */ jsx("div", { className: classes.dropZoneAreaLabels, children: /* @__PURE__ */ jsx(
|
|
142
|
-
/* @__PURE__ */ jsx(
|
|
143
|
-
|
|
144
|
-
{
|
|
145
|
-
iconSize: "M",
|
|
146
|
-
className: classes.dropZoneAreaIcon,
|
|
147
|
-
color: disabled ? "secondary_60" : "secondary"
|
|
148
|
-
}
|
|
149
|
-
),
|
|
150
|
-
/* @__PURE__ */ jsx("div", { className: classes.dropZoneAreaLabels, children: /* @__PURE__ */ jsxs(HvTypography, { className: classes.dragText, children: [
|
|
164
|
+
/* @__PURE__ */ jsx("div", { className: classes?.dropArea, children: dragState ? /* @__PURE__ */ jsx("div", { className: classes.dropZoneAreaLabels, children: /* @__PURE__ */ jsx("div", { className: classes.dragText, children: labels?.dropFiles }) }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
165
|
+
/* @__PURE__ */ jsx(Doc, { size: "M", className: classes.dropZoneAreaIcon }),
|
|
166
|
+
/* @__PURE__ */ jsx("div", { className: classes.dropZoneAreaLabels, children: /* @__PURE__ */ jsxs("div", { className: classes.dragText, children: [
|
|
151
167
|
labels?.drag,
|
|
152
168
|
/* @__PURE__ */ jsx(
|
|
153
169
|
"span",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DropZone.js","sources":["../../../../src/FileUploader/DropZone/DropZone.tsx"],"sourcesContent":["import { useRef, useState } from \"react\";\nimport { Doc } from \"@hitachivantara/uikit-react-icons\";\nimport {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { HvInfoMessage, HvLabel } from \"../../FormElement\";\nimport { useUniqueId } from \"../../hooks/useUniqueId\";\nimport { HvTypography } from \"../../Typography\";\nimport { uniqueId } from \"../../utils/helpers\";\nimport { setId } from \"../../utils/setId\";\nimport { HvFileData, HvFilesAddedEvent } from \"../File\";\nimport { convertUnits } from \"../utils\";\nimport { staticClasses, useClasses } from \"./DropZone.styles\";\n\nexport { staticClasses as dropZoneClasses };\n\nexport type HvDropZoneClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvDropZoneLabels {\n /**\n * Extensions of the accepted file types\n */\n acceptedFiles?: string;\n /**\n * Dropzone area label.\n */\n dropzone?: string;\n /**\n * Size file warning label.\n */\n sizeWarning?: string;\n /**\n * Size file warning label.\n */\n drag?: string;\n /**\n * Size file warning label.\n */\n selectFiles?: string;\n /**\n * Theming sheet used to style components\n * */\n dropFiles?: string;\n /**\n * Message to display when file size is greater than allowed\n * */\n fileSizeError?: string;\n /**\n * Message to display when file type is greater than allowed\n * */\n fileTypeError?: string;\n}\n\nexport interface HvDropZoneProps {\n /**\n * Id to be applied to the root node.\n */\n id?: string;\n /**\n * Labels to present in FileUploader.\n */\n labels?: HvDropZoneLabels;\n /**\n * Whether the Dropzone should accept multiple files at once.\n */\n multiple?: boolean;\n /**\n * If the input is disabled or not\n */\n disabled?: boolean;\n /**\n * Files extensions accepted for upload.\n */\n accept?: React.InputHTMLAttributes<HTMLInputElement>[\"accept\"];\n /**\n * Max upload size\n * */\n maxFileSize: number;\n /**\n * Function responsible for processing files added to the drop zone.\n */\n onFilesAdded?: HvFilesAddedEvent;\n /**\n * Whether the DropZone should hide labels or not.\n */\n hideLabels?: boolean;\n /**\n * Attributes applied to the input element.\n */\n inputProps?: React.InputHTMLAttributes<HTMLInputElement>;\n /**\n * A Jss Object used to override or extend the styles applied to the component.\n */\n classes?: HvDropZoneClasses;\n}\n\n// TODO: remove/review in `v6`: delegate to HTML `accept` and/or add custom validation\nfunction validateAccept(file?: File, acceptAttr?: string) {\n if (!file || !acceptAttr) return true;\n\n const acceptEntries = acceptAttr.split(\",\");\n const fileName = file.name || \"\";\n const mimeType = (file.type || \"\").toLowerCase();\n const baseMimeType = mimeType.replace(/\\/.*$/, \"\");\n\n return acceptEntries.some((type) => {\n const validType = type.trim().toLowerCase();\n if (validType.charAt(0) === \".\") {\n return fileName.toLowerCase().endsWith(validType);\n }\n // This is something like a image/* mime type\n if (validType.endsWith(\"/*\")) {\n return baseMimeType === validType.replace(/\\/.*$/, \"\");\n }\n return mimeType === validType;\n });\n}\n\nexport const HvDropZone = (props: HvDropZoneProps) => {\n const {\n id: idProp,\n classes: classesProp,\n labels,\n accept,\n maxFileSize,\n inputProps,\n hideLabels,\n multiple = true,\n disabled = false,\n onFilesAdded,\n } = useDefaultProps(\"HvDropZone\", props);\n const id = useUniqueId(idProp);\n\n const { classes, cx } = useClasses(classesProp);\n\n const [dragState, setDragState] = useState(false);\n\n const inputRef = useRef<HTMLInputElement | null>(null);\n\n const handleDragLeave = () => {\n setDragState(false);\n };\n\n const handleDragEnter: React.DragEventHandler = (event) => {\n if (disabled) return;\n event.stopPropagation();\n event.preventDefault();\n setDragState(true);\n };\n\n const onChangeHandler = (filesList: FileList) => {\n const filesToProcess = Object.values(filesList);\n\n const newFiles = filesToProcess.map((file) => {\n const newFile: HvFileData = new File([file], file.name, {\n type: file.type,\n lastModified: file.lastModified,\n });\n newFile.id = uniqueId(\"uploaded-file-data-\");\n\n const isSizeAllowed = file.size <= maxFileSize;\n const isFileAccepted =\n !accept ||\n accept.includes(file.type?.split(\"/\")[1]) || // TODO: remove in v6\n validateAccept(file, accept);\n\n if (!isFileAccepted) {\n newFile.errorMessage = labels?.fileTypeError;\n newFile.status = \"fail\";\n } else if (!isSizeAllowed) {\n newFile.errorMessage = labels?.fileSizeError;\n newFile.status = \"fail\";\n }\n\n return newFile;\n });\n\n onFilesAdded?.(newFiles);\n };\n\n return (\n <>\n {!hideLabels && (\n <div id={id} className={classes.dropZoneLabelsGroup}>\n <HvLabel\n id={setId(id, \"input-file-label\")}\n htmlFor={setId(id, \"input-file\")}\n label={labels?.dropzone}\n className={classes.dropZoneLabel}\n />\n <HvInfoMessage id={setId(id, \"description\")}>\n {Number.isInteger(maxFileSize) &&\n `${labels?.sizeWarning} ${convertUnits(maxFileSize)}`}\n {labels?.acceptedFiles\n ? labels.acceptedFiles\n : accept && `\\u00A0(${accept?.replaceAll(\",\", \", \")})`}\n </HvInfoMessage>\n </div>\n )}\n <div\n id={setId(id, \"input-file-container\")}\n className={cx(classes.dropZoneContainer, {\n [classes.dragAction]: dragState,\n [classes.dropZoneContainerDisabled]: disabled,\n })}\n >\n <input\n id={setId(id, \"input-file\")}\n className={classes.inputArea}\n type=\"file\"\n multiple={multiple}\n disabled={disabled}\n title={!disabled ? `${labels?.drag}\\xa0${labels?.selectFiles}` : \"\"}\n onClick={() => {\n if (inputRef.current) {\n inputRef.current.value = \"\";\n }\n }}\n onChange={() => {\n if (!disabled && inputRef.current?.files) {\n onChangeHandler(inputRef.current.files);\n }\n }}\n onDragEnter={handleDragEnter}\n onDragOver={handleDragEnter}\n onDragLeave={handleDragLeave}\n onDropCapture={handleDragLeave}\n onDrop={(event) => {\n if (disabled) return;\n\n const { files } = event.dataTransfer;\n if (multiple === true || files.length === 1) {\n event.stopPropagation();\n event.preventDefault();\n onChangeHandler(files);\n }\n }}\n ref={inputRef}\n accept={accept}\n {...inputProps}\n />\n <div className={classes?.dropArea}>\n {dragState ? (\n <div className={classes.dropZoneAreaLabels}>\n <HvTypography className={classes.dragText}>\n {labels?.dropFiles}\n </HvTypography>\n </div>\n ) : (\n <>\n <Doc\n iconSize=\"M\"\n className={classes.dropZoneAreaIcon}\n color={disabled ? \"secondary_60\" : \"secondary\"}\n />\n <div className={classes.dropZoneAreaLabels}>\n <HvTypography className={classes.dragText}>\n {labels?.drag}\n <span\n className={classes.selectFilesText}\n >{`\\xa0${labels?.selectFiles}`}</span>\n </HvTypography>\n </div>\n </>\n )}\n </div>\n </div>\n </>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;AAmGA,SAAS,eAAe,MAAa,YAAqB;AACxD,MAAI,CAAC,QAAQ,CAAC,WAAmB,QAAA;AAE3B,QAAA,gBAAgB,WAAW,MAAM,GAAG;AACpC,QAAA,WAAW,KAAK,QAAQ;AAC9B,QAAM,YAAY,KAAK,QAAQ,IAAI,YAAY;AAC/C,QAAM,eAAe,SAAS,QAAQ,SAAS,EAAE;AAE1C,SAAA,cAAc,KAAK,CAAC,SAAS;AAClC,UAAM,YAAY,KAAK,KAAK,EAAE,YAAY;AAC1C,QAAI,UAAU,OAAO,CAAC,MAAM,KAAK;AAC/B,aAAO,SAAS,cAAc,SAAS,SAAS;AAAA,IAAA;AAG9C,QAAA,UAAU,SAAS,IAAI,GAAG;AAC5B,aAAO,iBAAiB,UAAU,QAAQ,SAAS,EAAE;AAAA,IAAA;AAEvD,WAAO,aAAa;AAAA,EAAA,CACrB;AACH;AAEa,MAAA,aAAa,CAAC,UAA2B;AAC9C,QAAA;AAAA,IACJ,IAAI;AAAA,IACJ,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX,WAAW;AAAA,IACX;AAAA,EAAA,IACE,gBAAgB,cAAc,KAAK;AACjC,QAAA,KAAK,YAAY,MAAM;AAE7B,QAAM,EAAE,SAAS,OAAO,WAAW,WAAW;AAE9C,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,KAAK;AAE1C,QAAA,WAAW,OAAgC,IAAI;AAErD,QAAM,kBAAkB,MAAM;AAC5B,iBAA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AAA,EAAa,WAAW,QAAQ,UAC9B,kBAAQ,UACX,CAAA,EAAA,CACF,IAGE,qBAAA,UAAA,EAAA,UAAA;AAAA,YAAA;AAAA,cAAC;AAAA,cAAA;AAAA,gBACC,UAAS;AAAA,gBACT,WAAW,QAAQ;AAAA,gBACnB,OAAO,WAAW,iBAAiB;AAAA,cAAA;AAAA,YACrC;AAAA,YACA,oBAAC,SAAI,WAAW,QAAQ,oBACtB,UAAC,qBAAA,cAAA,EAAa,WAAW,QAAQ,UAC9B,UAAA;AAAA,cAAQ,QAAA;AAAA,cACT;AAAA,gBAAC;AAAA,gBAAA;AAAA,kBACC,WAAW,QAAQ;AAAA,kBACnB,UAAA,IAAO,QAAQ,WAAW;AAAA,gBAAA;AAAA,cAAA;AAAA,YAAG,EAAA,CACjC,EACF,CAAA;AAAA,UAAA,EAAA,CACF,EAEJ,CAAA;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EACF,GACF;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"DropZone.js","sources":["../../../../src/FileUploader/DropZone/DropZone.tsx"],"sourcesContent":["import { useContext, useRef, useState } from \"react\";\nimport { Doc } from \"@hitachivantara/uikit-react-icons\";\nimport {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport {\n HvFormElementContext,\n HvFormElementProps,\n HvInfoMessage,\n HvLabel,\n} from \"../../FormElement\";\nimport { useLabels } from \"../../hooks/useLabels\";\nimport { useUniqueId } from \"../../hooks/useUniqueId\";\nimport { uniqueId } from \"../../utils/helpers\";\nimport { setId } from \"../../utils/setId\";\nimport { HvFileData, HvFilesAddedEvent } from \"../File\";\nimport { convertUnits } from \"../utils\";\nimport { staticClasses, useClasses } from \"./DropZone.styles\";\n\nexport { staticClasses as dropZoneClasses };\n\nexport type HvDropZoneClasses = ExtractNames<typeof useClasses>;\n\nconst DEFAULT_LABELS = {\n /** Extensions of the accepted file types */\n acceptedFiles: \"\",\n /** Dropzone area label. @deprecated use `label` prop instead */\n dropzone: \"Label\",\n /** Size file warning label. */\n sizeWarning: \"Max. file size:\",\n /** Size file warning label. */\n drag: \"Drop files here or\",\n /** Size file warning label. */\n selectFiles: \"click to upload\",\n /** Theming sheet used to style components */\n dropFiles: \"Drop files here\",\n /** Message to display when file size is greater than allowed */\n fileSizeError: \"The file exceeds the maximum upload size\",\n /** Message to display when file type is greater than allowed */\n fileTypeError: \"File type not allowed for upload\",\n\n removeFileButtonLabel: \"Remove File\",\n};\n\nexport type HvDropZoneLabels = Partial<typeof DEFAULT_LABELS>;\n\nexport interface HvDropZoneProps\n extends Pick<HvFormElementProps, \"id\" | \"disabled\" | \"label\"> {\n /**\n * Labels to present in FileUploader.\n */\n labels?: HvDropZoneLabels;\n /**\n * Whether the Dropzone should accept multiple files at once.\n */\n multiple?: boolean;\n /**\n * Files extensions accepted for upload.\n */\n accept?: React.InputHTMLAttributes<HTMLInputElement>[\"accept\"];\n /**\n * Max upload size\n * */\n maxFileSize: number;\n /**\n * Function responsible for processing files added to the drop zone.\n */\n onFilesAdded?: HvFilesAddedEvent;\n /**\n * Whether the DropZone should hide labels or not.\n */\n hideLabels?: boolean;\n /**\n * Attributes applied to the input element.\n */\n inputProps?: React.InputHTMLAttributes<HTMLInputElement>;\n /**\n * A Jss Object used to override or extend the styles applied to the component.\n */\n classes?: HvDropZoneClasses;\n}\n\n// TODO: remove/review in `v6`: delegate to HTML `accept` and/or add custom validation\nfunction validateAccept(file?: File, acceptAttr?: string) {\n if (!file || !acceptAttr) return true;\n\n const acceptEntries = acceptAttr.split(\",\");\n const fileName = file.name || \"\";\n const mimeType = (file.type || \"\").toLowerCase();\n const baseMimeType = mimeType.replace(/\\/.*$/, \"\");\n\n return acceptEntries.some((type) => {\n const validType = type.trim().toLowerCase();\n if (validType.charAt(0) === \".\") {\n return fileName.toLowerCase().endsWith(validType);\n }\n // This is something like a image/* mime type\n if (validType.endsWith(\"/*\")) {\n return baseMimeType === validType.replace(/\\/.*$/, \"\");\n }\n return mimeType === validType;\n });\n}\n\nexport const HvDropZone = (props: HvDropZoneProps) => {\n const {\n id: idProp,\n classes: classesProp,\n label,\n labels: labelsProp,\n accept,\n maxFileSize,\n inputProps,\n hideLabels,\n multiple = true,\n onFilesAdded,\n } = useDefaultProps(\"HvDropZone\", props);\n const id = useUniqueId(idProp);\n const labels = useLabels(DEFAULT_LABELS, labelsProp);\n const { classes, cx } = useClasses(classesProp);\n const { disabled } = useContext(HvFormElementContext);\n\n const [dragState, setDragState] = useState(false);\n\n const inputRef = useRef<HTMLInputElement>(null);\n\n const handleDragLeave = () => {\n setDragState(false);\n };\n\n const handleDragEnter: React.DragEventHandler = (event) => {\n if (disabled) return;\n event.stopPropagation();\n event.preventDefault();\n setDragState(true);\n };\n\n const onChangeHandler = (filesList: FileList) => {\n const filesToProcess = Object.values(filesList);\n\n const newFiles = filesToProcess.map((file) => {\n const newFile: HvFileData = new File([file], file.name, {\n type: file.type,\n lastModified: file.lastModified,\n });\n newFile.id = uniqueId(\"uploaded-file-data-\");\n\n const isSizeAllowed = file.size <= maxFileSize;\n const isFileAccepted =\n !accept ||\n accept.includes(file.type?.split(\"/\")[1]) || // TODO: remove in v6\n validateAccept(file, accept);\n\n if (!isFileAccepted) {\n newFile.errorMessage = labels?.fileTypeError;\n newFile.status = \"fail\";\n } else if (!isSizeAllowed) {\n newFile.errorMessage = labels?.fileSizeError;\n newFile.status = \"fail\";\n }\n\n return newFile;\n });\n\n onFilesAdded?.(newFiles);\n };\n\n return (\n <>\n {!hideLabels && (\n <div id={id} className={classes.dropZoneLabelsGroup}>\n <HvLabel\n showGutter\n id={setId(id, \"input-file-label\")}\n htmlFor={setId(id, \"input-file\")}\n label={label ?? labels?.dropzone}\n className={classes.dropZoneLabel}\n />\n <HvInfoMessage id={setId(id, \"description\")}>\n {Number.isInteger(maxFileSize) &&\n `${labels?.sizeWarning} ${convertUnits(maxFileSize)}`}\n {labels?.acceptedFiles\n ? labels.acceptedFiles\n : accept && `\\u00A0(${accept?.replaceAll(\",\", \", \")})`}\n </HvInfoMessage>\n </div>\n )}\n <div\n id={setId(id, \"input-file-container\")}\n className={cx(classes.dropZoneContainer, {\n [classes.dragAction]: dragState,\n [classes.dropZoneContainerDisabled]: disabled,\n })}\n >\n <input\n id={setId(id, \"input-file\")}\n className={classes.inputArea}\n type=\"file\"\n multiple={multiple}\n disabled={disabled}\n title={!disabled ? `${labels?.drag}\\xa0${labels?.selectFiles}` : \"\"}\n onClick={() => {\n if (inputRef.current) {\n inputRef.current.value = \"\";\n }\n }}\n onChange={() => {\n if (!disabled && inputRef.current?.files) {\n onChangeHandler(inputRef.current.files);\n }\n }}\n onDragEnter={handleDragEnter}\n onDragOver={handleDragEnter}\n onDragLeave={handleDragLeave}\n onDropCapture={handleDragLeave}\n onDrop={(event) => {\n if (disabled) return;\n\n const { files } = event.dataTransfer;\n if (multiple === true || files.length === 1) {\n event.stopPropagation();\n event.preventDefault();\n onChangeHandler(files);\n }\n }}\n ref={inputRef}\n accept={accept}\n {...inputProps}\n />\n <div className={classes?.dropArea}>\n {dragState ? (\n <div className={classes.dropZoneAreaLabels}>\n <div className={classes.dragText}>{labels?.dropFiles}</div>\n </div>\n ) : (\n <>\n <Doc size=\"M\" className={classes.dropZoneAreaIcon} />\n <div className={classes.dropZoneAreaLabels}>\n <div className={classes.dragText}>\n {labels?.drag}\n <span\n className={classes.selectFilesText}\n >{`\\xa0${labels?.selectFiles}`}</span>\n </div>\n </div>\n </>\n )}\n </div>\n </div>\n </>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;AAyBA,MAAM,iBAAiB;AAAA;AAAA,EAErB,eAAe;AAAA;AAAA,EAEf,UAAU;AAAA;AAAA,EAEV,aAAa;AAAA;AAAA,EAEb,MAAM;AAAA;AAAA,EAEN,aAAa;AAAA;AAAA,EAEb,WAAW;AAAA;AAAA,EAEX,eAAe;AAAA;AAAA,EAEf,eAAe;AAAA,EAEf,uBAAuB;AACzB;AAyCA,SAAS,eA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AI,WAAW,QAAQ,oBACtB,UAAC,qBAAA,OAAA,EAAI,WAAW,QAAQ,UACrB,UAAA;AAAA,cAAQ,QAAA;AAAA,cACT;AAAA,gBAAC;AAAA,gBAAA;AAAA,kBACC,WAAW,QAAQ;AAAA,kBACnB,UAAA,IAAO,QAAQ,WAAW;AAAA,gBAAA;AAAA,cAAA;AAAA,YAAG,EAAA,CACjC,EACF,CAAA;AAAA,UAAA,EAAA,CACF,EAEJ,CAAA;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EACF,GACF;AAEJ;"}
|
|
@@ -8,15 +8,13 @@ const { staticClasses, useClasses } = createClasses("HvDropZone", {
|
|
|
8
8
|
display: "flex",
|
|
9
9
|
border: `1px dashed ${theme.colors.secondary_60}`,
|
|
10
10
|
cursor: "pointer",
|
|
11
|
-
|
|
11
|
+
backgroundColor: theme.colors.atmo1,
|
|
12
12
|
borderRadius: theme.radii.round,
|
|
13
13
|
"&:hover": {
|
|
14
|
-
|
|
15
|
-
border: `1px dashed ${theme.colors.secondary}`
|
|
14
|
+
borderColor: theme.colors.secondary
|
|
16
15
|
},
|
|
17
16
|
"&:focus-within": {
|
|
18
|
-
|
|
19
|
-
border: `1px dashed ${theme.colors.secondary}`,
|
|
17
|
+
borderColor: theme.colors.secondary,
|
|
20
18
|
...outlineStyles
|
|
21
19
|
}
|
|
22
20
|
},
|
|
@@ -29,22 +27,16 @@ const { staticClasses, useClasses } = createClasses("HvDropZone", {
|
|
|
29
27
|
}
|
|
30
28
|
},
|
|
31
29
|
dragAction: {
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
backgroundColor: theme.colors.atmo1,
|
|
31
|
+
borderColor: theme.colors.primary
|
|
34
32
|
},
|
|
35
33
|
dropZoneContainerDisabled: {
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
color: theme.colors.secondary_60,
|
|
35
|
+
backgroundColor: theme.colors.atmo3,
|
|
36
|
+
borderColor: "currentcolor",
|
|
38
37
|
cursor: "not-allowed",
|
|
39
38
|
"&:hover": {
|
|
40
|
-
|
|
41
|
-
border: `1px dashed ${theme.colors.secondary_60}`
|
|
42
|
-
},
|
|
43
|
-
"& $dragText": {
|
|
44
|
-
color: theme.colors.secondary_60
|
|
45
|
-
},
|
|
46
|
-
"& $selectFilesText": {
|
|
47
|
-
color: theme.colors.secondary_60
|
|
39
|
+
borderColor: "currentcolor"
|
|
48
40
|
}
|
|
49
41
|
},
|
|
50
42
|
inputArea: {
|
|
@@ -59,7 +51,8 @@ const { staticClasses, useClasses } = createClasses("HvDropZone", {
|
|
|
59
51
|
},
|
|
60
52
|
dropArea: {
|
|
61
53
|
display: "flex",
|
|
62
|
-
margin:
|
|
54
|
+
margin: theme.spacing("md", "auto"),
|
|
55
|
+
gap: theme.space.xs,
|
|
63
56
|
minHeight: 48
|
|
64
57
|
},
|
|
65
58
|
dropZoneAreaLabels: {
|
|
@@ -67,18 +60,11 @@ const { staticClasses, useClasses } = createClasses("HvDropZone", {
|
|
|
67
60
|
maxWidth: 120,
|
|
68
61
|
margin: "auto"
|
|
69
62
|
},
|
|
70
|
-
dropZoneAreaIcon: {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
},
|
|
74
|
-
dropZoneLabel: {
|
|
75
|
-
paddingBottom: 6
|
|
76
|
-
},
|
|
77
|
-
dragText: {
|
|
78
|
-
...theme.typography.body
|
|
79
|
-
},
|
|
63
|
+
dropZoneAreaIcon: {},
|
|
64
|
+
dropZoneLabel: {},
|
|
65
|
+
dragText: {},
|
|
80
66
|
selectFilesText: {
|
|
81
|
-
|
|
67
|
+
fontWeight: theme.typography.label.fontWeight
|
|
82
68
|
}
|
|
83
69
|
});
|
|
84
70
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DropZone.styles.js","sources":["../../../../src/FileUploader/DropZone/DropZone.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\nimport { theme } from \"@hitachivantara/uikit-styles\";\n\nimport { outlineStyles } from \"../../utils/focusUtils\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvDropZone\", {\n dropZoneContainer: {\n position: \"relative\",\n width: \"100%\",\n display: \"flex\",\n border: `1px dashed ${theme.colors.secondary_60}`,\n cursor: \"pointer\",\n
|
|
1
|
+
{"version":3,"file":"DropZone.styles.js","sources":["../../../../src/FileUploader/DropZone/DropZone.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\nimport { theme } from \"@hitachivantara/uikit-styles\";\n\nimport { outlineStyles } from \"../../utils/focusUtils\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvDropZone\", {\n dropZoneContainer: {\n position: \"relative\",\n width: \"100%\",\n display: \"flex\",\n border: `1px dashed ${theme.colors.secondary_60}`,\n cursor: \"pointer\",\n backgroundColor: theme.colors.atmo1,\n borderRadius: theme.radii.round,\n\n \"&:hover\": {\n borderColor: theme.colors.secondary,\n },\n\n \"&:focus-within\": {\n borderColor: theme.colors.secondary,\n ...outlineStyles,\n },\n },\n dropZoneLabelsGroup: {\n display: \"flex\",\n justifyContent: \"start\",\n\n \"& label:nth-of-type(1)\": {},\n\n \"& p:nth-of-type(2)\": {\n marginLeft: \"auto\",\n },\n },\n dragAction: {\n backgroundColor: theme.colors.atmo1,\n borderColor: theme.colors.primary,\n },\n dropZoneContainerDisabled: {\n color: theme.colors.secondary_60,\n backgroundColor: theme.colors.atmo3,\n borderColor: \"currentcolor\",\n cursor: \"not-allowed\",\n \"&:hover\": {\n borderColor: \"currentcolor\",\n },\n },\n inputArea: {\n opacity: 0,\n width: \"100%\",\n position: \"absolute\",\n height: \"100%\",\n cursor: \"pointer\",\n\n \"&:disabled\": {\n cursor: \"not-allowed\",\n },\n },\n dropArea: {\n display: \"flex\",\n margin: theme.spacing(\"md\", \"auto\"),\n gap: theme.space.xs,\n minHeight: 48,\n },\n dropZoneAreaLabels: {\n display: \"flex\",\n maxWidth: 120,\n margin: \"auto\",\n },\n dropZoneAre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B;AAAA,IAClB,SAAS;AAAA,IACT,UAAU;AAAA,IACV,QAAQ;AAAA,EACV;AAAA,EACA,kBAAkB,CAAC;AAAA,EACnB,eAAe,CAAC;AAAA,EAChB,UAAU,CAAC;AAAA,EACX,iBAAiB;AAAA,IACf,YAAY,MAAM,WAAW,MAAM;AAAA,EAAA;AAEvC,CAAC;"}
|
|
@@ -2,44 +2,44 @@ import { jsxs, jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { useDefaultProps } from "@hitachivantara/uikit-react-utils";
|
|
3
3
|
import { useLabels } from "../hooks/useLabels.js";
|
|
4
4
|
import { setId } from "../utils/setId.js";
|
|
5
|
+
import { useClasses } from "./FileUploader.styles.js";
|
|
6
|
+
import { staticClasses } from "./FileUploader.styles.js";
|
|
5
7
|
import { HvDropZone } from "./DropZone/DropZone.js";
|
|
6
8
|
import { HvFileList } from "./FileList/FileList.js";
|
|
9
|
+
import { HvFormElement } from "../FormElement/FormElement.js";
|
|
7
10
|
const DEFAULT_LABELS = {
|
|
8
|
-
dropzone: "Label",
|
|
9
|
-
sizeWarning: "Max. file size:",
|
|
10
|
-
drag: "Drop files here or",
|
|
11
|
-
selectFiles: "click to upload",
|
|
12
|
-
dropFiles: "Drop files here",
|
|
13
|
-
fileSizeError: "The file exceeds the maximum upload size",
|
|
14
|
-
fileTypeError: "File type not allowed for upload",
|
|
15
11
|
removeFileButtonLabel: "Remove File"
|
|
16
12
|
};
|
|
17
13
|
const HvFileUploader = (props) => {
|
|
18
14
|
const {
|
|
19
15
|
id,
|
|
20
16
|
className,
|
|
17
|
+
classes: classesProp,
|
|
21
18
|
labels: labelsProp,
|
|
22
19
|
fileList,
|
|
23
20
|
multiple = true,
|
|
24
|
-
|
|
25
|
-
hideLabels
|
|
21
|
+
label,
|
|
22
|
+
hideLabels,
|
|
26
23
|
maxFileSize = Infinity,
|
|
27
24
|
inputProps = {},
|
|
25
|
+
accept,
|
|
28
26
|
acceptedFiles = [],
|
|
27
|
+
// TODO: consider adding/replacing with onFilesChange
|
|
29
28
|
onFilesAdded,
|
|
30
29
|
onFileRemoved,
|
|
31
30
|
...others
|
|
32
31
|
} = useDefaultProps("HvFileUploader", props);
|
|
32
|
+
const { classes, cx } = useClasses(classesProp);
|
|
33
33
|
const labels = useLabels(DEFAULT_LABELS, labelsProp);
|
|
34
|
-
return /* @__PURE__ */ jsxs(
|
|
34
|
+
return /* @__PURE__ */ jsxs(HvFormElement, { id, className: cx(classes.root, className), ...others, children: [
|
|
35
35
|
/* @__PURE__ */ jsx(
|
|
36
36
|
HvDropZone,
|
|
37
37
|
{
|
|
38
38
|
id: setId(id, "dropzone"),
|
|
39
|
+
label,
|
|
39
40
|
labels,
|
|
40
41
|
multiple,
|
|
41
|
-
|
|
42
|
-
accept: acceptedFiles.join(","),
|
|
42
|
+
accept: accept ?? acceptedFiles.join(","),
|
|
43
43
|
maxFileSize,
|
|
44
44
|
onFilesAdded,
|
|
45
45
|
inputProps,
|
|
@@ -58,5 +58,6 @@ const HvFileUploader = (props) => {
|
|
|
58
58
|
] });
|
|
59
59
|
};
|
|
60
60
|
export {
|
|
61
|
-
HvFileUploader
|
|
61
|
+
HvFileUploader,
|
|
62
|
+
staticClasses as fileUploaderClasses
|
|
62
63
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileUploader.js","sources":["../../../src/FileUploader/FileUploader.tsx"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"FileUploader.js","sources":["../../../src/FileUploader/FileUploader.tsx"],"sourcesContent":["import {\n ExtractNames,\n useDefaultProps,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { HvFormElement, HvFormElementProps } from \"../FormElement\";\nimport { useLabels } from \"../hooks/useLabels\";\nimport { setId } from \"../utils/setId\";\nimport { HvDropZone, HvDropZoneLabels, HvDropZoneProps } from \"./DropZone\";\nimport { HvFileData, HvFileRemovedEvent, HvFilesAddedEvent } from \"./File\";\nimport { HvFileList } from \"./FileList\";\nimport { staticClasses, useClasses } from \"./FileUploader.styles\";\n\nexport { staticClasses as fileUploaderClasses };\n\nexport type HvFileUploaderClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvFileUploaderLabels extends HvDropZoneLabels {\n /** Value of aria-label to apply to remove file button in FileList */\n removeFileButtonLabel?: string;\n}\n\nexport interface HvFileUploaderProps extends HvFormElementProps {\n /**\n * An object containing all the labels.\n */\n labels?: HvFileUploaderLabels;\n /**\n * An object used to override or extend the styles applied to the component.\n */\n classes?: HvFileUploaderClasses;\n /**\n * The files to upload.\n */\n fileList?: HvFileData[];\n /**\n * Whether the Dropzone should accept multiple files at once.\n */\n multiple?: boolean;\n /**\n * If the input is disabled or not\n */\n disabled?: boolean;\n /**\n * Max upload size\n * */\n maxFileSize?: number;\n /** File types accepted for uploading. @see [HTML input file accept](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#accept) */\n accept?: HvDropZoneProps[\"accept\"];\n /** Files extensions accepted for upload. @deprecated use `accept` instead */\n acceptedFiles?: string[];\n /**\n * Callback fired when files are added.\n */\n onFilesAdded?: HvFilesAddedEvent;\n /**\n * Callback fired when file is removed from list.\n */\n onFileRemoved?: HvFileRemovedEvent;\n /**\n * Whether the DropZone should hide labels or not.\n */\n hideLabels?: boolean;\n /**\n * Attributes applied to the input element.\n */\n inputProps?: React.InputHTMLAttributes<HTMLInputElement>;\n}\n\n// TODO: This component needs to adopt the Form element shape and deprecate its way of composing labels\n\nconst DEFAULT_LABELS = {\n removeFileButtonLabel: \"Remove File\",\n};\n\n/**\n * Lets the user choose one or more files from their device storage. Once chosen,\n * the files can be uploaded to a server or manipulated on the client side.\n *\n * Accepted file types follow the format of the html [input accept attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file).\n */\nexport const HvFileUploader = (props: HvFileUploaderProps) => {\n const {\n id,\n className,\n classes: classesProp,\n labels: labelsProp,\n fileList,\n multiple = true,\n label,\n hideLabels,\n maxFileSize = Infinity,\n inputProps = {},\n accept,\n acceptedFiles = [],\n // TODO: consider adding/replacing with onFilesChange\n onFilesAdded,\n onFileRemoved,\n ...others\n } = useDefaultProps(\"HvFileUploader\", props);\n const { classes, cx } = useClasses(classesProp);\n const labels = useLabels(DEFAULT_LABELS, labelsProp);\n\n return (\n <HvFormElement id={id} className={cx(classes.root, className)} {...others}>\n <HvDropZone\n id={setId(id, \"dropzone\")}\n label={label}\n labels={labels}\n multiple={multiple}\n accept={accept ?? acceptedFiles.join(\",\")}\n maxFileSize={maxFileSize}\n onFilesAdded={onFilesAdded}\n inputProps={inputProps}\n hideLabels={hideLabels}\n />\n <HvFileList\n id={setId(id, \"filelist\")}\n list={fileList}\n onFileRemoved={onFileRemoved}\n removeFileButtonLabel={labels?.removeFileButtonLabel}\n />\n </HvFormElement>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;AAuEA,MAAM,iBAAiB;AAAA,EACrB,uBAAuB;AACzB;AAQa,MAAA,iBAAiB,CAAC,UAA+B;AACtD,QAAA;AAAA,IACJ;AAAA,IACA;AAAA,IACA,SAAS;AAAA,IACT,QAAQ;AAAA,IACR;AAAA,IACA,WAAW;AAAA,IACX;AAAA,IACA;AAAA,IACA,cAAc;AAAA,IACd,aAAa,CAAC;AAAA,IACd;AAAA,IACA,gBAAgB,CAAC;AAAA;AAAA,IAEjB;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EAAA,IACD,gBAAgB,kBAAkB,KAAK;AAC3C,QAAM,EAAE,SAAS,OAAO,WAAW,WAAW;AACxC,QAAA,SAAS,UAAU,gBAAgB,UAAU;AAGjD,SAAA,qBAAC,eAAc,EAAA,IAAQ,WAAW,GAAG,QAAQ,MAAM,SAAS,GAAI,GAAG,QACjE,UAAA;AAAA,IAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,IAAI,MAAM,IAAI,UAAU;AAAA,QACxB;AAAA,QACA;AAAA,QACA;AAAA,QACA,QAAQ,UAAU,cAAc,KAAK,GAAG;AAAA,QACxC;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MAAA;AAAA,IACF;AAAA,IACA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,IAAI,MAAM,IAAI,UAAU;AAAA,QACxB,MAAM;AAAA,QACN;AAAA,QACA,uBAAuB,QAAQ;AAAA,MAAA;AAAA,IAAA;AAAA,EACjC,GACF;AAEJ;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileUploader.styles.js","sources":["../../../src/FileUploader/FileUploader.styles.ts"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvFileUploader\", {\n root: {},\n});\n"],"names":[],"mappings":";AAEO,MAAM,EAAE,eAAe,eAAe,cAAc,kBAAkB;AAAA,EAC3E,MAAM,CAAA;AACR,CAAC;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../../src/FileUploader/utils.ts"],"sourcesContent":["const units = [\"B\", \"kB\", \"MB\", \"GB\", \"TB\", \"PB\", \"EB\", \"ZB\", \"YB\"];\n\
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../src/FileUploader/utils.ts"],"sourcesContent":["const units = [\"B\", \"kB\", \"MB\", \"GB\", \"TB\", \"PB\", \"EB\", \"ZB\", \"YB\"];\n\nconst findBestUnit = (bytes: number, base = 1000) => {\n const i = bytes > 0 ? Math.floor(Math.log(bytes) / Math.log(base)) : 0;\n const si = Math.min(i, units.length - 1); // safe index\n\n return { unit: units[si], value: bytes / base ** si };\n};\n\nexport const convertUnits = (bytes: number, base = 1000) => {\n const { unit, value } = findBestUnit(bytes, base);\n\n return value.toFixed(2) + unit;\n};\n"],"names":[],"mappings":"AAAA,MAAM,QAAQ,CAAC,KAAK,MAAM,MAAM,MAAM,MAAM,MAAM,MAAM,MAAM,IAAI;AAElE,MAAM,eAAe,CAAC,OAAe,OAAO,QAAS;AACnD,QAAM,IAAI,QAAQ,IAAI,KAAK,MAAM,KAAK,IAAI,KAAK,IAAI,KAAK,IAAI,IAAI,CAAC,IAAI;AACrE,QAAM,KAAK,KAAK,IAAI,GAAG,MAAM,SAAS,CAAC;AAEhC,SAAA,EAAE,MAAM,MAAM,EAAE,GAAG,OAAO,QAAQ,QAAQ,GAAG;AACtD;AAEO,MAAM,eAAe,CAAC,OAAe,OAAO,QAAS;AAC1D,QAAM,EAAE,MAAM,MAAA,IAAU,aAAa,OAAO,IAAI;AAEzC,SAAA,MAAM,QAAQ,CAAC,IAAI;AAC5B;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FilterGroup.js","sources":["../../../src/FilterGroup/FilterGroup.tsx"],"sourcesContent":["import { forwardRef } from \"react\";\nimport {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport {\n HvFormElement,\n HvFormElementProps,\n HvFormStatus,\n HvInfoMessage,\n HvLabel,\n HvWarningText,\n} from \"../FormElement\";\nimport { useControlled } from \"../hooks/useControlled\";\nimport { useLabels } from \"../hooks/useLabels\";\nimport { useUniqueId } from \"../hooks/useUniqueId\";\nimport { setId } from \"../utils/setId\";\nimport {\n HvFilterGroupContent,\n HvFilterGroupContentProps,\n} from \"./FilterContent\";\nimport { staticClasses, useClasses } from \"./FilterGroup.styles\";\nimport { HvFilterGroupProvider } from \"./FilterGroupContext\";\nimport {\n HvFilterGroupFilters,\n HvFilterGroupHorizontalPlacement,\n HvFilterGroupValue,\n} from \"./types\";\n\nexport { staticClasses as filterGroupClasses };\n\nexport type HvFilterGroupClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvFilterGroupProps\n extends Omit<\n HvFormElementProps,\n \"classes\" | \"onChange\" | \"defaultValue\" | \"statusMessage\"\n > {\n /** The initial value of the input when in single calendar mode. */\n filters: HvFilterGroupFilters;\n /** The form element name. */\n name?: string;\n /**\n * The label of the form element.\n *\n * The form element must be labeled for accessibility reasons.\n * If not provided, an aria-label or aria-labelledby must be provided instead.\n */\n label?: React.ReactNode;\n /** Provide additional descriptive text for the form element. */\n description?: React.ReactNode;\n /** Indicates that the form element is disabled. */\n disabled?: boolean;\n /** Indicates that user input is required on the form element. */\n required?: boolean;\n /**\n * The status of the form element.\n *\n * Valid is correct, invalid is incorrect and standBy means no validations have run.\n *\n * When uncontrolled and unspecified it will default to \"standBy\" and change to either \"valid\"\n * or \"invalid\" after any change to the state.\n */\n status?: HvFormStatus;\n /** The error message to show when `status` is \"invalid\". Defaults to \"Required\". */\n statusMessage?: React.ReactNode;\n /** The callback fired when the cancel button is clicked. */\n onCancel?: (event: React.MouseEvent<HTMLButtonElement> | Event) => void;\n /** The callback fired when the clear filters button is clicked. */\n onClear?: (event: React.MouseEvent<HTMLButtonElement>) => void;\n /** The callback fired when the value changes. */\n onChange?: (\n event: React.MouseEvent<HTMLButtonElement>,\n value?: HvFilterGroupValue,\n ) => void;\n /** An Object containing the various text associated with the input. */\n labels?: HvFilterGroupLabels;\n /** The placeholder value when nothing is selected. */\n placeholder?: string;\n /** The default value of the filter group. If defined the clear action will reset to it. */\n defaultValue?: HvFilterGroupValue;\n /** The value of the filter group. */\n value?: HvFilterGroupValue;\n /** The placement where the filter group should be placed according to the input. Options are `left` or `right`. */\n horizontalPlacement?: HvFilterGroupHorizontalPlacement;\n /** Disable the portal behavior. The children stay within it's parent DOM hierarchy. */\n disablePortal?: boolean;\n /** Sets if the filter container should be out of the screen or stay visible. */\n escapeWithReference?: boolean;\n /** The height of the filter panel, between 295 and 425. Defaults to 350 */\n height?: number | string;\n /** The filter content props */\n filterContentProps?: Partial<HvFilterGroupContentProps>;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvFilterGroupClasses;\n}\n\nconst DEFAULT_LABELS = {\n /** Apply button label. */\n applyLabel: \"Apply\",\n /** Cancel button label. */\n cancelLabel: \"Cancel\",\n /** Clear button label. */\n clearLabel: \"Clear Filters\",\n /** Placeholder label. */\n placeholder: \"Filters\",\n /** SearchBox placeholder label. */\n searchBoxPlaceholder: \"Search\",\n /** Select All placeholder label. */\n selectAll: \"All\",\n /** Multi selection conjunction placeholder label. */\n multiSelectionConjunction: \"/\",\n};\n\nexport type HvFilterGroupLabels = Partial<typeof DEFAULT_LABELS>;\n\n/**\n * This component implements one potential use-case of the Filter Group pattern Design System Specifies.\n * Due to the enormous variety of capabilities required for this, we strongly recommend checking the code of the component and extend it yourself,\n * while we do not provide a better approach for building this component with smaller and more composable parts.\n */\nexport const HvFilterGroup = forwardRef<HTMLDivElement, HvFilterGroupProps>(\n function HvFilterGroup(props, ref) {\n const {\n className,\n id,\n name,\n required,\n disabled,\n label,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n description,\n \"aria-describedby\": ariaDescribedBy,\n onChange,\n onCancel,\n onClear,\n status,\n statusMessage,\n labels: labelsProp,\n defaultValue,\n value,\n filters,\n horizontalPlacement = \"right\",\n disablePortal = true,\n escapeWithReference = true,\n height = 350,\n filterContentProps,\n classes: classesProp,\n ...others\n } = useDefaultProps(\"HvFilterGroup\", props);\n\n const { classes, cx } = useClasses(classesProp);\n const [validationMessage] = useControlled(statusMessage, \"Required\");\n\n const elementId = useUniqueId(id);\n\n const labels = useLabels(DEFAULT_LABELS, labelsProp);\n\n const hasLabel = label != null;\n\n const hasDescription = description != null;\n\n // Error message area will only be needed if the status is being controlled\n // or if required is true\n const canShowError = status !== undefined || required;\n\n return (\n <HvFormElement\n id={id}\n name={name}\n value={value}\n status={status}\n disabled={disabled}\n required={required}\n className={cx(classes.root, className)}\n {...others}\n >\n {(hasLabel || hasDescription) && (\n <div className={classes.labelContainer}>\n {hasLabel && (\n <HvLabel\n id={setId(elementId, \"label\")}\n htmlFor={setId(elementId, \"input\")}\n label={label}\n className={classes.label}\n />\n )}\n\n {hasDescription && (\n <HvInfoMessage\n id={setId(elementId, \"description\")}\n className={classes.description}\n >\n {description}\n </HvInfoMessage>\n )}\n </div>\n )}\n <HvFilterGroupProvider\n defaultValue={defaultValue}\n value={value}\n filters={filters}\n >\n <HvFilterGroupContent\n ref={ref}\n id={elementId}\n disabled={disabled}\n disablePortal={disablePortal}\n variableWidth\n placement={horizontalPlacement}\n escapeWithReference={escapeWithReference}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n status={status}\n onChange={onChange}\n onCancel={onCancel}\n onClear={onClear}\n labels={labels}\n height={height}\n {...filterContentProps}\n />\n {canShowError && (\n <HvWarningText\n id={setId(elementId, \"error\")}\n disableBorder\n className={classes.error}\n >\n {validationMessage}\n </HvWarningText>\n )}\n </HvFilterGroupProvider>\n </HvFormElement>\n );\n },\n);\n"],"names":["HvFilterGroup"],"mappings":";;;;;;;;;;;;;;;AAkGA,MAAM,iBAAiB;AAAA;AAAA,EAErB,YAAY;AAAA;AAAA,EAEZ,aAAa;AAAA;AAAA,EAEb,YAAY;AAAA;AAAA,EAEZ,aAAa;AAAA;AAAA,EAEb,sBAAsB;AAAA;AAAA,EAEtB,WAAW;AAAA;AAAA,EAEX,2BAA2B;AAC7B;AASO,MAAM,gBAAgB;AAAA,EAC3B,SAASA,eAAc,OAAO,KAAK;AAC3B,UAAA;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,cAAc;AAAA,MACd,mBAAmB;AAAA,MACnB;AAAA,MACA,oBAAoB;AAAA,MACpB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,QAAQ;AAAA,MACR;AAAA,MACA;AAAA,MACA;AAAA,MACA,sBAAsB;AAAA,MACtB,gBAAgB;AAAA,MAChB,sBAAsB;AAAA,MACtB,SAAS;AAAA,MACT;AAAA,MACA,SAAS;AAAA,MACT,GAAG;AAAA,IAAA,IACD,gBAAgB,iBAAiB,KAAK;AAE1C,UAAM,EAAE,SAAS,OAAO,WAAW,WAAW;AAC9C,UAAM,CAAC,iBAAiB,IAAI,cAAc,eAAe,UAAU;AAE7D,UAAA,YAAY,YAAY,EAAE;AAE1B,UAAA,SAA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A;AAAA,kBAAA;AAAA,gBAAA;AAAA,cACH;AAAA,YAAA;AAAA,UAAA;AAAA,QAEJ;AAAA,MAAA;AAAA,IACF;AAAA,EAAA;AAGN;"}
|
|
1
|
+
{"version":3,"file":"FilterGroup.js","sources":["../../../src/FilterGroup/FilterGroup.tsx"],"sourcesContent":["import { forwardRef } from \"react\";\nimport {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport {\n HvFormElement,\n HvFormElementProps,\n HvFormStatus,\n HvInfoMessage,\n HvLabel,\n HvWarningText,\n} from \"../FormElement\";\nimport { useControlled } from \"../hooks/useControlled\";\nimport { useLabels } from \"../hooks/useLabels\";\nimport { useUniqueId } from \"../hooks/useUniqueId\";\nimport { setId } from \"../utils/setId\";\nimport {\n HvFilterGroupContent,\n HvFilterGroupContentProps,\n} from \"./FilterContent\";\nimport { staticClasses, useClasses } from \"./FilterGroup.styles\";\nimport { HvFilterGroupProvider } from \"./FilterGroupContext\";\nimport {\n HvFilterGroupFilters,\n HvFilterGroupHorizontalPlacement,\n HvFilterGroupValue,\n} from \"./types\";\n\nexport { staticClasses as filterGroupClasses };\n\nexport type HvFilterGroupClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvFilterGroupProps\n extends Omit<\n HvFormElementProps,\n \"classes\" | \"onChange\" | \"defaultValue\" | \"statusMessage\"\n > {\n /** The initial value of the input when in single calendar mode. */\n filters: HvFilterGroupFilters;\n /** The form element name. */\n name?: string;\n /**\n * The label of the form element.\n *\n * The form element must be labeled for accessibility reasons.\n * If not provided, an aria-label or aria-labelledby must be provided instead.\n */\n label?: React.ReactNode;\n /** Provide additional descriptive text for the form element. */\n description?: React.ReactNode;\n /** Indicates that the form element is disabled. */\n disabled?: boolean;\n /** Indicates that user input is required on the form element. */\n required?: boolean;\n /**\n * The status of the form element.\n *\n * Valid is correct, invalid is incorrect and standBy means no validations have run.\n *\n * When uncontrolled and unspecified it will default to \"standBy\" and change to either \"valid\"\n * or \"invalid\" after any change to the state.\n */\n status?: HvFormStatus;\n /** The error message to show when `status` is \"invalid\". Defaults to \"Required\". */\n statusMessage?: React.ReactNode;\n /** The callback fired when the cancel button is clicked. */\n onCancel?: (event: React.MouseEvent<HTMLButtonElement> | Event) => void;\n /** The callback fired when the clear filters button is clicked. */\n onClear?: (event: React.MouseEvent<HTMLButtonElement>) => void;\n /** The callback fired when the value changes. */\n onChange?: (\n event: React.MouseEvent<HTMLButtonElement>,\n value?: HvFilterGroupValue,\n ) => void;\n /** An Object containing the various text associated with the input. */\n labels?: HvFilterGroupLabels;\n /** The placeholder value when nothing is selected. */\n placeholder?: string;\n /** The default value of the filter group. If defined the clear action will reset to it. */\n defaultValue?: HvFilterGroupValue;\n /** The value of the filter group. */\n value?: HvFilterGroupValue;\n /** The placement where the filter group should be placed according to the input. Options are `left` or `right`. */\n horizontalPlacement?: HvFilterGroupHorizontalPlacement;\n /** Disable the portal behavior. The children stay within it's parent DOM hierarchy. */\n disablePortal?: boolean;\n /** Sets if the filter container should be out of the screen or stay visible. */\n escapeWithReference?: boolean;\n /** The height of the filter panel, between 295 and 425. Defaults to 350 */\n height?: number | string;\n /** The filter content props */\n filterContentProps?: Partial<HvFilterGroupContentProps>;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvFilterGroupClasses;\n}\n\nconst DEFAULT_LABELS = {\n /** Apply button label. */\n applyLabel: \"Apply\",\n /** Cancel button label. */\n cancelLabel: \"Cancel\",\n /** Clear button label. */\n clearLabel: \"Clear Filters\",\n /** Placeholder label. */\n placeholder: \"Filters\",\n /** SearchBox placeholder label. */\n searchBoxPlaceholder: \"Search\",\n /** Select All placeholder label. */\n selectAll: \"All\",\n /** Multi selection conjunction placeholder label. */\n multiSelectionConjunction: \"/\",\n};\n\nexport type HvFilterGroupLabels = Partial<typeof DEFAULT_LABELS>;\n\n/**\n * This component implements one potential use-case of the Filter Group pattern Design System Specifies.\n * Due to the enormous variety of capabilities required for this, we strongly recommend checking the code of the component and extend it yourself,\n * while we do not provide a better approach for building this component with smaller and more composable parts.\n */\nexport const HvFilterGroup = forwardRef<HTMLDivElement, HvFilterGroupProps>(\n function HvFilterGroup(props, ref) {\n const {\n className,\n id,\n name,\n required,\n disabled,\n label,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n description,\n \"aria-describedby\": ariaDescribedBy,\n onChange,\n onCancel,\n onClear,\n status,\n statusMessage,\n labels: labelsProp,\n defaultValue,\n value,\n filters,\n horizontalPlacement = \"right\",\n disablePortal = true,\n escapeWithReference = true,\n height = 350,\n filterContentProps,\n classes: classesProp,\n ...others\n } = useDefaultProps(\"HvFilterGroup\", props);\n\n const { classes, cx } = useClasses(classesProp);\n const [validationMessage] = useControlled(statusMessage, \"Required\");\n\n const elementId = useUniqueId(id);\n\n const labels = useLabels(DEFAULT_LABELS, labelsProp);\n\n const hasLabel = label != null;\n\n const hasDescription = description != null;\n\n // Error message area will only be needed if the status is being controlled\n // or if required is true\n const canShowError = status !== undefined || required;\n\n return (\n <HvFormElement\n id={id}\n name={name}\n value={value}\n status={status}\n disabled={disabled}\n required={required}\n className={cx(classes.root, className)}\n {...others}\n >\n {(hasLabel || hasDescription) && (\n <div className={classes.labelContainer}>\n {hasLabel && (\n <HvLabel\n showGutter\n id={setId(elementId, \"label\")}\n htmlFor={setId(elementId, \"input\")}\n label={label}\n className={classes.label}\n />\n )}\n\n {hasDescription && (\n <HvInfoMessage\n id={setId(elementId, \"description\")}\n className={classes.description}\n >\n {description}\n </HvInfoMessage>\n )}\n </div>\n )}\n <HvFilterGroupProvider\n defaultValue={defaultValue}\n value={value}\n filters={filters}\n >\n <HvFilterGroupContent\n ref={ref}\n id={elementId}\n disabled={disabled}\n disablePortal={disablePortal}\n variableWidth\n placement={horizontalPlacement}\n escapeWithReference={escapeWithReference}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n status={status}\n onChange={onChange}\n onCancel={onCancel}\n onClear={onClear}\n labels={labels}\n height={height}\n {...filterContentProps}\n />\n {canShowError && (\n <HvWarningText\n id={setId(elementId, \"error\")}\n disableBorder\n className={classes.error}\n >\n {validationMessage}\n </HvWarningText>\n )}\n </HvFilterGroupProvider>\n </HvFormElement>\n );\n },\n);\n"],"names":["HvFilterGroup"],"mappings":";;;;;;;;;;;;;;;AAkGA,MAAM,iBAAiB;AAAA;AAAA,EAErB,YAAY;AAAA;AAAA,EAEZ,aAAa;AAAA;AAAA,EAEb,YAAY;AAAA;AAAA,EAEZ,aAAa;AAAA;AAAA,EAEb,sBAAsB;AAAA;AAAA,EAEtB,WAAW;AAAA;AAAA,EAEX,2BAA2B;AAC7B;AASO,MAAM,gBAAgB;AAAA,EAC3B,SAASA,eAAc,OAAO,KAAK;AAC3B,UAAA;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,cAAc;AAAA,MACd,mBAAmB;AAAA,MACnB;AAAA,MACA,oBAAoB;AAAA,MACpB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,QAAQ;AAAA,MACR;AAAA,MACA;AAAA,MACA;AAAA,MACA,sBAAsB;AAAA,MACtB,gBAAgB;AAAA,MAChB,sBAAsB;AAAA,MACtB,SAAS;AAAA,MACT;AAAA,MACA,SAAS;AAAA,MACT,GAAG;AAAA,IAAA,IACD,gBAAgB,iBAAiB,KAAK;AAE1C,UAAM,EAAE,SAAS,OAAO,WAAW,WAAW;AAC9C,UAAM,CAAC,iBAAiB,IAAI,cAAc,eAAe,UAAU;AAE7D,UAAA,YAAY,YAAY,EAAE;AAE1B,UAAA,SAAS,UAAU,gBAAgB,UAAU;AAEnD,UAAM,WAAW,SAAS;AAE1B,UAAM,iBAAiB,eAAe;AAIhC,UAAA,eAAe,WAAW,UAAa;AAG3C,WAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA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
2
2
|
const { staticClasses, useClasses } = createClasses("HvFilterGroup", {
|
|
3
3
|
root: {},
|
|
4
|
-
label: {
|
|
5
|
-
display: "flex",
|
|
6
|
-
alignItems: "flex-start"
|
|
7
|
-
},
|
|
4
|
+
label: {},
|
|
8
5
|
labelContainer: { display: "flex", alignItems: "flex-start" },
|
|
9
6
|
description: {},
|
|
10
7
|
error: {}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FilterGroup.styles.js","sources":["../../../src/FilterGroup/FilterGroup.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvFilterGroup\", {\n root: {},\n label: {
|
|
1
|
+
{"version":3,"file":"FilterGroup.styles.js","sources":["../../../src/FilterGroup/FilterGroup.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvFilterGroup\", {\n root: {},\n label: {},\n labelContainer: { display: \"flex\", alignItems: \"flex-start\" },\n description: {},\n error: {},\n});\n"],"names":[],"mappings":";AAEO,MAAM,EAAE,eAAe,eAAe,cAAc,iBAAiB;AAAA,EAC1E,MAAM,CAAC;AAAA,EACP,OAAO,CAAC;AAAA,EACR,gBAAgB,EAAE,SAAS,QAAQ,YAAY,aAAa;AAAA,EAC5D,aAAa,CAAC;AAAA,EACd,OAAO,CAAA;AACT,CAAC;"}
|
|
@@ -14,6 +14,7 @@ const HvLabel = (props) => {
|
|
|
14
14
|
className,
|
|
15
15
|
children,
|
|
16
16
|
label,
|
|
17
|
+
showGutter,
|
|
17
18
|
disabled: disabledProp,
|
|
18
19
|
required: requiredProp,
|
|
19
20
|
htmlFor: htmlForProp,
|
|
@@ -33,8 +34,8 @@ const HvLabel = (props) => {
|
|
|
33
34
|
className: cx(
|
|
34
35
|
classes.root,
|
|
35
36
|
{
|
|
36
|
-
[classes.labelDisabled]:
|
|
37
|
-
[classes.childGutter]:
|
|
37
|
+
[classes.labelDisabled]: disabled,
|
|
38
|
+
[classes.childGutter]: showGutter || children && label
|
|
38
39
|
},
|
|
39
40
|
className
|
|
40
41
|
),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Label.js","sources":["../../../../src/FormElement/Label/Label.tsx"],"sourcesContent":["import { useContext } from \"react\";\nimport {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { HvTypography, HvTypographyProps } from \"../../Typography\";\nimport { setId } from \"../../utils/setId\";\nimport { HvFormElementContext } from \"../context\";\nimport { findDescriptors } from \"../utils\";\nimport { staticClasses, useClasses } from \"./Label.styles\";\n\nexport { staticClasses as labelClasses };\n\nexport type HvLabelClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvLabelProps extends HvTypographyProps<\"label\"> {\n /** Id to be applied to the root node */\n id?: string;\n /** The text to be shown by the label. */\n label?: React.ReactNode;\n /** The id of the form element the label is bound to. */\n htmlFor?: string;\n /** If `true` the label is displayed with a disabled style. */\n disabled?: boolean;\n /** If `true`, the label will indicate that the form element is required (an `*` after the label text). */\n required?: boolean;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvLabelClasses;\n}\n\n/**\n * Provides the user with a recognizable name for a given form element.\n */\nexport const HvLabel = (props: HvLabelProps) => {\n const {\n id: idProp,\n classes: classesProp,\n className,\n children,\n label,\n disabled: disabledProp,\n required: requiredProp,\n htmlFor: htmlForProp,\n ...others\n } = useDefaultProps(\"HvLabel\", props);\n\n const { classes, cx } = useClasses(classesProp);\n\n const context = useContext(HvFormElementContext);\n\n const disabled = disabledProp ?? context.disabled;\n const required = requiredProp ?? context.required;\n const id = idProp ?? setId(context.id, \"label\");\n\n const forId = htmlForProp || findDescriptors(children)?.input?.[0]?.id;\n\n return (\n <>\n <HvTypography\n id={id}\n className={cx(\n classes.root,\n {\n [classes.labelDisabled]:
|
|
1
|
+
{"version":3,"file":"Label.js","sources":["../../../../src/FormElement/Label/Label.tsx"],"sourcesContent":["import { useContext } from \"react\";\nimport {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { HvTypography, HvTypographyProps } from \"../../Typography\";\nimport { setId } from \"../../utils/setId\";\nimport { HvFormElementContext } from \"../context\";\nimport { findDescriptors } from \"../utils\";\nimport { staticClasses, useClasses } from \"./Label.styles\";\n\nexport { staticClasses as labelClasses };\n\nexport type HvLabelClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvLabelProps extends HvTypographyProps<\"label\"> {\n /** Id to be applied to the root node */\n id?: string;\n /** The text to be shown by the label. */\n label?: React.ReactNode;\n /** Whether to give label gutter spacing */\n showGutter?: boolean;\n /** The id of the form element the label is bound to. */\n htmlFor?: string;\n /** If `true` the label is displayed with a disabled style. */\n disabled?: boolean;\n /** If `true`, the label will indicate that the form element is required (an `*` after the label text). */\n required?: boolean;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvLabelClasses;\n}\n\n/**\n * Provides the user with a recognizable name for a given form element.\n */\nexport const HvLabel = (props: HvLabelProps) => {\n const {\n id: idProp,\n classes: classesProp,\n className,\n children,\n label,\n showGutter,\n disabled: disabledProp,\n required: requiredProp,\n htmlFor: htmlForProp,\n ...others\n } = useDefaultProps(\"HvLabel\", props);\n\n const { classes, cx } = useClasses(classesProp);\n\n const context = useContext(HvFormElementContext);\n\n const disabled = disabledProp ?? context.disabled;\n const required = requiredProp ?? context.required;\n const id = idProp ?? setId(context.id, \"label\");\n\n const forId = htmlForProp || findDescriptors(children)?.input?.[0]?.id;\n\n return (\n <>\n <HvTypography\n id={id}\n className={cx(\n classes.root,\n {\n [classes.labelDisabled]: disabled,\n [classes.childGutter]: showGutter || (children && label),\n },\n className,\n )}\n variant=\"label\"\n component=\"label\"\n htmlFor={forId}\n {...others}\n >\n {label}\n {required && <span aria-hidden=\"true\">*</span>}\n </HvTypography>\n {children}\n </>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;AAoCa,MAAA,UAAU,CAAC,UAAwB;AACxC,QAAA;AAAA,IACJ,IAAI;AAAA,IACJ,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV,UAAU;AAAA,IACV,SAAS;AAAA,IACT,GAAG;AAAA,EAAA,IACD,gBAAgB,WAAW,KAAK;AAEpC,QAAM,EAAE,SAAS,OAAO,WAAW,WAAW;AAExC,QAAA,UAAU,WAAW,oBAAoB;AAEzC,QAAA,WAAW,gBAAgB,QAAQ;AACnC,QAAA,WAAW,gBAAgB,QAAQ;AACzC,QAAM,KAAK,UAAU,MAAM,QAAQ,IAAI,OAAO;AAE9C,QAAM,QAAQ,eAAe,gBAAgB,QAAQ,GAAG,QAAQ,CAAC,GAAG;AAEpE,SAEI,qBAAA,UAAA,EAAA,UAAA;AAAA,IAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC;AAAA,QACA,WAAW;AAAA,UACT,QAAQ;AAAA,UACR;AAAA,YACE,CAAC,QAAQ,aAAa,GAAG;AAAA,YACzB,CAAC,QAAQ,WAAW,GAAG,cAAe,YAAY;AAAA,UACpD;AAAA,UACA;AAAA,QACF;AAAA,QACA,SAAQ;AAAA,QACR,WAAU;AAAA,QACV,SAAS;AAAA,QACR,GAAG;AAAA,QAEH,UAAA;AAAA,UAAA;AAAA,UACA,YAAY,oBAAC,QAAK,EAAA,eAAY,QAAO,UAAC,IAAA,CAAA;AAAA,QAAA;AAAA,MAAA;AAAA,IACzC;AAAA,IACC;AAAA,EAAA,GACH;AAEJ;"}
|
|
@@ -3,7 +3,7 @@ import { theme } from "@hitachivantara/uikit-styles";
|
|
|
3
3
|
const { staticClasses, useClasses } = createClasses("HvLabel", {
|
|
4
4
|
root: { fontWeight: theme.fontWeights.normal, display: "inline-block" },
|
|
5
5
|
labelDisabled: { color: theme.colors.secondary_60 },
|
|
6
|
-
childGutter: { paddingBottom:
|
|
6
|
+
childGutter: { paddingBottom: 4 }
|
|
7
7
|
});
|
|
8
8
|
export {
|
|
9
9
|
staticClasses,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Label.styles.js","sources":["../../../../src/FormElement/Label/Label.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\nimport { theme } from \"@hitachivantara/uikit-styles\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvLabel\", {\n root: { fontWeight: theme.fontWeights.normal, display: \"inline-block\" },\n labelDisabled: { color: theme.colors.secondary_60 },\n childGutter: { paddingBottom:
|
|
1
|
+
{"version":3,"file":"Label.styles.js","sources":["../../../../src/FormElement/Label/Label.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\nimport { theme } from \"@hitachivantara/uikit-styles\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvLabel\", {\n root: { fontWeight: theme.fontWeights.normal, display: \"inline-block\" },\n labelDisabled: { color: theme.colors.secondary_60 },\n childGutter: { paddingBottom: 4 },\n});\n"],"names":[],"mappings":";;AAGO,MAAM,EAAE,eAAe,eAAe,cAAc,WAAW;AAAA,EACpE,MAAM,EAAE,YAAY,MAAM,YAAY,QAAQ,SAAS,eAAe;AAAA,EACtE,eAAe,EAAE,OAAO,MAAM,OAAO,aAAa;AAAA,EAClD,aAAa,EAAE,eAAe,EAAE;AAClC,CAAC;"}
|
|
@@ -3,7 +3,7 @@ import { forwardRef, useContext, useRef, useState, useEffect } from "react";
|
|
|
3
3
|
import { ClickAwayListener } from "@mui/base/ClickAwayListener";
|
|
4
4
|
import { Popper } from "@mui/base/Popper";
|
|
5
5
|
import { useForkRef } from "@mui/material/utils";
|
|
6
|
-
import { useTheme } from "@hitachivantara/uikit-react-utils";
|
|
6
|
+
import { useDefaultProps, useTheme } from "@hitachivantara/uikit-react-utils";
|
|
7
7
|
import { getContainerElement } from "../../utils/document.js";
|
|
8
8
|
import { setId } from "../../utils/setId.js";
|
|
9
9
|
import { HvFormElementContext } from "../context.js";
|
|
@@ -25,7 +25,7 @@ const HvSuggestions = forwardRef(function HvSuggestions2(props, extRef) {
|
|
|
25
25
|
onSuggestionSelected,
|
|
26
26
|
popperProps,
|
|
27
27
|
...others
|
|
28
|
-
} = props;
|
|
28
|
+
} = useDefaultProps("HvSuggestions", props);
|
|
29
29
|
const { classes, cx } = useClasses(classesProp);
|
|
30
30
|
const { rootId } = useTheme();
|
|
31
31
|
const context = useContext(HvFormElementContext);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Suggestions.js","sources":["../../../../src/FormElement/Suggestions/Suggestions.tsx"],"sourcesContent":["import { forwardRef, useContext, useEffect, useRef, useState } from \"react\";\nimport {\n ClickAwayListener,\n ClickAwayListenerProps,\n} from \"@mui/base/ClickAwayListener\";\nimport { Popper, PopperProps } from \"@mui/base/Popper\";\nimport { useForkRef } from \"@mui/material/utils\";\nimport {
|
|
1
|
+
{"version":3,"file":"Suggestions.js","sources":["../../../../src/FormElement/Suggestions/Suggestions.tsx"],"sourcesContent":["import { forwardRef, useContext, useEffect, useRef, useState } from \"react\";\nimport {\n ClickAwayListener,\n ClickAwayListenerProps,\n} from \"@mui/base/ClickAwayListener\";\nimport { Popper, PopperProps } from \"@mui/base/Popper\";\nimport { useForkRef } from \"@mui/material/utils\";\nimport {\n useDefaultProps,\n useTheme,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { HvListItem } from \"../../ListContainer\";\nimport { HvSelectionList } from \"../../SelectionList\";\nimport { HvBaseProps } from \"../../types/generic\";\nimport { getContainerElement } from \"../../utils/document\";\nimport { setId } from \"../../utils/setId\";\nimport { HvFormElementContext } from \"../context\";\nimport { staticClasses, useClasses } from \"./Suggestions.styles\";\n\nexport { staticClasses as suggestionsClasses };\n\nexport type HvSuggestionsClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvSuggestion {\n id?: string;\n label: React.ReactNode;\n value?: string;\n disabled?: boolean;\n}\n\nexport interface HvSuggestionsProps extends HvBaseProps {\n /** Whether suggestions is visible */\n open?: boolean;\n /**\n * Whether suggestions is visible.\n * @deprecated use `open` instead.\n * */\n expanded?: boolean;\n /** The HTML element Suggestions attaches to. */\n anchorEl?: HTMLElement | null;\n /** Array of { id, label, ...others } values to display in the suggestion list */\n suggestionValues?: HvSuggestion[] | null;\n /** Function called when a suggestion is selected */\n onSuggestionSelected?: (event: React.MouseEvent, value: HvSuggestion) => void;\n /** Function called when suggestion list is closed */\n onClose?: ClickAwayListenerProps[\"onClickAway\"];\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvSuggestionsClasses;\n /**\n * If enabled, the suggestions list will be rendered using a portal.\n * If disabled, it will be under the DOM hierarchy of the parent component.\n * @default false\n * */\n enablePortal?: boolean;\n /** Props passed to the underlying MUI Popper component */\n popperProps?: Partial<PopperProps>;\n}\n\nexport const HvSuggestions = forwardRef<\n // no-indent\n unknown,\n HvSuggestionsProps\n>(function HvSuggestions(props, extRef) {\n const {\n id: idProp,\n className,\n classes: classesProp,\n expanded = false,\n enablePortal = false,\n open: openProp,\n anchorEl,\n suggestionValues = [],\n onClose,\n onSuggestionSelected,\n popperProps,\n ...others\n } = useDefaultProps(\"HvSuggestions\", props);\n\n const { classes, cx } = useClasses(classesProp);\n\n const { rootId } = useTheme();\n\n const context = useContext(HvFormElementContext);\n const id = idProp ?? setId(context.id, \"suggestions\");\n\n const ref = useRef<HTMLDivElement>(null);\n const forkedRef = useForkRef(ref, extRef);\n\n // TODO: remove controlled+uncontrolled `expanded` prop in v6\n const [isOpen, setIsOpen] = useState(expanded);\n useEffect(() => {\n setIsOpen(expanded);\n }, [expanded]);\n\n return (\n <div\n id={id}\n ref={forkedRef}\n className={cx(classes.root, className)}\n {...others}\n >\n <ClickAwayListener\n onClickAway={(event) => {\n setIsOpen(false);\n onClose?.(event);\n }}\n >\n <Popper\n style={{\n // @ts-ignore\n \"--popper-width\": enablePortal\n ? `${anchorEl?.clientWidth}px`\n : \"100%\",\n }}\n open={openProp ?? isOpen}\n disablePortal={!enablePortal}\n container={enablePortal ? getContainerElement(rootId) : undefined}\n anchorEl={anchorEl}\n className={cx(classes.popper, {\n [classes.portal]: enablePortal,\n })}\n {...popperProps}\n >\n <HvSelectionList\n className={classes.list}\n id={setId(id, \"list\")}\n onChange={onSuggestionSelected}\n >\n {suggestionValues?.map((item) => (\n <HvListItem key={item.id} value={item} disabled={item.disabled}>\n {item.label}\n </HvListItem>\n ))}\n </HvSelectionList>\n </Popper>\n </ClickAwayListener>\n </div>\n );\n});\n"],"names":["HvSuggestions"],"mappings":";;;;;;;;;;;;;AA4DO,MAAM,gBAAgB,WAI3B,SAASA,eAAc,OAAO,QAAQ;AAChC,QAAA;AAAA,IACJ,IAAI;AAAA,IACJ;AAAA,IACA,SAAS;AAAA,IACT,WAAW;AAAA,IACX,eAAe;AAAA,IACf,MAAM;AAAA,IACN;AAAA,IACA,mBAAmB,CAAC;AAAA,IACpB;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EAAA,IACD,gBAAgB,iBAAiB,KAAK;AAE1C,QAAM,EAAE,SAAS,OAAO,WAAW,WAAW;AAExC,QAAA,EAAE,OAAO,IAAI,SAAS;AAEtB,QAAA,UAAU,WAAW,oBAAoB;AAC/C,QAAM,KAAK,UAAU,MAAM,QAAQ,IAAI,aAAa;AAE9C,QAAA,MAAM,OAAuB,IAAI;AACjC,QAAA,YAAY,WAAW,KAAK,MAAM;AAGxC,QAAM,CAAC,QAAQ,SAAS,IAAI,SAAS,QAAQ;AAC7C,YAAU,MAAM;AACd,cAAU,QAAQ;AAAA,EAAA,GACjB,CAAC,QAAQ,CAAC;AAGX,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC;AAAA,MACA,KAAK;AAAA,MACL,WAAW,GAAG,QAAQ,MAAM,SAAS;AAAA,MACpC,GAAG;AAAA,MAEJ,UAAA;AAAA,QAAC;AAAA,QAAA;AAAA,UACC,aAAa,CAAC,UAAU;AACtB,sBAAU,KAAK;AACf,sBAAU,KAAK;AAAA,UACjB;AAAA,UAEA,UAAA;AAAA,YAAC;AAAA,YAAA;AAAA,cACC,OAAO;AAAA;AAAA,gBAEL,kBAAkB,eACd,GAAG,UAAU,WAAW,OACxB;AAAA,cACN;AAAA,cACA,MAAM,YAAY;AAAA,cAClB,eAAe,CAAC;AAAA,cAChB,WAAW,eAAe,oBAAoB,MAAM,IAAI;AAAA,cACxD;AAAA,cACA,WAAW,GAAG,QAAQ,QAAQ;AAAA,gBAC5B,CAAC,QAAQ,MAAM,GAAG;AAAA,cAAA,CACnB;AAAA,cACA,GAAG;AAAA,cAEJ,UAAA;AAAA,gBAAC;AAAA,gBAAA;AAAA,kBACC,WAAW,QAAQ;AAAA,kBACnB,IAAI,MAAM,IAAI,MAAM;AAAA,kBACpB,UAAU;AAAA,kBAET,UAAkB,kBAAA,IAAI,CAAC,6BACrB,YAAyB,EAAA,OAAO,MAAM,UAAU,KAAK,UACnD,UAAA,KAAK,MADS,GAAA,KAAK,EAEtB,CACD;AAAA,gBAAA;AAAA,cAAA;AAAA,YACH;AAAA,UAAA;AAAA,QACF;AAAA,MAAA;AAAA,IACF;AAAA,EACF;AAEJ,CAAC;"}
|
|
@@ -4,6 +4,7 @@ const { staticClasses, useClasses } = createClasses("HvSuggestions", {
|
|
|
4
4
|
root: { position: "relative" },
|
|
5
5
|
list: {
|
|
6
6
|
backgroundColor: theme.colors.atmo1,
|
|
7
|
+
border: `1px solid ${theme.colors.secondary}`,
|
|
7
8
|
boxShadow: theme.colors.shadow,
|
|
8
9
|
padding: theme.space.xs,
|
|
9
10
|
width: "100%"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Suggestions.styles.js","sources":["../../../../src/FormElement/Suggestions/Suggestions.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\nimport { theme } from \"@hitachivantara/uikit-styles\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvSuggestions\", {\n root: { position: \"relative\" },\n list: {\n backgroundColor: theme.colors.atmo1,\n boxShadow: theme.colors.shadow,\n padding: theme.space.xs,\n width: \"100%\",\n },\n popper: {\n width: \"var(--popper-width)\",\n position: \"absolute\",\n zIndex: theme.zIndices.tooltip,\n \":not($portal)\": {\n transform: \"translate3d(0, -1px, 0) !important\",\n },\n },\n portal: {},\n});\n"],"names":[],"mappings":";;AAGO,MAAM,EAAE,eAAe,eAAe,cAAc,iBAAiB;AAAA,EAC1E,MAAM,EAAE,UAAU,WAAW;AAAA,EAC7B,MAAM;AAAA,IACJ,iBAAiB,MAAM,OAAO;AAAA,IAC9B,WAAW,MAAM,OAAO;AAAA,IACxB,SAAS,MAAM,MAAM;AAAA,IACrB,OAAO;AAAA,EACT;AAAA,EACA,QAAQ;AAAA,IACN,OAAO;AAAA,IACP,UAAU;AAAA,IACV,QAAQ,MAAM,SAAS;AAAA,IACvB,iBAAiB;AAAA,MACf,WAAW;AAAA,IAAA;AAAA,EAEf;AAAA,EACA,QAAQ,CAAA;AACV,CAAC;"}
|
|
1
|
+
{"version":3,"file":"Suggestions.styles.js","sources":["../../../../src/FormElement/Suggestions/Suggestions.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\nimport { theme } from \"@hitachivantara/uikit-styles\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvSuggestions\", {\n root: { position: \"relative\" },\n list: {\n backgroundColor: theme.colors.atmo1,\n border: `1px solid ${theme.colors.secondary}`,\n boxShadow: theme.colors.shadow,\n padding: theme.space.xs,\n width: \"100%\",\n },\n popper: {\n width: \"var(--popper-width)\",\n position: \"absolute\",\n zIndex: theme.zIndices.tooltip,\n \":not($portal)\": {\n transform: \"translate3d(0, -1px, 0) !important\",\n },\n },\n portal: {},\n});\n"],"names":[],"mappings":";;AAGO,MAAM,EAAE,eAAe,eAAe,cAAc,iBAAiB;AAAA,EAC1E,MAAM,EAAE,UAAU,WAAW;AAAA,EAC7B,MAAM;AAAA,IACJ,iBAAiB,MAAM,OAAO;AAAA,IAC9B,QAAQ,aAAa,MAAM,OAAO,SAAS;AAAA,IAC3C,WAAW,MAAM,OAAO;AAAA,IACxB,SAAS,MAAM,MAAM;AAAA,IACrB,OAAO;AAAA,EACT;AAAA,EACA,QAAQ;AAAA,IACN,OAAO;AAAA,IACP,UAAU;AAAA,IACV,QAAQ,MAAM,SAAS;AAAA,IACvB,iBAAiB;AAAA,MACf,WAAW;AAAA,IAAA;AAAA,EAEf;AAAA,EACA,QAAQ,CAAA;AACV,CAAC;"}
|
package/dist/esm/Input/Input.js
CHANGED