-
Notifications
You must be signed in to change notification settings - Fork 267
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
fix(empty): actions add support for events #2854
Changes from 2 commits
fb9e2f0
87dff85
1d7077c
d1f496b
3a76df7
8ad602c
995ca6b
b5ffcdf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from 'react' | ||
import { Empty, Toast } from '@nutui/nutui-react' | ||
|
||
const Demo7 = () => { | ||
return ( | ||
<Empty | ||
status="error" | ||
description="加载失败" | ||
style={{ marginBottom: '20px' }} | ||
actions={[ | ||
{ | ||
text: 'Action', | ||
type: 'info', | ||
onClick: () => { | ||
Toast.show({ title: 'Action Click!' }) | ||
}, | ||
}, | ||
]} | ||
/> | ||
) | ||
} | ||
export default Demo7 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from 'react' | ||
import { Empty, Toast } from '@nutui/nutui-react-taro' | ||
|
||
const Demo7 = () => { | ||
return ( | ||
<> | ||
<Toast id="toast-empty" /> | ||
<Empty | ||
status="error" | ||
description="加载失败" | ||
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 建议使用翻译系统替代硬编码文本 建议将 "加载失败" 文本添加到翻译系统中,以支持国际化。 -description="加载失败"
+description={translated.loadFailed}
|
||
style={{ marginBottom: '20px' }} | ||
actions={[ | ||
{ | ||
text: 'Action', | ||
type: 'info', | ||
onClick: () => { | ||
Toast.show('toast-empty', { title: 'Action Click!' }) | ||
}, | ||
}, | ||
]} | ||
/> | ||
</> | ||
) | ||
} | ||
export default Demo7 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,13 @@ | ||
import React from 'react' | ||
import { ButtonFill, ButtonSize, ButtonType } from '@/packages/button' | ||
|
||
export interface EmptyAction { | ||
text: string | ||
text: React.ReactNode | ||
className?: string | ||
style?: React.CSSProperties | ||
type?: ButtonType | ||
size?: ButtonSize | ||
fill?: ButtonFill | ||
disabled?: boolean | ||
onClick?: () => void | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export const getButtonType = (actions, index) => { | ||
Check failure on line 1 in src/packages/empty/utils.ts GitHub Actions / build
|
||
const action = actions[index] | ||
if (!actions || actions.length === 0) return 'default' | ||
if (action.type) return action.type | ||
oasis-cloud marked this conversation as resolved.
Show resolved
Hide resolved
|
||
actions.length > 1 && index === 0 ? 'default' : 'primary' | ||
} | ||
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. 需要修复类型定义和逻辑错误 该函数存在以下问题:
建议按照以下方式修改代码: - export const getButtonType = (actions, index) => {
+ export const getButtonType = (actions: EmptyAction[], index: number): ButtonType => {
+ if (!actions || actions.length === 0) return 'default'
+
+ const action = actions[index]
- const action = actions[index]
- if (!actions || actions.length === 0) return 'default'
if (action.type) return action.type
- actions.length > 1 && index === 0 ? 'default' : 'primary'
+ return actions.length > 1 && index === 0 ? 'default' : 'primary'
}
🧰 Tools🪛 GitHub Check: build[failure] 1-1: [failure] 1-1: |
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.
中文