@synerise/ds-popover 1.1.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.
Files changed (41) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/LICENSE.md +21 -0
  3. package/README.md +30 -0
  4. package/dist/Popover.const.d.ts +2 -0
  5. package/dist/Popover.const.js +2 -0
  6. package/dist/Popover.d.ts +3 -0
  7. package/dist/Popover.js +18 -0
  8. package/dist/Popover.types.d.ts +39 -0
  9. package/dist/Popover.types.js +1 -0
  10. package/dist/components/PopoverClose.d.ts +2 -0
  11. package/dist/components/PopoverClose.js +16 -0
  12. package/dist/components/PopoverContent.d.ts +2 -0
  13. package/dist/components/PopoverContent.js +73 -0
  14. package/dist/components/PopoverTrigger.d.ts +6 -0
  15. package/dist/components/PopoverTrigger.js +38 -0
  16. package/dist/components/PopoverTrigger.styles.d.ts +1 -0
  17. package/dist/components/PopoverTrigger.styles.js +5 -0
  18. package/dist/components/index.d.ts +3 -0
  19. package/dist/components/index.js +3 -0
  20. package/dist/contexts/PopoverContext.d.ts +7 -0
  21. package/dist/contexts/PopoverContext.js +2 -0
  22. package/dist/contexts/index.d.ts +1 -0
  23. package/dist/contexts/index.js +1 -0
  24. package/dist/hooks/index.d.ts +2 -0
  25. package/dist/hooks/index.js +2 -0
  26. package/dist/hooks/useListNavigationConfig.d.ts +24 -0
  27. package/dist/hooks/useListNavigationConfig.js +10 -0
  28. package/dist/hooks/usePopover.d.ts +58 -0
  29. package/dist/hooks/usePopover.js +117 -0
  30. package/dist/hooks/usePopoverContext.d.ts +59 -0
  31. package/dist/hooks/usePopoverContext.js +9 -0
  32. package/dist/index.d.ts +4 -0
  33. package/dist/index.js +4 -0
  34. package/dist/modules.d.js +1 -0
  35. package/dist/utils/getDefaultTransitionConfig.d.ts +2 -0
  36. package/dist/utils/getDefaultTransitionConfig.js +10 -0
  37. package/dist/utils/getMiddleware.d.ts +12 -0
  38. package/dist/utils/getMiddleware.js +33 -0
  39. package/dist/utils/index.d.ts +2 -0
  40. package/dist/utils/index.js +2 -0
  41. package/package.json +47 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ # 1.1.0 (2025-11-06)
