|
| 1 | +# Superform Development Guide |
| 2 | + |
| 3 | +## Component Argument Convention |
| 4 | + |
| 5 | +HTML components follow a strict convention for arguments: |
| 6 | + |
| 7 | +- **Positional/named keyword arguments** are for component configuration (non-HTML concerns) |
| 8 | +- **`**kwargs`** are for HTML attributes that pass through to the rendered element |
| 9 | + |
| 10 | +```ruby |
| 11 | +# field is positional, value: is config, **attributes are HTML |
| 12 | +class Radio < Field |
| 13 | + def initialize(field, value:, **attributes) |
| 14 | + super(field, **attributes) |
| 15 | + @value = value |
| 16 | + end |
| 17 | +end |
| 18 | + |
| 19 | +# options: and multiple: are config, **attributes are HTML |
| 20 | +class Select < Field |
| 21 | + def initialize(field, options:, multiple: false, **attributes) |
| 22 | + super(field, **attributes) |
| 23 | + @options = options |
| 24 | + @multiple = multiple |
| 25 | + end |
| 26 | +end |
| 27 | +``` |
| 28 | + |
| 29 | +The Field methods mirror this: config args are explicit, HTML attributes flow through as `**kwargs`. |
| 30 | + |
| 31 | +```ruby |
| 32 | +def radio(value, **attributes) |
| 33 | + Components::Radio.new(field, value:, **attributes) |
| 34 | +end |
| 35 | + |
| 36 | +def select(*options, multiple: false, **attributes, &) |
| 37 | + Components::Select.new(field, options:, multiple:, **attributes, &) |
| 38 | +end |
| 39 | +``` |
| 40 | + |
| 41 | +## Key Architecture |
| 42 | + |
| 43 | +- **Field** is a data binding object (model, key, value, DOM name) — not HTML |
| 44 | +- **Components** are HTML elements — their kwargs should be HTML attributes |
| 45 | +- **Form** is a Phlex component that contains fields and renders the `<form>` tag |
| 46 | +- Customization is through subclassing, not runtime options |
0 commit comments