Skip to content

Commit

Permalink
fix(components): add "cssText" option to both Footer/Pagination
Browse files Browse the repository at this point in the history
- the "cssText" is used by the width calculation, which calculate (100% width - rightPadding), but user could overwrite it with his own width or any other css style to the Footer/Pagination container element
  • Loading branch information
ghiscoding-SE committed Jul 23, 2020
1 parent a33e387 commit abd4fcd
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 16 deletions.
14 changes: 12 additions & 2 deletions packages/common/src/interfaces/customFooterOption.interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
export interface CustomFooterOption {
/**
* Defaults to "width: calc(100% - ${gridOptions.autoResize.rightPadding}px)", CSS width of the Custom Footer element.
* The width is calculated by taking in consideration "autoResize.rightPadding" that might optionally be provided in the grid options
*
* IMPORTANT NOTE:
* This property is already used by the "width" calculation, which is the default CSS styling (width: calc(100% - {rightPadding})),
* If you want to use it for something else than the width then make sure to also include the width calculation inside that text styling
*/
cssText?: string;

/** Optionally pass some text to be displayed on the left side (in the "left-footer" css class) */
leftFooterText?: string;

Expand All @@ -8,8 +18,8 @@ export interface CustomFooterOption {
/** Date format used when showing the "Last Update" timestamp in the metrics section. */
dateFormat?: string;

/** Defaults to 25, height of the Custom Footer in pixels (this is required and is used by the auto-resizer) */
footerHeight?: number;
/** Defaults to 25, height of the Custom Footer in pixels, it could be a number (25) or a string ("25px") but it has to be in pixels. It will be used by the auto-resizer calculations. */
footerHeight?: number | string;

/** Defaults to false, do we want to hide the last update timestamp (endTime)? */
hideLastUpdateTimestamp?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/interfaces/gridOption.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ export interface GridOption {
/** Defaults to true, which will display numbers indicating column sort precedence are displayed in the columns when multiple columns selected */
numberedMultiColumnSort?: boolean;

/** Pagination options, these are currently used ONLY with a Backend Service API (GraphQL/OData Services) */
/** Pagination options (pageSize, pageSizes, pageNumber, totalItems) */
pagination?: Pagination;

/** if you want to pass custom paramaters to your Formatter/Editor or anything else */
Expand Down
10 changes: 10 additions & 0 deletions packages/common/src/interfaces/pagination.interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
export interface Pagination {
/**
* Defaults to "width: calc(100% - ${gridOptions.autoResize.rightPadding}px)", CSS width of the Pagination element.
* The width is calculated by taking in consideration "autoResize.rightPadding" that might optionally be provided in the grid options
*
* IMPORTANT NOTE:
* This property is already used by the "width" calculation, which is the default CSS styling (width: calc(100% - {rightPadding})),
* If you want to use it for something else than the width then make sure to also include the width calculation inside that text styling
*/
cssText?: string;

/** Current page number that we are we currently displaying. */
pageNumber?: number;

Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('Slick-Footer Component', () => {
mockGridOptions.autoResize = { rightPadding: 15 };
component.renderFooter(div);

expect(component.width).toBe('width: calc(100% - 15px);');
expect(component.cssText).toBe('width: calc(100% - 15px);');
});

it('should create a the Slick-Footer component in the DOM', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe('Slick-Pagination Component', () => {
mockGridOptions.autoResize = { rightPadding: 15 };
component.renderPagination(div);

expect(component.width).toBe('width: calc(100% - 15px);');
expect(component.cssText).toBe('width: calc(100% - 15px);');
});

it('should create a the Slick-Pagination component in the DOM', () => {
Expand Down
10 changes: 5 additions & 5 deletions packages/vanilla-bundle/src/components/slick-footer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { BindingHelper } from '../services/binding.helper';
export class SlickFooterComponent {
private _bindingHelper: BindingHelper;
private _footerElement: HTMLDivElement;
private _width = '100%';
private _defaultCssText = '100%';

get gridUid(): string {
return this.grid?.getUID() ?? '';
Expand All @@ -32,8 +32,8 @@ export class SlickFooterComponent {
return this.gridOptions.locales || Constants.locales;
}

get width() {
return this._width;
get cssText() {
return this._defaultCssText;
}

set metrics(metrics: Metrics) {
Expand Down Expand Up @@ -86,12 +86,12 @@ export class SlickFooterComponent {
private createFooterContainer(gridParentContainerElm: HTMLElement) {
// when user adds an extra right padding on the auto-resize, we need to deduct it from our footer width
if (this.gridOptions.autoResize?.rightPadding) {
this._width = `width: calc(100% - ${this.gridOptions.autoResize.rightPadding}px);`;
this._defaultCssText = `width: calc(100% - ${this.gridOptions.autoResize.rightPadding}px);`;
}

const footerElm = document.createElement('div');
footerElm.className = `slick-custom-footer row ${this.gridUid}`;
footerElm.style.cssText = this._width;
footerElm.style.cssText = this.customFooterOptions?.cssText ?? this._defaultCssText;
footerElm.style.height = `${this.customFooterOptions.footerHeight || 20}px`;

const leftFooterElm = document.createElement('div');
Expand Down
10 changes: 5 additions & 5 deletions packages/vanilla-bundle/src/components/slick-pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class SlickPaginationComponent {
private _enableTranslate = false;
private _locales: Locale;
private _subscriptions: Subscription[] = [];
private _width = '100%';
private _defaultCssText = '100%';
currentPagination: ServicePagination;
firstButtonClasses = '';
lastButtonClasses = '';
Expand Down Expand Up @@ -121,8 +121,8 @@ export class SlickPaginationComponent {
return this.pageNumber === this.pageCount || this.totalItems === 0;
}

get width() {
return this._width;
get cssText() {
return this._defaultCssText;
}

dispose() {
Expand All @@ -140,14 +140,14 @@ export class SlickPaginationComponent {
if (paginationTemplate) {
// when user adds an extra right padding on the auto-resize, we need to deduct it from our pagination width
if (this.gridOptions.autoResize?.rightPadding) {
this._width = `width: calc(100% - ${this.gridOptions.autoResize.rightPadding}px);`;
this._defaultCssText = `width: calc(100% - ${this.gridOptions.autoResize.rightPadding}px);`;
}

const temp = document.createElement('div');
temp.innerHTML = paginationTemplate;
this._paginationElement = temp.firstChild as HTMLDivElement;
this._paginationElement.classList.add(this.gridUid, 'pager');
this._paginationElement.style.cssText = this._width;
this._paginationElement.style.cssText = this.gridOptions.pagination?.cssText ?? this._defaultCssText;

if (gridParentContainerElm?.appendChild && this._paginationElement) {
gridParentContainerElm.appendChild(this._paginationElement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,8 @@ export class SlickVanillaGridBundle {
const fixedGridDimensions = (this._gridOptions?.gridHeight || this._gridOptions?.gridWidth) ? { height: this._gridOptions?.gridHeight, width: this._gridOptions?.gridWidth } : undefined;
const autoResizeOptions = this._gridOptions?.autoResize ?? { bottomPadding: 0 };
if (autoResizeOptions && autoResizeOptions.bottomPadding !== undefined) {
autoResizeOptions.bottomPadding += this._gridOptions?.customFooterOptions?.footerHeight ?? DATAGRID_FOOTER_HEIGHT;
const footerHeight: string | number = this._gridOptions?.customFooterOptions?.footerHeight ?? DATAGRID_FOOTER_HEIGHT;
autoResizeOptions.bottomPadding += parseInt(`${footerHeight}`, 10);
}
if (autoResizeOptions && autoResizeOptions.bottomPadding !== undefined && this._gridOptions.enablePagination) {
autoResizeOptions.bottomPadding += DATAGRID_PAGINATION_HEIGHT;
Expand Down

0 comments on commit abd4fcd

Please sign in to comment.