Skip to content

Commit

Permalink
Switch to a function-modifier, resolving CrowdStrike/ember-velcro#149
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Oct 15, 2024
1 parent 68458e7 commit 8154564
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion ember-primitives/src/floating-ui.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { default as FloatingUI } from './floating-ui/component.gts';
export { AnchorTo as anchorTo } from './floating-ui/modifier.ts';
export { anchorTo } from './floating-ui/modifier.ts';
21 changes: 10 additions & 11 deletions ember-primitives/src/floating-ui/modifier.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { assert } from '@ember/debug';
import { registerDestructor } from '@ember/destroyable';

import { autoUpdate, computePosition, flip, hide, offset, shift } from '@floating-ui/dom';
import Modifier from 'ember-modifier';
import { modifier as eModifier } from 'ember-modifier';

import { exposeMetadata } from './middleware.ts';

Expand Down Expand Up @@ -33,20 +32,20 @@ export interface Signature {
};
}

export class AnchorTo extends Modifier<Signature> {
modify(
floatingElement: Signature['Element'],
[_referenceElement]: Signature['Args']['Positional'],
export const anchorTo = eModifier<Signature>(
(
floatingElement,
[_referenceElement],
{
strategy = 'fixed',
offsetOptions = 0,
placement = 'bottom',
flipOptions,
shiftOptions,
middleware = [],
setData: setData,
}: Signature['Args']['Named']
) {
setData,
}
) => {
const referenceElement: null | HTMLElement | SVGElement =
typeof _referenceElement === 'string'
? document.querySelector(_referenceElement)
Expand Down Expand Up @@ -106,6 +105,6 @@ export class AnchorTo extends Modifier<Signature> {

let cleanup = autoUpdate(referenceElement, floatingElement, update);

registerDestructor(this, cleanup);
return cleanup;
}
}
);

0 comments on commit 8154564

Please sign in to comment.