-
Notifications
You must be signed in to change notification settings - Fork 2
/
GroupItem.tsx
112 lines (93 loc) · 3.29 KB
/
GroupItem.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
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
/*---------------------------------------------------------------------------------------------
* 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 {
ConditionalStringValue,
OnItemExecutedFunc,
StringGetter,
} from "@itwin/appui-abstract";
import { ActionButtonItemDef } from "../shared/ActionButtonItemDef";
import type { AnyItemDef } from "../shared/AnyItemDef";
import type { GroupItemProps } from "../shared/GroupItemProps";
import type { ItemDefBase } from "../shared/ItemDefBase";
import { ItemList, ItemMap } from "../shared/ItemMap";
import { PropsHelper } from "../utils/PropsHelper";
// -----------------------------------------------------------------------------
// GroupItemDef class
// -----------------------------------------------------------------------------
/** An Item that opens a group of items.
* @public
*/
export class GroupItemDef extends ActionButtonItemDef {
private static _sId = 0;
public static groupIdPrefix = "Group-";
public groupId: string;
public itemsInColumn: number;
public items: AnyItemDef[];
public defaultActiveItemId?: string;
/** @internal */
public overflow: boolean = false;
private _itemList!: ItemList;
private _itemMap!: ItemMap;
private _panelLabel: string | StringGetter | ConditionalStringValue = "";
constructor(
groupItemProps: GroupItemProps,
onItemExecuted?: OnItemExecutedFunc
) {
super(groupItemProps, onItemExecuted);
this.groupId =
groupItemProps.groupId !== undefined ? groupItemProps.groupId : "";
if (groupItemProps.groupId) this.groupId = groupItemProps.groupId;
else {
GroupItemDef._sId++;
this.groupId = GroupItemDef.groupIdPrefix + GroupItemDef._sId;
}
this.itemsInColumn =
groupItemProps.itemsInColumn !== undefined
? groupItemProps.itemsInColumn
: 7;
this._panelLabel = PropsHelper.getStringSpec(
groupItemProps.panelLabel,
groupItemProps.panelLabelKey
);
this.items = groupItemProps.items;
this.defaultActiveItemId = groupItemProps.defaultActiveItemId;
}
public get id(): string {
return this.groupId;
}
/** Get the panelLabel string */
public get panelLabel(): string {
return PropsHelper.getStringFromSpec(this._panelLabel);
}
/** Set the panelLabel.
* @param v A string or a function to get the string.
*/
public setPanelLabel(v: string | StringGetter | ConditionalStringValue) {
this._panelLabel = v;
}
public resolveItems(force?: boolean): void {
if (this._itemList && !force) return;
this._itemList = new ItemList();
this._itemMap = new ItemMap();
this.items.map((item: AnyItemDef) => {
const id: string = item.id;
this._itemList.addItem(item);
this._itemMap.set(id, item);
});
}
public getItemById(id: string): ItemDefBase | undefined {
return this._itemMap.get(id);
}
public getItemByIndex(index: number): ItemDefBase | undefined {
return this._itemList.items[index];
}
public get itemCount(): number {
return this._itemList.items.length;
}
public override execute(): void {}
}