@copilotkit/react-ui 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/.turbo/turbo-build.log +12 -14
  2. package/CHANGELOG.md +13 -0
  3. package/dist/index.css +1 -1
  4. package/dist/index.d.ts +36 -2
  5. package/dist/index.js +48 -10
  6. package/dist/index.mjs +26 -0
  7. package/package.json +39 -8
  8. package/src/components/chat-components/chat-list.tsx +32 -0
  9. package/src/components/chat-components/chat-message-actions.tsx +40 -0
  10. package/src/components/chat-components/chat-message.tsx +74 -0
  11. package/src/components/chat-components/chat-panel.tsx +77 -0
  12. package/src/components/chat-components/chat-scroll-anchor.tsx +29 -0
  13. package/src/components/chat-components/clear-history.tsx +73 -0
  14. package/src/components/chat-components/copilot-chat.tsx +61 -0
  15. package/src/components/chat-components/default-empty-screen.tsx +62 -0
  16. package/src/components/chat-components/external-link.tsx +29 -0
  17. package/src/components/chat-components/markdown.tsx +9 -0
  18. package/src/components/chat-components/prompt-form.tsx +91 -0
  19. package/src/components/chat-components/theme-toggle.tsx +31 -0
  20. package/src/components/chat-components/toaster.tsx +3 -0
  21. package/src/components/chat-components/ui/alert-dialog.tsx +150 -0
  22. package/src/components/chat-components/ui/badge.tsx +36 -0
  23. package/src/components/chat-components/ui/button.tsx +57 -0
  24. package/src/components/chat-components/ui/codeblock.tsx +142 -0
  25. package/src/components/chat-components/ui/dialog.tsx +128 -0
  26. package/src/components/chat-components/ui/dropdown-menu.tsx +128 -0
  27. package/src/components/chat-components/ui/icons.tsx +507 -0
  28. package/src/components/chat-components/ui/input.tsx +25 -0
  29. package/src/components/chat-components/ui/label.tsx +26 -0
  30. package/src/components/chat-components/ui/select.tsx +119 -0
  31. package/src/components/chat-components/ui/separator.tsx +31 -0
  32. package/src/components/chat-components/ui/sheet.tsx +122 -0
  33. package/src/components/chat-components/ui/switch.tsx +29 -0
  34. package/src/components/chat-components/ui/textarea.tsx +24 -0
  35. package/src/components/chat-components/ui/tooltip.tsx +30 -0
  36. package/src/components/index.ts +7 -0
  37. package/src/components/sidebar/copilot-sidebar-ui-provider.tsx +74 -0
  38. package/src/components/sidebar/copilot-sidebar.tsx +40 -0
  39. package/src/components/sidebar/sidebar-context.tsx +11 -0
  40. package/src/context/index.ts +1 -0
  41. package/src/hooks/index.ts +1 -0
  42. package/src/hooks/use-at-bottom.tsx +23 -0
  43. package/src/hooks/use-copy-to-clipboard.tsx +33 -0
  44. package/src/hooks/use-enter-submit.tsx +23 -0
  45. package/src/index.tsx +4 -3
  46. package/src/lib/utils.ts +43 -0
  47. package/src/types/index.ts +1 -0
  48. package/src/types/types.ts +18 -0
  49. package/tailwind.config.js +1 -1
  50. package/tsconfig.json +1 -1
  51. package/dist/Button.d.ts +0 -3
  52. package/dist/Button.js +0 -10
  53. package/dist/Card.d.ts +0 -7
  54. package/dist/Card.js +0 -10
  55. package/dist/chunk-6OZR7L23.js +0 -7
  56. package/dist/chunk-FGO3LSHH.js +0 -7
  57. package/src/Button.tsx +0 -16
  58. package/src/Card.tsx +0 -27
