Skip to content

Commit 507337c

Browse files
authored
Merge pull request #515 from rulishu/rls
fix(Empty): 修改Empty测试用例报错
2 parents fd8ec28 + 0099742 commit 507337c

File tree

4 files changed

+60
-57
lines changed

4 files changed

+60
-57
lines changed

packages/core/src/Empty/index.tsx

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@ import React, { Component } from 'react';
22
import { StyleSheet, Text, TextProps } from 'react-native';
33
import Icon from '../Icon';
44
import Flex, { FlexProps } from '../Flex';
5+
import { iconStr } from './svg';
56

6-
const iconStr = `
7-
<svg width="64" height="41" viewBox="0 0 64 41">
8-
<g transform="translate(0 1)" fill="none" fill-rule="evenodd">
9-
<ellipse fill="#F5F5F5" cx="32" cy="33" rx="32" ry="7"></ellipse>
10-
<g fill-rule="nonzero" stroke="#D9D9D9">
11-
<path fill="#FFF" d="M55 12.76L44.854 1.258C44.367.474 43.656 0 42.907 0H21.093c-.749 0-1.46.474-1.947 1.257L9 12.761V22h46v-9.24z"></path>
12-
<path fill="#FAFAFA" d="M41.613 15.931c0-1.605.994-2.93 2.227-2.931H55v18.137C55 33.26 53.68 35 52.05 35h-40.1C10.32 35 9 33.259 9 31.137V13h11.16c1.233 0 2.227 1.323 2.227 2.928v.022c0 1.605 1.005 2.901 2.237 2.901h14.752c1.232 0 2.237-1.308 2.237-2.913v-.007z"></path>
13-
</g>
14-
</g>
15-
</svg>
16-
`;
7+
// export const iconStr = `
8+
// <svg width="64" height="41" viewBox="0 0 64 41">
9+
// <g transform="translate(0 1)" fill="none" fill-rule="evenodd">
10+
// <ellipse fill="#F5F5F5" cx="32" cy="33" rx="32" ry="7"></ellipse>
11+
// <g fill-rule="nonzero" stroke="#D9D9D9">
12+
// <path fill="#FFF" d="M55 12.76L44.854 1.258C44.367.474 43.656 0 42.907 0H21.093c-.749 0-1.46.474-1.947 1.257L9 12.761V22h46v-9.24z"></path>
13+
// <path fill="#FAFAFA" d="M41.613 15.931c0-1.605.994-2.93 2.227-2.931H55v18.137C55 33.26 53.68 35 52.05 35h-40.1C10.32 35 9 33.259 9 31.137V13h11.16c1.233 0 2.227 1.323 2.227 2.928v.022c0 1.605 1.005 2.901 2.237 2.901h14.752c1.232 0 2.237-1.308 2.237-2.913v-.007z"></path>
14+
// </g>
15+
// </g>
16+
// </svg>
17+
// `;
1718

