-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathCheckbox.tsx
More file actions
61 lines (57 loc) · 1.8 KB
/
Copy pathCheckbox.tsx
File metadata and controls
61 lines (57 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { Stack, Switch } from "@mui/material"
import type React from "react"
import { SoundPlayer } from "@/systems/sound/SoundPlayer"
import Label from "./Label"
import { LabelWithTooltip } from "./StyledComponents"
export type CheckboxProps = {
/**
* The label text that will be on the right of the checkbox.
*/
label: string
/**
* Custom styling options.
*/
className?: string
/**
* A variable that controls the current state of the checkbox
*/
checked: boolean
/**
* If true, the checkbox will not be labeled.
*/
hideLabel?: boolean
/**
* Callback function to handle state changes of the checkbox.
* @param checked new state of the checkbox
*/
onClick?: (checked: boolean) => void
/**
* Text to show as a tooltip next to the label.
*/
tooltip?: string
/**
* Whether to disable the checkbox
*/
disabled?: boolean
}
const Checkbox: React.FC<CheckboxProps> = ({ label, className, checked, hideLabel, onClick, tooltip, disabled }) => {
return (
<Stack direction="row" justifyContent="space-between" alignItems="center" textAlign="center">
{hideLabel ? null : tooltip ? (
<LabelWithTooltip labelText={label} tooltipText={tooltip} />
) : (
<Label size="sm" className={`mr-12 ${className} whitespace-nowrap`}>
{label}
</Label>
)}
<Switch
onChange={(e: React.ChangeEvent<HTMLInputElement>) => onClick && onClick(e.target.checked)}
{...SoundPlayer.getInstance().checkboxSoundEffects()}
checked={checked}
disabled={disabled}
role="checkbox"
/>
</Stack>
)
}
export default Checkbox