-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathApplicationTitle.tsx
More file actions
84 lines (78 loc) · 2.79 KB
/
Copy pathApplicationTitle.tsx
File metadata and controls
84 lines (78 loc) · 2.79 KB
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
import React from "react";
import { HeaderName as CarbonHeaderName, HeaderNameProps as CarbonHeaderNameProps } from "@carbon/react";
import { CLASSPREFIX as eccgui } from "../../configuration/constants";
type SvgDepiction = HTMLElement & SVGElement;
type ImgDepiction = HTMLElement & HTMLImageElement;
export type ApplicationTitleProps = CarbonHeaderNameProps<"a"> & {
/**
application logo, <img>, <svg> or react element
*/
depiction?: ImgDepiction | SvgDepiction | React.ReactNode;
/**
is the application title visually displayed or not
*/
isNotDisplayed?: boolean;
/**
if displayed, is the width aligned with displayed sidebar navigation
*/
isAlignedWithSidebar?: boolean;
/**
is the sidebar navigation currently displayed or not
*/
isApplicationSidebarExpanded: boolean;
/**
native attributes for the anchor HTML element (<a>)
*/
htmlAProps?: React.AnchorHTMLAttributes<HTMLAnchorElement>;
};
export const ApplicationTitle = ({
children,
className = "",
prefix = "",
href,
depiction,
isNotDisplayed = false,
isAlignedWithSidebar = false,
isApplicationSidebarExpanded,
htmlAProps,
...otherCarbonHeaderNameProps
}: ApplicationTitleProps) => {
const classApplication = `${eccgui}-application__title`;
const classNotDisplayed =
isNotDisplayed || (!isApplicationSidebarExpanded && typeof isNotDisplayed === "undefined")
? "cds--visually-hidden"
: "";
const classAlignedSidebar =
isAlignedWithSidebar || isApplicationSidebarExpanded ? `${eccgui}-application__title--withsidebar` : "";
return (
<CarbonHeaderName
{...otherCarbonHeaderNameProps}
{...htmlAProps}
className={`${classApplication} ${classAlignedSidebar} ${classNotDisplayed} ${className}`}
href={href}
prefix=""
>
<span className={`${eccgui}-application__title--content`}>
{!!depiction && (
<>
<span className={`${eccgui}-application__title--depiction`}>
{React.isValidElement(depiction)
? depiction
: depiction instanceof HTMLElement
? <>{depiction.outerHTML}</>
: depiction}
</span>
</>
)}
{!!prefix && (
<>
<span className="cds--header__name--prefix">{prefix}</span>
</>
)}
{children}
</span>
</CarbonHeaderName>
);
};
export default ApplicationTitle;