Search documentation of Plushie

# Plushie.Widget.Container (Plushie v0.7.2)

Copy Markdown View Source

Container layout, wraps a single child with padding, sizing, and styling.

## Props

Name | Type | Default | Description
--- | --- | --- | ---
`padding` | `number() | {number(), number()} | %Plushie.Type.Padding{}` | `nil` | Padding inside the container.
`width` | `:fill | :shrink | {:fill_portion, pos_integer()} | number()` | `nil` | Container width. Default: shrink.
`height` | `:fill | :shrink | {:fill_portion, pos_integer()} | number()` | `nil` | Container height. Default: shrink.
`max_width` | `number()` | `nil` | Maximum width in pixels.
`max_height` | `number()` | `nil` | Maximum height in pixels.
`center` | `boolean()` | `nil` | Center child in both axes. Default: false.
`clip` | `boolean()` | `nil` | Clip child that overflows. Default: false.
`align_x` | `:left | :center | :right | :top | :bottom` | `nil` | Horizontal alignment: `:left`, `:center`, `:right`.
`align_y` | `:left | :center | :right | :top | :bottom` | `nil` | Vertical alignment: `:top`, `:center`, `:bottom`.
`background` | `String.t() | %__MODULE__{}` | `nil` | Background fill. Accepts a color or gradient.
`color` | `String.t()` | `nil` | Text color override.
`border` | `%Plushie.Type.Border{}` | `nil` | Border specification: `%{color, width, radius}`.
`shadow` | `%Plushie.Type.Shadow{}` | `nil` | Shadow specification: `%{color, offset, blur_radius}`.

| `style` | `:default \| :primary \| :secondary \| :success \| :danger \| :warning \| :dark \| :weak \| :rounded_box \| term()` | `nil` | Named preset or custom `StyleMap`. | | `event_rate` | `integer()` | `nil` | Max events per second for coalescable events. | | `a11y` | `%Plushie.Type.A11y{} \| map() \| keyword()` | `nil` | Accessibility annotations. |

## Summary

### Types

option()
preset()
t()

### Functions

a11y(widget, descriptor)

Accessibility annotations.

align_bottom(container, height \\ :fill)

Aligns content to the bottom. Sets height and align_y: :bottom.

align_left(container, width \\ :fill)

Aligns content to the left. Sets width and align_x: :left.

align_right(container, width \\ :fill)

Aligns content to the right. Sets width and align_x: :right.

align_top(container, height \\ :fill)

Aligns content to the top. Sets height and align_y: :top.

align_x(widget, descriptor)

Horizontal alignment: `:left`, `:center`, `:right`.

align_y(widget, descriptor)

Vertical alignment: `:top`, `:center`, `:bottom`.

background(widget, descriptor)

Sets the background fill (color or gradient).

border(widget, descriptor)

Border specification: `%{color, width, radius}`.

build(widget)

Converts this widget struct to a `ui_node()` map.

center(c)

Centers the child in both axes. Defaults to true when called with no argument.

center(widget, descriptor)

Center child in both axes. Default: false.

center_x(container, width \\ :fill)

Centers content horizontally. Sets width and align_x: :center.

center_y(container, height \\ :fill)

Centers content vertically. Sets height and align_y: :center.

clip(widget, descriptor)

Clip child that overflows. Default: false.

color(widget, descriptor)

Text color override.

container(id, opts \\ [])

Creates a `:container` widget.

event_rate(widget, descriptor)

Max events per second for coalescable events.

extend(widget, children)

Appends multiple children to the widget.

height(widget, descriptor)

Container height. Default: shrink.

max_height(widget, descriptor)

Maximum height in pixels.

max_width(widget, descriptor)

Maximum width in pixels.

new(id, opts \\ [])

Creates a new widget struct with the given ID and keyword options.

padding(widget, descriptor)

Padding inside the container.

push(widget, child)

Appends a child to the widget.

shadow(widget, descriptor)

Shadow specification: `%{color, offset, blur_radius}`.

style(widget, descriptor)

Named preset or custom `StyleMap`.

width(widget, descriptor)

Container width. Default: shrink.

with_options(widget, opts)

