Unverified Commit 7102e297 authored by Frederik von Sperling's avatar Frederik von Sperling Committed by GitHub

example: panda css (#55004)

# Panda CSS example
This example contains a simple implementation of [Panda CSS](https://panda-css.com/). It contains styling for a link made in four different approaches supported by Panda CSS. Refer to the [documentation](https://panda-css.com/docs) for when to use - and how to combine - the different approaches to suit your needs.

## Link examples
-  [Atomic Recipe (CVA)](https://panda-css.com/docs/concepts/recipes#atomic-recipe-or-cva) Create multi-variant atomic styles with a type-safe runtime API.
- [Atomic Style](https://panda-css.com/docs/concepts/writing-styles#atomic-styles) Type-safe reusable atoms with small CSS footprint.
- [Config Recipe](https://panda-css.com/docs/concepts/recipes#config-recipe) Resuable recipes extracted and generated just-in-time.
- [Text Styles](https://panda-css.com/docs/theming/text-styles#defining-text-styles) Global text styles for consistent and legible typography.

## Preview
Preview the example live on [https://example-panda-css.vercel.app/](https://example-panda-css.vercel.app/)

## Motivation
Panda CSS is a CSS-in-JS framework, that support the new era of server components and the rise of the app-directory in Next.js. It is a performant, type-safe, developer friendly framework, which uses modern CSS features. It is heavily inspired by existing frameworks, such as Chakra UI, Vanilla Extract, Stitches and Tailwind.

More on [why you should choose Panda CSS](https://panda-css.com/docs/overview/why-panda)
parent 4a6319cd
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# next.js
/.next/
/out/
# production
/build
# misc
.DS_Store
*.pem
# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# local env files
.env*.local
# vercel
.vercel
# typescript
*.tsbuildinfo
next-env.d.ts
# Panda CSS artifacts
/styled-system
\ No newline at end of file
# Panda CSS Example
This example contains a simple implementation of [Panda CSS](https://panda-css.com/). It contains styling for a link made in four different approaches supported by Panda CSS. Refer to the [documentation](https://panda-css.com/docs) for when to use - and how to combine - the different approaches to suit your needs.
## Link examples
- [Atomic Recipe (CVA)](https://panda-css.com/docs/concepts/recipes#atomic-recipe-or-cva) Create multi-variant atomic styles with a type-safe runtime API.
- [Atomic Style](https://panda-css.com/docs/concepts/writing-styles#atomic-styles) Type-safe reusable atoms with small CSS footprint.
- [Config Recipe](https://panda-css.com/docs/concepts/recipes#config-recipe) Resuable recipes extracted and generated just-in-time.
- [Text Styles](https://panda-css.com/docs/theming/text-styles#defining-text-styles) Global text styles for consistent and legible typography.
## Deploy your own
Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example):
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/vercel/next.js/tree/canary/examples/DIRECTORY_NAME&project-name=DIRECTORY_NAME&repository-name=DIRECTORY_NAME)
## Preview
Preview the example live on [https://example-panda-css.vercel.app/](https://example-panda-css.vercel.app/)
## How to use
Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init), [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/), [pnpm](https://pnpm.io), or [Bun](https://bun.sh/docs/cli/bunx) to bootstrap the example:
```bash
npx create-next-app --example panda-css panda-css-app
```
```bash
yarn create next-app --example panda-css panda-css-app
```
```bash
pnpm create next-app --example panda-css panda-css-app
```
```bash
bunx create-next-app --example panda-css panda-css-app
```
Deploy it to the cloud with [Vercel](https://vercel.com/new?utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)).
import { cva } from '@/styled-system/css'
const styles = cva({
base: {
color: {
_default: 'gray.800',
_osDark: 'gray.100',
},
fontFamily: 'inter',
},
variants: {
size: {
sm: { fontSize: 'sm' },
lg: { fontSize: 'lg' },
},
},
defaultVariants: {
size: 'lg',
},
})
/**
* Link with atomic recipe
* @see https://panda-css.com/docs/concepts/recipes#atomic-recipe-or-cva
*/
export default function LinkWithAtomicRecipe() {
return (
<a
className={styles({ size: 'lg' })}
href="https://panda-css.com/docs/concepts/recipes#atomic-recipe-or-cva"
target="_blank"
rel="noreferrer"
>
Link with <b>atomic recipe</b>
<span className="icon">-&gt;</span>
</a>
)
}
import { css } from '@/styled-system/css'
const styles = css({
fontSize: 'lg',
color: {
_default: 'gray.800',
_osDark: 'gray.100',
},
fontFamily: 'inter',
})
/**
* Link with atomic styles
* @see https://panda-css.com/docs/concepts/writing-styles#atomic-styles
*/
export default function LinkWithAtomicStyle() {
return (
<a
className={styles}
href="https://panda-css.com/docs/concepts/writing-styles#atomic-styles"
target="_blank"
rel="noreferrer"
>
Link with <b>atomic style</b>
<span className="icon">-&gt;</span>
</a>
)
}
import { link } from '@/styled-system/recipes'
/**
* Link with config recipe
* @see https://panda-css.com/docs/concepts/recipes#config-recipe
*/
export default function LinkWithConfigRecipe() {
return (
<a
className={link({ size: 'lg' })}
href="https://panda-css.com/docs/concepts/recipes#config-recipe"
target="_blank"
rel="noreferrer"
>
Link with <b>config recipe</b>
<span className="icon">-&gt;</span>
</a>
)
}
import { css } from '@/styled-system/css'
const styles = css({
textStyle: 'link',
color: {
_default: 'gray.800',
_osDark: 'gray.100',
},
})
/**
* Link with text styles
* @see https://panda-css.com/docs/theming/text-styles#defining-text-styles
*/
export default function LinkWithTextStyles() {
return (
<a
className={styles}
href="https://panda-css.com/docs/theming/text-styles#defining-text-styles"
target="_blank"
rel="noreferrer"
>
Link with <b>text styles</b>
<span className="icon">-&gt;</span>
</a>
)
}
/* https://panda-css.com/docs/installation/nextjs#configure-the-entry-css-with-layers */
@layer reset, base, tokens, recipes, utilities;
import './global.css'
import type { Metadata } from 'next'
import { Inter } from 'next/font/google'
// https://panda-css.com/docs/guides/fonts#setup
const InterFont = Inter({
weight: ['400', '500', '700'],
display: 'swap',
subsets: ['latin'],
variable: '--font-inter',
})
export const metadata: Metadata = {
title: 'Create Next App with Panda CSS',
description: 'Generated by create next app',
}
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en" className={`${InterFont.variable}`}>
<body>{children}</body>
</html>
)
}
import { css } from '@/styled-system/css'
import LinkWithAtomicStyle from '@/app/components/link-with-atomic-style'
import LinkWithAtomicRecipe from '@/app/components/link-with-atomic-recipe'
import LinkWithConfigRecipe from '@/app/components/link-with-config-recipe'
import LinkWithTextStyles from '@/app/components/link-with-text-styles'
const styles = css({
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
gap: '2rem',
p: '6rem',
minH: '100vh',
})
export default function Home() {
return (
<main className={styles}>
<LinkWithAtomicStyle />
<LinkWithAtomicRecipe />
<LinkWithConfigRecipe />
<LinkWithTextStyles />
</main>
)
}
/** @type {import('next').NextConfig} */
const nextConfig = {}
module.exports = nextConfig
{
"private": true,
"scripts": {
"prepare": "panda codegen",
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"next": "latest",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@pandacss/dev": "^0.15.1",
"@types/node": "^20.7.0",
"@types/react": "^18.2.22",
"@types/react-dom": "^18.2.7",
"typescript": "^5.2.2"
}
}
import {
defineConfig,
defineGlobalStyles,
defineRecipe,
defineTextStyles,
} from '@pandacss/dev'
// https://panda-css.com/docs/theming/text-styles#defining-text-styles
export const textStyles = defineTextStyles({
link: {
description: 'The classic link text style - used in demo links',
value: {
fontSize: 'lg',
fontFamily: 'inter',
},
},
})
// https://panda-css.com/docs/concepts/recipes#config-recipe
export const linkRecipe = defineRecipe({
className: 'link',
description: 'The styles for the link component',
base: {
color: {
_default: 'gray.800',
_osDark: 'gray.100',
},
fontFamily: 'inter',
},
variants: {
size: {
sm: { fontSize: 'sm' },
lg: { fontSize: 'lg' },
},
},
defaultVariants: {
size: 'lg',
},
})
// https://panda-css.com/docs/concepts/writing-styles#global-styles
const globalCss = defineGlobalStyles({
html: {
bg: {
_default: 'white',
_osDark: 'black',
},
'& .icon': {
ml: 2,
fontSize: 'lg',
fontWeight: 700,
},
},
})
// https://panda-css.com/docs/references/config
export default defineConfig({
// Whether to use css reset
preflight: true,
// Where to look for your css declarations
include: ['./app/**/*.{js,jsx,ts,tsx}'],
// Files to exclude
exclude: [],
// Useful for theme customization
theme: {
extend: {
tokens: {
fonts: {
inter: { value: 'var(--font-inter)' },
},
},
recipes: {
link: linkRecipe,
},
textStyles,
},
},
// The output directory for your css system
outdir: 'styled-system',
// Global styles
globalCss,
})
module.exports = {
plugins: {
'@pandacss/dev/postcss': {},
},
}
{
"compilerOptions": {
"target": "es6",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "ESNext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./*"]
}
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts",
"styled-system"
],
"exclude": ["node_modules"]
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment