Skip to content
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
3 changes: 3 additions & 0 deletions src/packages/avatar/avatar.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
background: '#eee',
color: '#666',
fit: 'cover',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以不要直接删除,先加一个 待废弃 标志吧~~

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好啦~

mode: 'scaleToFill',
src: '',
alt: '',
avatarIndex: 0,
Expand All @@ -40,6 +41,7 @@
color,
src,
icon,
mode,
fit,
avatarIndex,
className,
Expand Down Expand Up @@ -104,7 +106,7 @@
) {
setShowMax(true)
}
}, [avatarIndex, groupCount])

Check warning on line 109 in src/packages/avatar/avatar.taro.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useEffect has a missing dependency: 'groupMax'. Either include it or remove the dependency array

const errorEvent = () => {
onError && onError()
Expand All @@ -130,6 +132,7 @@
className={`nut-avatar-img nut-avatar-${groupSize || size || 'normal'}-img`}
src={src}
style={{ objectFit: fit }}
mode={mode}
onError={errorEvent}
/>
)}
Expand Down
6 changes: 6 additions & 0 deletions src/packages/avatar/demo.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Demo6 from './demos/taro/demo6'
import Demo7 from './demos/taro/demo7'
import Demo8 from './demos/taro/demo8'
import Demo9 from './demos/taro/demo9'
import Demo10 from './demos/taro/demo10'

const AvatarDemo = () => {
const [translated] = useTranslate({
Expand All @@ -26,6 +27,7 @@ const AvatarDemo = () => {
f645fc65: '组合头像可控制层级方向',
'43f00872': '点击头像触发事件',
f645fc66: '列表展示',
imageMode: '图片填充模式',
},
'zh-TW': {
'67f78db5': '支持三種尺寸:small、normal、large',
Expand All @@ -37,6 +39,7 @@ const AvatarDemo = () => {
f645fc65: '組合頭像可控制層級方向',
'43f00872': '點擊頭像觸發事件',
f645fc66: '列表展示',
imageMode: '圖片填充模式',
},
'en-US': {
'67f78db5': 'Support three sizes: small, normal, large',
Expand All @@ -49,6 +52,7 @@ const AvatarDemo = () => {
f645fc65: 'Combining avatars to control hierarchy direction',
'43f00872': 'Click on the avatar to trigger the event',
f645fc66: 'list',
imageMode: 'Image fill mode',
},
})

Expand Down Expand Up @@ -76,6 +80,8 @@ const AvatarDemo = () => {
<Demo8 />
<View className="h2">{translated.f645fc66}</View>
<Demo9 />
<View className="h2">{translated.imageMode}</View>
<Demo10 />
</ScrollView>
</>
)
Expand Down
16 changes: 16 additions & 0 deletions src/packages/avatar/demos/taro/demo10.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react'
import { Avatar, Cell } from '@nutui/nutui-react-taro'

const Demo10 = () => {
const src =
'https://storage.360buyimg.com/imgtools/e067cd5b69-07c864c0-dd02-11ed-8b2c-d7f58b17086a.png'
return (
<Cell>
<Avatar src={src} mode="scaleToFill" style={{ marginRight: 10 }} />
<Avatar src={src} mode="aspectFit" style={{ marginRight: 10 }} />
<Avatar src={src} mode="aspectFill" style={{ marginRight: 10 }} />
<Avatar src={src} mode="widthFix" />
</Cell>
)
}
export default Demo10
11 changes: 10 additions & 1 deletion src/packages/avatar/doc.taro.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ Icon 和字符型可以自定义图标颜色及背景色

:::

### 图片填充模式

:::demo

<CodeBlock src='taro/demo10.tsx'></CodeBlock>

:::

## Avatar

### Props
Expand All @@ -101,8 +109,9 @@ Icon 和字符型可以自定义图标颜色及背景色
| background | 设置 Icon、字符类型头像的背景色 | `string` | `#eee` |
| color | 设置 Icon、字符类型头像的颜色 | `string` | `#666` |
| src | 设置图片类型头像的地址 | `string` | `-` |
| mode | 图片裁剪、缩放模式,同 Taro Image 的 mode 属性 | `scaleToFill` \| `aspectFit` \| `aspectFill` \| `widthFix` \| `heightFix` \| `top` \| `bottom` \| `center` \| `left` \| `right` \| `top left` \| `top right` \| `bottom left` \| `bottom right` | `scaleToFill` |
| icon | 设置 Icon 类型头像图标 | `ReactNode` | `-` |
| onClick | 点击头像触发事件 | `(e: MouseEvent<HTMLDivElement>) => void` | `-` |
| onClick | 点击头像触发事件 | `(e: ITouchEvent) => void` | `-` |
| onError | 图片加载失败的事件 | `() => void` | `-` |

## Avatar.Group
Expand Down
8 changes: 7 additions & 1 deletion src/types/spec/avatar/taro.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { ITouchEvent } from '@tarojs/components'
import { ITouchEvent, ImageProps } from '@tarojs/components'
import { BaseAvatar, BaseAvatarGroup } from './base'

export interface TaroAvatarProps extends Omit<BaseAvatar, 'onClick'> {
avatarIndex: number
/** 图片裁剪、缩放的模式,同 Taro Image 的 mode 属性 */
mode: keyof ImageProps.Mode
/**
* @deprecated 请使用 mode 属性代替
*/
fit: BaseAvatar['fit']
onClick: (e: ITouchEvent) => void
}

Expand Down
Loading