Browse Source

#878 add upload demo for displaying markdown files

Falko Schindler 2 năm trước cách đây
mục cha
commit
1635b3cce6
1 tập tin đã thay đổi với 17 bổ sung0 xóa
  1. 17 0
      website/more_documentation/upload_documentation.py

+ 17 - 0
website/more_documentation/upload_documentation.py

@@ -16,3 +16,20 @@ def more() -> None:
         ui.upload(on_upload=lambda e: ui.notify(f'Uploaded {e.name}'),
                   on_rejected=lambda: ui.notify('Rejected!'),
                   max_file_size=1_000_000).classes('max-w-full')
+
+    @text_demo('Show file content', '''
+        In this demo, the uploaded markdown file is shown in a dialog.
+    ''')
+    def show_file_content() -> None:
+        from nicegui import events
+
+        with ui.dialog().props('full-width') as dialog:
+            with ui.card():
+                content = ui.markdown()
+
+        def handle_upload(e: events.UploadEventArguments):
+            text = e.content.read().decode('utf-8')
+            content.set_content(text)
+            dialog.open()
+
+        ui.upload(on_upload=handle_upload).props('accept=.md').classes('max-w-full')