Files
web/apps/scandic-web/components/TempDesignSystem/Form/Checkbox/index.tsx
Hrishikesh Vaipurkar 73cb423c95 Merged in feat/SW-2078-update-confirmation-page-vouchers (pull request #1731)
Feat/SW-2078 update confirmation page vouchers and Corp Cheques rate

* feat: SW-2078 Tablet bookingCode ref forward issue fix

(cherry picked from commit 16a6a00fd99b6b6220a98ad74de062d67d35e1c0)

* feat: SW-2078 Display Vouchers and Cheques prices on confirmation page

(cherry picked from commit a76494de497a7d5e7641cb0036bd7055acf875c1)

* feat: SW-2078 Rebase issue fix

* feat: SW-2079 Updated rate title in terms modal

* feat: SW-2078 Optimized code

* feat: SW-2078 Removed extra tags


Approved-by: Christian Andolf
2025-04-08 07:27:40 +00:00

67 lines
1.8 KiB
TypeScript

"use client"
import { forwardRef } from "react"
import { Checkbox as AriaCheckbox } from "react-aria-components"
import { useController, useFormContext } from "react-hook-form"
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
import Caption from "@/components/TempDesignSystem/Text/Caption"
import styles from "./checkbox.module.css"
import type { CheckboxProps } from "@/types/components/checkbox"
const Checkbox = forwardRef<
HTMLInputElement,
React.PropsWithChildren<CheckboxProps>
>(function Checkbox(
{ className, name, children, registerOptions, hideError, topAlign = false },
ref
) {
const { control } = useFormContext()
const { field, fieldState } = useController({
control,
name,
rules: registerOptions,
})
return (
<AriaCheckbox
className={`${styles.container} ${className}`}
isSelected={field.value}
onChange={field.onChange}
data-testid={name}
isDisabled={registerOptions?.disabled}
excludeFromTabOrder
>
{({ isSelected }) => (
<>
<span
className={`${styles.checkboxContainer} ${topAlign ? styles.topAlign : ""}`}
>
<span
className={styles.checkbox}
tabIndex={registerOptions?.disabled ? undefined : 0}
ref={ref}
>
{isSelected && (
<MaterialIcon icon="check" color="Icon/Inverted" />
)}
</span>
{children}
</span>
{fieldState.error && !hideError ? (
<Caption className={styles.error} fontOnly>
<MaterialIcon icon="info" color="Icon/Interactive/Accent" />
{fieldState.error.message}
</Caption>
) : null}
</>
)}
</AriaCheckbox>
)
})
export default Checkbox