View Source Kino.Input (Kino v0.8.0)
Various input elements for entering data.
examples
Examples
First, create an input and make sure it is rendered,
either by placing it at the end of a code cell or by
explicitly rendering it with Kino.render/1
.
input = Kino.Input.text("Name")
Then read the value at any later point:
name = Kino.Input.read(input)
async-api
Async API
You can subscribe to input changes or use the Stream
API for event feed. See the Kino.Control
module for
more details.
Link to this section Summary
Functions
Creates a new checkbox.
Creates a new color input.
Creates a new image input.
Creates a new number input.
Creates a new password input.
Creates a new slider input.
Synchronously reads the current input value.
Creates a new select input.
Creates a new text input.
Creates a new multiline text input.
Creates a new URL input.
Link to this section Types
@opaque t()
Link to this section Functions
Creates a new checkbox.
The input value can be either true
or false
.
options
Options
:default
- the initial input value. Defaults tofalse
Creates a new color input.
The input value can be a hex color string.
options
Options
:default
- the initial input value. Defaults to#6583FF
Creates a new image input.
The input value is a map, with the image binary and metadata:
%{
data: binary(),
height: pos_integer(),
width: pos_integer(),
format: :rgb | :png | :jpeg
}
Note that the value can also be nil
, if no image is selected.
options
Options
:format
- the format to read the image as, either of::rgb
(default) - the binary includes raw pixel values, each encoded as a single byte in the HWC order. Such binary can be directly converted to anNx
tensor, with no additional decoding:png
:jpeg
(or:jpg
)
:size
- the size to fit the image into, given as{height, width}
:fit
- the strategy of fitting the image into:size
, either of::contain
(default) - resizes the image, such that it fits in a box of:size
, but preserving the aspect ratio. The resulting image can be smaller or equal to:size
:match
- resizes the image to:size
, with no respect for aspect ratio:pad
- same as:contain
, but pads the image to match:size
exactly:crop
- resizes the image, such that one edge fits in:size
and the other overflows, then center-crops the image to match:size
exactly
Creates a new number input.
The input value is can be either a number or nil
.
options
Options
:default
- the initial input value. Defaults tonil
Creates a new password input.
This is similar to text input, except the content is not visible by default.
options
Options
:default
- the initial input value. Defaults to""
Creates a new slider input.
The input value can be either float in the configured range.
options
Options
:default
- the initial input value. Defaults to the minimum value:min
- the minimum value:max
- the maximum value:step
- the slider increment
Synchronously reads the current input value.
Note that to retrieve the value, the input must be rendered first, otherwise an error is raised.
examples
Examples
input = Kino.Input.text("Name")
Kino.Input.read(input)
Creates a new select input.
The input expects a list of options in the form [{value, label}]
,
where value
is an arbitrary term and label
is a descriptive
string.
options
Options
:default
- the initial input value. Defaults to the first value from the given list of options
examples
Examples
Kino.Input.select("Language", [en: "English", fr: "Français"])
Kino.Input.select("Language", [{1, "One"}, {2, "Two"}, {3, "Three"}])
Creates a new text input.
options
Options
:default
- the initial input value. Defaults to""
Creates a new multiline text input.
options
Options
:default
- the initial input value. Defaults to""
Creates a new URL input.
The input value can be either a valid URL string or nil
.
options
Options
:default
- the initial input value. Defaults tonil