UNPKG

2.5 kBTypeScriptView Raw
1/*
2 * Copyright 2016 Palantir Technologies, Inc. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17import classNames from "classnames";
18import * as React from "react";
19
20import * as Classes from "../../common/classes";
21import { ActionProps, LinkProps } from "../../common/props";
22import { Icon } from "../icon/icon";
23
24// eslint-disable-next-line deprecation/deprecation
25export type BreadcrumbProps = IBreadcrumbProps;
26/** @deprecated use BreadcrumbProps */
27export interface IBreadcrumbProps extends ActionProps, LinkProps {
28 /** Whether this breadcrumb is the current breadcrumb. */
29 current?: boolean;
30
31 /**
32 * Pass through value to icon's title attribute. Should be used for breadcrumbs without
33 * text or children defined.
34 */
35 iconTitle?: string;
36}
37
38export 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};