Filament.Defcomponent (filament v0.2.1)

Copy Markdown

The defcomponent macro implementation.

Supports two forms:

  • defcomponent do: block - inferred name from parent module (for single-component modules)
  • defcomponent Name do: block - explicit name (for multi-component modules)

Inferred Name Form

When a module defines exactly one component with the inferred form, the component takes the name of the parent module:

defmodule TodoWeb.Components.FilterBar do
  use Filament.Component

  defcomponent do
    prop(:filters, :list, required: true)
    # ...
  end
end

This allows using the component as TodoWeb.Components.FilterBar instead of TodoWeb.Components.FilterBar.FilterBar.

Explicit Name Form

Use the explicit form when defining multiple components in one module:

defmodule MyComponents do
  use Filament.Component

  defcomponent Button do
    # ...
  end

  defcomponent Input do
    # ...
  end
end

Components are accessed as MyComponents.Button and MyComponents.Input.

Summary

Functions

defcomponent(list)

(macro)

defcomponent(name, list)

(macro)

prop(name, type, opts \\ [])

(macro)