refactor(ui): move Toggle component to Composition API + TS (#3281)

* refactor(frontend): move Toggle component to Composition API + TS

**Toggle.vue**:
- Enable composition API and TS
- Added `disabled` to props
- Remove redundant `checked`
- Replace `modelValue` and `emits` with `defineModel` compiler macro

**Others**:
- Replace emit handling and `model-value` with `v-model` where simple logic was used
  - Not `FeatureFlagSettings.vue` (contained custom code on receiving emit)
  - Not `Mods.vue` (contained custom code on receiving emit)
- Remove redundant `checked` attribute

* fix(app): toggles not updating value
This commit is contained in:
Erb3
2025-02-21 19:43:49 +01:00
committed by GitHub
parent 719b395b7b
commit 195cc9cee0
9 changed files with 35 additions and 110 deletions

View File

@@ -225,7 +225,7 @@
</template>
</div>
<div class="preview">
<Toggle id="preview" v-model="previewMode" :checked="previewMode" />
<Toggle id="preview" v-model="previewMode" />
<label class="label" for="preview"> Preview </label>
</div>
</div>
@@ -263,31 +263,31 @@
</template>
<script setup lang="ts">
import { type Component, computed, ref, onMounted, onBeforeUnmount, toRef, watch } from 'vue'
import { type Component, computed, onBeforeUnmount, onMounted, ref, toRef, watch } from 'vue'
import { Compartment, EditorState } from '@codemirror/state'
import { EditorView, keymap, placeholder as cm_placeholder } from '@codemirror/view'
import { markdown } from '@codemirror/lang-markdown'
import { indentWithTab, historyKeymap, history } from '@codemirror/commands'
import { history, historyKeymap, indentWithTab } from '@codemirror/commands'
import {
AlignLeftIcon,
BoldIcon,
CodeIcon,
Heading1Icon,
Heading2Icon,
Heading3Icon,
BoldIcon,
ImageIcon,
InfoIcon,
ItalicIcon,
ScanEyeIcon,
StrikethroughIcon,
CodeIcon,
LinkIcon,
ListBulletedIcon,
ListOrderedIcon,
TextQuoteIcon,
LinkIcon,
ImageIcon,
YouTubeIcon,
AlignLeftIcon,
PlusIcon,
XIcon,
ScanEyeIcon,
StrikethroughIcon,
TextQuoteIcon,
UploadIcon,
InfoIcon,
XIcon,
YouTubeIcon,
} from '@modrinth/assets'
import { markdownCommands, modrinthMarkdownEditorKeymap } from '@modrinth/utils/codemirror'
import { renderHighlightedString } from '@modrinth/utils/highlight'

View File

@@ -1,35 +1,19 @@
<template>
<input
:id="id"
type="checkbox"
class="switch stylized-toggle"
:id="id"
:disabled="disabled"
:checked="checked"
@change="toggle"
@change="checked = !checked"
/>
</template>
<script>
export default {
props: {
id: {
type: String,
required: true,
},
modelValue: {
type: Boolean,
},
checked: {
type: Boolean,
required: true,
},
},
emits: ['update:modelValue'],
methods: {
toggle() {
if (!this.disabled) {
this.$emit('update:modelValue', !this.modelValue)
}
},
},
}
<script setup lang="ts">
defineProps<{
id?: string
disabled?: boolean
}>()
const checked = defineModel<boolean>()
</script>