Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Commit 6ccd6f3

Browse files
committed
fix: hide Toggle Dark Mode from Grid Menu by default
1 parent b5d6191 commit 6ccd6f3

File tree

5 files changed

+26
-10
lines changed

5 files changed

+26
-10
lines changed

src/app/examples/grid-composite-editor.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div id="demo-container" class="container-fluid">
22
<h2>
33
{{title}}
4-
<button class="btn btn-outline-secondary btn-sm ms-3" (click)="toggleDarkModeGrid()"
4+
<button class="btn btn-outline-secondary btn-sm ms-3" (click)="toggleDarkMode()"
55
data-test="toggle-dark-mode">
66
<span>Toggle Dark Mode</span>
77
</button>

src/app/examples/grid-composite-editor.component.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ const myCustomTitleValidator = (value: any, args: any) => {
8484
encapsulation: ViewEncapsulation.None,
8585
})
8686
export class GridCompositeEditorComponent implements OnDestroy, OnInit {
87-
private _darkModeGrid = false;
87+
private _darkMode = false;
8888
title = 'Example 30: Composite Editor Modal';
8989
subTitle = `Composite Editor allows you to Create, Clone, Edit, Mass Update & Mass Selection Changes inside a nice Modal Window.
9090
<br>The modal is simply populated by looping through your column definition list and also uses a lot of the same logic as inline editing (see <a href="https://ghiscoding.gitbook.io/angular-slickgrid/grid-functionalities/composite-editor-modal" target="_blank">Composite Editor - Uncyclo</a>.)`;
@@ -384,7 +384,7 @@ export class GridCompositeEditorComponent implements OnDestroy, OnInit {
384384
container: '#demo-container',
385385
rightPadding: 10
386386
},
387-
darkMode: this._darkModeGrid,
387+
darkMode: this._darkMode,
388388
enableAutoSizeColumns: true,
389389
enableAutoResize: true,
390390
showCustomFooter: true,
@@ -443,6 +443,15 @@ export class GridCompositeEditorComponent implements OnDestroy, OnInit {
443443
},
444444
// when using the cellMenu, you can change some of the default options and all use some of the callback methods
445445
enableCellMenu: true,
446+
gridMenu: {
447+
hideToggleDarkModeCommand: false, // disabled command by default
448+
onCommand: (_, args) => {
449+
if (args.command === 'toggle-dark-mode') {
450+
this._darkMode = !this._darkMode; // keep local toggle var in sync
451+
this.toggleBodyBackground();
452+
}
453+
}
454+
}
446455
};
447456
}
448457

@@ -625,7 +634,7 @@ export class GridCompositeEditorComponent implements OnDestroy, OnInit {
625634
onRendered: (modalElm) => {
626635
// Bootstrap requires extra attribute when toggling Dark Mode (data-bs-theme="dark")
627636
// we need to manually add this attribute ourselve before opening the Composite Editor Modal
628-
modalElm.dataset.bsTheme = this._darkModeGrid ? 'dark' : 'light';
637+
modalElm.dataset.bsTheme = this._darkMode ? 'dark' : 'light';
629638
},
630639
onSave: (formValues, _selection, dataContext) => {
631640
const serverResponseDelay = 50;
@@ -762,16 +771,20 @@ export class GridCompositeEditorComponent implements OnDestroy, OnInit {
762771
this.editQueue = [];
763772
}
764773

765-
toggleDarkModeGrid() {
766-
this._darkModeGrid = !this._darkModeGrid;
767-
if (this._darkModeGrid) {
774+
toggleDarkMode() {
775+
this._darkMode = !this._darkMode;
776+
this.toggleBodyBackground();
777+
this.angularGrid.slickGrid?.setOptions({ darkMode: this._darkMode });
778+
}
779+
780+
toggleBodyBackground() {
781+
if (this._darkMode) {
768782
document.querySelector<HTMLDivElement>('.panel-wm-content')!.classList.add('dark-mode');
769783
document.querySelector<HTMLDivElement>('#demo-container')!.dataset.bsTheme = 'dark';
770784
} else {
771785
document.querySelector('.panel-wm-content')!.classList.remove('dark-mode');
772786
document.querySelector<HTMLDivElement>('#demo-container')!.dataset.bsTheme = 'light';
773787
}
774-
this.angularGrid.slickGrid?.setOptions({ darkMode: this._darkModeGrid });
775788
}
776789

777790
mockProducts() {

src/app/examples/grid-contextmenu.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div class="container-fluid">
22
<h2>
33
{{title}}
4-
<button class="btn btn-outline-secondary btn-sm ms-3" (click)="toggleDarkModeGrid()"
4+
<button class="btn btn-outline-secondary btn-sm ms-3" (click)="toggleDarkMode()"
55
data-test="toggle-dark-mode">
66
<span>Toggle Dark Mode</span>
77
</button>

src/app/examples/grid-contextmenu.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ export class GridContextMenuComponent implements OnInit, OnDestroy {
547547
);
548548
}
549549

550-
toggleDarkModeGrid() {
550+
toggleDarkMode() {
551551
this._darkModeGrid = !this._darkModeGrid;
552552
if (this._darkModeGrid) {
553553
document.querySelector<HTMLDivElement>('.panel-wm-content')!.classList.add('dark-mode');

src/app/modules/angular-slickgrid/global-grid-options.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ export const GlobalGridOptions: Partial<GridOption> = {
146146
exportExcelCommandKey: 'EXPORT_TO_EXCEL',
147147
exportTextDelimitedCommandKey: 'EXPORT_TO_TAB_DELIMITED',
148148
refreshDatasetCommandKey: 'REFRESH_DATASET',
149+
toggleDarkModeCommandKey: 'TOGGLE_DARK_MODE',
149150
toggleFilterCommandKey: 'TOGGLE_FILTER_ROW',
150151
togglePreHeaderCommandKey: 'TOGGLE_PRE_HEADER_ROW',
151152
},
@@ -158,6 +159,7 @@ export const GlobalGridOptions: Partial<GridOption> = {
158159
hideForceFitButton: false,
159160
hideRefreshDatasetCommand: false,
160161
hideSyncResizeButton: true,
162+
hideToggleDarkModeCommand: true,
161163
hideToggleFilterCommand: false,
162164
hideTogglePreHeaderCommand: false,
163165
iconCssClass: 'fa fa-bars',
@@ -168,6 +170,7 @@ export const GlobalGridOptions: Partial<GridOption> = {
168170
iconExportExcelCommand: 'fa fa-file-excel-o text-success',
169171
iconExportTextDelimitedCommand: 'fa fa-download',
170172
iconRefreshDatasetCommand: 'fa fa-refresh',
173+
iconToggleDarkModeCommand: 'fa fa-moon-o mdi mdi-brightness-4',
171174
iconToggleFilterCommand: 'fa fa-random',
172175
iconTogglePreHeaderCommand: 'fa fa-random',
173176
menuWidth: 16,

0 commit comments

Comments
 (0)