@coreui/react 4.5.2 → 4.6.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coreui/react",
3
- "version": "4.5.2",
3
+ "version": "4.6.0",
4
4
  "description": "UI Components Library for React.js",
5
5
  "keywords": [
6
6
  "react",
@@ -35,24 +35,24 @@
35
35
  "build": "rollup -c --bundleConfigAsCjs"
36
36
  },
37
37
  "devDependencies": {
38
- "@popperjs/core": "^2.11.5",
38
+ "@popperjs/core": "^2.11.6",
39
39
  "@rollup/plugin-commonjs": "^24.0.1",
40
40
  "@rollup/plugin-node-resolve": "^15.0.1",
41
41
  "@rollup/plugin-typescript": "^11.0.0",
42
42
  "@testing-library/jest-dom": "^5.16.5",
43
43
  "@testing-library/react": "^13.4.0",
44
44
  "@types/react": "18.0.27",
45
- "@types/react-dom": "^18.0.6",
45
+ "@types/react-dom": "^18.0.10",
46
46
  "@types/react-transition-group": "^4.4.5",
47
47
  "classnames": "^2.3.2",
48
48
  "prop-types": "^15.8.1",
49
49
  "react": "^18.2.0",
50
50
  "react-dom": "^18.2.0",
51
- "react-popper": "^2.2.5",
51
+ "react-popper": "^2.3.0",
52
52
  "react-transition-group": "^4.4.5",
53
- "rollup": "^3.7.5",
54
- "tslib": "^2.4.1",
55
- "typescript": "^4.9.4"
53
+ "rollup": "^3.14.0",
54
+ "tslib": "^2.5.0",
55
+ "typescript": "^4.9.5"
56
56
  },
57
57
  "peerDependencies": {
58
58
  "react": ">=17",
@@ -6,7 +6,7 @@ import { Transition } from 'react-transition-group'
6
6
  import { Colors, colorPropType } from '../Types'
7
7
  import { CCloseButton } from '../close-button/CCloseButton'
8
8
 
9
- import { useForkedRef } from '../../utils/hooks'
9
+ import { useForkedRef } from '../../hooks'
10
10
 
11
11
  export interface CAlertProps extends HTMLAttributes<HTMLDivElement> {
12
12
  /**
@@ -3,7 +3,7 @@ import { Transition } from 'react-transition-group'
3
3
  import PropTypes from 'prop-types'
4
4
  import classNames from 'classnames'
5
5
 
6
- import { useForkedRef } from '../../utils/hooks'
6
+ import { useForkedRef } from '../../hooks'
7
7
 
8
8
  export interface CBackdropProps extends HTMLAttributes<HTMLDivElement> {
9
9
  /**
@@ -12,7 +12,7 @@ import PropTypes from 'prop-types'
12
12
  import classNames from 'classnames'
13
13
 
14
14
  import { isInViewport } from '../../utils'
15
- import { useForkedRef } from '../../utils/hooks'
15
+ import { useForkedRef } from '../../hooks'
16
16
 
17
17
  export interface CCarouselProps extends HTMLAttributes<HTMLDivElement> {
18
18
  /**
@@ -2,7 +2,7 @@ import React, { forwardRef, HTMLAttributes, useContext, useEffect, useState, use
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 { CCarouselContext } from './CCarousel'
7
7
  export interface CCarouselItemProps extends HTMLAttributes<HTMLDivElement> {
8
8
  /**
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
  import { CSSTransition } from 'react-transition-group'
5
5
 
6
- import { useForkedRef } from '../../utils/hooks'
6
+ import { useForkedRef } from '../../hooks'
7
7
 
8
8
  export interface CCollapseProps extends HTMLAttributes<HTMLDivElement> {
9
9
  /**
@@ -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
 
@@ -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'
@@ -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> {
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
  import { Transition } from 'react-transition-group'
5
5
 
6
- import { useForkedRef } from '../../utils/hooks'
6
+ import { useForkedRef } from '../../hooks'
7
7
  export interface CTabPaneProps extends HTMLAttributes<HTMLDivElement> {
8
8
  /**
9
9
  * A string of all className you want applied to the base component.
@@ -12,7 +12,7 @@ import classNames from 'classnames'
12
12
 
13
13
  import { Colors, colorPropType } from '../Types'
14
14
 
15
- import { useForkedRef } from '../../utils/hooks'
15
+ import { useForkedRef } from '../../hooks'
16
16
 
17
17
  export interface CToastProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title'> {
18
18
  /**
File without changes
File without changes