@coreui/react-pro 4.8.0 → 4.9.0-next.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.
Files changed (67) hide show
  1. package/README.md +1 -1
  2. package/dist/components/calendar/index.d.ts +2 -0
  3. package/dist/components/calendar/utils.d.ts +23 -0
  4. package/dist/components/date-picker/CDatePicker.d.ts +1 -1
  5. package/dist/components/date-range-picker/CDateRangePicker.d.ts +2 -2
  6. package/dist/components/element-cover/CElementCover.d.ts +0 -4
  7. package/dist/components/element-cover/index.d.ts +2 -0
  8. package/dist/components/index.d.ts +1 -0
  9. package/dist/components/offcanvas/COffcanvas.d.ts +7 -1
  10. package/dist/components/smart-table/CSmartTableBody.d.ts +6 -5
  11. package/dist/components/smart-table/CSmartTableHead.d.ts +6 -3
  12. package/dist/components/smart-table/CSmartTableInterface.d.ts +30 -59
  13. package/dist/components/smart-table/types.d.ts +53 -0
  14. package/dist/components/smart-table/utils.d.ts +16 -0
  15. package/dist/components/time-picker/types.d.ts +15 -0
  16. package/dist/components/time-picker/utils.d.ts +23 -0
  17. package/dist/hooks/index.d.ts +3 -0
  18. package/dist/hooks/useForkedRef.d.ts +7 -0
  19. package/dist/hooks/useStateWithCallback.d.ts +2 -0
  20. package/dist/index.es.js +1076 -1005
  21. package/dist/index.es.js.map +1 -1
  22. package/dist/index.js +1076 -1004
  23. package/dist/index.js.map +1 -1
  24. package/dist/utils/index.d.ts +2 -1
  25. package/dist/utils/isObjectInArray.d.ts +2 -0
  26. package/package.json +11 -11
  27. package/src/components/alert/CAlert.tsx +1 -1
  28. package/src/components/backdrop/CBackdrop.tsx +1 -1
  29. package/src/components/calendar/CCalendar.tsx +351 -240
  30. package/src/components/calendar/index.ts +3 -0
  31. package/src/{utils/calendar.ts → components/calendar/utils.ts} +1 -1
  32. package/src/components/carousel/CCarousel.tsx +1 -1
  33. package/src/components/carousel/CCarouselItem.tsx +1 -1
  34. package/src/components/collapse/CCollapse.tsx +1 -1
  35. package/src/components/date-picker/CDatePicker.tsx +1 -1
  36. package/src/components/date-range-picker/CDateRangePicker.tsx +3 -3
  37. package/src/components/dropdown/CDropdown.tsx +1 -1
  38. package/src/components/dropdown/CDropdownToggle.tsx +1 -1
  39. package/src/components/element-cover/CElementCover.tsx +16 -22
  40. package/src/components/element-cover/index.ts +3 -0
  41. package/src/components/form/CFormCheck.tsx +1 -1
  42. package/src/components/index.ts +1 -0
  43. package/src/components/modal/CModal.tsx +1 -1
  44. package/src/components/nav/CNavLink.tsx +2 -1
  45. package/src/components/offcanvas/COffcanvas.tsx +35 -17
  46. package/src/components/sidebar/CSidebar.tsx +1 -1
  47. package/src/components/smart-table/CSmartTable.tsx +262 -256
  48. package/src/components/smart-table/CSmartTableBody.tsx +31 -41
  49. package/src/components/smart-table/CSmartTableCleaner.tsx +1 -1
  50. package/src/components/smart-table/CSmartTableFilter.tsx +1 -3
  51. package/src/components/smart-table/CSmartTableHead.tsx +53 -103
  52. package/src/components/smart-table/CSmartTableInterface.tsx +41 -71
  53. package/src/components/smart-table/CSmartTableItemsPerPageSelector.tsx +1 -2
  54. package/src/components/smart-table/types.tsx +65 -0
  55. package/src/components/smart-table/utils.tsx +199 -0
  56. package/src/components/tabs/CTabPane.tsx +1 -1
  57. package/src/components/time-picker/CTimePicker.tsx +50 -23
  58. package/src/components/time-picker/CTimePickerRollCol.tsx +1 -1
  59. package/src/components/time-picker/types.ts +15 -0
  60. package/src/{utils/time.ts → components/time-picker/utils.ts} +43 -2
  61. package/src/components/toast/CToast.tsx +1 -1
  62. package/src/components/virtual-scroller/CVirtualScroller.tsx +1 -1
  63. package/src/{utils/hooks → hooks}/index.ts +0 -0
  64. package/src/{utils/hooks → hooks}/useForkedRef.ts +0 -0
  65. package/src/{utils/hooks → hooks}/useStateWithCallback.ts +0 -0
  66. package/src/utils/index.ts +2 -1
  67. package/src/utils/isObjectInArray.ts +14 -0
