Skip to content

Commit 02b6b0d

Browse files
committed
refactor: CSidebar: clearify component
1 parent 30e7004 commit 02b6b0d

File tree

1 file changed

+15
-23
lines changed

1 file changed

+15
-23
lines changed

src/template/CSidebar.js

+15-23
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ import classNames from 'classnames'
55
export const Context = React.createContext({})
66

77
//component - CoreUI / CSidebar
8-
9-
const CSidebar = props=>{
8+
const CSidebar = props => {
109

1110
const {
1211
children,
1312
className,
14-
//
1513
innerRef,
1614
breakpoint,
1715
show,
@@ -35,12 +33,11 @@ const CSidebar = props=>{
3533
const [openDropdown, setOpenDropdown] = useState()
3634

3735
const node = useRef({}).current
38-
const reference = (r) => {
36+
const reference = r => {
3937
node.current = r
4038
innerRef && innerRef(r)
4139
}
4240

43-
4441
const [minimized, setIsMinimized] = useState(minimize)
4542
useMemo(() => {
4643
setIsMinimized(minimize)
@@ -51,8 +48,6 @@ const CSidebar = props=>{
5148
onMinimizeChange && onMinimizeChange(minimized)
5249
}
5350

54-
// compData.nextRender = true
55-
5651
useMemo(() => {
5752
setIsOpen(show)
5853
}, [show])
@@ -63,7 +58,7 @@ const CSidebar = props=>{
6358
}, [isOpen])
6459

6560
//methods
66-
const sidebarCloseListener = (e) => {
61+
const sidebarCloseListener = e => {
6762
if (
6863
document.getElementById(key + 'backdrop') &&
6964
!node.current.contains(e.target)
@@ -98,13 +93,12 @@ const CSidebar = props=>{
9893
setIsOpen(overlaid ? false : 'responsive')
9994
}
10095

101-
const isOnMobile = ()=>{
96+
const isOnMobile = () => {
10297
return Boolean(getComputedStyle(node.current).getPropertyValue('--is-mobile'))
10398
}
10499

105100
const onSidebarClick = e => {
106101
const sidebarItemClicked = String(e.target.className).includes('c-sidebar-nav-link')
107-
108102
if (
109103
sidebarItemClicked &&
110104
hideOnMobileClick &&
@@ -115,20 +109,19 @@ const CSidebar = props=>{
115109
}
116110

117111
// render
118-
119112
const haveResponsiveClass = breakpoint && isOpen === 'responsive'
120113
const classes = classNames(
121-
className,
122114
'c-sidebar',
123-
colorScheme ? `c-sidebar-${colorScheme}` : null,
124-
isOpen===true ? 'c-sidebar-show' : null,
125-
haveResponsiveClass ? `c-sidebar-${breakpoint}-show` : null,
126-
fixed && !overlaid ? 'c-sidebar-fixed' : null,
127-
aside ? 'c-sidebar-right' : null,
128-
minimized && !unfoldable ? 'c-sidebar-minimized' : null,
129-
minimized && unfoldable ? 'c-sidebar-unfoldable' : null,
130-
overlaid ? 'c-sidebar-overlaid' : null,
131-
size ? `c-sidebar-${size}` : null
115+
colorScheme && `c-sidebar-${colorScheme}`,
116+
isOpen === true && 'c-sidebar-show',
117+
haveResponsiveClass && `c-sidebar-${breakpoint}-show`,
118+
fixed && !overlaid && 'c-sidebar-fixed',
119+
aside && 'c-sidebar-right',
120+
minimized && !unfoldable && 'c-sidebar-minimized',
121+
minimized && unfoldable && 'c-sidebar-unfoldable',
122+
overlaid && 'c-sidebar-overlaid',
123+
size && `c-sidebar-${size}`,
124+
className
132125
)
133126

134127
return (
@@ -140,8 +133,8 @@ const CSidebar = props=>{
140133
setOpenDropdown
141134
}}>
142135
<div
143-
{...attributes}
144136
className={classes}
137+
{...attributes}
145138
ref={reference}
146139
onClick={onSidebarClick}
147140
>
@@ -155,7 +148,6 @@ const CSidebar = props=>{
155148
CSidebar.propTypes = {
156149
children: PropTypes.node,
157150
className: PropTypes.oneOfType([PropTypes.string, PropTypes.array, PropTypes.object]),
158-
//
159151
innerRef: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
160152
fixed: PropTypes.bool,
161153
unfoldable: PropTypes.bool,

0 commit comments

Comments
 (0)