AItool commited on
Commit
01f6f52
·
verified ·
1 Parent(s): e4fb719

Update second.py

Browse files
Files changed (1) hide show
  1. second.py +126 -96
second.py CHANGED
@@ -1,96 +1,126 @@
1
- from fasthtml.common import *
2
- # MonsterUI shadows fasthtml components with the same name
3
- from monsterui.all import *
4
- # If you don't want shadowing behavior, you use import monsterui.core as ... style instead
5
-
6
- # Get frankenui and tailwind headers via CDN using Theme.blue.headers()
7
- hdrs = Theme.blue.headers()
8
-
9
- # fast_app is shadowed by MonsterUI to make it default to no Pico, and add body classes
10
- # needed for frankenui theme styling
11
- app, rt = fast_app(hdrs=hdrs)
12
-
13
- # Examples Product Data to render in the gallery and detail pages  
14
- products = [
15
- {"name": "Laptop", "price": "$999", "img": "https://picsum.photos/400/100?random=1"},
16
- {"name": "Smartphone", "price": "$599", "img": "https://picsum.photos/400/100?random=2"},
17
- {"name": "Headphones", "price": "$199", "img": "https://picsum.photos/400/100?random=3"},
18
- {"name": "Smartwatch", "price": "$299", "img": "https://picsum.photos/400/100?random=4"},
19
- {"name": "Tablet", "price": "$449", "img": "https://picsum.photos/400/100?random=5"},
20
- {"name": "Camera", "price": "$799", "img": "https://picsum.photos/400/100?random=6"},]
21
-
22
- def ProductCard(p):
23
- # Card does lots of boilerplate classes so you can just pass in the content
24
- return Card(
25
- # width:100% makes the image take the full width so we are guarenteed that we won't
26
- # have the image cut off or not large enough. Because all our images are a consistent
27
- # size we do not need to worry about stretching or skewing the image, this is ideal.
28
- # If you have images of different sizes, you will need to use object-fit:cover and/or
29
- # height to either strech, shrink, or crop the image. It is much better to adjust your
30
- # images to be a consistent size upfront so you don't have to handle edge cases of
31
- # different images skeweing/stretching differently.
32
- Img(src=p["img"], alt=p["name"], style="width:100%"),
33
- # All components can take a cls argument to add additional styling - `mt-2` adds margin
34
- # to the top (see spacing tutorial for details on spacing).
35
- #
36
- # Often adding space makes a site look more put together - usually the 2 - 5 range is a
37
- # good choice
38
- H4(p["name"], cls="mt-2"),
39
- # There are helpful Enums, such as TextPresetsT, ButtonT, ContainerT, etc that allow for easy
40
- # discoverability of class options.
41
- # bold_sm is helpful for things that you want to look like regular text, but stand out
42
- # visually for emphasis.
43
- P(p["price"], cls=TextPresets.bold_sm),
44
- # ButtonT.primary is useful for actions you really want the user to take (like adding
45
- # something to the card) - these stand out visually. For dangerous actions (like
46
- # deleting something) you generally would want to use ButtonT.destructive. For UX actions
47
- # that aren't a goal of the page (like cancelling something that hasn't been submitted)
48
- # you generally want the default styling.
49
- Button("Click me!", cls=(ButtonT.primary, "mt-2"),
50
- # HTMX can be used as normal on any component
51
- hx_get=product_detail.to(product_name=p['name']),
52
- hx_push_url='true',
53
- hx_target='body'))
54
-
55
- @rt
56
- def index():
57
- # Titled using a H1 title, sets the page title, and wraps contents in Main(Container(...)) using
58
- # frankenui styles. Generally you will want to use Titled for all of your pages
59
- return Titled("Example Store Front!",
60
- Grid(*[ProductCard(p) for p in products], cols_lg=3))
61
-
62
- example_product_description = """\n
63
- This is a sample detailed description of the {product_name}. You can see when clicking on the card
64
- from the gallery you can:
65
-
66
- + Have a detailed description of the product on the page
67
- + Have an order form to fill out and submit
68
- + Anything else you want!
69
- """
70
-
71
- @rt
72
- def product_detail(product_name:str):
73
- return Titled("Product Detail",
74
- # Grid lays out its children in a responsive grid
75
- Grid(
76
- Div(
77
- H1(product_name),
78
- # render_md is a helper that renders markdown into HTML using frankenui styles.
79
- render_md(example_product_description.format(product_name=product_name))),
80
- Div(
81
- H3("Order Form"),
82
- # Form automatically has a class of 'space-y-3' for a margin between each child.
83
- Form(
84
- # LabelInput is a convience wrapper for a label and input that links them.
85
- LabelInput("Name", id='name'),
86
- LabelInput("Email", id='email'),
87
- LabelInput("Quantity", id='quantity'),
88
- # ButtonT.primary because this is the primary action of the page!
89
- Button("Submit", cls=ButtonT.primary))
90
-
91
- ),
92
- # Grid has defaults and args for cols at different breakpoints, but you can pass in
93
- # your own to customize responsiveness.
94
- cols_lg=2))
95
-
96
- serve()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ "MonsterUI Scrollspy Example application"
3
+
4
+ from fasthtml.common import *
5
+ from monsterui.all import *
6
+ import random
7
+
8
+ # Using the "slate" theme with Highlight.js enabled
9
+ hdrs = Theme.slate.headers(highlightjs=True)
10
+ app, rt = fast_app(hdrs=hdrs)
11
+
12
+ ################################
13
+ ### Example Data and Content ###
14
+ ################################
15
+ products = [
16
+ {"name": "Laptop", "price": "$999"},
17
+ {"name": "Smartphone", "price": "$599"}
18
+ ]
19
+
20
+ code_example = """
21
+ # Python Code Example
22
+ def greet(name):
23
+ return f"Hello, {name}!"
24
+
25
+ print(greet("World"))
26
+ """
27
+ testimonials = [
28
+ {"name": "Alice", "feedback": "Great products and excellent customer service!"},
29
+ {"name": "Bob", "feedback": "Fast shipping and amazing quality!"},
30
+ {"name": "Charlie", "feedback": "Amazing experience! Will definitely buy again."},
31
+ {"name": "Diana", "feedback": "Affordable prices and great variety!"},
32
+ {"name": "Edward", "feedback": "Customer support was very helpful."},
33
+ {"name": "Fiona", "feedback": "Loved the design and quality!"}
34
+ ]
35
+
36
+ # Team members
37
+ team = [
38
+ {"name": "Isaac Flath", "role": "CEO"},
39
+ {"name": "Benjamin Clavié", "role": "AI Researcher"},
40
+ {"name": "Alexis Gallagher", "role": "ML Engineer"},
41
+ {"name": "Hamel Husain", "role": "Data Scientist"},
42
+ {"name": "Austin Huang", "role": "Software Engineer"},
43
+ {"name": "Benjamin Warner", "role": "Product Manager"},
44
+ {"name": "Jonathan Whitaker", "role": "UX Designer"},
45
+ {"name": "Kerem Turgutlu", "role": "DevOps Engineer"},
46
+ {"name": "Curtis Allan", "role": "DevOps Engineer"},
47
+ {"name": "Audrey Roy Greenfeld", "role": "Security Analyst"},
48
+ {"name": "Nathan Cooper", "role": "Full Stack Developer"},
49
+ {"name": "Jeremy Howard", "role": "CTO"},
50
+ {"name": "Wayde Gilliam", "role": "Cloud Architect"},
51
+ {"name": "Daniel Roy Greenfeld", "role": "Blockchain Expert"},
52
+ {"name": "Tommy Collins", "role": "AI Ethics Researcher"}
53
+ ]
54
+
55
+
56
+ def ProductCard(p,img_id=1):
57
+ return Card(
58
+ PicSumImg(w=500, height=100, id=img_id),
59
+ DivFullySpaced(H4(p["name"]), P(Strong(p["price"], cls=TextT.sm))),
60
+ Button("Details", cls=(ButtonT.primary, "w-full")))
61
+
62
+ def TestimonialCard(t,img_id=1):
63
+ return Card(
64
+ DivLAligned(PicSumImg(w=50, h=50, cls='rounded-full', id=img_id), H4(t["name"])),
65
+ P(Q((t["feedback"]))))
66
+
67
+
68
+ def TeamCard(m,img_id=1):
69
+ return Card(
70
+ DivLAligned(
71
+ PicSumImg(w=50, h=50, cls='rounded-full', id=img_id),
72
+ Div(H4(m["name"]), P(m["role"]))),
73
+ DivRAligned(
74
+ UkIcon('twitter', cls='w-5 h-5'),
75
+ UkIcon('linkedin', cls='w-5 h-5'),
76
+ UkIcon('github', cls='w-5 h-5'),
77
+ cls=TextT.gray+'space-x-2'
78
+ ),
79
+ cls='p-3')
80
+
81
+ ################################
82
+ ### Navigation and Scrollspy ###
83
+ ################################
84
+
85
+ scrollspy_links = (
86
+ A("Welcome", href="#welcome-section"),
87
+ A("Products", href="#products-section"),
88
+ A("Testimonials", href="#testimonials-section"),
89
+ A("Team", href="#team-section"),
90
+ A("Code Example", href="#code-section"))
91
+ @rt
92
+ def index():
93
+ def _Section(*c, **kwargs): return Section(*c, cls='space-y-3 my-48',**kwargs)
94
+ return Container(
95
+ NavBar(
96
+ *scrollspy_links,
97
+ brand=DivLAligned(H3("Scrollspy Demo!"),UkIcon('rocket',height=30,width=30)),
98
+ sticky=True, uk_scrollspy_nav=True,
99
+ scrollspy_cls=ScrollspyT.bold),
100
+ NavContainer(
101
+ *map(Li, scrollspy_links),
102
+ uk_scrollspy_nav=True,
103
+ sticky=True,
104
+ cls=(NavT.primary,'pt-20 px-5 pr-10')),
105
+ Container(
106
+ # Notice the ID of each section corresponds to the `scrollspy_links` dictionary
107
+ # So in scollspy `NavContainer` the `href` of each `Li` is the ID of the section
108
+ DivCentered(
109
+ H1("Welcome to the Store!"),
110
+ Subtitle("Explore our products and enjoy dynamic code examples."),
111
+ id="welcome-section"),
112
+ _Section(H2("Products"),
113
+ Grid(*[ProductCard(p,img_id=i) for i,p in enumerate(products)], cols_lg=2),
114
+ id="products-section"),
115
+ _Section(H2("Testimonials"),
116
+ Slider(*[TestimonialCard(t,img_id=i) for i,t in enumerate(testimonials)]),
117
+ id="testimonials-section"),
118
+ _Section(H2("Our Team"),
119
+ Grid(*[TeamCard(m,img_id=i) for i,m in enumerate(team)], cols_lg=2, cols_max=3),
120
+ id="team-section"),
121
+ _Section(H2("Code Example"),
122
+ CodeBlock(code_example, lang="python"),
123
+ id="code-section")),
124
+ cls=(ContainerT.xl,'uk-container-expand'))
125
+
126
+ serve()