11import { Dom } from '../core/dom' ;
2-
3- const CENTER_ICON =
4- '<path d="M0 0h48v48h-48z" fill="none"/><path d="M24 16c-4.42 0-8 3.58-8 8s3.58 8 8 8 8-3.58 8-8-3.58-8-8-8zm-14 14h-4v8c0 2.21 1.79 4 4 4h8v-4h-8v-8zm0-20h8v-4h-8c-2.21 0-4 1.79-4 4v8h4v-8zm28-4h-8v4h8v8h4v-8c0-2.21-1.79-4-4-4zm0 32h-8v4h8c2.21 0 4-1.79 4-4v-8h-4v8z"/>' ;
5- const DELETE_ICON =
6- '<path d="M24 4c-11.05 0-20 8.95-20 20s8.95 20 20 20 20-8.95 20-20-8.95-20-20-20zm10 27.17l-2.83 2.83-7.17-7.17-7.17 7.17-2.83-2.83 7.17-7.17-7.17-7.17 2.83-2.83 7.17 7.17 7.17-7.17 2.83 2.83-7.17 7.17 7.17 7.17z" fill="#E01A24"/><path d="M0 0h48v48h-48z" fill="none"/>' ;
7- const MOVE_ICON =
8- '<path d="M20 18h8v-6h6l-10-10-10 10h6v6zm-2 2h-6v-6l-10 10 10 10v-6h6v-8zm28 4l-10-10v6h-6v8h6v6l10-10zm-18 6h-8v6h-6l10 10 10-10h-6v-6z"/><path d="M0 0h48v48h-48z" fill="none"/>' ;
2+ import { Icons } from '../core/icons' ;
93
104export class ControlBarView {
115 public static create ( parent : HTMLElement ) : ControlBarView {
126 const root = Dom . element ( 'div' , {
137 class : 'sqd-control-bar'
148 } ) ;
159
16- const deleteButton = createButton ( DELETE_ICON , 'Delete selected step' ) ;
10+ const deleteButton = createButton ( Icons . delete , 'Delete selected step' ) ;
1711 deleteButton . classList . add ( 'sqd-hidden' ) ;
1812
19- const resetButton = createButton ( CENTER_ICON , 'Reset' ) ;
13+ const resetButton = createButton ( Icons . center , 'Reset' ) ;
2014
21- const moveButton = createButton ( MOVE_ICON , 'Turn on/off drag and drop' ) ;
15+ const moveButton = createButton ( Icons . move , 'Turn on/off drag and drop' ) ;
2216 moveButton . classList . add ( 'sqd-disabled' ) ;
2317
2418 root . appendChild ( resetButton ) ;
@@ -35,16 +29,25 @@ export class ControlBarView {
3529 private readonly resetButton : Element
3630 ) { }
3731
38- public bindDeleteButtonClick ( handler : ( e : Event ) => void ) {
39- this . deleteButton . addEventListener ( 'click' , handler ) ;
32+ public bindDeleteButtonClick ( handler : ( ) => void ) {
33+ this . deleteButton . addEventListener ( 'click' , e => {
34+ e . preventDefault ( ) ;
35+ handler ( ) ;
36+ } ) ;
4037 }
4138
42- public bindMoveButtonClick ( handler : ( e : Event ) => void ) {
43- this . moveButton . addEventListener ( 'click' , handler ) ;
39+ public bindMoveButtonClick ( handler : ( ) => void ) {
40+ this . moveButton . addEventListener ( 'click' , e => {
41+ e . preventDefault ( ) ;
42+ handler ( ) ;
43+ } ) ;
4444 }
4545
46- public bindResetButtonClick ( handler : ( e : Event ) => void ) {
47- this . resetButton . addEventListener ( 'click' , handler ) ;
46+ public bindResetButtonClick ( handler : ( ) => void ) {
47+ this . resetButton . addEventListener ( 'click' , e => {
48+ e . preventDefault ( ) ;
49+ handler ( ) ;
50+ } ) ;
4851 }
4952
5053 public setIsDeleteButtonHidden ( isHidden : boolean ) {
@@ -61,11 +64,7 @@ function createButton(iconContent: string, title: string): HTMLElement {
6164 class : 'sqd-control-bar-button' ,
6265 title
6366 } ) ;
64- const icon = Dom . svg ( 'svg' , {
65- class : 'sqd-control-bar-button-icon' ,
66- viewBox : '0 0 48 48'
67- } ) ;
68- icon . innerHTML = iconContent ;
67+ const icon = Icons . create ( 'sqd-control-bar-button-icon' , iconContent ) ;
6968 button . appendChild ( icon ) ;
7069 return button ;
7170}
0 commit comments