Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] feat(Breadcrumb): render icon if provided through props #3786

Merged
merged 3 commits into from
Nov 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/core/src/components/breadcrumbs/_breadcrumbs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ Styleguide breadcrumbs
.#{$ns}-breadcrumb,
.#{$ns}-breadcrumb-current,
.#{$ns}-breadcrumbs-collapsed {
display: inline-block;
display: inline-flex;
align-items: center;
font-size: $pt-font-size-large;
}

Expand All @@ -71,6 +72,10 @@ Styleguide breadcrumbs
cursor: not-allowed;
color: $pt-text-color-disabled;
}

.#{$ns}-icon {
margin-right: $pt-grid-size / 2;
}
}

.#{$ns}-breadcrumb-current {
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/components/breadcrumbs/breadcrumb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import * as React from "react";

import * as Classes from "../../common/classes";
import { IActionProps, ILinkProps } from "../../common/props";
import { Icon } from "../icon/icon";

export interface IBreadcrumbProps extends IActionProps, ILinkProps {
/** Whether this breadcrumb is the current breadcrumb. */
Expand All @@ -34,9 +35,13 @@ export const Breadcrumb: React.SFC<IBreadcrumbProps> = breadcrumbProps => {
},
breadcrumbProps.className,
);

const icon = breadcrumbProps.icon != null ? <Icon icon={breadcrumbProps.icon} /> : undefined;

if (breadcrumbProps.href == null && breadcrumbProps.onClick == null) {
return (
<span className={classes}>
{icon}
{breadcrumbProps.text}
{breadcrumbProps.children}
</span>
Expand All @@ -50,6 +55,7 @@ export const Breadcrumb: React.SFC<IBreadcrumbProps> = breadcrumbProps => {
tabIndex={breadcrumbProps.disabled ? null : 0}
target={breadcrumbProps.target}
>
{icon}
{breadcrumbProps.text}
{breadcrumbProps.children}
</a>
Expand Down
7 changes: 6 additions & 1 deletion packages/core/test/breadcrumbs/breadcrumbTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { shallow } from "enzyme";
import * as React from "react";
import { spy } from "sinon";

import { Breadcrumb, Classes } from "../../src/index";
import { Breadcrumb, Classes, Icon } from "../../src/index";

describe("Breadcrumb", () => {
it("renders its contents", () => {
Expand Down Expand Up @@ -50,4 +50,9 @@ describe("Breadcrumb", () => {
assert.lengthOf(shallow(<Breadcrumb />).find("a"), 0);
assert.lengthOf(shallow(<Breadcrumb />).find("span"), 1);
});

it("renders an icon if one is provided", () => {
assert.lengthOf(shallow(<Breadcrumb />).find(Icon), 0);
assert.lengthOf(shallow(<Breadcrumb icon="folder-close" />).find(Icon), 1);
});
});