@coreui/react-pro 4.9.0-next.1 → 4.10.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 (186) hide show
  1. package/README.md +1 -1
  2. package/dist/components/conditional-portal/CConditionalPortal.d.ts +12 -0
  3. package/dist/components/conditional-portal/index.d.ts +2 -0
  4. package/dist/components/date-range-picker/CDateRangePicker.d.ts +6 -0
  5. package/dist/components/form/CFormCheck.d.ts +7 -1
  6. package/dist/components/form/CFormSwitch.d.ts +6 -0
  7. package/dist/components/index.d.ts +1 -0
  8. package/dist/components/table/CTableResponsiveWrapper.d.ts +0 -1
  9. package/dist/components/time-picker/CTimePicker.d.ts +6 -0
  10. package/dist/index.es.js +507 -728
  11. package/dist/index.es.js.map +1 -1
  12. package/dist/index.js +506 -726
  13. package/dist/index.js.map +1 -1
  14. package/package.json +11 -6
  15. package/src/components/accordion/CAccordion.tsx +7 -3
  16. package/src/components/accordion/CAccordionBody.tsx +1 -2
  17. package/src/components/accordion/CAccordionButton.tsx +1 -3
  18. package/src/components/accordion/CAccordionHeader.tsx +1 -3
  19. package/src/components/accordion/CAccordionItem.tsx +2 -4
  20. package/src/components/accordion/__tests__/__snapshots__/CAccordionBody.spec.tsx.snap +2 -2
  21. package/src/components/alert/CAlert.tsx +19 -27
  22. package/src/components/alert/CAlertHeading.tsx +1 -3
  23. package/src/components/alert/CAlertLink.tsx +1 -3
  24. package/src/components/alert/__tests__/__snapshots__/CAlert.spec.tsx.snap +1 -1
  25. package/src/components/avatar/CAvatar.tsx +14 -11
  26. package/src/components/backdrop/CBackdrop.tsx +9 -12
  27. package/src/components/badge/CBadge.tsx +19 -17
  28. package/src/components/breadcrumb/CBreadcrumb.tsx +1 -2
  29. package/src/components/breadcrumb/CBreadcrumbItem.tsx +12 -8
  30. package/src/components/button/CButton.tsx +7 -9
  31. package/src/components/button-group/CButtonGroup.tsx +9 -7
  32. package/src/components/button-group/CButtonToolbar.tsx +1 -3
  33. package/src/components/calendar/utils.ts +7 -9
  34. package/src/components/callout/CCallout.tsx +11 -9
  35. package/src/components/card/CCard.tsx +12 -10
  36. package/src/components/card/CCardBody.tsx +1 -3
  37. package/src/components/card/CCardFooter.tsx +1 -3
  38. package/src/components/card/CCardGroup.tsx +1 -3
  39. package/src/components/card/CCardHeader.tsx +1 -3
  40. package/src/components/card/CCardImage.tsx +5 -3
  41. package/src/components/card/CCardImageOverlay.tsx +1 -3
  42. package/src/components/card/CCardLink.tsx +1 -3
  43. package/src/components/card/CCardSubtitle.tsx +1 -3
  44. package/src/components/card/CCardText.tsx +1 -3
  45. package/src/components/card/CCardTitle.tsx +1 -3
  46. package/src/components/carousel/CCarousel.tsx +8 -8
  47. package/src/components/carousel/CCarouselCaption.tsx +1 -3
  48. package/src/components/carousel/CCarouselItem.tsx +11 -9
  49. package/src/components/close-button/CCloseButton.tsx +9 -10
  50. package/src/components/collapse/CCollapse.tsx +8 -20
  51. package/src/components/collapse/__tests__/CCollapse.spec.tsx +2 -3
  52. package/src/components/conditional-portal/CConditionalPortal.tsx +29 -0
  53. package/src/components/conditional-portal/index.ts +3 -0
  54. package/src/components/date-range-picker/CDateRangePicker.tsx +19 -11
  55. package/src/components/date-range-picker/utils.ts +2 -2
  56. package/src/components/dropdown/CDropdown.tsx +35 -30
  57. package/src/components/dropdown/CDropdownDivider.tsx +1 -3
  58. package/src/components/dropdown/CDropdownHeader.tsx +1 -3
  59. package/src/components/dropdown/CDropdownItem.tsx +6 -3
  60. package/src/components/dropdown/CDropdownItemPlain.tsx +1 -3
  61. package/src/components/dropdown/CDropdownMenu.tsx +27 -31
  62. package/src/components/dropdown/CDropdownToggle.tsx +29 -23
  63. package/src/components/dropdown/__tests__/CDropdown.spec.tsx +2 -4
  64. package/src/components/dropdown/__tests__/__snapshots__/CDropdown.spec.tsx.snap +1 -1
  65. package/src/components/footer/CFooter.tsx +5 -3
  66. package/src/components/form/CForm.tsx +5 -2
  67. package/src/components/form/CFormCheck.tsx +87 -63
  68. package/src/components/form/CFormControlWrapper.tsx +3 -3
  69. package/src/components/form/CFormFeedback.tsx +11 -8
  70. package/src/components/form/CFormFloating.tsx +1 -2
  71. package/src/components/form/CFormInput.tsx +10 -12
  72. package/src/components/form/CFormLabel.tsx +1 -2
  73. package/src/components/form/CFormRange.tsx +1 -2
  74. package/src/components/form/CFormSelect.tsx +15 -10
  75. package/src/components/form/CFormSwitch.tsx +31 -20
  76. package/src/components/form/CFormText.tsx +1 -2
  77. package/src/components/form/CFormTextarea.tsx +13 -9
  78. package/src/components/form/CInputGroup.tsx +11 -8
  79. package/src/components/form/CInputGroupText.tsx +1 -2
  80. package/src/components/form/__tests__/CFormRange.spec.tsx +1 -1
  81. package/src/components/form/__tests__/__snapshots__/CForm.spec.tsx.snap +2 -6
  82. package/src/components/form/__tests__/__snapshots__/CFormRange.spec.tsx.snap +2 -2
  83. package/src/components/grid/CCol.tsx +8 -6
  84. package/src/components/grid/CContainer.tsx +8 -6
  85. package/src/components/grid/CRow.tsx +4 -3
  86. package/src/components/header/CHeader.tsx +12 -13
  87. package/src/components/header/CHeaderBrand.tsx +1 -3
  88. package/src/components/header/CHeaderBrand.tsx~HEAD +1 -3
  89. package/src/components/header/CHeaderDivider.tsx +1 -3
  90. package/src/components/header/CHeaderNav.tsx +6 -3
  91. package/src/components/header/CHeaderText.tsx +1 -3
  92. package/src/components/header/CHeaderToggler.tsx +2 -4
  93. package/src/components/image/CImage.tsx +17 -10
  94. package/src/components/image/__tests__/__snapshots__/CImage.spec.tsx.snap +1 -3
  95. package/src/components/index.ts +1 -0
  96. package/src/components/link/CLink.tsx +2 -4
  97. package/src/components/list-group/CListGroup.tsx +11 -10
  98. package/src/components/list-group/CListGroupItem.tsx +13 -12
  99. package/src/components/loading-button/CLoadingButton.tsx +1 -3
  100. package/src/components/modal/CModal.tsx +55 -70
  101. package/src/components/modal/CModalBody.tsx +1 -3
  102. package/src/components/modal/CModalContent.tsx +1 -3
  103. package/src/components/modal/CModalDialog.tsx +16 -14
  104. package/src/components/modal/CModalFooter.tsx +1 -3
  105. package/src/components/modal/CModalHeader.tsx +1 -2
  106. package/src/components/modal/CModalTitle.tsx +1 -3
  107. package/src/components/modal/__tests__/CModal.spec.tsx +19 -20
  108. package/src/components/multi-select/CMultiSelect.tsx +19 -19
  109. package/src/components/multi-select/utils.ts +3 -3
  110. package/src/components/nav/CNav.tsx +13 -10
  111. package/src/components/nav/CNavGroup.tsx +1 -3
  112. package/src/components/nav/CNavGroupItems.tsx +1 -2
  113. package/src/components/nav/CNavItem.tsx +8 -10
  114. package/src/components/nav/CNavLink.tsx +1 -2
  115. package/src/components/nav/CNavTitle.tsx +1 -2
  116. package/src/components/navbar/CNavbar.tsx +21 -22
  117. package/src/components/navbar/CNavbarBrand.tsx +2 -3
  118. package/src/components/navbar/CNavbarNav.tsx +6 -3
  119. package/src/components/navbar/CNavbarText.tsx +1 -3
  120. package/src/components/navbar/CNavbarToggler.tsx +2 -4
  121. package/src/components/offcanvas/COffcanvas.tsx +39 -66
  122. package/src/components/offcanvas/COffcanvasBody.tsx +1 -3
  123. package/src/components/offcanvas/COffcanvasHeader.tsx +1 -3
  124. package/src/components/offcanvas/COffcanvasTitle.tsx +1 -3
  125. package/src/components/offcanvas/__tests__/COffcanvas.spec.tsx +7 -2
  126. package/src/components/offcanvas/__tests__/__snapshots__/COffcanvas.spec.tsx.snap +9 -4
  127. package/src/components/pagination/CPagination.tsx +12 -9
  128. package/src/components/pagination/CPaginationItem.tsx +12 -11
  129. package/src/components/pagination/__tests__/CPagination.spec.tsx +3 -3
  130. package/src/components/pagination/__tests__/CPaginationItem.spec.tsx +3 -3
  131. package/src/components/picker/CPicker.tsx +6 -6
  132. package/src/components/placeholder/CPlaceholder.tsx +13 -11
  133. package/src/components/popover/CPopover.tsx +22 -33
  134. package/src/components/progress/CProgress.tsx +12 -10
  135. package/src/components/progress/CProgressBar.tsx +9 -11
  136. package/src/components/sidebar/CSidebar.tsx +20 -18
  137. package/src/components/sidebar/CSidebarBrand.tsx +1 -2
  138. package/src/components/sidebar/CSidebarFooter.tsx +1 -2
  139. package/src/components/sidebar/CSidebarHeader.tsx +1 -2
  140. package/src/components/sidebar/CSidebarNav.tsx +2 -2
  141. package/src/components/sidebar/CSidebarToggler.tsx +1 -2
  142. package/src/components/smart-pagination/CSmartPagination.tsx +22 -20
  143. package/src/components/smart-table/CSmartTable.tsx +4 -8
  144. package/src/components/smart-table/utils.ts +3 -4
  145. package/src/components/spinner/CSpinner.tsx +11 -8
  146. package/src/components/table/CTable.tsx +20 -18
  147. package/src/components/table/CTableBody.tsx +12 -8
  148. package/src/components/table/CTableDataCell.tsx +14 -10
  149. package/src/components/table/CTableFoot.tsx +12 -8
  150. package/src/components/table/CTableHead.tsx +12 -8
  151. package/src/components/table/CTableHeaderCell.tsx +12 -8
  152. package/src/components/table/CTableResponsiveWrapper.tsx +2 -3
  153. package/src/components/table/CTableRow.tsx +14 -10
  154. package/src/components/table/__tests__/__snapshots__/CTable.spec.tsx.snap +1 -5
  155. package/src/components/table/utils.ts +2 -7
  156. package/src/components/tabs/CTabContent.tsx +1 -2
  157. package/src/components/tabs/CTabPane.tsx +17 -20
  158. package/src/components/tabs/__tests__/CTabPane.spec.tsx +2 -5
  159. package/src/components/tabs/__tests__/__snapshots__/CTabPane.spec.tsx.snap +1 -1
  160. package/src/components/time-picker/CTimePicker.tsx +21 -14
  161. package/src/components/toast/CToast.tsx +29 -42
  162. package/src/components/toast/CToastBody.tsx +1 -2
  163. package/src/components/toast/CToastClose.tsx +3 -1
  164. package/src/components/toast/CToastHeader.tsx +1 -2
  165. package/src/components/toast/CToaster.tsx +26 -26
  166. package/src/components/toast/__tests__/CToast.spec.tsx +2 -1
  167. package/src/components/toast/__tests__/__snapshots__/CToast.spec.tsx.snap +1 -66
  168. package/src/components/tooltip/CTooltip.tsx +21 -32
  169. package/src/components/virtual-scroller/CVirtualScroller.tsx +4 -6
  170. package/src/components/widgets/CWidgetStatsA.tsx +8 -6
  171. package/src/components/widgets/CWidgetStatsD.tsx +9 -10
  172. package/src/components/widgets/CWidgetStatsE.tsx +1 -3
  173. package/src/components/widgets/CWidgetStatsF.tsx +1 -4
  174. package/dist/components/Types.d.ts +0 -14
  175. package/dist/components/multi-select/CMultiSelectCleaner.d.ts +0 -2
  176. package/dist/components/multi-select/CMultiSelectSearchInput.d.ts +0 -5
  177. package/dist/components/pagination/CSmartPagination.d.ts +0 -80
  178. package/dist/components/time-picker/CTimePicker copy.d.ts +0 -46
  179. package/dist/utils/calendar.d.ts +0 -23
  180. package/dist/utils/getNextSibling.d.ts +0 -2
  181. package/dist/utils/getPreviousSibling.d.ts +0 -2
  182. package/dist/utils/hooks/index.d.ts +0 -3
  183. package/dist/utils/hooks/useForkedRef.d.ts +0 -7
  184. package/dist/utils/hooks/useStateWithCallback.d.ts +0 -2
  185. package/dist/utils/isVisible.d.ts +0 -2
  186. package/dist/utils/time.d.ts +0 -21
