|
| 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; |
0 commit comments