UNPKG

@nextcloud/vue

Version:
1 lines 4.6 kB
{"version":3,"file":"NcAppSettingsSection-B9R7enkC.mjs","sources":["../../src/components/NcAppSettingsSection/NcAppSettingsSection.vue"],"sourcesContent":["<!--\n - SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors\n - SPDX-License-Identifier: AGPL-3.0-or-later\n-->\n\n<script setup lang=\"ts\">\nimport type { Slot } from 'vue'\n\nimport { computed, inject, onBeforeUnmount, onMounted, watch } from 'vue'\nimport { logger } from '../../utils/logger.ts'\nimport { APP_SETTINGS_LEGACY_DESIGN_KEY, useAppSettingsDialog } from '../NcAppSettingsDialog/useAppSettingsDialog.ts'\n\nconst props = defineProps<{\n\t/** Name of the section */\n\tname: string\n\t/** Optional description of the section */\n\tdescription?: string\n\t/** The id of the section */\n\tid: string\n\t/** The id of the section */\n\torder?: number\n}>()\n\nconst slots = defineSlots<{\n\t/** Section content */\n\tdefault?: Slot\n\t/** Optional icon for the section in the navigation */\n\ticon?: Slot\n}>()\n\nconst { registerSection, unregisterSection } = useAppSettingsDialog()\nconst legacy = inject(APP_SETTINGS_LEGACY_DESIGN_KEY)!\n\nconst htmlId = computed(() => 'settings-section_' + props.id)\n\n// Validate id prop - only alphanumeric, dash and underscore\nwatch(() => props.id, () => {\n\tif (!/^[a-z0-9\\-_]+$/.test(props.id)) {\n\t\tlogger.warn(`Invalid id prop: ${props.id}. Only alphanumeric, dash and underscore are allowed.`)\n\t}\n}, { immediate: true })\n\n// Reactive changes for section navigation\nwatch([() => props.id, () => props.name, () => props.order], (\n\t[newId, newName, newOrder],\n\t[oldId, ,],\n) => {\n\tunregisterSection(oldId)\n\tregisterSection(newId, newName, newOrder, slots?.icon?.())\n})\n\nonMounted(() => {\n\tregisterSection(props.id, props.name, props.order, slots?.icon?.())\n})\n\nonBeforeUnmount(() => {\n\tunregisterSection(props.id)\n})\n</script>\n\n<template>\n\t<section\n\t\t:id=\"htmlId\"\n\t\t:aria-labelledby=\"`${htmlId}--label`\"\n\t\tclass=\"app-settings-section\"\n\t\t:class=\"{ 'app-settings-section__legacy': legacy }\">\n\t\t<h3 :id=\"`${htmlId}--label`\" class=\"app-settings-section__name\">\n\t\t\t{{ name }}\n\t\t</h3>\n\t\t<div class=\"app-settings-section__description\">\n\t\t\t{{ description }}\n\t\t</div>\n\t\t<div class=\"app-settings-section__content\">\n\t\t\t<slot />\n\t\t</div>\n\t</section>\n</template>\n\n<style lang=\"scss\" scoped>\n.app-settings-section {\n\t--form-element-label-offset: calc(var(--border-radius-element) + var(--default-grid-baseline));\n\t--app-settings-section-text-offset: var(--form-element-label-offset);\n\t--app-settings-section-content-gap: calc(6 * var(--default-grid-baseline));\n\tmargin-block-end: calc(8 * var(--default-grid-baseline));\n\n\t&__name {\n\t\tmargin: 0;\n\t\tpadding-inline: var(--app-settings-section-text-offset);\n\t\tpadding-block: 0;\n\t\tfont-size: 20px;\n\t\tfont-weight: bold;\n\t}\n\n\t&__description {\n\t\tpadding-inline: var(--app-settings-section-text-offset);\n\t\tcolor: var(--color-text-maxcontrast);\n\t}\n\n\t&__content {\n\t\tmargin-block-start: calc(2 * var(--default-grid-baseline));\n\n\t\tdisplay: flex;\n\t\tflex-direction: column;\n\t\tjustify-content: stretch;\n\t\tgap: var(--app-settings-section-content-gap);\n\t}\n}\n\n.app-settings-section__legacy {\n\t--app-settings-section-text-offset: 0;\n\t--app-settings-section-content-gap: 0;\n}\n</style>\n"],"names":["_useSlots","_createElementBlock","_normalizeClass","_unref","_createElementVNode","name","_toDisplayString","description","_renderSlot"],"mappings":";;;;;;;;;;;;;;;;;AAYA,UAAM,QAAQ;AAWd,UAAM,QAAQA,SAAA;AAOd,UAAM,EAAE,iBAAiB,kBAAA,IAAsB,qBAAA;AAC/C,UAAM,SAAS,OAAO,8BAA8B;AAEpD,UAAM,SAAS,SAAS,MAAM,sBAAsB,MAAM,EAAE;AAG5D,UAAM,MAAM,MAAM,IAAI,MAAM;AAC3B,UAAI,CAAC,iBAAiB,KAA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