Skip to content

Commit

Permalink
Add create-error utility and update import paths for cn() (#72)
Browse files Browse the repository at this point in the history
* ✨ Add create-error utility with preview and category

* ✨ Update import paths for utility functions to use cuicui package one
  • Loading branch information
damien-schneider authored Dec 30, 2024
1 parent 19f7672 commit faf4cfd
Show file tree
Hide file tree
Showing 39 changed files with 215 additions and 39 deletions.
2 changes: 1 addition & 1 deletion apps/website/src/components/coming-soon.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import GradientText from "../ui/gradient-text";
import { cn } from "../utils/cn";
import { cn } from "@/cuicui/utils/cn";

export default function ComingSoonCard() {
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";
import { type MotionProps, motion } from "motion/react";
import type React from "react";
import { cn } from "#/src/utils/cn";
import { cn } from "@/cuicui/utils/cn";
export default function AnimatedTabMotionDiv({
className,
...props
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
ScrollAreaViewport,
ScrollBar,
} from "#/src/ui/shadcn/scrollarea";
import { cn } from "#/src/utils/cn";
import { cn } from "@/cuicui/utils/cn";
import { getContainerHeightClass } from "#/src/components/component-wrapper/get-container-height-class";
import { createElement } from "react";
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { useLayoutEffect, useState, type ReactNode } from "react";
import { CustomIframe } from "#/src/components/custom-iframe-component";
import type { ComponentHeightType } from "@cuicui/ui/lib/types/component";
import { cn } from "#/src/utils/cn";
import { cn } from "@/cuicui/utils/cn";
import { getContainerHeightClass } from "#/src/components/component-wrapper/get-container-height-class";
import { RefreshCwIcon } from "lucide-react";
import { ScrollArea, ScrollAreaViewport } from "#/src/ui/shadcn/scrollarea";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as Tabs from "@radix-ui/react-tabs";
import ComponentTabRenderer from "#/src/components/component-wrapper/component-tab-renderer";

import { cn } from "#/src/utils/cn";
import { cn } from "@/cuicui/utils/cn";
import type { ComponentType } from "@cuicui/ui/lib/types/component";

export type TabType = "preview" | "code-component" | "code-preview";
Expand Down
3 changes: 2 additions & 1 deletion apps/website/src/components/custom-iframe-component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import type React from "react";
import Frame from "react-frame-component";

import type { ComponentHeightType } from "@cuicui/ui/lib/types/component";
import { cn } from "#/src/utils/cn";

import { getContainerHeightClass } from "#/src/components/component-wrapper/get-container-height-class";
import { cn } from "@/cuicui/utils/cn";

export const CustomIframe = ({
children,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"use client";
import React from "react";
import { cn } from "#/src/utils/cn";
import { cn } from "@/cuicui/utils/cn";
import { MoonIcon, SunIcon } from "lucide-react";

import { useTheme } from "next-themes";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { sectionList } from "@/section-list";
import { FloatingDock } from "#/src/components/floating-dock-navigation/floating-docks-component";
import { ArrowUpRightIcon, GithubIcon } from "lucide-react";
import { cn } from "#/src/utils/cn";
import { cn } from "@/cuicui/utils/cn";
import Link from "next/link";

import PillToggleTheme from "@/cuicui/application-ui/theme/pill-switch-theme/default.variant";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
useId,
useState,
} from "react";
import { cn } from "#/src/utils/cn";
import { cn } from "@/cuicui/utils/cn";

export type AnimatedBackgroundProps = {
children:
Expand Down
2 changes: 1 addition & 1 deletion apps/website/src/components/navigation/desktop-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import Link from "next/link";
import Image from "next/image";

import LogoLarge from "#/src/assets/logo/logo-large.png";
import { cn } from "../../utils/cn";

import Byline from "../../ui/byline";

Expand All @@ -12,6 +11,7 @@ import StarCuicuiGithubButton from "../../ui/star-github-project-button";
import { SearchMenu } from "../search-menu/search-menu";
import NavigationMenu from "./navigation-menu";
import InfoMenuList from "#/src/components/navigation/info-menu-list";
import { cn } from "@/cuicui/utils/cn";

export function DesktopSideMenu({
className,
Expand Down
2 changes: 1 addition & 1 deletion apps/website/src/components/navigation/navigation-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Link from "next/link";
import { usePathname, useSelectedLayoutSegments } from "next/navigation";
import type { AnchorHTMLAttributes, ReactNode } from "react";

import { cn } from "#/src/utils/cn";
import { cn } from "@/cuicui/utils/cn";
import type { SectionType } from "@cuicui/ui/lib/types/component";

export function GlobalNavItem({
Expand Down
2 changes: 1 addition & 1 deletion apps/website/src/components/navigation/navigation-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from "#/src/components/navigation/navigation-item";
import { sectionList } from "@/section-list";
import type { CategoryType } from "@cuicui/ui/lib/types/component";
import { cn } from "#/src/utils/cn";
import { cn } from "@/cuicui/utils/cn";

export default function NavigationMenu({
isMobile,
Expand Down
2 changes: 1 addition & 1 deletion apps/website/src/components/not-found-card.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Link from "next/link";
import GradientText from "../ui/gradient-text";
import { cn } from "../utils/cn";
import { cn } from "@/cuicui/utils/cn";

export default function NotFoundCard() {
return (
Expand Down
2 changes: 1 addition & 1 deletion apps/website/src/ui/badge.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type VariantProps, cva } from "class-variance-authority";

import type React from "react";
import { cn } from "../utils/cn";
import { cn } from "@/cuicui/utils/cn";

const badgeVariants = cva(
cn(
Expand Down
2 changes: 1 addition & 1 deletion apps/website/src/ui/button.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type VariantProps, cva } from "class-variance-authority";
import { type HTMLMotionProps, motion } from "motion/react";
import type React from "react";
import { cn } from "../utils/cn";
import { cn } from "@/cuicui/utils/cn";
import GradientContainer from "./gradient-container";
import GradientText from "./gradient-text";

Expand Down
2 changes: 0 additions & 2 deletions apps/website/src/ui/byline.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import Link from "next/link";
import { cn } from "../utils/cn";
import GradientContainer from "./gradient-container";
import {
ModernGradientContainerContent,
ModernGradientContainerRoot,
Expand Down
2 changes: 1 addition & 1 deletion apps/website/src/ui/code-command-container.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cn } from "../utils/cn";
import { cn } from "@/cuicui/utils/cn";
import CodeHighlighter from "./code-highlighter";

// import { ScrollArea, ScrollBar } from "./shadcn/scrollarea";
Expand Down
2 changes: 1 addition & 1 deletion apps/website/src/ui/code-highlighter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { HTMLAttributes } from "react";
import CopyToClipboardButton from "#/src/components/component-wrapper/copy-to-clipboard-button";
import ShikiCode from "@cuicui/ui/cuicui/application-ui/code/advanced-code-block/code-highlighter";

import { cn } from "../utils/cn";
import { cn } from "@/cuicui/utils/cn";
export default function CodeHighlighter({
code,
className,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import { CheckIcon, ClipboardIcon } from "lucide-react";
import { toast } from "sonner";
import { cn } from "../utils/cn";

import { Button } from "./shadcn/button";
import { ScrollArea, ScrollAreaViewport, ScrollBar } from "./shadcn/scrollarea";
Expand Down
2 changes: 1 addition & 1 deletion apps/website/src/ui/gradient-container.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { HTMLAttributes, ReactNode } from "react";
import { cn } from "#/src/utils/cn";
import { cn } from "@/cuicui/utils/cn";

export const GradientContainer = ({
children,
Expand Down
2 changes: 1 addition & 1 deletion apps/website/src/ui/gradient-text.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ReactNode } from "react";
import { cn } from "../utils/cn";
import { cn } from "@/cuicui/utils/cn";

export const GradientText = ({
children,
Expand Down
2 changes: 1 addition & 1 deletion apps/website/src/ui/navigation-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
useEffect,
} from "react";
import { cloneElement, isValidElement, useId, useState } from "react";
import { cn } from "../utils/cn";
import { cn } from "@/cuicui/utils/cn";

interface NavigationMenuProps extends React.HTMLAttributes<HTMLDivElement> {
children: ReactNode;
Expand Down
2 changes: 1 addition & 1 deletion apps/website/src/ui/shadcn/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Slot } from "@radix-ui/react-slot";
import { type VariantProps, cva } from "class-variance-authority";

import { type ButtonHTMLAttributes, forwardRef } from "react";
import { cn } from "#/src/utils/cn";
import { cn } from "@/cuicui/utils/cn";

const buttonVariants = cva(
cn(
Expand Down
2 changes: 1 addition & 1 deletion apps/website/src/ui/shadcn/command.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
forwardRef,
} from "react";
import { Dialog, DialogContent } from "#/src/ui/shadcn/dialog";
import { cn } from "#/src/utils/cn";
import { cn } from "@/cuicui/utils/cn";

const Command = forwardRef<
ElementRef<typeof CommandPrimitive>,
Expand Down
2 changes: 1 addition & 1 deletion apps/website/src/ui/shadcn/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
type HTMLAttributes,
forwardRef,
} from "react";
import { cn } from "#/src/utils/cn";
import { cn } from "@/cuicui/utils/cn";

const Dialog = DialogPrimitive.Root;

Expand Down
2 changes: 1 addition & 1 deletion apps/website/src/ui/shadcn/dropdown-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
type HTMLAttributes,
forwardRef,
} from "react";
import { cn } from "#/src/utils/cn";
import { cn } from "@/cuicui/utils/cn";

const DropdownMenu = DropdownMenuPrimitive.Root;

Expand Down
2 changes: 1 addition & 1 deletion apps/website/src/ui/shadcn/resizable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { GripVertical } from "lucide-react";
import type { ComponentProps } from "react";

import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels";
import { cn } from "#/src/utils/cn";
import { cn } from "@/cuicui/utils/cn";

const ResizablePanelGroup = ({
className,
Expand Down
2 changes: 1 addition & 1 deletion apps/website/src/ui/shadcn/scrollarea.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { cn } from "#/src/utils/cn";
import { cn } from "@/cuicui/utils/cn";
import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area";
import * as React from "react";

Expand Down
2 changes: 1 addition & 1 deletion apps/website/src/ui/shadcn/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
type ElementRef,
forwardRef,
} from "react";
import { cn } from "#/src/utils/cn";
import { cn } from "@/cuicui/utils/cn";

const Select = SelectPrimitive.Root;

Expand Down
2 changes: 1 addition & 1 deletion apps/website/src/ui/shadcn/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
type ElementRef,
forwardRef,
} from "react";
import { cn } from "#/src/utils/cn";
import { cn } from "@/cuicui/utils/cn";

const Tabs = TabsPrimitive.Root;

Expand Down
2 changes: 1 addition & 1 deletion apps/website/src/ui/stepper.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ReactNode } from "react";
import { cn } from "../utils/cn";
import { cn } from "@/cuicui/utils/cn";

export const StaticStep = ({
step,
Expand Down
6 changes: 0 additions & 6 deletions apps/website/src/utils/cn.ts

This file was deleted.

2 changes: 2 additions & 0 deletions packages/ui/categories-previews-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import other_cursors_preview from "./cuicui/other/cursors/preview";
import utils_catch_error_preview from "./cuicui/utils/catch-error/preview";
import utils_sleep_preview from "./cuicui/utils/sleep/preview";
import utils_cn_preview from "./cuicui/utils/cn/preview";
import utils_create_error_preview from "./cuicui/utils/create-error/preview";
import marketing_ui_statistics_preview from "./cuicui/marketing-ui/statistics/preview";
import marketing_ui_footer_preview from "./cuicui/marketing-ui/footer/preview";
import marketing_ui_carousels_preview from "./cuicui/marketing-ui/carousels/preview";
Expand Down Expand Up @@ -91,6 +92,7 @@ export const categoriesPreviewsList: Record<string, () => JSX.Element> = {
"catch-error": utils_catch_error_preview,
sleep: utils_sleep_preview,
cn: utils_cn_preview,
"create-error": utils_create_error_preview,
statistics: marketing_ui_statistics_preview,
footer: marketing_ui_footer_preview,
carousels: marketing_ui_carousels_preview,
Expand Down
11 changes: 11 additions & 0 deletions packages/ui/cuicui/utils/create-error/category.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { CategoryMetaType } from "@/lib/types/component";
import { ChevronsLeftRightEllipsisIcon } from "lucide-react";

export const Category: CategoryMetaType = {
name: "Create Error",
description: "Utilities to create normalized errors accross the application",
icon: ChevronsLeftRightEllipsisIcon,
latestUpdateDate: new Date("2024-12-30"),
};

export default Category;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { ComponentMetaType } from "@/lib/types/component";

export const Component: ComponentMetaType = {
name: "Create Error",
description: "Utilities to create normalized errors accross the application",
};

export default Component;
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"use client";
import { createError, type NormalizedError } from "@/cuicui/utils/create-error";
import { useEffect, useState } from "react";

export const PreviewCreateError = () => {
const [error, setError] = useState<NormalizedError | null>(null);
useEffect(() => {
console.log("error", error);
}, [error]);
return (
<div className="cuicui-default-style">
<button
type="button"
onClick={() => {
setError(createError("This is an error"));
}}
>
Display a simple error
</button>
<button
type="button"
onClick={() => {
setError(
createError("BAD_REQUEST", {
message: "This is a custom error",
fatal: true,
}),
);
}}
>
Display an error with a custom message
</button>
<p>Error message: {error?.message}</p>
<pre>{JSON.stringify(error, null, 2)}</pre>
</div>
);
};

export default PreviewCreateError;
Loading

0 comments on commit faf4cfd

Please sign in to comment.