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 1 commit
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="components-inline-color-popover components-inline-color-popover"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shimotmk ここは同じclass名(components-inline-color-popover)を追加してますが、vk- 系のクラスの誤りでしょうか。paddingが無かったので、それは別ブランチかなと思ってたんですが、ご確認をば。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mthaichi
確認ありがとうございます
修正しました

Copy link
Contributor

@mthaichi mthaichi Jan 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shimotmk paddingの調整は別ブランチで行いますか?
であれば、マージしておきます。

ここで併せてやっちゃっても問題ないような気がしますが、おまかせします。
・・・あ、paddingの調整はインライン文字列の方にいれるのかな。
一応確認です。

Copy link
Contributor Author

@shimotmk shimotmk Jan 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mthaichi
paddingのcss追加は別ブランチでやりますー

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