'use client'; import { cn } from '@/lib/utils'; import { CopyIcon } from 'lucide-react'; import { useState } from 'react'; import { Button } from '@/components/shared/ui/button'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, DialogClose, } from '@/components/shared/ui/dialog'; import { CodeEditor } from '@/components/shared/CodeEditor'; import { CopyButton } from '@/components/shared/ui/copy-button'; import { Tabs, TabsContent, TabsList, TabsTrigger, } from '@/components/shared/ui/tabs'; import { FontDefinition } from '@/components/bricks/theme/font-pairing'; import { ColorThemeObject } from '@/components/bricks/theme/color-themes'; import { getShipixenThemeJs } from '@/components/bricks/theme/code-stringifiers/get-theme-js-file'; import { getShadcnTheme } from '@/components/bricks/theme/code-stringifiers/get-shadcn-ui-theme-string'; import { getHtmlTheme } from '@/components/bricks/theme/code-stringifiers/get-html-theme-string'; import { getNextjsFontImportString, getNextjsFontString, getNextjsHtmlFontString, } from '@/components/bricks/theme/code-stringifiers/get-nextjs-font-string'; import { getHtmlFontPageString, getHtmlFontStyleString, } from '@/components/bricks/theme/code-stringifiers/get-html-font-string'; import { stripIndents } from 'common-tags'; const COPY_TYPES = { NEXTJS: 'nextjs', REACT: 'react', HTML: 'html', SHADCN_UI: 'shadcnui', }; type CopyType = (typeof COPY_TYPES)[keyof typeof COPY_TYPES]; const ThemeCodeEditor = ({ fonts, themeObject, copyType, className = '', }: { fonts: { default: FontDefinition; display: FontDefinition; }; themeObject: ColorThemeObject; copyType: CopyType; className?: string; }) => { let formattedCodeStrings: { formattedCodeString: string; fileName: string; language?: string; }[] = []; const theme = { primary: { lighter: themeObject.colors.primary[3], light: themeObject.colors.primary[4], main: themeObject.colors.primary[5], dark: themeObject.colors.primary[6], darker: themeObject.colors.primary[7], }, secondary: { lighter: themeObject.colors.secondary[3], light: themeObject.colors.secondary[4], main: themeObject.colors.secondary[5], dark: themeObject.colors.secondary[6], darker: themeObject.colors.secondary[7], }, primaryTailwindName: themeObject.tailwindNames.primary, secondaryTailwindName: themeObject.tailwindNames.secondary, }; switch (copyType) { case COPY_TYPES.NEXTJS: formattedCodeStrings = [ { formattedCodeString: `${getNextjsFontImportString( fonts, )}\n\n${getNextjsFontString(fonts)}\n\n${getNextjsHtmlFontString()}`, fileName: 'app/layout.tsx', }, { formattedCodeString: getShipixenThemeJs(theme), fileName: 'data/config/colors.js', }, { formattedCodeString: getHtmlTheme(theme), fileName: 'globals.css (optional if you are NOT using Shipixen, add css variables)', language: 'css', }, ]; break; case COPY_TYPES.REACT: formattedCodeStrings = [ { formattedCodeString: getHtmlFontPageString(fonts), fileName: 'index.html', language: 'html', }, { formattedCodeString: getHtmlTheme(theme), fileName: 'index.css', language: 'css', }, ]; break; case COPY_TYPES.SHADCN_UI: formattedCodeStrings = [ { formattedCodeString: `${getNextjsFontImportString( fonts, )}\n\n${getNextjsFontString(fonts)}\n\n${getNextjsHtmlFontString()}`, fileName: 'app/layout.tsx', }, { formattedCodeString: `${getShadcnTheme(theme)}\n${stripIndents( getHtmlFontStyleString(fonts), )}`, fileName: 'globals.css', language: 'css', }, ]; break; case COPY_TYPES.HTML: formattedCodeStrings = [ { formattedCodeString: getHtmlFontPageString(fonts), fileName: 'index.html', }, { formattedCodeString: `${getHtmlTheme(theme)}\n\n${stripIndents( getHtmlFontStyleString(fonts), )}`, fileName: 'index.css', language: 'css', }, ]; break; default: break; } return ( <> {formattedCodeStrings.map( ({ formattedCodeString, fileName, language }, index) => { return (
{fileName}