-
Notifications
You must be signed in to change notification settings - Fork 277
refactor: fixed overlay zIndex is not effective, and extract types of dialog, overlay, fixednav, popup, toast #2954
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
Changes from 5 commits
257a609
bdf2b44
9bb8d6b
fc0555a
eb09a1d
65a3c5a
2669d02
55922ba
3c4129a
8890392
120b470
ebf76d9
17cdc10
b29b2f1
75f29b3
f5a2030
c1973ca
2c2f9cc
be6a549
faafaaa
cd423cf
ddb072a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,17 +1,20 @@ | ||||||
import React, { FunctionComponent, ReactNode, HTMLAttributes } from 'react' | ||||||
import React, { FunctionComponent, HTMLAttributes } from 'react' | ||||||
import classNames from 'classnames' | ||||||
import { ContentProps } from './types' | ||||||
|
||||||
interface ContentProps { | ||||||
visible: boolean | ||||||
title: ReactNode | ||||||
header: ReactNode | ||||||
footer: ReactNode | ||||||
close: ReactNode | ||||||
footerDirection: string | ||||||
export const defaultContentProps: ContentProps = { | ||||||
visible: false, | ||||||
title: '', | ||||||
header: null, | ||||||
footer: null, | ||||||
close: '', | ||||||
footerDirection: '', | ||||||
onClick: () => {}, | ||||||
} | ||||||
|
||||||
export const Content: FunctionComponent< | ||||||
Partial<ContentProps> & HTMLAttributes<HTMLDivElement> | ||||||
Partial<ContentProps> & | ||||||
Omit<HTMLAttributes<HTMLDivElement>, 'title' | 'content'> | ||||||
> = (props) => { | ||||||
const { | ||||||
visible, | ||||||
|
@@ -22,7 +25,9 @@ export const Content: FunctionComponent< | |||||
footerDirection, | ||||||
onClick, | ||||||
children, | ||||||
} = props | ||||||
style, | ||||||
className, | ||||||
} = { ...defaultContentProps, ...props } | ||||||
|
||||||
const classPrefix = 'nut-dialog' | ||||||
|
||||||
|
@@ -31,15 +36,17 @@ export const Content: FunctionComponent< | |||||
} | ||||||
|
||||||
const renderFooter = () => { | ||||||
return footer ? ( | ||||||
<div | ||||||
className={classNames(`${classPrefix}-footer`, { | ||||||
[footerDirection as any]: footerDirection, | ||||||
})} | ||||||
> | ||||||
{footer} | ||||||
</div> | ||||||
) : null | ||||||
return ( | ||||||
footer && ( | ||||||
<div | ||||||
className={classNames(`${classPrefix}-footer`, { | ||||||
[footerDirection as any]: footerDirection, | ||||||
})} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 类型转换需要改进 使用 建议定义一个明确的类型: - [footerDirection as any]: footerDirection,
+ [footerDirection as 'horizontal' | 'vertical']: footerDirection, 📝 Committable suggestion
Suggested change
|
||||||
> | ||||||
{footer} | ||||||
</div> | ||||||
) | ||||||
) | ||||||
} | ||||||
|
||||||
const handleClick = (e: any) => { | ||||||
|
@@ -48,8 +55,8 @@ export const Content: FunctionComponent< | |||||
|
||||||
return ( | ||||||
<div | ||||||
className={classNames(`${classPrefix}-outer`, props.className)} | ||||||
style={props.style} | ||||||
className={classNames(`${classPrefix}-outer`, className)} | ||||||
style={style} | ||||||
onClick={(e) => handleClick(e)} | ||||||
> | ||||||
{close} | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,8 @@ import { CSSTransition } from 'react-transition-group' | |
import { View } from '@tarojs/components' | ||
import { Failure, Close } from '@nutui/icons-react-taro' | ||
import Button from '@/packages/button/index.taro' | ||
import { DialogBasicProps } from './config' | ||
import { Content } from './content.taro' | ||
import { DialogBasicProps } from './types' | ||
import { Content, defaultContentProps } from './content.taro' | ||
import { useConfig } from '@/packages/configprovider/configprovider.taro' | ||
import Overlay from '@/packages/overlay/index.taro' | ||
import { | ||
|
@@ -15,33 +15,37 @@ import { | |
useCustomEventsPath, | ||
useParams, | ||
} from '@/utils/use-custom-event' | ||
import { BasicComponent } from '@/utils/typings' | ||
import { useLockScrollTaro } from '@/utils/use-lock-scoll-taro' | ||
import { mergeProps } from '@/utils/merge-props' | ||
import { defaultOverlayProps } from '@/packages/overlay/overlay.taro' | ||
|
||
export type DialogProps = DialogBasicProps & BasicComponent | ||
const defaultProps = { | ||
const defaultProps: DialogBasicProps = { | ||
...defaultOverlayProps, | ||
...defaultContentProps, | ||
title: '', | ||
content: '', | ||
header: '', | ||
footer: '', | ||
confirmText: '', | ||
cancelText: '', | ||
overlay: true, | ||
closeOnOverlayClick: true, | ||
overlayStyle: {}, | ||
overlayClassName: 'nut-dialog-overlay', | ||
hideConfirmButton: false, | ||
hideCancelButton: false, | ||
disableConfirmButton: false, | ||
footerDirection: 'horizontal', | ||
lockScroll: true, | ||
closeIconPosition: 'bottom', | ||
closeIcon: false, | ||
zIndex: 1200, | ||
beforeCancel: () => true, | ||
beforeClose: () => true, | ||
onCancel: () => {}, | ||
onClose: () => {}, | ||
onOverlayClick: () => true, | ||
} as DialogProps | ||
} | ||
Comment on lines
+21
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 需要修复类型不匹配问题
建议检查并确保所有必需的属性都已定义,特别是 🧰 Tools🪛 GitHub Check: build[failure] 21-21: 🪛 GitHub Actions: CI[error] 21-21: Type mismatch error: Object type is not assignable to type 'DialogBasicProps'. Check the property types in the dialog component. |
||
|
||
export const BaseDialog: FunctionComponent<Partial<DialogProps>> & { | ||
export const BaseDialog: FunctionComponent<Partial<DialogBasicProps>> & { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 建议优化事件处理和类型定义
建议如下修改: - setParams({ ...options, visible: status })
+ setParams?.({ ...options, visible: status }) Also applies to: 94-94 |
||
open: typeof open | ||
close: typeof close | ||
} = (props) => { | ||
|
@@ -70,8 +74,11 @@ export const BaseDialog: FunctionComponent<Partial<DialogProps>> & { | |
confirmText, | ||
cancelText, | ||
overlay, | ||
overlayStyle, | ||
overlayClassName, | ||
closeIconPosition, | ||
closeIcon, | ||
zIndex, | ||
onClose, | ||
onCancel, | ||
onConfirm, | ||
|
@@ -84,11 +91,7 @@ export const BaseDialog: FunctionComponent<Partial<DialogProps>> & { | |
useCustomEvent( | ||
id as string, | ||
({ status, options }: { status: boolean; options: any }) => { | ||
if (status) { | ||
setParams({ ...options, visible: true }) | ||
} else { | ||
setParams({ ...options, visible: false }) | ||
} | ||
setParams({ ...options, visible: status }) | ||
} | ||
) | ||
const refObject = useLockScrollTaro(!!(visible && lockScroll)) | ||
|
@@ -181,9 +184,9 @@ export const BaseDialog: FunctionComponent<Partial<DialogProps>> & { | |
|
||
const onHandleClickOverlay = (e: any) => { | ||
if (closeOnOverlayClick && visible && e.target === e.currentTarget) { | ||
const closed = onOverlayClick && onOverlayClick() | ||
closed && onClose?.() | ||
closed && onCancel?.() | ||
const closed = onOverlayClick && onOverlayClick(e) | ||
closed && onClose && onClose() | ||
closed && onCancel && onCancel() | ||
} | ||
} | ||
|
||
|
@@ -194,15 +197,17 @@ export const BaseDialog: FunctionComponent<Partial<DialogProps>> & { | |
catchMove={lockScroll} | ||
> | ||
<> | ||
{overlay ? ( | ||
{overlay && ( | ||
<Overlay | ||
zIndex={zIndex} | ||
visible={visible} | ||
style={overlayStyle} | ||
className={overlayClassName} | ||
closeOnOverlayClick={closeOnOverlayClick} | ||
lockScroll={lockScroll} | ||
onClick={onHandleClickOverlay} | ||
className={classNames('nut-dialog-overlay')} | ||
/> | ||
) : null} | ||
)} | ||
|
||
<CSSTransition | ||
in={visible} | ||
|
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.
newConfig 中存在 title 时,无法被覆盖,值一直是 config.title