Skip to content

Commit 1d53864

Browse files
committed
fixes #327
1 parent aeb67dc commit 1d53864

File tree

6 files changed

+518
-422
lines changed

6 files changed

+518
-422
lines changed

fasthtml/_modidx.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,28 +113,29 @@
113113
'fasthtml/oauth.py'),
114114
'fasthtml.oauth._AppClient.retr_id': ('api/oauth.html#_appclient.retr_id', 'fasthtml/oauth.py'),
115115
'fasthtml.oauth._AppClient.retr_info': ('api/oauth.html#_appclient.retr_info', 'fasthtml/oauth.py')},
116+
'fasthtml.pico': { 'fasthtml.pico.Card': ('api/pico.html#card', 'fasthtml/pico.py'),
117+
'fasthtml.pico.Container': ('api/pico.html#container', 'fasthtml/pico.py'),
118+
'fasthtml.pico.DialogX': ('api/pico.html#dialogx', 'fasthtml/pico.py'),
119+
'fasthtml.pico.Grid': ('api/pico.html#grid', 'fasthtml/pico.py'),
120+
'fasthtml.pico.Group': ('api/pico.html#group', 'fasthtml/pico.py'),
121+
'fasthtml.pico.Search': ('api/pico.html#search', 'fasthtml/pico.py'),
122+
'fasthtml.pico.set_pico_cls': ('api/pico.html#set_pico_cls', 'fasthtml/pico.py')},
116123
'fasthtml.starlette': {},
117124
'fasthtml.svg': {},
118125
'fasthtml.toaster': {},
119126
'fasthtml.xtend': { 'fasthtml.xtend.A': ('api/xtend.html#a', 'fasthtml/xtend.py'),
120127
'fasthtml.xtend.AX': ('api/xtend.html#ax', 'fasthtml/xtend.py'),
121128
'fasthtml.xtend.Any': ('api/xtend.html#any', 'fasthtml/xtend.py'),
122129
'fasthtml.xtend.AnyNow': ('api/xtend.html#anynow', 'fasthtml/xtend.py'),
123-
'fasthtml.xtend.Card': ('api/xtend.html#card', 'fasthtml/xtend.py'),
124130
'fasthtml.xtend.CheckboxX': ('api/xtend.html#checkboxx', 'fasthtml/xtend.py'),
125-
'fasthtml.xtend.Container': ('api/xtend.html#container', 'fasthtml/xtend.py'),
126-
'fasthtml.xtend.DialogX': ('api/xtend.html#dialogx', 'fasthtml/xtend.py'),
127131
'fasthtml.xtend.Favicon': ('api/xtend.html#favicon', 'fasthtml/xtend.py'),
128132
'fasthtml.xtend.Form': ('api/xtend.html#form', 'fasthtml/xtend.py'),
129-
'fasthtml.xtend.Grid': ('api/xtend.html#grid', 'fasthtml/xtend.py'),
130-
'fasthtml.xtend.Group': ('api/xtend.html#group', 'fasthtml/xtend.py'),
131133
'fasthtml.xtend.Hidden': ('api/xtend.html#hidden', 'fasthtml/xtend.py'),
132134
'fasthtml.xtend.Now': ('api/xtend.html#now', 'fasthtml/xtend.py'),
133135
'fasthtml.xtend.On': ('api/xtend.html#on', 'fasthtml/xtend.py'),
134136
'fasthtml.xtend.Prev': ('api/xtend.html#prev', 'fasthtml/xtend.py'),
135137
'fasthtml.xtend.Script': ('api/xtend.html#script', 'fasthtml/xtend.py'),
136138
'fasthtml.xtend.ScriptX': ('api/xtend.html#scriptx', 'fasthtml/xtend.py'),
137-
'fasthtml.xtend.Search': ('api/xtend.html#search', 'fasthtml/xtend.py'),
138139
'fasthtml.xtend.Socials': ('api/xtend.html#socials', 'fasthtml/xtend.py'),
139140
'fasthtml.xtend.Style': ('api/xtend.html#style', 'fasthtml/xtend.py'),
140141
'fasthtml.xtend.StyleX': ('api/xtend.html#stylex', 'fasthtml/xtend.py'),
@@ -145,5 +146,4 @@
145146
'fasthtml.xtend.loose_format': ('api/xtend.html#loose_format', 'fasthtml/xtend.py'),
146147
'fasthtml.xtend.replace_css_vars': ('api/xtend.html#replace_css_vars', 'fasthtml/xtend.py'),
147148
'fasthtml.xtend.run_js': ('api/xtend.html#run_js', 'fasthtml/xtend.py'),
148-
'fasthtml.xtend.set_pico_cls': ('api/xtend.html#set_pico_cls', 'fasthtml/xtend.py'),
149149
'fasthtml.xtend.undouble_braces': ('api/xtend.html#undouble_braces', 'fasthtml/xtend.py')}}}

