refactor nav.jsx into functional component

Mostly a straightforward change to a functional component.  Smaller refactors include removing `_.omit` which isn't needed.
This commit is contained in:
Gazook89
2026-07-13 22:41:42 -05:00
parent 2eb246ab0d
commit 4e5e5986cd
+24 -53
View File
@@ -1,21 +1,16 @@
import './navbar.less'; import './navbar.less';
import React, { useState, useRef, useEffect } from 'react'; import React, { useState, useRef, useEffect } from 'react';
import createReactClass from 'create-react-class';
import _ from 'lodash';
import cx from 'classnames'; import cx from 'classnames';
import NaturalCritIcon from '@components/svg/naturalcrit-d20.svg.jsx'; import NaturalCritIcon from '@components/svg/naturalcrit-d20.svg.jsx';
const Nav = { const Nav = {
base : createReactClass({ base : ({ children, className, ...props })=>{
displayName : 'Nav.base', return <nav className={className}>
render : function(){ {children}
return <nav> </nav>;
{this.props.children} },
</nav>; logo : ()=>{
}
}),
logo : function(){
return <a className='navLogo' href='https://www.naturalcrit.com'> return <a className='navLogo' href='https://www.naturalcrit.com'>
<NaturalCritIcon /> <NaturalCritIcon />
<span className='name'> <span className='name'>
@@ -24,50 +19,26 @@ const Nav = {
</a>; </a>;
}, },
section : createReactClass({ section : ({ children, className, ...props })=>{
displayName : 'Nav.section', return <div className={cx([`navSection`, className])}>
render : function(){ {children}
return <div className={`navSection ${this.props.className ?? ''}`}> </div>;
{this.props.children} },
item : ({ icon, href, newTab, onClick, color, children, className, ...props })=>{
const classes = cx('navItem', color, className);
if(href){
return <a className={classes} href={href} target={newTab ? '_blank' : '_self'} {...props}>
{children}
{icon && <i className={icon}></i>}
</a>;
} else {
return <div {...props} className={classes} onClick={onClick} >
{children}
{icon && <i className={icon}></i>}
</div>; </div>;
} }
}), },
item : createReactClass({
displayName : 'Nav.item',
getDefaultProps : function() {
return {
icon : null,
href : null,
newTab : false,
onClick : function(){},
color : null
};
},
handleClick : function(e){
this.props.onClick(e);
},
render : function(){
const classes = cx('navItem', this.props.color, this.props.className);
let icon;
if(this.props.icon) icon = <i className={this.props.icon} />;
const props = _.omit(this.props, ['newTab']);
if(this.props.href){
return <a {...props} className={classes} target={this.props.newTab ? '_blank' : '_self'} >
{this.props.children}
{icon}
</a>;
} else {
return <div {...props} className={classes} onClick={this.handleClick} >
{this.props.children}
{icon}
</div>;
}
}
}),
dropdown : function dropdown(props) { dropdown : function dropdown(props) {
props = Object.assign({}, props, { props = Object.assign({}, props, {