-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5f3f594
commit d62b3cc
Showing
12 changed files
with
203 additions
and
52 deletions.
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,21 @@ | ||
# Viewport size | ||
|
||
## Overview | ||
|
||
Viewport size enables you to create responsive or size-specific UIs. | ||
|
||
## Examples | ||
|
||
### Different styles | ||
|
||
... | ||
|
||
### Different layout | ||
|
||
... | ||
|
||
## API | ||
|
||
::: mesop.features.viewport_size.viewport_size | ||
|
||
::: mesop.features.viewport_size.Size |
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,8 @@ | ||
import mesop as me | ||
|
||
|
||
@me.page(path="/viewport_size") | ||
def app(): | ||
me.text( | ||
f"viewport_size width={me.viewport_size().width} height={me.viewport_size().height}" | ||
) |
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,34 @@ | ||
from dataclasses import dataclass | ||
|
||
from mesop.runtime import runtime | ||
|
||
|
||
@dataclass(kw_only=True) | ||
class Size: | ||
""" | ||
This class represents the size of the viewport. | ||
Attributes: | ||
width: The width of the viewport in pixels. | ||
height: The height of the viewport in pixels. | ||
""" | ||
|
||
width: int | ||
height: int | ||
|
||
|
||
def viewport_size() -> Size: | ||
""" | ||
This function returns the current viewport size. | ||
The viewport size is an object of the class Size, which has two properties: width and height. | ||
These properties represent the current width and height of the viewport in pixels. | ||
Returns: | ||
Size: An object of class Size representing the current viewport size. | ||
""" | ||
pb_size = runtime().context().viewport_size() | ||
return Size( | ||
width=pb_size.width, | ||
height=pb_size.height, | ||
) |
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,15 @@ | ||
import {test, expect} from '@playwright/test'; | ||
|
||
test('viewport_size', async ({page}) => { | ||
await page.goto('/viewport_size'); | ||
await page.setViewportSize({width: 400, height: 300}); | ||
// For the following assertions, make sure the width has updated so that | ||
// there isn't a race condition. | ||
expect(await page.getByText('viewport_size width=400').textContent()).toEqual( | ||
'viewport_size width=400 height=300', | ||
); | ||
await page.setViewportSize({width: 500, height: 200}); | ||
expect(await page.getByText('viewport_size width=500').textContent()).toEqual( | ||
'viewport_size width=500 height=200', | ||
); | ||
}); |
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,8 @@ | ||
import {ViewportSize} from 'mesop/mesop/protos/ui_jspb_proto_pb/mesop/protos/ui_pb'; | ||
|
||
export function getViewportSize(): ViewportSize { | ||
const viewportSize = new ViewportSize(); | ||
viewportSize.setWidth(window.innerWidth); | ||
viewportSize.setHeight(window.innerHeight); | ||
return viewportSize; | ||
} |