88 "strings"
99 "time"
1010
11+ "github.com/rfwlab/rfw/v1/composition"
1112 "github.com/rfwlab/rfw/v1/core"
1213 dom "github.com/rfwlab/rfw/v1/dom"
1314 events "github.com/rfwlab/rfw/v1/events"
@@ -106,11 +107,11 @@ func (c *DocsComponent) mount(hc *core.HTMLComponent) {
106107 if ! strings .Contains (strings .ToLower (title ), q ) {
107108 continue
108109 }
109- a := doc . CreateElement ( "a" )
110- a . Set ( "href" , " /docs/"+ link )
111- a . Set ( "textContent" , title )
112- a . Set ( "className " , "block px-2 py-1 text-gray-700 dark:text-zinc-200 hover:bg-gray-100 dark:hover:bg-zinc-700" )
113- ch := events .Listen ("mousedown" , a .Value )
110+ a := composition . A ().
111+ Href ( " /docs/"+ link ).
112+ Text ( title ).
113+ Classes ( "block " , "px-2" , " py-1" , " text-gray-700" , " dark:text-zinc-200" , " hover:bg-gray-100" , " dark:hover:bg-zinc-700" )
114+ ch := events .Listen ("mousedown" , a .Element (). Value )
114115 go func (l string ) {
115116 for e := range ch {
116117 if ! c .mounted {
@@ -123,7 +124,7 @@ func (c *DocsComponent) mount(hc *core.HTMLComponent) {
123124 router .Navigate ("/docs/" + l )
124125 }
125126 }(link )
126- results .Call ( "appendChild" , a . Value )
127+ results .AppendChild ( a . Element () )
127128 count ++
128129 if count >= 5 {
129130 break
@@ -199,11 +200,11 @@ func (c *DocsComponent) mount(hc *core.HTMLComponent) {
199200 id := h .Get ("id" ).String ()
200201 text := h .Get ("text" ).String ()
201202 depth := h .Get ("depth" ).Int ()
202- a := doc . CreateElement ( "a" )
203- a . Set ( "href" , " #"+ id )
204- a . Set ( "textContent" , text )
205- a . Set ( "className " , "block py-1 pl-" + strconv .Itoa ((depth - 1 )* 4 )+ " text-gray-700 dark:text-zinc-200 dark:hover:text-white hover:text-black" )
206- ch := events .Listen ("click" , a .Value )
203+ a := composition . A ().
204+ Href ( " #"+ id ).
205+ Text ( text ).
206+ Classes ( "block " , "py-1" , " pl-"+ strconv .Itoa ((depth - 1 )* 4 ), " text-gray-700" , " dark:text-zinc-200" , " dark:hover:text-white" , " hover:text-black" )
207+ ch := events .Listen ("click" , a .Element (). Value )
207208 go func (i string ) {
208209 for e := range ch {
209210 e .Call ("preventDefault" )
@@ -212,7 +213,7 @@ func (c *DocsComponent) mount(hc *core.HTMLComponent) {
212213 }
213214 }
214215 }(id )
215- toc .Call ( "appendChild" , a . Value )
216+ toc .AppendChild ( a . Element () )
216217 }
217218 }
218219 }
@@ -236,33 +237,33 @@ func (c *DocsComponent) mount(hc *core.HTMLComponent) {
236237 nav .SetHTML ("" )
237238 if idx > 0 {
238239 prev := c .order [idx - 1 ]
239- a := doc . CreateElement ( "a" )
240- a . Set ( "className" , " text-white" )
241- a . Set ( "href" , " /docs/"+ prev )
242- a . Set ( "textContent" , " \u2190 "+ c .titleFor (prev ))
243- ch := events .Listen ("click" , a .Value )
240+ a := composition . A ().
241+ Classes ( " text-white" ).
242+ Href ( " /docs/" + prev ).
243+ Text ( " \u2190 " + c .titleFor (prev ))
244+ ch := events .Listen ("click" , a .Element (). Value )
244245 go func (p string ) {
245246 for e := range ch {
246247 e .Call ("preventDefault" )
247248 router .Navigate ("/docs/" + p )
248249 }
249250 }(prev )
250- nav .Call ( "appendChild" , a . Value )
251+ nav .AppendChild ( a . Element () )
251252 }
252253 if idx >= 0 && idx < len (c .order )- 1 {
253254 next := c .order [idx + 1 ]
254- a := doc . CreateElement ( "a" )
255- a . Set ( "className" , " ml-auto text-white" )
256- a . Set ( "href" , " /docs/"+ next )
257- a . Set ( "textContent" , c .titleFor (next )+ " \u2192 " )
258- ch := events .Listen ("click" , a .Value )
255+ a := composition . A ().
256+ Classes ( " ml-auto" , " text-white" ).
257+ Href ( " /docs/" + next ).
258+ Text ( c .titleFor (next ) + " \u2192 " )
259+ ch := events .Listen ("click" , a .Element (). Value )
259260 go func (n string ) {
260261 for e := range ch {
261262 e .Call ("preventDefault" )
262263 router .Navigate ("/docs/" + n )
263264 }
264265 }(next )
265- nav .Call ( "appendChild" , a . Value )
266+ nav .AppendChild ( a . Element () )
266267 }
267268 }
268269 }()
@@ -294,7 +295,6 @@ func (c *DocsComponent) unmount(hc *core.HTMLComponent) {
294295}
295296
296297func (c * DocsComponent ) renderSidebar (items js.Value , parent dom.Element , level int ) {
297- doc := dom .Doc ()
298298 length := items .Length ()
299299 for i := 0 ; i < length ; i ++ {
300300 item := items .Index (i )
@@ -307,11 +307,11 @@ func (c *DocsComponent) renderSidebar(items js.Value, parent dom.Element, level
307307 link := strings .TrimSuffix (path .String (), ".md" )
308308 c .meta [link ] = struct { Title , Description string }{Title : title , Description : desc }
309309 c .order = append (c .order , link )
310- a := doc . CreateElement ( "a" )
311- a . Set ( "href" , " /docs/"+ link )
312- a . Set ( "textContent" , title )
313- a . Set ( "className " , "block py-1 pl-" + strconv .Itoa (4 * level )+ " text-gray-700 dark:text-zinc-200 dark:hover:text-white hover:text-black" )
314- ch := events .Listen ("click" , a .Value )
310+ a := composition . A ().
311+ Href ( " /docs/"+ link ).
312+ Text ( title ).
313+ Classes ( "block " , "py-1" , " pl-"+ strconv .Itoa (4 * level ), " text-gray-700" , " dark:text-zinc-200" , " dark:hover:text-white" , " hover:text-black" )
314+ ch := events .Listen ("click" , a .Element (). Value )
315315 go func (l string ) {
316316 for evt := range ch {
317317 if ! c .mounted {
@@ -321,14 +321,14 @@ func (c *DocsComponent) renderSidebar(items js.Value, parent dom.Element, level
321321 router .Navigate ("/docs/" + l )
322322 }
323323 }(link )
324- parent .Call ( "appendChild" , a . Value )
324+ parent .AppendChild ( a . Element () )
325325 }
326326 if children := item .Get ("children" ); children .Truthy () {
327327 if ! item .Get ("path" ).Truthy () && title != "" {
328- h := doc . CreateElement ( "div" )
329- h . Set ( "textContent" , title )
330- h . Set ( "className" , " mt-4 mb-1 font-semibold text-gray-900 dark:text-white pl-"+ strconv .Itoa (4 * level ))
331- parent .Call ( "appendChild" , h . Value )
328+ h := composition . Div ().
329+ Text ( title ).
330+ Classes ( " mt-4" , " mb-1" , " font-semibold" , " text-gray-900" , " dark:text-white" , " pl-"+ strconv .Itoa (4 * level ))
331+ parent .AppendChild ( h . Element () )
332332 }
333333 c .renderSidebar (children , parent , level + 1 )
334334 }
0 commit comments