@coreui/react-pro 4.9.0-next.0 → 4.9.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 (239) hide show
  1. package/README.md +1 -1
  2. package/dist/components/alert/CAlert.d.ts +1 -1
  3. package/dist/components/avatar/CAvatar.d.ts +1 -1
  4. package/dist/components/badge/CBadge.d.ts +1 -1
  5. package/dist/components/button/CButton.d.ts +1 -1
  6. package/dist/components/calendar/utils.d.ts +0 -1
  7. package/dist/components/callout/CCallout.d.ts +1 -1
  8. package/dist/components/card/CCard.d.ts +1 -1
  9. package/dist/components/conditional-portal/CConditionalPortal.d.ts +12 -0
  10. package/dist/components/conditional-portal/index.d.ts +2 -0
  11. package/dist/components/date-range-picker/CDateRangePicker.d.ts +1 -1
  12. package/dist/components/date-range-picker/utils.d.ts +1 -0
  13. package/dist/components/dropdown/CDropdown.d.ts +1 -1
  14. package/dist/components/dropdown/CDropdownToggle.d.ts +1 -1
  15. package/dist/components/form/CFormCheck.d.ts +8 -2
  16. package/dist/components/form/CFormSwitch.d.ts +6 -0
  17. package/dist/components/index.d.ts +1 -0
  18. package/dist/components/list-group/CListGroupItem.d.ts +4 -5
  19. package/dist/components/multi-select/CMultiSelect.d.ts +1 -13
  20. package/dist/components/multi-select/CMultiSelectNativeSelect.d.ts +1 -1
  21. package/dist/components/multi-select/CMultiSelectOptions.d.ts +1 -1
  22. package/dist/components/multi-select/CMultiSelectSelection.d.ts +1 -1
  23. package/dist/components/multi-select/types.d.ts +14 -0
  24. package/dist/components/multi-select/utils.d.ts +6 -0
  25. package/dist/components/navbar/CNavbar.d.ts +1 -1
  26. package/dist/components/picker/CPicker.d.ts +1 -1
  27. package/dist/components/placeholder/CPlaceholder.d.ts +1 -1
  28. package/dist/components/popover/CPopover.d.ts +1 -1
  29. package/dist/components/progress/CProgressBar.d.ts +1 -1
  30. package/dist/components/smart-table/CSmartTableHead.d.ts +1 -1
  31. package/dist/components/smart-table/CSmartTableInterface.d.ts +8 -0
  32. package/dist/components/smart-table/types.d.ts +1 -1
  33. package/dist/components/spinner/CSpinner.d.ts +1 -1
  34. package/dist/components/table/CTable.d.ts +2 -18
  35. package/dist/components/table/CTableBody.d.ts +1 -1
  36. package/dist/components/table/CTableDataCell.d.ts +1 -1
  37. package/dist/components/table/CTableFoot.d.ts +1 -1
  38. package/dist/components/table/CTableHead.d.ts +1 -1
  39. package/dist/components/table/CTableHeaderCell.d.ts +1 -1
  40. package/dist/components/table/CTableResponsiveWrapper.d.ts +0 -1
  41. package/dist/components/table/CTableRow.d.ts +1 -1
  42. package/dist/components/table/types.d.ts +17 -0
  43. package/dist/components/table/utils.d.ts +5 -0
  44. package/dist/components/toast/CToast.d.ts +1 -1
  45. package/dist/components/toast/CToastClose.d.ts +1 -1
  46. package/dist/components/tooltip/CTooltip.d.ts +1 -1
  47. package/dist/components/virtual-scroller/CVirtualScroller.d.ts +0 -8
  48. package/dist/components/widgets/CWidgetStatsA.d.ts +1 -1
  49. package/dist/components/widgets/CWidgetStatsB.d.ts +1 -1
  50. package/dist/components/widgets/CWidgetStatsC.d.ts +1 -1
  51. package/dist/components/widgets/CWidgetStatsD.d.ts +1 -1
  52. package/dist/components/widgets/CWidgetStatsF.d.ts +1 -1
  53. package/dist/index.es.js +696 -927
  54. package/dist/index.es.js.map +1 -1
  55. package/dist/index.js +695 -925
  56. package/dist/index.js.map +1 -1
  57. package/dist/props.d.ts +8 -0
  58. package/dist/types.d.ts +7 -0
  59. package/dist/utils/index.d.ts +1 -3
  60. package/package.json +11 -6
  61. package/src/components/accordion/CAccordion.tsx +7 -3
  62. package/src/components/accordion/CAccordionBody.tsx +2 -2
  63. package/src/components/accordion/CAccordionButton.tsx +1 -3
  64. package/src/components/accordion/CAccordionCollapse.tsx +1 -0
  65. package/src/components/accordion/CAccordionHeader.tsx +1 -3
  66. package/src/components/accordion/CAccordionItem.tsx +2 -4
  67. package/src/components/accordion/__tests__/__snapshots__/CAccordionBody.spec.tsx.snap +2 -2
  68. package/src/components/alert/CAlert.tsx +21 -28
  69. package/src/components/alert/CAlertHeading.tsx +1 -3
  70. package/src/components/alert/CAlertLink.tsx +1 -3
  71. package/src/components/alert/__tests__/__snapshots__/CAlert.spec.tsx.snap +1 -1
  72. package/src/components/avatar/CAvatar.tsx +16 -19
  73. package/src/components/backdrop/CBackdrop.tsx +10 -13
  74. package/src/components/badge/CBadge.tsx +21 -27
  75. package/src/components/breadcrumb/CBreadcrumb.tsx +1 -2
  76. package/src/components/breadcrumb/CBreadcrumbItem.tsx +12 -8
  77. package/src/components/button/CButton.tsx +10 -10
  78. package/src/components/button-group/CButtonGroup.tsx +9 -7
  79. package/src/components/button-group/CButtonToolbar.tsx +1 -3
  80. package/src/components/calendar/utils.ts +7 -55
  81. package/src/components/callout/CCallout.tsx +13 -10
  82. package/src/components/card/CCard.tsx +14 -11
  83. package/src/components/card/CCardBody.tsx +1 -3
  84. package/src/components/card/CCardFooter.tsx +1 -3
  85. package/src/components/card/CCardGroup.tsx +1 -3
  86. package/src/components/card/CCardHeader.tsx +1 -3
  87. package/src/components/card/CCardImage.tsx +5 -3
  88. package/src/components/card/CCardImageOverlay.tsx +1 -3
  89. package/src/components/card/CCardLink.tsx +1 -3
  90. package/src/components/card/CCardSubtitle.tsx +1 -3
  91. package/src/components/card/CCardText.tsx +1 -3
  92. package/src/components/card/CCardTitle.tsx +1 -3
  93. package/src/components/carousel/CCarousel.tsx +8 -8
  94. package/src/components/carousel/CCarouselCaption.tsx +1 -3
  95. package/src/components/carousel/CCarouselItem.tsx +11 -9
  96. package/src/components/close-button/CCloseButton.tsx +9 -10
  97. package/src/components/collapse/CCollapse.tsx +8 -20
  98. package/src/components/collapse/__tests__/CCollapse.spec.tsx +2 -3
  99. package/src/components/conditional-portal/CConditionalPortal.tsx +29 -0
  100. package/src/components/conditional-portal/index.ts +3 -0
  101. package/src/components/date-range-picker/CDateRangePicker.tsx +11 -13
  102. package/src/components/date-range-picker/utils.ts +49 -0
  103. package/src/components/dropdown/CDropdown.tsx +26 -23
  104. package/src/components/dropdown/CDropdownDivider.tsx +1 -3
  105. package/src/components/dropdown/CDropdownHeader.tsx +1 -3
  106. package/src/components/dropdown/CDropdownItem.tsx +7 -5
  107. package/src/components/dropdown/CDropdownItemPlain.tsx +1 -3
  108. package/src/components/dropdown/CDropdownMenu.tsx +29 -32
  109. package/src/components/dropdown/CDropdownToggle.tsx +34 -27
  110. package/src/components/dropdown/__tests__/CDropdown.spec.tsx +2 -4
  111. package/src/components/dropdown/__tests__/__snapshots__/CDropdown.spec.tsx.snap +1 -1
  112. package/src/components/footer/CFooter.tsx +5 -3
  113. package/src/components/form/CForm.tsx +5 -2
  114. package/src/components/form/CFormCheck.tsx +90 -66
  115. package/src/components/form/CFormControlValidation.tsx +0 -1
  116. package/src/components/form/CFormControlWrapper.tsx +3 -4
  117. package/src/components/form/CFormFeedback.tsx +11 -8
  118. package/src/components/form/CFormFloating.tsx +1 -2
  119. package/src/components/form/CFormInput.tsx +18 -16
  120. package/src/components/form/CFormLabel.tsx +1 -2
  121. package/src/components/form/CFormRange.tsx +2 -4
  122. package/src/components/form/CFormSelect.tsx +16 -12
  123. package/src/components/form/CFormSwitch.tsx +31 -20
  124. package/src/components/form/CFormText.tsx +1 -2
  125. package/src/components/form/CFormTextarea.tsx +14 -11
  126. package/src/components/form/CInputGroup.tsx +11 -8
  127. package/src/components/form/CInputGroupText.tsx +1 -2
  128. package/src/components/form/__tests__/CFormRange.spec.tsx +1 -1
  129. package/src/components/form/__tests__/__snapshots__/CForm.spec.tsx.snap +2 -6
  130. package/src/components/form/__tests__/__snapshots__/CFormRange.spec.tsx.snap +2 -2
  131. package/src/components/grid/CCol.tsx +8 -6
  132. package/src/components/grid/CContainer.tsx +8 -6
  133. package/src/components/grid/CRow.tsx +4 -3
  134. package/src/components/header/CHeader.tsx +12 -13
  135. package/src/components/header/CHeaderBrand.tsx +1 -3
  136. package/src/components/header/CHeaderBrand.tsx~HEAD +1 -3
  137. package/src/components/header/CHeaderDivider.tsx +1 -3
  138. package/src/components/header/CHeaderNav.tsx +6 -3
  139. package/src/components/header/CHeaderText.tsx +1 -3
  140. package/src/components/header/CHeaderToggler.tsx +2 -4
  141. package/src/components/image/CImage.tsx +17 -10
  142. package/src/components/image/__tests__/__snapshots__/CImage.spec.tsx.snap +1 -3
  143. package/src/components/index.ts +1 -0
  144. package/src/components/link/CLink.tsx +2 -4
  145. package/src/components/list-group/CListGroup.tsx +11 -10
  146. package/src/components/list-group/CListGroupItem.tsx +21 -20
  147. package/src/components/list-group/CListGroupItem.tsx~HEAD +3 -1
  148. package/src/components/loading-button/CLoadingButton.tsx +1 -3
  149. package/src/components/modal/CModal.tsx +57 -72
  150. package/src/components/modal/CModalBody.tsx +1 -3
  151. package/src/components/modal/CModalContent.tsx +1 -3
  152. package/src/components/modal/CModalDialog.tsx +16 -14
  153. package/src/components/modal/CModalFooter.tsx +1 -3
  154. package/src/components/modal/CModalHeader.tsx +4 -4
  155. package/src/components/modal/CModalTitle.tsx +1 -3
  156. package/src/components/modal/__tests__/CModal.spec.tsx +19 -20
  157. package/src/components/multi-select/CMultiSelect.tsx +34 -93
  158. package/src/components/multi-select/CMultiSelectNativeSelect.tsx +1 -1
  159. package/src/components/multi-select/CMultiSelectOptions.tsx +2 -2
  160. package/src/components/multi-select/CMultiSelectSelection.tsx +1 -1
  161. package/src/components/multi-select/types.ts +15 -0
  162. package/src/components/multi-select/utils.ts +92 -0
  163. package/src/components/nav/CNav.tsx +13 -10
  164. package/src/components/nav/CNavGroup.tsx +1 -3
  165. package/src/components/nav/CNavGroupItems.tsx +1 -2
  166. package/src/components/nav/CNavItem.tsx +9 -10
  167. package/src/components/nav/CNavLink.tsx +4 -5
  168. package/src/components/nav/CNavTitle.tsx +1 -2
  169. package/src/components/navbar/CNavbar.tsx +23 -23
  170. package/src/components/navbar/CNavbarBrand.tsx +2 -3
  171. package/src/components/navbar/CNavbarNav.tsx +6 -3
  172. package/src/components/navbar/CNavbarText.tsx +1 -3
  173. package/src/components/navbar/CNavbarToggler.tsx +2 -4
  174. package/src/components/offcanvas/COffcanvas.tsx +42 -68
  175. package/src/components/offcanvas/COffcanvasBody.tsx +1 -3
  176. package/src/components/offcanvas/COffcanvasHeader.tsx +1 -3
  177. package/src/components/offcanvas/COffcanvasTitle.tsx +1 -3
  178. package/src/components/offcanvas/__tests__/COffcanvas.spec.tsx +7 -2
  179. package/src/components/offcanvas/__tests__/__snapshots__/COffcanvas.spec.tsx.snap +9 -4
  180. package/src/components/pagination/CPagination.tsx +12 -9
  181. package/src/components/pagination/CPaginationItem.tsx +12 -11
  182. package/src/components/pagination/__tests__/CPagination.spec.tsx +3 -3
  183. package/src/components/pagination/__tests__/CPaginationItem.spec.tsx +3 -3
  184. package/src/components/picker/CPicker.tsx +7 -7
  185. package/src/components/placeholder/CPlaceholder.tsx +15 -12
  186. package/src/components/popover/CPopover.tsx +24 -34
  187. package/src/components/progress/CProgress.tsx +13 -10
  188. package/src/components/progress/CProgressBar.tsx +11 -12
  189. package/src/components/sidebar/CSidebar.tsx +22 -19
  190. package/src/components/sidebar/CSidebarBrand.tsx +1 -2
  191. package/src/components/sidebar/CSidebarFooter.tsx +1 -2
  192. package/src/components/sidebar/CSidebarHeader.tsx +1 -2
  193. package/src/components/sidebar/CSidebarNav.tsx +2 -2
  194. package/src/components/sidebar/CSidebarToggler.tsx +1 -2
  195. package/src/components/smart-pagination/CSmartPagination.tsx +22 -20
  196. package/src/components/smart-table/CSmartTable.tsx +5 -9
  197. package/src/components/smart-table/CSmartTableBody.tsx +82 -81
  198. package/src/components/smart-table/CSmartTableHead.tsx +5 -2
  199. package/src/components/smart-table/CSmartTableInterface.tsx +8 -0
  200. package/src/components/smart-table/{utils.tsx → utils.ts} +4 -5
  201. package/src/components/spinner/CSpinner.tsx +13 -9
  202. package/src/components/table/CTable.tsx +45 -77
  203. package/src/components/table/CTableBody.tsx +14 -9
  204. package/src/components/table/CTableDataCell.tsx +16 -11
  205. package/src/components/table/CTableFoot.tsx +14 -9
  206. package/src/components/table/CTableHead.tsx +14 -9
  207. package/src/components/table/CTableHeaderCell.tsx +14 -9
  208. package/src/components/table/CTableResponsiveWrapper.tsx +2 -3
  209. package/src/components/table/CTableRow.tsx +16 -11
  210. package/src/components/table/__tests__/__snapshots__/CTable.spec.tsx.snap +1 -5
  211. package/src/components/table/types.ts +20 -0
  212. package/src/components/table/utils.ts +24 -0
  213. package/src/components/tabs/CTabContent.tsx +1 -2
  214. package/src/components/tabs/CTabPane.tsx +18 -20
  215. package/src/components/tabs/__tests__/CTabPane.spec.tsx +2 -5
  216. package/src/components/tabs/__tests__/__snapshots__/CTabPane.spec.tsx.snap +1 -1
  217. package/src/components/time-picker/CTimePicker.tsx +14 -18
  218. package/src/components/toast/CToast.tsx +32 -45
  219. package/src/components/toast/CToastBody.tsx +1 -2
  220. package/src/components/toast/CToastClose.tsx +4 -2
  221. package/src/components/toast/CToastHeader.tsx +1 -2
  222. package/src/components/toast/CToaster.tsx +27 -26
  223. package/src/components/toast/__tests__/CToast.spec.tsx +2 -1
  224. package/src/components/toast/__tests__/__snapshots__/CToast.spec.tsx.snap +1 -66
  225. package/src/components/tooltip/CTooltip.tsx +24 -34
  226. package/src/components/virtual-scroller/CVirtualScroller.tsx +35 -60
  227. package/src/components/widgets/CWidgetStatsA.tsx +11 -9
  228. package/src/components/widgets/CWidgetStatsB.tsx +4 -4
  229. package/src/components/widgets/CWidgetStatsC.tsx +4 -4
  230. package/src/components/widgets/CWidgetStatsD.tsx +13 -15
  231. package/src/components/widgets/CWidgetStatsE.tsx +2 -5
  232. package/src/components/widgets/CWidgetStatsF.tsx +4 -8
  233. package/src/{components/Types.tsx → props.ts} +1 -68
  234. package/src/types.ts +68 -0
  235. package/src/utils/index.ts +1 -3
  236. package/src/components/multi-select/CMultiSelectCleaner.tsx +0 -18
  237. package/src/utils/getNextSibling.ts +0 -18
  238. package/src/utils/getPreviousSibling.ts +0 -18
  239. package/src/components/smart-table/{types.tsx → types.ts} +1 -1
