Skip to content

Commit

Permalink
style: re-format with larger line length
Browse files Browse the repository at this point in the history
  • Loading branch information
maartenbreddels committed Mar 21, 2024
1 parent bf661ec commit 68ea96f
Show file tree
Hide file tree
Showing 11 changed files with 437 additions and 957 deletions.
3 changes: 3 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"printWidth": 140
}
139 changes: 137 additions & 2 deletions examples/demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,145 @@
"metadata": {},
"outputs": [],
"source": [
"# import ipyantd.components as antd\n",
"import ipyantd.components as antd\n",
"# # import solara\n",
"# import reacton\n",
"# import ipyreact"
"import ipyreact"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e5f19e9b",
"metadata": {},
"outputs": [],
"source": [
"import ipywidgets\n",
"from IPython.display import clear_output\n",
"\n",
"options = [\n",
" dict(label=\"Apple\", value=\"apple\"),\n",
" dict(label=\"Pear\", value=\"pear\"),\n",
" dict(label=\"Cherry\", value=\"cherry\"),\n",
"]\n",
"\n",
"menu_items = [\n",
" dict(key=\"1\", label=ipyreact.Widget(_type=\"div\", children=[\"Click me 1\"], events={\"onClick\": print})),\n",
" dict(key=\"2\", label=ipyreact.Widget(_type=\"div\", children=[\"Click me 2\"], events={\"onClick\": print})),\n",
"]\n",
"text = \"\"\"Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n",
"Sed non risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed, dolor. \n",
"Cras elementum ultrices diam. Maecenas ligula massa, varius a, semper congue, euismod non, mi. \n",
"Proin porttitor, orci nec nonummy molestie, enim est eleifend mi, non fermentum diam nisl sit amet erat. \n",
"Duis semper.\n",
"Duis arcu massa, scelerisque vitae, consequat in, pretium a, enim. Pellentesque congue.\n",
"\"\"\"\n",
"\n",
"\n",
"def dialog_open(event_data):\n",
" with output:\n",
" clear_output(wait=True)\n",
" print(\"Modal opened\")\n",
" dialog.value = True\n",
"\n",
"\n",
"def dialog_close(event_data):\n",
" with output:\n",
" clear_output(wait=True)\n",
" print(\"Modal closed\")\n",
" dialog.value = False\n",
" \n",
"def show_value(change):\n",
" new = change[\"new\"]\n",
" with output:\n",
" clear_output(wait=True)\n",
" print(\"value = \", new)\n",
"\n",
"def report_click(event_data=None):\n",
" with output:\n",
" clear_output(wait=True)\n",
" print(\"Clicked\")\n",
"\n",
"demo = ipyreact.Widget.element(_type=\"div\", children=[\n",
" antd.Row(props=dict(gutter=[48,48], style={\"padding\": \"100px\"}), children=[\n",
" antd.Col(props=dict(span=8, style={\"boxSizing\": \"border-box\"}), children=[\n",
" ipyreact.Widget.element(_type=\"div\", children=[\n",
" antd.Button(children=[\"Button\"], props=dict(type=\"primary\"), events={\"onClick\": report_click}),\n",
" antd.Button(children=[\"Button\"]),\n",
" ]),\n",
" ]),\n",
" antd.Col(props=dict(span=8), children=[\n",
" antd.Button(children=[\"Button\"], props=dict(type=\"primary\", shape=\"round\")),\n",
" antd.Button(props=dict(type=\"primary\", shape=\"circle\", icon=icons.Icon(\"SearchOutlined\"))),\n",
" antd.Button(props=dict(shape=\"circle\", icon=icons.Icon(\"SearchOutlined\"))),\n",
" ]),\n",
" antd.Col(props=dict(span=8), children=[\n",
" antd.Button(children=[\"Button\"], props=dict(type=\"text\")),\n",
" ]),\n",
" antd.Col(props=dict(span=8), children=[\n",
" antd.Button(children=[\"Button\"], props=dict(type=\"primary\", size=\"small\")),\n",
" antd.Button(children=[\"Button\"], props=dict(size=\"small\")),\n",
" ]),\n",
" antd.Col(props=dict(span=8), children=[\n",
" antd.Button(children=[\"Button\"], props=dict(type=\"primary\", shape=\"round\", size=\"small\")),\n",
" antd.Button(props=dict(type=\"primary\", shape=\"circle\", icon=icons.Icon(\"SearchOutlined\"), size=\"small\")),\n",
" antd.Button(props=dict(shape=\"circle\", icon=icons.Icon(\"SearchOutlined\"), size=\"small\")),\n",
" ]),\n",
" antd.Col(props=dict(span=8), children=[\n",
" antd.Button(children=[\"Button\"], props=dict(type=\"text\", size=\"small\")),\n",
" ]),\n",
" \n",
" # sliders\n",
" antd.Col(props=dict(span=8), children=[\n",
" antd.Slider(value=0, props=dict(min=0, max=100)),\n",
" ]),\n",
" antd.Col(props=dict(span=8), children=[\n",
" slider_range := antd.Slider(value=[20, 70], props=dict(min=0, max=100, range=True)),\n",
" ]),\n",
" antd.Col(props=dict(span=8), children=[\n",
" slider := antd.Slider(value=30, props=dict(min=0, max=100, tooltip=dict(open=True))),\n",
" ]),\n",
"\n",
" # select\n",
" antd.Col(props=dict(span=8), children=[\n",
" select := antd.Select(value=\"pear\", props=dict(options=options, style=dict(width=\"120px\"))),\n",
" ]),\n",
" antd.Col(props=dict(span=8), children=[\n",
" multi_select := antd.Select(value=[\"cherry\"], props=dict(options=options, style=dict(width=\"220px\"), mode=\"multiple\"))\n",
" ]),\n",
" antd.Col(props=dict(span=8), children=[\n",
" # only supported in 5.31+\n",
" # antd.Select(value=\"pear\", props=dict(options=options, variant=\"filled\", style=dict(width=\"120px\"))),\n",
" ]),\n",
" \n",
" # misc\n",
" antd.Col(props=dict(span=8), children=[\n",
" switch := antd.Switch(value=True),\n",
" ]),\n",
" antd.Col(props=dict(span=8), children=[\n",
" dropdown := antd.Dropdown(props=dict(menu=dict(items=menu_items), trigger=[\"click\"]), children=\n",
" [ipyreact.Widget.element(_type=\"span\", children=[\"Menu\"])]\n",
" ),\n",
" ]),\n",
" antd.Col(props=dict(span=8), children=[\n",
" dialog := antd.Modal(events={\"onOk\": dialog_close, \"onCancel\": dialog_close}, children=[\n",
" ipyreact.Widget.element(_type=\"div\", children=[text])\n",
" ]),\n",
" antd.Button(children=[\"Dialog\"], props=dict(type=\"primary\"), events={\"onClick\": dialog_open}),\n",
" ]),\n",
"\n",
" \n",
" ]),\n",
" output := ipywidgets.Output()\n",
"])\n",
"select.observe(show_value, \"value\")\n",
"multi_select.observe(show_value, \"value\")\n",
"slider.observe(show_value, \"value\")\n",
"slider_range.observe(show_value, \"value\")\n",
"switch.observe(show_value, \"value\")\n",
"with output:\n",
" print(\" \")\n",
"demo"
]
},
{
Expand Down
99 changes: 18 additions & 81 deletions examples/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,11 @@ def report_click(event_data=None):
menu_items = [
dict(
key="1",
label=ipyreact.Widget.element(
_type="div", children=["Click me 1"], events={"onClick": report_click}
),
label=ipyreact.Widget.element(_type="div", children=["Click me 1"], events={"onClick": report_click}),
),
dict(
key="2",
label=ipyreact.Widget.element(
_type="div", children=["Click me 2"], events={"onClick": report_click}
),
label=ipyreact.Widget.element(_type="div", children=["Click me 2"], events={"onClick": report_click}),
),
]
text = """Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Expand All @@ -64,87 +60,37 @@ def Page():
# buttons
with antd.Col(props=dict(span=8, style={"boxSizing": "border-box"})):
with ipyreact.Widget.element(_type="div"):
antd.Button(
children=["Button"],
props=dict(type="primary"),
events={"onClick": report_click},
)
antd.Button(children=["Button"], props=dict(type="primary"), events={"onClick": report_click})
antd.Button(children=["Button"])
with antd.Col(props=dict(span=8)):
antd.Button(
children=["Button"], props=dict(type="primary", shape="round")
)
antd.Button(
props=dict(
type="primary",
shape="circle",
icon=icons.Icon("SearchOutlined"),
)
)
antd.Button(
props=dict(shape="circle", icon=icons.Icon("SearchOutlined"))
)
antd.Button(children=["Button"], props=dict(type="primary", shape="round"))
antd.Button(props=dict(type="primary", shape="circle", icon=icons.Icon("SearchOutlined")))
antd.Button(props=dict(shape="circle", icon=icons.Icon("SearchOutlined")))
with antd.Col(props=dict(span=8)):
antd.Button(children=["Button"], props=dict(type="text"))
with antd.Col(props=dict(span=8)):
antd.Button(
children=["Button"], props=dict(type="primary", size="small")
)
antd.Button(children=["Button"], props=dict(type="primary", size="small"))
antd.Button(children=["Button"], props=dict(size="small"))
with antd.Col(props=dict(span=8)):
antd.Button(
children=["Button"],
props=dict(type="primary", shape="round", size="small"),
)
antd.Button(
props=dict(
type="primary",
shape="circle",
icon=icons.Icon("SearchOutlined"),
size="small",
)
)
antd.Button(
props=dict(
shape="circle", icon=icons.Icon("SearchOutlined"), size="small"
)
)
antd.Button(children=["Button"], props=dict(type="primary", shape="round", size="small"))
antd.Button(props=dict(type="primary", shape="circle", icon=icons.Icon("SearchOutlined"), size="small"))
antd.Button(props=dict(shape="circle", icon=icons.Icon("SearchOutlined"), size="small"))
with antd.Col(props=dict(span=8)):
antd.Button(children=["Button"], props=dict(type="text", size="small"))

# sliders
with antd.Col(props=dict(span=8)):
antd.Slider(
value=slider.value, on_value=slider.set, props=dict(min=0, max=100)
)
antd.Slider(value=slider.value, on_value=slider.set, props=dict(min=0, max=100))
with antd.Col(props=dict(span=8)):
antd.Slider(
value=slider_range.value,
on_value=slider_range.set,
props=dict(min=0, max=100, range=True),
)
antd.Slider(value=slider_range.value, on_value=slider_range.set, props=dict(min=0, max=100, range=True))
with antd.Col(props=dict(span=8)):
antd.Slider(
value=slider.value,
on_value=slider.set,
props=dict(min=0, max=100, tooltip=dict(open=True)),
)
antd.Slider(value=slider.value, on_value=slider.set, props=dict(min=0, max=100, tooltip=dict(open=True)))

# select
with antd.Col(props=dict(span=8)):
antd.Select(
value=select.value,
on_value=select.set,
props=dict(options=options, style=dict(width="120px")),
)
antd.Select(value=select.value, on_value=select.set, props=dict(options=options, style=dict(width="120px")))
with antd.Col(props=dict(span=8)):
antd.Select(
value=multi_select.value,
on_value=multi_select.set,
props=dict(
options=options, style=dict(width="220px"), mode="multiple"
),
)
antd.Select(value=multi_select.value, on_value=multi_select.set, props=dict(options=options, style=dict(width="220px"), mode="multiple"))
with antd.Col(props=dict(span=8)):
pass
# only supported in 5.31+
Expand All @@ -154,21 +100,12 @@ def Page():
with antd.Col(props=dict(span=8)):
antd.Switch(value=switch.value, on_value=switch.set)
with antd.Col(props=dict(span=8)):
with antd.Dropdown(
props=dict(menu=dict(items=menu_items), trigger=["click"])
):
with antd.Dropdown(props=dict(menu=dict(items=menu_items), trigger=["click"])):
ipyreact.Widget.element(_type="span", children=["Menu"])
with antd.Col(props=dict(span=8)):
with antd.Modal(
value=dialog.value,
events={"onOk": dialog_close, "onCancel": dialog_close},
):
with antd.Modal(value=dialog.value, events={"onOk": dialog_close, "onCancel": dialog_close}):
ipyreact.Widget.element(_type="div", children=[text])
antd.Button(
children=["Dialog"],
props=dict(type="primary"),
events={"onClick": dialog_open},
)
antd.Button(children=["Dialog"], props=dict(type="primary"), events={"onClick": dialog_open})

solara.Preformatted(f"message: {message.value or ''}")
solara.Preformatted(f"slider: {slider.value}")
Expand Down
21 changes: 7 additions & 14 deletions generate/generate-schema.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ async function extractPropsAndSaveToFile(inputFilePath, outputFilePath) {
}
const outputFilePath = "./generate/propslist.json"; // Replace with your desired output file path

const propsList = await extractPropsAndSaveToFile(
inputFilePath,
outputFilePath,
);
const propsList = await extractPropsAndSaveToFile(inputFilePath, outputFilePath);

// We can either get the schema for one file and one type...
// const schema = TJS.generateSchema(program, propsList, settings);
Expand All @@ -72,16 +69,12 @@ propsList.forEach((props) => {
});
const schema = generator.getSchemaForSymbols(propsList);

await fs.writeFile(
"./generate/schema.json",
JSON.stringify(schema, undefined, 4),
function (err) {
if (err) {
return console.log(err);
}
console.log("The file was saved!");
},
);
await fs.writeFile("./generate/schema.json", JSON.stringify(schema, undefined, 4), function (err) {
if (err) {
return console.log(err);
}
console.log("The file was saved!");
});

// // ... or a generator that lets us incrementally get more schemas

Expand Down
4 changes: 1 addition & 3 deletions generate/polish-schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ def remove_unsupported(obj):
events[name].add(prop_name)
definition["properties"].pop(prop_name)
if events[name]:
definition["properties"]["events"] = {
"$ref": "#/definitions/" + name + "Events"
}
definition["properties"]["events"] = {"$ref": "#/definitions/" + name + "Events"}

all_events = set()
for name, event_set in events.items():
Expand Down
10 changes: 1 addition & 9 deletions ipyantd/assets/antd-jupyter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,5 @@ export function ModalStatefull({ value, setValue, ...rest }) {
rest.onCancel();
}
};
return (
<antd.Modal
open={value}
afterOpenChange={onOpenChange}
onOk={handleOk}
onCancel={handleCancel}
{...rest}
/>
);
return <antd.Modal open={value} afterOpenChange={onOpenChange} onOk={handleOk} onCancel={handleCancel} {...rest} />;
}
Loading

0 comments on commit 68ea96f

Please sign in to comment.