Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Popup): add closeOnSwipe prop #6203

Merged
merged 2 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components/popup/index.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ It is suitable for displaying pop-up windows, information prompts, selection inp
| stopPropagation | Stop the propagation of some events. | `PropagationEvent[]` | `['click']` |
| style | Container style | `React.CSSProperties` | - |
| visible | Whether visible | `boolean` | `false` |
| closeOnSwipe | Whether to support closing by swiping up/down | `boolean` | `false` |

### CSS Variables

Expand Down
1 change: 1 addition & 0 deletions src/components/popup/index.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
| stopPropagation | 阻止某些事件的冒泡 | `PropagationEvent[]` | `['click']` |
| style | 容器样式 | `React.CSSProperties` | - |
| visible | 是否可见 | `boolean` | `false` |
| closeOnSwipe | 是否支持向上/下滑动关闭 | `boolean` | `false` |

### CSS 变量

Expand Down
3 changes: 3 additions & 0 deletions src/components/popup/popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ const classPrefix = `adm-popup`
export type PopupProps = PopupBaseProps &
PropsWithChildren<{
position?: 'bottom' | 'top' | 'left' | 'right'
closeOnSwipe?: boolean
}> &
NativeProps<'--z-index'>

const defaultProps = {
...defaultPopupBaseProps,
closeOnSwipe: false,
position: 'bottom',
}

Expand Down Expand Up @@ -70,6 +72,7 @@ export const Popup: FC<PopupProps> = p => {

const bind = useDrag(
({ swipe: [, swipeY] }) => {
if (!props.closeOnSwipe) return
if (
(swipeY === 1 && props.position === 'bottom') ||
(swipeY === -1 && props.position === 'top')
Expand Down
6 changes: 3 additions & 3 deletions src/components/popup/tests/popup.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as React from 'react'
import { render, cleanup, fireEvent, mockDrag } from 'testing'
import { render, mockDrag } from 'testing'
import Popup from '..'

describe('Popup', () => {
test('top swipe should be closed', () => {
const onClose = jest.fn()
render(
<Popup visible={true} onClose={onClose} position='top'>
<Popup visible onClose={onClose} position='top' closeOnSwipe>
<div style={{ height: '400px', width: '400px' }}></div>
</Popup>
)
Expand All @@ -26,7 +26,7 @@ describe('Popup', () => {
test('bottom swipe should be closed', () => {
const onClose = jest.fn()
render(
<Popup visible={true} onClose={onClose} position='bottom'>
<Popup visible onClose={onClose} position='bottom' closeOnSwipe>
<div style={{ height: '400px', width: '400px' }}></div>
</Popup>
)
Expand Down