Skip to content

Commit

Permalink
feat: Add @packages/ui/Tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
kumanoayumi committed Oct 10, 2024
1 parent 6330f56 commit f97a20f
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 0 deletions.
4 changes: 4 additions & 0 deletions frontend/apps/service-site/src/styles/variables.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@
calc(2 * var(--default-page-margin))
);
--default-header-height: 64px;
--z-index-popup-button: 10;
--z-index-toast: 100;
--z-index-hover-card: 2;
--z-index-tooltip: 200;
}
25 changes: 25 additions & 0 deletions frontend/packages/ui/src/components/Tooltip/Tooltip.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.content {
z-index: var(--z-index-tooltip);
padding: var(--spacing-1half) var(--spacing-1);
font-size: var(--font-size-1);
color: var(--tooltip-foreground);
background-color: var(--tooltip-background);
border: 1px solid var(--tooltip-border);
border-radius: var(--border-radius-sm);
animation-duration: 150ms;
animation-timing-function: var(--default-timing-function);
}

.content[data-state='delayed-open'] {
animation-name: fadeIn;
}

@keyframes fadeIn {
from {
opacity: 0;
}

to {
opacity: 1;
}
}
32 changes: 32 additions & 0 deletions frontend/packages/ui/src/components/Tooltip/Tooltip.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { Meta, StoryObj } from '@storybook/react'
import {
TooltipContent,
TooltipPortal,
TooltipProvider,
TooltipRoot,
TooltipTrigger,
} from './Tooltip'

const StoryComponent = () => {
return (
<TooltipProvider>
<TooltipRoot>
<TooltipTrigger asChild>
<span>Hover me</span>
</TooltipTrigger>
<TooltipPortal>
<TooltipContent sideOffset={5}>Add to library</TooltipContent>
</TooltipPortal>
</TooltipRoot>
</TooltipProvider>
)
}

const meta = {
component: StoryComponent,
} satisfies Meta<typeof StoryComponent>

export default meta
type Story = StoryObj<typeof meta>

export const Default: Story = {}
31 changes: 31 additions & 0 deletions frontend/packages/ui/src/components/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* eslint-disable no-restricted-imports */
import {
Content,
Portal,
Provider,
Root,
Trigger,
} from '@radix-ui/react-tooltip'
import {
type ComponentProps,
type FC,
type PropsWithChildren,
forwardRef,
} from 'react'
import styles from './Tooltip.module.css'

export const TooltipContent = forwardRef<
HTMLDivElement,
ComponentProps<typeof Content>
>((props, ref) => {
return <Content {...props} ref={ref} className={styles.content} />
})

TooltipContent.displayName = 'TooltipContent'

export const TooltipProvider: FC<PropsWithChildren> = ({ children }) => {
return <Provider delayDuration={100}>{children}</Provider>
}
export const TooltipPortal = Portal
export const TooltipRoot = Root
export const TooltipTrigger = Trigger
1 change: 1 addition & 0 deletions frontend/packages/ui/src/components/Tooltip/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './Tooltip'
1 change: 1 addition & 0 deletions frontend/packages/ui/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './DropdownMenu'
export * from './Tooltip'

0 comments on commit f97a20f

Please sign in to comment.