forked from excalidraw/excalidraw
-
Notifications
You must be signed in to change notification settings - Fork 1
/
LockElementButton.tsx
53 lines (48 loc) · 1.18 KB
/
LockElementButton.tsx
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
import "./ToolIcon.scss";
import clsx from "clsx";
import { ToolButtonSize } from "./ToolButton";
import { LockedIcon, UnlockedIcon } from "./icons";
type LockElementIconProps = {
title?: string;
name?: string;
checked: boolean;
disabled?: boolean;
onChange?(): void;
isMobile?: boolean;
};
const DEFAULT_SIZE: ToolButtonSize = "medium";
const ICONS = {
CHECKED: LockedIcon,
UNCHECKED: UnlockedIcon,
};
export const LockElementButton = (props: LockElementIconProps) => {
return (
<label
className={clsx(
"ToolIcon ToolIcon__lock",
`ToolIcon_size_${DEFAULT_SIZE}`,
{
"is-mobile": props.isMobile,
},
{
disabled: props.disabled,
},
)}
title={`${props.title} — Ctrl + Shift + L`}
>
<input
className="ToolIcon_type_checkbox"
type="checkbox"
name={props.name}
onChange={props.onChange}
checked={props.checked}
disabled={props.disabled}
aria-label={props.title}
data-testid="toolbar-lock"
/>
<div className="ToolIcon__icon">
{props.checked ? ICONS.CHECKED : ICONS.UNCHECKED}
</div>
</label>
);
};