@simplybusiness/mobius 4.0.0 → 4.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 (33) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/cjs/components/Popover/Popover.d.ts +16 -0
  3. package/dist/cjs/components/Popover/Popover.js +70 -0
  4. package/dist/cjs/components/Popover/Popover.js.map +1 -0
  5. package/dist/cjs/components/Popover/Popover.stories.d.ts +28 -0
  6. package/dist/cjs/components/Popover/Popover.stories.js +43 -0
  7. package/dist/cjs/components/Popover/Popover.stories.js.map +1 -0
  8. package/dist/cjs/components/Popover/Popover.test.d.ts +1 -0
  9. package/dist/cjs/components/Popover/Popover.test.js +105 -0
  10. package/dist/cjs/components/Popover/Popover.test.js.map +1 -0
  11. package/dist/cjs/components/Popover/index.d.ts +1 -0
  12. package/dist/cjs/components/Popover/index.js +18 -0
  13. package/dist/cjs/components/Popover/index.js.map +1 -0
  14. package/dist/cjs/components/index.d.ts +2 -1
  15. package/dist/cjs/components/index.js +2 -1
  16. package/dist/cjs/components/index.js.map +1 -1
  17. package/dist/cjs/tsconfig.tsbuildinfo +1 -1
  18. package/dist/esm/components/Popover/Popover.js +63 -0
  19. package/dist/esm/components/Popover/Popover.js.map +1 -0
  20. package/dist/esm/components/Popover/index.js +2 -0
  21. package/dist/esm/components/Popover/index.js.map +1 -0
  22. package/dist/esm/components/index.js +2 -1
  23. package/dist/esm/components/index.js.map +1 -1
  24. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  25. package/dist/mobius.d.ts +18 -0
  26. package/package.json +5 -4
  27. package/src/components/Popover/Popover.mdx +107 -0
  28. package/src/components/Popover/Popover.stories.tsx +105 -0
  29. package/src/components/Popover/Popover.story.styles.css +25 -0
  30. package/src/components/Popover/Popover.test.tsx +186 -0
  31. package/src/components/Popover/Popover.tsx +137 -0
  32. package/src/components/Popover/index.tsx +1 -0
  33. package/src/components/index.tsx +2 -1
package/CHANGELOG.md CHANGED
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file, or link in
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [4.1.0] - 2023-12-01
9
+
10
+ ## Added
11
+
12
+ - Added `<Popover>` component
13
+
8
14
  ## 4.0.0
9
15
 
10
16
  ### Fixed
@@ -432,6 +438,7 @@ Additionally, mobius and themes are available on the public NPM registry and can
432
438
 
433
439
  ## Github Links
434
440
 
441
+ [4.1.0]: https://github.com/simplybusiness/mobius/releases/tag/v4.1.0
435
442
  [4.0.0]: https://github.com/simplybusiness/mobius/releases/tag/v4.0.0
436
443
  [3.12.2]: https://github.com/simplybusiness/mobius/releases/tag/v3.12.2
437
444
  [3.12.1]: https://github.com/simplybusiness/mobius/releases/tag/v3.12.1
