LedgerUI.Components.ImageInput (LedgerUI v0.2.0)

Copy Markdown View Source

An image field: the picture (an avatar, a logo) in a round or rounded frame, with an edit overlay and a small button to remove or revert it.

<.image_input name="avatar" value={@user.avatar_url} size="lg" />
<.image_input name="logo" value="/images/logo.png" shape="rounded" />

With a name the frame is a file picker: clicking the picture opens the chooser, the chosen file shows at once and the button puts the first picture back or, with nothing chosen, empties the field and sets the hidden <name>_remove input to 1. The behaviour lives in the LedgerUI.ImageInput hook (priv/static/ledger_ui/hooks/image_input.js).

Without a name it is only the frame (the design's lu-imgin): initials draws a filled frame with letters, hover forces the edit overlay and progress draws the upload ring.

Deviations from the README: size has no default (nil is the design's 88px frame with a large icon, same as md) and shape accepts square (the design's default radius) and wide too.

Summary

Functions

Renders the image field.

Functions

image_input(assigns)

Renders the image field.

Attributes

  • id (:string) - Defaults to nil.
  • name (:string) - The name of the file input; <name>_remove is the hidden one. Defaults to nil.
  • value (:string) - The address of the picture it holds now. Defaults to nil.
  • accept (:string) - Defaults to ".png,.jpg,.jpeg,.webp".
  • size (:string) - Defaults to nil.Must be one of nil, "lg", "md", "sm", or "xl".
  • shape (:string) - Defaults to "circle". Must be one of "circle", "rounded", "square", or "wide".
  • label (:string) - Defaults to "Choose a picture".
  • remove_label (:string) - Defaults to "Remove or revert the picture".
  • initials (:string) - Letters on a filled frame when there is no picture. Defaults to nil.
  • hover (:boolean) - Draws the edit overlay (the hover state). Defaults to false.
  • loop (:string) - Animated demo of a state: hover loops the edit overlay (m-hover), ring loops the upload ring (m-loop). Defaults to nil. Must be one of nil, "hover", or "ring".
  • progress (:integer) - An upload ring, 0 to 100. Defaults to nil.
  • disabled (:boolean) - Defaults to false.
  • class (:any) - Defaults to nil.
  • Global attributes are accepted.