Merge pull request #8923 from kuangp/feat/shortcutIcon

feat(shortcuts): make sidebar item icon configurable
This commit is contained in:
Fredrik Adelöw
2022-01-17 18:34:45 +01:00
committed by GitHub
4 changed files with 26 additions and 4 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-shortcuts': patch
---
Allow shortcut side bar item icon to be configurable
+8 -1
View File
@@ -7,6 +7,7 @@
import { ApiRef } from '@backstage/core-plugin-api';
import { BackstagePlugin } from '@backstage/core-plugin-api';
import { IconComponent } from '@backstage/core-plugin-api';
import { Observable } from '@backstage/types';
import ObservableImpl from 'zen-observable';
import { StorageApi } from '@backstage/core-plugin-api';
@@ -51,7 +52,7 @@ export interface ShortcutApi {
// Warning: (ae-missing-release-tag) "Shortcuts" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export const Shortcuts: () => JSX.Element;
export const Shortcuts: (props: ShortcutsProps) => JSX.Element;
// Warning: (ae-missing-release-tag) "shortcutsApiRef" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
@@ -62,4 +63,10 @@ export const shortcutsApiRef: ApiRef<ShortcutApi>;
//
// @public (undocumented)
export const shortcutsPlugin: BackstagePlugin<{}, {}>;
// @public
export interface ShortcutsProps {
// (undocumented)
icon?: IconComponent;
}
```
+12 -3
View File
@@ -26,9 +26,18 @@ import {
SidebarItem,
SidebarScrollWrapper,
} from '@backstage/core-components';
import { useApi } from '@backstage/core-plugin-api';
import { IconComponent, useApi } from '@backstage/core-plugin-api';
export const Shortcuts = () => {
/**
* ShortcutsProps
* Props for the {@link Shortcuts} component.
* @public
*/
export interface ShortcutsProps {
icon?: IconComponent;
}
export const Shortcuts = (props: ShortcutsProps) => {
const shortcutApi = useApi(shortcutsApiRef);
const shortcuts = useObservable(
useMemo(() => shortcutApi.shortcut$(), [shortcutApi]),
@@ -47,7 +56,7 @@ export const Shortcuts = () => {
return (
<SidebarScrollWrapper>
<SidebarItem
icon={PlayListAddIcon}
icon={props.icon ?? PlayListAddIcon}
text="Add Shortcuts"
onClick={handleClick}
/>
+1
View File
@@ -23,3 +23,4 @@
export { shortcutsPlugin, Shortcuts } from './plugin';
export * from './api';
export type { Shortcut } from './types';
export type { ShortcutsProps } from './Shortcuts';