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

Add Shadcn-ui example #488

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions examples/with-shadcn-ui/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<p align="center"><img src="https://i.imgur.com/a9QWW0v.png"></p>

## Usage

### Create an App

```
# with npx
$ npx create-nextron-app my-app --example with-tailwindcss

# with yarn
$ yarn create nextron-app my-app --example with-tailwindcss

# with pnpm
$ pnpm dlx create-nextron-app my-app --example with-tailwindcss
```

### Install Dependencies

```
$ cd my-app

# using yarn or npm
$ yarn (or `npm install`)

# using pnpm
$ pnpm install --shamefully-hoist
```

### Use it

```
# development mode
$ yarn dev (or `npm run dev` or `pnpm run dev`)

# production build
$ yarn build (or `npm run build` or `pnpm run build`)
```
17 changes: 17 additions & 0 deletions examples/with-shadcn-ui/components.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "default",
"rsc": true,
"tsx": true,
"tailwind": {
"config": "@/tailwind.config.js",
"css": "@/styles/globals.css",
"baseColor": "slate",
"cssVariables": true,
"prefix": ""
},
"aliases": {
"components": "@/components",
"utils": "@/lib/utils"
}
}
12 changes: 12 additions & 0 deletions examples/with-shadcn-ui/electron-builder.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
appId: com.example.nextron
productName: My Nextron App
copyright: Copyright © 2018 Yoshihide Shiono
directories:
output: dist
buildResources: resources
files:
- from: .
filter:
- package.json
- app
publish: null
37 changes: 37 additions & 0 deletions examples/with-shadcn-ui/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"private": true,
"name": "my-nextron-app",
"description": "My application description",
"version": "1.0.0",
"author": "Yoshihide Shiono <shiono.yoshihide@gmail.com>",
"main": "app/background.js",
"scripts": {
"dev": "nextron",
"build": "nextron build",
"postinstall": "electron-builder install-app-deps"
},
"dependencies": {
"@radix-ui/react-slot": "^1.1.0",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"electron-serve": "^1.3.0",
"electron-store": "^8.2.0",
"lucide-react": "^0.428.0",
"tailwind-merge": "^2.5.2",
"tailwindcss-animate": "^1.0.7"
},
"devDependencies": {
"@types/node": "^20.11.16",
"@types/react": "^18.2.52",
"autoprefixer": "^10.4.19",
"electron": "^31.0.1",
"electron-builder": "^24.13.3",
"next": "^14.2.4",
"nextron": "^9.1.0",
"postcss": "^8.4.38",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"tailwindcss": "^3.4.3",
"typescript": "^5.4.5"
}
}
56 changes: 56 additions & 0 deletions examples/with-shadcn-ui/renderer/components/ui/button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import * as React from "react"
import { Slot } from "@radix-ui/react-slot"
import { cva, type VariantProps } from "class-variance-authority"

import { cn } from "@/lib/utils"

const buttonVariants = cva(
"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
{
variants: {
variant: {
default: "bg-primary text-primary-foreground hover:bg-primary/90",
destructive:
"bg-destructive text-destructive-foreground hover:bg-destructive/90",
outline:
"border border-input bg-background hover:bg-accent hover:text-accent-foreground",
secondary:
"bg-secondary text-secondary-foreground hover:bg-secondary/80",
ghost: "hover:bg-accent hover:text-accent-foreground",
link: "text-primary underline-offset-4 hover:underline",
},
size: {
default: "h-10 px-4 py-2",
sm: "h-9 rounded-md px-3",
lg: "h-11 rounded-md px-8",
icon: "h-10 w-10",
},
},
defaultVariants: {
variant: "default",
size: "default",
},
}
)

export interface ButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
VariantProps<typeof buttonVariants> {
asChild?: boolean
}

const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
({ className, variant, size, asChild = false, ...props }, ref) => {
const Comp = asChild ? Slot : "button"
return (
<Comp
className={cn(buttonVariants({ variant, size, className }))}
ref={ref}
{...props}
/>
)
}
)
Button.displayName = "Button"

export { Button, buttonVariants }
79 changes: 79 additions & 0 deletions examples/with-shadcn-ui/renderer/components/ui/card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import * as React from "react"

import { cn } from "@/lib/utils"

const Card = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn(
"rounded-lg border bg-card text-card-foreground shadow-sm",
className
)}
{...props}
/>
))
Card.displayName = "Card"