7
+
8
+
9
+ ### Features
10
+
11
+ * **dropdown:** dropdownMenu component ([f0ec827](https://github.com/Synerise/synerise-design/commit/f0ec82792cdcb021fa9a454912f6e7a892e53895))
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Synerise
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,30 @@
1
+ ---
2
+ id: popover
3
+ title: Popover
4
+ ---
5
+
6
+ Popover UI Component
7
+
8
+ ## Installation
9
+ ```
10
+ npm i @synerise/ds-popover
11
+ or
12
+ yarn add @synerise/ds-popover
13
+ ```
14
+
15
+ ## Usage
16
+ ```
17
+ import Popover from '@synerise/ds-popover'
18
+
19
+ <Popover />
20
+
21
+ ```
22
+
23
+ ## Demo
24
+
25
+ <iframe src="/storybook-static/iframe.html?id=components-popover--default"></iframe>
26
+
27
+ ## API
28
+
29
+ | Property | Description | Type | Default |
30
+ | --- | --- | --- | --- |
@@ -0,0 +1,2 @@
1
+ export declare const HOVER_OPEN_DELAY = 100;
2
+ export declare const HOVER_CLOSE_DELAY = 100;
@@ -0,0 +1,2 @@
1
+ export var HOVER_OPEN_DELAY = 100;
2
+ export var HOVER_CLOSE_DELAY = 100;
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ import type { PopoverProps } from './Popover.types';
3
+ export declare const Popover: ({ children, modal, ...restOptions }: PopoverProps) => React.JSX.Element;
@@ -0,0 +1,18 @@
1
+ var _excluded = ["children", "modal"];
2
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
3
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
4
+ import React from 'react';
5
+ import { PopoverContext } from './contexts';
6
+ import { usePopover } from './hooks';
7
+ export var Popover = function Popover(_ref) {
8
+ var children = _ref.children,
9
+ _ref$modal = _ref.modal,
10
+ modal = _ref$modal === void 0 ? false : _ref$modal,
11
+ restOptions = _objectWithoutPropertiesLoose(_ref, _excluded);
12
+ var popover = usePopover(_extends({
13
+ modal: modal
14
+ }, restOptions));
15
+ return /*#__PURE__*/React.createElement(PopoverContext.Provider, {
16
+ value: popover
17
+ }, children);
18
+ };
@@ -0,0 +1,39 @@
1
+ import { type ReactNode } from 'react';
2
+ import { type AutoUpdateOptions, type FlipOptions, type OffsetOptions, type OpenChangeReason, type Placement, type ShiftOptions, type UseDismissProps, type UseListNavigationProps, type UseTransitionStylesProps } from '@floating-ui/react';
3
+ export type PopoverProps = {
4
+ children: ReactNode;
5
+ } & PopoverOptions;
6
+ export type PopoverTriggerType = 'click' | 'hover';
7
+ type SharedMiddlewareConfig = {
8
+ enabled?: boolean;
9
+ };
10
+ export type OffsetConfig = SharedMiddlewareConfig & Exclude<OffsetOptions, number>;
11
+ export type FlipConfig = SharedMiddlewareConfig & FlipOptions;
12
+ export type ShiftConfig = SharedMiddlewareConfig & ShiftOptions;
13
+ export type PopoverOptions = {
14
+ initialOpen?: boolean;
15
+ placement?: Placement;
16
+ modal?: boolean;
17
+ testId?: string;
18
+ componentId?: string;
19
+ autoUpdate?: boolean | AutoUpdateOptions;
20
+ open?: boolean;
21
+ offsetConfig?: OffsetConfig;
22
+ flipConfig?: FlipConfig;
23
+ shiftConfig?: ShiftConfig;
24
+ dismissConfig?: UseDismissProps;
25
+ listNavigationConfig?: UseListNavigationProps;
26
+ trigger?: PopoverTriggerType | PopoverTriggerType[];
27
+ /**
28
+ * defaults to theme.variables['zindex-dropdown'],
29
+ */
30
+ zIndex?: number;
31
+ onOpenChange?: (open: boolean, event?: Event, reason?: OpenChangeReason) => void;
32
+ onDismiss?: (event?: Event, reason?: OpenChangeReason) => void;
33
+ getPopupContainer?: (element: HTMLElement) => HTMLElement;
34
+ transitionDuration?: number;
35
+ getTransitionConfig?: ({ placement, }: {
36
+ placement: Placement;
37
+ }) => Partial<UseTransitionStylesProps>;
38
+ };
39
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare const PopoverClose: React.ForwardRefExoticComponent<React.ButtonHTMLAttributes<HTMLButtonElement> & React.RefAttributes<HTMLButtonElement>>;
@@ -0,0 +1,16 @@
1
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
+ import React, { forwardRef } from 'react';
3
+ import { usePopoverContext } from '../hooks/usePopoverContext';
4
+ export var PopoverClose = /*#__PURE__*/forwardRef(function PopoverClose(props, ref) {
5
+ var _usePopoverContext = usePopoverContext(),
6
+ setOpen = _usePopoverContext.setOpen;
7
+ return /*#__PURE__*/React.createElement("button", _extends({
8
+ type: "button",
9
+ ref: ref
10
+ }, props, {
11
+ onClick: function onClick(event) {
12
+ props.onClick == null || props.onClick(event);
13
+ setOpen(false);
14
+ }
15
+ }));
16
+ });
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare const PopoverContent: React.ForwardRefExoticComponent<Omit<React.HTMLProps<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,73 @@
1
+ var _excluded = ["style"];
2
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
3
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
4
+ import React, { forwardRef, useEffect, useMemo, useRef, useState } from 'react';
5
+ import { FloatingFocusManager, FloatingPortal, useMergeRefs } from '@floating-ui/react';
6
+ import { useTheme } from '@synerise/ds-core';
7
+ import { usePopoverContext } from '../hooks/usePopoverContext';
8
+ export var PopoverContent = /*#__PURE__*/forwardRef(function PopoverContent(_ref, propRef) {
9
+ var style = _ref.style,
10
+ props = _objectWithoutPropertiesLoose(_ref, _excluded);
11
+ var _usePopoverContext = usePopoverContext(),
12
+ floatingContext = _usePopoverContext.context,
13
+ getPopupContainer = _usePopoverContext.getPopupContainer,
14
+ modal = _usePopoverContext.modal,
15
+ testId = _usePopoverContext.testId,
16
+ refs = _usePopoverContext.refs,
17
+ getFloatingProps = _usePopoverContext.getFloatingProps,
18
+ floatingStyles = _usePopoverContext.floatingStyles,
19
+ labelId = _usePopoverContext.labelId,
20
+ descriptionId = _usePopoverContext.descriptionId,
21
+ transitionStyles = _usePopoverContext.transitionStyles,
22
+ componentId = _usePopoverContext.componentId,
23
+ zIndex = _usePopoverContext.zIndex;
24
+ var theme = useTheme();
25
+ var _useState = useState(false),
26
+ transitionEnded = _useState[0],
27
+ setTransitionEnded = _useState[1];
28
+ var popupContainerRef = useRef(null);
29
+ var ref = useMergeRefs([refs.setFloating, propRef]);
30
+ useEffect(function () {
31
+ if (!floatingContext.open) {
32
+ setTransitionEnded(false);
33
+ }
34
+ }, [floatingContext.open]);
35
+ useEffect(function () {
36
+ if (getPopupContainer && refs.reference.current) {
37
+ popupContainerRef.current = getPopupContainer(refs.reference.current);
38
+ }
39
+ }, [getPopupContainer, refs.reference]);
40
+ var dataProps = useMemo(function () {
41
+ var propsSet = {
42
+ 'data-testid': "popover-" + testId + "-content",
43
+ 'data-popover-content': 'true'
44
+ };
45
+ if (componentId) {
46
+ propsSet["data-popover-" + componentId] = 'true';
47
+ }
48
+ return propsSet;
49
+ }, [componentId, testId]);
50
+ if (!floatingContext.open) {
51
+ return null;
52
+ }
53
+ return /*#__PURE__*/React.createElement(FloatingPortal, {
54
+ root: getPopupContainer ? popupContainerRef : undefined
55
+ }, /*#__PURE__*/React.createElement(FloatingFocusManager, {
56
+ initialFocus: -1,
57
+ context: floatingContext,
58
+ modal: modal
59
+ }, /*#__PURE__*/React.createElement("div", _extends({}, dataProps, {
60
+ ref: ref,
61
+ style: _extends({}, floatingStyles, style, {
62
+ zIndex: zIndex !== undefined ? "" + zIndex : theme.variables['zindex-dropdown']
63
+ }),
64
+ "aria-labelledby": labelId,
65
+ "aria-describedby": descriptionId
66
+ }, getFloatingProps(props)), transitionStyles ? /*#__PURE__*/React.createElement("div", {
67
+ "data-transition-state": transitionEnded ? 'ended' : 'started',
68
+ style: transitionStyles,
69
+ onTransitionEnd: function onTransitionEnd() {
70
+ return setTransitionEnded(true);
71
+ }
72
+ }, props.children) : props.children)));
73
+ });
@@ -0,0 +1,6 @@
1
+ import React, { type ReactNode } from 'react';
2
+ export type PopoverTriggerProps = {
3
+ children: ReactNode;
4
+ asChild?: boolean;
5
+ };
6
+ export declare const PopoverTrigger: React.ForwardRefExoticComponent<Omit<React.HTMLProps<HTMLElement> & PopoverTriggerProps, "ref"> & React.RefAttributes<HTMLElement>>;
@@ -0,0 +1,38 @@
1
+ var _excluded = ["children", "asChild"];
2
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
3
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
4
+ import React, { cloneElement, forwardRef, isValidElement } from 'react';
5
+ import { useMergeRefs } from '@floating-ui/react';
6
+ import { usePopoverContext } from '../hooks/usePopoverContext';
7
+ import * as S from './PopoverTrigger.styles';
8
+ export var PopoverTrigger = /*#__PURE__*/forwardRef(function (_ref, propRef) {
9
+ var children = _ref.children,
10
+ _ref$asChild = _ref.asChild,
11
+ asChild = _ref$asChild === void 0 ? false : _ref$asChild,
12
+ props = _objectWithoutPropertiesLoose(_ref, _excluded);
13
+ var context = usePopoverContext();
14
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
+ var childrenRef = children.ref;
16
+ var ref = useMergeRefs([context.refs.setReference, propRef, childrenRef]);
17
+ // `asChild` allows the user to pass any element as the anchor
18
+ // if the child is a component it needs to forward the ref to a html element
19
+ // so that the Popover can position itself correctly.
20
+ if (asChild && /*#__PURE__*/isValidElement(children)) {
21
+ var referenceProps = context.getReferenceProps(_extends({
22
+ ref: ref,
23
+ 'data-popover-trigger': true,
24
+ 'data-testid': "popover-" + context.testId + "-trigger"
25
+ }, props, children.props, {
26
+ 'data-state': context.open ? 'open' : 'closed'
27
+ }));
28
+ return /*#__PURE__*/cloneElement(children, _extends({}, referenceProps));
29
+ }
30
+ return /*#__PURE__*/React.createElement(S.Trigger, _extends({
31
+ ref: ref
32
+ // The user can style the trigger based on the state
33
+ ,
34
+ "data-state": context.open ? 'open' : 'closed',
35
+ "data-popover-trigger": true,
36
+ "data-testid": "popover-" + context.testId + "-trigger"
37
+ }, context.getReferenceProps(props)), children);
38
+ });
@@ -0,0 +1 @@
1
+ export declare const Trigger: import("styled-components").StyledComponent<"span", any, {}, never>;
@@ -0,0 +1,5 @@
1
+ import styled from 'styled-components';
2
+ export var Trigger = styled.span.withConfig({
3
+ displayName: "PopoverTriggerstyles__Trigger",
4
+ componentId: "sc-1irht31-0"
5
+ })(["display:flex;"]);
@@ -0,0 +1,3 @@
1
+ export * from './PopoverTrigger';
2
+ export * from './PopoverClose';
3
+ export * from './PopoverContent';
@@ -0,0 +1,3 @@
1
+ export * from './PopoverTrigger';
2
+ export * from './PopoverClose';
3
+ export * from './PopoverContent';
@@ -0,0 +1,7 @@
1
+ import { type Dispatch, type SetStateAction } from 'react';
2
+ import { type usePopover } from '../hooks';
3
+ export type ContextType = (ReturnType<typeof usePopover> & {
4
+ setLabelId: Dispatch<SetStateAction<string | undefined>>;
5
+ setDescriptionId: Dispatch<SetStateAction<string | undefined>>;
6
+ }) | null;
7
+ export declare const PopoverContext: import("react").Context<ContextType>;
@@ -0,0 +1,2 @@
1
+ import { createContext } from 'react';
2
+ export var PopoverContext = /*#__PURE__*/createContext(null);
@@ -0,0 +1 @@
1
+ export * from './PopoverContext';
@@ -0,0 +1 @@
1
+ export * from './PopoverContext';
@@ -0,0 +1,2 @@
1
+ export * from './usePopover';
2
+ export * from './usePopoverContext';
@@ -0,0 +1,2 @@
1
+ export * from './usePopover';
2
+ export * from './usePopoverContext';
@@ -0,0 +1,24 @@
1
+ import { type UseListNavigationProps } from '@floating-ui/react';
2
+ export declare const useListNavigationConfig: (listNavigationConfig?: UseListNavigationProps) => {
3
+ listRef: React.MutableRefObject<Array<HTMLElement | null>>;
4
+ activeIndex: number | null;
5
+ onNavigate?: (activeIndex: number | null) => void;
6
+ enabled: boolean;
7
+ selectedIndex?: number | null;
8
+ focusItemOnOpen?: boolean | "auto";
9
+ focusItemOnHover?: boolean;
10
+ openOnArrowKeyDown?: boolean;
11
+ disabledIndices?: Array<number> | ((index: number) => boolean);
12
+ allowEscape?: boolean;
13
+ loop?: boolean;
14
+ nested?: boolean;
15
+ parentOrientation?: UseListNavigationProps["orientation"];
16
+ rtl?: boolean;
17
+ virtual?: boolean;
18
+ orientation?: "vertical" | "horizontal" | "both";
19
+ cols?: number;
20
+ scrollItemIntoView?: boolean | ScrollIntoViewOptions;
21
+ virtualItemRef?: React.MutableRefObject<HTMLElement | null>;
22
+ itemSizes?: import("@floating-ui/utils").Dimensions[];
23
+ dense?: boolean;
24
+ };
@@ -0,0 +1,10 @@
1
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
+ import { useRef } from 'react';
3
+ export var useListNavigationConfig = function useListNavigationConfig(listNavigationConfig) {
4
+ var listRef = useRef([]);
5
+ return _extends({
6
+ activeIndex: null,
7
+ enabled: false,
8
+ listRef: listRef
9
+ }, listNavigationConfig);
10
+ };
@@ -0,0 +1,58 @@
1
+ import { type OpenChangeReason } from '@floating-ui/react';
2
+ import { type PopoverOptions } from '../Popover.types';
3
+ export declare const usePopover: ({ initialOpen, placement, modal, trigger, open: controlledOpen, onOpenChange: setControlledOpen, onDismiss, transitionDuration, getPopupContainer, autoUpdate: autoUpdateWhileMounted, dismissConfig, offsetConfig, flipConfig, shiftConfig, testId, componentId, listNavigationConfig, getTransitionConfig, zIndex, }?: PopoverOptions) => {
4
+ modal: boolean | undefined;
5
+ labelId: string | undefined;
6
+ getPopupContainer: ((element: HTMLElement) => HTMLElement) | undefined;
7
+ descriptionId: string | undefined;
8
+ setLabelId: import("react").Dispatch<import("react").SetStateAction<string | undefined>>;
9
+ setDescriptionId: import("react").Dispatch<import("react").SetStateAction<string | undefined>>;
10
+ testId: string;
11
+ zIndex: number | undefined;
12
+ componentId: string | undefined;
13
+ placement: import("@floating-ui/utils").Placement;
14
+ strategy: import("@floating-ui/utils").Strategy;
15
+ middlewareData: import("@floating-ui/core").MiddlewareData;
16
+ x: number;
17
+ y: number;
18
+ isPositioned: boolean;
19
+ update: () => void;
20
+ floatingStyles: React.CSSProperties;
21
+ refs: {
22
+ reference: import("react").MutableRefObject<import("@floating-ui/react-dom").ReferenceType | null>;
23
+ floating: React.MutableRefObject<HTMLElement | null>;
24
+ setReference: (node: import("@floating-ui/react-dom").ReferenceType | null) => void;
25
+ setFloating: (node: HTMLElement | null) => void;
26
+ } & import("@floating-ui/react").ExtendedRefs<import("@floating-ui/react").ReferenceType>;
27
+ elements: {
28
+ reference: import("@floating-ui/react-dom").ReferenceType | null;
29
+ floating: HTMLElement | null;
30
+ } & import("@floating-ui/react").ExtendedElements<import("@floating-ui/react").ReferenceType>;
31
+ context: {
32
+ x: number;
33
+ y: number;
34
+ placement: import("@floating-ui/utils").Placement;
35
+ strategy: import("@floating-ui/utils").Strategy;
36
+ middlewareData: import("@floating-ui/core").MiddlewareData;
37
+ isPositioned: boolean;
38
+ update: () => void;
39
+ floatingStyles: React.CSSProperties;
40
+ open: boolean;
41
+ onOpenChange: (open: boolean, event?: Event, reason?: OpenChangeReason) => void;
42
+ events: import("@floating-ui/react").FloatingEvents;
43
+ dataRef: React.MutableRefObject<import("@floating-ui/react").ContextData>;
44
+ nodeId: string | undefined;
45
+ floatingId: string | undefined;
46
+ refs: import("@floating-ui/react").ExtendedRefs<import("@floating-ui/react").ReferenceType>;
47
+ elements: import("@floating-ui/react").ExtendedElements<import("@floating-ui/react").ReferenceType>;
48
+ };
49
+ getReferenceProps: (userProps?: React.HTMLProps<Element>) => Record<string, unknown>;
50
+ getFloatingProps: (userProps?: React.HTMLProps<HTMLElement>) => Record<string, unknown>;
51
+ getItemProps: (userProps?: Omit<React.HTMLProps<HTMLElement>, "selected" | "active"> & {
52
+ active?: boolean;
53
+ selected?: boolean;
54
+ }) => Record<string, unknown>;
55
+ open: boolean;
56
+ setOpen: (open: boolean, event?: Event, reason?: OpenChangeReason) => void;
57
+ transitionStyles: import("react").CSSProperties | undefined;
58
+ };
@@ -0,0 +1,117 @@
1
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
+ import { useMemo, useState } from 'react';
3
+ import { autoUpdate, useClick, useDismiss, useFloating, useHover, useInteractions, useListNavigation, useRole, useTransitionStyles } from '@floating-ui/react';
4
+ import { HOVER_CLOSE_DELAY, HOVER_OPEN_DELAY } from '../Popover.const';
5
+ import { getDefaultTransitionConfig, getMiddleware } from '../utils';
6
+ import { useListNavigationConfig } from './useListNavigationConfig';
7
+ export var usePopover = function usePopover(_temp) {
8
+ var _ref = _temp === void 0 ? {} : _temp,
9
+ _ref$initialOpen = _ref.initialOpen,
10
+ initialOpen = _ref$initialOpen === void 0 ? false : _ref$initialOpen,
11
+ _ref$placement = _ref.placement,
12
+ placement = _ref$placement === void 0 ? 'bottom' : _ref$placement,
13
+ modal = _ref.modal,
14
+ _ref$trigger = _ref.trigger,
15
+ trigger = _ref$trigger === void 0 ? 'click' : _ref$trigger,
16
+ controlledOpen = _ref.open,
17
+ setControlledOpen = _ref.onOpenChange,
18
+ onDismiss = _ref.onDismiss,
19
+ transitionDuration = _ref.transitionDuration,
20
+ getPopupContainer = _ref.getPopupContainer,
21
+ autoUpdateWhileMounted = _ref.autoUpdate,
22
+ _ref$dismissConfig = _ref.dismissConfig,
23
+ dismissConfig = _ref$dismissConfig === void 0 ? {} : _ref$dismissConfig,
24
+ _ref$offsetConfig = _ref.offsetConfig,
25
+ offsetConfig = _ref$offsetConfig === void 0 ? {} : _ref$offsetConfig,
26
+ _ref$flipConfig = _ref.flipConfig,
27
+ flipConfig = _ref$flipConfig === void 0 ? {} : _ref$flipConfig,
28
+ _ref$shiftConfig = _ref.shiftConfig,
29
+ shiftConfig = _ref$shiftConfig === void 0 ? {} : _ref$shiftConfig,
30
+ _ref$testId = _ref.testId,
31
+ testId = _ref$testId === void 0 ? 'noTestId' : _ref$testId,
32
+ componentId = _ref.componentId,
33
+ listNavigationConfig = _ref.listNavigationConfig,
34
+ _ref$getTransitionCon = _ref.getTransitionConfig,
35
+ getTransitionConfig = _ref$getTransitionCon === void 0 ? getDefaultTransitionConfig : _ref$getTransitionCon,
36
+ zIndex = _ref.zIndex;
37
+ var _useState = useState(initialOpen),
38
+ uncontrolledOpen = _useState[0],
39
+ setUncontrolledOpen = _useState[1];
40
+ var _useState2 = useState(),
41
+ labelId = _useState2[0],
42
+ setLabelId = _useState2[1];
43
+ var _useState3 = useState(),
44
+ descriptionId = _useState3[0],
45
+ setDescriptionId = _useState3[1];
46
+ var open = controlledOpen != null ? controlledOpen : uncontrolledOpen;
47
+ var setOpen = setControlledOpen != null ? setControlledOpen : setUncontrolledOpen;
48
+ var triggerArray = Array.isArray(trigger) ? trigger : [trigger];
49
+ var whileElementsMounted = useMemo(function () {
50
+ if (!autoUpdateWhileMounted) {
51
+ return undefined;
52
+ }
53
+ if (autoUpdateWhileMounted === true) {
54
+ return autoUpdate;
55
+ }
56
+ return function (referenceEl, floatingEl, update) {
57
+ var cleanup = autoUpdate(referenceEl, floatingEl, update, autoUpdateWhileMounted);
58
+ return cleanup;
59
+ };
60
+ }, [autoUpdateWhileMounted]);
61
+ var data = useFloating({
62
+ placement: placement,
63
+ open: open,
64
+ onOpenChange: function onOpenChange(newState, event, reason) {
65
+ setOpen(newState, event, reason);
66
+ if (dismissConfig.enabled !== false && (reason === 'escape-key' || reason === 'outside-press')) {
67
+ onDismiss == null || onDismiss(event, reason);
68
+ }
69
+ },
70
+ whileElementsMounted: whileElementsMounted,
71
+ middleware: getMiddleware({
72
+ offsetConfig: offsetConfig,
73
+ flipConfig: flipConfig,
74
+ shiftConfig: shiftConfig
75
+ })
76
+ });
77
+ var context = data.context;
78
+ var isClickEnabled = triggerArray.includes('click');
79
+ var isHoverEnabled = triggerArray.includes('hover');
80
+ var listNavConfig = useListNavigationConfig(listNavigationConfig);
81
+ var listNav = useListNavigation(context, listNavConfig);
82
+ var click = useClick(context, {
83
+ enabled: isClickEnabled && controlledOpen === undefined
84
+ });
85
+ var hover = useHover(context, {
86
+ enabled: isHoverEnabled,
87
+ delay: {
88
+ open: HOVER_OPEN_DELAY,
89
+ close: HOVER_CLOSE_DELAY
90
+ }
91
+ });
92
+ var dismiss = useDismiss(context, dismissConfig);
93
+ var role = useRole(context);
94
+ var interactions = useInteractions([click, hover, dismiss, role, listNav]);
95
+ var _useTransitionStyles = useTransitionStyles(context, _extends({
96
+ duration: transitionDuration
97
+ }, getTransitionConfig(data))),
98
+ styles = _useTransitionStyles.styles,
99
+ isMounted = _useTransitionStyles.isMounted;
100
+ return useMemo(function () {
101
+ return _extends({
102
+ open: isMounted,
103
+ setOpen: setOpen,
104
+ transitionStyles: typeof transitionDuration === 'number' ? styles : undefined
105
+ }, interactions, data, {
106
+ modal: modal,
107
+ labelId: labelId,
108
+ getPopupContainer: getPopupContainer,
109
+ descriptionId: descriptionId,
110
+ setLabelId: setLabelId,
111
+ setDescriptionId: setDescriptionId,
112
+ testId: testId,
113
+ zIndex: zIndex,
114
+ componentId: componentId
115
+ });
116
+ }, [getPopupContainer, isMounted, setOpen, transitionDuration, styles, interactions, data, modal, labelId, descriptionId, zIndex, testId, componentId]);
117
+ };
@@ -0,0 +1,59 @@
1
+ export declare const usePopoverContext: () => {
2
+ modal: boolean | undefined;
3
+ labelId: string | undefined;
4
+ getPopupContainer: ((element: HTMLElement) => HTMLElement) | undefined;
5
+ descriptionId: string | undefined;
6
+ setLabelId: import("react").Dispatch<import("react").SetStateAction<string | undefined>>;
7
+ setDescriptionId: import("react").Dispatch<import("react").SetStateAction<string | undefined>>;
8
+ testId: string;
9
+ zIndex: number | undefined;
10
+ componentId: string | undefined;
11
+ placement: import("@floating-ui/utils").Placement;
12
+ strategy: import("@floating-ui/utils").Strategy;
13
+ middlewareData: import("@floating-ui/core").MiddlewareData;
14
+ x: number;
15
+ y: number;
16
+ isPositioned: boolean;
17
+ update: () => void;
18
+ floatingStyles: React.CSSProperties;
19
+ refs: {
20
+ reference: import("react").MutableRefObject<import("@floating-ui/react-dom").ReferenceType | null>;
21
+ floating: React.MutableRefObject<HTMLElement | null>;
22
+ setReference: (node: import("@floating-ui/react-dom").ReferenceType | null) => void;
23
+ setFloating: (node: HTMLElement | null) => void;
24
+ } & import("@floating-ui/react").ExtendedRefs<import("@floating-ui/react").ReferenceType>;
25
+ elements: {
26
+ reference: import("@floating-ui/react-dom").ReferenceType | null;
27
+ floating: HTMLElement | null;
28
+ } & import("@floating-ui/react").ExtendedElements<import("@floating-ui/react").ReferenceType>;
29
+ context: {
30
+ x: number;
31
+ y: number;
32
+ placement: import("@floating-ui/utils").Placement;
33
+ strategy: import("@floating-ui/utils").Strategy;
34
+ middlewareData: import("@floating-ui/core").MiddlewareData;
35
+ isPositioned: boolean;
36
+ update: () => void;
37
+ floatingStyles: React.CSSProperties;
38
+ open: boolean;
39
+ onOpenChange: (open: boolean, event?: Event, reason?: import("@floating-ui/react").OpenChangeReason) => void;
40
+ events: import("@floating-ui/react").FloatingEvents;
41
+ dataRef: React.MutableRefObject<import("@floating-ui/react").ContextData>;
42
+ nodeId: string | undefined;
43
+ floatingId: string | undefined;
44
+ refs: import("@floating-ui/react").ExtendedRefs<import("@floating-ui/react").ReferenceType>;
45
+ elements: import("@floating-ui/react").ExtendedElements<import("@floating-ui/react").ReferenceType>;
46
+ };
47
+ getReferenceProps: (userProps?: React.HTMLProps<Element>) => Record<string, unknown>;
48
+ getFloatingProps: (userProps?: React.HTMLProps<HTMLElement>) => Record<string, unknown>;
49
+ getItemProps: (userProps?: Omit<React.HTMLProps<HTMLElement>, "selected" | "active"> & {
50
+ active?: boolean;
51
+ selected?: boolean;
52
+ }) => Record<string, unknown>;
53
+ open: boolean;
54
+ setOpen: (open: boolean, event?: Event, reason?: import("@floating-ui/react").OpenChangeReason) => void;
55
+ transitionStyles: import("react").CSSProperties | undefined;
56
+ } & {
57
+ setLabelId: import("react").Dispatch<import("react").SetStateAction<string | undefined>>;
58
+ setDescriptionId: import("react").Dispatch<import("react").SetStateAction<string | undefined>>;
59
+ };
@@ -0,0 +1,9 @@
1
+ import { useContext } from 'react';
2
+ import { PopoverContext } from '../contexts';
3
+ export var usePopoverContext = function usePopoverContext() {
4
+ var context = useContext(PopoverContext);
5
+ if (context === null) {
6
+ throw new Error('Popover components must be wrapped in <Popover />');
7
+ }
8
+ return context;
9
+ };
@@ -0,0 +1,4 @@
1
+ export * from './Popover';
2
+ export * from './components';
3
+ export { Popover as default } from './Popover';
4
+ export * from './Popover.types';
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export * from './Popover';
2
+ export * from './components';
3
+ export { Popover as default } from './Popover';
4
+ export * from './Popover.types';
@@ -0,0 +1 @@
1
+ import '@testing-library/jest-dom';
@@ -0,0 +1,2 @@
1
+ import { type UseTransitionStylesProps } from '@floating-ui/react';
2
+ export declare const getDefaultTransitionConfig: () => Partial<UseTransitionStylesProps>;
@@ -0,0 +1,10 @@
1
+ export var getDefaultTransitionConfig = function getDefaultTransitionConfig() {
2
+ return {
3
+ open: {
4
+ opacity: 1
5
+ },
6
+ initial: {
7
+ opacity: 0
8
+ }
9
+ };
10
+ };
@@ -0,0 +1,12 @@
1
+ import { type FlipConfig, type OffsetConfig, type ShiftConfig } from '../Popover.types';
2
+ type GetMiddleware = {
3
+ offsetConfig: OffsetConfig;
4
+ flipConfig: FlipConfig;
5
+ shiftConfig: ShiftConfig;
6
+ };
7
+ export declare const getMiddleware: ({ offsetConfig, flipConfig, shiftConfig, }: GetMiddleware) => {
8
+ name: string;
9
+ options?: any;
10
+ fn: (state: import("@floating-ui/dom").MiddlewareState) => import("@floating-ui/core").MiddlewareReturn | Promise<import("@floating-ui/core").MiddlewareReturn>;
11
+ }[];
12
+ export {};
@@ -0,0 +1,33 @@
1
+ var _excluded = ["enabled"],
2
+ _excluded2 = ["enabled"],
3
+ _excluded3 = ["enabled"];
4
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
5
+ import { flip, offset, shift } from '@floating-ui/react';
6
+ export var getMiddleware = function getMiddleware(_ref) {
7
+ var offsetConfig = _ref.offsetConfig,
8
+ flipConfig = _ref.flipConfig,
9
+ shiftConfig = _ref.shiftConfig;
10
+ var middleware = [];
11
+ var _ref2 = offsetConfig || {},
12
+ _ref2$enabled = _ref2.enabled,
13
+ offsetEnabled = _ref2$enabled === void 0 ? true : _ref2$enabled,
14
+ offsetOptions = _objectWithoutPropertiesLoose(_ref2, _excluded);
15
+ var _ref3 = flipConfig || {},
16
+ _ref3$enabled = _ref3.enabled,
17
+ flipEnabled = _ref3$enabled === void 0 ? true : _ref3$enabled,
18
+ flipOptions = _objectWithoutPropertiesLoose(_ref3, _excluded2);
19
+ var _ref4 = shiftConfig || {},
20
+ _ref4$enabled = _ref4.enabled,
21
+ shiftEnabled = _ref4$enabled === void 0 ? true : _ref4$enabled,
22
+ shiftOptions = _objectWithoutPropertiesLoose(_ref4, _excluded3);
23
+ if (offsetEnabled) {
24
+ middleware.push(offset(offsetOptions));
25
+ }
26
+ if (flipEnabled) {
27
+ middleware.push(flip(flipOptions));
28
+ }
29
+ if (shiftEnabled) {
30
+ middleware.push(shift(shiftOptions));
31
+ }
32
+ return middleware;
33
+ };
@@ -0,0 +1,2 @@
1
+ export * from './getDefaultTransitionConfig';
2
+ export * from './getMiddleware';
@@ -0,0 +1,2 @@
1
+ export * from './getDefaultTransitionConfig';
2
+ export * from './getMiddleware';
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@synerise/ds-popover",
3
+ "version": "1.1.0",
4
+ "description": "Popover UI Component for the Synerise Design System",
5
+ "license": "ISC",
6
+ "repository": "Synerise/synerise-design",
7
+ "main": "dist/index.js",
8
+ "files": [
9
+ "/dist",
10
+ "CHANGELOG.md",
11
+ "README.md",
12
+ "package.json",
13
+ "LICENSE.md"
14
+ ],
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "scripts": {
19
+ "build": "npm run build:js && npm run build:css && npm run defs",
20
+ "build:css": "node ../../../scripts/style/less.js",
21
+ "build:js": "babel --delete-dir-on-start --root-mode upward src --out-dir dist --extensions '.js,.ts,.tsx'",
22
+ "build:watch": "npm run build:js -- --watch",
23
+ "defs": "tsc --declaration --outDir dist/ --emitDeclarationOnly",
24
+ "prepublish": "npm run build",
25
+ "types": "tsc --noEmit",
26
+ "pack:ci": "npm pack --pack-destination ../../storybook/storybook-static/static",
27
+ "test": "jest",
28
+ "test:watch": "npm run test -- --watchAll",
29
+ "upgrade:ds": "ncu -f \"@synerise/ds-*\" -u"
30
+ },
31
+ "sideEffects": [
32
+ "dist/style/*",
33
+ "*.less"
34
+ ],
35
+ "types": "dist/index.d.ts",
36
+ "dependencies": {
37
+ "@floating-ui/react": "^0.27.13"
38
+ },
39
+ "devDependencies": {
40
+ "@testing-library/user-event": "^14"
41
+ },
42
+ "peerDependencies": {
43
+ "@synerise/ds-core": "*",
44
+ "react": ">=16.9.0 <= 18.3.1"
45
+ },
46
+ "gitHead": "cbbb7d9f155735bcc4035d8fd8a7813878d6e051"
47
+ }