-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9a83dfb
commit 2c65ff5
Showing
8 changed files
with
60 additions
and
152 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
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 |
---|---|---|
@@ -1,21 +1,50 @@ | ||
/** | ||
* This interface should be used by components that want to leverage the error pattern. The error pattern conditionally adds error text to the template when an error is configured to be visible. | ||
*/ | ||
import { attr, FASTElement, observable } from '@microsoft/fast-element'; | ||
|
||
export interface ErrorPattern { | ||
/** | ||
* The error text that will be displayed when a component is in the error appearance | ||
*/ | ||
errorText?: string; | ||
|
||
/* | ||
* Show the error appearance of the control | ||
*/ | ||
errorVisible: boolean; | ||
errorHasOverflow: boolean; | ||
} | ||
|
||
/* @internal | ||
* Indicates if the error text has overflowed its container. The value should not be | ||
* set directly. Instead, it is used with the `overflow` directive. When declared in an | ||
* implementation of `ErrorPattern`, it must be declared as `@observable`. | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
type FASTElementConstructor = abstract new (...args: any[]) => FASTElement; | ||
|
||
// As the returned class is internal to the function, we can't write a signature that uses is directly, so rely on inference | ||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type | ||
export function mixinErrorPattern<TBase extends FASTElementConstructor>(base: TBase) { | ||
/** | ||
* The Mixin that provides a concrete column with the API to support being resized | ||
* proportionally within a Table. | ||
*/ | ||
errorHasOverflow: boolean; | ||
abstract class ErrorPatternElement extends base implements ErrorPattern { | ||
/** | ||
* The error text that will be displayed when a component is in the error appearance | ||
*/ | ||
public errorText?: string; | ||
|
||
/* | ||
* Show the error appearance of the control | ||
*/ | ||
public errorVisible = false; | ||
|
||
/* @internal | ||
* Indicates if the error text has overflowed its container. The value should not be | ||
* set directly. Instead, it is used with the `overflow` directive. | ||
*/ | ||
public errorHasOverflow = false; | ||
} | ||
|
||
attr({ attribute: 'error-text' })( | ||
ErrorPatternElement.prototype, | ||
'errorText' | ||
); | ||
attr({ attribute: 'error-visible', mode: 'boolean' })( | ||
ErrorPatternElement.prototype, | ||
'errorVisible' | ||
); | ||
observable( | ||
ErrorPatternElement.prototype, | ||
'errorHasOverflow' | ||
); | ||
return ErrorPatternElement; | ||
} |
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
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
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