sb-floating-panel-vue 1.0.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,75 +1,27 @@
1
- import { Placement } from '@floating-ui/vue';
2
- import { CSSProperties, Ref } from 'vue';
3
- /**
4
- * Props for the SbFloating component.
5
- * This component renders the floating panel and (optionally) its arrow using teleport.
6
- */
7
- interface SbFloatingProps {
8
- /**
9
- * The ref to bind to the floating panel element.
10
- */
11
- floatingRef: Ref<HTMLElement | null>;
12
- /**
13
- * Optional ref to bind to the floating arrow element.
14
- */
15
- floatingArrowRef?: Ref<HTMLElement | null>;
16
- /**
17
- * Whether the floating panel is open (visible).
18
- */
19
- isOpen: boolean;
20
- /**
21
- * The final placement resolved by Floating UI (e.g., 'bottom-start').
22
- */
23
- floatingPlacement: Placement;
24
- /**
25
- * Computed inline styles for the floating panel.
26
- */
27
- floatingStyle: CSSProperties;
28
- /**
29
- * Computed inline styles for the floating arrow (optional).
30
- */
31
- floatingArrowStyle?: CSSProperties;
32
- /**
33
- * Optional dimension (width & height) of the floating arrow.
34
- * If provided, will override default arrow size.
35
- */
36
- arrowDimensions?: number;
37
- /**
38
- * Optional z-index to apply to the floating panel and arrow.
39
- */
40
- zIndex?: number;
41
- /**
42
- * Animation name used in Vue <transition>.
43
- * Supported values: 'fade', 'scale-fade', 'none'.
44
- * @default 'scale-fade'
45
- */
46
- animation?: 'fade' | 'scale-fade' | 'none';
47
- /**
48
- * Duration of the transition animation in milliseconds.
49
- * @default 300
50
- */
51
- duration?: number;
52
- }
53
- declare function __VLS_template(): {
54
- attrs: Partial<{}>;
55
- slots: {
56
- default?(_: {}): any;
57
- };
58
- refs: {};
59
- rootEl: any;
1
+ import { SbFloatingProps } from '../types';
2
+ declare var __VLS_22: {};
3
+ type __VLS_Slots = {} & {
4
+ default?: (props: typeof __VLS_22) => any;
60
5
  };
61
- type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
62
- declare const __VLS_component: import('vue').DefineComponent<SbFloatingProps, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<SbFloatingProps> & Readonly<{}>, {
63
- floatingArrowStyle: CSSProperties;
64
- floatingArrowRef: Ref<HTMLElement | null>;
65
- arrowDimensions: number;
66
- zIndex: number;
67
- animation: "fade" | "scale-fade" | "none";
68
- duration: number;
6
+ declare const __VLS_base: import('vue').DefineComponent<SbFloatingProps, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
7
+ "after-enter": () => any;
8
+ "after-leave": () => any;
9
+ }, string, import('vue').PublicProps, Readonly<SbFloatingProps> & Readonly<{
10
+ "onAfter-enter"?: (() => any) | undefined;
11
+ "onAfter-leave"?: (() => any) | undefined;
12
+ }>, {
13
+ as: string;
14
+ role: string;
15
+ transition: string;
16
+ teleportTo: string | HTMLElement;
17
+ teleportDisabled: boolean;
18
+ zIndex: string | number;
19
+ autoFocus: boolean;
69
20
  }, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
70
- declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
21
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
22
+ declare const _default: typeof __VLS_export;
71
23
  export default _default;
72
- type __VLS_WithTemplateSlots<T, S> = T & {
24
+ type __VLS_WithSlots<T, S> = T & {
73
25
  new (): {
74
26
  $slots: S;
75
27
  };
@@ -1,40 +1,16 @@
1
- import { Ref } from 'vue';
2
- /**
3
- * Props for the SbReference component.
4
- * Renders the reference element for the floating panel system.
5
- */
6
- interface SbReferenceProps {
7
- /**
8
- * The ref to bind to the reference DOM element.
9
- */
10
- referenceRef: Ref<HTMLElement | null>;
11
- /**
12
- * HTML tag to render as the reference.
13
- * Useful for accessibility and customization.
14
- * @default 'button'
15
- */
16
- as?: 'button' | 'a' | 'div' | 'span';
17
- /**
18
- * Optional click handler for toggling the floating panel.
19
- */
20
- onClick?: () => void;
21
- }
22
- declare function __VLS_template(): {
23
- attrs: Partial<{}>;
24
- slots: {
25
- default?(_: {}): any;
26
- };
27
- refs: {};
28
- rootEl: any;
1
+ import { SbReferenceProps } from '../types';
2
+ declare var __VLS_10: {};
3
+ type __VLS_Slots = {} & {
4
+ default?: (props: typeof __VLS_10) => any;
29
5
  };
30
- type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
31
- declare const __VLS_component: import('vue').DefineComponent<SbReferenceProps, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<SbReferenceProps> & Readonly<{}>, {
32
- onClick: () => void;
33
- as: "button" | "a" | "div" | "span";
6
+ declare const __VLS_base: import('vue').DefineComponent<SbReferenceProps, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<SbReferenceProps> & Readonly<{}>, {
7
+ as: string;
8
+ ariaHaspopup: "dialog" | "menu" | "listbox" | "tree" | "grid" | "true" | "false";
34
9
  }, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
35
- declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
10
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
11
+ declare const _default: typeof __VLS_export;
36
12
  export default _default;
37
- type __VLS_WithTemplateSlots<T, S> = T & {
13
+ type __VLS_WithSlots<T, S> = T & {
38
14
  new (): {
39
15
  $slots: S;
40
16
  };
@@ -1,81 +1,31 @@
1
- import { FloatingElement, Placement, Strategy } from '@floating-ui/vue';
2
- import { CSSProperties, Ref, ComputedRef } from 'vue';
1
+ import { ComputedRef, CSSProperties, MaybeRefOrGetter, Ref } from 'vue';
2
+ import { SbAlignment, SbPlacement, SbSide, SbStrategy } from '../types';
3
3
  /**
4
- * Configuration options for the `useSbFloatingPanel` composable.
4
+ * Options of the internal `useSbFloatingPanel` composable. Every option can be a value,
5
+ * a ref or a getter, so `SbContainer` props stay reactive.
5
6
  */
6
- interface FloatingSettings {
7
- /**
8
- * Defines the preferred placement of the floating element relative to the reference.
9
- * Example: 'top', 'bottom-start', 'right-end', etc.
10
- */
11
- placement: Placement;
12
- /**
13
- * Determines the positioning strategy for the floating element.
14
- * Can be either 'absolute' or 'fixed'.
15
- */
16
- strategy: Strategy;
17
- /**
18
- * Specifies the distance (in pixels) between the reference and floating elements.
19
- */
20
- offsetValue: number;
21
- /**
22
- * Enables the use of a directional arrow pointing from the floating element to the reference.
23
- */
24
- hasArrow?: boolean;
25
- /**
26
- * When enabled, synchronizes the width of the floating element to match the reference element.
27
- * Useful for dropdowns or inputs.
28
- */
29
- hasResize?: boolean;
7
+ export interface FloatingPanelOptions {
8
+ isOpen: MaybeRefOrGetter<boolean>;
9
+ placement: MaybeRefOrGetter<SbPlacement>;
10
+ strategy: MaybeRefOrGetter<SbStrategy>;
11
+ offset: MaybeRefOrGetter<number>;
12
+ padding: MaybeRefOrGetter<number>;
13
+ matchWidth: MaybeRefOrGetter<boolean | 'min'>;
14
+ hideWhenDetached: MaybeRefOrGetter<boolean>;
15
+ }
16
+ export interface FloatingPanel {
17
+ reference: Ref<HTMLElement | null>;
18
+ floating: Ref<HTMLElement | null>;
19
+ /** Positioning styles for the outer wrapper (Floating UI styles + `visibility` from `hide`). */
20
+ floatingStyles: ComputedRef<CSSProperties>;
21
+ /** Placement resolved after `flip`. */
22
+ placement: Readonly<Ref<SbPlacement>>;
23
+ side: ComputedRef<SbSide>;
24
+ align: ComputedRef<SbAlignment | undefined>;
25
+ isPositioned: Readonly<Ref<boolean>>;
26
+ update: () => void;
30
27
  }
31
28
  /**
32
- * `useSbFloatingPanel` is a composable that wraps Floating UI logic to manage
33
- * floating elements with optional arrow and dynamic width support.
34
- *
35
- * It provides bindings and style objects ready to apply to your `ref` elements in Vue templates.
36
- *
37
- * @param settings - Configuration options for placement, offset, and behavior.
38
- * @returns Bindings and utility functions to control the floating panel.
39
- *
40
- * @example
41
- * ```ts
42
- * const {
43
- * reference,
44
- * floating,
45
- * floatingArrow,
46
- * floatingPlacement,
47
- * floatingStyle,
48
- * floatingArrowStyle,
49
- * isOpen,
50
- * toggle,
51
- * open,
52
- * close
53
- * } = useSbFloatingPanel({
54
- * placement: 'bottom',
55
- * strategy: 'absolute',
56
- * offsetValue: 10,
57
- * hasArrow: true,
58
- * hasResize: false
59
- * });
60
- * ```
61
- *
62
- * @example
63
- * ```html
64
- * <div ref="reference">Anchor</div>
65
- * <div ref="floating" v-if="isOpen">Panel</div>
66
- * <div ref="floatingArrow" v-if="isOpen">Arrow</div>
67
- * ```
29
+ * Wraps Floating UI for the components. Not part of the public API.
68
30
  */
69
- export declare function useSbFloatingPanel(settings: FloatingSettings): {
70
- reference: Ref<HTMLElement | null>;
71
- floating: Ref<FloatingElement | null>;
72
- floatingArrow: Ref<HTMLElement | null>;
73
- floatingPlacement: Ref<Placement>;
74
- floatingStyle: ComputedRef<CSSProperties>;
75
- floatingArrowStyle: ComputedRef<CSSProperties>;
76
- isOpen: Ref<boolean>;
77
- toggle: () => void;
78
- open: () => void;
79
- close: () => void;
80
- };
81
- export {};
31
+ export declare function useSbFloatingPanel(options: FloatingPanelOptions): FloatingPanel;
@@ -0,0 +1,23 @@
1
+ import { InjectionKey, Ref } from 'vue';
2
+ import { FloatingPanel } from './composables/useSbFloatingPanel';
3
+ import { SbTrigger } from './types';
4
+ /**
5
+ * State shared by `SbContainer` with `SbReference` and `SbFloating`.
6
+ */
7
+ export interface SbFloatingContext extends FloatingPanel {
8
+ isOpen: Readonly<Ref<boolean>>;
9
+ disabled: Readonly<Ref<boolean>>;
10
+ trigger: Readonly<Ref<SbTrigger>>;
11
+ floatingId: string;
12
+ open: () => void;
13
+ close: () => void;
14
+ toggle: () => void;
15
+ /** Whether an event target is inside the reference, the panel or a nested container. */
16
+ contains: (target: EventTarget | null) => boolean;
17
+ /** Whether a nested container is open. */
18
+ hasOpenChild: () => boolean;
19
+ /** Registers a nested container; returns the function that unregisters it. */
20
+ registerChild: (child: SbFloatingContext) => () => void;
21
+ }
22
+ export declare const sbFloatingContextKey: InjectionKey<SbFloatingContext>;
23
+ export declare function useSbFloatingContext(component: string): SbFloatingContext;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { useSbFloatingPanel } from './composables/useSbFloatingPanel';
2
1
  export { default as SbContainer } from './components/SbContainer.vue';
3
2
  export { default as SbReference } from './components/SbReference.vue';
4
3
  export { default as SbFloating } from './components/SbFloating.vue';
4
+ export type { SbContainerProps, SbContainerSlotProps, SbContainerExposed, SbReferenceProps, SbFloatingProps, SbTrigger, SbPlacement, SbSide, SbAlignment, SbStrategy, } from './types';