-
-
Notifications
You must be signed in to change notification settings - Fork 667
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6b0dc56
commit 5458b84
Showing
7 changed files
with
136 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,27 @@ | ||
from nicegui import ui | ||
|
||
from ..tools import text_demo | ||
from ..model import ElementDocumentation | ||
|
||
|
||
def main_demo() -> None: | ||
ui.label('some label') | ||
class LabelDocumentation(ElementDocumentation, element=ui.label): | ||
|
||
def main_demo(self) -> None: | ||
ui.label('some label') | ||
|
||
def more() -> None: | ||
@text_demo('Change Appearance Depending on the Content', ''' | ||
You can overwrite the `_handle_text_change` method to update other attributes of a label depending on its content. | ||
This technique also works for bindings as shown in the example below. | ||
''') | ||
def status(): | ||
class status_label(ui.label): | ||
def _handle_text_change(self, text: str) -> None: | ||
super()._handle_text_change(text) | ||
if text == 'ok': | ||
self.classes(replace='text-positive') | ||
else: | ||
self.classes(replace='text-negative') | ||
def more_demos(self) -> None: | ||
@self.add_markdown_demo('Change Appearance Depending on the Content', ''' | ||
You can overwrite the `_handle_text_change` method to update other attributes of a label depending on its content. | ||
This technique also works for bindings as shown in the example below. | ||
''') | ||
def status(): | ||
class status_label(ui.label): | ||
def _handle_text_change(self, text: str) -> None: | ||
super()._handle_text_change(text) | ||
if text == 'ok': | ||
self.classes(replace='text-positive') | ||
else: | ||
self.classes(replace='text-negative') | ||
|
||
model = {'status': 'error'} | ||
status_label().bind_text_from(model, 'status') | ||
ui.switch(on_change=lambda e: model.update(status='ok' if e.value else 'error')) | ||
model = {'status': 'error'} | ||
status_label().bind_text_from(model, 'status') | ||
ui.switch(on_change=lambda e: model.update(status='ok' if e.value else 'error')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters