design-zystem 1.0.242 → 1.0.244

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
@@ -852,6 +852,7 @@ var StyledButton = import_styled_components9.default.button.withConfig({
852
852
  font-family: 'Open Sans', sans-serif;
853
853
 
854
854
  width: ${(props) => props.width || "fit-content"};
855
+ min-width: fit-content;
855
856
 
856
857
  ${(p) => {
857
858
  const base = getColor(p.variant, colors.blue_700);
@@ -4510,31 +4511,49 @@ var PopoverItem = import_styled_components41.default.div`
4510
4511
  background: #f5f5f5;
4511
4512
  }
4512
4513
  `;
4513
- var Popover = ({ items = [], children }) => {
4514
+ var Popover = ({
4515
+ items = [],
4516
+ children,
4517
+ anchorRef,
4518
+ offsetY = 8
4519
+ }) => {
4514
4520
  const [open, setOpen] = (0, import_react24.useState)(false);
4515
4521
  const ref = (0, import_react24.useRef)(null);
4516
4522
  const menuRef = (0, import_react24.useRef)(null);
4517
- const [menuPosition, setMenuPosition] = (0, import_react24.useState)({ top: 0, left: 0 });
4523
+ const [menuPosition, setMenuPosition] = (0, import_react24.useState)({
4524
+ mode: "default",
4525
+ top: 0,
4526
+ left: 0
4527
+ });
4518
4528
  const updatePosition = (0, import_react24.useCallback)(() => {
4519
4529
  var _a;
4520
- if (!ref.current) {
4521
- return;
4530
+ if (!ref.current) return;
4531
+ if (anchorRef == null ? void 0 : anchorRef.current) {
4532
+ const anchorRect = anchorRef.current.getBoundingClientRect();
4533
+ setMenuPosition({
4534
+ mode: "anchor",
4535
+ bottom: window.innerHeight - anchorRect.top + offsetY,
4536
+ left: anchorRect.left,
4537
+ width: anchorRect.width
4538
+ });
4539
+ } else {
4540
+ const rect = ref.current.getBoundingClientRect();
4541
+ const estimatedMenuHeight = items.length * 42 + 8;
4542
+ const menuHeight = ((_a = menuRef.current) == null ? void 0 : _a.getBoundingClientRect().height) ? menuRef.current.getBoundingClientRect().height : estimatedMenuHeight;
4543
+ const viewportPadding = 8;
4544
+ const spaceBelow = window.innerHeight - rect.bottom;
4545
+ const shouldOpenAbove = spaceBelow < menuHeight + 6;
4546
+ const top = shouldOpenAbove ? rect.top - menuHeight - 6 : rect.bottom + 6;
4547
+ setMenuPosition({
4548
+ mode: "default",
4549
+ top: Math.max(
4550
+ viewportPadding,
4551
+ Math.min(top, window.innerHeight - menuHeight - viewportPadding)
4552
+ ),
4553
+ left: rect.right
4554
+ });
4522
4555
  }
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]);
4556
+ }, [items.length, anchorRef, offsetY]);
4538
4557
  (0, import_react24.useEffect)(() => {
4539
4558
  const handleClickOutside = (event) => {
4540
4559
  var _a, _b;
@@ -4556,33 +4575,34 @@ var Popover = ({ items = [], children }) => {
4556
4575
  document.removeEventListener("mousedown", handleClickOutside);
4557
4576
  };
4558
4577
  }, [open, updatePosition]);
4578
+ const menuStyle = menuPosition.mode === "anchor" ? {
4579
+ top: "auto",
4580
+ bottom: menuPosition.bottom,
4581
+ left: menuPosition.left,
4582
+ width: menuPosition.width,
4583
+ transform: "none"
4584
+ } : {
4585
+ top: menuPosition.top,
4586
+ bottom: "auto",
4587
+ left: menuPosition.left,
4588
+ transform: "translateX(-100%)"
4589
+ };
4559
4590
  return /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)(PopoverWrapper, { ref, children: [
4560
4591
  /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(PopoverTrigger, { onClick: () => setOpen((o) => !o), children }),
4561
4592
  open && (0, import_react_dom2.createPortal)(
4562
- /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
4563
- PopoverMenu,
4593
+ /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(PopoverMenu, { ref: menuRef, style: menuStyle, children: items.map((item, idx) => /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
4594
+ PopoverItem,
4564
4595
  {
4565
- ref: menuRef,
4566
- style: {
4567
- top: menuPosition.top,
4568
- left: menuPosition.left,
4569
- transform: "translateX(-100%)"
4596
+ isLast: idx === items.length - 1,
4597
+ onClick: () => {
4598
+ setOpen(false);
4599
+ item.action();
4570
4600
  },
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
- ),
4601
+ onMouseDown: (e) => e.preventDefault(),
4602
+ children: item.label
4603
+ },
4604
+ typeof item.label === "string" ? item.label : idx
4605
+ )) }),
4586
4606
  document.body
4587
4607
  )
4588
4608
  ] });
package/dist/index.mjs CHANGED
@@ -758,6 +758,7 @@ var StyledButton = styled9.button.withConfig({
758
758
  font-family: 'Open Sans', sans-serif;
759
759
 
760
760
  width: ${(props) => props.width || "fit-content"};
761
+ min-width: fit-content;
761
762
 
762
763
  ${(p) => {
763
764
  const base = getColor(p.variant, colors.blue_700);
@@ -4396,7 +4397,12 @@ var IconTabs = ({
4396
4397
  };
4397
4398
 
4398
4399
  // src/Components/Popover/Popover.tsx
4399
- import { useState as useState15, useRef as useRef12, useEffect as useEffect13, useCallback as useCallback4 } from "react";
4400
+ import {
4401
+ useState as useState15,
4402
+ useRef as useRef12,
4403
+ useEffect as useEffect13,
4404
+ useCallback as useCallback4
4405
+ } from "react";
4400
4406
  import { createPortal } from "react-dom";
4401
4407
  import styled41 from "styled-components";
4402
4408
  import { jsx as jsx49, jsxs as jsxs24 } from "react/jsx-runtime";
@@ -4431,31 +4437,49 @@ var PopoverItem = styled41.div`
4431
4437
  background: #f5f5f5;
4432
4438
  }
4433
4439
  `;
4434
- var Popover = ({ items = [], children }) => {
4440
+ var Popover = ({
4441
+ items = [],
4442
+ children,
4443
+ anchorRef,
4444
+ offsetY = 8
4445
+ }) => {
4435
4446
  const [open, setOpen] = useState15(false);
4436
4447
  const ref = useRef12(null);
4437
4448
  const menuRef = useRef12(null);
4438
- const [menuPosition, setMenuPosition] = useState15({ top: 0, left: 0 });
4449
+ const [menuPosition, setMenuPosition] = useState15({
4450
+ mode: "default",
4451
+ top: 0,
4452
+ left: 0
4453
+ });
4439
4454
  const updatePosition = useCallback4(() => {
4440
4455
  var _a;
4441
- if (!ref.current) {
4442
- return;
4456
+ if (!ref.current) return;
4457
+ if (anchorRef == null ? void 0 : anchorRef.current) {
4458
+ const anchorRect = anchorRef.current.getBoundingClientRect();
4459
+ setMenuPosition({
4460
+ mode: "anchor",
4461
+ bottom: window.innerHeight - anchorRect.top + offsetY,
4462
+ left: anchorRect.left,
4463
+ width: anchorRect.width
4464
+ });
4465
+ } else {
4466
+ const rect = ref.current.getBoundingClientRect();
4467
+ const estimatedMenuHeight = items.length * 42 + 8;
4468
+ const menuHeight = ((_a = menuRef.current) == null ? void 0 : _a.getBoundingClientRect().height) ? menuRef.current.getBoundingClientRect().height : estimatedMenuHeight;
4469
+ const viewportPadding = 8;
4470
+ const spaceBelow = window.innerHeight - rect.bottom;
4471
+ const shouldOpenAbove = spaceBelow < menuHeight + 6;
4472
+ const top = shouldOpenAbove ? rect.top - menuHeight - 6 : rect.bottom + 6;
4473
+ setMenuPosition({
4474
+ mode: "default",
4475
+ top: Math.max(
4476
+ viewportPadding,
4477
+ Math.min(top, window.innerHeight - menuHeight - viewportPadding)
4478
+ ),
4479
+ left: rect.right
4480
+ });
4443
4481
  }
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]);
4482
+ }, [items.length, anchorRef, offsetY]);
4459
4483
  useEffect13(() => {
4460
4484
  const handleClickOutside = (event) => {
4461
4485
  var _a, _b;
@@ -4477,33 +4501,34 @@ var Popover = ({ items = [], children }) => {
4477
4501
  document.removeEventListener("mousedown", handleClickOutside);
4478
4502
  };
4479
4503
  }, [open, updatePosition]);
4504
+ const menuStyle = menuPosition.mode === "anchor" ? {
4505
+ top: "auto",
4506
+ bottom: menuPosition.bottom,
4507
+ left: menuPosition.left,
4508
+ width: menuPosition.width,
4509
+ transform: "none"
4510
+ } : {
4511
+ top: menuPosition.top,
4512
+ bottom: "auto",
4513
+ left: menuPosition.left,
4514
+ transform: "translateX(-100%)"
4515
+ };
4480
4516
  return /* @__PURE__ */ jsxs24(PopoverWrapper, { ref, children: [
4481
4517
  /* @__PURE__ */ jsx49(PopoverTrigger, { onClick: () => setOpen((o) => !o), children }),
4482
4518
  open && createPortal(
4483
- /* @__PURE__ */ jsx49(
4484
- PopoverMenu,
4519
+ /* @__PURE__ */ jsx49(PopoverMenu, { ref: menuRef, style: menuStyle, children: items.map((item, idx) => /* @__PURE__ */ jsx49(
4520
+ PopoverItem,
4485
4521
  {
4486
- ref: menuRef,
4487
- style: {
4488
- top: menuPosition.top,
4489
- left: menuPosition.left,
4490
- transform: "translateX(-100%)"
4522
+ isLast: idx === items.length - 1,
4523
+ onClick: () => {
4524
+ setOpen(false);
4525
+ item.action();
4491
4526
  },
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
- ),
4527
+ onMouseDown: (e) => e.preventDefault(),
4528
+ children: item.label
4529
+ },
4530
+ typeof item.label === "string" ? item.label : idx
4531
+ )) }),
4507
4532
  document.body
4508
4533
  )
4509
4534
  ] });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "design-zystem",
3
- "version": "1.0.242",
3
+ "version": "1.0.244",
4
4
  "description": "A React design system of importable components",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",