* Define a component to be exposed from the registry. Creates the 4 different variants of the component and ensures the correct files are included. * * @param title The title of the component. * @param description The description of the component. * @param category The category of the component.
({
title,
description,
category,
categories,
meta,
variants = ['JS-CSS', 'JS-TW', 'TS-CSS', 'TS-TW']
}: {
title: string;
description: string;
category: Category;
categories?: string[];
meta?: Record<string, string>;
variants?: readonly Variant[];
})
| 56 | * @returns An array of RegistryItem objects. |
| 57 | */ |
| 58 | function defineComponent({ |
| 59 | title, |
| 60 | description, |
| 61 | category, |
| 62 | categories, |
| 63 | meta, |
| 64 | variants = ['JS-CSS', 'JS-TW', 'TS-CSS', 'TS-TW'] |
| 65 | }: { |
| 66 | title: string; |
| 67 | description: string; |
| 68 | category: Category; |
| 69 | categories?: string[]; |
| 70 | meta?: Record<string, string>; |
| 71 | variants?: readonly Variant[]; |
| 72 | }): RegistryItem[] { |
| 73 | const baseItem: Omit<RegistryItem, 'files' | 'name'> = { |
| 74 | title, |
| 75 | description, |
| 76 | type: 'registry:component', |
| 77 | categories: [category, ...(categories ?? [])], |
| 78 | meta, |
| 79 | ...(title === 'Lanyard' ? { dependencyResolution: 'manual' as const } : {}) |
| 80 | }; |
| 81 | |
| 82 | const filesForVariant = (basePath: string, sourceFile: string, styleFile?: string) => |
| 83 | title === 'Lanyard' |
| 84 | ? [ |
| 85 | ...(styleFile ? [{ path: `${basePath}/${styleFile}` }] : []), |
| 86 | { path: `${basePath}/${sourceFile}` } |
| 87 | ] |
| 88 | : [{ path: basePath }]; |
| 89 | |
| 90 | // this might warrant a bit of explanation |
| 91 | // basically we check if the variant is included in the variants array and if so we return the item as part of an array |
| 92 | // otherwise we return an empty array |
| 93 | // we then spread that array empty or otherwise into the return array |
| 94 | return [ |
| 95 | // JS + CSS |
| 96 | ...(variants.includes('JS-CSS') |
| 97 | ? [ |
| 98 | { |
| 99 | ...baseItem, |
| 100 | name: `${baseItem.title}-JS-CSS`, |
| 101 | files: filesForVariant(`src/content/${category}/${title}`, `${title}.jsx`, `${title}.css`) |
| 102 | } |
| 103 | ] |
| 104 | : []), |
| 105 | |
| 106 | // JS + Tailwind |
| 107 | ...(variants.includes('JS-TW') |
| 108 | ? [ |
| 109 | { |
| 110 | ...baseItem, |
| 111 | name: `${baseItem.title}-JS-TW`, |
| 112 | files: filesForVariant(`src/tailwind/${category}/${title}`, `${title}.jsx`) |
| 113 | } |
| 114 | ] |
| 115 | : []), |
no test coverage detected