Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drag and Drop #1733

Merged
merged 45 commits into from
Apr 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
294fe72
WIP: wrapping react-beautiful-dnd, adding eui opinions
thompsongl Mar 7, 2019
ec9467b
Merge branch 'master' into draggable
thompsongl Mar 8, 2019
a23c9d8
WIP: support cloning items
thompsongl Mar 8, 2019
e41403e
Merge branch 'master' into draggable
thompsongl Mar 12, 2019
01ba4ab
add drag result services; update for style prop support
thompsongl Mar 12, 2019
f222535
update service types; actual clone behavior on copy
thompsongl Mar 14, 2019
6b68aba
WIP: docs :notebook:
thompsongl Mar 14, 2019
59f6da4
Merge branch 'master' into draggable
thompsongl Mar 14, 2019
2028e6c
deps
thompsongl Mar 15, 2019
0d4be8a
start to example explanations
thompsongl Mar 15, 2019
8e995cb
use animation speed variable
thompsongl Mar 15, 2019
67d47a8
docs example write ups
thompsongl Mar 15, 2019
c4fc40d
bump react-beautiful-dnd
thompsongl Mar 18, 2019
37461d1
typescript fixes; start to testing; a11y focus fix
thompsongl Mar 18, 2019
1c11b65
Merge branch 'master' into draggable
thompsongl Mar 19, 2019
1632708
more docs
thompsongl Mar 19, 2019
047b8b8
complex docs example; nested focus fix
thompsongl Mar 20, 2019
12e2f42
update clone behavior to work with latest dnd release
thompsongl Mar 20, 2019
61c85c6
zIndex change for current dragging item only
thompsongl Mar 20, 2019
5ba48e5
a11y improvement for drag handles
thompsongl Mar 20, 2019
dcc92d9
Altered styles and added some props
Mar 22, 2019
50710fb
Merge branch 'master' into draggable
thompsongl Mar 22, 2019
952da3f
simple docs edits
thompsongl Mar 22, 2019
cdeeab6
Merge pull request #1 from cchaos/draggable/design
thompsongl Mar 22, 2019
a174f01
clean up scss; add remove fn
thompsongl Mar 22, 2019
80b4c31
add more euidragdropcontext docs
thompsongl Mar 25, 2019
43c3f11
Merge branch 'master' into draggable
thompsongl Mar 25, 2019
a6e1a07
Merge branch 'master' into draggable
thompsongl Mar 29, 2019
2adc175
fix drop in clone example
thompsongl Mar 29, 2019
a7e80f5
disabledInteractiveElementBlocking; beta badge
thompsongl Apr 1, 2019
3fcfd01
cherry-pick beta badge from cchaos/eui-selectable
thompsongl Apr 2, 2019
d84bb68
Merge branch 'master' into draggable
thompsongl Apr 2, 2019
ce06bd8
Merge branch 'master' into draggable
thompsongl Apr 2, 2019
fdda184
clone docs improvements: no box resize, no drop animation on remove
thompsongl Apr 2, 2019
5f691f2
update clone example container sizes
thompsongl Apr 2, 2019
32360d3
Reverted using EuiListGroup for custom handle doc
Apr 2, 2019
39bebc9
Merge pull request #2 from cchaos/draggable/design
thompsongl Apr 2, 2019
d54ff39
isRemovable prop name change; clean up
thompsongl Apr 2, 2019
db62d6a
Merge branch 'master' into draggable
thompsongl Apr 3, 2019
0c68d16
#1733 changelog entry
thompsongl Apr 3, 2019
8c21327
fix guide prop table; add prop table descriptions
thompsongl Apr 3, 2019
1a698ac
docs account for empty list size
thompsongl Apr 3, 2019
9c4d838
Revert "cherry-pick beta badge from cchaos/eui-selectable"
thompsongl Apr 3, 2019
9e6b31d
Merge branch 'master' into draggable
thompsongl Apr 3, 2019
a718eb3
isRemovable blurb
thompsongl Apr 3, 2019
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## [`master`](https://github.com/elastic/eui/tree/master)

