Skip to content

Commit 17f8df1

Browse files
authored
Merge pull request #80 from opf/impl/69488-wrapper-for-shadow-dom
define a shadow dom wrapper component
2 parents 3497b36 + 2e0c300 commit 17f8df1

File tree

7 files changed

+125
-66
lines changed

7 files changed

+125
-66
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ npm run dev
7676

7777
Which will start a vite server with a BlockNote editor instance including the available extensions.
7878

79+
#### Usage within a shadow dom root
80+
81+
This project uses `styledComponents` to define styles. This means that styles are, by default, injected onto the page header. To be able to use styles onto a shadow dom root it is necessary to use our `ShadowDomWrapper` component targeting the root for the styles.
82+
83+
```tsx
84+
<ShadowDomWrapper target={targetHtmlElementOrShadowRoot}>
85+
<MyBlockNoteView />
86+
</ShadowDomWrapper>
87+
```
88+
7989
### To run locally with valid API requests to an OpenProject instance
8090

8191
Step 1: Make sure that the OpenProject instance URL is correct in App.tsx

index.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,18 @@
55
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<title>Vite + React + TS</title>
8+
<script type="module" src="/src/op-blocknote.ts"></script>
89
</head>
910
<body>
11+
<div>-- page root --</div>
1012
<div id="root"></div>
1113
<script type="module" src="/src/main.tsx"></script>
14+
15+
<br />
16+
<br />
17+
<br />
18+
19+
<div>-- shadow dom --</div>
20+
<op-block-note />
1221
</body>
1322
</html>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { PropsWithChildren } from "react";
2+
import { StyleSheetManager } from "styled-components";
3+
4+
interface ShadowDomWrapperProps {
5+
target: ShadowRoot | HTMLElement;
6+
}
7+
8+
export const ShadowDomWrapper = ({ children, target }: PropsWithChildren<ShadowDomWrapperProps>) => (
9+
<StyleSheetManager target={target}>
10+
{children}
11+
</StyleSheetManager>
12+
);

lib/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from "./OpenProjectWorkPackageBlock";
2+
export * from "./ShadowDomWrapper";

package-lock.json

Lines changed: 41 additions & 61 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)