hugobarauna commited on
Commit
2e3498a
1 Parent(s): 6a67920

Create kino_ui_widgets.livemd

Browse files
Files changed (1) hide show
  1. public-apps/kino_ui_widgets.livemd +88 -0
public-apps/kino_ui_widgets.livemd ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!-- livebook:{"app_settings":{"access_type":"public","auto_shutdown_ms":3600000,"output_type":"rich","show_source":true,"slug":"kino-widgets"}} -->
2
+
3
+ # Kino UI widgets
4
+
5
+ ```elixir
6
+ Mix.install([
7
+ {:kino, "~> 0.12.3"}
8
+ ])
9
+ ```
10
+
11
+ ## Kino.Input
12
+
13
+ ````elixir
14
+ defmodule Helpers do
15
+ def display_widget_demo("select") do
16
+ code =
17
+ quote do
18
+ Kino.Input.select("select", en: "English", fr: "Français")
19
+ end
20
+
21
+ markdown = build_code_sample("select", code)
22
+
23
+ render_input_demo(markdown, code)
24
+ end
25
+
26
+ def display_widget_demo(function_name) do
27
+ code =
28
+ quote do
29
+ Kino.Input.unquote(String.to_atom(function_name))(unquote(function_name))
30
+ end
31
+
32
+ markdown = build_code_sample(function_name, code)
33
+
34
+ render_input_demo(markdown, code)
35
+ end
36
+
37
+ defp build_code_sample(title, code) do
38
+ Kino.Markdown.new("""
39
+ ### #{title}
40
+
41
+ ```elixir
42
+ #{Macro.to_string(code)}
43
+ ```
44
+ """)
45
+ end
46
+
47
+ defp render_input_demo(code_sample_markdown, code) do
48
+ {result, _bindings} = Code.eval_quoted(code)
49
+
50
+ Kino.render(
51
+ Kino.Layout.grid([code_sample_markdown, result, Kino.HTML.new("<br/>")], boxed: true)
52
+ )
53
+
54
+ Kino.render(Kino.HTML.new("<br/>"))
55
+ end
56
+ end
57
+ ````
58
+
59
+ ```elixir
60
+ import Helpers
61
+ ```
62
+
63
+ ```elixir
64
+ Kino.Markdown.new("## Kino.input")
65
+ ```
66
+
67
+ ```elixir
68
+ kino_input_functions = ~w(
69
+ audio
70
+ checkbox
71
+ color
72
+ file
73
+ image
74
+ number
75
+ password
76
+ range
77
+ select
78
+ text
79
+ textarea
80
+ url
81
+ utc_datetime
82
+ utc_time
83
+ )
84
+
85
+ Enum.each(kino_input_functions, fn function_name ->
86
+ display_widget_demo(function_name)
87
+ end)
88
+ ```