diff --git a/apps/theming/src/components/ThemeList.vue b/apps/theming/src/components/ThemeList.vue index a50c2cd0d803a..888ced8b60956 100644 --- a/apps/theming/src/components/ThemeList.vue +++ b/apps/theming/src/components/ThemeList.vue @@ -26,6 +26,11 @@ const props = defineProps<{ */ multiple?: boolean + /** + * The default theme if multiple is false + */ + default?: ITheme + /** * The list of available themes */ @@ -60,18 +65,13 @@ async function toggleTheme(theme: ITheme, state: boolean) { return } - if (!props.multiple && state === false) { - // handled by the radio logic below for the enabled element - return - } - try { loading.value = true if (state === false) { await axios.delete(generateOcsUrl('apps/theming/api/v1/theme/{themeId}', { themeId: theme.id })) - if (!props.multiple) { + if (!props.multiple && props.default) { // If the theme was disabled, we need to enable the default theme - const defaultTheme = props.themes.find((t) => t.id === 'default') + const defaultTheme = props.themes.find((t) => t.id === props.default!.id) if (defaultTheme && !defaultTheme.enabled) { await axios.put(generateOcsUrl('apps/theming/api/v1/theme/{themeId}/enable', { themeId: defaultTheme.id })) defaultTheme.enabled = true @@ -112,7 +112,7 @@ async function toggleTheme(theme: ITheme, state: boolean) { :enforced="theme.id === enforcedTheme" :loading :theme - :unique="!multiple" + :type="multiple ? 'checkbox' : ($props.default ? 'radio' : 'switch')" :name @update:modelValue="toggleTheme(theme, $event)" /> diff --git a/apps/theming/src/components/ThemeListItem.vue b/apps/theming/src/components/ThemeListItem.vue index 765f71d07b292..86ea762d871b5 100644 --- a/apps/theming/src/components/ThemeListItem.vue +++ b/apps/theming/src/components/ThemeListItem.vue @@ -31,18 +31,30 @@ const props = defineProps<{ /** The theme */ theme: ITheme /** - * If true, the theme can be selected exclusively (radio button), - * otherwise it can be selected in addition to other themes (switch) + * The type of the switch. */ - unique: boolean + type: 'checkbox' | 'radio' | 'switch' /** * When multiple themes are allowed, this is the name of the input group. */ name?: string }>() -const switchType = computed(() => props.unique ? 'radio' : 'checkbox') const imageUrl = computed(() => generateFilePath('theming', 'img', props.theme.id + '.jpg')) +const checkboxValue = computed({ + get() { + if (props.type === 'switch') { + return isSelected.value + } else if (props.type === 'radio') { + return isSelected.value ? props.theme.id : false + } else { + return isSelected.value ? [props.theme.id] : [] + } + }, + set() { + isSelected.value = !isSelected.value + }, +})