1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | import classNames from "classnames";
|
18 | import * as React from "react";
|
19 |
|
20 | import * as Classes from "../../common/classes";
|
21 | import { ActionProps, LinkProps } from "../../common/props";
|
22 | import { Icon } from "../icon/icon";
|
23 |
|
24 |
|
25 | export type BreadcrumbProps = IBreadcrumbProps;
|
26 |
|
27 | export interface IBreadcrumbProps extends ActionProps, LinkProps {
|
28 |
|
29 | current?: boolean;
|
30 |
|
31 | |
32 |
|
33 |
|
34 |
|
35 | iconTitle?: string;
|
36 | }
|
37 |
|
38 | export const Breadcrumb: React.FunctionComponent<BreadcrumbProps> = breadcrumbProps => {
|
39 | const classes = classNames(
|
40 | Classes.BREADCRUMB,
|
41 | {
|
42 | [Classes.BREADCRUMB_CURRENT]: breadcrumbProps.current,
|
43 | [Classes.DISABLED]: breadcrumbProps.disabled,
|
44 | },
|
45 | breadcrumbProps.className,
|
46 | );
|
47 |
|
48 | const icon =
|
49 | breadcrumbProps.icon != null ? (
|
50 | <Icon title={breadcrumbProps.iconTitle} icon={breadcrumbProps.icon} />
|
51 | ) : undefined;
|
52 |
|
53 | if (breadcrumbProps.href == null && breadcrumbProps.onClick == null) {
|
54 | return (
|
55 | <span className={classes}>
|
56 | {icon}
|
57 | {breadcrumbProps.text}
|
58 | {breadcrumbProps.children}
|
59 | </span>
|
60 | );
|
61 | }
|
62 | return (
|
63 | <a
|
64 | className={classes}
|
65 | href={breadcrumbProps.href}
|
66 | onClick={breadcrumbProps.disabled ? undefined : breadcrumbProps.onClick}
|
67 | tabIndex={breadcrumbProps.disabled ? undefined : 0}
|
68 | target={breadcrumbProps.target}
|
69 | >
|
70 | {icon}
|
71 | {breadcrumbProps.text}
|
72 | {breadcrumbProps.children}
|
73 | </a>
|
74 | );
|
75 | };
|