Skip to content

Commit bfbb756

Browse files
authored
Use DragDropContextProvider in Tutorial (#1272)
* docs: use the dragdropcontextprovider in the tutorial example * docs: turn on auto-formatting of markdown files, run auto-formatting on existing documentation * docs: add a prettier override for markdown to not use tabs
1 parent e3fb069 commit bfbb756

27 files changed

+727
-738
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
"**/bower_components": true
55
},
66
"editor.tabSize": 2,
7+
"[markdown]": {
8+
"editor.formatOnSave": true
9+
},
710
"[typescript]": {
811
"editor.formatOnSave": true
912
},

package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,15 @@
116116
"semi": false,
117117
"singleQuote": true,
118118
"trailingComma": "all",
119-
"useTabs": true
119+
"useTabs": true,
120+
"overrides": [
121+
{
122+
"files": "*.md",
123+
"options": {
124+
"useTabs": false
125+
}
126+
}
127+
]
120128
},
121129
"workspaces": {
122130
"packages": [

packages/dnd-core/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ It powers [React DnD](https://github.com/react-dnd/react-dnd) internally.
1313

1414
To give you a better idea:
1515

16-
* There is no DOM here
17-
* We let you define drop target and drag source logic
18-
* We let you supply custom underlying implementations (console, DOM via jQuery, React, React Native, _whatever_)
19-
* We manage drag source and drop target interaction
16+
- There is no DOM here
17+
- We let you define drop target and drag source logic
18+
- We let you supply custom underlying implementations (console, DOM via jQuery, React, React Native, _whatever_)
19+
- We manage drag source and drop target interaction
2020

2121
This was written to support some rather complicated scenarios that were too hard to implement in [React DnD](https://github.com/react-dnd/react-dnd) due to its current architecture:
2222

23-
* [Mocking drag and drop interaction in tests](https://github.com/react-dnd/react-dnd/issues/55)
24-
* [Full support for arbitrary nesting and handling drag sources and drop targets](https://github.com/react-dnd/react-dnd/issues/87)
25-
* [Dragging multiple items at once](https://github.com/react-dnd/react-dnd/issues/14)
26-
* [Even when source is removed, letting another drag source “represent it” (e.g. card disappeared from one Kanban list, reappeared in another one)](https://github.com/react-dnd/react-dnd/pull/64#issuecomment-76118757)
23+
- [Mocking drag and drop interaction in tests](https://github.com/react-dnd/react-dnd/issues/55)
24+
- [Full support for arbitrary nesting and handling drag sources and drop targets](https://github.com/react-dnd/react-dnd/issues/87)
25+
- [Dragging multiple items at once](https://github.com/react-dnd/react-dnd/issues/14)
26+
- [Even when source is removed, letting another drag source “represent it” (e.g. card disappeared from one Kanban list, reappeared in another one)](https://github.com/react-dnd/react-dnd/pull/64#issuecomment-76118757)
2727

2828
As it turns out, these problems are much easier to solve when DOM is thrown out of the window.
2929

packages/documentation/README.md

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
Gatsby's default starter
88
</h1>
99

10-
Kick off your project with this default boilerplate. This barebones starter ships with the main Gatsby configuration files you might need.
10+
Kick off your project with this default boilerplate. This barebones starter ships with the main Gatsby configuration files you might need.
1111

1212
_Have another more specific idea? You may want to check out our vibrant collection of [official and community-created starters](https://www.gatsbyjs.org/docs/gatsby-starters/)._
1313

@@ -34,11 +34,11 @@ _Have another more specific idea? You may want to check out our vibrant collecti
3434
1. **Open the source code and start editing!**
3535

3636
Your site is now running at `http://localhost:8000`!
37-
38-
*Note: You'll also see a second link: `http://localhost:8000/___graphql`. This is a tool you can use to experiment with querying your data. Learn more about using this tool in the [Gatsby tutorial](https://www.gatsbyjs.org/tutorial/part-five/#introducing-graphiql).*
39-
37+
38+
\_Note: You'll also see a second link: `http://localhost:8000/___graphql`. This is a tool you can use to experiment with querying your data. Learn more about using this tool in the [Gatsby tutorial](https://www.gatsbyjs.org/tutorial/part-five/#introducing-graphiql).\_
39+
4040
Open the `my-default-starter` directory in your code editor of choice and edit `src/pages/index.js`. Save your changes and the browser will update in real time!
41-
41+
4242
## 🧐 What's inside?
4343

4444
A quick look at the top-level files and directories you'll see in a Gatsby project.
@@ -58,39 +58,39 @@ A quick look at the top-level files and directories you'll see in a Gatsby proje
5858
├── README.md
5959
└── yarn.lock
6060
61-
1. **`/node_modules`**: This directory contains all of the modules of code that your project depends on (npm packages) are automatically installed.
62-
63-
2. **`/src`**: This directory will contain all of the code related to what you will see on the front-end of your site (what you see in the browser) such as your site header or a page template. `src` is a convention for “source code”.
64-
65-
3. **`.gitignore`**: This file tells git which files it should not track / not maintain a version history for.
66-
67-
4. **`.prettierrc`**: This is a configuration file for [Prettier](https://prettier.io/). Prettier is a tool to help keep the formatting of your code consistent.
68-
69-
5. **`gatsby-browser.js`**: This file is where Gatsby expects to find any usage of the [Gatsby browser APIs](https://www.gatsbyjs.org/docs/browser-apis/) (if any). These allow customization/extension of default Gatsby settings affecting the browser.
70-
71-
6. **`gatsby-config.js`**: This is the main configuration file for a Gatsby site. This is where you can specify information about your site (metadata) like the site title and description, which Gatsby plugins you’d like to include, etc. (Check out the [config docs](https://www.gatsbyjs.org/docs/gatsby-config/) for more detail).
72-
73-
7. **`gatsby-node.js`**: This file is where Gatsby expects to find any usage of the [Gatsby Node APIs](https://www.gatsbyjs.org/docs/node-apis/) (if any). These allow customization/extension of default Gatsby settings affecting pieces of the site build process.
74-
75-
8. **`gatsby-ssr.js`**: This file is where Gatsby expects to find any usage of the [Gatsby server-side rendering APIs](https://www.gatsbyjs.org/docs/ssr-apis/) (if any). These allow customization of default Gatsby settings affecting server-side rendering.
76-
77-
9. **`LICENSE`**: Gatsby is licensed under the MIT license.
78-
79-
10. **`package-lock.json`** (See `package.json` below, first). This is an automatically generated file based on the exact versions of your npm dependencies that were installed for your project. **(You won’t change this file directly).**
80-
81-
11. **`package.json`**: A manifest file for Node.js projects, which includes things like metadata (the project’s name, author, etc). This manifest is how npm knows which packages to install for your project.
82-
83-
12. **`README.md`**: A text file containing useful reference information about your project.
84-
85-
13. **`yarn.lock`**: [Yarn](https://yarnpkg.com/) is a package manager alternative to npm. You can use either yarn or npm, though all of the Gatsby docs reference npm. This file serves essentially the same purpose as `package-lock.json`, just for a different package management system.
61+
1. **`/node_modules`**: This directory contains all of the modules of code that your project depends on (npm packages) are automatically installed.
62+
63+
2. **`/src`**: This directory will contain all of the code related to what you will see on the front-end of your site (what you see in the browser) such as your site header or a page template. `src` is a convention for “source code”.
64+
65+
3. **`.gitignore`**: This file tells git which files it should not track / not maintain a version history for.
66+
67+
4. **`.prettierrc`**: This is a configuration file for [Prettier](https://prettier.io/). Prettier is a tool to help keep the formatting of your code consistent.
68+
69+
5. **`gatsby-browser.js`**: This file is where Gatsby expects to find any usage of the [Gatsby browser APIs](https://www.gatsbyjs.org/docs/browser-apis/) (if any). These allow customization/extension of default Gatsby settings affecting the browser.
70+
71+
6. **`gatsby-config.js`**: This is the main configuration file for a Gatsby site. This is where you can specify information about your site (metadata) like the site title and description, which Gatsby plugins you’d like to include, etc. (Check out the [config docs](https://www.gatsbyjs.org/docs/gatsby-config/) for more detail).
72+
73+
7. **`gatsby-node.js`**: This file is where Gatsby expects to find any usage of the [Gatsby Node APIs](https://www.gatsbyjs.org/docs/node-apis/) (if any). These allow customization/extension of default Gatsby settings affecting pieces of the site build process.
74+
75+
8. **`gatsby-ssr.js`**: This file is where Gatsby expects to find any usage of the [Gatsby server-side rendering APIs](https://www.gatsbyjs.org/docs/ssr-apis/) (if any). These allow customization of default Gatsby settings affecting server-side rendering.
76+
77+
9. **`LICENSE`**: Gatsby is licensed under the MIT license.
78+
79+
10. **`package-lock.json`** (See `package.json` below, first). This is an automatically generated file based on the exact versions of your npm dependencies that were installed for your project. **(You won’t change this file directly).**
80+
81+
11. **`package.json`**: A manifest file for Node.js projects, which includes things like metadata (the project’s name, author, etc). This manifest is how npm knows which packages to install for your project.
82+
83+
12. **`README.md`**: A text file containing useful reference information about your project.
84+
85+
13. **`yarn.lock`**: [Yarn](https://yarnpkg.com/) is a package manager alternative to npm. You can use either yarn or npm, though all of the Gatsby docs reference npm. This file serves essentially the same purpose as `package-lock.json`, just for a different package management system.
8686
8787
## 🎓 Learning Gatsby
8888
8989
Looking for more guidance? Full documentation for Gatsby lives [on the website](https://www.gatsbyjs.org/). Here are some places to start:
9090
91-
- **For most developers, we recommend starting with our [in-depth tutorial for creating a site with Gatsby](https://www.gatsbyjs.org/tutorial/).** It starts with zero assumptions about your level of ability and walks through every step of the process.
91+
- **For most developers, we recommend starting with our [in-depth tutorial for creating a site with Gatsby](https://www.gatsbyjs.org/tutorial/).** It starts with zero assumptions about your level of ability and walks through every step of the process.
9292
93-
- **To dive straight into code samples, head [to our documentation](https://www.gatsbyjs.org/docs/).** In particular, check out the _Guides_, _API Reference_, and _Advanced Tutorials_ sections in the sidebar.
93+
- **To dive straight into code samples, head [to our documentation](https://www.gatsbyjs.org/docs/).** In particular, check out the _Guides_, _API Reference_, and _Advanced Tutorials_ sections in the sidebar.
9494
9595
## 💫 Deploy
9696

packages/documentation/markdown/docs/00 Quick Start/FAQ.md

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
2-
path: "/docs/faq"
3-
title: "FAQ"
2+
path: '/docs/faq'
3+
title: 'FAQ'
44
---
5-
*New to React DnD? [Read the overview](/docs/overview) before jumping into the docs.*
65

7-
FAQ
8-
===================
6+
_New to React DnD? [Read the overview](/docs/overview) before jumping into the docs._
7+
8+
# FAQ
99

1010
## Usage
1111

@@ -45,55 +45,50 @@ Because [`DragSource`](/docs/api/drag-source) and [`DropTarget`](/docs/api/drop-
4545

4646
When using [function components](https://facebook.github.io/react/docs/reusable-components.html#stateless-functions), the `component` parameter will always be `null` in the `beginDrag`/`endDrag`/`drop`/`hover` methods. This is because it is not possible to attach a ref to a stateless function component as explained in [the React docs](https://facebook.github.io/react/docs/reusable-components.html#stateless-functions).
4747

48-
4948
```js
50-
import { DragSource } from 'react-dnd';
51-
import flow from 'lodash/flow';
49+
import { DragSource } from 'react-dnd'
50+
import flow from 'lodash/flow'
5251

5352
class YourComponent {
5453
/* ... */
5554
}
5655

5756
export default flow(
58-
DragSource(/* ... */)
59-
DropTarget(/* ... */)
60-
)(YourComponent);
57+
DragSource(/* ... */),
58+
DropTarget(/* ... */),
59+
)(YourComponent)
6160
```
6261

6362
### How do I register a drop target for the native files?
6463

6564
If you are using the [HTML5 backend](/docs//backends/html5), you can register a drop target for one of the `NativeTypes` it exports:
6665

6766
```js
68-
import React from 'react';
69-
import { NativeTypes } from 'react-dnd-html5-backend';
70-
import { DropTarget } from 'react-dnd';
67+
import React from 'react'
68+
import { NativeTypes } from 'react-dnd-html5-backend'
69+
import { DropTarget } from 'react-dnd'
7170

7271
const fileTarget = {
7372
drop(props, monitor) {
74-
console.log(monitor.getItem().files);
75-
}
76-
};
73+
console.log(monitor.getItem().files)
74+
},
75+
}
7776

7877
function FileDropZone({ connectDropTarget, isOver, canDrop }) {
7978
return connectDropTarget(
8079
<div>
8180
{!isOver && !canDrop && 'Drag files from the hard drive'}
8281
{!isOver && canDrop && 'Drag the files here'}
8382
{isOver && 'Drop the files'}
84-
</div>
85-
);
83+
</div>,
84+
)
8685
}
8786

88-
export default DropTarget(
89-
NativeTypes.FILE,
90-
fileTarget,
91-
(connect, monitor) => ({
92-
connectDropTarget: connect.dropTarget(),
93-
isOver: monitor.isOver(),
94-
canDrop: monitor.canDrop()
95-
})
96-
)(FileDropZone);
87+
export default DropTarget(NativeTypes.FILE, fileTarget, (connect, monitor) => ({
88+
connectDropTarget: connect.dropTarget(),
89+
isOver: monitor.isOver(),
90+
canDrop: monitor.canDrop(),
91+
}))(FileDropZone)
9792
```
9893

9994
### How do I write a custom backend?
@@ -119,7 +114,7 @@ class Page {
119114
}
120115
}
121116

122-
export default DragDropContext(HTML5Backend)(Page);
117+
export default DragDropContext(HTML5Backend)(Page)
123118
```
124119

125120
It might surprise you that your route handler's `willTransitionTo` (or a similar method) won't get triggered in this case! React DnD doesn't proxy your components' static methods and properties. This is too fragile and full of edge cases, so you must do it yourself. It's not hard! Just put your statics onto the components returned by React DnD instead:
@@ -131,12 +126,12 @@ class Page {
131126
}
132127
}
133128

134-
Page = DragDropContext(HTML5Backend)(Page);
135-
Page.willTransitionTo = function (transition, params) {
129+
Page = DragDropContext(HTML5Backend)(Page)
130+
Page.willTransitionTo = function(transition, params) {
136131
/* ... */
137132
}
138133

139-
export default Page;
134+
export default Page
140135
```
141136

142137
## Meta
@@ -163,8 +158,8 @@ It is loosely based on the pre-React code written at Stampsy by [Andrew Kuznetso
163158

164159
React DnD would not have reached the 1.0 release without the generous donations from:
165160

166-
* [Macropod](https://macropod.com/), a company developing team productivity software;
167-
* [Webflow](https://webflow.com/), a company creating a professional responsive website builder.
161+
- [Macropod](https://macropod.com/), a company developing team productivity software;
162+
- [Webflow](https://webflow.com/), a company creating a professional responsive website builder.
168163

169164
[Gadzhi Kharkharov](http://kkga.me/) styled the website, and the [fixed-data-table](https://github.com/facebook/fixed-data-table) project provided the website template.
170165

0 commit comments

Comments
 (0)