Skip to content

Commit c60ad47

Browse files
committed
chore: Prettier code
1 parent f0a6b7f commit c60ad47

File tree

13 files changed

+788
-334
lines changed

13 files changed

+788
-334
lines changed

.prettierrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"endOfLine": "lf",
3+
"semi": true,
4+
"singleQuote": true,
5+
"tabWidth": 2,
6+
"trailingComma": "all"
7+
}

src/DOMWrap.jsx

Lines changed: 77 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,29 @@ class DOMWrap extends React.Component {
3535
entries.forEach(this.setChildrenWidthAndResize);
3636
});
3737

38-
[].slice.call(menuUl.children).concat(menuUl).forEach(el => {
39-
this.resizeObserver.observe(el);
40-
});
38+
[].slice
39+
.call(menuUl.children)
40+
.concat(menuUl)
41+
.forEach(el => {
42+
this.resizeObserver.observe(el);
43+
});
4144

4245
if (typeof MutationObserver !== 'undefined') {
4346
this.mutationObserver = new MutationObserver(() => {
4447
this.resizeObserver.disconnect();
45-
[].slice.call(menuUl.children).concat(menuUl).forEach(el => {
46-
this.resizeObserver.observe(el);
47-
});
48+
[].slice
49+
.call(menuUl.children)
50+
.concat(menuUl)
51+
.forEach(el => {
52+
this.resizeObserver.observe(el);
53+
});
4854
this.setChildrenWidthAndResize();
4955
});
50-
this.mutationObserver.observe(
51-
menuUl,
52-
{ attributes: false, childList: true, subTree: false }
53-
);
56+
this.mutationObserver.observe(menuUl, {
57+
attributes: false,
58+
childList: true,
59+
subTree: false,
60+
});
5461
}
5562
}
5663
}
@@ -73,21 +80,31 @@ class DOMWrap extends React.Component {
7380
}
7481

7582
// filter out all overflowed indicator placeholder
76-
return [].slice.call(ul.children)
77-
.filter(node => {
78-
return node.className.split(' ').indexOf(`${prefixCls}-overflowed-submenu`) < 0;
79-
});
80-
}
83+
return [].slice.call(ul.children).filter(node => {
84+
return (
85+
node.className.split(' ').indexOf(`${prefixCls}-overflowed-submenu`) < 0
86+
);
87+
});
88+
};
8189

82-
getOverflowedSubMenuItem = (keyPrefix, overflowedItems, renderPlaceholder) => {
90+
getOverflowedSubMenuItem = (
91+
keyPrefix,
92+
overflowedItems,
93+
renderPlaceholder,
94+
) => {
8395
const { overflowedIndicator, level, mode, prefixCls, theme } = this.props;
8496
if (level !== 1 || mode !== 'horizontal') {
8597
return null;
8698
}
8799
// put all the overflowed item inside a submenu
88100
// with a title of overflow indicator ('...')
89101
const copy = this.props.children[0];
90-
const { children: throwAway, title, style: propStyle, ...rest } = copy.props;
102+
const {
103+
children: throwAway,
104+
title,
105+
style: propStyle,
106+
...rest,
107+
} = copy.props;
91108

92109
let style = { ...propStyle };
93110
let key = `${keyPrefix}-overflowed-indicator`;
@@ -131,7 +148,7 @@ class DOMWrap extends React.Component {
131148
{overflowedItems}
132149
</SubMenu>
133150
);
134-
}
151+
};
135152

