Nuxt/packages/nuxt3/src/pages/runtime/layout.ts

25 lines
725 B
TypeScript
Raw Normal View History

import { defineComponent, h, Ref } from 'vue'
// @ts-ignore
2021-06-30 16:32:22 +00:00
import layouts from '#build/layouts'
export default defineComponent({
props: {
name: {
type: [String, Boolean, Object] as unknown as () => string | false | Ref<string | false>,
2021-06-30 16:32:22 +00:00
default: 'default'
}
},
setup (props, context) {
return () => {
const layout = (props.name && typeof props.name === 'object' ? props.name.value : props.name) ?? 'default'
2021-06-30 16:32:22 +00:00
if (!layouts[layout]) {
if (process.dev && layout && layout !== 'default') {
console.warn(`Invalid layout \`${layout}\` selected.`)
}
return context.slots.default()
}
return h(layouts[layout], props, context.slots)
}
}
})