@coreui/react-pro 4.1.0 → 4.1.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.
- package/README.md +1 -1
- 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.es.js +52 -23
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +52 -23
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- 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/utils/hooks/useForkedRef.ts +5 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coreui/react-pro",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.1",
|
|
4
4
|
"description": "UI Components Library for React.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -37,22 +37,22 @@
|
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@popperjs/core": "^2.11.0",
|
|
39
39
|
"@rollup/plugin-commonjs": "^21.0.1",
|
|
40
|
-
"@rollup/plugin-node-resolve": "^13.
|
|
40
|
+
"@rollup/plugin-node-resolve": "^13.1.1",
|
|
41
41
|
"@rollup/plugin-typescript": "^8.3.0",
|
|
42
|
-
"@testing-library/jest-dom": "^5.
|
|
42
|
+
"@testing-library/jest-dom": "^5.16.1",
|
|
43
43
|
"@testing-library/react": "^12.1.2",
|
|
44
|
-
"@types/react": "^17.0.
|
|
44
|
+
"@types/react": "^17.0.38",
|
|
45
45
|
"@types/react-dom": "^17.0.11",
|
|
46
46
|
"@types/react-transition-group": "^4.4.4",
|
|
47
47
|
"classnames": "^2.3.1",
|
|
48
|
-
"prop-types": "^15.
|
|
48
|
+
"prop-types": "^15.8.0",
|
|
49
49
|
"react": "^17.0.2",
|
|
50
50
|
"react-dom": "^17.0.2",
|
|
51
51
|
"react-popper": "^2.2.5",
|
|
52
52
|
"react-transition-group": "^4.4.2",
|
|
53
|
-
"rollup": "^2.
|
|
53
|
+
"rollup": "^2.62.0",
|
|
54
54
|
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
55
|
-
"typescript": "^4.5.
|
|
55
|
+
"typescript": "^4.5.4"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"react": "^17",
|
|
@@ -13,7 +13,7 @@ export interface CPopoverProps {
|
|
|
13
13
|
/**
|
|
14
14
|
* Content node for your component.
|
|
15
15
|
*/
|
|
16
|
-
content: ReactNode
|
|
16
|
+
content: ReactNode | string
|
|
17
17
|
/**
|
|
18
18
|
* Offset of the popover relative to its target.
|
|
19
19
|
*/
|
|
@@ -29,7 +29,7 @@ export interface CPopoverProps {
|
|
|
29
29
|
/**
|
|
30
30
|
* Title node for your component.
|
|
31
31
|
*/
|
|
32
|
-
title?: ReactNode
|
|
32
|
+
title?: ReactNode | string
|
|
33
33
|
/**
|
|
34
34
|
* Sets which event handlers you’d like provided to your toggle prop. You can specify one trigger or an array of them.
|
|
35
35
|
*
|
|
@@ -147,12 +147,12 @@ export const CPopover: FC<CPopoverProps> = ({
|
|
|
147
147
|
|
|
148
148
|
CPopover.propTypes = {
|
|
149
149
|
children: PropTypes.any,
|
|
150
|
-
content: PropTypes.node,
|
|
150
|
+
content: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
|
|
151
151
|
placement: PropTypes.oneOf(['auto', 'top', 'right', 'bottom', 'left']),
|
|
152
152
|
offset: PropTypes.any, // TODO: find good proptype
|
|
153
153
|
onHide: PropTypes.func,
|
|
154
154
|
onShow: PropTypes.func,
|
|
155
|
-
title: PropTypes.string,
|
|
155
|
+
title: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
|
|
156
156
|
trigger: triggerPropType,
|
|
157
157
|
visible: PropTypes.bool,
|
|
158
158
|
}
|
|
@@ -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,
|
|
@@ -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
|
}
|