|
@@ -4,12 +4,16 @@ import BaseComponent, { BaseProps } from '../_base/baseComponent';
|
|
|
import React from 'react';
|
|
import React from 'react';
|
|
|
import PropTypes from 'prop-types';
|
|
import PropTypes from 'prop-types';
|
|
|
import cls from 'classnames';
|
|
import cls from 'classnames';
|
|
|
-import { times, noop } from 'lodash';
|
|
|
|
|
|
|
+import { noop, times } from 'lodash';
|
|
|
|
|
|
|
|
import isNullOrUndefined from '@douyinfe/semi-foundation/utils/isNullOrUndefined';
|
|
import isNullOrUndefined from '@douyinfe/semi-foundation/utils/isNullOrUndefined';
|
|
|
import { cloneDeep, isSemiIcon } from '../_utils';
|
|
import { cloneDeep, isSemiIcon } from '../_utils';
|
|
|
-import ItemFoundation, { ItemProps, SelectedItemProps, ItemAdapter } from '@douyinfe/semi-foundation/navigation/itemFoundation';
|
|
|
|
|
-import { strings, cssClasses } from '@douyinfe/semi-foundation/navigation/constants';
|
|
|
|
|
|
|
+import ItemFoundation, {
|
|
|
|
|
+ ItemAdapter,
|
|
|
|
|
+ ItemProps,
|
|
|
|
|
+ SelectedItemProps
|
|
|
|
|
+} from '@douyinfe/semi-foundation/navigation/itemFoundation';
|
|
|
|
|
+import { cssClasses, strings } from '@douyinfe/semi-foundation/navigation/constants';
|
|
|
|
|
|
|
|
import Tooltip from '../tooltip';
|
|
import Tooltip from '../tooltip';
|
|
|
import NavContext from './nav-context';
|
|
import NavContext from './nav-context';
|
|
@@ -114,7 +118,7 @@ export default class NavItem extends BaseComponent<NavItemProps, NavItemState> {
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- renderIcon(icon: React.ReactNode, pos: string, isToggleIcon = false) {
|
|
|
|
|
|
|
+ renderIcon(icon: React.ReactNode, pos: string, isToggleIcon = false, key: number | string = 0) {
|
|
|
if (this.props.isSubNav) {
|
|
if (this.props.isSubNav) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
@@ -134,8 +138,8 @@ export default class NavItem extends BaseComponent<NavItemProps, NavItemState> {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
- <i className={className}>
|
|
|
|
|
- {isSemiIcon(icon) ? React.cloneElement((icon as React.ReactElement), {size: (icon as React.ReactElement).props.size || iconSize}) : icon}
|
|
|
|
|
|
|
+ <i className={className} key={key}>
|
|
|
|
|
+ {isSemiIcon(icon) ? React.cloneElement((icon as React.ReactElement), { size: (icon as React.ReactElement).props.size || iconSize }) : icon}
|
|
|
</i>
|
|
</i>
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
@@ -189,7 +193,6 @@ export default class NavItem extends BaseComponent<NavItemProps, NavItemState> {
|
|
|
const selected = this.adapter.getSelected();
|
|
const selected = this.adapter.getSelected();
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
let itemChildren = null;
|
|
let itemChildren = null;
|
|
|
if (!isNullOrUndefined(children)) {
|
|
if (!isNullOrUndefined(children)) {
|
|
|
itemChildren = children;
|
|
itemChildren = children;
|
|
@@ -197,15 +200,15 @@ export default class NavItem extends BaseComponent<NavItemProps, NavItemState> {
|
|
|
let placeholderIcons = null;
|
|
let placeholderIcons = null;
|
|
|
if (mode === strings.MODE_VERTICAL && !limitIndent && !isCollapsed) {
|
|
if (mode === strings.MODE_VERTICAL && !limitIndent && !isCollapsed) {
|
|
|
const iconAmount = (icon && !indent) ? level : level - 1;
|
|
const iconAmount = (icon && !indent) ? level : level - 1;
|
|
|
- placeholderIcons = times(iconAmount, () => this.renderIcon(null, strings.ICON_POS_RIGHT, false));
|
|
|
|
|
|
|
+ placeholderIcons = times(iconAmount, (index) => this.renderIcon(null, strings.ICON_POS_RIGHT, false, index));
|
|
|
}
|
|
}
|
|
|
itemChildren = (
|
|
itemChildren = (
|
|
|
<>
|
|
<>
|
|
|
{placeholderIcons}
|
|
{placeholderIcons}
|
|
|
- {this.context.toggleIconPosition === strings.TOGGLE_ICON_LEFT && this.renderIcon(toggleIcon, strings.ICON_POS_RIGHT, true)}
|
|
|
|
|
- {icon || indent || isInSubNav ? this.renderIcon(icon, strings.ICON_POS_LEFT) : null}
|
|
|
|
|
|
|
+ {this.context.toggleIconPosition === strings.TOGGLE_ICON_LEFT && this.renderIcon(toggleIcon, strings.ICON_POS_RIGHT, true, 'key-toggle-pos-right')}
|
|
|
|
|
+ {icon || indent || isInSubNav ? this.renderIcon(icon, strings.ICON_POS_LEFT, false, 'key-position-left') : null}
|
|
|
{!isNullOrUndefined(text) ? <span className={`${cssClasses.PREFIX}-item-text`}>{text}</span> : ''}
|
|
{!isNullOrUndefined(text) ? <span className={`${cssClasses.PREFIX}-item-text`}>{text}</span> : ''}
|
|
|
- {this.context.toggleIconPosition === strings.TOGGLE_ICON_RIGHT && this.renderIcon(toggleIcon, strings.ICON_POS_RIGHT, true)}
|
|
|
|
|
|
|
+ {this.context.toggleIconPosition === strings.TOGGLE_ICON_RIGHT && this.renderIcon(toggleIcon, strings.ICON_POS_RIGHT, true, 'key-toggle-pos-right')}
|
|
|
</>
|
|
</>
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
@@ -246,7 +249,7 @@ export default class NavItem extends BaseComponent<NavItemProps, NavItemState> {
|
|
|
);
|
|
);
|
|
|
} else {
|
|
} else {
|
|
|
// Items are divided into normal and sub-wrap
|
|
// Items are divided into normal and sub-wrap
|
|
|
- const popoverItemCls = cls(`${className || `${clsPrefix }-normal`}`, {
|
|
|
|
|
|
|
+ const popoverItemCls = cls(`${className || `${clsPrefix}-normal`}`, {
|
|
|
[clsPrefix]: true,
|
|
[clsPrefix]: true,
|
|
|
[`${clsPrefix}-sub`]: isSubNav,
|
|
[`${clsPrefix}-sub`]: isSubNav,
|
|
|
[`${clsPrefix}-selected`]: selected && !isSubNav,
|
|
[`${clsPrefix}-selected`]: selected && !isSubNav,
|