Skip to content

Commit 52bd09a

Browse files
committed
add NotAvailable component
1 parent 47395f9 commit 52bd09a

2 files changed

Lines changed: 70 additions & 0 deletions

File tree

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import React from "react";
2+
3+
import {
4+
CLASSPREFIX as eccgui,
5+
Tag,
6+
TagProps,
7+
Tooltip,
8+
TooltipProps,
9+
} from "../../../index";
10+
import { TestableComponent } from "../interfaces";
11+
export interface NotAvailableProps extends TestableComponent, Pick<TagProps, "icon" | "className">, Pick<TooltipProps, "intent"> {
12+
/**
13+
* Text displayed by the element.
14+
*/
15+
label?: TagProps["children"];
16+
/**
17+
* Add a tooltip to the element.
18+
* You need to set an empty string `""` to remove it.
19+
*/
20+
tooltip?: TooltipProps["content"];
21+
/**
22+
* Specify the display of the used `Tag` component.
23+
*/
24+
tagProps?: Omit<TagProps, "icon" | "intent" | "children">;
25+
/**
26+
* Specify the display of the used `Tooltip` component.
27+
*/
28+
tooltipProps?: Omit<TooltipProps, "content" | "intent" | "children">;
29+
/**
30+
* Do not use the `Tag` component for the display.
31+
* The `intent` state can be displayed only on the tooltip then.
32+
*/
33+
noTag?: boolean;
34+
}
35+
36+
/**
37+
* Simple placeholder element that can be used to display info about missing data.
38+
*/
39+
export const NotAvailable = ({
40+
label = "n/a",
41+
tooltip = "not available",
42+
icon,
43+
intent,
44+
tagProps,
45+
tooltipProps,
46+
className,
47+
noTag = false,
48+
...otherProps
49+
}: NotAvailableProps) => {
50+
const defaultTagProps : TagProps = { icon, intent, emphasis: "weaker", className: `${eccgui}-notavailable` + className ? ` ${className}` : "" };
51+
const naElement = noTag === false ? (
52+
<Tag
53+
{...defaultTagProps}
54+
{...tagProps}
55+
{...otherProps}
56+
>
57+
{ label ?? "n/a"}
58+
</Tag>
59+
) : <>{ label ?? "n/a"}</>;
60+
const defaultTooltipProps : TooltipProps = {
61+
children: naElement,
62+
content: tooltip,
63+
intent,
64+
};
65+
66+
return tooltip ? <Tooltip {...defaultTooltipProps} {...tooltipProps} /> : naElement;
67+
};
68+
69+
export default NotAvailable;

src/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export * from "./Link/Link";
2323
export * from "./List/List";
2424
export * from "./Menu";
2525
export * from "./MultiSuggestField";
26+
export * from "./NotAvailable/NotAvailable";
2627
export * from "./Notification";
2728
export * from "./OverviewItem";
2829
export * from "./Pagination/Pagination";

0 commit comments

Comments
 (0)