@@ -0,0 +1,77 @@
1
+ import { type UseChatHelpers } from 'ai/react'
2
+
3
+ import { Button } from './ui/button'
4
+ import { PromptForm } from './prompt-form'
5
+ import { IconRefresh, IconStop } from './ui/icons'
6
+
7
+ export interface ChatPanelProps
8
+ extends Pick<
9
+ UseChatHelpers,
10
+ | 'append'
11
+ | 'isLoading'
12
+ | 'reload'
13
+ | 'messages'
14
+ | 'stop'
15
+ | 'input'
16
+ | 'setInput'
17
+ > {
18
+ id?: string
19
+ }
20
+
21
+ export function ChatPanel({
22
+ id,
23
+ isLoading,
24
+ stop,
25
+ append,
26
+ reload,
27
+ input,
28
+ setInput,
29
+ messages
30
+ }: ChatPanelProps) {
31
+ return (
32
+ <div
33
+ className="inset-x-0 bottom-0 bg-gradient-to-b from-muted/10 from-10% to-muted/30 to-50% mt-4 mb-8"
34
+ style={{ width: '100%', overflow: 'hidden', boxSizing: 'border-box' }}
35
+ >
36
+ <div className="mx-auto sm:max-w-2xl sm:px-4">
37
+ <div className="flex h-10 items-center justify-center mb-4">
38
+ {isLoading ? (
39
+ <Button
40
+ variant="outline"
41
+ onClick={() => stop()}
42
+ className="bg-background"
43
+ >
44
+ <IconStop className="mr-2" />
45
+ Stop generating
46
+ </Button>
47
+ ) : (
48
+ messages?.length > 0 && (
49
+ <Button
50
+ variant="outline"
51
+ onClick={() => reload()}
52
+ className="bg-background"
53
+ >
54
+ <IconRefresh className="mr-2" />
55
+ Regenerate response
56
+ </Button>
57
+ )
58
+ )}
59
+ </div>
60
+ <div className="space-y-4 border-2 bg-background px-4 py-2 shadow-lg sm:rounded-xl md:py-4">
61
+ <PromptForm
62
+ onSubmit={async value => {
63
+ await append({
64
+ id,
65
+ content: value,
66
+ role: 'user'
67
+ })
68
+ }}
69
+ input={input}
70
+ setInput={setInput}
71
+ isLoading={isLoading}
72
+ />
73
+ </div>
74
+ </div>
75
+ </div>
76
+ )
77
+ }
@@ -0,0 +1,29 @@
1
+ 'use client'
2
+
3
+ import * as React from 'react'
4
+ import { useInView } from 'react-intersection-observer'
5
+
6
+ import { useAtBottom } from '../../hooks/use-at-bottom'
7
+
8
+ interface ChatScrollAnchorProps {
9
+ trackVisibility?: boolean
10
+ }
11
+
12
+ export function ChatScrollAnchor({ trackVisibility }: ChatScrollAnchorProps) {
13
+ const isAtBottom = useAtBottom()
14
+ const { ref, entry, inView } = useInView({
15
+ trackVisibility,
16
+ delay: 100,
17
+ rootMargin: '0px 0px -150px 0px'
18
+ })
19
+
20
+ React.useEffect(() => {
21
+ if (isAtBottom && trackVisibility && !inView) {
22
+ entry?.target.scrollIntoView({
23
+ block: 'start'
24
+ })
25
+ }
26
+ }, [inView, entry, isAtBottom, trackVisibility])
27
+
28
+ return <div ref={ref} className="h-px w-full" />
29
+ }
@@ -0,0 +1,73 @@
1
+ 'use client'
2
+
3
+ import * as React from 'react'
4
+ import { useRouter } from 'next/navigation'
5
+ import { toast } from 'react-hot-toast'
6
+
7
+ import { ServerActionResult } from "../../types/types"
8
+ import { Button } from './ui/button'
9
+ import {
10
+ AlertDialog,
11
+ AlertDialogAction,
12
+ AlertDialogCancel,
13
+ AlertDialogContent,
14
+ AlertDialogDescription,
15
+ AlertDialogFooter,
16
+ AlertDialogHeader,
17
+ AlertDialogTitle,
18
+ AlertDialogTrigger
19
+ } from './ui/alert-dialog'
20
+ import { IconSpinner } from './ui/icons'
21
+
22
+ interface ClearHistoryProps {
23
+ clearChats: () => ServerActionResult<void>
24
+ }
25
+
26
+ export function ClearHistory({ clearChats }: ClearHistoryProps) {
27
+ const [open, setOpen] = React.useState(false)
28
+ const [isPending, startTransition] = React.useTransition()
29
+ const router = useRouter()
30
+
31
+ return (
32
+ <AlertDialog open={open} onOpenChange={setOpen}>
33
+ <AlertDialogTrigger asChild>
34
+ <Button variant="ghost" disabled={isPending}>
35
+ {isPending && <IconSpinner className="mr-2" />}
36
+ Clear history
37
+ </Button>
38
+ </AlertDialogTrigger>
39
+ <AlertDialogContent>
40
+ <AlertDialogHeader>
41
+ <AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
42
+ <AlertDialogDescription>
43
+ This will permanently delete your chat history and remove your data
44
+ from our servers.
45
+ </AlertDialogDescription>
46
+ </AlertDialogHeader>
47
+ <AlertDialogFooter>
48
+ <AlertDialogCancel disabled={isPending}>Cancel</AlertDialogCancel>
49
+ <AlertDialogAction
50
+ disabled={isPending}
51
+ onClick={(event: any) => {
52
+ event.preventDefault()
53
+ startTransition(async () => {
54
+ const result = await clearChats()
55
+
56
+ if (result && 'error' in result) {
57
+ toast.error(result.error)
58
+ return
59
+ }
60
+
61
+ setOpen(false)
62
+ router.push('/')
63
+ })
64
+ }}
65
+ >
66
+ {isPending && <IconSpinner className="mr-2 animate-spin" />}
67
+ Delete
68
+ </AlertDialogAction>
69
+ </AlertDialogFooter>
70
+ </AlertDialogContent>
71
+ </AlertDialog>
72
+ )
73
+ }
@@ -0,0 +1,61 @@
1
+ 'use client'
2
+
3
+ import React from 'react'
4
+
5
+ import { ChatList } from './chat-list'
6
+ import { ChatPanel } from './chat-panel'
7
+ import { DefaultEmptyScreen, EmptyScreenProps } from './default-empty-screen'
8
+ import { ChatScrollAnchor } from './chat-scroll-anchor'
9
+ import { UseCopilotChatOptions } from "@copilotkit/react-core"
10
+ import { useCopilotChat } from "@copilotkit/react-core"
11
+
12
+ interface ChatComponentInjectionsProps {
13
+ EmptyScreen?: React.FC<EmptyScreenProps>
14
+ }
15
+
16
+ interface CopilotChatProps
17
+ extends UseCopilotChatOptions,
18
+ ChatComponentInjectionsProps {}
19
+
20
+ export function CopilotChat({
21
+ id,
22
+ initialMessages,
23
+ makeSystemMessage,
24
+ EmptyScreen = DefaultEmptyScreen
25
+ }: CopilotChatProps) {
26
+ const { visibleMessages, append, reload, stop, isLoading, input, setInput } =
27
+ useCopilotChat({ id, initialMessages, makeSystemMessage })
28
+
29
+ return (
30
+ <div
31
+ className="w-full h-full flex flex-col overflow-hidden box-border items-start"
32
+ >
33
+ <div
34
+ className="pt-5 px-5 overflow-y-auto overflow-x-hidden w-full flex-grow"
35
+ >
36
+ {visibleMessages.length ? (
37
+ <div className="pl-0 pr-6">
38
+ <ChatList messages={visibleMessages} />
39
+ <ChatScrollAnchor trackVisibility={isLoading} />
40
+ </div>
41
+ ) : (
42
+ <EmptyScreen setInput={setInput} />
43
+ )}
44
+ </div>
45
+
46
+ <div className="flex-shrink-0 w-full">
47
+ <ChatPanel
48
+ id={id}
49
+ isLoading={isLoading}
50
+ stop={stop}
51
+ append={append}
52
+ reload={reload}
53
+ messages={visibleMessages}
54
+ input={input}
55
+ setInput={setInput}
56
+ />
57
+ </div>
58
+ </div>
59
+ )
60
+ }
61
+
@@ -0,0 +1,62 @@
1
+ 'use client'
2
+ import React from 'react'
3
+ import { UseChatHelpers } from 'ai/react'
4
+
5
+ import { Button } from './ui/button'
6
+ import { ExternalLink } from './external-link'
7
+ import { IconArrowRight } from './ui/icons'
8
+
9
+ const exampleMessages = [
10
+ {
11
+ heading: 'Explain technical concepts',
12
+ message: `What is a "serverless function"?`
13
+ },
14
+ {
15
+ heading: 'Summarize an article',
16
+ message: 'Summarize the following article for a 2nd grader: \n'
17
+ },
18
+ {
19
+ heading: 'Draft an email',
20
+ message: `Draft an email to my boss about the following: \n`
21
+ }
22
+ ]
23
+
24
+ export interface EmptyScreenProps {
25
+ setInput: React.Dispatch<React.SetStateAction<string>>
26
+ }
27
+
28
+ export const DefaultEmptyScreen: React.FC<EmptyScreenProps> = props => {
29
+ return (
30
+ <div className="mx-auto max-w-2xl px-4">
31
+ <div className="rounded-lg border bg-background p-8">
32
+ <h1 className="mb-2 text-lg font-semibold">Welcome to Copilot! 👋</h1>
33
+ <p className="mb-2 leading-normal text-muted-foreground">
34
+ This is a Copilot built with{' '}
35
+ <ExternalLink href="https://recursively.ai">
36
+ recursively.ai's
37
+ </ExternalLink>{' '}
38
+ <ExternalLink href="https://github.com/RecursivelyAI/CopilotKit">
39
+ CopilotKit
40
+ </ExternalLink>{' '}
41
+ .
42
+ </p>
43
+ <p className="leading-normal text-muted-foreground">
44
+ You can start a conversation here or try the following examples:
45
+ </p>
46
+ <div className="mt-4 flex flex-col items-start space-y-2">
47
+ {exampleMessages.map((message, index) => (
48
+ <Button
49
+ key={index}
50
+ variant="link"
51
+ className="h-auto p-0 text-base"
52
+ onClick={() => props.setInput(message.message)}
53
+ >
54
+ <IconArrowRight className="mr-2 text-muted-foreground" />
55
+ {message.heading}
56
+ </Button>
57
+ ))}
58
+ </div>
59
+ </div>
60
+ </div>
61
+ )
62
+ }
@@ -0,0 +1,29 @@
1
+ export function ExternalLink({
2
+ href,
3
+ children
4
+ }: {
5
+ href: string
6
+ children: React.ReactNode
7
+ }) {
8
+ return (
9
+ <a
10
+ href={href}
11
+ target="_blank"
12
+ className="inline-flex flex-1 justify-center gap-1 leading-4 hover:underline"
13
+ >
14
+ <span>{children}</span>
15
+ <svg
16
+ aria-hidden="true"
17
+ height="7"
18
+ viewBox="0 0 6 6"
19
+ width="7"
20
+ className="opacity-70"
21
+ >
22
+ <path
23
+ d="M1.25215 5.54731L0.622742 4.9179L3.78169 1.75597H1.3834L1.38936 0.890915H5.27615V4.78069H4.40513L4.41109 2.38538L1.25215 5.54731Z"
24
+ fill="currentColor"
25
+ ></path>
26
+ </svg>
27
+ </a>
28
+ )
29
+ }
@@ -0,0 +1,9 @@
1
+ import { FC, memo } from 'react'
2
+ import ReactMarkdown, { Options } from 'react-markdown'
3
+
4
+ export const MemoizedReactMarkdown: FC<Options> = memo(
5
+ ReactMarkdown,
6
+ (prevProps, nextProps) =>
7
+ prevProps.children === nextProps.children &&
8
+ prevProps.className === nextProps.className
9
+ )
@@ -0,0 +1,91 @@
1
+ import * as React from 'react'
2
+ import TextareaAutosize from 'react-textarea-autosize'
3
+ import { UseChatHelpers } from 'ai/react'
4
+
5
+ import { useEnterSubmit } from '../../hooks/use-enter-submit'
6
+ import { cn } from '../../lib/utils'
7
+ import { Button, buttonVariants } from './ui/button'
8
+ import { Tooltip, TooltipContent, TooltipTrigger } from './ui/tooltip'
9
+ import { IconArrowElbow, IconPlus } from './ui/icons'
10
+ import Link from 'next/link'
11
+
12
+ export interface PromptProps
13
+ extends Pick<UseChatHelpers, 'input' | 'setInput'> {
14
+ onSubmit: (value: string) => Promise<void>
15
+ isLoading: boolean
16
+ }
17
+
18
+ export function PromptForm({
19
+ onSubmit,
20
+ input,
21
+ setInput,
22
+ isLoading
23
+ }: PromptProps) {
24
+ const { formRef, onKeyDown } = useEnterSubmit()
25
+ const inputRef = React.useRef<HTMLTextAreaElement>(null)
26
+
27
+ React.useEffect(() => {
28
+ if (inputRef.current) {
29
+ inputRef.current.focus()
30
+ }
31
+ }, [])
32
+
33
+ return (
34
+ <form
35
+ onSubmit={async e => {
36
+ e.preventDefault()
37
+ if (!input?.trim()) {
38
+ return
39
+ }
40
+ setInput('')
41
+ await onSubmit(input)
42
+ }}
43
+ ref={formRef}
44
+ >
45
+ <div className="relative flex max-h-60 w-full grow flex-col overflow-hidden bg-background px-8 sm:rounded-md border sm:px-12">
46
+ <Tooltip>
47
+ <TooltipTrigger asChild>
48
+ <Link
49
+ href="/"
50
+ className={cn(
51
+ buttonVariants({ size: 'sm', variant: 'outline' }),
52
+ 'absolute left-0 top-4 h-8 w-8 rounded-full bg-background p-0 sm:left-4'
53
+ )}
54
+ >
55
+ <IconPlus />
56
+ <span className="sr-only">New Chat</span>
57
+ </Link>
58
+ </TooltipTrigger>
59
+ <TooltipContent>New Chat</TooltipContent>
60
+ </Tooltip>
61
+ <TextareaAutosize
62
+ ref={inputRef}
63
+ tabIndex={0}
64
+ onKeyDown={onKeyDown}
65
+ rows={1}
66
+ value={input}
67
+ onChange={e => setInput(e.target.value)}
68
+ placeholder="Send a message."
69
+ spellCheck={false}
70
+ className="min-h-[60px] w-full resize-none bg-transparent px-4 py-[1.3rem] focus-within:outline-none sm:text-sm"
71
+ />
72
+ <div className="absolute right-0 top-4 sm:right-4">
73
+ <Tooltip>
74
+ <TooltipTrigger asChild>
75
+ <Button
76
+ type="submit"
77
+ size="icon"
78
+ disabled={isLoading || input === ''}
79
+ className=" bg-slate-300"
80
+ >
81
+ <IconArrowElbow />
82
+ <span className="sr-only">Send message</span>
83
+ </Button>
84
+ </TooltipTrigger>
85
+ <TooltipContent>Send message</TooltipContent>
86
+ </Tooltip>
87
+ </div>
88
+ </div>
89
+ </form>
90
+ )
91
+ }
@@ -0,0 +1,31 @@
1
+ 'use client'
2
+
3
+ import * as React from 'react'
4
+ import { useTheme } from 'next-themes'
5
+
6
+ import { Button } from './ui/button'
7
+ import { IconMoon, IconSun } from './ui/icons'
8
+
9
+ export function ThemeToggle() {
10
+ const { setTheme, theme } = useTheme()
11
+ const [_, startTransition] = React.useTransition()
12
+
13
+ return (
14
+ <Button
15
+ variant="ghost"
16
+ size="icon"
17
+ onClick={() => {
18
+ startTransition(() => {
19
+ setTheme(theme === 'light' ? 'dark' : 'light')
20
+ })
21
+ }}
22
+ >
23
+ {!theme ? null : theme === 'dark' ? (
24
+ <IconMoon className="transition-all" />
25
+ ) : (
26
+ <IconSun className="transition-all" />
27
+ )}
28
+ <span className="sr-only">Toggle theme</span>
29
+ </Button>
30
+ )
31
+ }
@@ -0,0 +1,3 @@
1
+ 'use client'
2
+
3
+ export { Toaster } from 'react-hot-toast'
@@ -0,0 +1,150 @@
1
+ 'use client'
2
+
3
+ import * as React from 'react'
4
+ import * as AlertDialogPrimitive from '@radix-ui/react-alert-dialog'
5
+
6
+ import { cn } from '../../../lib/utils'
7
+ import { buttonVariants } from './button'
8
+
9
+ const AlertDialog = AlertDialogPrimitive.Root
10
+
11
+ const AlertDialogTrigger = AlertDialogPrimitive.Trigger
12
+
13
+ const AlertDialogPortal = ({
14
+ className,
15
+ children,
16
+ ...props
17
+ }: AlertDialogPrimitive.AlertDialogPortalProps) => (
18
+ <AlertDialogPrimitive.Portal className={cn(className)} {...props}>
19
+ <div className="fixed inset-0 z-50 flex items-end justify-center sm:items-center">
20
+ {children}
21
+ </div>
22
+ </AlertDialogPrimitive.Portal>
23
+ )
24
+ AlertDialogPortal.displayName = AlertDialogPrimitive.Portal.displayName
25
+
26
+ const AlertDialogOverlay = React.forwardRef<
27
+ React.ElementRef<typeof AlertDialogPrimitive.Overlay>,
28
+ React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Overlay>
29
+ >(({ className, children, ...props }, ref) => (
30
+ <AlertDialogPrimitive.Overlay
31
+ className={cn(
32
+ 'fixed inset-0 z-50 bg-background/80 backdrop-blur-sm transition-opacity animate-in fade-in',
33
+ className
34
+ )}
35
+ {...props}
36
+ ref={ref}
37
+ />
38
+ ))
39
+ AlertDialogOverlay.displayName = AlertDialogPrimitive.Overlay.displayName
40
+
41
+ const AlertDialogContent = React.forwardRef<
42
+ React.ElementRef<typeof AlertDialogPrimitive.Content>,
43
+ React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Content>
44
+ >(({ className, ...props }, ref) => (
45
+ <AlertDialogPortal>
46
+ <AlertDialogOverlay />
47
+ <AlertDialogPrimitive.Content
48
+ ref={ref}
49
+ className={cn(
50
+ 'fixed z-50 grid w-full max-w-lg scale-100 gap-4 border bg-background p-6 opacity-100 shadow-lg animate-in fade-in-90 slide-in-from-bottom-10 sm:rounded-lg sm:zoom-in-90 sm:slide-in-from-bottom-0 md:w-full',
51
+ className
52
+ )}
53
+ {...props}
54
+ />
55
+ </AlertDialogPortal>
56
+ ))
57
+ AlertDialogContent.displayName = AlertDialogPrimitive.Content.displayName
58
+
59
+ const AlertDialogHeader = ({
60
+ className,
61
+ ...props
62
+ }: React.HTMLAttributes<HTMLDivElement>) => (
63
+ <div
64
+ className={cn(
65
+ 'flex flex-col space-y-2 text-center sm:text-left',
66
+ className
67
+ )}
68
+ {...props}
69
+ />
70
+ )
71
+ AlertDialogHeader.displayName = 'AlertDialogHeader'
72
+
73
+ const AlertDialogFooter = ({
74
+ className,
75
+ ...props
76
+ }: React.HTMLAttributes<HTMLDivElement>) => (
77
+ <div
78
+ className={cn(
79
+ 'flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2',
80
+ className
81
+ )}
82
+ {...props}
83
+ />
84
+ )
85
+ AlertDialogFooter.displayName = 'AlertDialogFooter'
86
+
87
+ const AlertDialogTitle = React.forwardRef<
88
+ React.ElementRef<typeof AlertDialogPrimitive.Title>,
89
+ React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Title>
90
+ >(({ className, ...props }, ref) => (
91
+ <AlertDialogPrimitive.Title
92
+ ref={ref}
93
+ className={cn('text-lg font-semibold', className)}
94
+ {...props}
95
+ />
96
+ ))
97
+ AlertDialogTitle.displayName = AlertDialogPrimitive.Title.displayName
98
+
99
+ const AlertDialogDescription = React.forwardRef<
100
+ React.ElementRef<typeof AlertDialogPrimitive.Description>,
101
+ React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Description>
102
+ >(({ className, ...props }, ref) => (
103
+ <AlertDialogPrimitive.Description
104
+ ref={ref}
105
+ className={cn('text-sm text-muted-foreground', className)}
106
+ {...props}
107
+ />
108
+ ))
109
+ AlertDialogDescription.displayName =
110
+ AlertDialogPrimitive.Description.displayName
111
+
112
+ const AlertDialogAction = React.forwardRef<
113
+ React.ElementRef<typeof AlertDialogPrimitive.Action>,
114
+ React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Action>
115
+ >(({ className, ...props }, ref) => (
116
+ <AlertDialogPrimitive.Action
117
+ ref={ref}
118
+ className={cn(buttonVariants(), className)}
119
+ {...props}
120
+ />
121
+ ))
122
+ AlertDialogAction.displayName = AlertDialogPrimitive.Action.displayName
123
+
124
+ const AlertDialogCancel = React.forwardRef<
125
+ React.ElementRef<typeof AlertDialogPrimitive.Cancel>,
126
+ React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Cancel>
127
+ >(({ className, ...props }, ref) => (
128
+ <AlertDialogPrimitive.Cancel
129
+ ref={ref}
130
+ className={cn(
131
+ buttonVariants({ variant: 'outline' }),
132
+ 'mt-2 sm:mt-0',
133
+ className
134
+ )}
135
+ {...props}
136
+ />
137
+ ))
138
+ AlertDialogCancel.displayName = AlertDialogPrimitive.Cancel.displayName
139
+
140
+ export {
141
+ AlertDialog,
142
+ AlertDialogTrigger,
143
+ AlertDialogContent,
144
+ AlertDialogHeader,
145
+ AlertDialogFooter,
146
+ AlertDialogTitle,
147
+ AlertDialogDescription,
148
+ AlertDialogAction,
149
+ AlertDialogCancel
150
+ }
@@ -0,0 +1,36 @@
1
+ import * as React from 'react'
2
+ import { cva, type VariantProps } from 'class-variance-authority'
3
+
4
+ import { cn } from '../../../lib/utils'
5
+
6
+ const badgeVariants = cva(
7
+ 'inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2',
8
+ {
9
+ variants: {
10
+ variant: {
11
+ default:
12
+ 'border-transparent bg-primary text-primary-foreground hover:bg-primary/80',
13
+ secondary:
14
+ 'border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80',
15
+ destructive:
16
+ 'border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80',
17
+ outline: 'text-foreground'
18
+ }
19
+ },
20
+ defaultVariants: {
21
+ variant: 'default'
22
+ }
23
+ }
24
+ )
25
+
26
+ export interface BadgeProps
27
+ extends React.HTMLAttributes<HTMLDivElement>,
28
+ VariantProps<typeof badgeVariants> {}
29
+
30
+ function Badge({ className, variant, ...props }: BadgeProps) {
31
+ return (
32
+ <div className={cn(badgeVariants({ variant }), className)} {...props} />
33
+ )
34
+ }
35
+
36
+ export { Badge, badgeVariants }