瀏覽代碼

log component layout and styling

Falko Schindler 3 年之前
父節點
當前提交
d141dfefdc
共有 3 個文件被更改,包括 9 次插入6 次删除
  1. 3 0
      nicegui/elements/custom_view.py
  2. 4 6
      nicegui/elements/log.js
  3. 2 0
      nicegui/elements/log.py

+ 3 - 0
nicegui/elements/custom_view.py

@@ -15,6 +15,7 @@ class CustomView(jp.JustpyBaseComponent):
 
         self.pages = {}
         self.classes = ''
+        self.style = ''
         self.options = jp.Dict(**options)
 
         super().__init__(temp=False)
@@ -50,5 +51,7 @@ class CustomView(jp.JustpyBaseComponent):
             'vue_type': self.vue_type,
             'id': self.id,
             'show': True,
+            'classes': self.classes,
+            'style': self.style,
             'options': self.options,
         }

+ 4 - 6
nicegui/elements/log.js

@@ -1,17 +1,15 @@
-var lines = [];
-
 Vue.component("log", {
-  template: `<div v-bind:id="jp_props.id">Hello!</div>`,
+  template: `<textarea v-bind:id="jp_props.id" :class="jp_props.classes" :style="jp_props.style"></textarea>`,
   mounted() {
     comp_dict[this.$props.jp_props.id] = this;
   },
   methods: {
     push(line) {
-      lines.push(line);
-      document.getElementById(this.$props.jp_props.id).innerText = lines;
+      const textarea = document.getElementById(this.$props.jp_props.id);
+      textarea.innerHTML += (textarea.innerHTML ? "\n" : "") + line;
+      textarea.scrollTop = textarea.scrollHeight;
     },
   },
-  updated() {},
   props: {
     jp_props: Object,
   },

+ 2 - 0
nicegui/elements/log.py

@@ -15,6 +15,8 @@ class Log(Element):
 
         super().__init__(LogView())
 
+        self.classes('border whitespace-pre font-mono')
+
     async def push(self, line: str):
 
         await asyncio.gather(*[