Skip to content

Commit 16c4a63

Browse files
committed
♻️(frontend) replace default comment toolbar button
Replace the default comment toolbar button with a custom one to follow the design system.
1 parent e397d46 commit 16c4a63

File tree

3 files changed

+88
-1
lines changed

3 files changed

+88
-1
lines changed

src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteToolBar/BlockNoteToolbar.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { useTranslation } from 'react-i18next';
1010

1111
import { useConfig } from '@/core/config/api';
1212

13+
import { CommentToolbarButton } from '../comments/CommentToolbarButton';
1314
import { getCalloutFormattingToolbarItems } from '../custom-blocks';
1415

1516
import { AIGroupButton } from './AIButton';
@@ -25,17 +26,21 @@ export const BlockNoteToolbar = () => {
2526
const { data: conf } = useConfig();
2627

2728
const toolbarItems = useMemo(() => {
28-
const toolbarItems = getFormattingToolbarItems([
29+
let toolbarItems = getFormattingToolbarItems([
2930
...blockTypeSelectItems(dict),
3031
getCalloutFormattingToolbarItems(t),
3132
]);
33+
34+
// Find the index of the file download button
3235
const fileDownloadButtonIndex = toolbarItems.findIndex(
3336
(item) =>
3437
typeof item === 'object' &&
3538
item !== null &&
3639
'key' in item &&
3740
(item as { key: string }).key === 'fileDownloadButton',
3841
);
42+
43+
// Replace the default file download button with our custom FileDownloadButton
3944
if (fileDownloadButtonIndex !== -1) {
4045
toolbarItems.splice(
4146
fileDownloadButtonIndex,
@@ -50,12 +55,22 @@ export const BlockNoteToolbar = () => {
5055
);
5156
}
5257

58+
// Remove default Comment button
59+
toolbarItems = toolbarItems.filter((item) => {
60+
if (typeof item === 'object' && item !== null && 'key' in item) {
61+
return item.key !== 'addCommentButton';
62+
}
63+
return true;
64+
});
65+
5366
return toolbarItems;
5467
}, [dict, t]);
5568

5669
const formattingToolbar = useCallback(() => {
5770
return (
5871
<FormattingToolbar>
72+
<CommentToolbarButton />
73+
5974
{toolbarItems}
6075

6176
{/* Extra button to do some AI powered actions */}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { useBlockNoteEditor, useComponentsContext } from '@blocknote/react';
2+
import { useTranslation } from 'react-i18next';
3+
import { css } from 'styled-components';
4+
5+
import { Box, Icon } from '@/components';
6+
import { useCunninghamTheme } from '@/cunningham';
7+
import { useDocStore } from '@/features/docs/doc-management';
8+
9+
import {
10+
DocsBlockSchema,
11+
DocsInlineContentSchema,
12+
DocsStyleSchema,
13+
} from '../../types';
14+
15+
export const CommentToolbarButton = () => {
16+
const Components = useComponentsContext();
17+
const { currentDoc } = useDocStore();
18+
const { t } = useTranslation();
19+
const { spacingsTokens, colorsTokens } = useCunninghamTheme();
20+
const editor = useBlockNoteEditor<
21+
DocsBlockSchema,
22+
DocsInlineContentSchema,
23+
DocsStyleSchema
24+
>();
25+
26+
const hasActiveUnresolvedThread = editor._tiptapEditor.isActive('comment', {
27+
orphan: false,
28+
});
29+
30+
if (!editor.isEditable || !Components || !currentDoc?.abilities.comment) {
31+
return null;
32+
}
33+
34+
return (
35+
<Box $direction="row" className="--docs--comment-toolbar-button">
36+
<Components.Generic.Toolbar.Button
37+
className="bn-button"
38+
onClick={() => {
39+
editor.comments?.startPendingComment();
40+
}}
41+
isDisabled={hasActiveUnresolvedThread}
42+
>
43+
<Box
44+
$direction="row"
45+
$align="center"
46+
$gap={spacingsTokens['xs']}
47+
$padding={{ right: '2xs' }}
48+
>
49+
<Icon
50+
iconName="comment"
51+
className="--docs--icon-bg"
52+
$theme="greyscale"
53+
$variation="600"
54+
$padding="0.15rem"
55+
$size="16px"
56+
/>
57+
{t('Comment')}
58+
</Box>
59+
</Components.Generic.Toolbar.Button>
60+
<Box
61+
$background={colorsTokens['greyscale-100']}
62+
$width="1px"
63+
$height="70%"
64+
$margin={{ left: '2px' }}
65+
$css={css`
66+
align-self: center;
67+
`}
68+
/>
69+
</Box>
70+
);
71+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
export * from './CommentToolbarButton';
12
export * from './styles';
23
export * from './useComments';

0 commit comments

Comments
 (0)