Component definition

The component.json reference.

A component's definition, component.json, describes it to the paywall designer, the Voidhash agent and publishing. #[component] builds the same definition into your module. Publishing checks that both agree on its traits, props, events, preview states, capabilities and size. The id, version, title, description, icon, category and keywords are the bundle's own.

component.json
{
  "id": "acme/plan-picker",
  "version": "1.0.0",
  "title": "Plan picker",
  "description": "Selectable plans with a purchase button.",
  "icon": { "kind": "builtin", "name": "list" },
  "category": "Pricing",
  "keywords": ["plans", "pricing"],
  "implementation": { "kind": "wasm", "abi": 2 },
  "traits": { "frame": { "resize": "width" }, "appearance": {}, "effects": {} },
  "children": { "kind": "none" },
  "props": [
    { "name": "plans", "type": { "kind": "list", "of": { "kind": "product" } }, "default": [] },
    { "name": "accent", "title": "Accent", "type": { "kind": "color" }, "default": "#7c3aed" }
  ],
  "events": [
    { "name": "selected", "payload": [{ "name": "productId", "type": { "kind": "string" } }] }
  ],
  "previewStates": ["default"],
  "capabilities": ["commerce"],
  "panel": false,
  "fallback": "placeholder",
  "defaultSize": { "width": "fill", "height": "hug" }
}

A bundle you publish to your organization needs a component.json. Components in your project's .voidhash working copy use the definition #[component] builds instead.

Fields

FieldMeaning
id<namespace>/<name>. The namespace is your organization's; the name uses lowercase letters, digits and dashes.
versionA semantic version such as 1.2.0. Each published version is permanent, so bump it for every publish.
titleThe name the designer shows.
descriptionOne or two sentences about what the component does.
icon{ "kind": "builtin", "name": "list" } (such as component, list, timer, gift), or ship an icon.png.
categoryThe group the designer lists the component in, such as Pricing.
keywordsWords people search for in the designer.
implementation{ "kind": "wasm", "abi": 2 } for components built with voidhash-ui, or "abi": 3 for inputs.
traitsThe designer sections and canvas behavior the component takes part in. See Traits.
children{ "kind": "none" }, { "kind": "any" }, or { "kind": "slots", "slots": [{ "name": "default" }] }.
propsThe settings the designer shows. See Props.
eventsWhat the component emits, such as a selection, that paywalls bind to actions.
previewStatesThe states the designer can preview the component in. The first is the default.
capabilitiesWhat the component can do for the person using your app. See Capabilities.
panelWhether the component ships its own editor panel. Without one, the designer shows its props.
fallbackWhat an app that cannot run the component shows instead: placeholder, hide or children.
defaultSizeThe size a new instance starts at: fill, hug or a number of points, per axis.
followsTextSizetrue to have the text elements your component draws follow the text size people choose on their phone. See Text size.
valueFor an input: { "type": "string" }, number, boolean or list (texts without repeats), the value a paywall binds to a variable. Add "secret": true to keep it out of analytics and saved state.

Traits

A trait gives every instance a designer section and its canvas behavior, as built-in layers have them. An instance keeps only the settings of the traits its definition declares.

TraitDesigner sectionWhat instances get
framePositionPosition, size, margins and how the instance sits in its parent.
layoutLayoutPadding, gap, alignment and clipping of what the component holds.
appearanceAppearanceOpacity, blend mode, visibility and corner radius.
fillFillBackgrounds: colors, gradients and image fills.
borderBorderA border.
outlineOutlineAn outline.
effectsEffectsShadows, blurs, rotation and flips.
statesVariantsVariants that restyle the instance while their condition holds.
interactionsEventsTap actions on the instance itself.
variablesVariablesVariables an instance already declares, to move to the flow.
sharedElementShared elementA shared element id, so the instance flies between screens.

Text layers also have typography, but component instances have no text style, so declaring it gives them nothing. Expose text settings as props instead. An editor panel edits only the style of the declared traits.

Resizing

frame takes resize, the canvas's resize handles: both, width or height for one axis, or none to keep the instance's size. Add aspect: "intrinsic" to keep its proportions while resizing. A component without frame sizes itself from defaultSize and can't be resized on the canvas. In Rust, declare traits on the component:

#[component(traits(frame(resize = "width"), appearance, effects), size(width = "fill", height = "hug"))]

Text size

A paywall's own texts follow the text size people choose on their phone (Dynamic Type on iOS, the font size on Android), but a component's text keeps the sizes your code gives it unless the definition says "followsTextSize": true. With it, the paywall sizes every text and text field element your component draws for that text size, as it sizes its own texts: set it when your layout gives text the room it needs, such as boxes that hug their content or wrap. In Rust, add follows_text_size to #[component(...)].

Text in a box of a fixed size needs more care. Either way, cx.font_scale() is the text size as a multiple of the designed size (1 by default, about 3 at the largest iOS size, 2 on Android):

  • Size the box from it, and cap how far the text grows with .max_font_scale(...) so it can't grow past the box, as a code entry's digit boxes do.
  • Or leave followsTextSize out and size both the box and the text from cx.font_scale() yourself, up to a limit that keeps your layout usable, as a wheel picker's rows do.

.fixed_font_size() keeps one text at its size, such as a glyph used as an icon. A component version you already published keeps its behavior: publish a new version to follow the text size.

Slots

A component with children: { "kind": "slots" } shows its inner layers where its code renders slot() (the default slot) or slot_named("footer"). In the designer, each inner layer names its slot.

Props

Each prop has a name, a type and a default. The type sets what the prop holds and the control the designer shows; other fields label, group and localize it. See Component props for every field, type and its Rust form.

The definition must declare what the component's code declares: the same traits, props, events, preview states, capabilities, panel and default size. Publishing names every difference it finds.

Apps that can't show a build

Voidhash sends a paywall build only to an app whose SDK can run every component in it. An app that can't run a build gets the most recently live earlier build of the same paywall that it can run, and only when none fits the answer for a location with nothing assigned, so it shows your own fallback instead of a broken paywall.

The same check applies to A/B tests. An app that can't show its arm's newest build is shown an earlier build of the arm's paywall and counted as exposed to the arm; one that can show none of them is shown nothing at that location and isn't counted.

Some components run natively inside the SDK. An SDK without such a component still gets the paywall and shows the component's fallback in its place, so choose placeholder, hide or children with that in mind.

Next steps

Something wrong or missing on this page? Tell us by email or on Discord.