Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

蛍光マーカーURLPopoverからPopoverに変更 #970

Merged
merged 2 commits into from
Jan 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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="vk-blocks-format-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