Skip to content

Commit 91058c4

Browse files
committed
feat(grid): add class for previewed selection
1 parent 68cafba commit 91058c4

File tree

5 files changed

+44
-11
lines changed

5 files changed

+44
-11
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
$ui-grid-cell-background-color: var(--color-background, #ffffff);
22
$ui-grid-border-color: var(--color-border-de-emp, #cfd8dd);
3-
$ui-grid-cell-bottom-border: 0.5px solid $ui-grid-border-color;
3+
$ui-grid-cell-bottom-border: 1px solid $ui-grid-border-color;
44
$ui-grid-row-hover-color: var(--color-hover, #e9f1fa);
55
$header-background-color: var(--color-background-secondary, #f4f5f7);
66
$grid-actions-box-shadow: var(--color-background, #ffffff);
7+
$preview-selection-color: var(--color-primary, #0067df);

projects/angular/components/ui-grid/src/body/ui-grid-column.directive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export class UiGridColumnDirective<T> implements OnChanges, OnDestroy {
169169
}
170170

171171
/**
172-
* If the column should be styled as primary.
172+
* If the column should be styled as primary. Has the side-effect of setting column to sticky.
173173
*
174174
*/
175175
@Input()

projects/angular/components/ui-grid/src/ui-grid.component.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,8 @@
378378
index: index,
379379
expanded: expandedEntries,
380380
last: last,
381-
columnWidths: columnWidths
381+
columnWidths: columnWidths,
382+
previewSelectedEntityId: (previewSelected$ | async)
382383
}">
383384
</ng-container>
384385
</ng-container>
@@ -401,12 +402,14 @@
401402
let-expanded="expanded"
402403
let-last="last"
403404
let-index="index"
404-
let-columnWidths="columnWidths">
405+
let-columnWidths="columnWidths"
406+
let-previewSelectedEntityId="previewSelectedEntityId">
405407
<div cdkMonitorSubtreeFocus
406408
class="ui-grid-row"
407409
*ngIf="!isRowExpanded(row?.id) || expandMode === 'preserve'"
408410
[class.ui-grid-row-state-expanded]="isRowExpanded(row?.id)"
409411
[class.ui-grid-border-none]="!footer && last"
412+
[class.selected-preview]="previewSelectedEntityId === row?.id"
410413
[ngClass]="rowConfig?.ngClassFn(row) ?? ''"
411414
[tabIndex]="0"
412415
[attr.data-row-index]="index"

projects/angular/components/ui-grid/src/ui-grid.component.scss

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,12 @@ ui-grid {
463463
}
464464
}
465465
}
466+
467+
&.selected-preview {
468+
> div:first-of-type {
469+
box-shadow: inset 4px 0px 0px $preview-selection-color;
470+
}
471+
}
466472
}
467473

468474
.ui-grid-header-row,
@@ -602,7 +608,6 @@ ui-grid {
602608
padding-right: $ui-grid-default-spacing;
603609
right: 0;
604610
bottom: 0;
605-
box-shadow: -16px 0px 16px -4px $ui-grid-row-hover-color;
606611
}
607612
}
608613
}

projects/angular/components/ui-grid/src/ui-grid.component.ts

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ export class UiGridComponent<T extends IGridDataEntry>
209209
this._initResizeManager();
210210
}
211211
}
212+
get resizeStrategy() {
213+
return this._resizeStrategy;
214+
}
212215

213216
/**
214217
* Marks the grid loading state.
@@ -413,6 +416,15 @@ export class UiGridComponent<T extends IGridDataEntry>
413416
@Input()
414417
useCardView = false;
415418

419+
/**
420+
* Id of the entity that should be previewed
421+
*
422+
*/
423+
@Input()
424+
set previewSelectionId(value: string) {
425+
this.previewSelected$.next(value);
426+
}
427+
416428
/**
417429
* Emits an event with the sort model when a column sort changes.
418430
*
@@ -696,6 +708,12 @@ export class UiGridComponent<T extends IGridDataEntry>
696708
})),
697709
);
698710

711+
/**
712+
* Emits the id of the entity that should be previewed.
713+
*
714+
*/
715+
previewSelected$ = new BehaviorSubject<string | number>('');
716+
699717
/**
700718
* @internal
701719
* @ignore
@@ -1127,13 +1145,19 @@ export class UiGridComponent<T extends IGridDataEntry>
11271145
}
11281146

11291147
onRowClick(event: Event, row: T) {
1130-
if (this.shouldSelectOnRowClick && (event.target instanceof Element) &&
1148+
if ((event.target instanceof Element) &&
11311149
!EXCLUDED_ROW_SELECTION_ELEMENTS.find(el => (event.target as Element).closest(el))) {
1132-
if (this.singleSelectable) {
1133-
this.rowSelected(row);
1134-
} else {
1135-
this.selectionManager.toggle(row);
1136-
}
1150+
if (this.resizeStrategy === ResizeStrategy.ScrollableGrid) {
1151+
this.previewSelected$.next(row.id);
1152+
}
1153+
1154+
if (this.shouldSelectOnRowClick) {
1155+
if (this.singleSelectable) {
1156+
this.rowSelected(row);
1157+
} else {
1158+
this.selectionManager.toggle(row);
1159+
}
1160+
}
11371161
}
11381162
this.rowClick.emit({
11391163
event,

0 commit comments

Comments
 (0)