forked from remirror/remirror
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
116 additions
and
2 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
74 changes: 74 additions & 0 deletions
74
packages/storybook-react/stories/extension-image/with-figcaption.tsx
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,74 @@ | ||
import 'remirror/styles/all.css'; | ||
|
||
import { ApplySchemaAttributes, NodeExtensionSpec, NodeSpecOverride } from 'remirror'; | ||
import { ImageExtension } from 'remirror/extensions'; | ||
import { Remirror, ThemeProvider, useRemirror } from '@remirror/react'; | ||
|
||
class FigcaptionExtension extends ImageExtension { | ||
createNodeSpec(extra: ApplySchemaAttributes, override: NodeSpecOverride): NodeExtensionSpec { | ||
const spec = super.createNodeSpec(extra, override); | ||
|
||
return { | ||
...spec, | ||
attrs: { | ||
...spec.attrs, | ||
figcaptionText: { default: '' }, | ||
}, | ||
toDOM: (node) => [ | ||
'figure', | ||
{ | ||
style: 'border: 2px solid #479e0c; padding: 8px; margin: 8px; text-align: center;', | ||
}, | ||
spec.toDOM!(node), | ||
[ | ||
'figcaption', | ||
{ style: 'background-color: #3d3d3d; color: #f1f1f1; padding: 8px;' }, | ||
node.attrs.figcaptionText, | ||
], | ||
], | ||
}; | ||
} | ||
} | ||
|
||
const extensions = () => [new FigcaptionExtension()]; | ||
|
||
const WithFigcaption = (): JSX.Element => { | ||
const imageSrc = 'https://dummyimage.com/2000x800/479e0c/fafafa'; | ||
|
||
const { manager, state, onChange } = useRemirror({ | ||
extensions, | ||
content: { | ||
type: 'doc', | ||
content: [ | ||
{ | ||
type: 'paragraph', | ||
content: [ | ||
{ | ||
type: 'image', | ||
attrs: { | ||
height: 160, | ||
width: 400, | ||
src: imageSrc, | ||
figcaptionText: 'This is a <figcaption> element', | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
}); | ||
|
||
return ( | ||
<ThemeProvider> | ||
<Remirror | ||
manager={manager} | ||
autoFocus | ||
onChange={onChange} | ||
initialContent={state} | ||
autoRender='end' | ||
/> | ||
</ThemeProvider> | ||
); | ||
}; | ||
|
||
export default WithFigcaption; |
30 changes: 30 additions & 0 deletions
30
website/extension-examples/extension-image/with-figcaption.tsx
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,30 @@ | ||
/** | ||
* THIS FILE IS AUTO GENERATED! | ||
* | ||
* Run `pnpm -w generate:website-examples` to regenerate this file. | ||
*/ | ||
|
||
// @ts-nocheck | ||
|
||
import CodeBlock from '@theme/CodeBlock'; | ||
import BrowserOnly from '@docusaurus/BrowserOnly'; | ||
import ComponentSource from '!!raw-loader!../../../packages/storybook-react/stories/extension-image/with-figcaption.tsx'; | ||
|
||
import { StoryExample } from '../../src/components/story-example-component'; | ||
|
||
const ExampleComponent = (): JSX.Element => { | ||
const story = ( | ||
<BrowserOnly> | ||
{() => { | ||
const ComponentStory = require('../../../packages/storybook-react/stories/extension-image/with-figcaption').default | ||
return <ComponentStory/> | ||
}} | ||
</BrowserOnly> | ||
); | ||
const source = <CodeBlock className='language-tsx'>{ComponentSource}</CodeBlock>; | ||
|
||
return <StoryExample story={story} source={source} />; | ||
}; | ||
|
||
export default ExampleComponent; | ||
|