A dialog is a high-priority, intentionally disruptive message that requires action from the merchant before they can continue using POS.
import React, {useState} from 'react';
import {
Button,
Dialog,
Screen,
reactExtension,
} from '@shopify/ui-extensions-react/point-of-sale';
const SmartGridModal = () => {
const [visible, setVisible] = useState(false);
const handlePrimaryAction = () => {
setVisible(false);
console.log('Primary action pressed');
};
const handleSecondaryAction = () => {
setVisible(false);
console.log('Secondary action pressed');
};
return (
<Screen name="Dialog" title="Dialog Title">
<Button
title="Show dialog"
onPress={() => setVisible(true)}
/>
<Dialog
type="error"
title="Dialog title"
content="Dialog content"
actionText="Primary action"
onAction={handlePrimaryAction}
secondaryActionText="Secondary action"
onSecondaryAction={handleSecondaryAction}
isVisible={visible}
/>
</Screen>
);
};
export default reactExtension(
'pos.home.modal.render',
() => <SmartGridModal />,
);
import {
Button,
Dialog,
Screen,
extension,
} from '@shopify/ui-extensions/point-of-sale';
export default extension(
'pos.home.modal.render',
(root) => {
const mainScreen = root.createComponent(
Screen,
{
name: 'Dialog',
title: 'Dialog Title',
},
);
const button = root.createComponent(Button, {
title: 'Show dialog',
onPress: () =>
dialog.updateProps({visible: true}),
});
const handlePrimaryAction = () => {
dialog.updateProps({visible: false});
console.log('Primary action pressed');
};
const handleSecondaryAction = () => {
dialog.updateProps({visible: false});
console.log('Secondary action pressed');
};
const dialog = root.createComponent(Dialog, {
type: 'error',
title: 'Dialog title',
content: 'Dialog content',
actionText: 'Primary action',
onAction: handlePrimaryAction,
secondaryActionText: 'Secondary action',
onSecondaryAction: handleSecondaryAction,
isVisible: false,
});
mainScreen.append(button);
mainScreen.append(dialog);
root.append(mainScreen);
},
);
The text displayed in the title of the dialog.
The text displayed in the body of the dialog.
The text displayed in the primary action button of the dialog.
The text displayed in the secondary action section of the dialog.
Whether a secondary action displays.
Determines the dialog’s appearance and function.
A callback that performs when the action is triggered.
A callback that is executed when the secondary action is triggered.
Whether the dialog should be presented.
'default' | 'alert' | 'error' | 'destructive'