@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
@@ -1,8 +1,6 @@
1
1
  import React, { ElementType, forwardRef, ReactNode, useEffect, useRef, useState } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
 
4
- import type { ColumnFilter, ColumnFilterValue, Column, Item, Sorter, SorterValue } from './types'
5
-
6
4
  import { CFormCheck, CFormInput } from '../form'
7
5
  import { CTableHeaderCell, CTableRow } from '../table'
8
6
  import { CTableHead, CTableHeadProps } from '../table/CTableHead'
@@ -16,6 +14,8 @@ import {
16
14
  getTableHeaderCellStyles,
17
15
  } from './utils'
18
16
 
17
+ import type { ColumnFilter, ColumnFilterValue, Column, Item, Sorter, SorterValue } from './types'
18
+
19
19
  export interface CSmartTableHeadProps extends CTableHeadProps {
20
20
  columnFilter?: boolean | ColumnFilter
21
21
  columnFilterState?: ColumnFilterValue
@@ -93,12 +93,15 @@ export const CSmartTableHead = forwardRef<HTMLTableSectionElement, CSmartTableHe
93
93
  if (getColumnSorterState(getColumnKey(column), sorterState) === 0) {
94
94
  return <span className="opacity-25 float-end me-1">{sortingIcon}</span>
95
95
  }
96
+
96
97
  if (getColumnSorterState(getColumnKey(column), sorterState) === 'asc') {
97
98
  return <span className="float-end me-1">{sortingIconAscending}</span>
98
99
  }
100
+
99
101
  if (getColumnSorterState(getColumnKey(column), sorterState) === 'desc') {
100
102
  return <span className="float-end me-1">{sortingIconDescending}</span>
101
103
  }
104
+
102
105
  return
103
106
  }
104
107
 
