@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.
- package/README.md +1 -1
- package/dist/components/alert/CAlert.d.ts +1 -1
- package/dist/components/avatar/CAvatar.d.ts +1 -1
- package/dist/components/badge/CBadge.d.ts +1 -1
- package/dist/components/button/CButton.d.ts +1 -1
- package/dist/components/calendar/utils.d.ts +0 -1
- package/dist/components/callout/CCallout.d.ts +1 -1
- package/dist/components/card/CCard.d.ts +1 -1
- package/dist/components/conditional-portal/CConditionalPortal.d.ts +12 -0
- package/dist/components/conditional-portal/index.d.ts +2 -0
- package/dist/components/date-range-picker/CDateRangePicker.d.ts +1 -1
- package/dist/components/date-range-picker/utils.d.ts +1 -0
- package/dist/components/dropdown/CDropdown.d.ts +1 -1
- package/dist/components/dropdown/CDropdownToggle.d.ts +1 -1
- package/dist/components/form/CFormCheck.d.ts +8 -2
- package/dist/components/form/CFormSwitch.d.ts +6 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/list-group/CListGroupItem.d.ts +4 -5
- package/dist/components/multi-select/CMultiSelect.d.ts +1 -13
- package/dist/components/multi-select/CMultiSelectNativeSelect.d.ts +1 -1
- package/dist/components/multi-select/CMultiSelectOptions.d.ts +1 -1
- package/dist/components/multi-select/CMultiSelectSelection.d.ts +1 -1
- package/dist/components/multi-select/types.d.ts +14 -0
- package/dist/components/multi-select/utils.d.ts +6 -0
- package/dist/components/navbar/CNavbar.d.ts +1 -1
- package/dist/components/picker/CPicker.d.ts +1 -1
- package/dist/components/placeholder/CPlaceholder.d.ts +1 -1
- package/dist/components/popover/CPopover.d.ts +1 -1
- package/dist/components/progress/CProgressBar.d.ts +1 -1
- package/dist/components/smart-table/CSmartTableHead.d.ts +1 -1
- package/dist/components/smart-table/CSmartTableInterface.d.ts +8 -0
- package/dist/components/smart-table/types.d.ts +1 -1
- package/dist/components/spinner/CSpinner.d.ts +1 -1
- package/dist/components/table/CTable.d.ts +2 -18
- package/dist/components/table/CTableBody.d.ts +1 -1
- package/dist/components/table/CTableDataCell.d.ts +1 -1
- package/dist/components/table/CTableFoot.d.ts +1 -1
- package/dist/components/table/CTableHead.d.ts +1 -1
- package/dist/components/table/CTableHeaderCell.d.ts +1 -1
- package/dist/components/table/CTableResponsiveWrapper.d.ts +0 -1
- package/dist/components/table/CTableRow.d.ts +1 -1
- package/dist/components/table/types.d.ts +17 -0
- package/dist/components/table/utils.d.ts +5 -0
- package/dist/components/toast/CToast.d.ts +1 -1
- package/dist/components/toast/CToastClose.d.ts +1 -1
- package/dist/components/tooltip/CTooltip.d.ts +1 -1
- package/dist/components/virtual-scroller/CVirtualScroller.d.ts +0 -8
- package/dist/components/widgets/CWidgetStatsA.d.ts +1 -1
- package/dist/components/widgets/CWidgetStatsB.d.ts +1 -1
- package/dist/components/widgets/CWidgetStatsC.d.ts +1 -1
- package/dist/components/widgets/CWidgetStatsD.d.ts +1 -1
- package/dist/components/widgets/CWidgetStatsF.d.ts +1 -1
- package/dist/index.es.js +696 -927
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +695 -925
- package/dist/index.js.map +1 -1
- package/dist/props.d.ts +8 -0
- package/dist/types.d.ts +7 -0
- package/dist/utils/index.d.ts +1 -3
- package/package.json +11 -6
- package/src/components/accordion/CAccordion.tsx +7 -3
- package/src/components/accordion/CAccordionBody.tsx +2 -2
- package/src/components/accordion/CAccordionButton.tsx +1 -3
- package/src/components/accordion/CAccordionCollapse.tsx +1 -0
- package/src/components/accordion/CAccordionHeader.tsx +1 -3
- package/src/components/accordion/CAccordionItem.tsx +2 -4
- package/src/components/accordion/__tests__/__snapshots__/CAccordionBody.spec.tsx.snap +2 -2
- package/src/components/alert/CAlert.tsx +21 -28
- package/src/components/alert/CAlertHeading.tsx +1 -3
- package/src/components/alert/CAlertLink.tsx +1 -3
- package/src/components/alert/__tests__/__snapshots__/CAlert.spec.tsx.snap +1 -1
- package/src/components/avatar/CAvatar.tsx +16 -19
- package/src/components/backdrop/CBackdrop.tsx +10 -13
- package/src/components/badge/CBadge.tsx +21 -27
- package/src/components/breadcrumb/CBreadcrumb.tsx +1 -2
- package/src/components/breadcrumb/CBreadcrumbItem.tsx +12 -8
- package/src/components/button/CButton.tsx +10 -10
- package/src/components/button-group/CButtonGroup.tsx +9 -7
- package/src/components/button-group/CButtonToolbar.tsx +1 -3
- package/src/components/calendar/utils.ts +7 -55
- package/src/components/callout/CCallout.tsx +13 -10
- package/src/components/card/CCard.tsx +14 -11
- package/src/components/card/CCardBody.tsx +1 -3
- package/src/components/card/CCardFooter.tsx +1 -3
- package/src/components/card/CCardGroup.tsx +1 -3
- package/src/components/card/CCardHeader.tsx +1 -3
- package/src/components/card/CCardImage.tsx +5 -3
- package/src/components/card/CCardImageOverlay.tsx +1 -3
- package/src/components/card/CCardLink.tsx +1 -3
- package/src/components/card/CCardSubtitle.tsx +1 -3
- package/src/components/card/CCardText.tsx +1 -3
- package/src/components/card/CCardTitle.tsx +1 -3
- package/src/components/carousel/CCarousel.tsx +8 -8
- package/src/components/carousel/CCarouselCaption.tsx +1 -3
- package/src/components/carousel/CCarouselItem.tsx +11 -9
- package/src/components/close-button/CCloseButton.tsx +9 -10
- package/src/components/collapse/CCollapse.tsx +8 -20
- package/src/components/collapse/__tests__/CCollapse.spec.tsx +2 -3
- package/src/components/conditional-portal/CConditionalPortal.tsx +29 -0
- package/src/components/conditional-portal/index.ts +3 -0
- package/src/components/date-range-picker/CDateRangePicker.tsx +11 -13
- package/src/components/date-range-picker/utils.ts +49 -0
- package/src/components/dropdown/CDropdown.tsx +26 -23
- package/src/components/dropdown/CDropdownDivider.tsx +1 -3
- package/src/components/dropdown/CDropdownHeader.tsx +1 -3
- package/src/components/dropdown/CDropdownItem.tsx +7 -5
- package/src/components/dropdown/CDropdownItemPlain.tsx +1 -3
- package/src/components/dropdown/CDropdownMenu.tsx +29 -32
- package/src/components/dropdown/CDropdownToggle.tsx +34 -27
- package/src/components/dropdown/__tests__/CDropdown.spec.tsx +2 -4
- package/src/components/dropdown/__tests__/__snapshots__/CDropdown.spec.tsx.snap +1 -1
- package/src/components/footer/CFooter.tsx +5 -3
- package/src/components/form/CForm.tsx +5 -2
- package/src/components/form/CFormCheck.tsx +90 -66
- package/src/components/form/CFormControlValidation.tsx +0 -1
- package/src/components/form/CFormControlWrapper.tsx +3 -4
- package/src/components/form/CFormFeedback.tsx +11 -8
- package/src/components/form/CFormFloating.tsx +1 -2
- package/src/components/form/CFormInput.tsx +18 -16
- package/src/components/form/CFormLabel.tsx +1 -2
- package/src/components/form/CFormRange.tsx +2 -4
- package/src/components/form/CFormSelect.tsx +16 -12
- package/src/components/form/CFormSwitch.tsx +31 -20
- package/src/components/form/CFormText.tsx +1 -2
- package/src/components/form/CFormTextarea.tsx +14 -11
- package/src/components/form/CInputGroup.tsx +11 -8
- package/src/components/form/CInputGroupText.tsx +1 -2
- package/src/components/form/__tests__/CFormRange.spec.tsx +1 -1
- package/src/components/form/__tests__/__snapshots__/CForm.spec.tsx.snap +2 -6
- package/src/components/form/__tests__/__snapshots__/CFormRange.spec.tsx.snap +2 -2
- package/src/components/grid/CCol.tsx +8 -6
- package/src/components/grid/CContainer.tsx +8 -6
- package/src/components/grid/CRow.tsx +4 -3
- package/src/components/header/CHeader.tsx +12 -13
- package/src/components/header/CHeaderBrand.tsx +1 -3
- package/src/components/header/CHeaderBrand.tsx~HEAD +1 -3
- package/src/components/header/CHeaderDivider.tsx +1 -3
- package/src/components/header/CHeaderNav.tsx +6 -3
- package/src/components/header/CHeaderText.tsx +1 -3
- package/src/components/header/CHeaderToggler.tsx +2 -4
- package/src/components/image/CImage.tsx +17 -10
- package/src/components/image/__tests__/__snapshots__/CImage.spec.tsx.snap +1 -3
- package/src/components/index.ts +1 -0
- package/src/components/link/CLink.tsx +2 -4
- package/src/components/list-group/CListGroup.tsx +11 -10
- package/src/components/list-group/CListGroupItem.tsx +21 -20
- package/src/components/list-group/CListGroupItem.tsx~HEAD +3 -1
- package/src/components/loading-button/CLoadingButton.tsx +1 -3
- package/src/components/modal/CModal.tsx +57 -72
- package/src/components/modal/CModalBody.tsx +1 -3
- package/src/components/modal/CModalContent.tsx +1 -3
- package/src/components/modal/CModalDialog.tsx +16 -14
- package/src/components/modal/CModalFooter.tsx +1 -3
- package/src/components/modal/CModalHeader.tsx +4 -4
- package/src/components/modal/CModalTitle.tsx +1 -3
- package/src/components/modal/__tests__/CModal.spec.tsx +19 -20
- package/src/components/multi-select/CMultiSelect.tsx +34 -93
- package/src/components/multi-select/CMultiSelectNativeSelect.tsx +1 -1
- package/src/components/multi-select/CMultiSelectOptions.tsx +2 -2
- package/src/components/multi-select/CMultiSelectSelection.tsx +1 -1
- package/src/components/multi-select/types.ts +15 -0
- package/src/components/multi-select/utils.ts +92 -0
- package/src/components/nav/CNav.tsx +13 -10
- package/src/components/nav/CNavGroup.tsx +1 -3
- package/src/components/nav/CNavGroupItems.tsx +1 -2
- package/src/components/nav/CNavItem.tsx +9 -10
- package/src/components/nav/CNavLink.tsx +4 -5
- package/src/components/nav/CNavTitle.tsx +1 -2
- package/src/components/navbar/CNavbar.tsx +23 -23
- package/src/components/navbar/CNavbarBrand.tsx +2 -3
- package/src/components/navbar/CNavbarNav.tsx +6 -3
- package/src/components/navbar/CNavbarText.tsx +1 -3
- package/src/components/navbar/CNavbarToggler.tsx +2 -4
- package/src/components/offcanvas/COffcanvas.tsx +42 -68
- package/src/components/offcanvas/COffcanvasBody.tsx +1 -3
- package/src/components/offcanvas/COffcanvasHeader.tsx +1 -3
- package/src/components/offcanvas/COffcanvasTitle.tsx +1 -3
- package/src/components/offcanvas/__tests__/COffcanvas.spec.tsx +7 -2
- package/src/components/offcanvas/__tests__/__snapshots__/COffcanvas.spec.tsx.snap +9 -4
- package/src/components/pagination/CPagination.tsx +12 -9
- package/src/components/pagination/CPaginationItem.tsx +12 -11
- package/src/components/pagination/__tests__/CPagination.spec.tsx +3 -3
- package/src/components/pagination/__tests__/CPaginationItem.spec.tsx +3 -3
- package/src/components/picker/CPicker.tsx +7 -7
- package/src/components/placeholder/CPlaceholder.tsx +15 -12
- package/src/components/popover/CPopover.tsx +24 -34
- package/src/components/progress/CProgress.tsx +13 -10
- package/src/components/progress/CProgressBar.tsx +11 -12
- package/src/components/sidebar/CSidebar.tsx +22 -19
- package/src/components/sidebar/CSidebarBrand.tsx +1 -2
- package/src/components/sidebar/CSidebarFooter.tsx +1 -2
- package/src/components/sidebar/CSidebarHeader.tsx +1 -2
- package/src/components/sidebar/CSidebarNav.tsx +2 -2
- package/src/components/sidebar/CSidebarToggler.tsx +1 -2
- package/src/components/smart-pagination/CSmartPagination.tsx +22 -20
- package/src/components/smart-table/CSmartTable.tsx +5 -9
- package/src/components/smart-table/CSmartTableBody.tsx +82 -81
- package/src/components/smart-table/CSmartTableHead.tsx +5 -2
- package/src/components/smart-table/CSmartTableInterface.tsx +8 -0
- package/src/components/smart-table/{utils.tsx → utils.ts} +4 -5
- package/src/components/spinner/CSpinner.tsx +13 -9
- package/src/components/table/CTable.tsx +45 -77
- package/src/components/table/CTableBody.tsx +14 -9
- package/src/components/table/CTableDataCell.tsx +16 -11
- package/src/components/table/CTableFoot.tsx +14 -9
- package/src/components/table/CTableHead.tsx +14 -9
- package/src/components/table/CTableHeaderCell.tsx +14 -9
- package/src/components/table/CTableResponsiveWrapper.tsx +2 -3
- package/src/components/table/CTableRow.tsx +16 -11
- package/src/components/table/__tests__/__snapshots__/CTable.spec.tsx.snap +1 -5
- package/src/components/table/types.ts +20 -0
- package/src/components/table/utils.ts +24 -0
- package/src/components/tabs/CTabContent.tsx +1 -2
- package/src/components/tabs/CTabPane.tsx +18 -20
- package/src/components/tabs/__tests__/CTabPane.spec.tsx +2 -5
- package/src/components/tabs/__tests__/__snapshots__/CTabPane.spec.tsx.snap +1 -1
- package/src/components/time-picker/CTimePicker.tsx +14 -18
- package/src/components/toast/CToast.tsx +32 -45
- package/src/components/toast/CToastBody.tsx +1 -2
- package/src/components/toast/CToastClose.tsx +4 -2
- package/src/components/toast/CToastHeader.tsx +1 -2
- package/src/components/toast/CToaster.tsx +27 -26
- package/src/components/toast/__tests__/CToast.spec.tsx +2 -1
- package/src/components/toast/__tests__/__snapshots__/CToast.spec.tsx.snap +1 -66
- package/src/components/tooltip/CTooltip.tsx +24 -34
- package/src/components/virtual-scroller/CVirtualScroller.tsx +35 -60
- package/src/components/widgets/CWidgetStatsA.tsx +11 -9
- package/src/components/widgets/CWidgetStatsB.tsx +4 -4
- package/src/components/widgets/CWidgetStatsC.tsx +4 -4
- package/src/components/widgets/CWidgetStatsD.tsx +13 -15
- package/src/components/widgets/CWidgetStatsE.tsx +2 -5
- package/src/components/widgets/CWidgetStatsF.tsx +4 -8
- package/src/{components/Types.tsx → props.ts} +1 -68
- package/src/types.ts +68 -0
- package/src/utils/index.ts +1 -3
- package/src/components/multi-select/CMultiSelectCleaner.tsx +0 -18
- package/src/utils/getNextSibling.ts +0 -18
- package/src/utils/getPreviousSibling.ts +0 -18
- 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
|
-
|
|
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' && (
|
|
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' && (
|
|
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 {
|
|
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
|
|
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
|
|
6
|
+
import { CTableHeaderCell } from './CTableHeaderCell'
|
|
8
7
|
import { CTableBody } from './CTableBody'
|
|
9
|
-
import { CTableDataCell
|
|
10
|
-
import { 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
|
|
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
|
|
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
|
-
{
|
|
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
|
-
{
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
...(item._cellProps
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
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 {
|
|
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
|
|
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 {
|
|
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
|
|
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 {
|
|
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
|
|
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 {
|
|
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
|
|
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 {
|
|
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
|
|
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.
|
|
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 {
|
|
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
|
|
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={
|
|
15
|
+
<div className={classNames('tab-content', className)} {...rest} ref={ref}>
|
|
17
16
|
{children}
|
|
18
17
|
</div>
|
|
19
18
|
)
|