Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/hip-shirts-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/ui-extensions': minor
---

implements the cash drawer api to the ui extensions repository
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import {ReferenceEntityTemplateSchema} from '@shopify/generate-docs';
import {generateJsxCodeBlock} from '../helpers/generateCodeBlock';
import {TargetLink} from '../types/ExtensionTargetType';

const generateJsxCodeBlockForCashDrawerApi = (
title: string,
fileName: string,
) => generateJsxCodeBlock(title, 'cash-drawer-api', fileName);

const data: ReferenceEntityTemplateSchema = {
name: 'Cash Drawer API',
description: `
The Cash Drawer API is an API exposed to extensions for cash drawer functionality, specifically allowing UI extensions to control cash drawer operations.

#### Supporting targets
- ${TargetLink.PosHomeTileRender}
- ${TargetLink.PosHomeModalRender}
- ${TargetLink.PosPurchasePostActionMenuItemRender}
- ${TargetLink.PosPurchasePostActionRender}
- ${TargetLink.PosPurchasePostBlockRender}
- ${TargetLink.PosReturnPostActionMenuItemRender}
- ${TargetLink.PosReturnPostActionRender}
- ${TargetLink.PosReturnPostBlockRender}
- ${TargetLink.PosExchangePostActionMenuItemRender}
- ${TargetLink.PosExchangePostActionRender}
- ${TargetLink.PosExchangePostBlockRender}
`,
isVisualComponent: false,
type: 'APIs',
definitions: [
{
title: 'CashDrawerApi',
description: 'Interface for handling cash drawer operations.',
type: 'CashDrawerApi',
},
],
category: 'APIs',
related: [],
examples: {
description: 'Examples of using the Cash Drawer API',
examples: [
{
codeblock: generateJsxCodeBlockForCashDrawerApi(
'Open the cash drawer',
'default.example',
),
},
],
},
};

export default data;
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {render} from 'preact';

export default async () => {
render(<Extension />, document.body);
};

const Extension = () => {
return (
<s-page heading="Cash Drawer API">
<s-scroll-box>
<s-button
onClick={() =>
shopify.cashDrawer.open()
}
>
Open cash drawer
</s-button>
</s-scroll-box>
</s-page>
);
};
2 changes: 2 additions & 0 deletions packages/ui-extensions/src/surfaces/point-of-sale/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export type {

export type {CartLineItemApi} from './api/cart-line-item-api/cart-line-item-api';

export type {CashDrawerApi} from './api/cash-drawer-api/cash-drawer-api';

export type {ActionApi, ActionApiContent} from './api/action-api/action-api';

export type {StandardApi} from './api/standard/standard-api';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* The Cash Drawer API in POS UI extensions includes select cash drawer functionality.
*/
export interface CashDrawerApiContent {
/**
* Opens the connected cash drawer.
*
* @returns Void
*
*/
open(): Promise<void>;
}

/**
* Interface for the Cash Drawer API
*/
export interface CashDrawerApi {
cashDrawer: CashDrawerApiContent;
}