2020-10-15 20:01:38 +03:00
# Customisations
2023-07-07 17:25:22 +03:00
### 🦖 DEPRECATED
2023-12-20 15:21:26 +03:00
Customisations have been deprecated in favour of the [Module API ](https://github.com/element-hq/element-web/blob/develop/docs/modules.md ).
2023-07-07 17:25:22 +03:00
If you have use cases from customisations which are not yet available via the Module API please open an issue.
Customisations will be removed from the codebase in a future release.
---
2020-10-15 20:01:38 +03:00
Element Web and the React SDK support "customisation points" that can be used to
easily add custom logic specific to a particular deployment of Element Web.
2024-11-04 12:49:20 +03:00
An example of this is the [media customisations
module](https://github.com/element-hq/element-web/blob/develop/src/customisations/Media.ts).
2020-10-15 20:01:38 +03:00
This module in the React SDK only defines some empty functions and their types:
it does not do anything by default.
To make use of these customisation points, you will first need to fork Element
Web so that you can add your own code. Even though the default module is part of
the React SDK, you can still override it from the Element Web layer:
1. Copy the default customisation module to
2024-11-04 12:49:20 +03:00
`element-web/src/customisations/YourNameMedia.ts`
2020-10-15 20:01:38 +03:00
2. Edit customisations points and make sure export the ones you actually want to
activate
2022-02-24 22:52:08 +03:00
3. Create/add an entry to `customisations.json` next to the webpack config:
2020-10-15 20:01:38 +03:00
2022-02-24 22:52:08 +03:00
```json
{
2024-11-04 12:49:20 +03:00
"src/customisations/Media.ts": "src/customisations/YourNameMedia.ts"
2022-02-24 22:52:08 +03:00
}
```
2020-10-15 20:01:38 +03:00
By isolating customisations to their own module, this approach should remove the
chance of merge conflicts when updating your fork, and thus simplify ongoing
maintenance.
2022-02-09 19:21:54 +03:00
2022-02-24 22:52:08 +03:00
**Note**: The project deliberately does not exclude `customisations.json` from Git.
This is to ensure that in shared projects it's possible to have a common config. By
default, Element Web does _not_ ship with this file to prevent conflicts.
### Custom components
2022-03-29 00:17:56 +03:00
Maintainers can use the above system to override components if they wish. Maintenance and API surface compatibility are
left as a responsibility for the project - the layering in Element Web (including the react-sdk) do not make guarantees
that properties/state machines won't change.
2022-02-24 22:52:08 +03:00
2022-02-09 19:21:54 +03:00
### Component visibility customisation
2022-02-24 22:52:08 +03:00
2022-02-09 19:21:54 +03:00
UI for some actions can be hidden via the ComponentVisibility customisation:
2022-12-09 15:28:29 +03:00
2022-02-09 19:21:54 +03:00
- inviting users to rooms and spaces,
- creating rooms,
- creating spaces,
2024-10-15 16:57:26 +03:00
To customise visibility create a customisation module from [ComponentVisibility ](https://github.com/element-hq/element-web/blob/master/src/customisations/ComponentVisibility.ts ) following the instructions above.
2022-02-09 19:21:54 +03:00
2022-02-24 22:52:08 +03:00
`shouldShowComponent` determines whether the active MatrixClient user should be able to use
2022-02-09 19:21:54 +03:00
the given UI component. When `shouldShowComponent` returns falsy all UI components for that feature will be hidden.
If shown, the user might still not be able to use the
component depending on their contextual permissions. For example, invite options
2022-02-24 22:52:08 +03:00
might be shown to the user, but they won't have permission to invite users to
2022-02-09 19:21:54 +03:00
the current room: the button will appear disabled.
For example, to only allow users who meet a certain condition to create spaces:
2022-12-09 15:28:29 +03:00
2022-02-24 22:52:08 +03:00
```typescript
2022-02-09 19:21:54 +03:00
function shouldShowComponent(component: UIComponent): boolean {
2022-02-24 22:52:08 +03:00
if (component === UIComponent.CreateSpaces) {
// customConditionCheck() is a function of your own creation
const userMeetsCondition = customConditionCheck(MatrixClientPeg.get().getUserId());
return userMeetsCondition;
}
return true;
2022-02-09 19:21:54 +03:00
}
```
2022-12-09 15:28:29 +03:00
2022-02-24 22:52:08 +03:00
In this example, all UI related to creating a space will be hidden unless the users meets the custom condition.