keycloak-scim/apps/admin-ui/src/components/dynamic/TextComponent.tsx
2023-01-26 10:31:07 +01:00

37 lines
1,004 B
TypeScript

import { FormGroup } from "@patternfly/react-core";
import { useFormContext } from "react-hook-form";
import { useTranslation } from "react-i18next";
import { HelpItem } from "../help-enabler/HelpItem";
import { KeycloakTextArea } from "../keycloak-text-area/KeycloakTextArea";
import type { ComponentProps } from "./components";
import { convertToName } from "./DynamicComponents";
export const TextComponent = ({
name,
label,
helpText,
defaultValue,
isDisabled = false,
}: ComponentProps) => {
const { t } = useTranslation("dynamic");
const { register } = useFormContext();
return (
<FormGroup
label={t(label!)}
labelIcon={
<HelpItem helpText={t(helpText!)} fieldLabelId={`dynamic:${label}`} />
}
fieldId={name!}
>
<KeycloakTextArea
id={name!}
data-testid={name}
isDisabled={isDisabled}
defaultValue={defaultValue?.toString()}
{...register(convertToName(name!))}
/>
</FormGroup>
);
};