-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add a mixin for disabled and apply it to md-button
- Loading branch information
Showing
4 changed files
with
53 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import {mixinDisabled} from './disabled'; | ||
|
||
|
||
describe('MixinDisabled', () => { | ||
it('should augment an existing class with a disabled property', () => { | ||
class EmptyClass { } | ||
|
||
let classWithDisabled = mixinDisabled(EmptyClass); | ||
let instance = new classWithDisabled(); | ||
|
||
expect(instance.disabled) | ||
.toBe(false, 'Expected the mixed-into class to have a disabled property'); | ||
|
||
instance.disabled = true; | ||
expect(instance.disabled) | ||
.toBe(true, 'Expected the mixed-into class to have an updated disabled property'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import {coerceBooleanProperty} from '../coercion/boolean-property'; | ||
|
||
|
||
/** @docs-private */ | ||
export type Constructor<T> = new(...args: any[]) => T; | ||
|
||
/** @docs-private */ | ||
export interface Disabled { | ||
disabled: boolean; | ||
} | ||
|
||
/** Mixin to augment a directive with a `disabled` property. */ | ||
export function mixinDisabled<T extends Constructor<{}>>(base: T): Constructor<Disabled> & T { | ||
return class extends base { | ||
private _disabled: boolean = false; | ||
|
||
get disabled() { return this._disabled; } | ||
set disabled(value: any) { this._disabled = coerceBooleanProperty(value); } | ||
|
||
constructor(...args: any[]) { super(...args); } | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {Disabled, mixinDisabled} from './disabled'; |