Skip to content

Commit

Permalink
fix: 简化逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyatong committed Jul 24, 2024
1 parent fc7b8a9 commit 5518d85
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 53 deletions.
23 changes: 6 additions & 17 deletions src/packages/toast/Notification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,12 @@ export default class Notification extends React.PureComponent<
renderIcon() {
const { icon } = this.props
if (typeof icon === 'string') {
let iconNode = null
switch (icon) {
case 'success':
iconNode = <Check />
break
case 'loading':
iconNode = <Loading className="nut-icon-loading" />
break
case 'fail':
iconNode = <Failure />
break
case 'warn':
iconNode = <Tips />
break
default:
break
}
const iconNode = {
success: <Check />,
fail: <Failure />,
warn: <Tips />,
loading: <Loading className="nut-icon-loading" />,
}[icon]
return <p className={`${classPrefix}-icon-wrapper`}>{iconNode}</p>
}
return icon
Expand Down
18 changes: 0 additions & 18 deletions src/packages/toast/toast.scss
Original file line number Diff line number Diff line change
Expand Up @@ -111,24 +111,6 @@
}
}

&-loading {
.nut-toast-inner {
display: inline-flex;
flex-direction: column;
justify-content: center;
align-items: center;
}

.nut-toast-icon-wrapper {
animation: rotation 2s linear infinite;

.nut-icon {
width: 24px;
height: 24px;
}
}
}

&-rtl {
left: auto;
right: 0;
Expand Down
33 changes: 16 additions & 17 deletions src/packages/toast/toast.taro.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { FunctionComponent, useEffect, useRef } from 'react'
import Taro from '@tarojs/taro'
import classNames from 'classnames'
import { Text, View } from '@tarojs/components'
import { Failure, Loading, Success, Tips } from '@nutui/icons-react-taro'
Expand All @@ -13,26 +12,27 @@ import {
} from '@/utils/use-custom-event'
import { usePropsValue } from '@/utils/use-props-value'
import { useRtl } from '@/packages/configprovider/index.taro'
import { harmonyAndRn, harmony } from '@/utils/platform-taro'

export type ToastPosition = 'top' | 'bottom' | 'center'
export type ToastSize = 'small' | 'base' | 'large'
export type ToastWordBreak = 'normal' | 'break-all' | 'break-word'

export interface ToastProps extends BasicComponent {
id?: string
maskClassName?: string
contentClassName?: string
contentStyle?: React.CSSProperties
icon: React.ReactNode
iconSize: string
content: React.ReactNode
duration: number
position?: ToastPosition
type: string
title: string
closeOnOverlayClick: boolean
lockScroll: boolean
size: ToastSize
icon: React.ReactNode
iconSize: string
maskClassName?: string
content: React.ReactNode
contentClassName?: string
contentStyle?: React.CSSProperties
type: string
visible: boolean
wordBreak?: ToastWordBreak
onClose: () => void
Expand All @@ -45,18 +45,18 @@ export interface ToastProps extends BasicComponent {
const defaultProps = {
...ComponentDefaults,
id: '',
duration: 2, // 时长,duration为0则一直展示
position: 'center',
title: '',
size: 'base', // 设置字体大小,默认base,可选large\small\base
icon: null,
iconSize: '20',
content: '',
msg: '',
duration: 2, // 时长,duration为0则一直展示
position: 'center',
type: 'text',
title: '',
closeOnOverlayClick: false,
lockScroll: false,
contentClassName: '', // 内容自定义样式名
size: 'base', // 设置字体大小,默认base,可选large\small\base
visible: false,
wordBreak: 'break-all',
onClose: () => {}, // 未实现
Expand Down Expand Up @@ -166,7 +166,7 @@ export const Toast: FunctionComponent<
return icon
}

return Taro.getEnv() !== 'RN' && Taro.getEnv() !== 'HARMONY'
return !harmonyAndRn()
? {
success: <Success color="#ffffff" size={iconSize} />,
fail: <Failure color="#ffffff" size={iconSize} />,
Expand All @@ -186,10 +186,9 @@ export const Toast: FunctionComponent<
'nut-toast-rtl': rtl,
})

const styles =
Taro.getEnv() === 'HARMONY'
? { left: '50%', transform: 'translate(-50%, -50%)' }
: null
const styles = harmony()
? { left: '50%', transform: 'translate(-50%, -50%)' }
: null

return (
<>
Expand Down
2 changes: 1 addition & 1 deletion src/packages/toast/toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ let options: ToastProps = {
title: '',
size: 'base', // 设置字体大小,默认base,可选large\small\base
icon: null,
onClose: () => {},
closeOnOverlayClick: false, // 是否点击遮罩可关闭
lockScroll: false,
contentClassName: '',
wordBreak: 'break-all',
onClose: () => {},
}

function getInstance(
Expand Down

0 comments on commit 5518d85

Please sign in to comment.