Skip to content

Commit

Permalink
templates: fix issue with shadcn utilities alias across website templ…
Browse files Browse the repository at this point in the history
…ate and localization example (payloadcms#10507)

Fixes the utilities alias used by shadcn to a specific file renamed to
`ui.ts` from `cn.ts` since there may be other utilities installed by
shadcn depending on the components the user installs.

Co-Authored-By: Q.Tran <[email protected]>
  • Loading branch information
paulpopus and tranlehaiquan authored Jan 10, 2025
1 parent fd96a9a commit d20dc58
Show file tree
Hide file tree
Showing 72 changed files with 102 additions and 84 deletions.
2 changes: 1 addition & 1 deletion examples/localization/components.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
},
"aliases": {
"components": "@/components",
"utils": "@/utilities"
"utils": "@/utilities/ui"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Metadata } from 'next'

import { cn } from 'src/utilities/cn'
import { cn } from '@/utilities/ui'
import { GeistMono } from 'geist/font/mono'
import { GeistSans } from 'geist/font/sans'
import React from 'react'
Expand Down
2 changes: 1 addition & 1 deletion examples/localization/src/blocks/Banner/Component.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { BannerBlock as BannerBlockProps } from 'src/payload-types'

import { cn } from 'src/utilities/cn'
import { cn } from '@/utilities/ui'
import React from 'react'
import RichText from '@/components/RichText'

Expand Down
2 changes: 1 addition & 1 deletion examples/localization/src/blocks/Content/Component.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cn } from 'src/utilities/cn'
import { cn } from '@/utilities/ui'
import React from 'react'
import RichText from '@/components/RichText'

Expand Down
2 changes: 1 addition & 1 deletion examples/localization/src/blocks/MediaBlock/Component.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { StaticImageData } from 'next/image'

import { cn } from 'src/utilities/cn'
import { cn } from '@/utilities/ui'
import React from 'react'
import RichText from '@/components/RichText'

Expand Down
2 changes: 1 addition & 1 deletion examples/localization/src/blocks/RenderBlocks.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cn } from 'src/utilities/cn'
import { cn } from '@/utilities/ui'
import React, { Fragment } from 'react'

import type { Page } from '@/payload-types'
Expand Down
2 changes: 1 addition & 1 deletion examples/localization/src/components/AdminBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import type { PayloadAdminBarProps } from 'payload-admin-bar'

import { cn } from '@/utilities/cn'
import { cn } from '@/utilities/ui'
import { useSelectedLayoutSegments } from 'next/navigation'
import { PayloadAdminBar } from 'payload-admin-bar'
import React, { useState } from 'react'
Expand Down
2 changes: 1 addition & 1 deletion examples/localization/src/components/Card/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use client'
import { cn } from '@/utilities/cn'
import { cn } from '@/utilities/ui'
import useClickableCard from '@/utilities/useClickableCard'
import Link from 'next/link'
import React, { Fragment } from 'react'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cn } from 'src/utilities/cn'
import { cn } from '@/utilities/ui'
import React from 'react'

import type { Post } from '@/payload-types'
Expand Down
2 changes: 1 addition & 1 deletion examples/localization/src/components/Link/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Button, type ButtonProps } from '@/components/ui/button'
import { cn } from 'src/utilities/cn'
import { cn } from '@/utilities/ui'
import { Link as i18nLink } from '@/i18n/routing'
import React from 'react'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import type { StaticImageData } from 'next/image'

import { cn } from 'src/utilities/cn'
import { cn } from '@/utilities/ui'
import NextImage from 'next/image'
import React from 'react'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client'

import { cn } from 'src/utilities/cn'
import { cn } from '@/utilities/ui'
import React, { useEffect, useRef } from 'react'

import type { Props as MediaProps } from '../types'
Expand Down
2 changes: 1 addition & 1 deletion examples/localization/src/components/Pagination/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
PaginationNext,
PaginationPrevious,
} from '@/components/ui/pagination'
import { cn } from '@/utilities/cn'
import { cn } from '@/utilities/ui'
import { useRouter } from 'next/navigation'
import React from 'react'

Expand Down
2 changes: 1 addition & 1 deletion examples/localization/src/components/RichText/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cn } from '@/utilities/cn'
import { cn } from '@/utilities/ui'
import React from 'react'

import { serializeLexical } from './serialize'
Expand Down
2 changes: 1 addition & 1 deletion examples/localization/src/components/ui/button.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cn } from 'src/utilities/cn'
import { cn } from '@/utilities/ui'
import { Slot } from '@radix-ui/react-slot'
import { type VariantProps, cva } from 'class-variance-authority'
import * as React from 'react'
Expand Down
2 changes: 1 addition & 1 deletion examples/localization/src/components/ui/card.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cn } from 'src/utilities/cn'
import { cn } from '@/utilities/ui'
import * as React from 'react'

const Card: React.FC<
Expand Down
2 changes: 1 addition & 1 deletion examples/localization/src/components/ui/checkbox.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client'

