Skip to content

Commit

Permalink
docs(www): add fonts docs (shadcn-ui#1752)
Browse files Browse the repository at this point in the history
  • Loading branch information
shadcn authored Oct 15, 2023
1 parent 271fb87 commit 416c4a4
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
53 changes: 53 additions & 0 deletions content/docs/installation/next.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,59 @@ Configure the import alias for utils: › @/lib/utils
Are you using React Server Components? › no / yes
```

### Fonts

I use [Inter](https://rsms.me/inter/) as the default font. Inter is not required. You can replace it with any other font.

Here's how I configure Inter for Next.js:

**1. Import the font in the root layout:**

```js showLineNumbers title=app/layout.tsx {2,4-7,15-16}
import "@/styles/globals.css"
import { Inter as FontSans } from "next/font/google"

export const fontSans = FontSans({
subsets: ["latin"],
variable: "--font-sans",
})

export default function RootLayout({ children }: RootLayoutProps) {
return (
<html lang="en" suppressHydrationWarning>
<head />
<body
className={cn(
"min-h-screen bg-background font-sans antialiased",
fontSans.variable
)}
>
...
</body>
</html>
)
}
```

**2. Configure `theme.extend.fontFamily` in `tailwind.config.js`**

```js showLineNumbers title=tailwind.config.js {9-11}
const { fontFamily } = require("tailwindcss/defaultTheme")

/** @type {import('tailwindcss').Config} */
module.exports = {
darkMode: ["class"],
content: ["app/**/*.{ts,tsx}", "components/**/*.{ts,tsx}"],
theme: {
extend: {
fontFamily: {
sans: ["var(--font-sans)", ...fontFamily.sans],
},
},
},
}
```

### App structure

Here's how I structure my Next.js apps. You can use this as a reference:
Expand Down
3 changes: 3 additions & 0 deletions registry/default/ui/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const DialogTrigger = DialogPrimitive.Trigger

const DialogPortal = DialogPrimitive.Portal

const DialogClose = DialogPrimitive.Close

const DialogOverlay = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Overlay>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
Expand Down Expand Up @@ -110,6 +112,7 @@ export {
Dialog,
DialogPortal,
DialogOverlay,
DialogClose,
DialogTrigger,
DialogContent,
DialogHeader,
Expand Down
3 changes: 3 additions & 0 deletions registry/new-york/ui/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const DialogTrigger = DialogPrimitive.Trigger

const DialogPortal = DialogPrimitive.Portal

const DialogClose = DialogPrimitive.Close

const DialogOverlay = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Overlay>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
Expand Down Expand Up @@ -111,6 +113,7 @@ export {
DialogPortal,
DialogOverlay,
DialogTrigger,
DialogClose,
DialogContent,
DialogHeader,
DialogFooter,
Expand Down

0 comments on commit 416c4a4

Please sign in to comment.