-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add react shadcn example (#108)
- Loading branch information
Showing
25 changed files
with
1,250 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
.DS_Store | ||
|
||
.pnp | ||
.pnp.js | ||
.env.local | ||
.env.*.local | ||
.history | ||
*.log* | ||
|
||
node_modules/ | ||
.yarn-integrity | ||
.pnpm-store/ | ||
*.tsbuildinfo | ||
.eslintcache | ||
|
||
dist/ | ||
coverage/ | ||
release/ | ||
output/ | ||
log/ | ||
|
||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"$schema": "https://ui.shadcn.com/schema.json", | ||
"style": "new-york", | ||
"rsc": false, | ||
"tsx": true, | ||
"tailwind": { | ||
"config": "tailwind.config.ts", | ||
"css": "src/global.less", | ||
"baseColor": "zinc", | ||
"cssVariables": true, | ||
"prefix": "" | ||
}, | ||
"aliases": { | ||
"components": "@/components", | ||
"utils": "@/utils/style", | ||
"ui": "@/components/ui", | ||
"lib": "@/lib", | ||
"hooks": "@/hooks" | ||
}, | ||
"iconLibrary": "lucide" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { setupStaticServer } from '@webx-kit/test-utils/playwright'; | ||
import { expect, test } from './context'; | ||
|
||
const getWebpageURL = setupStaticServer(test); | ||
|
||
test('Popup Page', async ({ getURL, page }) => { | ||
await page.goto(await getURL('popup.html')); | ||
|
||
await page.locator('button', { hasText: 'Account' }).click(); | ||
await expect(page.getByRole('tabpanel')).toHaveText('Make changes to your account here.'); | ||
|
||
await page.locator('button', { hasText: 'Password' }).click(); | ||
await expect(page.getByRole('tabpanel')).toHaveText('Change your password here.'); | ||
}); | ||
|
||
test('Content Scripts', async ({ page }) => { | ||
await page.goto(getWebpageURL()); | ||
await page.getByTestId('settings').click(); | ||
await expect(page.getByTestId('title')).toContainText('Move Goal'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import path from 'node:path'; | ||
import { createWebxTest } from '@webx-kit/test-utils/playwright'; | ||
|
||
export const test = createWebxTest({ | ||
extensionPath: path.resolve(__dirname, '../dist'), | ||
}); | ||
|
||
export const { expect } = test; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"name": "@webx-kit/example-with-shadcn", | ||
"version": "0.0.0", | ||
"private": true, | ||
"scripts": { | ||
"dev": "rsbuild dev", | ||
"build": "rsbuild build", | ||
"test": "playwright test", | ||
"lint:type": "tsc --noEmit" | ||
}, | ||
"dependencies": { | ||
"@radix-ui/react-dialog": "^1.1.4", | ||
"@radix-ui/react-slot": "^1.1.1", | ||
"@radix-ui/react-tabs": "^1.1.2", | ||
"@webx-kit/runtime": "workspace:^", | ||
"class-variance-authority": "^0.7.1", | ||
"clsx": "^2.1.1", | ||
"lucide-react": "^0.468.0", | ||
"react": "^19.0.0", | ||
"react-dom": "^19.0.0", | ||
"tailwind-merge": "^2.5.5", | ||
"tailwindcss-animate": "^1.0.7", | ||
"vaul": "^1.1.2" | ||
}, | ||
"devDependencies": { | ||
"@playwright/test": "^1.49.0", | ||
"@rsbuild/core": "catalog:", | ||
"@rsbuild/plugin-less": "catalog:", | ||
"@rsbuild/plugin-react": "catalog:", | ||
"@types/chrome": "^0.0.287", | ||
"@types/node": "^22.10.1", | ||
"@types/react": "^19.0.1", | ||
"@types/react-dom": "^19.0.1", | ||
"@webx-kit/rsbuild-plugin": "workspace:^", | ||
"@webx-kit/test-utils": "workspace:^", | ||
"tailwindcss": "^3.4.16", | ||
"typescript": "^5.7.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* @see {@link https://playwright.dev/docs/chrome-extensions Chrome extensions | Playwright} | ||
*/ | ||
import { defineConfig, devices } from '@playwright/test'; | ||
|
||
export default defineConfig({ | ||
projects: [ | ||
{ | ||
name: 'chromium', | ||
use: { | ||
...devices['Desktop Chrome'], | ||
channel: 'chromium', | ||
}, | ||
}, | ||
], | ||
testDir: './e2e', | ||
retries: 2, | ||
}); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { defineConfig } from '@rsbuild/core'; | ||
import { pluginLess } from '@rsbuild/plugin-less'; | ||
import { pluginReact } from '@rsbuild/plugin-react'; | ||
import { webxPlugin } from '@webx-kit/rsbuild-plugin'; | ||
|
||
export default defineConfig({ | ||
plugins: [ | ||
pluginLess(), | ||
pluginReact(), | ||
webxPlugin({ | ||
background: './src/background/index.ts', | ||
contentScripts: { | ||
import: './src/content-scripts/index.tsx', | ||
matches: ['<all_urls>'], | ||
}, | ||
}), | ||
], | ||
source: { | ||
entry: { | ||
popup: './src/pages/popup/index.tsx', | ||
}, | ||
}, | ||
output: { | ||
copy: [ | ||
{ | ||
from: './public', | ||
to: './public', | ||
}, | ||
], | ||
}, | ||
tools: { | ||
postcss: { | ||
postcssOptions: { | ||
plugins: [require('tailwindcss')], | ||
}, | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('hello'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { createContext } from 'react'; | ||
|
||
export const ContainerProvider = createContext<HTMLElement>(document.body); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import * as React from 'react'; | ||
import { Slot } from '@radix-ui/react-slot'; | ||
import { cva, type VariantProps } from 'class-variance-authority'; | ||
|
||
import { cn } from '@/utils/style'; | ||
|
||
const buttonVariants = cva( | ||
'inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0', | ||
{ | ||
variants: { | ||
variant: { | ||
default: 'bg-primary text-primary-foreground shadow hover:bg-primary/90', | ||
destructive: 'bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90', | ||
outline: 'border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground', | ||
secondary: 'bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80', | ||
ghost: 'hover:bg-accent hover:text-accent-foreground', | ||
link: 'text-primary underline-offset-4 hover:underline', | ||
}, | ||
size: { | ||
default: 'h-9 px-4 py-2', | ||
sm: 'h-8 rounded-md px-3 text-xs', | ||
lg: 'h-10 rounded-md px-8', | ||
icon: 'h-9 w-9', | ||
}, | ||
}, | ||
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import * as React from 'react'; | ||
import { Drawer as DrawerPrimitive } from 'vaul'; | ||
|
||
import { cn } from '@/utils/style'; | ||
|
||
const Drawer = ({ shouldScaleBackground = true, ...props }: React.ComponentProps<typeof DrawerPrimitive.Root>) => ( | ||
<DrawerPrimitive.Root shouldScaleBackground={shouldScaleBackground} {...props} /> | ||
); | ||
Drawer.displayName = 'Drawer'; | ||
|
||
const DrawerTrigger = DrawerPrimitive.Trigger; | ||
|
||
const DrawerPortal = DrawerPrimitive.Portal; | ||
|
||
const DrawerClose = DrawerPrimitive.Close; | ||
|
||
const DrawerOverlay = React.forwardRef< | ||
React.ComponentRef<typeof DrawerPrimitive.Overlay>, | ||
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Overlay> | ||
>(({ className, ...props }, ref) => ( | ||
<DrawerPrimitive.Overlay ref={ref} className={cn('fixed inset-0 z-50 bg-black/80', className)} {...props} /> | ||
)); | ||
DrawerOverlay.displayName = DrawerPrimitive.Overlay.displayName; | ||
|
||
const DrawerContent = React.forwardRef< | ||
React.ComponentRef<typeof DrawerPrimitive.Content>, | ||
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Content> | ||
>(({ className, children, ...props }, ref) => ( | ||
<DrawerPortal> | ||
<DrawerOverlay /> | ||
<DrawerPrimitive.Content | ||
ref={ref} | ||
className={cn( | ||
'fixed inset-x-0 bottom-0 z-50 mt-24 flex h-auto flex-col rounded-t-[10px] border bg-background', | ||
className | ||
)} | ||
{...props} | ||
> | ||
<div className="mx-auto mt-4 h-2 w-[100px] rounded-full bg-muted" /> | ||
{children} | ||
</DrawerPrimitive.Content> | ||
</DrawerPortal> | ||
)); | ||
DrawerContent.displayName = 'DrawerContent'; | ||
|
||
const DrawerHeader = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => ( | ||
<div className={cn('grid gap-1.5 p-4 text-center sm:text-left', className)} {...props} /> | ||
); | ||
DrawerHeader.displayName = 'DrawerHeader'; | ||
|
||
const DrawerFooter = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => ( | ||
<div className={cn('mt-auto flex flex-col gap-2 p-4', className)} {...props} /> | ||
); | ||
DrawerFooter.displayName = 'DrawerFooter'; | ||
|
||
const DrawerTitle = React.forwardRef< | ||
React.ComponentRef<typeof DrawerPrimitive.Title>, | ||
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Title> | ||
>(({ className, ...props }, ref) => ( | ||
<DrawerPrimitive.Title | ||
ref={ref} | ||
className={cn('text-lg font-semibold leading-none tracking-tight', className)} | ||
{...props} | ||
/> | ||
)); | ||
DrawerTitle.displayName = DrawerPrimitive.Title.displayName; | ||
|
||
const DrawerDescription = React.forwardRef< | ||
React.ComponentRef<typeof DrawerPrimitive.Description>, | ||
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Description> | ||
>(({ className, ...props }, ref) => ( | ||
<DrawerPrimitive.Description ref={ref} className={cn('text-sm text-muted-foreground', className)} {...props} /> | ||
)); | ||
DrawerDescription.displayName = DrawerPrimitive.Description.displayName; | ||
|
||
export { | ||
Drawer, | ||
DrawerPortal, | ||
DrawerOverlay, | ||
DrawerTrigger, | ||
DrawerClose, | ||
DrawerContent, | ||
DrawerHeader, | ||
DrawerFooter, | ||
DrawerTitle, | ||
DrawerDescription, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import * as React from 'react'; | ||
import * as TabsPrimitive from '@radix-ui/react-tabs'; | ||
|
||
import { cn } from '@/utils/style'; | ||
|
||
const Tabs = TabsPrimitive.Root; | ||
|
||
const TabsList = React.forwardRef< | ||
React.ComponentRef<typeof TabsPrimitive.List>, | ||
React.ComponentPropsWithoutRef<typeof TabsPrimitive.List> | ||
>(({ className, ...props }, ref) => ( | ||
<TabsPrimitive.List | ||
ref={ref} | ||
className={cn( | ||
'inline-flex h-9 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground', | ||
className | ||
)} | ||
{...props} | ||
/> | ||
)); | ||
TabsList.displayName = TabsPrimitive.List.displayName; | ||
|
||
const TabsTrigger = React.forwardRef< | ||
React.ComponentRef<typeof TabsPrimitive.Trigger>, | ||
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Trigger> | ||
>(({ className, ...props }, ref) => ( | ||
<TabsPrimitive.Trigger | ||
ref={ref} | ||
className={cn( | ||
'inline-flex items-center justify-center whitespace-nowrap rounded-md px-3 py-1 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow', | ||
className | ||
)} | ||
{...props} | ||
/> | ||
)); | ||
TabsTrigger.displayName = TabsPrimitive.Trigger.displayName; | ||
|
||
const TabsContent = React.forwardRef< | ||
React.ComponentRef<typeof TabsPrimitive.Content>, | ||
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Content> | ||
>(({ className, ...props }, ref) => ( | ||
<TabsPrimitive.Content | ||
ref={ref} | ||
className={cn( | ||
'mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2', | ||
className | ||
)} | ||
{...props} | ||
/> | ||
)); | ||
TabsContent.displayName = TabsPrimitive.Content.displayName; | ||
|
||
export { Tabs, TabsList, TabsTrigger, TabsContent }; |
Oops, something went wrong.