Skip to content

Commit

Permalink
fix(types): correct OffsetOptions alias (#2888)
Browse files Browse the repository at this point in the history
  • Loading branch information
atomiks committed May 5, 2024
1 parent 1fa4c30 commit 8e613d7
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 35 deletions.
5 changes: 5 additions & 0 deletions .changeset/fifty-pens-dream.md
@@ -0,0 +1,5 @@
---
"@floating-ui/dom": patch
---

fix(types): correct `OffsetOptions` alias
2 changes: 1 addition & 1 deletion packages/dom/src/index.ts
Expand Up @@ -58,6 +58,7 @@ export type {
MiddlewareArguments,
MiddlewareState,
NodeScroll,
OffsetOptions,
Platform,
ReferenceElement,
ShiftOptions,
Expand All @@ -78,7 +79,6 @@ export type {
Length,
MiddlewareData,
MiddlewareReturn,
OffsetOptions,
Padding,
Placement,
Rect,
Expand Down
36 changes: 2 additions & 34 deletions packages/dom/src/middleware.ts
Expand Up @@ -26,41 +26,11 @@ import type {
HideOptions,
Middleware,
MiddlewareState,
OffsetOptions,
ShiftOptions,
SizeOptions,
} from './types';

// `OffsetOptions` in the core library were originally already `Derivable`. For
// backwards-compatibility, re-define it here to use the DOM Derivable type.
type OffsetOptions =
| number
| Partial<{
/**
* The axis that runs along the side of the floating element. Represents
* the distance (gutter or margin) between the reference and floating
* element.
* @default 0
*/
mainAxis: number;
/**
* The axis that runs along the alignment of the floating element.
* Represents the skidding between the reference and floating element.
* @default 0
*/
crossAxis: number;
/**
* The same axis as `crossAxis` but applies only to aligned placements
* and inverts the `end` alignment. When set to a number, it overrides the
* `crossAxis` value.
*
* A positive number will move the floating element in the direction of
* the opposite edge to the one that is aligned, while a negative number
* the reverse.
* @default null
*/
alignmentAxis: number | null;
}>;

/**
* Resolves with an object of overflow side offsets that determine how much the
* element is overflowing a given clipping boundary on each side.
Expand All @@ -81,9 +51,7 @@ export const detectOverflow: (
* object may be passed.
* @see https://floating-ui.com/docs/offset
*/
export const offset: (
options?: OffsetOptions | Derivable<OffsetOptions>,
) => Middleware = offsetCore;
export const offset: (options?: OffsetOptions) => Middleware = offsetCore;

/**
* Optimizes the visibility of the floating element by choosing the placement
Expand Down
32 changes: 32 additions & 0 deletions packages/dom/src/types.ts
Expand Up @@ -26,6 +26,38 @@ type Promisable<T> = T | Promise<T>;

export type Derivable<T> = (state: MiddlewareState) => T;

export type OffsetValue =
| number
| {
/**
* The axis that runs along the side of the floating element. Represents
* the distance (gutter or margin) between the reference and floating
* element.
* @default 0
*/
mainAxis?: number;
/**
* The axis that runs along the alignment of the floating element.
* Represents the skidding between the reference and floating element.
* @default 0
*/
crossAxis?: number;
/**
* The same axis as `crossAxis` but applies only to aligned placements
* and inverts the `end` alignment. When set to a number, it overrides the
* `crossAxis` value.
*
* A positive number will move the floating element in the direction of
* the opposite edge to the one that is aligned, while a negative number
* the reverse.
* @default null
*/
alignmentAxis?: number | null;
};
// `OffsetOptions` in the core library were originally already `Derivable`. For
// backwards-compatibility, re-define it here to use the DOM Derivable type.
export type OffsetOptions = OffsetValue | Derivable<OffsetValue>;

export interface Platform {
// Required
getElementRects: (args: {
Expand Down

0 comments on commit 8e613d7

Please sign in to comment.