-
Notifications
You must be signed in to change notification settings - Fork 2
/
ItemDefBase.ts
130 lines (109 loc) · 3.8 KB
/
ItemDefBase.ts
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Item
*/
import type * as React from "react";
import type {
ConditionalBooleanValue,
ConditionalStringValue,
StringGetter,
} from "@itwin/appui-abstract";
import { PropsHelper } from "../utils/PropsHelper";
import type { ItemProps } from "./ItemProps";
import type { BadgeType, IconSpec } from "@itwin/core-react";
/** Base state for any 'stateful' React component
* @public
*/
export interface BaseItemState {
isVisible?: boolean; // Default - true
isEnabled?: boolean; // Default - true
isActive?: boolean; // Default - false
isPressed?: boolean; // Default - false
}
/** The base class for Items.
* @public
*/
export abstract class ItemDefBase {
private _label: string | StringGetter | ConditionalStringValue = "";
private _tooltip: string | StringGetter | ConditionalStringValue = "";
private _description: string | StringGetter | ConditionalStringValue = "";
public isPressed: boolean = false;
private _isActive: boolean = false;
public get isActive(): boolean {
return this._isActive;
}
public set isActive(v: boolean) {
this._isActive = v;
}
public applicationData?: any;
public isHidden?: boolean | ConditionalBooleanValue;
public isDisabled?: boolean | ConditionalBooleanValue;
public badgeType?: BadgeType;
public iconSpec?: IconSpec;
public iconElement?: React.ReactNode;
public static initializeDef(me: ItemDefBase, itemProps: ItemProps): void {
me.isHidden = itemProps.isHidden;
me.isDisabled = itemProps.isDisabled;
me.isPressed =
itemProps.isPressed !== undefined ? itemProps.isPressed : false;
me.isActive = itemProps.isActive !== undefined ? itemProps.isActive : false;
me.badgeType = itemProps.badgeType;
if (itemProps.applicationData !== undefined)
me.applicationData = itemProps.applicationData;
if (itemProps.iconSpec) me.iconSpec = itemProps.iconSpec;
if (itemProps.icon) me.iconSpec = itemProps.icon;
me._label = PropsHelper.getStringSpec(itemProps.label, itemProps.labelKey);
me._tooltip = PropsHelper.getStringSpec(
itemProps.tooltip,
itemProps.tooltipKey
);
me._description = PropsHelper.getStringSpec(
itemProps.description,
itemProps.descriptionKey
);
}
constructor(itemProps: ItemProps) {
ItemDefBase.initializeDef(this, itemProps);
}
public get trayId() {
return undefined;
}
public abstract get id(): string;
/** Get the label string */
public get rawLabel(): string | StringGetter | ConditionalStringValue {
return this._label;
}
/** Get the label string */
public get label(): string {
return PropsHelper.getStringFromSpec(this._label);
}
/** Set the label.
* @param v A string or a function to get the string.
*/
public setLabel(v: string | StringGetter | ConditionalStringValue) {
this._label = v;
}
/** Get the tooltip string */
public get tooltip(): string {
return PropsHelper.getStringFromSpec(this._tooltip);
}
/** Set the tooltip.
* @param v A string or a function to get the string.
*/
public setTooltip(v: string | StringGetter | ConditionalStringValue) {
this._tooltip = v;
}
/** Get the description string */
public get description(): string {
return PropsHelper.getStringFromSpec(this._description);
}
/** Set the description.
* @param v A string or a function to get the string.
*/
public setDescription(v: string | StringGetter | ConditionalStringValue) {
this._description = v;
}
}