@coreui/react-pro 4.0.2 → 4.1.3
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/accordion/CAccordionCollapse.d.ts +1 -1
- package/dist/components/collapse/CCollapse.d.ts +4 -0
- package/dist/components/modal/CModal.d.ts +1 -0
- package/dist/components/placeholder/CPlaceholder.d.ts +51 -0
- package/dist/components/popover/CPopover.d.ts +2 -2
- package/dist/components/smart-table/CSmartTableBody.d.ts +3 -3
- package/dist/components/smart-table/CSmartTableInterface.d.ts +9 -6
- package/dist/components/tooltip/CTooltip.d.ts +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.es.js +353 -219
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +353 -218
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
- package/src/components/accordion/CAccordionCollapse.tsx +1 -1
- package/src/components/collapse/CCollapse.tsx +36 -3
- package/src/components/grid/CCol.tsx +8 -8
- package/src/components/grid/CContainer.tsx +3 -3
- package/src/components/grid/CRow.tsx +6 -6
- package/src/components/modal/CModal.tsx +42 -19
- package/src/components/modal/__tests__/CModal.spec.tsx +1 -1
- package/src/components/modal/__tests__/__snapshots__/CModal.spec.tsx.snap +2 -10
- package/src/components/offcanvas/COffcanvas.tsx +15 -2
- package/src/components/offcanvas/__tests__/COffcanvas.spec.tsx +1 -1
- package/src/components/offcanvas/__tests__/__snapshots__/COffcanvas.spec.tsx.snap +2 -2
- package/src/components/placeholder/CPlaceholder.tsx +114 -0
- package/src/components/placeholder/__tests__/CPlaceholder.spec.tsx +21 -0
- package/src/components/placeholder/__tests__/__snapshots__/CPlaceholder.spec.tsx.snap +17 -0
- package/src/components/popover/CPopover.tsx +4 -4
- package/src/components/smart-table/CSmartTable.tsx +15 -9
- package/src/components/smart-table/CSmartTableBody.tsx +9 -4
- package/src/components/smart-table/CSmartTableHead.tsx +1 -1
- package/src/components/smart-table/CSmartTableInterface.tsx +10 -6
- package/src/components/tooltip/CTooltip.tsx +2 -2
- package/src/index.ts +2 -0
- package/src/utils/hooks/useForkedRef.ts +5 -0
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import React, { ChangeEvent, forwardRef, useEffect, useMemo, useRef, useState } from 'react'
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
ColumnFilterValue,
|
|
6
|
+
CSmartTableProps,
|
|
7
|
+
Item,
|
|
8
|
+
ItemInternal,
|
|
9
|
+
SorterValue,
|
|
10
|
+
} from './CSmartTableInterface'
|
|
5
11
|
|
|
6
12
|
import { CSmartPagination } from '../pagination/CSmartPagination'
|
|
7
13
|
import { CElementCover } from '../element-cover/CElementCover'
|
|
@@ -98,7 +104,7 @@ export const CSmartTable = forwardRef<HTMLDivElement, CSmartTableProps>(
|
|
|
98
104
|
const previousItemsValue = useRef<Item[]>()
|
|
99
105
|
|
|
100
106
|
const [_activePage, setActivePage] = useState<number>(activePage)
|
|
101
|
-
const [_items, setItems] = useState<
|
|
107
|
+
const [_items, setItems] = useState<ItemInternal[]>([])
|
|
102
108
|
const [_itemsPerPage, setItemsPerPage] = useState(itemsPerPage)
|
|
103
109
|
const [columnFilterState, setColumnFilterState] = useState<ColumnFilterValue>(
|
|
104
110
|
columnFilterValue ? columnFilterValue : {},
|
|
@@ -229,7 +235,7 @@ export const CSmartTable = forwardRef<HTMLDivElement, CSmartTableProps>(
|
|
|
229
235
|
compData.changeItems,
|
|
230
236
|
])
|
|
231
237
|
|
|
232
|
-
const columnFiltered:
|
|
238
|
+
const columnFiltered: ItemInternal[] = useMemo(() => {
|
|
233
239
|
let items = _items
|
|
234
240
|
if (columnFilter && typeof columnFilter === 'object' && columnFilter.external) {
|
|
235
241
|
return items
|
|
@@ -245,7 +251,7 @@ export const CSmartTable = forwardRef<HTMLDivElement, CSmartTableProps>(
|
|
|
245
251
|
return items
|
|
246
252
|
}, [compData.columnFiltered, _items])
|
|
247
253
|
|
|
248
|
-
const tableFiltered:
|
|
254
|
+
const tableFiltered: ItemInternal[] = useMemo(() => {
|
|
249
255
|
let items = columnFiltered
|
|
250
256
|
if (
|
|
251
257
|
!tableFilterState ||
|
|
@@ -266,7 +272,7 @@ export const CSmartTable = forwardRef<HTMLDivElement, CSmartTableProps>(
|
|
|
266
272
|
JSON.stringify(columnFiltered),
|
|
267
273
|
])
|
|
268
274
|
|
|
269
|
-
const sortedItems:
|
|
275
|
+
const sortedItems: ItemInternal[] = useMemo(() => {
|
|
270
276
|
const col = sorterState?.column
|
|
271
277
|
if (
|
|
272
278
|
!col ||
|
|
@@ -292,12 +298,12 @@ export const CSmartTable = forwardRef<HTMLDivElement, CSmartTableProps>(
|
|
|
292
298
|
|
|
293
299
|
const firstItemOnActivePageIndex: number = _activePage ? (_activePage - 1) * _itemsPerPage : 0
|
|
294
300
|
|
|
295
|
-
const itemsOnActivePage:
|
|
301
|
+
const itemsOnActivePage: ItemInternal[] = sortedItems.slice(
|
|
296
302
|
firstItemOnActivePageIndex,
|
|
297
303
|
firstItemOnActivePageIndex + _itemsPerPage,
|
|
298
304
|
)
|
|
299
305
|
|
|
300
|
-
const currentItems:
|
|
306
|
+
const currentItems: ItemInternal[] = _activePage ? itemsOnActivePage : sortedItems
|
|
301
307
|
|
|
302
308
|
const isFiltered: string =
|
|
303
309
|
tableFilterState || sorterState?.column || Object.values(columnFilterState).join('')
|
|
@@ -350,7 +356,7 @@ export const CSmartTable = forwardRef<HTMLDivElement, CSmartTableProps>(
|
|
|
350
356
|
const handleSelectAllChecked = () => {
|
|
351
357
|
if (selectedAll === true) {
|
|
352
358
|
setItems(
|
|
353
|
-
_items.map((item:
|
|
359
|
+
_items.map((item: ItemInternal) => {
|
|
354
360
|
return { ...item, _selected: false }
|
|
355
361
|
}),
|
|
356
362
|
)
|
|
@@ -358,7 +364,7 @@ export const CSmartTable = forwardRef<HTMLDivElement, CSmartTableProps>(
|
|
|
358
364
|
}
|
|
359
365
|
|
|
360
366
|
setItems(
|
|
361
|
-
_items.map((item:
|
|
367
|
+
_items.map((item: ItemInternal) => {
|
|
362
368
|
return { ...item, _selected: true }
|
|
363
369
|
}),
|
|
364
370
|
)
|
|
@@ -7,15 +7,20 @@ import { CTableDataCell } from '../table/CTableDataCell'
|
|
|
7
7
|
|
|
8
8
|
import { CFormCheck } from '../form/CFormCheck'
|
|
9
9
|
|
|
10
|
-
import { Item, ScopedColumns } from './CSmartTableInterface'
|
|
10
|
+
import { Item, ItemInternal, ScopedColumns } from './CSmartTableInterface'
|
|
11
11
|
|
|
12
12
|
export interface CSmartTableBodyProps extends CTableBodyProps {
|
|
13
13
|
clickableRows?: boolean
|
|
14
|
-
currentItems:
|
|
14
|
+
currentItems: ItemInternal[]
|
|
15
15
|
firstItemOnActivePageIndex: number
|
|
16
16
|
noItemsLabel?: string | ReactNode
|
|
17
17
|
onRowChecked?: (id: number, value: boolean) => void
|
|
18
|
-
onRowClick?: (
|
|
18
|
+
onRowClick?: (
|
|
19
|
+
item: ItemInternal,
|
|
20
|
+
index: number,
|
|
21
|
+
columnName: string,
|
|
22
|
+
event: MouseEvent | boolean,
|
|
23
|
+
) => void
|
|
19
24
|
rawColumnNames: string[]
|
|
20
25
|
scopedColumns?: ScopedColumns
|
|
21
26
|
selectable?: boolean
|
|
@@ -64,7 +69,7 @@ export const CSmartTableBody = forwardRef<HTMLTableSectionElement, CSmartTableBo
|
|
|
64
69
|
{...rest}
|
|
65
70
|
ref={ref}
|
|
66
71
|
>
|
|
67
|
-
{currentItems.map((item:
|
|
72
|
+
{currentItems.map((item: ItemInternal, trIndex) => {
|
|
68
73
|
return (
|
|
69
74
|
<React.Fragment key={trIndex}>
|
|
70
75
|
<CTableRow
|
|
@@ -205,7 +205,7 @@ export const CSmartTableHead = forwardRef<HTMLTableSectionElement, CSmartTableHe
|
|
|
205
205
|
CSmartTableHead.propTypes = {
|
|
206
206
|
columnFilter: PropTypes.oneOfType([PropTypes.bool, PropTypes.object]),
|
|
207
207
|
columnFilterState: PropTypes.object,
|
|
208
|
-
columnSorter: PropTypes.bool,
|
|
208
|
+
columnSorter: PropTypes.oneOfType([PropTypes.bool, PropTypes.object]),
|
|
209
209
|
component: PropTypes.elementType,
|
|
210
210
|
children: PropTypes.node,
|
|
211
211
|
columns: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.any, PropTypes.string])).isRequired, // TODO: improve this Prop Type,
|
|
@@ -8,10 +8,10 @@ import { CTableRowProps } from '../table/CTableRow'
|
|
|
8
8
|
import { CTableHeadProps } from '../table/CTableHead'
|
|
9
9
|
|
|
10
10
|
export interface Column {
|
|
11
|
-
sorter?: boolean
|
|
12
|
-
key: string
|
|
13
|
-
label?: string
|
|
14
11
|
filter?: boolean
|
|
12
|
+
label?: string
|
|
13
|
+
key: string
|
|
14
|
+
sorter?: boolean
|
|
15
15
|
_style?: any
|
|
16
16
|
_props?: CTableHeaderCellProps
|
|
17
17
|
}
|
|
@@ -27,9 +27,12 @@ export interface ColumnFilterValue {
|
|
|
27
27
|
|
|
28
28
|
export interface Item {
|
|
29
29
|
[key: string]: number | string | any
|
|
30
|
+
_props?: CTableRowProps
|
|
31
|
+
_selected?: boolean
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface ItemInternal extends Item {
|
|
30
35
|
_id: number
|
|
31
|
-
_props: CTableRowProps
|
|
32
|
-
_selected: boolean
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
export interface ItemsPerPageSelect {
|
|
@@ -44,6 +47,7 @@ export interface Sorter {
|
|
|
44
47
|
}
|
|
45
48
|
|
|
46
49
|
export interface ScopedColumns {
|
|
50
|
+
[key: string]: any
|
|
47
51
|
details?: (a: Item, b: number) => ReactNode
|
|
48
52
|
}
|
|
49
53
|
|
|
@@ -115,7 +119,7 @@ export interface CSmartTableProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
115
119
|
* - sorter (Boolean) - disables sorting of the column when set to false
|
|
116
120
|
* - filter (Boolean) - removes filter from column when set to false.
|
|
117
121
|
*/
|
|
118
|
-
columns?:
|
|
122
|
+
columns?: (string | Column)[]
|
|
119
123
|
/**
|
|
120
124
|
* Enables table sorting by column value. Sorting will be performed corectly only if values in column are of one type: string (case insensitive) or number.
|
|
121
125
|
*
|
|
@@ -13,7 +13,7 @@ export interface CTooltipProps {
|
|
|
13
13
|
/**
|
|
14
14
|
* Content node for your component.
|
|
15
15
|
*/
|
|
16
|
-
content: ReactNode
|
|
16
|
+
content: ReactNode | string
|
|
17
17
|
/**
|
|
18
18
|
* Callback fired when the component requests to be hidden.
|
|
19
19
|
*/
|
|
@@ -126,7 +126,7 @@ export const CTooltip: FC<CTooltipProps> = ({
|
|
|
126
126
|
|
|
127
127
|
CTooltip.propTypes = {
|
|
128
128
|
children: PropTypes.any,
|
|
129
|
-
content: PropTypes.node,
|
|
129
|
+
content: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
|
|
130
130
|
placement: PropTypes.oneOf(['auto', 'top', 'right', 'bottom', 'left']),
|
|
131
131
|
onHide: PropTypes.func,
|
|
132
132
|
onShow: PropTypes.func,
|
package/src/index.ts
CHANGED
|
@@ -89,6 +89,7 @@ import { CNavbarToggler } from './components/navbar/CNavbarToggler'
|
|
|
89
89
|
import { CPagination } from './components/pagination/CPagination'
|
|
90
90
|
import { CPaginationItem } from './components/pagination/CPaginationItem'
|
|
91
91
|
import { CSmartPagination } from './components/pagination/CSmartPagination'
|
|
92
|
+
import { CPlaceholder } from './components/placeholder/CPlaceholder'
|
|
92
93
|
import { CPopover } from './components/popover/CPopover'
|
|
93
94
|
import { CProgress } from './components/progress/CProgress'
|
|
94
95
|
import { CProgressBar } from './components/progress/CProgressBar'
|
|
@@ -212,6 +213,7 @@ export {
|
|
|
212
213
|
CNavbarToggler,
|
|
213
214
|
CPagination,
|
|
214
215
|
CPaginationItem,
|
|
216
|
+
CPlaceholder,
|
|
215
217
|
CPopover,
|
|
216
218
|
CProgress,
|
|
217
219
|
CProgressBar,
|
|
@@ -9,6 +9,7 @@ export type AssignableRef<ValueType> =
|
|
|
9
9
|
}['bivarianceHack']
|
|
10
10
|
| React.MutableRefObject<ValueType | null>
|
|
11
11
|
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
13
|
export function useForkedRef<RefValueType = any>(
|
|
13
14
|
...refs: (AssignableRef<RefValueType> | null | undefined)[]
|
|
14
15
|
) {
|
|
@@ -16,6 +17,7 @@ export function useForkedRef<RefValueType = any>(
|
|
|
16
17
|
if (refs.every((ref) => ref == null)) {
|
|
17
18
|
return null
|
|
18
19
|
}
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
21
|
return (node: any) => {
|
|
20
22
|
refs.forEach((ref) => {
|
|
21
23
|
assignRef(ref, node)
|
|
@@ -24,8 +26,10 @@ export function useForkedRef<RefValueType = any>(
|
|
|
24
26
|
}, refs)
|
|
25
27
|
}
|
|
26
28
|
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
27
30
|
export function assignRef<RefValueType = any>(
|
|
28
31
|
ref: AssignableRef<RefValueType> | null | undefined,
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
33
|
value: any,
|
|
30
34
|
) {
|
|
31
35
|
if (ref == null) return
|
|
@@ -40,6 +44,7 @@ export function assignRef<RefValueType = any>(
|
|
|
40
44
|
}
|
|
41
45
|
}
|
|
42
46
|
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
|
|
43
48
|
export function isFunction(value: any): value is Function {
|
|
44
49
|
return !!(value && {}.toString.call(value) == '[object Function]')
|
|
45
50
|
}
|