diff --git a/.changeset/fifty-pens-dream.md b/.changeset/fifty-pens-dream.md new file mode 100644 index 0000000000..79253f86c3 --- /dev/null +++ b/.changeset/fifty-pens-dream.md @@ -0,0 +1,5 @@ +--- +"@floating-ui/dom": patch +--- + +fix(types): correct `OffsetOptions` alias diff --git a/packages/dom/src/index.ts b/packages/dom/src/index.ts index 6f4aba6336..a79c72d68d 100644 --- a/packages/dom/src/index.ts +++ b/packages/dom/src/index.ts @@ -58,6 +58,7 @@ export type { MiddlewareArguments, MiddlewareState, NodeScroll, + OffsetOptions, Platform, ReferenceElement, ShiftOptions, @@ -78,7 +79,6 @@ export type { Length, MiddlewareData, MiddlewareReturn, - OffsetOptions, Padding, Placement, Rect, diff --git a/packages/dom/src/middleware.ts b/packages/dom/src/middleware.ts index 5965da8a27..b2ac3fc934 100644 --- a/packages/dom/src/middleware.ts +++ b/packages/dom/src/middleware.ts @@ -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. @@ -81,9 +51,7 @@ export const detectOverflow: ( * object may be passed. * @see https://floating-ui.com/docs/offset */ -export const offset: ( - options?: OffsetOptions | Derivable, -) => Middleware = offsetCore; +export const offset: (options?: OffsetOptions) => Middleware = offsetCore; /** * Optimizes the visibility of the floating element by choosing the placement diff --git a/packages/dom/src/types.ts b/packages/dom/src/types.ts index 955f8bb25a..7fd64ee7eb 100644 --- a/packages/dom/src/types.ts +++ b/packages/dom/src/types.ts @@ -26,6 +26,38 @@ type Promisable = T | Promise; export type Derivable = (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; + export interface Platform { // Required getElementRects: (args: {