b172762288
Main components define properties; instances keep values as overrides, so
main edits keep them and definition changes re-apply everywhere. Enum
options use the overrides format and can restyle, retext, show, hide or
re-icon any layer. Templates: text, active (tab bars, navs), status.
set_component_props, set_instance_props, props= on <x-paper-instance>,
get_components lists them, {Prop} in code links, inspector controls.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2.5 KiB
2.5 KiB
Component properties
Why
A status badge, a tab bar or a list row is drawn once as a component, but every use differs:
the status is Autorizada, Rejeitada or Na SEFAZ; a different tab is active; the label and the
icon change. Today each case is its own component (Badge / Green, Tabs / Lojas, Tabs / Pedidos) or hand edits on layers, so a design needs a component per state and an agent edits
layer by layer.
What
- Properties live on the main component (
Node.props), each with a name and a type:text: the text of a layer (layer).bool: shows or hides a layer.icon: the icon of an icon layer (Icon / set:name), anyset:name.enum: a list of options; each option is a set of changes in theoverridesformat ({"Label": "Rejeitada", "$root": {"background": "var(--danger-bg)"}, "Dot": {"icon": "lucide:x"}}), so an option can restyle, retext, show, hide or re-icon any layer. Fully custom.
- Instances keep their values (
Node.prop_valueson the instance root) and apply them as overrides, so edits to the main keep them; editing the definitions re-applies every instance's values on every page. - Templates make the common cases one call:
text(a text property per text layer),active(an enum choosing which item of a row, tab bar or nav is active, with active and inactive styles) andstatus(an enum of statuses, each a colour that tints the root and colours its text and icon). - Where to use it:
set_component_props(define, or from a template),set_instance_props(many instances in one call),get_components(lists properties),<x-paper-instance component="Badge" props='{"Status":"Rejeitada"}'/>inwrite_html, the inspector (a control per property on an instance; templates on a main), and code links ({Status}in a usage template is the instance's value).
Not now
Variant sets made of several mains, nested property exposure (a row exposing its badge's properties), numeric properties.
Acceptance
- A badge with an enum Status (Autorizada, Rejeitada) shows the option's colours and label on each instance; switching the value updates only that instance.
- Editing the main (gap) keeps every instance's values; editing an option's colour updates every instance using it.
- The
activetemplate on a five-item tab bar makes one property whose options are the item names; each instance shows its active item highlighted. - An icon property swaps the icon and survives a sync of the main.