-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: popover component & new topic actions layout (#580)
- Loading branch information
Showing
24 changed files
with
1,309 additions
and
276 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { Meta, StoryFn } from '@storybook/react'; | ||
import React from 'react'; | ||
|
||
import Button from '../Button'; | ||
import type { PopoverProps } from '.'; | ||
import Popover from '.'; | ||
|
||
const storyMeta: Meta<typeof Popover> = { | ||
title: 'modern/Popover', | ||
component: Popover, | ||
}; | ||
|
||
export default storyMeta; | ||
|
||
const Template: StoryFn<PopoverProps> = (args) => { | ||
return <Popover {...args} />; | ||
}; | ||
|
||
export const Default = Template.bind({}); | ||
Default.args = { | ||
content: <div style={{ padding: 30 }}>Popover content</div>, | ||
children: <Button>Popover</Button>, | ||
}; |
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,24 @@ | ||
import './style/index.less'; | ||
|
||
import classNames from 'classnames'; | ||
import React from 'react'; | ||
|
||
export interface PopoverProps { | ||
content: React.ReactNode; | ||
children: React.ReactNode; | ||
className?: string; | ||
} | ||
|
||
const Popover = ({ children, content, className }: PopoverProps) => { | ||
return ( | ||
<div className={classNames('bgm-popover', className)}> | ||
{children} | ||
{/* 添加一个wrapper使绝对定位元素能够水平居中 */} | ||
<div className='bgm-popover__container'> | ||
<div className='bgm-popover__content'>{content}</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default 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,29 @@ | ||
@import '../../../theme/base.less'; | ||
|
||
.bgm-popover { | ||
display: inline-block; | ||
|
||
&__container { | ||
position: relative; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
} | ||
|
||
&__content { | ||
border: 1px solid @gray-10; | ||
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.05); | ||
background-color: white; | ||
border-radius: 17px; | ||
position: absolute; | ||
visibility: hidden; | ||
opacity: 0; | ||
transition: visibility 0s, opacity 0.15s linear; | ||
z-index: 99; | ||
} | ||
|
||
&:hover &__content { | ||
visibility: visible; | ||
opacity: 1; | ||
} | ||
} |
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
51 changes: 51 additions & 0 deletions
51
packages/design/components/Topic/CommentActions.stories.tsx
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,51 @@ | ||
import type { StoryFn } from '@storybook/react'; | ||
import React from 'react'; | ||
import { BrowserRouter } from 'react-router-dom'; | ||
|
||
import type { CommentActionsProps } from './CommentActions'; | ||
import CommentActions from './CommentActions'; | ||
|
||
export default { | ||
title: 'Topic/CommentActions', | ||
component: CommentActions, | ||
}; | ||
|
||
const Template: StoryFn<CommentActionsProps> = (args) => { | ||
return ( | ||
<BrowserRouter> | ||
<CommentActions {...args} id={375793} /> | ||
</BrowserRouter> | ||
); | ||
}; | ||
|
||
export const Basic = Template.bind({}); | ||
|
||
export const WithText = Template.bind({}); | ||
WithText.args = { | ||
showText: true, | ||
}; | ||
|
||
export const IsAuthor = Template.bind({}); | ||
IsAuthor.args = { | ||
isAuthor: true, | ||
}; | ||
IsAuthor.parameters = { | ||
docs: { | ||
description: { | ||
story: '显示编辑和删除按钮', | ||
}, | ||
}, | ||
}; | ||
|
||
export const NonEditable = Template.bind({}); | ||
NonEditable.args = { | ||
isAuthor: true, | ||
editable: false, | ||
}; | ||
NonEditable.parameters = { | ||
docs: { | ||
description: { | ||
story: '显示删除按钮,但隐藏编辑按钮,例如有子回复时', | ||
}, | ||
}, | ||
}; |
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,62 @@ | ||
import React from 'react'; | ||
|
||
import { Comment as CommentIcon, More } from '@bangumi/icons'; | ||
|
||
import Button from '../../components/Button'; | ||
import Popover from '../Popover'; | ||
|
||
export interface CommentActionsProps { | ||
id: number; | ||
onReply?: () => void; | ||
onDelete?: () => void; | ||
isAuthor?: boolean; | ||
editable?: boolean; | ||
showText?: boolean; | ||
} | ||
|
||
const CommentActions = ({ | ||
id, | ||
onReply, | ||
onDelete, | ||
isAuthor = false, | ||
editable = true, | ||
showText = false, | ||
}: CommentActionsProps) => { | ||
return ( | ||
<div className='bgm-comment-actions'> | ||
<Button type='plain' size='small' onClick={onReply} title='回复'> | ||
<CommentIcon /> | ||
{showText && '回复'} | ||
</Button> | ||
{/* TODO: 实现贴贴功能 */} | ||
<Popover | ||
content={ | ||
<div className='bgm-comment-actions__popover'> | ||
{isAuthor && ( | ||
<> | ||
{editable && ( | ||
<Button.Link type='text' size='small' to={`/group/reply/${id}/edit`}> | ||
编辑 | ||
</Button.Link> | ||
)} | ||
<Button type='text' size='small' onClick={onDelete}> | ||
删除 | ||
</Button> | ||
</> | ||
)} | ||
{/* TODO: 实现绝交和报告疑虑功能 */} | ||
<Button type='text'>绝交</Button> | ||
<Button type='text'>报告疑虑</Button> | ||
</div> | ||
} | ||
> | ||
<Button type='plain' size='small' className='bgm-comment-actions__more' title='其他'> | ||
<More /> | ||
{showText && '其他'} | ||
</Button> | ||
</Popover> | ||
</div> | ||
); | ||
}; | ||
|
||
export default CommentActions; |
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
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
37 changes: 37 additions & 0 deletions
37
packages/design/components/Topic/__test__/CommentActions.spec.tsx
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,37 @@ | ||
import { render as _render } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { BrowserRouter } from 'react-router-dom'; | ||
|
||
import type { CommentActionsProps } from '../CommentActions'; | ||
import CommentActions from '../CommentActions'; | ||
|
||
const render = (props: CommentActionsProps) => | ||
_render( | ||
<BrowserRouter> | ||
<CommentActions {...props} /> | ||
</BrowserRouter>, | ||
); | ||
|
||
describe('Basic Usage', () => { | ||
it('should render', () => { | ||
expect(render({ id: 233 })).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
describe('With Text', () => { | ||
it('should render', () => { | ||
expect(render({ id: 233, showText: true })).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
describe('Is Author', () => { | ||
it('should render', () => { | ||
expect(render({ id: 233, isAuthor: true })).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
describe('Non-editable', () => { | ||
it('should render', () => { | ||
expect(render({ id: 233, isAuthor: true, editable: false })).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.