@coreui/react-pro 4.9.0-next.0 → 4.9.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) 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/date-range-picker/CDateRangePicker.d.ts +1 -1
  10. package/dist/components/date-range-picker/utils.d.ts +1 -0
  11. package/dist/components/dropdown/CDropdown.d.ts +1 -1
  12. package/dist/components/dropdown/CDropdownToggle.d.ts +1 -1
  13. package/dist/components/form/CFormCheck.d.ts +1 -1
  14. package/dist/components/list-group/CListGroupItem.d.ts +4 -5
  15. package/dist/components/multi-select/CMultiSelect.d.ts +1 -13
  16. package/dist/components/multi-select/CMultiSelectNativeSelect.d.ts +1 -1
  17. package/dist/components/multi-select/CMultiSelectOptions.d.ts +1 -1
  18. package/dist/components/multi-select/CMultiSelectSelection.d.ts +1 -1
  19. package/dist/components/multi-select/types.d.ts +14 -0
  20. package/dist/components/multi-select/utils.d.ts +6 -0
  21. package/dist/components/navbar/CNavbar.d.ts +1 -1
  22. package/dist/components/picker/CPicker.d.ts +1 -1
  23. package/dist/components/placeholder/CPlaceholder.d.ts +1 -1
  24. package/dist/components/popover/CPopover.d.ts +1 -1
  25. package/dist/components/progress/CProgressBar.d.ts +1 -1
  26. package/dist/components/smart-table/CSmartTableHead.d.ts +1 -1
  27. package/dist/components/smart-table/CSmartTableInterface.d.ts +8 -0
  28. package/dist/components/smart-table/types.d.ts +1 -1
  29. package/dist/components/spinner/CSpinner.d.ts +1 -1
  30. package/dist/components/table/CTable.d.ts +2 -18
  31. package/dist/components/table/CTableBody.d.ts +1 -1
  32. package/dist/components/table/CTableDataCell.d.ts +1 -1
  33. package/dist/components/table/CTableFoot.d.ts +1 -1
  34. package/dist/components/table/CTableHead.d.ts +1 -1
  35. package/dist/components/table/CTableHeaderCell.d.ts +1 -1
  36. package/dist/components/table/CTableRow.d.ts +1 -1
  37. package/dist/components/table/types.d.ts +17 -0
  38. package/dist/components/table/utils.d.ts +5 -0
  39. package/dist/components/toast/CToast.d.ts +1 -1
  40. package/dist/components/toast/CToastClose.d.ts +1 -1
  41. package/dist/components/tooltip/CTooltip.d.ts +1 -1
  42. package/dist/components/virtual-scroller/CVirtualScroller.d.ts +0 -8
  43. package/dist/components/widgets/CWidgetStatsA.d.ts +1 -1
  44. package/dist/components/widgets/CWidgetStatsB.d.ts +1 -1
  45. package/dist/components/widgets/CWidgetStatsC.d.ts +1 -1
  46. package/dist/components/widgets/CWidgetStatsD.d.ts +1 -1
  47. package/dist/components/widgets/CWidgetStatsF.d.ts +1 -1
  48. package/dist/index.es.js +216 -225
  49. package/dist/index.es.js.map +1 -1
  50. package/dist/index.js +216 -225
  51. package/dist/index.js.map +1 -1
  52. package/dist/props.d.ts +8 -0
  53. package/dist/types.d.ts +7 -0
  54. package/dist/utils/index.d.ts +1 -3
  55. package/package.json +1 -1
  56. package/src/components/accordion/CAccordionBody.tsx +1 -0
  57. package/src/components/accordion/CAccordionCollapse.tsx +1 -0
  58. package/src/components/alert/CAlert.tsx +2 -1
  59. package/src/components/avatar/CAvatar.tsx +2 -8
  60. package/src/components/backdrop/CBackdrop.tsx +1 -1
  61. package/src/components/badge/CBadge.tsx +2 -10
  62. package/src/components/button/CButton.tsx +3 -1
  63. package/src/components/calendar/utils.ts +0 -46
  64. package/src/components/callout/CCallout.tsx +2 -1
  65. package/src/components/card/CCard.tsx +2 -1
  66. package/src/components/date-range-picker/CDateRangePicker.tsx +2 -2
  67. package/src/components/date-range-picker/utils.ts +49 -0
  68. package/src/components/dropdown/CDropdown.tsx +2 -1
  69. package/src/components/dropdown/CDropdownItem.tsx +1 -2
  70. package/src/components/dropdown/CDropdownMenu.tsx +2 -1
  71. package/src/components/dropdown/CDropdownToggle.tsx +5 -4
  72. package/src/components/form/CFormCheck.tsx +3 -3
  73. package/src/components/form/CFormControlValidation.tsx +0 -1
  74. package/src/components/form/CFormControlWrapper.tsx +0 -1
  75. package/src/components/form/CFormInput.tsx +8 -4
  76. package/src/components/form/CFormRange.tsx +1 -2
  77. package/src/components/form/CFormSelect.tsx +1 -2
  78. package/src/components/form/CFormTextarea.tsx +1 -2
  79. package/src/components/list-group/CListGroupItem.tsx +8 -8
  80. package/src/components/list-group/CListGroupItem.tsx~HEAD +3 -1
  81. package/src/components/modal/CModal.tsx +2 -2
  82. package/src/components/modal/CModalHeader.tsx +3 -2
  83. package/src/components/multi-select/CMultiSelect.tsx +15 -74
  84. package/src/components/multi-select/CMultiSelectNativeSelect.tsx +1 -1
  85. package/src/components/multi-select/CMultiSelectOptions.tsx +2 -2
  86. package/src/components/multi-select/CMultiSelectSelection.tsx +1 -1
  87. package/src/components/multi-select/types.ts +15 -0
  88. package/src/components/multi-select/utils.ts +92 -0
  89. package/src/components/nav/CNavItem.tsx +1 -0
  90. package/src/components/nav/CNavLink.tsx +3 -3
  91. package/src/components/navbar/CNavbar.tsx +2 -1
  92. package/src/components/offcanvas/COffcanvas.tsx +4 -3
  93. package/src/components/picker/CPicker.tsx +1 -1
  94. package/src/components/placeholder/CPlaceholder.tsx +2 -1
  95. package/src/components/popover/CPopover.tsx +2 -1
  96. package/src/components/progress/CProgress.tsx +1 -0
  97. package/src/components/progress/CProgressBar.tsx +2 -1
  98. package/src/components/sidebar/CSidebar.tsx +2 -1
  99. package/src/components/smart-table/CSmartTable.tsx +1 -1
  100. package/src/components/smart-table/CSmartTableBody.tsx +82 -81
  101. package/src/components/smart-table/CSmartTableHead.tsx +5 -2
  102. package/src/components/smart-table/CSmartTableInterface.tsx +8 -0
  103. package/src/components/smart-table/{utils.tsx → utils.ts} +1 -1
  104. package/src/components/spinner/CSpinner.tsx +2 -1
  105. package/src/components/table/CTable.tsx +25 -59
  106. package/src/components/table/CTableBody.tsx +2 -1
  107. package/src/components/table/CTableDataCell.tsx +2 -1
  108. package/src/components/table/CTableFoot.tsx +2 -1
  109. package/src/components/table/CTableHead.tsx +2 -1
  110. package/src/components/table/CTableHeaderCell.tsx +2 -1
  111. package/src/components/table/CTableRow.tsx +2 -1
  112. package/src/components/table/types.ts +20 -0
  113. package/src/components/table/utils.ts +29 -0
  114. package/src/components/tabs/CTabPane.tsx +1 -0
  115. package/src/components/time-picker/CTimePicker.tsx +2 -4
  116. package/src/components/toast/CToast.tsx +3 -3
  117. package/src/components/toast/CToastClose.tsx +2 -2
  118. package/src/components/toast/CToaster.tsx +2 -1
  119. package/src/components/tooltip/CTooltip.tsx +3 -2
  120. package/src/components/virtual-scroller/CVirtualScroller.tsx +31 -54
  121. package/src/components/widgets/CWidgetStatsA.tsx +3 -3
  122. package/src/components/widgets/CWidgetStatsB.tsx +4 -4
  123. package/src/components/widgets/CWidgetStatsC.tsx +4 -4
  124. package/src/components/widgets/CWidgetStatsD.tsx +4 -5
  125. package/src/components/widgets/CWidgetStatsE.tsx +1 -2
  126. package/src/components/widgets/CWidgetStatsF.tsx +3 -4
  127. package/src/{components/Types.tsx → props.ts} +1 -68
  128. package/src/types.ts +68 -0
  129. package/src/utils/index.ts +1 -3
  130. package/src/components/multi-select/CMultiSelectCleaner.tsx +0 -18
  131. package/src/utils/getNextSibling.ts +0 -18
  132. package/src/utils/getPreviousSibling.ts +0 -18
  133. package/src/components/smart-table/{types.tsx → types.ts} +1 -1
