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(list): #2574 #2583

Merged
merged 1 commit into from
Sep 7, 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
5 changes: 5 additions & 0 deletions .changeset/nasty-students-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/list": patch
---

feat: avatar 支持传入 ReactNode
5 changes: 5 additions & 0 deletions .changeset/tender-yaks-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/hiui": patch
---

List feat: avatar 支持传入 ReactNode
2 changes: 1 addition & 1 deletion packages/ui/list/src/ListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const ListItem: React.FC<ListItemProps> = ({
<div className={cx(`${prefixCls}-item`, className)}>
{avatar && (
<div className={`${prefixCls}-item__avatar`} key="avatar">
<img src={avatar} />
{typeof avatar === 'string' ? <img src={avatar} /> : avatar}
</div>
)}
<div className={`${prefixCls}-item__content`}>
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/list/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ export interface ListDataItem {
*/
extra?: React.ReactNode
/**
* 左侧图片资源地址
* 左侧图片
*/
avatar?: string
avatar?: React.ReactNode
/**
* 右侧操作项
*/
Expand Down
48 changes: 48 additions & 0 deletions packages/ui/list/stories/avatar.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React from 'react'
import List from '../src'
import AvatarComp from '@hi-ui/avatar'

/**
* @title 自定义头像
*/
export const Avatar = () => {
return (
<>
<h1>Avatar</h1>
<div className="list-avatar__wrap">
<List
data={[
{
title: '下单量-指标',
description: '下单量在交易环节中整体用户下单的数量',
extra: '最新使用:2019.12.23 下午07:07',
avatar:
'https://cdn.cnbj1.fds.api.mi-img.com/hiui-template/resources/images/HiUI/logo.png',
action: '编辑',
},
{
title: '下单量-指标',
description: '下单量在交易环节中整体用户下单的数量',
extra: '最新使用:2019.12.23 下午07:07',
avatar:
'https://cdn.cnbj1.fds.api.mi-img.com/hiui-template/resources/images/HiUI/logo.png',
action: '编辑',
},
]}
render={(dataItem) => {
console.log('dataItem', dataItem)

const { avatar, ...rest } = dataItem

return (
<List.Item
{...rest}
avatar={<AvatarComp size={'lg'} shape={'square'} src={avatar as string} />}
/>
)
}}
/>
</div>
</>
)
}
1 change: 1 addition & 0 deletions packages/ui/list/stories/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export * from './no-split.stories'
export * from './action.stories'
export * from './empty.stories'
export * from './no-border.stories'
export * from './avatar.stories'

export default {
title: 'Data Display/List',
Expand Down