add ComponentVisibility to customisation docs (#21008)

* add componentvisibility to customisation md

Signed-off-by: Kerry Archibald <kerrya@element.io>

* few more words

Signed-off-by: Kerry Archibald <kerrya@element.io>
This commit is contained in:
Kerry 2022-02-09 17:21:54 +01:00 committed by GitHub
parent 762fc53c61
commit d4a019b27a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -32,3 +32,30 @@ steps to remove the need for build changes like the above.
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.
### Component visibility customisation
UI for some actions can be hidden via the ComponentVisibility customisation:
- inviting users to rooms and spaces,
- creating rooms,
- creating spaces,
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.
`shouldShowComponent` determines whether or not the active MatrixClient user should be able to use
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
might be shown to the user but they won't have permission to invite users to
the current room: the button will appear disabled.
For example, to only allow users who meet a certain condition to create spaces:
```
function shouldShowComponent(component: UIComponent): boolean {
if (component === UIComponent.CreateSpaces) {
const userMeetsCondition = <<check your custom condition here>>
return userMeetsCondition;
}
return true;
}
```
In this example, all UI related to creating a space will be hidden unless the users meets a custom condition.