Skip to content

Commit 4b97ec4

Browse files
committed
Update interactive examples
1 parent e6421a0 commit 4b97ec4

File tree

5 files changed

+111
-54
lines changed

5 files changed

+111
-54
lines changed

apps/docs/react/guides/multiple-sortable-lists.mdx

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ First, let's set up the initial setup for the columns and items. We'll be creati
2424

2525

2626
<CodeSandbox height="560" previewHeight="260" files={{
27-
"/App.js": App,
28-
"/Column.js": Column,
29-
"/Item.js": Item,
30-
"/Styles.css": Styles
31-
}} />
27+
"App.js": App,
28+
"Column.js": Column,
29+
"Item.js": Item,
30+
"styles.css": Styles
31+
}} showTabs />
3232

3333
## Adding drag and drop functionality
3434

@@ -37,8 +37,8 @@ Now, let's add drag and drop functionality to the items. We'll be using the [use
3737

3838
<CodeSandbox height="435" previewHeight="260" files={{
3939
...files,
40-
"/Item.js": {code: SortableItem, active: true},
41-
}} />
40+
"Item.js": {code: SortableItem, active: true},
41+
}} showTabs />
4242

4343
As you can see, we've added the `useSortable` hook to the `Item` component. We've also passed the `id`, `index`, `type`, `accept`, and `group` props to the hook.
4444

@@ -52,8 +52,8 @@ We'll be using the [useDroppable](/react/hooks/use-droppable) hook to create a d
5252

5353
<CodeSandbox height="455" previewHeight="260" files={{
5454
...files,
55-
"/Column.js": {code: DroppableColumn, active: true},
56-
}} />
55+
"Column.js": {code: DroppableColumn, active: true},
56+
}} showTabs />
5757

5858
<Note>We're setting the `collisionPriority` to `CollisionPriority.Low` to prioritize collisions of items over collisions of columns. Learn more about [detecting collisions](/concepts/droppable#detecting-collisions).</Note>
5959

@@ -63,9 +63,9 @@ We'll be using the [DragDropProvider](/react/components/drag-drop-provider) comp
6363

6464
<CodeSandbox height="455" previewHeight="260" files={{
6565
...files,
66-
"/App.js": {code: AppDroppableColumns, active: true},
67-
"/Column.js": {code: DroppableColumn},
68-
}} />
66+
"App.js": {code: AppDroppableColumns, active: true},
67+
"Column.js": {code: DroppableColumn},
68+
}} showTabs />
6969

7070
As you can see, we've added the `DragDropProvider` component to the `App` component. We've also added an `onDragOver` event handler to listen for drag and drop events.
7171

@@ -81,16 +81,16 @@ Here's how you can modify the `Column` component to make it sortable:
8181

8282
<CodeSandbox height="455" previewHeight="260" files={{
8383
...files,
84-
"/App.js": {code: AppSortableColumns},
85-
"/Column.js": {code: SortableColumn, active: true},
86-
}} />
84+
"App.js": {code: AppSortableColumns},
85+
"Column.js": {code: SortableColumn, active: true},
86+
}} showTabs />
8787

8888
<Info>You'll also need to pass the column `index` prop to the `Column` component in the `App` component.</Info>
8989

9090
If we want to control the state of the columns in React, we can update the `App` component to handle the column order in the `onDragEnd` callback:
9191

9292
```jsx App.js
93-
export function App({style = styles}) {
93+
export function App() {
9494
const [items, setItems] = useState({
9595
A: ['A0', 'A1', 'A2'],
9696
B: ['B0', 'B1'],
@@ -144,7 +144,7 @@ For example, here is how we would update our app to handle this case for the ord
144144
import React, {useRef, useState} from 'react';
145145
import {DragDropProvider} from '@dnd-kit/react';
146146
import {move} from '@dnd-kit/helpers';
147-
import "./Styles.css";
147+
import "./styles.css";
148148

149149
import {Column} from './Column';
150150
import {Item} from './Item';
@@ -203,9 +203,9 @@ export function App({style = styles}) {
203203
<Note>Optimistic updates performed by `@dnd-kit` are automatically reverted when a drag operation is canceled.</Note>
204204
205205
export const App = `import React, {useState} from 'react';
206-
import {Column} from './Column';
207-
import {Item} from './Item';
208-
import './Styles.css';
206+
import {Column} from './Column.js';
207+
import {Item} from './Item.js';
208+
import './styles.css';
209209

210210
export default function App() {
211211
const [items] = useState({
@@ -230,9 +230,9 @@ export default function App() {
230230
export const AppDroppableColumns = `import React, {useState} from 'react';
231231
import {DragDropProvider} from '@dnd-kit/react';
232232
import {move} from '@dnd-kit/helpers';
233-
import {Column} from './Column';
234-
import {Item} from './Item';
235-
import './Styles.css';
233+
import {Column} from './Column.js';
234+
import {Item} from './Item.js';
235+
import './styles.css';
236236

237237
export default function App() {
238238
const [items, setItems] = useState({
@@ -263,9 +263,9 @@ export default function App() {
263263
export const AppSortableColumns = `import React, {useState} from 'react';
264264
import {DragDropProvider} from '@dnd-kit/react';
265265
import {move} from '@dnd-kit/helpers';
266-
import {Column} from './Column';
267-
import {Item} from './Item';
268-
import './Styles.css';
266+
import {Column} from './Column.js';
267+
import {Item} from './Item.js';
268+
import './styles.css';
269269

270270
export default function App() {
271271
const [items, setItems] = useState({
@@ -361,7 +361,7 @@ export const SortableItem = `import React from 'react';
361361
import {useSortable} from '@dnd-kit/react/sortable';
362362

363363
export function Item({id, index, column}) {
364-
const {ref} = useSortable({
364+
const {ref, isDragSource} = useSortable({
365365
id,
366366
index,
367367
type: 'item',
@@ -370,17 +370,13 @@ export function Item({id, index, column}) {
370370
});
371371

372372
return (
373-
<button className="Item" ref={ref}>
373+
<button className="Item" ref={ref} data-dragging={isDragSource}>
374374
{id}
375375
</button>
376376
);
377377
}`;
378378
379-
export const Styles = (() => `
380-
html {
381-
background-color: ${typeof document != 'undefined' && document.documentElement.classList.contains('dark') ? '#11131b' : '#fafafd'};
382-
}
383-
379+
export const Styles = `
384380
.Root {
385381
display: flex;
386382
flex-direction: row;
@@ -408,19 +404,19 @@ html {
408404
border: none;
409405
border-radius: 5px;
410406
cursor: grab;
411-
transition: transform 0.3s ease-in, box-shadow 0.3s ease-in;
407+
transition: transform 0.2s ease, box-shadow 0.2s ease;
412408
transform: scale(1);
413409
box-shadow: inset 0px 0px 1px rgba(0,0,0,0.4), 0 0 0 calc(1px / var(--scale-x, 1)) rgba(63, 63, 68, 0.05), 0px 1px calc(2px / var(--scale-x, 1)) 0 rgba(34, 33, 81, 0.05);
414410
}
415411

416-
.Item[data-dnd-dragging="true"] {
412+
.Item[data-dragging="true"] {
417413
transform: scale(1.02);
418414
box-shadow: inset 0px 0px 1px rgba(0,0,0,0.5), -1px 0 15px 0 rgba(34, 33, 81, 0.01), 0px 15px 15px 0 rgba(34, 33, 81, 0.25)
419-
}`)();
415+
}`;
420416
421417
export const files = {
422-
"/Item.js": {code: SortableItem, hidden: true},
423-
"/App.js": {code: App, hidden: true},
424-
"/Column.js": {code: Column, hidden: true},
425-
"/Styles.css": {code: Styles, hidden: true}
418+
"Item.js": {code: SortableItem, hidden: true},
419+
"App.js": {code: App, hidden: true},
420+
"Column.js": {code: Column, hidden: true},
421+
"styles.css": {code: Styles, hidden: true}
426422
};

0 commit comments

Comments
 (0)