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): new Empty component #3287

Merged
merged 11 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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 examples/empty/demos/base.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<t-empty theme="primary">Empty</t-empty>
</template>
9 changes: 9 additions & 0 deletions examples/empty/empty.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## empty

::: demo demos/base 默认
:::

### 属性配置
| 属性 | 类型 | 默认值 | 必传 | 说明 |
|-----|-----|-----|-----|-----|
|-|-|-|-|-|
8 changes: 8 additions & 0 deletions site/site.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,14 @@ const docs = [
component: () => import('tdesign-vue/descriptions/descriptions.md'),
componentEn: () => import('tdesign-vue/descriptions/descriptions.en-US.md'),
},
{
title: 'Empty 空状态',
titleEn: 'Empty',
name: 'empty',
path: '/vue/components/empty',
component: () => import('tdesign-vue/empty/empty.md'),
componentEn: () => import('tdesign-vue/empty/empty.en-US.md'),
},
{
title: 'Image 图片',
titleEn: 'Image',
Expand Down
2 changes: 1 addition & 1 deletion src/_common
Submodule _common updated 59 files
+41 −0 docs/mobile/api/action-sheet.en-US.md
+8 −0 docs/mobile/api/action-sheet.md
+19 −0 docs/mobile/api/badge.en-US.md
+5 −5 docs/mobile/api/badge.md
+66 −0 docs/mobile/api/button.en-US.md
+34 −5 docs/mobile/api/button.md
+36 −0 docs/mobile/api/collapse.en-US.md
+18 −3 docs/mobile/api/collapse.md
+21 −0 docs/mobile/api/count-down.en-US.md
+8 −3 docs/mobile/api/count-down.md
+35 −0 docs/mobile/api/grid.en-US.md
+18 −2 docs/mobile/api/grid.md
+19 −0 docs/mobile/api/image-viewer.en-US.md
+6 −5 docs/mobile/api/image-viewer.md
+29 −0 docs/mobile/api/image.en-US.md
+11 −17 docs/mobile/api/image.md
+64 −0 docs/mobile/api/input.en-US.md
+40 −12 docs/mobile/api/input.md
+17 −0 docs/mobile/api/link.en-US.md
+15 −0 docs/mobile/api/link.md
+45 −0 docs/mobile/api/loading.en-US.md
+14 −12 docs/mobile/api/loading.md
+31 −0 docs/mobile/api/search.en-US.md
+19 −5 docs/mobile/api/search.md
+25 −0 docs/mobile/api/side-bar.en-US.md
+25 −0 docs/mobile/api/side-bar.md
+41 −0 docs/mobile/api/tab-bar.en-US.md
+22 −10 docs/mobile/api/tab-bar.md
+21 −0 docs/mobile/api/table.en-US.md
+21 −0 docs/mobile/api/table.md
+25 −0 docs/mobile/api/toast.en-US.md
+7 −17 docs/mobile/api/toast.md
+4 −0 docs/web/api/empty.en-US.md
+4 −0 docs/web/api/empty.md
+26 −0 docs/web/api/list.en-US.md
+30 −0 docs/web/api/list.md
+1 −0 js/global-config/locale/ar_KW.ts
+1 −0 js/global-config/locale/en_US.ts
+1 −0 js/global-config/locale/it_IT.ts
+1 −0 js/global-config/locale/ja_JP.ts
+1 −0 js/global-config/locale/ko_KR.ts
+1 −0 js/global-config/locale/ru_RU.ts
+1 −0 js/global-config/locale/zh_CN.ts
+1 −0 js/global-config/locale/zh_TW.ts
+1 −1 js/time-picker/const.ts
+37 −0 js/time-picker/utils.ts
+11 −11 style/mobile/components/_index.less
+11 −11 style/mobile/components/badge/v2/_index.less
+40 −2 style/mobile/components/button/v2/_index.less
+8 −0 style/mobile/components/button/v2/_var.less
+44 −0 style/mobile/components/image/v2/_index.less
+10 −5 style/mobile/components/link/_index.less
+61 −15 style/mobile/components/link/_var.less
+8 −0 style/mobile/components/loading/_index.less
+1 −1 style/mobile/components/overlay/v2/_index.less
+14 −0 style/mobile/utilities/_animation.less
+29 −0 style/web/components/empty/_index.less
+10 −5 style/web/components/empty/_var.less
+78 −0 test/unit/time-picker/utils.test.js
1 change: 1 addition & 0 deletions src/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export * from './calendar';
export * from './card';
export * from './comment';
export * from './descriptions';
export * from './empty';
export * from './image';
export * from './image-viewer';
export * from './list';
Expand Down
75 changes: 74 additions & 1 deletion src/config-provider/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ButtonProps } from '../button';
import { FormErrorMessage } from '../form';
import { MessageOptions } from '../message';
import { ImageProps } from '../image';
import { TNode, SizeEnum } from '../common';
import { TNode, SizeEnum, AttachNode } from '../common';
uyarn marked this conversation as resolved.
Show resolved Hide resolved

