-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(comp: empty): add component empty (#132)
* feat(comp:empty): update and add test fix #54
- Loading branch information
Showing
13 changed files
with
248 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/components/empty/__tests__/__snapshots__/empty.spec.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Empty.vue render work 1`] = `"<div class=\\"ix-empty\\"><div class=\\"ix-empty-image\\"><i class=\\"ix-icon ix-icon-empty\\" role=\\"img\\" arialabel=\\"empty\\"></i></div><div class=\\"ix-empty-description\\">暂无数据</div><!--v-if--></div>"`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { mount, MountingOptions, VueWrapper } from '@vue/test-utils' | ||
import { DefineComponent } from 'vue' | ||
import IxEmpty from '../src/Empty.vue' | ||
import { EmptyProps } from '../src/types' | ||
|
||
describe('Empty.vue', () => { | ||
let EmptyMount: ( | ||
options?: MountingOptions<Partial<EmptyProps>>, | ||
) => VueWrapper<InstanceType<DefineComponent<EmptyProps>>> | ||
|
||
beforeEach(() => { | ||
EmptyMount = (options = {}) => { | ||
return mount<EmptyProps>(IxEmpty, { | ||
...options, | ||
}) | ||
} | ||
}) | ||
|
||
test('render work', () => { | ||
const wrapper = EmptyMount() | ||
expect(wrapper.html()).toMatchSnapshot() | ||
}) | ||
|
||
test('image work', async () => { | ||
const wrapper = EmptyMount() | ||
expect(wrapper.find('.ix-icon').exists()).toEqual(true) | ||
|
||
await wrapper.setProps({ image: 'image.url' }) | ||
|
||
expect(wrapper.find('.ix-icon').exists()).toEqual(false) | ||
expect(wrapper.find('img').exists()).toEqual(true) | ||
}) | ||
|
||
test('description work', async () => { | ||
const description = 'my description' | ||
const wrapper = EmptyMount({ props: { description } }) | ||
|
||
expect(wrapper.find('.ix-empty-description').text()).toEqual(description) | ||
}) | ||
|
||
test('description slot work', async () => { | ||
const description = 'description slots' | ||
const wrapper = EmptyMount({ | ||
props: { description: 'description props' }, | ||
slots: { description }, | ||
}) | ||
|
||
expect(wrapper.find('.ix-empty-description').text()).toEqual(description) | ||
}) | ||
|
||
test('default slot work', async () => { | ||
const wrapper = EmptyMount({ slots: { default: '<div class="default-slot"></div>' } }) | ||
expect(wrapper.find('.default-slot').exists()).toEqual(true) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
order: 0 | ||
title: | ||
zh: 基本用法 | ||
en: Basic usage | ||
--- | ||
|
||
## zh | ||
|
||
简单的展示。 | ||
|
||
## demo | ||
|
||
```html | ||
<template> | ||
<ix-empty /> | ||
</template> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--- | ||
order: 0 | ||
title: | ||
zh: 自定义 | ||
en: Customized | ||
--- | ||
|
||
## zh | ||
|
||
- 通过设置 `image` 来自定义图片。 | ||
- 通过设置 `description` 来自定义描述内容, 支持 `v-slot:description`, 如果需要隐藏描述, 传入一个空字符串即可。 | ||
- 通过设置 `v-slot:default` 来自定义描述内容。 | ||
|
||
## demo | ||
|
||
```html | ||
<template> | ||
<ix-empty | ||
image="https://gw.alipayobjects.com/zos/antfincdn/ZHrcdLPrvN/empty.svg" | ||
description="Customize Description" | ||
> | ||
<ix-button mode="primary">Create Now</ix-button> | ||
</ix-empty> | ||
<ix-divider /> | ||
<ix-empty> | ||
<template #description> | ||
<span>Customize <a href="#API">Description</a></span> | ||
</template> | ||
</ix-empty> | ||
<ix-divider /> | ||
<ix-empty description=""></ix-empty> | ||
</template> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
category: components | ||
type: 数据展示 | ||
title: Empty | ||
subtitle: 空数据 | ||
cover: | ||
cols: 1 | ||
--- | ||
|
||
没有数据时的展示占位图。 | ||
|
||
## 何时使用 | ||
|
||
- 当前没有数据时,用于提示用户。 | ||
|
||
## API | ||
|
||
### `ix-empty` | ||
|
||
#### Props | ||
|
||
| 名称 | 说明 | 类型 | 默认值 | 全局配置 | 备注 | | ||
| --- | --- | --- | --- | --- | --- | | ||
| `description` | 自定义描述内容 | `string \| v-slot:description` | — | — | — | | ||
| `image` | 设置自定义图片地址 | `string` | — | — | — | | ||
|
||
#### Slots | ||
|
||
| 名称 | 说明 | 参数类型 | 备注 | | ||
| --- | --- | --- | --- | | ||
| `defalut` | 自定义 `Footer` 区域内容 | - | - | | ||
|
||
### 主题变量 | ||
|
||
| 变量名 | default 主题| 说明 | | ||
| --- | --- | --- | | ||
| @empty-margin-md | @margin-md | - | | ||
| @empty-line-height-md | @line-height-base | - | | ||
| @empty-font-size-md | @font-size-md | - | | ||
| @empty-icon-font-size-md | `64px` | - | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { installComponent } from '@idux/components/core/utils' | ||
import IxEmpty from './src/Empty.vue' | ||
|
||
IxEmpty.install = installComponent(IxEmpty) | ||
|
||
export { IxEmpty } | ||
export * from './src/types' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<template> | ||
<div class="ix-empty"> | ||
<div class="ix-empty-image"> | ||
<img v-if="image" :src="image" alt="empty image" /> | ||
<ix-icon v-else name="empty" /> | ||
</div> | ||
<div v-if="description$$ || $slots.description" class="ix-empty-description"> | ||
<slot name="description">{{ description$$ }}</slot> | ||
</div> | ||
<div v-if="$slots.default" class="ix-empty-footer"> | ||
<slot /> | ||
</div> | ||
</div> | ||
</template> | ||
<script lang="ts"> | ||
import type { EmptyProps } from './types' | ||
import { defineComponent, computed } from 'vue' | ||
import { PropTypes } from '@idux/cdk/utils' | ||
import { IxIcon } from '@idux/components/icon' | ||
import { getLocale } from '@idux/components/i18n' | ||
export default defineComponent({ | ||
name: 'IxEmpty', | ||
components: { IxIcon }, | ||
props: { | ||
description: PropTypes.string, | ||
image: PropTypes.string, | ||
}, | ||
setup(props: EmptyProps) { | ||
const emptyLocale = getLocale('empty') | ||
const description$$ = computed(() => props.description ?? emptyLocale.value.description) | ||
return { description$$ } | ||
}, | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { DefineComponent } from 'vue' | ||
|
||
interface EmptyOriginalProps { | ||
/** 自定义描述内容 */ | ||
description?: string | ||
/** 图片地址 */ | ||
image?: string | ||
} | ||
|
||
export type EmptyProps = Readonly<EmptyOriginalProps> | ||
|
||
export type EmptyComponent = InstanceType<DefineComponent<EmptyProps>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
@import '../../style/default.less'; | ||
|
||
@empty-prefix: ~'@{idux-prefix}-empty'; | ||
|
||
.@{empty-prefix} { | ||
display: block; | ||
text-align: center; | ||
font-size: @empty-font-size-md; | ||
line-height: @empty-line-height-md; | ||
margin: 0 @empty-margin-md; | ||
|
||
&-image { | ||
margin-bottom: @empty-margin-md; | ||
|
||
img { | ||
height: 100%; | ||
} | ||
|
||
.@{icon-prefix} { | ||
font-size: @empty-icon-font-size-md; | ||
} | ||
} | ||
|
||
&-description { | ||
margin: 0; | ||
} | ||
|
||
&-footer { | ||
margin-top: @empty-margin-md; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters