-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce
HtmlPortal
to render HTML elements inside custom containers
- Loading branch information
Showing
11 changed files
with
241 additions
and
152 deletions.
There are no files selected for viewing
This file contains 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 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 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,83 @@ | ||
import { | ||
DefaultInteractions, | ||
Html, | ||
useVisCanvasContext, | ||
VisCanvas, | ||
} from '@h5web/lib'; | ||
import HtmlPortal from '@h5web/lib/src/vis/shared/HtmlPortal'; | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import FillHeight from './decorators/FillHeight'; | ||
|
||
const meta = { | ||
title: 'Building Blocks/HtmlPortal', | ||
component: HtmlPortal, | ||
decorators: [FillHeight], | ||
parameters: { layout: 'fullscreen' }, | ||
argTypes: { container: { control: false } }, | ||
} satisfies Meta<typeof HtmlPortal>; | ||
|
||
export default meta; | ||
type Story = StoryObj<Meta>; | ||
|
||
export const Default = { | ||
render: () => { | ||
return ( | ||
<VisCanvas | ||
abscissaConfig={{ visDomain: [0, 3], showGrid: true }} | ||
ordinateConfig={{ visDomain: [50, 100], showGrid: true }} | ||
> | ||
<DefaultInteractions /> | ||
<MyHtml /> | ||
</VisCanvas> | ||
); | ||
}, | ||
} satisfies Story; | ||
|
||
function MyHtml() { | ||
const { canvasWrapper } = useVisCanvasContext(); | ||
|
||
return ( | ||
<HtmlPortal container={canvasWrapper}> | ||
<div | ||
style={{ | ||
position: 'absolute', | ||
top: 40, | ||
left: 20, | ||
width: '36em', | ||
padding: '0 1rem', | ||
border: '3px solid blue', | ||
backgroundColor: 'rgba(255, 255, 255, 0.8)', | ||
}} | ||
> | ||
<p> | ||
While <code>Html</code> always renders its children into a{' '} | ||
<code>div</code> next to the <code>canvas</code> element,{' '} | ||
<strong> | ||
<code>HtmlPortal</code> | ||
</strong>{' '} | ||
uses a React portal to render its children into a given{' '} | ||
<code>container</code> element. | ||
</p> | ||
<p> | ||
The two main use cases for{' '} | ||
<strong> | ||
<code>HtmlPortal</code> | ||
</strong>{' '} | ||
are: | ||
</p> | ||
<ul> | ||
<li> | ||
rendering HTML elements into <code>canvasWrapper</code> so they | ||
overflow the canvas (like this <code>div</code>); | ||
</li> | ||
<li> | ||
rendering the children of multiple <code>HtmlPortal</code> elements | ||
inside the same container (as such, <code>SvgElement</code> and{' '} | ||
<code>FloatingControl</code> both rely on <code>HtmlPortal</code>). | ||
</li> | ||
</ul> | ||
</div> | ||
</HtmlPortal> | ||
); | ||
} |
This file contains 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 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 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
Oops, something went wrong.