This repository was archived by the owner on Jan 30, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 9
Add support for rendering a custom wrapper around Element #13
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
9bc0a8d
Add support for rendering a custom Banner on top of Element
a61c5be
toBe used as matcher
maheichyk b588f01
Comments are added.
f3be6ac
Set react as a peer dependency.
e348d34
Comment added.
e615b7a
Revert "Set react as a peer dependency."
cddbdd0
Readme updated.
2eaedd5
Add react as peer dependency.
6e36a39
Merge branch 'main' into banner_lifecycle
0b5a32d
Conform to Typescript `strict` mode
220c551
Merge branch 'main' into banner_lifecycle
743a391
Wrapper React Component replacing Banner.
0095b5f
Use semantic elements
maheichyk f0b4fcd
Test is updated, copyright.
fe55424
Merge branch 'main' into banner_lifecycle
maheichyk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
}; | ||
testEnvironment: 'jsdom', | ||
setupFilesAfterEnv: ["<rootDir>/test/setupTests.ts"], | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
Copyright 2023 Mikhail Aheichyk | ||
Copyright 2023 Nordeck IT + Consulting GmbH. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import { ComponentType, PropsWithChildren } from 'react'; | ||
|
||
/** | ||
* Wrapper lifecycle events | ||
*/ | ||
export enum WrapperLifecycle { | ||
/** | ||
* An event to request the wrapper. It is sent by Element to get the wrapper provided by the module if any. | ||
*/ | ||
Wrapper = 'wrapper' | ||
} | ||
|
||
/** | ||
* Opts object that is populated with a Wrapper. | ||
*/ | ||
export type WrapperOpts = { | ||
/** | ||
* A Wrapper React Component to be rendered around the Matrix Chat. | ||
*/ | ||
Wrapper: ComponentType<PropsWithChildren<{}>>; | ||
}; | ||
|
||
/** | ||
* Helper type that documents how to implement a wrapper listener. | ||
*/ | ||
export type WrapperListener = (opts: WrapperOpts) => void; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
Copyright 2023 Mikhail Aheichyk | ||
Copyright 2023 Nordeck IT + Consulting GmbH. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
|
||
import { RuntimeModule } from '../../src/RuntimeModule'; | ||
import { WrapperLifecycle, WrapperListener, WrapperOpts } from '../../src/lifecycles/WrapperLifecycle'; | ||
|
||
describe('WrapperLifecycle', () => { | ||
let module: RuntimeModule; | ||
|
||
beforeAll(() => { | ||
module = new class extends RuntimeModule { | ||
constructor() { | ||
super(undefined as any); | ||
|
||
this.on(WrapperLifecycle.Wrapper, this.wrapperListener); | ||
} | ||
|
||
protected wrapperListener: WrapperListener = (wrapperOpts: WrapperOpts) => { | ||
wrapperOpts.Wrapper = ({ children }) => { | ||
return <> | ||
<header>Header</header> | ||
{children} | ||
<footer>Footer</footer> | ||
</>; | ||
}; | ||
}; | ||
}; | ||
}); | ||
|
||
it('should wrap a matrix client with header and footer', () => { | ||
const opts: WrapperOpts = { Wrapper: React.Fragment }; | ||
module.emit(WrapperLifecycle.Wrapper, opts); | ||
|
||
render(<opts.Wrapper><span>MatrixChat</span></opts.Wrapper>); | ||
|
||
const header = screen.getByRole('banner'); | ||
expect(header).toBeInTheDocument(); | ||
const matrixChat = screen.getByText(/MatrixChat/i); | ||
expect(matrixChat).toBeInTheDocument(); | ||
const footer = screen.getByRole('contentinfo'); | ||
expect(footer).toBeInTheDocument(); | ||
|
||
expect(header.nextSibling).toBe(matrixChat); | ||
expect(matrixChat.nextSibling).toBe(footer); | ||
}); | ||
}); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
Copyright 2023 Mikhail Aheichyk | ||
Copyright 2023 Nordeck IT + Consulting GmbH. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import "@testing-library/jest-dom"; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.