Skip to content

Commit

Permalink
PR: Library: Library Only: Dynamic matrix's row drag-n-drop (#9075)
Browse files Browse the repository at this point in the history
work for the #8596
  • Loading branch information
dmitry-kurmanov authored Dec 3, 2024
1 parent 05902a8 commit 01bd8ab
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 16 deletions.
25 changes: 25 additions & 0 deletions packages/survey-core/src/common-styles/sv-drag-drop.scss
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,31 @@
align-items: center;
line-height: 0;
}

.sd-table__cell.sd-table__cell--drag {
>div {
background-color: $question-background;
min-height: calcSize(6);
}
}
}

.sd-table__cell--header,
.sd-table__cell {
&.sd-table__cell--drag {
padding-right: 0;
padding-left: 0;
}
}

.sd-question--mobile {

.sd-table__cell--header,
.sd-table__cell {
&.sd-table__cell--drag {
display: none;
}
}
}

.sv-matrix-row--drag-drop-ghost-mod td {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,55 +58,80 @@
}
}

.sd-table__row:hover {
.sd-drag-element__svg {
visibility: visible;
}
}

.sd-table__cell.sd-table__cell--drag {
>div {
display: flex;
justify-content: end;
align-items: center;
margin-left: calcSize(-4);
width: calcSize(4);
background-color: $question-background;
min-height: calcSize(6);
}
}

.sd-drag-element__svg {
width: calcSize(2);
height: calcSize(2);
width: calcSize(3);
height: calcSize(3);
display: block;
cursor: pointer;
visibility: hidden;

use {
fill: $foreground-light;
fill: $primary;
}
}

@keyframes borderAnimation {
from {
border-width: 0px;
}

to {
border-width: 8px;
}
}

@keyframes paddingAnimation {
from {
padding-top: 0;
padding-bottom: 0;
}

to {
padding-top: 24px;
padding-bottom: 32px;
}
}

@keyframes empty {
from {
}
to {
}
from {}

to {}
}