fasthtml/common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from sqlite_minutils import Database
88
from fastlite import *
99
from .basics import *
10+
from .pico import *
1011
from .authmw import *
1112
from .live_reload import *
1213
from .toaster import *

fasthtml/pico.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/04_pico.ipynb.
2+
3+
# %% auto 0
4+
__all__ = ['picocss', 'picolink', 'picocondcss', 'picocondlink', 'set_pico_cls', 'Card', 'Group', 'Search', 'Grid', 'DialogX',
5+
'Container']
6+
7+
# %% ../nbs/api/04_pico.ipynb
8+
from typing import Any
9+
10+
from fastcore.utils import *
11+
from fastcore.xml import *
12+
from fastcore.meta import use_kwargs, delegates
13+
from .components import *
14+
from .xtend import *
15+
16+
try: from IPython import display
17+
except ImportError: display=None
18+
19+
# %% ../nbs/api/04_pico.ipynb
20+
picocss = "https://cdn.jsdelivr.net/npm/@picocss/pico@latest/css/pico.min.css"
21+
picolink = (Link(rel="stylesheet", href=picocss),
22+
Style(":root { --pico-font-size: 100%; }"))
23+
picocondcss = "https://cdn.jsdelivr.net/npm/@picocss/pico@latest/css/pico.conditional.min.css"
24+
picocondlink = (Link(rel="stylesheet", href=picocondcss),
25+
Style(":root { --pico-font-size: 100%; }"))
26+
27+
# %% ../nbs/api/04_pico.ipynb
28+
def set_pico_cls():
29+
js = """var sel = '.cell-output, .output_area';
30+
document.querySelectorAll(sel).forEach(e => e.classList.add('pico'));
31+
32+
new MutationObserver(ms => {
33+
ms.forEach(m => {
34+
m.addedNodes.forEach(n => {
35+
if (n.nodeType === 1) {
36+
var nc = n.classList;
37+
if (nc && (nc.contains('cell-output') || nc.contains('output_area'))) nc.add('pico');
38+
n.querySelectorAll(sel).forEach(e => e.classList.add('pico'));
39+
}
40+
});
41+
});
42+
}).observe(document.body, { childList: true, subtree: true });"""
43+
return display.Javascript(js)
44+
45+
# %% ../nbs/api/04_pico.ipynb
46+
@delegates(ft_hx, keep=True)
47+
def Card(*c, header=None, footer=None, **kwargs)->FT:
48+
"A PicoCSS Card, implemented as an Article with optional Header and Footer"
49+
if header: c = (Header(header),) + c
50+
if footer: c += (Footer(footer),)
51+
return Article(*c, **kwargs)
52+
53+
# %% ../nbs/api/04_pico.ipynb
54+
@delegates(ft_hx, keep=True)
55+
def Group(*c, **kwargs)->FT:
56+
"A PicoCSS Group, implemented as a Fieldset with role 'group'"
57+
return Fieldset(*c, role="group", **kwargs)
58+
59+
# %% ../nbs/api/04_pico.ipynb
60+
@delegates(ft_hx, keep=True)
61+
def Search(*c, **kwargs)->FT:
62+
"A PicoCSS Search, implemented as a Form with role 'search'"
63+
return Form(*c, role="search", **kwargs)
64+
65+
# %% ../nbs/api/04_pico.ipynb
66+
@delegates(ft_hx, keep=True)
67+
def Grid(*c, cls='grid', **kwargs)->FT:
68+
"A PicoCSS Grid, implemented as child Divs in a Div with class 'grid'"
69+
c = tuple(o if isinstance(o,list) else Div(o) for o in c)
70+
return ft_hx('div', *c, cls=cls, **kwargs)
71+
72+
# %% ../nbs/api/04_pico.ipynb
73+
@delegates(ft_hx, keep=True)
74+
def DialogX(*c, open=None, header=None, footer=None, id=None, **kwargs)->FT:
75+
"A PicoCSS Dialog, with children inside a Card"
76+
card = Card(*c, header=header, footer=footer, **kwargs)
77+
return Dialog(card, open=open, id=id)
78+
79+
# %% ../nbs/api/04_pico.ipynb
80+
@delegates(ft_hx, keep=True)
81+
def Container(*args, **kwargs)->FT:
82+
"A PicoCSS Container, implemented as a Main with class 'container'"
83+
return Main(*args, cls="container", **kwargs)

