Loading...
Loading...
Compare original and translation side by side
references/patterns.mdtailwindcssreferences/patterns.mdtailwindcssbg-backgroundbg-cardbg-mutedbg-popovertext-foregroundtext-muted-foregroundtext-card-foregroundborder-borderborder-inputborder-ringbg-primary text-primary-foregroundbg-secondary text-secondary-foregroundbg-destructive text-destructive-foregroundbg-accent text-accent-foregroundbg-whitetext-blackborder-gray-200bg-backgroundbg-cardbg-mutedbg-popovertext-foregroundtext-muted-foregroundtext-card-foregroundborder-borderborder-inputborder-ringbg-primary text-primary-foregroundbg-secondary text-secondary-foregroundbg-destructive text-destructive-foregroundbg-accent text-accent-foregroundbg-whitetext-blackborder-gray-200npx shadcn-ui@latest add button card dialognpx shadcn-ui@latest add button card dialogexport interface ButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
VariantProps<typeof buttonVariants> {
loading?: boolean
}
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
({ className, variant, size, loading, children, ...props }, ref) => {
return (
<button
className={cn(buttonVariants({ variant, size, className }))}
ref={ref}
disabled={loading || props.disabled}
{...props}
>
{loading && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
{children}
</button>
)
}
)export interface ButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
VariantProps<typeof buttonVariants> {
loading?: boolean
}
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
({ className, variant, size, loading, children, ...props }, ref) => {
return (
<button
className={cn(buttonVariants({ variant, size, className }))}
ref={ref}
disabled={loading || props.disabled}
{...props}
>
{loading && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
{children}
</button>
)
}
)// CORRECT
export const CardTech = CardTechRoot;
export const CardTechHeader = CardHeader;
export const CardTechTitle = CardTitle;
export const CardTechContent = CardContent;
// WRONG - Do not use
export const CardTech = Object.assign(CardTechRoot, {
Header: CardHeader,
Content: CardContent,
});// 正确写法
export const CardTech = CardTechRoot;
export const CardTechHeader = CardHeader;
export const CardTechTitle = CardTitle;
export const CardTechContent = CardContent;
// 错误写法 - 请勿使用
export const CardTech = Object.assign(CardTechRoot, {
Header: CardHeader,
Content: CardContent,
});<Dialog>
<DialogTrigger asChild>
<Button>Open Dialog</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Accessible Title</DialogTitle>
<DialogDescription>
This description helps screen readers understand the dialog's purpose
</DialogDescription>
</DialogHeader>
</DialogContent>
</Dialog><Dialog>
<DialogTrigger asChild>
<Button>Open Dialog</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Accessible Title</DialogTitle>
<DialogDescription>
This description helps screen readers understand the dialog's purpose
</DialogDescription>
</DialogHeader>
</DialogContent>
</Dialog>globals.css@layer base {
:root {
--success: 142 76% 36%;
--success-foreground: 355 100% 100%;
}
.dark {
--success: 142 76% 46%;
--success-foreground: 142 76% 10%;
}
}globals.css@layer base {
:root {
--success: 142 76% 36%;
--success-foreground: 355 100% 100%;
}
.dark {
--success: 142 76% 46%;
--success-foreground: 142 76% 10%;
}
}pnpm run typecheckpnpm run testreferences/patterns.mdpnpm run typecheckpnpm run testreferences/patterns.md