Skip to content

Commit

Permalink
Add shadcn template
Browse files Browse the repository at this point in the history
  • Loading branch information
cezaraugusto committed Oct 4, 2024
1 parent 21f5698 commit 54c53fb
Show file tree
Hide file tree
Showing 23 changed files with 1,242 additions and 48 deletions.
31 changes: 31 additions & 0 deletions examples/sidebar-shadcn/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
node_modules

# testing
coverage

# production
dist

# misc
.DS_Store

# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local

# lock files
yarn.lock
package-lock.json

# debug files
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# extension.js
extension-env.d.ts
3 changes: 3 additions & 0 deletions examples/sidebar-shadcn/background.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
chrome.runtime.onInstalled.addListener(() => {
chrome.sidePanel.setPanelBehavior({ openPanelOnActionClick: true });
});
56 changes: 56 additions & 0 deletions examples/sidebar-shadcn/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/sidebar-shadcn/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}
26 changes: 26 additions & 0 deletions examples/sidebar-shadcn/components/ui/label.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@


import * as React from 'react'
import * as LabelPrimitive from '@radix-ui/react-label'
import {cva, type VariantProps} from 'class-variance-authority'

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

const labelVariants = cva(
'text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70'
)

const Label = React.forwardRef<
React.ElementRef<typeof LabelPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> &
VariantProps<typeof labelVariants>
>(({className, ...props}, ref) => (
<LabelPrimitive.Root
ref={ref}
className={cn(labelVariants(), className)}
{...props}
/>
))
Label.displayName = LabelPrimitive.Root.displayName

export {Label}
29 changes: 29 additions & 0 deletions examples/sidebar-shadcn/components/ui/switch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@


import * as React from 'react'
import * as SwitchPrimitives from '@radix-ui/react-switch'

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

const Switch = React.forwardRef<
React.ElementRef<typeof SwitchPrimitives.Root>,
React.ComponentPropsWithoutRef<typeof SwitchPrimitives.Root>
>(({className, ...props}, ref) => (
<SwitchPrimitives.Root
className={cn(
'peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input',
className
)}
{...props}
ref={ref}
>
<SwitchPrimitives.Thumb
className={cn(
'pointer-events-none block h-4 w-4 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0'
)}
/>
</SwitchPrimitives.Root>
))
Switch.displayName = SwitchPrimitives.Root.displayName

export {Switch}
Binary file added examples/sidebar-shadcn/images/extension_48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions examples/sidebar-shadcn/images/shadcn.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions examples/sidebar-shadcn/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {clsx, type ClassValue} from 'clsx'
import {twMerge} from 'tailwind-merge'

export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
25 changes: 25 additions & 0 deletions examples/sidebar-shadcn/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"manifest_version": 3,
"version": "0.0.1",
"name": "sidepanel-extension",
"author": "Your Name",
"description": "An Extension.js example.",
"icons": {
"48": "images/extension_48.png"
},
"action": {
"default_icon": {
"48": "images/extension_48.png"
},
"default_title": "Open Side Panel"
},
"side_panel": {
"default_path": "sidebar/index.html",
"default_title": "Side Panel Content"
},
"permissions": ["sidePanel", "tabs"],
"background": {
"chromium:service_worker": "background.ts",
"firefox:scripts": ["background.ts"]
}
}
39 changes: 39 additions & 0 deletions examples/sidebar-shadcn/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"private": true,
"name": "sidepanel-extension",
"description": "An Extension.js example.",
"version": "0.0.1",
"author": {
"name": "Your Name",
"email": "your@email.com",
"url": "https://yourwebsite.com"
},
"license": "MIT",
"scripts": {
"dev": "extension dev",
"start": "extension start",
"build": "extension build"
},
"dependencies": {
"@radix-ui/react-label": "^2.1.0",
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-switch": "^1.1.1",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"tailwind-merge": "^2.5.3",
"tailwindcss-animate": "^1.0.7"
},
"devDependencies": {
"@tailwindcss/typography": "^0.5.15",
"@types/react": "^18.2.64",
"@types/react-dom": "^18.2.21",
"autoprefixer": "^10.4.20",
"daisyui": "^4.12.10",
"extension": "latest",
"postcss": "^8.4.47",
"tailwindcss": "^3.4.13",
"typescript": "5.3.3"
}
}
3 changes: 3 additions & 0 deletions examples/sidebar-shadcn/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
plugins: [require("tailwindcss"), require("autoprefixer")],
};
7 changes: 7 additions & 0 deletions examples/sidebar-shadcn/public/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
67 changes: 67 additions & 0 deletions examples/sidebar-shadcn/sidebar/SidebarApp.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import {Button} from '@/components/ui/button'
import {
Card,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle
} from '@/components/ui/card'
import {Label} from '@/components/ui/label'
import {Switch} from '@/components/ui/switch'
import './styles.css'
import shadcnLogo from '../images/shadcn.svg'

export default function SidebarApp() {
return (
<Card className="h-full">
<CardHeader>
<img src={shadcnLogo} alt="shadcn Logo" className="w-12 h-12" />
<CardTitle>
<CardTitle>Welcome to your shadcn Extension.</CardTitle>
<CardDescription>Manage your cookie settings here.</CardDescription>
</CardTitle>
</CardHeader>
<CardContent className="grid gap-6">
<div className="flex items-center justify-between space-x-4">
<Label htmlFor="necessary" className="flex flex-col space-y-1">
<span>Strictly Necessary</span>
<span className="text-xs font-normal leading-snug text-muted-foreground">
These cookies are essential in order to use the website and use
its features.
</span>
</Label>
<Switch id="necessary" defaultChecked aria-label="Necessary" />
</div>
<div className="flex items-center justify-between space-x-4">
<Label htmlFor="functional" className="flex flex-col space-y-1">
<span>Functional Cookies</span>
<span className="text-xs font-normal leading-snug text-muted-foreground">
These cookies allow the website to provide personalized
functionality.
</span>
</Label>
<Switch id="functional" aria-label="Functional" />
</div>
<div className="flex items-center justify-between space-x-4">
<Label htmlFor="performance" className="flex flex-col space-y-1">
<span>Performance Cookies</span>
<span className="text-xs font-normal leading-snug text-muted-foreground">
These cookies help to improve the performance of the website.
</span>
</Label>
<Switch id="performance" aria-label="Performance" />
</div>
</CardContent>
<CardFooter>
<p>
Learn more about creating cross-browser extensions at{' '}
<a href="https://extension.js.org" target="_blank" className='underline'>
https://extension.js.org
</a>
.
</p>
</CardFooter>
</Card>
)
}
Loading

0 comments on commit 54c53fb

Please sign in to comment.