11import * as React from "react" ;
22import Link from "@docusaurus/Link" ;
33import clsx from "clsx" ;
4+ import { IconName } from "@site/src/typescript/iconName" ;
5+ import { Icon } from "./Icon" ;
6+ import isInternalUrl from "@docusaurus/isInternalUrl" ;
7+
8+ export type ButtonVariant =
9+ | "default"
10+ | "outline"
11+ | "ghost"
12+ | "destructive"
13+ | "secondary" ;
14+
415
516export interface ButtonProps
617 extends React . ButtonHTMLAttributes < HTMLButtonElement > {
718 children : React . ReactNode ;
819 url ?: string ;
920 className ?: string ;
10- variant ?: "default" | "outline" | "ghost" | "destructive" ;
21+ variant ?: ButtonVariant ;
1122 size ?: "sm" | "md" | "lg" ;
23+ iconName ?: IconName ;
1224}
1325
14- const variantClasses : Record < NonNullable < ButtonProps [ "variant" ] > , string > = {
26+ const variantClasses : Record < ButtonVariant , string > = {
1527 default : "bg-primary !text-white dark:!text-black hover:bg-primary-darker" ,
28+ secondary : "bg-gray-300 hover:bg-gray-400 dark:bg-secondary !text-black dark:hover:bg-secondary-darker" ,
1629 outline :
1730 "border !text-black border-black/25 !text-foreground hover:bg-black/5 dark:!text-white dark:border-white/25 dark:hover:bg-white/5" ,
1831 ghost : "hover:bg-muted !text-foreground" ,
@@ -29,8 +42,9 @@ export default function Button({
2942 children,
3043 url,
3144 className = "" ,
32- variant = "default " ,
45+ variant = "secondary " ,
3346 size = "md" ,
47+ iconName,
3448 ...props
3549} : ButtonProps ) {
3650 const baseClasses = clsx (
@@ -43,16 +57,21 @@ export default function Button({
4357 ) ;
4458
4559 if ( url ) {
60+ const isExternal = ! isInternalUrl ( url ) ;
4661 return (
47- < Link to = { url } className = { baseClasses } >
48- { children }
62+ < Link
63+ { ...( isExternal ? { href : url } : { to : url } ) }
64+ className = { baseClasses }
65+ >
66+ { children } { iconName && < Icon icon = { iconName } /> }
67+ { isExternal && < Icon icon = "newtab" className = "ml-2" size = "xs" /> }
4968 </ Link >
5069 ) ;
5170 }
5271
5372 return (
5473 < button className = { baseClasses } { ...props } >
55- { children }
74+ { children } { iconName && < Icon icon = { iconName } /> }
5675 </ button >
5776 ) ;
5877}
0 commit comments