Skip to content

Commit

Permalink
refactor handleChange
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdholt committed Jun 11, 2024
1 parent c852cb9 commit 18709fc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
23 changes: 23 additions & 0 deletions packages/web-components/src/anchor-button/anchor-button.options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,26 @@ export const AnchorTarget = {
* @public
*/
export type AnchorTarget = ValuesOf<typeof AnchorTarget>;

/**
* Reflected anchor attributes.
*
* @public
*/
export const AnchorAttributes = {
download: 'download',
href: 'href',
hreflang: 'hreflang',
ping: 'ping',
referrerpolicy: 'referrerpolicy',
rel: 'rel',
target: 'target',
type: 'type',
} as const;

/**
* Type for anchor attributes.
*
* @public
*/
export type AnchorAttributes = ValuesOf<typeof AnchorAttributes>;
22 changes: 11 additions & 11 deletions packages/web-components/src/anchor-button/anchor-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { keyEnter } from '@microsoft/fast-web-utilities';
import { StartEnd } from '../patterns/index.js';
import type { StartEndOptions } from '../patterns/index.js';
import { applyMixins } from '../utils/apply-mixins.js';
import type {
AnchorButtonAppearance,
AnchorButtonShape,
AnchorButtonSize,
AnchorTarget,
import {
AnchorAttributes,
type AnchorButtonAppearance,
type AnchorButtonShape,
type AnchorButtonSize,
type AnchorTarget,
} from './anchor-button.options.js';

/**
Expand Down Expand Up @@ -201,12 +202,11 @@ export class AnchorButton extends FASTElement {
* @param propertyName
*/
public handleChange(source: any, propertyName: string) {
if (propertyName === ('appearance' || 'size' || 'shape' || 'icon-only')) {
return;
}
const attribute = this.$fastController.definition.attributeLookup[propertyName]?.attribute;
if (attribute) {
this.handleProxyAttributeChange(attribute, this[propertyName as keyof this] as string);
if (propertyName in AnchorAttributes) {
const attribute = this.$fastController.definition.attributeLookup[propertyName]?.attribute;
if (attribute) {
this.handleProxyAttributeChange(attribute, this[propertyName as AnchorAttributes]);
}
}
}

Expand Down

0 comments on commit 18709fc

Please sign in to comment.