Skip to content

Commit

Permalink
add ComponentVisibility to customisation docs (#21008)
Browse files Browse the repository at this point in the history
* add componentvisibility to customisation md

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

* few more words

Signed-off-by: Kerry Archibald <kerrya@element.io>
  • Loading branch information
Kerry authored Feb 9, 2022
1 parent 762fc53 commit d4a019b
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions docs/customisations.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit d4a019b

Please sign in to comment.