On Beagle, it’s possible to create a customized action from a CustomAction
.
Each platform has its own way to make this implementation on frontend. Below is an example on how to do it for Web projects
You must create an interface with _beagleAction_
as a mandatory propriety and with the necessary parameters to your action. For this example, you will create a msg
attribute string
type.
On _beagleAction_
, put the customized action name following the snippet ‘custom:nameOfAction’.
interface CustomAction {
_beagleAction_: 'custom:CustomAction',
msg: string
}
ActionHandler
where the generic type is the interface you have just created:import { ActionHandler } from '@zup-it/beagle-web'
export const customHandler: ActionHandler<CustomAction> = ({ action }) => {
/*
We can access our parameter defined on the interface, for example, action.msg brings us the msg value.
*/
alert(action.msg)
}
For Angular: add on beagle.module.ts:
@BeagleModule({
...
customActions:{
"custom:CustomAction": customHandler //action handler name
}
})
export class Beagle {}
For React: add to your Beagle’s configurations file:
export default createBeagleUIService<any>({
...
customActions:{
"custom:CustomAction": customHandler //action handler name
}
})
To create this action, your code must be like:
@RegisterAction
data class CustomAction(
val msg: String? = null
) : Action
Below, see an example of an Action in a Button’s type component:
{
"_beagleComponent_": "beagle:button",
"text": "Beagle Button",
"onPress": [
{
"_beagleAction_": "custom:customAction",
"msg": "I am a Toast."
}
]
}
Button(
text = "Beagle Button",
onPress = listOf(CustomAction("I am a Toast"))
)
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.