1
1
import { defineRoot , dirtyCheck , update , component , List , eventDispatcher , getProps , useReducer } from "ivi" ;
2
- import { htm } from "@ivi/tpl " ;
2
+ import { htm as html } from "@ivi/htm " ;
3
3
import { Entry , State , Action , ActionType } from "./types.js" ;
4
4
5
5
const random = ( max : number ) => Math . round ( Math . random ( ) * 1000 ) % max ;
@@ -66,21 +66,26 @@ interface RowProps {
66
66
const Row = component < RowProps > ( ( c ) => {
67
67
const onSelect = ( ) => { dispatch ( c , { type : ActionType . Select , entry : getProps ( c ) . entry } ) ; } ;
68
68
const onRemove = ( ) => { dispatch ( c , { type : ActionType . Remove , entry : getProps ( c ) . entry } ) ; } ;
69
- return ( { entry, selected } ) => htm `
70
- tr${ selected === true ? "danger" : "" }
71
- td.col-md-1 =${ entry . id }
72
- td.col-md-4
73
- a @click=${ onSelect } =${ entry . label }
74
- td.col-md-1
75
- a @click=${ onRemove } span.glyphicon.glyphicon-remove :aria-hidden='true'
76
- td.col-md-6
77
- ` ;
69
+ return ( { entry, selected } ) => html `
70
+ < tr class =${ selected === true ? "danger" : "" } >
71
+ < td class ="col-md-1 " .textContent =${ entry . id } / >
72
+ < td class ="col-md-4 ">
73
+ < a @click =${ onSelect } .textContent =${ entry . label } />
74
+ </ td >
75
+ < td class ="col-md-1 ">
76
+ < a @click =${ onRemove } >
77
+ < span class ="glyphicon glyphicon-remove " aria-hidden ="true "/>
78
+ </ a >
79
+ </ td >
80
+ < td class ="col-md-6 "/>
81
+ </ tr >
82
+ ` ;
78
83
} ) ;
79
84
80
- const Button = ( text : string , id : string , onClick : ( ) => void ) => /* preventClone */ htm `
81
- div. col-sm-6. smallpad
82
- button. btn. btn-primary. btn-block : type=' button' : id=${ id } @click=${ onClick }
83
- = ${ text }
85
+ const Button = ( text : string , id : string , onClick : ( ) => void ) => /* preventClone */ html `
86
+ < div class =" col-sm-6 smallpad " >
87
+ < button class =" btn btn-primary btn-block " type =" button " id =${ id } @click =${ onClick } .textContent= ${ text } />
88
+ </ div >
84
89
` ;
85
90
86
91
const App = component ( ( c ) => {
@@ -98,18 +103,28 @@ const App = component((c) => {
98
103
99
104
return ( ) => {
100
105
const { data, selected } = _state ( ) ;
101
- return /* preventClone */ htm `
102
- div.container
103
- div.jumbotron
104
- div.row
105
- div.col-md-6 h1 'ivi'
106
- div.col-md-6 div.row ${ buttons }
107
- table.table.table-hover.table-striped.test-data
108
- @dispatch=${ onDispatch }
109
- ${ data . length
110
- ? htm `tbody ${ List ( data , getEntryId , ( entry ) => Row ( { entry, selected : selected === entry . id } ) ) } `
111
- : htm `tbody` }
112
- span.preloadicon.glyphicon.glyphicon-remove :aria-hidden='true'
106
+ return /* preventClone */ html `
107
+ < div class ="container ">
108
+ < div class ="jumbotron ">
109
+ < div class ="row ">
110
+ < div class ="col-md-6 ">
111
+ < h1 > ivi</ h1 >
112
+ </ div >
113
+ < div class ="col-md-6 ">
114
+ < div class ="row ">
115
+ ${ buttons }
116
+ </ div >
117
+ </ div >
118
+ </ div >
119
+ </ div >
120
+ < table class ="table table-hover table-striped test-data " @dispatch =${ onDispatch } >
121
+ ${ data . length
122
+ ? html `< tbody > ${ List ( data , getEntryId , ( entry ) => Row ( { entry, selected : selected === entry . id } ) ) } </ tbody > `
123
+ : html `< tbody /> `
124
+ }
125
+ </ table >
126
+ < span class ="preloadicon glyphicon glyphicon-remove " aria-hidden ="true "/>
127
+ </ div >
113
128
` ;
114
129
} ;
115
130
} ) ;
0 commit comments