├── .gitignore
├── create-react-app-example
├── .gitignore
├── README.md
├── favicon.ico
├── index.html
├── package.json
├── reactcards
│ ├── card.js
│ └── entry.js
├── src
│ ├── App.css
│ ├── App.js
│ ├── index.css
│ ├── index.js
│ └── logo.svg
└── test
│ └── App.js
├── package.json
├── src
├── cards.js
├── components.js
└── main.js
└── test
├── advanced.js
├── components.js
├── index.js
└── simple.js
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 |
--------------------------------------------------------------------------------
/create-react-app-example/.gitignore:
--------------------------------------------------------------------------------
1 | # See http://help.github.com/ignore-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | node_modules
5 |
6 | # production
7 | build
8 |
9 | # misc
10 | .DS_Store
11 | npm-debug.log
12 |
--------------------------------------------------------------------------------
/create-react-app-example/README.md:
--------------------------------------------------------------------------------
1 | Below you will find some information on how to perform common tasks.
2 | You can find the most recent version of this guide [here](https://github.com/facebookincubator/create-react-app/blob/master/template/README.md).
3 |
4 | ## Sending Feedback
5 |
6 | We are always open to [your feedback](https://github.com/facebookincubator/create-react-app/issues).
7 |
8 | ## Folder Structure
9 |
10 | After creation, your project should look like this:
11 |
12 | ```
13 | my-app/
14 | README.md
15 | index.html
16 | favicon.ico
17 | node_modules/
18 | package.json
19 | src/
20 | App.css
21 | App.js
22 | index.css
23 | index.js
24 | logo.svg
25 | ```
26 |
27 | For the project to build, **these files must exist with exact filenames**:
28 |
29 | * `index.html` is the page template;
30 | * `favicon.ico` is the icon you see in the browser tab;
31 | * `src/index.js` is the JavaScript entry point.
32 |
33 | You can delete or rename the other files.
34 |
35 | You may create subdirectories inside `src`. For faster rebuilds, only files inside `src` are processed by Webpack.
36 | You need to **put any JS and CSS files inside `src`**, or Webpack won’t see them.
37 |
38 | You can, however, create more top-level directories.
39 | They will not be included in the production build so you can use them for things like documentation.
40 |
41 | >**Known Issue:**
42 | >
43 | >You may encounter an issue where changing a file inside `src` doesn’t trigger a recompilation. Most likely this happens because the path in your filesystem differs in its casing from the path you imported. For example, if a file is called `App.js` but you are importing `app.js`, the watcher might not recognize changes to it. We are [considering](https://github.com/facebookincubator/create-react-app/issues/240) enforcing some checks to prevent this. If this doesn’t help, check out the page on [troubleshooting watching](https://webpack.github.io/docs/troubleshooting.html#watching).
44 |
45 | ## Available Scripts
46 |
47 | In the project directory, you can run:
48 |
49 | ### `npm start`
50 |
51 | Runs the app in the development mode.
52 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
53 |
54 | The page will reload if you make edits.
55 | You will also see any lint errors in the console.
56 |
57 | ### `npm run build`
58 |
59 | Builds the app for production to the `build` folder.
60 | It correctly bundles React in production mode and optimizes the build for the best performance.
61 |
62 | The build is minified and the filenames include the hashes.
63 | Your app is ready to be deployed!
64 |
65 | ### `npm run eject`
66 |
67 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!**
68 |
69 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
70 |
71 | Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
72 |
73 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
74 |
75 | ## How To...
76 |
77 | ### Install a Dependency
78 |
79 | The generated project includes React and ReactDOM as dependencies. It also includes a set of scripts used by Create React App as a development dependency. You may install other dependencies (for example, React Router) with `npm`:
80 |
81 | ```
82 | npm install --save
83 | ```
84 |
85 | ### Import a Component
86 |
87 | This project setup supports ES6 modules thanks to Babel.
88 | While you can still use `require()` and `module.exports`, we encourage you to use [`import` and `export`](http://exploringjs.com/es6/ch_modules.html) instead.
89 |
90 | For example:
91 |
92 | ### `Button.js`
93 |
94 | ```js
95 | import React, { Component } from 'react';
96 |
97 | class Button extends Component {
98 | render() {
99 | // ...
100 | }
101 | }
102 |
103 | export default Button; // Don’t forget to use export default!
104 | ```
105 |
106 | ### `DangerButton.js`
107 |
108 | ```js
109 | import React, { Component } from 'react';
110 | import Button from './Button'; // Import a component from another file
111 |
112 | class DangerButton extends Component {
113 | render() {
114 | return ;
115 | }
116 | }
117 |
118 | export default DangerButton;
119 | ```
120 |
121 | Be aware of the [difference between default and named exports](http://stackoverflow.com/questions/36795819/react-native-es-6-when-should-i-use-curly-braces-for-import/36796281#36796281). It is a common source of mistakes.
122 |
123 | We suggest that you stick to using default imports and exports when a module only exports a single thing (for example, a component). That’s what you get when you use `export default Button` and `import Button from './Button'`.
124 |
125 | Named exports are useful for utility modules that export several functions. A module may have at most one default export and as many named exports as you like.
126 |
127 | Learn more about ES6 modules:
128 |
129 | * [When to use the curly braces?](http://stackoverflow.com/questions/36795819/react-native-es-6-when-should-i-use-curly-braces-for-import/36796281#36796281)
130 | * [Exploring ES6: Modules](http://exploringjs.com/es6/ch_modules.html)
131 | * [Understanding ES6: Modules](https://leanpub.com/understandinges6/read#leanpub-auto-encapsulating-code-with-modules)
132 |
133 | ### Add a Stylesheet
134 |
135 | This project setup uses [Webpack](https://webpack.github.io/) for handling all assets. Webpack offers a custom way of “extending” the concept of `import` beyond JavaScript. To express that a JavaScript file depends on a CSS file, you need to **import the CSS from the JavaScript file**:
136 |
137 | #### `Button.css`
138 |
139 | ```css
140 | .Button {
141 | padding: 20px;
142 | }
143 | ```
144 |
145 | #### `Button.js`
146 |
147 | ```js
148 | import React, { Component } from 'react';
149 | import './Button.css'; // Tell Webpack that Button.js uses these styles
150 |
151 | class Button extends Component {
152 | render() {
153 | // You can use them as regular CSS styles
154 | return ;
155 | }
156 | }
157 | ```
158 |
159 | **This is not required for React** but many people find this feature convenient. You can read about the benefits of this approach [here](https://medium.com/seek-ui-engineering/block-element-modifying-your-javascript-components-d7f99fcab52b). However you should be aware that this makes your code less portable to other build tools and environments than Webpack.
160 |
161 | In development, expressing dependencies this way allows your styles to be reloaded on the fly as you edit them. In production, all CSS files will be concatenated into a single minified `.css` file in the build output.
162 |
163 | If you are concerned about using Webpack-specific semantics, you can put all your CSS right into `src/index.css`. It would still be imported from `src/index.js`, but you could always remove that import if you later migrate to a different build tool.
164 |
165 | ### Post-Process CSS
166 |
167 | This project setup minifies your CSS and adds vendor prefixes to it automatically through [Autoprefixer](https://github.com/postcss/autoprefixer) so you don’t need to worry about it.
168 |
169 | For example, this:
170 |
171 | ```css
172 | .App {
173 | display: flex;
174 | flex-direction: row;
175 | align-items: center;
176 | }
177 | ```
178 |
179 | becomes this:
180 |
181 | ```css
182 | .App {
183 | display: -webkit-box;
184 | display: -ms-flexbox;
185 | display: flex;
186 | -webkit-box-orient: horizontal;
187 | -webkit-box-direction: normal;
188 | -ms-flex-direction: row;
189 | flex-direction: row;
190 | -webkit-box-align: center;
191 | -ms-flex-align: center;
192 | align-items: center;
193 | }
194 | ```
195 |
196 | There is currently no support for preprocessors such as Less, or for sharing variables across CSS files.
197 |
198 | ### Add Images and Fonts
199 |
200 | With Webpack, using static assets like images and fonts works similarly to CSS.
201 |
202 | You can **`import` an image right in a JavaScript module**. This tells Webpack to include that image in the bundle. Unlike CSS imports, importing an image or a font gives you a string value. This value is the final image path you can reference in your code.
203 |
204 | Here is an example:
205 |
206 | ```js
207 | import React from 'react';
208 | import logo from './logo.png'; // Tell Webpack this JS file uses this image
209 |
210 | console.log(logo); // /logo.84287d09.png
211 |
212 | function Header() {
213 | // Import result is the URL of your image
214 | return ;
215 | }
216 |
217 | export default function Header;
218 | ```
219 |
220 | This works in CSS too:
221 |
222 | ```css
223 | .Logo {
224 | background-image: url(./logo.png);
225 | }
226 | ```
227 |
228 | Webpack finds all relative module references in CSS (they start with `./`) and replaces them with the final paths from the compiled bundle. If you make a typo or accidentally delete an important file, you will see a compilation error, just like when you import a non-existent JavaScript module. The final filenames in the compiled bundle are generated by Webpack from content hashes. If the file content changes in the future, Webpack will give it a different name in production so you don’t need to worry about long-term caching of assets.
229 |
230 | Please be advised that this is also a custom feature of Webpack.
231 |
232 | **It is not required for React** but many people enjoy it (and React Native uses a similar mechanism for images). However it may not be portable to some other environments, such as Node.js and Browserify. If you prefer to reference static assets in a more traditional way outside the module system, please let us know [in this issue](https://github.com/facebookincubator/create-react-app/issues/28), and we will consider support for this.
233 |
234 | ### Install React Bootstrap
235 |
236 | You don’t have to use React Bootstrap together with React but it is a popular library for integrating Bootstrap with React apps. If you need it, you can integrate it with Create React App by following these steps:
237 |
238 | **Step 1.** Install React Bootstrap and Bootstrap from NPM. React Bootstrap does not include Bootstrap CSS so this needs to be installed as well.
239 |
240 | ```
241 | npm install react-bootstrap --save
242 | npm install bootstrap@3 --save
243 | ```
244 |
245 | **Step 2.** Import Bootstrap CSS and optionally Bootstrap theme CSS in the ```index.js``` file.
246 |
247 | ```
248 | import './index.css';
249 | import 'bootstrap/dist/css/bootstrap.css';
250 | import 'bootstrap/dist/css/bootstrap-theme.css';
251 | ```
252 |
253 | **Step 3.** Import required React Bootstrap components within ```App.js``` file or your custom component files.
254 |
255 | ```
256 | import React, { Component } from 'react';
257 | import { Navbar, Jumbotron, Button } from 'react-bootstrap';
258 | ```
259 |
260 | Now you are ready to use the imported React Bootstrap components within your component hierarchy defined in the render method. Here is an example [App.js](https://github.com/manavsehgal/react-eshop/blob/master/src/App.js) redone using React Bootstrap.
261 |
262 | ### Display Lint Output in the Editor
263 |
264 | >Note: this feature is available with `react-scripts@0.2.0` and higher.
265 |
266 | Some editors, including Sublime Text, Atom, and Visual Studio Code, provide plugins for ESLint.
267 |
268 | They are not required for linting. You should see the linter output right in your terminal as well as the browser console. However, if you prefer the lint results to appear right in your editor, there are some extra steps you can do.
269 |
270 | You would need to install an ESLint plugin for your editor first.
271 | Then make sure `package.json` of your project ends with this block:
272 |
273 | ```js
274 | {
275 | // ...
276 | "eslintConfig": {
277 | "extends": "./node_modules/react-scripts/config/eslint.js"
278 | }
279 | }
280 | ```
281 |
282 | Projects generated with `react-scripts@0.2.0` and higher should already have it.
283 | If you don’t need ESLint integration with your editor, you can safely delete those three lines from your `package.json`.
284 |
285 | Finally, you will need to install some packages *globally*:
286 |
287 | ```sh
288 | npm install -g eslint babel-eslint eslint-plugin-react eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-flowtype
289 | ```
290 |
291 | We recognize that this is suboptimal, but it is currently required due to the way we hide the ESLint dependency. The ESLint team is already [working on a solution to this](https://github.com/eslint/eslint/issues/3458) so this may become unnecessary in a couple of months.
292 |
293 | ### Add Flow
294 |
295 | Flow typing is currently [not supported out of the box](https://github.com/facebookincubator/create-react-app/issues/72) with the default `.flowconfig` generated by Flow. If you run it, you might get errors like this:
296 |
297 | ```
298 | node_modules/fbjs/lib/Deferred.js.flow:60
299 | 60: Promise.prototype.done.apply(this._promise, arguments);
300 | ^^^^ property `done`. Property not found in
301 | 495: declare class Promise<+R> {
302 | ^ Promise. See lib: /private/tmp/flow/flowlib_34952d31/core.js:495
303 |
304 | node_modules/fbjs/lib/shallowEqual.js.flow:29
305 | 29: return x !== 0 || 1 / (x: $FlowIssue) === 1 / (y: $FlowIssue);
306 | ^^^^^^^^^^ identifier `$FlowIssue`. Could not resolve name
307 |
308 | src/App.js:3
309 | 3: import logo from './logo.svg';
310 | ^^^^^^^^^^^^ ./logo.svg. Required module not found
311 |
312 | src/App.js:4
313 | 4: import './App.css';
314 | ^^^^^^^^^^^ ./App.css. Required module not found
315 |
316 | src/index.js:5
317 | 5: import './index.css';
318 | ^^^^^^^^^^^^^ ./index.css. Required module not found
319 | ```
320 |
321 | To fix this, change your `.flowconfig` to look like this:
322 |
323 | ```
324 | [libs]
325 | ./node_modules/fbjs/flow/lib
326 |
327 | [options]
328 | esproposal.class_static_fields=enable
329 | esproposal.class_instance_fields=enable
330 |
331 | module.name_mapper='^\(.*\)\.css$' -> 'react-scripts/config/flow/css'
332 | module.name_mapper='^\(.*\)\.\(jpg\|png\|gif\|eot\|svg\|ttf\|woff\|woff2\|mp4\|webm\)$' -> 'react-scripts/config/flow/file'
333 |
334 | suppress_type=$FlowIssue
335 | suppress_type=$FlowFixMe
336 | ```
337 |
338 | Re-run flow, and you shouldn’t get any extra issues.
339 |
340 | If you later `eject`, you’ll need to replace `react-scripts` references with the `` placeholder, for example:
341 |
342 | ```
343 | module.name_mapper='^\(.*\)\.css$' -> '/config/flow/css'
344 | module.name_mapper='^\(.*\)\.\(jpg\|png\|gif\|eot\|svg\|ttf\|woff\|woff2\|mp4\|webm\)$' -> '/config/flow/file'
345 | ```
346 |
347 | We will consider integrating more tightly with Flow in the future so that you don’t have to do this.
348 |
349 | ### Deploy
350 |
351 | #### GitHub Pages
352 |
353 | >Note: this feature is available with `react-scripts@0.2.0` and higher.
354 |
355 | First, open your `package.json` and add a `homepage` field.
356 | It could look like this:
357 |
358 | ```js
359 | {
360 | "name": "my-app",
361 | "homepage": "http://myusername.github.io/my-app",
362 | // ...
363 | }
364 | ```
365 |
366 | Now, whenever you run `npm run build`, you will see a cheat sheet with a sequence of commands to deploy to GitHub pages:
367 |
368 | ```sh
369 | git checkout -B gh-pages
370 | git add -f build
371 | git commit -am "Rebuild website"
372 | git push origin :gh-pages
373 | git subtree push --prefix build origin gh-pages
374 | git checkout -
375 | ```
376 |
377 | You may copy and paste them, or put them into a custom shell script. You may also customize them for another hosting provider.
378 |
379 | Note that GitHub Pages doesn't support routers that use the HTML5 `pushState` history API under the hood (for example, React Router using `browserHistory`). This is becasue when there is a fresh page load for a url like `http://user.github.io/todomvc/todos/42`, where `/todos/42` is a frontend route, the GitHub Pages server returns 404 because it knows nothing of `/todos/42`. If you want to add a router to a project hosted on GitHub Pages, here are a couple of solutions:
380 | * You could switch from using HTML5 history API to routing with hashes. If you use React Router, you can switch to `hashHistory` for this effect, but the URL will be longer and more verbose (for example, `http://user.github.io/todomvc/#/todos/42?_k=yknaj`). [Read more](https://github.com/reactjs/react-router/blob/master/docs/guides/Histories.md#histories) about different history implementations in React Router.
381 | * Alternatively, you can use a trick to teach GitHub Pages to handle 404 by redirecting to your `index.html` page with a special redirect parameter. You would need to add a `404.html` file with the redirection code to the `build` folder before deploying your project, and you’ll need to add code handling the redirect parameter to `index.html`. You can find a detailed explanation of this technique [in this guide](https://github.com/rafrex/spa-github-pages).
382 |
383 | #### Heroku
384 |
385 | Use the [Heroku Buildpack for create-react-app](https://github.com/mars/create-react-app-buildpack).
386 |
387 | ### Something Missing?
388 |
389 | If you have ideas for more “How To” recipes that should be on this page, [let us know](https://github.com/facebookincubator/create-react-app/issues) or [contribute some!](https://github.com/facebookincubator/create-react-app/edit/master/template/README.md)
390 |
--------------------------------------------------------------------------------
/create-react-app-example/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/steos/reactcards-example/6999b493b6f712f0dd191e6f4fc8f38ac362865c/create-react-app-example/favicon.ico
--------------------------------------------------------------------------------
/create-react-app-example/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | React App
7 |
8 |
9 |
10 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/create-react-app-example/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "foobar",
3 | "version": "0.0.1",
4 | "private": true,
5 | "devDependencies": {
6 | "react-scripts": "0.2.1",
7 | "reactcards": "^0.4.0"
8 | },
9 | "dependencies": {
10 | "react": "^15.2.1",
11 | "react-dom": "^15.2.1"
12 | },
13 | "scripts": {
14 | "start": "react-scripts start",
15 | "build": "react-scripts build",
16 | "eject": "react-scripts eject",
17 | "reactcards": "reactcards -p 8080 -e ./reactcards/entry.js"
18 | },
19 | "eslintConfig": {
20 | "extends": "./node_modules/react-scripts/config/eslint.js"
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/create-react-app-example/reactcards/card.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import cards from 'reactcards'
3 | import App from '../src/App'
4 | import * as appTests from '../test/App'
5 |
6 | const demo = cards('demo')
7 |
8 | demo.card(
9 | `## markdown doc
10 | you can use markdown for card documentation
11 | - foo
12 | - bar`,
13 |
14 | )
15 |
16 | demo.card()
17 |
18 | demo.markdown(`
19 | # a markdown card
20 | this is a simple markdown card
21 | - lorem
22 | - ipsum
23 | `)
24 |
25 | demo.test(appTests, {title:'simple tests'})
26 |
27 | demo.test(
28 | `## component tests
29 | Here you can see the results of some component tests.`,
30 | appTests
31 | )
32 |
--------------------------------------------------------------------------------
/create-react-app-example/reactcards/entry.js:
--------------------------------------------------------------------------------
1 | import {run} from 'reactcards';
2 | import './card';
3 |
4 |
5 | if (module.hot) {
6 | module.hot.accept()
7 | }
8 |
9 | // of we go...
10 | run();
--------------------------------------------------------------------------------
/create-react-app-example/src/App.css:
--------------------------------------------------------------------------------
1 | .App {
2 | text-align: center;
3 | }
4 |
5 | .App-logo {
6 | animation: App-logo-spin infinite 20s linear;
7 | height: 80px;
8 | }
9 |
10 | .App-header {
11 | background-color: #222;
12 | height: 150px;
13 | padding: 20px;
14 | color: white;
15 | }
16 |
17 | .App-intro {
18 | font-size: large;
19 | }
20 |
21 | @keyframes App-logo-spin {
22 | from { transform: rotate(0deg); }
23 | to { transform: rotate(360deg); }
24 | }
25 |
--------------------------------------------------------------------------------
/create-react-app-example/src/App.js:
--------------------------------------------------------------------------------
1 | import React, { Component, PropTypes } from 'react';
2 | import logo from './logo.svg';
3 | import './App.css';
4 |
5 | class App extends Component {
6 | render() {
7 | return (
8 |
9 |
10 |
11 |
{this.props.message}
12 |
13 |
14 | );
15 | }
16 | }
17 |
18 | App.propTypes = {
19 | messages: PropTypes.string
20 | }
21 |
22 | export default App;
23 |
--------------------------------------------------------------------------------
/create-react-app-example/src/index.css:
--------------------------------------------------------------------------------
1 | body {
2 | margin: 0;
3 | padding: 0;
4 | font-family: sans-serif;
5 | }
6 |
--------------------------------------------------------------------------------
/create-react-app-example/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 | import App from './App';
4 | import './index.css';
5 |
6 | ReactDOM.render(
7 | ,
8 | document.getElementById('root')
9 | );
10 |
--------------------------------------------------------------------------------
/create-react-app-example/src/logo.svg:
--------------------------------------------------------------------------------
1 |
8 |
--------------------------------------------------------------------------------
/create-react-app-example/test/App.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import { assert } from 'chai'
3 | import { shallow } from 'enzyme'
4 | import App from '../src/App'
5 |
6 | export function testAppComponent() {
7 | describe('Test ', () => {
8 | it('should display a bar. drink up!', () => {
9 | const wrapper = shallow()
10 | assert.equal(wrapper.text(), '?!')
11 | })
12 | })
13 | }
14 |
15 | export function testAppComponentTwo() {
16 | describe('Test ', () => {
17 | it('should display Foo says \'testing\'', () => {
18 | const wrapper = shallow()
19 | assert.equal(wrapper.text(), "testing")
20 | })
21 | })
22 | }
23 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "scripts": {
3 | "cards": "./node_modules/.bin/reactcards -e src/main.js"
4 | },
5 | "devDependencies": {
6 | "reactcards": "^0.3.0"
7 | },
8 | "dependencies": {
9 | "react": "^15.1.0",
10 | "react-dom": "^15.1.0"
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/cards.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import cards from 'reactcards'
3 | import {Foo, Bar, StatefulCounter, StatelessCounter, TodoList} from './components'
4 | import * as testSimple from '../test/simple'
5 | import * as testComponents from '../test/components'
6 | import * as advancedTestComponents from '../test/advanced'
7 |
8 | const demo = cards('demo')
9 | const abc = cards('ABC')
10 |
11 | abc.card(, 'here is a simple example')
12 |
13 | demo.card(
14 | `## markdown doc
15 | you can use markdown for card documentation
16 | - foo
17 | - bar`,
18 |
19 | )
20 |
21 | demo.card()
22 |
23 | demo.card(, {title: 'a bar card'})
24 |
25 | demo.card(
26 | `## Counter
27 |
28 | This is a stateful counter. If you change the value prop
29 | in the source file it will not update because the new prop will be ignored
30 | and instead the component local state is rendered.
31 |
32 | Implement *componentWillReceiveProps* and override the component local state
33 | if you want this to work as expected.`,
34 |
35 |
36 | )
37 |
38 | demo.card(
39 | `## Stateless Counter
40 | This example shows how to manage state when you have a stateless
41 | component. The card can also dump the current state as JSON if
42 | you set the *inspect* flag to true.`,
43 |
44 | (state) =>
45 | state.update(x => x + 1)}
48 | dec={() => state.update(x => x - 1)}/>,
49 | {
50 | init: 23,
51 | inspect: true,
52 | }
53 | )
54 |
55 | demo.card(
56 | `## Undo/Redo
57 | Same example as before but with undo/redo controls added by the card.`,
58 |
59 | (state) =>
60 | state.update(x => x + 1)}
63 | dec={() => state.update(x => x - 1)}/>,
64 | {
65 | init: 1337,
66 | history:true,
67 | }
68 | )
69 |
70 | demo.card(
71 | `## TodoList
72 | A simple todo list showing history and inspect feature
73 | with a little more interesting model than just a simple number.`,
74 |
75 | (state) =>
76 | state.update(items => [...items, {text, done: false}])}
78 | onToggleItem={(index) => state.update(items => [
79 | ...items.slice(0, index),
80 | {...items[index], done: !items[index].done},
81 | ...items.slice(index + 1)
82 | ])}/>,
83 | {
84 | init: [],
85 | history: true,
86 | inspect: true,
87 | }
88 | )
89 |
90 | demo.markdown(`
91 | # a markdown card
92 | this is a simple markdown card
93 | - lorem
94 | - ipsum
95 | `)
96 |
97 | demo.test(testSimple, {title:'simple tests'})
98 |
99 | demo.test(
100 | `## component tests
101 | Here you can see the results of some component tests.`,
102 | testComponents
103 | )
104 |
105 | demo.test(advancedTestComponents, { title: 'advanced component tests' })
106 |
--------------------------------------------------------------------------------
/src/components.js:
--------------------------------------------------------------------------------
1 | import React, {Component} from 'react'
2 |
3 | export class Foo extends Component {
4 | componentWillReceiveProps(nextProps) {
5 | console.log('Foo receiving props', nextProps, this.props)
6 | }
7 | componentWillUnmount() {
8 | console.log('Foo unmounting')
9 | }
10 | componentDidMount() {
11 | console.log('Foo did mount')
12 | }
13 | componentDidUpdate() {
14 | console.log('Foo updated!')
15 | }
16 | render() {
17 | return