Applies keyword options to an existing widget struct.

## Types

# option()

    @type option() ::
      (((((((((((((({:padding,
                     number()
                     | {number(), number()}
                     | %Plushie.Type.Padding{
                         bottom: term(),
                         left: term(),
                         right: term(),
                         top: term()
                       }}
                    | {:width,
                       :fill | :shrink | {:fill_portion, pos_integer()} | number()})
                   | {:height,
                      :fill | :shrink | {:fill_portion, pos_integer()} | number()})
                  | {:max_width, number()})
                 | {:max_height, number()})
                | {:center, boolean()})
               | {:clip, boolean()})
              | {:align_x, :left | :center | :right | :top | :bottom})
             | {:align_y, :left | :center | :right | :top | :bottom})
            | {:background,
               (atom() | String.t() | map())
               | %Plushie.Widget.Container{
                   a11y: term(),
                   align_x: term(),
                   align_y: term(),
                   background: term(),
                   border: term(),
                   center: term(),
                   children: term(),
                   clip: term(),
                   color: term(),
                   event_rate: term(),
                   height: term(),
                   id: term(),
                   max_height: term(),
                   max_width: term(),
                   padding: term(),
                   shadow: term(),
                   style: term(),
                   width: term()
                 }})
           | {:color, atom() | String.t() | map()})
          | {:border,
             %Plushie.Type.Border{color: term(), radius: term(), width: term()}})
         | {:shadow,
            %Plushie.Type.Shadow{
              blur_radius: term(),
              color: term(),
              offset_x: term(),
              offset_y: term()
            }})
        | {:style,
           :default
           | :primary
           | :secondary
           | :success
           | :danger
           | :warning
           | :dark
           | :weak
           | :rounded_box
           | term()})
       | {:event_rate, integer()})
      | {:a11y,
         %Plushie.Type.A11y{
           active_descendant: term(),
           busy: term(),
           described_by: term(),
           description: term(),
           disabled: term(),
           error_message: term(),
           expanded: term(),
           has_popup: term(),
           hidden: term(),
           invalid: term(),
           label: term(),
           label_from: term(),
           labelled_by: term(),
           level: term(),
           live: term(),
           mnemonic: term(),
           modal: term(),
           orientation: term(),
           position_in_set: term(),
           radio_group: term(),
           read_only: term(),
           required: term(),
           role: term(),
           selected: term(),
           size_of_set: term(),
           toggled: term(),
           value: term()
         }
         | map()
         | keyword()}

# preset()

    @type preset() ::
      :warning
      | :danger
      | :success
      | :secondary
      | :primary
      | :dark
      | :bordered_box
      | :rounded_box
      | :transparent

# t()

    @type t() :: %Plushie.Widget.Container{
      a11y:
        (%Plushie.Type.A11y{
           active_descendant: term(),
           busy: term(),
           described_by: term(),
           description: term(),
           disabled: term(),
           error_message: term(),
           expanded: term(),
           has_popup: term(),
           hidden: term(),
           invalid: term(),
           label: term(),
           label_from: term(),
           labelled_by: term(),
           level: term(),
           live: term(),
           mnemonic: term(),
           modal: term(),
           orientation: term(),
           position_in_set: term(),
           radio_group: term(),
           read_only: term(),
           required: term(),
           role: term(),
           selected: term(),
           size_of_set: term(),
           toggled: term(),
           value: term()
         }
         | map()
         | keyword())
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      align_x:
        (:left | :center | :right | :top | :bottom)
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      align_y:
        (:left | :center | :right | :top | :bottom)
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      background:
        (String.t()
         | %Plushie.Widget.Container{
             a11y: term(),
             align_x: term(),
             align_y: term(),
             background: term(),
             border: term(),
             center: term(),
             children: term(),
             clip: term(),
             color: term(),
             event_rate: term(),
             height: term(),
             id: term(),
             max_height: term(),
             max_width: term(),
             padding: term(),
             shadow: term(),
             style: term(),
             width: term()
           })
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      border:
        %Plushie.Type.Border{color: term(), radius: term(), width: term()}
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      center:
        boolean()
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      children: [Plushie.Widget.ui_node()],
      clip:
        boolean()
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      color:
        String.t()
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      event_rate:
        integer()
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      height:
        (:fill | :shrink | {:fill_portion, pos_integer()} | number())
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      id: String.t(),
      max_height:
        number()
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      max_width:
        number()
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      padding:
        (number()
         | {number(), number()}
         | %Plushie.Type.Padding{
             bottom: term(),
             left: term(),
             right: term(),
             top: term()
           })
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      shadow:
        %Plushie.Type.Shadow{
          blur_radius: term(),
          color: term(),
          offset_x: term(),
          offset_y: term()
        }
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      style:
        (:default
         | :primary
         | :secondary
         | :success
         | :danger
         | :warning
         | :dark
         | :weak
         | :rounded_box
         | term())
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      width:
        (:fill | :shrink | {:fill_portion, pos_integer()} | number())
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil
    }

