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

[feature] items in confirmChange #113

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const Example = () => (
| childrenProp | string | `"children"` | Name of a property for children. |
| className | string | `undefined` | Extra class name which can be passed to a root element. |
| collapsed | boolean | `false` | Makes groups collapsed by default. |
| confirmChange | function | `() => true` | Callback which has a single parameter with keys: `dragItem` - item which is being dragged, `destinationParent` - item where dragItem is about to land (or `null` if moving to root). Let function return `false` if this movement should not happen. |
| confirmChange | function | `() => true` | Callback which has a single parameter with keys: `dragItem` - item which is being dragged, `destinationParent` - item where dragItem is about to land (or `null` if moving to root), `items` - new array after position change. Let function return `false` if this movement should not happen. |
| disableCollapse | boolean | `false` | Disable toggling a collapsed state of items with children. If you need to set a specific initial state, then it is still possible to do so with the public method `collapse`. |
| disableDrag | boolean or function | `false` | Disable dragging. Pass boolean to apply to all items. Pass a callback to target individual items. It has a single parameter with keys: `item` - item from your array, `index` - number, index of the item, `depth` - number, depth of the item. |
| group | string or number | `random string` | Different group names may be passed if you have more than one nestable component on a page and want some extra styles for portal instances. |
Expand Down
4 changes: 2 additions & 2 deletions dist/Nestable/Nestable.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/Nestable/Nestable.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/example/example.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export type Item = Record<string, any>;
export type ConfirmChange = (options: {
dragItem: Item;
destinationParent: Item | null;
items: Item[];
}) => boolean;
export type DisableDragFn = (options: {
item: Item;
Expand Down
2 changes: 1 addition & 1 deletion src/Nestable/Nestable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ class Nestable extends Component<NestableProps, NestableState> {
? pathTo
: pathTo.slice(0, -1);
const destinationParent = this.getItemByPath(destinationPath);
if (!confirmChange({dragItem, destinationParent})) return;

const removePath = this.getSplicePath(pathFrom, {
numToRemove: 1,
Expand All @@ -170,6 +169,7 @@ class Nestable extends Component<NestableProps, NestableState> {

items = update(items, removePath);
items = update(items, insertPath);
if (!confirmChange({dragItem, destinationParent, items})) return;

this.setState(prevState => ({
...prevState,
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export type ConfirmChange = (
options: {
dragItem: Item;
destinationParent: Item | null;
items: Item[];
}
) => boolean;

Expand Down