This repository has been archived by the owner on Aug 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
4599 lines (4086 loc) · 110 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from fasthtml.common import * # type: ignore
from fasthtml.js import MarkdownJS, SortableJS, HighlightJS
#from fastapi import Request
#-----------------------------------------------------------------------------
# HTML 5 conventions
# Probably better implementation of a dark/light switch:
# https://github.com/picocss/examples/blob/master/v2-react-color-schemes-and-modal/src/components/ColorSchemeSwitcher.js
html = Html(lang='en',
# data_theme="light"
)
# document.documentElement.setAttribute('data-theme', prefersDark ? 'dark' : 'light');
# Dark/Lite mode
# // const prefersDark =
# // window.matchMedia &&
# // window.matchMedia("(prefers-color-scheme: dark)").matches;
# //
# // document.addEventListener("DOMContentLoaded", function () {
# // document.documentElement.setAttribute('data-theme', prefersDark ? 'dark' : 'light');
data_theme = Script('''
document.addEventListener("DOMContentLoaded", function () {
document.querySelectorAll(".dark-mode-switcher").forEach(function (switcher) {
switcher.addEventListener("click", function (e) {
// const theme = document.documentElement.getAttribute('data-theme');
if (document.documentElement.getAttribute('data-theme') === "dark") {
document.documentElement.setAttribute("data-theme", "light");
} else {
document.documentElement.setAttribute("data-theme", "dark");
}
e.preventDefault();
});
});
});
''')
onload_theme = Script(
'''const prefersDark =
window.matchMedia &&
window.matchMedia("(prefers-color-scheme: dark)").matches;
me("html").attribute('data-theme', prefersDark ? 'dark' : 'light');'''
)
# theme_button_test = Script('''me("html").attribute('data-theme', 'dark' ? 'light' : 'dark');''')
head = (
Meta(charset="utf-8"),
Meta(name="viewport", content="width=device-width, initial-scale=1"),
Meta(name="color-scheme", content="light dark"),
# Script(src="https://unpkg.com/hyperscript.org@0.9.12"),
# Script(src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"),
data_theme,
)
line_numbers = (
Script(src="//cdn.jsdelivr.net/npm/highlightjs-line-numbers.js@2.8.0/dist/highlightjs-line-numbers.min.js"),
Script("hljs.highlightAll(); hljs.initLineNumbersOnLoad({singleLine: false});")
)
#-----------------------------------------------------------------------------
# Page-specific
header_text = 'FastHTML 🧡 Pico CSS'
title = Title(header_text)
footer_text = P("Made by kit using FastHTML & Pico CSS, June 2024.")
#-----------------------------------------------------------------------------
# <head> scripts & css
pico_css = Link(
rel="stylesheet",
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.pumpkin.min.css",
type="text/css"
)
page_css = Link(
rel="stylesheet",
href="style/single-page copy.css",
type="text/css"
)
#-----------------------------------------------------------------------------
# FastHTML app
app = FastHTML(hdrs=(
head,
pico_css,
page_css,
MarkdownJS('.markdown'),
SortableJS('.sortable'),
HighlightJS('.highlight'),
line_numbers,
onload_theme,
# theme_button_test,
# title,
))
rt = app.route
@rt("/{fname:path}.{ext:static}") # Serve static files
async def get(fname:str, ext:str): return FileResponse(f'{fname}.{ext}') # type: ignore
#-----------------------------------------------------------------------------
# Features
# Dark/Light mode toggle
def theme_button():
return Article(
Button(
f"Toggle theme",
cls="contrast dark-mode-switcher",
value="Toggle dark mode",
),
id="theme-switcher",
aria_label="Theme switcher",
)
def theme_toggle():
return A(
f"🌗",
cls="contrast dark-mode-switcher",
href="/",
data_tooltip="Dark/Light mode",
data_placement="bottom",
value="Toggle dark mode",
id="theme-switcher",
aria_label="Theme switcher",
)
#-----------------------------------------------------------------------------
# Helper functions to build proper HTML structure (nesting, etc.)
# Must-have to change ALL at once (CSS class, HTML layout, whatever)
# /!\ Absolutely minimalist and specific to this website
def span_code(code, lang=None):
'''Returns an inline <code> block.
Use within <h4> sections to display code examples.
'''
if lang:
cls = "inline-code highlight language-"+lang
else:
# cls = "inline-code highlight"
cls = "inline-code"
return Code(code, cls=cls)
def div_code(code, lang=None):
'''Returns a <div> wrapping a <pre><code> block.
Use within <h4> sections to display code examples.
'''
if lang: cls='highlight language-'+lang
else: cls='highlight'
return Div(
Pre(
Code(code,
cls=cls
),
),
cls='code',
)
def cl_h(code, lang='html'):
'''Think of this as div_code_html().
'''
return div_code(code, lang)
def cl_f(code, lang='python'):
'''Think of this as div_code_python_fasthtml().
'''
return div_code(code, lang)
def heading(lv:int, title:str, desc=None):
'''Returns a header block with title and anchor link. Followed by optional description.
'''
h = [H1, H2, H3, H4, H5, H6]
hn = h[lv-1]
anchor = title.lower().replace(' ', '-')
return (
hn(
title,
A(
'🔗',
href='#'+anchor,
id=anchor,
cls='secondary',
tabindex="-1",
)
),
P(desc) if desc else None,
)
def aside(*aside_tags):
'''Returns an <aside> block. TODO: Implementation
`aside_tags` needs to be created (ToC) from the list of H2, H3, H4…
'''
return Aside(aside_tags)
# +
# def art_c(*c): # c for content
# return (*c, )
# +
# def art_footer(html, python):
# return Footer(Pre(span_code(html)), Pre(span_code(python)))
# =
def article(*c, hd=None, ft=None, card=False, **kwargs):
return Card(*c, header=hd, footer=ft, **kwargs) if card else Article(*c, header=hd, footer=ft, **kwargs)
# c: lv2_s & lv3_s contain other sections (lv3_s & lv4_s respectively);
# lv4_s contains c_n_m_k (tuple of HTML tags)
def section(*c, lv:int, title:str, desc=None, **kwargs):
return Section(heading(lv=lv, title=title, desc=desc), *c, **kwargs)
# We wrap all lv2 (MAIN) sections in a div with proper id and role.
def div_lv2_s(*sections, **kwargs):
return Div(*sections, id="content", role="document", **kwargs)
# Create <main> with flat lv2 (MAIN) sections. Optional aside etc.
def main(*lv2_s, aside_tags=None, **kwargs):
return (
Main(
aside(aside_tags) if aside_tags else None,
div_lv2_s(*lv2_s, **kwargs),
cls="container",
)
)
#-----------------------------------------------------------------------------
# PAGE CONTENTS
# pico_ → HTML/CSS code
# fh_ → FastHTML (Python) code
# body_ → Tags
# sec_ → section
# #_#_# → section number
# lv#_sec → <h#> (h2, h3, h4) section
#--------------------------------------------------------------------------- 1
# 1. Getting started
# 1.1. Quick start
# 1.2. Version picker
# 1.3. Color schemes
# 1.4. Class-less version
# 1.5. Conditional styling
# 1.6. RTL
#---------------------------------- 1.1
# 1.1 Quick start
# 1.1.1 Install manually
# 1.1.2 Usage from CDN
# 1.1.3 Usage with NPM
# 1.1.4 Install with Composer
# 1.1.5 Starter HTML template
pico_1_1_1 = cl_h(
"""<link rel="stylesheet" href="css/pico.min.css" />""",
lang="html",
)
body_1_1_1 = (
P(
A(
"Download Pico",
rel="noopener noreferrer",
href="https://github.com/picocss/pico/archive/refs/heads/main.zip",
target="_blank"
),
""" and link """,
span_code("/css/pico.min.css"),
""" in the """,
span_code("""<head>""", lang="html", ),
""" of your website.""",
),
pico_1_1_1,
)
sec_1_1_1 = section(
body_1_1_1,
lv=4, title="Install manually",
)
pico_1_1_2 = cl_h(
"""<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css"
/>""",
lang="html",
)
body_1_1_2 = P(
"""Alternatively, you can use """,
A(
"jsDelivr CDN",
rel="noopener noreferrer",
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/",
target="_blank"
),
""" to link """,
span_code("pico.min.css"),
'.',
pico_1_1_2,
)
sec_1_1_2 = section(body_1_1_2,
lv=4, title="Usage from CDN",
)
pico_1_1_5 = cl_h(
"""<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="color-scheme" content="light dark" />
<link rel="stylesheet" href="css/pico.min.css">
<title>Hello world!</title>
</head>
<body>
<main class="container">
<h1>Hello world!</h1>
</main>
</body>
</html>""",
lang="html",
)
fh_1_1_5 = cl_f(
"""from fasthtml.common import *
html = Html(lang='en')
head = (
Meta(charset="utf-8"),
Meta(name="viewport", content="width=device-width, initial-scale=1"),
Meta(name="color-scheme", content="light dark"),
Link(rel="stylesheet",
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.pumpkin.min.css"
)
)
app = FastHTML(hdrs=head)
rt = app.route
@rt("/")
def get():
return html, Main(H1('Hello world!'), cls="container")"""
)
sec_1_1_5 = section(pico_1_1_5, fh_1_1_5,
lv=4, title="Starter HTML template",
)
# this must nest all lv4_s
sec_1_1_0 = section(
P("There are 4 ways to get started with pico.css:"),
sec_1_1_1,
sec_1_1_2,
sec_1_1_5,
lv=3, title="Quick start",
desc=(
"""Link """,
span_code("pico.css"),
""" manually or via CDN for a dependency-free setup, or use NPM or Composer for advanced usage.""",
),
)
#---------------------------------- 1.2
sec_1_2_0 = section(
lv=3, title="Version picker",
desc="Easily select the ideal Pico CSS version variant to match your project's needs."
)
#---------------------------------- 1.3
body_1_3_1 = (
P( "Color schemes can be defined for the entire document using ",
span_code('<html data-theme="light">', lang='html'),
" or for specific HTML elements, such as ",
span_code('<article data-theme="dark">', lang='html'),
".",
),
P( "Color schemes at the HTML tag level work great for elements such as ",
span_code('<a>', lang='html'), ', ',
span_code('<button>', lang='html'), ', ',
span_code('<table>', lang='html'), ', ',
span_code('<input>', lang='html'), ', ',
span_code('<textarea>', lang='html'), ', ',
span_code('<select>', lang='html'), ', ',
span_code('<article>', lang='html'), ', ',
span_code('<dialog>', lang='html'), ', ',
span_code('<progress>', lang='html'), '.',
),
P( "CSS variables specific to the color scheme are assigned to every HTML tag. However, we have not enforced specific background and color settings across all HTML tags to maintain transparent backgrounds and ensure colors are inherited from the parent tag."
),
P( "For some other HTML tags, you might need to explicitly set ",
span_code('background-color', lang='css'),
" and ",
span_code('color', lang='css'),
"."
),
),
css_1_3_1 = div_code(
"""section {
background-color: var(--pico-background-color);
color: var(--pico-color);
}""",
lang="css",
)
sec_1_3_1 = section(body_1_3_1, css_1_3_1,
lv=4, title="Usage",
)
def art_1_3_2(dark:bool=False):
if dark:
theme, title = "dark", H2("Dark card")
else:
theme, title = "light", H2("Light card")
aria = f"Forced {theme} theme example"
pico = f"<article data-theme={theme}>\n …\n</article>"
footer = Footer(Pre(span_code(pico, lang='html'),),cls="code",)
form = Form(
Fieldset(
Input(type="text",
name="login",
placeholder="Login",
aria_label="Login",
autocomplete="username",
),
Input(type="password",
name="password",
placeholder="Password",
aria_label="Password",
autocomplete="current-password",
),
Button("Login", type="submit"),
cls='grid',
),
Fieldset(
Label(
Input(type="checkbox",
role="switch",
name="switch",
checked="",
),
"Remember me",
),
),
)
return Article(
title,
form,
footer,
cls="card",
data_theme=theme,
aria_label=aria,
)
art_1_3_2a = art_1_3_2()
art_1_3_2b = art_1_3_2(dark=True),
fh_1_3_2 = P("FastHTML 🡇", cls="fh-cue"), cl_h(
"""Article(…, data_theme="light")\nArticle(…, data_theme="dark")""",
lang="python",
)
sec_1_3_2 = section(
art_1_3_2a,
art_1_3_2b,
fh_1_3_2,
lv=4, title="Card example",
)
sec_1_3_0 = section(
P("""The default color scheme is Light. The Dark scheme is automatically enabled if the user has dark mode enabled """,
span_code("prefers-color-scheme: dark;"), '.'),
theme_button(),
sec_1_3_1,
sec_1_3_2,
lv=3, title="Color Schemes",
desc=(
"""Pico CSS comes with both Light and Dark color schemes, automatically enabled based on user preferences."""
)
)
#---------------------------------- 1.4
sec_1_4_0 = section(
lv=3, title="Class-less version",
desc=(
"Embrace minimalism with Pico’s ",
span_code(".classless"),
" version, a semantic option for wild HTML purists who prefer a stripped-down approach.",
),
)
#---------------------------------- 1.5
sec_1_5_0 = section(
lv=3, title="Conditional styling",
desc=(
"Apply Pico CSS styles selectively by wrapping elements in a ",
span_code(".pico"),
" container, ideal for mixed-style environments.",
),
)
#---------------------------------- 1.6
sec_1_6_0 = section(
lv=3, title="RTL",
desc="Support for Right-To-Left text."
)
# lv2_s must nest all lv3_s
sec_1_0_0 = section(
sec_1_1_0,
sec_1_2_0,
sec_1_3_0,
sec_1_4_0,
sec_1_5_0,
sec_1_6_0,
lv=2, title="Getting started",
)
#--------------------------------------------------------------------------- 2
# 2. Customization
# 2.1 CSS Variables
# 2.2 Sass
# 2.3 Colors
#---------------------------------- 2.1
sec_2_1_0 = section(
lv=3, title="CSS Variables",
desc="Customize Pico's design system with over 130 CSS variables to create a unique look and feel."
)
#---------------------------------- 2.2
sec_2_2_0 = section(
lv=3, title="Sass",
desc=(
"Build your own minimal design system by compiling a custom version of Pico CSS framework with ",
A("SASS"),
"."),
)
#---------------------------------- 2.3
sec_2_3_0 = section(
lv=3, title="Colors",
desc="Pico comes with 380 manually crafted colors to help you personalize your brand design system."
)
sec_2_0_0 = section(
sec_2_1_0,
sec_2_2_0,
sec_2_3_0,
lv=2, title="Customization",
)
#--------------------------------------------------------------------------- 3
# 3.Layout
# 3.1 Container
# 3.2 Landmarks & section
# 3.3 Grid
# 3.4 Overflow auto NEW
#---------------------------------- 3.1
# 3.1 Container
# 3.1.1 Breakpoints
# 3.1.2 Fixed width
# 3.1.3 Fluid width
# 3.1.4 Semantic containers
body_3_1_1a = (
P("Pico includes six default breakpoints. These breakpoints can be customized with ",
A("Sass", href="https://picocss.com/docs/sass"), "."),
)
table_3_1_1 = Table(
Thead(Tr(Th("Device"), Th("Breakpoint"), Th("Viewport"))),
Tbody(
Tr(Td("Extra small"), Td("<576px"), Td("100%")),
Tr(Td("Small"), Td("≥576px"), Td("510px")),
Tr(Td("Medium"), Td("≥768px"), Td("700px")),
Tr(Td("Large"), Td("≥1024px"), Td("950px")),
Tr(Td("Extra large"), Td("≥1280px"), Td("1200px")),
Tr(Td("Extra extra large"), Td("≥1536px"), Td("1450px")),
),
)
body_3_1_1b = (
P(span_code(".container"),
" and ",
span_code(".container-fluid"),
" are not available in the ",
A("class‑less version", href="https://picocss.com/docs/classless"),
" (see ",
A("Semantic containers", href="https://picocss.com/docs/container#semantic-containers"),
" for an alternative)."),
)
sec_3_1_1 = section(
body_3_1_1a,
table_3_1_1,
body_3_1_1b,
lv=4, title="Breakpoints",
)
body_3_1_2 = (
P(span_code(".container"), " provides a centered container with a fixed width."),
cl_h(
"""<body>
<main class="container">
...
</main>
</body>
""", lang="html"),
)
sec_3_1_2 = section(
body_3_1_2,
lv=4, title="Fixed width",
)
body_3_1_3 = (
P(span_code(".container-fluid"), " provides a full-width container."),
cl_h(
"""<body>
<main class="container-fluid">
...
</main>
</body>
""", lang="html"),
)
sec_3_1_3 = section(
body_3_1_3,
lv=4, title="Fluid width",
)
body_3_1_4 = (
P(
"In the classless version, ",
span_code("<header>", lang='html'), ", ",
span_code("<main>", lang='html'), ", and ",
span_code("<footer>", lang='html'),
" inside ",
span_code("<body>", lang='html'),
" act as containers to define a centered or a fluid viewport."),
P("See ", A("Class-less version", href="https://picocss.com/docs/classless"), "."),
)
sec_3_1_4 = section(
body_3_1_4,
lv=4, title="Semantic containers",
)
sec_3_1_0 = section(
sec_3_1_1,
sec_3_1_2,
sec_3_1_3,
sec_3_1_4,
lv=3, title="Container",
desc=("Use ", span_code('.container'), "for a centered viewport or ", span_code('.container-fluid'), " for a full-width layout.")
)
#---------------------------------- 3.2
# 3.2 Landmarks & section
# 3.2.1 Landmarks
# 3.2.2 Custom root container
# 3.2.3 Section
body_3_2_1 = (
P(
span_code("<header>", lang='html'), ", ",
span_code("<main>", lang='html'), ", and ",
span_code("<footer>", lang='html'),
" as direct children of ",
span_code("<body>", lang='html'),
" provide a responsive vertical padding.",
),
)
pico_3_2_1 = cl_h(
"""<body>
<header>...</header>
<main>...</main>
<footer>...</footer>
</body>
""", lang="html"),
sec_3_2_1 = section(
body_3_2_1,
pico_3_2_1,
lv=4, title="Landmarks",
)
body_3_2_2a = (
P(
"If you need to customize the default root container for ",
span_code("<header>", lang='html'), ", ",
span_code("<main>", lang='html'), ", and ",
span_code("<footer>", lang='html'),
", you can recompile Pico with another CSS selector.",
),
P("Useful for ", A("React", href="https://reactjs.org/"), ", ", A("Gatsby", href="https://www.gatsbyjs.com/"), " or ", A("Next.js", href="https://nextjs.org/"), "."),
)
pico_3_2_2a = cl_h(
"""/* Custom Class-less version for React */
@use "pico" with (
// Define the root element used to target <header>, <main>, <footer>
// with $enable-semantic-container and $enable-responsive-spacings
$semantic-root-element: "#root";
// Enable <header>, <main>, <footer> inside $semantic-root-element as containers
$enable-semantic-container: true;
// Enable .classes
$enable-classes: false;
)
""", lang="jsx"),
body_3_2_2b = (
P("The code above will compile Pico with the containers defined like this:"),
)
pico_3_2_2b = div_code(
"""/* Containers */
#root > header,
#root > main,
#root > footer {
...
}
""", lang='css'),
body_3_2_2c = (
P(
"Learn more about ",
A("compiling a custom version of Pico with SASS",
href="https://picocss.com/docs/sass"), "."),
)
sec_3_2_2 = section(
body_3_2_2a,
pico_3_2_2a,
body_3_2_2b,
pico_3_2_2b,
body_3_2_2c,
lv=4, title="Custom root container",
)
body_3_2_3 = (
P(
span_code("<section>", lang='html'),
" provides a responsive margin-bottom to separate your sections."),
)
sec_3_2_3 = section(
body_3_2_3,
lv=4, title="Section",
)
sec_3_2_0 = section(
sec_3_2_1,
sec_3_2_2,
sec_3_2_3,
lv=3, title="Landmarks & section",
desc="Structure your pages with semantic landmarks and sections for better accessibility and graceful spacings.",
)
#---------------------------------- 3.3
# 3.3 Grid
# 3.3.1 Syntax
# 3.3.2 About CSS Grids
art_3_3_1 = Article(
Div(
Div(1),
Div(2),
Div(3),
Div(4),
cls="grid"
),
Footer(
cl_h(
"""<div class="grid">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
</div>""",
lang="html"),
cls="code",
),
cls="component"
)
body_3_3_1 = (
P("Columns intentionally collapse on small devices (", span_code("<768px"), ")."),
P(span_code(".grid"), "is not available in the ", A("class‑less", href="https://picocss.com/docs/classless"), " version."),
)
sec_3_3_1 = section(
art_3_3_1,
body_3_3_1,
lv=4, title="Syntax",
)
body_3_3_2 = (
P("As Pico focuses on native HTML elements, we kept this grid system minimalist."),
P("A complete grid system in flexbox, with all the ordering, offsetting, and breakpoints utilities, can be heavier than the total size of the Pico library. Not really in the Pico spirit."),
P("If you need a quick way to prototype or build a complex layout, you can look at ", Strong("Flexbox grid layouts"), "-for example, ", A("Bootstrap Grid System", href="https://getbootstrap.com/docs/4.2/getting-started/contents/"), " or ", A("Flexbox Grid", href="http://flexboxgrid.com/"), "."),
P("If you need a light and custom grid, you can look at CSS Grid Generators-for example, ", A("CSS Grid Generator", href="https://cssgrid-generator.netlify.com/"), ", ", A("Layoutit!", href="http://grid.layoutit.com/"), " or ", A("Griddy", href="https://griddy.io/"), "."),
P("Alternatively, you can ", A("learn about CSS Grid", href="https://learncssgrid.com/"), "."),
)
sec_3_3_2 = section(
body_3_3_2,
lv=4, title="About CSS Grids",
)
sec_3_3_0 = section(
sec_3_3_1,
sec_3_3_2,
lv=3, title="Grid",
desc=(
"Create minimal responsive layouts with ",
span_code(".grid"),
" to enable auto-layout columns."),
)
#---------------------------------- 3.4
# 3.4 Overflow auto
body_3_4_1 = (
P("Useful to have responsive ", span_code("<table>", lang='html'), "."),
)
table_3_4_1 = (Div(
Table(
Thead(
Tr(Th("Heading"),Th("Heading"),Th("Heading"),Th("Heading"),
Th("Heading"),Th("Heading"),Th("Heading"),Th("Heading"),
Th("Heading"),Th("Heading"),Th("Heading"),Th("Heading"))),
Tbody(
Tr(Td("Cell"),Td("Cell"),Td("Cell"),Td("Cell"),Td("Cell"),Td("Cell"),
Td("Cell"),Td("Cell"),Td("Cell"),Td("Cell"),Td("Cell"),Td("Cell")),
Tr(Td("Cell"),Td("Cell"),Td("Cell"),Td("Cell"),Td("Cell"),Td("Cell"),
Td("Cell"),Td("Cell"),Td("Cell"),Td("Cell"),Td("Cell"),Td("Cell")),
Tr(Td("Cell"),Td("Cell"),Td("Cell"),Td("Cell"),Td("Cell"),Td("Cell"),
Td("Cell"),Td("Cell"),Td("Cell"),Td("Cell"),Td("Cell"),Td("Cell")),)
),
cls="overflow-auto",
))
pico_3_4_1 = cl_h(
"""<div class="overflow-auto">
<table>
…
</table>
</div>""",
lang="html"
)
sec_3_4_0 = section(
body_3_4_1,
table_3_4_1,
pico_3_4_1,
lv=3, title="Overflow auto",
desc=(
span_code(".overflow-auto"),
" enables automatic scrollbars to an element if its content extends beyond its limits."),
)
sec_3_0_0 = section(
sec_3_1_0,
sec_3_2_0,
sec_3_3_0,
sec_3_4_0,
lv=2, title="Layout",
)
#----------------------------------------------------------------------------4
# 4. Content
# 4.1 Typography
# 4.2 Link
# 4.3 Button
# 4.4 Table
#---------------------------------- 4.1
# 4.1 Typography
# 4.1.1 Font sizes
# 4.1.2 Headings
# 4.1.3 Heading group
# 4.1.4 Inline text elements
# 4.1.5 Blockquote
# 4.1.6 Horizontal rule
table_4_1_1a = Table(
Thead(
Tr(Th("Breakpoint"),Th("xs"),Th("sm"),Th("md"),Th("lg"),Th("xl"),Th("xxl")),
),
Tbody(
Tr(Td("Base"),Td("16px"),Td("17px"),Td("18px"), Td("19px"), Td("20px"), Td("21px")),
Tr(Td(span_code("<h1>") ), Td("32px"),Td("34px"), Td("36px"), Td("38px"), Td("40px"), Td("42px")),
Tr(Td(span_code("<h2>") ), Td("28px"),Td("29.75px"), Td("31.5px"), Td("33.25px"), Td("35px"), Td("36.75px")),
Tr(Td(span_code("<h3>") ), Td("24px"),Td("25.5px"), Td("27px"), Td("28.5px"), Td("30px"), Td("31.5px")),
Tr(Td(span_code("<h4>") ), Td("20px"),Td("21.25px"), Td("22.5px"), Td("23.75px"), Td("25px"), Td("26.25px")),
Tr(Td(span_code("<h5>") ), Td("18px"),Td("19.125px"),Td("20.25px"),Td("21.375px"),Td("22.5px"),Td("23.625px")),
Tr(Td(span_code("<h6>") ), Td("16px"),Td("17px"), Td("18px"), Td("19px"), Td("20px"), Td("21px")),
Tr(Td(span_code("<small>")), Td("14px"),Td("14.875px"),Td("15.75px"),Td("16.625px"),Td("17.5px"),Td("18.375px")),
),
cls="overflow-auto",
)
body_4_1_1a = P("In ", span_code("rem"), " units:")
table_4_1_1b = Table(
Thead(
Tr(Th("Breakpoint"),Th("xs"),Th("sm"),Th("md"),Th("lg"),Th("xl"),Th("xxl")),
),
Tbody(
Tr(Td("Base"),Td("100%"),Td("106.25%"),Td("112.5%"),Td("118.75%"),Td("125%"),Td("131.25%")),
Tr(Td(span_code("<h1>") ),Td("x 2rem"),Td("x 2rem"),Td("x 2rem"),Td("x 2rem"),Td("x 2rem"),Td("x 2rem")),
Tr(Td(span_code("<h2>") ),Td("x 1.75rem"),Td("x 1.75rem"),Td("x 1.75rem"),Td("x 1.75rem"),Td("x 1.75rem"),Td("x 1.75rem")),
Tr(Td(span_code("<h3>") ),Td("x 1.5rem"),Td("x 1.5rem"),Td("x 1.5rem"),Td("x 1.5rem"),Td("x 1.5rem"),Td("x 1.5rem")),
Tr(Td(span_code("<h4>") ),Td("x 1.25rem"),Td("x 1.25rem"),Td("x 1.25rem"),Td("x 1.25rem"),Td("x 1.25rem"),Td("x 1.25rem")),
Tr(Td(span_code("<h5>") ),Td("x 1.125rem"),Td("x 1.125rem"),Td("x 1.125rem"),Td("x 1.125rem"),Td("x 1.125rem"),Td("x 1.125rem")),
Tr(Td(span_code("<h6>") ),Td("x 1rem"),Td("x 1rem"),Td("x 1rem"),Td("x 1rem"),Td("x 1rem"),Td("x 1rem")),
Tr(Td(span_code("<small>")),Td("x 0.875em"),Td("x 0.875em"),Td("x 0.875em"),Td("x 0.875em"),Td("x 0.875em"),Td("x 0.875em")),
),
cls="overflow-auto",
)
body_4_1_1b = (
P("To ensure that the user’s default font size is followed, the base font size is defined as a percentage that grows with the user’s screen size, while HTML elements are defined in ", span_code("rem"), "."),
P("Since ", span_code("rem"), " is a multiplier of the HTML document font size, all HTML element’s font sizes grow proportionally with the size of the user’s screen.")
)
sec_4_1_1 = section(
body_4_1_1a,
table_4_1_1a,
body_4_1_1b,
table_4_1_1b,
lv=4, title="Font sizes",
)
#------------------
art_4_1_2 = article(
H1("Heading 1"),
H2("Heading 2"),
H3("Heading 3"),
H4("Heading 4"),
H5("Heading 5"),
H6("Heading 6"),)
pico_4_1_2 = cl_h(
code="""<h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<h4>Heading 4</h4>
<h5>Heading 5</h5>
<h6>Heading 6</h6>""",
lang="html"),
sec_4_1_2 = section(
art_4_1_2,
pico_4_1_2,
lv=4, title="Headings",
)
#------------------
sec_4_1_3 = section(