Skip to content
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 :max_height option for Kino.Layout.grid/2 #479

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 7 additions & 2 deletions lib/kino/layout.ex
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ defmodule Kino.Layout do
* `:gap` - the amount of spacing between grid items in pixels.
Defaults to `8`

* `:max_height` - the maximum height of the grid in pixels. When
enabled, a scroll appears if the grid content exceeds the given
height

## Examples

images =
Expand All @@ -65,12 +69,13 @@ defmodule Kino.Layout do
"""
@spec grid(list(term()), keyword()) :: t()
def grid(terms, opts \\ []) when is_list(terms) do
opts = Keyword.validate!(opts, columns: 1, boxed: false, gap: 8)
opts = Keyword.validate!(opts, columns: 1, boxed: false, gap: 8, max_height: nil)

info = %{
columns: opts[:columns],
boxed: opts[:boxed],
gap: opts[:gap]
gap: opts[:gap],
max_height: opts[:max_height]
}

%Kino.Layout{type: :grid, items: terms, info: info}
Expand Down
1 change: 1 addition & 0 deletions lib/kino/render.ex
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ defimpl Kino.Render, for: Kino.Layout do
outputs: outputs,
columns: kino.info.columns,
gap: kino.info.gap,
max_height: kino.info.max_height,
boxed: kino.info.boxed
}
end
Expand Down
Loading