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

fix(empty): fix active search empty will flush #542

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
135 changes: 36 additions & 99 deletions src/empty/__tests__/__snapshots__/empty.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -1,106 +1,43 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Empty should support empty success render 1`] = `
{
"asFragment": [Function],
"baseElement": <body>
<div>
<div
class="dtc-empty"
>
<div
class="ant-empty"
>
<div
class="ant-empty-image"
style="height: 80px;"
>
<img
src="empty_default.png"
/>
</div>
<div
class="ant-empty-description"
>
No Data
</div>
</div>
</div>
exports[`Empty match snapshots 1`] = `
<DocumentFragment>
<div
class="ant-empty dtc-empty"
>
<div
class="ant-empty-image"
>
<img
src="empty_default.png"
/>
</div>
<div
class="ant-empty-description"
>
No Data
</div>
</div>
</DocumentFragment>
`;

exports[`Empty match snapshots 2`] = `
<DocumentFragment>
<div
class="ant-empty dtc-empty dtc-empty__large"
>
<div
class="ant-empty-image"
>
<img
src="empty_default.png"
/>
</div>
</body>,
"container": <div>
<div
class="dtc-empty"
class="ant-empty-description"
>
<div
class="ant-empty"
>
<div
class="ant-empty-image"
style="height: 80px;"
>
<img
src="empty_default.png"
/>
</div>
<div
class="ant-empty-description"
>
No Data
</div>
</div>
No Data
</div>
</div>,
"debug": [Function],
"findAllByAltText": [Function],
"findAllByDisplayValue": [Function],
"findAllByLabelText": [Function],
"findAllByPlaceholderText": [Function],
"findAllByRole": [Function],
"findAllByTestId": [Function],
"findAllByText": [Function],
"findAllByTitle": [Function],
"findByAltText": [Function],
"findByDisplayValue": [Function],
"findByLabelText": [Function],
"findByPlaceholderText": [Function],
"findByRole": [Function],
"findByTestId": [Function],
"findByText": [Function],
"findByTitle": [Function],
"getAllByAltText": [Function],
"getAllByDisplayValue": [Function],
"getAllByLabelText": [Function],
"getAllByPlaceholderText": [Function],
"getAllByRole": [Function],
"getAllByTestId": [Function],
"getAllByText": [Function],
"getAllByTitle": [Function],
"getByAltText": [Function],
"getByDisplayValue": [Function],
"getByLabelText": [Function],
"getByPlaceholderText": [Function],
"getByRole": [Function],
"getByTestId": [Function],
"getByText": [Function],
"getByTitle": [Function],
"queryAllByAltText": [Function],
"queryAllByDisplayValue": [Function],
"queryAllByLabelText": [Function],
"queryAllByPlaceholderText": [Function],
"queryAllByRole": [Function],
"queryAllByTestId": [Function],
"queryAllByText": [Function],
"queryAllByTitle": [Function],
"queryByAltText": [Function],
"queryByDisplayValue": [Function],
"queryByLabelText": [Function],
"queryByPlaceholderText": [Function],
"queryByRole": [Function],
"queryByTestId": [Function],
"queryByText": [Function],
"queryByTitle": [Function],
"rerender": [Function],
"unmount": [Function],
}
</div>
</DocumentFragment>
`;
18 changes: 8 additions & 10 deletions src/empty/__tests__/empty.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,20 @@ import '@testing-library/jest-dom/extend-expect';
import Empty, { IMG_MAP } from '..';

describe('Empty', () => {
test('should support empty success render', () => {
const wrapper = render(<Empty />);
expect(wrapper).toMatchSnapshot();
});
it('should support empty image default size', () => {
const { container } = render(<Empty size="large" />);
expect(container.querySelector<HTMLDivElement>('.ant-empty-image')?.style.height).toBe(
'100px'
);
test('match snapshots', () => {
expect(render(<Empty />).asFragment()).toMatchSnapshot();
expect(render(<Empty size="large" />).asFragment()).toMatchSnapshot();
});
it('should support empty image size should change', () => {
const { container } = render(<Empty imageStyle={{ height: 20 }} />);
expect(container.querySelector<HTMLDivElement>('.ant-empty-image')?.style.height).toBe(
'20px'
);
});
it('should render nothing for incorrect type', () => {
const { container } = render(<Empty type={'test' as any} />);
expect(container.querySelector<HTMLDivElement>('.ant-empty-image')?.innerHTML).toBe('');
});

it('should support empty image size from iamgeStyle', () => {
const { container } = render(<Empty imageStyle={{ height: 40 }} size="large" />);
Expand Down Expand Up @@ -74,7 +72,7 @@ describe('Empty', () => {
<div className="data">show data</div>
</Empty>
);
expect(container.querySelector('.dtc-empty')?.children[0].classList).toContain('ant-empty');
expect(container.querySelector('.dtc-empty')?.classList).toContain('ant-empty');
});

it('should show correct antd empty children', () => {
Expand Down
9 changes: 8 additions & 1 deletion src/empty/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,14 @@ import { Empty } from 'dt-react-component';
import { Space } from 'antd';

export default () => {
return <Empty description="搜索无数据" type="search" active={true} />;
return (
<>
<Empty description="搜索无数据" type="search" active={true} />
<Empty description="搜索无数据" type="search" />
<Empty description="搜索无数据" size="large" type="search" active={true} />
<Empty description="搜索无数据" size="large" type="search" />
</>
);
};
```

Expand Down
25 changes: 15 additions & 10 deletions src/empty/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const Empty = (props: EmptyProps) => {
active = false,
children,
image,
imageStyle,
extra,
className,
style,
Expand All @@ -39,10 +38,10 @@ const Empty = (props: EmptyProps) => {
const img = () => {
if (type === 'search' && active) {
return (
<div className="dtc-empty__container">
<>
<SearchIcon className="dtc-empty__search" />
<LoupeIcon className="dtc-empty__loupe" />
</div>
</>
);
} else if (IMG_MAP[type]) {
return <img src={require(`./emptyImg/${IMG_MAP[type]}`)} />;
Expand All @@ -54,14 +53,20 @@ const Empty = (props: EmptyProps) => {
let newImage: ReactNode = img() || null;
if (image) newImage = image as ReactNode;

const height = size === 'default' ? 80 : 100;

return showEmpty ? (
<div className={classNames('dtc-empty', className)} style={style}>
<AntdEmpty {...restProps} image={newImage} imageStyle={{ height, ...imageStyle }}>
{extra}
</AntdEmpty>
</div>
<AntdEmpty
className={classNames(
'dtc-empty',
size === 'large' && 'dtc-empty__large',
active && 'dtc-empty__active',
className
)}
style={style}
image={newImage}
{...restProps}
>
{extra}
</AntdEmpty>
) : (
<>{children}</>
);
Expand Down
65 changes: 37 additions & 28 deletions src/empty/style.scss
Original file line number Diff line number Diff line change
@@ -1,42 +1,51 @@
.dtc-empty {
.ant-empty {
$defaultSize: 80px;
$largeSize: 100px;

.ant-empty.dtc-empty {
.ant-empty-image {
display: flex;
justify-content: center;
width: $defaultSize;
height: $defaultSize;
font-size: $defaultSize;
margin: 0 auto 8px;
}
.ant-empty-description {
color: #8B8FA8;
line-height: 20px;
font-size: 14px;
font-family: PingFangSC-Regular, "PingFang SC";
font-weight: 400;
}
&__active {
.ant-empty-image {
display: flex;
justify-content: center;
margin-bottom: 8px;
}
.ant-empty-description {
color: #8B8FA8;
line-height: 20px;
font-size: 14px;
font-family: PingFangSC-Regular, "PingFang SC";
font-weight: 400;
position: relative;
}
}
}

.dtc-empty__container {
position: relative;
width: 80px;
height: 80px;
bottom: 8px;
.dtc-empty__search {
font-size: 80px;
position: absolute;
top: 0;
left: 0;
width: 80px;
height: 80px;
line-height: 0;
font-size: 100%;
}
.dtc-empty__loupe {
font-size: 38px;
line-height: 0;
position: absolute;
width: 38px;
height: 38px;
font-size: 38px;
right: 10px;
bottom: 2px;
animation:
animY 1s cubic-bezier(0.36, 0, 0.64, 1) 0.5s infinite alternate,
animX 1s cubic-bezier(0.36, 0, 0.64, 1) -0s infinite alternate;
}
&__large {
.ant-empty-image {
width: $largeSize;
height: $largeSize;
font-size: $largeSize;
}
.dtc-empty__loupe {
font-size: 48px;
}
}
}

@keyframes animX {
Expand Down
Loading