- **[Beta]** Added new `EuiSelectable` component ([#1699](https://github.com/elastic/eui/pull/1699))
- **[Beta]** Added new drag and drop components: `EuiDragDropContext`, `EuiDraggable`, and `EuiDroppable` ([#1733](https://github.com/elastic/eui/pull/1733))


## [`9.7.2`](https://github.com/elastic/eui/tree/v9.7.2)
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"dependencies": {
"@types/lodash": "^4.14.116",
"@types/numeral": "^0.0.25",
"@types/react-beautiful-dnd": "^10.1.0",
"classnames": "^2.2.5",
"core-js": "^2.5.1",
"highlight.js": "^9.12.0",
Expand All @@ -56,6 +57,7 @@
"numeral": "^2.0.6",
"prop-types": "^15.6.0",
"react-ace": "^5.5.0",
"react-beautiful-dnd": "^10.1.0",
"react-color": "^2.13.8",
"react-focus-lock": "^1.17.7",
"react-input-autosize": "^2.2.1",
Expand Down
2 changes: 1 addition & 1 deletion src-docs/src/components/guide_section/guide_section.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export class GuideSection extends Component {

const rows = propNames.map(propName => {
const {
description: propDescription,
description: propDescription = '',
required,
defaultValue,
type,
Expand Down
4 changes: 4 additions & 0 deletions src-docs/src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ import { DelayHideExample }
import { DescriptionListExample }
from './views/description_list/description_list_example';

import { DragAndDropExample }
from './views/drag_and_drop/drag_and_drop_example';

import { EmptyPromptExample }
from './views/empty_prompt/empty_prompt_example';

Expand Down Expand Up @@ -388,6 +391,7 @@ const navigation = [{
CardExample,
CodeExample,
DescriptionListExample,
DragAndDropExample,
EmptyPromptExample,
HealthExample,
IconExample,
Expand Down
41 changes: 41 additions & 0 deletions src-docs/src/views/drag_and_drop/drag_and_drop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React, { useState } from 'react';
import {
EuiDragDropContext,
EuiDraggable,
EuiDroppable,
EuiPanel
} from '../../../../src/components';

import { reorder } from '../../../../src/components/drag_and_drop';

import { makeList } from './helper';

export default () => {
const [list, setList] = useState(makeList(3));
const onDragEnd = ({ source, destination }) => {
if (source && destination) {
const items = reorder(
list,
source.index,
destination.index
);

setList(items);
}
};
return (
<EuiDragDropContext onDragEnd={onDragEnd}>
<EuiDroppable droppableId="DROPPABLE_AREA" spacing="m" withPanel>
{list.map(({ content, id }, idx) => (
<EuiDraggable spacing="m" key={id} index={idx} draggableId={id}>
{(provided, state) => (
<EuiPanel hasShadow={state.isDragging}>
{content}{state.isDragging && ' ✨'}
</EuiPanel>
)}
</EuiDraggable>
))}
</EuiDroppable>
</EuiDragDropContext>
);
};
30 changes: 30 additions & 0 deletions src-docs/src/views/drag_and_drop/drag_and_drop_bare.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React, { useState } from 'react';
import {
EuiDragDropContext,
EuiDraggable,
EuiDroppable
} from '../../../../src/components';

import { makeList } from './helper';

export default () => {
const [list] = useState(makeList(3));
const onDragEnd = ({ source, destination }) => {
console.log(source, destination);
};
return (
<EuiDragDropContext onDragEnd={onDragEnd}>
<EuiDroppable droppableId="DROPPABLE_AREA_BARE">
{list.map(({ content, id }, idx) => (
<EuiDraggable key={id} index={idx} draggableId={id}>
{() => (
<div>
{content}
</div>
)}
</EuiDraggable>
))}
</EuiDroppable>
</EuiDragDropContext>
);
};
119 changes: 119 additions & 0 deletions src-docs/src/views/drag_and_drop/drag_and_drop_clone.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import React, { useState } from 'react';
import {
EuiButtonIcon,
EuiDragDropContext,
EuiFlexGroup,
EuiFlexItem,
EuiDraggable,
EuiDroppable,
EuiIcon,
EuiPanel
} from '../../../../src/components';

import {
copy,
reorder
} from '../../../../src/components/drag_and_drop';

import { makeId, makeList } from './helper';

export default () => {
const [isItemRemovable, setIsItemRemovable] = useState(false);
const [list1, setList1] = useState(makeList(3));
const [list2, setList2] = useState([]);
const lists = { DROPPABLE_AREA_COPY_1: list1, DROPPABLE_AREA_COPY_2: list2 };
const actions = { DROPPABLE_AREA_COPY_1: setList1, DROPPABLE_AREA_COPY_2: setList2 };
const remove = (droppableId, index) => {
const list = Array.from(lists[droppableId]);
list.splice(index, 1);

actions[droppableId](list);
};
const onDragUpdate = ({ source, destination }) => {
const shouldRemove = !destination && source.droppableId === 'DROPPABLE_AREA_COPY_2';
setIsItemRemovable(shouldRemove);
};
const onDragEnd = ({ source, destination }) => {
if (source && destination) {
if (source.droppableId === destination.droppableId) {
const items = reorder(
lists[destination.droppableId],
source.index,
destination.index
);

actions[destination.droppableId](items);
} else {
const sourceId = source.droppableId;
const destinationId = destination.droppableId;
const result = copy(
lists[sourceId],
lists[destinationId],
source,
destination,
{
property: 'id',
modifier: makeId
}
);

actions[sourceId](result[sourceId]);
actions[destinationId](result[destinationId]);
}
} else if (!destination && source.droppableId === 'DROPPABLE_AREA_COPY_2') {
remove(source.droppableId, source.index);
}
};
return (
<EuiDragDropContext onDragEnd={onDragEnd} onDragUpdate={onDragUpdate}>
<EuiFlexGroup>
<EuiFlexItem style={{ width: '50%' }}>

<EuiDroppable droppableId="DROPPABLE_AREA_COPY_1" cloneDraggables={true} spacing="l" grow>
{list1.map(({ content, id }, idx) => (
<EuiDraggable key={id} index={idx} draggableId={id} spacing="l">
<EuiPanel>
{content}
</EuiPanel>
</EuiDraggable>
))}
</EuiDroppable>

</EuiFlexItem>
<EuiFlexItem style={{ width: '50%' }}>

<EuiDroppable droppableId="DROPPABLE_AREA_COPY_2" withPanel grow>
{list2.length ?
(
list2.map(({ content, id }, idx) => (
<EuiDraggable key={id} index={idx} draggableId={id} spacing="l" isRemovable={isItemRemovable}>
<EuiPanel>
<EuiFlexGroup gutterSize="none" alignItems="center">
<EuiFlexItem>{content}</EuiFlexItem>
<EuiFlexItem grow={false}>
{isItemRemovable ? (
<EuiIcon type="trash" color="danger" />
) : (
<EuiButtonIcon
iconType="cross"
aria-label="Remove"
onClick={() => remove('DROPPABLE_AREA_COPY_2', idx)}
/>
)}
</EuiFlexItem>
</EuiFlexGroup>
</EuiPanel>
</EuiDraggable>
))
) : (
<EuiFlexGroup alignItems="center" justifyContent="spaceAround" gutterSize="none" style={{ height: '100%' }}>
<EuiFlexItem grow={false}>Drop Items Here</EuiFlexItem>
</EuiFlexGroup>
)}
</EuiDroppable>

</EuiFlexItem>
</EuiFlexGroup>
</EuiDragDropContext>
);
};
90 changes: 90 additions & 0 deletions src-docs/src/views/drag_and_drop/drag_and_drop_complex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import React, { useState } from 'react';
import {
EuiDragDropContext,
EuiDraggable,
EuiDroppable,
EuiButtonIcon,
EuiPanel
} from '../../../../src/components';

import { move, reorder } from '../../../../src/components/drag_and_drop';

import { makeList } from './helper';

export default () => {
const [list, setList] = useState([1, 2]);
const [list1, setList1] = useState(makeList(3));
const [list2, setList2] = useState(makeList(3, 4));
const lists = { COMPLEX_DROPPABLE_PARENT: list, COMPLEX_DROPPABLE_AREA_1: list1, COMPLEX_DROPPABLE_AREA_2: list2 };
const actions = { COMPLEX_DROPPABLE_PARENT: setList, COMPLEX_DROPPABLE_AREA_1: setList1, COMPLEX_DROPPABLE_AREA_2: setList2 };
const onDragEnd = ({ source, destination }) => {
if (source && destination) {
if (source.droppableId === destination.droppableId) {
const items = reorder(
lists[destination.droppableId],
source.index,
destination.index
);

actions[destination.droppableId](items);
} else {
const sourceId = source.droppableId;
const destinationId = destination.droppableId;
const result = move(
lists[sourceId],
lists[destinationId],
source,
destination
);

actions[sourceId](result[sourceId]);
actions[destinationId](result[destinationId]);
}

}
};
return (
<EuiDragDropContext onDragEnd={onDragEnd}>

<EuiDroppable
droppableId="COMPLEX_DROPPABLE_PARENT"
type="MACRO"
direction="horizontal"
withPanel
spacing="l"
style={{ display: 'flex' }}
>
{list.map((did, didx) => (
<EuiDraggable
key={did}
index={didx}
draggableId={`COMPLEX_DRAGGABLE_${did}`}
spacing="l"
style={{ flex: '1 0 50%' }}
disableInteractiveElementBlocking // Allows button to be drag handle
>
{(provided) => (
<EuiPanel paddingSize="s">
<EuiButtonIcon
iconType="grab"
aria-label="Drag Handle"
{...provided.dragHandleProps}
/>
<EuiDroppable droppableId={`COMPLEX_DROPPABLE_AREA_${did}`} type="MICRO" spacing="m" style={{ flex: '1 0 50%' }}>
{lists[`COMPLEX_DROPPABLE_AREA_${did}`].map(({ content, id }, idx) => (
<EuiDraggable key={id} index={idx} draggableId={id} spacing="m">
<EuiPanel>
{content}
</EuiPanel>
</EuiDraggable>
))}
</EuiDroppable>
</EuiPanel>
)}
</EuiDraggable>
))}
</EuiDroppable>

</EuiDragDropContext>
);
};
53 changes: 53 additions & 0 deletions src-docs/src/views/drag_and_drop/drag_and_drop_custom_handle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React, { useState } from 'react';
import {
EuiDragDropContext,
EuiDraggable,
EuiDroppable,
EuiFlexGroup,
EuiFlexItem,
EuiIcon,
EuiPanel
} from '../../../../src/components';

import { reorder } from '../../../../src/components/drag_and_drop';

import { makeList } from './helper';

export default () => {
const [list, setList] = useState(makeList(3));
const onDragEnd = ({ source, destination }) => {
if (source && destination) {
const items = reorder(
list,
source.index,
destination.index
);

setList(items);
}
};
return (
<EuiDragDropContext onDragEnd={onDragEnd}>
<EuiDroppable droppableId="CUSTOM_HANDLE_DROPPABLE_AREA" spacing="m" withPanel>
{list.map(({ content, id }, idx) => (
<EuiDraggable spacing="m" key={id} index={idx} draggableId={id} customDragHandle={true}>
{(provided) => (
<EuiPanel className="custom" paddingSize="m">
<EuiFlexGroup>
<EuiFlexItem grow={false}>
<div {...provided.dragHandleProps}>
<EuiIcon type="grab" />
</div>
</EuiFlexItem>
<EuiFlexItem>
{content}
</EuiFlexItem>
</EuiFlexGroup>
</EuiPanel>
)}
</EuiDraggable>
))}
</EuiDroppable>
</EuiDragDropContext>
);
};
Loading