design-zystem 1.0.242 → 1.0.243

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.
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as react from 'react';
3
- import { HTMLAttributes, ReactNode, CSSProperties, MouseEventHandler, MouseEvent, ChangeEvent, FocusEvent, KeyboardEvent, ImgHTMLAttributes } from 'react';
3
+ import { HTMLAttributes, ReactNode, CSSProperties, MouseEventHandler, MouseEvent, ChangeEvent, FocusEvent, KeyboardEvent, ImgHTMLAttributes, RefObject } from 'react';
4
4
 
5
5
  interface PageContainerProps extends HTMLAttributes<HTMLDivElement> {
6
6
  justifyContent?: string;
@@ -806,8 +806,10 @@ interface PopoverItem {
806
806
  interface PopoverProps {
807
807
  items?: PopoverItem[];
808
808
  children?: ReactNode;
809
+ anchorRef?: RefObject<HTMLElement>;
810
+ offsetY?: number;
809
811
  }
810
- declare const Popover: ({ items, children }: PopoverProps) => react_jsx_runtime.JSX.Element;
812
+ declare const Popover: ({ items, children, anchorRef, offsetY, }: PopoverProps) => react_jsx_runtime.JSX.Element;
811
813
 
812
814
  interface MetricCardProps {
813
815
  icon: string;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as react from 'react';
3
- import { HTMLAttributes, ReactNode, CSSProperties, MouseEventHandler, MouseEvent, ChangeEvent, FocusEvent, KeyboardEvent, ImgHTMLAttributes } from 'react';
3
+ import { HTMLAttributes, ReactNode, CSSProperties, MouseEventHandler, MouseEvent, ChangeEvent, FocusEvent, KeyboardEvent, ImgHTMLAttributes, RefObject } from 'react';
4
4
 
5
5
  interface PageContainerProps extends HTMLAttributes<HTMLDivElement> {
6
6
  justifyContent?: string;
@@ -806,8 +806,10 @@ interface PopoverItem {
806
806
  interface PopoverProps {
807
807
  items?: PopoverItem[];
808
808
  children?: ReactNode;
809
+ anchorRef?: RefObject<HTMLElement>;
810
+ offsetY?: number;
809
811
  }
810
- declare const Popover: ({ items, children }: PopoverProps) => react_jsx_runtime.JSX.Element;
812
+ declare const Popover: ({ items, children, anchorRef, offsetY, }: PopoverProps) => react_jsx_runtime.JSX.Element;
811
813
 
812
814
  interface MetricCardProps {
813
815
  icon: string;
package/dist/index.js CHANGED
@@ -4510,31 +4510,49 @@ var PopoverItem = import_styled_components41.default.div`
4510
4510
  background: #f5f5f5;
4511
4511
  }
4512
4512
  `;
4513
- var Popover = ({ items = [], children }) => {
4513
+ var Popover = ({
4514
+ items = [],
4515
+ children,
4516
+ anchorRef,
4517
+ offsetY = 8
4518
+ }) => {
4514
4519
  const [open, setOpen] = (0, import_react24.useState)(false);
4515
4520
  const ref = (0, import_react24.useRef)(null);
4516
4521
  const menuRef = (0, import_react24.useRef)(null);
4517
- const [menuPosition, setMenuPosition] = (0, import_react24.useState)({ top: 0, left: 0 });
4522
+ const [menuPosition, setMenuPosition] = (0, import_react24.useState)({
4523
+ mode: "default",
4524
+ top: 0,
4525
+ left: 0
4526
+ });
4518
4527
  const updatePosition = (0, import_react24.useCallback)(() => {
4519
4528
  var _a;
4520
- if (!ref.current) {
4521
- return;
4529
+ if (!ref.current) return;
4530
+ if (anchorRef == null ? void 0 : anchorRef.current) {
4531
+ const anchorRect = anchorRef.current.getBoundingClientRect();
4532
+ setMenuPosition({
4533
+ mode: "anchor",
4534
+ bottom: window.innerHeight - anchorRect.top + offsetY,
4535
+ left: anchorRect.left,
4536
+ width: anchorRect.width
4537
+ });
4538
+ } else {
4539
+ const rect = ref.current.getBoundingClientRect();
4540
+ const estimatedMenuHeight = items.length * 42 + 8;
4541
+ const menuHeight = ((_a = menuRef.current) == null ? void 0 : _a.getBoundingClientRect().height) ? menuRef.current.getBoundingClientRect().height : estimatedMenuHeight;
4542
+ const viewportPadding = 8;
4543
+ const spaceBelow = window.innerHeight - rect.bottom;
4544
+ const shouldOpenAbove = spaceBelow < menuHeight + 6;
4545
+ const top = shouldOpenAbove ? rect.top - menuHeight - 6 : rect.bottom + 6;
4546
+ setMenuPosition({
4547
+ mode: "default",
4548
+ top: Math.max(
4549
+ viewportPadding,
4550
+ Math.min(top, window.innerHeight - menuHeight - viewportPadding)
4551
+ ),
4552
+ left: rect.right
4553
+ });
4522
4554
  }
4523
- const rect = ref.current.getBoundingClientRect();
4524
- const estimatedMenuHeight = items.length * 42 + 8;
4525
- const menuHeight = ((_a = menuRef.current) == null ? void 0 : _a.getBoundingClientRect().height) ? menuRef.current.getBoundingClientRect().height : estimatedMenuHeight;
4526
- const viewportPadding = 8;
4527
- const spaceBelow = window.innerHeight - rect.bottom;
4528
- const shouldOpenAbove = spaceBelow < menuHeight + 6;
4529
- const top = shouldOpenAbove ? rect.top - menuHeight - 6 : rect.bottom + 6;
4530
- setMenuPosition({
4531
- top: Math.max(
4532
- viewportPadding,
4533
- Math.min(top, window.innerHeight - menuHeight - viewportPadding)
4534
- ),
4535
- left: rect.right
4536
- });
4537
- }, [items.length]);
4555
+ }, [items.length, anchorRef, offsetY]);
4538
4556
  (0, import_react24.useEffect)(() => {
4539
4557
  const handleClickOutside = (event) => {
4540
4558
  var _a, _b;
@@ -4556,33 +4574,34 @@ var Popover = ({ items = [], children }) => {
4556
4574
  document.removeEventListener("mousedown", handleClickOutside);
4557
4575
  };
4558
4576
  }, [open, updatePosition]);
4577
+ const menuStyle = menuPosition.mode === "anchor" ? {
4578
+ top: "auto",
4579
+ bottom: menuPosition.bottom,
4580
+ left: menuPosition.left,
4581
+ width: menuPosition.width,
4582
+ transform: "none"
4583
+ } : {
4584
+ top: menuPosition.top,
4585
+ bottom: "auto",
4586
+ left: menuPosition.left,
4587
+ transform: "translateX(-100%)"
4588
+ };
4559
4589
  return /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)(PopoverWrapper, { ref, children: [
4560
4590
  /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(PopoverTrigger, { onClick: () => setOpen((o) => !o), children }),
4561
4591
  open && (0, import_react_dom2.createPortal)(
4562
- /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
4563
- PopoverMenu,
4592
+ /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(PopoverMenu, { ref: menuRef, style: menuStyle, children: items.map((item, idx) => /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
4593
+ PopoverItem,
4564
4594
  {
4565
- ref: menuRef,
4566
- style: {
4567
- top: menuPosition.top,
4568
- left: menuPosition.left,
4569
- transform: "translateX(-100%)"
4595
+ isLast: idx === items.length - 1,
4596
+ onClick: () => {
4597
+ setOpen(false);
4598
+ item.action();
4570
4599
  },
4571
- children: items.map((item, idx) => /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
4572
- PopoverItem,
4573
- {
4574
- isLast: idx === items.length - 1,
4575
- onClick: () => {
4576
- setOpen(false);
4577
- item.action();
4578
- },
4579
- onMouseDown: (e) => e.preventDefault(),
4580
- children: item.label
4581
- },
4582
- typeof item.label === "string" ? item.label : idx
4583
- ))
4584
- }
4585
- ),
4600
+ onMouseDown: (e) => e.preventDefault(),
4601
+ children: item.label
4602
+ },
4603
+ typeof item.label === "string" ? item.label : idx
4604
+ )) }),
4586
4605
  document.body
4587
4606
  )
4588
4607
  ] });
package/dist/index.mjs CHANGED
@@ -4396,7 +4396,12 @@ var IconTabs = ({
4396
4396
  };
4397
4397
 
4398
4398
  // src/Components/Popover/Popover.tsx
4399
- import { useState as useState15, useRef as useRef12, useEffect as useEffect13, useCallback as useCallback4 } from "react";
4399
+ import {
4400
+ useState as useState15,
4401
+ useRef as useRef12,
4402
+ useEffect as useEffect13,
4403
+ useCallback as useCallback4
4404
+ } from "react";
4400
4405
  import { createPortal } from "react-dom";
4401
4406
  import styled41 from "styled-components";
4402
4407
  import { jsx as jsx49, jsxs as jsxs24 } from "react/jsx-runtime";
@@ -4431,31 +4436,49 @@ var PopoverItem = styled41.div`
4431
4436
  background: #f5f5f5;
4432
4437
  }
4433
4438
  `;
4434
- var Popover = ({ items = [], children }) => {
4439
+ var Popover = ({
4440
+ items = [],
4441
+ children,
4442
+ anchorRef,
4443
+ offsetY = 8
4444
+ }) => {
4435
4445
  const [open, setOpen] = useState15(false);
4436
4446
  const ref = useRef12(null);
4437
4447
  const menuRef = useRef12(null);
4438
- const [menuPosition, setMenuPosition] = useState15({ top: 0, left: 0 });
4448
+ const [menuPosition, setMenuPosition] = useState15({
4449
+ mode: "default",
4450
+ top: 0,
4451
+ left: 0
4452
+ });
4439
4453
  const updatePosition = useCallback4(() => {
4440
4454
  var _a;
4441
- if (!ref.current) {
4442
- return;
4455
+ if (!ref.current) return;
4456
+ if (anchorRef == null ? void 0 : anchorRef.current) {
4457
+ const anchorRect = anchorRef.current.getBoundingClientRect();
4458
+ setMenuPosition({
4459
+ mode: "anchor",
4460
+ bottom: window.innerHeight - anchorRect.top + offsetY,
4461
+ left: anchorRect.left,
4462
+ width: anchorRect.width
4463
+ });
4464
+ } else {
4465
+ const rect = ref.current.getBoundingClientRect();
4466
+ const estimatedMenuHeight = items.length * 42 + 8;
4467
+ const menuHeight = ((_a = menuRef.current) == null ? void 0 : _a.getBoundingClientRect().height) ? menuRef.current.getBoundingClientRect().height : estimatedMenuHeight;
4468
+ const viewportPadding = 8;
4469
+ const spaceBelow = window.innerHeight - rect.bottom;
4470
+ const shouldOpenAbove = spaceBelow < menuHeight + 6;
4471
+ const top = shouldOpenAbove ? rect.top - menuHeight - 6 : rect.bottom + 6;
4472
+ setMenuPosition({
4473
+ mode: "default",
4474
+ top: Math.max(
4475
+ viewportPadding,
4476
+ Math.min(top, window.innerHeight - menuHeight - viewportPadding)
4477
+ ),
4478
+ left: rect.right
4479
+ });
4443
4480
  }
4444
- const rect = ref.current.getBoundingClientRect();
4445
- const estimatedMenuHeight = items.length * 42 + 8;
4446
- const menuHeight = ((_a = menuRef.current) == null ? void 0 : _a.getBoundingClientRect().height) ? menuRef.current.getBoundingClientRect().height : estimatedMenuHeight;
4447
- const viewportPadding = 8;
4448
- const spaceBelow = window.innerHeight - rect.bottom;
4449
- const shouldOpenAbove = spaceBelow < menuHeight + 6;
4450
- const top = shouldOpenAbove ? rect.top - menuHeight - 6 : rect.bottom + 6;
4451
- setMenuPosition({
4452
- top: Math.max(
4453
- viewportPadding,
4454
- Math.min(top, window.innerHeight - menuHeight - viewportPadding)
4455
- ),
4456
- left: rect.right
4457
- });
4458
- }, [items.length]);
4481
+ }, [items.length, anchorRef, offsetY]);
4459
4482
  useEffect13(() => {
4460
4483
  const handleClickOutside = (event) => {
4461
4484
  var _a, _b;
@@ -4477,33 +4500,34 @@ var Popover = ({ items = [], children }) => {
4477
4500
  document.removeEventListener("mousedown", handleClickOutside);
4478
4501
  };
4479
4502
  }, [open, updatePosition]);
4503
+ const menuStyle = menuPosition.mode === "anchor" ? {
4504
+ top: "auto",
4505
+ bottom: menuPosition.bottom,
4506
+ left: menuPosition.left,
4507
+ width: menuPosition.width,
4508
+ transform: "none"
4509
+ } : {
4510
+ top: menuPosition.top,
4511
+ bottom: "auto",
4512
+ left: menuPosition.left,
4513
+ transform: "translateX(-100%)"
4514
+ };
4480
4515
  return /* @__PURE__ */ jsxs24(PopoverWrapper, { ref, children: [
4481
4516
  /* @__PURE__ */ jsx49(PopoverTrigger, { onClick: () => setOpen((o) => !o), children }),
4482
4517
  open && createPortal(
4483
- /* @__PURE__ */ jsx49(
4484
- PopoverMenu,
4518
+ /* @__PURE__ */ jsx49(PopoverMenu, { ref: menuRef, style: menuStyle, children: items.map((item, idx) => /* @__PURE__ */ jsx49(
4519
+ PopoverItem,
4485
4520
  {
4486
- ref: menuRef,
4487
- style: {
4488
- top: menuPosition.top,
4489
- left: menuPosition.left,
4490
- transform: "translateX(-100%)"
4521
+ isLast: idx === items.length - 1,
4522
+ onClick: () => {
4523
+ setOpen(false);
4524
+ item.action();
4491
4525
  },
4492
- children: items.map((item, idx) => /* @__PURE__ */ jsx49(
4493
- PopoverItem,
4494
- {
4495
- isLast: idx === items.length - 1,
4496
- onClick: () => {
4497
- setOpen(false);
4498
- item.action();
4499
- },
4500
- onMouseDown: (e) => e.preventDefault(),
4501
- children: item.label
4502
- },
4503
- typeof item.label === "string" ? item.label : idx
4504
- ))
4505
- }
4506
- ),
4526
+ onMouseDown: (e) => e.preventDefault(),
4527
+ children: item.label
4528
+ },
4529
+ typeof item.label === "string" ? item.label : idx
4530
+ )) }),
4507
4531
  document.body
4508
4532
  )
4509
4533
  ] });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "design-zystem",
3
- "version": "1.0.242",
3
+ "version": "1.0.243",
4
4
  "description": "A React design system of importable components",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",