1
- import React , { ChangeEvent , memo , PropsWithChildren , useCallback , useState } from 'react'
1
+ import React , { ChangeEvent , memo , PropsWithChildren , useState } from 'react'
2
2
3
3
import MySvg from '../svg/index'
4
4
import styles from './style.module.scss'
5
- import { Input , message , Dropdown } from 'antd'
6
- import { SettingOutlined } from '@ant-design/icons'
7
- import { settingMenu } from 'src/mock'
8
- import MyMenu from 'src/components/my-menu'
9
- import { SettingMenuItem } from 'src/utils'
5
+ import { Input , message , Dropdown , Menu } from 'antd'
6
+ import { SettingOutlined , CheckOutlined } from '@ant-design/icons'
7
+ import { settingMenu } from 'src/mock'
8
+ import { SettingMenuItem } from 'src/utils'
10
9
11
10
interface MyHeaderProps {
12
11
onInputValue ?: ( val : string ) => void
13
12
onMenuChange ?: ( val : any ) => void
14
13
}
15
14
16
- export default memo ( function index ( { onInputValue, onMenuChange } : PropsWithChildren < MyHeaderProps > ) {
17
- console . log ( 'header' )
15
+ const handleItemContent = ( item : SettingMenuItem ) => {
16
+ if ( item . type === 'check' ) {
17
+ const activedClass = item . value === '1' ? styles [ 'actived' ] : ''
18
+ return (
19
+ < >
20
+ < CheckOutlined className = { activedClass } />
21
+ < span className = { activedClass } > { item . content } </ span >
22
+ </ >
23
+ )
24
+ }
25
+ return item . content
26
+ }
27
+
28
+ export default memo ( function index ( {
29
+ onInputValue,
30
+ onMenuChange,
31
+ } : PropsWithChildren < MyHeaderProps > ) {
18
32
const [ menuData , setMenuData ] = useState < SettingMenuItem [ ] > ( settingMenu )
19
33
20
34
const handleChange = ( e : ChangeEvent < HTMLInputElement > ) => {
@@ -25,23 +39,30 @@ export default memo(function index({ onInputValue, onMenuChange }: PropsWithChil
25
39
onInputValue && onInputValue ( value )
26
40
}
27
41
28
- const onChangeKey = ( key : string ) => {
29
- const newData = menuData . map ( item => {
42
+ const onChangeKey = ( { key } : any ) => {
43
+ const newData = menuData . map ( ( item ) => {
30
44
if ( item . id === parseInt ( key ) ) {
31
45
if ( key === '120' ) {
32
46
const changeValue = item . value === '0' ? '1' : '0'
47
+ changeValue === '1' && message . success ( '已启用markdown语法' )
33
48
onMenuChange && onMenuChange ( changeValue )
34
- return { ...item , value : changeValue }
49
+ return { ...item , value : changeValue }
35
50
}
36
51
}
37
52
return item
38
53
} )
39
54
setMenuData ( newData )
40
55
}
41
56
42
- const showMenu = useCallback ( ( ) => {
43
- return < MyMenu menuData = { menuData } onChangeKey = { onChangeKey } />
44
- } , [ menuData ] )
57
+ const menu = (
58
+ < Menu onClick = { onChangeKey } className = { styles [ 'menu-container' ] } >
59
+ { menuData . map ( ( item ) => (
60
+ < Menu . Item key = { item . id } className = { styles [ 'menu-item' ] } >
61
+ { handleItemContent ( item ) }
62
+ </ Menu . Item >
63
+ ) ) }
64
+ </ Menu >
65
+ )
45
66
46
67
return (
47
68
< div className = { styles [ 'header-container' ] } >
@@ -56,7 +77,7 @@ export default memo(function index({ onInputValue, onMenuChange }: PropsWithChil
56
77
</ div >
57
78
</ div >
58
79
< div className = { `${ styles [ 'header-right' ] } all-center` } >
59
- < Dropdown overlay = { showMenu } >
80
+ < Dropdown overlay = { menu } trigger = { [ 'click' ] } >
60
81
< SettingOutlined className = { styles [ 'setting' ] } />
61
82
</ Dropdown >
62
83
</ div >
0 commit comments