1
- import { Button , Dropdown } from 'antd' ;
1
+ import { Button , Dropdown , Space , Switch , Typography } from 'antd' ;
2
2
import classNames from 'classnames' ;
3
3
import RecentListComponent from 'components/common/recent-list.component' ;
4
4
import SearchableMenuComponent from 'components/common/searchable-menu.component' ;
5
5
import React from 'react' ;
6
- import { AiOutlineDown } from 'react-icons/ai' ;
6
+ import { AiOutlineCheck , AiOutlineClose , AiOutlineDown } from 'react-icons/ai' ;
7
7
import withStyles , { WithStylesProps } from 'react-jss' ;
8
8
import { connect , Dispatch } from 'react-redux' ;
9
9
import { GitmojiDefinition , GITMOJIS } from 'shared/presets/gitmojis' ;
10
10
import { AppState , EditorState } from 'state' ;
11
11
12
- import { GitmojiSelectAction } from './state/editor.action' ;
12
+ import { GitmojiSelectAction , ToggleShortcodeAction } from './state/editor.action' ;
13
13
14
14
const styles = ( theme : CommitComposerTheme ) => ( {
15
15
menu : {
@@ -60,8 +60,30 @@ const styles = (theme: CommitComposerTheme) => ({
60
60
minWidth : 'unset' ,
61
61
} ,
62
62
} ,
63
+ searchBar : {
64
+ backgroundColor : theme . lighter ,
65
+ padding : 9 ,
66
+ } ,
67
+ noTopPadding : {
68
+ paddingTop : 0 ,
69
+ } ,
63
70
recentList : {
64
71
maxHeight : 70 ,
72
+ backgroundColor : theme . lighter ,
73
+ } ,
74
+ recentItem : {
75
+ '&:hover' : {
76
+ backgroundColor : theme . itemHoverBG ,
77
+ } ,
78
+ } ,
79
+ actionContainer : {
80
+ padding : '4px 9px' ,
81
+ justifyContent : 'flex-end' ,
82
+ width : '100%' ,
83
+ backgroundColor : theme . lighter ,
84
+ } ,
85
+ actionText : {
86
+ fontSize : 12 ,
65
87
} ,
66
88
} ) ;
67
89
@@ -71,6 +93,7 @@ export interface ReduxProps {
71
93
}
72
94
export interface DispatchProps {
73
95
gitmojiSelected : ( gitmoji : GitmojiDefinition ) => void ;
96
+ toggleShortcode : ( value : boolean ) => void ;
74
97
}
75
98
type Props = WithStylesProps < typeof styles > & OwnProps & ReduxProps & DispatchProps ;
76
99
export interface State {
@@ -106,12 +129,13 @@ class GitmojiPickerComponent extends React.Component<Props, State> {
106
129
}
107
130
108
131
render ( ) : JSX . Element {
109
- const { classes, editor } = this . props ;
132
+ const { classes, editor, toggleShortcode } = this . props ;
110
133
const { hovered, visible } = this . state ;
111
134
112
135
const menu = (
113
136
< span className = { classes . menu } >
114
137
< RecentListComponent
138
+ itemClassName = { classes . recentItem }
115
139
className = { classes . recentList }
116
140
onClick = { ( key ) => this . handleClick ( key ) }
117
141
items = { editor . recentGitmojis . map ( ( x ) => ( {
@@ -127,6 +151,9 @@ class GitmojiPickerComponent extends React.Component<Props, State> {
127
151
< SearchableMenuComponent
128
152
focus = { visible }
129
153
className = { classes . items }
154
+ searchBarClassName = { classNames ( classes . searchBar , {
155
+ [ classes . noTopPadding ] : Boolean ( editor . recentGitmojis ?. length ) ,
156
+ } ) }
130
157
onClick = { ( key ) => this . handleClick ( key ) }
131
158
items = { GITMOJIS . map ( ( x ) => ( {
132
159
item : x . shortcode ,
@@ -137,8 +164,18 @@ class GitmojiPickerComponent extends React.Component<Props, State> {
137
164
{ x . icon }
138
165
</ span >
139
166
) ,
140
- } ) ) }
141
- />
167
+ } ) ) } >
168
+ < Space className = { classes . actionContainer } >
169
+ < Typography . Text className = { classes . actionText } > Shortcode:</ Typography . Text >
170
+ < Switch
171
+ size = "small"
172
+ defaultChecked = { editor . useShortcode }
173
+ checkedChildren = { < AiOutlineCheck /> }
174
+ unCheckedChildren = { < AiOutlineClose /> }
175
+ onChange = { ( x ) => toggleShortcode ( x ) }
176
+ />
177
+ </ Space >
178
+ </ SearchableMenuComponent >
142
179
</ span >
143
180
) ;
144
181
@@ -178,6 +215,7 @@ function mapStateToProps(state: AppState): ReduxProps {
178
215
function mapDispatchToProps ( dispatch : Dispatch ) : DispatchProps {
179
216
return {
180
217
gitmojiSelected : ( gitmoji ) => dispatch ( GitmojiSelectAction . get ( gitmoji ) ) ,
218
+ toggleShortcode : ( value ) => dispatch ( ToggleShortcodeAction . get ( value ) ) ,
181
219
} ;
182
220
}
183
221
0 commit comments