Skip to content

Commit

Permalink
Add :max_height option for Kino.Layout.grid/2 (#479)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatanklosko authored Oct 31, 2024
1 parent 8f96f76 commit 05d7da7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
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
4 changes: 2 additions & 2 deletions lib/kino/proxy.ex
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ defmodule Kino.Proxy do
Plug.Conn.send_resp(conn, 200, "hello world!")
end
end
Kino.Proxy.listen(MyPlug)
Or a more complex example, using `Plug.Router` to handle multiple endpoints:
defmodule ApiRouter do
use Plug.Router
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

0 comments on commit 05d7da7

Please sign in to comment.