import { cn } from 'src/utilities/cn'
import { cn } from '@/utilities/ui'
import * as CheckboxPrimitive from '@radix-ui/react-checkbox'
import { Check } from 'lucide-react'
import * as React from 'react'
Expand Down
2 changes: 1 addition & 1 deletion examples/localization/src/components/ui/input.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cn } from 'src/utilities/cn'
import { cn } from '@/utilities/ui'
import * as React from 'react'

const Input: React.FC<
Expand Down
2 changes: 1 addition & 1 deletion examples/localization/src/components/ui/label.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client'

import { cn } from 'src/utilities/cn'
import { cn } from '@/utilities/ui'
import * as LabelPrimitive from '@radix-ui/react-label'
import { type VariantProps, cva } from 'class-variance-authority'
import * as React from 'react'
Expand Down
2 changes: 1 addition & 1 deletion examples/localization/src/components/ui/pagination.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ButtonProps } from '@/components/ui/button'

import { buttonVariants } from '@/components/ui/button'
import { cn } from 'src/utilities/cn'
import { cn } from '@/utilities/ui'
import { ChevronLeft, ChevronRight, MoreHorizontal } from 'lucide-react'
import * as React from 'react'

Expand Down
2 changes: 1 addition & 1 deletion examples/localization/src/components/ui/select.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client'

import { cn } from 'src/utilities/cn'
import { cn } from '@/utilities/ui'
import * as SelectPrimitive from '@radix-ui/react-select'
import { Check, ChevronDown, ChevronUp } from 'lucide-react'
import * as React from 'react'
Expand Down
2 changes: 1 addition & 1 deletion examples/localization/src/components/ui/textarea.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cn } from 'src/utilities/cn'
import { cn } from '@/utilities/ui'
import * as React from 'react'

const Textarea: React.FC<
Expand Down
6 changes: 0 additions & 6 deletions examples/localization/src/utilities/cn.ts

This file was deleted.

12 changes: 12 additions & 0 deletions examples/localization/src/utilities/ui.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Utility functions for UI components automatically added by ShadCN and used in a few of our frontend components and blocks.
*
* Other functions may be exported from here in the future or by installing other shadcn components.
*/

import { type ClassValue, clsx } from 'clsx'
import { twMerge } from 'tailwind-merge'

export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
2 changes: 1 addition & 1 deletion templates/website/components.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
},
"aliases": {
"components": "@/components",
"utils": "@/utilities"
"utils": "@/utilities/ui"
}
}
2 changes: 1 addition & 1 deletion templates/website/src/app/(frontend)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Metadata } from 'next'

import { cn } from 'src/utilities/cn'
import { cn } from '@/utilities/ui'
import { GeistMono } from 'geist/font/mono'
import { GeistSans } from 'geist/font/sans'
import React from 'react'
Expand Down
2 changes: 1 addition & 1 deletion templates/website/src/blocks/Banner/Component.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { BannerBlock as BannerBlockProps } from 'src/payload-types'

import { cn } from 'src/utilities/cn'
import { cn } from '@/utilities/ui'
import React from 'react'
import RichText from '@/components/RichText'

Expand Down
2 changes: 1 addition & 1 deletion templates/website/src/blocks/Content/Component.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cn } from 'src/utilities/cn'
import { cn } from '@/utilities/ui'
import React from 'react'
import RichText from '@/components/RichText'

Expand Down
2 changes: 1 addition & 1 deletion templates/website/src/blocks/MediaBlock/Component.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { StaticImageData } from 'next/image'

import { cn } from 'src/utilities/cn'
import { cn } from '@/utilities/ui'
import React from 'react'
import RichText from '@/components/RichText'

Expand Down
2 changes: 1 addition & 1 deletion templates/website/src/blocks/RenderBlocks.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cn } from 'src/utilities/cn'
import { cn } from '@/utilities/ui'
import React, { Fragment } from 'react'

import type { Page } from '@/payload-types'
Expand Down
2 changes: 1 addition & 1 deletion templates/website/src/components/AdminBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import type { PayloadAdminBarProps } from 'payload-admin-bar'

import { cn } from '@/utilities/cn'
import { cn } from '@/utilities/ui'
import { useSelectedLayoutSegments } from 'next/navigation'
import { PayloadAdminBar } from 'payload-admin-bar'
import React, { useState } from 'react'
Expand Down
2 changes: 1 addition & 1 deletion templates/website/src/components/Card/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use client'
import { cn } from '@/utilities/cn'
import { cn } from '@/utilities/ui'
import useClickableCard from '@/utilities/useClickableCard'
import Link from 'next/link'
import React, { Fragment } from 'react'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cn } from 'src/utilities/cn'
import { cn } from '@/utilities/ui'
import React from 'react'

import type { Post } from '@/payload-types'
Expand Down
2 changes: 1 addition & 1 deletion templates/website/src/components/Link/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Button, type ButtonProps } from '@/components/ui/button'
import { cn } from 'src/utilities/cn'
import { cn } from '@/utilities/ui'
import Link from 'next/link'
import React from 'react'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import type { StaticImageData } from 'next/image'

import { cn } from 'src/utilities/cn'
import { cn } from '@/utilities/ui'
import NextImage from 'next/image'
import React from 'react'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client'

import { cn } from 'src/utilities/cn'
import { cn } from '@/utilities/ui'
import React, { useEffect, useRef } from 'react'

import type { Props as MediaProps } from '../types'
Expand Down
2 changes: 1 addition & 1 deletion templates/website/src/components/Pagination/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
PaginationNext,
PaginationPrevious,
} from '@/components/ui/pagination'
import { cn } from '@/utilities/cn'
import { cn } from '@/utilities/ui'
import { useRouter } from 'next/navigation'
import React from 'react'

Expand Down
2 changes: 1 addition & 1 deletion templates/website/src/components/RichText/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type {
} from '@/payload-types'
import { BannerBlock } from '@/blocks/Banner/Component'
import { CallToActionBlock } from '@/blocks/CallToAction/Component'
import { cn } from '@/utilities/cn'
import { cn } from '@/utilities/ui'

type NodeTypes =
| DefaultNodeTypes
Expand Down
2 changes: 1 addition & 1 deletion templates/website/src/components/ui/button.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cn } from 'src/utilities/cn'
import { cn } from '@/utilities/ui'
import { Slot } from '@radix-ui/react-slot'
import { type VariantProps, cva } from 'class-variance-authority'
import * as React from 'react'
Expand Down
2 changes: 1 addition & 1 deletion templates/website/src/components/ui/card.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cn } from 'src/utilities/cn'
import { cn } from '@/utilities/ui'
import * as React from 'react'

const Card: React.FC<
Expand Down
2 changes: 1 addition & 1 deletion templates/website/src/components/ui/checkbox.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client'

import { cn } from 'src/utilities/cn'
import { cn } from '@/utilities/ui'
import * as CheckboxPrimitive from '@radix-ui/react-checkbox'
import { Check } from 'lucide-react'
import * as React from 'react'
Expand Down
2 changes: 1 addition & 1 deletion templates/website/src/components/ui/input.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cn } from 'src/utilities/cn'
import { cn } from '@/utilities/ui'
import * as React from 'react'

const Input: React.FC<
Expand Down
2 changes: 1 addition & 1 deletion templates/website/src/components/ui/label.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client'

import { cn } from 'src/utilities/cn'
import { cn } from '@/utilities/ui'
import * as LabelPrimitive from '@radix-ui/react-label'
import { type VariantProps, cva } from 'class-variance-authority'
import * as React from 'react'
Expand Down
2 changes: 1 addition & 1 deletion templates/website/src/components/ui/pagination.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ButtonProps } from '@/components/ui/button'

import { buttonVariants } from '@/components/ui/button'
import { cn } from 'src/utilities/cn'
import { cn } from '@/utilities/ui'
import { ChevronLeft, ChevronRight, MoreHorizontal } from 'lucide-react'
import * as React from 'react'

Expand Down
2 changes: 1 addition & 1 deletion templates/website/src/components/ui/select.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client'

import { cn } from 'src/utilities/cn'
import { cn } from '@/utilities/ui'
import * as SelectPrimitive from '@radix-ui/react-select'
import { Check, ChevronDown, ChevronUp } from 'lucide-react'
import * as React from 'react'
Expand Down
2 changes: 1 addition & 1 deletion templates/website/src/components/ui/textarea.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cn } from 'src/utilities/cn'
import { cn } from '@/utilities/ui'
import * as React from 'react'

const Textarea: React.FC<
Expand Down
6 changes: 0 additions & 6 deletions templates/website/src/utilities/cn.ts

This file was deleted.

12 changes: 12 additions & 0 deletions templates/website/src/utilities/ui.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Utility functions for UI components automatically added by ShadCN and used in a few of our frontend components and blocks.
*
* Other functions may be exported from here in the future or by installing other shadcn components.
*/

import { type ClassValue, clsx } from 'clsx'
import { twMerge } from 'tailwind-merge'

export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
2 changes: 1 addition & 1 deletion templates/with-vercel-website/components.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
},
"aliases": {
"components": "@/components",
"utils": "@/utilities"
"utils": "@/utilities/ui"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Metadata } from 'next'

import { cn } from 'src/utilities/cn'
import { cn } from '@/utilities/ui'
import { GeistMono } from 'geist/font/mono'
import { GeistSans } from 'geist/font/sans'
import React from 'react'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { BannerBlock as BannerBlockProps } from 'src/payload-types'

import { cn } from 'src/utilities/cn'
import { cn } from '@/utilities/ui'
import React from 'react'
import RichText from '@/components/RichText'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cn } from 'src/utilities/cn'
import { cn } from '@/utilities/ui'
import React from 'react'
import RichText from '@/components/RichText'

Expand Down
Loading

0 comments on commit d20dc58

Please sign in to comment.