From 3889c887518b4515e01481c351556c3e31fa146b Mon Sep 17 00:00:00 2001 From: christophercr Date: Wed, 29 May 2019 17:54:10 +0200 Subject: [PATCH] refactor(stark-ui): remove 'StarkComponentUtil.isInputEnabled' in favor of Angular CDK function 'coerceBooleanProperty' ISSUES CLOSED: #1190 BREAKING CHANGE: `StarkComponentUtil.isInputEnabled()` function has been removed. To coerce boolean inputs in your components you can use the `coerceBooleanProperty()` function from `@angular/cdk/coercion` instead. --- .../table/components/table.component.ts | 7 ++--- packages/stark-ui/src/util.ts | 1 - packages/stark-ui/src/util/component.ts | 1 - .../src/util/component/component.util.spec.ts | 29 ------------------- .../src/util/component/component.util.ts | 12 -------- 5 files changed, 3 insertions(+), 47 deletions(-) delete mode 100644 packages/stark-ui/src/util/component.ts delete mode 100644 packages/stark-ui/src/util/component/component.util.spec.ts delete mode 100644 packages/stark-ui/src/util/component/component.util.ts diff --git a/packages/stark-ui/src/modules/table/components/table.component.ts b/packages/stark-ui/src/modules/table/components/table.component.ts index 9174c1ce6e..a512c5c1d4 100644 --- a/packages/stark-ui/src/modules/table/components/table.component.ts +++ b/packages/stark-ui/src/modules/table/components/table.component.ts @@ -43,7 +43,6 @@ import { import { AbstractStarkUiComponent } from "../../../common/classes/abstract-component"; import { StarkPaginationComponent, StarkPaginationConfig } from "../../pagination/components"; import { StarkPaginateEvent } from "../../pagination/components/paginate-event.intf"; -import { StarkComponentUtil } from "../../../util/component"; import { StarkMinimapComponentMode, StarkMinimapItemProperties } from "../../minimap/components"; import find from "lodash-es/find"; @@ -375,7 +374,7 @@ export class StarkTableComponent extends AbstractStarkUiComponent implements OnI * Whether the multiple row selection is enabled. */ public get isMultiSelectEnabled(): boolean { - return StarkComponentUtil.isInputEnabled(this.multiSelect); + return coerceBooleanProperty(this.multiSelect); } /** @@ -496,11 +495,11 @@ export class StarkTableComponent extends AbstractStarkUiComponent implements OnI } if (changes["fixedHeader"]) { - this.isFixedHeaderEnabled = StarkComponentUtil.isInputEnabled(this.fixedHeader); + this.isFixedHeaderEnabled = coerceBooleanProperty(this.fixedHeader); } if (changes["multiSort"]) { - this.isMultiSortEnabled = StarkComponentUtil.isInputEnabled(this.multiSort); + this.isMultiSortEnabled = coerceBooleanProperty(this.multiSort); } if (changes["rowsSelectable"]) { diff --git a/packages/stark-ui/src/util.ts b/packages/stark-ui/src/util.ts index 11909b94a1..f9ae097faa 100644 --- a/packages/stark-ui/src/util.ts +++ b/packages/stark-ui/src/util.ts @@ -1,3 +1,2 @@ -export * from "./util/component"; export * from "./util/dom"; export * from "./util/form"; diff --git a/packages/stark-ui/src/util/component.ts b/packages/stark-ui/src/util/component.ts deleted file mode 100644 index 87ee30b105..0000000000 --- a/packages/stark-ui/src/util/component.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./component/component.util"; diff --git a/packages/stark-ui/src/util/component/component.util.spec.ts b/packages/stark-ui/src/util/component/component.util.spec.ts deleted file mode 100644 index 45ddb4d422..0000000000 --- a/packages/stark-ui/src/util/component/component.util.spec.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { StarkComponentUtil } from "./component.util"; - -/* tslint:disable:no-big-function */ -describe("Util: ComponentUtil", () => { - describe("isInputEnabled", () => { - it("shouldReturnTrue", () => { - let result: boolean = StarkComponentUtil.isInputEnabled(""); - expect(result).toBe(true); - - result = StarkComponentUtil.isInputEnabled("true"); - expect(result).toBe(true); - - result = StarkComponentUtil.isInputEnabled(true); - expect(result).toBe(true); - }); - - it("shouldReturnFalse", () => { - let result: boolean = StarkComponentUtil.isInputEnabled("false"); - expect(result).toBe(false); - - result = StarkComponentUtil.isInputEnabled(false); - expect(result).toBe(false); - - /* tslint:disable-next-line:no-undefined-argument */ - result = StarkComponentUtil.isInputEnabled(undefined); - expect(result).toBe(false); - }); - }); -}); diff --git a/packages/stark-ui/src/util/component/component.util.ts b/packages/stark-ui/src/util/component/component.util.ts deleted file mode 100644 index 89ffeabc19..0000000000 --- a/packages/stark-ui/src/util/component/component.util.ts +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Stark specific Component commands - */ -export class StarkComponentUtil { - /** - * Check if passed input is equal to "true", empty string or true. - * @param input - Input to be checked - */ - public static isInputEnabled(input?: string): boolean { - return typeof input === "boolean" ? input : input === "true" || input === ""; - } -}