-
Notifications
You must be signed in to change notification settings - Fork 2
/
ActionButtonList.tsx
73 lines (66 loc) · 2.3 KB
/
ActionButtonList.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
/*---------------------------------------------------------------------------------------------
* 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 "./ActionButtonList.scss";
import * as React from "react";
import type { PropertyRecord } from "@itwin/appui-abstract";
import { Orientation } from "@itwin/core-react";
import type {
ActionButtonRenderer,
ActionButtonRendererProps,
} from "./ActionButtonRenderer";
/** Properties of [[ActionButtonList]] React component
* @public
*/
export interface ActionButtonListProps {
/** Orientation to use for displaying the action buttons */
orientation: Orientation;
/** Property that action buttons belong to */
property: PropertyRecord;
/** Array of action button renderers */
actionButtonRenderers: ActionButtonRenderer[];
/** Indicated whether a property is hovered */
isPropertyHovered?: boolean;
}
/** ActionButtonList React component.
* @public
*/
export class ActionButtonList extends React.PureComponent<ActionButtonListProps> {
private getClassName(orientation: Orientation) {
return orientation === Orientation.Horizontal
? "components-property-action-button-list--horizontal"
: "components-property-action-button-list--vertical";
}
/** @internal */
public override render() {
return (
<div className={this.getClassName(this.props.orientation)}>
{this.props.actionButtonRenderers.map((renderer, index) => (
<ActionButtonContainer
key={index}
renderer={renderer}
rendererProps={{
property: this.props.property,
isPropertyHovered: this.props.isPropertyHovered,
}}
/>
))}
</div>
);
}
}
interface ActionButtonContainerProps {
renderer: ActionButtonRenderer;
rendererProps: ActionButtonRendererProps;
}
function ActionButtonContainer(props: ActionButtonContainerProps) {
const actionButton = props.renderer(props.rendererProps);
if (!actionButton) return null;
return (
<div className="components-action-button-container">{actionButton}</div>
);
}