Skip to content

Commit e68c611

Browse files
feat(apollo-react): added platform detection util to StickyNoteNode
1 parent e6316bb commit e68c611

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

packages/apollo-react/src/canvas/components/StickyNoteNode/FormattingToolbar.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
ToolbarSeparator,
1616
} from './StickyNoteNode.styles';
1717
import type { TextSelection } from './StickyNoteNode.types';
18+
import { getModifierKey, isMac } from './StickyNoteNode.utils';
1819

1920
interface FormattingToolbarProps {
2021
textAreaRef: RefObject<HTMLTextAreaElement | null>;
@@ -52,23 +53,26 @@ const FormattingToolbarComponent = ({
5253
const handleBulletList = useCallback(() => applyFormat(toggleBulletList), [applyFormat]);
5354
const handleNumberedList = useCallback(() => applyFormat(toggleNumberedList), [applyFormat]);
5455

56+
const mod = getModifierKey();
57+
const shift = isMac() ? '⇧' : '+Shift+';
58+
5559
return (
5660
<FormattingToolbarContainer
5761
borderColor={borderColor}
5862
onMouseDown={(e) => e.preventDefault()}
5963
className="nodrag nowheel"
6064
>
61-
<ApTooltip content="Bold (⌘B)" placement="top" delay>
65+
<ApTooltip content={`Bold (${mod}+B)`} placement="top" delay>
6266
<FormattingButton isActive={activeFormats.bold} onClick={handleBold}>
6367
<NodeIcon icon="bold" size={14} />
6468
</FormattingButton>
6569
</ApTooltip>
66-
<ApTooltip content="Italic (⌘I)" placement="top" delay>
70+
<ApTooltip content={`Italic (${mod}+I)`} placement="top" delay>
6771
<FormattingButton isActive={activeFormats.italic} onClick={handleItalic}>
6872
<NodeIcon icon="italic" size={14} />
6973
</FormattingButton>
7074
</ApTooltip>
71-
<ApTooltip content="Strikethrough (⌘⇧X)" placement="top" delay>
75+
<ApTooltip content={`Strikethrough (${mod}${shift}X)`} placement="top" delay>
7276
<FormattingButton isActive={activeFormats.strikethrough} onClick={handleStrikethrough}>
7377
<NodeIcon icon="strikethrough" size={14} />
7478
</FormattingButton>

packages/apollo-react/src/canvas/components/StickyNoteNode/StickyNoteNode.utils.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,21 @@ export const preserveNewlines = (markdown: string): string => {
2222

2323
return result;
2424
};
25+
26+
// NOTE: refactor isMac and getModifierKey into shared util if using within components outside of StickyNoteNode.
27+
28+
/**
29+
* Returns true if the current platform is macOS.
30+
*/
31+
export const isMac = (): boolean => {
32+
return typeof navigator !== 'undefined' && navigator.platform.includes('Mac');
33+
};
34+
35+
/**
36+
* Returns the platform-specific modifier key symbol
37+
* - Mac: ⌘ (Command)
38+
* - Windows/Linux: Ctrl
39+
*/
40+
export const getModifierKey = (): string => {
41+
return isMac() ? '⌘' : 'Ctrl';
42+
};

0 commit comments

Comments
 (0)