Skip to content

Commit 3d05153

Browse files
committed
feat: Enhance the fullscreen command. #217
1 parent 155e77a commit 3d05153

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

core/src/commands/fullscreen.tsx

+16-8
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@ import React, { useEffect, useRef, useState } from 'react';
22
import { ICommand } from '.';
33
import { IMarkdownEditor, ToolBarProps } from '..';
44

5-
const Fullscreen: React.FC<{ command: ICommand; editorProps: IMarkdownEditor & ToolBarProps }> = (props) => {
6-
const { editorProps } = props;
5+
interface FullscreenButtonProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'onClick'> {
6+
command: ICommand;
7+
editorProps: IMarkdownEditor & ToolBarProps;
8+
onClick?: (evn: React.MouseEvent<HTMLButtonElement, MouseEvent>, isFull: boolean) => void;
9+
}
10+
11+
export const FullscreenButton: React.FC<FullscreenButtonProps> = (props) => {
12+
const { editorProps, command, onClick, ...reset } = props;
713
const $height = useRef<number>(0);
814
const [full, setFull] = useState(false);
915
const fullRef = useRef(full);
@@ -72,22 +78,24 @@ const Fullscreen: React.FC<{ command: ICommand; editorProps: IMarkdownEditor & T
7278
}
7379
}, [full, editorProps]);
7480

75-
const click = () => {
76-
fullRef.current = !full;
77-
setFull(!full);
81+
const click = (evn: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
82+
let isFull = !full;
83+
fullRef.current = isFull;
84+
setFull(isFull);
85+
onClick?.(evn, isFull);
7886
};
7987

8088
return (
81-
<button onClick={click} type="button" className={full ? 'active' : ''}>
82-
{props.command.icon}
89+
<button {...reset} onClick={click} type="button" className={full ? 'active' : ''}>
90+
{command.icon}
8391
</button>
8492
);
8593
};
8694

8795
export const fullscreen: ICommand = {
8896
name: 'fullscreen',
8997
keyCommand: 'fullscreen',
90-
button: (command, props, opts) => <Fullscreen command={command} editorProps={{ ...props, ...opts }} />,
98+
button: (command, props, opts) => <FullscreenButton command={command} editorProps={{ ...props, ...opts }} />,
9199
icon: (
92100
<svg fill="currentColor" viewBox="0 0 448 512" height="15" width="15">
93101
<path d="M128 32H32C14.31 32 0 46.31 0 64v96c0 17.69 14.31 32 32 32s32-14.31 32-32V96h64c17.69 0 32-14.31 32-32s-14.3-32-32-32zm288 0h-96c-17.69 0-32 14.31-32 32s14.31 32 32 32h64v64c0 17.69 14.31 32 32 32s32-14.31 32-32V64c0-17.69-14.3-32-32-32zM128 416H64v-64c0-17.69-14.31-32-32-32S0 334.31 0 352v96c0 17.69 14.31 32 32 32h96c17.69 0 32-14.31 32-32s-14.3-32-32-32zm288-96c-17.69 0-32 14.31-32 32v64h-64c-17.69 0-32 14.31-32 32s14.31 32 32 32h96c17.69 0 32-14.31 32-32v-96c0-17.7-14.3-32-32-32z" />

0 commit comments

Comments
 (0)