UNPKG

8.84 kBMarkdownView Raw
1# [Polaris React](https://polaris.shopify.com/)
2
3[![npm version](https://img.shields.io/npm/v/@shopify/polaris.svg?style=flat)](https://www.npmjs.com/package/@shopify/polaris) [![Travis build status](https://travis-ci.com/Shopify/polaris-react.svg?branch=master)](https://travis-ci.com/Shopify/polaris-react) [![codecov](https://codecov.io/gh/Shopify/polaris-react/branch/master/graph/badge.svg?token=IKyeKcpRs1)](https://codecov.io/gh/Shopify/polaris-react) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/Shopify/polaris-react/blob/master/.github/CONTRIBUTING.md#your-first-pull-request)
4
5Polaris React is a component library designed to help developers create the best experience for merchants who use Shopify. Visit the [Polaris style guide](https://polaris.shopify.com) to learn more.
6
7## App development
8
9For more information about creating apps for the Shopify App Store, take a look at the [app development documentation](https://developers.shopify.com/app-development).
10
11## Using the React components
12
13While we do offer a CSS-only version, **we strongly recommend using the React versions of our components**. It’s the version that we use at Shopify. It allows for rich, complex components like Tabs and Popovers, and will not have as many breaking changes as the CSS-only version.
14
15### Installation
16
17Run the following command using [npm](https://www.npmjs.com/):
18
19```bash
20npm install @shopify/polaris --save
21```
22
23If you prefer [Yarn](https://yarnpkg.com/en/), use the following command instead:
24
25```bash
26yarn add @shopify/polaris
27```
28
29### Usage
30
311. Import the CSS directly into your project if your asset packager supports it:
32
33```js
34import '@shopify/polaris/dist/styles.css';
35```
36
37Otherwise include the CSS in your HTML. We suggest copying the styles file into your own project, but you may also use it directly:
38
39```html
40<link
41 rel="stylesheet"
42 href="https://unpkg.com/@shopify/polaris@5.8.0/dist/styles.css"
43/>
44```
45
462. Include the translations and any of the provided components in your project:
47
48```js
49import enTranslations from '@shopify/polaris/locales/en.json';
50import {AppProvider, Page, Card, Button} from '@shopify/polaris';
51```
52
533. Tell React to render the element in the DOM:
54
55```js
56ReactDOM.render(
57 <AppProvider i18n={enTranslations}>
58 <Page title="Example app">
59 <Card sectioned>
60 <Button onClick={() => alert('Button clicked!')}>Example button</Button>
61 </Card>
62 </Page>
63 </AppProvider>,
64 document.querySelector('#app'),
65);
66```
67
68## Using the CSS components
69
70If React doesn’t make sense for your application, you can use a CSS-only version of our components. This includes all the styles you need for every component in the library, but you’ll be responsible for writing the correct markup and updating classes and DOM attributes in response to user events.
71
72### Usage
73
741. Include the CSS in your HTML. We suggest copying the styles file into your own project, but you may also use it directly:
75
76```html
77<link
78 rel="stylesheet"
79 href="https://unpkg.com/@shopify/polaris@5.8.0/dist/styles.css"
80/>
81```
82
832. Include the markup and associated classes in your HTML document:
84
85```html
86<button class="Polaris-Button">Example button</button>
87```
88
89## Examples
90
91We have created example applications to document some of the ways you could include Polaris in one of your own applications. Each of these examples includes further documentation on how to install dependencies and run the app:
92
93- [create-react-app example](https://github.com/Shopify/polaris-react/tree/master/examples/create-react-app)
94- [create-react-app with TypeScript and react-testing example](https://github.com/Shopify/polaris-react/tree/master/examples/create-react-app-ts-react-testing)
95- [Webpack example](https://github.com/Shopify/polaris-react/tree/master/examples/webpack)
96- [CSS-only example](https://github.com/Shopify/polaris-react/tree/master/examples/cdn-styles)
97- [next.js example](https://github.com/Shopify/polaris-react/tree/master/examples/next.js)
98
99## Development
100
101We use Storybook to create a simple, hot-reloading playground for development on these components. You can edit the `playground/Playground.tsx` file to import the components you are working on, and run `yarn dev` in order to start the development server. Please do not commit your work on the playground so that it remains pristine for other developers to work on.
102
103### Testing on mobile or a virtual machine
104
105To test the changes on a mobile or virtual machine, you will need to open the source of the iFrame, to do this:
106
1071. Run `yarn dev`
1081. Make sure your virtual machine and mobile device are on the same network
1091. Open http://YOUR_IP_ADDRESS:ASSIGNED_PORT/iframe.html?selectedKind=Playground&selectedStory=Playground in your mobile device or virtual machine
110
111### Testing in a consuming project
112
1131. In your terminal, run `yarn run build-consumer PROJECT_DIRECTORY` from the polaris-react repo
114
115`PROJECT_DIRECTORY` is where the build will be copied, which must be a sibling of the `polaris-react` directory.
116
117```sh
118# Example
119yarn run build-consumer polaris-styleguide
120```
121
1222. In your terminal, open a second tab and run `yarn run dev` from the `polaris-styleguide` repository
123
124In the example above, the build is copied to `polaris-styleguide/node_modules/@shopify/polaris`. And in this case, a rebuild of `polaris-styleguide` is required after copying the `polaris-react` build, but may not be the case for all consuming projects.
125
126```sh
127# Example
128cd ../polaris-styleguide/
129yarn run build:development
130```
131
132Also, when running `yarn install`, copied builds will be overwritten and will require running `yarn run build-consumer PROJECT_DIRECTORY` again.
133
134### Visual regression testing
135
136[Percy](https://percy.io/) runs for every pull request. Percy is a tool that compares screenshots for every single component we have in the library.
137
138Percy is not always 100% accurate. Since it uses screenshot comparison, even browser sub-pixel rendering differences can cause Percy to ask for user confirmation of whether a change was intended or not. In cases like that, use your best judgment to determine whether you need to address it or not. This is why the choice to approve something or not is always manual. While everyone can view changes, only members of the Shopify team can approve changes.
139
140#### Manual visual regression testing
141
142To start a server for manually viewing the visual regression testing examples, run `yarn run dev`.
143
144## Learning resources
145
146If you’re new to React, we recommend you start with the [official React Getting Started documentation](https://facebook.github.io/react/docs/hello-world.html). As you read through the topics we suggest you follow along using their [React Hello World CodePen example](http://codepen.io/gaearon/pen/ZpvBNJ?editors=0010).
147
148Additional resources:
149
150- Online training courses at [reacttraining.com](http://reacttraining.com), [buildwithreact.com](http://buildwithreact.com), and [reactforbeginners.com](http://reactforbeginners.com).
151- The community resources in [Awesome React](https://github.com/enaqx/awesome-react).
152- As questions and find answers in the various [React support communities](https://facebook.github.io/react/community/support.html).
153
154## Methodology
155
156We set out to make our components easy to use. Each of our components has a well-documented (and fully typed) public interface with strong, consistently-applied conventions. This way, developers don’t need to worry about the underlying implementation. Instead, they can focus on creating amazing merchant experiences.
157
158We ensure that our components are made for everyone. They meet accessibility standards and are responsive to any screen or device. We also put a lot of effort into optimizing the performance of the components, so everyone can build inclusive experiences that work.
159
160We make our components flexible enough to meet diverse needs. They present the information you pass in and give you smart callbacks when something has changed, but they don’t enforce any structure beyond that. No matter what type of experience you’re creating, you can use components as the building blocks of your product or feature.
161
162## Contributing
163
164Pull requests are welcome. See the [contribution guidelines](https://github.com/Shopify/polaris-react/blob/master/.github/CONTRIBUTING.md) for more information.
165
166## Licenses
167
168- Source code is under a [custom license](https://github.com/Shopify/polaris-react/blob/master/LICENSE.md) based on MIT. The license restricts Polaris usage to applications that integrate or interoperate with Shopify software or services, with additional restrictions for external, stand-alone applications.
169- All icons and images are licensed under the [Polaris Design Guidelines License Agreement](https://polaris.shopify.com/legal/license)