2020-10-15 19:01:38 +02:00
# Customisations
2023-07-07 16:25:22 +02:00
### 🦖 DEPRECATED
Customisations have been deprecated in favour of the [Module API ](https://github.com/vector-im/element-web/blob/develop/docs/modules.md ).
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 19:01:38 +02: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.
An example of this is the [security customisations
module](https://github.com/matrix-org/matrix-react-sdk/blob/develop/src/customisations/Security.ts).
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
2020-10-16 12:22:28 +02:00
`element-web/src/customisations/YourNameSecurity.ts`
2020-10-15 19:01:38 +02:00
2. Edit customisations points and make sure export the ones you actually want to
activate
2022-02-24 20:52:08 +01:00
3. Create/add an entry to `customisations.json` next to the webpack config:
2020-10-15 19:01:38 +02:00
2022-02-24 20:52:08 +01:00
```json
{
"src/customisations/Security.ts": "src/customisations/YourNameSecurity.ts"
}
```
2020-10-15 19:01:38 +02: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 17:21:54 +01:00
2022-02-24 20:52:08 +01: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
2022-12-09 13:28:29 +01:00
default, Element Web does _not_ ship with this file to prevent conflicts.
2022-02-24 20:52:08 +01:00
### Custom components
2022-03-28 23:17:56 +02: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 20:52:08 +01:00
2022-02-09 17:21:54 +01:00
### Component visibility customisation
2022-02-24 20:52:08 +01:00
2022-02-09 17:21:54 +01:00
UI for some actions can be hidden via the ComponentVisibility customisation:
2022-12-09 13:28:29 +01:00
- inviting users to rooms and spaces,
- creating rooms,
- creating spaces,
2022-02-09 17:21:54 +01:00
To customise visibility create a customisation module from [ComponentVisibility ](https://github.com/matrix-org/matrix-react-sdk/blob/master/src/customisations/ComponentVisibility.ts ) following the instructions above.
2022-02-24 20:52:08 +01:00
`shouldShowComponent` determines whether the active MatrixClient user should be able to use
2022-02-09 17:21:54 +01: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 20:52:08 +01:00
might be shown to the user, but they won't have permission to invite users to
2022-02-09 17:21:54 +01: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 13:28:29 +01:00
2022-02-24 20:52:08 +01:00
```typescript
2022-02-09 17:21:54 +01:00
function shouldShowComponent(component: UIComponent): boolean {
2022-02-24 20:52:08 +01: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 17:21:54 +01:00
}
```
2022-12-09 13:28:29 +01:00
2022-02-24 20:52:08 +01:00
In this example, all UI related to creating a space will be hidden unless the users meets the custom condition.