Skip to content

Commit 9e468e8

Browse files
committed
finish off creating interfaces main content
1 parent 06403ac commit 9e468e8

File tree

11 files changed

+409
-28
lines changed

11 files changed

+409
-28
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from idom import component, html, run
2+
3+
4+
@component
5+
def DataList(items, filter_by_priority=None, sort_by_priority=False):
6+
if filter_by_priority is not None:
7+
items = [i for i in items if i["priority"] <= filter_by_priority]
8+
if sort_by_priority:
9+
items = list(sorted(items, key=lambda i: i["priority"]))
10+
list_item_elements = [html.li(i["text"]) for i in items]
11+
return html.ul(list_item_elements)
12+
13+
14+
@component
15+
def TodoList():
16+
tasks = [
17+
{"text": "Make breakfast", "priority": 0},
18+
{"text": "Feed the dog", "priority": 0},
19+
{"text": "Do laundry", "priority": 2},
20+
{"text": "Go on a run", "priority": 1},
21+
{"text": "Clean the house", "priority": 2},
22+
{"text": "Go to the grocery store", "priority": 2},
23+
{"text": "Do some coding", "priority": 1},
24+
{"text": "Read a book", "priority": 1},
25+
]
26+
return html.section(
27+
html.h1("My Todo List"),
28+
DataList(tasks, filter_by_priority=1, sort_by_priority=True),
29+
)
30+
31+
32+
run(TodoList)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from idom import component, html, run
2+
3+
4+
@component
5+
def DataList(items):
6+
list_item_elements = [html.li(text) for text in items]
7+
return html.ul(list_item_elements)
8+
9+
10+
@component
11+
def TodoList():
12+
tasks = [
13+
"Make breakfast (important)",
14+
"Feed the dog (important)",
15+
"Do laundry",
16+
"Go on a run (important)",
17+
"Clean the house",
18+
"Go to the grocery store",
19+
"Do some coding",
20+
"Read a book (important)",
21+
]
22+
return html.section(
23+
html.h1("My Todo List"),
24+
DataList(tasks),
25+
)
26+
27+
28+
run(TodoList)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from idom import component, html, run
2+
3+
4+
@component
5+
def DataList(items, filter_by_priority=None, sort_by_priority=False):
6+
if filter_by_priority is not None:
7+
items = [i for i in items if i["priority"] <= filter_by_priority]
8+
if sort_by_priority:
9+
items = list(sorted(items, key=lambda i: i["priority"]))
10+
list_item_elements = [html.li(i["text"], key=i["id"]) for i in items]
11+
return html.ul(list_item_elements)
12+
13+
14+
@component
15+
def TodoList():
16+
tasks = [
17+
{"id": 0, "text": "Make breakfast", "priority": 0},
18+
{"id": 1, "text": "Feed the dog", "priority": 0},
19+
{"id": 2, "text": "Do laundry", "priority": 2},
20+
{"id": 3, "text": "Go on a run", "priority": 1},
21+
{"id": 4, "text": "Clean the house", "priority": 2},
22+
{"id": 5, "text": "Go to the grocery store", "priority": 2},
23+
{"id": 6, "text": "Do some coding", "priority": 1},
24+
{"id": 7, "text": "Read a book", "priority": 1},
25+
]
26+
return html.section(
27+
html.h1("My Todo List"),
28+
DataList(tasks, filter_by_priority=1, sort_by_priority=True),
29+
)
30+
31+
32+
run(TodoList)

docs/source/conf.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# http://www.sphinx-doc.org/en/master/config
88

99
import sys
10+
from doctest import NORMALIZE_WHITESPACE
1011
from pathlib import Path
1112

1213

@@ -102,6 +103,10 @@
102103
# Controls how sphinx.ext.autodoc represents typehints in the function signature
103104
autodoc_typehints = "description"
104105

106+
# -- Doc Test Configuration -------------------------------------------------------
107+
108+
doctest_default_flags = NORMALIZE_WHITESPACE
109+
105110
# -- Extension Configuration ------------------------------------------------------
106111

107112
# -- MyST Parser --

docs/source/creating-interfaces/dynamic-element-children.rst

Lines changed: 0 additions & 4 deletions
This file was deleted.

docs/source/creating-interfaces/index.rst

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Creating Interfaces
66

77
html-with-idom
88
your-first-components
9-
dynamic-element-children
9+
rendering-data
1010

1111
.. dropdown:: :octicon:`bookmark-fill;2em` What You'll Learn
1212
:color: info
@@ -19,19 +19,19 @@ Creating Interfaces
1919
:link: html-with-idom
2020
:link-type: doc
2121

22-
Learn how to construct HTML layouts with IDOM.
22+
Construct HTML layouts with IDOM.
2323

2424
.. grid-item-card:: :octicon:`package` Your First Components
2525
:link: your-first-components
2626
:link-type: doc
2727

28-
Discover how to define and use components.
28+
Define and use components.
2929

30-
.. grid-item-card:: :octicon:`versions` Dynamic Element Children
31-
:link: dynamic-element-children
30+
.. grid-item-card:: :octicon:`versions` Rendering Data
31+
:link: rendering-data
3232
:link-type: doc
3333

34-
Correctly render lists of child elements that may change in length or order.
34+
Render HTML elements and components from raw data
3535

3636
IDOM is a Python package for making user interfaces (UI). These interfaces are built
3737
from small elements of functionality like buttons text and images. IDOM allows you to
@@ -92,19 +92,11 @@ components are just a normal Python functions that return :ref:`HTML <HTML with
9292
The one special thing about them that we'll concern ourselves with now, is that to
9393
create them we need to add an ``@component`` `decorator
9494
<https://realpython.com/primer-on-python-decorators/>`__. To see what this looks like in
95-
practice we'll put the todo list HTML from above into a component:
95+
practice we'll quickly make a ``Photo`` component:
9696

9797
.. example:: creating_interfaces.simple_photo
9898
:activate-result:
9999

100100

101-
Section 3: Parametrizing Components
102-
-----------------------------------
103-
104-
105-
Section 4: Conditional Rendering
106-
--------------------------------
107-
108-
109-
Section 5: Dynamic Element Children
110-
-----------------------------------
101+
Section 3: Rendering Data
102+
-------------------------

0 commit comments

Comments
 (0)