@qoretechnologies/reqore 0.35.2 → 0.36.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/dist/components/Collection/index.d.ts +11 -2
- package/dist/components/Collection/index.d.ts.map +1 -1
- package/dist/components/Collection/index.js +33 -7
- package/dist/components/Collection/index.js.map +1 -1
- package/dist/components/KeyValueTable/index.d.ts +27 -0
- package/dist/components/KeyValueTable/index.d.ts.map +1 -0
- package/dist/components/KeyValueTable/index.js +87 -0
- package/dist/components/KeyValueTable/index.js.map +1 -0
- package/dist/components/Table/body.d.ts +0 -1
- package/dist/components/Table/body.d.ts.map +1 -1
- package/dist/components/Table/body.js +6 -2
- package/dist/components/Table/body.js.map +1 -1
- package/dist/components/Table/index.d.ts +3 -1
- package/dist/components/Table/index.d.ts.map +1 -1
- package/dist/components/Table/index.js +50 -39
- package/dist/components/Table/index.js.map +1 -1
- package/dist/components/Table/row.d.ts.map +1 -1
- package/dist/components/Table/row.js +9 -3
- package/dist/components/Table/row.js.map +1 -1
- package/dist/components/Table/value.d.ts +7 -0
- package/dist/components/Table/value.d.ts.map +1 -0
- package/dist/components/Table/value.js +37 -0
- package/dist/components/Table/value.js.map +1 -0
- package/dist/components/Tree/index.d.ts +3 -1
- package/dist/components/Tree/index.d.ts.map +1 -1
- package/dist/components/Tree/index.js +9 -2
- package/dist/components/Tree/index.js.map +1 -1
- package/dist/constants/paging.d.ts +1 -0
- package/dist/constants/paging.d.ts.map +1 -1
- package/dist/constants/paging.js +20 -1
- package/dist/constants/paging.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Collection/index.tsx +41 -6
- package/src/components/KeyValueTable/index.tsx +123 -0
- package/src/components/Table/body.tsx +9 -4
- package/src/components/Table/index.tsx +86 -52
- package/src/components/Table/row.tsx +9 -3
- package/src/components/Table/value.tsx +27 -0
- package/src/components/Tree/index.tsx +13 -2
- package/src/constants/paging.ts +22 -0
- package/src/index.tsx +2 -0
- package/src/stories/Collection/Collection.stories.tsx +16 -0
- package/src/stories/KeyValueTable/KeyValueTable.stories.tsx +199 -0
- package/src/stories/Table/Table.stories.tsx +18 -1
- package/src/stories/Tree/Tree.stories.tsx +13 -0
- package/tests.json +1 -1
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { keys } from 'lodash';
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { TReqoreIntent } from '../../constants/theme';
|
|
4
|
+
import { IReqoreIconName } from '../../types/icons';
|
|
5
|
+
import { IReqorePanelProps } from '../Panel';
|
|
6
|
+
import ReqoreTable, {
|
|
7
|
+
IReqoreTableColumn,
|
|
8
|
+
IReqoreTableProps,
|
|
9
|
+
IReqoreTableRowData,
|
|
10
|
+
TReqoreTableColumnContent,
|
|
11
|
+
} from '../Table';
|
|
12
|
+
import { IReqoreTableValueProps, ReqoreTableValue } from '../Table/value';
|
|
13
|
+
|
|
14
|
+
export type TReqoreKeyValueTablePrimitiveValue = string | number | boolean | null | undefined;
|
|
15
|
+
export type TReqoreKeyValueTableValue =
|
|
16
|
+
| TReqoreKeyValueTablePrimitiveValue
|
|
17
|
+
| TReqoreKeyValueTablePrimitiveValue[]
|
|
18
|
+
| { [key: string]: TReqoreKeyValueTableValue };
|
|
19
|
+
|
|
20
|
+
export interface IReqoreKeyValueTableProps
|
|
21
|
+
extends IReqorePanelProps,
|
|
22
|
+
Pick<IReqoreTableProps, 'striped' | 'width' | 'height' | 'fill'> {
|
|
23
|
+
data: { [key: string | number]: TReqoreKeyValueTableValue };
|
|
24
|
+
|
|
25
|
+
keyLabel?: string;
|
|
26
|
+
keyIcon?: IReqoreIconName;
|
|
27
|
+
keyColumnIntent?: TReqoreIntent;
|
|
28
|
+
keyAlign?: IReqoreTableColumn['align'];
|
|
29
|
+
maxKeyWidth?: number;
|
|
30
|
+
|
|
31
|
+
valueLabel?: string;
|
|
32
|
+
valueIcon?: IReqoreIconName;
|
|
33
|
+
valueAlign?: IReqoreTableColumn['align'];
|
|
34
|
+
minValueWidth?: number;
|
|
35
|
+
defaultValueFilter?: string | number;
|
|
36
|
+
|
|
37
|
+
valueRenderer?: (
|
|
38
|
+
data: IReqoreTableRowData,
|
|
39
|
+
defaultComponent?: ({
|
|
40
|
+
value,
|
|
41
|
+
}: IReqoreTableValueProps) => TReqoreTableColumnContent | JSX.Element
|
|
42
|
+
) => JSX.Element;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const ReqoreKeyValueTable = ({
|
|
46
|
+
data,
|
|
47
|
+
keyLabel,
|
|
48
|
+
keyIcon,
|
|
49
|
+
valueLabel,
|
|
50
|
+
valueIcon,
|
|
51
|
+
valueRenderer,
|
|
52
|
+
keyColumnIntent = 'muted',
|
|
53
|
+
minValueWidth = 100,
|
|
54
|
+
maxKeyWidth = 200,
|
|
55
|
+
keyAlign = 'left',
|
|
56
|
+
valueAlign = 'left',
|
|
57
|
+
defaultValueFilter,
|
|
58
|
+
...rest
|
|
59
|
+
}: IReqoreKeyValueTableProps) => {
|
|
60
|
+
const { columns, items } = useMemo(() => {
|
|
61
|
+
let columns: IReqoreTableColumn[] = [
|
|
62
|
+
{
|
|
63
|
+
dataId: 'tableKey',
|
|
64
|
+
grow: 1,
|
|
65
|
+
width: maxKeyWidth < 150 ? maxKeyWidth : 150,
|
|
66
|
+
pin: 'left',
|
|
67
|
+
hideable: false,
|
|
68
|
+
intent: keyColumnIntent,
|
|
69
|
+
maxWidth: maxKeyWidth,
|
|
70
|
+
align: keyAlign,
|
|
71
|
+
|
|
72
|
+
header: {
|
|
73
|
+
icon: keyIcon,
|
|
74
|
+
label: keyLabel,
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
cell: {
|
|
78
|
+
content: 'title',
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
dataId: 'value',
|
|
83
|
+
grow: 3,
|
|
84
|
+
hideable: false,
|
|
85
|
+
filterable: true,
|
|
86
|
+
pinnable: false,
|
|
87
|
+
minWidth: minValueWidth,
|
|
88
|
+
filter: defaultValueFilter,
|
|
89
|
+
align: valueAlign,
|
|
90
|
+
|
|
91
|
+
header: {
|
|
92
|
+
icon: valueIcon,
|
|
93
|
+
label: valueLabel,
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
cell: {
|
|
97
|
+
content: (data) =>
|
|
98
|
+
valueRenderer?.(data, ReqoreTableValue) || <ReqoreTableValue value={data.value} />,
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
];
|
|
102
|
+
|
|
103
|
+
let items: IReqoreTableRowData[] = [];
|
|
104
|
+
|
|
105
|
+
keys(data).map((key) => {
|
|
106
|
+
items.push({
|
|
107
|
+
tableKey: key,
|
|
108
|
+
value: data[key],
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
return { columns, items };
|
|
113
|
+
}, [data]);
|
|
114
|
+
|
|
115
|
+
return (
|
|
116
|
+
<ReqoreTable
|
|
117
|
+
columns={columns}
|
|
118
|
+
data={items}
|
|
119
|
+
{...rest}
|
|
120
|
+
className={`${rest.className || ''} reqore-key-value-table`}
|
|
121
|
+
/>
|
|
122
|
+
);
|
|
123
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { forwardRef } from 'react';
|
|
1
|
+
import { forwardRef, useMemo } from 'react';
|
|
2
2
|
import { useMount } from 'react-use';
|
|
3
3
|
import { FixedSizeList as List } from 'react-window';
|
|
4
4
|
import styled from 'styled-components';
|
|
@@ -7,7 +7,6 @@ import { useCombinedRefs } from '../../hooks/useCombinedRefs';
|
|
|
7
7
|
import ReqoreTableRow, { IReqoreTableRowOptions } from './row';
|
|
8
8
|
|
|
9
9
|
export interface IReqoreTableSectionBodyProps extends IReqoreTableRowOptions {
|
|
10
|
-
rowHeight?: number;
|
|
11
10
|
height: number;
|
|
12
11
|
refs: {
|
|
13
12
|
left: React.RefObject<HTMLDivElement>;
|
|
@@ -30,7 +29,6 @@ const ReqoreTableBody = forwardRef<HTMLDivElement, IReqoreTableSectionBodyProps>
|
|
|
30
29
|
{
|
|
31
30
|
data,
|
|
32
31
|
height,
|
|
33
|
-
rowHeight,
|
|
34
32
|
size = 'normal',
|
|
35
33
|
refs,
|
|
36
34
|
type,
|
|
@@ -70,11 +68,18 @@ const ReqoreTableBody = forwardRef<HTMLDivElement, IReqoreTableSectionBodyProps>
|
|
|
70
68
|
});
|
|
71
69
|
});
|
|
72
70
|
|
|
71
|
+
const rowHeight = useMemo(
|
|
72
|
+
() => (rest.flat ? TABLE_SIZE_TO_PX[size] : TABLE_SIZE_TO_PX[size] + 1),
|
|
73
|
+
[size, rest.flat]
|
|
74
|
+
);
|
|
75
|
+
|
|
73
76
|
return (
|
|
74
77
|
<StyledList
|
|
75
78
|
outerRef={targetRef}
|
|
76
79
|
itemCount={data.length}
|
|
77
|
-
height
|
|
80
|
+
// If the defined height is less than the count of items' height
|
|
81
|
+
// use that height instead
|
|
82
|
+
height={height > data.length * rowHeight ? data.length * rowHeight : height}
|
|
78
83
|
className='reqore-table-body'
|
|
79
84
|
itemSize={rest.flat ? TABLE_SIZE_TO_PX[size] : TABLE_SIZE_TO_PX[size] + 1}
|
|
80
85
|
itemData={{
|
|
@@ -3,7 +3,8 @@ import { size as count, isArray } from 'lodash';
|
|
|
3
3
|
import React, { useCallback, useMemo, useRef, useState } from 'react';
|
|
4
4
|
import { useMeasure, useUpdateEffect } from 'react-use';
|
|
5
5
|
import styled, { css } from 'styled-components';
|
|
6
|
-
import { ReqoreMessage, ReqorePanel, ReqoreVerticalSpacer } from '../..';
|
|
6
|
+
import { ReqoreMessage, ReqorePaginationContainer, ReqorePanel, ReqoreVerticalSpacer } from '../..';
|
|
7
|
+
import { TReqorePaginationType, getPagingObjectFromType } from '../../constants/paging';
|
|
7
8
|
import { TABLE_SIZE_TO_PX, TSizes } from '../../constants/sizes';
|
|
8
9
|
import { IReqoreTheme, TReqoreIntent } from '../../constants/theme';
|
|
9
10
|
import { useQueryWithDelay } from '../../hooks/useQueryWithDelay';
|
|
@@ -96,6 +97,8 @@ export interface IReqoreTableProps extends IReqorePanelProps {
|
|
|
96
97
|
height?: number;
|
|
97
98
|
wrapperSize?: TSizes;
|
|
98
99
|
|
|
100
|
+
paging?: TReqorePaginationType<IReqoreTableRowData>;
|
|
101
|
+
|
|
99
102
|
sort?: IReqoreTableSort;
|
|
100
103
|
onSortChange?: (sort?: IReqoreTableSort) => void;
|
|
101
104
|
|
|
@@ -141,16 +144,18 @@ export interface IReqoreTableSort {
|
|
|
141
144
|
|
|
142
145
|
const StyledTableWrapper = styled.div`
|
|
143
146
|
overflow: hidden;
|
|
147
|
+
display: flex;
|
|
148
|
+
flex-flow: column;
|
|
144
149
|
|
|
145
150
|
${({ isPinned }) =>
|
|
146
151
|
isPinned
|
|
147
152
|
? css`
|
|
148
153
|
flex-shrink: 0;
|
|
154
|
+
z-index: 1;
|
|
155
|
+
box-shadow: 1px -1px 20px -2px rgba(0, 0, 0, 0.8);
|
|
149
156
|
`
|
|
150
157
|
: css`
|
|
151
158
|
width: 100%;
|
|
152
|
-
display: flex;
|
|
153
|
-
flex-flow: column;
|
|
154
159
|
flex: 1;
|
|
155
160
|
`};
|
|
156
161
|
`;
|
|
@@ -192,6 +197,7 @@ const ReqoreTable = ({
|
|
|
192
197
|
rowComponent,
|
|
193
198
|
bodyCellComponent,
|
|
194
199
|
onSelectClick,
|
|
200
|
+
paging,
|
|
195
201
|
...rest
|
|
196
202
|
}: IReqoreTableProps) => {
|
|
197
203
|
const leftTableRef = useRef<HTMLDivElement>(undefined);
|
|
@@ -308,7 +314,7 @@ const ReqoreTable = ({
|
|
|
308
314
|
const transformedData = useMemo(() => {
|
|
309
315
|
// Filter by global query
|
|
310
316
|
let filteredData = _data.filter((datum) =>
|
|
311
|
-
JSON.stringify(datum).toLowerCase().includes(query.toLowerCase())
|
|
317
|
+
JSON.stringify(datum).toLowerCase().includes(query.toString().toLowerCase())
|
|
312
318
|
);
|
|
313
319
|
|
|
314
320
|
// Filter by column filters
|
|
@@ -434,12 +440,7 @@ const ReqoreTable = ({
|
|
|
434
440
|
}, []);
|
|
435
441
|
|
|
436
442
|
const columnsList = useMemo(() => {
|
|
437
|
-
const _columnsList: IReqorePanelSubAction[] = [
|
|
438
|
-
{
|
|
439
|
-
divider: true,
|
|
440
|
-
label: 'Show / hide columns',
|
|
441
|
-
},
|
|
442
|
-
];
|
|
443
|
+
const _columnsList: IReqorePanelSubAction[] = [];
|
|
443
444
|
|
|
444
445
|
const addColumn = (column: IReqoreTableColumn) => {
|
|
445
446
|
_columnsList.push({
|
|
@@ -465,21 +466,47 @@ const ReqoreTable = ({
|
|
|
465
466
|
}
|
|
466
467
|
});
|
|
467
468
|
|
|
469
|
+
if (count(_columnsList)) {
|
|
470
|
+
_columnsList.unshift({
|
|
471
|
+
divider: true,
|
|
472
|
+
label: 'Show / hide columns',
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
|
|
468
476
|
return _columnsList;
|
|
469
477
|
}, [finalColumns]);
|
|
470
478
|
|
|
479
|
+
const handleScrollToTop = () => {
|
|
480
|
+
mainTableRef.current?.scrollTo({
|
|
481
|
+
top: 0,
|
|
482
|
+
behavior: 'smooth',
|
|
483
|
+
});
|
|
484
|
+
leftTableRef.current?.scrollTo({
|
|
485
|
+
top: 0,
|
|
486
|
+
behavior: 'smooth',
|
|
487
|
+
});
|
|
488
|
+
rightTableRef.current?.scrollTo({
|
|
489
|
+
top: 0,
|
|
490
|
+
behavior: 'smooth',
|
|
491
|
+
});
|
|
492
|
+
|
|
493
|
+
setIsScrolled(false);
|
|
494
|
+
};
|
|
495
|
+
|
|
471
496
|
const tableActions = useMemo<IReqorePanelAction[]>(() => {
|
|
472
497
|
const finalActions: IReqorePanelAction[] = [...actions];
|
|
473
498
|
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
499
|
+
if (count(columnsList)) {
|
|
500
|
+
finalActions.push({
|
|
501
|
+
label: 'Columns',
|
|
502
|
+
icon: 'LayoutColumnLine',
|
|
503
|
+
className: 'reqore-table-columns-options',
|
|
504
|
+
badge: getColumnsCount(getOnlyShownColumns(finalColumns)),
|
|
505
|
+
intent: hasHiddenColumns(finalColumns) ? 'info' : undefined,
|
|
506
|
+
multiSelect: true,
|
|
507
|
+
actions: columnsList,
|
|
508
|
+
});
|
|
509
|
+
}
|
|
483
510
|
|
|
484
511
|
if (filterable) {
|
|
485
512
|
finalActions.push({
|
|
@@ -515,22 +542,7 @@ const ReqoreTable = ({
|
|
|
515
542
|
tooltip: 'Scroll to top',
|
|
516
543
|
className: 'reqore-table-columns-scroll-top',
|
|
517
544
|
responsive: true,
|
|
518
|
-
onClick:
|
|
519
|
-
mainTableRef.current?.scrollTo({
|
|
520
|
-
top: 0,
|
|
521
|
-
behavior: 'smooth',
|
|
522
|
-
});
|
|
523
|
-
leftTableRef.current?.scrollTo({
|
|
524
|
-
top: 0,
|
|
525
|
-
behavior: 'smooth',
|
|
526
|
-
});
|
|
527
|
-
rightTableRef.current?.scrollTo({
|
|
528
|
-
top: 0,
|
|
529
|
-
behavior: 'smooth',
|
|
530
|
-
});
|
|
531
|
-
|
|
532
|
-
setIsScrolled(false);
|
|
533
|
-
},
|
|
545
|
+
onClick: handleScrollToTop,
|
|
534
546
|
});
|
|
535
547
|
}
|
|
536
548
|
|
|
@@ -598,7 +610,7 @@ const ReqoreTable = ({
|
|
|
598
610
|
[finalColumns]
|
|
599
611
|
);
|
|
600
612
|
|
|
601
|
-
const renderTable = (type: 'left' | 'main' | 'right' = 'main') => {
|
|
613
|
+
const renderTable = (type: 'left' | 'main' | 'right' = 'main', items: IReqoreTableRowData[]) => {
|
|
602
614
|
const tableColumns = columnsByType[type];
|
|
603
615
|
const isPinned = type === 'left' || type === 'right';
|
|
604
616
|
|
|
@@ -617,19 +629,19 @@ const ReqoreTable = ({
|
|
|
617
629
|
onSortChange={handleSortChange}
|
|
618
630
|
heightAsGroup={hasGroupedColumns(finalColumns)}
|
|
619
631
|
sortData={_sort}
|
|
620
|
-
hasVerticalScroll={count(
|
|
632
|
+
hasVerticalScroll={count(items) * TABLE_SIZE_TO_PX[size] > height}
|
|
621
633
|
onColumnsUpdate={handleColumnsUpdate}
|
|
622
634
|
onFilterChange={(dataId: string, value: any) => {
|
|
623
635
|
handleColumnsUpdate(dataId, 'filter', value);
|
|
624
636
|
}}
|
|
625
637
|
component={headerCellComponent}
|
|
626
638
|
/>
|
|
627
|
-
{count(
|
|
639
|
+
{count(items) === 0 ? null : (
|
|
628
640
|
<ReqoreTableBody
|
|
629
641
|
ref={refs[type]}
|
|
630
642
|
refs={refs}
|
|
631
643
|
type={type}
|
|
632
|
-
data={
|
|
644
|
+
data={items}
|
|
633
645
|
columns={tableColumns}
|
|
634
646
|
height={fill ? sizes.height : height}
|
|
635
647
|
selectable={selectable}
|
|
@@ -649,6 +661,8 @@ const ReqoreTable = ({
|
|
|
649
661
|
);
|
|
650
662
|
};
|
|
651
663
|
|
|
664
|
+
const pagingOptions = useMemo(() => getPagingObjectFromType(paging), [paging]);
|
|
665
|
+
|
|
652
666
|
return (
|
|
653
667
|
<ReqorePanel
|
|
654
668
|
transparent
|
|
@@ -665,19 +679,39 @@ const ReqoreTable = ({
|
|
|
665
679
|
getContentRef={wrapperRef}
|
|
666
680
|
badge={badge}
|
|
667
681
|
>
|
|
668
|
-
<
|
|
669
|
-
{
|
|
670
|
-
{
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
682
|
+
<ReqorePaginationContainer<IReqoreTableRowData>
|
|
683
|
+
items={transformedData}
|
|
684
|
+
type={
|
|
685
|
+
paging
|
|
686
|
+
? {
|
|
687
|
+
...pagingOptions,
|
|
688
|
+
onPageChange: () => {
|
|
689
|
+
if (!pagingOptions.infinite) {
|
|
690
|
+
handleScrollToTop();
|
|
691
|
+
}
|
|
692
|
+
},
|
|
693
|
+
}
|
|
694
|
+
: undefined
|
|
695
|
+
}
|
|
696
|
+
>
|
|
697
|
+
{(pagedData) => (
|
|
698
|
+
<>
|
|
699
|
+
<StyledTablesWrapper className='reqore-table-wrapper'>
|
|
700
|
+
{renderTable('left', pagedData)}
|
|
701
|
+
{renderTable('main', pagedData)}
|
|
702
|
+
{renderTable('right', pagedData)}
|
|
703
|
+
</StyledTablesWrapper>
|
|
704
|
+
{count(pagedData) === 0 ? (
|
|
705
|
+
<>
|
|
706
|
+
<ReqoreVerticalSpacer height={10} />
|
|
707
|
+
<ReqoreMessage flat size={size} icon='Search2Line'>
|
|
708
|
+
{emptyMessage}
|
|
709
|
+
</ReqoreMessage>
|
|
710
|
+
</>
|
|
711
|
+
) : null}
|
|
712
|
+
</>
|
|
713
|
+
)}
|
|
714
|
+
</ReqorePaginationContainer>
|
|
681
715
|
</ReqorePanel>
|
|
682
716
|
);
|
|
683
717
|
};
|
|
@@ -124,12 +124,18 @@ const ReqoreTableRow = ({
|
|
|
124
124
|
);
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
|
|
127
|
+
let content = cell?.content;
|
|
128
128
|
|
|
129
129
|
if (isFunction(content)) {
|
|
130
|
-
|
|
130
|
+
// Check what type does the content function return
|
|
131
|
+
if (React.isValidElement(content(data))) {
|
|
132
|
+
const Content = content;
|
|
133
|
+
// If it's a react element, return it
|
|
134
|
+
return <Content {...data} _size={size} _dataId={dataId} />;
|
|
135
|
+
}
|
|
131
136
|
|
|
132
|
-
|
|
137
|
+
// If it's a function, call it and return the result
|
|
138
|
+
content = content(data) as any;
|
|
133
139
|
}
|
|
134
140
|
|
|
135
141
|
if (isString(content)) {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import ReqoreIcon from '../Icon';
|
|
2
|
+
import { ReqoreP } from '../Paragraph';
|
|
3
|
+
|
|
4
|
+
export interface IReqoreTableValueProps {
|
|
5
|
+
value?: string | number | boolean | any[] | { [key: string]: any };
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const ReqoreTableValue = ({ value }: IReqoreTableValueProps) => {
|
|
9
|
+
if (value === undefined || value === null) {
|
|
10
|
+
return <>-</>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
switch (typeof value) {
|
|
14
|
+
case 'string':
|
|
15
|
+
case 'number':
|
|
16
|
+
return <ReqoreP className='reqore-table-text'>{value}</ReqoreP>;
|
|
17
|
+
case 'boolean':
|
|
18
|
+
return (
|
|
19
|
+
<ReqoreIcon
|
|
20
|
+
icon={value ? 'CheckLine' : 'CloseLine'}
|
|
21
|
+
intent={value ? 'success' : 'danger'}
|
|
22
|
+
/>
|
|
23
|
+
);
|
|
24
|
+
default:
|
|
25
|
+
return <ReqoreP className='reqore-table-text'>{JSON.stringify(value)}</ReqoreP>;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
@@ -8,6 +8,7 @@ import { IWithReqoreSize } from '../../types/global';
|
|
|
8
8
|
import ReqoreButton from '../Button';
|
|
9
9
|
import ReqoreControlGroup from '../ControlGroup';
|
|
10
10
|
import { IReqorePanelProps } from '../Panel';
|
|
11
|
+
import { getZoomActions, sizeToZoom, zoomToSize } from '../Table/helpers';
|
|
11
12
|
import ReqoreTag from '../Tag';
|
|
12
13
|
|
|
13
14
|
export interface IReqoreTreeProps extends IReqorePanelProps, IWithReqoreSize {
|
|
@@ -18,6 +19,8 @@ export interface IReqoreTreeProps extends IReqorePanelProps, IWithReqoreSize {
|
|
|
18
19
|
onItemClick?: (value: any, path?: string[]) => void;
|
|
19
20
|
withLabelCopy?: boolean;
|
|
20
21
|
showControls?: boolean;
|
|
22
|
+
zoomable?: boolean;
|
|
23
|
+
defaultZoom?: 0 | 0.5 | 1 | 1.5 | 2;
|
|
21
24
|
}
|
|
22
25
|
|
|
23
26
|
export interface ITreeStyle {
|
|
@@ -38,6 +41,8 @@ export const ReqoreTree = ({
|
|
|
38
41
|
onItemClick,
|
|
39
42
|
withLabelCopy,
|
|
40
43
|
showControls = true,
|
|
44
|
+
zoomable,
|
|
45
|
+
defaultZoom,
|
|
41
46
|
...rest
|
|
42
47
|
}: IReqoreTreeProps) => {
|
|
43
48
|
const [_mode, setMode] = useState<'tree' | 'copy'>(mode);
|
|
@@ -45,6 +50,7 @@ export const ReqoreTree = ({
|
|
|
45
50
|
const [allExpanded, setAllExpanded] = useState(expanded || !showControls);
|
|
46
51
|
const [_showTypes, setShowTypes] = useState(showTypes);
|
|
47
52
|
const addNotification = useReqoreProperty('addNotification');
|
|
53
|
+
const [zoom, setZoom] = useState(defaultZoom || sizeToZoom[size]);
|
|
48
54
|
|
|
49
55
|
const handleCopyClick = () => {
|
|
50
56
|
setMode('copy');
|
|
@@ -99,7 +105,7 @@ export const ReqoreTree = ({
|
|
|
99
105
|
return (
|
|
100
106
|
<div key={index} style={{ margin: level === 1 ? '15px 0' : `15px` }}>
|
|
101
107
|
{isObject ? (
|
|
102
|
-
<ReqoreControlGroup size={
|
|
108
|
+
<ReqoreControlGroup size={zoomToSize[zoom]}>
|
|
103
109
|
<ReqoreButton
|
|
104
110
|
className='reqore-tree-toggle'
|
|
105
111
|
icon={isExpandable ? 'ArrowDownSFill' : 'ArrowRightSFill'}
|
|
@@ -112,7 +118,7 @@ export const ReqoreTree = ({
|
|
|
112
118
|
{_showTypes ? <ReqoreTag label={dataType} className='reqore-tree-type' /> : null}
|
|
113
119
|
</ReqoreControlGroup>
|
|
114
120
|
) : (
|
|
115
|
-
<ReqoreControlGroup size={
|
|
121
|
+
<ReqoreControlGroup size={zoomToSize[zoom]}>
|
|
116
122
|
<ReqoreTag
|
|
117
123
|
label={displayKey}
|
|
118
124
|
actions={
|
|
@@ -184,6 +190,11 @@ export const ReqoreTree = ({
|
|
|
184
190
|
actions={
|
|
185
191
|
showControls
|
|
186
192
|
? [
|
|
193
|
+
{
|
|
194
|
+
fluid: false,
|
|
195
|
+
group: getZoomActions('reqore-tree', zoom, setZoom),
|
|
196
|
+
show: !!zoomable,
|
|
197
|
+
},
|
|
187
198
|
{
|
|
188
199
|
className: 'reqore-tree-expand-all',
|
|
189
200
|
icon: 'ArrowDownFill',
|
package/src/constants/paging.ts
CHANGED
|
@@ -24,6 +24,28 @@ export type TReqorePaginationTypeResult<T> = {
|
|
|
24
24
|
includeBottomControls?: boolean;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
+
export function getPagingObjectFromType<T>(
|
|
28
|
+
type: TReqorePaginationType<T>
|
|
29
|
+
): IReqoreComponentPagingOptions<T> {
|
|
30
|
+
if (typeof type === 'object') {
|
|
31
|
+
return type;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
switch (type) {
|
|
35
|
+
case 'buttons':
|
|
36
|
+
return {};
|
|
37
|
+
case 'list':
|
|
38
|
+
return {
|
|
39
|
+
showPagesAs: 'list',
|
|
40
|
+
};
|
|
41
|
+
case 'infinite':
|
|
42
|
+
case 'auto-load':
|
|
43
|
+
return { infinite: true };
|
|
44
|
+
default:
|
|
45
|
+
return {};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
27
49
|
export function getPaginationOptionsFromType<T>(
|
|
28
50
|
type: TReqorePaginationType<T>
|
|
29
51
|
): TReqorePaginationTypeResult<T> {
|
package/src/index.tsx
CHANGED
|
@@ -24,6 +24,7 @@ export {
|
|
|
24
24
|
} from './components/Header';
|
|
25
25
|
export { default as ReqoreIcon } from './components/Icon';
|
|
26
26
|
export { default as ReqoreInput } from './components/Input';
|
|
27
|
+
export { IReqoreKeyValueTableProps, ReqoreKeyValueTable } from './components/KeyValueTable';
|
|
27
28
|
export { default as ReqoreLayoutContent } from './components/Layout/content';
|
|
28
29
|
export { default as ReqoreMenu } from './components/Menu';
|
|
29
30
|
export { default as ReqoreMenuDivider } from './components/Menu/divider';
|
|
@@ -49,6 +50,7 @@ export { default as ReqoreTable } from './components/Table';
|
|
|
49
50
|
export { ReqoreTableBodyCell } from './components/Table/cell';
|
|
50
51
|
export { ReqoreTableHeaderCell } from './components/Table/headerCell';
|
|
51
52
|
export { default as ReqoreTableRow } from './components/Table/row';
|
|
53
|
+
export { ReqoreTableValue } from './components/Table/value';
|
|
52
54
|
export { default as ReqoreTabs } from './components/Tabs';
|
|
53
55
|
export { default as ReqoreTabsContent } from './components/Tabs/content';
|
|
54
56
|
export { default as ReqoreTabsListItem } from './components/Tabs/item';
|
|
@@ -125,6 +125,22 @@ SelectedFirst.args = {
|
|
|
125
125
|
showSelectedFirst: true,
|
|
126
126
|
};
|
|
127
127
|
|
|
128
|
+
export const Zoomable = Template.bind({});
|
|
129
|
+
Zoomable.args = {
|
|
130
|
+
label: 'Collection of items',
|
|
131
|
+
items,
|
|
132
|
+
zoomable: true,
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export const WithDefaultZoom = Template.bind({});
|
|
136
|
+
WithDefaultZoom.args = {
|
|
137
|
+
label: 'Collection of items',
|
|
138
|
+
items,
|
|
139
|
+
zoomable: true,
|
|
140
|
+
size: 'tiny',
|
|
141
|
+
defaultZoom: 2,
|
|
142
|
+
};
|
|
143
|
+
|
|
128
144
|
export const CustomColumnsData = Template.bind({});
|
|
129
145
|
CustomColumnsData.args = {
|
|
130
146
|
columns: 2,
|