-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
275 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Button } from '../Button'; | ||
|
||
import { Popover, PopoverTrigger, PopoverContent } from '.'; | ||
|
||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { cn } from '@/libs/utils'; | ||
|
||
const meta: Meta<typeof Popover> = { | ||
component: Popover, | ||
parameters: { | ||
layout: 'centered', | ||
}, | ||
tags: ['autodocs'], | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof Popover>; | ||
|
||
export const Default: Story = { | ||
render: () => ( | ||
<Popover> | ||
<PopoverTrigger>Popover</PopoverTrigger> | ||
<PopoverContent>Content</PopoverContent> | ||
</Popover> | ||
), | ||
}; | ||
|
||
export const WithButton: Story = { | ||
render: () => ( | ||
<Popover> | ||
<PopoverTrigger asChild> | ||
<Button>Popover</Button> | ||
</PopoverTrigger> | ||
<PopoverContent className={cn('text-white', 'bg-black')}> | ||
Content | ||
</PopoverContent> | ||
</Popover> | ||
), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { render } from '@testing-library/react'; | ||
|
||
import '@testing-library/jest-dom'; | ||
import { Popover, PopoverTrigger, PopoverContent } from '.'; | ||
|
||
describe('ui/Popoverのテスト', () => { | ||
it('renders trigger text correctly', () => { | ||
const triggerText = 'Trigger'; | ||
const screen = render( | ||
<Popover> | ||
<PopoverTrigger>{triggerText}</PopoverTrigger> | ||
<PopoverContent>Content</PopoverContent> | ||
</Popover> | ||
); | ||
|
||
expect(screen.getByText(triggerText)).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders content correctly', () => { | ||
const content = 'Content'; | ||
const screen = render( | ||
<Popover open> | ||
<PopoverTrigger>Trigger</PopoverTrigger> | ||
<PopoverContent>{content}</PopoverContent> | ||
</Popover> | ||
); | ||
|
||
expect(screen.getByText(content)).toBeInTheDocument(); | ||
}); | ||
|
||
it('not renders content by default', () => { | ||
const content = 'Content'; | ||
const screen = render( | ||
<Popover> | ||
<PopoverTrigger>Trigger</PopoverTrigger> | ||
<PopoverContent>{content}</PopoverContent> | ||
</Popover> | ||
); | ||
|
||
expect(() => screen.getByText(content)).toThrow(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use client'; | ||
|
||
import { forwardRef } from 'react'; | ||
|
||
import * as PopoverPrimitive from '@radix-ui/react-popover'; | ||
|
||
import { cn } from '@/libs/utils'; | ||
|
||
const Popover = PopoverPrimitive.Root; | ||
|
||
const PopoverTrigger = PopoverPrimitive.Trigger; | ||
|
||
const PopoverContent = forwardRef< | ||
React.ElementRef<typeof PopoverPrimitive.Content>, | ||
React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Content> | ||
>(({ className, align = 'center', sideOffset = 4, ...props }, ref) => ( | ||
<PopoverPrimitive.Portal> | ||
<PopoverPrimitive.Content | ||
ref={ref} | ||
align={align} | ||
sideOffset={sideOffset} | ||
className={cn( | ||
'z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2', | ||
className | ||
)} | ||
{...props} | ||
/> | ||
</PopoverPrimitive.Portal> | ||
)); | ||
PopoverContent.displayName = PopoverPrimitive.Content.displayName; | ||
|
||
export { Popover, PopoverTrigger, PopoverContent }; |