-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor breadcrumbs, introduces Breadcrumbs Service and Contribution
Signed-off-by: Cornelius A. Ludmann <cornelius.ludmann@typefox.io>
- Loading branch information
1 parent
e35e597
commit 03eb644
Showing
28 changed files
with
898 additions
and
508 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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,24 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2019 TypeFox and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import { Disposable } from '../../common/disposable'; | ||
|
||
export interface BreadcrumbPopup extends Disposable { | ||
|
||
breadcrumbId: string | ||
|
||
isOpen: boolean | ||
} |
42 changes: 42 additions & 0 deletions
42
packages/core/src/browser/breadcrumbs/breadcrumb-renderer.tsx
This file contains 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,42 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2019 TypeFox and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import * as React from 'react'; | ||
import { injectable } from 'inversify'; | ||
import { Breadcrumb } from './breadcrumb'; | ||
import { Breadcrumbs } from './breadcrumbs'; | ||
|
||
export const BreadcrumbRenderer = Symbol('BreadcrumbRenderer'); | ||
export interface BreadcrumbRenderer { | ||
/** | ||
* Renders the given breadcrumb. If `onClick` is given, it is called on breadcrumb click. | ||
*/ | ||
render(breadcrumb: Breadcrumb, onClick?: (breadcrumb: Breadcrumb, event: React.MouseEvent) => void): React.ReactNode; | ||
} | ||
|
||
@injectable() | ||
export class DefaultBreadcrumbRenderer implements BreadcrumbRenderer { | ||
render(breadcrumb: Breadcrumb, onClick?: (breadcrumb: Breadcrumb, event: React.MouseEvent) => void): React.ReactNode { | ||
return <li key={breadcrumb.id} title={breadcrumb.longLabel} | ||
className={Breadcrumbs.Styles.BREADCRUMB_ITEM + (!onClick ? '' : ' ' + Breadcrumbs.Styles.BREADCRUMB_ITEM_HAS_POPUP)} | ||
onClick={event => onClick && onClick(breadcrumb, event)} | ||
tabIndex={0} | ||
data-breadcrumb-id={breadcrumb.id} | ||
> | ||
{breadcrumb.iconClass && <span className={breadcrumb.iconClass}></span>} <span> {breadcrumb.label}</span> | ||
</li >; | ||
} | ||
} |
This file contains 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,34 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2019 TypeFox and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
/** A single breadcrumb in the breadcrumbs bar. */ | ||
export interface Breadcrumb { | ||
|
||
/** An ID of this breadcrumb that should be unique in the breadcrumbs bar. */ | ||
id: string | ||
|
||
/** The breadcrumb type. Should be the same as the contribution type `BreadcrumbsContribution#type`. */ | ||
type: symbol | ||
|
||
/** The text that will be rendered as label. */ | ||
label: string | ||
|
||
/** A longer text that will be used as tooltip text. */ | ||
longLabel: string | ||
|
||
/** A CSS class for the icon. */ | ||
iconClass?: string | ||
} |
44 changes: 44 additions & 0 deletions
44
packages/core/src/browser/breadcrumbs/breadcrumbs-contribution.ts
This file contains 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,44 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2019 TypeFox and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import URI from '../../common/uri'; | ||
import { Breadcrumb } from './breadcrumb'; | ||
import { BreadcrumbPopup } from './breadcrumb-popup'; | ||
|
||
export const BreadcrumbsContribution = Symbol('BreadcrumbsContribution'); | ||
export interface BreadcrumbsContribution { | ||
|
||
/** | ||
* The breadcrumb type. Breadcrumbs returned by `#computeBreadcrumbs(uri)` should have this as `Breadcrumb#type`. | ||
*/ | ||
type: symbol; | ||
|
||
/** | ||
* The priority of this breadcrumbs contribution. Contributions with lower priority are rendered first. | ||
*/ | ||
priority: number; | ||
|
||
/** | ||
* Computes breadcrumbs for a given URI. | ||
*/ | ||
computeBreadcrumbs(uri: URI): Promise<Breadcrumb[]>; | ||
|
||
/** | ||
* Opens the breadcrumb popup for the given breadcrumb at the given position. | ||
* Parent is used as host element. | ||
*/ | ||
openPopup(breadcrumb: Breadcrumb, position: { x: number, y: number }, parent: HTMLElement): Promise<BreadcrumbPopup | undefined>; | ||
} |
Oops, something went wrong.