@coreui/react 4.3.1 → 4.4.1

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 (45) hide show
  1. package/README.md +1 -1
  2. package/dist/components/Types.d.ts +6 -6
  3. package/dist/components/button/CButton.d.ts +4 -3
  4. package/dist/components/dropdown/CDropdown.d.ts +4 -6
  5. package/dist/components/dropdown/CDropdownItem.d.ts +1 -1
  6. package/dist/components/form/CFormCheck.d.ts +1 -1
  7. package/dist/components/form/CFormLabel.d.ts +2 -2
  8. package/dist/components/form/CFormRange.d.ts +1 -1
  9. package/dist/components/form/CFormSelect.d.ts +1 -1
  10. package/dist/components/form/CInputGroupText.d.ts +2 -2
  11. package/dist/components/form/index.d.ts +3 -1
  12. package/dist/components/grid/CCol.d.ts +3 -3
  13. package/dist/components/grid/CRow.d.ts +1 -1
  14. package/dist/components/header/CHeaderBrand.d.ts +2 -2
  15. package/dist/components/link/CLink.d.ts +2 -2
  16. package/dist/components/list-group/CListGroupItem.d.ts +3 -3
  17. package/dist/components/nav/CNavLink.d.ts +1 -1
  18. package/dist/components/toast/CToastClose.d.ts +4 -1
  19. package/dist/components/widgets/CWidgetStatsD.d.ts +1 -1
  20. package/dist/index.es.js +107 -70
  21. package/dist/index.es.js.map +1 -1
  22. package/dist/index.js +404 -372
  23. package/dist/index.js.map +1 -1
  24. package/dist/utils/hooks/useForkedRef.d.ts +1 -1
  25. package/package.json +12 -13
  26. package/src/components/button/CButton.tsx +3 -3
  27. package/src/components/carousel/CCarousel.tsx +1 -1
  28. package/src/components/dropdown/CDropdown.tsx +7 -5
  29. package/src/components/dropdown/CDropdownMenu.tsx +8 -0
  30. package/src/components/dropdown/CDropdownToggle.tsx +1 -1
  31. package/src/components/form/CFormLabel.tsx +2 -2
  32. package/src/components/form/CFormRange.tsx +1 -1
  33. package/src/components/form/CInputGroupText.tsx +3 -2
  34. package/src/components/form/__tests__/CFormRange.spec.tsx +2 -2
  35. package/src/components/form/__tests__/CInputGroupText.spec.tsx +9 -0
  36. package/src/components/form/__tests__/__snapshots__/CInputGroupText.spec.tsx.snap +11 -0
  37. package/src/components/form/index.ts +4 -0
  38. package/src/components/header/CHeaderBrand.tsx +3 -2
  39. package/src/components/link/CLink.tsx +2 -2
  40. package/src/components/list-group/CListGroupItem.tsx +2 -2
  41. package/src/components/modal/CModal.tsx +18 -1
  42. package/src/components/nav/CNavGroup.tsx +4 -1
  43. package/src/components/sidebar/CSidebarNav.tsx +4 -1
  44. package/src/components/toast/CToastClose.tsx +4 -1
  45. package/src/components/toast/__tests__/__snapshots__/CToast.spec.tsx.snap +13 -0
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- export declare type AssignableRef<ValueType> = {
2
+ export type AssignableRef<ValueType> = {
3
3
  bivarianceHack(instance: ValueType | null): void;
4
4
  }['bivarianceHack'] | React.MutableRefObject<ValueType | null>;
5
5
  export declare function useForkedRef<RefValueType = any>(...refs: (AssignableRef<RefValueType> | null | undefined)[]): ((node: any) => void) | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coreui/react",
3
- "version": "4.3.1",
3
+ "version": "4.4.1",
4
4
  "description": "UI Components Library for React.js",
5
5
  "keywords": [
6
6
  "react",
@@ -32,28 +32,27 @@
32
32
  "src/"
33
33
  ],
34
34
  "scripts": {
35
- "build": "rollup -c"
35
+ "build": "rollup -c --bundleConfigAsCjs"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@popperjs/core": "^2.11.5",
39
- "@rollup/plugin-commonjs": "^22.0.1",
40
- "@rollup/plugin-node-resolve": "^13.3.0",
41
- "@rollup/plugin-typescript": "^8.3.4",
42
- "@testing-library/jest-dom": "^5.16.4",
43
- "@testing-library/react": "^13.3.0",
44
- "@types/react": "18.0.15",
39
+ "@rollup/plugin-commonjs": "^23.0.4",
40
+ "@rollup/plugin-node-resolve": "^15.0.1",
41
+ "@rollup/plugin-typescript": "^10.0.1",
42
+ "@testing-library/jest-dom": "^5.16.5",
43
+ "@testing-library/react": "^13.4.0",
44
+ "@types/react": "18.0.26",
45
45
  "@types/react-dom": "^18.0.6",
46
46
  "@types/react-transition-group": "^4.4.5",
47
- "classnames": "^2.3.1",
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
51
  "react-popper": "^2.2.5",
52
52
  "react-transition-group": "^4.4.5",
53
- "rollup": "^2.77.2",
54
- "rollup-plugin-peer-deps-external": "^2.2.4",
55
- "tslib": "^2.4.0",
56
- "typescript": "^4.7.4"
53
+ "rollup": "^3.7.2",
54
+ "tslib": "^2.4.1",
55
+ "typescript": "^4.9.4"
57
56
  },
58
57
  "peerDependencies": {
59
58
  "react": ">=17",
@@ -1,11 +1,11 @@
1
- import React, { ButtonHTMLAttributes, ElementType, forwardRef } from 'react'
1
+ import React, { ElementType, forwardRef } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
 
5
5
  import { Colors, Shapes, colorPropType } from '../Types'
6
- import { CLink } from '../link/CLink'
6
+ import { CLink, CLinkProps } from '../link/CLink'
7
7
 
8
- export interface CButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
8
+ export interface CButtonProps extends Omit<CLinkProps, 'size'> {
9
9
  /**
10
10
  * Toggle the active state for the component.
11
11
  */
@@ -235,7 +235,7 @@ export const CCarousel = forwardRef<HTMLDivElement, CCarouselProps>(
235
235
  <div className="carousel-inner">
236
236
  {Children.map(children, (child, index) => {
237
237
  if (React.isValidElement(child)) {
238
- return React.cloneElement(child, {
238
+ return React.cloneElement(child as React.ReactElement<any>, {
239
239
  active: active === index ? true : false,
240
240
  direction: direction,
241
241
  key: index,
@@ -56,10 +56,8 @@ export interface CDropdownProps extends HTMLAttributes<HTMLDivElement | HTMLLIEl
56
56
  dark?: boolean
57
57
  /**
58
58
  * Sets a specified direction and location of the dropdown menu.
59
- *
60
- * @type 'dropup' | 'dropend' | 'dropstart'
61
59
  */
62
- direction?: 'dropup' | 'dropend' | 'dropstart'
60
+ direction?: 'center' | 'dropup' | 'dropup-center' | 'dropend' | 'dropstart'
63
61
  /**
64
62
  * Callback fired when the component requests to be hidden.
65
63
  */
@@ -146,7 +144,11 @@ export const CDropdown = forwardRef<HTMLDivElement | HTMLLIElement, CDropdownPro
146
144
  {
147
145
  show: _visible,
148
146
  },
149
- direction,
147
+ direction === 'center'
148
+ ? 'dropdown-center'
149
+ : direction === 'dropup-center'
150
+ ? 'dropup dropup-center'
151
+ : direction,
150
152
  className,
151
153
  )
152
154
 
@@ -202,7 +204,7 @@ CDropdown.propTypes = {
202
204
  className: PropTypes.string,
203
205
  component: PropTypes.elementType,
204
206
  dark: PropTypes.bool,
205
- direction: PropTypes.oneOf(['dropup', 'dropend', 'dropstart']),
207
+ direction: PropTypes.oneOf(['center', 'dropup', 'dropup-center', 'dropend', 'dropstart']),
206
208
  onHide: PropTypes.func,
207
209
  onShow: PropTypes.func,
208
210
  placement: placementPropType,
@@ -86,10 +86,18 @@ export const CDropdownMenu: FC<CDropdownMenuProps> = ({
86
86
 
87
87
  let _placement: Placements = placement
88
88
 
89
+ if (direction === 'center') {
90
+ _placement = 'bottom'
91
+ }
92
+
89
93
  if (direction === 'dropup') {
90
94
  _placement = 'top-start'
91
95
  }
92
96
 
97
+ if (direction === 'dropup-center') {
98
+ _placement = 'top'
99
+ }
100
+
93
101
  if (direction === 'dropend') {
94
102
  _placement = 'right-start'
95
103
  }
@@ -75,7 +75,7 @@ export const CDropdownToggle: FC<CDropdownToggleProps> = ({
75
75
  const Toggler = (ref?: React.Ref<any>) => {
76
76
  return custom && React.isValidElement(children) ? (
77
77
  <>
78
- {React.cloneElement(children, {
78
+ {React.cloneElement(children as React.ReactElement<any>, {
79
79
  'aria-expanded': visible,
80
80
  ...(!rest.disabled && { ...triggers }),
81
81
  ref: useForkedRef(ref, dropdownToggleRef),
@@ -1,8 +1,8 @@
1
- import React, { forwardRef, AllHTMLAttributes } from 'react'
1
+ import React, { forwardRef, LabelHTMLAttributes } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
 
5
- export interface CFormLabelProps extends AllHTMLAttributes<HTMLLabelElement> {
5
+ export interface CFormLabelProps extends LabelHTMLAttributes<HTMLLabelElement> {
6
6
  /**
7
7
  * A string of all className you want applied to the component.
8
8
  */
@@ -38,7 +38,7 @@ export interface CFormRangeProps extends InputHTMLAttributes<HTMLInputElement> {
38
38
  /**
39
39
  * Specifies the interval between legal numbers in the component.
40
40
  */
41
- steps: number
41
+ step?: number
42
42
  /**
43
43
  * The `value` attribute of component.
44
44
  *
@@ -1,8 +1,9 @@
1
- import React, { ElementType, forwardRef, HTMLAttributes } from 'react'
1
+ import React, { ElementType, forwardRef, LabelHTMLAttributes } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
 
5
- export interface CInputGroupTextProps extends HTMLAttributes<HTMLLabelElement | HTMLSpanElement> {
5
+ export interface CInputGroupTextProps
6
+ extends LabelHTMLAttributes<HTMLLabelElement | HTMLSpanElement> {
6
7
  /**
7
8
  * A string of all className you want applied to the component.
8
9
  */
@@ -4,7 +4,7 @@ import '@testing-library/jest-dom/extend-expect'
4
4
  import { CFormRange } from '../../../index'
5
5
 
6
6
  test('loads and displays CFormRange component', async () => {
7
- const { container } = render(<CFormRange steps={3} />)
7
+ const { container } = render(<CFormRange step={3} />)
8
8
  expect(container).toMatchSnapshot()
9
9
  })
10
10
 
@@ -12,7 +12,7 @@ test('CFormRange customize', async () => {
12
12
  const { container } = render(
13
13
  <CFormRange
14
14
  className="bazinga"
15
- steps={2}
15
+ step={2}
16
16
  disabled={true}
17
17
  max={150}
18
18
  min={20}
@@ -8,6 +8,15 @@ test('loads and displays CInputGroupText component', async () => {
8
8
  expect(container).toMatchSnapshot()
9
9
  })
10
10
 
11
+ test('renders CInputGroupText component as a label', async () => {
12
+ const { container } = render(
13
+ <CInputGroupText component="label" htmlFor="input">
14
+ Test
15
+ </CInputGroupText>,
16
+ )
17
+ expect(container).toMatchSnapshot()
18
+ })
19
+
11
20
  test('CInputGroupText customize', async () => {
12
21
  const { container } = render(<CInputGroupText className="bazinga">Test</CInputGroupText>)
13
22
  expect(container).toMatchSnapshot()
@@ -19,3 +19,14 @@ exports[`loads and displays CInputGroupText component 1`] = `
19
19
  </span>
20
20
  </div>
21
21
  `;
22
+
23
+ exports[`renders CInputGroupText component as a label 1`] = `
24
+ <div>
25
+ <label
26
+ class="input-group-text"
27
+ for="input"
28
+ >
29
+ Test
30
+ </label>
31
+ </div>
32
+ `;
@@ -1,5 +1,7 @@
1
1
  import { CForm } from './CForm'
2
2
  import { CFormCheck } from './CFormCheck'
3
+ import { CFormControlValidation } from './CFormControlValidation'
4
+ import { CFormControlWrapper } from './CFormControlWrapper'
3
5
  import { CFormFeedback } from './CFormFeedback'
4
6
  import { CFormFloating } from './CFormFloating'
5
7
  import { CFormInput } from './CFormInput'
@@ -15,6 +17,8 @@ import { CInputGroupText } from './CInputGroupText'
15
17
  export {
16
18
  CForm,
17
19
  CFormCheck,
20
+ CFormControlValidation,
21
+ CFormControlWrapper,
18
22
  CFormFeedback,
19
23
  CFormFloating,
20
24
  CFormInput,
@@ -1,8 +1,9 @@
1
- import React, { ElementType, forwardRef, HTMLAttributes } from 'react'
1
+ import React, { ElementType, forwardRef, AnchorHTMLAttributes } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
 
5
- export interface CHeaderBrandProps extends HTMLAttributes<HTMLAnchorElement | HTMLSpanElement> {
5
+ export interface CHeaderBrandProps
6
+ extends AnchorHTMLAttributes<HTMLAnchorElement | HTMLSpanElement> {
6
7
  /**
7
8
  * A string of all className you want applied to the component.
8
9
  */
@@ -2,7 +2,7 @@ import React, { AllHTMLAttributes, ElementType, forwardRef, MouseEvent } from 'r
2
2
  import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
 
5
- export interface CLinkProps extends AllHTMLAttributes<HTMLElement> {
5
+ export interface CLinkProps extends AllHTMLAttributes<HTMLButtonElement | HTMLAnchorElement> {
6
6
  /**
7
7
  * Toggle the active state for the component.
8
8
  */
@@ -36,7 +36,7 @@ export const CLink = forwardRef<HTMLButtonElement | HTMLAnchorElement, CLinkProp
36
36
  {...(active && { 'aria-current': 'page' })}
37
37
  {...(Component === 'a' && disabled && { 'aria-disabled': true, tabIndex: -1 })}
38
38
  {...((Component === 'a' || Component === 'button') && {
39
- onClick: (event: MouseEvent<HTMLElement>) => {
39
+ onClick: (event: MouseEvent<HTMLButtonElement | HTMLAnchorElement>) => {
40
40
  event.preventDefault
41
41
  !disabled && rest.onClick && rest.onClick(event)
42
42
  },
@@ -1,4 +1,4 @@
1
- import React, { ElementType, HTMLAttributes, forwardRef } from 'react'
1
+ import React, { ElementType, AnchorHTMLAttributes, forwardRef } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
 
@@ -6,7 +6,7 @@ import { Colors, colorPropType } from '../Types'
6
6
  import { CLink } from '../link/CLink'
7
7
 
8
8
  export interface CListGroupItemProps
9
- extends HTMLAttributes<HTMLLIElement | HTMLAnchorElement | HTMLButtonElement> {
9
+ extends AnchorHTMLAttributes<HTMLLIElement | HTMLAnchorElement | HTMLButtonElement> {
10
10
  /**
11
11
  * Toggle the active state for the component.
12
12
  */
@@ -171,6 +171,12 @@ export const CModal = forwardRef<HTMLDivElement, CModalProps>(
171
171
  useLayoutEffect(() => {
172
172
  if (_visible) {
173
173
  document.body.classList.add('modal-open')
174
+
175
+ if (backdrop) {
176
+ document.body.style.overflow = 'hidden'
177
+ document.body.style.paddingRight = '0px'
178
+ }
179
+
174
180
  setTimeout(
175
181
  () => {
176
182
  modalRef.current?.focus()
@@ -179,8 +185,19 @@ export const CModal = forwardRef<HTMLDivElement, CModalProps>(
179
185
  )
180
186
  } else {
181
187
  document.body.classList.remove('modal-open')
188
+
189
+ if (backdrop) {
190
+ document.body.style.removeProperty('overflow')
191
+ document.body.style.removeProperty('padding-right')
192
+ }
193
+ }
194
+ return () => {
195
+ document.body.classList.remove('modal-open')
196
+ if (backdrop) {
197
+ document.body.style.removeProperty('overflow')
198
+ document.body.style.removeProperty('padding-right')
199
+ }
182
200
  }
183
- return () => document.body.classList.remove('modal-open')
184
201
  }, [_visible])
185
202
 
186
203
  const handleClickOutside = (event: Event) => {
@@ -124,7 +124,10 @@ export const CNavGroup = forwardRef<HTMLLIElement, CNavGroupProps>(
124
124
  >
125
125
  {React.Children.map(children, (child, index) => {
126
126
  if (React.isValidElement(child)) {
127
- return React.cloneElement(child, { key: index, idx: `${idx}.${index}` })
127
+ return React.cloneElement(child as React.ReactElement<any>, {
128
+ key: index,
129
+ idx: `${idx}.${index}`,
130
+ })
128
131
  }
129
132
  return
130
133
  })}
@@ -29,7 +29,10 @@ export const CSidebarNav = forwardRef<HTMLUListElement, CSidebarNavProps>(
29
29
  <CNavContext.Provider value={CNavContextValues}>
30
30
  {React.Children.map(children, (child, index) => {
31
31
  if (React.isValidElement(child)) {
32
- return React.cloneElement(child, { key: index, idx: `${index}` })
32
+ return React.cloneElement(child as React.ReactElement<any>, {
33
+ key: index,
34
+ idx: `${index}`,
35
+ })
33
36
  }
34
37
  return
35
38
  })}
@@ -3,7 +3,10 @@ import PropTypes from 'prop-types'
3
3
  import { CToastContext } from './CToast'
4
4
  import { CCloseButton, CCloseButtonProps } from '../close-button/CCloseButton'
5
5
 
6
- export interface CToastCloseProps extends CCloseButtonProps {
6
+ import type { CButtonProps } from '../button/CButton'
7
+
8
+ type CombineButtonProps = CCloseButtonProps & CButtonProps
9
+ export interface CToastCloseProps extends CombineButtonProps {
7
10
  /**
8
11
  * Component used for the root node. Either a string to use a HTML element or a component.
9
12
  */
@@ -53,6 +53,19 @@ exports[`CToast customize 4`] = `
53
53
  `;
54
54
 
55
55
  exports[`CToast customize 5`] = `
56
+ <div>
57
+ <div
58
+ aria-atomic="true"
59
+ aria-live="assertive"
60
+ class="toast fade bg-warning border-0 bazinga showing"
61
+ role="alert"
62
+ >
63
+ Test
64
+ </div>
65
+ </div>
66
+ `;
67
+
68
+ exports[`CToast customize 6`] = `
56
69
  <div>
57
70
  <div
58
71
  aria-atomic="true"