generated from pascalmartineau/wp-skeleton
refactor: sections-map
All checks were successful
Deploy WordPress and Nuxt / deploy (push) Successful in 1m6s
All checks were successful
Deploy WordPress and Nuxt / deploy (push) Successful in 1m6s
This commit is contained in:
15
wp-content/themes/ccat/shared/utils/sections-map.ts
Normal file
15
wp-content/themes/ccat/shared/utils/sections-map.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import SectionTextBlock from "~/components/sections/SectionTextBlock.vue";
|
||||
import type { TheSectionFragment } from "#graphql-operations";
|
||||
|
||||
export const sectionsMap = {
|
||||
GroupAbstractBuilderSectionsTextBlockLayout: SectionTextBlock,
|
||||
} as const;
|
||||
|
||||
export type FieldGroupName = keyof typeof sectionsMap;
|
||||
|
||||
export function useSection(section: TheSectionFragment) {
|
||||
const { fieldGroupName, ...attrs } = section;
|
||||
const component = sectionsMap[fieldGroupName as FieldGroupName];
|
||||
if (!component) throw createError({ statusCode: 500, statusMessage: "Erreur interne", message: "Section invalide." });
|
||||
return { component, attrs };
|
||||
}
|
||||
Reference in New Issue
Block a user