Skip to content

Commit 1fe1e34

Browse files
committed
refactor(CNavbar): improve and clean-up syntax
1 parent 253a377 commit 1fe1e34

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

packages/coreui-react/src/components/navbar/CNavbar.tsx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,6 @@ export const CNavbar = forwardRef<HTMLDivElement, CNavbarProps>(
5353
},
5454
ref,
5555
) => {
56-
let content
57-
if (container) {
58-
content = (
59-
<div className={`container${container !== true ? '-' + container : ''}`}>{children}</div>
60-
)
61-
} else {
62-
content = children
63-
}
64-
6556
return (
6657
<Component
6758
className={classNames(
@@ -77,7 +68,13 @@ export const CNavbar = forwardRef<HTMLDivElement, CNavbarProps>(
7768
{...rest}
7869
ref={ref}
7970
>
80-
{content}
71+
{container ? (
72+
<div className={typeof container === 'string' ? `container-${container}` : 'container'}>
73+
{children}
74+
</div>
75+
) : (
76+
<>{children}</>
77+
)}
8178
</Component>
8279
)
8380
},

packages/coreui-react/src/components/navbar/CNavbarBrand.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export interface CNavbarBrandProps extends HTMLAttributes<HTMLAnchorElement | HT
2020

2121
export const CNavbarBrand = forwardRef<HTMLAnchorElement | HTMLSpanElement, CNavbarBrandProps>(
2222
({ children, component, className, ...rest }, ref) => {
23-
const Component = component ? component : rest.href ? 'a' : 'span'
23+
const Component = component ?? (rest.href ? 'a' : 'span')
2424

2525
return (
2626
<Component className={classNames('navbar-brand', className)} {...rest} ref={ref}>

packages/coreui-react/src/components/navbar/CNavbarToggler.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const CNavbarToggler = forwardRef<HTMLButtonElement, CNavbarTogglerProps>
1313
({ children, className, ...rest }, ref) => {
1414
return (
1515
<button type="button" className={classNames('navbar-toggler', className)} {...rest} ref={ref}>
16-
{children ? children : <span className="navbar-toggler-icon"></span>}
16+
{children ?? <span className="navbar-toggler-icon"></span>}
1717
</button>
1818
)
1919
},

0 commit comments

Comments
 (0)