Skip to content

Commit

Permalink
feat(react): add new component tooltip (#64)
Browse files Browse the repository at this point in the history
Close #44
  • Loading branch information
Sebastián García authored Apr 1, 2024
2 parents 28f3f18 + 2665156 commit 23c70d2
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ _Display_
- [x] Alert Dialog
- [x] Badge
- [ ] Menu
- [ ] Tooltips
- [x] Tooltips
- [x] Tables
- [ ] Code block

Expand Down
13 changes: 11 additions & 2 deletions examples/with-vitejs/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState } from 'react'
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, Badge, Button, Card, CardContent, CardDescription, CardHeader, CardTitle, Input, Label, Menubar, MenubarCheckboxItem, MenubarContent, MenubarItem, MenubarMenu, MenubarRadioGroup, MenubarRadioItem, MenubarSeparator, MenubarShortcut, MenubarSub, MenubarSubContent, MenubarSubTrigger, MenubarTrigger, ScrollArea, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, Separator, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow } from '@openui-org/react'
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, Badge, Button, Card, CardContent, CardDescription, CardHeader, CardTitle, Input, Label, Menubar, MenubarCheckboxItem, MenubarContent, MenubarItem, MenubarMenu, MenubarRadioGroup, MenubarRadioItem, MenubarSeparator, MenubarShortcut, MenubarSub, MenubarSubContent, MenubarSubTrigger, MenubarTrigger, ScrollArea, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, Separator, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@openui-org/react'
import reactLogo from './assets/react.svg'
import viteLogo from '/vite.svg'
import imgPrueba from '/bghome.png'
Expand Down Expand Up @@ -248,7 +248,16 @@ function App() {
</TableRow>
</TableFooter>
</Table>

<div className="flex justify-center p-10">
<TooltipProvider>
<Tooltip>
<TooltipTrigger>Hover</TooltipTrigger>
<TooltipContent>
<p>Add to library</p>
</TooltipContent>
</Tooltip>
</TooltipProvider>
</div>
</>
)
}
Expand Down
1 change: 1 addition & 0 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"@radix-ui/react-separator": "1.0.3",
"@radix-ui/react-slider": "1.1.2",
"@radix-ui/react-slot": "1.0.2",
"@radix-ui/react-tooltip": "1.0.7",
"class-variance-authority": "0.7.0",
"clsx": "2.1.0",
"embla-carousel-react": "8.0.0",
Expand Down
39 changes: 39 additions & 0 deletions packages/react/src/components/tooltip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import * as React from 'react'
import * as TooltipPrimitive from '@radix-ui/react-tooltip'
import { cn } from '../lib/cn'
import { Button } from './button'

const TooltipProvider = TooltipPrimitive.Provider

const Tooltip = TooltipPrimitive.Root

function TooltipTrigger({
className,
...props
}: React.ButtonHTMLAttributes<HTMLButtonElement>) {
return (
<TooltipPrimitive.Trigger asChild>
<Button className={cn('hover:bg-dark-500/30 border border-dark-500/30', className)} {...props} />
</TooltipPrimitive.Trigger>
)
}

TooltipTrigger.displayName = TooltipPrimitive.Trigger

const TooltipContent = React.forwardRef<
React.ElementRef<typeof TooltipPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Content>
>(({ className, sideOffset = 4, ...props }, ref) => (
<TooltipPrimitive.Content
ref={ref}
sideOffset={sideOffset}
className={cn(
'z-50 overflow-hidden rounded-md border border-dark-500 bg-dark-900/100 px-3 py-1.5 text-sm text-popover-foreground shadow-md',
className,
)}
{...props}
/>
))
TooltipContent.displayName = TooltipPrimitive.Content.displayName

export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider }
1 change: 1 addition & 0 deletions packages/react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ export * from './components/separator'
export * from './components/checkbox'
export * from './components/scroll-area'
export * from './components/menu'
export * from './components/tooltip'
35 changes: 35 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 23c70d2

Please sign in to comment.