|
| 1 | +""" |
| 2 | +Example Tailwind command: |
| 3 | +
|
| 4 | +``` |
| 5 | +npx tailwindcss -i ./tailwind_input.css -o ./tailwind.css |
| 6 | +``` |
| 7 | +
|
| 8 | +Example Tailwind config: |
| 9 | +
|
| 10 | +``` |
| 11 | +/** @type {import('tailwindcss').Config} */ |
| 12 | +module.exports = { |
| 13 | + content: ["main.py"], |
| 14 | + theme: { |
| 15 | + extend: {}, |
| 16 | + }, |
| 17 | + plugins: [], |
| 18 | + safelist: [], |
| 19 | +}; |
| 20 | +``` |
| 21 | +
|
| 22 | +Original HTML mark up: |
| 23 | +
|
| 24 | +``` |
| 25 | +<html> |
| 26 | +<body class="min-h-screen flex flex-col"> |
| 27 | +
|
| 28 | + <!-- Header --> |
| 29 | + <header class="bg-gray-800 text-white py-4"> |
| 30 | + <div class="container mx-auto"> |
| 31 | + <h1 class="text-2xl font-bold">Header</h1> |
| 32 | + </div> |
| 33 | + </header> |
| 34 | +
|
| 35 | + <!-- Main Content with Sidebar --> |
| 36 | + <div class="flex flex-1"> |
| 37 | + <!-- Sidebar --> |
| 38 | + <aside class="w-64 bg-gray-200 p-4"> |
| 39 | + <h2 class="text-lg font-semibold mb-4">Sidebar</h2> |
| 40 | + <ul> |
| 41 | + <li><a href="#" class="text-gray-700 block py-2">Link 1</a></li> |
| 42 | + <li><a href="#" class="text-gray-700 block py-2">Link 2</a></li> |
| 43 | + <li><a href="#" class="text-gray-700 block py-2">Link 3</a></li> |
| 44 | + </ul> |
| 45 | + </aside> |
| 46 | +
|
| 47 | + <!-- Main Content --> |
| 48 | + <main class="flex-1 p-6 bg-gray-100"> |
| 49 | + <div class="grid grid-cols-1 md:grid-cols-3 gap-4"> |
| 50 | + <div class="bg-white p-6 rounded shadow"> |
| 51 | + <h2 class="text-xl font-bold mb-2">Box 1</h2> |
| 52 | + <p>This is the content for box 1.</p> |
| 53 | + </div> |
| 54 | + <div class="bg-white p-6 rounded shadow"> |
| 55 | + <h2 class="text-xl font-bold mb-2">Box 2</h2> |
| 56 | + <p>This is the content for box 2.</p> |
| 57 | + </div> |
| 58 | + <div class="bg-white p-6 rounded shadow"> |
| 59 | + <h2 class="text-xl font-bold mb-2">Box 3</h2> |
| 60 | + <p>This is the content for box 3.</p> |
| 61 | + </div> |
| 62 | + </div> |
| 63 | + </main> |
| 64 | + </div> |
| 65 | +
|
| 66 | + <!-- Footer --> |
| 67 | + <footer class="bg-gray-800 text-white py-4"> |
| 68 | + <div class="container mx-auto"> |
| 69 | + <p>© 2024 Your Company</p> |
| 70 | + </div> |
| 71 | + </footer> |
| 72 | +
|
| 73 | +</body> |
| 74 | +</html> |
| 75 | +``` |
| 76 | +""" |
| 77 | + |
| 78 | +import mesop as me |
| 79 | + |
| 80 | + |
| 81 | +@me.page( |
| 82 | + security_policy=me.SecurityPolicy( |
| 83 | + allowed_iframe_parents=["https://google.github.io"] |
| 84 | + ), |
| 85 | + stylesheets=[ |
| 86 | + # Specify your Tailwind CSS URL here. |
| 87 | + # |
| 88 | + # For local testing, you can just launch a basic Python HTTP server: |
| 89 | + # python -m http.server 8000 |
| 90 | + "http://localhost:8000/assets/tailwind.css", |
| 91 | + ], |
| 92 | + path="/tailwind", |
| 93 | +) |
| 94 | +def app(): |
| 95 | + with me.box(classes="min-h-screen flex flex-col"): |
| 96 | + with me.box(classes="bg-gray-800 text-white py-4"): |
| 97 | + with me.box(classes="container mx-auto"): |
| 98 | + with me.box(classes="text-2xl font-bold"): |
| 99 | + me.text("Header") |
| 100 | + |
| 101 | + with me.box(classes="flex flex-1"): |
| 102 | + with me.box(classes="w-64 bg-gray-200 p-4"): |
| 103 | + with me.box(classes="text-lg font-semibold mb-4"): |
| 104 | + me.text("Sidebar") |
| 105 | + with me.box(classes="text-gray-700 block py-2"): |
| 106 | + me.text("Link 1") |
| 107 | + with me.box(classes="text-gray-700 block py-2"): |
| 108 | + me.text("Link 2") |
| 109 | + with me.box(classes="text-gray-700 block py-2"): |
| 110 | + me.text("Link 3") |
| 111 | + |
| 112 | + with me.box(classes="flex-1 p-6 bg-gray-100"): |
| 113 | + with me.box(classes="grid grid-cols-1 md:grid-cols-3 gap-4"): |
| 114 | + with me.box(classes="bg-white p-6 rounded shadow"): |
| 115 | + with me.box(classes="text-xl font-bold mb-2"): |
| 116 | + me.text("Box 1") |
| 117 | + me.text("This is the content for box 1.") |
| 118 | + |
| 119 | + with me.box(classes="bg-white p-6 rounded shadow"): |
| 120 | + with me.box(classes="text-xl font-bold mb-2"): |
| 121 | + me.text("Box 2") |
| 122 | + me.text("This is the content for box 2") |
| 123 | + |
| 124 | + with me.box(classes="bg-white p-6 rounded shadow"): |
| 125 | + with me.box(classes="text-xl font-bold mb-2"): |
| 126 | + me.text("Box 3") |
| 127 | + me.text("This is the content for box 3") |
| 128 | + |
| 129 | + with me.box(classes="bg-gray-800 text-white py-4"): |
| 130 | + with me.box(classes="container mx-auto"): |
| 131 | + me.text("2024 Mesop") |
0 commit comments