2023-10-06 13:15:39 +00:00
|
|
|
import { TextInputTypes } from "@patternfly/react-core";
|
2023-11-14 11:04:55 +00:00
|
|
|
import { KeycloakTextInput } from "../keycloak-text-input/KeycloakTextInput";
|
|
|
|
import { UserProfileFieldProps } from "./UserProfileFields";
|
2023-07-18 11:40:53 +00:00
|
|
|
import { UserProfileGroup } from "./UserProfileGroup";
|
2023-11-14 11:04:55 +00:00
|
|
|
import { fieldName, isRequiredAttribute } from "./utils";
|
2023-07-18 11:40:53 +00:00
|
|
|
|
2023-11-14 11:04:55 +00:00
|
|
|
export const TextComponent = (props: UserProfileFieldProps) => {
|
|
|
|
const { form, inputType, attribute } = props;
|
2023-10-06 13:15:39 +00:00
|
|
|
const isRequired = isRequiredAttribute(attribute);
|
|
|
|
const type = inputType.startsWith("html")
|
|
|
|
? (inputType.substring("html".length + 2) as TextInputTypes)
|
2023-07-18 11:40:53 +00:00
|
|
|
: "text";
|
|
|
|
|
|
|
|
return (
|
2023-11-14 11:04:55 +00:00
|
|
|
<UserProfileGroup {...props}>
|
2023-07-18 11:40:53 +00:00
|
|
|
<KeycloakTextInput
|
2023-10-06 13:15:39 +00:00
|
|
|
id={attribute.name}
|
|
|
|
data-testid={attribute.name}
|
2023-07-18 11:40:53 +00:00
|
|
|
type={type}
|
2023-10-06 13:15:39 +00:00
|
|
|
placeholder={attribute.annotations?.["inputTypePlaceholder"] as string}
|
|
|
|
readOnly={attribute.readOnly}
|
|
|
|
isRequired={isRequired}
|
2023-11-14 11:04:55 +00:00
|
|
|
{...form.register(fieldName(attribute.name))}
|
2023-07-18 11:40:53 +00:00
|
|
|
/>
|
|
|
|
</UserProfileGroup>
|
|
|
|
);
|
|
|
|
};
|