Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit c88a814

Browse files
author
Mikhail Aheichyk
committed
Add support for rendering a custom Banner on top of Element
Signed-off-by: Mikhail Aheichyk <[email protected]>
1 parent 3038ec2 commit c88a814

File tree

5 files changed

+99
-1
lines changed

5 files changed

+99
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"eslint-plugin-import": "^2.26.0",
4444
"eslint-plugin-matrix-org": "^0.4.0",
4545
"jest": "^27.5.1",
46+
"react": "17.0.2",
4647
"rimraf": "^3.0.2",
4748
"ts-jest": "^27.1.4",
4849
"typescript": "^4.6.3"

src/lifecycles/BannerLifecycle.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
Copyright 2023 Mikhail Aheichyk
3+
Copyright 2023 Nordeck IT + Consulting GmbH.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
18+
export enum BannerLifecycle {
19+
Banner = "banner",
20+
}
21+
22+
export type BannerOpts = {
23+
banner: JSX.Element | undefined;
24+
};
25+
26+
export type BannerListener = (opts: BannerOpts) => void;

src/lifecycles/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ limitations under the License.
1616

1717
import { RoomViewLifecycle } from "./RoomViewLifecycle";
1818
import { WidgetLifecycle } from "./WidgetLifecycle";
19+
import { BannerLifecycle } from "./BannerLifecycle";
1920

2021
export type AnyLifecycle =
2122
| RoomViewLifecycle
2223
| WidgetLifecycle
24+
| BannerLifecycle
2325
;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
Copyright 2023 Mikhail Aheichyk
3+
Copyright 2023 Nordeck IT + Consulting GmbH.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
18+
import React from 'react';
19+
20+
import { BannerOpts, BannerListener } from "../../src/lifecycles/BannerLifecycle";
21+
import { RuntimeModule } from "../../src/RuntimeModule";
22+
import { BannerLifecycle } from "../../lib/lifecycles/BannerLifecycle";
23+
24+
describe("BannerLifecycle", () => {
25+
const customBanner = React.createElement('div');
26+
27+
let module: RuntimeModule;
28+
29+
beforeAll(() => {
30+
module = new class extends RuntimeModule {
31+
constructor() {
32+
super(undefined);
33+
34+
this.on(BannerLifecycle.Banner, this.bannerListener);
35+
}
36+
37+
protected bannerListener: BannerListener = (bannerOpts: BannerOpts) => {
38+
bannerOpts.banner = customBanner;
39+
};
40+
};
41+
});
42+
43+
it('should handle request to render the banner', () => {
44+
const opts: BannerOpts = {banner: undefined};
45+
module.emit(BannerLifecycle.Banner, opts);
46+
47+
expect(opts.banner).toEqual(customBanner);
48+
});
49+
});

yarn.lock

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3292,7 +3292,7 @@ jest@^27.5.1:
32923292
import-local "^3.0.2"
32933293
jest-cli "^27.5.1"
32943294

3295-
js-tokens@^4.0.0:
3295+
"js-tokens@^3.0.0 || ^4.0.0", js-tokens@^4.0.0:
32963296
version "4.0.0"
32973297
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
32983298
integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==
@@ -3448,6 +3448,13 @@ lodash@^4.7.0:
34483448
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
34493449
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
34503450

3451+
loose-envify@^1.1.0:
3452+
version "1.4.0"
3453+
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"
3454+
integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==
3455+
dependencies:
3456+
js-tokens "^3.0.0 || ^4.0.0"
3457+
34513458
lru-cache@^6.0.0:
34523459
version "6.0.0"
34533460
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-6.0.0.tgz#6d6fe6570ebd96aaf90fcad1dafa3b2566db3a94"
@@ -3576,6 +3583,11 @@ nwsapi@^2.2.0:
35763583
resolved "https://registry.yarnpkg.com/nwsapi/-/nwsapi-2.2.0.tgz#204879a9e3d068ff2a55139c2c772780681a38b7"
35773584
integrity sha512-h2AatdwYH+JHiZpv7pt/gSX1XoRGb7L/qSIeuqA6GwYoF9w1vP1cw42TO0aI2pNyshRK5893hNSl+1//vHK7hQ==
35783585

3586+
object-assign@^4.1.1:
3587+
version "4.1.1"
3588+
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
3589+
integrity sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==
3590+
35793591
object-inspect@^1.12.0, object-inspect@^1.9.0:
35803592
version "1.12.0"
35813593
resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.12.0.tgz#6e2c120e868fd1fd18cb4f18c31741d0d6e776f0"
@@ -3807,6 +3819,14 @@ react-is@^17.0.1:
38073819
resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0"
38083820
integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==
38093821

3822+
3823+
version "17.0.2"
3824+
resolved "https://registry.yarnpkg.com/react/-/react-17.0.2.tgz#d0b5cc516d29eb3eee383f75b62864cfb6800037"
3825+
integrity sha512-gnhPt75i/dq/z3/6q/0asP78D0u592D5L1pd7M8P+dck6Fu/jJeL6iVVK23fptSUZj8Vjf++7wXA8UNclGQcbA==
3826+
dependencies:
3827+
loose-envify "^1.1.0"
3828+
object-assign "^4.1.1"
3829+
38103830
readdirp@~3.6.0:
38113831
version "3.6.0"
38123832
resolved "https://registry.yarnpkg.com/readdirp/-/readdirp-3.6.0.tgz#74a370bd857116e245b29cc97340cd431a02a6c7"

0 commit comments

Comments
 (0)