Skip to content

Commit 27d023d

Browse files
authored
fix(YfmNote): fix yfm-note tooltip view and active state (#1031)
1 parent b073b71 commit 27d023d

6 files changed

+28
-19
lines changed
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
.g-md-yfm-note-toolbar {
2-
margin: 2px 8px;
2+
margin: var(--g-spacing-half);
33
}
44

55
.g-md-toolbar-group__s-button_id_ {
66
&note-type-tip {
7-
color: var(--yfm-color-note-tip);
7+
--g-button-text-color: var(--yfm-color-note-tip);
8+
--g-button-text-color-hover: var(--yfm-color-note-tip);
89
}
910
&note-type-info {
10-
color: var(--yfm-color-note-info);
11+
--g-button-text-color: var(--yfm-color-note-info);
12+
--g-button-text-color-hover: var(--yfm-color-note-info);
1113
}
1214
&note-type-alert {
13-
color: var(--yfm-color-note-important);
15+
--g-button-text-color: var(--yfm-color-note-important);
16+
--g-button-text-color-hover: var(--yfm-color-note-important);
1417
}
1518
&note-type-warning {
16-
color: var(--yfm-color-note-warning);
19+
--g-button-text-color: var(--yfm-color-note-warning);
20+
--g-button-text-color-hover: var(--yfm-color-note-warning);
1721
}
1822
}

packages/editor/src/extensions/yfm/YfmNote/plugins/YfmNoteTooltipPlugin/YfmNoteToolbar.tsx

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ import type {EditorView} from '#pm/view';
99
import {i18n} from 'src/i18n/yfm-note';
1010
import {typedMemo} from 'src/react-utils/memo';
1111
import {Toolbar, type ToolbarData, ToolbarDataType} from 'src/toolbar';
12+
import {ToolbarWrapToContext} from 'src/toolbar/ToolbarRerender';
1213
import {removeNode} from 'src/utils/remove-node';
1314

15+
import {NoteAttrs} from '../../const';
16+
1417
import './YfmNoteToolbar.scss';
1518

1619
const ToolbarMemoized = typedMemo(Toolbar);
@@ -23,7 +26,6 @@ enum YfmNoteType {
2326
}
2427

2528
const isEnable = () => true;
26-
const isActive = () => false;
2729

2830
const changeType: (
2931
type: YfmNoteType,
@@ -38,8 +40,8 @@ const changeType: (
3840
dispatch(
3941
tr.setNodeMarkup(pos, null, {
4042
...node.attrs,
41-
class: `yfm-note yfm-accent-${type}`,
42-
'note-type': type,
43+
[NoteAttrs.Class]: `yfm-note yfm-accent-${type}`,
44+
[NoteAttrs.Type]: type,
4345
}),
4446
);
4547
};
@@ -66,7 +68,7 @@ export function YfmNoteToolbar({pos, node, editorView}: YfmNoteToolbarProps) {
6668
icon: {data: CircleInfo},
6769
title: i18n(type),
6870
type: ToolbarDataType.SingleButton,
69-
isActive,
71+
isActive: () => nodeRef.current.attrs[NoteAttrs.Type] === type,
7072
isEnable,
7173
exec: (view) =>
7274
changeType(type)({
@@ -83,7 +85,8 @@ export function YfmNoteToolbar({pos, node, editorView}: YfmNoteToolbarProps) {
8385
icon: {data: TrashBin},
8486
title: i18n('remove'),
8587
type: ToolbarDataType.SingleButton,
86-
isActive,
88+
theme: 'danger',
89+
isActive: () => false,
8790
isEnable,
8891
exec: (view) =>
8992
removeNode({
@@ -98,14 +101,16 @@ export function YfmNoteToolbar({pos, node, editorView}: YfmNoteToolbarProps) {
98101
}, [nodeRef, posRef]);
99102

100103
return (
101-
<ToolbarMemoized
102-
editor={editorView}
103-
focus={onFocus}
104-
// the yfm class allows to access css variables
105-
// https://github.com/diplodoc-platform/transform/blob/master/src/scss/_common.scss#L17
106-
className="yfm g-md-yfm-note-toolbar"
107-
qa="g-md-toolbar-yfm-note"
108-
data={toolbarData}
109-
/>
104+
<ToolbarWrapToContext editor={editorView}>
105+
<ToolbarMemoized
106+
editor={editorView}
107+
focus={onFocus}
108+
// the yfm class allows to access css variables
109+
// https://github.com/diplodoc-platform/transform/blob/master/src/scss/_common.scss#L17
110+
className="yfm g-md-yfm-note-toolbar"
111+
qa="g-md-toolbar-yfm-note"
112+
data={toolbarData}
113+
/>
114+
</ToolbarWrapToContext>
110115
);
111116
}

0 commit comments

Comments
 (0)