1819
export interface EmptyProps extends FlexProps {
1920
/**
@@ -38,24 +39,17 @@ export interface EmptyProps extends FlexProps {
3839
children?: React.ReactNode;
3940
}
4041

41-
export default class Empty extends Component<EmptyProps> {
42-
static defaultProps: EmptyProps = {
43-
size: 64,
44-
label: '暂无数据',
45-
xml: iconStr,
46-
};
47-
render() {
48-
const { size, label, xml, labelStyle, children, ...props } = this.props;
49-
return (
50-
<Flex direction="column" justify="center" align="center" {...props}>
51-
{xml && <Icon xml={xml} size={size} />}
52-
{!!children
53-
? children
54-
: label &&
55-
typeof label === 'string' && <Text style={StyleSheet.flatten([styles.label, labelStyle])}>{label}</Text>}
56-
</Flex>
57-
);
58-
}
42+
export default function Empty(props: EmptyProps) {
43+
const { size = 64, label = '暂无数据', xml = iconStr, labelStyle, children, ...otherProps } = props;
44+
return (
45+
<Flex direction="column" justify="center" align="center" {...otherProps}>
46+
{xml && <Icon xml={xml} size={size} />}
47+
{!!children
48+
? children
49+
: label &&
50+
typeof label === 'string' && <Text style={StyleSheet.flatten([styles.label, labelStyle])}>{label}</Text>}
51+
</Flex>
52+
);
5953
}
6054

6155
const styles = StyleSheet.create({

packages/core/src/Empty/svg.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export const iconStr = `
2+
<svg width="64" height="41" viewBox="0 0 64 41">
3+
<g transform="translate(0 1)" fill="none" fill-rule="evenodd">
4+
<ellipse fill="#F5F5F5" cx="32" cy="33" rx="32" ry="7"></ellipse>
5+
<g fill-rule="nonzero" stroke="#D9D9D9">
6+
<path fill="#FFF" d="M55 12.76L44.854 1.258C44.367.474 43.656 0 42.907 0H21.093c-.749 0-1.46.474-1.947 1.257L9 12.761V22h46v-9.24z"></path>
7+
<path fill="#FAFAFA" d="M41.613 15.931c0-1.605.994-2.93 2.227-2.931H55v18.137C55 33.26 53.68 35 52.05 35h-40.1C10.32 35 9 33.259 9 31.137V13h11.16c1.233 0 2.227 1.323 2.227 2.928v.022c0 1.605 1.005 2.901 2.237 2.901h14.752c1.232 0 2.237-1.308 2.237-2.913v-.007z"></path>
8+
</g>
9+
</g>
10+
</svg>
11+
`;

packages/core/src/WingBlank/README.md

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@ import React,{Component} from 'react';
1111
import { Text } from 'react-native';
1212
import { WingBlank } from '@uiw/react-native';
1313

14-
class Demo extends Component {
15-
render() {
16-
return (
17-
<WingBlank>
18-
<Text>两翼留白两翼留白两翼留白两翼留白两翼留白两翼留白两翼留白两翼留白两翼留白两翼留白两翼留白两翼留白两翼留白两翼留白两翼留白两翼留白两翼留两翼留白两翼留白两翼留白两翼留白</Text>
19-
</WingBlank>
20-
);
21-
}
14+
function Demo() {
15+
return (
16+
<WingBlank>
17+
<Text>两翼留白两翼留白两翼留白两翼留白两翼留白两翼留白两翼留白两翼留白两翼留白两翼留白两翼留白两翼留白两翼留白两翼留白两翼留白两翼留白两翼留两翼留白两翼留白两翼留白两翼留白</Text>
18+
</WingBlank>
19+
);
2220
}
2321
export default Demo
2422
```
@@ -30,22 +28,20 @@ import React,{Component,Fragment} from 'react';
3028
import { Text } from 'react-native';
3129
import { WingBlank } from '@uiw/react-native';
3230

33-
class Demo extends Component {
34-
render() {
35-
return (
36-
<Fragment>
37-
<WingBlank size='small'>
38-
<Text>两翼留白两翼留白</Text>
39-
</WingBlank>
40-
<WingBlank size='default'>
41-
<Text>两翼留白两翼留白</Text>
42-
</WingBlank>
43-
<WingBlank size='large'>
44-
<Text>两翼留白两翼留白</Text>
45-
</WingBlank>
46-
</Fragment>
47-
);
48-
}
31+
function Demo() {
32+
return (
33+
<Fragment>
34+
<WingBlank size='small'>
35+
<Text>两翼留白两翼留白</Text>
36+
</WingBlank>
37+
<WingBlank size='default'>
38+
<Text>两翼留白两翼留白</Text>
39+
</WingBlank>
40+
<WingBlank size='large'>
41+
<Text>两翼留白两翼留白</Text>
42+
</WingBlank>
43+
</Fragment>
44+
);
4945
}
5046
export default Demo
5147
```

test-ci/src/__tests__/empty.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@ import React from 'react';
77
import Empty from '../lib/Empty';
88
// Note: test renderer must be required after react-native.
99
import renderer from 'react-test-renderer';
10+
import { iconStr } from '../lib/Empty/svg';
1011

1112
it('Empty', () => {
1213
const component = renderer.create(
13-
<Empty label="冇得数据咯" size={120} labelStyle={{ color: 'red' }}>冇得数据咯</Empty>
14+
<Empty label="冇得数据咯" size={120} labelStyle={{ color: 'red' }} xml={iconStr}>
15+
冇得数据咯
16+
</Empty>,
1417
);
1518
expect(component.root.props.label).toBe('冇得数据咯');
1619
expect(component.root.props.size).toBe(120);
1720
expect(component.root.props.labelStyle).toBeTruthy();
18-
expect(component.root.props.xml).toBeTruthy();
21+
expect(component.root.props.xml).toStrictEqual(iconStr);
1922
expect(component.root.props.children).toBe('冇得数据咯');
20-
21-
});
23+
});

0 commit comments

Comments
 (0)