-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1118 from scheduleonce/avengers/tabs-module-qa
Create new component for tabs in once-ui
- Loading branch information
Showing
57 changed files
with
32,622 additions
and
15,827 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
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
163 changes: 163 additions & 0 deletions
163
ui/src/components/core/common-behaviors/common-module.ts
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,163 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import { HighContrastModeDetector } from '@angular/cdk/a11y'; | ||
import { BidiModule } from '@angular/cdk/bidi'; | ||
import { | ||
inject, | ||
Inject, | ||
InjectionToken, | ||
NgModule, | ||
Optional, | ||
} from '@angular/core'; | ||
import { VERSION as CDK_VERSION } from '@angular/cdk'; | ||
import { DOCUMENT } from '@angular/common'; | ||
import { Platform, _isTestEnvironment } from '@angular/cdk/platform'; | ||
import { VERSION } from '../version'; | ||
import { isDevMode } from '@angular/core'; | ||
|
||
/** @docs-private */ | ||
export function MATERIAL_SANITY_CHECKS_FACTORY(): SanityChecks { | ||
return true; | ||
} | ||
|
||
/** Injection token that configures whether the Material sanity checks are enabled. */ | ||
export const MATERIAL_SANITY_CHECKS = new InjectionToken<SanityChecks>( | ||
'mat-sanity-checks', | ||
{ | ||
providedIn: 'root', | ||
factory: MATERIAL_SANITY_CHECKS_FACTORY, | ||
} | ||
); | ||
|
||
/** | ||
* Possible sanity checks that can be enabled. If set to | ||
* true/false, all checks will be enabled/disabled. | ||
*/ | ||
export type SanityChecks = boolean | GranularSanityChecks; | ||
|
||
/** Object that can be used to configure the sanity checks granularly. */ | ||
export interface GranularSanityChecks { | ||
doctype: boolean; | ||
theme: boolean; | ||
version: boolean; | ||
} | ||
|
||
/** | ||
* Module that captures anything that should be loaded and/or run for *all* Angular Material | ||
* components. This includes Bidi, etc. | ||
* | ||
* This module should be imported to each top-level component module (e.g., OuiTabsModule). | ||
*/ | ||
@NgModule({ | ||
imports: [BidiModule], | ||
exports: [BidiModule], | ||
}) | ||
export class OuiCommonModule { | ||
/** Whether we've done the global sanity checks (e.g. a theme is loaded, there is a doctype). */ | ||
private _hasDoneGlobalChecks = false; | ||
|
||
constructor( | ||
highContrastModeDetector: HighContrastModeDetector, | ||
@Optional() | ||
@Inject(MATERIAL_SANITY_CHECKS) | ||
private _sanityChecks: SanityChecks, | ||
@Inject(DOCUMENT) private _document: Document | ||
) { | ||
// While A11yModule also does this, we repeat it here to avoid importing A11yModule | ||
// in OuiCommonModule. | ||
highContrastModeDetector._applyBodyHighContrastModeCssClasses(); | ||
|
||
if (!this._hasDoneGlobalChecks) { | ||
this._hasDoneGlobalChecks = true; | ||
|
||
if (typeof isDevMode === 'undefined' || isDevMode) { | ||
// Inject in here so the reference to `Platform` can be removed in production mode. | ||
const platform = inject(Platform, { optional: true }); | ||
|
||
if (this._checkIsEnabled('doctype')) { | ||
_checkDoctypeIsDefined(this._document); | ||
} | ||
|
||
if (this._checkIsEnabled('theme')) { | ||
_checkThemeIsPresent(this._document, !!platform?.isBrowser); | ||
} | ||
|
||
if (this._checkIsEnabled('version')) { | ||
_checkCdkVersionMatch(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** Gets whether a specific sanity check is enabled. */ | ||
private _checkIsEnabled(name: keyof GranularSanityChecks): boolean { | ||
if (_isTestEnvironment()) { | ||
return false; | ||
} | ||
|
||
if (typeof this._sanityChecks === 'boolean') { | ||
return this._sanityChecks; | ||
} | ||
|
||
return !!this._sanityChecks[name]; | ||
} | ||
} | ||
|
||
/** Checks that the page has a doctype. */ | ||
function _checkDoctypeIsDefined(doc: Document): void { | ||
if (!doc.doctype) { | ||
console.warn( | ||
'Current document does not have a doctype. This may cause ' + | ||
'some Angular Material components not to behave as expected.' | ||
); | ||
} | ||
} | ||
|
||
/** Checks that a theme has been included. */ | ||
function _checkThemeIsPresent(doc: Document, isBrowser: boolean): void { | ||
// We need to assert that the `body` is defined, because these checks run very early | ||
// and the `body` won't be defined if the consumer put their scripts in the `head`. | ||
if (!doc.body || !isBrowser) { | ||
return; | ||
} | ||
|
||
const testElement = doc.createElement('div'); | ||
testElement.classList.add('mat-theme-loaded-marker'); | ||
doc.body.appendChild(testElement); | ||
|
||
const computedStyle = getComputedStyle(testElement); | ||
|
||
// In some situations the computed style of the test element can be null. For example in | ||
// Firefox, the computed style is null if an application is running inside of a hidden iframe. | ||
// See: https://bugzilla.mozilla.org/show_bug.cgi?id=548397 | ||
if (computedStyle && computedStyle.display !== 'none') { | ||
console.warn( | ||
'Could not find Angular Material core theme. Most Material ' + | ||
'components may not work as expected. For more info refer ' + | ||
'to the theming guide: https://material.angular.io/guide/theming' | ||
); | ||
} | ||
|
||
testElement.remove(); | ||
} | ||
|
||
/** Checks whether the Material version matches the CDK version. */ | ||
function _checkCdkVersionMatch(): void { | ||
if (VERSION.full !== CDK_VERSION.full) { | ||
console.warn( | ||
'The Angular Material version (' + | ||
VERSION.full + | ||
') does not match ' + | ||
'the Angular CDK version (' + | ||
CDK_VERSION.full + | ||
').\n' + | ||
'Please ensure the versions of these two packages exactly match.' | ||
); | ||
} | ||
} |
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 +1,5 @@ | ||
export type Constructor<T> = new (...args: any[]) => T; | ||
|
||
export type AbstractConstructor<T = object> = abstract new ( | ||
...args: any[] | ||
) => T; |
43 changes: 43 additions & 0 deletions
43
ui/src/components/core/common-behaviors/disable-ripple.spec.ts
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,43 @@ | ||
import { mixinDisableRipple } from './disable-ripple'; | ||
|
||
describe('mixinDisableRipple', () => { | ||
it('should augment an existing class with a disableRipple property', () => { | ||
const classWithMixin = mixinDisableRipple(TestClass); | ||
const instance = new classWithMixin(); | ||
|
||
expect(instance.disableRipple) | ||
.withContext( | ||
'Expected the mixed-into class to have a disable-ripple property' | ||
) | ||
.toBe(false); | ||
|
||
instance.disableRipple = true; | ||
|
||
expect(instance.disableRipple) | ||
.withContext( | ||
'Expected the mixed-into class to have an updated disable-ripple property' | ||
) | ||
.toBe(true); | ||
}); | ||
|
||
it('should coerce values being passed to the disableRipple property', () => { | ||
const classWithMixin = mixinDisableRipple(TestClass); | ||
const instance = new classWithMixin(); | ||
|
||
expect(instance.disableRipple) | ||
.withContext('Expected disableRipple to be set to false initially') | ||
.toBe(false); | ||
|
||
// Setting string values to the disableRipple property should be prevented by TypeScript's | ||
// type checking, but developers can still set string values from their template bindings. | ||
(instance as any).disableRipple = ''; | ||
|
||
expect(instance.disableRipple) | ||
.withContext( | ||
'Expected disableRipple to be set to true if an empty string is set as value' | ||
) | ||
.toBe(true); | ||
}); | ||
}); | ||
|
||
class TestClass {} |
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,44 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import { coerceBooleanProperty } from '@angular/cdk/coercion'; | ||
import { AbstractConstructor, Constructor } from './constructor'; | ||
|
||
/** @docs-private */ | ||
export interface CanDisableRipple { | ||
/** Whether ripples are disabled. */ | ||
disableRipple: boolean; | ||
} | ||
|
||
type CanDisableRippleCtor = Constructor<CanDisableRipple> & | ||
AbstractConstructor<CanDisableRipple>; | ||
|
||
/** Mixin to augment a directive with a `disableRipple` property. */ | ||
export function mixinDisableRipple<T extends AbstractConstructor<{}>>( | ||
base: T | ||
): CanDisableRippleCtor & T; | ||
export function mixinDisableRipple<T extends Constructor<{}>>( | ||
base: T | ||
): CanDisableRippleCtor & T { | ||
return class extends base { | ||
private _disableRipple = false; | ||
|
||
/** Whether the ripple effect is disabled or not. */ | ||
get disableRipple(): boolean { | ||
return this._disableRipple; | ||
} | ||
set disableRipple(value: any) { | ||
this._disableRipple = coerceBooleanProperty(value); | ||
} | ||
|
||
constructor(...args: any[]) { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument | ||
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 |
---|---|---|
@@ -1,6 +1,8 @@ | ||
export * from './common-module'; | ||
export * from './color'; | ||
export * from './disabled'; | ||
export * from './constructor'; | ||
export * from './tabIndex'; | ||
export * from './initialized'; | ||
export * from './error-state'; | ||
export * from './disable-ripple'; |
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,8 @@ | ||
// This mixin ensures an element spans to fill the nearest ancestor with defined positioning. | ||
@mixin fill { | ||
top: 0; | ||
left: 0; | ||
right: 0; | ||
bottom: 0; | ||
position: absolute; | ||
} |
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,12 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import { Version } from '@angular/core'; | ||
|
||
/** Current version of Angular Material. */ | ||
export const VERSION = new Version('0.0.0-PLACEHOLDER'); |
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
Oops, something went wrong.