TexteaInc / funix

Building web apps without manually creating widgets
http://funix.io
MIT License
90 stars 10 forks source link

widget type in decorator #7

Open forrestbao opened 2 years ago

forrestbao commented 2 years ago

Can we allow users to specify the widget type in the decorator?

TURX commented 2 years ago

What do you mean by "widget type"? Is it the choice of some styles to display on frontend?

forrestbao commented 2 years ago

No. A slider is a widget. A radio button is a widget. Widget is a concept in GUI. See examples here. https://ipywidgets.readthedocs.io/en/latest/examples/Widget%20List.html

Yazawazi commented 1 year ago

We currently support the widget type.

For example:

@textea_export(
    a={
        "treat_as": "config",
        "widget": ["switch"]
    }
    ...
)

This will render a as a switch, and you can change widget to ["checkbox"], it will render a as a checkbox.

The widget syntax is: [top level, second level, ...] (Or string like switch, just for elements like the config)

For example: ["simple", "slider[0, 100, 5]"]

It means that the top-level widget is simple, and all elements in simple will be rendered as slider.

And you can customize the widget style corresponding to the basic type by setting the theme, for example:

types:
  float, str: input
  int: slider
  bool: switch

It means float and str will be rendered as input, int will be rendered as slider, and bool will be rendered as switch.