Skip to content

Commit 48e4942

Browse files
committed
feat(highlight): impl .defaultColor and render 'no fill' as none instead of yellow
1 parent 37110e1 commit 48e4942

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/extensions/Highlight/Highlight.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@ import type { GeneralOptions } from '@/types';
55

66
import HighlightActionButton from './components/HighlightActionButton';
77

8-
export interface HighlightOptions
9-
extends TiptapHighlightOptions,
10-
GeneralOptions<HighlightOptions> {}
8+
export interface HighlightOptions extends TiptapHighlightOptions, GeneralOptions<HighlightOptions> {
9+
/**
10+
* The default color to use initially
11+
*/
12+
defaultColor?: string
13+
}
1114

1215
export const Highlight = /* @__PURE__ */ TiptapHighlight.extend<HighlightOptions>({
1316
addOptions() {
1417
return {
1518
...this.parent?.(),
1619
multicolor: true,
17-
button: ({ editor, t }) => ({
20+
button: ({ editor, t, extension }) => ({
1821
component: HighlightActionButton,
1922
componentProps: {
2023
action: (color?: unknown) => {
@@ -30,6 +33,7 @@ export const Highlight = /* @__PURE__ */ TiptapHighlight.extend<HighlightOptions
3033
disabled: false,
3134
shortcutKeys: ['⇧', 'mod', 'H'],
3235
tooltip: t('editor.highlight.tooltip'),
36+
defaultColor: extension.options.defaultColor
3337
},
3438
}),
3539
};

src/extensions/Highlight/components/HighlightActionButton.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ interface IPropsHighlightActionButton {
1515
isActive?: ButtonViewReturnComponentProps['isActive']
1616
tooltipOptions?: TooltipContentProps
1717
shortcutKeys?: string[]
18+
defaultColor?: string
1819
}
1920

2021
function IconC({ fill }: any) {
@@ -50,7 +51,7 @@ function IconC({ fill }: any) {
5051
<path
5152
d="M51,218 L205,218 C211.075132,218 216,222.924868 216,229 C216,235.075132 211.075132,240 205,240 L51,240 C44.9248678,240 40,235.075132 40,229 C40,222.924868 44.9248678,218 51,218 Z"
5253
id="矩形"
53-
fill={fill || '#FBDE28'}
54+
fill={fill || 'none'}
5455
/>
5556
</g>
5657
</g>
@@ -60,7 +61,7 @@ function IconC({ fill }: any) {
6061

6162
function HighlightActionButton(props: IPropsHighlightActionButton) {
6263
// const { action, isActive, disabled, icon, tooltip } = props as any;
63-
const [selectedColor, setSelectedColor] = useState<any>(undefined);
64+
const [selectedColor, setSelectedColor] = useState<any>(props?.defaultColor);
6465

6566
function onChange(color: string | undefined) {
6667
props.action?.(color);

0 commit comments

Comments
 (0)