-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
feat: popover component & new topic actions layout #580
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d331c4d
feat: PopOver component
y-young 69fb19b
refactor: update topic actions design
y-young a81fe54
fix: add ComponentActions tests & fix old tests
y-young 9398f09
fix: build
y-young 835f917
fix: e2e test
y-young 141636d
fix: hide actions when not logged in
y-young 4acd5f7
fix: update snapshot
y-young e02cc5b
fix: remove useless entry file
y-young a525b3f
fix: hide separate line when not logged in
y-young 4da9877
Merge branch 'master' into fix/topic-actions
trim21 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
绝交是啥功能 (bgm38) (不是代码问题,纯好奇)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
啊?就是原站的拉黑功能啊
https://bgm.tv/settings/privacy