Skip to content

Commit

Permalink
chore(text-anchor): decouple from FAST Foundation (VIV-2252) (#2051)
Browse files Browse the repository at this point in the history
Decouple fast foundation
  • Loading branch information
RichardHelm authored Dec 6, 2024
1 parent 731882e commit 03aa44c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
10 changes: 6 additions & 4 deletions libs/components/src/lib/text-anchor/text-anchor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Anchor, applyMixins } from '@microsoft/fast-foundation';
import { attr, ViewTemplate } from '@microsoft/fast-element';
import { FoundationElement } from '@microsoft/fast-foundation';
import { Appearance, Connotation } from '../enums';
import { AffixIcon } from '../../shared/patterns/affix';
import { applyMixins } from '../../shared/foundation/utilities/apply-mixins';
import { Anchor } from '../../shared/foundation/anchor/anchor';

/**
* Types of text anchor connotation.
Expand All @@ -27,7 +29,7 @@ export type TextAnchorAppearance = Extract<
* @component text-anchor
* @slot icon - Add an icon to the component.
*/
export class TextAnchor extends Anchor {
export class TextAnchor extends FoundationElement {
/**
* Indicates the text anchor's text.
*
Expand Down Expand Up @@ -64,5 +66,5 @@ export class TextAnchor extends Anchor {
}
}

export interface TextAnchor extends AffixIcon {}
applyMixins(TextAnchor, AffixIcon);
export interface TextAnchor extends AffixIcon, Anchor {}
applyMixins(TextAnchor, AffixIcon, Anchor);
7 changes: 6 additions & 1 deletion libs/components/src/shared/foundation/anchor/anchor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { attr } from '@microsoft/fast-element';
import { applyMixins } from '@microsoft/fast-foundation';
import { ARIAGlobalStatesAndProperties } from '../patterns/aria-global';
import { applyMixins } from '../utilities/apply-mixins';

/**
* Based largely on the {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a | <a> element }.
Expand Down Expand Up @@ -85,6 +85,11 @@ export class Anchor {
@attr
// @ts-expect-error Type is incorrectly non-optional
type: string;

/**
* References the root element
*/
control: HTMLAnchorElement | undefined;
}

/**
Expand Down
34 changes: 16 additions & 18 deletions libs/wrapper-gen/src/generator/customElementDeclarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,21 @@ const resolveComponentDeclaration = (
...declaration._localTypeDefs,
};
}

// Apply vivid mixins
if (declaration.vividComponent) {
const mixins = extractVividMixins(className, declaration._modulePath);
for (const mixinName of mixins) {
if (!(mixinName in VividMixins)) {
throw new Error(`Unknown mixin ${mixinName}`);
}
declaration.attributes = inheritItems(
getAttributeName,
VividMixins[mixinName],
declaration.attributes
);
}
}
}

return declaration;
Expand Down Expand Up @@ -505,24 +520,7 @@ export const getClassNameOfVividComponent = (name: string): string => {
export const getVividComponentDeclaration = (
name: string,
className: string
): Declaration => {
const declaration = resolveComponentDeclaration(vividDeclarations, className);

// Apply vivid mixins
const mixins = extractVividMixins(className, declaration._modulePath);
for (const mixinName of mixins) {
if (!(mixinName in VividMixins)) {
throw new Error(`Unknown mixin ${mixinName}`);
}
declaration.attributes = inheritItems(
getAttributeName,
VividMixins[mixinName],
declaration.attributes
);
}

return declaration;
};
): Declaration => resolveComponentDeclaration(vividDeclarations, className);

/**
* Lists all public components from Vivid. E.g. 'accordion-item'.
Expand Down

0 comments on commit 03aa44c

Please sign in to comment.