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(@internal Attribute(@internal Aligned, msg)),
content: @internal Element(msg),
)
HiddenLabel(text: String)
}
Constructors
-
Label( location: LabelLocation, attrs: List(@internal Attribute(@internal Aligned, msg)), content: @internal 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(@internal Attribute(@internal Aligned, msg)),
content: @internal Element(msg),
)
}
Constructors
-
Placeholder( attrs: List(@internal Attribute(@internal Aligned, msg)), content: @internal Element(msg), )
pub type RadioOption(value, msg) {
RadioOption(
value: value,
view: fn(OptionState) -> @internal Element(msg),
)
}
Constructors
-
RadioOption( value: value, view: fn(OptionState) -> @internal 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), )
Values
pub fn button(
attrs: List(@internal Attribute(@internal Aligned, msg)),
on_press on_press: option.Option(msg),
label label: @internal Element(msg),
) -> @internal Element(msg)
Create a button element
pub fn checkbox(
attrs: List(@internal Attribute(@internal Aligned, msg)),
on_change on_change: fn(Bool) -> msg,
icon icon: fn(Bool) -> @internal Element(msg),
checked checked: Bool,
label label: Label(msg),
) -> @internal Element(msg)
Create a checkbox input
pub fn current_password(
attrs: List(@internal Attribute(@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,
) -> @internal Element(msg)
Create a current password input
pub fn default_checkbox(checked: Bool) -> @internal Element(msg)
pub fn email(
attrs: List(@internal Attribute(@internal Aligned, msg)),
on_change on_change: fn(String) -> msg,
text text: String,
placeholder placeholder: option.Option(Placeholder(msg)),
label label: Label(msg),
) -> @internal Element(msg)
Create an email input
pub fn focused_on_load() -> @internal Attribute(
@internal Aligned,
msg,
)
Set an element to be focused when the page loads
pub fn label_above(
attrs: List(@internal Attribute(@internal Aligned, msg)),
content: @internal Element(msg),
) -> Label(msg)
Create a label positioned above
pub fn label_below(
attrs: List(@internal Attribute(@internal Aligned, msg)),
content: @internal 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(@internal Attribute(@internal Aligned, msg)),
content: @internal Element(msg),
) -> Label(msg)
Create a label positioned to the left
pub fn label_right(
attrs: List(@internal Attribute(@internal Aligned, msg)),
content: @internal Element(msg),
) -> Label(msg)
Create a label positioned to the right
pub fn multiline(
attrs: List(@internal Attribute(@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,
) -> @internal Element(msg)
Create a multiline text input (textarea)
pub fn new_password(
attrs: List(@internal Attribute(@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,
) -> @internal Element(msg)
Create a new password input
pub fn option(
value: value,
content: @internal Element(msg),
) -> RadioOption(value, msg)
Create a radio option with default styling
pub fn option_with(
value: value,
view: fn(OptionState) -> @internal Element(msg),
) -> RadioOption(value, msg)
Create a radio option with custom styling
pub fn placeholder(
attrs: List(@internal Attribute(@internal Aligned, msg)),
content: @internal Element(msg),
) -> Placeholder(msg)
Create a placeholder for text inputs
pub fn radio(
attrs: List(@internal Attribute(@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),
) -> @internal Element(msg)
Create a radio button group (column layout)
pub fn radio_row(
attrs: List(@internal Attribute(@internal Aligned, msg)),
on_change: fn(option) -> msg,
options: List(RadioOption(option, msg)),
selected: option.Option(option),
label: Label(msg),
) -> @internal Element(msg)
Create a radio button group (row layout)
pub fn search(
attrs: List(@internal Attribute(@internal Aligned, msg)),
on_change on_change: fn(String) -> msg,
text text: String,
placeholder placeholder: option.Option(Placeholder(msg)),
label label: Label(msg),
) -> @internal Element(msg)
Create a search input
pub fn slider(
attributes: List(@internal Attribute(@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),
) -> @internal 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 fill
andwidth (px someWidth)
will cause the slider to be vertical.height (px someHeight)
andwidth (px someWidth)
wheresomeHeight
>someWidth
will also do it.- otherwise, the slider will be horizontal.
Note If you want a slider for an Int
value:
- set
step
to 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(@internal Attribute(@internal Aligned, msg)),
on_change on_change: fn(String) -> msg,
text text: String,
placeholder placeholder: option.Option(Placeholder(msg)),
label label: Label(msg),
) -> @internal Element(msg)
Create a spell-checked text input
pub fn text_input(
attrs: List(@internal Attribute(@internal Aligned, msg)),
on_change on_change: fn(String) -> msg,
text text: String,
placeholder placeholder: option.Option(Placeholder(msg)),
label label: Label(msg),
) -> @internal Element(msg)
Create a basic text input
pub fn thumb(
attrs: List(@internal Attribute(@internal Aligned, a)),
) -> Thumb(a)
Create a slider thumb
pub fn username(
attrs: List(@internal Attribute(@internal Aligned, msg)),
on_change on_change: fn(String) -> msg,
text text: String,
placeholder placeholder: option.Option(Placeholder(msg)),
label label: Label(msg),
) -> @internal Element(msg)
Create a username input