1. Home
  2. /
  3. Elm-ui
  4. /
  5. Elm UI Counter with Step

Elm UI Counter with Step - Elm-ui Typing CST Test

Loading…

Elm UI Counter with Step — Elm-ui Code

A counter that increases or decreases by a specified step.

module Main exposing (main)

import Browser
import Element exposing (..)
import Element.Events exposing (onClick)

-- MODEL

type alias Model =
	{ count : Int, step : Int }

initialModel : Model
initialModel =
	{ count = 0, step = 5 }

-- UPDATE

type Msg = Increment | Decrement

update : Msg -> Model -> Model
update msg model =
	case msg of
		Increment -> { model | count = model.count + model.step }
		Decrement -> { model | count = model.count - model.step }

-- VIEW

view : Model -> Element Msg
view model =
	column [ spacing 10, padding 20, alignCenter ]
		[ text ("Count: " ++ String.fromInt model.count)
		, row [ spacing 10 ]
		[ button [ onClick Increment ] (text "+")
		, button [ onClick Decrement ] (text "-")
		]
		]

-- MAIN

main = Browser.sandbox { init = initialModel, update = update, view = view }

Elm-ui Language Guide

Elm UI is a library for building web interfaces in Elm, focusing on layout and styling in a declarative, type-safe way without relying on CSS.

Primary Use Cases

  • ▸Building web interfaces in Elm
  • ▸Creating responsive layouts without CSS
  • ▸Developing reusable UI components
  • ▸Prototyping web app designs quickly
  • ▸Type-safe styling and spacing

Notable Features

  • ▸Declarative layout syntax
  • ▸Completely typed in Elm
  • ▸Composable UI boxes
  • ▸Supports responsive and flexible layouts
  • ▸Eliminates manual CSS for many tasks

Origin & Creator

Elm UI was created by the Elm community, with Evan Czaplicki (creator of Elm) influencing its design for declarative UI patterns.

Industrial Note

Elm UI is used primarily in Elm applications to replace CSS for layout management, providing strong type safety and predictable UI behavior.

More Elm-ui Typing Exercises

Elm UI Counter ExampleElm UI Hello WorldElm UI Button Click ExampleElm UI Toggle ExampleElm UI Input ExampleElm UI Color Box ExampleElm UI Progress ExampleElm UI List Example

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher