Skip to content

Commit

Permalink
Support toggling smart cell editor visibility (#467)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatanklosko authored Aug 25, 2024
1 parent 37af142 commit 5e3e9b1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/kino/js/live/context.ex
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ defmodule Kino.JS.Live.Context do
## Options
* `:editor` - note that the smart cell must be initialized with an
editor during on init. Supported options: `:source`, `:intellisense_node`.
editor during init. Supported options: `:source`, `:intellisense_node`,
`:visible`
"""
@spec reconfigure_smart_cell(t(), keyword()) :: t()
Expand Down
5 changes: 5 additions & 0 deletions lib/kino/smart_cell.ex
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ defmodule Kino.SmartCell do
This is only applicable when `:language` is Elixir. Defaults to
`nil`
* `:visible` - whether the editor is shown. Altering this option
with `Kino.JS.Live.Context.reconfigure_smart_cell/2` allows the
editor to be shown or hidden, depending on the smart cell state.
Defaults to `true`
Note that you can programmatically reconfigure some of these options
later using `Kino.JS.Live.Context.reconfigure_smart_cell/2`.
Expand Down
8 changes: 5 additions & 3 deletions lib/kino/smart_cell/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ defmodule Kino.SmartCell.Server do
source: editor_opts[:source] || legacy_source,
language: editor_opts[:language],
placement: editor_opts[:placement],
intellisense_node: editor_opts[:intellisense_node]
intellisense_node: editor_opts[:intellisense_node],
visible: editor_opts[:visible]
}
end

Expand Down Expand Up @@ -61,7 +62,7 @@ defmodule Kino.SmartCell.Server do
" Make sure to enable smart cell editor during init"
end

Keyword.validate!(editor_opts, [:source, :intellisense_node])
Keyword.validate!(editor_opts, [:source, :intellisense_node, :visible])
end

put_in(ctx.__private__.smart_cell[:reconfigure_options], opts)
Expand Down Expand Up @@ -138,7 +139,8 @@ defmodule Kino.SmartCell.Server do
language: nil,
intellisense_node: nil,
placement: :bottom,
default_source: ""
default_source: "",
visible: true
])

unless editor_opts[:placement] in [:top, :bottom] do
Expand Down

0 comments on commit 5e3e9b1

Please sign in to comment.