|
351 | 351 | "def Toast(*c, # Content for toast (often test)\n",
|
352 | 352 | " cls='', # Classes for toast (often `ToastHT` and `ToastVT` options)\n",
|
353 | 353 | " alert_cls='', # classes for altert (often `AlertT` options)\n",
|
| 354 | + " dur=5.0, # no. of seconds before the toast disappears\n", |
354 | 355 | " **kwargs # Additional args for outer container (`Div` tag)\n",
|
355 | 356 | " )->FT: # Div(Alert(...), cls='toast')\n",
|
356 | 357 | " \"Toasts are stacked announcements, positioned on the corner of page.\"\n",
|
357 | 358 | " a = Alert(*c, cls=alert_cls)\n",
|
358 |
| - " return Div(a, cls=('toast', stringify(cls)), **kwargs)" |
| 359 | + " _id = fh.unqid()\n", |
| 360 | + " js = Script('''(()=>setTimeout(()=>document.querySelector('[data-mui=\"%s\"]').remove(),%s))()'''%(_id,dur*1000))\n", |
| 361 | + " return Div(a, js, data_mui=_id, cls=('toast', stringify(cls)), **kwargs)" |
359 | 362 | ]
|
360 | 363 | },
|
361 | 364 | {
|
|
376 | 379 | "data": {
|
377 | 380 | "text/markdown": [
|
378 | 381 | "```html\n",
|
379 |
| - "<div class=\"toast toast-start toast-middle\">\n", |
| 382 | + "<div data-mui=\"_yRjKNgMBRCah1Xnjm5yP-w\" class=\"toast toast-start toast-middle\">\n", |
380 | 383 | " <div class=\"alert \" role=\"alert\">\n",
|
381 | 384 | "<span>New message arrived.</span> </div>\n",
|
382 |
| - "</div>\n", |
| 385 | + "<script>(()=>setTimeout(()=>document.querySelector('[data-mui="_yRjKNgMBRCah1Xnjm5yP-w"]').remove(),5000.0))()</script></div>\n", |
383 | 386 | "\n",
|
384 | 387 | "```"
|
385 | 388 | ],
|
386 | 389 | "text/plain": [
|
387 |
| - "div((div((span(('New message arrived.',),{}),),{'class': 'alert ', 'role': 'alert'}),),{'class': 'toast toast-start toast-middle'})" |
| 390 | + "div((div((span(('New message arrived.',),{}),),{'class': 'alert ', 'role': 'alert'}), script(('(()=>setTimeout(()=>document.querySelector(\\'[data-mui=\"_yRjKNgMBRCah1Xnjm5yP-w\"]\\').remove(),5000.0))()',),{})),{'data-mui': '_yRjKNgMBRCah1Xnjm5yP-w', 'class': 'toast toast-start toast-middle'})" |
388 | 391 | ]
|
389 | 392 | },
|
390 | 393 | "execution_count": null,
|
|
414 | 417 | "data": {
|
415 | 418 | "text/markdown": [
|
416 | 419 | "```html\n",
|
417 |
| - "<div class=\"toast \">\n", |
| 420 | + "<div data-mui=\"_HJB8HS8NTsOSXq5TJbCaWA\" class=\"toast \">\n", |
418 | 421 | " <div class=\"alert alert-info\" role=\"alert\">\n",
|
419 | 422 | "<span>New message arrived.</span> </div>\n",
|
420 |
| - "</div>\n", |
| 423 | + "<script>(()=>setTimeout(()=>document.querySelector('[data-mui="_HJB8HS8NTsOSXq5TJbCaWA"]').remove(),5000.0))()</script></div>\n", |
421 | 424 | "\n",
|
422 | 425 | "```"
|
423 | 426 | ],
|
424 | 427 | "text/plain": [
|
425 |
| - "div((div((span(('New message arrived.',),{}),),{'class': 'alert alert-info', 'role': 'alert'}),),{'class': 'toast '})" |
| 428 | + "div((div((span(('New message arrived.',),{}),),{'class': 'alert alert-info', 'role': 'alert'}), script(('(()=>setTimeout(()=>document.querySelector(\\'[data-mui=\"_HJB8HS8NTsOSXq5TJbCaWA\"]\\').remove(),5000.0))()',),{})),{'data-mui': '_HJB8HS8NTsOSXq5TJbCaWA', 'class': 'toast '})" |
426 | 429 | ]
|
427 | 430 | },
|
428 | 431 | "execution_count": null,
|
|
434 | 437 | "Toast(\"New message arrived.\", alert_cls=AlertT.info)"
|
435 | 438 | ]
|
436 | 439 | },
|
| 440 | + { |
| 441 | + "cell_type": "markdown", |
| 442 | + "id": "b380807d", |
| 443 | + "metadata": {}, |
| 444 | + "source": [ |
| 445 | + "Set the Toast duration to 10 seconds." |
| 446 | + ] |
| 447 | + }, |
| 448 | + { |
| 449 | + "cell_type": "code", |
| 450 | + "execution_count": null, |
| 451 | + "id": "180451d1", |
| 452 | + "metadata": {}, |
| 453 | + "outputs": [ |
| 454 | + { |
| 455 | + "data": { |
| 456 | + "text/markdown": [ |
| 457 | + "```html\n", |
| 458 | + "<div data-mui=\"_Wjau44fWRlSG_WP73WgL6w\" class=\"toast \">\n", |
| 459 | + " <div class=\"alert alert-info\" role=\"alert\">\n", |
| 460 | + "<span>New message arrived.</span> </div>\n", |
| 461 | + "<script>(()=>setTimeout(()=>document.querySelector('[data-mui="_Wjau44fWRlSG_WP73WgL6w"]').remove(),10000.0))()</script></div>\n", |
| 462 | + "\n", |
| 463 | + "```" |
| 464 | + ], |
| 465 | + "text/plain": [ |
| 466 | + "div((div((span(('New message arrived.',),{}),),{'class': 'alert alert-info', 'role': 'alert'}), script(('(()=>setTimeout(()=>document.querySelector(\\'[data-mui=\"_Wjau44fWRlSG_WP73WgL6w\"]\\').remove(),10000.0))()',),{})),{'data-mui': '_Wjau44fWRlSG_WP73WgL6w', 'class': 'toast '})" |
| 467 | + ] |
| 468 | + }, |
| 469 | + "execution_count": null, |
| 470 | + "metadata": {}, |
| 471 | + "output_type": "execute_result" |
| 472 | + } |
| 473 | + ], |
| 474 | + "source": [ |
| 475 | + "Toast(\"New message arrived.\", alert_cls=AlertT.info, dur=10.0)" |
| 476 | + ] |
| 477 | + }, |
437 | 478 | {
|
438 | 479 | "cell_type": "code",
|
439 | 480 | "execution_count": null,
|
|
456 | 497 | ],
|
457 | 498 | "metadata": {
|
458 | 499 | "kernelspec": {
|
459 |
| - "display_name": "python3", |
| 500 | + "display_name": "python", |
460 | 501 | "language": "python",
|
461 |
| - "name": "python3" |
| 502 | + "name": "python" |
462 | 503 | }
|
463 | 504 | },
|
464 | 505 | "nbformat": 4,
|
|
0 commit comments