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

fix: hide Toggle Dark Mode from Grid Menu by default #308

Merged
merged 5 commits into from
Mar 23, 2024
Merged
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
29 changes: 29 additions & 0 deletions docs/styling/dark-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,35 @@ this.compositeEditorInstance?.openDetails({
});
```

### Grid Menu
By default there is no command for toggling the Dark Mode from the Grid Menu, however you can show the command at any time via the following settings:

```ts
export class MyDemo {
isDarkModeEnabled = false;

defineGrid() {
this.gridOptions = {
darkMode: this.isDarkModeEnabled,
gridMenu: {
hideToggleDarkModeCommand: false, // hidden by default

// you can optionally add extra command to toggle your own page styling as well
onCommand: (_, args) => {
// ...
},

// you can also change the icon and/or command name
iconToggleDarkModeCommand: 'fa fa-moon-o',
commandLabels: {
toggleDarkModeCommand: 'Toggle Dark Mode',
},
}
};
}
}
```

### Tweaking Some Colors

The Dark Mode Theme was created by setting a few CSS variables, in some cases you might need to tweak some of these variables. Take a look at the Slickgrid-Universal [CSS variables](https://github.com/ghiscoding/slickgrid-universal/blob/670946dcedd330a70d2e88127a0042474e7a5348/packages/common/src/styles/_variables.scss#L976-L985) to see which variables were reassigned. Also note that if you're using other Themes like Material or Salesforce, then there's also other variables that are set (see [Material variables](https://github.com/ghiscoding/slickgrid-universal/blob/670946dcedd330a70d2e88127a0042474e7a5348/packages/common/src/styles/_variables-theme-material.scss#L159-L189) or [Salesforce variables](https://github.com/ghiscoding/slickgrid-universal/blob/670946dcedd330a70d2e88127a0042474e7a5348/packages/common/src/styles/_variables-theme-salesforce.scss#L202-L219))
Expand Down
4 changes: 2 additions & 2 deletions src/examples/slickgrid/Example24.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ class Example24 extends React.Component<Props, State> {
this.setState((state: State) => ({ ...state, selectedLanguage: nextLanguage }));
}

toggleDarkModeGrid() {
toggleDarkMode() {
this._darkModeGrid = !this._darkModeGrid;
if (this._darkModeGrid) {
document.querySelector<HTMLDivElement>('.panel-wm-content')!.classList.add('dark-mode');
Expand All @@ -584,7 +584,7 @@ class Example24 extends React.Component<Props, State> {
<span className="fa fa-link"></span> code
</a>
</span>
<button className="btn btn-outline-secondary btn-sm ms-2" onClick={() => this.toggleDarkModeGrid()} data-test="toggle-dark-mode">
<button className="btn btn-outline-secondary btn-sm ms-2" onClick={() => this.toggleDarkMode()} data-test="toggle-dark-mode">
<span>Toggle Dark Mode</span>
</button>
</h2>
Expand Down
27 changes: 20 additions & 7 deletions src/examples/slickgrid/Example30.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ interface State extends BaseSlickGridState {
complexityLevelList: Array<{ value: number; label: string; }>;
}
export default class Example30 extends React.Component<Props, State> {
private _darkModeGrid = false;
private _darkMode = false;

title = 'Example 30: Composite Editor Modal';
subTitle = `Composite Editor allows you to Create, Clone, Edit, Mass Update & Mass Selection Changes inside a nice Modal Window.
Expand Down Expand Up @@ -451,6 +451,15 @@ export default class Example30 extends React.Component<Props, State> {
},
// when using the cellMenu, you can change some of the default options and all use some of the callback methods
enableCellMenu: true,
gridMenu: {
hideToggleDarkModeCommand: false, // hidden by default
onCommand: (_, args) => {
if (args.command === 'toggle-dark-mode') {
this._darkMode = !this._darkMode; // keep local toggle var in sync
this.toggleBodyBackground();
}
}
}
};

