Skip to content

Commit f8f3321

Browse files
Add new web extensions and extension points (#670)
* docs(dev): add new web extensions and extension points * add new mode prop --------- Co-authored-by: Alexander Ackermann <abackermann91@gmail.com>
1 parent 612ff22 commit f8f3321

2 files changed

Lines changed: 82 additions & 2 deletions

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
title: 'Floating Action Button extensions'
3+
sidebar_position: 8
4+
id: floating-action-button-extensions
5+
---
6+
7+
## Extension Type FloatingActionButton
8+
9+
This extension type allows apps to register a global action that is either displayed within the left sidebar (for desktop resolutions) or as a floating action button (for mobile resolutions). The extension point for this extension type is `global.floating-action-button`.
10+
11+
:::warning
12+
You need to take care of the visibility of your floating action button extension via the `isActive` property, otherwise you might end up overwriting other extensions' action buttons. In most cases, it makes sense to only display the button when your app is currently active.
13+
:::
14+
15+
### Configuration
16+
17+
To define a floating action button extension, you implement the `FloatingActionButtonExtension` interface. Here's what it looks like:
18+
19+
```typescript
20+
interface FloatingActionButtonExtension {
21+
id: string;
22+
type: 'floatingActionButton';
23+
extensionPointIds?: string[];
24+
label: () => string;
25+
isActive: () => boolean;
26+
isDisabled?: () => boolean;
27+
color?: string;
28+
icon?: string;
29+
mode: () => 'drop' | 'handler';
30+
handler?: () => Promise<void> | void;
31+
dropComponent?: Component;
32+
}
33+
```
34+
35+
For `id`, `type`, and `extensionPointIds`, please see [extension base section](../#extension-base-configuration) in the top level docs.
36+
37+
The `mode` property determines whether the floating action button triggers a handler function or renders a `dropComponent` when clicked. If mode returns `handler`, the click handler function is executed, if it returns `drop`, the specified `dropComponent` is shown instead.
38+
39+
`isDisabled` controls the disabled state of the button whereas `isActive` determines if the button is showing at all.
40+
41+
`icon` is an icon name string that can be picked from [Remix Icon](https://remixicon.com/).
42+
43+
### Example
44+
45+
The following example shows how the files app is registering a floating action button extension for creating new files or folders. Note that the example assumes you're in a Vue injection context (e.g. within the `setup` method of your app's `defineWebApplication` call).
46+
47+
```typescript
48+
import { useGettext } from 'vue3-gettext';
49+
import CreateOrUploadMenu from './components/CreateOrUploadMenu.vue';
50+
import { useIsFilesAppActive, useResourcesStore } from '@opencloud-eu/web-pkg';
51+
52+
const { $gettext } = useGettext();
53+
const isFilesAppActive = useIsFilesAppActive();
54+
const resourcesStore = useResourcesStore();
55+
56+
const extension = {
57+
id: 'com.github.opencloud-eu.web.files.floating-action-button',
58+
extensionPointIds: ['global.floating-action-button'],
59+
type: 'floatingActionButton',
60+
icon: 'add',
61+
label: () => $gettext('New'),
62+
isActive: () => {
63+
return unref(isFilesAppActive);
64+
},
65+
isDisabled: () => {
66+
return !resourcesStore.currentFolder?.canUpload();
67+
},
68+
dropComponent: CreateOrUploadMenu
69+
};
70+
```

docs/dev/web/extension-system/index.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ For building an extension you can choose from the types predefined by the OpenCl
114114
For details, please refer to the [folder view docs](./extension-types/folder-view-extensions).
115115
6. `CustomComponentExtension` (type `customComponent`) - An extension that can register a custom component for a render target. For details, please refer to the
116116
[custom component docs](./extension-types/custom-component-extensions)
117+
7. `FloatingActionButtonExtension` (type `floatingActionButton`) - An extension that can register a global action that is either displayed within the left sidebar (for desktop resolutions) or as a floating action button (for mobile resolutions). For details, please refer to the
118+
[floating action button docs](./extension-types/floating-action-button-extensions).
117119

118120
You're free to introduce your own extension types within your application code and use the extension registry to query the available ones. However, if you have the impression
119121
that an important extension type is missing and would be beneficial for the platform, please reach out to us by opening a [GitHub issue](https://github.com/opencloud-eu/web/issues/new/choose).
@@ -140,9 +142,16 @@ your extension will be used automatically.
140142
1. Left Sidebar for Navigation. ExtensionPointId `app.${appName}.navItems` (dynamically created for each app). Mounts extensions of type `sidebarNav`.
141143
2. Global top bar
142144
1. Center area. ExtensionPointId `app.runtime.header.center`. Mounts extensions of type `customComponent`.
143-
2. Progress bar for the global loading state. ExtensionPointId `app.runtime.global-progress-bar`. Mounts a single extensions of type `customComponent`. If multiple exist, the user can choose via the account page.
145+
2. Left area. ExtensionPointId `app.runtime.header.left`. Mounts extensions of type `customComponent`.
146+
3. Right area. ExtensionPointId `app.runtime.header.right`. Mounts extensions of type `customComponent`.
147+
4. Progress bar for the global loading state. ExtensionPointId `app.runtime.global-progress-bar`. Mounts a single extension of type `customComponent`. If multiple exist, the user can choose via the account page.
144148
3. Files app
145-
1. Right sidebar. ExtensionPointId `app.files.sidebar`. Mounts extensions of type `sidebarPanel`. Used in any file(s) context (files app, file viewer apps, file editor apps).
149+
1. Right sidebar.
150+
1. Panels. ExtensionPointId `app.files.sidebar`. Mounts extensions of type `sidebarPanel`. Used in any file(s) context (files app, file viewer apps, file editor apps).
151+
2. File details table. ExtensionPointId `app.files.sidebar.file-details.table`. Mounts extensions of type `customComponent`. Properties `space` and `resource` can be retrieved via injection context.
152+
3. Space details table. ExtensionPointId `app.files.sidebar.space-details.table`. Mounts extensions of type `customComponent`. Properties `space` and `resource` can be retrieved via injection context.
153+
4. Shares panel people list top section. ExtensionPointId `app.files.sidebar.shares-panel.shared-with.top`. Mounts extensions of type `customComponent`. Properties `space` and `resource` can be retrieved via injection context.
154+
5. Shares panel people list bottom section. ExtensionPointId `app.files.sidebar.shares-panel.shared-with.bottom`. Mounts extensions of type `customComponent`. Properties `space` and `resource` can be retrieved via injection context.
146155
2. Folder views for regular folders. ExtensionPointId `app.files.folder-views.folder`. Mounts extensions of type `folderView`.
147156
3. Folder views for the project spaces overview. ExtensionPointId `app.files.folder-views.project-spaces`. Mounts extensions of type `folderView`.
148157
4. Folder views for the favorites page. ExtensionPointId `app.files.folder-views.favorites`. Mounts extensions of type `folderView`.
@@ -154,6 +163,7 @@ your extension will be used automatically.
154163
10. Quick actions for the trash overview. ExtensionPointId `app.files.trash-quick-actions`. Mounts extensions of type `action`.
155164
4. Global search providers. ExtensionPointId `app.search.providers`. Utilizes extensions of type `search` as search engines for the search input in the global top bar.
156165
5. User preference panels. ExtensionPointId `app.runtime.preferences.panels`. Mounts extensions of type `customComponent`.
166+
6. Global Floating Action button. ExtensionPointId `global.floating-action-button`. Mounts extensions of type `floatingActionButton`.
157167

158168
#### User Preferences for Extensions
159169

0 commit comments

Comments
 (0)