Skip to content

Commit

Permalink
Merge pull request #106 from coreui/dev-v2.5.7-nav-icon-fix
Browse files Browse the repository at this point in the history
v2.5.7
  • Loading branch information
xidedix authored Feb 28, 2020
2 parents 3a3ee13 + 15904e8 commit 300fc61
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
### [@coreui/react](https://coreui.io/) changelog

##### `v2.5.7`
- fix(SidebarNav): add missing alternative icon config object

##### `v2.5.6`
- fix(SidebarNav): navigate to route on AppSideBarNav parent menu click - thanx @regimani #98

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coreui/react",
"version": "2.5.6",
"version": "2.5.7",
"description": "CoreUI React Bootstrap 4 components",
"license": "MIT",
"author": {
Expand Down
11 changes: 11 additions & 0 deletions src/SidebarNav.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ router | inject `react-router-dom@5` object | _mandatory for @coreui/react ^2.5.
},
```

- item.icon: string (css class string for <i> tag)
```json5
icon: 'icon-speedometer' // css class string for <i> tag
```
- item.icon: { class, innerText, attributes }
(v2.5.7 up alternative icon config object)
```json5
icon: { class: 'material-icons', innerText: 'insert_emoticon', attributes: { title: 'smiley' }}
```
---

__React Router Link `url`__

`url: string` - a string representation of the Link location, created by concatenating the location’s pathname, search, and hash properties.
Expand Down
22 changes: 18 additions & 4 deletions src/SidebarNav2.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class AppSidebarNav2 extends Component {

// nav dropdown
navDropdown(item, key) {
const classIcon = classNames('nav-icon', item.icon);
const itemIcon = this.navIcon(item)
const attributes = this.getAttribs(item.attributes);
const classes = classNames('nav-link', 'nav-dropdown-toggle', item.class, attributes.class, attributes.className);
delete attributes.class;
Expand All @@ -148,8 +148,7 @@ class AppSidebarNav2 extends Component {
to={item.url || ''}
{...attributes}
onClick={(e) => this.handleClick(e, item)}>
<i className={classIcon}/>
{item.name}{this.navBadge(item.badge)}
{itemIcon}{item.name}{this.navBadge(item.badge)}
</NavLink>
<ul className="nav-dropdown-items">
{this.navList(item.children)}
Expand All @@ -169,11 +168,26 @@ class AppSidebarNav2 extends Component {
);
}

navIcon(item) {
const icon = item.icon;
const iconObject = (typeof icon === 'object' && (icon !== null)) ? {iconClass: icon.class, iconClassName: icon.className, ...icon} : { iconClass: icon };
const {iconClass, iconClassName, innerText, img, attributes} = iconObject;
const iconAttr = {...attributes};
delete iconAttr.class;
delete iconAttr.className;
delete iconAttr.img;
const iconImg = img && img.src ? img : null;
const iconInner = innerText || null;
const classIcon = classNames('nav-icon', iconClass, iconClassName);
const iconComponent = iconImg ? <img {...iconAttr} className={classIcon} src={iconImg.src} /> : <i {...iconAttr} className={classIcon}>{iconInner}</i>
return (iconComponent)
}

// nav link
navLink(item, key, classes) {
const ref = React.createRef();
const url = item.url || '';
const itemIcon = <i className={classes.icon} />
const itemIcon = this.navIcon(item)
const itemBadge = this.navBadge(item.badge)
const attributes = this.getAttribs(item.attributes)
classes.link = classNames(classes.link, attributes.class, attributes.className)
Expand Down

0 comments on commit 300fc61

Please sign in to comment.