fasthtml/xtend.py

Lines changed: 7 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/02_xtend.ipynb.
22

33
# %% auto 0
4-
__all__ = ['picocss', 'picolink', 'picocondcss', 'picocondlink', 'set_pico_cls', 'A', 'Form', 'AX', 'Hidden', 'CheckboxX', 'Card',
5-
'Group', 'Search', 'Grid', 'DialogX', 'Container', 'Script', 'Style', 'double_braces', 'undouble_braces',
6-
'loose_format', 'ScriptX', 'replace_css_vars', 'StyleX', 'On', 'Any', 'Prev', 'Now', 'AnyNow', 'run_js',
7-
'Titled', 'Socials', 'Favicon', 'jsd', 'clear']
4+
__all__ = ['A', 'Form', 'AX', 'Hidden', 'CheckboxX', 'Script', 'Style', 'double_braces', 'undouble_braces', 'loose_format',
5+
'ScriptX', 'replace_css_vars', 'StyleX', 'On', 'Any', 'Prev', 'Now', 'AnyNow', 'run_js', 'Titled', 'Socials',
6+
'Favicon', 'jsd', 'clear']
87

98
# %% ../nbs/api/02_xtend.ipynb
109
from dataclasses import dataclass, asdict
@@ -19,32 +18,6 @@
1918
try: from IPython import display
2019
except ImportError: display=None
2120

22-
# %% ../nbs/api/02_xtend.ipynb
23-
picocss = "https://cdn.jsdelivr.net/npm/@picocss/pico@latest/css/pico.min.css"
24-
picolink = (Link(rel="stylesheet", href=picocss),
25-
Style(":root { --pico-font-size: 100%; }"))
26-
picocondcss = "https://cdn.jsdelivr.net/npm/@picocss/pico@latest/css/pico.conditional.min.css"
27-
picocondlink = (Link(rel="stylesheet", href=picocondcss),
28-
Style(":root { --pico-font-size: 100%; }"))
29-
30-
# %% ../nbs/api/02_xtend.ipynb
31-
def set_pico_cls():
32-
js = """var sel = '.cell-output, .output_area';
33-
document.querySelectorAll(sel).forEach(e => e.classList.add('pico'));
34-
35-
new MutationObserver(ms => {
36-
ms.forEach(m => {
37-
m.addedNodes.forEach(n => {
38-
if (n.nodeType === 1) {
39-
var nc = n.classList;
40-
if (nc && (nc.contains('cell-output') || nc.contains('output_area'))) nc.add('pico');
41-
n.querySelectorAll(sel).forEach(e => e.classList.add('pico'));
42-
}
43-
});
44-
});
45-
}).observe(document.body, { childList: true, subtree: true });"""
46-
return display.Javascript(js)
47-
4821
# %% ../nbs/api/02_xtend.ipynb
4922
@delegates(ft_hx, keep=True)
5023
def A(*c, hx_get=None, target_id=None, hx_swap=None, href='#', **kwargs)->FT:
@@ -65,9 +38,9 @@ def AX(txt, hx_get=None, target_id=None, hx_swap=None, href='#', **kwargs)->FT:
6538

