@coreui/react-pro 4.0.1 → 4.1.2
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 +157 -0
- package/dist/components/accordion/CAccordionCollapse.d.ts +1 -1
- package/dist/components/collapse/CCollapse.d.ts +4 -0
- package/dist/components/form/CFormLabel.d.ts +2 -2
- 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/CSmartTableHead.d.ts +2 -1
- 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 +341 -211
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +341 -210
- 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/form/CFormLabel.tsx +2 -2
- package/src/components/form/__tests__/CFormLabel.spec.tsx +8 -0
- package/src/components/form/__tests__/__snapshots__/CFormLabel.spec.tsx.snap +11 -0
- 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/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 +25 -12
- package/src/components/smart-table/CSmartTableBody.tsx +9 -4
- package/src/components/smart-table/CSmartTableHead.tsx +16 -3
- 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 : {},
|
|
@@ -112,6 +118,7 @@ export const CSmartTable = forwardRef<HTMLDivElement, CSmartTableProps>(
|
|
|
112
118
|
useMemo(() => {
|
|
113
119
|
if (JSON.stringify(previousSorterValue.current) !== JSON.stringify(sorterValue)) {
|
|
114
120
|
previousSorterValue.current = sorterValue
|
|
121
|
+
setSorterState({ ...sorterValue })
|
|
115
122
|
}
|
|
116
123
|
}, [sorterValue])
|
|
117
124
|
|
|
@@ -160,7 +167,11 @@ export const CSmartTable = forwardRef<HTMLDivElement, CSmartTableProps>(
|
|
|
160
167
|
} else if (state.state === 'asc') {
|
|
161
168
|
state.state = 'desc'
|
|
162
169
|
} else {
|
|
163
|
-
|
|
170
|
+
if (typeof columnSorter === 'object' && !columnSorter.resetable) {
|
|
171
|
+
state.state = 'asc'
|
|
172
|
+
} else {
|
|
173
|
+
state.state = 0
|
|
174
|
+
}
|
|
164
175
|
}
|
|
165
176
|
} else {
|
|
166
177
|
state.column = column
|
|
@@ -183,6 +194,7 @@ export const CSmartTable = forwardRef<HTMLDivElement, CSmartTableProps>(
|
|
|
183
194
|
return
|
|
184
195
|
}
|
|
185
196
|
const newState = { ...columnFilterState, [`${colName}`]: value }
|
|
197
|
+
setActivePage(1)
|
|
186
198
|
setColumnFilterState(newState)
|
|
187
199
|
}
|
|
188
200
|
|
|
@@ -191,6 +203,7 @@ export const CSmartTable = forwardRef<HTMLDivElement, CSmartTableProps>(
|
|
|
191
203
|
if ((isLazy && type === 'input') || (!isLazy && type === 'change')) {
|
|
192
204
|
return
|
|
193
205
|
}
|
|
206
|
+
setActivePage(1)
|
|
194
207
|
setTableFilterState(value)
|
|
195
208
|
}
|
|
196
209
|
|
|
@@ -222,7 +235,7 @@ export const CSmartTable = forwardRef<HTMLDivElement, CSmartTableProps>(
|
|
|
222
235
|
compData.changeItems,
|
|
223
236
|
])
|
|
224
237
|
|
|
225
|
-
const columnFiltered:
|
|
238
|
+
const columnFiltered: ItemInternal[] = useMemo(() => {
|
|
226
239
|
let items = _items
|
|
227
240
|
if (columnFilter && typeof columnFilter === 'object' && columnFilter.external) {
|
|
228
241
|
return items
|
|
@@ -238,7 +251,7 @@ export const CSmartTable = forwardRef<HTMLDivElement, CSmartTableProps>(
|
|
|
238
251
|
return items
|
|
239
252
|
}, [compData.columnFiltered, _items])
|
|
240
253
|
|
|
241
|
-
const tableFiltered:
|
|
254
|
+
const tableFiltered: ItemInternal[] = useMemo(() => {
|
|
242
255
|
let items = columnFiltered
|
|
243
256
|
if (
|
|
244
257
|
!tableFilterState ||
|
|
@@ -259,7 +272,7 @@ export const CSmartTable = forwardRef<HTMLDivElement, CSmartTableProps>(
|
|
|
259
272
|
JSON.stringify(columnFiltered),
|
|
260
273
|
])
|
|
261
274
|
|
|
262
|
-
const sortedItems:
|
|
275
|
+
const sortedItems: ItemInternal[] = useMemo(() => {
|
|
263
276
|
const col = sorterState?.column
|
|
264
277
|
if (
|
|
265
278
|
!col ||
|
|
@@ -285,12 +298,12 @@ export const CSmartTable = forwardRef<HTMLDivElement, CSmartTableProps>(
|
|
|
285
298
|
|
|
286
299
|
const firstItemOnActivePageIndex: number = _activePage ? (_activePage - 1) * _itemsPerPage : 0
|
|
287
300
|
|
|
288
|
-
const itemsOnActivePage:
|
|
301
|
+
const itemsOnActivePage: ItemInternal[] = sortedItems.slice(
|
|
289
302
|
firstItemOnActivePageIndex,
|
|
290
303
|
firstItemOnActivePageIndex + _itemsPerPage,
|
|
291
304
|
)
|
|
292
305
|
|
|
293
|
-
const currentItems:
|
|
306
|
+
const currentItems: ItemInternal[] = _activePage ? itemsOnActivePage : sortedItems
|
|
294
307
|
|
|
295
308
|
const isFiltered: string =
|
|
296
309
|
tableFilterState || sorterState?.column || Object.values(columnFilterState).join('')
|
|
@@ -343,7 +356,7 @@ export const CSmartTable = forwardRef<HTMLDivElement, CSmartTableProps>(
|
|
|
343
356
|
const handleSelectAllChecked = () => {
|
|
344
357
|
if (selectedAll === true) {
|
|
345
358
|
setItems(
|
|
346
|
-
_items.map((item:
|
|
359
|
+
_items.map((item: ItemInternal) => {
|
|
347
360
|
return { ...item, _selected: false }
|
|
348
361
|
}),
|
|
349
362
|
)
|
|
@@ -351,7 +364,7 @@ export const CSmartTable = forwardRef<HTMLDivElement, CSmartTableProps>(
|
|
|
351
364
|
}
|
|
352
365
|
|
|
353
366
|
setItems(
|
|
354
|
-
_items.map((item:
|
|
367
|
+
_items.map((item: ItemInternal) => {
|
|
355
368
|
return { ...item, _selected: true }
|
|
356
369
|
}),
|
|
357
370
|
)
|
|
@@ -360,6 +373,7 @@ export const CSmartTable = forwardRef<HTMLDivElement, CSmartTableProps>(
|
|
|
360
373
|
useEffect(() => {
|
|
361
374
|
if (selectable) {
|
|
362
375
|
const selected = _items.filter((item) => item._selected === true)
|
|
376
|
+
onSelectedItemsChange && onSelectedItemsChange(selected)
|
|
363
377
|
|
|
364
378
|
if (selected.length === _items.length) {
|
|
365
379
|
setSelectedAll(true)
|
|
@@ -374,8 +388,6 @@ export const CSmartTable = forwardRef<HTMLDivElement, CSmartTableProps>(
|
|
|
374
388
|
if (selected.length !== 0 && selected.length !== _items.length) {
|
|
375
389
|
setSelectedAll('indeterminate')
|
|
376
390
|
}
|
|
377
|
-
|
|
378
|
-
onSelectedItemsChange && onSelectedItemsChange(selected)
|
|
379
391
|
}
|
|
380
392
|
}, [_items])
|
|
381
393
|
|
|
@@ -423,6 +435,7 @@ export const CSmartTable = forwardRef<HTMLDivElement, CSmartTableProps>(
|
|
|
423
435
|
<CSmartTableHead
|
|
424
436
|
{...tableHeadProps}
|
|
425
437
|
columnFilter={columnFilter}
|
|
438
|
+
columnFilterState={columnFilterState}
|
|
426
439
|
columns={columns ? columns : rawColumnNames}
|
|
427
440
|
columnSorter={columnSorter}
|
|
428
441
|
selectable={selectable}
|
|
@@ -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
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import React, { ElementType, forwardRef, ReactNode, useEffect, useRef } from 'react'
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
ColumnFilter,
|
|
6
|
+
ColumnFilterValue,
|
|
7
|
+
Column,
|
|
8
|
+
Sorter,
|
|
9
|
+
SorterValue,
|
|
10
|
+
} from './CSmartTableInterface'
|
|
5
11
|
|
|
6
12
|
import { CFormInput } from '../form/CFormInput'
|
|
7
13
|
import { CFormCheck } from '../form/CFormCheck'
|
|
@@ -10,6 +16,7 @@ import { CTableHeaderCell } from '../table/CTableHeaderCell'
|
|
|
10
16
|
import { CTableRow } from '../table/CTableRow'
|
|
11
17
|
export interface CSmartTableHeadProps extends CTableHeadProps {
|
|
12
18
|
columnFilter?: boolean | ColumnFilter
|
|
19
|
+
columnFilterState?: ColumnFilterValue
|
|
13
20
|
columnSorter?: boolean | Sorter
|
|
14
21
|
component?: string | ElementType
|
|
15
22
|
columns: (Column | string)[]
|
|
@@ -29,6 +36,7 @@ export const CSmartTableHead = forwardRef<HTMLTableSectionElement, CSmartTableHe
|
|
|
29
36
|
(
|
|
30
37
|
{
|
|
31
38
|
columnFilter,
|
|
39
|
+
columnFilterState,
|
|
32
40
|
columnSorter,
|
|
33
41
|
component: Component = CTableHead,
|
|
34
42
|
columns,
|
|
@@ -176,7 +184,11 @@ export const CSmartTableHead = forwardRef<HTMLTableSectionElement, CSmartTableHe
|
|
|
176
184
|
handleFilterOnChange &&
|
|
177
185
|
handleFilterOnChange(key(column), (event.target as HTMLInputElement).value)
|
|
178
186
|
}
|
|
179
|
-
|
|
187
|
+
value={
|
|
188
|
+
columnFilterState && columnFilterState[key(column)]
|
|
189
|
+
? columnFilterState[key(column)]
|
|
190
|
+
: ''
|
|
191
|
+
}
|
|
180
192
|
aria-label={`column name: '${label(column)}' filter input`}
|
|
181
193
|
/>
|
|
182
194
|
)}
|
|
@@ -192,7 +204,8 @@ export const CSmartTableHead = forwardRef<HTMLTableSectionElement, CSmartTableHe
|
|
|
192
204
|
|
|
193
205
|
CSmartTableHead.propTypes = {
|
|
194
206
|
columnFilter: PropTypes.oneOfType([PropTypes.bool, PropTypes.object]),
|
|
195
|
-
|
|
207
|
+
columnFilterState: PropTypes.object,
|
|
208
|
+
columnSorter: PropTypes.oneOfType([PropTypes.bool, PropTypes.object]),
|
|
196
209
|
component: PropTypes.elementType,
|
|
197
210
|
children: PropTypes.node,
|
|
198
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
|
}
|