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

新增Empty组件 #505

Merged
merged 10 commits into from
Sep 18, 2024
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 site/mobile/mobile.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,5 +262,10 @@ export default {
name: 'table',
component: () => import('tdesign-mobile-react/table/_example/index.tsx'),
},
{
title: 'Empty 空状态',
name: 'empty',
component: () => import('tdesign-mobile-react/empty/_example/index.tsx'),
},
],
};
6 changes: 6 additions & 0 deletions site/web/site.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,12 @@ export default {
path: '/mobile-react/components/count-down',
component: () => import('tdesign-mobile-react/count-down/count-down.md'),
},
{
title: 'Empty 空状态',
name: 'empty',
path: '/mobile-react/components/empty',
component: () => import('tdesign-mobile-react/empty/empty.md'),
},
{
title: 'Image 图片',
name: 'image',
Expand Down
2 changes: 1 addition & 1 deletion src/_common
Submodule _common updated 55 files
+27 −27 .github/workflows/pull-request.yml
+47 −0 docs/mobile/api/checkbox.en-US.md
+26 −14 docs/mobile/api/checkbox.md
+12 −0 docs/mobile/api/drawer.md
+23 −0 docs/mobile/api/empty.en-US.md
+23 −0 docs/mobile/api/empty.md
+19 −0 docs/mobile/api/image-viewer.en-US.md
+6 −5 docs/mobile/api/image-viewer.md
+17 −0 docs/mobile/api/indexes.en-US.md
+6 −0 docs/mobile/api/indexes.md
+19 −0 docs/mobile/api/popover.en-US.md
+19 −0 docs/mobile/api/popover.md
+15 −0 docs/mobile/api/pull-down-refresh.en-US.md
+3 −11 docs/mobile/api/pull-down-refresh.md
+35 −0 docs/mobile/api/radio.en-US.md
+23 −5 docs/mobile/api/radio.md
+35 −0 docs/mobile/api/stepper.en-US.md
+16 −10 docs/mobile/api/stepper.md
+33 −0 docs/mobile/api/swipe-cell.en-US.md
+9 −29 docs/mobile/api/swipe-cell.md
+39 −0 docs/mobile/api/tabs.en-US.md
+15 −17 docs/mobile/api/tabs.md
+25 −0 docs/mobile/api/tree-select.en-US.md
+25 −0 docs/mobile/api/tree-select.md
+12 −0 docs/mobile/api_v2/drawer.en-US.md
+12 −0 docs/mobile/api_v2/drawer.md
+1 −1 docs/mobile/api_v2/indexes.en-US.md
+4 −0 docs/mobile/api_v2/picker.en-US.md
+4 −0 docs/mobile/api_v2/picker.md
+26 −0 docs/web/api/list.en-US.md
+30 −0 docs/web/api/list.md
+1 −0 js/avatar/utils.ts
+3 −3 js/date-picker/utils.ts
+72 −16 js/input-number/large-number.ts
+6 −1 js/input-number/number.ts
+3 −2 style/mobile/_variables.less
+33 −11 style/mobile/components/_index.less
+16 −12 style/mobile/components/avatar/v2/_index.less
+9 −0 style/mobile/components/avatar/v2/_mixin.less
+11 −8 style/mobile/components/avatar/v2/_var.less
+1 −71 style/mobile/components/button/v2/_index.less
+1 −16 style/mobile/components/button/v2/_var.less
+1 −1 style/mobile/components/picker/v2/_index.less
+24 −14 style/mobile/components/radio/v2/_index.less
+5 −0 style/mobile/components/radio/v2/_mixin.less
+1 −1 style/mobile/components/result/v2/_var.less
+1 −1 style/mobile/components/swipe-cell/v2/_index.less
+1 −1 style/mobile/components/toast/v2/_index.less
+1 −1 style/mobile/package.json
+37 −0 style/mobile/theme/_font.less
+2 −0 style/mobile/theme/_index.less
+1 −1 style/web/components/switch/_index.less
+20 −0 test/unit/date-picker/utils.test.js
+41 −0 test/unit/input-number/formatDecimal.test.js
+23 −6 test/unit/input-number/largeNumberToFixed.test.js
39 changes: 39 additions & 0 deletions src/empty/Empty.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React from 'react';
import TImage from '../image';
import { TdEmptyProps } from './type';
import { StyledProps } from '../common';
import parseTNode from '../_util/parseTNode';
import { usePrefixClass } from '../hooks/useClass';

export interface EmptyProps extends TdEmptyProps, StyledProps {}

const Empty: React.FC<EmptyProps> = (props) => {
const { action, description, icon, image } = props;

const emptyClass = usePrefixClass('empty');

const renderThumb = () => {
const tNodeImage = parseTNode(image);
if (tNodeImage) {
return typeof image === 'string' ? <TImage src={image} /> : tNodeImage;
}

const tNodeIcon = parseTNode(icon);
if (tNodeIcon) {
return <div className={`${emptyClass}__icon`}>{tNodeIcon}</div>;
}
return null;
};

return (
<div className={`${emptyClass}`}>
<div className={`${emptyClass}__thumb`}>{renderThumb()}</div>
{description && <div className={`${emptyClass}__description`}>{description}</div>}
{action && <div className={`${emptyClass}__actions`}>{action}</div>}
epoll-j marked this conversation as resolved.
Show resolved Hide resolved
</div>
);
};

Empty.displayName = 'Empty';

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

export default function Base() {
return <Empty icon={<InfoCircleFilledIcon />} description="描述文字" />;
}
17 changes: 17 additions & 0 deletions src/empty/_example/buttonEmpty.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import { Empty, Button } from 'tdesign-mobile-react';
import { InfoCircleFilledIcon } from 'tdesign-icons-react';

export default function ButtonEmpty() {
return (
<Empty
icon={<InfoCircleFilledIcon />}
description="描述文字"
action={
<Button theme="primary" size="large">
操作按钮
</Button>
}
/>
);
}
6 changes: 6 additions & 0 deletions src/empty/_example/imageEmpty.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from 'react';
import { Empty } from 'tdesign-mobile-react';

export default function ImageEmpty() {
return <Empty image="https://tdesign.gtimg.com/mobile/demos/empty1.png" description="描述文字" />;
}
23 changes: 23 additions & 0 deletions src/empty/_example/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';
import TDemoBlock from '../../../site/mobile/components/DemoBlock';
import TDemoHeader from '../../../site/mobile/components/DemoHeader';
import BaseDemo from './base';
import ImageEmptyDemo from './imageEmpty';
import ButtonEmptyDemo from './buttonEmpty';

export default function EmptyDemo() {
return (
<div className="tdesign-mobile-demo">
<TDemoHeader title="Empty 空状态" summary="用于空状态时的占位提示。" />
<TDemoBlock summary="图标空状态">
<BaseDemo />
</TDemoBlock>
<TDemoBlock summary="自定义图片空状态">
<ImageEmptyDemo />
</TDemoBlock>
<TDemoBlock summary="带操作空状态">
<ButtonEmptyDemo />
</TDemoBlock>
</div>
);
}
14 changes: 14 additions & 0 deletions src/empty/empty.en-US.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
:: BASE_DOC ::

## API

### Empty Props

name | type | default | description | required
-- | -- | -- | -- | --
className | String | - | className of component | N
style | Object | - | CSS(Cascading Style Sheets),Typescript:`React.CSSProperties` | N
action | TElement | - | action block。Typescript:`TNode`。[see more ts definition](https://github.com/Tencent/tdesign-mobile-react/blob/develop/src/common.ts) | N
description | TNode | - | empty component description。Typescript:`string \| TNode`。[see more ts definition](https://github.com/Tencent/tdesign-mobile-react/blob/develop/src/common.ts) | N
icon | TNode | - | Typescript:`string \| TNode`。[see more ts definition](https://github.com/Tencent/tdesign-mobile-react/blob/develop/src/common.ts) | N
image | TNode | - | image url, or Image component props, or custom any node you need.。Typescript:`string \| TNode`。[see more ts definition](https://github.com/Tencent/tdesign-mobile-react/blob/develop/src/common.ts) | N
14 changes: 14 additions & 0 deletions src/empty/empty.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
:: BASE_DOC ::

## API

### Empty Props

名称 | 类型 | 默认值 | 描述 | 必传
-- | -- | -- | -- | --
className | String | - | 类名 | N
style | Object | - | 样式,TS 类型:`React.CSSProperties` | N
action | TElement | - | 操作按钮。TS 类型:`TNode`。[通用类型定义](https://github.com/Tencent/tdesign-mobile-react/blob/develop/src/common.ts) | N
description | TNode | - | 描述文字。TS 类型:`string \| TNode`。[通用类型定义](https://github.com/Tencent/tdesign-mobile-react/blob/develop/src/common.ts) | N
icon | TNode | - | 图标。TS 类型:`string \| TNode`。[通用类型定义](https://github.com/Tencent/tdesign-mobile-react/blob/develop/src/common.ts) | N
image | TNode | - | 图片地址。TS 类型:`string \| TNode`。[通用类型定义](https://github.com/Tencent/tdesign-mobile-react/blob/develop/src/common.ts) | N
9 changes: 9 additions & 0 deletions src/empty/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import _Empty from './Empty';

import './style/index.js';

export type { EmptyProps } from './Empty';
export * from './type';

export const Empty = _Empty;
export default Empty;
1 change: 1 addition & 0 deletions src/empty/style/css.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './index.css';
1 change: 1 addition & 0 deletions src/empty/style/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '../../_common/style/mobile/components/empty/_index.less';
26 changes: 26 additions & 0 deletions src/empty/type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* eslint-disable */

/**
* 该文件为脚本自动生成文件,请勿随意修改。如需修改请联系 PMC
* */

import { TNode, TElement } from '../common';

export interface TdEmptyProps {
/**
* 操作按钮
*/
action?: TElement;
/**
* 描述文字
*/
description?: TNode;
/**
* 图标
*/
icon?: TNode;
/**
* 图片地址
*/
image?: TNode;
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export * from './swipe-cell';
export * from './tag';
export * from './result';
export * from './table';
export * from './empty';

/**
* 消息提醒(7个)
Expand Down
Loading
Loading