UNPKG

@keycloakify/keycloak-admin-ui

Version:
22 lines 1.65 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { FormGroup } from "@patternfly/react-core"; import { useState } from "react"; import { Controller, useFormContext } from "react-hook-form"; import { useTranslation } from "react-i18next"; import { HelpItem } from "../../ui-shared"; import { FileUpload } from "../../components/json-file-upload/patternfly/FileUpload"; import { convertToName } from "../../components/dynamic/DynamicComponents"; export const FileComponent = ({ name, label, helpText, defaultValue, required, isDisabled = false, }) => { const { t } = useTranslation(); const { control } = useFormContext(); const [filename, setFilename] = useState(""); const [isLoading, setIsLoading] = useState(false); return (_jsx(FormGroup, { label: t(label), labelIcon: _jsx(HelpItem, { helpText: t(helpText), fieldLabelId: `${label}` }), fieldId: name, isRequired: required, children: _jsx(Controller, { name: convertToName(name), control: control, defaultValue: defaultValue || "", render: ({ field }) => (_jsx(FileUpload, { id: name, value: field.value, type: "text", filename: filename, isDisabled: isDisabled, onFileInputChange: (_, file) => setFilename(file.name), onReadStarted: () => setIsLoading(true), onReadFinished: () => setIsLoading(false), onClearClick: () => { field.onChange(""); setFilename(""); }, isLoading: isLoading, allowEditingUploadedText: false, onChange: (value, filename) => { field.onChange(value); setFilename(filename); } })) }) })); }; //# sourceMappingURL=FileComponent.js.map