Shows a dynamically generated UI - !!!POC version, expect changes
Param: ctx
The context in which the UI is rendered
Param: element
The JSX element representing the UI to be shown
Returns
An object with state property that holds the current UI values and property button that holds the value of the clicked button that resolved the showUI promise
Remarks
Every showUI must call a container function first. Container functions are bubble, modal, shield, and splitView.
Container function can contain headerBar, group, and navigationBar. All are optional.
showUI can be resolved by using button component with resolve: true property or by using navigationBar component with buttons property. One of them must be present to resolve the showUI promise.
If sub element wants to be displayed, it must be wrapped by group.
For alignment purposes, vertical and horizontal functions can be used.
To display a spinner, use progressItem component. Make sure showUI is called with void and not awaited.
The return value of showUI contains each UI element state grouped by name. State is any type of data that UI element needs to maintain.
in example:
const { state } = await showUI(ctx, element);
state.hobbies // ['reading', 'traveling'] - checkboxList with name 'hobbies'
state.firstName // 'Mark' - input with name 'firstName'
state.food // 'burger' - radioList with name 'food'
state.country // 'us' - select with name 'country'
Example
Usage with various elements
constresult = awaitshowUI( ctx, bubble([ headerBar({title:'Modular UI form'}), group([ text({ text:async (data) => '**First name:** ' + data.firstName + '\n **Country:** ' + data.country + '\n **Hobby:** ' + data.hobbies + '\n **Food:** ' + data.food, }), input({ name:'firstName', label:'First name', defaultValue:'Mark', }), fileUpload({ name:'upload-file', fileUploadTitle:'Upload Files', uploadButton:'Upload', text:'Please select file to upload.', error:'You can upload up to 3 files only.', maxFileLimit:3, minFileLimit:1, loadingText:'Uploading...', validate:async (file:DroppedFile) => { constisValid = false// Apply your validation logic here constmessage = isValid ? '' : 'File is not valid' return { isValid, message, processedFile:file }; }, allowedTypes: { types: ['image/*', 'application/pdf'], message:'File type must be an image or a PDF', }, maxFileSize: { size:5 * 1024 * 1024, // 5MB message:'File size must be less than 5MB', }, }), select({ name:'country', label:'Country', items: [ {value:'us', label:'United States'}, {value:'de', label:'Germany'}, {value:'fr', label:'France'}, ], }), checkboxList({ name:'hobbies', label:'Hobbies', items: [ {value:'reading', label:'Reading'}, {value:'traveling', label:'Traveling'}, {value:'cooking', label:'Cooking'}, ], }), radioList({ name:'food', label:'food', items:async (state) => state.country === 'us' ? [ {value:'burger', label:'Burger'}, {value:'fries', label:'Fries'}, ] : [ {value:'pasta', label:'Pasta'}, {value:'pizza', label:'Pizza'}, {value:'salad', label:'Salad'}, ], }), statuses({ statuses: [ { status:'success', text:'Data fetched successfully.' }, { status:'warning', text:'Data filtered successfully.' }, { status:'error', text:'Data filtered successfully.' }, ], }), button({ text:'Submit', value:'submit', resolve:true, // to resolve the showUI promise updateState:async (state, value) => { // buttons can also update state constcount = state.count || 0; return {count:count + 1}; }, }), spinner({ title:'Loading...', description:'Please wait while we load the data.', }), ]), ]), );
Example
Usage to show a spinner
voidshowUI(ctx, bubble([ group([ progressItem({ status:'running', title:'Loading...', description:'Please wait while we load the data.', }), ]), ]), );
Example
Usage with text and navigationBar that can be used to display a message to user
Shows a dynamically generated UI - !!!POC version, expect changes
Param: ctx
The context in which the UI is rendered
Param: element
The JSX element representing the UI to be shown
Returns
An object with state property that holds the current UI values and property button that holds the value of the clicked button that resolved the showUI promise
Remarks
bubble
,modal
,shield
, andsplitView
.showUI
can be resolved by usingbutton
component withresolve: true
property or by usingnavigationBar
component withbuttons
property. One of them must be present to resolve the showUI promise.group
.vertical
andhorizontal
functions can be used.progressItem
component. Make sure showUI is called with void and not awaited.Example
Usage with various elements
Example
Usage to show a spinner
Example
Usage with text and navigationBar that can be used to display a message to user
Example
Usage with form elements and navigationBar