@@ -0,0 +1,16 @@
1
+ import { ReactElement, ReactNode, Ref, RefAttributes } from "react";
2
+ import { DOMProps } from "../../types/dom";
3
+ export type PopoverElementType = HTMLDivElement;
4
+ export interface PopoverProps extends DOMProps, RefAttributes<PopoverElementType> {
5
+ children?: ReactNode;
6
+ trigger: ReactElement;
7
+ isOpen?: boolean;
8
+ /** Callback that fires each time the accordion is opened */
9
+ onOpen?: () => void;
10
+ /** Callback that fires each time the accordion is closed */
11
+ onClose?: () => void;
12
+ /** Custom class name for setting specific CSS */
13
+ className?: string;
14
+ }
15
+ export type PopoverRef = Ref<PopoverElementType>;
16
+ export declare const Popover: (props: PopoverProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Popover = void 0;
7
+ const jsx_runtime_1 = require("react/jsx-runtime");
8
+ const icons_1 = require("@simplybusiness/icons");
9
+ const react_1 = require("react");
10
+ const classnames_1 = __importDefault(require("classnames"));
11
+ const react_tiny_popover_1 = require("react-tiny-popover");
12
+ const hooks_1 = require("../../hooks");
13
+ const Button_1 = require("../Button");
14
+ const Icon_1 = require("../Icon");
15
+ const Popover = (props) => {
16
+ const popoverRef = (0, react_1.useRef)(null);
17
+ const triggerRef = (0, react_1.useRef)(null);
18
+ const { trigger, children, isOpen, onOpen, onClose, className } = props;
19
+ const previousIsOpen = (0, react_1.useRef)(isOpen);
20
+ const hasExternalState = typeof isOpen !== "undefined";
21
+ const [open, setOpen] = (0, react_1.useState)(isOpen);
22
+ const containerClasses = (0, classnames_1.default)("mobius", "mobius/PopoverContainer", className);
23
+ const noop = () => { };
24
+ const openPopover = (0, react_1.useCallback)(() => {
25
+ setOpen(true);
26
+ if (onOpen) {
27
+ onOpen();
28
+ }
29
+ }, [onOpen]);
30
+ const closePopover = (0, react_1.useCallback)(() => {
31
+ setOpen(false);
32
+ if (onClose) {
33
+ onClose();
34
+ }
35
+ }, [onClose]);
36
+ const handleClick = () => {
37
+ if (open) {
38
+ closePopover();
39
+ return;
40
+ }
41
+ openPopover();
42
+ };
43
+ const triggerComponent = (0, react_1.cloneElement)(trigger, {
44
+ className: "mobius/PopoverToggle",
45
+ onClick: hasExternalState ? noop : handleClick,
46
+ });
47
+ (0, hooks_1.useWindowEvent)("keydown", e => {
48
+ if (open && e.key === "Escape") {
49
+ closePopover();
50
+ }
51
+ });
52
+ (0, react_1.useEffect)(() => {
53
+ if (isOpen) {
54
+ openPopover();
55
+ return;
56
+ }
57
+ // Prevent 'onClose' being called when
58
+ // 'isOpen === false' on initial render
59
+ if (previousIsOpen.current === isOpen) {
60
+ previousIsOpen.current = undefined;
61
+ return;
62
+ }
63
+ if (!isOpen) {
64
+ closePopover();
65
+ }
66
+ }, [isOpen, closePopover, openPopover]);
67
+ return ((0, jsx_runtime_1.jsx)(react_tiny_popover_1.Popover, { isOpen: !!open, positions: ["bottom"], ref: triggerRef, content: (0, jsx_runtime_1.jsx)("div", { className: containerClasses, ref: popoverRef, children: (0, jsx_runtime_1.jsxs)("div", { className: "mobius/Popover", children: [(0, jsx_runtime_1.jsx)("header", { className: "mobius/PopoverHeader", children: (0, jsx_runtime_1.jsx)(Button_1.Button, { type: "button", className: "mobius/PopoverCloseButton", onClick: handleClick, "aria-label": "Close", variant: "ghost", children: (0, jsx_runtime_1.jsx)(Icon_1.Icon, { icon: icons_1.cross, size: "md", className: "mobius/PopoverCloseIcon" }) }) }), (0, jsx_runtime_1.jsx)("div", { className: "mobius/PopoverBody", children: children })] }) }), children: triggerComponent }));
68
+ };
69
+ exports.Popover = Popover;
70
+ //# sourceMappingURL=Popover.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Popover.js","sourceRoot":"","sources":["../../../../src/components/Popover/Popover.tsx"],"names":[],"mappings":";;;;;;;AAAA,iDAA8C;AAC9C,iCAUe;AACf,4DAAoC;AACpC,2DAA4D;AAC5D,uCAA6C;AAE7C,sCAAmC;AACnC,kCAA+B;AAoBxB,MAAM,OAAO,GAAG,CAAC,KAAmB,EAAE,EAAE;IAC7C,MAAM,UAAU,GAAG,IAAA,cAAM,EAAC,IAAI,CAAC,CAAC;IAChC,MAAM,UAAU,GAAG,IAAA,cAAM,EAAC,IAAI,CAAC,CAAC;IAChC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,KAAK,CAAC;IACxE,MAAM,cAAc,GAAG,IAAA,cAAM,EAAsB,MAAM,CAAC,CAAC;IAC3D,MAAM,gBAAgB,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC;IACvD,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,IAAA,gBAAQ,EAAC,MAAM,CAAC,CAAC;IACzC,MAAM,gBAAgB,GAAG,IAAA,oBAAU,EACjC,QAAQ,EACR,yBAAyB,EACzB,SAAS,CACV,CAAC;IACF,MAAM,IAAI,GAAG,GAAG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AE,WAAW,CAAC,CAAC,CAAC;IAExC,OAAO,CACL,uBAAC,4BAAW,IACV,MAAM,EAAE,CAAC,CAAC,IAAI,EACd,SAAS,EAAE,CAAC,QAAQ,CAAC,EACrB,GAAG,EAAE,UAAU,EACf,OAAO,EACL,gCAAK,SAAS,EAAE,gBAAgB,EAAE,GAAG,EAAE,UAAU,YAC/C,iCAAK,SAAS,EAAC,gBAAgB,aAC7B,mCAAQ,SAAS,EAAC,sBAAsB,YACtC,uBAAC,eAAM,IACL,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,2BAA2B,EACrC,OAAO,EAAE,WAAW,gBACT,OAAO,EAClB,OAAO,EAAC,OAAO,YAEf,uBAAC,WAAI,IACH,IAAI,EAAE,aAAK,EACX,IAAI,EAAC,IAAI,EACT,SAAS,EAAC,yBAAyB,GACnC,GACK,GACF,EACT,gCAAK,SAAS,EAAC,oBAAoB,YAAE,QAAQ,GAAO,IAChD,GACF,YAGP,gBAAgB,GACL,CACf,CAAC;AACJ,CAAC,CAAC;AAnGW,QAAA,OAAO,WAmGlB"}
@@ -0,0 +1,28 @@
1
+ import type { Meta } from "@storybook/react";
2
+ import { Ref } from "react";
3
+ import { Popover, PopoverProps } from "..";
4
+ declare const _default: {
5
+ title: string;
6
+ component: (props: PopoverProps) => import("react/jsx-runtime").JSX.Element;
7
+ argTypes: {
8
+ isOpen: {
9
+ control: {
10
+ type: string;
11
+ };
12
+ };
13
+ };
14
+ decorators: ((Story: import("@storybook/types").PartialStoryFn<import("@storybook/react/dist/types-0a347bb9").R, {
15
+ children?: import("react").ReactNode;
16
+ trigger: import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
17
+ isOpen?: boolean | undefined;
18
+ onOpen?: (() => void) | undefined;
19
+ onClose?: (() => void) | undefined;
20
+ className?: string | undefined;
21
+ id?: string | undefined;
22
+ ref?: Ref<HTMLDivElement> | undefined;
23
+ key?: import("react").Key | null | undefined;
24
+ }>) => import("react/jsx-runtime").JSX.Element)[];
25
+ };
26
+ export default _default;
27
+ export declare const Normal: Meta<typeof Popover>;
28
+ export declare const QCP: Meta<typeof Popover>;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QCP = exports.Normal = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const __1 = require("..");
7
+ const excludeControls_1 = require("../../utils/excludeControls");
8
+ exports.default = {
9
+ title: "Components/Popover",
10
+ component: __1.Popover,
11
+ argTypes: Object.assign({ isOpen: {
12
+ control: { type: "boolean" },
13
+ } }, (0, excludeControls_1.excludeControls)("className", "children", "trigger", "id", "onOpen", "onClose")),
14
+ decorators: [
15
+ Story => {
16
+ // eslint-disable-next-line global-require
17
+ require("./Popover.story.styles.css");
18
+ return (0, jsx_runtime_1.jsx)(Story, {});
19
+ },
20
+ ],
21
+ };
22
+ const QuestionIcon = (0, react_1.forwardRef)((props, ref) => ((0, jsx_runtime_1.jsxs)("svg", Object.assign({ xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", width: "16px", height: "16px", ref: ref }, props, { children: [(0, jsx_runtime_1.jsxs)("g", { clipPath: "url(#clip0_1641_88567)", children: [(0, jsx_runtime_1.jsx)("path", { d: "M6.25 6.25002C6.25017 5.36011 6.91818 4.61203 7.80241 4.51155C8.68663 4.41107 9.50546 4.99019 9.7053 5.85737C9.90515 6.72456 9.42235 7.60364 8.58333 7.90027C8.23357 8.02393 7.99981 8.35471 8 8.72569V9.31253", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round" }), (0, jsx_runtime_1.jsx)("path", { d: "M8 11.0625C7.87919 11.0625 7.78125 11.1604 7.78125 11.2812C7.78125 11.4021 7.87919 11.5 8 11.5C8.12081 11.5 8.21875 11.4021 8.21875 11.2812C8.21875 11.1604 8.12081 11.0625 8 11.0625V11.0625", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round" }), (0, jsx_runtime_1.jsx)("circle", { cx: "8", cy: "8", r: "6.5625", stroke: "currentColor" })] }), (0, jsx_runtime_1.jsx)("defs", { children: (0, jsx_runtime_1.jsx)("clipPath", { id: "clip0_1641_88567", children: (0, jsx_runtime_1.jsx)("rect", { width: "16", height: "16", fill: "white" }) }) })] }))));
23
+ exports.Normal = {
24
+ render: (args) => (0, jsx_runtime_1.jsx)(__1.Popover, Object.assign({}, args)),
25
+ args: {
26
+ isOpen: undefined,
27
+ children: (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: "No way! Now I know everything I need to \uD83D\uDE80." }),
28
+ trigger: (0, jsx_runtime_1.jsx)(__1.Button, { variant: "primary", children: "If only I had more information" }),
29
+ },
30
+ };
31
+ exports.QCP = {
32
+ render: (args) => {
33
+ // eslint-disable-next-line react-hooks/rules-of-hooks
34
+ const [isOpen, setIsOpen] = (0, react_1.useState)(false);
35
+ const handleClick = () => setIsOpen(!isOpen);
36
+ return ((0, jsx_runtime_1.jsx)("div", { className: "popover-example", children: (0, jsx_runtime_1.jsx)(__1.Button, { variant: "ghost", onClick: handleClick, children: (0, jsx_runtime_1.jsxs)(__1.Flex, { children: [(0, jsx_runtime_1.jsx)("span", { children: "Occurrence Limit" }), (0, jsx_runtime_1.jsx)(__1.Popover, Object.assign({}, args, { isOpen: isOpen }))] }) }) }));
37
+ },
38
+ args: {
39
+ trigger: (0, jsx_runtime_1.jsx)(QuestionIcon, {}),
40
+ children: ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: "This is the maximum amount of money you'll get to cover a single incident that occurs during the policy period, regardless of when it's reported." })),
41
+ },
42
+ };
43
+ //# sourceMappingURL=Popover.stories.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Popover.stories.js","sourceRoot":"","sources":["../../../../src/components/Popover/Popover.stories.tsx"],"names":[],"mappings":";;;;AACA,iCAAkD;AAClD,0BAAyD;AACzD,iEAA8D;AAE9D,kBAAe;IACb,KAAK,EAAE,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IAAkB,EAAE,EAAE,CAAC,uBAAC,WAAO,oBAAK,IAAI,EAAI;IACrD,IAAI,EAAE;QACJ,MAAM,EAAE,SAAS;QACjB,QAAQ,EAAE,qHAAgD;QAC1D,OAAO,EAAE,uBAAC,UAAM,IAAC,OAAO,EAAC,SAAS,+CAAwC;KAC3E;CACF,CAAC;AAEW,QAAA,GAAG,GAAyB;IACvC,MAAM,EAAE,CAAC,IAAkB,EAAE,EAAE;QAC7B,sDAAsD;QACtD,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,IAAA,gBAAQ,EAAU,KAAK,CAAC,CAAC;QACrD,MAAM,WAAW,GAAG,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC;QAC7C,OAAO,CACL,gCAAK,SAAS,EAAC,iBAAiB,YAC9B,uBAAC,UAAM,IAAC,OAAO,EAAC,OAAO,EAAC,OAAO,EAAE,WAAW,YAC1C,wBAAC,QAAI,eACH,gEAA6B,EAC7B,uBAAC,WAAO,oBAAK,IAAI,IAAE,MAAM,EAAE,MAAM,IAAI,IAChC,GACA,GACL,CACP,CAAC;IACJ,CAAC;IACD,IAAI,EAAE;QACJ,OAAO,EAAE,uBAAC,YAAY,KAAG;QACzB,QAAQ,EAAE,CACR,iNAIG,CACJ;KACF;CACF,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const jsx_runtime_1 = require("react/jsx-runtime");
4
+ const react_1 = require("@testing-library/react");
5
+ const _1 = require(".");
6
+ const CONTAINER_ID = "react-tiny-popover-container";
7
+ const CONTAINER_CLASS_NAME = "mobius/PopoverContainer";
8
+ const TOGGLE_CLASS_NAME = "mobius/PopoverToggle";
9
+ const POPOVER_CLASS_NAME = "mobius/Popover";
10
+ const HEADER_CLASS_NAME = "mobius/PopoverHeader";
11
+ const CLOSE_BUTTON_CLASS_NAME = "mobius/PopoverCloseButton";
12
+ const CLOSE_ICON_CLASS_NAME = "mobius/PopoverCloseIcon";
13
+ const BODY_CLASS_NAME = "mobius/PopoverBody";
14
+ describe("Popover", () => {
15
+ it("should render without errors", () => {
16
+ const component = (0, react_1.render)((0, jsx_runtime_1.jsx)(_1.Popover, { trigger: (0, jsx_runtime_1.jsx)("button", { type: "button", children: "Click me" }), children: "Sample Text" }));
17
+ expect(component).toBeTruthy();
18
+ });
19
+ it("should open when clicked", async () => {
20
+ const sampleText = "Sample Text";
21
+ const triggerText = "Click me";
22
+ (0, react_1.render)((0, jsx_runtime_1.jsx)(_1.Popover, { trigger: (0, jsx_runtime_1.jsx)("button", { type: "button", children: triggerText }), children: sampleText }));
23
+ const button = react_1.screen.getByText(triggerText);
24
+ react_1.fireEvent.click(button);
25
+ await (0, react_1.waitFor)(() => {
26
+ expect(react_1.screen.queryByText(sampleText)).toBeInTheDocument();
27
+ });
28
+ const closeButton = react_1.screen.getByLabelText("Close");
29
+ react_1.fireEvent.click(closeButton);
30
+ expect(react_1.screen.queryByText(sampleText)).not.toBeInTheDocument();
31
+ });
32
+ describe("uses correct class names", () => {
33
+ it("uses correct classes", async () => {
34
+ var _a;
35
+ const sampleText = "Sample Text";
36
+ const triggerText = "Click me";
37
+ (0, react_1.render)((0, jsx_runtime_1.jsx)(_1.Popover, { trigger: (0, jsx_runtime_1.jsx)("button", { type: "button", children: triggerText }), children: sampleText }));
38
+ const button = react_1.screen.getByText(triggerText);
39
+ expect(button).toHaveClass(TOGGLE_CLASS_NAME);
40
+ react_1.fireEvent.click(button);
41
+ const popoverContainer = (_a = document.querySelector(`#${CONTAINER_ID}`)) === null || _a === void 0 ? void 0 : _a.firstChild;
42
+ await (0, react_1.waitFor)(() => {
43
+ expect(popoverContainer).toHaveClass("mobius");
44
+ });
45
+ const closeButton = react_1.screen.getByLabelText("Close");
46
+ const body = react_1.screen.getByText(sampleText);
47
+ expect(popoverContainer).toHaveClass(CONTAINER_CLASS_NAME);
48
+ expect(popoverContainer === null || popoverContainer === void 0 ? void 0 : popoverContainer.firstChild).toHaveClass(POPOVER_CLASS_NAME);
49
+ expect(closeButton.parentElement).toHaveClass(HEADER_CLASS_NAME);
50
+ expect(closeButton).toHaveClass(CLOSE_BUTTON_CLASS_NAME);
51
+ expect(closeButton.firstChild).toHaveClass(CLOSE_ICON_CLASS_NAME);
52
+ expect(body).toHaveClass(BODY_CLASS_NAME);
53
+ });
54
+ it("includes custom class name", async () => {
55
+ const customClassName = "my-class";
56
+ const sampleText = "Sample Text";
57
+ const triggerText = "Click me";
58
+ (0, react_1.render)((0, jsx_runtime_1.jsx)(_1.Popover, { className: customClassName, trigger: (0, jsx_runtime_1.jsx)("button", { type: "button", children: triggerText }), children: sampleText }));
59
+ const button = react_1.screen.getByText(triggerText);
60
+ react_1.fireEvent.click(button);
61
+ const popoverContainer = document.querySelector(`#${CONTAINER_ID}`);
62
+ await (0, react_1.waitFor)(() => {
63
+ expect(popoverContainer === null || popoverContainer === void 0 ? void 0 : popoverContainer.firstChild).toHaveClass(customClassName);
64
+ });
65
+ });
66
+ });
67
+ describe("events", () => {
68
+ describe("given isOpen prop is set", () => {
69
+ it("should not call onOpen or onClose when first rendered", () => {
70
+ const sampleText = "Sample Text";
71
+ const triggerText = "Click me";
72
+ const onOpen = jest.fn();
73
+ const onClose = jest.fn();
74
+ (0, react_1.render)((0, jsx_runtime_1.jsx)(_1.Popover, { isOpen: false, trigger: (0, jsx_runtime_1.jsx)("button", { type: "button", children: triggerText }), onOpen: onOpen, onClose: onClose, children: sampleText }));
75
+ expect(onOpen).not.toHaveBeenCalled();
76
+ expect(onClose).not.toHaveBeenCalled();
77
+ });
78
+ });
79
+ it("calls onOpen when Popover is opened", () => {
80
+ const sampleText = "Sample Text";
81
+ const triggerText = "Click me";
82
+ const onOpen = jest.fn();
83
+ const onClose = jest.fn();
84
+ (0, react_1.render)((0, jsx_runtime_1.jsx)(_1.Popover, { trigger: (0, jsx_runtime_1.jsx)("button", { type: "button", children: triggerText }), onOpen: onOpen, onClose: onClose, children: sampleText }));
85
+ const button = react_1.screen.getByText(triggerText);
86
+ react_1.fireEvent.click(button);
87
+ expect(onOpen).toHaveBeenCalled();
88
+ expect(onClose).not.toHaveBeenCalled();
89
+ });
90
+ it("calls onClose when Popover is closed", () => {
91
+ const sampleText = "Sample Text";
92
+ const triggerText = "Click me";
93
+ const onOpen = jest.fn();
94
+ const onClose = jest.fn();
95
+ (0, react_1.render)((0, jsx_runtime_1.jsx)(_1.Popover, { trigger: (0, jsx_runtime_1.jsx)("button", { type: "button", children: triggerText }), onOpen: onOpen, onClose: onClose, children: sampleText }));
96
+ const button = react_1.screen.getByText(triggerText);
97
+ react_1.fireEvent.click(button);
98
+ const closeButton = react_1.screen.getByLabelText("Close");
99
+ react_1.fireEvent.click(closeButton);
100
+ expect(onClose).toHaveBeenCalled();
101
+ expect(onOpen).toHaveBeenCalledTimes(1);
102
+ });
103
+ });
104
+ });
105
+ //# sourceMappingURL=Popover.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Popover.test.js","sourceRoot":"","sources":["../../../../src/components/Popover/Popover.test.tsx"],"names":[],"mappings":";;;AAAA,kDAA4E;AAC5E,wBAA4B;AAE5B,MAAM,YAAY,GAAG,8BAA8B,CAAC;AACpD,MAAM,oBAAoB,GAAG,yBAAyB,CAAC;AACvD,MAAM,iBAAiB,GAAG,sBAAsB,CAAC;AACjD,MAAM,kBAAkB,GAAG,gBAAgB,CAAC;AAC5C,MAAM,iBAAiB,GAAG,sBAAsB,CAAC;AACjD,MAAM,uBAAuB,GAAG,2BAA2B,CAAC;AAC5D,MAAM,qBAAqB,GAAG,yBAAyB,CAAC;AACxD,MAAM,eAAe,GAAG,oBAAoB,CAAC;AAE7C,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;IACvB,EAAE,CAAC,8BAA8B,EAAE,GAAG,EAAE;QACtC,MAAM,SAAS,GAAG,IAAA,cAAM,EACtB,uBAAC,UAAO,IAAC,OAAO,EAAE,mCA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AAM,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;YAEnD,iBAAS,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;YAE7B,MAAM,CAAC,OAAO,CAAC,CAAC,gBAAgB,EAAE,CAAC;YACnC,MAAM,CAAC,MAAM,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;QAC1C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export * from "./Popover";
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./Popover"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/Popover/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B"}
@@ -23,12 +23,13 @@ export * from "./Modal";
23
23
  export * from "./NumberField";
24
24
  export * from "./Option";
25
25
  export * from "./PasswordField";
26
+ export * from "./Popover";
26
27
  export * from "./Progress";
27
28
  export * from "./Radio";
28
- export * from "./SVG";
29
29
  export * from "./Segment";
30
30
  export * from "./Select";
31
31
  export * from "./Slider";
32
+ export * from "./SVG";
32
33
  export * from "./Table";
33
34
  export * from "./Text";
34
35
  export * from "./TextArea";
@@ -39,12 +39,13 @@ __exportStar(require("./Modal"), exports);
39
39
  __exportStar(require("./NumberField"), exports);
40
40
  __exportStar(require("./Option"), exports);
41
41
  __exportStar(require("./PasswordField"), exports);
42
+ __exportStar(require("./Popover"), exports);
42
43
  __exportStar(require("./Progress"), exports);
43
44
  __exportStar(require("./Radio"), exports);
44
- __exportStar(require("./SVG"), exports);
45
45
  __exportStar(require("./Segment"), exports);
46
46
  __exportStar(require("./Select"), exports);
47
47
  __exportStar(require("./Slider"), exports);
48
+ __exportStar(require("./SVG"), exports);
48
49
  __exportStar(require("./Table"), exports);
49
50
  __exportStar(require("./Text"), exports);
50
51
  __exportStar(require("./TextArea"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,0CAAwB;AACxB,wCAAsB;AACtB,gDAA8B;AAC9B,2CAAyB;AACzB,6CAA2B;AAC3B,8CAA4B;AAC5B,4CAA0B;AAC1B,2CAAyB;AACzB,iDAA+B;AAC/B,iDAA+B;AAC/B,6CAA2B;AAC3B,yCAAuB;AACvB,yCAAuB;AACvB,yCAAuB;AACvB,0CAAwB;AACxB,0CAAwB;AACxB,yCAAuB;AACvB,+CAA6B;AAC7B,yCAAuB;AACvB,qDAAmC;AACnC,0CAAwB;AACxB,gDAA8B;AAC9B,2CAAyB;AACzB,kDAAgC;AAChC,6CAA2B;AAC3B,0CAAwB;AACxB,wCAAsB;AACtB,4CAA0B;AAC1B,2CAAyB;AACzB,2CAAyB;AACzB,0CAAwB;AACxB,yCAAuB;AACvB,6CAA2B;AAC3B,kDAAgC;AAChC,8CAA4B;AAC5B,0CAAwB;AACxB,mDAAiC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,0CAAwB;AACxB,wCAAsB;AACtB,gDAA8B;AAC9B,2CAAyB;AACzB,6CAA2B;AAC3B,8CAA4B;AAC5B,4CAA0B;AAC1B,2CAAyB;AACzB,iDAA+B;AAC/B,iDAA+B;AAC/B,6CAA2B;AAC3B,yCAAuB;AACvB,yCAAuB;AACvB,yCAAuB;AACvB,0CAAwB;AACxB,0CAAwB;AACxB,yCAAuB;AACvB,+CAA6B;AAC7B,yCAAuB;AACvB,qDAAmC;AACnC,0CAAwB;AACxB,gDAA8B;AAC9B,2CAAyB;AACzB,kDAAgC;AAChC,4CAA0B;AAC1B,6CAA2B;AAC3B,0CAAwB;AACxB,4CAA0B;AAC1B,2CAAyB;AACzB,2CAAyB;AACzB,wCAAsB;AACtB,0CAAwB;AACxB,yCAAuB;AACvB,6CAA2B;AAC3B,kDAAgC;AAChC,8CAA4B;AAC5B,0CAAwB;AACxB,mDAAiC"}