import './LayoutSettings.scss' import { NButton, NFlex, NForm, NFormItem, NInputNumber, NSelect, NSwitch, } from 'naive-ui' import { defineComponent } from 'vue' import type { PropType } from 'vue' import { LAYOUT_MODES } from './AdminShell' import type { LayoutConfig, LayoutMode } from './AdminShell' import { renderLayoutPreview } from './layout-preview' import type { LayoutPreview } from './layout-preview' export interface LayoutChoice { id: string label: string preview: LayoutMode | LayoutPreview disabled?: boolean hint?: string } export const LayoutSettings = defineComponent({ name: 'LayoutSettings', props: { showDescription: Boolean, choices: { type: Array as PropType, default: void 0 }, selectedId: { type: String, default: void 0 }, selectionNotice: { type: String, default: void 0 }, onSelect: { type: Function as PropType<(id: string) => void>, default: void 0, }, layout: { type: Object as PropType, required: true }, defaults: { type: Object as PropType, required: true }, translate: { type: Function as PropType<(key: string) => string>, required: true, }, update: { type: Function as PropType<(value: Partial) => void>, required: true, }, }, setup(props) { const text = props.translate const update = props.update return () => { const selected = props.selectedId ?? props.layout.mode const choices = props.choices ?? LAYOUT_MODES.map((mode) => ({ id: mode, preview: mode, label: text(mode), hint: text(`modeHint.${mode}`), disabled: false, })) const hint = choices.find(({ id }) => id === selected)?.hint return ( {props.showDescription ? (

{text('description')}

) : null}
{choices.map((choice) => { const mode = typeof choice.preview === 'string' ? choice.preview : LAYOUT_MODES.find((item) => item === choice.id) return ( ) })}
{props.selectionNotice || (props.showDescription && hint) ? (

{props.selectionNotice || hint}

) : null} ({ value, label: text(value), }))} onUpdateValue={(value: LayoutConfig['contentWidth']) => update({ contentWidth: value }) } /> { if (value !== null) update({ contentMaxWidth: value }) }} /> { if (value !== null) update({ contentPadding: value }) }} /> update({ fixedHeader })} /> update({ fixedFooter })} /> update({ ...props.defaults })}> {text('reset')}
) } }, })