Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 27 additions & 23 deletions e2e_playwright/st_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@

from __future__ import annotations

from typing import TYPE_CHECKING, cast

import numpy as np
import numpy.typing as npt

import streamlit as st

if TYPE_CHECKING:
from streamlit.elements.lib.layout_utils import Gap

LOREM_IPSUM = (
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor "
"incididunt ut labore et dolore magna aliqua."
Expand Down Expand Up @@ -53,29 +58,28 @@
c.image(BLACK_IMG)

# Various column gaps
with st.expander("Column gap small", expanded=True):
c4, c5, c6 = st.columns(3, gap="small")
c4.image(BLACK_IMG)
c5.image(BLACK_IMG)
c6.image(BLACK_IMG)

with st.expander("Column gap medium", expanded=True):
c7, c8, c9 = st.columns(3, gap="medium")
c7.image(BLACK_IMG)
c8.image(BLACK_IMG)
c9.image(BLACK_IMG)

with st.expander("Column gap large", expanded=True):
c10, c11, c12 = st.columns(3, gap="large")
c10.image(BLACK_IMG)
c11.image(BLACK_IMG)
c12.image(BLACK_IMG)

with st.expander("Column gap none", expanded=True):
c13, c14, c15 = st.columns(3, gap=None)
c13.image(BLACK_IMG)
c14.image(BLACK_IMG)
c15.image(BLACK_IMG)

GAPS = cast(
"list[Gap|None]",
[
None,
"xxsmall",
"xsmall",
"small",
"medium",
"large",
"xlarge",
"xxlarge",
],
)

for gap in GAPS:
gap_name = str(gap).lower()

with st.expander(f"Column gap {gap_name}", expanded=True):
cols = st.columns(3, gap=gap)
for col in cols:
col.image(BLACK_IMG)

with st.expander("Nested columns - one level", expanded=True):
col1, col2 = st.columns(2)
Expand Down
76 changes: 26 additions & 50 deletions e2e_playwright/st_columns_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,58 +65,34 @@ def test_columns_with_border(app: Page, assert_snapshot: ImageCompareFunction):
assert_snapshot(column_container, name="st_columns-with_border")


def test_column_gap_small_is_correctly_applied(
def test_column_gap_is_correctly_applied(
app: Page, assert_snapshot: ImageCompareFunction
):
"""Test that the small column gap is correctly applied."""
column_gap_small = (
get_expander(app, "Column gap small").get_by_test_id("stHorizontalBlock").nth(0)
)
# We use regex here since some browsers may resolve this to two numbers:
expect(column_gap_small).to_have_css("gap", re.compile("16px"))
column_gap_small.scroll_into_view_if_needed()
assert_snapshot(column_gap_small, name="st_columns-column_gap_small")


def test_column_gap_medium_is_correctly_applied(
app: Page, assert_snapshot: ImageCompareFunction
):
"""Test that the medium column gap is correctly applied."""
column_gap_medium = (
get_expander(app, "Column gap medium")
.get_by_test_id("stHorizontalBlock")
.nth(0)
)
# We use regex here since some browsers may resolve this to two numbers:
expect(column_gap_medium).to_have_css("gap", re.compile("32px"))
column_gap_medium.scroll_into_view_if_needed()
assert_snapshot(column_gap_medium, name="st_columns-column_gap_medium")


def test_column_gap_large_is_correctly_applied(
app: Page, assert_snapshot: ImageCompareFunction
):
"""Test that the large column gap is correctly applied."""
column_gap_large = (
get_expander(app, "Column gap large").get_by_test_id("stHorizontalBlock").nth(0)
)
# We use regex here since some browsers may resolve this to two numbers:
expect(column_gap_large).to_have_css("gap", re.compile("64px"))
column_gap_large.scroll_into_view_if_needed()
assert_snapshot(column_gap_large, name="st_columns-column_gap_large")


def test_column_gap_none_is_correctly_applied(
app: Page, assert_snapshot: ImageCompareFunction
):
"""Test that the none column gap is correctly applied."""
column_gap_none = (
get_expander(app, "Column gap none").get_by_test_id("stHorizontalBlock").nth(0)
)
# We use regex here since some browsers may resolve this to two numbers:
expect(column_gap_none).to_have_css("gap", re.compile("0px"))
column_gap_none.scroll_into_view_if_needed()
assert_snapshot(column_gap_none, name="st_columns-column_gap_none")
"""Test that the different-sized column gaps are correctly applied."""

gaps = [
(None, "0"),
("xxsmall", "4px"),
("xsmall", "8px"),
("small", "16px"),
("medium", "32px"),
("large", "64px"),
("xlarge", "96px"),
("xxlarge", "128px"),
]

for gap, gap_value in gaps:
gap_name = str(gap).lower()

column_gap = (
get_expander(app, f"Column gap {gap_name}")
.get_by_test_id("stHorizontalBlock")
.nth(0)
)
# We use regex here since some browsers may resolve this to two numbers:
expect(column_gap).to_have_css("gap", re.compile(gap_value))
column_gap.scroll_into_view_if_needed()
assert_snapshot(column_gap, name=f"st_columns-column_gap_{gap_name}")


def test_one_level_nesting_works_correctly(
Expand Down
211 changes: 62 additions & 149 deletions e2e_playwright/st_layouts_container_gap_size.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,160 +12,73 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import streamlit as st
from __future__ import annotations

with st.container(
border=True,
gap="small",
horizontal=True,
key="container-horizontal-gap-small",
):
st.html(
'<div style="background:lightblue">One</div>',
width="stretch",
)
st.html(
'<div style="background:lightblue">Two</div>',
width="stretch",
)
st.html(
'<div style="background:lightblue">Three</div>',
width="stretch",
)
st.html(
'<div style="background:lightblue">Four</div>',
width="stretch",
)
from typing import TYPE_CHECKING, cast

with st.container(
border=True,
gap="medium",
horizontal=True,
key="container-horizontal-gap-medium",
):
st.html(
'<div style="background:lightblue">One</div>',
width="stretch",
)
st.html(
'<div style="background:lightblue">Two</div>',
width="stretch",
)
st.html(
'<div style="background:lightblue">Three</div>',
width="stretch",
)
st.html(
'<div style="background:lightblue">Four</div>',
width="stretch",
)
import streamlit as st

with st.container(
border=True,
gap="large",
horizontal=True,
key="container-horizontal-gap-large",
):
st.html(
'<div style="background:lightblue">One</div>',
width="stretch",
)
st.html(
'<div style="background:lightblue">Two</div>',
width="stretch",
)
st.html(
'<div style="background:lightblue">Three</div>',
width="stretch",
)
st.html(
'<div style="background:lightblue">Four</div>',
width="stretch",
)
if TYPE_CHECKING:
from streamlit.elements.lib.layout_utils import Gap

with st.container(
border=True,
gap=None,
horizontal=True,
key="container-horizontal-gap-none",
):
st.html(
'<div style="background:lightblue">One</div>',
width="stretch",
)
st.html(
'<div style="background:lightblue">Two</div>',
width="stretch",
)
st.html(
'<div style="background:lightblue">Three</div>',
width="stretch",
)
st.html(
'<div style="background:lightblue">Four</div>',
width="stretch",
)
GAPS = cast(
"list[Gap | None]",
[
None,
"xxsmall",
"xsmall",
"small",
"medium",
"large",
"xlarge",
"xxlarge",
],
)

with st.container(
border=True, gap="small", horizontal=False, key="container-vertical-gap-small"
):
st.html(
'<div style="background:lightblue">One</div>',
width="stretch",
)
st.html(
'<div style="background:lightblue">Two</div>',
width="stretch",
)
st.html(
'<div style="background:lightblue">Three</div>',
width="stretch",
)
for gap in GAPS:
gap_name = str(gap).lower()

with st.container(
border=True, gap="medium", horizontal=False, key="container-vertical-gap-medium"
):
st.html(
'<div style="background:lightblue">One</div>',
width="stretch",
)
st.html(
'<div style="background:lightblue">Two</div>',
width="stretch",
)
st.html(
'<div style="background:lightblue">Three</div>',
width="stretch",
)
with st.container(
border=True,
gap=gap,
horizontal=True,
key=f"container-horizontal-gap-{gap_name}",
):
st.html(
'<div style="background:lightblue">One</div>',
width="stretch",
)
st.html(
'<div style="background:lightblue">Two</div>',
width="stretch",
)
st.html(
'<div style="background:lightblue">Three</div>',
width="stretch",
)
st.html(
'<div style="background:lightblue">Four</div>',
width="stretch",
)

with st.container(
border=True, gap="large", horizontal=False, key="container-vertical-gap-large"
):
st.html(
'<div style="background:lightblue">One</div>',
width="stretch",
)
st.html(
'<div style="background:lightblue">Two</div>',
width="stretch",
)
st.html(
'<div style="background:lightblue">Three</div>',
width="stretch",
)
for gap in GAPS:
gap_name = str(gap).lower()

with st.container(
border=True, gap=None, horizontal=False, key="container-vertical-gap-none"
):
st.html(
'<div style="background:lightblue">One</div>',
width="stretch",
)
st.html(
'<div style="background:lightblue">Two</div>',
width="stretch",
)
st.html(
'<div style="background:lightblue">Three</div>',
width="stretch",
)
with st.container(
border=True,
gap=gap,
horizontal=False,
key=f"container-vertical-gap-{gap_name}",
):
st.html(
'<div style="background:lightblue">One</div>',
width="stretch",
)
st.html(
'<div style="background:lightblue">Two</div>',
width="stretch",
)
st.html(
'<div style="background:lightblue">Three</div>',
width="stretch",
)
Loading
Loading