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: add empty component #226

Merged
merged 3 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
37 changes: 37 additions & 0 deletions src/components/empty/__tests__/empty.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import * as React from 'react';
import { render } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';

import Empty, { DEFAULT_BASE64, GREY_BASE64 } from '../index';

describe('Empty', () => {
mumiao marked this conversation as resolved.
Show resolved Hide resolved
it('image size should change', () => {
mumiao marked this conversation as resolved.
Show resolved Hide resolved
const { container } = render(<Empty imageStyle={{ height: 20 }} />);
expect(
container.querySelector<HTMLDivElement>('.ant-empty-image')?.style.height
).toBe('20px');
});

it('description can be false', () => {
const { container } = render(<Empty description={false} />);
expect(container.querySelector('.ant-empty-description')).toBeFalsy();
});

it('render correct img for default type', () => {
const { container } = render(<Empty />);
const srcValue = container.querySelector('img').getAttribute('src');
expect(srcValue).toEqual(DEFAULT_BASE64);
})

it('render correct img for grey type', () => {
const { container } = render(<Empty type='grey' />);
const srcValue = container.querySelector('img').getAttribute('src');
expect(srcValue).toEqual(GREY_BASE64);
})

it('render correct img when have image props', () => {
const { container } = render(<Empty image="public/iamges/drag-drawer-icon.png" type="grey" />);
const srcValue = container.querySelector('img').getAttribute('src');
expect(srcValue).toEqual('public/iamges/drag-drawer-icon.png');
})
});
20 changes: 20 additions & 0 deletions src/components/empty/index.tsx

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions src/components/empty/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.ant-empty {
.ant-empty-description {
color: #8b8fa8;
line-height: 20px;
font-size: 14px;
font-family: PingFangSC-Regular, 'PingFang SC';
font-weight: 400;
}
}
1 change: 1 addition & 0 deletions src/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ export { default as TableCell } from './tableCell';
export { default as TextMark } from './textMark';
export { default as ToolModal } from './toolModal';
export { default as ProgressLine } from './progressLine'
export { default as Empty } from './empty'

58 changes: 58 additions & 0 deletions src/stories/empty.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import React from 'react'
import { storiesOf } from '@storybook/react';
import { withKnobs } from '@storybook/addon-knobs';
import { PropsTable } from './components/propsTable';
import Empty from '../components/empty';

const stories = storiesOf('Empty 空状态', module);
stories.addDecorator(withKnobs)

const propDefinitions = [{
property: 'type',
propType: 'string',
required: false,
description: '默认展示图片的类型',
defaultValue: 'default'
}, {
property: 'image',
propType: 'React.Node',
required: false,
description: '自定义图片(设置该参数时,默认的图片不生效)',
defaultValue: ''
}, {
property: '其他参数',
propType: '',
required: false,
description: <a target="_blank" rel="noopener noreferrer" href="https://ant.design/components/empty-cn/#API">继承antd4.x的Empty</a>,
defaultValue: ''
}]

stories.add('Empty 空状态', () => (
mumiao marked this conversation as resolved.
Show resolved Hide resolved
<div className='story_wrapper'>
<h2>何时使用</h2>
<p>{`当目前没有数据时,用于显式的用户提示。初始化场景时的引导创建流程`}</p>
<h2>1、使用默认空状态</h2>
<Empty />
<h2>2、使用灰色空状态</h2>
<Empty type="grey" />
<h2>3、使用自定义图片</h2>
<Empty image="https://user-images.githubusercontent.com/38368040/195246598-5adf8985-3f78-48b1-8116-bc4d78982df8.jpeg" />
</div>
), {
info: {
text: `
代码示例:
~~~js
<p style={style}>1、使用默认空状态</p>
<Empty />

<p style={style}>2、使用灰色空状态</p>
<Empty type="grey" />

<p style={style}>3、使用自定义图片</p>
<Empty image="https://user-images.githubusercontent.com/38368040/195246598-5adf8985-3f78-48b1-8116-bc4d78982df8.jpeg" />
~~~
`,
TableComponent: () => PropsTable({ propDefinitions })
}
});
1 change: 1 addition & 0 deletions src/styles/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
@import "../components/spreadSheet/style.scss";
@import "../components/toolModal/style.scss";
@import "../components/mxGraph/style.scss";
@import "../components/empty/style.scss";

.sb-show-main{
#root>div:nth-child(3) {
Expand Down