Skip to content

Commit f5c8fcb

Browse files
Fix component rendering for .ts components (#60)
* ♻️ refactor SectionsList to sectionList across the application * 🐛 Check isValid before rendering * ⬆️ update qrcode.react to version 4.1.0
1 parent cee17df commit f5c8fcb

File tree

23 files changed

+194
-196
lines changed

23 files changed

+194
-196
lines changed

apps/website/__tests__/components/component-categories.test.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { describe, expect, it } from "vitest";
2-
import { SectionsList } from "@cuicui/ui";
2+
import { sectionList } from "@cuicui/ui/lib/section-list";
33
import { getFileContentAsString } from "#/src/utils/get-file-content-as-string";
44

5-
describe("SectionsList", () => {
5+
describe("sectionList", () => {
66
it("should have the correct number of sections", () => {
7-
expect(SectionsList).toHaveLength(7);
7+
expect(sectionList).toHaveLength(7);
88
});
99

1010
it("should have the correct section slugs in the good order", () => {
11-
const sectionSlugs = SectionsList.map((section) => section.slug);
11+
const sectionSlugs = sectionList.map((section) => section.slug);
1212
expect(sectionSlugs).toEqual([
1313
"common-ui",
1414
"application-ui",
@@ -21,7 +21,7 @@ describe("SectionsList", () => {
2121
});
2222

2323
it("category should have componentList === null if comingSoonCategory === true", () => {
24-
for (const section of SectionsList) {
24+
for (const section of sectionList) {
2525
if (section.type !== "multiple-component") {
2626
continue;
2727
}
@@ -55,7 +55,7 @@ describe("SectionsList", () => {
5555
}
5656
};
5757

58-
for (const section of SectionsList) {
58+
for (const section of sectionList) {
5959
if (section.type !== "multiple-component") {
6060
continue;
6161
}

apps/website/src/app/(site)/[section]/[category]/page.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { notFound } from "next/navigation";
22
import MultipleComponentCategory from "#/src/app/(site)/[section]/[category]/multiple-component-section";
33
import SingleComponentCategory from "#/src/app/(site)/[section]/[category]/single-component-section";
4-
import { SectionsList } from "@cuicui/ui";
4+
import { sectionList } from "@cuicui/ui/lib/section-list";
55
import type {
66
CategoryType,
77
SingleComponentCategoryType,
@@ -15,7 +15,7 @@ type Props = {
1515
};
1616

1717
export async function generateStaticParams() {
18-
const params = SectionsList.flatMap((section) => {
18+
const params = sectionList.flatMap((section) => {
1919
if (
2020
section.type === "multiple-component" ||
2121
section.type === "single-component"
@@ -38,7 +38,7 @@ export async function generateStaticParams() {
3838
}
3939

4040
export default async function Page({ params }: Readonly<Props>) {
41-
const section = SectionsList.find(
41+
const section = sectionList.find(
4242
(section) => section.slug === params.section,
4343
);
4444
if (!section) {

apps/website/src/app/(site)/[section]/[category]/single-component-section.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default async function SingleComponentCategory({
2727

2828
const component = await fetchSingleComponentData({
2929
categorySlug: category.slug,
30-
component: { ...category.component },
30+
component: category.component,
3131
});
3232

3333
return (

apps/website/src/app/card.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type {
22
CategoryType,
33
SingleComponentCategoryType,
44
} from "@cuicui/ui/lib/types/component";
5-
import { categoriesPreviewsList } from "@/categories-previews-list";
5+
import { categoriesPreviewsList } from "@cuicui/ui/categories-previews-list";
66
import { createElement } from "react";
77
import { HourglassIcon } from "lucide-react";
88

@@ -28,7 +28,7 @@ export const MainMenuCardContent = ({
2828
if (Component) {
2929
return (
3030
<div className="flex items-center justify-center size-full gap-2 py-4 px-12">
31-
{createElement(Component, { category })}
31+
{createElement(Component)}
3232
</div>
3333
);
3434
}

apps/website/src/app/preview/[section]/[category]/[component]/[variant]/page.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SectionsList } from "@cuicui/ui/lib/sections-list";
1+
import { sectionList } from "@cuicui/ui/lib/section-list";
22
import type { Metadata } from "next";
33
import { notFound } from "next/navigation";
44
import { createElement } from "react";
@@ -9,7 +9,7 @@ export const metadata: Metadata = {
99
};
1010

1111
export async function generateStaticParams() {
12-
return SectionsList.map((section) => {
12+
return sectionList.map((section) => {
1313
if (section.type === "multiple-component") {
1414
return section.categoriesList.map((category) => {
1515
return category.componentList?.map((component) => {
@@ -70,7 +70,7 @@ export const findCorrespondingComponent = ({
7070
component: string;
7171
variant?: string;
7272
}) => {
73-
const sectionFound = SectionsList.find((s) => s.slug === section);
73+
const sectionFound = sectionList.find((s) => s.slug === section);
7474
if (!sectionFound) {
7575
return null;
7676
}

apps/website/src/app/preview/[section]/[category]/[component]/page.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { findCorrespondingComponent } from "#/src/app/preview/[section]/[category]/[component]/[variant]/page";
2-
import { SectionsList } from "@cuicui/ui/lib/sections-list";
2+
import { sectionList } from "@cuicui/ui/lib/section-list";
33
import type { Metadata } from "next";
44
import { notFound } from "next/navigation";
55
import { createElement } from "react";
@@ -10,7 +10,7 @@ export const metadata: Metadata = {
1010
};
1111

1212
export async function generateStaticParams() {
13-
return SectionsList.map((section) => {
13+
return sectionList.map((section) => {
1414
if (section.type === "single-component") {
1515
return section.categoriesList.map((category) => {
1616
if (!category.component) {

apps/website/src/app/sitemap.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { MetadataRoute } from "next";
2-
import { SectionsList } from "@cuicui/ui";
2+
import { sectionList } from "@cuicui/ui/lib/section-list";
33

44
export const port = process.env.PORT ?? 3000;
55

@@ -34,7 +34,7 @@ const staticSitemap: MetadataRoute.Sitemap = [
3434

3535
function getComponentsSitemap(): MetadataRoute.Sitemap {
3636
const componentSitemap: MetadataRoute.Sitemap = [];
37-
SectionsList.flatMap((section) => {
37+
sectionList.flatMap((section) => {
3838
if (
3939
section.type === "multiple-component" ||
4040
section.type === "single-component"

apps/website/src/components/component-wrapper/component-tab-renderer.tsx

+9-7
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
} from "#/src/ui/shadcn/scrollarea";
2222
import { cn } from "#/src/utils/cn";
2323
import { getContainerHeightClass } from "#/src/components/component-wrapper/get-container-height-class";
24-
import { createElement } from "react";
24+
import { createElement, isValidElement } from "react";
2525
const tabs = [
2626
{
2727
name: "Preview",
@@ -119,9 +119,10 @@ export default function ComponentTabRenderer({
119119
size={size}
120120
// key={render}
121121
>
122-
{typeof component === "function"
123-
? createElement(component)
124-
: (component ?? <p>An error has occured</p>)}
122+
{isValidElement(component)
123+
? component
124+
: //@ts-ignore
125+
createElement(component)}
125126
</ComponentWrapper>
126127
</ResizablePanel>
127128
<ResizableHandle
@@ -139,9 +140,10 @@ export default function ComponentTabRenderer({
139140
size={size}
140141
// key={render}
141142
>
142-
{typeof component === "function"
143-
? createElement(component)
144-
: (component ?? <p>An error has occured</p>)}
143+
{isValidElement(component)
144+
? component
145+
: //@ts-ignore
146+
createElement(component)}
145147
</ComponentWrapper>
146148
)}
147149
</Tabs.Content>

apps/website/src/components/floating-dock-navigation/floating-dock.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { SectionsList } from "@cuicui/ui";
2-
1+
import { sectionList } from "@cuicui/ui/lib/section-list";
32
import { FloatingDock } from "#/src/components/floating-dock-navigation/floating-docks-component";
43
import { ArrowUpRightIcon, GithubIcon } from "lucide-react";
54
import { cn } from "#/src/utils/cn";
@@ -8,7 +7,7 @@ import Link from "next/link";
87
import { FloatingDockToggleTheme } from "#/src/components/floating-dock-navigation/floating-dock-toggle-theme";
98
import { CUICUI_GITHUB_URL } from "#/src/lib/site.const";
109

11-
const sectionLinks = SectionsList.map((section) => {
10+
const sectionLinks = sectionList.map((section) => {
1211
return {
1312
title: section.name,
1413
Icon: <section.icon className="size-6" />,

apps/website/src/components/navigation/navigation-menu.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
GlobalNavItem,
55
SectionWrapper,
66
} from "#/src/components/navigation/navigation-item";
7-
import { SectionsList } from "@cuicui/ui";
7+
import { sectionList } from "@cuicui/ui/lib/section-list";
88
import type {
99
CategoryType,
1010
SingleComponentCategoryType,
@@ -55,7 +55,7 @@ export default function NavigationMenu({
5555

5656
return (
5757
<nav className={cn("mt-5 mb-12 px-1 space-y-2 min-h-full", className)}>
58-
{SectionsList.map((section) => {
58+
{sectionList.map((section) => {
5959
if (section.type === "page") {
6060
return (
6161
<SectionWrapper

apps/website/src/components/search-menu/search-menu.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { SearchIcon } from "lucide-react";
55
import { type ComponentProps, useState } from "react";
66
import { FirstSectionCommandGroup } from "#/src/components/search-menu/first-section-command-group";
77
import { SearchGroupComponentSection } from "#/src/components/search-menu/search-group-multi-component-section";
8-
import { SectionsList } from "@cuicui/ui";
8+
import { sectionList } from "@cuicui/ui/lib/section-list";
99
import { useKeyPress } from "@cuicui/ui/cuicui/hooks/use-key-press/use-key-press";
1010
import {
1111
CommandDialog,
@@ -60,7 +60,7 @@ export function SearchMenu({ ...props }: ComponentProps<"button">) {
6060

6161
<FirstSectionCommandGroup closeSearchMenu={() => setOpen(false)} />
6262

63-
{SectionsList.map((section) => {
63+
{sectionList.map((section) => {
6464
return (
6565
<SearchGroupComponentSection
6666
closeSearchMenu={() => setOpen(false)}

apps/website/src/utils/get-file-content-as-string.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"use server";
2+
import { sectionList } from "@cuicui/ui/lib/section-list";
23
import { promises as fs } from "node:fs";
34
import path from "node:path";
45

@@ -53,15 +54,13 @@ async function GetFileContentFromPathWithoutExtension(
5354
}
5455
}
5556

56-
import { SectionsList } from "@cuicui/ui";
57-
5857
function getComponentPath({
5958
componentSlug,
6059
variantName,
6160
}: { componentSlug: string; variantName: string }) {
6261
let basePath: null | string = null;
6362

64-
for (const section of SectionsList) {
63+
for (const section of sectionList) {
6564
if (section.type === "page") {
6665
continue;
6766
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { SectionsList } from "@cuicui/ui";
1+
import { sectionList } from "@cuicui/ui/lib/section-list";
22
import type { SectionType } from "@cuicui/ui/lib/types/component";
33

44
export function findSectionBySlug(slug: string): SectionType | null {
5-
return SectionsList.find((section) => section.slug === slug) ?? null;
5+
return sectionList.find((section) => section.slug === slug) ?? null;
66
}

packages/ui/cuicui/application-ui/dropdown-menu/mac-os-dropdown/component.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import { PreviewMacOSDropdownMenu } from "@/cuicui/application-ui/dropdown-menu/
22
import type { ComponentType } from "@/lib/types/component";
33

44
export const macOsDropdownComponent: ComponentType = {
5-
sizePreview: "sm",
65
slug: "mac-os-dropdown",
6+
name: "Mac OS Dropdown",
7+
description: "Mac OS dropdown menu",
8+
sizePreview: "sm",
79
variantList: [
810
{
911
name: "Default",
@@ -12,6 +14,4 @@ export const macOsDropdownComponent: ComponentType = {
1214
slugComponentFile: "mac-os-dropdown",
1315
},
1416
],
15-
name: "Mac OS Dropdown",
16-
description: "Mac OS dropdown menu",
1717
};

packages/ui/cuicui/other/other.section.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { RectangleEllipsisIcon } from "lucide-react";
2-
import type { SectionType } from "@/lib/types/component";
2+
import type { MultiComponentSectionType } from "@/lib/types/component";
33
import { cursorCategory } from "@/cuicui/other/cursors/cursor.category";
44
import { mockUpsCategory } from "@/cuicui/other/mock-ups/mock-ups.category";
55
import { patternsCategory } from "@/cuicui/other/patterns/patterns.category";
66
import { qrCodeCategory } from "@/cuicui/other/qr-code/qr-code.category";
77
import { transitionWrappersCategory } from "@/cuicui/other/transition-wrappers/transition-wrappers.category";
88
import { creativeEffectCategory } from "@/cuicui/other/creative-effects/category.creative-effet";
9-
export const otherSection: SectionType = {
9+
export const otherSection: MultiComponentSectionType = {
1010
name: "Other",
1111
slug: "other",
1212
type: "multiple-component",
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
import type { ComponentType } from "@/lib/types/component";
2-
3-
import PreviewBarCodeGenerator from "@/cuicui/other/qr-code/bar-code-generator/preview-bar-code-generator";
2+
import { PreviewBarCodeGenerator } from "@/cuicui/other/qr-code/bar-code-generator/preview-bar-code-generator";
43

54
export const BarCodeGeneratorComponent: ComponentType = {
6-
name: "Bar Code Generator",
75
slug: "bar-code-generator",
6+
name: "Bar Code Generator",
87
description: "Generate bar codes",
98
sizePreview: "sm",
109
variantList: [
1110
{
12-
component: <PreviewBarCodeGenerator />,
11+
name: "Bar Code Generator",
12+
component: PreviewBarCodeGenerator,
1313
slugComponentFile: "bar-code-generator",
1414
slugPreviewFile: "preview-bar-code-generator",
15-
name: "Bar Code Generator",
1615
},
1716
],
1817
};

packages/ui/cuicui/other/qr-code/bar-code-generator/preview-bar-code-generator.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useState } from "react";
33
import { ModernSimpleInput } from "@/cuicui/common-ui/inputs/modern-simple-input/modern-simple-input";
44
import { BarCodeGenerator } from "@/cuicui/other/qr-code/bar-code-generator/bar-code-generator";
55

6-
export default function PreviewBarCodeGenerator() {
6+
export const PreviewBarCodeGenerator = () => {
77
const [value, setValue] = useState("https://www.modul.day/");
88
return (
99
<div className="flex w-full flex-col items-center gap-4">
@@ -26,4 +26,4 @@ export default function PreviewBarCodeGenerator() {
2626
)}
2727
</div>
2828
);
29-
}
29+
};
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import type { ComponentType } from "@/lib/types/component";
22
import { QrCodeGenerator } from "@/cuicui/other/qr-code/qr-code-generator/qr-code-generator";
3+
34
export const QrCodeGeneratorComponent: ComponentType = {
4-
sizePreview: "md",
55
slug: "qr-code-generator",
6+
name: "QR Code Generator",
7+
description: "A QR code generator component using qrcode.react",
8+
sizePreview: "md",
69
variantList: [
710
{
811
name: "Default",
912
component: QrCodeGenerator,
1013
slugPreviewFile: "qr-code-generator",
1114
},
1215
],
13-
name: "QR Code Generator",
14-
description: "A QR code generator component using qrcode.react",
1516
};
16-
17-
export default QrCodeGeneratorComponent;

packages/ui/cuicui/other/qr-code/qr-code.category.tsx packages/ui/cuicui/other/qr-code/qr-code.category.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { QrCodeIcon } from "lucide-react";
22
import type { CategoryType } from "@/lib/types/component";
3-
import { BarCodeGeneratorComponent } from "@/cuicui/other/qr-code/bar-code-generator/bar-code-generator.component";
3+
import { BarCodeGeneratorComponent } from "@/cuicui/other/qr-code/bar-code-generator/component";
44
import { QrCodeGeneratorComponent } from "@/cuicui/other/qr-code/qr-code-generator/component";
55

66
export const qrCodeCategory: CategoryType = {

packages/ui/index.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { SectionsList } from "./lib/sections-list";
21
import { AnimatedNumber } from "@/cuicui/other/transition-wrappers/animated-number/animated-number";
3-
import { categoriesPreviewsList } from "./categories-previews-list";
42

5-
export { SectionsList, AnimatedNumber, categoriesPreviewsList };
3+
export { AnimatedNumber };

packages/ui/lib/sections-list.ts packages/ui/lib/section-list.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { utilsSection } from "@/cuicui/utils/utils.section";
88
import type { SectionType } from "./types/component";
99
import { marketingUiSection } from "@/cuicui/marketing-ui/section.marketing-ui";
1010

11-
export const SectionsList: SectionType[] = [
11+
export const sectionList: SectionType[] = [
1212
commonUiSection,
1313
applicationUiSection,
1414
marketingUiSection,

packages/ui/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"jsbarcode": "3.11.6",
4040
"lucide-react": "^0.453.0",
4141
"next": "14.2.3",
42-
"qrcode.react": "4.0.1",
42+
"qrcode.react": "4.1.0",
4343
"react": "18.2.0",
4444
"react-dom": "18.2.0",
4545
"sonner": "1.5.0",

0 commit comments

Comments
 (0)