const CardHeader = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn("flex flex-col space-y-1.5 p-6", className)}
{...props}
/>
))
CardHeader.displayName = "CardHeader"

const CardTitle = React.forwardRef<
HTMLParagraphElement,
React.HTMLAttributes<HTMLHeadingElement>
>(({ className, ...props }, ref) => (
<h3
ref={ref}
className={cn(
"text-2xl font-semibold leading-none tracking-tight",
className
)}
{...props}
/>
))
CardTitle.displayName = "CardTitle"

const CardDescription = React.forwardRef<
HTMLParagraphElement,
React.HTMLAttributes<HTMLParagraphElement>
>(({ className, ...props }, ref) => (
<p
ref={ref}
className={cn("text-sm text-muted-foreground", className)}
{...props}
/>
))
CardDescription.displayName = "CardDescription"

const CardContent = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div ref={ref} className={cn("p-6 pt-0", className)} {...props} />
))
CardContent.displayName = "CardContent"

const CardFooter = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn("flex items-center p-6 pt-0", className)}
{...props}
/>
))
CardFooter.displayName = "CardFooter"

export { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardContent }
6 changes: 6 additions & 0 deletions examples/with-shadcn-ui/renderer/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { type ClassValue, clsx } from "clsx"
import { twMerge } from "tailwind-merge"

export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
12 changes: 12 additions & 0 deletions examples/with-shadcn-ui/renderer/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/** @type {import('next').NextConfig} */
module.exports = {
output: 'export',
distDir: process.env.NODE_ENV === 'production' ? '../app' : '.next',
trailingSlash: true,
images: {
unoptimized: true,
},
webpack: (config) => {
return config
},
}
26 changes: 26 additions & 0 deletions examples/with-shadcn-ui/renderer/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react'
import type { AppProps } from 'next/app'

import '../styles/globals.css'
import { Inter as FontSans } from "next/font/google"
import { cn } from '@/lib/utils'

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

function MyApp({ Component, pageProps }: AppProps) {
return (
<main
className={cn(
"min-h-screen bg-background font-sans antialiased",
fontSans.variable
)}
>
<Component {...pageProps} />
</main>
)
}

export default MyApp
34 changes: 34 additions & 0 deletions examples/with-shadcn-ui/renderer/pages/home.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react'
import Head from 'next/head'
import Image from 'next/image'
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card'
import { Button } from '@/components/ui/button'
import Link from 'next/link'

export default function HomePage() {
return (
<React.Fragment>
<Head>
<title>Home - Nextron (with-shadcn-ui)</title>
</Head>
<div className="flex justify-center pt-6">
<Card className='w-96'>
<CardHeader>
<CardTitle>⚡ Nextron ⚡</CardTitle>
<CardDescription>
Nextron Example, with TypeScript, Tailwind CSS, and Shadcn UI.
</CardDescription>
</CardHeader>
<CardContent className='flex justify-center'>
<Image src="/images/logo.png" alt="Nextron" width={120} height={120} />
</CardContent>
<CardFooter className='flex justify-end'>
<Button>
<Link href="/next">Go to Next page</Link>
</Button>
</CardFooter>
</Card>
</div>
</React.Fragment>
)
}
29 changes: 29 additions & 0 deletions examples/with-shadcn-ui/renderer/pages/next.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react'
import Head from 'next/head'
import Link from 'next/link'
import Image from 'next/image'

export default function NextPage() {
return (
<React.Fragment>
<Head>
<title>Next - Nextron (with-shadcn-ui)</title>
</Head>
<div className="grid grid-col-1 text-2xl w-full text-center">
<div>
<Image
className="ml-auto mr-auto"
src="/images/logo.png"
alt="Logo image"
width={256}
height={256}
/>
</div>
<span>⚡ Nextron ⚡</span>
</div>
<div className="mt-1 w-full flex-wrap flex justify-center">
<Link href="/home">Go to home page</Link>
</div>
</React.Fragment>
)
}
8 changes: 8 additions & 0 deletions examples/with-shadcn-ui/renderer/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
plugins: {
tailwindcss: {
config: './renderer/tailwind.config.js',
},
autoprefixer: {},
},
}
7 changes: 7 additions & 0 deletions examples/with-shadcn-ui/renderer/preload.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { IpcHandler } from '../main/preload'

declare global {
interface Window {
ipc: IpcHandler
}
}
Loading