Widgets

/

interact

Button

An accessible button. .fnc(...) runs on activation (click, Enter, Space). Unstyled except .preset(default).

A counter

Button is an accessible button: .fnc { … } runs when it is clicked, tapped, or pressed with Enter or Space. It is unstyled; style it like a Container, or start from .preset(default). Every Button gives a little when pressed.

LAYROpen in playground
Page(
  .name(Counter)
  .route('/')
  var int count = 0
  Scaffold(
    .config(color: canvas)
    .body(
      Row(
        .config(gap: 12, padding: all(24), yAlign: mid)
        Button(
          .config(color: accent, cornerRadius: 10, padding: sym(x: 18, y: 10))
          .fnc { count++ }
          .obj(Text(.config(color: onAccent, weight: semibold) .obj('Add one')))
        )
        Button(
          .preset(default)
          .config(disabled: count == 0, label: 'Reset')
          .fnc { count = 0 }
        )
        Text(.config(size: 18, weight: semibold) .obj('$count'))
      )
    )
  )
)

label gives a Button plain text; for styled content put a Text in its .obj. Either way the text is its accessible name. In a Form, submit: true makes a Button submit it.

Config keys

KeyTypeDefaultMeaning
w (width)len | fill | hugWidth: a length, fill (share the remaining space) or hug (fit content, default).
h (height)len | fill | hugHeight: a length, fill or hug (default).
size (s)sizeWidth and height together: size: 200 or size: (200, 120).
minW (minWidth)lenMinimum width.
maxW (maxWidth)lenMaximum width.
minH (minHeight)lenMinimum height.
maxH (maxHeight)lenMaximum height.
aspect (aspectRatio)numAspect ratio (width / height), e.g. 16/9.
color (bg, background, colorBG)paintBackground paint: a colour or gradient.
padding (pad)insetsSpace inside the object.
cornerRadius (radius, borderRadius, corner)radiusCorner radius: one length or only(topLeft: 8, …).
borderWidthlenBorder width.
borderColorcolorBorder colour.
borderAlignin | mid | outinWhere the border sits relative to the edge: in, mid or out.
borderStylesolid | dashed | dottedsolidBorder line style.
borderSidesall | top | bottom | left | right | x | yallWhich sides draw the border (inside the box).
shadowshadowDrop shadow(s): shadow(y: 4, blur: 12, color: black.alpha(20%)).
clipboolClip children to the object's bounds (and corner radius).
zintStacking order among siblings.
margininsetsSpace outside the object: all(8), sym(x: 8, y: 4), only(top: 8).
opacitynumOpacity from 0 to 1.
hide (hidden)boolRemoves the object from layout and the accessibility tree.
shrinknum1Shrink priority when space runs out. Lower shrinks first; 0 never shrinks.
flexnum1Share of remaining space for fill sizes.
cursorauto | pointer | text | grab | grabbing | move | notAllowed | crosshair | nonePointer cursor.
className (class)txtExtra CSS class names: styling hooks for your own stylesheet (hover rules, third-party CSS).
labeltxtButton text (and accessible name).
disabledboolDisabled.
submitboolSubmits its Form.
objAlign (align, alignment, contentAlign)aligntopLeftWhere the object's content sits inside it.

Group .border(align, color, width, style, sides): Border settings grouped: .border(align: in, color: #0d0d0d, width: 2).

Slots

  • .obj: one object, the default slot

Events

.fnc runs on press. .on(...) accepts tap, press, hover, hoverEnd, focus, blur, key, drag, swipe, mount, unmount, visible.