-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Update examples to v4 & add ts-react-testing example #1937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,5 +1,5 @@ | ||
node_modules | ||
/examples/*/build | ||
/examples | ||
/build | ||
/build-intermediate | ||
/docs | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 @@ | ||
SKIP_PREFLIGHT_CHECK=true |
This file contains hidden or 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,23 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* |
This file contains hidden or 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 @@ | ||
# Example App: Create React App | ||
|
||
Demonstrates Polaris and react-testing inside a [create-react-app](https://github.com/facebookincubator/create-react-app) project with minimal setup and configuration. | ||
|
||
## Dependencies | ||
|
||
- [yarn](https://github.com/yarnpkg/yarn/) or [npm](https://www.npmjs.com/) | ||
|
||
## Getting started | ||
|
||
### Installation | ||
|
||
Install all the project dependencies. | ||
|
||
**With Yarn** | ||
|
||
```bash | ||
yarn install | ||
``` | ||
|
||
**With npm** | ||
|
||
```bash | ||
npm install | ||
``` | ||
|
||
### Development | ||
|
||
Run the local `create-react-app` development server with Polaris preconfigured. | ||
|
||
**With Yarn** | ||
|
||
```bash | ||
yarn start | ||
``` | ||
|
||
**With npm** | ||
|
||
```bash | ||
npm start | ||
``` | ||
|
||
Open **http://localhost:3000** in your browser and you should see the Polaris example application. |
This file contains hidden or 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,34 @@ | ||
{ | ||
"name": "create-react-app-ts-react-testing", | ||
"version": "0.1.0", | ||
"private": true, | ||
"dependencies": { | ||
"@shopify/polaris": "^4.0.0-rc.2", | ||
"@types/jest": "24.0.15", | ||
"@types/node": "12.6.5", | ||
"@types/react": "16.8.23", | ||
"@types/react-dom": "16.8.4", | ||
"react": "^16.8.6", | ||
"react-dom": "^16.8.6", | ||
"react-scripts": "3.0.1", | ||
"typescript": "3.5.3" | ||
}, | ||
"scripts": { | ||
"start": "react-scripts start", | ||
"build": "react-scripts build", | ||
"test": "react-scripts test", | ||
"eject": "react-scripts eject" | ||
}, | ||
"browserslist": { | ||
"production": [ | ||
">0.2%", | ||
"not dead", | ||
"not op_mini all" | ||
], | ||
"development": [ | ||
"last 1 chrome version", | ||
"last 1 firefox version", | ||
"last 1 safari version" | ||
] | ||
} | ||
} |
Binary file not shown.
38 changes: 38 additions & 0 deletions
38
examples/create-react-app-ts-react-testing/public/index.html
This file contains hidden or 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 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<meta name="theme-color" content="#000000" /> | ||
<!-- | ||
manifest.json provides metadata used when your web app is installed on a | ||
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/ | ||
--> | ||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" /> | ||
<!-- | ||
Notice the use of %PUBLIC_URL% in the tags above. | ||
It will be replaced with the URL of the `public` folder during the build. | ||
Only files inside the `public` folder can be referenced from the HTML. | ||
|
||
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will | ||
work correctly both with client-side routing and a non-root public URL. | ||
Learn how to configure a non-root public URL by running `npm run build`. | ||
--> | ||
<title>Polaris: create-react-app</title> | ||
</head> | ||
<body> | ||
<noscript>You need to enable JavaScript to run this app.</noscript> | ||
<div id="root"></div> | ||
<!-- | ||
This HTML file is a template. | ||
If you open it directly in the browser, you will see an empty page. | ||
|
||
You can add webfonts, meta tags, or analytics to this file. | ||
The build step will place the bundled scripts into the <body> tag. | ||
|
||
To begin the development, run `npm start` or `yarn start`. | ||
To create a production bundle, use `npm run build` or `yarn build`. | ||
--> | ||
</body> | ||
</html> |
15 changes: 15 additions & 0 deletions
15
examples/create-react-app-ts-react-testing/public/manifest.json
This file contains hidden or 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,15 @@ | ||
{ | ||
"short_name": "Polaris App", | ||
"name": "Poalris Create React App Sample", | ||
"icons": [ | ||
{ | ||
"src": "favicon.ico", | ||
"sizes": "64x64 32x32 24x24 16x16", | ||
"type": "image/x-icon" | ||
} | ||
], | ||
"start_url": ".", | ||
"display": "standalone", | ||
"theme_color": "#000000", | ||
"background_color": "#ffffff" | ||
} |
10 changes: 10 additions & 0 deletions
10
examples/create-react-app-ts-react-testing/src/App.test.tsx
This file contains hidden or 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 React from 'react'; | ||
import {Page} from '@shopify/polaris'; | ||
import {mount} from './tests/utils/react-testing'; | ||
import App from './App'; | ||
|
||
// Sample test to demonstrate how you should test with react-testing & Polaris | ||
test('renders page', () => { | ||
const wrapper = mount(<App />); | ||
expect(wrapper).toContainReactComponent(Page); | ||
}); |
This file contains hidden or 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,172 @@ | ||
import React, {useState, useCallback} from 'react'; | ||
import { | ||
Layout, | ||
Page, | ||
FooterHelp, | ||
Card, | ||
Link, | ||
Button, | ||
FormLayout, | ||
TextField, | ||
AccountConnection, | ||
ChoiceList, | ||
SettingToggle, | ||
} from '@shopify/polaris'; | ||
import {ImportMinor} from '@shopify/polaris-icons'; | ||
|
||
interface AccountProps { | ||
onAction(): void; | ||
} | ||
|
||
export default function App() { | ||
const [first, setFirst] = useState(''); | ||
const [last, setLast] = useState(''); | ||
const [email, setEmail] = useState(''); | ||
const [checkboxes, setCheckboxes] = useState([]); | ||
const [connected, setConnected] = useState(false); | ||
|
||
const handleFirstChange = useCallback((value) => setFirst(value), []); | ||
const handleLastChange = useCallback((value) => setLast(value), []); | ||
const handleEmailChange = useCallback((value) => setEmail(value), []); | ||
const handleCheckboxesChange = useCallback( | ||
(value) => setCheckboxes(value), | ||
[], | ||
); | ||
|
||
const toggleConnection = useCallback( | ||
() => { | ||
setConnected(!connected); | ||
}, | ||
[connected], | ||
); | ||
|
||
const breadcrumbs = [ | ||
{content: 'Sample apps', url: '/sample-apps'}, | ||
{content: 'Create React App', url: '/create-react-app'}, | ||
]; | ||
const primaryAction = {content: 'New product'}; | ||
const secondaryActions = [{content: 'Import', icon: ImportMinor}]; | ||
|
||
const choiceListItems = [ | ||
{label: 'I accept the Terms of Service', value: 'false'}, | ||
{label: 'I consent to receiving emails', value: 'false2'}, | ||
]; | ||
|
||
const accountSectionDescription = connected | ||
? 'Disconnect your account from your Shopify store.' | ||
: 'Connect your account to your Shopify store.'; | ||
|
||
const accountMarkup = connected ? ( | ||
<DisconnectAccount onAction={toggleConnection} /> | ||
) : ( | ||
<ConnectAccount onAction={toggleConnection} /> | ||
); | ||
|
||
return ( | ||
<Page | ||
title="Polaris" | ||
breadcrumbs={breadcrumbs} | ||
primaryAction={primaryAction} | ||
secondaryActions={secondaryActions} | ||
> | ||
<Layout> | ||
<Layout.AnnotatedSection | ||
title="Style" | ||
description="Customize the style of your checkout" | ||
> | ||
<SettingToggle | ||
action={{ | ||
content: 'Customize Checkout', | ||
}} | ||
> | ||
Upload your store’s logo, change colors and fonts, and more. | ||
</SettingToggle> | ||
</Layout.AnnotatedSection> | ||
|
||
<Layout.AnnotatedSection | ||
title="Account" | ||
description={accountSectionDescription} | ||
> | ||
{accountMarkup} | ||
</Layout.AnnotatedSection> | ||
|
||
<Layout.AnnotatedSection | ||
title="Form" | ||
description="A sample form using Polaris components." | ||
> | ||
<Card sectioned> | ||
<FormLayout> | ||
<FormLayout.Group> | ||
<TextField | ||
value={first} | ||
label="First name" | ||
placeholder="Tom" | ||
onChange={handleFirstChange} | ||
/> | ||
<TextField | ||
value={last} | ||
label="Last name" | ||
placeholder="Ford" | ||
onChange={handleLastChange} | ||
/> | ||
</FormLayout.Group> | ||
|
||
<TextField | ||
value={email} | ||
label="Email" | ||
placeholder="example@email.com" | ||
onChange={handleEmailChange} | ||
/> | ||
|
||
<ChoiceList | ||
title="Terms & Consent" | ||
titleHidden | ||
allowMultiple | ||
choices={choiceListItems} | ||
selected={checkboxes} | ||
onChange={handleCheckboxesChange} | ||
/> | ||
|
||
<Button primary>Submit</Button> | ||
</FormLayout> | ||
</Card> | ||
</Layout.AnnotatedSection> | ||
|
||
<Layout.Section> | ||
<FooterHelp> | ||
For more details on Polaris, visit our{' '} | ||
<Link url="https://polaris.shopify.com">style guide</Link>. | ||
</FooterHelp> | ||
</Layout.Section> | ||
</Layout> | ||
</Page> | ||
); | ||
} | ||
|
||
function ConnectAccount({onAction}: AccountProps) { | ||
return ( | ||
<AccountConnection | ||
action={{content: 'Connect', onAction}} | ||
details="No account connected" | ||
termsOfService={ | ||
<p> | ||
By clicking Connect, you are accepting Sample’s{' '} | ||
<Link url="https://polaris.shopify.com">Terms and Conditions</Link>, | ||
including a commission rate of 15% on sales. | ||
</p> | ||
} | ||
/> | ||
); | ||
} | ||
|
||
function DisconnectAccount({onAction}: AccountProps) { | ||
return ( | ||
<AccountConnection | ||
connected | ||
action={{content: 'Disconnect', onAction}} | ||
accountName="Tom Ford" | ||
title={<Link url="http://google.com">Tom Ford</Link>} | ||
details="Account id: d587647ae4" | ||
/> | ||
); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our examples are to be run independently, we shouldn't link based on our repo's rules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