Components
A Custom Component is a React functional component you register under Manage Components in RUAL Studio and place on a state page, available since RUAL Core 13.0.6. This page covers how existing components receive blueprint data and call blueprint functions.
For new interactive pieces on a web page, see when a custom script is needed.
Built-in components are blocks
RUAL provides an extensive list of components within the blueprinting environment. These default blocks are React-based functional components, integrated directly into blueprinting. For needs they do not cover, Custom Components give access to all custom React functional component capabilities.
Custom Components live under Manage Components
Since v13.0.6 of RUAL Core, the left-side menu has an option titled "Manage Components": an overview of the custom React components available across your entire cluster.
Build them as React Functional Components. They support everything you expect of a React component, with the minor changes for blueprinting described below.
Blueprint-specific parameters
For blocks that support storages or fields, access these through parameters. This promotes component reuse, but the parameters do not automatically appear in your code.
| Parameter | Description |
|---|---|
bp_field | A string that identifies the selected field name, which may be prefixed by the form identifier if a form_id inpin is present. |
bp_multiple_fields | An array of objects, each containing a selected field. |
bp_hash | A hash provided to FetchJS for retrieving fresh JavaScript when executing a script. |
bp_img_src | A URL or data: URL for an asset generated by the backend. |
bp_submit_data | A JWT-encoded object for submitting data to the backend. |
bp_hyperlink | The URL of the selected State Page. |
bp_translate_key | The translation key selected for the block. |
bp_action_guid | An identifier used by some blocks to execute queries and interact with the backend storage. |
bp_iterate_component | A path to the static custom component. Supply this to RUAL.fetchComponent, and it returns a valid cached React Component. Primarily used in iterative contexts, such as Advanced Datatables. |
Certain inpin IDs are not directly usable within a React Component, and are remapped:
| Inpin ID | Parameter |
|---|---|
id | rual_id |
Trigger a blueprint function through an inpin
First define an inpin. This example uses an inpin named onclick of the type Executable Function with the identifier onclick.
const { runBlueprintFunction } = window.RUAL;
export default function CustomButtonComponent ({ uiclass, uistyle, uiattributes, onclick }) {
function triggerFunction () {
runBlueprintFunction(onclick, {
'value': 'custom-value'
});
}
return (
<button
{ ...uiattributes }
type="button"
onClick={ triggerFunction }
className={ ['form-control', uiclass] }
style={ uistyle || {} }
>Click me</button>
);
}
Using React hooks
You can import any standard React hook for use in these components. This one uses React State:
const { useState } = window.React;
export default function CustomButtonComponent ({ uiclass, uistyle, uiattributes }) {
const [isLoading, setIsLoading] = useState(false);
function triggerFunction () {
setIsLoading(true);
setTimeout(() => {
setIsLoading(false);
}, 1000);
}
return (
<button
{ ...uiattributes }
type="button"
onClick={ triggerFunction }
className={ ['form-control', uiclass] }
style={ uistyle || {} }
>
{isLoading ? 'Loading...' : 'Click me'}
</button>
);
}
Object and array values for className
React Web does not accept object and array-based className properties, as React Native does. In RUAL these formats are supported, so you can combine multiple classes from inpins or other properties.
// uiclass = { 'bpclass': true }
export default function CustomClassNameComponent ({ uiclass }) {
const classArrayExample = ['card-body'];
return (
<div
className={ [{
'card': true,
'other': false
}, 'form-control', uiclass, classArrayExample] }
>Class will be <code>card form-control bpclass card-body</code></div>
);
}
Frequently asked
Can I write my own React components in RUAL?
Yes. Since RUAL Core 13.0.6, the Manage Components section in RUAL Studio lets you register custom React functional components on the cluster. They support standard React features such as hooks, with minor modifications to integrate with blueprinting.
How does a custom RUAL component receive the field selected on the blueprint?
Through parameters such as bp_field, a string holding the selected field name, and bp_multiple_fields for multiple selections. These parameters promote component reuse, but they do not automatically appear in your code.
How do I trigger a blueprint function from a custom RUAL component?
Define an inpin of the type Executable Function, for example one named onclick, and call it from your component code. The blueprint then runs the flow wired to that pin.
