-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2407 from Shopify/njo/pos-print
Add PrintApi and PrintPreview to point-of-sale
- Loading branch information
Showing
16 changed files
with
234 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...es/ui-extensions-react/src/surfaces/point-of-sale/components/PrintPreview/PrintPreview.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { | ||
PrintPreview as BasePrintPreview, | ||
PrintPreviewProps, | ||
} from '@shopify/ui-extensions/point-of-sale'; | ||
import {createRemoteReactComponent} from '@remote-ui/react'; | ||
|
||
export const PrintPreview = createRemoteReactComponent< | ||
typeof BasePrintPreview, | ||
PrintPreviewProps | ||
>(BasePrintPreview); |
42 changes: 42 additions & 0 deletions
42
packages/ui-extensions/docs/surfaces/point-of-sale/reference/apis/print-api.doc.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import {ReferenceEntityTemplateSchema} from '@shopify/generate-docs'; | ||
import {generateCodeBlock} from '../helpers/generateCodeBlock'; | ||
|
||
const generateCodeBlockForPrintApi = (title: string, fileName: string) => | ||
generateCodeBlock(title, 'print-api', fileName); | ||
|
||
const data: ReferenceEntityTemplateSchema = { | ||
name: 'Print API', | ||
description: ` | ||
The Print API provides access to printing functionality. | ||
`, | ||
isVisualComponent: false, | ||
type: 'APIs', | ||
definitions: [ | ||
{ | ||
title: 'PrintApi', | ||
description: '', | ||
type: 'PrintApiContent', | ||
}, | ||
], | ||
category: 'APIs', | ||
related: [ | ||
{ | ||
name: 'PrintPreview Component', | ||
subtitle: 'See how to use the Print API with a PrintPreview.', | ||
url: '/api/pos-ui-extensions/components/printpreview', | ||
}, | ||
], | ||
examples: { | ||
description: 'Examples of using the Print API', | ||
examples: [ | ||
{ | ||
codeblock: generateCodeBlockForPrintApi( | ||
'Print directly from the tile', | ||
'print', | ||
), | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
export default data; |
35 changes: 35 additions & 0 deletions
35
packages/ui-extensions/docs/surfaces/point-of-sale/reference/components/PrintPreview.doc.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import {ReferenceEntityTemplateSchema} from '@shopify/generate-docs'; | ||
import {generateCodeBlock} from '../helpers/generateCodeBlock'; | ||
|
||
const generateCodeBlockForPrintPreview = (title: string, fileName: string) => | ||
generateCodeBlock(title, 'print-preview', fileName); | ||
|
||
const data: ReferenceEntityTemplateSchema = { | ||
name: 'PrintPreview', | ||
description: 'Renders a `PrintPreview`.', | ||
isVisualComponent: true, | ||
type: 'component', | ||
definitions: [ | ||
{ | ||
title: 'PrintPreview', | ||
description: '', | ||
type: 'PrintPreviewProps', | ||
}, | ||
], | ||
category: 'Components', | ||
related: [ | ||
{ | ||
name: 'Print API', | ||
subtitle: 'See how to use the Print API.', | ||
url: '/api/pos-ui-extensions/apis/print-api', | ||
}, | ||
], | ||
defaultExample: { | ||
codeblock: generateCodeBlockForPrintPreview( | ||
'Render a PrintPreview and a button for printing', | ||
'default.example', | ||
), | ||
}, | ||
}; | ||
|
||
export default data; |
14 changes: 14 additions & 0 deletions
14
packages/ui-extensions/docs/surfaces/point-of-sale/reference/examples/print-api/print.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import {Tile, extension} from '@shopify/ui-extensions/point-of-sale'; | ||
|
||
export default extension('pos.home.tile.render', (root, api) => { | ||
const tile = root.createComponent(Tile, { | ||
title: 'My app', | ||
subtitle: 'Hello world!', | ||
enabled: true, | ||
onPress: () => { | ||
api.print.print('/documents/test-print'); | ||
}, | ||
}); | ||
|
||
root.append(tile); | ||
}); |
24 changes: 24 additions & 0 deletions
24
packages/ui-extensions/docs/surfaces/point-of-sale/reference/examples/print-api/print.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React from 'react'; | ||
import { | ||
Tile, | ||
reactExtension, | ||
useApi, | ||
} from '@shopify/ui-extensions-react/point-of-sale'; | ||
|
||
const TileComponent = () => { | ||
const api = useApi(); | ||
return ( | ||
<Tile | ||
title="My app" | ||
subtitle="Hello world!" | ||
onPress={() => { | ||
api.print.print('documents/test-print'); | ||
}} | ||
enabled | ||
/> | ||
); | ||
}; | ||
|
||
export default reactExtension('pos.home.tile.render', () => { | ||
return <TileComponent />; | ||
}); |
38 changes: 38 additions & 0 deletions
38
...xtensions/docs/surfaces/point-of-sale/reference/examples/print-preview/default.example.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { | ||
Button, | ||
PrintPreview, | ||
Screen, | ||
extension, | ||
} from '@shopify/ui-extensions/point-of-sale'; | ||
|
||
export default extension( | ||
'pos.home.modal.render', | ||
(root, api) => { | ||
const homeScreen = root.createComponent( | ||
Screen, | ||
{ | ||
name: 'Home', | ||
title: 'Home', | ||
}, | ||
); | ||
|
||
const printButton = root.createComponent( | ||
Button, | ||
{ | ||
title: 'Print', | ||
onPress: api.print.print, | ||
}, | ||
); | ||
|
||
const printPreview = root.createComponent( | ||
PrintPreview, | ||
{ | ||
src: '/documents/test-print', | ||
}, | ||
); | ||
|
||
homeScreen.append(printPreview); | ||
|
||
root.append(homeScreen); | ||
}, | ||
); |
27 changes: 27 additions & 0 deletions
27
...tensions/docs/surfaces/point-of-sale/reference/examples/print-preview/default.example.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from 'react'; | ||
|
||
import { | ||
Screen, | ||
reactExtension, | ||
Button, | ||
useApi, | ||
} from '@shopify/ui-extensions-react/point-of-sale'; | ||
|
||
const Modal = () => { | ||
const api = useApi<'pos.home.modal.render'>(); | ||
|
||
return ( | ||
<Screen name="Home" title="Home"> | ||
<Button | ||
title="Print" | ||
onPress={api.print.print} | ||
/> | ||
<PrintPreview src="/documents/test-print" /> | ||
</Screen> | ||
); | ||
}; | ||
|
||
export default reactExtension( | ||
'pos.home.modal.render', | ||
() => <Modal />, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
16 changes: 16 additions & 0 deletions
16
packages/ui-extensions/src/surfaces/point-of-sale/api/print-api/print-api.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* Access the print API for printing functionality | ||
*/ | ||
export interface PrintApiContent { | ||
/** Trigger a print dialog | ||
* @param src the source to print. Omit to use the current PrintPreview contents. | ||
*/ | ||
print(src?: string): void; | ||
} | ||
|
||
/** | ||
* Interface for printing | ||
*/ | ||
export interface PrintApi { | ||
print: PrintApiContent; | ||
} |
14 changes: 8 additions & 6 deletions
14
packages/ui-extensions/src/surfaces/point-of-sale/api/standard/standard-api.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
import type {ConnectivityApi} from '../connectivity-api/connectivity-api'; | ||
import type {DeviceApi} from '../device-api/device-api'; | ||
import type {LocaleApi} from '../locale-api/locale-api'; | ||
import type {SessionApi} from '../session-api/session-api'; | ||
import type {ToastApi} from '../toast-api/toast-api'; | ||
import type {ProductSearchApi} from '../product-search-api/product-search-api'; | ||
import {ConnectivityApi} from '../connectivity-api/connectivity-api'; | ||
import {DeviceApi} from '../device-api/device-api'; | ||
import {LocaleApi} from '../locale-api/locale-api'; | ||
import {SessionApi} from '../session-api/session-api'; | ||
import {ToastApi} from '../toast-api/toast-api'; | ||
import {ProductSearchApi} from '../product-search-api/product-search-api'; | ||
import {PrintApi} from '../print-api/print-api'; | ||
|
||
export type StandardApi<T> = {[key: string]: any} & { | ||
extensionPoint: T; | ||
} & LocaleApi & | ||
ToastApi & | ||
SessionApi & | ||
PrintApi & | ||
ProductSearchApi & | ||
DeviceApi & | ||
ConnectivityApi; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
packages/ui-extensions/src/surfaces/point-of-sale/components/PrintPreview/PrintPreview.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import {createRemoteComponent} from '@remote-ui/core'; | ||
|
||
export interface PrintPreviewProps { | ||
/** | ||
* The source to print. | ||
*/ | ||
src: string; | ||
} | ||
|
||
export const PrintPreview = createRemoteComponent< | ||
'PrintPreview', | ||
PrintPreviewProps | ||
>('PrintPreview'); |