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 de2290b

Browse filesBrowse files
committed
refactor(CCarousel): move the context outside the component
1 parent ad0ef5e commit de2290b
Copy full SHA for de2290b

File tree

Expand file treeCollapse file tree

4 files changed

+18
-14
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+18
-14
lines changed

‎packages/coreui-react/src/components/carousel/CCarousel.tsx

Copy file name to clipboardExpand all lines: packages/coreui-react/src/components/carousel/CCarousel.tsx
+6-12Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React, {
22
Children,
3-
createContext,
43
forwardRef,
54
HTMLAttributes,
65
TouchEvent,
@@ -14,6 +13,8 @@ import classNames from 'classnames'
1413
import { isInViewport } from '../../utils'
1514
import { useForkedRef } from '../../hooks'
1615

16+
import { CCarouselContext } from './CCarouselContext'
17+
1718
export interface CCarouselProps extends HTMLAttributes<HTMLDivElement> {
1819
/**
1920
* index of the active item.
@@ -71,13 +72,6 @@ interface DataType {
7172
timeout?: null | ReturnType<typeof setTimeout>
7273
}
7374

74-
export interface ContextProps {
75-
setAnimating: (a: boolean) => void
76-
setCustomInterval: (a: boolean | number) => void
77-
}
78-
79-
export const CCarouselContext = createContext({} as ContextProps)
80-
8175
export const CCarousel = forwardRef<HTMLDivElement, CCarouselProps>(
8276
(
8377
{
@@ -96,7 +90,7 @@ export const CCarousel = forwardRef<HTMLDivElement, CCarouselProps>(
9690
wrap = true,
9791
...rest
9892
},
99-
ref,
93+
ref
10094
) => {
10195
const carouselRef = useRef<HTMLDivElement>(null)
10296
const forkedRef = useForkedRef(ref, carouselRef)
@@ -141,7 +135,7 @@ export const CCarousel = forwardRef<HTMLDivElement, CCarouselProps>(
141135
if (typeof interval === 'number') {
142136
data.timeout = setTimeout(
143137
() => nextItemWhenVisible(),
144-
typeof customInterval === 'number' ? customInterval : interval,
138+
typeof customInterval === 'number' ? customInterval : interval
145139
)
146140
}
147141
}
@@ -228,7 +222,7 @@ export const CCarousel = forwardRef<HTMLDivElement, CCarouselProps>(
228222
{
229223
'carousel-fade': transition === 'crossfade',
230224
},
231-
className,
225+
className
232226
)}
233227
{...(dark && { 'data-coreui-theme': 'dark' })}
234228
onMouseEnter={_pause}
@@ -288,7 +282,7 @@ export const CCarousel = forwardRef<HTMLDivElement, CCarouselProps>(
288282
</CCarouselContext.Provider>
289283
</div>
290284
)
291-
},
285+
}
292286
)
293287

294288
CCarousel.propTypes = {

‎packages/coreui-react/src/components/carousel/CCarouselCaption.tsx

Copy file name to clipboardExpand all lines: packages/coreui-react/src/components/carousel/CCarouselCaption.tsx
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface CCarouselCaptionProps extends HTMLAttributes<HTMLDivElement> {
1212
export const CCarouselCaption = forwardRef<HTMLDivElement, CCarouselCaptionProps>(
1313
({ className, ...rest }, ref) => {
1414
return <div className={classNames('carousel-caption', className)} {...rest} ref={ref} />
15-
},
15+
}
1616
)
1717

1818
CCarouselCaption.propTypes = {
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { createContext } from 'react'
2+
3+
export interface CCarouselContextProps {
4+
setAnimating: (a: boolean) => void
5+
setCustomInterval: (a: boolean | number) => void
6+
}
7+
8+
export const CCarouselContext = createContext({} as CCarouselContextProps)

‎packages/coreui-react/src/components/carousel/CCarouselItem.tsx

Copy file name to clipboardExpand all lines: packages/coreui-react/src/components/carousel/CCarouselItem.tsx
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import PropTypes from 'prop-types'
33
import classNames from 'classnames'
44

55
import { useForkedRef } from '../../hooks'
6-
import { CCarouselContext } from './CCarousel'
6+
7+
import { CCarouselContext } from './CCarouselContext'
8+
79
export interface CCarouselItemProps extends HTMLAttributes<HTMLDivElement> {
810
/**
911
* @ignore

0 commit comments

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