mirror of
https://dev.azure.com/globalhealthx/EMR/_git/helix-engage
synced 2026-04-11 18:28:15 +00:00
chore: initial Untitled UI Vite scaffold with FontAwesome Pro
This commit is contained in:
48
src/components/base/input/label.tsx
Normal file
48
src/components/base/input/label.tsx
Normal file
@@ -0,0 +1,48 @@
|
||||
import type { ReactNode, Ref } from "react";
|
||||
import { HelpCircle } from "@untitledui/icons";
|
||||
import type { LabelProps as AriaLabelProps } from "react-aria-components";
|
||||
import { Label as AriaLabel } from "react-aria-components";
|
||||
import { Tooltip, TooltipTrigger } from "@/components/base/tooltip/tooltip";
|
||||
import { cx } from "@/utils/cx";
|
||||
|
||||
interface LabelProps extends AriaLabelProps {
|
||||
children: ReactNode;
|
||||
isRequired?: boolean;
|
||||
tooltip?: string;
|
||||
tooltipDescription?: string;
|
||||
ref?: Ref<HTMLLabelElement>;
|
||||
}
|
||||
|
||||
export const Label = ({ isRequired, tooltip, tooltipDescription, className, ...props }: LabelProps) => {
|
||||
return (
|
||||
<AriaLabel
|
||||
// Used for conditionally hiding/showing the label element via CSS:
|
||||
// <Input label="Visible only on mobile" className="lg:**:data-label:hidden" />
|
||||
// or
|
||||
// <Input label="Visible only on mobile" className="lg:label:hidden" />
|
||||
data-label="true"
|
||||
{...props}
|
||||
className={cx("flex cursor-default items-center gap-0.5 text-sm font-medium text-secondary", className)}
|
||||
>
|
||||
{props.children}
|
||||
|
||||
<span className={cx("hidden text-brand-tertiary", isRequired && "block", typeof isRequired === "undefined" && "group-required:block")}>*</span>
|
||||
|
||||
{tooltip && (
|
||||
<Tooltip title={tooltip} description={tooltipDescription} placement="top">
|
||||
<TooltipTrigger
|
||||
// `TooltipTrigger` inherits the disabled state from the parent form field
|
||||
// but we don't that. We want the tooltip be enabled even if the parent
|
||||
// field is disabled.
|
||||
isDisabled={false}
|
||||
className="cursor-pointer text-fg-quaternary transition duration-200 hover:text-fg-quaternary_hover focus:text-fg-quaternary_hover"
|
||||
>
|
||||
<HelpCircle className="size-4" />
|
||||
</TooltipTrigger>
|
||||
</Tooltip>
|
||||
)}
|
||||
</AriaLabel>
|
||||
);
|
||||
};
|
||||
|
||||
Label.displayName = "Label";
|
||||
Reference in New Issue
Block a user