Skip to content

Commit

Permalink
fix / Highlighter :
Browse files Browse the repository at this point in the history
URLPopoverからPopoverに変更
関連 : WordPress/gutenberg#34680
  • Loading branch information
shimotmk committed Jan 19, 2022
1 parent b332e5a commit 32622e9
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions src/extensions/common/highlighter/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* highlighter block type
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { useState } from '@wordpress/element';
import { useCallback, useState } from '@wordpress/element';
import {
registerFormatType,
applyFormat,
Expand All @@ -14,9 +14,12 @@ import {
RichTextToolbarButton,
RichTextShortcut,
ColorPalette,
URLPopover,
} from '@wordpress/block-editor';
import { Icon } from '@wordpress/components';
import { Popover, Icon } from '@wordpress/components';

/**
* Internal dependencies
*/
import { ReactComponent as IconSVG } from './icon.svg';
import hex2rgba from '@vkblocks/utils/hex-to-rgba';

Expand Down Expand Up @@ -51,7 +54,7 @@ const hightliterOnApply = ({ color, value, onChange }) => {
};

const HighlighterEdit = (props) => {
const { value, isActive, onChange } = props;
const { value, isActive, onChange, contentRef } = props;
const shortcutType = 'primary';
const shortcutChar = 'h';

Expand All @@ -68,9 +71,18 @@ const HighlighterEdit = (props) => {
background: `linear-gradient(transparent 60%, ${rgbaHeightlightColor} 0)`,
};
}
const anchorRef = useAnchorRef({ ref: props.contentRef, value });
const anchorRef = useAnchorRef({ ref: contentRef, value });
const [isAddingColor, setIsAddingColor] = useState(false);

const enableIsAddingColor = useCallback(
() => setIsAddingColor(true),
[setIsAddingColor]
);
const disableIsAddingColor = useCallback(
() => setIsAddingColor(false),
[setIsAddingColor]
);

return (
<>
<RichTextShortcut
Expand All @@ -90,6 +102,7 @@ const HighlighterEdit = (props) => {
});
}
setIsAddingColor(true);
enableIsAddingColor(true);
}}
shortcutType={shortcutType}
shortcutCharacter={shortcutChar}
Expand All @@ -102,11 +115,11 @@ const HighlighterEdit = (props) => {
}
/>
{isAddingColor && (
<URLPopover
<Popover
value={value}
className="components-inline-color-popover"
className="components-inline-color-popover components-inline-color-popover"
anchorRef={anchorRef}
onClose={() => setIsAddingColor(false)}
onClose={disableIsAddingColor}
>
<ColorPalette
value={heightlightColor}
Expand All @@ -125,7 +138,7 @@ const HighlighterEdit = (props) => {
setIsAddingColor(false);
}}
/>
</URLPopover>
</Popover>
)}
</>
);
Expand Down

0 comments on commit 32622e9

Please sign in to comment.