-
Notifications
You must be signed in to change notification settings - Fork 2.3k
[draft] BreadcrumbsNext #8082
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
Draft
cameronjoyner
wants to merge
5
commits into
develop
Choose a base branch
from
cj/breadcrumbs-next-2
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+252
−0
Draft
[draft] BreadcrumbsNext #8082
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
packages/core/src/components/breadcrumbs-next/BreadcrumbsNext.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| /* | ||
| * (c) Copyright 2026 Palantir Technologies Inc. All rights reserved. | ||
| */ | ||
|
|
||
| import type { Meta, StoryObj } from "@storybook/react-vite"; | ||
| import { storybookLayoutDecorator } from "@storybook-common"; | ||
| import React from "react"; | ||
|
|
||
| import { Boundary } from "../../common/boundary"; | ||
| import type { BreadcrumbProps } from "../breadcrumbs/breadcrumb"; | ||
|
|
||
| import { BreadcrumbsNext } from "./breadcrumbsNext"; | ||
|
|
||
| const SAMPLE_ITEMS: BreadcrumbProps[] = [ | ||
| { text: "Home", href: "#", icon: "home" }, | ||
| { text: "Projects", href: "#", icon: "projects" }, | ||
| { text: "Blueprint", href: "#" }, | ||
| { text: "Components", href: "#" }, | ||
| { text: "Breadcrumbs" }, | ||
| ]; | ||
|
|
||
| type StoryArgs = React.ComponentProps<typeof BreadcrumbsNext> & { width?: number }; | ||
|
|
||
| const meta: Meta<StoryArgs> = { | ||
| title: "Core/BreadcrumbsNext", | ||
| component: BreadcrumbsNext, | ||
| decorators: [storybookLayoutDecorator], | ||
| tags: ["autodocs"], | ||
| args: { | ||
| items: SAMPLE_ITEMS, | ||
| collapseFrom: Boundary.START, | ||
| width: 400, | ||
| }, | ||
| argTypes: { | ||
| collapseFrom: { | ||
| control: "select", | ||
| options: Object.values(Boundary), | ||
| }, | ||
| minVisibleItems: { | ||
| control: "number", | ||
| }, | ||
| width: { control: { type: "range", min: 100, max: 800, step: 10 } }, | ||
| }, | ||
| } satisfies Meta<StoryArgs>; | ||
|
|
||
| export default meta; | ||
| type Story = StoryObj<typeof meta>; | ||
|
|
||
| /** | ||
| * A basic breadcrumbs component with default styling. Adjust the width slider to see overflow behavior. | ||
| */ | ||
| export const Default: Story = { | ||
| render: ({ width, ...args }) => ( | ||
| <div style={{ width }}> | ||
| <BreadcrumbsNext {...args} /> | ||
| </div> | ||
| ), | ||
| }; | ||
|
|
||
| /** | ||
| * Interactive playground with all props toggleable via Storybook controls. | ||
| */ | ||
| export const Playground: Story = { | ||
| args: { | ||
| items: SAMPLE_ITEMS, | ||
| collapseFrom: Boundary.START, | ||
| minVisibleItems: 0, | ||
| }, | ||
| render: ({ width, ...args }) => ( | ||
| <div style={{ width }}> | ||
| <BreadcrumbsNext {...args} /> | ||
| </div> | ||
| ), | ||
| }; |
177 changes: 177 additions & 0 deletions
177
packages/core/src/components/breadcrumbs-next/breadcrumbsNext.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,177 @@ | ||
| /* | ||
| * Copyright 2026 Palantir Technologies, Inc. All rights reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import classNames from "classnames"; | ||
| import { memo, useCallback } from "react"; | ||
|
|
||
| import { Boundary, Classes, DISPLAYNAME_PREFIX, type Props, removeNonHTMLProps } from "../../common"; | ||
| import { Breadcrumb, type BreadcrumbProps } from "../breadcrumbs/breadcrumb"; | ||
| import { Menu } from "../menu/menu"; | ||
| import { MenuItem } from "../menu/menuItem"; | ||
| import { OverflowList, type OverflowListProps } from "../overflow-list/overflowList"; | ||
| import { PopoverNext } from "../popover-next/popoverNext"; | ||
|
|
||
| const EMPTY_ITEMS: readonly BreadcrumbProps[] = []; | ||
|
|
||
| export interface BreadcrumbsNextProps extends Props { | ||
| /** | ||
| * Callback invoked to render visible breadcrumbs. Best practice is to | ||
| * render a `<Breadcrumb>` element. If `currentBreadcrumbRenderer` is also | ||
| * supplied, that callback will be used for the current breadcrumb instead. | ||
| * | ||
| * @default Breadcrumb | ||
| */ | ||
| breadcrumbRenderer?: (props: BreadcrumbProps) => React.JSX.Element; | ||
|
|
||
| /** | ||
| * Which direction the breadcrumbs should collapse from: start or end. | ||
| * | ||
| * @default Boundary.START | ||
| */ | ||
| collapseFrom?: Boundary; | ||
|
|
||
| /** | ||
| * Callback invoked to render the current breadcrumb, which is the last | ||
| * element in the `items` array. | ||
| * | ||
| * If this prop is omitted, `breadcrumbRenderer` will be invoked for the | ||
| * current breadcrumb instead. | ||
| */ | ||
| currentBreadcrumbRenderer?: (props: BreadcrumbProps) => React.JSX.Element; | ||
|
|
||
| /** | ||
| * All breadcrumbs to display. Breadcrumbs that do not fit in the container | ||
| * will be rendered in an overflow menu instead. | ||
| * | ||
| * @default [] | ||
| */ | ||
| items?: readonly BreadcrumbProps[]; | ||
|
|
||
| /** | ||
| * The minimum number of visible breadcrumbs that should never collapse into | ||
| * the overflow menu, regardless of DOM dimensions. | ||
| * | ||
| * @default 0 | ||
| */ | ||
| minVisibleItems?: number; | ||
|
|
||
| /** | ||
| * Props to spread to the `OverflowList` popover target. | ||
| */ | ||
| overflowButtonProps?: React.HTMLProps<HTMLSpanElement>; | ||
|
|
||
| /** | ||
| * Props to spread to `OverflowList`. Note that `items`, | ||
| * `overflowRenderer`, and `visibleItemRenderer` cannot be changed. | ||
| */ | ||
| overflowListProps?: Partial< | ||
| Omit<OverflowListProps<BreadcrumbProps>, "items" | "overflowRenderer" | "visibleItemRenderer"> | ||
| >; | ||
| } | ||
|
|
||
| /** | ||
| * BreadcrumbsNext component. | ||
| * | ||
| * Uses PopoverNext (Floating UI) for the overflow menu instead of Popover (Popper.js). | ||
| * Does not expose popover configuration props, making it forward-compatible with | ||
| * future popover implementation changes. | ||
| * | ||
| * @see https://blueprintjs.com/docs/#core/components/breadcrumbs | ||
| */ | ||
| export const BreadcrumbsNext: React.FC<BreadcrumbsNextProps> = memo(props => { | ||
| const { | ||
| breadcrumbRenderer, | ||
| className, | ||
| collapseFrom = Boundary.START, | ||
| currentBreadcrumbRenderer, | ||
| items = EMPTY_ITEMS, | ||
| minVisibleItems = 0, | ||
| overflowButtonProps, | ||
| overflowListProps = {}, | ||
| } = props; | ||
|
|
||
| const renderBreadcrumb = useCallback( | ||
| (breadcrumbProps: BreadcrumbProps, isCurrent: boolean) => { | ||
| if (isCurrent && currentBreadcrumbRenderer != null) { | ||
| return currentBreadcrumbRenderer(breadcrumbProps); | ||
| } else if (breadcrumbRenderer != null) { | ||
| return breadcrumbRenderer(breadcrumbProps); | ||
| } else { | ||
| return <Breadcrumb current={isCurrent} {...breadcrumbProps} />; | ||
| } | ||
| }, | ||
| [breadcrumbRenderer, currentBreadcrumbRenderer], | ||
| ); | ||
|
|
||
| const renderBreadcrumbWrapper = useCallback( | ||
| (breadcrumbProps: BreadcrumbProps, index: number) => { | ||
| const isCurrent = items[items.length - 1] === breadcrumbProps; | ||
| return <li key={index}>{renderBreadcrumb(breadcrumbProps, isCurrent)}</li>; | ||
| }, | ||
| [items, renderBreadcrumb], | ||
| ); | ||
|
|
||
| const renderOverflowBreadcrumb = useCallback((breadcrumbProps: BreadcrumbProps, index: number) => { | ||
| const isClickable = breadcrumbProps.href != null || breadcrumbProps.onClick != null; | ||
| const htmlProps = removeNonHTMLProps(breadcrumbProps); | ||
| return <MenuItem disabled={!isClickable} {...htmlProps} text={breadcrumbProps.text} key={index} />; | ||
| }, []); | ||
|
|
||
| const renderOverflow = useCallback( | ||
| (overflowItems: readonly BreadcrumbProps[]) => { | ||
| let orderedItems = overflowItems; | ||
| if (collapseFrom === Boundary.START) { | ||
| orderedItems = overflowItems.slice().reverse(); | ||
| } | ||
|
|
||
| return ( | ||
| <li> | ||
| <PopoverNext | ||
| content={<Menu>{orderedItems.map(renderOverflowBreadcrumb)}</Menu>} | ||
| disabled={orderedItems.length === 0} | ||
| placement={collapseFrom === Boundary.END ? "bottom-end" : "bottom-start"} | ||
| > | ||
| <span | ||
| aria-label="collapsed breadcrumbs" | ||
| role="button" | ||
| tabIndex={0} | ||
| {...overflowButtonProps} | ||
| className={classNames(Classes.BREADCRUMBS_COLLAPSED, overflowButtonProps?.className)} | ||
| /> | ||
| </PopoverNext> | ||
| </li> | ||
| ); | ||
| }, | ||
| [collapseFrom, overflowButtonProps, renderOverflowBreadcrumb], | ||
| ); | ||
|
|
||
| return ( | ||
| <OverflowList | ||
| collapseFrom={collapseFrom} | ||
| minVisibleItems={minVisibleItems} | ||
| tagName="ol" | ||
| navigable={true} | ||
| navigationAriaLabel="Breadcrumb" | ||
| {...overflowListProps} | ||
| className={classNames(Classes.BREADCRUMBS, overflowListProps.className, className)} | ||
| items={items} | ||
| overflowRenderer={renderOverflow} | ||
| visibleItemRenderer={renderBreadcrumbWrapper} | ||
| /> | ||
| ); | ||
| }); | ||
|
|
||
| BreadcrumbsNext.displayName = `${DISPLAYNAME_PREFIX}.BreadcrumbsNext`; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only difference