-
Notifications
You must be signed in to change notification settings - Fork 37
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 #2006 from Shopify/js-section-scrollview
Added docs and examples for scrollview and section
- Loading branch information
Showing
7 changed files
with
245 additions
and
0 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
42 changes: 42 additions & 0 deletions
42
...-extensions/docs/surfaces/point-of-sale/reference/examples/scroll-view/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,42 @@ | ||
import { | ||
extension, | ||
Screen, | ||
ScrollView, | ||
Stack, | ||
Navigator, | ||
Text, | ||
} from '@shopify/ui-extensions/point-of-sale'; | ||
|
||
export default extension( | ||
'pos.home.modal.render', | ||
(root) => { | ||
const screen = root.createComponent(Screen, { | ||
name: 'ScrollView', | ||
title: 'ScrollView', | ||
}); | ||
|
||
const scrollView = | ||
root.createComponent(ScrollView); | ||
|
||
for (let i = 0; i < 25; i++) { | ||
const stack = root.createComponent(Stack, { | ||
paddingVertical: 'Small', | ||
direction: 'vertical', | ||
paddingHorizontal: 'Small', | ||
}); | ||
|
||
const textElement = | ||
root.createComponent(Text); | ||
textElement.append(`Text element ${i}`); | ||
|
||
stack.append(textElement); | ||
scrollView.append(stack); | ||
} | ||
|
||
screen.append(scrollView); | ||
const navigator = | ||
root.createComponent(Navigator); | ||
navigator.append(screen); | ||
root.append(navigator); | ||
}, | ||
); |
47 changes: 47 additions & 0 deletions
47
...extensions/docs/surfaces/point-of-sale/reference/examples/scroll-view/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,47 @@ | ||
import React, {ReactNode} from 'react'; | ||
import { | ||
Text, | ||
Navigator, | ||
Screen, | ||
ScrollView, | ||
Stack, | ||
reactExtension, | ||
} from '@shopify/ui-extensions-react/point-of-sale'; | ||
|
||
const ModalComponent = () => { | ||
const textElement = ( | ||
count: number, | ||
): ReactNode => { | ||
return ( | ||
<Stack | ||
direction="vertical" | ||
paddingHorizontal="Small" | ||
paddingVertical="Small" | ||
> | ||
<Text>{`Text element ${count}`}</Text> | ||
</Stack> | ||
); | ||
}; | ||
|
||
return ( | ||
<Navigator> | ||
<Screen | ||
title="ScrollView" | ||
name="ScrollView" | ||
> | ||
<ScrollView> | ||
{Array.from(Array(25)).map((_, count) => | ||
textElement(count), | ||
)} | ||
</ScrollView> | ||
</Screen> | ||
</Navigator> | ||
); | ||
}; | ||
|
||
export default reactExtension( | ||
'pos.home.modal.render', | ||
() => { | ||
return <ModalComponent />; | ||
}, | ||
); |
74 changes: 74 additions & 0 deletions
74
...s/ui-extensions/docs/surfaces/point-of-sale/reference/examples/section/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,74 @@ | ||
import { | ||
extension, | ||
Screen, | ||
ScrollView, | ||
Stack, | ||
Navigator, | ||
Text, | ||
Section, | ||
Selectable, | ||
} from '@shopify/ui-extensions/point-of-sale'; | ||
|
||
export default extension( | ||
'pos.home.modal.render', | ||
(root, api) => { | ||
const screen = root.createComponent(Screen, { | ||
name: 'Section', | ||
title: 'Section', | ||
}); | ||
|
||
const scrollView = | ||
root.createComponent(ScrollView); | ||
|
||
const section = root.createComponent( | ||
Section, | ||
{ | ||
title: 'Section', | ||
action: { | ||
title: 'Show toast', | ||
onPress: () => | ||
api.toast.show('Hello world!'), | ||
}, | ||
}, | ||
); | ||
|
||
for (let i = 1; i < 5; i++) { | ||
const selectable = root.createComponent( | ||
Selectable, | ||
{ | ||
onPress: () => | ||
api.toast.show(`Item ${i}!`), | ||
}, | ||
); | ||
const stack = root.createComponent(Stack, { | ||
paddingVertical: 'Small', | ||
direction: 'vertical', | ||
paddingHorizontal: 'Small', | ||
}); | ||
|
||
const textElement = | ||
root.createComponent(Text); | ||
textElement.append(`Item ${i}`); | ||
|
||
stack.append(textElement); | ||
selectable.append(stack); | ||
section.append(selectable); | ||
} | ||
|
||
const rootStack = root.createComponent( | ||
Stack, | ||
{ | ||
paddingHorizontal: 'HalfPoint', | ||
direction: 'vertical', | ||
}, | ||
); | ||
rootStack.append(section); | ||
|
||
scrollView.append(rootStack); | ||
screen.append(scrollView); | ||
const navigator = | ||
root.createComponent(Navigator); | ||
navigator.append(screen); | ||
root.append(navigator); | ||
}, | ||
); |
43 changes: 43 additions & 0 deletions
43
.../ui-extensions/docs/surfaces/point-of-sale/reference/examples/section/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,43 @@ | ||
import React from 'react' | ||
import { Text, Navigator, Screen, ScrollView, Stack, reactExtension, Section, useApi, Selectable } from '@shopify/ui-extensions-react/point-of-sale' | ||
|
||
const ModalComponent = () => { | ||
const api = useApi<'pos.home.modal.render'>(); | ||
|
||
return ( | ||
<Navigator> | ||
<Screen title="Section" name="Section"> | ||
<ScrollView> | ||
<Stack direction="vertical" paddingHorizontal="HalfPoint"> | ||
<Section title='Items' action={{title: "Show toast", onPress: () => api.toast.show('Hello world!')}}> | ||
<Selectable onPress={() => api.toast.show('Item 1!')}> | ||
<Stack direction="vertical" paddingHorizontal="Small" paddingVertical="Small"> | ||
<Text>Item 1</Text> | ||
</Stack> | ||
</Selectable> | ||
<Selectable onPress={() => api.toast.show('Item 2!')}> | ||
<Stack direction="vertical" paddingHorizontal="Small" paddingVertical="Small"> | ||
<Text>Item 2</Text> | ||
</Stack> | ||
</Selectable> | ||
<Selectable onPress={() => api.toast.show('Item 3!')}> | ||
<Stack direction="vertical" paddingHorizontal="Small" paddingVertical="Small"> | ||
<Text>Item 3</Text> | ||
</Stack> | ||
</Selectable> | ||
<Selectable onPress={() => api.toast.show('Item 4!')}> | ||
<Stack direction="vertical" paddingHorizontal="Small" paddingVertical="Small"> | ||
<Text>Item 4</Text> | ||
</Stack> | ||
</Selectable> | ||
</Section> | ||
</Stack> | ||
</ScrollView> | ||
</Screen> | ||
</Navigator> | ||
) | ||
} | ||
|
||
export default reactExtension('pos.home.modal.render', () => { | ||
return <ModalComponent /> | ||
}) |
20 changes: 20 additions & 0 deletions
20
packages/ui-extensions/src/surfaces/point-of-sale/components/Section/Section.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