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

Export drag and drop service methods #2377

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Expand Up @@ -9,6 +9,7 @@

- Fixed spacing of `EuiFormErrorText` to match `EuiFormHelpText` ([#2354](https://github.com/elastic/eui/pull/2354))
- Fixed bug in `EuiPopover` where Array.prototype.slice() may have been called on 'undefined' ([#2369](https://github.com/elastic/eui/pull/2369))
- Properly exported `copy`, `move`, and `reorder` drag-and-drop service methods ([#2377](https://github.com/elastic/eui/pull/2377))

## [`14.2.0`](https://github.com/elastic/eui/tree/v14.2.0)

Expand Down
4 changes: 2 additions & 2 deletions src-docs/src/views/drag_and_drop/drag_and_drop.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import {
EuiPanel,
} from '../../../../src/components';

import { reorder } from '../../../../src/components/drag_and_drop';
import { euiDragDropReorder } 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);
const items = euiDragDropReorder(list, source.index, destination.index);

setList(items);
}
Expand Down
9 changes: 6 additions & 3 deletions src-docs/src/views/drag_and_drop/drag_and_drop_clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import {
EuiPanel,
} from '../../../../src/components';

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

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

Expand All @@ -37,7 +40,7 @@ export default () => {
const onDragEnd = ({ source, destination }) => {
if (source && destination) {
if (source.droppableId === destination.droppableId) {
const items = reorder(
const items = euiDragDropReorder(
lists[destination.droppableId],
source.index,
destination.index
Expand All @@ -47,7 +50,7 @@ export default () => {
} else {
const sourceId = source.droppableId;
const destinationId = destination.droppableId;
const result = copy(
const result = euiDragDropCopy(
lists[sourceId],
lists[destinationId],
source,
Expand Down
9 changes: 6 additions & 3 deletions src-docs/src/views/drag_and_drop/drag_and_drop_complex.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import {
EuiPanel,
} from '../../../../src/components';

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

import { makeList } from './helper';

Expand All @@ -28,7 +31,7 @@ export default () => {
const onDragEnd = ({ source, destination }) => {
if (source && destination) {
if (source.droppableId === destination.droppableId) {
const items = reorder(
const items = euiDragDropReorder(
lists[destination.droppableId],
source.index,
destination.index
Expand All @@ -38,7 +41,7 @@ export default () => {
} else {
const sourceId = source.droppableId;
const destinationId = destination.droppableId;
const result = move(
const result = euiDragDropMove(
lists[sourceId],
lists[destinationId],
source,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import {
EuiPanel,
} from '../../../../src/components';

import { reorder } from '../../../../src/components/drag_and_drop';
import { euiDragDropReorder } 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);
const items = euiDragDropReorder(list, source.index, destination.index);

setList(items);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import {
EuiDroppable,
} from '../../../../src/components';

import { reorder } from '../../../../src/components/drag_and_drop';
import { euiDragDropReorder } 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);
const items = euiDragDropReorder(list, source.index, destination.index);

setList(items);
}
Expand Down
9 changes: 6 additions & 3 deletions src-docs/src/views/drag_and_drop/drag_and_drop_move_lists.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import {
EuiPanel,
} from '../../../../src/components';

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

import { makeList } from './helper';

Expand All @@ -21,7 +24,7 @@ export default () => {
const actions = { DROPPABLE_AREA_1: setList1, DROPPABLE_AREA_2: setList2 };
if (source && destination) {
if (source.droppableId === destination.droppableId) {
const items = reorder(
const items = euiDragDropReorder(
lists[destination.droppableId],
source.index,
destination.index
Expand All @@ -31,7 +34,7 @@ export default () => {
} else {
const sourceId = source.droppableId;
const destinationId = destination.droppableId;
const result = move(
const result = euiDragDropMove(
lists[sourceId],
lists[destinationId],
source,
Expand Down
9 changes: 6 additions & 3 deletions src-docs/src/views/drag_and_drop/drag_and_drop_types.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import {
EuiPanel,
} from '../../../../src/components';

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

import { makeList } from './helper';

Expand All @@ -29,7 +32,7 @@ export default () => {
};
if (source && destination) {
if (source.droppableId === destination.droppableId) {
const items = reorder(
const items = euiDragDropReorder(
lists[destination.droppableId],
source.index,
destination.index
Expand All @@ -39,7 +42,7 @@ export default () => {
} else {
const sourceId = source.droppableId;
const destinationId = destination.droppableId;
const result = move(
const result = euiDragDropMove(
lists[sourceId],
lists[destinationId],
source,
Expand Down
6 changes: 5 additions & 1 deletion src/components/drag_and_drop/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
export { EuiDragDropContext } from './drag_drop_context';
export { EuiDraggable } from './draggable';
export { EuiDroppable } from './droppable';
export { copy, move, reorder } from './services';
export {
euiDragDropCopy,
euiDragDropMove,
euiDragDropReorder,
} from './services';

// Interfaces in react-beautiful-dnd that EUI abstracts over
// allows consumers to pull these from EUI instead of react-beautiful-dnd
Expand Down
6 changes: 3 additions & 3 deletions src/components/drag_and_drop/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ interface DropResult {
[droppableId: string]: any[];
}

export const reorder = (
export const euiDragDropReorder = (
list: [],
startIndex: number,
endIndex: number
Expand All @@ -16,7 +16,7 @@ export const reorder = (
return result;
};

export const move = (
export const euiDragDropMove = (
sourceList: any[],
destinationList: any[],
dropResultSource: DraggableLocation,
Expand All @@ -34,7 +34,7 @@ export const move = (
};
};

export const copy = (
export const euiDragDropCopy = (
sourceList: any[],
destinationList: any[],
dropResultSource: DraggableLocation,
Expand Down
3 changes: 3 additions & 0 deletions src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ export {
EuiDragDropContext,
EuiDraggable,
EuiDroppable,
euiDragDropCopy,
euiDragDropMove,
euiDragDropReorder,
} from './drag_and_drop';

export { EuiEmptyPrompt } from './empty_prompt';
Expand Down