Skip to content

Commit b5e3088

Browse files
authored
chore: Use father and fix lint (#287)
* init father * clean up * clean deps * update to storybook * fix selectKeys lint * fix example lint * fix util lint * fix inner lint * fix subPopup lint * fix class define * all lint * fix ci * revert export * add miss typo * inline isMobile
1 parent c60ad47 commit b5e3088

34 files changed

+619
-474
lines changed

.eslintrc.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const base = require('@umijs/fabric/dist/eslint');
2+
3+
module.exports = {
4+
...base,
5+
rules: {
6+
...base.rules,
7+
'import/no-named-as-default': 0,
8+
'no-template-curly-in-string': 0,
9+
'prefer-promise-reject-errors': 0,
10+
'react/no-array-index-key': 0,
11+
'react/require-default-props': 0,
12+
'react/sort-comp': 0,
13+
'react/no-find-dom-node': 1,
14+
'@typescript-eslint/no-explicit-any': 0,
15+
'jsx-a11y/label-has-associated-control': 0,
16+
'jsx-a11y/label-has-for': 0,
17+
},
18+
};

.fatherrc.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default {
2+
cjs: 'babel',
3+
esm: { type: 'babel', importLibToEs: true },
4+
preCommit: {
5+
eslint: true,
6+
prettier: true,
7+
},
8+
};

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.storybook
12
*.iml
23
*.log
34
.idea/

.travis.yml

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,17 @@
11
language: node_js
22

3-
sudo: false
4-
5-
notifications:
6-
email:
7-
8-
93
node_js:
10-
- 6.0.0
4+
- 10
115

12-
before_install:
13-
- |
14-
if ! git diff --name-only $TRAVIS_COMMIT_RANGE | grep -qvE '(\.md$)|(^(docs|examples))/'
15-
then
16-
echo "Only docs were updated, stopping build process."
17-
exit
18-
fi
19-
npm install [email protected] -g
20-
phantomjs --version
216
script:
227
- |
238
if [ "$TEST_TYPE" = test ]; then
24-
npm test
9+
npm run coverage && \
10+
bash <(curl -s https://codecov.io/bash)
2511
else
2612
npm run $TEST_TYPE
2713
fi
2814
env:
2915
matrix:
3016
- TEST_TYPE=lint
31-
- TEST_TYPE=test
32-
- TEST_TYPE=coverage
17+
- TEST_TYPE=test

examples/antd.html

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/antd.js

Lines changed: 72 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
/* eslint no-console:0 */
1+
/* eslint-disable no-console, react/require-default-props, no-param-reassign */
22

33
import React from 'react';
4-
import ReactDOM from 'react-dom';
5-
import PropTypes from 'prop-types';
6-
import Menu, { SubMenu, Item as MenuItem, Divider } from 'rc-menu';
7-
import 'rc-menu/assets/index.less';
84
import animate from 'css-animation';
5+
import PropTypes from 'prop-types';
6+
import Menu, { SubMenu, Item as MenuItem, Divider } from '../src';
7+
import '../assets/index.less';
98

109
function handleClick(info) {
1110
console.log(`clicked ${info.key}`);
@@ -30,8 +29,8 @@ const animation = {
3029
});
3130
},
3231

33-
appear() {
34-
return this.enter.apply(this, arguments);
32+
appear(...args) {
33+
return this.enter(...args);
3534
},
3635

3736
leave(node, done) {
@@ -50,32 +49,37 @@ const animation = {
5049
},
5150
};
5251

53-
const reactContainer = document.getElementById('__react-content');
54-
5552
const nestSubMenu = (
5653
<SubMenu
57-
title={
58-
<span className="submenu-title-wrapper">offset sub menu 2</span>
59-
}
54+
title={<span className="submenu-title-wrapper">offset sub menu 2</span>}
6055
key="4"
6156
popupOffset={[10, 15]}
6257
>
6358
<MenuItem key="4-1">inner inner</MenuItem>
64-
<Divider/>
59+
<Divider />
6560
<SubMenu
6661
key="4-2"
6762
title={<span className="submenu-title-wrapper">sub menu 1</span>}
6863
>
69-
<SubMenu title={<span className="submenu-title-wrapper">sub 4-2-0</span>} key="4-2-0">
64+
<SubMenu
65+
title={<span className="submenu-title-wrapper">sub 4-2-0</span>}
66+
key="4-2-0"
67+
>
7068
<MenuItem key="4-2-0-1">inner inner</MenuItem>
7169
<MenuItem key="4-2-0-2">inner inner2</MenuItem>
7270
</SubMenu>
7371
<MenuItem key="4-2-1">inn</MenuItem>
74-
<SubMenu title={<span className="submenu-title-wrapper">sub menu 4</span>} key="4-2-2">
72+
<SubMenu
73+
title={<span className="submenu-title-wrapper">sub menu 4</span>}
74+
key="4-2-2"
75+
>
7576
<MenuItem key="4-2-2-1">inner inner</MenuItem>
7677
<MenuItem key="4-2-2-2">inner inner2</MenuItem>
7778
</SubMenu>
78-
<SubMenu title={<span className="submenu-title-wrapper">sub menu 3</span>} key="4-2-3">
79+
<SubMenu
80+
title={<span className="submenu-title-wrapper">sub menu 3</span>}
81+
key="4-2-3"
82+
>
7983
<MenuItem key="4-2-3-1">inner inner</MenuItem>
8084
<MenuItem key="4-2-3-2">inner inner2</MenuItem>
8185
</SubMenu>
@@ -88,19 +92,27 @@ function onOpenChange(value) {
8892
}
8993

9094
const children1 = [
91-
<SubMenu title={<span className="submenu-title-wrapper">sub menu</span>} key="1">
95+
<SubMenu
96+
title={<span className="submenu-title-wrapper">sub menu</span>}
97+
key="1"
98+
>
9299
<MenuItem key="1-1">0-1</MenuItem>
93100
<MenuItem key="1-2">0-2</MenuItem>
94101
</SubMenu>,
95102
nestSubMenu,
96103
<MenuItem key="2">1</MenuItem>,
97104
<MenuItem key="3">outer</MenuItem>,
98-
<MenuItem key="5" disabled>disabled</MenuItem>,
105+
<MenuItem key="5" disabled>
106+
disabled
107+
</MenuItem>,
99108
<MenuItem key="6">outer3</MenuItem>,
100109
];
101110

102111
const children2 = [
103-
<SubMenu title={<span className="submenu-title-wrapper">sub menu</span>} key="1">
112+
<SubMenu
113+
title={<span className="submenu-title-wrapper">sub menu</span>}
114+
key="1"
115+
>
104116
<MenuItem key="1-1">0-1</MenuItem>
105117
<MenuItem key="1-2">0-2</MenuItem>
106118
</SubMenu>,
@@ -111,32 +123,39 @@ const children2 = [
111123
const customizeIndicator = <span>Add More Items</span>;
112124

113125
class CommonMenu extends React.Component {
114-
state={
126+
state = {
115127
children: children1,
116128
overflowedIndicator: undefined,
117-
}
129+
};
130+
118131
toggleChildren = () => {
119-
this.setState({
120-
children: this.state.children === children1 ? children2 : children1,
121-
});
122-
}
132+
this.setState(({ children }) => ({
133+
children: children === children1 ? children2 : children1,
134+
}));
135+
};
136+
123137
toggleOverflowedIndicator = () => {
124-
this.setState({
138+
this.setState(({ overflowedIndicator }) => ({
125139
overflowedIndicator:
126-
this.state.overflowedIndicator === undefined ?
127-
customizeIndicator :
128-
undefined,
129-
});
130-
}
140+
overflowedIndicator === undefined ? customizeIndicator : undefined,
141+
}));
142+
};
143+
131144
render() {
132145
const { triggerSubMenuAction } = this.props;
133146
const { children, overflowedIndicator } = this.state;
134147
return (
135148
<div>
136-
{this.props.updateChildrenAndOverflowedIndicator && <div>
137-
<button onClick={this.toggleChildren}>toggle children</button>
138-
<button onClick={this.toggleOverflowedIndicator}>toggle overflowedIndicator</button>
139-
</div>}
149+
{this.props.updateChildrenAndOverflowedIndicator && (
150+
<div>
151+
<button type="button" onClick={this.toggleChildren}>
152+
toggle children
153+
</button>
154+
<button type="button" onClick={this.toggleOverflowedIndicator}>
155+
toggle overflowedIndicator
156+
</button>
157+
</div>
158+
)}
140159
<Menu
141160
onClick={handleClick}
142161
triggerSubMenuAction={triggerSubMenuAction}
@@ -162,7 +181,7 @@ CommonMenu.propTypes = {
162181
updateChildrenAndOverflowedIndicator: PropTypes.bool,
163182
};
164183

165-
function render(container) {
184+
function Demo() {
166185
const horizontalMenu = (
167186
<CommonMenu
168187
mode="horizontal"
@@ -181,12 +200,7 @@ function render(container) {
181200
/>
182201
);
183202

184-
const verticalMenu = (
185-
<CommonMenu
186-
mode="vertical"
187-
openAnimation="zoom"
188-
/>
189-
);
203+
const verticalMenu = <CommonMenu mode="vertical" openAnimation="zoom" />;
190204

191205
const inlineMenu = (
192206
<CommonMenu
@@ -196,23 +210,26 @@ function render(container) {
196210
/>
197211
);
198212

199-
ReactDOM.render(<div style={{ margin: 20 }}>
200-
<h2>antd menu</h2>
201-
<div>
202-
<h3>horizontal</h3>
213+
return (
214+
<div style={{ margin: 20 }}>
215+
<h2>antd menu</h2>
216+
<div>
217+
<h3>horizontal</h3>
203218

204-
<div style={{ margin: 20 }}>{horizontalMenu}</div>
205-
<h3>horizontal and click</h3>
219+
<div style={{ margin: 20 }}>{horizontalMenu}</div>
220+
<h3>horizontal and click</h3>
206221

207-
<div style={{ margin: 20 }}>{horizontalMenu2}</div>
208-
<h3>vertical</h3>
222+
<div style={{ margin: 20 }}>{horizontalMenu2}</div>
223+
<h3>vertical</h3>
209224

210-
<div style={{ margin: 20, width: 200 }}>{verticalMenu}</div>
211-
<h3>inline</h3>
225+
<div style={{ margin: 20, width: 200 }}>{verticalMenu}</div>
226+
<h3>inline</h3>
212227

213-
<div style={{ margin: 20, width: 400 }}>{inlineMenu}</div>
228+
<div style={{ margin: 20, width: 400 }}>{inlineMenu}</div>
229+
</div>
214230
</div>
215-
</div>, container);
231+
);
216232
}
217233

218-
render(reactContainer);
234+
export default Demo;
235+
/* eslint-enable */

examples/custom-icon.html

Whitespace-only changes.

0 commit comments

Comments
 (0)