6639
# %% ../nbs/api/02_xtend.ipynb
6740
@delegates(ft_hx, keep=True)
68-
def Hidden(value:Any="", **kwargs)->FT:
41+
def Hidden(value:Any="", id:Any=None, **kwargs)->FT:
6942
"An Input of type 'hidden'"
70-
return Input(type="hidden", value=value, **kwargs)
43+
return Input(type="hidden", value=value, id=id, **kwargs)
7144

7245
# %% ../nbs/api/02_xtend.ipynb
7346
@delegates(ft_hx, keep=True)
@@ -79,46 +52,6 @@ def CheckboxX(checked:bool=False, label=None, value="1", id=None, name=None, **k
7952
if label: res = Label(res, label)
8053
return Hidden(name=name, skip=True, value=""), res
8154

82-
# %% ../nbs/api/02_xtend.ipynb
83-
@delegates(ft_hx, keep=True)
84-
def Card(*c, header=None, footer=None, **kwargs)->FT:
85-
"A PicoCSS Card, implemented as an Article with optional Header and Footer"
86-
if header: c = (Header(header),) + c
87-
if footer: c += (Footer(footer),)
88-
return Article(*c, **kwargs)
89-
90-
# %% ../nbs/api/02_xtend.ipynb
91-
@delegates(ft_hx, keep=True)
92-
def Group(*c, **kwargs)->FT:
93-
"A PicoCSS Group, implemented as a Fieldset with role 'group'"
94-
return Fieldset(*c, role="group", **kwargs)
95-
96-
# %% ../nbs/api/02_xtend.ipynb
97-
@delegates(ft_hx, keep=True)
98-
def Search(*c, **kwargs)->FT:
99-
"A PicoCSS Search, implemented as a Form with role 'search'"
100-
return Form(*c, role="search", **kwargs)
101-
102-
# %% ../nbs/api/02_xtend.ipynb
103-
@delegates(ft_hx, keep=True)
104-
def Grid(*c, cls='grid', **kwargs)->FT:
105-
"A PicoCSS Grid, implemented as child Divs in a Div with class 'grid'"
106-
c = tuple(o if isinstance(o,list) else Div(o) for o in c)
107-
return ft_hx('div', *c, cls=cls, **kwargs)
108-
109-
# %% ../nbs/api/02_xtend.ipynb
110-
@delegates(ft_hx, keep=True)
111-
def DialogX(*c, open=None, header=None, footer=None, id=None, **kwargs)->FT:
112-
"A PicoCSS Dialog, with children inside a Card"
113-
card = Card(*c, header=header, footer=footer, **kwargs)
114-
return Dialog(card, open=open, id=id)
115-
116-
# %% ../nbs/api/02_xtend.ipynb
117-
@delegates(ft_hx, keep=True)
118-
def Container(*args, **kwargs)->FT:
119-
"A PicoCSS Container, implemented as a Main with class 'container'"
120-
return Main(*args, cls="container", **kwargs)
121-
12255
# %% ../nbs/api/02_xtend.ipynb
12356
@delegates(ft_html, keep=True)
12457
def Script(code:str="", **kwargs)->FT:
@@ -211,9 +144,9 @@ def run_js(js, id=None, **kw):
211144

212145
# %% ../nbs/api/02_xtend.ipynb
213146
@delegates(ft_hx, keep=True)
214-
def Titled(title:str="FastHTML app", *args, **kwargs)->FT:
147+
def Titled(title:str="FastHTML app", *args, cls="container", **kwargs)->FT:
215148
"An HTML partial containing a `Title`, and `H1`, and any provided children"
216-
return Title(title), Main(H1(title), *args, cls="container", **kwargs)
149+
return Title(title), Main(H1(title), *args, cls=cls, **kwargs)
217150

218151
# %% ../nbs/api/02_xtend.ipynb
219152
def Socials(title, site_name, description, image, url=None, w=1200, h=630, twitter_site=None, creator=None, card='summary'):

0 commit comments

Comments
 (0)