@coreui/react 4.4.1 → 4.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/components/carousel/CCarousel.d.ts +6 -0
- package/dist/components/form/CFormControlWrapper.d.ts +6 -0
- package/dist/index.es.js +651 -622
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +651 -622
- package/dist/index.js.map +1 -1
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/isVisible.d.ts +2 -0
- package/package.json +3 -3
- package/src/components/carousel/CCarousel.tsx +38 -10
- package/src/components/form/CFormControlWrapper.tsx +20 -1
- package/src/components/form/CFormInput.tsx +2 -0
- package/src/components/form/CFormSelect.tsx +2 -0
- package/src/components/form/CFormTextarea.tsx +2 -0
- package/src/components/modal/CModal.tsx +4 -1
- package/src/components/sidebar/CSidebar.tsx +1 -10
- package/src/utils/index.ts +3 -0
- package/src/utils/isVisible.ts +11 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coreui/react",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.5.0",
|
|
4
4
|
"description": "UI Components Library for React.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@popperjs/core": "^2.11.5",
|
|
39
|
-
"@rollup/plugin-commonjs": "^23.0.
|
|
39
|
+
"@rollup/plugin-commonjs": "^23.0.7",
|
|
40
40
|
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
41
41
|
"@rollup/plugin-typescript": "^10.0.1",
|
|
42
42
|
"@testing-library/jest-dom": "^5.16.5",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"react-dom": "^18.2.0",
|
|
51
51
|
"react-popper": "^2.2.5",
|
|
52
52
|
"react-transition-group": "^4.4.5",
|
|
53
|
-
"rollup": "^3.7.
|
|
53
|
+
"rollup": "^3.7.5",
|
|
54
54
|
"tslib": "^2.4.1",
|
|
55
55
|
"typescript": "^4.9.4"
|
|
56
56
|
},
|
|
@@ -3,6 +3,7 @@ import React, {
|
|
|
3
3
|
createContext,
|
|
4
4
|
forwardRef,
|
|
5
5
|
HTMLAttributes,
|
|
6
|
+
TouchEvent,
|
|
6
7
|
useState,
|
|
7
8
|
useEffect,
|
|
8
9
|
useRef,
|
|
@@ -10,18 +11,9 @@ import React, {
|
|
|
10
11
|
import PropTypes from 'prop-types'
|
|
11
12
|
import classNames from 'classnames'
|
|
12
13
|
|
|
14
|
+
import { isVisible } from '../../utils'
|
|
13
15
|
import { useForkedRef } from '../../utils/hooks'
|
|
14
16
|
|
|
15
|
-
const isVisible = (element: HTMLDivElement) => {
|
|
16
|
-
const rect = element.getBoundingClientRect()
|
|
17
|
-
return (
|
|
18
|
-
rect.top >= 0 &&
|
|
19
|
-
rect.left >= 0 &&
|
|
20
|
-
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
|
|
21
|
-
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
|
|
22
|
-
)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
17
|
export interface CCarouselProps extends HTMLAttributes<HTMLDivElement> {
|
|
26
18
|
/**
|
|
27
19
|
* index of the active item.
|
|
@@ -59,6 +51,12 @@ export interface CCarouselProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
59
51
|
* If set to 'hover', pauses the cycling of the carousel on mouseenter and resumes the cycling of the carousel on mouseleave. If set to false, hovering over the carousel won't pause it.
|
|
60
52
|
*/
|
|
61
53
|
pause?: boolean | 'hover'
|
|
54
|
+
/**
|
|
55
|
+
* Set whether the carousel should support left/right swipe interactions on touchscreen devices.
|
|
56
|
+
*
|
|
57
|
+
* @since 4.5.0
|
|
58
|
+
*/
|
|
59
|
+
touch?: boolean
|
|
62
60
|
/**
|
|
63
61
|
* Set type of the transition.
|
|
64
62
|
*/
|
|
@@ -93,6 +91,7 @@ export const CCarousel = forwardRef<HTMLDivElement, CCarouselProps>(
|
|
|
93
91
|
onSlid,
|
|
94
92
|
onSlide,
|
|
95
93
|
pause = 'hover',
|
|
94
|
+
touch = true,
|
|
96
95
|
transition,
|
|
97
96
|
wrap = true,
|
|
98
97
|
...rest
|
|
@@ -108,6 +107,7 @@ export const CCarousel = forwardRef<HTMLDivElement, CCarouselProps>(
|
|
|
108
107
|
const [customInterval, setCustomInterval] = useState<boolean | number>()
|
|
109
108
|
const [direction, setDirection] = useState<string>('next')
|
|
110
109
|
const [itemsNumber, setItemsNumber] = useState<number>(0)
|
|
110
|
+
const [touchPosition, setTouchPosition] = useState<number | null>(null)
|
|
111
111
|
const [visible, setVisible] = useState<boolean>()
|
|
112
112
|
|
|
113
113
|
useEffect(() => {
|
|
@@ -202,11 +202,38 @@ export const CCarousel = forwardRef<HTMLDivElement, CCarouselProps>(
|
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
+
const handleTouchMove = (e: TouchEvent) => {
|
|
206
|
+
const touchDown = touchPosition
|
|
207
|
+
|
|
208
|
+
if (touchDown === null) {
|
|
209
|
+
return
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const currentTouch = e.touches[0].clientX
|
|
213
|
+
const diff = touchDown - currentTouch
|
|
214
|
+
|
|
215
|
+
if (diff > 5) {
|
|
216
|
+
handleControlClick('next')
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (diff < -5) {
|
|
220
|
+
handleControlClick('prev')
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
setTouchPosition(null)
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const handleTouchStart = (e: TouchEvent) => {
|
|
227
|
+
const touchDown = e.touches[0].clientX
|
|
228
|
+
setTouchPosition(touchDown)
|
|
229
|
+
}
|
|
230
|
+
|
|
205
231
|
return (
|
|
206
232
|
<div
|
|
207
233
|
className={_className}
|
|
208
234
|
onMouseEnter={_pause}
|
|
209
235
|
onMouseLeave={cycle}
|
|
236
|
+
{...(touch && { onTouchStart: handleTouchStart, onTouchMove: handleTouchMove })}
|
|
210
237
|
{...rest}
|
|
211
238
|
ref={forkedRef}
|
|
212
239
|
>
|
|
@@ -271,6 +298,7 @@ CCarousel.propTypes = {
|
|
|
271
298
|
onSlid: PropTypes.func,
|
|
272
299
|
onSlide: PropTypes.func,
|
|
273
300
|
pause: PropTypes.oneOf([false, 'hover']),
|
|
301
|
+
touch: PropTypes.bool,
|
|
274
302
|
transition: PropTypes.oneOf(['slide', 'crossfade']),
|
|
275
303
|
wrap: PropTypes.bool,
|
|
276
304
|
}
|
|
@@ -12,6 +12,12 @@ export interface CFormControlWrapperProps extends CFormControlValidationProps {
|
|
|
12
12
|
* @ignore
|
|
13
13
|
*/
|
|
14
14
|
children?: ReactNode
|
|
15
|
+
/**
|
|
16
|
+
* A string of all className you want applied to the floating label wrapper.
|
|
17
|
+
*
|
|
18
|
+
* @since 4.5.0
|
|
19
|
+
*/
|
|
20
|
+
floatingClassName?: string
|
|
15
21
|
/**
|
|
16
22
|
* Provide valuable, actionable valid feedback when using standard HTML form validation which applied two CSS pseudo-classes, `:invalid` and `:valid`.
|
|
17
23
|
*
|
|
@@ -42,6 +48,7 @@ export const CFormControlWrapper: FC<CFormControlWrapperProps> = ({
|
|
|
42
48
|
feedback,
|
|
43
49
|
feedbackInvalid,
|
|
44
50
|
feedbackValid,
|
|
51
|
+
floatingClassName,
|
|
45
52
|
floatingLabel,
|
|
46
53
|
id,
|
|
47
54
|
invalid,
|
|
@@ -51,9 +58,20 @@ export const CFormControlWrapper: FC<CFormControlWrapperProps> = ({
|
|
|
51
58
|
valid,
|
|
52
59
|
}) => {
|
|
53
60
|
return floatingLabel ? (
|
|
54
|
-
<CFormFloating>
|
|
61
|
+
<CFormFloating className={floatingClassName}>
|
|
55
62
|
{children}
|
|
56
63
|
<CFormLabel htmlFor={id}>{label || floatingLabel}</CFormLabel>
|
|
64
|
+
{text && <CFormText id={describedby}>{text}</CFormText>}
|
|
65
|
+
<CFormControlValidation
|
|
66
|
+
describedby={describedby}
|
|
67
|
+
feedback={feedback}
|
|
68
|
+
feedbackInvalid={feedbackInvalid}
|
|
69
|
+
feedbackValid={feedbackValid}
|
|
70
|
+
floatingLabel={floatingLabel}
|
|
71
|
+
invalid={invalid}
|
|
72
|
+
tooltipFeedback={tooltipFeedback}
|
|
73
|
+
valid={valid}
|
|
74
|
+
/>
|
|
57
75
|
</CFormFloating>
|
|
58
76
|
) : (
|
|
59
77
|
<>
|
|
@@ -76,6 +94,7 @@ export const CFormControlWrapper: FC<CFormControlWrapperProps> = ({
|
|
|
76
94
|
|
|
77
95
|
CFormControlWrapper.propTypes = {
|
|
78
96
|
children: PropTypes.node,
|
|
97
|
+
floatingClassName: PropTypes.string,
|
|
79
98
|
floatingLabel: PropTypes.oneOfType([PropTypes.node, PropTypes.string]),
|
|
80
99
|
label: PropTypes.oneOfType([PropTypes.node, PropTypes.string]),
|
|
81
100
|
text: PropTypes.oneOfType([PropTypes.node, PropTypes.string]),
|
|
@@ -58,6 +58,7 @@ export const CFormInput = forwardRef<HTMLInputElement, CFormInputProps>(
|
|
|
58
58
|
feedback,
|
|
59
59
|
feedbackInvalid,
|
|
60
60
|
feedbackValid,
|
|
61
|
+
floatingClassName,
|
|
61
62
|
floatingLabel,
|
|
62
63
|
id,
|
|
63
64
|
invalid,
|
|
@@ -101,6 +102,7 @@ export const CFormInput = forwardRef<HTMLInputElement, CFormInputProps>(
|
|
|
101
102
|
feedback={feedback}
|
|
102
103
|
feedbackInvalid={feedbackInvalid}
|
|
103
104
|
feedbackValid={feedbackValid}
|
|
105
|
+
floatingClassName={floatingClassName}
|
|
104
106
|
floatingLabel={floatingLabel}
|
|
105
107
|
id={id}
|
|
106
108
|
invalid={invalid}
|
|
@@ -52,6 +52,7 @@ export const CFormSelect = forwardRef<HTMLSelectElement, CFormSelectProps>(
|
|
|
52
52
|
feedback,
|
|
53
53
|
feedbackInvalid,
|
|
54
54
|
feedbackValid,
|
|
55
|
+
floatingClassName,
|
|
55
56
|
floatingLabel,
|
|
56
57
|
htmlSize,
|
|
57
58
|
id,
|
|
@@ -81,6 +82,7 @@ export const CFormSelect = forwardRef<HTMLSelectElement, CFormSelectProps>(
|
|
|
81
82
|
feedback={feedback}
|
|
82
83
|
feedbackInvalid={feedbackInvalid}
|
|
83
84
|
feedbackValid={feedbackValid}
|
|
85
|
+
floatingClassName={floatingClassName}
|
|
84
86
|
floatingLabel={floatingLabel}
|
|
85
87
|
id={id}
|
|
86
88
|
invalid={invalid}
|
|
@@ -44,6 +44,7 @@ export const CFormTextarea = forwardRef<HTMLTextAreaElement, CFormTextareaProps>
|
|
|
44
44
|
feedback,
|
|
45
45
|
feedbackInvalid,
|
|
46
46
|
feedbackValid,
|
|
47
|
+
floatingClassName,
|
|
47
48
|
floatingLabel,
|
|
48
49
|
id,
|
|
49
50
|
invalid,
|
|
@@ -70,6 +71,7 @@ export const CFormTextarea = forwardRef<HTMLTextAreaElement, CFormTextareaProps>
|
|
|
70
71
|
feedback={feedback}
|
|
71
72
|
feedbackInvalid={feedbackInvalid}
|
|
72
73
|
feedbackValid={feedbackValid}
|
|
74
|
+
floatingClassName={floatingClassName}
|
|
73
75
|
floatingLabel={floatingLabel}
|
|
74
76
|
id={id}
|
|
75
77
|
invalid={invalid}
|
|
@@ -108,6 +108,7 @@ export const CModal = forwardRef<HTMLDivElement, CModalProps>(
|
|
|
108
108
|
transition = true,
|
|
109
109
|
unmountOnClose = true,
|
|
110
110
|
visible,
|
|
111
|
+
...rest
|
|
111
112
|
},
|
|
112
113
|
ref,
|
|
113
114
|
) => {
|
|
@@ -233,7 +234,9 @@ export const CModal = forwardRef<HTMLDivElement, CModalProps>(
|
|
|
233
234
|
scrollable={scrollable}
|
|
234
235
|
size={size}
|
|
235
236
|
>
|
|
236
|
-
<CModalContent ref={modalContentRef}>
|
|
237
|
+
<CModalContent {...rest} ref={modalContentRef}>
|
|
238
|
+
{children}
|
|
239
|
+
</CModalContent>
|
|
237
240
|
</CModalDialog>
|
|
238
241
|
</div>
|
|
239
242
|
</CModalContext.Provider>
|
|
@@ -3,6 +3,7 @@ import { createPortal } from 'react-dom'
|
|
|
3
3
|
import PropTypes from 'prop-types'
|
|
4
4
|
import classNames from 'classnames'
|
|
5
5
|
|
|
6
|
+
import { isVisible } from '../../utils'
|
|
6
7
|
import { useForkedRef } from '../../utils/hooks'
|
|
7
8
|
import { CBackdrop } from '../backdrop/CBackdrop'
|
|
8
9
|
|
|
@@ -52,16 +53,6 @@ export interface CSidebarProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
52
53
|
const isOnMobile = (element: HTMLDivElement) =>
|
|
53
54
|
Boolean(getComputedStyle(element).getPropertyValue('--cui-is-mobile'))
|
|
54
55
|
|
|
55
|
-
const isVisible = (element: HTMLDivElement) => {
|
|
56
|
-
const rect = element.getBoundingClientRect()
|
|
57
|
-
return (
|
|
58
|
-
rect.top >= 0 &&
|
|
59
|
-
rect.left >= 0 &&
|
|
60
|
-
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
|
|
61
|
-
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
|
|
62
|
-
)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
56
|
export const CSidebar = forwardRef<HTMLDivElement, CSidebarProps>(
|
|
66
57
|
(
|
|
67
58
|
{
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const isVisible = (element: HTMLElement) => {
|
|
2
|
+
const rect = element.getBoundingClientRect()
|
|
3
|
+
return (
|
|
4
|
+
rect.top >= 0 &&
|
|
5
|
+
rect.left >= 0 &&
|
|
6
|
+
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
|
|
7
|
+
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
|
|
8
|
+
)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default isVisible
|