136153
// memorize rendered menuSize
137154
setChildrenWidthAndResize = () => {
@@ -150,7 +167,8 @@ class DOMWrap extends React.Component {
150167
return;
151168
}
152169

153-
const lastOverflowedIndicatorPlaceholder = ul.children[ulChildrenNodes.length - 1];
170+
const lastOverflowedIndicatorPlaceholder =
171+
ul.children[ulChildrenNodes.length - 1];
154172

155173
// need last overflowed indicator for calculating length;
156174
setStyle(lastOverflowedIndicatorPlaceholder, 'display', 'inline-block');
@@ -160,8 +178,9 @@ class DOMWrap extends React.Component {
160178
// reset display attribute for all hidden elements caused by overflow to calculate updated width
161179
// and then reset to original state after width calculation
162180

163-
const overflowedItems = menuItemNodes
164-
.filter(c => c.className.split(' ').indexOf(MENUITEM_OVERFLOWED_CLASSNAME) >= 0);
181+
const overflowedItems = menuItemNodes.filter(
182+
c => c.className.split(' ').indexOf(MENUITEM_OVERFLOWED_CLASSNAME) >= 0,
183+
);
165184

166185
overflowedItems.forEach(c => {
167186
setStyle(c, 'display', 'inline-block');
@@ -172,12 +191,17 @@ class DOMWrap extends React.Component {
172191
overflowedItems.forEach(c => {
173192
setStyle(c, 'display', 'none');
174193
});
175-
this.overflowedIndicatorWidth = getWidth(ul.children[ul.children.length - 1]);
176-
this.originalTotalWidth = this.menuItemSizes.reduce((acc, cur) => acc + cur, 0);
194+
this.overflowedIndicatorWidth = getWidth(
195+
ul.children[ul.children.length - 1],
196+
);
197+
this.originalTotalWidth = this.menuItemSizes.reduce(
198+
(acc, cur) => acc + cur,
199+
0,
200+
);
177201
this.handleResize();
178202
// prevent the overflowed indicator from taking space;
179203
setStyle(lastOverflowedIndicatorPlaceholder, 'display', 'none');
180-
}
204+
};
181205

182206
resizeObserver = null;
183207
mutationObserver = null;
@@ -223,18 +247,21 @@ class DOMWrap extends React.Component {
223247
}
224248

225249
this.setState({ lastVisibleIndex });
226-
}
250+
};
227251

228252
renderChildren(children) {
229253
// need to take care of overflowed items in horizontal mode
230254
const { lastVisibleIndex } = this.state;
231255
return (children || []).reduce((acc, childNode, index) => {
232256
let item = childNode;
233257
if (this.props.mode === 'horizontal') {
234-
let overflowed = this.getOverflowedSubMenuItem(childNode.props.eventKey, []);
235-
if (lastVisibleIndex !== undefined
236-
&&
237-
this.props.className.indexOf(`${this.props.prefixCls}-root`) !== -1
258+
let overflowed = this.getOverflowedSubMenuItem(
259+
childNode.props.eventKey,
260+
[],
261+
);
262+
if (
263+
lastVisibleIndex !== undefined &&
264+
this.props.className.indexOf(`${this.props.prefixCls}-root`) !== -1
238265
) {
239266
if (index > lastVisibleIndex) {
240267
item = React.cloneElement(
@@ -248,14 +275,16 @@ class DOMWrap extends React.Component {
248275
);
249276
}
250277
if (index === lastVisibleIndex + 1) {
251-
this.overflowedItems = children.slice(lastVisibleIndex + 1).map(c => {
252-
return React.cloneElement(
253-
c,
254-
// children[index].key will become '.$key' in clone by default,
255-
// we have to overwrite with the correct key explicitly
256-
{ key: c.props.eventKey, mode: 'vertical-left' },
257-
);
258-
});
278+
this.overflowedItems = children
279+
.slice(lastVisibleIndex + 1)
280+
.map(c => {
281+
return React.cloneElement(
282+
c,
283+
// children[index].key will become '.$key' in clone by default,
284+
// we have to overwrite with the correct key explicitly
285+
{ key: c.props.eventKey, mode: 'vertical-left' },
286+
);
287+
});
259288

260289
overflowed = this.getOverflowedSubMenuItem(
261290
childNode.props.eventKey,
@@ -268,7 +297,9 @@ class DOMWrap extends React.Component {
268297

269298
if (index === children.length - 1) {
270299
// need a placeholder for calculating overflowed indicator width
271-
ret.push(this.getOverflowedSubMenuItem(childNode.props.eventKey, [], true));
300+
ret.push(
301+
this.getOverflowedSubMenuItem(childNode.props.eventKey, [], true),
302+
);
272303
}
273304
return ret;
274305
}
@@ -294,18 +325,20 @@ class DOMWrap extends React.Component {
294325
rest.className += ` ${hiddenClassName}`;
295326
}
296327

297-
return (
298-
<Tag {...rest}>
299-
{this.renderChildren(this.props.children)}
300-
</Tag>
301-
);
328+
return <Tag {...rest}>{this.renderChildren(this.props.children)}</Tag>;
302329
}
303330
}
304331

305332
DOMWrap.propTypes = {
306333
className: PropTypes.string,
307334
children: PropTypes.node,
308-
mode: PropTypes.oneOf(['horizontal', 'vertical', 'vertical-left', 'vertical-right', 'inline']),
335+
mode: PropTypes.oneOf([
336+
'horizontal',
337+
'vertical',
338+
'vertical-left',
339+
'vertical-right',
340+
'inline',
341+
]),
309342
prefixCls: PropTypes.string,
310343
level: PropTypes.number,
311344
theme: PropTypes.string,

src/Menu.jsx

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ class Menu extends React.Component {
1111
selectedKeys: PropTypes.arrayOf(PropTypes.string),
1212
defaultOpenKeys: PropTypes.arrayOf(PropTypes.string),
1313
openKeys: PropTypes.arrayOf(PropTypes.string),
14-
mode: PropTypes.oneOf(['horizontal', 'vertical', 'vertical-left', 'vertical-right', 'inline']),
14+
mode: PropTypes.oneOf([
15+
'horizontal',
16+
'vertical',
17+
'vertical-left',
18+
'vertical-right',
19+
'inline',
20+
]),
1521
getPopupContainer: PropTypes.func,
1622
onClick: PropTypes.func,
1723
onSelect: PropTypes.func,
@@ -85,7 +91,7 @@ class Menu extends React.Component {
8591
this.updateMiniStore();
8692
}
8793

88-
onSelect = (selectInfo) => {
94+
onSelect = selectInfo => {
8995
const props = this.props;
9096
if (props.selectable) {
9197
// root menu
@@ -106,24 +112,24 @@ class Menu extends React.Component {
106112
selectedKeys,
107113
});
108114
}
109-
}
115+
};
110116

111-
onClick = (e) => {
117+
onClick = e => {
112118
this.props.onClick(e);
113-
}
119+
};
114120

115121
// onKeyDown needs to be exposed as a instance method
116122
// e.g., in rc-select, we need to navigate menu item while
117123
// current active item is rc-select input box rather than the menu itself
118124
onKeyDown = (e, callback) => {
119125
this.innerMenu.getWrappedInstance().onKeyDown(e, callback);
120-
}
126+
};
121127

122-
onOpenChange = (event) => {
128+
onOpenChange = event => {
123129
const props = this.props;
124130
const openKeys = this.store.getState().openKeys.concat();
125131
let changed = false;
126-
const processSingle = (e) => {
132+
const processSingle = e => {
127133
let oneChanged = false;
128134
if (e.open) {
129135
oneChanged = openKeys.indexOf(e.key) === -1;
@@ -151,9 +157,9 @@ class Menu extends React.Component {
151157
}
152158
props.onOpenChange(openKeys);
153159
}
154-
}
160+
};
155161

156-
onDeselect = (selectInfo) => {
162+
onDeselect = selectInfo => {
157163
const props = this.props;
158164
if (props.selectable) {
159165
const selectedKeys = this.store.getState().selectedKeys.concat();
@@ -172,7 +178,7 @@ class Menu extends React.Component {
172178
selectedKeys,
173179
});
174180
}
175-
}
181+
};
176182

177183
getOpenTransitionName = () => {
178184
const props = this.props;
@@ -182,7 +188,7 @@ class Menu extends React.Component {
182188
transitionName = `${props.prefixCls}-open-${animationName}`;
183189
}
184190
return transitionName;
185-
}
191+
};
186192

187193
updateMiniStore() {
188194
if ('selectedKeys' in this.props) {
@@ -211,7 +217,9 @@ class Menu extends React.Component {
211217
};
212218
return (
213219
<Provider store={this.store}>
214-
<SubPopupMenu {...props} ref={c => this.innerMenu = c}>{this.props.children}</SubPopupMenu>
220+
<SubPopupMenu {...props} ref={c => (this.innerMenu = c)}>
221+
{this.props.children}
222+
</SubPopupMenu>
215223
</Provider>
216224
);
217225
}

src/MenuItem.jsx

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ export class MenuItem extends React.Component {
5353
const { active, parentMenu, eventKey } = this.props;
5454
// 在 parentMenu 上层保存滚动状态,避免重复的 MenuItem key 导致滚动跳动
5555
// https://github.com/ant-design/ant-design/issues/16181
56-
if (!prevProps.active && active && (!parentMenu || !parentMenu[`scrolled-${eventKey}`])) {
56+
if (
57+
!prevProps.active &&
58+
active &&
59+
(!parentMenu || !parentMenu[`scrolled-${eventKey}`])
60+
) {
5761
if (this.node) {
5862
scrollIntoView(this.node, ReactDOM.findDOMNode(parentMenu), {
5963
onlyScrollIfNeeded: true,
@@ -106,7 +110,14 @@ export class MenuItem extends React.Component {
106110
};
107111

108112
onClick = e => {
109-
const { eventKey, multiple, onClick, onSelect, onDeselect, isSelected } = this.props;
113+
const {
114+
eventKey,
115+
multiple,
116+
onClick,
117+
onSelect,
118+
onDeselect,
119+
isSelected,
120+
} = this.props;
110121
const info = {
111122
key: eventKey,
112123
keyPath: [eventKey],
@@ -200,7 +211,13 @@ export class MenuItem extends React.Component {
200211
icon = React.createElement(this.props.itemIcon, this.props);
201212
}
202213
return (
203-
<li {...props} {...attrs} {...mouseEvent} style={style} ref={this.saveNode}>
214+
<li
215+
{...props}
216+
{...attrs}
217+
{...mouseEvent}
218+
style={style}
219+
ref={this.saveNode}
220+
>
204221
{props.children}
205222
{icon}
206223
</li>
@@ -210,9 +227,11 @@ export class MenuItem extends React.Component {
210227

211228
MenuItem.isMenuItem = true;
212229

213-
const connected = connect(({ activeKey, selectedKeys }, { eventKey, subMenuKey }) => ({
214-
active: activeKey[subMenuKey] === eventKey,
215-
isSelected: selectedKeys.indexOf(eventKey) !== -1,
216-
}))(MenuItem);
230+
const connected = connect(
231+
({ activeKey, selectedKeys }, { eventKey, subMenuKey }) => ({
232+
active: activeKey[subMenuKey] === eventKey,
233+
isSelected: selectedKeys.indexOf(eventKey) !== -1,
234+
}),
235+
)(MenuItem);
217236

218237
export default connected;

src/MenuItemGroup.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ class MenuItemGroup extends React.Component {
1515
disabled: true,
1616
};
1717

18-
renderInnerMenuItem = (item) => {
18+
renderInnerMenuItem = item => {
1919
const { renderMenuItem, index } = this.props;
2020
return renderMenuItem(item, index, this.props.subMenuKey);
21-
}
21+
};
2222

2323
render() {
2424
const { ...props } = this.props;

0 commit comments

Comments
 (0)