File tree
Expand file treeCollapse file tree4 files changed
+17
-14
lines changed packages/coreui-react/src/components
Expand file treeCollapse file tree4 files changed
+17
-14
lines changed Original file line number | Diff line number | Diff line change |
---|
@@ -16,7 +16,7 @@ import type { TransitionStatus } from 'react-transition-group'
|
16 | 16 |
|
17 | 17 | import { PolymorphicRefForwardingComponent } from '../../helpers'
|
18 | 18 |
|
19 |
| -import { CNavContext } from '../sidebar/CSidebarNav' |
| 19 | +import { CSidebarNavContext } from '../sidebar/CSidebarNavContext' |
20 | 20 |
|
21 | 21 | export interface CNavGroupProps extends HTMLAttributes<HTMLDivElement | HTMLLIElement> {
|
22 | 22 | /**
|
@@ -62,7 +62,7 @@ export const CNavGroup: PolymorphicRefForwardingComponent<'li', CNavGroupProps>
|
62 | 62 | // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
63 | 63 | const navItemsRef = useRef<any>(null)
|
64 | 64 |
|
65 |
| -const { visibleGroup, setVisibleGroup } = useContext(CNavContext) |
| 65 | +const { visibleGroup, setVisibleGroup } = useContext(CSidebarNavContext) |
66 | 66 |
|
67 | 67 | const [_visible, setVisible] = useState(
|
68 | 68 | Boolean(visible || (idx && visibleGroup && isInVisibleGroup(visibleGroup, idx))),
|
|
Original file line number | Diff line number | Diff line change |
---|
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types'
|
3 | 3 | import classNames from 'classnames'
|
4 | 4 |
|
5 | 5 | import { CLinkProps, CLink } from '../link/CLink'
|
6 |
| -import { CNavContext } from '../sidebar/CSidebarNav' |
| 6 | +import { CSidebarNavContext } from '../sidebar/CSidebarNavContext' |
7 | 7 |
|
8 | 8 | import { PolymorphicRefForwardingComponent } from '../../helpers'
|
9 | 9 | import { useForkedRef } from '../../hooks'
|
@@ -26,7 +26,7 @@ export const CNavLink: PolymorphicRefForwardingComponent<'a', CNavLinkProps> = f
|
26 | 26 | const navLinkRef = useRef<HTMLAnchorElement>(null)
|
27 | 27 | const forkedRef = useForkedRef(ref, navLinkRef)
|
28 | 28 |
|
29 |
| -const { setVisibleGroup } = useContext(CNavContext) |
| 29 | +const { setVisibleGroup } = useContext(CSidebarNavContext) |
30 | 30 |
|
31 | 31 | useEffect(() => {
|
32 | 32 | rest.active = navLinkRef.current?.classList.contains('active')
|
|
Original file line number | Diff line number | Diff line change |
---|
|
1 | 1 | import React, {
|
2 |
| -createContext, |
3 | 2 | ElementType,
|
4 | 3 | forwardRef,
|
5 | 4 | HTMLAttributes,
|
@@ -13,6 +12,9 @@ import classNames from 'classnames'
|
13 | 12 | import type { CNavGroupProps } from '../nav/CNavGroup'
|
14 | 13 | import type { CNavLinkProps } from '../nav/CNavLink'
|
15 | 14 | import type { CNavItemProps } from '../nav/CNavItem'
|
| 15 | + |
| 16 | +import { CSidebarNavContext } from './CSidebarNavContext' |
| 17 | + |
16 | 18 | import { PolymorphicRefForwardingComponent } from '../../helpers'
|
17 | 19 |
|
18 | 20 | export interface CSidebarNavProps extends HTMLAttributes<HTMLUListElement> {
|
@@ -28,13 +30,6 @@ export interface CSidebarNavProps extends HTMLAttributes<HTMLUListElement> {
|
28 | 30 | className?: string
|
29 | 31 | }
|
30 | 32 |
|
31 |
| -interface ContextProps { |
32 |
| -visibleGroup: string |
33 |
| -setVisibleGroup: React.Dis<React.SetStateAction<string | undefined>> |
34 |
| -} |
35 |
| - |
36 |
| -export const CNavContext = createContext({} as ContextProps) |
37 |
| - |
38 | 33 | const isNavElement = (
|
39 | 34 | child: ReactNode
|
40 | 35 | ): child is ReactElement<CNavGroupProps | CNavLinkProps | CNavItemProps> => {
|
@@ -82,11 +77,11 @@ export const CSidebarNav: PolymorphicRefForwardingComponent<'ul', CSidebarNavPro
|
82 | 77 | }
|
83 | 78 |
|
84 | 79 | return (
|
85 |
| -<CNavContext.Provider value={CNavContextValues}> |
| 80 | +<CSidebarNavContext.Provider value={CNavContextValues}> |
86 | 81 | <Component className={classNames('sidebar-nav', className)} ref={ref} {...rest}>
|
87 | 82 | {recursiveClone(children)}
|
88 | 83 | </Component>
|
89 |
| -</CNavContext.Provider> |
| 84 | +</CSidebarNavContext.Provider> |
90 | 85 | )
|
91 | 86 | })
|
92 | 87 |
|
|
Original file line number | Diff line number | Diff line change |
---|
|
| 1 | +import { createContext } from 'react' |
| 2 | + |
| 3 | +export interface CSidebarNavContextProps { |
| 4 | +visibleGroup: string |
| 5 | +setVisibleGroup: React.Dis<React.SetStateAction<string | undefined>> |
| 6 | +} |
| 7 | + |
| 8 | +export const CSidebarNavContext = createContext({} as CSidebarNavContextProps) |
You can’t perform that action at this time.
0 commit comments