Open a modal from a button
Show a modal when a reader selects a custom block button.
Before you start
Add the component
import { createComponent, createIntegration } from '@gitbook/runtime';
const modalTrigger = createComponent({
componentId: 'modal-example',
render: async () => (
<block>
<button
label="Open modal"
onPress={{
action: '@ui.modal.open',
componentId: 'modal-content',
props: {
message: 'Hello world'
}
}}
/>
</block>
)
});
const modalContent = createComponent({
componentId: 'modal-content',
render: async () => (
<modal title="Hello world">
<text>Modal content</text>
<button
label="Close"
onPress={{
action: '@ui.modal.close',
returnValue: {}
}}
/>
</modal>
)
});
export default createIntegration({
components: [modalTrigger, modalContent]
});Add the block to your manifest
Test the block
Next steps
Last updated
Was this helpful?