@@ -23,7 +23,7 @@ export interface CDatePickerProps
23
23
  * The id global attribute defines an identifier (ID) that must be unique in the whole document.
24
24
  *
25
25
  * The name attribute for the input element is generated based on the `id` property:
26
- * - {id}-date
26
+ * - \{id\}-date
27
27
  */
28
28
  id?: string
29
29
  /**
@@ -12,7 +12,7 @@ import { CFormControlWrapper, CFormControlWrapperProps } from '../form/CFormCont
12
12
  import { CPicker, CPickerProps } from '../picker/CPicker'
13
13
  import { CTimePicker } from '../time-picker/CTimePicker'
14
14
 
15
- import { getLocalDateFromString } from '../../utils/calendar'
15
+ import { getLocalDateFromString } from '../calendar/utils'
16
16
 
17
17
  import { Colors } from '../Types'
18
18
  export interface CDateRangePickerProps
@@ -46,8 +46,8 @@ export interface CDateRangePickerProps
46
46
  * The id global attribute defines an identifier (ID) that must be unique in the whole document.
47
47
  *
48
48
  * The name attributes for input elements are generated based on the `id` property:
49
- * - {id}-start-date
50
- * - {id}-end-date
49
+ * - \{id\}-start-date
50
+ * - \{id\}-end-date
51
51
  */
52
52
  id?: string
53
53
  /**
@@ -13,7 +13,7 @@ import classNames from 'classnames'
13
13
  import { Manager } from 'react-popper'
14
14
 
15
15
  import { Placements, placementPropType } from '../Types'
16
- import { useForkedRef } from '../../utils/hooks'
16
+ import { useForkedRef } from '../../hooks'
17
17
 
18
18
  export type Directions = 'start' | 'end'
19
19
 
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
  import { Reference } from 'react-popper'
5
5
 
6
- import { useForkedRef } from '../../utils/hooks'
6
+ import { useForkedRef } from '../../hooks'
7
7
 
8
8
  import { Triggers, triggerPropType } from '../Types'
9
9
 
@@ -9,7 +9,7 @@ import React, {
9
9
  } from 'react'
10
10
  import classNames from 'classnames'
11
11
 
12
- import { useForkedRef } from '../../utils/hooks'
12
+ import { useForkedRef } from '../../hooks'
13
13
  import { CSpinner } from '../spinner/CSpinner'
14
14
 
15
15
  interface CElementCoverProps extends HTMLAttributes<HTMLDivElement> {
@@ -21,14 +21,10 @@ interface CElementCoverProps extends HTMLAttributes<HTMLDivElement> {
21
21
  * Array of custom boundaries. Use to create custom cover area (instead of parent element area). Area is defined by four sides: 'top', 'bottom', 'right', 'left'. If side is not defined by any custom boundary it is equal to parent element boundary. Each custom boundary is object with keys:
22
22
  * - sides (array) - select boundaries of element to define boundaries. Sides names: 'top', 'bottom', 'right', 'left'.
23
23
  * - query (string) - query used to get element which define boundaries. Search will be done only inside parent element, by parent.querySelector(query) function.
24
- *
25
- * @type {sides: string[], query: string}[]
26
24
  */
