11import { Checkbox as MedusaCheckbox } from '@medusajs/ui' ;
22import clsx from 'clsx' ;
3- import { forwardRef } from 'react' ;
43import { FieldWrapper } from './FieldWrapper' ;
54import { Label } from './Label' ;
65import type { BasicFieldProps } from './types' ;
@@ -9,43 +8,53 @@ export type CheckedState = boolean | 'indeterminate';
98export type FieldCheckboxProps = BasicFieldProps & {
109 checked ?: CheckedState ;
1110 onChange ?: ( checked : CheckedState ) => void ;
11+ ref ?: React . Ref < HTMLButtonElement > ;
1212} ;
1313
14- export const FieldCheckbox : React . FC < FieldCheckboxProps > = forwardRef < HTMLButtonElement , FieldCheckboxProps > (
15- ( { label, labelClassName, labelTooltip, wrapperClassName, errorClassName, formErrors, onChange, ...props } , ref ) => {
16- return (
17- < FieldWrapper < FieldCheckboxProps >
18- wrapperClassName = { wrapperClassName }
19- errorClassName = { errorClassName }
20- formErrors = { formErrors }
21- { ...props }
22- >
23- { ( fieldProps ) => (
24- < div className = "flex items-center" >
25- < MedusaCheckbox
26- { ...fieldProps }
27- ref = { ref }
28- checked = { props . checked }
29- onChange = { ( e ) => { } }
30- onCheckedChange = { ( checked ) => {
31- onChange ?.( checked ) ;
14+ export const FieldCheckbox : React . FC < FieldCheckboxProps > = ( {
15+ label,
16+ labelClassName,
17+ labelTooltip,
18+ wrapperClassName,
19+ errorClassName,
20+ formErrors,
21+ onChange,
22+ ref,
23+ ...props
24+ } ) => {
25+ return (
26+ < FieldWrapper < FieldCheckboxProps >
27+ wrapperClassName = { wrapperClassName }
28+ errorClassName = { errorClassName }
29+ formErrors = { formErrors }
30+ { ...props }
31+ >
32+ { ( fieldProps ) => (
33+ < div className = "flex items-center" >
34+ < MedusaCheckbox
35+ { ...fieldProps }
36+ ref = { ref }
37+ checked = { props . checked }
38+ onChange = { ( e ) => { } }
39+ onCheckedChange = { ( checked ) => {
40+ onChange ?.( checked ) ;
41+ } }
42+ />
43+
44+ { label && (
45+ < Label
46+ htmlFor = { props . name }
47+ onClick = { ( ) => {
48+ onChange ?.( ! props . checked ) ;
3249 } }
33- />
50+ className = { clsx ( 'ml-2 !mb-0 font-normal [&>label]:!cursor-pointer' , labelClassName ) }
51+ >
52+ { label }
53+ </ Label >
54+ ) }
55+ </ div >
56+ ) }
57+ </ FieldWrapper >
58+ ) ;
59+ } ;
3460
35- { label && (
36- < Label
37- htmlFor = { props . name }
38- onClick = { ( ) => {
39- onChange ?.( ! props . checked ) ;
40- } }
41- className = { clsx ( 'ml-2 !mb-0 font-normal [&>label]:!cursor-pointer' , labelClassName ) }
42- >
43- { label }
44- </ Label >
45- ) }
46- </ div >
47- ) }
48- </ FieldWrapper >
49- ) ;
50- } ,
51- ) ;
0 commit comments