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
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
node_modules
/examples/*/build
/examples
Copy link
Member Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

/build
/build-intermediate
/docs
Expand Down
2 changes: 2 additions & 0 deletions UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f

### Enhancements

- Added a new create-react-app example in typescript demonstrating polaris and react-testing ([#1937](https://github.com/Shopify/polaris-react/pull/1937))
- Exported `AppliedFilterInterface` and `FilterInterface` from `Filters` ([#1924](https://github.com/Shopify/polaris-react/pull/1924))
- Improved color contrast of links inside `Banner` ([#1651](https://github.com/Shopify/polaris-react/pull/1651))

Expand All @@ -56,6 +57,7 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f

### Dependency upgrades

- Updated `@shopify/polaris` in all examples to 4.0.0-rc.2 ([#1937](https://github.com/Shopify/polaris-react/pull/1937))
- Added `@material-ui/react-transition-group` and removed `react-transition-group` to support `React.StrictMode` ([#1759](https://github.com/Shopify/polaris-react/pull/1759))
- Added `@shopify/react-testing` ([#1596](https://github.com/Shopify/polaris-react/pull/1596))
- Removed`@shopify/css-utilities` ([#1586](https://github.com/Shopify/polaris-react/pull/1586))
Expand Down
2 changes: 1 addition & 1 deletion examples/cdn-styles/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The CDN hosted CSS file needs to be included in your HTML document. Replace the
```html
<link
rel="stylesheet"
href="https://sdks.shopifycdn.com/polaris/3.20.0/polaris.min.css"
href="https://sdks.shopifycdn.com/polaris/4.0.0-rc.2/polaris.min.css"
/>
```

Expand Down
2 changes: 1 addition & 1 deletion examples/cdn-styles/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Polaris CDN Styles</title>
<link rel="stylesheet" href="https://sdks.shopifycdn.com/polaris/3.20.0/polaris.min.css" />
<link rel="stylesheet" href="https://sdks.shopifycdn.com/polaris/4.0.0-rc.2/polaris.min.css" />
</head>

<body>
Expand Down
1 change: 1 addition & 0 deletions examples/create-react-app-ts-react-testing/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SKIP_PREFLIGHT_CHECK=true
23 changes: 23 additions & 0 deletions examples/create-react-app-ts-react-testing/.gitignore
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*
43 changes: 43 additions & 0 deletions examples/create-react-app-ts-react-testing/README.md
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.
34 changes: 34 additions & 0 deletions examples/create-react-app-ts-react-testing/package.json
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 examples/create-react-app-ts-react-testing/public/index.html
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 examples/create-react-app-ts-react-testing/public/manifest.json
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 examples/create-react-app-ts-react-testing/src/App.test.tsx
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);
});
172 changes: 172 additions & 0 deletions examples/create-react-app-ts-react-testing/src/App.tsx
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"
/>
);
}
Loading