export interface GlobalConfigProvider {
/**
Expand All @@ -25,6 +25,10 @@ export interface GlobalConfigProvider {
* 动画效果控制,`ripple` 指波纹动画, `expand` 指展开动画,`fade` 指渐变动画。默认为 `{ include: ['ripple','expand','fade'], exclude: [] }`
*/
animation?: Partial<Record<'include' | 'exclude', Array<AnimationType>>>;
/**
* null
*/
attach?: AttachNode | { imageViewer?: AttachNode; message?: AttachNode; popup?: AttachNode; dialog?: AttachNode };
uyarn marked this conversation as resolved.
Show resolved Hide resolved
/**
* 日历组件全局配置
*/
Expand All @@ -46,6 +50,10 @@ export interface GlobalConfigProvider {
* 日期选择器全局配置
*/
datePicker?: DatePickerConfig;
/**
* 描述全局配置
*/
descriptions?: DescriptionsConfig;
uyarn marked this conversation as resolved.
Show resolved Hide resolved
/**
* 对话框全局配置
*/
Expand All @@ -54,6 +62,10 @@ export interface GlobalConfigProvider {
* 抽屉全局配置
*/
drawer?: DrawerConfig;
/**
* 空状态全局配置
*/
empty?: EmptyConfig;
/**
* 表单组件全局配置
*/
Expand Down Expand Up @@ -94,6 +106,10 @@ export interface GlobalConfigProvider {
* 气泡确认框全局配置
*/
popconfirm?: PopconfirmConfig;
/**
* 评分全局配置
*/
rate?: RateConfig;
uyarn marked this conversation as resolved.
Show resolved Hide resolved
/**
* 选择器组件全局配置
*/
Expand Down Expand Up @@ -126,6 +142,10 @@ export interface GlobalConfigProvider {
* 树选择器组件全局配置
*/
treeSelect?: TreeSelectConfig;
/**
* 排版组件全局配置
*/
typography?: TypographyConfig;
uyarn marked this conversation as resolved.
Show resolved Hide resolved
/**
* 上传组件全局配置
*/
Expand Down Expand Up @@ -775,6 +795,11 @@ export interface UploadConfigFileList {
}

export interface FormConfig {
/**
* 字段旁边的冒号,中文为“:”
* @default ''
*/
colonText?: string;
uyarn marked this conversation as resolved.
Show resolved Hide resolved
/**
* 表单错误信息配置,示例:`{ idcard: '请输入正确的身份证号码', max: '字符长度不能超过 ${max}' }`
*/
Expand All @@ -794,6 +819,10 @@ export interface TagConfig {
}

export interface StepsConfig {
/**
* 已完成步骤图标,【注意】使用渲染函数输出图标组件
*/
checkIcon?: TNode;
uyarn marked this conversation as resolved.
Show resolved Hide resolved
/**
* 错误步骤图标,【注意】使用渲染函数输出图标组件
*/
Expand All @@ -813,6 +842,14 @@ export interface AlertConfig {
expandText?: string;
}

export interface DescriptionsConfig {
/**
* 字段旁边的冒号,中文为“:”
* @default ''
*/
colonText?: string;
}

uyarn marked this conversation as resolved.
Show resolved Hide resolved
export interface AnchorConfig {
/**
* 语言配置,“链接复制成功”描述文本
Expand Down Expand Up @@ -887,6 +924,42 @@ export interface GuideConfig {
skipButtonProps?: ButtonProps;
}

export interface RateConfig {
/**
* 评分描述,默认值:['极差', '失望', '一般', '满意', '惊喜']
*/
rateText?: string[];
}

uyarn marked this conversation as resolved.
Show resolved Hide resolved
export interface EmptyConfig {
/**
* 空状态组件各类型的图片配置
*/
image?: { maintenance: TNode; success: TNode; fail: TNode; empty: TNode; networkError: TNode };
/**
* 空状态组件各类型的标题文本配置
*/
titleText?: { maintenance: string; success: string; fail: string; empty: string; networkError: string };
}

export interface TypographyConfig {
/**
* 语言配置,“收起”描述文本
* @default ''
*/
collapseText?: string;
/**
* 语言配置,“复制成功”描述文本
* @default ''
*/
copiedText?: string;
/**
* 语言配置,“展开”描述文本
* @default ''
*/
expandText?: string;
}

uyarn marked this conversation as resolved.
Show resolved Hide resolved
export type AnimationType = 'ripple' | 'expand' | 'fade';

export type IconConfig = GlobalIconConfig;
Expand Down
30 changes: 30 additions & 0 deletions src/empty/__test__/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { mount } from '@vue/test-utils';
import Empty from '@/src/empty/index.ts';

// every component needs four parts: props/events/slots/functions.
describe('Empty', () => {
// test props api
describe(':props', () => {
it('', () => {
const wrapper = mount({
render() {
return <Empty></Empty>;
},
});
expect(wrapper.exists()).toBe(true);
});
});

// test events
describe('@event', () => {});

// test slots
describe('<slot>', () => {
it('', () => {});
});

// test exposure function
describe('function', () => {
it('', () => {});
});
});
7 changes: 7 additions & 0 deletions src/empty/_example-composition/base.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<template>
<t-space direction="vertical" align="center">
<t-empty>
<template #title>title</template>
</t-empty>
</t-space>
</template>
18 changes: 18 additions & 0 deletions src/empty/_example-composition/descriptions.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<template>
<t-empty :description="description" :title="title">
<template #action>
<t-button @click="goToIndex">返回首页</t-button>
</template>
</t-empty>
</template>
<script setup>
import { ref } from 'vue';

const title = ref('空状态 Empty');
const description = ref('暂无数据 Description');

function goToIndex() {
console.log('go to index');
location.href = '/';
}
</script>
13 changes: 13 additions & 0 deletions src/empty/_example-composition/operation.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<template>
<t-empty>
<template #action>
<t-button @click="goToIndex">返回首页</t-button>
</template>
</t-empty>
</template>
<script setup>
function goToIndex() {
console.log('go to index');
location.href = '/';
}
</script>
25 changes: 25 additions & 0 deletions src/empty/_example-composition/self-defined.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<template>
<t-row :gutter="40">
<t-col>
<t-empty description="暂无数据">
<template #image>
<ErrorCircleIcon :size="64" color="var(--td-text-color-placeholder)" />
</template>
</t-empty>
</t-col>
<t-col>
<t-empty description="暂无数据">
<template #image>
<div
style="
width: '64px';
height: '64px';
background-image: 'url(https://tdesign.gtimg.com/demo/demo-image-1.png)';
background-size: '100% 100%';
"
></div>
</template>
</t-empty>
</t-col>
</t-row>
</template>
39 changes: 39 additions & 0 deletions src/empty/_example-composition/size.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<template>
<t-space direction="vertical">
<t-radio-group variant="primary-filled" :value="size" @change="onChange">
<t-radio-button value="small">small</t-radio-button>
<t-radio-button value="medium">medium</t-radio-button>
<t-radio-button value="large">large</t-radio-button>
</t-radio-group>
<div style="margin-top: '20px'; height: '100px'">
<t-row :gutter="40">
<t-col>
<t-empty type="empty" :size="size"></t-empty>
</t-col>
<t-col>
<t-empty type="maintenance" :size="size"></t-empty>
</t-col>
<t-col>
<t-empty type="network-error" :size="size"></t-empty>
</t-col>
<t-col>
<t-empty type="success" :size="size"></t-empty>
</t-col>
<t-col>
<t-empty type="fail" :size="size"></t-empty>
</t-col>
</t-row>
</div>
</t-space>
</template>
<script lang="ts" setup>
import { ref } from 'vue';

type SIZE = 'small' | 'medium' | 'large';

const size = ref('medium');

function onChange(value: SIZE) {
this.size = value;
}
</script>
19 changes: 19 additions & 0 deletions src/empty/_example-composition/status.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<template>
<t-row :gutter="40">
<t-col>
<t-empty type="empty"></t-empty>
</t-col>
<t-col>
<t-empty type="maintenance"></t-empty>
</t-col>
<t-col>
<t-empty type="network-error"></t-empty>
</t-col>
<t-col>
<t-empty type="success"></t-empty>
</t-col>
<t-col>
<t-empty type="fail"></t-empty>
</t-col>
</t-row>
</template>
7 changes: 7 additions & 0 deletions src/empty/_example/base.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<template>
<t-space direction="vertical" align="center">
<t-empty>
<template #title>title</template>
</t-empty>
</t-space>
</template>
24 changes: 24 additions & 0 deletions src/empty/_example/descriptions.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<template>
<t-empty :description="description" :title="title">
<template #action>
<t-button @click="goToIndex">返回首页</t-button>
</template>
</t-empty>
</template>
<script>
export default {
data() {
return {
title: '空状态 Empty',
description: '暂无数据 Description',
timer: null,
};
},
methods: {
goToIndex() {
console.log('go to index');
location.href = '/';
},
},
};
</script>
20 changes: 20 additions & 0 deletions src/empty/_example/operation.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<template>
<t-empty>
<template #action>
<t-button @click="goToIndex">返回首页</t-button>
</template>
</t-empty>
</template>
<script>
export default {
data() {
return {};
},
methods: {
goToIndex() {
console.log('go to index');
location.href = '/';
},
},
};
</script>
Loading
Loading