|
15 | 15 | */
|
16 | 16 |
|
17 | 17 | import React from 'react';
|
18 |
| -import { createDevApp } from '@backstage/dev-utils'; |
| 18 | +import { createDevApp, DevAppPageOptions } from '@backstage/dev-utils'; |
| 19 | +import AddIcon from '@mui/icons-material/Add'; |
| 20 | +import GitIcon from '@mui/icons-material/GitHub'; |
| 21 | +import MenuIcon from '@mui/icons-material/Menu'; |
| 22 | +import { GitHubIcon } from '@backstage/core-components'; |
| 23 | +import { ScalprumContext, ScalprumState } from '@scalprum/react-core'; |
| 24 | +import { PluginStore } from '@openshift/dynamic-plugin-sdk'; |
| 25 | + |
19 | 26 | import { ExampleComponent } from './ExampleComponent/ExampleComponent';
|
| 27 | +import { |
| 28 | + DynamicGlobalFloatingActionButton, |
| 29 | + FloatingActionButton, |
| 30 | + Slot, |
| 31 | +} from '../src'; |
| 32 | + |
| 33 | +const mockFloatingButtons: FloatingActionButton[] = [ |
| 34 | + { |
| 35 | + color: 'success', |
| 36 | + icon: <GitIcon />, |
| 37 | + label: 'Git repo', |
| 38 | + showLabel: true, |
| 39 | + to: 'https://github.com/xyz', |
| 40 | + toolTip: 'Git', |
| 41 | + }, |
| 42 | + |
| 43 | + { |
| 44 | + color: 'info', |
| 45 | + label: 'Quay', |
| 46 | + to: 'https://quay.io', |
| 47 | + toolTip: 'Quay', |
| 48 | + icon: '<svg viewBox="0 0 250 300" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid"><path d="M200.134 0l55.555 117.514-55.555 117.518h-47.295l55.555-117.518L152.84 0h47.295zM110.08 99.836l20.056-38.092-2.29-8.868L102.847 0H55.552l48.647 102.898 5.881-3.062zm17.766 74.433l-17.333-39.034-6.314-3.101-48.647 102.898h47.295l25-52.88v-7.883z" fill="#40B4E5"/><path d="M152.842 235.032L97.287 117.514 152.842 0h47.295l-55.555 117.514 55.555 117.518h-47.295zm-97.287 0L0 117.514 55.555 0h47.296L47.295 117.514l55.556 117.518H55.555z" fill="#003764"/></svg>', |
| 49 | + }, |
| 50 | + { |
| 51 | + slot: Slot.BOTTOM_LEFT, |
| 52 | + color: 'success', |
| 53 | + icon: <AddIcon />, |
| 54 | + label: 'Add', |
| 55 | + toolTip: 'Add', |
| 56 | + to: '/test-global-floating-action', |
| 57 | + priority: 100, |
| 58 | + }, |
| 59 | + { |
| 60 | + slot: Slot.BOTTOM_LEFT, |
| 61 | + color: 'success', |
| 62 | + label: 'Github', |
| 63 | + icon: <GitHubIcon />, |
| 64 | + toolTip: 'Github', |
| 65 | + to: 'https://github.com/xyz', |
| 66 | + priority: 200, |
| 67 | + visibleOnPaths: ['/test-global-floating-action'], |
| 68 | + }, |
| 69 | + { |
| 70 | + color: 'success', |
| 71 | + icon: <MenuIcon />, |
| 72 | + label: 'Menu', |
| 73 | + toolTip: 'Menu', |
| 74 | + to: 'https://github.com/xyz', |
| 75 | + priority: 200, |
| 76 | + excludeOnPaths: ['/test-global-floating-action'], |
| 77 | + }, |
| 78 | +]; |
| 79 | + |
| 80 | +const createPage = ({ |
| 81 | + navTitle, |
| 82 | + path, |
| 83 | + component, |
| 84 | +}: { |
| 85 | + navTitle: string; |
| 86 | + component: React.ReactElement; |
| 87 | + pageTitle: string; |
| 88 | + path: string; |
| 89 | +}): DevAppPageOptions => { |
| 90 | + const scalprumState: ScalprumState = { |
| 91 | + initialized: true, |
| 92 | + api: { |
| 93 | + dynamicRootConfig: { |
| 94 | + mountPoints: { |
| 95 | + 'global.floatingactionbutton/component': [ |
| 96 | + { |
| 97 | + staticJSXContent: null, |
| 98 | + config: { |
| 99 | + color: 'success', |
| 100 | + icon: 'github', |
| 101 | + label: 'DP: Git repo', |
| 102 | + showLabel: true, |
| 103 | + to: 'https://github.com/xyz', |
| 104 | + toolTip: 'Git', |
| 105 | + }, |
| 106 | + }, |
| 107 | + { |
| 108 | + staticJSXContent: null, |
| 109 | + config: { |
| 110 | + color: 'info', |
| 111 | + label: 'Quay', |
| 112 | + to: 'https://quay.io', |
| 113 | + toolTip: 'Quay', |
| 114 | + icon: '<svg viewBox="0 0 250 300" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid"><path d="M200.134 0l55.555 117.514-55.555 117.518h-47.295l55.555-117.518L152.84 0h47.295zM110.08 99.836l20.056-38.092-2.29-8.868L102.847 0H55.552l48.647 102.898 5.881-3.062zm17.766 74.433l-17.333-39.034-6.314-3.101-48.647 102.898h47.295l25-52.88v-7.883z" fill="#40B4E5"/><path d="M152.842 235.032L97.287 117.514 152.842 0h47.295l-55.555 117.514 55.555 117.518h-47.295zm-97.287 0L0 117.514 55.555 0h47.296L47.295 117.514l55.556 117.518H55.555z" fill="#003764"/></svg>', |
| 115 | + }, |
| 116 | + }, |
| 117 | + { |
| 118 | + staticJSXContent: null, |
| 119 | + config: { |
| 120 | + slot: 'bottom-left', |
| 121 | + color: 'success', |
| 122 | + label: 'Github', |
| 123 | + icon: 'github', |
| 124 | + toolTip: 'Github', |
| 125 | + to: 'https://github.com/xyz', |
| 126 | + priority: 200, |
| 127 | + visibleOnPaths: ['/test-global-floating-action-3'], |
| 128 | + }, |
| 129 | + }, |
| 130 | + ], |
| 131 | + }, |
| 132 | + }, |
| 133 | + }, |
| 134 | + config: {}, |
| 135 | + pluginStore: new PluginStore(), |
| 136 | + }; |
| 137 | + |
| 138 | + const pageContent = ( |
| 139 | + <ScalprumContext.Provider value={scalprumState}> |
| 140 | + <DynamicGlobalFloatingActionButton /> |
| 141 | + {component} |
| 142 | + </ScalprumContext.Provider> |
| 143 | + ); |
| 144 | + |
| 145 | + return { |
| 146 | + element: pageContent, |
| 147 | + title: navTitle, |
| 148 | + path, |
| 149 | + }; |
| 150 | +}; |
20 | 151 |
|
21 | 152 | createDevApp()
|
22 | 153 | .addPage({
|
23 |
| - element: <ExampleComponent />, |
| 154 | + element: <ExampleComponent floatingButtons={mockFloatingButtons} />, |
24 | 155 | title: 'Page 1',
|
25 | 156 | path: '/test-global-floating-action',
|
26 | 157 | })
|
27 | 158 | .addPage({
|
28 |
| - element: <ExampleComponent />, |
| 159 | + element: <ExampleComponent floatingButtons={mockFloatingButtons} />, |
29 | 160 | title: 'Page 2',
|
30 | 161 | path: '/test-global-floating-action-2',
|
31 | 162 | })
|
| 163 | + .addPage( |
| 164 | + createPage({ |
| 165 | + navTitle: 'Page 3', |
| 166 | + pageTitle: 'Page 3', |
| 167 | + path: '/test-global-floating-action-3', |
| 168 | + component: <ExampleComponent />, |
| 169 | + }), |
| 170 | + ) |
| 171 | + .addPage( |
| 172 | + createPage({ |
| 173 | + navTitle: 'Page 4', |
| 174 | + pageTitle: 'Page 4', |
| 175 | + path: '/test-global-floating-action-4', |
| 176 | + component: <ExampleComponent />, |
| 177 | + }), |
| 178 | + ) |
32 | 179 | .render();
|
0 commit comments