@@ -93,6 +93,8 @@ export interface CSmartTableProps extends HTMLAttributes<HTMLDivElement> {
93
93
  *
94
94
  * Example item:
95
95
  * `{ name: 'John' , age: 12, _props: { color: 'success' }, _cellProps: { age: { className: 'fw-bold'}}}`
96
+ *
97
+ * @since 4.9.0
96
98
  */
97
99
  items?: Item[]
98
100
  /**
@@ -148,6 +150,8 @@ export interface CSmartTableProps extends HTMLAttributes<HTMLDivElement> {
148
150
  onRowClick?: (item: Item, index: number, columnName: string, event: MouseEvent | boolean) => void
149
151
  /**
150
152
  * Select all callback.
153
+ *
154
+ * @since 4.9.0
151
155
  */
152
156
  onSelectAll?: () => void
153
157
  /**
@@ -183,12 +187,16 @@ export interface CSmartTableProps extends HTMLAttributes<HTMLDivElement> {
183
187
  *
184
188
  * Can be customized, by passing prop as object with additional options as keys. Available options:
185
189
  * - external (Boolean) - Disables automatic selection inside the component.
190
+ *
191
+ * @since 4.9.0
186
192
  */
187
193
  selectAll?: boolean | { external?: boolean }
188
194
  /**
189
195
  * Array of selected objects, where each object represents one item - row in table.
190
196
  *
191
197
  * Example item: `{ name: 'John' , age: 12 }`
198
+ *
199
+ * @since 4.9.0
192
200
  */
193
201
  selected?: Item[]
194
202
  /**
@@ -79,9 +79,8 @@ export const getColumnLabel = (column: Column | string) =>
79
79
 
80
80
  export const getColumnNames = (columns: (string | Column)[] | undefined, items: Item[]) =>
81
81
  columns
82
- ? columns.map((column: Column) => {
83
- if (typeof column === 'object') return column.key
84
- else return column
82
+ ? columns.map((column: Column | string) => {
83
+ return typeof column === 'object' ? column.key : column
85
84
  })
86
85
  : getColumnNamesFromItems(items)
87
86
 
@@ -132,7 +131,7 @@ export const getTableHeaderCellStyles = (
132
131
  if (
133
132
  columnSorter &&
134
133
  (typeof column !== 'object' ||
135
- (typeof column === 'object' && (typeof column.sorter === 'undefined' || column.sorter)))
134
+ (typeof column === 'object' && (column.sorter === undefined || column.sorter)))
136
135
  ) {
137
136
  style['cursor'] = 'pointer'
138
137
  }
@@ -157,7 +156,7 @@ export const isSortable = (
157
156
  columnSorter &&
158
157
  (!columns ||
159
158
  typeof column !== 'object' ||
160
- (typeof column === 'object' && (typeof column.sorter === 'undefined' || column.sorter))) &&
159
+ (typeof column === 'object' && (column.sorter === undefined || column.sorter))) &&
161
160
  isDataColumn
162
161
  )
163
162
  }
@@ -2,7 +2,8 @@ import React, { ElementType, forwardRef, HTMLAttributes } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
 
5
- import { Colors, colorPropType } from '../Types'
5
+ import { colorPropType } from '../../props'
6
+ import type { Colors } from '../../types'
6
7
 
7
8
  export interface CSpinnerProps extends HTMLAttributes<HTMLDivElement | HTMLSpanElement> {
8
9
  /**
@@ -46,15 +47,18 @@ export const CSpinner = forwardRef<HTMLDivElement | HTMLSpanElement, CSpinnerPro
46
47
  },
47
48
  ref,
48
49
  ) => {
49
- const _className = classNames(
50
- `spinner-${variant}`,
51
- `text-${color}`,
52
- size && `spinner-${variant}-${size}`,
53
- className,
54
- )
55
-
56
50
  return (
57
- <Component className={_className} role="status" {...rest} ref={ref}>
51
+ <Component
52
+ className={classNames(
53
+ `spinner-${variant}`,
54
+ `text-${color}`,
55
+ size && `spinner-${variant}-${size}`,
56
+ className,
57
+ )}
58
+ role="status"
59
+ {...rest}
60
+ ref={ref}
61
+ >
58
62
  <span className="visually-hidden">{visuallyHiddenLabel}</span>
59
63
  </Component>
60
64
  )
@@ -1,17 +1,21 @@
1
- import React, { forwardRef, TableHTMLAttributes } from 'react'
1
+ import React, { forwardRef, TableHTMLAttributes, useMemo } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
 
5
- import { Colors, colorPropType } from '../Types'
6
5
  import { CTableHead, CTableHeadProps } from './CTableHead'
7
- import { CTableHeaderCell, CTableHeaderCellProps } from './CTableHeaderCell'
6
+ import { CTableHeaderCell } from './CTableHeaderCell'
8
7
  import { CTableBody } from './CTableBody'
9
- import { CTableDataCell, CTableDataCellProps } from './CTableDataCell'
10
- import { CTableRow, CTableRowProps } from './CTableRow'
8
+ import { CTableDataCell } from './CTableDataCell'
9
+ import { CTableRow } from './CTableRow'
11
10
  import { CTableFoot, CTableFootProps } from './CTableFoot'
12
11
  import { CTableCaption } from './CTableCaption'
13
12
  import { CTableResponsiveWrapper } from './CTableResponsiveWrapper'
14
13
 
14
+ import { colorPropType } from '../../props'
15
+ import type { Colors } from '../../types'
16
+ import { getColumnLabel, getColumnNames } from './utils'
17
+ import type { Column, FooterItem, Item } from './types'
18
+
15
19
  export interface CTableProps extends Omit<TableHTMLAttributes<HTMLTableElement>, 'align'> {
16
20
  /**
17
21
  * Set the vertical aligment.
@@ -123,23 +127,6 @@ export interface CTableProps extends Omit<TableHTMLAttributes<HTMLTableElement>,
123
127
  tableHeadProps?: CTableHeadProps
124
128
  }
125
129
 
126
- export interface Column {
127
- label?: string
128
- key: string
129
- _style?: any
130
- _props?: CTableHeaderCellProps
131
- }
132
-
133
- export interface Item {
134
- [key: string]: number | string | any
135
- _props?: CTableRowProps
136
- }
137
-
138
- export interface FooterItem {
139
- label?: string
140
- _props?: CTableDataCellProps
141
- }
142
-
143
130
  export const CTable = forwardRef<HTMLTableElement, CTableProps>(
144
131
  (
145
132
  {
@@ -166,50 +153,30 @@ export const CTable = forwardRef<HTMLTableElement, CTableProps>(
166
153
  },
167
154
  ref,
168
155
  ) => {
169
- const _className = classNames(
170
- 'table',
171
- {
172
- [`align-${align}`]: align,
173
- [`border-${borderColor}`]: borderColor,
174
- [`caption-top`]: captionTop || caption === 'top',
175
- 'table-bordered': bordered,
176
- 'table-borderless': borderless,
177
- [`table-${color}`]: color,
178
- 'table-hover': hover,
179
- 'table-sm': small,
180
- 'table-striped': striped,
181
- 'table-striped-columns': stripedColumns,
182
- },
183
- className,
184
- )
185
-
186
- const rawColumnNames = columns
187
- ? columns.map((column: Column) => {
188
- if (typeof column === 'object') return column.key
189
- else return column
190
- })
191
- : Object.keys((items && items[0]) || {}).filter((el) => el.charAt(0) !== '_')
192
-
193
- const pretifyName = (name: string) => {
194
- return name
195
- .replace(/[-_.]/g, ' ')
196
- .replace(/ +/g, ' ')
197
- .replace(/([a-z0-9])([A-Z])/g, '$1 $2')
198
- .split(' ')
199
- .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
200
- .join(' ')
201
- }
202
-
203
- const label = (column: Column | string) =>
204
- typeof column === 'object'
205
- ? column.label !== undefined
206
- ? column.label
207
- : pretifyName(column.key)
208
- : pretifyName(column)
156
+ const columnNames = useMemo(() => getColumnNames(columns, items), [columns, items])
209
157
 
210
158
  return (
211
159
  <CTableResponsiveWrapper responsive={responsive}>
212
- <table className={_className} {...rest} ref={ref}>
160
+ <table
161
+ className={classNames(
162
+ 'table',
163
+ {
164
+ [`align-${align}`]: align,
165
+ [`border-${borderColor}`]: borderColor,
166
+ [`caption-top`]: captionTop || caption === 'top',
167
+ 'table-bordered': bordered,
168
+ 'table-borderless': borderless,
169
+ [`table-${color}`]: color,
170
+ 'table-hover': hover,
171
+ 'table-sm': small,
172
+ 'table-striped': striped,
173
+ 'table-striped-columns': stripedColumns,
174
+ },
175
+ className,
176
+ )}
177
+ {...rest}
178
+ ref={ref}
179
+ >
213
180
  {((caption && caption !== 'top') || captionTop) && (
214
181
  <CTableCaption>{caption || captionTop}</CTableCaption>
215
182
  )}
@@ -222,7 +189,7 @@ export const CTable = forwardRef<HTMLTableElement, CTableProps>(
222
189
  {...(column._style && { style: { ...column._style } })}
223
190
  key={index}
224
191
  >
225
- {label(column)}
192
+ {getColumnLabel(column)}
226
193
  </CTableHeaderCell>
227
194
  ))}
228
195
  </CTableRow>
@@ -232,19 +199,20 @@ export const CTable = forwardRef<HTMLTableElement, CTableProps>(
232
199
  <CTableBody>
233
200
  {items.map((item: Item, index: number) => (
234
201
  <CTableRow {...(item._props && { ...item._props })} key={index}>
235
- {rawColumnNames.map((colName: string, index: number) => {
236
- return item[colName] ? (
237
- <CTableDataCell
238
- {...(item._cellProps && {
239
- ...(item._cellProps['all'] && { ...item._cellProps['all'] }),
240
- ...(item._cellProps[colName] && { ...item._cellProps[colName] }),
241
- })}
242
- key={index}
243
- >
244
- {item[colName]}
245
- </CTableDataCell>
246
- ) : null
247
- })}
202
+ {columnNames &&
203
+ columnNames.map((colName: string, index: number) => {
204
+ return item[colName] ? (
205
+ <CTableDataCell
206
+ {...(item._cellProps && {
207
+ ...(item._cellProps['all'] && { ...item._cellProps['all'] }),
208
+ ...(item._cellProps[colName] && { ...item._cellProps[colName] }),
209
+ })}
210
+ key={index}
211
+ >
212
+ {item[colName]}
213
+ </CTableDataCell>
214
+ ) : null
215
+ })}
248
216
  </CTableRow>
249
217
  ))}
250
218
  </CTableBody>
@@ -2,7 +2,8 @@ import React, { forwardRef, HTMLAttributes } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
 
5
- import { Colors, colorPropType } from '../Types'
5
+ import { colorPropType } from '../../props'
6
+ import type { Colors } from '../../types'
6
7
 
7
8
  export interface CTableBodyProps extends HTMLAttributes<HTMLTableSectionElement> {
8
9
  /**
@@ -19,15 +20,19 @@ export interface CTableBodyProps extends HTMLAttributes<HTMLTableSectionElement>
19
20
 
20
21
  export const CTableBody = forwardRef<HTMLTableSectionElement, CTableBodyProps>(
21
22
  ({ children, className, color, ...rest }, ref) => {
22
- const _className = classNames(
23
- {
24
- [`table-${color}`]: color,
25
- },
26
- className,
27
- )
28
-
29
23
  return (
30
- <tbody className={_className ? _className : undefined} {...rest} ref={ref}>
24
+ <tbody
25
+ className={
26
+ classNames(
27
+ {
28
+ [`table-${color}`]: color,
29
+ },
30
+ className,
31
+ ) || undefined
32
+ }
33
+ {...rest}
34
+ ref={ref}
35
+ >
31
36
  {children}
32
37
  </tbody>
33
38
  )
@@ -2,7 +2,8 @@ import React, { forwardRef, TdHTMLAttributes, ThHTMLAttributes } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
 
5
- import { Colors, colorPropType } from '../Types'
5
+ import { colorPropType } from '../../props'
6
+ import type { Colors } from '../../types'
6
7
 
7
8
  export interface CTableDataCellProps
8
9
  extends Omit<TdHTMLAttributes<HTMLTableCellElement>, 'align'>,
@@ -33,19 +34,23 @@ export interface CTableDataCellProps
33
34
 
34
35
  export const CTableDataCell = forwardRef<HTMLTableCellElement, CTableDataCellProps>(
35
36
  ({ children, active, align, className, color, ...rest }, ref) => {
36
- const _className = classNames(
37
- {
38
- [`align-${align}`]: align,
39
- 'table-active': active,
40
- [`table-${color}`]: color,
41
- },
42
- className,
43
- )
44
-
45
37
  const Component = rest.scope ? 'th' : 'td'
46
38
 
47
39
  return (
48
- <Component className={_className ? _className : undefined} {...rest} ref={ref}>
40
+ <Component
41
+ className={
42
+ classNames(
43
+ {
44
+ [`align-${align}`]: align,
45
+ 'table-active': active,
46
+ [`table-${color}`]: color,
47
+ },
48
+ className,
49
+ ) || undefined
50
+ }
51
+ {...rest}
52
+ ref={ref}
53
+ >
49
54
  {children}
50
55
  </Component>
51
56
  )
@@ -2,7 +2,8 @@ import PropTypes from 'prop-types'
2
2
  import React, { forwardRef, HTMLAttributes } from 'react'
3
3
  import classNames from 'classnames'
4
4
 
5
- import { Colors, colorPropType } from '../Types'
5
+ import { colorPropType } from '../../props'
6
+ import type { Colors } from '../../types'
6
7
 
7
8
  export interface CTableFootProps extends HTMLAttributes<HTMLTableSectionElement> {
8
9
  /**
@@ -19,15 +20,19 @@ export interface CTableFootProps extends HTMLAttributes<HTMLTableSectionElement>
19
20
 
20
21
  export const CTableFoot = forwardRef<HTMLTableSectionElement, CTableFootProps>(
21
22
  ({ children, className, color, ...rest }, ref) => {
22
- const _className = classNames(
23
- {
24
- [`table-${color}`]: color,
25
- },
26
- className,
27
- )
28
-
29
23
  return (
30
- <tfoot className={_className ? _className : undefined} {...rest} ref={ref}>
24
+ <tfoot
25
+ className={
26
+ classNames(
27
+ {
28
+ [`table-${color}`]: color,
29
+ },
30
+ className,
31
+ ) || undefined
32
+ }
33
+ {...rest}
34
+ ref={ref}
35
+ >
31
36
  {children}
32
37
  </tfoot>
33
38
  )
@@ -2,7 +2,8 @@ import React, { forwardRef, HTMLAttributes } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
 
5
- import { Colors, colorPropType } from '../Types'
5
+ import { colorPropType } from '../../props'
6
+ import type { Colors } from '../../types'
6
7
 
7
8
  export interface CTableHeadProps extends HTMLAttributes<HTMLTableSectionElement> {
8
9
  /**
@@ -19,15 +20,19 @@ export interface CTableHeadProps extends HTMLAttributes<HTMLTableSectionElement>
19
20
 
20
21
  export const CTableHead = forwardRef<HTMLTableSectionElement, CTableHeadProps>(
21
22
  ({ children, className, color, ...rest }, ref) => {
22
- const _className = classNames(
23
- {
24
- [`table-${color}`]: color,
25
- },
26
- className,
27
- )
28
-
29
23
  return (
30
- <thead className={_className ? _className : undefined} {...rest} ref={ref}>
24
+ <thead
25
+ className={
26
+ classNames(
27
+ {
28
+ [`table-${color}`]: color,
29
+ },
30
+ className,
31
+ ) || undefined
32
+ }
33
+ {...rest}
34
+ ref={ref}
35
+ >
31
36
  {children}
32
37
  </thead>
33
38
  )
@@ -2,7 +2,8 @@ import React, { forwardRef, ThHTMLAttributes } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
 
5
- import { Colors, colorPropType } from '../Types'
5
+ import { colorPropType } from '../../props'
6
+ import type { Colors } from '../../types'
6
7
 
7
8
  export interface CTableHeaderCellProps extends ThHTMLAttributes<HTMLTableCellElement> {
8
9
  /**
@@ -19,15 +20,19 @@ export interface CTableHeaderCellProps extends ThHTMLAttributes<HTMLTableCellEle
19
20
 
20
21
  export const CTableHeaderCell = forwardRef<HTMLTableCellElement, CTableHeaderCellProps>(
21
22
  ({ children, className, color, ...rest }, ref) => {
22
- const _className = classNames(
23
- {
24
- [`table-${color}`]: color,
25
- },
26
- className,
27
- )
28
-
29
23
  return (
30
- <th className={_className ? _className : undefined} {...rest} ref={ref}>
24
+ <th
25
+ className={
26
+ classNames(
27
+ {
28
+ [`table-${color}`]: color,
29
+ },
30
+ className,
31
+ ) || undefined
32
+ }
33
+ {...rest}
34
+ ref={ref}
35
+ >
31
36
  {children}
32
37
  </th>
33
38
  )
@@ -2,7 +2,6 @@ import React, { FC, HTMLAttributes } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
 
4
4
  export interface CTableResponsiveWrapperProps extends HTMLAttributes<HTMLDivElement> {
5
- children: any
6
5
  /**
7
6
  * Make any table responsive across all viewports or pick a maximum breakpoint with which to have a responsive table up to.
8
7
  */
@@ -24,12 +23,12 @@ export const CTableResponsiveWrapper: FC<CTableResponsiveWrapperProps> = ({
24
23
  {children}
25
24
  </div>
26
25
  ) : (
27
- children
26
+ <>{children}</>
28
27
  )
29
28
  }
30
29
 
31
30
  CTableResponsiveWrapper.propTypes = {
32
- children: PropTypes.any,
31
+ children: PropTypes.node,
33
32
  responsive: PropTypes.oneOfType([
34
33
  PropTypes.bool,
35
34
  PropTypes.oneOf<'sm' | 'md' | 'lg' | 'xl' | 'xxl'>(['sm', 'md', 'lg', 'xl', 'xxl']),
@@ -2,7 +2,8 @@ import React, { forwardRef, HTMLAttributes } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
 
5
- import { Colors, colorPropType } from '../Types'
5
+ import { colorPropType } from '../../props'
6
+ import type { Colors } from '../../types'
6
7
 
7
8
  export interface CTableRowProps extends HTMLAttributes<HTMLTableRowElement> {
8
9
  /**
@@ -27,17 +28,21 @@ export interface CTableRowProps extends HTMLAttributes<HTMLTableRowElement> {
27
28
 
28
29
  export const CTableRow = forwardRef<HTMLTableRowElement, CTableRowProps>(
29
30
  ({ children, active, align, className, color, ...rest }, ref) => {
30
- const _className = classNames(
31
- {
32
- [`align-${align}`]: align,
33
- 'table-active': active,
34
- [`table-${color}`]: color,
35
- },
36
- className,
37
- )
38
-
39
31
  return (
40
- <tr className={_className ? _className : undefined} {...rest} ref={ref}>
32
+ <tr
33
+ className={
34
+ classNames(
35
+ {
36
+ [`align-${align}`]: align,
37
+ 'table-active': active,
38
+ [`table-${color}`]: color,
39
+ },
40
+ className,
41
+ ) || undefined
42
+ }
43
+ {...rest}
44
+ ref={ref}
45
+ >
41
46
  {children}
42
47
  </tr>
43
48
  )
@@ -8,7 +8,6 @@ exports[`CTable customize 1`] = `
8
8
  <table
9
9
  class="table align-middle border-primary caption-top table-bordered table-borderless table-info table-hover table-sm table-striped bazinga"
10
10
  >
11
- <tbody />
12
11
  <tbody>
13
12
  <tr>
14
13
  <td>
@@ -26,7 +25,6 @@ exports[`CTable full example test 1`] = `
26
25
  <table
27
26
  class="table caption-top"
28
27
  >
29
- <tbody />
30
28
  <caption>
31
29
  List of users
32
30
  </caption>
@@ -194,8 +192,6 @@ exports[`loads and displays CTable component 1`] = `
194
192
  <div>
195
193
  <table
196
194
  class="table"
197
- >
198
- <tbody />
199
- </table>
195
+ />
200
196
  </div>
201
197
  `;
@@ -0,0 +1,20 @@
1
+ import { CTableDataCellProps } from '../table/CTableDataCell'
2
+ import { CTableHeaderCellProps } from '../table/CTableHeaderCell'
3
+ import { CTableRowProps } from '../table/CTableRow'
4
+
5
+ export type Column = {
6
+ label?: string
7
+ key: string
8
+ _style?: any
9
+ _props?: CTableHeaderCellProps
10
+ }
11
+
12
+ export type FooterItem = {
13
+ label?: string
14
+ _props?: CTableDataCellProps
15
+ }
16
+
17
+ export type Item = {
18
+ [key: string]: number | string | any
19
+ _props?: CTableRowProps
20
+ }
@@ -0,0 +1,24 @@
1
+ import type { Column, Item } from './types'
2
+
3
+ export const pretifyName = (name: string) => {
4
+ return name
5
+ .replace(/[-_.]/g, ' ')
6
+ .replace(/ +/g, ' ')
7
+ .replace(/([a-z0-9])([A-Z])/g, '$1 $2')
8
+ .split(' ')
9
+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
10
+ .join(' ')
11
+ }
12
+
13
+ export const getColumnLabel = (column: Column | string) =>
14
+ typeof column === 'object' ? column.label ?? pretifyName(column.key) : pretifyName(column)
15
+
16
+ export const getColumnNames = (columns: (string | Column)[] | undefined, items?: Item[]) =>
17
+ columns
18
+ ? columns.map((column: Column | string) => {
19
+ return typeof column === 'object' ? column.key : column
20
+ })
21
+ : items && getColumnNamesFromItems(items)
22
+
23
+ export const getColumnNamesFromItems = (items: Item[]) =>
24
+ Object.keys(items[0] || {}).filter((el) => el.charAt(0) !== '_')
@@ -11,9 +11,8 @@ export interface CTabContentProps extends HTMLAttributes<HTMLDivElement> {
11
11
 
12
12
  export const CTabContent = forwardRef<HTMLDivElement, CTabContentProps>(
13
13
  ({ children, className, ...rest }, ref) => {
14
- const _className = classNames('tab-content', className)
15
14
  return (
16
- <div className={_className} {...rest} ref={ref}>
15
+ <div className={classNames('tab-content', className)} {...rest} ref={ref}>
17
16
  {children}
18
17
  </div>
19
18
  )