mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-20 10:47:35 -05:00
* add JSProperty to pydom so it can be used to create descriptors mapping to specific JS attributes * add pyweb.ui * fix pyweb imports * fix link and a elements and add a script element * fix imports and add initialization to load resources to shoelace module * new pyweb.ui test folder * remove comments * add Icon to shoelace components * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * use html property rather than accessing _js directly * add markdown suppport * move examples section out of stdlib pyweb to examples.py in the demo itself * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * simplify demo code * improve docstrings * precommit fixes * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * simplify code for main page * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * add load_resources to markdown * add showlace extra style dynamically * precommit * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * add gallery files * add global attributes and dynamic property assignment * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add shoelace radio component (#1961) * add shoelace radio component * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> * fix type that lead using the the JSDescriptor directly instead of the factory method * add missing marked dependency * refactor gallary to simplify codebase * precommig lint * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * add text attribute to pydom Elements * add global JS attributes to elements and improve demos * lint * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix image instantiation on card since the API has changed * add attributes to all classes in elements * lint * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * change example creation functions to take the label and the object directly * fix input name clashing with input keyword * refactor examples to better simplify and automate * fix div clashing names * fix demo left menu width * simplify base elements demo by moving all the examples to the examples module * rename Grid to grid to align to other elements * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * reorg classes order in elements.py and add missing elements to examples * fix issue related to now importing div from pyweb.ui * improve demo * link and fix spelling typo * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add a bunch more elements (#1966) * Add copy button * Add skeleton and spinner * Add Switch * Add text area * Add more elements * More styling to each component * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Fabio Pliger <fpliger@users.noreply.github.com> * Add radio group (#1963) * add radio group * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Fabio Pliger <fpliger@users.noreply.github.com> * Small tweaks to main demo page (#1962) * Small tweaks to main demo page * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Fabio Pliger <fpliger@users.noreply.github.com> * fix post merge issues * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fixed issues with renaming Grid to grid, after we merged * lint * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * add multple HTML elements in alphabetical order from abbr to em * fix attributes of some of the elements added in the previous commit and add embed * fix embed attributes and add fieldset * add figcation, figure and form. Also fix ordering of definitoin of img and input_ * add style and lint * wrap up adding all major html elements * fix test failing due to different error message from fake server compared to a real test server * change default docstring associated with all classes dynamically patched * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * lint * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * add pyweb tests * lint * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * add global attributes and change abbr test * fix abbr to inherit from TextElementBase * add address test and improve error messaging when ElementBase gets a bad input as style * change test helper function to be more flexible on attributes and manage content vs non content based elements. Also adds area tests * add test for more elements up to caption * fix canvas and caption as elements that have content and fix name typo on figcaption * fix another typo on figcaption * minor fixes and complete tests for all elements * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * adapt shoelace to latest upates in ui.elements * fix issue with example code not showing created button * move global attributes to base class * replace all the calls to _add_js_properties with defining attributes directly in the classes * finish moving all properties manually on each class * remove _add_js_properties * replace JSProperty with js_property * replace JSProperty with js_property * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fixed merge conflicts * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * remove js_property and just use JSProperty with name and allow_nones as arguments * fix bug around Element not being able to map global attributes in subclasses * remove js_property and fix references * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * precommit * precommit again * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * lint * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * enable pyweb on micropython * switch examples to micropython * fix pydom issue with micropython, created by the monkeypatch around JsProxy * print micropython version on micropython pydom example * lint and remove of textwrap in stdlib for micropython compatibility * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * added msising attributes on the option Element. Tests are all passing now * fix tests * lint * temp ugly fix for micropython, using the when decorator with a function without arguments * small fixes and improvements to examples * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix examples and broken link from the removal of markdown and shoelace from stdlib * lint * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * dynamically change the server address in tests * use the right element in test_a * lint * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * skipping test_audio in CI due to different behavior of fake_server vs a real server, that runs in local tests * add conditional expected_missing_file_errors property to manage different behaviour between local tests and CI (due to fake_server) * lint * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Askat <aaskat@users.noreply.github.com> Co-authored-by: Fábio Rosado <hello@fabiorosado.dev> Co-authored-by: Andrea Giammarchi <andrea.giammarchi@gmail.com>
301 lines
9.7 KiB
Python
301 lines
9.7 KiB
Python
from markdown import markdown
|
|
from pyscript import when, window
|
|
from pyweb import pydom
|
|
from pyweb.ui.elements import (
|
|
a,
|
|
br,
|
|
button,
|
|
code,
|
|
div,
|
|
grid,
|
|
h1,
|
|
h2,
|
|
h3,
|
|
h4,
|
|
h5,
|
|
h6,
|
|
img,
|
|
input_,
|
|
p,
|
|
small,
|
|
strong,
|
|
)
|
|
from shoelace import (
|
|
Alert,
|
|
Button,
|
|
Card,
|
|
CopyButton,
|
|
Details,
|
|
Dialog,
|
|
Divider,
|
|
Icon,
|
|
Radio,
|
|
RadioGroup,
|
|
Range,
|
|
Rating,
|
|
RelativeTime,
|
|
Skeleton,
|
|
Spinner,
|
|
Switch,
|
|
Tag,
|
|
Textarea,
|
|
)
|
|
|
|
LOREM_IPSUM = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
|
|
details_code = """
|
|
LOREM_IPSUM = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
|
|
Details(LOREM_IPSUM, summary="Try me")
|
|
"""
|
|
example_dialog_close_btn = Button("Close")
|
|
example_dialog = Dialog(div([p(LOREM_IPSUM), example_dialog_close_btn]), label="Try me")
|
|
example_dialog_btn = Button("Open Dialog")
|
|
|
|
|
|
def toggle_dialog():
|
|
example_dialog.open = not (example_dialog.open)
|
|
|
|
|
|
when("click", example_dialog_btn)(toggle_dialog)
|
|
when("click", example_dialog_close_btn)(toggle_dialog)
|
|
|
|
pydom.body.append(example_dialog)
|
|
|
|
|
|
# ELEMENTS
|
|
|
|
# Button
|
|
btn = button("Click me!")
|
|
when("click", btn)(lambda: window.alert("Clicked!"))
|
|
|
|
# Inputs
|
|
inputs_div = div()
|
|
inputs_code = []
|
|
for input_type in [
|
|
"text",
|
|
"password",
|
|
"email",
|
|
"number",
|
|
"date",
|
|
"time",
|
|
"color",
|
|
"range",
|
|
]:
|
|
inputs_div.append(input_(type=input_type, style={"display": "block"}))
|
|
inputs_code.append(f"input_(type='{input_type}')")
|
|
|
|
|
|
headers_div = div()
|
|
headers_code = []
|
|
for header in [h1, h2, h3, h4, h5, h6]:
|
|
headers_div.append(header(f"{header.tag.upper()} header"))
|
|
headers_code.append(f'{header.tag}("{header.tag.upper()} header")')
|
|
headers_code = "\n".join(headers_code)
|
|
|
|
rich_input = input_(
|
|
type="text",
|
|
name="some name",
|
|
autofocus=True,
|
|
pattern="\w{3,16}",
|
|
placeholder="add text with > 3 chars",
|
|
required=True,
|
|
size="20",
|
|
)
|
|
inputs_div.append(rich_input)
|
|
inputs_code.append("# You can create inputs with more options like")
|
|
inputs_code.append("# this by passing properties as kwargs")
|
|
inputs_code.append(
|
|
"input_(type='text', name='some name', autofocus=True, pattern='\\w{3,16}', placeholder='add text with > 3 chars', required=True, size='20')"
|
|
)
|
|
inputs_code = "\n".join(inputs_code)
|
|
|
|
MARKDOWN_EXAMPLE = """# This is a header
|
|
|
|
This is a ~~paragraph~~ text with **bold** and *italic* text in it!
|
|
"""
|
|
|
|
kits = {
|
|
"shoelace": {
|
|
"Alert": {
|
|
"instance": Alert(
|
|
"This is a standard alert. You can customize its content and even the icon."
|
|
),
|
|
"code": "Alert('This is a standard alert. You can customize its content and even the icon.'",
|
|
},
|
|
"Icon": {
|
|
"instance": Icon(name="heart"),
|
|
"code": 'Icon(name="heart")',
|
|
},
|
|
"Button": {
|
|
"instance": Button("Try me"),
|
|
"code": 'Button("Try me")',
|
|
},
|
|
"Card": {
|
|
"instance": Card(
|
|
p("This is a cool card!"),
|
|
image="https://pyscript.net/assets/images/pyscript-sticker-black.svg",
|
|
footer=div([Button("More Info"), Rating()]),
|
|
),
|
|
"code": """
|
|
Card(p("This is a cool card!"), image="https://pyscript.net/assets/images/pyscript-sticker-black.svg", footer=div([Button("More Info"), Rating()]))
|
|
""",
|
|
},
|
|
"Details": {
|
|
"instance": Details(LOREM_IPSUM, summary="Try me"),
|
|
"code": 'Details(LOREM_IPSUM, summary="Try me")',
|
|
},
|
|
"Dialog": {
|
|
"instance": example_dialog_btn,
|
|
"code": 'Dialog(div([p(LOREM_IPSUM), Button("Close")]), summary="Try me")',
|
|
},
|
|
"Divider": {
|
|
"instance": Divider(),
|
|
"code": "Divider()",
|
|
},
|
|
"Rating": {
|
|
"instance": Rating(),
|
|
"code": "Rating()",
|
|
},
|
|
"Radio": {
|
|
"instance": Radio("Option 42"),
|
|
"code": code('Radio("Option 42")'),
|
|
},
|
|
"Radio Group": {
|
|
"instance": RadioGroup(
|
|
[
|
|
Radio("radio 1", name="radio 1", value=1, style={"margin": "20px"}),
|
|
Radio("radio 2", name="radio 2", value=2, style={"margin": "20px"}),
|
|
Radio("radio 3", name="radio 3", value=3, style={"margin": "20px"}),
|
|
],
|
|
label="Select an option",
|
|
),
|
|
"code": code(
|
|
"""
|
|
RadioGroup([Radio("radio 1", name="radio 1", value=1, style={"margin": "20px"}),
|
|
Radio("radio 2", name="radio 2", value=2, style={"margin": "20px"}),
|
|
Radio("radio 3", name="radio 3", value=3, style={"margin": "20px"})],
|
|
label="Select an option"),"""
|
|
),
|
|
},
|
|
"CopyButton": {
|
|
"instance": CopyButton(
|
|
value="PyShoes!",
|
|
copy_label="Copy me!",
|
|
sucess_label="Copied, check your clipboard!",
|
|
error_label="Oops, something went wrong!",
|
|
feedback_timeout=2000,
|
|
tooltip_placement="top",
|
|
),
|
|
"code": 'CopyButton(value="PyShoes!", copy_label="Copy me!", sucess_label="Copied, check your clipboard!", error_label="Oops, something went wrong!", feedback_timeout=2000, tooltip_placement="top")',
|
|
},
|
|
"Skeleton": {
|
|
"instance": Skeleton(effect="pulse"),
|
|
"code": "Skeleton(effect='pulse')",
|
|
},
|
|
"Spinner": {
|
|
"instance": Spinner(),
|
|
"code": "Spinner()",
|
|
},
|
|
"Switch": {
|
|
"instance": Switch(name="switch", size="large"),
|
|
"code": 'Switch(name="switch", size="large")',
|
|
},
|
|
"Textarea": {
|
|
"instance": Textarea(
|
|
name="textarea",
|
|
label="Textarea",
|
|
size="medium",
|
|
help_text="This is a textarea",
|
|
resize="auto",
|
|
),
|
|
"code": 'Textarea(name="textarea", label="Textarea", size="medium", help_text="This is a textarea", resize="auto")',
|
|
},
|
|
"Tag": {
|
|
"instance": Tag("Tag", variant="primary", size="medium"),
|
|
"code": 'Tag("Tag", variant="primary", size="medium")',
|
|
},
|
|
"Range": {
|
|
"instance": Range(min=0, max=100, value=50),
|
|
"code": "Range(min=0, max=100, value=50)",
|
|
},
|
|
"RelativeTime": {
|
|
"instance": RelativeTime(date="2021-01-01T00:00:00Z"),
|
|
"code": 'RelativeTime(date="2021-01-01T00:00:00Z")',
|
|
},
|
|
# "SplitPanel": {
|
|
# "instance": SplitPanel(
|
|
# div("First panel"), div("Second panel"), orientation="vertical"
|
|
# ),
|
|
# "code": code(
|
|
# 'SplitPanel(div("First panel"), div("Second panel"), orientation="vertical")'
|
|
# ),
|
|
# },
|
|
},
|
|
"elements": {
|
|
"button": {
|
|
"instance": btn,
|
|
"code": """btn = button("Click me!")
|
|
when('click', btn)(lambda: window.alert("Clicked!"))
|
|
parentdiv.append(btn)
|
|
""",
|
|
},
|
|
"div": {
|
|
"instance": div(
|
|
"This is a div",
|
|
style={
|
|
"text-align": "center",
|
|
"margin": "0 auto",
|
|
"background-color": "cornsilk",
|
|
},
|
|
),
|
|
"code": 'div("This is a div", style={"text-align": "center", "margin": "0 auto", "background-color": "cornsilk"})',
|
|
},
|
|
"input": {"instance": inputs_div, "code": inputs_code},
|
|
"grid": {
|
|
"instance": grid(
|
|
"30% 70%",
|
|
[
|
|
div("This is a grid", style={"background-color": "lightblue"}),
|
|
p("with 2 elements", style={"background-color": "lightyellow"}),
|
|
],
|
|
),
|
|
"code": 'grid([div("This is a grid")])',
|
|
},
|
|
"headers": {"instance": headers_div, "code": headers_code},
|
|
"a": {
|
|
"instance": a(
|
|
"Click here for something awesome",
|
|
href="https://pyscript.net",
|
|
target="_blank",
|
|
),
|
|
"code": 'a("Click here for something awesome", href="https://pyscript.net", target="_blank")',
|
|
},
|
|
"br": {
|
|
"instance": div([p("This is a paragraph"), br(), p("with a line break")]),
|
|
"code": 'div([p("This is a paragraph"), br(), p("with a line break")])',
|
|
},
|
|
"img": {
|
|
"instance": img(src="./giphy_winner.gif", style={"max-width": "200px"}),
|
|
"code": 'img(src="./giphy_winner.gif", style={"max-width": "200px"})',
|
|
},
|
|
"code": {
|
|
"instance": code("print('Hello, World!')"),
|
|
"code": "code(\"print('Hello, World!')\")",
|
|
},
|
|
"p": {"instance": p("This is a paragraph"), "code": 'p("This is a paragraph")'},
|
|
"small": {
|
|
"instance": small("This is a small text"),
|
|
"code": 'small("This is a small text")',
|
|
},
|
|
"strong": {
|
|
"instance": strong("This is a strong text"),
|
|
"code": 'strong("This is a strong text")',
|
|
},
|
|
},
|
|
"markdown": {
|
|
"markdown": {
|
|
"instance": markdown(MARKDOWN_EXAMPLE),
|
|
"code": f'markdown("""{MARKDOWN_EXAMPLE}""")',
|
|
},
|
|
},
|
|
}
|