@@ -2,8 +2,14 @@ import React, { useEffect, useRef, useState } from 'react';
2
2
import { ICommand } from '.' ;
3
3
import { IMarkdownEditor , ToolBarProps } from '..' ;
4
4
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 ;
7
13
const $height = useRef < number > ( 0 ) ;
8
14
const [ full , setFull ] = useState ( false ) ;
9
15
const fullRef = useRef ( full ) ;
@@ -72,22 +78,24 @@ const Fullscreen: React.FC<{ command: ICommand; editorProps: IMarkdownEditor & T
72
78
}
73
79
} , [ full , editorProps ] ) ;
74
80
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 ) ;
78
86
} ;
79
87
80
88
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 }
83
91
</ button >
84
92
) ;
85
93
} ;
86
94
87
95
export const fullscreen : ICommand = {
88
96
name : 'fullscreen' ,
89
97
keyCommand : 'fullscreen' ,
90
- button : ( command , props , opts ) => < Fullscreen command = { command } editorProps = { { ...props , ...opts } } /> ,
98
+ button : ( command , props , opts ) => < FullscreenButton command = { command } editorProps = { { ...props , ...opts } } /> ,
91
99
icon : (
92
100
< svg fill = "currentColor" viewBox = "0 0 448 512" height = "15" width = "15" >
93
101
< 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