AItool commited on
Commit
f240e93
·
verified ·
1 Parent(s): 42601df

Upload second.py

Browse files
Files changed (1) hide show
  1. second.py +96 -0
second.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()