@@ -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
  )
@@ -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
  }
@@ -56,7 +56,7 @@ export const CFormControlWrapper: FC<CFormControlWrapperProps> = ({
56
56
  tooltipFeedback,
57
57
  valid,
58
58
  }) => {
59
- const formControlValidation = () => (
59
+ const FormControlValidation = () => (
60
60
  <CFormControlValidation
61
61
  describedby={describedby}
62
62
  feedback={feedback}
@@ -73,14 +73,14 @@ export const CFormControlWrapper: FC<CFormControlWrapperProps> = ({
73
73
  {children}
74
74
  <CFormLabel htmlFor={id}>{label || floatingLabel}</CFormLabel>
75
75
  {text && <CFormText id={describedby}>{text}</CFormText>}
76
- {formControlValidation()}
76
+ <FormControlValidation />
77
77
  </CFormFloating>
78
78
  ) : (
79
79
  <>
80
80
  {label && <CFormLabel htmlFor={id}>{label}</CFormLabel>}
81
81
  {children}
82
82
  {text && <CFormText id={describedby}>{text}</CFormText>}
83
- {formControlValidation()}
83
+ <FormControlValidation />
84
84
  </>
85
85
  )
86
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
  )
@@ -89,17 +89,6 @@ export const CFormInput = forwardRef<HTMLInputElement, CFormInputProps>(
89
89
  return () => clearTimeout(timeOutId)
90
90
  }, [value])
91
91
 
92
- const _className = classNames(
93
- plainText ? 'form-control-plaintext' : 'form-control',
94
- {
95
- [`form-control-${size}`]: size,
96
- 'form-control-color': type === 'color',
97
- 'is-invalid': invalid,
98
- 'is-valid': valid,
99
- },
100
- className,
101
- )
102
-
103
92
  return (
104
93
  <CFormControlWrapper
105
94
  describedby={rest['aria-describedby']}
@@ -116,7 +105,16 @@ export const CFormInput = forwardRef<HTMLInputElement, CFormInputProps>(
116
105
  valid={valid}
117
106
  >
118
107
  <input
119
- 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
+ )}
120
118
  id={id}
121
119
  type={type}
122
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
  )
@@ -48,11 +48,10 @@ export interface CFormRangeProps extends InputHTMLAttributes<HTMLInputElement> {
48
48
 
49
49
  export const CFormRange = forwardRef<HTMLInputElement, CFormRangeProps>(
50
50
  ({ className, label, ...rest }, ref) => {
51
- const _className = classNames('form-range', className)
52
51
  return (
53
52
  <>
54
53
  {label && <CFormLabel htmlFor={rest.id}>{label}</CFormLabel>}
55
- <input type="range" className={_className} {...rest} ref={ref} />
54
+ <input type="range" className={classNames('form-range', className)} {...rest} ref={ref} />
56
55
  </>
57
56
  )
58
57
  },
@@ -66,15 +66,6 @@ export const CFormSelect = forwardRef<HTMLSelectElement, CFormSelectProps>(
66
66
  },
67
67
  ref,
68
68
  ) => {
69
- const _className = classNames(
70
- 'form-select',
71
- {
72
- [`form-select-${size}`]: size,
73
- 'is-invalid': invalid,
74
- 'is-valid': valid,
75
- },
76
- className,
77
- )
78
69
  return (
79
70
  <CFormControlWrapper
80
71
  describedby={rest['aria-describedby']}
@@ -90,7 +81,21 @@ export const CFormSelect = forwardRef<HTMLSelectElement, CFormSelectProps>(
90
81
  tooltipFeedback={tooltipFeedback}
91
82
  valid={valid}
92
83
  >
93
- <select id={id} className={_className} size={htmlSize} {...rest} ref={ref}>
84
+ <select
85
+ id={id}
86
+ className={classNames(
87
+ 'form-select',
88
+ {
89
+ [`form-select-${size}`]: size,
90
+ 'is-invalid': invalid,
91
+ 'is-valid': valid,
92
+ },
93
+ className,
94
+ )}
95
+ size={htmlSize}
96
+ {...rest}
97
+ ref={ref}
98
+ >
94
99
  {options
95
100
  ? options.map((option, index) => {
96
101
  return (
@@ -21,6 +21,12 @@ export interface CFormSwitchProps extends Omit<InputHTMLAttributes<HTMLInputElem
21
21
  * The element represents a caption for a component.
22
22
  */
23
23
  label?: string | ReactNode
24
+ /**
25
+ * Put switch on the opposite side.
26
+ *
27
+ * @sinve 4.7.0
28
+ */
29
+ reverse?: boolean
24
30
  /**
25
31
  * Size the component large or extra large. Works only with `switch`.
26
32
  */
@@ -36,28 +42,32 @@ export interface CFormSwitchProps extends Omit<InputHTMLAttributes<HTMLInputElem
36
42
  }
37
43
 
38
44
  export const CFormSwitch = forwardRef<HTMLInputElement, CFormSwitchProps>(
39
- ({ className, id, invalid, label, size, type = 'checkbox', valid, ...rest }, ref) => {
40
- const _className = classNames(
41
- 'form-check form-switch',
42
- {
43
- [`form-switch-${size}`]: size,
44
- 'is-invalid': invalid,
45
- 'is-valid': valid,
46
- },
47
- className,
48
- )
49
-
50
- const inputClassName = classNames('form-check-input', {
51
- 'is-invalid': invalid,
52
- 'is-valid': valid,
53
- })
54
- const labelClassName = classNames('form-check-label')
55
-
45
+ ({ className, id, invalid, label, reverse, size, type = 'checkbox', valid, ...rest }, ref) => {
56
46
  return (
57
- <div className={_className}>
58
- <input type={type} className={inputClassName} id={id} {...rest} ref={ref} />
47
+ <div
48
+ className={classNames(
49
+ 'form-check form-switch',
50
+ {
51
+ 'form-check-reverse': reverse,
52
+ [`form-switch-${size}`]: size,
53
+ 'is-invalid': invalid,
54
+ 'is-valid': valid,
55
+ },
56
+ className,
57
+ )}
58
+ >
59
+ <input
60
+ type={type}
61
+ className={classNames('form-check-input', {
62
+ 'is-invalid': invalid,
63
+ 'is-valid': valid,
64
+ })}
65
+ id={id}
66
+ {...rest}
67
+ ref={ref}
68
+ />
59
69
  {label && (
60
- <CFormLabel customClassName={labelClassName} {...(id && { htmlFor: id })}>
70
+ <CFormLabel customClassName="form-check-label" {...(id && { htmlFor: id })}>
61
71
  {label}
62
72
  </CFormLabel>
63
73
  )}
@@ -71,6 +81,7 @@ CFormSwitch.propTypes = {
71
81
  id: PropTypes.string,
72
82
  invalid: PropTypes.bool,
73
83
  label: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
84
+ reverse: PropTypes.bool,
74
85
  size: PropTypes.oneOf(['lg', 'xl']),
75
86
  type: PropTypes.oneOf(['checkbox', 'radio']),
76
87
  valid: PropTypes.bool,
@@ -15,9 +15,8 @@ export interface CFormTextProps extends HTMLAttributes<HTMLDivElement | HTMLSpan
15
15
 
16
16
  export const CFormText = forwardRef<HTMLDivElement | HTMLSpanElement, CFormTextProps>(
17
17
  ({ children, className, component: Component = 'div', ...rest }, ref) => {
18
- const _className = classNames('form-text', className)
19
18
  return (
20
- <Component className={_className} {...rest} ref={ref}>
19
+ <Component className={classNames('form-text', className)} {...rest} ref={ref}>
21
20
  {children}
22
21
  </Component>
23
22
  )
@@ -56,14 +56,6 @@ export const CFormTextarea = forwardRef<HTMLTextAreaElement, CFormTextareaProps>
56
56
  },
57
57
  ref,
58
58
  ) => {
59
- const _className = classNames(
60
- plainText ? 'form-control-plaintext' : 'form-control',
61
- {
62
- 'is-invalid': invalid,
63
- 'is-valid': valid,
64
- },
65
- className,
66
- )
67
59
  return (
68
60
  <CFormControlWrapper
69
61
  describedby={rest['aria-describedby']}
@@ -79,7 +71,19 @@ export const CFormTextarea = forwardRef<HTMLTextAreaElement, CFormTextareaProps>
79
71
  tooltipFeedback={tooltipFeedback}
80
72
  valid={valid}
81
73
  >
82
- <textarea className={_className} id={id} {...rest} ref={ref}>
74
+ <textarea
75
+ className={classNames(
76
+ plainText ? 'form-control-plaintext' : 'form-control',
77
+ {
78
+ 'is-invalid': invalid,
79
+ 'is-valid': valid,
80
+ },
81
+ className,
82
+ )}
83
+ id={id}
84
+ {...rest}
85
+ ref={ref}
86
+ >
83
87
  {children}
84
88
  </textarea>
85
89
  </CFormControlWrapper>
@@ -15,15 +15,18 @@ export interface CInputGroupProps extends HTMLAttributes<HTMLDivElement> {
15
15
 
16
16
  export const CInputGroup = forwardRef<HTMLDivElement, CInputGroupProps>(
17
17
  ({ children, className, size, ...rest }, ref) => {
18
- const _className = classNames(
19
- 'input-group',
20
- {
21
- [`input-group-${size}`]: size,
22
- },
23
- className,
24
- )
25
18
  return (
26
- <div className={_className} {...rest} ref={ref}>
19
+ <div
20
+ className={classNames(
21
+ 'input-group',
22
+ {
23
+ [`input-group-${size}`]: size,
24
+ },
25
+ className,
26
+ )}
27
+ {...rest}
28
+ ref={ref}
29
+ >
27
30
  {children}
28
31
  </div>
29
32
  )
@@ -16,9 +16,8 @@ export interface CInputGroupTextProps
16
16
 
17
17
  export const CInputGroupText = forwardRef<HTMLLabelElement | HTMLSpanElement, CInputGroupTextProps>(
18
18
  ({ children, className, component: Component = 'span', ...rest }, ref) => {
19
- const _className = classNames('input-group-text', className)
20
19
  return (
21
- <Component className={_className} {...rest} ref={ref}>
20
+ <Component className={classNames('input-group-text', className)} {...rest} ref={ref}>
22
21
  {children}
23
22
  </Component>
24
23
  )
@@ -27,7 +27,7 @@ test('CFormRange customize', async () => {
27
27
  expect(container.firstChild).toHaveAttribute('max', '150')
28
28
  expect(container.firstChild).toHaveAttribute('min', '20')
29
29
  expect(container.firstChild).toHaveAttribute('readonly', '')
30
- expect(container.firstChild).toHaveAttribute('steps', '2')
30
+ expect(container.firstChild).toHaveAttribute('step', '2')
31
31
  expect(container.firstChild).toHaveAttribute('type', 'range')
32
32
  expect(container.firstChild).toHaveAttribute('value', '80')
33
33
  })
@@ -12,9 +12,7 @@ exports[`CForm customize 1`] = `
12
12
 
13
13
  exports[`CForm example 1`] = `
14
14
  <div>
15
- <form
16
- class=""
17
- >
15
+ <form>
18
16
  <label
19
17
  class="form-label"
20
18
  >
@@ -55,9 +53,7 @@ exports[`CForm example 1`] = `
55
53
 
56
54
  exports[`loads and displays CForm component 1`] = `
57
55
  <div>
58
- <form
59
- class=""
60
- >
56
+ <form>
61
57
  Test
62
58
  </form>
63
59
  </div>
@@ -8,7 +8,7 @@ exports[`CFormRange customize 1`] = `
8
8
  max="150"
9
9
  min="20"
10
10
  readonly=""
11
- steps="2"
11
+ step="2"
12
12
  type="range"
13
13
  value="80"
14
14
  />
@@ -19,7 +19,7 @@ exports[`loads and displays CFormRange component 1`] = `
19
19
  <div>
20
20
  <input
21
21
  class="form-range"
22
- steps="3"
22
+ step="3"
23
23
  type="range"
24
24
  />
25
25
  </div>
@@ -101,13 +101,15 @@ export const CCol = forwardRef<HTMLDivElement, CColProps>(
101
101
  }
102
102
  })
103
103
 
104
- const _className = classNames(
105
- repsonsiveClassNames.length ? repsonsiveClassNames : 'col',
106
- className,
107
- )
108
-
109
104
  return (
110
- <div className={_className} {...rest} ref={ref}>
105
+ <div
106
+ className={classNames(
107
+ repsonsiveClassNames.length > 0 ? repsonsiveClassNames : 'col',
108
+ className,
109
+ )}
110
+ {...rest}
111
+ ref={ref}
112
+ >
111
113
  {children}
112
114
  </div>
113
115
  )