-
Notifications
You must be signed in to change notification settings - Fork 2
/
PropertyLabelRenderer.tsx
52 lines (48 loc) · 1.65 KB
/
PropertyLabelRenderer.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
/*---------------------------------------------------------------------------------------------
* 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 "./PropertyLabelRenderer.scss";
import * as React from "react";
/** Base properties for a property label renderer
* @public
*/
export interface PropertyLabelRendererProps {
/** Label to be rendered */
children: string | React.ReactElement;
/** Indicates whether to render a colon after the label */
renderColon?: boolean;
/** Custom tooltip for the component. */
tooltip?: string;
}
/** @internal */
export class PropertyLabelRenderer extends React.PureComponent<PropertyLabelRendererProps> {
/** Get React CSS style object based on provided offset from the left side */
public static getStyle(offset?: number): React.CSSProperties {
offset = offset ? offset : 0;
return {
paddingLeft: offset,
width: `calc(100% - ${offset}px)`,
};
}
public override render() {
const title =
this.props.tooltip ??
(typeof this.props.children == "string"
? this.props.children
: /* istanbul ignore next */ undefined);
return (
<>
<span className="components-property-label-renderer" title={title}>
{this.props.children}
</span>
{this.props.renderColon ? (
<span className="components-property-label-renderer-colon">:</span>
) : undefined}
</>
);
}
}