@matrix-widget-toolkit/mui 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,84 @@
1
+ # `@matrix-widget-toolkit/mui`
2
+
3
+ This package provides a [Mui](https://mui.com/) theme that fits to the default Element theme.
4
+ It provides:
5
+
6
+ - Themes that match Element Web (the only Matrix Client that supports the `matrix-widget-api` right now)
7
+ - A light, dark, and high-contract mode
8
+ - Adjustments to fulfill accessibility standards
9
+
10
+ ## Usage
11
+
12
+ Install it with:
13
+
14
+ ```bash
15
+ yarn add @matrix-widget-toolkit/mui @mui/material
16
+ ```
17
+
18
+ ### Providing the Widget API to components
19
+
20
+ Now you can use it in your application:
21
+
22
+ ```tsx
23
+ import { WidgetApiImpl } from '@matrix-widget-toolkit/api';
24
+ import {
25
+ MuiThemeProvider,
26
+ MuiWidgetApiProvider,
27
+ } from '@matrix-widget-toolkit/mui';
28
+ import { Button } from '@mui/material';
29
+
30
+ // Initiate the widget API on startup. The Client will initiate
31
+ // the connection with `capabilities` and we need to make sure
32
+ // that the message doesn't get lost while we are initiating React.
33
+ const widgetApiPromise = WidgetApiImpl.create();
34
+
35
+ function App() {
36
+ return (
37
+ <MuiThemeProvider>
38
+ <MuiWidgetApiProvider widgetApiPromise={widgetApiPromise}>
39
+ <Button>A styled button</Button>
40
+ </MuiWidgetApiProvider>
41
+ </MuiThemeProvider>
42
+ );
43
+ }
44
+
45
+ export default App;
46
+ ```
47
+
48
+ ### Setup i18n
49
+
50
+ The `matrix-widget-toolkit` uses [`i18next`](https://www.i18next.com/) to provide translations for messages.
51
+ To make it work in your widget you have to initialize it on your end.
52
+ See the [`i18next` getting started documentation](https://www.i18next.com/overview/getting-started).
53
+ This package provides a `WidgetToolkitI18nBackend` containing the translation data.
54
+ You can use the [`ChainedBackend` plugin](https://github.com/i18next/i18next-chained-backend) to load translation data for the `matrix-widget-toolkit` together the translation data for the widget itself.
55
+ The package provides a `WidgetApiLanguageDetector` that detects the language from the widget parameters with the [`i18next-browser-languagedetector` plugin](https://github.com/i18next/i18next-browser-languageDetector).
56
+ For more details, see the implementation in the [example widget](../../example-widget-mui/src/i18n.tsx).
57
+
58
+ ### Requesting capabilities on demand
59
+
60
+ You can hide child components till the user has approved all required capabilities:
61
+
62
+ ```tsx
63
+ import { MuiCapabilitiesGuard } from '@matrix-widget-toolkit/mui';
64
+ import { EventDirection, WidgetEventCapability } from 'matrix-widget-api';
65
+
66
+ <MuiCapabilitiesGuard
67
+ capabilities={[
68
+ WidgetEventCapability.forStateEvent(
69
+ EventDirection.Receive,
70
+ STATE_EVENT_ROOM_NAME
71
+ ),
72
+ ]}
73
+ >
74
+ /* Children are only displayed once the user has approved all capabilities. */
75
+ </MuiCapabilitiesGuard>;
76
+ ```
77
+
78
+ ## Customization
79
+
80
+ You can override the primary color by setting the `REACT_APP_PRIMARY_COLOR` environment variable.
81
+
82
+ > **Warning** Choosing a different primary color might result in not meeting contrast requirements for accessability.
83
+
84
+ You can force the high contrast theme by setting the `REACT_APP_FORCE_HIGH_CONTRAST_THEME` environment variable.