@@ -2,8 +2,7 @@ import React, { ElementType, forwardRef } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
 
5
- import { CLinkProps } from '../link/CLink'
6
- import { CLink } from '../link/CLink'
5
+ import { CLink, CLinkProps } from '../link/CLink'
7
6
 
8
7
  export interface CDropdownItemProps extends CLinkProps {
9
8
  /**
@@ -18,10 +17,13 @@ export interface CDropdownItemProps extends CLinkProps {
18
17
 
19
18
  export const CDropdownItem = forwardRef<HTMLButtonElement | HTMLAnchorElement, CDropdownItemProps>(
20
19
  ({ children, className, component = 'a', ...rest }, ref) => {
21
- const _className = classNames('dropdown-item', className)
22
-
23
20
  return (
24
- <CLink className={_className} component={component} {...rest} ref={ref}>
21
+ <CLink
22
+ className={classNames('dropdown-item', className)}
23
+ component={component}
24
+ {...rest}
25
+ ref={ref}
26
+ >
25
27
  {children}
26
28
  </CLink>
27
29
  )
@@ -15,10 +15,8 @@ export interface CDropdownItemPlainProps extends HTMLAttributes<HTMLSpanElement>
15
15
 
16
16
  export const CDropdownItemPlain = forwardRef<HTMLSpanElement, CDropdownItemPlainProps>(
17
17
  ({ children, className, component: Component = 'span', ...rest }, ref) => {
18
- const _className = classNames('dropdown-item-text', className)
19
-
20
18
  return (
21
- <Component className={_className} {...rest} ref={ref}>
19
+ <Component className={classNames('dropdown-item-text', className)} {...rest} ref={ref}>
22
20
  {children}
23
21
  </Component>
24
22
  )
@@ -3,9 +3,10 @@ import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
  import { Popper, PopperChildrenProps } from 'react-popper'
5
5
 
6
- import { Placements } from '../Types'
7
6
  import { Alignments, CDropdownContext } from './CDropdown'
8
7
 
8
+ import type { Placements } from '../../types'
9
+
9
10
  export interface CDropdownMenuProps
10
11
  extends HTMLAttributes<HTMLDivElement | HTMLUListElement>,
11
12
  Omit<
@@ -125,39 +126,35 @@ export const CDropdownMenu: FC<CDropdownMenuProps> = ({
125
126
  return classNames
126
127
  }
127
128
 
128
- const _className = classNames(
129
- 'dropdown-menu',
130
- {
131
- 'dropdown-menu-dark': dark,
132
- show: visible,
133
- },
134
- alignment && alignmentClassNames(alignment),
135
- className,
129
+ const dropdownMenuComponent = (style?: React.CSSProperties, ref?: React.Ref<HTMLDivElement>) => (
130
+ <Component
131
+ className={classNames(
132
+ 'dropdown-menu',
133
+ {
134
+ 'dropdown-menu-dark': dark,
135
+ show: visible,
136
+ },
137
+ alignment && alignmentClassNames(alignment),
138
+ className,
139
+ )}
140
+ ref={ref}
141
+ style={style}
142
+ role="menu"
143
+ aria-hidden={!visible}
144
+ {...(!popper && { 'data-coreui-popper': 'static' })}
145
+ {...rest}
146
+ >
147
+ {Component === 'ul'
148
+ ? React.Children.map(children, (child, index) => {
149
+ if (React.isValidElement(child)) {
150
+ return <li key={index}>{React.cloneElement(child)}</li>
151
+ }
152
+ return
153
+ })
154
+ : children}
155
+ </Component>
136
156
  )
137
157
 
138
- const dropdownMenuComponent = (style?: React.CSSProperties, ref?: React.Ref<HTMLDivElement>) => {
139
- return (
140
- <Component
141
- className={_className}
142
- ref={ref}
143
- style={style}
144
- role="menu"
145
- aria-hidden={!visible}
146
- {...(!popper && { 'data-coreui-popper': 'static' })}
147
- {...rest}
148
- >
149
- {Component === 'ul'
150
- ? React.Children.map(children, (child, index) => {
151
- if (React.isValidElement(child)) {
152
- return <li key={index}>{React.cloneElement(child)}</li>
153
- }
154
- return
155
- })
156
- : children}
157
- </Component>
158
- )
159
- }
160
-
161
158
  return popper && visible ? (
162
159
  <Popper innerRef={dropdownMenuRef} placement={_placement}>
163
160
  {({ ref, style }) => dropdownMenuComponent(style, ref)}
@@ -3,13 +3,14 @@ import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
  import { Reference } from 'react-popper'
5
5
 
6
- import { useForkedRef } from '../../hooks'
7
-
8
- import { Triggers, triggerPropType } from '../Types'
9
-
10
6
  import { CButton, CButtonProps } from '../button/CButton'
7
+
11
8
  import { CDropdownContext } from './CDropdown'
12
9
 
10
+ import { useForkedRef } from '../../hooks'
11
+ import { triggerPropType } from '../../props'
12
+ import type { Triggers } from '../../types'
13
+
13
14
  export interface CDropdownToggleProps extends Omit<CButtonProps, 'type'> {
14
15
  /**
15
16
  * Enables pseudo element caret on toggler.
@@ -41,14 +42,6 @@ export const CDropdownToggle: FC<CDropdownToggleProps> = ({
41
42
  ...rest
42
43
  }) => {
43
44
  const { dropdownToggleRef, popper, variant, visible, setVisible } = useContext(CDropdownContext)
44
- const _className = classNames(
45
- {
46
- 'dropdown-toggle': caret,
47
- 'dropdown-toggle-split': split,
48
- 'nav-link': variant === 'nav-item',
49
- },
50
- className,
51
- )
52
45
 
53
46
  const triggers = {
54
47
  ...((trigger === 'click' || trigger.includes('click')) && {
@@ -64,28 +57,42 @@ export const CDropdownToggle: FC<CDropdownToggleProps> = ({
64
57
  }
65
58
 
66
59
  const togglerProps = {
67
- className: _className,
60
+ className: classNames(
61
+ {
62
+ 'dropdown-toggle': caret,
63
+ 'dropdown-toggle-split': split,
64
+ 'nav-link': variant === 'nav-item',
65
+ },
66
+ className,
67
+ ),
68
68
  'aria-expanded': visible,
69
69
  ...(!rest.disabled && { ...triggers }),
70
- ...triggers,
71
70
  }
72
71
 
73
72
  // We use any because Toggler can be `a` as well as `button`.
74
73
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
75
74
  const Toggler = (ref?: React.Ref<any>) => {
76
- return custom && React.isValidElement(children) ? (
77
- <>
78
- {React.cloneElement(children as React.ReactElement<any>, {
79
- 'aria-expanded': visible,
80
- ...(!rest.disabled && { ...triggers }),
81
- ref: useForkedRef(ref, dropdownToggleRef),
82
- })}
83
- </>
84
- ) : variant === 'nav-item' ? (
85
- <a href="#" {...togglerProps} ref={useForkedRef(ref, dropdownToggleRef)}>
86
- {children}
87
- </a>
88
- ) : (
75
+ if (custom && React.isValidElement(children)) {
76
+ return (
77
+ <>
78
+ {React.cloneElement(children as React.ReactElement<any>, {
79
+ 'aria-expanded': visible,
80
+ ...(!rest.disabled && { ...triggers }),
81
+ ref: useForkedRef(ref, dropdownToggleRef),
82
+ })}
83
+ </>
84
+ )
85
+ }
86
+
87
+ if (variant === 'nav-item') {
88
+ return (
89
+ <a href="#" {...togglerProps} ref={useForkedRef(ref, dropdownToggleRef)}>
90
+ {children}
91
+ </a>
92
+ )
93
+ }
94
+
95
+ return (
89
96
  <CButton
90
97
  type="button"
91
98
  {...togglerProps}
@@ -54,7 +54,6 @@ test('CDropdown change visible prop', async () => {
54
54
  })
55
55
 
56
56
  test('CDropdown click', async () => {
57
- jest.useFakeTimers()
58
57
  render(
59
58
  <CDropdown>
60
59
  <CDropdownToggle>Test</CDropdownToggle>
@@ -71,10 +70,9 @@ test('CDropdown click', async () => {
71
70
  }
72
71
  jest.runAllTimers()
73
72
  expect(screen.getByText('Test').closest('div')).toHaveClass('show')
74
- fireEvent.click(document) //click outside
73
+ fireEvent.mouseUp(document.body) //click outside
74
+ await new Promise((r) => setTimeout(r, 1000))
75
75
  expect(screen.getByText('Test').closest('div')).not.toHaveClass('show')
76
- jest.runAllTimers()
77
- jest.useRealTimers()
78
76
  })
79
77
 
80
78
  test('CDropdown example', async () => {
@@ -3,7 +3,7 @@
3
3
  exports[`CDropdown customize 1`] = `
4
4
  <div>
5
5
  <li
6
- class="nav-item dropdown show dropstart bazinga"
6
+ class="nav-item dropdown dropstart show bazinga"
7
7
  >
8
8
  Test
9
9
  </li>
@@ -15,10 +15,12 @@ export interface CFooterProps extends HTMLAttributes<HTMLDivElement> {
15
15
 
16
16
  export const CFooter = forwardRef<HTMLDivElement, CFooterProps>(
17
17
  ({ children, className, position, ...rest }, ref) => {
18
- const _className = classNames('footer', { [`footer-${position}`]: position }, className)
19
-
20
18
  return (
21
- <div className={_className} {...rest} ref={ref}>
19
+ <div
20
+ className={classNames('footer', { [`footer-${position}`]: position }, className)}
21
+ {...rest}
22
+ ref={ref}
23
+ >
22
24
  {children}
23
25
  </div>
24
26
  )
@@ -15,9 +15,12 @@ export interface CFormProps extends FormHTMLAttributes<HTMLFormElement> {
15
15
 
16
16
  export const CForm = forwardRef<HTMLFormElement, CFormProps>(
17
17
  ({ children, className, validated, ...rest }, ref) => {
18
- const _className = classNames({ 'was-validated': validated }, className)
19
18
  return (
20
- <form className={_className} {...rest} ref={ref}>
19
+ <form
20
+ className={classNames({ 'was-validated': validated }, className) || undefined}
21
+ {...rest}
22
+ ref={ref}
23
+ >
21
24
  {children}
22
25
  </form>
23
26
  )
@@ -2,12 +2,12 @@ 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 '../../hooks'
6
- import { Colors, Shapes } from '../Types'
7
-
8
5
  import { CFormControlValidation, CFormControlValidationProps } from './CFormControlValidation'
9
6
  import { CFormLabel } from './CFormLabel'
10
7
 
8
+ import { useForkedRef } from '../../hooks'
9
+ import type { Colors, Shapes } from '../../types'
10
+
11
11
  export type ButtonObject = {
12
12
  /**
13
13
  * Sets the color context of the component to one of CoreUI’s themed colors.
@@ -55,7 +55,7 @@ export interface CFormCheckProps
55
55
  */
56
56
  indeterminate?: boolean
57
57
  /**
58
- * Group checkboxes or radios on the same horizontal row by adding.
58
+ * Group checkboxes or radios on the same horizontal row.
59
59
  */
60
60
  inline?: boolean
61
61
  /**
@@ -66,6 +66,12 @@ export interface CFormCheckProps
66
66
  * The element represents a caption for a component.
67
67
  */
68
68
  label?: string | ReactNode
69
+ /**
70
+ * Put checkboxes or radios on the opposite side.
71
+ *
72
+ * @sinve 4.7.0
73
+ */
74
+ reverse?: boolean
69
75
  /**
70
76
  * Specifies the type of component.
71
77
  */
@@ -92,6 +98,7 @@ export const CFormCheck = forwardRef<HTMLInputElement, CFormCheckProps>(
92
98
  inline,
93
99
  invalid,
94
100
  label,
101
+ reverse,
95
102
  type = 'checkbox',
96
103
  valid,
97
104
  ...rest
@@ -107,39 +114,21 @@ export const CFormCheck = forwardRef<HTMLInputElement, CFormCheckProps>(
107
114
  }
108
115
  }, [indeterminate])
