Macro for creating widget set modules that override built-in widget macros.
A widget set is a module that re-exports all of Plushie.UI but replaces
specific widget macros with alternatives. This enables widget packs,
custom themes, and per-app widget customization without manual import
juggling.
Usage
Define a widget set module:
defmodule MyApp.MaterialUI do
use Plushie.UI.WidgetSet,
override: [
button: MyApp.Widgets.MaterialButton,
text_input: MyApp.Widgets.MaterialTextInput
]
endUse it in view functions:
defmodule MyApp do
use Plushie.App
def view(model) do
use MyApp.MaterialUI
window "main", title: "My App" do
button("save", label: "Save") # uses MaterialButton
text("greeting", "Hello") # uses built-in (not overridden)
end
end
endHow it works
The macro generates a module that:
- Imports all of
Plushie.UIexcept the overridden widget macros - Imports the override modules, bringing their macros into scope
- Re-exports everything so consumers get a single import
Override modules must export macros with the same names and compatible
arities as the built-in widgets they replace. The easiest way to create
an override module is with use Plushie.Widget:
defmodule MyApp.Widgets.MaterialButton do
use Plushie.Widget
widget :button do
field :label, :string
field :rounded, :boolean, default: true
# ... material-specific fields
end
def view(id, props) do
import Plushie.UI
button(id, props.label, style: :primary, padding: 12)
end
end