mirror of
https://github.com/livebook-dev/livebook.git
synced 2024-12-29 19:20:46 +08:00
Add support for specifying column ratios in grid output (#2718)
Co-authored-by: Jonatan Kłosko <jonatanklosko@gmail.com>
This commit is contained in:
parent
b24f4c322e
commit
eefeb7aa6c
2 changed files with 16 additions and 2 deletions
|
@ -263,7 +263,7 @@ defprotocol Livebook.Runtime do
|
|||
@type grid_output :: %{
|
||||
type: :grid,
|
||||
outputs: list(t()),
|
||||
columns: pos_integer(),
|
||||
columns: pos_integer() | tuple(),
|
||||
gap: non_neg_integer(),
|
||||
boxed: boolean()
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ defmodule LivebookWeb.Output.GridComponent do
|
|||
<div
|
||||
id={"#{@id}-grid"}
|
||||
class="grid grid-cols-2 w-full"
|
||||
style={"grid-template-columns: repeat(#{@columns}, minmax(0, 1fr)); gap: #{@gap}px"}
|
||||
style={"grid-template-columns: #{make_template(@columns)}; gap: #{@gap}px"}
|
||||
phx-update="stream"
|
||||
>
|
||||
<div :for={{dom_id, output} <- @streams.outputs} id={dom_id}>
|
||||
|
@ -48,4 +48,18 @@ defmodule LivebookWeb.Output.GridComponent do
|
|||
</div>
|
||||
"""
|
||||
end
|
||||
|
||||
defp make_template(columns) when is_tuple(columns) do
|
||||
columns = Tuple.to_list(columns)
|
||||
|
||||
if Enum.all?(columns, &is_integer/1) do
|
||||
Enum.map_join(columns, " ", fn n -> "minmax(0, #{n}fr)" end)
|
||||
else
|
||||
""
|
||||
end
|
||||
end
|
||||
|
||||
defp make_template(columns) when is_integer(columns), do: "repeat(#{columns}, minmax(0, 1fr))"
|
||||
|
||||
defp make_template(_columns), do: ""
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue