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(Empty): add empty component #2817

Merged
merged 24 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d5033b0
feat(empty): add empty component
ZWkang Mar 28, 2024
2a17dd8
feat(empty): 增加 empty component 使用默认预设值,增加样式
ZWkang Jul 1, 2024
a2f7299
feat(empty): props className
ZWkang Jul 1, 2024
c4bae07
fix: empty wrapper class
ZWkang Jul 1, 2024
f6415ff
fix(empty): update name -> prefix
ZWkang Jul 1, 2024
8059207
Merge branch 'develop' into feature/react-empty-component
ZWkang Aug 8, 2024
c7c2a1f
docs(empty): add empty example
ZWkang Aug 8, 2024
56cef30
docs(empty): update docs example
HaixingOoO Aug 11, 2024
2246e5a
test(empty): update test snap
HaixingOoO Aug 11, 2024
7494fcb
chore: update snapshot
github-actions[bot] Aug 11, 2024
50cc97c
chore: update site route
Aug 12, 2024
5510bd3
test: update test snapshot
Aug 12, 2024
9f854ef
chore(empty): update ConfigProvider and i18n
HaixingOoO Aug 12, 2024
bf7521d
chore: update snapshot
github-actions[bot] Aug 12, 2024
ec6de9e
docs(empty): update ConfigProvider
liweijie0812 Aug 13, 2024
204b38b
docs(config-provider): delete ConfigProvider attach message
HaixingOoO Aug 13, 2024
d5dd983
chore(config-provider): delete attach message type
HaixingOoO Aug 13, 2024
a11d243
chore: add size api
Aug 21, 2024
9cdd8d8
chore: add size api
Aug 21, 2024
72b12a8
chore(empty): update type and md
HaixingOoO Aug 21, 2024
f59b924
chore(empty): update _common
HaixingOoO Aug 21, 2024
6c31467
Merge branch 'develop' of github.com:Tencent/tdesign-react into zw-up…
uyarn Aug 21, 2024
42593f1
chore: update snapshot
github-actions[bot] Aug 21, 2024
c029f20
chore: update common
Aug 22, 2024
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
8 changes: 8 additions & 0 deletions site/site.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,14 @@ export const docs = [
component: () => import('tdesign-react/descriptions/descriptions.md'),
componentEn: () => import('tdesign-react/descriptions/descriptions.en-US.md'),
},
{
title: 'Empty 空状态',
titleEn: 'Empty',
name: 'Empty',
path: '/react/components/empty',
component: () => import('tdesign-react/empty/empty.md'),
componentEn: () => import('tdesign-react/empty/empty.en-US.md'),
},
{
title: 'Image 图片',
titleEn: 'Image',
Expand Down
4 changes: 2 additions & 2 deletions src/auto-complete/_example/option.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const TEXTS = ['第一个默认联想词', '第二个默认联想词', '第三
const AutoCompleteOption = () => {
const [value, setValue] = useState('');

const options = TEXTS.map(text => ({
const options = TEXTS.map((text) => ({
text,
label: (
<div className="custom-option">
Expand All @@ -42,7 +42,7 @@ const AutoCompleteOption = () => {
<small className="description">这是关于联想词的描述,使用 label 渲染</small>
</div>
</div>
)
),
}));

useEffect(() => {
Expand Down
9 changes: 2 additions & 7 deletions src/auto-complete/_example/size.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,15 @@ const AutoCompleteSize = () => {
const [value3, setValue3] = useState('');

return (
<Space direction='vertical' style={{ width: '100%' }}>
<Space direction="vertical" style={{ width: '100%' }}>
<AutoComplete
value={value1}
options={options}
onChange={setValue1}
size="small"
inputProps={{ label: '小尺寸:' }}
/>
<AutoComplete
value={value2}
options={options}
onChange={setValue2}
inputProps={{ label: '中尺寸:' }}
/>
<AutoComplete value={value2} options={options} onChange={setValue2} inputProps={{ label: '中尺寸:' }} />
<AutoComplete
value={value3}
options={options}
Expand Down
2 changes: 1 addition & 1 deletion src/auto-complete/_example/status.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const AutoCompleteStatus = () => {
const [value, setValue] = useState('');

return (
<Space direction='vertical' style={{ width: '100%' }} size="32px">
<Space direction="vertical" style={{ width: '100%' }} size="32px">
<AutoComplete
value={value}
options={options}
Expand Down
33 changes: 25 additions & 8 deletions src/avatar/_example/size.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,31 @@ export default function SizeAvatar() {
</Avatar>
</Space>
<Space align="center">
<Avatar alt='test' image="https://tdesign.gtimg.com/site/avatar.jpg" shape="round" size="small" style={{ marginRight: '40px' }}>
</Avatar>
<Avatar image="https://tdesign.gtimg.com/site/avatar.jpg" shape="round" size="medium" style={{ marginRight: '40px' }}>
</Avatar>
<Avatar image="https://tdesign.gtimg.com/site/avatar.jpg" shape="round" size="large" style={{ marginRight: '40px' }}>
</Avatar>
<Avatar image="https://tdesign.gtimg.com/site/avatar.jpg" shape="round" size="100px" style={{ marginRight: '40px' }}>
</Avatar>
<Avatar
alt="test"
image="https://tdesign.gtimg.com/site/avatar.jpg"
shape="round"
size="small"
style={{ marginRight: '40px' }}
></Avatar>
<Avatar
image="https://tdesign.gtimg.com/site/avatar.jpg"
shape="round"
size="medium"
style={{ marginRight: '40px' }}
></Avatar>
<Avatar
image="https://tdesign.gtimg.com/site/avatar.jpg"
shape="round"
size="large"
style={{ marginRight: '40px' }}
></Avatar>
<Avatar
image="https://tdesign.gtimg.com/site/avatar.jpg"
shape="round"
size="100px"
style={{ marginRight: '40px' }}
></Avatar>
</Space>
</Space>
);
Expand Down
8 changes: 7 additions & 1 deletion src/collapse/_example/other.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ export default function CollapseExample() {
const [showIcon, setShowIcon] = useState(true);
return (
<Space direction="vertical">
<Collapse expandIcon={showIcon} value={collapseValue} borderless={borderless} disabled={disabledAll} onChange={setCollapseValue}>
<Collapse
expandIcon={showIcon}
value={collapseValue}
borderless={borderless}
disabled={disabledAll}
onChange={setCollapseValue}
>
<Panel header="这是一个折叠标题">
这部分是每个折叠面板折叠或展开的内容,可根据不同业务或用户的使用诉求,进行自定义填充。可以是纯文本、图文、子列表等内容形式。
</Panel>
Expand Down
4 changes: 3 additions & 1 deletion src/comment/_example/reply-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export default function BasicComment() {
const replyForm = (
<Space direction="vertical" align="end" style={{ width: '100%' }}>
<Textarea placeholder="请输入内容" value={replyData} onChange={setReplayData} />
<Button style={{ float: 'right' }} onClick={submitReply}>回复</Button>
<Button style={{ float: 'right' }} onClick={submitReply}>
回复
</Button>
</Space>
);

Expand Down
2 changes: 1 addition & 1 deletion src/dialog/_example/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function PluginModalExample() {
},
onCloseBtnClick: ({ e }) => {
console.log('close btn: ', e);
}
},
});
};
const handleDN = () => {
Expand Down
8 changes: 2 additions & 6 deletions src/dropdown/_example/click.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import React from 'react';
import {
Dropdown, Button, MessagePlugin,
} from 'tdesign-react';
import { Dropdown, Button, MessagePlugin } from 'tdesign-react';

export default function BasicDropdown() {
const getContent = () => <div>操作四</div>;
Expand Down Expand Up @@ -29,9 +27,7 @@ export default function BasicDropdown() {
];
return (
<Dropdown options={options}>
<Button>
hover我试试
</Button>
<Button>hover我试试</Button>
</Dropdown>
);
}
115 changes: 115 additions & 0 deletions src/empty/Empty.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import React, { isValidElement, type ReactNode } from 'react';
import cls from 'classnames';
import { isObject, isString } from 'lodash';
HaixingOoO marked this conversation as resolved.
Show resolved Hide resolved
import useDefaultProps from '../hooks/useDefaultProps';
import { emptyDefaultProps } from './defaultProps';
import { TdEmptyProps } from './type';
import Image from '../image';
import { StyledProps } from '../common';
import useConfig from '../hooks/useConfig';

import MaintenanceSvg from './assets/MaintenanceSvg';
import NetworkErrorSvg from './assets/NetworkErrorSvg';
import EmptySvg from './assets/EmptySvg';
import FailSvg from './assets/FailSvg';
import SuccessSvg from './assets/SuccessSvg';

export type EmptyProps = TdEmptyProps & StyledProps;

function getImageIns(data: EmptyProps['image']) {
let result = data;
if (isValidElement(data)) {
result = data;
} else if (isObject(data)) {
result = <Image {...(data as any)} />;
} else if (isString(data)) {
result = <Image src={data} />;
}

return data ? (result as ReactNode) : null;
}

const defaultMaps: {
[key in EmptyProps['type']]?: Pick<EmptyProps, 'image' | 'title'>;
} = {
maintenance: {
image: <MaintenanceSvg />,
title: '建设中',
HaixingOoO marked this conversation as resolved.
Show resolved Hide resolved
},
success: {
image: <SuccessSvg />,
title: '成功',
},
fail: {
image: <FailSvg />,
title: '失败',
},
'network-error': {
image: <NetworkErrorSvg />,
title: '网络错误',
},
empty: {
image: <EmptySvg />,
title: '暂无数据',
},
};

const Empty = (props: EmptyProps) => {
const {
image: propsImage,
imageStyle,
description: propsDescription,
title: propsTitle,
type,
action,
style,
className,
} = useDefaultProps(props, emptyDefaultProps);
const { classPrefix } = useConfig();

const prefix = `${classPrefix}-empty`;
const emptyClasses = cls(prefix, className);
const titleClasses = cls(`${prefix}__title`);
const imageClasses = cls(`${prefix}__image`);
const descriptionClasses = cls(`${prefix}__description`);
const actionCls = cls(`${prefix}__action`);

const typeImageProps = defaultMaps[type] ?? null;

const { image, description, title } = {
image: propsImage ? propsImage : typeImageProps?.image ?? null,
title: propsTitle ? propsTitle : typeImageProps?.title ?? null,
description: propsDescription,
};

function renderTitle() {
if (!title) {
return null;
}
return <div className={titleClasses}>{title}</div>;
}

function renderDescription() {
if (!description) {
return null;
}
return <div className={descriptionClasses}>{description}</div>;
}

const imageContent = getImageIns(image);

return (
<div className={emptyClasses} style={style}>
{imageContent ? (
<div className={imageClasses} style={imageStyle}>
{imageContent}
</div>
) : null}
{renderTitle()}
{renderDescription()}
{action ? <div className={actionCls}>{action}</div> : null}
</div>
);
};

export default Empty;
10 changes: 10 additions & 0 deletions src/empty/_example/base.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import { Empty } from 'tdesign-react';

export default function BasicGrid() {
return (
<>
<Empty type="empty" title="暂无数据" />
</>
);
}
17 changes: 17 additions & 0 deletions src/empty/_example/descriptions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import { Empty, Button } from 'tdesign-react';

export default function Operation() {
function goToIndex() {
console.log('go to index');
location.href = '/';
}
return (
<Empty
type="empty"
action={<Button onClick={goToIndex}>返回首页</Button>}
description="description"
title="暂无数据"
/>
);
}
10 changes: 10 additions & 0 deletions src/empty/_example/operation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import { Empty, Button } from 'tdesign-react';

export default function Operation() {
function goToIndex() {
console.log('go to index');
location.href = '/';
}
return <Empty type="empty" action={<Button onClick={goToIndex}>返回首页</Button>} title="暂无数据" />;
}
26 changes: 26 additions & 0 deletions src/empty/_example/self-defined.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react';
import { Empty, Row, Col } from 'tdesign-react';
import { ErrorCircleIcon } from 'tdesign-icons-react';

export default function BasicGrid() {
const CustomImageContainer = (
<div
style={{
width: '64px',
height: '64px',
backgroundImage: 'url(https://tdesign.gtimg.com/demo/demo-image-1.png)',
backgroundSize: '100% 100%',
}}
/>
);
return (
<Row gutter={40}>
<Col>
<Empty image={<ErrorCircleIcon size={64} color="rgba(0, 0, 0, 0.26)" />} description="暂无数据" />
</Col>
<Col>
<Empty description="暂无数据" image={CustomImageContainer} />
</Col>
</Row>
);
}
24 changes: 24 additions & 0 deletions src/empty/_example/status.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react';
import { Empty, Row, Col } from 'tdesign-react';

export default function StatusExample() {
return (
<Row gutter={40}>
<Col>
<Empty type="empty" />
</Col>
<Col>
<Empty type="maintenance" />
</Col>
<Col>
<Empty type="network-error" />
</Col>
<Col>
<Empty type="success" />
</Col>
<Col>
<Empty type="fail" />
</Col>
</Row>
);
}
Loading
Loading