|
| 1 | +from prefab_ui.actions import ShowToast |
| 2 | +from prefab_ui.app import PrefabApp |
| 3 | +from prefab_ui.components import ( |
| 4 | + H3, |
| 5 | + Badge, |
| 6 | + Button, |
| 7 | + Column, |
| 8 | + DataTable, |
| 9 | + DataTableColumn, |
| 10 | + Form, |
| 11 | + Input, |
| 12 | + Row, |
| 13 | + Select, |
| 14 | + SelectOption, |
| 15 | + Separator, |
| 16 | +) |
| 17 | + |
| 18 | +contacts = [ |
| 19 | + {"name": "Arthur Dent", "email": "arthur@earth.com", "category": "Customer"}, |
| 20 | + {"name": "Ford Prefect", "email": "ford@betelgeuse.org", "category": "Partner"}, |
| 21 | + { |
| 22 | + "name": "Trillian Astra", |
| 23 | + "email": "trillian@heartofgold.com", |
| 24 | + "category": "Customer", |
| 25 | + }, |
| 26 | + {"name": "Zaphod Beeblebrox", "email": "zaphod@galaxy.gov", "category": "Vendor"}, |
| 27 | +] |
| 28 | + |
| 29 | +rows = [ |
| 30 | + { |
| 31 | + "name": c["name"], |
| 32 | + "email": c["email"], |
| 33 | + "category": Badge( |
| 34 | + c["category"], |
| 35 | + variant="success" |
| 36 | + if c["category"] == "Customer" |
| 37 | + else "secondary" |
| 38 | + if c["category"] == "Partner" |
| 39 | + else "outline", |
| 40 | + ), |
| 41 | + } |
| 42 | + for c in contacts |
| 43 | +] |
| 44 | + |
| 45 | +with PrefabApp() as app: |
| 46 | + with Column(gap=4, css_class="p-6"): |
| 47 | + DataTable( |
| 48 | + columns=[ |
| 49 | + DataTableColumn(key="name", header="Name", sortable=True), |
| 50 | + DataTableColumn(key="email", header="Email"), |
| 51 | + DataTableColumn(key="category", header="Category"), |
| 52 | + ], |
| 53 | + rows=rows, |
| 54 | + search=True, |
| 55 | + ) |
| 56 | + |
| 57 | + Separator() |
| 58 | + |
| 59 | + H3("Add Contact") |
| 60 | + with Form( |
| 61 | + on_submit=ShowToast( |
| 62 | + "Contact saved! (preview demo — no backend wired)", |
| 63 | + variant="success", |
| 64 | + ), |
| 65 | + ): |
| 66 | + with Row(gap=4): |
| 67 | + Input(name="name", label="Name", placeholder="Full name", required=True) |
| 68 | + Input( |
| 69 | + name="email", |
| 70 | + label="Email", |
| 71 | + placeholder="name@example.com", |
| 72 | + required=True, |
| 73 | + ) |
| 74 | + with Select(name="category", label="Category"): |
| 75 | + SelectOption(value="Customer", label="Customer") |
| 76 | + SelectOption(value="Partner", label="Partner") |
| 77 | + SelectOption(value="Vendor", label="Vendor") |
| 78 | + Button("Save Contact") |
0 commit comments