Skip to content

Commit

Permalink
added MasonryWrapper component
Browse files Browse the repository at this point in the history
removed react-masonry-component deps
  • Loading branch information
nk-o committed Oct 16, 2023
1 parent 84dd6bc commit 438d739
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 63 deletions.
3 changes: 2 additions & 1 deletion classes/class-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ public function enqueue_block_editor_assets() {
// Block.
Visual_Portfolio_Assets::enqueue_script(
'visual-portfolio-gutenberg',
'build/gutenberg/index'
'build/gutenberg/index',
array( 'masonry' )
);
Visual_Portfolio_Assets::enqueue_style(
'visual-portfolio-gutenberg',
Expand Down
24 changes: 24 additions & 0 deletions gutenberg/components/masonry-wrapper/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { useEffect, useRef } from '@wordpress/element';

const { Masonry } = window;

export default function MasonryWrapper(props) {
const { options, children, ...restProps } = props;

const ref = useRef();

// Init.
useEffect(() => {
const instance = new Masonry(ref.current, options);

return () => {
instance.destroy();
};
}, [ref, options, children]);

return (
<div ref={ref} {...restProps}>
{children}
</div>
);
}
9 changes: 4 additions & 5 deletions gutenberg/components/tiles-selector/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import './style.scss';

import classnames from 'classnames/dedupe';
import Masonry from 'react-masonry-component';

import { Button } from '@wordpress/components';
import { Component } from '@wordpress/element';
import { __ } from '@wordpress/i18n';

import MasonryWrapper from '../masonry-wrapper';
import StylesRender from '../styles-render';
import ToggleModal from '../toggle-modal';

Expand Down Expand Up @@ -69,8 +69,8 @@ export default class TilesSelector extends Component {

return (
<>
<Masonry
elementType="div"
<StylesRender>{styles}</StylesRender>
<MasonryWrapper
data-tiles-preview={tilesType}
options={{
transitionDuration: 0,
Expand All @@ -81,8 +81,7 @@ export default class TilesSelector extends Component {
<div className="vpf-tiles-preview-item" />
</div>
))}
</Masonry>
<StylesRender>{styles}</StylesRender>
</MasonryWrapper>
</>
);
}
Expand Down
58 changes: 2 additions & 56 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
"photoswipe": "^4.1.3",
"raf-schd": "^4.0.3",
"react-ace": "^9.5.0",
"react-masonry-component": "^6.3.0",
"react-select": "^5.7.3",
"react-sortable-hoc": "^2.0.0",
"shorthash": "0.0.2",
Expand Down

0 comments on commit 438d739

Please sign in to comment.