|
1
|
import { Switch } from "@medusajs/ui" |
|
2
|
import type { Control, FieldValues, Path } from "react-hook-form" |
|
3
|
import { Form } from "../common/form" |
|
4
|
|
|
5
|
interface SwitchBlockProps<TValues extends FieldValues> { |
|
6
|
label: string |
|
7
|
description: string |
|
8
|
name: Path<TValues> |
|
9
|
control: Control<TValues> |
|
10
|
} |
|
11
|
|
|
12
|
export const SwitchBlock = <TValues extends FieldValues>( |
|
13
|
props: SwitchBlockProps<TValues> |
|
14
|
) => { |
|
15
|
return ( |
|
16
|
<Form.Field |
|
17
|
name={props.name} |
|
18
|
control={props.control} |
|
19
|
render={({ field: { value, onChange, ...field } }) => ( |
|
20
|
<Form.Item> |
|
21
|
<div className="flex items-start gap-3 bg-ui-bg-component shadow-elevation-card-rest rounded-lg p-3"> |
|
22
|
<Form.Control> |
|
23
|
<Switch |
|
24
|
size="small" |
|
25
|
checked={value} |
|
26
|
onCheckedChange={onChange} |
|
27
|
{...field} |
|
28
|
/> |
|
29
|
</Form.Control> |
|
30
|
<div className="flex flex-col"> |
|
31
|
<Form.Label>{props.label}</Form.Label> |
|
32
|
<Form.Hint>{props.description}</Form.Hint> |
|
33
|
</div> |
|
34
|
</div> |
|
35
|
</Form.Item> |
|
36
|
)} |
|
37
|
/> |
|
38
|
) |
|
39
|
} |