.sd-table__row--leave,
.sd-table__row--enter {
animation-name: empty;
--move-whole-animation-duration: calc(var(--move-animation-duration) + var(--move-animation-delay));
--fade-whole-animation-duration: calc(var(--fade-animation-duration) + var(--fade-animation-delay));
animation-duration: max(var(--fade-whole-animation-duration), var(--move-whole-animation-duration));
& > td {

&>td {
animation-name: borderAnimation;
animation-direction: var(--animation-direction);
animation-timing-function: var(--animation-timing-function);
animation-duration: var(--move-animation-duration);
animation-fill-mode: forwards;
animation-delay: var(--move-animation-delay);
& > div {

&>div {
animation-name: fadeIn, moveInWithOverflow;
opacity: 0;
animation-direction: var(--animation-direction);
Expand All @@ -117,6 +142,7 @@
}
}
}

.sd-table__row--enter {
--move-animation-delay: 0s;
--move-animation-duration: #{$matrix-row-move-in-duration};
Expand All @@ -125,6 +151,7 @@
--animation-direction: normal;
--animation-timing-function: #{$ease-out};
}

.sd-table__row--leave {
--move-animation-delay: #{$matrix-row-move-out-delay};
--move-animation-duration: #{$matrix-row-move-out-duration};
Expand All @@ -133,10 +160,12 @@
--animation-direction: reverse;
--animation-timing-function: #{$reverse-ease-out};
}

.sd-table__row--detail {

&.sd-table__row--enter,
&.sd-table__row--leave {
& > td {
&>td {
animation-name: borderAnimation, paddingAnimation;
animation-duration: var(--move-animation-duration);
animation-fill-mode: forwards;
Expand All @@ -153,6 +182,7 @@
--animation-direction: normal;
--animation-timing-function: #{$ease-out};
}

&.sd-table__row--leave {
--move-animation-delay: #{$matrix-detail-row-move-out-delay};
--move-animation-duration: #{$matrix-detail-row-move-out-duration};
Expand All @@ -161,4 +191,4 @@
--animation-direction: reverse;
--animation-timing-function: #{$reverse-ease-out};
}
}
}
10 changes: 6 additions & 4 deletions packages/survey-core/src/question_matrixdropdownrendered.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ export class QuestionMatrixDropdownRenderedTable extends Base {
if (!isShown) return;
this.headerRowValue = this.createRenderedRow(this.cssClasses);
if (this.isRowsDragAndDrop) {
this.headerRow.cells.push(this.createHeaderCell(null, "action"));
this.headerRow.cells.push(this.createHeaderCell(null, "action", this.cssClasses.actionsCellDrag));
}
if (this.hasActionCellInRows("start")) {
this.headerRow.cells.push(this.createHeaderCell(null, "action"));
Expand Down Expand Up @@ -1072,23 +1072,25 @@ export class QuestionMatrixDropdownRenderedTable extends Base {
if (!choices || !Array.isArray(choices)) return null;
return choices;
}
private setHeaderCellCssClasses(cell: QuestionMatrixDropdownRenderedCell, cellType?: string): void {
private setHeaderCellCssClasses(cell: QuestionMatrixDropdownRenderedCell, cellType?: string, classMod?: string): void {
cell.className = new CssClassBuilder()
.append(this.cssClasses.headerCell)
.append(this.cssClasses.columnTitleCell, this.matrix.isColumnLayoutHorizontal)
.append(this.cssClasses.emptyCell, !!cell.isEmpty)
.append(this.cssClasses.cell + "--" + cellType, !!cellType)
.append(classMod, !!classMod)
.toString();
}
private createHeaderCell(
column: MatrixDropdownColumn,
cellType: string = null
cellType: string = null,
classMod?: string
): QuestionMatrixDropdownRenderedCell {
let cell = !!column ? this.createTextCell(column.locTitle) : this.createEmptyCell();
cell.column = column;
this.setHeaderCell(column, cell);
if (!cellType) cellType = (!!column && column.cellType !== "default") ? column.cellType : this.matrix.cellType;
this.setHeaderCellCssClasses(cell, cellType);
this.setHeaderCellCssClasses(cell, cellType, classMod);
return cell;
}
private setHeaderCell(
Expand Down
2 changes: 1 addition & 1 deletion packages/survey-core/src/question_matrixdynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class QuestionMatrixDynamicModel extends QuestionMatrixDropdownModelBase
return true;
}
public onPointerDown(pointerDownEvent: PointerEvent, row: MatrixDropdownRowModelBase):void {
if (!row || !this.isRowsDragAndDrop) return;
if (!row || !this.isRowsDragAndDrop || this.isDesignMode) return;
if (this.isBanStartDrag(pointerDownEvent)) return;
if (row.isDetailPanelShowing) return;
this.draggedRow = row;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions visualRegressionTests/tests/defaultV2/matrixdynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ frameworks.forEach(framework => {

const matrixdynamicRoot = Selector(".sd-question");
await resetFocusToBody();
await t.hover(matrixdynamicRoot.find(".sd-table__row"));
await takeElementScreenshot("matrixdynamic-allowRowsDragAndDrop.png", matrixdynamicRoot, t, comparer);
});
});
Expand All @@ -246,7 +247,10 @@ frameworks.forEach(framework => {

const matrixdynamicRoot = Selector(".sd-question");
await resetFocusToBody();
await t.hover(matrixdynamicRoot.find(".sd-table__row").nth(0));
await takeElementScreenshot("matrixdynamic-allowRowsDragAndDrop-lockedRowCount.png", matrixdynamicRoot, t, comparer);
await t.hover(matrixdynamicRoot.find(".sd-table__row").nth(1));
await takeElementScreenshot("matrixdynamic-allowRowsDragAndDrop-lockedRowCount-2.png", matrixdynamicRoot, t, comparer);

await ClientFunction(() => { (window as any).survey.getAllQuestions()[0].allowRowsDragAndDrop = false; })();
await takeElementScreenshot("matrixdynamic-lockedRowCount.png", matrixdynamicRoot, t, comparer);
Expand Down

0 comments on commit 01bd8ab

Please sign in to comment.