legos/input
Types
pub type Box {
Box(bottom: Int, left: Int, right: Int, top: Int)
}
Constructors
-
Box(bottom: Int, left: Int, right: Int, top: Int)
pub type Label(msg) {
Label(
location: LabelLocation,
attrs: List(ui.Decoration(@internal Aligned, msg)),
content: ui.Element(msg),
)
HiddenLabel(text: String)
}
Constructors
-
Label( location: LabelLocation, attrs: List(ui.Decoration(@internal Aligned, msg)), content: ui.Element(msg), ) -
HiddenLabel(text: String)
pub type LabelLocation {
OnRight
OnLeft
Above
Below
}
Constructors
-
OnRight -
OnLeft -
Above -
Below
pub type OptionState {
Idle
Focused
Selected
}
Constructors
-
Idle -
Focused -
Selected
pub type Placeholder(msg) {
Placeholder(
attrs: List(ui.Decoration(@internal Aligned, msg)),
content: ui.Element(msg),
)
}
Constructors
-
Placeholder( attrs: List(ui.Decoration(@internal Aligned, msg)), content: ui.Element(msg), )
pub type RadioOption(value, msg) {
RadioOption(
value: value,
view: fn(OptionState) -> ui.Element(msg),
)
}
Constructors
-
RadioOption( value: value, view: fn(OptionState) -> ui.Element(msg), )
pub type TextConfig(msg) {
TextConfig(
on_change: fn(String) -> msg,
text: String,
placeholder: option.Option(Placeholder(msg)),
label: Label(msg),
)
}
Constructors
-
TextConfig( on_change: fn(String) -> msg, text: String, placeholder: option.Option(Placeholder(msg)), label: Label(msg), )
pub type Thumb(a) {
Thumb(attrs: List(ui.Decoration(@internal Aligned, a)))
}
Constructors
-
Thumb(attrs: List(ui.Decoration(@internal Aligned, a)))
Values
pub fn button(
attrs: List(ui.Decoration(@internal Aligned, msg)),
on_press on_press: option.Option(msg),
label label: ui.Element(msg),
) -> ui.Element(msg)
Create a button element
pub fn checkbox(
attrs: List(ui.Decoration(@internal Aligned, msg)),
on_change on_change: fn(Bool) -> msg,
icon icon: fn(Bool) -> ui.Element(msg),
checked checked: Bool,
label label: Label(msg),
) -> ui.Element(msg)
Create a checkbox input
pub fn current_password(
attrs: List(ui.Decoration(@internal Aligned, msg)),
on_change on_change: fn(String) -> msg,
text text_val: String,
placeholder placeholder_val: option.Option(Placeholder(msg)),
label label_val: Label(msg),
show show: Bool,
) -> ui.Element(msg)
Create a current password input
pub fn default_checkbox(checked: Bool) -> ui.Element(msg)
pub fn email(
attrs: List(ui.Decoration(@internal Aligned, msg)),
on_change on_change: fn(String) -> msg,
text text: String,
placeholder placeholder: option.Option(Placeholder(msg)),
label label: Label(msg),
) -> ui.Element(msg)
Create an email input
pub fn focused_on_load() -> ui.Decoration(@internal Aligned, msg)
Set an element to be focused when the page loads
pub fn label_above(
attrs: List(ui.Decoration(@internal Aligned, msg)),
content: ui.Element(msg),
) -> Label(msg)
Create a label positioned above
pub fn label_below(
attrs: List(ui.Decoration(@internal Aligned, msg)),
content: ui.Element(msg),
) -> Label(msg)
Create a label positioned below
pub fn label_hidden(text: String) -> Label(msg)
Create a hidden label for accessibility (screen readers only)
pub fn label_left(
attrs: List(ui.Decoration(@internal Aligned, msg)),
content: ui.Element(msg),
) -> Label(msg)
Create a label positioned to the left
pub fn label_right(
attrs: List(ui.Decoration(@internal Aligned, msg)),
content: ui.Element(msg),
) -> Label(msg)
Create a label positioned to the right
pub fn multiline(
attrs: List(ui.Decoration(@internal Aligned, msg)),
on_change on_change: fn(String) -> msg,
text text_val: String,
placeholder placeholder_val: option.Option(Placeholder(msg)),
label label_val: Label(msg),
spellcheck spellcheck_val: Bool,
) -> ui.Element(msg)
Create a multiline text input (textarea)
pub fn new_password(
attrs: List(ui.Decoration(@internal Aligned, msg)),
on_change on_change: fn(String) -> msg,
text text_val: String,
placeholder placeholder_val: option.Option(Placeholder(msg)),
label label_val: Label(msg),
show show: Bool,
) -> ui.Element(msg)
Create a new password input
pub fn option(
value: value,
content: ui.Element(msg),
) -> RadioOption(value, msg)
Create a radio option with default styling
pub fn option_with(
value: value,
view: fn(OptionState) -> ui.Element(msg),
) -> RadioOption(value, msg)
Create a radio option with custom styling
pub fn placeholder(
attrs: List(ui.Decoration(@internal Aligned, msg)),
content: ui.Element(msg),
) -> Placeholder(msg)
Create a placeholder for text inputs
pub fn radio(
attrs: List(ui.Decoration(@internal Aligned, msg)),
on_change on_change: fn(option) -> msg,
options options: List(RadioOption(option, msg)),
selected selected: option.Option(option),
label label: Label(msg),
) -> ui.Element(msg)
Create a radio button group (column layout)
pub fn radio_row(
attrs: List(ui.Decoration(@internal Aligned, msg)),
on_change: fn(option) -> msg,
options: List(RadioOption(option, msg)),
selected: option.Option(option),
label: Label(msg),
) -> ui.Element(msg)
Create a radio button group (row layout)
pub fn search(
attrs: List(ui.Decoration(@internal Aligned, msg)),
on_change on_change: fn(String) -> msg,
text text: String,
placeholder placeholder: option.Option(Placeholder(msg)),
label label: Label(msg),
) -> ui.Element(msg)
Create a search input
pub fn slider(
attributes: List(ui.Decoration(@internal Aligned, msg)),
on_change on_change: fn(Float) -> msg,
label label_val: Label(msg),
min min: Float,
max max: Float,
value value: Float,
thumb thumb: Thumb(msg),
step step: option.Option(Float),
) -> ui.Element(msg)
A slider input, good for capturing float values.
Input.slider [ Element.height (Element.px 30)
– Here is where we’re creating/styling the “track” , Element.behindContent (Element.el [ Element.width Element.fill , Element.height (Element.px 2) , Element.centerY , Background.color grey , Border.rounded 2 ] Element.none ) ] { on_change = AdjustValue , label = Input.labelAbove [] (text “My Slider Value”) , min = 0 , max = 75 , step = Nothing , value = model.sliderValue , thumb = Input.defaultThumb }
Element.behindContent is used to render the track of the slider. Without it, no track would be rendered. The thumb is the icon that you can move around.
The slider can be vertical or horizontal depending on the width/height of the slider.
height fillandwidth (px someWidth)will cause the slider to be vertical.height (px someHeight)andwidth (px someWidth)wheresomeHeight>someWidthwill also do it.- otherwise, the slider will be horizontal.
Note If you want a slider for an Int value:
- set
stepto beJust 1, or some other whole value value = toFloat model.myInt- And finally, round the value before making a message
on_change = round >> AdjustValue
pub fn spell_checked(
attrs: List(ui.Decoration(@internal Aligned, msg)),
on_change on_change: fn(String) -> msg,
text text: String,
placeholder placeholder: option.Option(Placeholder(msg)),
label label: Label(msg),
) -> ui.Element(msg)
Create a spell-checked text input
pub fn text_input(
attrs: List(ui.Decoration(@internal Aligned, msg)),
on_change on_change: fn(String) -> msg,
text text: String,
placeholder placeholder: option.Option(Placeholder(msg)),
label label: Label(msg),
) -> ui.Element(msg)
Create a basic text input
pub fn thumb(
attrs: List(ui.Decoration(@internal Aligned, a)),
) -> Thumb(a)
Create a slider thumb
pub fn username(
attrs: List(ui.Decoration(@internal Aligned, msg)),
on_change on_change: fn(String) -> msg,
text text: String,
placeholder placeholder: option.Option(Placeholder(msg)),
label label: Label(msg),
) -> ui.Element(msg)
Create a username input