@@ -10,6 +10,12 @@ interface FormatControlsProps {
1010 onAction : ( action : AppAction ) => void ;
1111}
1212
13+ const alignments = [
14+ { icon : 'fa fa-align-left' , label : 'Align left' , value : 'left' , textAlign : TextAlign . Left } ,
15+ { icon : 'fa fa-align-center' , label : 'Align center' , value : 'center' , textAlign : TextAlign . Center } ,
16+ { icon : 'fa fa-align-right' , label : 'Align right' , value : 'right' , textAlign : TextAlign . Right } ,
17+ ] ;
18+
1319export function FormatControls ( props : FormatControlsProps ) {
1420 const action = ( actionName : string , args ?: any ) => props . onAction ( { actionName, args} ) ;
1521
@@ -30,22 +36,22 @@ export function FormatControls(props: FormatControlsProps) {
3036 } ) ) ,
3137 ) ,
3238 React . createElement ( 'div' , { className : 'ows-button-row' } ,
33- React . createElement ( AlignButton , { action, alignment : TextAlign . Left , appearance : props . appearance } ) ,
34- React . createElement ( AlignButton , { action, alignment : TextAlign . Center , appearance : props . appearance } ) ,
35- React . createElement ( AlignButton , { action, alignment : TextAlign . Right , appearance : props . appearance } ) ,
39+ alignments . map ( ( alignment ) => React . createElement ( AlignButton , {
40+ action,
41+ alignment,
42+ appearance : props . appearance ,
43+ key : alignment . value ,
44+ } ) ) ,
3645 ) ,
3746 ) ,
3847 ) ;
3948}
4049
4150function AlignButton ( { action, alignment, appearance} : any ) {
42- const icon = alignment === TextAlign . Left
43- ? 'fa fa-align-left'
44- : alignment === TextAlign . Center ? 'fa fa-align-center' : 'fa fa-align-right' ;
45-
4651 return React . createElement ( Button , {
47- active : appearance . textAlign === alignment ,
48- icon,
49- onClick : ( ) => action ( 'align' , alignment ) ,
52+ active : appearance . textAlign === alignment . textAlign ,
53+ icon : alignment . icon ,
54+ onClick : ( ) => action ( 'align' , alignment . value ) ,
55+ title : alignment . label ,
5056 } ) ;
5157}
0 commit comments