Skip to content

Commit

Permalink
chore(components): adds apply-mixins from foundation (VIV-2017) (#2046)
Browse files Browse the repository at this point in the history
* chore: adds apply-mixins from foundation

* chore: formatting
  • Loading branch information
TaylorJ76 authored Dec 5, 2024
1 parent ee96006 commit db952b1
Show file tree
Hide file tree
Showing 22 changed files with 63 additions and 21 deletions.
3 changes: 2 additions & 1 deletion libs/components/src/lib/accordion-item/accordion-item.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { attr, nullableNumberConverter } from '@microsoft/fast-element';
import { applyMixins, FoundationElement } from '@microsoft/fast-foundation';
import { FoundationElement } from '@microsoft/fast-foundation';
import { AffixIconWithTrailing } from '../../shared/patterns/affix';
import { applyMixins } from '../../shared/foundation/utilities/apply-mixins';
import type { Size } from '../enums.js';

/**
Expand Down
3 changes: 2 additions & 1 deletion libs/components/src/lib/alert/alert.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { applyMixins, FoundationElement } from '@microsoft/fast-foundation';
import { FoundationElement } from '@microsoft/fast-foundation';
import { attr, nullableNumberConverter } from '@microsoft/fast-element';
import { Connotation } from '../enums';
import { Localized } from '../../shared/patterns';
import { AffixIcon } from '../../shared/patterns/affix';
import { applyMixins } from '../../shared/foundation/utilities/apply-mixins';
import { handleEscapeKeyAndStopPropogation } from '../../shared/dialog/index';

export type AlertConnotation =
Expand Down
3 changes: 2 additions & 1 deletion libs/components/src/lib/audio-player/audio-player.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint-disable max-len */
import { applyMixins, FoundationElement } from '@microsoft/fast-foundation';
import { FoundationElement } from '@microsoft/fast-foundation';
import { attr, Observable, type ValueConverter } from '@microsoft/fast-element';
import type { Connotation } from '../enums';
import { MediaSkipBy } from '../enums';
import { applyMixins } from '../../shared/foundation/utilities/apply-mixins';
import { Localized } from '../../shared/patterns';
import type { Slider } from '../slider/slider';

Expand Down
3 changes: 2 additions & 1 deletion libs/components/src/lib/badge/badge.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { applyMixins, FoundationElement } from '@microsoft/fast-foundation';
import { FoundationElement } from '@microsoft/fast-foundation';
import { attr } from '@microsoft/fast-element';
import { AffixIconWithTrailing } from '../../shared/patterns/affix';
import { applyMixins } from '../../shared/foundation/utilities/apply-mixins';

import type { Appearance, Connotation, Shape } from '../enums.js';

Expand Down
3 changes: 2 additions & 1 deletion libs/components/src/lib/banner/banner.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { applyMixins, FoundationElement } from '@microsoft/fast-foundation';
import { FoundationElement } from '@microsoft/fast-foundation';
import { attr, observable } from '@microsoft/fast-element';
import { applyMixins } from '../../shared/foundation/utilities/apply-mixins';
import { Connotation } from '../enums';
import { Localized } from '../../shared/patterns';
import { AffixIcon } from '../../shared/patterns/affix';
Expand Down
3 changes: 2 additions & 1 deletion libs/components/src/lib/breadcrumb-item/breadcrumb-item.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { attr, observable } from '@microsoft/fast-element';
import { applyMixins, FoundationElement } from '@microsoft/fast-foundation';
import { FoundationElement } from '@microsoft/fast-foundation';
import { Anchor } from '../../shared/foundation/anchor/anchor';
import { applyMixins } from '../../shared/foundation/utilities/apply-mixins';

/**
* @public
Expand Down
3 changes: 2 additions & 1 deletion libs/components/src/lib/dial-pad/dial-pad.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { applyMixins, FoundationElement } from '@microsoft/fast-foundation';
import { FoundationElement } from '@microsoft/fast-foundation';
import { attr } from '@microsoft/fast-element';
import { Localized } from '../../shared/patterns';
import { applyMixins } from '../../shared/foundation/utilities/apply-mixins';
import { TextField } from '../text-field/text-field';

/**
Expand Down
3 changes: 2 additions & 1 deletion libs/components/src/lib/dialog/dialog.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { applyMixins, FoundationElement } from '@microsoft/fast-foundation';
import { FoundationElement } from '@microsoft/fast-foundation';
import { attr, observable } from '@microsoft/fast-element';
import { applyMixins } from '../../shared/foundation/utilities/apply-mixins';
import { Localized } from '../../shared/patterns';
import { handleEscapeKeyAndStopPropogation } from '../../shared/dialog';

Expand Down
2 changes: 1 addition & 1 deletion libs/components/src/lib/fab/fab.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { attr } from '@microsoft/fast-element';
import { applyMixins } from '@microsoft/fast-foundation';
import { applyMixins } from '../../shared/foundation/utilities/apply-mixins';
import { VividFoundationButton } from '../../shared/foundation/button';
import type { Connotation, Size } from '../enums.js';
import { AffixIconWithTrailing } from '../../shared/patterns/affix';
Expand Down
3 changes: 2 additions & 1 deletion libs/components/src/lib/nav-disclosure/nav-disclosure.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { attr } from '@microsoft/fast-element';
import { applyMixins, FoundationElement } from '@microsoft/fast-foundation';
import { FoundationElement } from '@microsoft/fast-foundation';
import { applyMixins } from '../../shared/foundation/utilities/apply-mixins';
import { Appearance, Connotation } from '../enums';
import { AffixIcon } from '../../shared/patterns/affix';

Expand Down
2 changes: 1 addition & 1 deletion libs/components/src/lib/nav-item/nav-item.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { applyMixins } from '@microsoft/fast-foundation';
import { html } from '@microsoft/fast-element';
import { AffixIcon } from '../../shared/patterns/affix';
import { applyMixins } from '../../shared/foundation/utilities/apply-mixins';
import { TextAnchor } from '../text-anchor/text-anchor';

/**
Expand Down
3 changes: 2 additions & 1 deletion libs/components/src/lib/option/option.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { applyMixins, FoundationElement } from '@microsoft/fast-foundation';
import { FoundationElement } from '@microsoft/fast-foundation';
import { attr, observable, Observable } from '@microsoft/fast-element';
import { isHTMLElement } from '@microsoft/fast-web-utilities';
import { applyMixins } from '../../shared/foundation/utilities/apply-mixins';
import { AffixIconWithTrailing } from '../../shared/patterns/affix';
import { ARIAGlobalStatesAndProperties } from '../../shared/foundation/patterns/aria-global';

Expand Down
2 changes: 1 addition & 1 deletion libs/components/src/lib/range-slider/range-slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
nullableNumberConverter,
observable,
} from '@microsoft/fast-element';
import { applyMixins } from '@microsoft/fast-foundation';
import {
keyArrowDown,
keyArrowUp,
Expand All @@ -16,6 +15,7 @@ import {
keyArrowLeft,
keyArrowRight,
} from '@microsoft/fast-web-utilities/dist/key-codes';
import { applyMixins } from '../../shared/foundation/utilities/apply-mixins';
import { Connotation } from '../enums';
import {
type FormElement,
Expand Down
3 changes: 2 additions & 1 deletion libs/components/src/lib/searchable-select/option-tag.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { applyMixins, FoundationElement } from '@microsoft/fast-foundation';
import { FoundationElement } from '@microsoft/fast-foundation';
import { attr, observable } from '@microsoft/fast-element';
import { applyMixins } from '../../shared/foundation/utilities/apply-mixins';
import { Shape } from '../enums';
import { Localized } from '../../shared/patterns';

Expand Down
3 changes: 2 additions & 1 deletion libs/components/src/lib/slider/slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
observable,
volatile,
} from '@microsoft/fast-element';
import { applyMixins, getDirection } from '@microsoft/fast-foundation';
import { getDirection } from '@microsoft/fast-foundation';
import {
Direction,
keyArrowDown,
Expand All @@ -18,6 +18,7 @@ import {
keyArrowLeft,
keyArrowRight,
} from '@microsoft/fast-web-utilities/dist/key-codes';
import { applyMixins } from '../../shared/foundation/utilities/apply-mixins';
import type { Connotation } from '../enums';
import { Localized } from '../../shared/patterns';
import { roundToStepValue } from '../range-slider/utils/roundToStepValue';
Expand Down
3 changes: 2 additions & 1 deletion libs/components/src/lib/split-button/split-button.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { applyMixins, FoundationElement } from '@microsoft/fast-foundation';
import { FoundationElement } from '@microsoft/fast-foundation';
import { attr } from '@microsoft/fast-element';
import { applyMixins } from '../../shared/foundation/utilities/apply-mixins';
import type { Appearance, Connotation, Shape, Size } from '../enums.js';
import { AffixIcon } from '../../shared/patterns/affix';
import { Localized } from '../../shared/patterns';
Expand Down
3 changes: 2 additions & 1 deletion libs/components/src/lib/tab/tab.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { attr } from '@microsoft/fast-element';
import { applyMixins, FoundationElement } from '@microsoft/fast-foundation';
import { FoundationElement } from '@microsoft/fast-foundation';
import { applyMixins } from '../../shared/foundation/utilities/apply-mixins';
import { AffixIconWithTrailing } from '../../shared/patterns/affix';
import { Localized } from '../../shared/patterns';

Expand Down
3 changes: 2 additions & 1 deletion libs/components/src/lib/tag/tag.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { applyMixins, FoundationElement } from '@microsoft/fast-foundation';
import { FoundationElement } from '@microsoft/fast-foundation';
import { attr } from '@microsoft/fast-element';
import { applyMixins } from '../../shared/foundation/utilities/apply-mixins';
import { AffixIcon } from '../../shared/patterns/affix';

import type { Appearance, Connotation, Shape } from '../enums.js';
Expand Down
2 changes: 1 addition & 1 deletion libs/components/src/lib/text-field/text-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
observable,
} from '@microsoft/fast-element';
import { memoizeWith } from 'ramda';
import { applyMixins } from '@microsoft/fast-foundation';
import { applyMixins } from '../../shared/foundation/utilities/apply-mixins';
import type { Appearance, Shape, Size } from '../enums';
import {
AffixIcon,
Expand Down
2 changes: 1 addition & 1 deletion libs/components/src/lib/tree-item/tree-item.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TreeItem as FastTreeItem } from '@microsoft/fast-foundation';
import { attr } from '@microsoft/fast-element';
import { applyMixins } from '@microsoft/fast-foundation';
import { applyMixins } from '../../shared/foundation/utilities/apply-mixins';
import { AffixIcon } from '../../shared/patterns/affix';

/**
Expand Down
3 changes: 2 additions & 1 deletion libs/components/src/lib/video-player/video-player.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { applyMixins, FoundationElement } from '@microsoft/fast-foundation';
import { FoundationElement } from '@microsoft/fast-foundation';
import { attr } from '@microsoft/fast-element';
import videojs from 'video.js';
import { applyMixins } from '../../shared/foundation/utilities/apply-mixins';
import { MediaSkipBy } from '../enums';
import { Localized } from '../../shared/patterns';
import { getPlaybackRatesArray } from '../../shared/utils/playbackRates';
Expand Down
26 changes: 26 additions & 0 deletions libs/components/src/shared/foundation/utilities/apply-mixins.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { AttributeConfiguration } from '@microsoft/fast-element';

/**
* Apply mixins to a constructor.
* Sourced from {@link https://www.typescriptlang.org/docs/handbook/mixins.html | TypeScript Documentation }.
* @public
*/
export function applyMixins(derivedCtor: any, ...baseCtors: any[]) {
const derivedAttributes = AttributeConfiguration.locate(derivedCtor);

baseCtors.forEach((baseCtor) => {
Object.getOwnPropertyNames(baseCtor.prototype).forEach((name) => {
if (name !== 'constructor') {
Object.defineProperty(
derivedCtor.prototype,
name,
/* eslint-disable-next-line @typescript-eslint/no-non-null-assertion */
Object.getOwnPropertyDescriptor(baseCtor.prototype, name)!
);
}
});

const baseAttributes = AttributeConfiguration.locate(baseCtor);
baseAttributes.forEach((x) => derivedAttributes.push(x));
});
}

0 comments on commit db952b1

Please sign in to comment.