image_documentation.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. from nicegui import ui
  2. from ..documentation_tools import text_demo
  3. def main_demo() -> None:
  4. ui.image('https://picsum.photos/id/377/640/360')
  5. def more() -> None:
  6. ui.add_body_html('<script src="https://unpkg.com/@lottiefiles/lottie-player@latest/dist/lottie-player.js"></script>')
  7. @text_demo('Local files', '''
  8. You can use local images as well by passing a path to the image file.
  9. ''')
  10. def local():
  11. ui.image('website/static/logo.png').classes('w-16')
  12. @text_demo('Base64 string', '''
  13. You can also use a Base64 string as image source.
  14. ''')
  15. def base64():
  16. base64 = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='
  17. ui.image(base64).classes('w-2 h-2 m-auto')
  18. @text_demo('Lottie files', '''
  19. You can also use [Lottie files](https://lottiefiles.com/) with animations.
  20. ''')
  21. def lottie():
  22. # ui.add_body_html('<script src="https://unpkg.com/@lottiefiles/lottie-player@latest/dist/lottie-player.js"></script>')
  23. src = 'https://assets1.lottiefiles.com/datafiles/HN7OcWNnoqje6iXIiZdWzKxvLIbfeCGTmvXmEm1h/data.json'
  24. ui.html(f'<lottie-player src="{src}" loop autoplay />').classes('w-full')
  25. @text_demo('Image link', '''
  26. Images can link to another page by wrapping them in a [ui.link](https://nicegui.io/documentation/link).
  27. ''')
  28. def link():
  29. with ui.link(target='https://github.com/zauberzeug/nicegui'):
  30. ui.image('https://picsum.photos/id/41/640/360').classes('w-64')
  31. @text_demo('Force reload', '''
  32. You can force an image to reload by calling the `force_reload` method.
  33. It will append a timestamp to the image URL, which will make the browser reload the image.
  34. ''')
  35. def force_reload():
  36. img = ui.image('https://picsum.photos/640/360').classes('w-64')
  37. ui.button('Force reload', on_click=img.force_reload)