forked from openedx/frontend-app-admin-console
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuthZTitle.tsx
More file actions
87 lines (80 loc) · 2.43 KB
/
AuthZTitle.tsx
File metadata and controls
87 lines (80 loc) · 2.43 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
85
86
87
import {
ComponentType, isValidElement, ReactNode, Fragment,
} from 'react';
import { Link } from 'react-router-dom';
import {
Breadcrumb, Col, Container, Row, Button,
Stack,
useMediaQuery,
breakpoints,
} from '@openedx/paragon';
interface BreadcrumbLink {
label: string;
to?: string;
}
interface Action {
label: string;
icon?: ComponentType;
onClick: () => void;
}
export interface AuthZTitleProps {
activeLabel?: string;
pageTitle: string;
pageSubtitle: string | ReactNode;
navLinks?: BreadcrumbLink[];
actions?: (Action | ReactNode)[];
}
export const ActionButton = ({ label, icon, onClick }: Action) => (
<Button
iconBefore={icon}
onClick={onClick}
>
{label}
</Button>
);
const AuthZTitle = ({
activeLabel, navLinks = [], pageTitle, pageSubtitle, actions = [],
}: AuthZTitleProps) => {
const isDesktop = useMediaQuery({ minWidth: breakpoints.large.minWidth });
return (
<Container className="p-5 bg-light-100">
<Breadcrumb
linkAs={Link}
links={navLinks}
activeLabel={activeLabel}
/>
<Row className="mt-4">
<Col xs={12} md={7} className="mb-4">
<div className="d-flex align-items-center flex-column-sm">
<h2 className="text-primary mb-0">{pageTitle}</h2>
{typeof pageSubtitle === 'string'
? <> { pageSubtitle !== '' && <hr className="mx-lg-3" /> }<h3 className="mb-0 py-2 font-weight-light text-gray-700">{pageSubtitle}</h3></>
: <>{ pageSubtitle !== '' && <hr className="mx-lg-3" /> } <div className="mb-0">{pageSubtitle}</div></>}
</div>
</Col>
<Col xs={12} md={5}>
<Stack className="justify-content-end" direction={isDesktop ? 'horizontal' : 'vertical'}>
{
actions.map((action, index) => {
const content = isValidElement(action)
? action
: <ActionButton {...action as Action} />;
const key = isValidElement(action)
? action.key
: (action as Action).label;
return (
<Fragment key={`authz-header-action-${key}`}>
{content}
{(index === actions.length - 1) ? null
: (<hr className="mx-lg-5" />)}
</Fragment>
);
})
}
</Stack>
</Col>
</Row>
</Container>
);
};
export default AuthZTitle;