109
116
 
110
- const _className = classNames(
111
- 'form-check',
112
- {
113
- 'form-check-inline': inline,
114
- 'is-invalid': invalid,
115
- 'is-valid': valid,
116
- },
117
- className,
118
- )
119
-
120
- const inputClassName = classNames(button ? 'btn-check' : 'form-check-input', {
121
- 'is-invalid': invalid,
122
- 'is-valid': valid,
123
- 'me-2': hitArea,
124
- })
125
- const labelClassName = classNames(
126
- button
127
- ? classNames(
128
- 'btn',
129
- button.variant ? `btn-${button.variant}-${button.color}` : `btn-${button.color}`,
130
- {
131
- [`btn-${button.size}`]: button.size,
132
- },
133
- `${button.shape}`,
134
- )
135
- : 'form-check-label',
117
+ const FormControl = () => (
118
+ <input
119
+ type={type}
120
+ className={classNames(button ? 'btn-check' : 'form-check-input', {
121
+ 'is-invalid': invalid,
122
+ 'is-valid': valid,
123
+ 'me-2': hitArea,
124
+ })}
125
+ id={id}
126
+ {...rest}
127
+ ref={forkedRef}
128
+ />
136
129
  )
137
130
 
138
- const formControl = () => {
139
- return <input type={type} className={inputClassName} id={id} {...rest} ref={forkedRef} />
140
- }
141
-
142
- const formValidation = () => (
131
+ const FormValidation = () => (
143
132
  <CFormControlValidation
144
133
  describedby={rest['aria-describedby']}
145
134
  feedback={feedback}
@@ -152,39 +141,73 @@ export const CFormCheck = forwardRef<HTMLInputElement, CFormCheckProps>(
152
141
  />
153
142
  )
154
143
 
155
- const formLabel = () => {
156
- return (
157
- <CFormLabel customClassName={labelClassName} {...(id && { htmlFor: id })}>
158
- {label}
159
- </CFormLabel>
160
- )
144
+ const FormLabel = () => (
145
+ <CFormLabel
146
+ customClassName={classNames(
147
+ button
148
+ ? classNames(
149
+ 'btn',
150
+ button.variant ? `btn-${button.variant}-${button.color}` : `btn-${button.color}`,
151
+ {
152
+ [`btn-${button.size}`]: button.size,
153
+ },
154
+ `${button.shape}`,
155
+ )
156
+ : 'form-check-label',
157
+ )}
158
+ {...(id && { htmlFor: id })}
159
+ >
160
+ {label}
161
+ </CFormLabel>
162
+ )
163
+
164
+ const FormCheck = () => {
165
+ if (button) {
166
+ return (
167
+ <>
168
+ <FormControl />
169
+ {label && <FormLabel />}
170
+ <FormValidation />
171
+ </>
172
+ )
173
+ }
174
+
175
+ if (label) {
176
+ return hitArea ? (
177
+ <>
178
+ <FormControl />
179
+ <CFormLabel
180
+ customClassName={classNames('form-check-label stretched-link', className)}
181
+ {...(id && { htmlFor: id })}
182
+ >
183
+ {label}
184
+ </CFormLabel>
185
+ <FormValidation />
186
+ </>
187
+ ) : (
188
+ <div
189
+ className={classNames(
190
+ 'form-check',
191
+ {
192
+ 'form-check-inline': inline,
193
+ 'form-check-reverse': reverse,
194
+ 'is-invalid': invalid,
195
+ 'is-valid': valid,
196
+ },
197
+ className,
198
+ )}
199
+ >
200
+ <FormControl />
201
+ <FormLabel />
202
+ <FormValidation />
203
+ </div>
204
+ )
205
+ }
206
+
207
+ return <FormControl />
161
208
  }
162
209
 
163
- return button ? (
164
- <>
165
- {formControl()}
166
- {label && formLabel()}
167
- {formValidation()}
168
- </>
169
- ) : label ? (
170
- hitArea ? (
171
- <>
172
- <CFormLabel customClassName={className} {...(id && { htmlFor: id })}>
173
- {formControl()}
174
- {label}
175
- </CFormLabel>
176
- {formValidation()}
177
- </>
178
- ) : (
179
- <div className={_className}>
180
- {formControl()}
181
- {formLabel()}
182
- {formValidation()}
183
- </div>
184
- )
185
- ) : (
186
- formControl()
187
- )
210
+ return <FormCheck />
188
211
  },
189
212
  )
190
213
 
@@ -196,6 +219,7 @@ CFormCheck.propTypes = {
196
219
  indeterminate: PropTypes.bool,
197
220
  inline: PropTypes.bool,
198
221
  label: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
222
+ reverse: PropTypes.bool,
199
223
  type: PropTypes.oneOf(['checkbox', 'radio']),
200
224
  ...CFormControlValidation.propTypes,
201
225
  }
@@ -1,5 +1,4 @@
1
1
  import React, { FC, ReactNode } from 'react'
2
-
3
2
  import PropTypes from 'prop-types'
4
3
 
5
4
  import { CFormFeedback } from './CFormFeedback'
@@ -1,5 +1,4 @@
1
1
  import React, { FC, ReactNode } from 'react'
2
-
3
2
  import PropTypes from 'prop-types'
4
3
 
5
4
  import { CFormControlValidation, CFormControlValidationProps } from './CFormControlValidation'
@@ -57,7 +56,7 @@ export const CFormControlWrapper: FC<CFormControlWrapperProps> = ({
57
56
  tooltipFeedback,
58
57
  valid,
59
58
  }) => {
60
- const formControlValidation = () => (
59
+ const FormControlValidation = () => (
61
60
  <CFormControlValidation
62
61
  describedby={describedby}
63
62
  feedback={feedback}
@@ -74,14 +73,14 @@ export const CFormControlWrapper: FC<CFormControlWrapperProps> = ({
74
73
  {children}
75
74
  <CFormLabel htmlFor={id}>{label || floatingLabel}</CFormLabel>
76
75
  {text && <CFormText id={describedby}>{text}</CFormText>}
77
- {formControlValidation()}
76
+ <FormControlValidation />
78
77
  </CFormFloating>
79
78
  ) : (
80
79
  <>
81
80
  {label && <CFormLabel htmlFor={id}>{label}</CFormLabel>}
82
81
  {children}
83
82
  {text && <CFormText id={describedby}>{text}</CFormText>}
84
- {formControlValidation()}
83
+ <FormControlValidation />
85
84
  </>
86
85
  )
87
86
  }
@@ -30,15 +30,18 @@ export const CFormFeedback = forwardRef<HTMLDivElement | HTMLSpanElement, CFormF
30
30
  { children, className, component: Component = 'div', invalid, tooltip, valid, ...rest },
31
31
  ref,
32
32
  ) => {
33
- const _className = classNames(
34
- {
35
- [`invalid-${tooltip ? 'tooltip' : 'feedback'}`]: invalid,
36
- [`valid-${tooltip ? 'tooltip' : 'feedback'}`]: valid,
37
- },
38
- className,
39
- )
40
33
  return (
41
- <Component className={_className} {...rest} ref={ref}>
34
+ <Component
35
+ className={classNames(
36
+ {
37
+ [`invalid-${tooltip ? 'tooltip' : 'feedback'}`]: invalid,
38
+ [`valid-${tooltip ? 'tooltip' : 'feedback'}`]: valid,
39
+ },
40
+ className,
41
+ )}
42
+ {...rest}
43
+ ref={ref}
44
+ >
42
45
  {children}
43
46
  </Component>
44
47
  )
@@ -11,9 +11,8 @@ export interface CFormFloatingProps extends HTMLAttributes<HTMLDivElement> {
11
11
 
12
12
  export const CFormFloating = forwardRef<HTMLDivElement, CFormFloatingProps>(
13
13
  ({ children, className, ...rest }, ref) => {
14
- const _className = classNames('form-floating', className)
15
14
  return (
16
- <div className={_className} {...rest} ref={ref}>
15
+ <div className={classNames('form-floating', className)} {...rest} ref={ref}>
17
16
  {children}
18
17
  </div>
19
18
  )
@@ -1,10 +1,14 @@
1
- import React, { ChangeEventHandler, forwardRef, InputHTMLAttributes, useState } from 'react'
2
-
3
- import classNames from 'classnames'
1
+ import React, {
2
+ ChangeEventHandler,
3
+ forwardRef,
4
+ InputHTMLAttributes,
5
+ useEffect,
6
+ useState,
7
+ } from 'react'
4
8
  import PropTypes from 'prop-types'
9
+ import classNames from 'classnames'
5
10
 
6
11
  import { CFormControlWrapper, CFormControlWrapperProps } from './CFormControlWrapper'
7
- import { useEffect } from 'react'
8
12
 
9
13
  export interface CFormInputProps
10
14
  extends CFormControlWrapperProps,
@@ -85,17 +89,6 @@ export const CFormInput = forwardRef<HTMLInputElement, CFormInputProps>(
85
89
  return () => clearTimeout(timeOutId)
86
90
  }, [value])
87
91
 
88
- const _className = classNames(
89
- plainText ? 'form-control-plaintext' : 'form-control',
90
- {
91
- [`form-control-${size}`]: size,
92
- 'form-control-color': type === 'color',
93
- 'is-invalid': invalid,
94
- 'is-valid': valid,
95
- },
96
- className,
97
- )
98
-
99
92
  return (
100
93
  <CFormControlWrapper
101
94
  describedby={rest['aria-describedby']}
@@ -112,7 +105,16 @@ export const CFormInput = forwardRef<HTMLInputElement, CFormInputProps>(
112
105
  valid={valid}
113
106
  >
114
107
  <input
115
- className={_className}
108
+ className={classNames(
109
+ plainText ? 'form-control-plaintext' : 'form-control',
110
+ {
111
+ [`form-control-${size}`]: size,
112
+ 'form-control-color': type === 'color',
113
+ 'is-invalid': invalid,
114
+ 'is-valid': valid,
115
+ },
116
+ className,
117
+ )}
116
118
  id={id}
117
119
  type={type}
118
120
  onChange={(event) => (delay ? setValue(event) : onChange && onChange(event))}
@@ -15,9 +15,8 @@ export interface CFormLabelProps extends LabelHTMLAttributes<HTMLLabelElement> {
15
15
 
16
16
  export const CFormLabel = forwardRef<HTMLLabelElement, CFormLabelProps>(
17
17
  ({ children, className, customClassName, ...rest }, ref) => {
18
- const _className = customClassName ? customClassName : classNames('form-label', className)
19
18
  return (
20
- <label className={_className} {...rest} ref={ref}>
19
+ <label className={customClassName ?? classNames('form-label', className)} {...rest} ref={ref}>
21
20
  {children}
22
21
  </label>
23
22
  )
@@ -1,7 +1,6 @@
1
1
  import React, { ChangeEventHandler, forwardRef, InputHTMLAttributes, ReactNode } from 'react'
2
-
3
- import classNames from 'classnames'
4
2
  import PropTypes from 'prop-types'
3
+ import classNames from 'classnames'
5
4
 
6
5
  import { CFormLabel } from './CFormLabel'
7
6
  export interface CFormRangeProps extends InputHTMLAttributes<HTMLInputElement> {
@@ -49,11 +48,10 @@ export interface CFormRangeProps extends InputHTMLAttributes<HTMLInputElement> {
49
48
 
50
49
  export const CFormRange = forwardRef<HTMLInputElement, CFormRangeProps>(
51
50
  ({ className, label, ...rest }, ref) => {
52
- const _className = classNames('form-range', className)
53
51
  return (
54
52
  <>
55
53
  {label && <CFormLabel htmlFor={rest.id}>{label}</CFormLabel>}
56
- <input type="range" className={_className} {...rest} ref={ref} />
54
+ <input type="range" className={classNames('form-range', className)} {...rest} ref={ref} />
57
55
  </>
58
56
  )
59
57
  },