1
0
mirror of https://github.com/flarum/core.git synced 2025-08-06 08:27:42 +02:00

ComposerPostPreview: Add scroll anchoring callback

This will be needed to replace the `ReplyPlaceholderPreview` component.
This commit is contained in:
Franz Liedke
2020-09-11 17:23:02 +02:00
parent 174f3aba90
commit 85f8fc52b7

View File

@@ -12,10 +12,12 @@ import Component from '../../common/Component';
* *
* - `composer` The state of the composer controlling this preview. * - `composer` The state of the composer controlling this preview.
* - `className` A CSS class for the element surrounding the preview. * - `className` A CSS class for the element surrounding the preview.
* - `surround` A callback that can execute code before and after re-render, e.g. for scroll anchoring.
*/ */
export default class ComposerPostPreview extends Component { export default class ComposerPostPreview extends Component {
static initAttrs(attrs) { static initAttrs(attrs) {
attrs.className = attrs.className || ''; attrs.className = attrs.className || '';
attrs.surround = attrs.surround || ((preview) => preview());
} }
view() { view() {
@@ -39,7 +41,7 @@ export default class ComposerPostPreview extends Component {
preview = content; preview = content;
s9e.TextFormatter.preview(preview || '', vnode.dom); this.attrs.surround(() => s9e.TextFormatter.preview(preview || '', vnode.dom));
}; };
updatePreview(); updatePreview();