// Importing necessary libraries and components
import { useState } from "@wordpress/element";
import { Input, Tooltip } from "antd";
import {
InputProps as BaseInputProps,
TextAreaProps as BaseTextAreaProps,
SearchProps as BaseSearchProps,
} from "antd/es/input";
import { QuestionCircleOutlined } from "@ant-design/icons";
// Defining additional properties for labels
// These properties extend the base input properties from Ant Design
type LabelProps = {
label: string; // Label text for the input
helptext?: string; // Optional help text displayed as a tooltip
inputRef?: any; // Reference to the input element
};
// Extending Ant Design input types with label properties
type InputProps = BaseInputProps & LabelProps;
type TextAreaProps = BaseTextAreaProps & LabelProps;
type SearchProps = BaseSearchProps & LabelProps;
// Component to render a floating label
const FloatLabel = ({ text, float }: { text: string; float: boolean }) => {
return (
);
};
// Component for a floating input field
const FloatInput = ({ label, helptext, inputRef, ...props }: InputProps) => {
// State to track focus on the input field
const [focus, setFocus] = useState(false);
// Determine if the label should float
const float = focus || props.value || props.defaultValue ? true : false;
// Adjust input properties based on floating state
const inputProps = {
...props,
placeholder: float ? props.placeholder : "",
};
return (
);
};
// Component for a floating text area
const TextArea = ({ label, helptext, inputRef, ...props }: TextAreaProps) => {
// State to track focus on the text area
const [focus, setFocus] = useState(false);
// Determine if the label should float
const float = focus || props.value || props.defaultValue ? true : false;
// Adjust text area properties based on floating state
const inputProps = {
...props,
placeholder: float ? props.placeholder : "",
};
return (