27
- boundaries?: { sides: string[]; query: string }[] // TODO: check if this is correct, TJ
25
+ boundaries?: { sides: string[]; query: string }[]
28
26
  /**
29
27
  * Opacity of the cover.
30
- *
31
- * @type number
32
28
  */
33
29
  opacity?: number
34
30
  }
@@ -36,17 +32,18 @@ export const CElementCover = forwardRef<HTMLDivElement, CElementCoverProps>(
36
32
  ({ children, className, boundaries, opacity = 0.4, ...rest }, ref) => {
37
33
  const elementCoverRef = useRef<HTMLDivElement>(null)
38
34
  const forkedRef = useForkedRef(ref, elementCoverRef)
39
-
40
35
  const [customBoundaries, setCustomBoundaries] = useState({})
41
36
 
42
37
  const getCustomBoundaries = () => {
43
38
  if (!elementCoverRef || !elementCoverRef.current || !boundaries) {
44
39
  return {}
45
40
  }
41
+
46
42
  const parent = elementCoverRef.current.parentElement
47
43
  if (!parent) {
48
44
  return {}
49
45
  }
46
+
50
47
  const parentCoords = parent.getBoundingClientRect()
51
48
  const customBoundaries = {}
52
49
  boundaries.forEach(({ sides, query }) => {
@@ -54,6 +51,7 @@ export const CElementCover = forwardRef<HTMLDivElement, CElementCoverProps>(
54
51
  if (!element || !sides) {
55
52
  return
56
53
  }
54
+
57
55
  const coords = element.getBoundingClientRect()
58
56
  sides.forEach((side) => {
59
57
  const sideMargin = Math.abs(coords[side] - parentCoords[side])
@@ -67,8 +65,6 @@ export const CElementCover = forwardRef<HTMLDivElement, CElementCoverProps>(
67
65
  setCustomBoundaries(getCustomBoundaries())
68
66
  }, [JSON.stringify(getCustomBoundaries())])
69
67
 
70
- //render
71
-
72
68
  const classes = classNames(className)
73
69
 
74
70
  const containerCoords = {
@@ -82,23 +78,21 @@ export const CElementCover = forwardRef<HTMLDivElement, CElementCoverProps>(
82
78
  const coverStyles: CSSProperties = {
83
79
  ...containerCoords,
84
80
  position: 'absolute',
85
- backgroundColor: `rgb(255,255,255,${opacity})`,
81
+ backgroundColor: `rgba(255,255,255,${opacity})`,
86
82
  }
87
83
 
88
84
  return (
89
85
  <div className={classes} style={coverStyles} {...rest} ref={forkedRef}>
90
- {children || (
91
- <div
92
- style={{
93
- position: 'absolute',
94
- top: '50%',
95
- left: '50%',
96
- transform: 'translateX(-50%) translateY(-50%)',
97
- }}
98
- >
99
- <CSpinner variant="grow" color="primary" />
100
- </div>
101
- )}
86
+ <div
87
+ style={{
88
+ position: 'absolute',
89
+ top: '50%',
90
+ left: '50%',
91
+ transform: 'translateX(-50%) translateY(-50%)',
92
+ }}
93
+ >
94
+ {children || <CSpinner variant="grow" color="primary" />}
95
+ </div>
102
96
  </div>
103
97
  )
104
98
  },
@@ -0,0 +1,3 @@
1
+ import { CElementCover } from './CElementCover'
2
+
3
+ export { CElementCover }
@@ -2,7 +2,7 @@ import React, { forwardRef, InputHTMLAttributes, ReactNode, useEffect, useRef }
2
2
  import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
 
5
- import { useForkedRef } from '../../utils/hooks'
5
+ import { useForkedRef } from '../../hooks'
6
6
  import { Colors, Shapes } from '../Types'
7
7
 
8
8
  import { CFormControlValidation, CFormControlValidationProps } from './CFormControlValidation'
@@ -14,6 +14,7 @@ export * from './collapse'
14
14
  export * from './date-picker'
15
15
  export * from './date-range-picker'
16
16
  export * from './dropdown'
17
+ export * from './element-cover'
17
18
  export * from './footer'
18
19
  export * from './form'
19
20
  export * from './grid'
@@ -13,7 +13,7 @@ import PropTypes from 'prop-types'
13
13
  import classNames from 'classnames'
14
14
  import { Transition } from 'react-transition-group'
15
15
 
16
- import { useForkedRef } from '../../utils/hooks'
16
+ import { useForkedRef } from '../../hooks'
17
17
 
18
18
  import { CBackdrop } from '../backdrop/CBackdrop'
19
19
  import { CModalContent } from './CModalContent'
@@ -2,10 +2,11 @@ import React, { ElementType, forwardRef, useContext, useEffect, useRef } from 'r
2
2
  import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
 
5
- import { useForkedRef } from '../../utils/hooks'
5
+ import { useForkedRef } from '../../hooks'
6
6
 
7
7
  import { CNavContext } from '../sidebar/CSidebarNav'
8
8
  import { CLinkProps, CLink } from '../link/CLink'
9
+
9
10
  export interface CNavLinkProps extends Omit<CLinkProps, 'idx'> {
10
11
  /**
11
12
  * Toggle the active state for the component.
@@ -4,14 +4,14 @@ import { createPortal } from 'react-dom'
4
4
  import { Transition } from 'react-transition-group'
5
5
  import classNames from 'classnames'
6
6
 
7
- import { useForkedRef } from '../../utils/hooks'
7
+ import { useForkedRef } from '../../hooks'
8
8
  import { CBackdrop } from '../backdrop/CBackdrop'
9
9
 
10
10
  export interface COffcanvasProps extends HTMLAttributes<HTMLDivElement> {
11
11
  /**
12
12
  * Apply a backdrop on body while offcanvas is open.
13
13
  */
14
- backdrop?: boolean
14
+ backdrop?: boolean | 'static'
15
15
  /**
16
16
  * A string of all className you want applied to the base component.
17
17
  */
@@ -36,6 +36,12 @@ export interface COffcanvasProps extends HTMLAttributes<HTMLDivElement> {
36
36
  * Generates modal using createPortal.
37
37
  */
38
38
  portal?: boolean
39
+ /**
40
+ * Responsive offcanvas property hide content outside the viewport from a specified breakpoint and down.
41
+ *
42
+ * @since 4.6.0
43
+ */
44
+ responsive?: boolean | 'sm' | 'md' | 'lg' | 'xl' | 'xxl'
39
45
  /**
40
46
  * Allow body scrolling while offcanvas is open
41
47
  */
@@ -56,7 +62,8 @@ export const COffcanvas = forwardRef<HTMLDivElement, COffcanvasProps>(
56
62
  onHide,
57
63
  onShow,
58
64
  placement,
59
- portal = true,
65
+ portal = false,
66
+ responsive = true,
60
67
  scroll = false,
61
68
  visible = false,
62
69
  ...rest
@@ -86,26 +93,34 @@ export const COffcanvas = forwardRef<HTMLDivElement, COffcanvasProps>(
86
93
  }
87
94
  }, [_visible])
88
95
 
96
+ const getTransitionClass = (state: string) => {
97
+ return state === 'entering'
98
+ ? 'showing'
99
+ : state === 'entered'
100
+ ? 'show'
101
+ : state === 'exiting'
102
+ ? 'show hiding'
103
+ : ''
104
+ }
105
+
89
106
  const _className = classNames(
90
- 'offcanvas',
91
107
  {
108
+ [`offcanvas${typeof responsive !== 'boolean' ? '-' + responsive : ''}`]: responsive,
92
109
  [`offcanvas-${placement}`]: placement,
93
- show: _visible,
94
110
  },
95
111
  className,
96
112
  )
97
113
 
98
- const transitionStyles = {
99
- entering: { visibility: 'visible' },
100
- entered: { visibility: 'visible' },
101
- exiting: { visibility: 'visible' },
102
- exited: { visibility: 'hidden' },
103
- }
104
-
105
114
  const handleDismiss = () => {
106
115
  setVisible(false)
107
116
  }
108
117
 
118
+ const handleBackdropDismiss = () => {
119
+ if (backdrop !== 'static') {
120
+ setVisible(false)
121
+ }
122
+ }
123
+
109
124
  const handleKeyDown = useCallback(
110
125
  (event: React.KeyboardEvent<HTMLDivElement>) => {
111
126
  if (event.key === 'Escape' && keyboard) {
@@ -119,9 +134,8 @@ export const COffcanvas = forwardRef<HTMLDivElement, COffcanvasProps>(
119
134
  return (
120
135
  <>
121
136
  <div
122
- className={_className}
137
+ className={classNames(_className, getTransitionClass(state))}
123
138
  role="dialog"
124
- style={{ ...transitionStyles[state] }}
125
139
  tabIndex={-1}
126
140
  onKeyDown={handleKeyDown}
127
141
  {...rest}
@@ -154,7 +168,7 @@ export const COffcanvas = forwardRef<HTMLDivElement, COffcanvasProps>(
154
168
  createPortal(
155
169
  <CBackdrop
156
170
  className="offcanvas-backdrop"
157
- onClick={handleDismiss}
171
+ onClick={handleBackdropDismiss}
158
172
  visible={_visible}
159
173
  />,
160
174
  document.body,
@@ -162,7 +176,7 @@ export const COffcanvas = forwardRef<HTMLDivElement, COffcanvasProps>(
162
176
  : backdrop && (
163
177
  <CBackdrop
164
178
  className="offcanvas-backdrop"
165
- onClick={handleDismiss}
179
+ onClick={handleBackdropDismiss}
166
180
  visible={_visible}
167
181
  />
168
182
  )}
@@ -172,7 +186,7 @@ export const COffcanvas = forwardRef<HTMLDivElement, COffcanvasProps>(
172
186
  )
173
187
 
174
188
  COffcanvas.propTypes = {
175
- backdrop: PropTypes.bool,
189
+ backdrop: PropTypes.oneOfType([PropTypes.bool, PropTypes.oneOf<'static'>(['static'])]),
176
190
  children: PropTypes.node,
177
191
  className: PropTypes.string,
178
192
  keyboard: PropTypes.bool,
@@ -181,6 +195,10 @@ COffcanvas.propTypes = {
181
195
  placement: PropTypes.oneOf<'start' | 'end' | 'top' | 'bottom'>(['start', 'end', 'top', 'bottom'])
182
196
  .isRequired,
183
197
  portal: PropTypes.bool,
198
+ responsive: PropTypes.oneOfType([
199
+ PropTypes.bool,
200
+ PropTypes.oneOf<'sm' | 'md' | 'lg' | 'xl' | 'xxl'>(['sm', 'md', 'lg', 'xl', 'xxl']),
201
+ ]),
184
202
  scroll: PropTypes.bool,
185
203
  visible: PropTypes.bool,
186
204
  }
@@ -4,7 +4,7 @@ import PropTypes from 'prop-types'
4
4
  import classNames from 'classnames'
5
5
 
6
6
  import { isInViewport } from '../../utils'
7
- import { useForkedRef } from '../../utils/hooks'
7
+ import { useForkedRef } from '../../hooks'
8
8
  import { CBackdrop } from '../backdrop/CBackdrop'
9
9
 
10
10
  export interface CSidebarProps extends HTMLAttributes<HTMLDivElement> {