Refactor RadioInput widget (#332)
This commit is contained in:
parent
699562b735
commit
434695d578
|
|
@ -34,11 +34,7 @@
|
||||||
|
|
||||||
<Separator :type="SeparatorType.Unrelated" />
|
<Separator :type="SeparatorType.Unrelated" />
|
||||||
|
|
||||||
<RadioInput @update:index="viewModeChanged" v-model:index="viewModeIndex">
|
<RadioInput :entries="viewModeEntries" v-model:selectedIndex="viewModeIndex" />
|
||||||
<IconButton :action="() => {}" :icon="'ViewModeNormal'" :size="24" title="View Mode: Normal" />
|
|
||||||
<IconButton :action="() => comingSoon(319)" :icon="'ViewModeOutline'" :size="24" title="View Mode: Outline" />
|
|
||||||
<IconButton :action="() => comingSoon(320)" :icon="'ViewModePixels'" :size="24" title="View Mode: Pixels" />
|
|
||||||
</RadioInput>
|
|
||||||
<PopoverButton>
|
<PopoverButton>
|
||||||
<h3>View Mode</h3>
|
<h3>View Mode</h3>
|
||||||
<p>More view mode options will be here</p>
|
<p>More view mode options will be here</p>
|
||||||
|
|
@ -228,7 +224,7 @@ import PersistentScrollbar, { ScrollbarDirection } from "@/components/widgets/sc
|
||||||
import CanvasRuler, { RulerDirection } from "@/components/widgets/rulers/CanvasRuler.vue";
|
import CanvasRuler, { RulerDirection } from "@/components/widgets/rulers/CanvasRuler.vue";
|
||||||
import IconButton from "@/components/widgets/buttons/IconButton.vue";
|
import IconButton from "@/components/widgets/buttons/IconButton.vue";
|
||||||
import PopoverButton from "@/components/widgets/buttons/PopoverButton.vue";
|
import PopoverButton from "@/components/widgets/buttons/PopoverButton.vue";
|
||||||
import RadioInput from "@/components/widgets/inputs/RadioInput.vue";
|
import RadioInput, { RadioEntries } from "@/components/widgets/inputs/RadioInput.vue";
|
||||||
import NumberInput, { IncrementDirection } from "@/components/widgets/inputs/NumberInput.vue";
|
import NumberInput, { IncrementDirection } from "@/components/widgets/inputs/NumberInput.vue";
|
||||||
import DropdownInput from "@/components/widgets/inputs/DropdownInput.vue";
|
import DropdownInput from "@/components/widgets/inputs/DropdownInput.vue";
|
||||||
import OptionalInput from "@/components/widgets/inputs/OptionalInput.vue";
|
import OptionalInput from "@/components/widgets/inputs/OptionalInput.vue";
|
||||||
|
|
@ -238,10 +234,15 @@ import { SectionsOfMenuListEntries } from "@/components/widgets/floating-menus/M
|
||||||
const documentModeEntries: SectionsOfMenuListEntries = [
|
const documentModeEntries: SectionsOfMenuListEntries = [
|
||||||
[
|
[
|
||||||
{ label: "Design Mode", icon: "ViewportDesignMode" },
|
{ label: "Design Mode", icon: "ViewportDesignMode" },
|
||||||
{ label: "Select Mode", icon: "ViewportSelectMode" },
|
{ label: "Select Mode", icon: "ViewportSelectMode", action: () => comingSoon(330) },
|
||||||
{ label: "Guide Mode", icon: "ViewportGuideMode" },
|
{ label: "Guide Mode", icon: "ViewportGuideMode", action: () => comingSoon(331) },
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
const viewModeEntries: RadioEntries = [
|
||||||
|
{ value: "normal", icon: "ViewModeNormal", tooltip: "View Mode: Normal" },
|
||||||
|
{ value: "outline", icon: "ViewModeOutline", tooltip: "View Mode: Outline", action: () => comingSoon(319) },
|
||||||
|
{ value: "pixels", icon: "ViewModePixels", tooltip: "View Mode: Pixels", action: () => comingSoon(320) },
|
||||||
|
];
|
||||||
|
|
||||||
const wasm = import("@/../wasm/pkg");
|
const wasm = import("@/../wasm/pkg");
|
||||||
|
|
||||||
|
|
@ -294,12 +295,6 @@ export default defineComponent({
|
||||||
const { select_tool } = await wasm;
|
const { select_tool } = await wasm;
|
||||||
select_tool(toolName);
|
select_tool(toolName);
|
||||||
},
|
},
|
||||||
async viewModeChanged(toolIndex: number) {
|
|
||||||
function todo(_: number) {
|
|
||||||
return _;
|
|
||||||
}
|
|
||||||
todo(toolIndex);
|
|
||||||
},
|
|
||||||
async swapWorkingColors() {
|
async swapWorkingColors() {
|
||||||
const { swap_colors } = await wasm;
|
const { swap_colors } = await wasm;
|
||||||
swap_colors();
|
swap_colors();
|
||||||
|
|
@ -361,6 +356,7 @@ export default defineComponent({
|
||||||
canvasSvgHeight: "100%",
|
canvasSvgHeight: "100%",
|
||||||
activeTool: "Select",
|
activeTool: "Select",
|
||||||
documentModeEntries,
|
documentModeEntries,
|
||||||
|
viewModeEntries,
|
||||||
documentModeSelectionIndex: 0,
|
documentModeSelectionIndex: 0,
|
||||||
viewModeIndex: 0,
|
viewModeIndex: 0,
|
||||||
snappingEnabled: true,
|
snappingEnabled: true,
|
||||||
|
|
|
||||||
|
|
@ -183,7 +183,8 @@ const MenuList = defineComponent({
|
||||||
|
|
||||||
if (menuEntry.action) menuEntry.action();
|
if (menuEntry.action) menuEntry.action();
|
||||||
else if (this.defaultAction) this.defaultAction();
|
else if (this.defaultAction) this.defaultAction();
|
||||||
else this.$emit("update:activeEntry", menuEntry);
|
|
||||||
|
this.$emit("update:activeEntry", menuEntry);
|
||||||
},
|
},
|
||||||
handleEntryMouseEnter(menuEntry: MenuListEntry) {
|
handleEntryMouseEnter(menuEntry: MenuListEntry) {
|
||||||
if (!menuEntry.children || !menuEntry.children.length) return;
|
if (!menuEntry.children || !menuEntry.children.length) return;
|
||||||
|
|
|
||||||
|
|
@ -1,89 +1,99 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="radio-input" ref="radioInput">
|
<div class="radio-input" ref="radioInput">
|
||||||
<slot></slot>
|
<button :class="{ active: index === selectedIndex }" v-for="(entry, index) in entries" :key="index" @click="handleEntryClick(entry)" :title="entry.tooltip">
|
||||||
|
<IconLabel v-if="entry.icon" :icon="entry.icon" />
|
||||||
|
<TextLabel v-if="entry.label">{{ entry.label }}</TextLabel>
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
.radio-input {
|
.radio-input {
|
||||||
.popover-button button {
|
button {
|
||||||
border-radius: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
& > * {
|
|
||||||
border-radius: 0;
|
|
||||||
margin: 0;
|
|
||||||
|
|
||||||
&:first-child,
|
|
||||||
&:first-child button {
|
|
||||||
border-radius: 2px 0 0 2px;
|
|
||||||
}
|
|
||||||
|
|
||||||
&:last-child,
|
|
||||||
&:last-child button {
|
|
||||||
border-radius: 0 2px 2px 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
& + * {
|
|
||||||
margin-left: 1px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
& > button {
|
|
||||||
background: var(--color-5-dullgray);
|
background: var(--color-5-dullgray);
|
||||||
fill: var(--color-e-nearwhite);
|
fill: var(--color-e-nearwhite);
|
||||||
|
height: 24px;
|
||||||
|
padding: 0 4px;
|
||||||
|
outline: none;
|
||||||
|
border: none;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
background: var(--color-6-lowergray);
|
background: var(--color-6-lowergray);
|
||||||
|
color: var(--color-f-white);
|
||||||
|
|
||||||
|
svg {
|
||||||
|
fill: var(--color-f-white);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&.active {
|
&.active {
|
||||||
background: var(--color-accent);
|
background: var(--color-accent);
|
||||||
fill: var(--color-f-white);
|
color: var(--color-f-white);
|
||||||
|
|
||||||
|
svg {
|
||||||
|
fill: var(--color-f-white);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
& + button {
|
||||||
|
margin-left: 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:first-of-type {
|
||||||
|
border-radius: 2px 0 0 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:last-of-type {
|
||||||
|
border-radius: 0 2px 2px 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-label,
|
||||||
|
.text-label {
|
||||||
|
display: inline-block;
|
||||||
|
vertical-align: top;
|
||||||
|
}
|
||||||
|
|
||||||
|
.text-label {
|
||||||
|
margin: 0 4px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent } from "vue";
|
import { defineComponent, PropType } from "vue";
|
||||||
|
|
||||||
|
import IconLabel from "@/components/widgets/labels/IconLabel.vue";
|
||||||
|
import TextLabel from "@/components/widgets/labels/TextLabel.vue";
|
||||||
|
|
||||||
|
export interface RadioEntryData {
|
||||||
|
value?: string;
|
||||||
|
label?: string;
|
||||||
|
icon?: string;
|
||||||
|
tooltip?: string;
|
||||||
|
action?: Function;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type RadioEntries = Array<RadioEntryData>;
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
components: {},
|
|
||||||
props: {
|
props: {
|
||||||
index: { type: Number, required: true },
|
entries: { type: Array as PropType<RadioEntries>, required: true },
|
||||||
},
|
selectedIndex: { type: Number, required: true },
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
activeIndex: this.index,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
mounted() {
|
|
||||||
this.updateActiveIconButton();
|
|
||||||
|
|
||||||
(this.$refs.radioInput as Element).querySelectorAll(".icon-button").forEach((iconButton, index) => {
|
|
||||||
iconButton.addEventListener("click", () => {
|
|
||||||
this.setActive(index);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
watch: {
|
|
||||||
activeIndex() {
|
|
||||||
this.updateActiveIconButton();
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
// This method may be called by the user of this component by setting a `ref="radioInput"` attribute and calling `(this.$refs.viewModePicker as typeof RadioInput).setActive(...)`
|
handleEntryClick(menuEntry: RadioEntryData) {
|
||||||
setActive(index: number) {
|
const index = this.entries.indexOf(menuEntry);
|
||||||
this.activeIndex = index;
|
this.$emit("update:selectedIndex", index);
|
||||||
this.$emit("update:index", index);
|
|
||||||
this.$emit("changed", index);
|
if (menuEntry.action) menuEntry.action();
|
||||||
},
|
|
||||||
updateActiveIconButton() {
|
|
||||||
const iconButtons = (this.$refs.radioInput as Element).querySelectorAll(".icon-button");
|
|
||||||
iconButtons.forEach((iconButton) => iconButton.classList.remove("active"));
|
|
||||||
iconButtons[this.activeIndex].classList.add("active");
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
components: {
|
||||||
|
IconLabel,
|
||||||
|
TextLabel,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue