Skip to content
Draft
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
6 changes: 2 additions & 4 deletions packages/plasma-hope/api/plasma-hope.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ import { ShiftProps } from '@salutejs/plasma-core';
import { SmartPaginationDotsProps as SmartPaginationDotsProps_2 } from '@salutejs/plasma-core';
import { SnapAlign } from '@salutejs/plasma-core';
import { SnapType } from '@salutejs/plasma-core';
import { SortableContainerProps } from 'react-sortable-hoc';
import { SortableElementProps } from 'react-sortable-hoc';
import { SpacingProps } from '@salutejs/plasma-core';
import { StyledCard } from '@salutejs/plasma-core';
import { StyledComponent } from 'styled-components';
Expand Down Expand Up @@ -804,7 +802,7 @@ export { Popup }
export { PopupProps }

// @public
export const PreviewGallery: FC<PreviewGalleryProps & HTMLAttributes<HTMLDivElement> & SortableContainerProps>;
export const PreviewGallery: FC<PreviewGalleryProps & HTMLAttributes<HTMLDivElement>>;

// @public (undocumented)
export interface PreviewGalleryItemProps {
Expand All @@ -826,7 +824,7 @@ export interface PreviewGalleryProps {
actionIcon: JSX.Element;
// Warning: (ae-forgotten-export) The symbol "InteractionType" needs to be exported by the entry point index.d.ts
interactionType?: InteractionType;
items?: Array<PreviewGalleryItemProps & Omit<SortableElementProps, 'index'>>;
items?: Array<PreviewGalleryItemProps>;
itemSize?: string;
maxHeight?: number;
onItemAction?: (id: string | number) => void;
Expand Down
142 changes: 94 additions & 48 deletions packages/plasma-hope/package-lock.json

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

3 changes: 2 additions & 1 deletion packages/plasma-hope/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@
"directory": "packages/plasma-web-core"
},
"dependencies": {
"@dnd-kit/core": "6.3.1",
"@dnd-kit/sortable": "10.0.0",
"@popperjs/core": "2.9.2",
"@salutejs/plasma-core": "1.191.0",
"@salutejs/plasma-typo": "0.41.0",
"react-file-drop": "3.1.6",
"react-popper": "2.3.0",
"react-sortable-hoc": "2.0.0",
"storeon": "3.1.4"
},
"peerDependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useCallback, useState } from 'react';
import type { FC, HTMLAttributes } from 'react';
import { SortableContainerProps, SortableElementProps } from 'react-sortable-hoc';
import type { DragEndEvent } from '@dnd-kit/core';

import { noop } from './utils';
import { PreviewGalleryListItems } from './PreviewGalleryItems';
Expand All @@ -16,7 +16,7 @@ export interface PreviewGalleryProps {
/**
* Массив элементов.
*/
items?: Array<PreviewGalleryItemProps & Omit<SortableElementProps, 'index'>>;
items?: Array<PreviewGalleryItemProps>;
/**
* Тип взаимодействия с галереей - выбор или перетаскивание элементов.
*/
Expand Down Expand Up @@ -50,7 +50,7 @@ export interface PreviewGalleryProps {
/**
* Компонент для создания галереи превью изображений.
*/
export const PreviewGallery: FC<PreviewGalleryProps & HTMLAttributes<HTMLDivElement> & SortableContainerProps> = ({
export const PreviewGallery: FC<PreviewGalleryProps & HTMLAttributes<HTMLDivElement>> = ({
interactionType = 'selectable',
items = [],
maxHeight = 0,
Expand All @@ -59,19 +59,25 @@ export const PreviewGallery: FC<PreviewGalleryProps & HTMLAttributes<HTMLDivElem
onItemsSortEnd = noop,
...rest
}) => {
const distance = 1;
const axis = 'xy';
const [isGrabbing, setGrabbing] = useState<boolean>(false);

const onSortStart = useCallback(() => setGrabbing(true), []);

const onSortEnd = useCallback(
(indexes: SortableIndexProps) => {
(event: DragEndEvent) => {
setGrabbing(false);

onItemsSortEnd(indexes);
const { active, over } = event;
if (!over || active.id === over.id) {
return;
}

const oldIndex = items.findIndex((item) => item.id === active.id);
const newIndex = items.findIndex((item) => item.id === over.id);

onItemsSortEnd({ oldIndex, newIndex });
},
[onItemsSortEnd],
[items, onItemsSortEnd],
);

return (
Expand All @@ -81,8 +87,6 @@ export const PreviewGallery: FC<PreviewGalleryProps & HTMLAttributes<HTMLDivElem
onItemClick={onItemClick}
onSortStart={onSortStart}
onSortEnd={onSortEnd}
axis={axis}
distance={distance}
interactionType={interactionType}
isGrabbing={isGrabbing}
maxHeight={maxHeight}
Expand Down
Loading
Loading