Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(examples): add Radix UI example #41169

Merged
merged 14 commits into from Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 33 additions & 0 deletions examples/radix-ui/.gitignore
@@ -0,0 +1,33 @@
# 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*
.pnpm-debug.log*

# Local env files
.env.local
.env.development.local
.env.test.local
.env.production.local
balazsorban44 marked this conversation as resolved.
Show resolved Hide resolved

# Vercel
.vercel
balazsorban44 marked this conversation as resolved.
Show resolved Hide resolved
27 changes: 27 additions & 0 deletions examples/radix-ui/README.md
@@ -0,0 +1,27 @@
# Radix-ui Example

This example showcases a few basic Radix-UI components

## 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/git/external?repository-url=https://github.com/vercel/next.js/tree/canary/examples/radix-ui&project-name=radix-ui&repository-name=radix-ui)

## 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/), or [pnpm](https://pnpm.io) to bootstrap the example:

```bash
npx create-next-app --example radix-ui radix-ui-app
```

```bash
yarn create next-app --example radix-ui radix-ui-app
```

```bash
pnpm create next-app --example radix-ui radix-ui-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)).
5 changes: 5 additions & 0 deletions examples/radix-ui/next-env.d.ts
@@ -0,0 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
23 changes: 23 additions & 0 deletions examples/radix-ui/package.json
@@ -0,0 +1,23 @@
{
"scripts": {
balazsorban44 marked this conversation as resolved.
Show resolved Hide resolved
"dev": "next dev",
"build": "next build",
"start": "next start"
},
"dependencies": {
"@radix-ui/react-dropdown-menu": "1.0.0",
"@radix-ui/react-icons": "1.1.1",
"next": "latest",
"react": "latest",
"react-dom": "latest"
},
"devDependencies": {
"@types/node": "18.8.0",
"@types/react": "18.0.21",
"autoprefixer": "10.4.12",
"eslint": "8.24.0",
balazsorban44 marked this conversation as resolved.
Show resolved Hide resolved
"postcss": "8.4.17",
"tailwindcss": "3.1.8",
"typescript": "4.8.4"
}
}
6 changes: 6 additions & 0 deletions examples/radix-ui/postcss.config.js
@@ -0,0 +1,6 @@
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
5 changes: 5 additions & 0 deletions examples/radix-ui/src/pages/_app.tsx
@@ -0,0 +1,5 @@
import '../styles/styles.css'

export default function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />
}
175 changes: 175 additions & 0 deletions examples/radix-ui/src/pages/index.tsx
@@ -0,0 +1,175 @@
import { useState } from 'react'
import {
HamburgerMenuIcon,
DotFilledIcon,
CheckIcon,
ChevronRightIcon,
} from '@radix-ui/react-icons'
import * as DropdownMenu from '@radix-ui/react-dropdown-menu'

function RightSlot({ children }) {
return (
<div className="ml-auto pl-4 text-gray-500 group-hover:text-gray-200">
{children}
</div>
)
}

function DropdownMenuItem({ children, ...props }) {
return (
<DropdownMenu.Item
{...props}
className={
'group bg-white hover:bg-gray-700 hover:text-gray-200 text-xs rounded flex items-center h-6 px-1 pl-6 relative select-none' +
(props.disabled ? ' text-gray-500' : '')
}
>
{children}
</DropdownMenu.Item>
)
}

function DropdownMenuCheckboxItem({ children, ...props }) {
return (
<DropdownMenu.CheckboxItem
{...props}
className="group bg-white hover:bg-gray-700 hover:text-gray-200 text-xs rounded flex items-center h-6 px-1 pl-6 relative select-none"
>
{children}
</DropdownMenu.CheckboxItem>
)
}

function DropdownMenuItemIndicator({ children, ...props }) {
return (
<DropdownMenu.ItemIndicator
{...props}
className="absolute left-0 w-6 inline-flex items-center justify-center"
>
{children}
</DropdownMenu.ItemIndicator>
)
}

function Separator() {
return <DropdownMenu.Separator className="h-[1px] bg-gray-300 m-1" />
}

function DropdownMenuRadioItem({
children,
...props
}: {
children: React.ReactNode
value: string
}) {
return (
<DropdownMenu.RadioItem
{...props}
className="bg-white hover:bg-gray-700 hover:text-gray-200 text-xs rounded flex items-center h-6 px-1 pl-6 relative select-none"
>
{children}
</DropdownMenu.RadioItem>
)
}

export default function Home() {
const [bookmarksChecked, setBookmarksChecked] = useState(true)
const [urlsChecked, setUrlsChecked] = useState(false)
const [person, setPerson] = useState('pedro')
return (
<div className="h-screen w-full flex flex-col space-y-4 items-center justify-center bg-gradient-to-r from-cyan-500 to-blue-500">
<h1 className="text-6xl text-white font-semibold">
Radix-UI + Tailwindcss
</h1>
<h1 className="text-4xl text-white font-semibold">Click me!</h1>

<DropdownMenu.Root>
<DropdownMenu.Trigger
asChild
className="bg-white text-xs rounded-3xl flex items-center h-8 px-2 relative select-none"
>
<button
aria-label="Customise options"
className="h-8 w-8 inline-flex items-center justify-center shadow-lg"
>
<HamburgerMenuIcon />
</button>
</DropdownMenu.Trigger>

<DropdownMenu.Content
sideOffset={5}
className="bg-white rounded p-1 shadow-lg"
>
<DropdownMenuItem>
New Tab <RightSlot>⌘+T</RightSlot>
</DropdownMenuItem>
<DropdownMenuItem>
New Window <RightSlot>⌘+N</RightSlot>
</DropdownMenuItem>
<DropdownMenuItem disabled>
New Private Window <RightSlot>⇧+⌘+N</RightSlot>
</DropdownMenuItem>
<DropdownMenu.Sub>
<DropdownMenu.SubTrigger className="group bg-white hover:bg-gray-700 hover:text-gray-200 hover:border-0 text-xs rounded flex items-center h-6 px-1 pl-6 relative select-none">
More Tools
<RightSlot>
<ChevronRightIcon />
</RightSlot>
</DropdownMenu.SubTrigger>
<DropdownMenu.SubContent
sideOffset={2}
alignOffset={-5}
className="bg-white rounded p-1 shadow-lg"
>
<DropdownMenuItem>
Save Page As… <RightSlot>⌘+S</RightSlot>
</DropdownMenuItem>
<DropdownMenuItem>Create Shortcut…</DropdownMenuItem>
<DropdownMenuItem>Name Window…</DropdownMenuItem>
<Separator />
<DropdownMenuItem>Developer Tools</DropdownMenuItem>
</DropdownMenu.SubContent>
</DropdownMenu.Sub>
<Separator />
<DropdownMenuCheckboxItem
checked={bookmarksChecked}
onCheckedChange={setBookmarksChecked}
>
<DropdownMenuItemIndicator>
<CheckIcon />
</DropdownMenuItemIndicator>
Show Bookmarks <RightSlot>⌘+B</RightSlot>
</DropdownMenuCheckboxItem>
<DropdownMenuCheckboxItem
checked={urlsChecked}
onCheckedChange={setUrlsChecked}
>
<DropdownMenuItemIndicator>
<CheckIcon />
</DropdownMenuItemIndicator>
Show Full URLs
</DropdownMenuCheckboxItem>
<Separator />
<DropdownMenu.Label className="pl-6 leading-6 text-xs text-gray-700">
Contributors
</DropdownMenu.Label>

<DropdownMenu.RadioGroup value={person} onValueChange={setPerson}>
<DropdownMenuRadioItem value="pedro">
<DropdownMenuItemIndicator>
<DotFilledIcon />
</DropdownMenuItemIndicator>
Pedro Sanchez
</DropdownMenuRadioItem>
<DropdownMenuRadioItem value="pablo">
<DropdownMenuItemIndicator>
<DotFilledIcon />
</DropdownMenuItemIndicator>
Pablo Sanchez
</DropdownMenuRadioItem>
</DropdownMenu.RadioGroup>
</DropdownMenu.Content>
</DropdownMenu.Root>
</div>
)
}
3 changes: 3 additions & 0 deletions examples/radix-ui/src/styles/styles.css
@@ -0,0 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
8 changes: 8 additions & 0 deletions examples/radix-ui/tailwind.config.js
@@ -0,0 +1,8 @@
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ['./src/pages/**/*.{js,ts,jsx,tsx}'],
theme: {
extend: {},
},
plugins: [],
}
20 changes: 20 additions & 0 deletions examples/radix-ui/tsconfig.json
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"incremental": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve"
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}