this.setState((state: State) => ({
Expand Down Expand Up @@ -645,7 +654,7 @@ export default class Example30 extends React.Component<Props, State> {
onRendered: (modalElm) => {
// Bootstrap requires extra attribute when toggling Dark Mode (data-bs-theme="dark")
// we need to manually add this attribute ourselve before opening the Composite Editor Modal
modalElm.dataset.bsTheme = this._darkModeGrid ? 'dark' : 'light';
modalElm.dataset.bsTheme = this._darkMode ? 'dark' : 'light';
},
onSave: (formValues, _selection, dataContext) => {
const serverResponseDelay = 50;
Expand Down Expand Up @@ -690,16 +699,20 @@ export default class Example30 extends React.Component<Props, State> {
this.reactGrid.slickGrid.setOptions({ editable: isGridEditable });
}

toggleDarkModeGrid() {
this._darkModeGrid = !this._darkModeGrid;
if (this._darkModeGrid) {
toggleDarkMode() {
this._darkMode = !this._darkMode;
this.toggleBodyBackground();
this.reactGrid.slickGrid?.setOptions({ darkMode: this._darkMode });
}

toggleBodyBackground() {
if (this._darkMode) {
document.querySelector<HTMLDivElement>('.panel-wm-content')!.classList.add('dark-mode');
document.querySelector<HTMLDivElement>('#demo-container')!.dataset.bsTheme = 'dark';
} else {
document.querySelector('.panel-wm-content')!.classList.remove('dark-mode');
document.querySelector<HTMLDivElement>('#demo-container')!.dataset.bsTheme = 'light';
}
this.reactGrid.slickGrid?.setOptions({ darkMode: this._darkModeGrid });
}

removeUnsavedStylingFromCell(_item: any, column: Column, row: number) {
Expand Down Expand Up @@ -1009,7 +1022,7 @@ export default class Example30 extends React.Component<Props, State> {
<div id="demo-container" className="container-fluid">
<h2>
{this.title}
<button className="btn btn-outline-secondary btn-sm ms-2" onClick={() => this.toggleDarkModeGrid()} data-test="toggle-dark-mode">
<button className="btn btn-outline-secondary btn-sm ms-2" onClick={() => this.toggleDarkMode()} data-test="toggle-dark-mode">
<span>Toggle Dark Mode</span>
</button>
<span className="float-end font18">
Expand Down
1 change: 1 addition & 0 deletions src/slickgrid-react/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export class Constants {
TEXT_SORT_ASCENDING: 'Sort Ascending',
TEXT_SORT_DESCENDING: 'Sort Descending',
TEXT_STARTS_WITH: 'Starts With',
TEXT_TOGGLE_DARK_MODE: 'Toggle Dark Mode',
TEXT_TOGGLE_FILTER_ROW: 'Toggle Filter Row',
TEXT_TOGGLE_PRE_HEADER_ROW: 'Toggle Pre-Header Row',
TEXT_X_OF_Y_SELECTED: '# of % selected',
Expand Down
3 changes: 3 additions & 0 deletions src/slickgrid-react/global-grid-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ export const GlobalGridOptions: Partial<GridOption> = {
exportExcelCommandKey: 'EXPORT_TO_EXCEL',
exportTextDelimitedCommandKey: 'EXPORT_TO_TAB_DELIMITED',
refreshDatasetCommandKey: 'REFRESH_DATASET',
toggleDarkModeCommandKey: 'TOGGLE_DARK_MODE',
toggleFilterCommandKey: 'TOGGLE_FILTER_ROW',
togglePreHeaderCommandKey: 'TOGGLE_PRE_HEADER_ROW',
},
Expand All @@ -181,6 +182,7 @@ export const GlobalGridOptions: Partial<GridOption> = {
hideForceFitButton: false,
hideRefreshDatasetCommand: false,
hideSyncResizeButton: true,
hideToggleDarkModeCommand: true,
hideToggleFilterCommand: false,
hideTogglePreHeaderCommand: false,
iconCssClass: 'fa fa-bars',
Expand All @@ -191,6 +193,7 @@ export const GlobalGridOptions: Partial<GridOption> = {
iconExportExcelCommand: 'fa fa-file-excel-o',
iconExportTextDelimitedCommand: 'fa fa-download',
iconRefreshDatasetCommand: 'fa fa-refresh',
iconToggleDarkModeCommand: 'fa fa-moon-o mdi mdi-brightness-4',
iconToggleFilterCommand: 'fa fa-random',
iconTogglePreHeaderCommand: 'fa fa-random',
menuWidth: 16,
Expand Down
22 changes: 11 additions & 11 deletions test/cypress/e2e/example16.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ describe('Example 16 - Row Move & Checkbox Selector Selector Plugins', () => {
cy.get('[data-test="toggle-filtering-btn"]').click(); // show it back
});

it.skip('should expect "Clear all Filters" command to be hidden in the Grid Menu', () => {
it('should expect "Clear all Filters" command to be hidden in the Grid Menu', () => {
const expectedFullHeaderMenuCommands = ['Clear all Filters', 'Clear all Sorting', 'Toggle Filter Row', 'Export to Excel'];

cy.get('#grid16')
Expand All @@ -169,7 +169,7 @@ describe('Example 16 - Row Move & Checkbox Selector Selector Plugins', () => {
});
});

it.skip('should be able to toggle Filters functionality', () => {
it('should be able to toggle Filters functionality', () => {
const expectedTitles = ['', '', 'Title', '% Complete', 'Start', 'Finish', 'Completed', 'Title'];

cy.get('[data-test="toggle-filtering-btn"]').click(); // hide it
Expand All @@ -191,7 +191,7 @@ describe('Example 16 - Row Move & Checkbox Selector Selector Plugins', () => {
.each(($child, index) => expect($child.text()).to.eq(expectedTitles[index]));
});

it.skip('should be able to toggle Sorting functionality (disable) and expect all header menu Sorting commands to be hidden and also not show Sort hint while hovering a column', () => {
it('should be able to toggle Sorting functionality (disable) and expect all header menu Sorting commands to be hidden and also not show Sort hint while hovering a column', () => {
const expectedFullHeaderMenuCommands = ['Resize by Content', '', 'Sort Ascending', 'Sort Descending', '', 'Remove Filter', 'Remove Sort', 'Hide Column'];

cy.get('.slick-sort-indicator').should('have.length.greaterThan', 0); // sort icon hints
Expand Down Expand Up @@ -219,7 +219,7 @@ describe('Example 16 - Row Move & Checkbox Selector Selector Plugins', () => {
});
});

it.skip('should expect "Clear Sorting" command to be hidden in the Grid Menu', () => {
it('should expect "Clear Sorting" command to be hidden in the Grid Menu', () => {
const expectedFullHeaderMenuCommands = ['Clear all Filters', 'Clear all Sorting', 'Toggle Filter Row', 'Export to Excel'];

cy.get('#grid16')
Expand All @@ -240,7 +240,7 @@ describe('Example 16 - Row Move & Checkbox Selector Selector Plugins', () => {
});
});

it.skip('should be able to toggle Sorting functionality (re-enable) and expect all Sorting header menu commands to be hidden and also not show Sort hint while hovering a column', () => {
it('should be able to toggle Sorting functionality (re-enable) and expect all Sorting header menu commands to be hidden and also not show Sort hint while hovering a column', () => {
const expectedFullHeaderMenuCommands = ['Resize by Content', '', 'Sort Ascending', 'Sort Descending', '', 'Remove Filter', 'Remove Sort', 'Hide Column'];

cy.get('.slick-sort-indicator').should('have.length', 0); // sort icon hints
Expand All @@ -264,7 +264,7 @@ describe('Example 16 - Row Move & Checkbox Selector Selector Plugins', () => {
});
});

it.skip('should expect "Clear Sorting" command to be hidden in the Grid Menu', () => {
it('should expect "Clear Sorting" command to be hidden in the Grid Menu', () => {
const expectedFullHeaderMenuCommands = ['Clear all Filters', 'Clear all Sorting', 'Toggle Filter Row', 'Export to Excel'];

cy.get('#grid16')
Expand All @@ -285,7 +285,7 @@ describe('Example 16 - Row Move & Checkbox Selector Selector Plugins', () => {
});
});

it.skip('should be able to click disable Sorting functionality button and expect all Sorting commands to be hidden and also not show Sort hint while hovering a column', () => {
it('should be able to click disable Sorting functionality button and expect all Sorting commands to be hidden and also not show Sort hint while hovering a column', () => {
const expectedFullHeaderMenuCommands = ['Resize by Content', '', 'Sort Ascending', 'Sort Descending', '', 'Remove Filter', 'Remove Sort', 'Hide Column'];

cy.get('.slick-sort-indicator').should('have.length.greaterThan', 0); // sort icon hints
Expand Down Expand Up @@ -313,7 +313,7 @@ describe('Example 16 - Row Move & Checkbox Selector Selector Plugins', () => {
});
});

it.skip('should be able to click disable Filter functionality button and expect all Filter commands to be hidden and also not show Sort hint while hovering a column', () => {
it('should be able to click disable Filter functionality button and expect all Filter commands to be hidden and also not show Sort hint while hovering a column', () => {
const expectedFullHeaderMenuCommands = ['Resize by Content', '', 'Sort Ascending', 'Sort Descending', '', 'Remove Filter', 'Remove Sort', 'Hide Column'];

cy.get('[data-test="disable-filters-btn"]').click().click(); // even clicking twice should have same result
Expand All @@ -339,7 +339,7 @@ describe('Example 16 - Row Move & Checkbox Selector Selector Plugins', () => {
});
});

it.skip('should expect "Clear all Filters" command to be hidden in the Grid Menu', () => {
it('should expect "Clear all Filters" command to be hidden in the Grid Menu', () => {
const expectedFullHeaderMenuCommands = ['Clear all Filters', 'Clear all Sorting', 'Toggle Filter Row', 'Export to Excel'];

cy.get('#grid16')
Expand All @@ -360,7 +360,7 @@ describe('Example 16 - Row Move & Checkbox Selector Selector Plugins', () => {
});
});

it.skip('should open Column Picker and show the "Duration" column back to visible and expect it to have kept its position after toggling filter/sorting', () => {
it('should open Column Picker and show the "Duration" column back to visible and expect it to have kept its position after toggling filter/sorting', () => {
// first 2 cols are hidden but they do count as li item
const expectedFullPickerTitles = ['', '', 'Title', '% Complete', 'Start', 'Finish', 'Duration', 'Completed'];

Expand Down Expand Up @@ -403,7 +403,7 @@ describe('Example 16 - Row Move & Checkbox Selector Selector Plugins', () => {
});
});

it.skip('should add Edit/Delete columns and expect 2 new columns added at the beginning of the grid', () => {
it('should add Edit/Delete columns and expect 2 new columns added at the beginning of the grid', () => {
const newExpectedColumns = ['', '', ...fullTitles];
cy.get('[data-test="add-crud-columns-btn"]').click();

Expand Down