Pārlūkot izejas kodu

update ui.html (not working yet)

Falko Schindler 2 gadi atpakaļ
vecāks
revīzija
e455f4b3c6
4 mainītis faili ar 27 papildinājumiem un 32 dzēšanām
  1. 1 1
      nicegui/elements/colors.py
  2. 25 0
      nicegui/elements/html.py
  3. 0 31
      nicegui/elements/old/html.py
  4. 1 0
      nicegui/ui.py

+ 1 - 1
nicegui/elements/colors.py

@@ -13,7 +13,7 @@ class Colors(Element):
                  positive='#21ba45',
                  positive='#21ba45',
                  negative='#c10015',
                  negative='#c10015',
                  info='#31ccec',
                  info='#31ccec',
-                 warning='#f2c037'):
+                 warning='#f2c037') -> None:
         """Color Theming
         """Color Theming
 
 
         Sets the main colors (primary, secondary, accent, ...) used by `Quasar <https://quasar.dev/>`_.
         Sets the main colors (primary, secondary, accent, ...) used by `Quasar <https://quasar.dev/>`_.

+ 25 - 0
nicegui/elements/html.py

@@ -0,0 +1,25 @@
+from ..element import Element
+from .binding_mixins import BindContentMixin
+
+
+class Html(Element, BindContentMixin):
+
+    def __init__(self, content: str = '') -> None:
+        """HTML Element
+
+        Renders arbitrary HTML onto the page.
+        `Tailwind <https://tailwindcss.com/>`_ can be used for styling.
+        You can also use `ui.add_head_html` to add html code into the head of the document and `ui.add_body_html`
+        to add it into the body.
+
+        :param content: the HTML code to be displayed
+        """
+        super().__init__('div')
+        self.content = content
+        self.on_content_change(content)
+
+    def on_content_change(self, content: str) -> None:
+        if '</script>' in content:
+            raise ValueError('HTML elements must not contain <script> tags. Use ui.add_body_html() instead.')
+        self._text = content
+        self.update()

+ 0 - 31
nicegui/elements/old/html.py

@@ -1,31 +0,0 @@
-from typing import Any
-
-import justpy as jp
-
-from ..binding import BindableProperty, BindContentMixin
-from .element import Element
-
-
-class Html(Element, BindContentMixin):
-    content = BindableProperty()
-
-    def __init__(self, content: str = ''):
-        """HTML Element
-
-        Renders arbitrary HTML onto the page. `Tailwind <https://tailwindcss.com/>`_ can be used for styling.
-        You can also use `ui.add_head_html` to add html code into the head of the document and `ui.add_body_html`
-        to add it into the body.
-
-        :param content: the HTML code to be displayed
-        """
-        view = jp.QDiv(temp=False)
-        super().__init__(view)
-
-        self.content = content
-        self.bind_content_to(self.view, 'inner_html')
-
-    def set_content(self, content: str) -> None:
-        if '</script>' in content:
-            # TODO: should also be checked if content is set directly
-            raise ValueError('HTML elements must not contain <script> tags. Use ui.add_body_html() instead.')
-        self.content = content

+ 1 - 0
nicegui/ui.py

@@ -6,6 +6,7 @@ from .elements.card import CardSection as card_section
 from .elements.checkbox import Checkbox as checkbox
 from .elements.checkbox import Checkbox as checkbox
 from .elements.colors import Colors as colors
 from .elements.colors import Colors as colors
 from .elements.column import Column as column
 from .elements.column import Column as column
+from .elements.html import Html as html
 from .elements.icon import Icon as icon
 from .elements.icon import Icon as icon
 from .elements.image import Image as image
 from .elements.image import Image as image
 from .elements.label import Label as label
 from .elements.label import Label as label