-
Notifications
You must be signed in to change notification settings - Fork 2
/
ArrayPropertyValueRenderer.tsx
64 lines (58 loc) · 2.15 KB
/
ArrayPropertyValueRenderer.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Properties
*/
import * as React from "react";
import type { ArrayValue, PropertyRecord } from "@itwin/appui-abstract";
import { PropertyValueFormat } from "@itwin/appui-abstract";
import { Orientation } from "@itwin/core-react";
import type {
IPropertyValueRenderer,
PropertyValueRendererContext,
} from "../../ValueRendererManager";
import { PropertyContainerType } from "../../ValueRendererManager";
import { TableArrayValueRenderer } from "./table/ArrayValueRenderer";
import { withContextStyle } from "./WithContextStyle";
/** Default Array Property Renderer
* @public
*/
export class ArrayPropertyValueRenderer implements IPropertyValueRenderer {
/** Checks if the renderer can handle given property */
public canRender(record: PropertyRecord) {
return record.value.valueFormat === PropertyValueFormat.Array;
}
/** Method that returns a JSX representation of PropertyRecord */
public render(
record: PropertyRecord,
context?: PropertyValueRendererContext
) {
const recordItems = (record.value as ArrayValue).items;
if (context && context.containerType === PropertyContainerType.Table) {
return withContextStyle(
<TableArrayValueRenderer
propertyRecord={record}
onDialogOpen={context.onDialogOpen}
orientation={
context.orientation ? context.orientation : Orientation.Horizontal
}
/>,
context
);
}
if (
context &&
context.containerType === PropertyContainerType.PropertyPane
) {
return withContextStyle("", context);
}
return withContextStyle(
recordItems.length !== 0
? `${(record.value as ArrayValue).itemsTypeName}[${recordItems.length}]`
: `${(record.value as ArrayValue).itemsTypeName}[]`,
context
);
}
}