-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathShowPopupKeysForm.tsx
More file actions
106 lines (97 loc) · 3.05 KB
/
ShowPopupKeysForm.tsx
File metadata and controls
106 lines (97 loc) · 3.05 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import { useRef } from 'preact/hooks';
import { useLocale } from '../common/i18n';
import { KeyBox, KeyCheckbox } from './KeyBox';
export type HoldToShowSetting = { alt: boolean; ctrl: boolean; shift: boolean };
type Props = {
isMac: boolean;
holdToShowKeys: HoldToShowSetting;
holdToShowImageKeys: HoldToShowSetting;
onChangeHoldToShowKeys: (value: HoldToShowSetting) => void;
onChangeHoldToShowImageKeys: (value: HoldToShowSetting) => void;
};
export function ShowPopupKeysForm(props: Props) {
const { t } = useLocale();
return (
<fieldset class="border border-solid border-zinc-300 px-6 py-3 dark:border-zinc-500">
<p class="my-3 leading-6 italic">{t('options_show_popup_explanation')}</p>
<div class="grid auto-cols-max items-center gap-x-8">
<div class="col-span-2">{t('options_show_popup_text_subheading')}</div>
<KeyCheckboxes
isMac={props.isMac}
value={props.holdToShowKeys}
onChange={props.onChangeHoldToShowKeys}
/>
<div>
<svg
viewBox="0 0 120 90"
class="w-24 text-zinc-400 dark:text-zinc-300"
>
<use href="#text-with-cursor" />
</svg>
</div>
<div class="col-span-2">
{t('options_show_popup_images_subheading')}
</div>
<KeyCheckboxes
isMac={props.isMac}
value={props.holdToShowImageKeys}
onChange={props.onChangeHoldToShowImageKeys}
/>
<div>
<svg
viewBox="0 0 120 90"
class="w-24 text-zinc-400 dark:text-zinc-300"
>
<use href="#image-with-cursor" />
</svg>
</div>
</div>
</fieldset>
);
}
type KeyCheckboxesProps = {
isMac: boolean;
value: HoldToShowSetting;
onChange: (value: HoldToShowSetting) => void;
};
function KeyCheckboxes(props: KeyCheckboxesProps) {
const altRef = useRef<HTMLInputElement>(null);
const ctrlRef = useRef<HTMLInputElement>(null);
const shiftRef = useRef<HTMLInputElement>(null);
const onChange = () => {
props.onChange({
alt: altRef.current?.checked ?? false,
ctrl: ctrlRef.current?.checked ?? false,
shift: shiftRef.current?.checked ?? false,
});
};
return (
<div class="flex items-baseline gap-2">
<KeyCheckbox checked={props.value.alt} onClick={onChange} ref={altRef}>
<KeyBox label="Alt" isMac={props.isMac} />
</KeyCheckbox>
<span class={!props.value.alt || !props.value.ctrl ? 'opacity-50' : ''}>
+
</span>
<KeyCheckbox checked={props.value.ctrl} onClick={onChange} ref={ctrlRef}>
<KeyBox label="Ctrl" isMac={props.isMac} />
</KeyCheckbox>
<span
class={
!props.value.shift || (!props.value.alt && !props.value.ctrl)
? 'opacity-50'
: ''
}
>
+
</span>
<KeyCheckbox
checked={props.value.shift}
onClick={onChange}
ref={shiftRef}
>
<KeyBox label="Shift" isMac={props.isMac} />
</KeyCheckbox>
</div>
);
}