File size: 1,349 Bytes
a7060a0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { IconLockLocked, IconLockUnlocked } from "@humansignal/icons";
import type { ButtonProps } from "@humansignal/ui";
import type { HotkeyList } from "libs/editor/src/core/Hotkey";
import { observer } from "mobx-react";
import type { FC } from "react";
import { RegionControlButton } from "./RegionControlButton";

export const LockButton: FC<{
  item: any;
  annotation: any;
  hovered: boolean;
  locked: boolean;
  hotkey?: string;
  variant?: ButtonProps["variant"];
  look?: ButtonProps["look"];
  ariaLabel?: string;
  tooltip?: string;
  style?: ButtonProps["style"];
  displayedHotkey?: string;
  onClick: () => void;
}> = observer(({ item, annotation, locked, hotkey, variant, look, ariaLabel, tooltip, style, onClick }) => {
  if (!item) return null;
  const isLocked = locked || item.isReadOnly() || annotation.isReadOnly();
  const isRegionReadonly = item.isReadOnly() && !locked;
  const styles = {
    ...style,
    display: item.isReadOnly() || locked ? undefined : "none",
  };

  return (
    <RegionControlButton
      disabled={isRegionReadonly}
      onClick={onClick}
      hotkey={hotkey as HotkeyList}
      variant={variant}
      look={look}
      style={styles}
      aria-label={ariaLabel}
      tooltip={tooltip}
    >
      {isLocked ? <IconLockLocked /> : <IconLockUnlocked />}
    </RegionControlButton>
  );
});