-
Notifications
You must be signed in to change notification settings - Fork 292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CSS class support for box component #995
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import mesop as me | ||
|
||
|
||
@me.page( | ||
security_policy=me.SecurityPolicy( | ||
allowed_iframe_parents=["https://google.github.io"] | ||
), | ||
stylesheets=[ | ||
"https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css", | ||
], | ||
path="/bootstrap", | ||
) | ||
def page(): | ||
with me.box(classes="container"): | ||
with me.box( | ||
classes="d-flex flex-wrap justify-content-between py-3 mb-4 border-bottom", | ||
): | ||
with me.box( | ||
classes="d-flex align-items-center mb-3 mb-md-0 me-md-auto link-body-emphasis text-decoration-none fs-4", | ||
): | ||
me.text("Mesop") | ||
|
||
with me.box(classes="nav nav-pills"): | ||
with me.box(classes="nav-item"): | ||
with me.box(classes="nav-link active"): | ||
me.text("Features") | ||
with me.box(classes="nav-item"): | ||
with me.box(classes="nav-link"): | ||
me.text("About") | ||
|
||
with me.box(classes="container px-4 py-5"): | ||
with me.box(classes="pb-2 border-bottom"): | ||
me.text("Columns", type="headline-5") | ||
|
||
with me.box(classes="row g-4 py-5 row-cols-1 row-cols-lg-3"): | ||
with me.box(classes="feature col"): | ||
with me.box(classes="fs-2 text-body-emphasis"): | ||
me.text("Featured title") | ||
me.text( | ||
"Paragraph of text beneath the heading to explain the heading. We'll add onto it with another sentence and probably just keep going until we run out of words." | ||
) | ||
me.link(text="Call to action", url="/#") | ||
|
||
with me.box(classes="feature col"): | ||
with me.box(classes="fs-2 text-body-emphasis"): | ||
me.text("Featured title") | ||
me.text( | ||
"Paragraph of text beneath the heading to explain the heading. We'll add onto it with another sentence and probably just keep going until we run out of words." | ||
) | ||
me.link(text="Call to action", url="/#") | ||
|
||
with me.box(classes="feature col"): | ||
with me.box(classes="fs-2 text-body-emphasis"): | ||
me.text("Featured title") | ||
me.text( | ||
"Paragraph of text beneath the heading to explain the heading. We'll add onto it with another sentence and probably just keep going until we run out of words." | ||
) | ||
me.link(text="Call to action", url="/#") | ||
|
||
with me.box( | ||
classes="d-flex flex-wrap justify-content-between align-items-center py-3 my-4 border-top" | ||
): | ||
with me.box(classes="col-md-4 mb-0 text-body-secondary"): | ||
me.text("Copyright 2024 Mesop") | ||
|
||
with me.box(classes="nav col-md-4 justify-content-end"): | ||
with me.box(classes="nav-item"): | ||
with me.box(classes="nav-link px-2 text-body-secondary"): | ||
me.text("Home") | ||
with me.box(classes="nav-item"): | ||
with me.box(classes="nav-link px-2 text-body-secondary"): | ||
me.text("Features") | ||
with me.box(classes="nav-item"): | ||
with me.box(classes="nav-link px-2 text-body-secondary"): | ||
me.text("FAQs") | ||
with me.box(classes="nav-item"): | ||
with me.box(classes="nav-link px-2 text-body-secondary"): | ||
me.text("About") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
""" | ||
Example Tailwind command: | ||
|
||
``` | ||
npx tailwindcss -i ./tailwind_input.css -o ./tailwind.css | ||
``` | ||
|
||
Example Tailwind config: | ||
|
||
``` | ||
/** @type {import('tailwindcss').Config} */ | ||
module.exports = { | ||
content: ["main.py"], | ||
theme: { | ||
extend: {}, | ||
}, | ||
plugins: [], | ||
safelist: [], | ||
}; | ||
``` | ||
|
||
Original HTML mark up: | ||
|
||
``` | ||
<html> | ||
<body class="min-h-screen flex flex-col"> | ||
|
||
<!-- Header --> | ||
<header class="bg-gray-800 text-white py-4"> | ||
<div class="container mx-auto"> | ||
<h1 class="text-2xl font-bold">Header</h1> | ||
</div> | ||
</header> | ||
|
||
<!-- Main Content with Sidebar --> | ||
<div class="flex flex-1"> | ||
<!-- Sidebar --> | ||
<aside class="w-64 bg-gray-200 p-4"> | ||
<h2 class="text-lg font-semibold mb-4">Sidebar</h2> | ||
<ul> | ||
<li><a href="#" class="text-gray-700 block py-2">Link 1</a></li> | ||
<li><a href="#" class="text-gray-700 block py-2">Link 2</a></li> | ||
<li><a href="#" class="text-gray-700 block py-2">Link 3</a></li> | ||
</ul> | ||
</aside> | ||
|
||
<!-- Main Content --> | ||
<main class="flex-1 p-6 bg-gray-100"> | ||
<div class="grid grid-cols-1 md:grid-cols-3 gap-4"> | ||
<div class="bg-white p-6 rounded shadow"> | ||
<h2 class="text-xl font-bold mb-2">Box 1</h2> | ||
<p>This is the content for box 1.</p> | ||
</div> | ||
<div class="bg-white p-6 rounded shadow"> | ||
<h2 class="text-xl font-bold mb-2">Box 2</h2> | ||
<p>This is the content for box 2.</p> | ||
</div> | ||
<div class="bg-white p-6 rounded shadow"> | ||
<h2 class="text-xl font-bold mb-2">Box 3</h2> | ||
<p>This is the content for box 3.</p> | ||
</div> | ||
</div> | ||
</main> | ||
</div> | ||
|
||
<!-- Footer --> | ||
<footer class="bg-gray-800 text-white py-4"> | ||
<div class="container mx-auto"> | ||
<p>© 2024 Your Company</p> | ||
</div> | ||
</footer> | ||
|
||
</body> | ||
</html> | ||
``` | ||
""" | ||
|
||
import mesop as me | ||
|
||
|
||
@me.page( | ||
security_policy=me.SecurityPolicy( | ||
allowed_iframe_parents=["https://google.github.io"] | ||
), | ||
stylesheets=[ | ||
# Specify your Tailwind CSS URL here. | ||
# | ||
# For local testing, you can just launch a basic Python HTTP server: | ||
# python -m http.server 8000 | ||
"http://localhost:8000/assets/tailwind.css", | ||
], | ||
path="/tailwind", | ||
) | ||
def app(): | ||
with me.box(classes="min-h-screen flex flex-col"): | ||
with me.box(classes="bg-gray-800 text-white py-4"): | ||
with me.box(classes="container mx-auto"): | ||
with me.box(classes="text-2xl font-bold"): | ||
me.text("Header") | ||
|
||
with me.box(classes="flex flex-1"): | ||
with me.box(classes="w-64 bg-gray-200 p-4"): | ||
with me.box(classes="text-lg font-semibold mb-4"): | ||
me.text("Sidebar") | ||
with me.box(classes="text-gray-700 block py-2"): | ||
me.text("Link 1") | ||
with me.box(classes="text-gray-700 block py-2"): | ||
me.text("Link 2") | ||
with me.box(classes="text-gray-700 block py-2"): | ||
me.text("Link 3") | ||
|
||
with me.box(classes="flex-1 p-6 bg-gray-100"): | ||
with me.box(classes="grid grid-cols-1 md:grid-cols-3 gap-4"): | ||
with me.box(classes="bg-white p-6 rounded shadow"): | ||
with me.box(classes="text-xl font-bold mb-2"): | ||
me.text("Box 1") | ||
me.text("This is the content for box 1.") | ||
|
||
with me.box(classes="bg-white p-6 rounded shadow"): | ||
with me.box(classes="text-xl font-bold mb-2"): | ||
me.text("Box 2") | ||
me.text("This is the content for box 2") | ||
|
||
with me.box(classes="bg-white p-6 rounded shadow"): | ||
with me.box(classes="text-xl font-bold mb-2"): | ||
me.text("Box 3") | ||
me.text("This is the content for box 3") | ||
|
||
with me.box(classes="bg-gray-800 text-white py-4"): | ||
with me.box(classes="container mx-auto"): | ||
me.text("2024 Mesop") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
--default-bottom-panel-height: 400px; | ||
} | ||
|
||
.container { | ||
.me-container { | ||
height: 100%; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
.container { | ||
.me-container { | ||
height: 100%; | ||
} | ||
|
||
.content { | ||
.me-content { | ||
overflow: hidden; | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why does it need to be inline?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a great question. I wasn't quite able to figure that out. But when I looked at the generated markup, that first component-renderer box element does not have display block by default on main branch (which is definitely strange since in component renderer ts code, in the main branch, it should set the style to display block, at least that's what I would have thought).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I just remembered, I think it's because the first element isn't actually a box component, the root component is a special synthetic component that IIRC doesn't actually have a component type (the purpose of it is that sometimes you may have multiple top-level components under a page fn, so we want to treat it as a tree with the synthetic node). Maybe we should have it be a box component just to be more consistent? (I'm not sure if you noticed anything broke when switching from block to inline), but that can be a future change. this PR LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I noticed this because some things definitely broke when I changed it to display block. I think the primary issue occurred in the chat apps where the full height stuff wasn't working. So seems like something that could be adjusted.