Skip to content

Commit 11d8b80

Browse files
committed
Add checkbox to MenuBarInput widget
1 parent 6bb8357 commit 11d8b80

File tree

4 files changed

+57
-11
lines changed

4 files changed

+57
-11
lines changed

client/web/src/components/panels/Document.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,8 @@ export default defineComponent({
308308
const { reset_colors } = await wasm;
309309
reset_colors();
310310
},
311-
download(filename: string, svgData: string) {
312-
const svgBlob = new Blob([svgData], { type: "image/svg+xml;charset=utf-8" });
311+
download(filename: string, fileData: string) {
312+
const svgBlob = new Blob([fileData], { type: "image/svg+xml;charset=utf-8" });
313313
const svgUrl = URL.createObjectURL(svgBlob);
314314
const element = document.createElement("a");
315315

client/web/src/components/widgets/floating-menus/MenuList.vue

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,18 @@
1212
@mouseleave="handleEntryMouseLeave(entry)"
1313
:data-hover-menu-spawner-extend="entry.children && []"
1414
>
15-
<IconLabel :icon="entry.icon" v-if="entry.icon && drawIcon" />
16-
<div class="no-icon" v-else-if="drawIcon" />
15+
<CheckboxInput v-if="entry.checkbox" v-model:checked="entry.checked" :outlineStyle="true" :class="'entry-checkbox'" />
16+
<IconLabel v-else-if="entry.icon && drawIcon" :icon="entry.icon" :class="'entry-icon'" />
17+
<div v-else-if="drawIcon" class="no-icon" />
18+
1719
<span class="entry-label">{{ entry.label }}</span>
18-
<IconLabel :icon="'Info'" v-if="entry.shortcutRequiresLock && !fullscreen.keyboardLocked" :title="keyboardLockInfoMessage" />
20+
21+
<IconLabel v-if="entry.shortcutRequiresLock && !fullscreen.keyboardLocked" :icon="'Info'" :title="keyboardLockInfoMessage" />
1922
<UserInputLabel v-else-if="entry.shortcut && entry.shortcut.length" :inputKeys="[entry.shortcut]" />
23+
2024
<div class="submenu-arrow" v-if="entry.children && entry.children.length"></div>
2125
<div class="no-submenu-arrow" v-else></div>
26+
2227
<MenuList
2328
v-if="entry.children"
2429
:direction="MenuDirection.TopRight"
@@ -50,7 +55,7 @@
5055
flex: 0 0 auto;
5156
}
5257
53-
.icon-label svg {
58+
.entry-icon svg {
5459
fill: var(--color-e-nearwhite);
5560
}
5661
@@ -63,7 +68,8 @@
6368
margin-left: 8px;
6469
}
6570
66-
.icon-label,
71+
.entry-checkbox,
72+
.entry-icon,
6773
.no-icon {
6874
margin: 0 4px;
6975
@@ -112,6 +118,14 @@
112118
color: var(--color-f-white);
113119
}
114120
}
121+
122+
&:hover .entry-checkbox label .checkbox-box {
123+
border: 1px solid var(--color-f-white);
124+
125+
svg {
126+
fill: var(--color-f-white);
127+
}
128+
}
115129
}
116130
}
117131
}
@@ -125,6 +139,7 @@ import { SeparatorDirection, SeparatorType } from "@/components/widgets/widgets"
125139
import FloatingMenu, { MenuDirection, MenuType } from "@/components/widgets/floating-menus/FloatingMenu.vue";
126140
import Separator from "@/components/widgets/separators/Separator.vue";
127141
import IconLabel from "@/components/widgets/labels/IconLabel.vue";
142+
import CheckboxInput from "@/components/widgets/inputs/CheckboxInput.vue";
128143
import UserInputLabel from "@/components/widgets/labels/UserInputLabel.vue";
129144
130145
export type MenuListEntries = Array<MenuListEntry>;
@@ -134,14 +149,14 @@ interface MenuListEntryData {
134149
value?: string;
135150
label?: string;
136151
icon?: string;
137-
// TODO: Add `checkbox` (which overrides any `icon`)
152+
checkbox?: boolean;
138153
shortcut?: Array<string>;
139154
shortcutRequiresLock?: boolean;
140155
action?: Function;
141156
children?: SectionsOfMenuListEntries;
142157
}
143158
144-
export type MenuListEntry = MenuListEntryData & { ref?: typeof FloatingMenu | typeof MenuList };
159+
export type MenuListEntry = MenuListEntryData & { ref?: typeof FloatingMenu | typeof MenuList; checked?: boolean };
145160
146161
const KEYBOARD_LOCK_USE_FULLSCREEN = "This hotkey is reserved by the browser, but becomes available in fullscreen mode";
147162
const KEYBOARD_LOCK_SWITCH_BROWSER = "This hotkey is reserved by the browser, but becomes available in Chrome, Edge, and Opera which support the Keyboard.lock() API";
@@ -164,6 +179,8 @@ const MenuList = defineComponent({
164179
handleEntryClick(menuEntry: MenuListEntry) {
165180
(this.$refs.floatingMenu as typeof FloatingMenu).setClosed();
166181
182+
if (menuEntry.checkbox) menuEntry.checked = !menuEntry.checked;
183+
167184
if (menuEntry.action) menuEntry.action();
168185
else if (this.defaultAction) this.defaultAction();
169186
else this.$emit("update:activeEntry", menuEntry);
@@ -259,6 +276,7 @@ const MenuList = defineComponent({
259276
FloatingMenu,
260277
Separator,
261278
IconLabel,
279+
CheckboxInput,
262280
UserInputLabel,
263281
},
264282
});

client/web/src/components/widgets/inputs/CheckboxInput.vue

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div class="checkbox-input">
2+
<div class="checkbox-input" :class="{ 'outline-style': outlineStyle }">
33
<input type="checkbox" :id="`checkbox-input-${id}`" :checked="checked" @input="(e) => $emit('update:checked', e.target.checked)" />
44
<label :for="`checkbox-input-${id}`">
55
<div class="checkbox-box">
@@ -49,6 +49,33 @@
4949
background: var(--color-accent-hover);
5050
}
5151
}
52+
53+
&.outline-style label {
54+
.checkbox-box {
55+
border: 1px solid var(--color-e-nearwhite);
56+
padding: 1px;
57+
background: none;
58+
59+
svg {
60+
display: none;
61+
}
62+
}
63+
64+
&:hover .checkbox-box {
65+
border: 1px solid var(--color-f-white);
66+
}
67+
}
68+
69+
&.outline-style input:checked + label {
70+
.checkbox-box {
71+
background: none;
72+
73+
svg {
74+
display: block;
75+
fill: var(--color-e-nearwhite);
76+
}
77+
}
78+
}
5279
}
5380
</style>
5481

@@ -70,6 +97,7 @@ export default defineComponent({
7097
props: {
7198
checked: { type: Boolean, required: true },
7299
icon: { type: String, default: "Checkmark" },
100+
outlineStyle: { type: Boolean, default: false },
73101
},
74102
components: { IconLabel },
75103
});

client/web/src/components/widgets/inputs/MenuBarInput.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ const menuEntries: MenuListEntries = [
9393
{ label: "Save", shortcut: ["Ctrl", "S"] },
9494
{ label: "Save As…", shortcut: ["Ctrl", "", "S"] },
9595
{ label: "Save All", shortcut: ["Ctrl", "Alt", "S"] },
96-
{ label: "Auto-Save", shortcut: undefined },
96+
{ label: "Auto-Save", checkbox: true, checked: true },
9797
],
9898
[
9999
{ label: "Import…", shortcut: ["Ctrl", "I"] },

0 commit comments

Comments
 (0)