Skip to content

Commit

Permalink
chore: fix empty docs and complete demo (#3054)
Browse files Browse the repository at this point in the history
* chore: fix empty docs and complete demo

* chore: update test

* chore: update test
  • Loading branch information
uyarn authored Aug 22, 2024
1 parent cad316c commit 11fc230
Show file tree
Hide file tree
Showing 16 changed files with 349 additions and 358 deletions.
122 changes: 64 additions & 58 deletions site/test-coverage.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module.exports = {
"Util": {
"statements": "61.88%",
"branches": "48.57%",
"functions": "69.29%",
"lines": "63.77%"
"statements": "58.47%",
"branches": "47.92%",
"functions": "63.49%",
"lines": "60.29%"
},
"affix": {
"statements": "84.84%",
Expand All @@ -30,10 +30,10 @@ module.exports = {
"lines": "97.95%"
},
"avatar": {
"statements": "96.92%",
"statements": "92.64%",
"branches": "86.48%",
"functions": "100%",
"lines": "96.92%"
"functions": "75%",
"lines": "92.64%"
},
"backTop": {
"statements": "78.68%",
Expand Down Expand Up @@ -81,7 +81,7 @@ module.exports = {
"statements": "90.27%",
"branches": "83.01%",
"functions": "100%",
"lines": "91.42%"
"lines": "91.3%"
},
"collapse": {
"statements": "96.15%",
Expand Down Expand Up @@ -114,10 +114,10 @@ module.exports = {
"lines": "68.75%"
},
"datePicker": {
"statements": "62.55%",
"branches": "44.05%",
"functions": "60.6%",
"lines": "66.24%"
"statements": "59.16%",
"branches": "41.42%",
"functions": "58.9%",
"lines": "62.07%"
},
"descriptions": {
"statements": "98.82%",
Expand All @@ -126,10 +126,10 @@ module.exports = {
"lines": "100%"
},
"dialog": {
"statements": "85%",
"statements": "83.53%",
"branches": "71.92%",
"functions": "85%",
"lines": "87.24%"
"functions": "79.06%",
"lines": "85.62%"
},
"divider": {
"statements": "100%",
Expand All @@ -144,10 +144,16 @@ module.exports = {
"lines": "89.09%"
},
"dropdown": {
"statements": "89.02%",
"branches": "52.5%",
"statements": "89.28%",
"branches": "58.69%",
"functions": "80%",
"lines": "92.4%"
"lines": "92.59%"
},
"empty": {
"statements": "84.37%",
"branches": "63.63%",
"functions": "100%",
"lines": "84.37%"
},
"form": {
"statements": "83.5%",
Expand All @@ -168,10 +174,10 @@ module.exports = {
"lines": "99.31%"
},
"hooks": {
"statements": "55.22%",
"branches": "44.44%",
"functions": "60%",
"lines": "55.19%"
"statements": "61.17%",
"branches": "49.41%",
"functions": "68.86%",
"lines": "62.4%"
},
"image": {
"statements": "88.88%",
Expand All @@ -180,16 +186,16 @@ module.exports = {
"lines": "91.86%"
},
"imageViewer": {
"statements": "77.85%",
"branches": "82.25%",
"functions": "68.42%",
"lines": "77.62%"
"statements": "65.28%",
"branches": "76.54%",
"functions": "65.11%",
"lines": "65.59%"
},
"input": {
"statements": "93.82%",
"branches": "92.24%",
"statements": "93.9%",
"branches": "92.3%",
"functions": "89.47%",
"lines": "94.15%"
"lines": "94.19%"
},
"inputAdornment": {
"statements": "86.95%",
Expand Down Expand Up @@ -252,10 +258,10 @@ module.exports = {
"lines": "92.59%"
},
"pagination": {
"statements": "94.93%",
"branches": "77.77%",
"statements": "93.82%",
"branches": "76.08%",
"functions": "93.75%",
"lines": "94.8%"
"lines": "94.87%"
},
"popconfirm": {
"statements": "76.92%",
Expand All @@ -264,10 +270,10 @@ module.exports = {
"lines": "76.92%"
},
"popup": {
"statements": "47.01%",
"branches": "41.26%",
"statements": "48.38%",
"branches": "44.77%",
"functions": "45.23%",
"lines": "45%"
"lines": "46.52%"
},
"progress": {
"statements": "89.23%",
Expand All @@ -282,16 +288,16 @@ module.exports = {
"lines": "83.58%"
},
"rangeInput": {
"statements": "74.02%",
"statements": "75.32%",
"branches": "62.79%",
"functions": "48.14%",
"lines": "73.68%"
"functions": "51.85%",
"lines": "75%"
},
"rate": {
"statements": "96.22%",
"branches": "79.16%",
"statements": "96.36%",
"branches": "80.76%",
"functions": "100%",
"lines": "96.22%"
"lines": "96.36%"
},
"select": {
"statements": "100%",
Expand All @@ -313,9 +319,9 @@ module.exports = {
},
"slider": {
"statements": "89.47%",
"branches": "67.79%",
"branches": "68.85%",
"functions": "92.85%",
"lines": "90.47%"
"lines": "91.2%"
},
"space": {
"statements": "87.75%",
Expand Down Expand Up @@ -354,10 +360,10 @@ module.exports = {
"lines": "49.56%"
},
"tabs": {
"statements": "90.96%",
"branches": "79.04%",
"functions": "86.36%",
"lines": "91.17%"
"statements": "89.79%",
"branches": "77.27%",
"functions": "88%",
"lines": "90.86%"
},
"tag": {
"statements": "56.25%",
Expand All @@ -378,10 +384,10 @@ module.exports = {
"lines": "86.76%"
},
"timePicker": {
"statements": "77.41%",
"branches": "67.16%",
"functions": "66.66%",
"lines": "78.65%"
"statements": "82.88%",
"branches": "73.68%",
"functions": "86.36%",
"lines": "83.01%"
},
"timeline": {
"statements": "96.87%",
Expand All @@ -408,19 +414,19 @@ module.exports = {
"lines": "88.33%"
},
"treeSelect": {
"statements": "95.48%",
"branches": "86.17%",
"functions": "97.61%",
"lines": "97.22%"
"statements": "95.45%",
"branches": "82.35%",
"functions": "97.56%",
"lines": "97.2%"
},
"typography": {
"statements": "95.58%",
"statements": "95.52%",
"branches": "76.31%",
"functions": "81.81%",
"lines": "98.46%"
"lines": "98.43%"
},
"upload": {
"statements": "96.66%",
"statements": "96.77%",
"branches": "95.65%",
"functions": "88.88%",
"lines": "100%"
Expand Down
4 changes: 2 additions & 2 deletions src/empty/Empty.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ const Empty: React.FC<EmptyProps> = (props) => {
};

const prefix = `${classPrefix}-empty`;
const emptyClasses = cls(prefix, className);
const emptyClasses = cls(prefix, className, defaultSize[size]);
const titleClasses = cls(`${prefix}__title`);
const imageClasses = cls(`${prefix}__image`, defaultSize[size]);
const imageClasses = cls(`${prefix}__image`);
const descriptionClasses = cls(`${prefix}__description`);
const actionCls = cls(`${prefix}__action`);

Expand Down
43 changes: 43 additions & 0 deletions src/empty/__tests__/empty.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* eslint-disable */
import { render } from '@test/utils';
import React from 'react';

import Empty from '../index';

describe('Empty 组件测试', () => {
test('size', async () => {
const { container } = render(<Empty size="small" />);

expect(container.querySelector('.t-empty.t-size-s')).not.toBeNull();
});

test('title', async () => {
const { container } = render(<Empty title="title" />);

expect(container.querySelector('.t-empty__title').innerHTML).toBe('title');
});

test('description', async () => {
const { container } = render(<Empty description="description" />);

expect(container.querySelector('.t-empty__description').innerHTML).toBe('description');
});

test('action', async () => {
const { container } = render(<Empty action={<div>action</div>} />);

expect(container.querySelector('.t-empty__action').innerHTML).toBe('<div>action</div>');
});

test('type', async () => {
const { container } = render(<Empty type="success" />);
const successIconPath =
'M24 42C33.9411 42 42 33.9411 42 24C42 14.0589 33.9411 6 24 6C14.0589 6 6 14.0589 6 24C6 33.9411 14.0589 42 24 42ZM46 24C46 36.1503 36.1503 46 24 46C11.8497 46 2 36.1503 2 24C2 11.8497 11.8497 2 24 2C36.1503 2 46 11.8497 46 24ZM21 32.8284L12.1716 24L15 21.1716L21 27.1716L33 15.1716L35.8284 18L21 32.8284Z';
expect(container.querySelector('.t-empty__image').querySelector('path').getAttribute('d')).toBe(successIconPath);
});

test('image', async () => {
const { container } = render(<Empty image={<div>image</div>} />);
expect(container.querySelector('.t-empty__image').innerHTML).toBe('<div>image</div>');
});
});
6 changes: 1 addition & 5 deletions src/empty/_example/base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,5 @@ import React from 'react';
import { Empty } from 'tdesign-react';

export default function BasicGrid() {
return (
<>
<Empty type="empty" title="暂无数据" />
</>
);
return <Empty />;
}
9 changes: 1 addition & 8 deletions src/empty/_example/descriptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,5 @@ export default function Operation() {
console.log('go to index');
location.href = '/';
}
return (
<Empty
type="empty"
action={<Button onClick={goToIndex}>返回首页</Button>}
description="description"
title="暂无数据"
/>
);
return <Empty action={<Button onClick={goToIndex}>返回首页</Button>} description="description" />;
}
2 changes: 1 addition & 1 deletion src/empty/_example/operation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ export default function Operation() {
console.log('go to index');
location.href = '/';
}
return <Empty type="empty" action={<Button onClick={goToIndex}>返回首页</Button>} title="暂无数据" />;
return <Empty action={<Button onClick={goToIndex}>返回首页</Button>} />;
}
2 changes: 1 addition & 1 deletion src/empty/_example/self-defined.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function BasicGrid() {
return (
<Row gutter={40}>
<Col>
<Empty image={<ErrorCircleIcon size={64} color="rgba(0, 0, 0, 0.26)" />} description="暂无数据" />
<Empty image={<ErrorCircleIcon size={64} color="var(--td-text-color-placeholder)" />} description="暂无数据" />
</Col>
<Col>
<Empty description="暂无数据" image={CustomImageContainer} />
Expand Down
4 changes: 2 additions & 2 deletions src/empty/_example/size.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function StatusExample() {
return (
<Space direction="vertical">
<Radio.Group variant="default-filled" options={options} value={size} onChange={(value: SIZE) => setSize(value)} />
<Space direction="vertical">
<div style={{ marginTop: '20px', height: '100px' }}>
<Row gutter={40}>
<Col>
<Empty type="empty" size={size} />
Expand All @@ -41,7 +41,7 @@ export default function StatusExample() {
<Empty type="fail" size={size} />
</Col>
</Row>
</Space>
</div>
</Space>
);
}
11 changes: 4 additions & 7 deletions src/empty/assets/EmptySvg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,20 @@ export default function EmptySvg() {
<svg width="1em" height="1em" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
<g id="&#230;&#151;&#160;&#231;&#187;&#147;&#230;&#158;&#156;-no-result">
<g id="Union">
<path d="M22 0H26V8H22V0Z" fill="var(--td-text-color-disabled)" fillOpacity="0.26" />
<path d="M22 0H26V8H22V0Z" fill="var(--td-text-color-placeholder)" />
<path
d="M10.002 1.17157L7.17353 4L13.002 9.82843L15.8304 7L10.002 1.17157Z"
fill="var(--td-text-color-disabled)"
fillOpacity="0.26"
fill="var(--td-text-color-placeholder)"
/>
<path
fillRule="evenodd"
clipRule="evenodd"
d="M2 27.4689L10.8394 12H37.1606L46 27.4689V44H2V27.4689ZM13.1606 16L7.44636 26H17.8025L18.1889 27.5015C18.8551 30.0898 21.207 32 24 32C26.793 32 29.1449 30.0898 29.8111 27.5015L30.1975 26H40.5536L34.8394 16H13.1606Z"
fill="var(--td-text-color-disabled)"
fillOpacity="0.26"
fill="var(--td-text-color-placeholder)"
/>
<path
d="M37.998 1.17157L32.1696 7L34.998 9.82843L40.8265 4L37.998 1.17157Z"
fill="var(--td-text-color-disabled)"
fillOpacity="0.26"
fill="var(--td-text-color-placeholder)"
/>
</g>
</g>
Expand Down
Loading

0 comments on commit 11fc230

Please sign in to comment.