-
Notifications
You must be signed in to change notification settings - Fork 8
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
Showing
36 changed files
with
832 additions
and
10 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
132 changes: 132 additions & 0 deletions
132
backend/modelscope_studio/components/antd/modal/static/__init__.py
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 |
---|---|---|
@@ -0,0 +1,132 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Any, Literal | ||
|
||
from gradio.events import EventListener | ||
|
||
from .....utils.dev import ModelScopeLayoutComponent, resolve_frontend_dir | ||
|
||
|
||
class AntdModalStatic(ModelScopeLayoutComponent): | ||
""" | ||
Ant Design: https://ant.design/components/modal | ||
""" | ||
EVENTS = [ | ||
EventListener( | ||
"ok", | ||
callback=lambda block: block._internal.update(bind_ok_event=True)), | ||
EventListener("cancel", | ||
callback=lambda block: block._internal.update( | ||
bind_cancel_event=True)) | ||
] | ||
|
||
# supported slots | ||
SLOTS = [ | ||
'closeIcon', 'cancelButtonProps.icon', 'cancelText', | ||
'closable.closeIcon', 'closeIcon', 'footer', 'title', 'content', | ||
'okButtonProps.icon', 'okText', 'modalRender' | ||
] | ||
|
||
def __init__( | ||
self, | ||
props: dict | None = None, | ||
*, | ||
after_close: str | None = None, | ||
auto_focus_button: Literal['ok', 'cancel'] | None = 'ok', | ||
type: Literal['info', 'success', 'error', 'warning', 'confirm'] | ||
| None = None, | ||
class_names: dict | None = None, | ||
styles: dict | None = None, | ||
cancel_button_props: dict | None = None, | ||
cancel_text: str | None = None, | ||
centered: bool | None = None, | ||
closable: bool | dict | None = None, | ||
close_icon: str | None = None, | ||
confirm_loading: bool | None = None, | ||
destroy_on_close: bool | None = None, | ||
focus_trigger_after_close: bool | None = None, | ||
content: str | None = None, | ||
footer: str | None = None, | ||
force_render: bool | None = None, | ||
get_container: str | None = None, | ||
keyboard: bool | None = None, | ||
mask: bool | None = None, | ||
mask_closable: bool | None = None, | ||
modal_render: str | None = None, | ||
ok_text: str | None = None, | ||
ok_type: str | None = None, | ||
ok_button_props: dict | None = None, | ||
loading: bool | None = None, | ||
title: str | None = None, | ||
width: int | float | str | None = None, | ||
wrap_class_name: str | None = None, | ||
z_index: int | None = None, | ||
after_open_change: str | None = None, | ||
root_class_name: str | None = None, | ||
as_item: str | None = None, | ||
_internal: None = None, | ||
# gradio properties | ||
visible: bool = True, | ||
elem_id: str | None = None, | ||
elem_classes: list[str] | str | None = None, | ||
elem_style: dict | None = None, | ||
render: bool = True, | ||
**kwargs): | ||
super().__init__(visible=visible, | ||
elem_id=elem_id, | ||
elem_classes=elem_classes, | ||
render=render, | ||
as_item=as_item, | ||
elem_style=elem_style, | ||
**kwargs) | ||
self.props = props | ||
self.after_close = after_close | ||
self.auto_focus_button = auto_focus_button | ||
self.class_names = class_names | ||
self.styles = styles | ||
self.type = type | ||
self.cancel_button_props = cancel_button_props | ||
self.cancel_text = cancel_text | ||
self.centered = centered | ||
self.closable = closable | ||
self.close_icon = close_icon | ||
self.confirm_loading = confirm_loading | ||
self.destroy_on_close = destroy_on_close | ||
self.focus_trigger_after_close = focus_trigger_after_close | ||
self.content = content | ||
self.footer = footer | ||
self.force_render = force_render | ||
self.get_container = get_container | ||
self.keyboard = keyboard | ||
self.mask = mask | ||
self.mask_closable = mask_closable | ||
self.modal_render = modal_render | ||
self.ok_text = ok_text | ||
self.ok_type = ok_type | ||
self.ok_button_props = ok_button_props | ||
self.loading = loading | ||
self.title = title | ||
self.width = width | ||
self.wrap_class_name = wrap_class_name | ||
self.z_index = z_index | ||
self.after_open_change = after_open_change | ||
self.root_class_name = root_class_name | ||
|
||
FRONTEND_DIR = resolve_frontend_dir("modal", "static") | ||
|
||
@property | ||
def skip_api(self): | ||
return True | ||
|
||
def preprocess(self, payload: None) -> None: | ||
return payload | ||
|
||
def postprocess(self, value: None) -> None: | ||
|
||
return value | ||
|
||
def example_payload(self) -> Any: | ||
return None | ||
|
||
def example_value(self) -> Any: | ||
return None |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Drawer | ||
|
||
A panel that slides out from the edge of the screen. See [Ant Design](https://ant.design/components/drawer/) for more information. | ||
|
||
## Examples | ||
|
||
<demo name="basic"></demo> | ||
<demo name="extra_actions" title="Extra Actions"></demo> |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Drawer | ||
|
||
A panel that slides out from the edge of the screen. See [Ant Design](https://ant.design/components/drawer/) for more information. | ||
|
||
## Examples | ||
|
||
<demo name="basic"></demo> | ||
<demo name="extra_actions" title="Extra Actions"></demo> |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from helper.Docs import Docs | ||
|
||
docs = Docs(__file__) | ||
|
||
if __name__ == "__main__": | ||
docs.render().queue().launch() |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import gradio as gr | ||
|
||
import modelscope_studio.components.antd as antd | ||
import modelscope_studio.components.base as ms | ||
|
||
with gr.Blocks() as demo: | ||
with ms.Application(): | ||
with antd.ConfigProvider(): | ||
btn = antd.Button("Open Drawer", type="primary") | ||
with antd.Drawer(open=False, title="Basic Drawer") as drawer: | ||
antd.Typography.Paragraph("Some contents...") | ||
antd.Typography.Paragraph("Some contents...") | ||
antd.Typography.Paragraph("Some contents...") | ||
btn.click(fn=lambda: gr.update(open=True), outputs=[drawer]) | ||
|
||
drawer.close(fn=lambda: gr.update(open=False), outputs=[drawer]) | ||
|
||
if __name__ == "__main__": | ||
demo.queue().launch() |
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import gradio as gr | ||
|
||
import modelscope_studio.components.antd as antd | ||
import modelscope_studio.components.base as ms | ||
|
||
default_placement = 'right' | ||
|
||
with gr.Blocks() as demo: | ||
with ms.Application(): | ||
with antd.ConfigProvider(): | ||
with antd.Space(): | ||
placement = antd.RadioGroup( | ||
options=["top", "bottom", "left", "right"], | ||
value=default_placement) | ||
btn = antd.Button("Open Drawer", type="primary") | ||
with antd.Drawer(open=False, | ||
title="Drawer with extra actions", | ||
width=500) as drawer: | ||
with ms.Slot("extra"): | ||
with antd.Space(): | ||
cancel_btn = antd.Button("Cancel") | ||
ok_btn = antd.Button("OK", type="primary") | ||
antd.Typography.Paragraph("Some contents...") | ||
antd.Typography.Paragraph("Some contents...") | ||
antd.Typography.Paragraph("Some contents...") | ||
placement.change(fn=lambda p: gr.update(placement=p), | ||
inputs=[placement], | ||
outputs=[drawer]) | ||
btn.click(fn=lambda: gr.update(open=True), outputs=[drawer]) | ||
|
||
gr.on([drawer.close, ok_btn.click, cancel_btn.click], | ||
fn=lambda: gr.update(open=False), | ||
outputs=[drawer]) | ||
|
||
if __name__ == "__main__": | ||
demo.queue().launch() |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Message | ||
|
||
Display global messages as feedback in response to user operations. See [Ant Design](https://ant.design/components/message/) for more information. | ||
|
||
## Examples | ||
|
||
<demo name="basic"></demo> |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Message | ||
|
||
Display global messages as feedback in response to user operations. See [Ant Design](https://ant.design/components/message/) for more information. | ||
|
||
## Examples | ||
|
||
<demo name="basic"></demo> |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from helper.Docs import Docs | ||
|
||
docs = Docs(__file__) | ||
|
||
if __name__ == "__main__": | ||
docs.render().queue().launch() |
Oops, something went wrong.