display_modal()
  • 1 Minute to read

display_modal()


Article summary

This function displays a modal component.

Modals are a variant of dialog used to present critical information or request user input needed to complete a user’s workflow. Modals interrupt a user’s workflow by design. When active, a user is blocked from the on-page content and cannot return to their previous workflow until the modal task is completed or the user dismisses the modal.

Reference

Group 974 1.png

Explore more about this component here.

Arguments

ArgumentsTypeDefault Value
titlestringNoneTitle of the modal (mandatory)
title_sizeenumUI_TITLE_SIZE.MEDIUMSize of the title
subtitlestringSubtitle of the modal (optional)
contentstringNoneContext text of the modal (optional)
modal_typeenumUI_MODAL_TYPE.INFOenum to define the type of the modal, check UI_MODAL_TYPE
modal_sizeenumUI_MODAL_SIZE.NORMALenum representing the size of the modal, check UI_MODAL_SIZE
submit_textstring"Yes"Submit text button
cancel_textstring"No"Cancel text button
show_iconboolTrueShow icon in the modal
button_sizeint1Button size (1 = SMALL, 2 = MEDIUM, 3 = LARGE)
themeenumUI_THEME_TYPE.DARKenum representing the theme of the modal, check UI_THEME_TYPE. enum
custom_styledictNonedictionary containing custom styles for the modal (optional)
waitboolTrueboolean indicating whether to wait for a user response
callbackcallableNonecallable object to handle the response (optional)

See the complete list of general enumerations.

Return

Dictionary that contains the action performed by the user.
The action can be: canceled/confirmed/closed.
Example: {'action': 'confirmed', 'app_id': 'APP_ID'}

Exceptions

  • RayaUIMissingValue
  • RayaNeedCallback

See the complete list of ui exceptions and the complete list of general exceptions.

Callback Arguments

callback

ArgumentTypeDescription
datadictDict containing the result of the action

Example

r...

class RayaApplication(RayaApplicationBase):

    async def setup(self):
        self.ui = await self.enable_controller('ui')
        ....
        
    async def loop(self):
     ....
        response = await self.ui.display_modal(
            title="Oh no!", 
            subtitle="Retry this action?", 
            modal_type=MODAL_TYPE.ERROR
        )

        self.log.info(response)
      ...
      
    async def finish(self):
      ...

...
'''
{'action': 'canceled', 'app_id': 'doctest'}
(when modal button 'No' is clicked)
'''

Was this article helpful?