Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 08dde3d

Browse filesBrowse files
committed
refactor(CModal): move the context outside the component
1 parent 56e615d commit 08dde3d
Copy full SHA for 08dde3d

File tree

4 files changed

+23
-23
lines changed
Filter options

4 files changed

+23
-23
lines changed

‎packages/coreui-react/src/components/dropdown/CDropdown.tsx

Copy file name to clipboardExpand all lines: packages/coreui-react/src/components/dropdown/CDropdown.tsx
+3-20Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
1-
import React, {
2-
createContext,
3-
ElementType,
4-
forwardRef,
5-
HTMLAttributes,
6-
RefObject,
7-
useEffect,
8-
useRef,
9-
useState,
10-
} from 'react'
1+
import React, { ElementType, forwardRef, HTMLAttributes, useEffect, useRef, useState } from 'react'
112
import PropTypes from 'prop-types'
123
import classNames from 'classnames'
134
import type { Options } from '@popperjs/core'
145

6+
import { CDropdownContext } from './CDropdownContext'
7+
158
import { PolymorphicRefForwardingComponent } from '../../helpers'
169
import { useForkedRef, usePopper } from '../../hooks'
1710
import { placementPropType } from '../../props'
@@ -169,16 +162,6 @@ export interface CDropdownProps extends HTMLAttributes<HTMLDivElement | HTMLLIEl
169162
visible?: boolean
170163
}
171164

172-
interface ContextProps extends CDropdownProps {
173-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
174-
dropdownToggleRef: RefObject<any | null>
175-
dropdownMenuRef: RefObject<HTMLDivElement | HTMLUListElement | null>
176-
setVisible: React.Dispatch<React.SetStateAction<boolean | undefined>>
177-
portal: boolean
178-
}
179-
180-
export const CDropdownContext = createContext({} as ContextProps)
181-
182165
export const CDropdown: PolymorphicRefForwardingComponent<'div', CDropdownProps> = forwardRef<
183166
HTMLDivElement | HTMLLIElement,
184167
CDropdownProps
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { createContext, RefObject } from 'react'
2+
import { Alignments } from './types'
3+
4+
export interface CDropdownContextProps {
5+
alignment?: Alignments
6+
container?: DocumentFragment | Element | (() => DocumentFragment | Element | null) | null
7+
dark?: boolean
8+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
9+
dropdownToggleRef: RefObject<any | null>
10+
dropdownMenuRef: RefObject<HTMLDivElement | HTMLUListElement | null>
11+
setVisible: React.Dispatch<React.SetStateAction<boolean | undefined>>
12+
popper?: boolean
13+
portal?: boolean
14+
variant?: 'btn-group' | 'dropdown' | 'input-group' | 'nav-item'
15+
visible?: boolean
16+
}
17+
18+
export const CDropdownContext = createContext({} as CDropdownContextProps)

‎packages/coreui-react/src/components/dropdown/CDropdownMenu.tsx

Copy file name to clipboardExpand all lines: packages/coreui-react/src/components/dropdown/CDropdownMenu.tsx
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import React, { ElementType, forwardRef, HTMLAttributes, useContext } from 'reac
22
import PropTypes from 'prop-types'
33
import classNames from 'classnames'
44

5-
import { CDropdownContext } from './CDropdown'
65
import { CConditionalPortal } from '../conditional-portal'
6+
import { CDropdownContext } from './CDropdownContext'
77

88
import { PolymorphicRefForwardingComponent } from '../../helpers'
99
import { useForkedRef } from '../../hooks'

‎packages/coreui-react/src/components/dropdown/CDropdownToggle.tsx

Copy file name to clipboardExpand all lines: packages/coreui-react/src/components/dropdown/CDropdownToggle.tsx
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import PropTypes from 'prop-types'
33
import classNames from 'classnames'
44

55
import { CButton, CButtonProps } from '../button/CButton'
6-
7-
import { CDropdownContext } from './CDropdown'
6+
import { CDropdownContext } from './CDropdownContext'
87

98
import { triggerPropType } from '../../props'
109
import type { Triggers } from '../../types'

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.