Skip to content

Commit

Permalink
Improve the typing performance by render hooks panels for selected bl…
Browse files Browse the repository at this point in the history
…ocks only (#31381)
  • Loading branch information
youknowriad authored Apr 30, 2021
1 parent 0b01903 commit 32e57fc
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions packages/block-editor/src/hooks/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { COLOR_SUPPORT_KEY, ColorEdit } from './color';
import { FONT_SIZE_SUPPORT_KEY } from './font-size';
import { TypographyPanel, TYPOGRAPHY_SUPPORT_KEYS } from './typography';
import { SPACING_SUPPORT_KEY, SpacingPanel } from './spacing';
import useDisplayBlockControls from '../components/use-display-block-controls';

const styleSupportKeys = [
...TYPOGRAPHY_SUPPORT_KEYS,
Expand Down Expand Up @@ -182,13 +183,21 @@ export function addEditProps( settings ) {
*/
export const withBlockControls = createHigherOrderComponent(
( BlockEdit ) => ( props ) => {
return [
<TypographyPanel key="typography" { ...props } />,
<BorderPanel key="border" { ...props } />,
<ColorEdit key="colors" { ...props } />,
<BlockEdit key="edit" { ...props } />,
<SpacingPanel key="spacing" { ...props } />,
];
const shouldDisplayControls = useDisplayBlockControls();

return (
<>
{ shouldDisplayControls && (
<>
<TypographyPanel { ...props } />
<BorderPanel { ...props } />
<ColorEdit { ...props } />
<SpacingPanel { ...props } />
</>
) }
<BlockEdit { ...props } />
</>
);
},
'withToolbarControls'
);
Expand Down

0 comments on commit 32e57fc

Please sign in to comment.