## Functions

# a11y(widget, descriptor)

    @spec a11y(
      widget :: t(),
      value ::
        (%Plushie.Type.A11y{
           active_descendant: term(),
           busy: term(),
           described_by: term(),
           description: term(),
           disabled: term(),
           error_message: term(),
           expanded: term(),
           has_popup: term(),
           hidden: term(),
           invalid: term(),
           label: term(),
           label_from: term(),
           labelled_by: term(),
           level: term(),
           live: term(),
           mnemonic: term(),
           modal: term(),
           orientation: term(),
           position_in_set: term(),
           radio_group: term(),
           read_only: term(),
           required: term(),
           role: term(),
           selected: term(),
           size_of_set: term(),
           toggled: term(),
           value: term()
         }
         | map()
         | keyword())
        | nil
    ) :: t()

Accessibility annotations.

Accepts `%Plushie.Type.A11y{} | map() | keyword()`.

# align_bottom(container, height \\ :fill)

    @spec align_bottom(container :: t(), height :: Plushie.Type.Length.t()) :: t()

Aligns content to the bottom. Sets height and align_y: :bottom.

# align_left(container, width \\ :fill)

    @spec align_left(container :: t(), width :: Plushie.Type.Length.t()) :: t()

Aligns content to the left. Sets width and align_x: :left.

# align_right(container, width \\ :fill)

    @spec align_right(container :: t(), width :: Plushie.Type.Length.t()) :: t()

Aligns content to the right. Sets width and align_x: :right.

# align_top(container, height \\ :fill)

    @spec align_top(container :: t(), height :: Plushie.Type.Length.t()) :: t()

Aligns content to the top. Sets height and align_y: :top.

# align_x(widget, descriptor)

    @spec align_x(
      widget :: t(),
      value :: (:left | :center | :right | :top | :bottom) | nil
    ) :: t()

Horizontal alignment: `:left`, `:center`, `:right`.

Accepts `:left | :center | :right | :top | :bottom`.

# align_y(widget, descriptor)

    @spec align_y(
      widget :: t(),
      value :: (:left | :center | :right | :top | :bottom) | nil
    ) :: t()

Vertical alignment: `:top`, `:center`, `:bottom`.

Accepts `:left | :center | :right | :top | :bottom`.

# background(widget, descriptor)

    @spec background(
      widget :: t(),
      value ::
        ((atom() | String.t() | map())
         | %Plushie.Widget.Container{
             a11y: term(),
             align_x: term(),
             align_y: term(),
             background: term(),
             border: term(),
             center: term(),
             children: term(),
             clip: term(),
             color: term(),
             event_rate: term(),
             height: term(),
             id: term(),
             max_height: term(),
             max_width: term(),
             padding: term(),
             shadow: term(),
             style: term(),
             width: term()
           })
        | nil
    ) :: t()

Sets the background fill (color or gradient).

# border(widget, descriptor)

    @spec border(
      widget :: t(),
      value ::
        %Plushie.Type.Border{color: term(), radius: term(), width: term()} | nil
    ) :: t()

Border specification: `%{color, width, radius}`.

Accepts `%Plushie.Type.Border{}`.

# build(widget)

    @spec build(widget :: t()) :: Plushie.Widget.ui_node()

