2023-02-16 22:39:57 +00:00
|
|
|
import type { InputHTMLAttributes } from "react";
|
|
|
|
import React, { forwardRef } from "react";
|
2021-09-22 11:04:32 +00:00
|
|
|
|
2022-05-30 14:51:18 +00:00
|
|
|
import classNames from "@calcom/lib/classNames";
|
|
|
|
|
2022-05-23 08:11:04 +00:00
|
|
|
import InfoBadge from "@components/ui/InfoBadge";
|
|
|
|
|
2021-09-22 11:04:32 +00:00
|
|
|
type Props = InputHTMLAttributes<HTMLInputElement> & {
|
2022-05-23 08:11:04 +00:00
|
|
|
label?: React.ReactNode;
|
2021-09-22 11:04:32 +00:00
|
|
|
description: string;
|
2022-05-23 08:11:04 +00:00
|
|
|
descriptionAsLabel?: boolean;
|
2022-05-30 14:51:18 +00:00
|
|
|
informationIconText?: string;
|
2021-09-22 11:04:32 +00:00
|
|
|
};
|
|
|
|
|
2022-05-23 08:11:04 +00:00
|
|
|
const CheckboxField = forwardRef<HTMLInputElement, Props>(
|
2022-05-30 14:51:18 +00:00
|
|
|
({ label, description, informationIconText, ...rest }, ref) => {
|
|
|
|
const descriptionAsLabel = !label || rest.descriptionAsLabel;
|
2022-05-23 08:11:04 +00:00
|
|
|
return (
|
|
|
|
<div className="block items-center sm:flex">
|
2022-05-30 14:51:18 +00:00
|
|
|
{label && (
|
2022-05-23 08:11:04 +00:00
|
|
|
<div className="min-w-48 mb-4 sm:mb-0">
|
2022-05-30 14:51:18 +00:00
|
|
|
{React.createElement(
|
|
|
|
descriptionAsLabel ? "div" : "label",
|
|
|
|
{
|
2023-04-05 18:14:46 +00:00
|
|
|
className: "flex text-sm font-medium text-default",
|
2022-05-30 14:51:18 +00:00
|
|
|
...(!descriptionAsLabel
|
|
|
|
? {
|
|
|
|
htmlFor: rest.id,
|
|
|
|
}
|
|
|
|
: {}),
|
|
|
|
},
|
|
|
|
label
|
|
|
|
)}
|
2021-09-22 11:04:32 +00:00
|
|
|
</div>
|
2022-05-23 08:11:04 +00:00
|
|
|
)}
|
|
|
|
<div className="w-full">
|
|
|
|
<div className="relative flex items-start">
|
2022-05-30 14:51:18 +00:00
|
|
|
{React.createElement(
|
|
|
|
descriptionAsLabel ? "label" : "div",
|
|
|
|
{
|
|
|
|
className: classNames(
|
|
|
|
"relative flex items-start",
|
2023-04-05 18:14:46 +00:00
|
|
|
descriptionAsLabel ? "text-default" : "text-emphasis"
|
2022-05-30 14:51:18 +00:00
|
|
|
),
|
|
|
|
},
|
|
|
|
<>
|
|
|
|
<div className="flex h-5 items-center">
|
|
|
|
<input
|
|
|
|
{...rest}
|
|
|
|
ref={ref}
|
|
|
|
type="checkbox"
|
2023-04-05 18:14:46 +00:00
|
|
|
className="text-primary-600 focus:ring-primary-500 border-default h-4 w-4 rounded"
|
2022-05-30 14:51:18 +00:00
|
|
|
/>
|
|
|
|
</div>
|
2023-04-09 09:13:57 +00:00
|
|
|
<span className="ms-3 text-sm">{description}</span>
|
2022-05-30 14:51:18 +00:00
|
|
|
</>
|
|
|
|
)}
|
2022-07-13 21:14:16 +00:00
|
|
|
{informationIconText && <InfoBadge content={informationIconText} />}
|
2021-09-22 11:04:32 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-05-23 08:11:04 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
2021-09-22 11:04:32 +00:00
|
|
|
|
|
|
|
CheckboxField.displayName = "CheckboxField";
|
|
|
|
|
|
|
|
export default CheckboxField;
|