@@ -2,10 +2,10 @@ import React, { forwardRef, Fragment, HTMLAttributes, ReactNode } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
 
5
- import { Option } from './CMultiSelect'
6
5
  import { CVirtualScroller } from './../virtual-scroller'
7
6
 
8
- import { getNextSibling, getPreviousSibling } from './../../utils'
7
+ import { getNextSibling, getPreviousSibling } from './utils'
8
+ import type { Option } from './types'
9
9
 
10
10
  export interface CMultiSelectOptionsProps extends HTMLAttributes<HTMLDivElement> {
11
11
  handleOptionOnClick?: (option: Option) => void
@@ -1,7 +1,7 @@
1
1
  import React, { forwardRef, HTMLAttributes } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
 
4
- import type { SelectedOption } from './CMultiSelect'
4
+ import type { SelectedOption } from './types'
5
5
 
6
6
  export interface CMultiSelectSelectionProps extends HTMLAttributes<HTMLSpanElement> {
7
7
  multiple?: boolean
@@ -0,0 +1,15 @@
1
+ export type Option = {
2
+ disabled?: boolean
3
+ label?: string
4
+ options?: Option[]
5
+ order?: number
6
+ selected?: boolean
7
+ text: string
8
+ value: number | string
9
+ }
10
+
11
+ export type SelectedOption = {
12
+ disabled?: boolean
13
+ text: string
14
+ value: number | string
15
+ }
@@ -0,0 +1,92 @@
1
+ import type { Option, SelectedOption } from './types'
2
+
3
+ export const filterOptionsList = (search: string, _options: Option[]) => {
4
+ return search.length
5
+ ? _options &&
6
+ _options.reduce((acc: Option[], val: Option) => {
7
+ const options =
8
+ val.options &&
9
+ val.options.filter(
10
+ (element) =>
11
+ element.text && element.text.toLowerCase().includes(search.toLowerCase()),
12
+ )
13
+
14
+ if (
15
+ (val.text && val.text.toLowerCase().includes(search.toLowerCase())) ||
16
+ (options && options.length)
17
+ ) {
18
+ acc.push(Object.assign({}, val, options && options.length && { options }))
19
+ }
20
+
21
+ return acc
22
+ }, [])
23
+ : _options
24
+ }
25
+
26
+ export const flattenArray = (options: Option[]): Option[] => {
27
+ return options.reduce((acc: Option[], val: Option) => {
28
+ return acc.concat(Array.isArray(val.options) ? flattenArray(val.options) : val)
29
+ }, [])
30
+ }
31
+
32
+ export const getNextSibling = (elem: HTMLElement, selector?: string) => {
33
+ // Get the next sibling element
34
+ let sibling = elem.nextElementSibling
35
+
36
+ // If there's no selector, return the first sibling
37
+ if (!selector) return sibling
38
+
39
+ // If the sibling matches our selector, use it
40
+ // If not, jump to the next sibling and continue the loop
41
+ while (sibling) {
42
+ if (sibling.matches(selector)) return sibling
43
+ sibling = sibling.nextElementSibling
44
+ }
45
+
46
+ return
47
+ }
48
+
49
+ export const getPreviousSibling = (elem: HTMLElement, selector?: string) => {
50
+ // Get the next sibling element
51
+ let sibling = elem.previousElementSibling
52
+
53
+ // If there's no selector, return the first sibling
54
+ if (!selector) return sibling
55
+
56
+ // If the sibling matches our selector, use it
57
+ // If not, jump to the next sibling and continue the loop
58
+ while (sibling) {
59
+ if (sibling.matches(selector)) return sibling
60
+ sibling = sibling.previousElementSibling
61
+ }
62
+
63
+ return
64
+ }
65
+
66
+ export const selectOptions = (
67
+ options: Option[],
68
+ selected: SelectedOption[],
69
+ deselected?: Option[],
70
+ ) => {
71
+ let _selected = [...selected, ...options]
72
+
73
+ if (deselected) {
74
+ _selected = _selected.filter(
75
+ (selectedOption) =>
76
+ !deselected.some((deselectedOption) => deselectedOption.value === selectedOption.value),
77
+ )
78
+ }
79
+
80
+ const deduplicated = _selected.reduce((unique: Option[], option) => {
81
+ if (!unique.some((obj) => obj.value === option.value)) {
82
+ unique.push({
83
+ value: option.value,
84
+ text: option.text,
85
+ ...(option.disabled && { disabled: option.disabled }),
86
+ })
87
+ }
88
+ return unique
89
+ }, []) as SelectedOption[]
90
+
91
+ return deduplicated
92
+ }
@@ -1,6 +1,7 @@
1
1
  import React, { forwardRef } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
+
4
5
  import { CNavLink, CNavLinkProps } from './CNavLink'
5
6
 
6
7
  export const CNavItem = forwardRef<HTMLLIElement, CNavLinkProps>(
@@ -2,10 +2,10 @@ import React, { ElementType, forwardRef, useContext, useEffect, useRef } from 'r
2
2
  import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
 
5
- import { useForkedRef } from '../../hooks'
6
-
7
- import { CNavContext } from '../sidebar/CSidebarNav'
8
5
  import { CLinkProps, CLink } from '../link/CLink'
6
+ import { CNavContext } from '../sidebar/CSidebarNav'
7
+
8
+ import { useForkedRef } from '../../hooks'
9
9
 
10
10
  export interface CNavLinkProps extends Omit<CLinkProps, 'idx'> {
11
11
  /**
@@ -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 CNavbarProps extends HTMLAttributes<HTMLDivElement> {
8
9
  /**
@@ -1,12 +1,13 @@
1
- import PropTypes from 'prop-types'
2
1
  import React, { forwardRef, HTMLAttributes, useCallback, useEffect, useRef, useState } from 'react'
3
2
  import { createPortal } from 'react-dom'
4
- import { Transition } from 'react-transition-group'
3
+ import PropTypes from 'prop-types'
5
4
  import classNames from 'classnames'
5
+ import { Transition } from 'react-transition-group'
6
6
 
7
- import { useForkedRef } from '../../hooks'
8
7
  import { CBackdrop } from '../backdrop/CBackdrop'
9
8
 
9
+ import { useForkedRef } from '../../hooks'
10
+
10
11
  export interface COffcanvasProps extends HTMLAttributes<HTMLDivElement> {
11
12
  /**
12
13
  * Apply a backdrop on body while offcanvas is open.
@@ -7,7 +7,7 @@ import { CDropdown, CDropdownProps } from '../dropdown/CDropdown'
7
7
  import { CDropdownMenu } from '../dropdown/CDropdownMenu'
8
8
  import { CDropdownToggle } from '../dropdown/CDropdownToggle'
9
9
 
10
- import { Colors } from '../Types'
10
+ import { Colors } from '../../types'
11
11
 
12
12
  export interface CPickerProps extends Omit<CDropdownProps, 'variant'> {
13
13
  /**
@@ -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 CPlaceholderProps extends HTMLAttributes<HTMLSpanElement> {
8
9
  /**
@@ -5,7 +5,8 @@ import classNames from 'classnames'
5
5
  import { usePopper } from 'react-popper'
6
6
  import { Transition } from 'react-transition-group'
7
7
 
8
- import { Triggers, triggerPropType } from '../Types'
8
+ import { triggerPropType } from '../../props'
9
+ import type { Triggers } from '../../types'
9
10
 
10
11
  export interface CPopoverProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title'> {
11
12
  /**
@@ -1,6 +1,7 @@
1
1
  import React, { forwardRef, HTMLAttributes } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
+
4
5
  import { CProgressBar, CProgressBarProps } from './CProgressBar'
5
6
 
6
7
  export interface CProgressProps
@@ -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, Gradients, colorPropType, gradientsPropType } from '../Types'
5
+ import { colorPropType, gradientsPropType } from '../../props'
6
+ import type { Colors, Gradients } from '../../types'
6
7
 
7
8
  export interface CProgressBarProps extends HTMLAttributes<HTMLDivElement> {
8
9
  /**
@@ -3,9 +3,10 @@ import { createPortal } from 'react-dom'
3
3
  import PropTypes from 'prop-types'
4
4
  import classNames from 'classnames'
5
5
 
6
+ import { CBackdrop } from '../backdrop/CBackdrop'
7
+
6
8
  import { isInViewport } from '../../utils'
7
9
  import { useForkedRef } from '../../hooks'
8
- import { CBackdrop } from '../backdrop/CBackdrop'
9
10
 
10
11
  export interface CSidebarProps extends HTMLAttributes<HTMLDivElement> {
11
12
  /**
@@ -360,7 +360,7 @@ export const CSmartTable = forwardRef<HTMLDivElement, CSmartTableProps>(
360
360
  Object.values(columnFilterState).join('')
361
361
  }
362
362
  onClick={() => handleClean()}
363
- onKeyUp={(event) => {
363
+ onKeyDown={(event) => {
364
364
  if (event.key === 'Enter') handleClean()
365
365
  }}
366
366
  />
@@ -51,89 +51,90 @@ export const CSmartTableBody = forwardRef<HTMLTableSectionElement, CSmartTableBo
51
51
  {...rest}
52
52
  ref={ref}
53
53
  >
54
- {currentItems.map((item: Item, trIndex) => {
55
- return (
56
- <React.Fragment key={trIndex}>
57
- <CTableRow
58
- {...(item._props && { ...item._props })}
59
- {...(clickableRows && { tabIndex: 0 })}
60
- onClick={(event) =>
61
- onRowClick &&
62
- onRowClick(
63
- item,
64
- trIndex + firstItemOnActivePageIndex,
65
- getClickedColumnName(event.target as HTMLTextAreaElement, columnNames),
66
- event,
67
- )
68
- }
69
- >
70
- {selectable && (
71
- <CTableDataCell>
72
- <CFormCheck
73
- checked={
74
- selected &&
75
- isObjectInArray(selected, item, ['_cellProps', '_props', '_selected'])
76
- }
77
- onChange={(event) => {
78
- const _item = { ...item }
79
- delete _item['_cellProps']
80
- delete _item['_props']
81
- delete _item['_selected']
82
- onRowChecked && onRowChecked(_item, event.target.checked)
83
- }}
84
- />
85
- </CTableDataCell>
86
- )}
87
- {columnNames.map((colName, index) => {
88
- return (
89
- (scopedColumns &&
90
- scopedColumns[colName] &&
91
- React.cloneElement(
92
- scopedColumns[colName](item, trIndex + firstItemOnActivePageIndex),
93
- {
94
- key: index,
95
- },
96
- )) || (
97
- <CTableDataCell {...getTableDataCellProps(item, colName)} key={index}>
98
- {String(item[colName])}
99
- </CTableDataCell>
54
+ {currentItems.length ? (
55
+ currentItems.map((item: Item, trIndex) => {
56
+ return (
57
+ <React.Fragment key={trIndex}>
58
+ <CTableRow
59
+ {...(item._props && { ...item._props })}
60
+ {...(clickableRows && { tabIndex: 0 })}
61
+ onClick={(event) =>
62
+ onRowClick &&
63
+ onRowClick(
64
+ item,
65
+ trIndex + firstItemOnActivePageIndex,
66
+ getClickedColumnName(event.target as HTMLTextAreaElement, columnNames),
67
+ event,
100
68
  )
101
- )
102
- })}
103
- </CTableRow>
104
- {scopedColumns && scopedColumns.details && (
105
- <>
106
- <CTableRow>
107
- <CTableDataCell
108
- colSpan={colspan}
109
- className="p-0"
110
- style={{ borderBottomWidth: 0 }}
111
- tabIndex={-1}
112
- ></CTableDataCell>
113
- </CTableRow>
114
- <CTableRow
115
- onClick={(event) =>
116
- onRowClick &&
117
- onRowClick(
118
- item,
119
- trIndex + firstItemOnActivePageIndex,
120
- getClickedColumnName(event.target as HTMLTextAreaElement, columnNames),
121
- true,
122
- )
123
- }
124
- className="p-0"
125
- key={`details${trIndex}`}
126
- >
127
- <CTableDataCell colSpan={colspan} className="p-0" style={{ border: 0 }}>
128
- {scopedColumns.details(item, trIndex + firstItemOnActivePageIndex)}
69
+ }
70
+ >
71
+ {selectable && (
72
+ <CTableDataCell>
73
+ <CFormCheck
74
+ checked={
75
+ selected &&
76
+ isObjectInArray(selected, item, ['_cellProps', '_props', '_selected'])
77
+ }
78
+ onChange={(event) => {
79
+ const _item = { ...item }
80
+ delete _item['_cellProps']
81
+ delete _item['_props']
82
+ delete _item['_selected']
83
+ onRowChecked && onRowChecked(_item, event.target.checked)
84
+ }}
85
+ />
129
86
  </CTableDataCell>
130
- </CTableRow>
131
- </>
132
- )}
133
- </React.Fragment>
134
- )
135
- })}
136
- {!currentItems.length && (
87
+ )}
88
+ {columnNames.map((colName, index) => {
89
+ return (
90
+ (scopedColumns &&
91
+ scopedColumns[colName] &&
92
+ React.cloneElement(
93
+ scopedColumns[colName](item, trIndex + firstItemOnActivePageIndex),
94
+ {
95
+ key: index,
96
+ },
97
+ )) || (
98
+ <CTableDataCell {...getTableDataCellProps(item, colName)} key={index}>
99
+ {String(item[colName])}
100
+ </CTableDataCell>
101
+ )
102
+ )
103
+ })}
104
+ </CTableRow>
105
+ {scopedColumns && scopedColumns.details && (
106
+ <>
107
+ <CTableRow>
108
+ <CTableDataCell
109
+ colSpan={colspan}
110
+ className="p-0"
111
+ style={{ borderBottomWidth: 0 }}
112
+ tabIndex={-1}
113
+ ></CTableDataCell>
114
+ </CTableRow>
115
+ <CTableRow
116
+ onClick={(event) =>
117
+ onRowClick &&
118
+ onRowClick(
119
+ item,
120
+ trIndex + firstItemOnActivePageIndex,
121
+ getClickedColumnName(event.target as HTMLTextAreaElement, columnNames),
122
+ true,
123
+ )
124
+ }
125
+ className="p-0"
126
+ key={`details${trIndex}`}
127
+ >
128
+ <CTableDataCell colSpan={colspan} className="p-0" style={{ border: 0 }}>
129
+ {scopedColumns.details(item, trIndex + firstItemOnActivePageIndex)}
130
+ </CTableDataCell>
131
+ </CTableRow>
132
+ </>
133
+ )}
134
+ </React.Fragment>
135
+ )
136
+ })
137
+ ) : (
137
138
  <CTableRow>
138
139
  <CTableDataCell colSpan={colspan}>{noItemsLabel}</CTableDataCell>
139
140
  </CTableRow>
@@ -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,7 +79,7 @@ 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) => {
82
+ ? columns.map((column: Column | string) => {
83
83
  if (typeof column === 'object') return column.key
84
84
  else return column
85
85
  })
@@ -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
  /**
@@ -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
  {
@@ -183,29 +170,7 @@ export const CTable = forwardRef<HTMLTableElement, CTableProps>(
183
170
  className,
184
171
  )
185
172
 
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)
173
+ const columnNames = useMemo(() => getColumnNames(columns, items), [columns, items])
209
174
 
210
175
  return (
211
176
  <CTableResponsiveWrapper responsive={responsive}>
@@ -222,7 +187,7 @@ export const CTable = forwardRef<HTMLTableElement, CTableProps>(
222
187
  {...(column._style && { style: { ...column._style } })}
223
188
  key={index}
224
189
  >
225
- {label(column)}
190
+ {getColumnLabel(column)}
226
191
  </CTableHeaderCell>
227
192
  ))}
228
193
  </CTableRow>
@@ -232,19 +197,20 @@ export const CTable = forwardRef<HTMLTableElement, CTableProps>(
232
197
  <CTableBody>
233
198
  {items.map((item: Item, index: number) => (
234
199
  <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
- })}
200
+ {columnNames &&
201
+ columnNames.map((colName: string, index: number) => {
202
+ return item[colName] ? (
203
+ <CTableDataCell
204
+ {...(item._cellProps && {
205
+ ...(item._cellProps['all'] && { ...item._cellProps['all'] }),
206
+ ...(item._cellProps[colName] && { ...item._cellProps[colName] }),
207
+ })}
208
+ key={index}
209
+ >
210
+ {item[colName]}
211
+ </CTableDataCell>
212
+ ) : null
213
+ })}
248
214
  </CTableRow>
249
215
  ))}
250
216
  </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
  /**