Converts this widget struct to a `ui_node()` map.

# center(c)

Centers the child in both axes. Defaults to true when called with no argument.

# center(widget, descriptor)

    @spec center(widget :: t(), value :: boolean() | nil) :: t()

Center child in both axes. Default: false.

Accepts `boolean()`.

# center_x(container, width \\ :fill)

    @spec center_x(container :: t(), width :: Plushie.Type.Length.t()) :: t()

Centers content horizontally. Sets width and align_x: :center.

# center_y(container, height \\ :fill)

    @spec center_y(container :: t(), height :: Plushie.Type.Length.t()) :: t()

Centers content vertically. Sets height and align_y: :center.

# clip(widget, descriptor)

    @spec clip(widget :: t(), value :: boolean() | nil) :: t()

Clip child that overflows. Default: false.

Accepts `boolean()`.

# color(widget, descriptor)

    @spec color(widget :: t(), value :: (atom() | String.t() | map()) | nil) :: t()

Text color override.

Accepts `String.t()`.

# container(id, opts \\ [])

(macro)

Creates a `:container` widget.

Shorthand for `new/2`. Import this macro to use the widget name directly in view functions:

    import Plushie.Widget.Container, only: [container: 2]

    container("my-id", prop: value)

# event_rate(widget, descriptor)

    @spec event_rate(widget :: t(), value :: integer() | nil) :: t()

Max events per second for coalescable events.

Accepts `integer()`.

# extend(widget, children)

    @spec extend(widget :: t(), children :: [Plushie.Widget.child()]) :: t()

Appends multiple children to the widget.

# height(widget, descriptor)

    @spec height(
      widget :: t(),
      value :: (:fill | :shrink | {:fill_portion, pos_integer()} | number()) | nil
    ) :: t()

Container height. Default: shrink.

Accepts `:fill | :shrink | {:fill_portion, pos_integer()} | number()`.

# max_height(widget, descriptor)

    @spec max_height(widget :: t(), value :: number() | nil) :: t()

Maximum height in pixels.

Accepts `number()`.

# max_width(widget, descriptor)

    @spec max_width(widget :: t(), value :: number() | nil) :: t()

Maximum width in pixels.

Accepts `number()`.

# new(id, opts \\ [])

    @spec new(id :: String.t(), opts :: [option()]) :: t()

Creates a new widget struct with the given ID and keyword options.

# padding(widget, descriptor)

    @spec padding(
      widget :: t(),
      value ::
        (number()
         | {number(), number()}
         | %Plushie.Type.Padding{
             bottom: term(),
             left: term(),
             right: term(),
             top: term()
           })
        | nil
    ) :: t()

Padding inside the container.

Accepts `number() | {number(), number()} | %Plushie.Type.Padding{}`.

# push(widget, child)

    @spec push(widget :: t(), child :: Plushie.Widget.child()) :: t()

Appends a child to the widget.

# shadow(widget, descriptor)

    @spec shadow(
      widget :: t(),
      value ::
        %Plushie.Type.Shadow{
          blur_radius: term(),
          color: term(),
          offset_x: term(),
          offset_y: term()
        }
        | nil
    ) :: t()

Shadow specification: `%{color, offset, blur_radius}`.

Accepts `%Plushie.Type.Shadow{}`.

# style(widget, descriptor)

    @spec style(
      widget :: t(),
      value ::
        (:default
         | :primary
         | :secondary
         | :success
         | :danger
         | :warning
         | :dark
         | :weak
         | :rounded_box
         | term())
        | nil
    ) :: t()

Named preset or custom `StyleMap`.

Accepts `:default | :primary | :secondary | :success | :danger | :warning | :dark | :weak | :rounded_box | term()`.

# width(widget, descriptor)

    @spec width(
      widget :: t(),
      value :: (:fill | :shrink | {:fill_portion, pos_integer()} | number()) | nil
    ) ::
      t()

Container width. Default: shrink.

Accepts `:fill | :shrink | {:fill_portion, pos_integer()} | number()`.

# with_options(widget, opts)

    @spec with_options(widget :: t(), opts :: [option()]) :: t()

Applies keyword options to an existing widget struct.