@yakad/ui 1.3.108 → 1.3.110

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.
@@ -6,6 +6,7 @@
6
6
  background: rgb(var(--surfaceContainerHighestColor, 230 224 233));
7
7
  color: rgb(var(--onSurfaceColor, 28 27 31));
8
8
  fill: rgb(var(--onSurfaceColor, 28 27 31));
9
+ overflow: hidden;
9
10
  }
10
11
 
11
12
  .card.blur {
@@ -1,6 +1,7 @@
1
1
  /// <reference types="react" />
2
- import { CardProps } from "../";
3
- export interface WithDropdawnProps extends CardProps {
2
+ export interface WithDropdawnProps extends React.HTMLAttributes<HTMLDivElement> {
3
+ align?: "start" | "center" | "end";
4
+ blur?: boolean;
4
5
  trigger?: "onClick" | "onRightClick";
5
6
  dropdawnChildren?: React.ReactElement;
6
7
  children?: React.ReactElement<{
@@ -8,6 +9,6 @@ export interface WithDropdawnProps extends CardProps {
8
9
  }>;
9
10
  }
10
11
  export declare const WithDropdawn: {
11
- ({ trigger, dropdawnChildren, style, children, ...restProps }: WithDropdawnProps): import("react/jsx-runtime").JSX.Element;
12
+ ({ align, blur, trigger, dropdawnChildren, className, style, children, ...restProps }: WithDropdawnProps): import("react/jsx-runtime").JSX.Element;
12
13
  displayName: string;
13
14
  };
@@ -12,38 +12,54 @@ var __rest = (this && this.__rest) || function (s, e) {
12
12
  };
13
13
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
14
14
  import { useRef, useState, useEffect, cloneElement } from "react";
15
- import { Card, WithInteractions } from "../";
15
+ import classNames from "classnames";
16
+ import { WithInteractions } from "../";
17
+ import boxingStyles from "../boxing.module.css";
18
+ import styles from "./WithDropdawn.module.css";
16
19
  export const WithDropdawn = (_a) => {
17
- var { trigger = "onClick", dropdawnChildren, style, children } = _a, restProps = __rest(_a, ["trigger", "dropdawnChildren", "style", "children"]);
20
+ var { align, blur, trigger = "onClick", dropdawnChildren, className, style, children } = _a, restProps = __rest(_a, ["align", "blur", "trigger", "dropdawnChildren", "className", "style", "children"]);
18
21
  const toggleElementRef = useRef(null);
19
22
  const dropdawnRef = useRef(null);
20
23
  const [showDropdawn, setShowDropdawn] = useState(false);
24
+ const [dropdawnOnTop, setDropdawnOnTop] = useState(false);
21
25
  const [top, setTop] = useState(0);
22
- const [left, setLeft] = useState(0);
26
+ const [dropdawnX, setDropdawnX] = useState(0);
27
+ const [arrowTop, setArrowTop] = useState(0);
28
+ const [arrowX, setArrowX] = useState(0);
23
29
  const toggleShowDropdawn = () => setShowDropdawn((prev) => !prev);
24
30
  useEffect(() => {
25
31
  if (toggleElementRef.current && dropdawnRef.current) {
26
32
  const buttonRect = toggleElementRef.current.getBoundingClientRect();
27
33
  const dropdawnRect = dropdawnRef.current.getBoundingClientRect();
28
34
  const padding = 10;
29
- let top = buttonRect.bottom + padding;
30
- let left = buttonRect.left + buttonRect.width / 2 - dropdawnRect.width / 2;
35
+ let dTop = buttonRect.bottom + padding;
36
+ let dX = buttonRect.x + buttonRect.width / 2;
37
+ let aTop = top;
38
+ let aX = dX;
31
39
  // Prevent overflow bottom
32
- if (top + dropdawnRect.height > window.innerHeight) {
33
- top = buttonRect.top - dropdawnRect.height - padding;
40
+ if (dTop + dropdawnRect.height > window.innerHeight) {
41
+ dTop = buttonRect.top - dropdawnRect.height - padding;
42
+ aTop = buttonRect.top - padding;
43
+ setDropdawnOnTop(true);
34
44
  }
45
+ else
46
+ setDropdawnOnTop(false);
35
47
  // Prevent overflow right
36
- if (left + dropdawnRect.width > window.innerWidth - padding) {
37
- left = window.innerWidth - dropdawnRect.width - padding;
48
+ if (dX + dropdawnRect.width / 2 > window.innerWidth - padding) {
49
+ dX = window.innerWidth - dropdawnRect.width / 2 - padding;
38
50
  }
39
51
  // Prevent overflow left
40
- if (left < padding) {
41
- left = padding;
52
+ if (dX - dropdawnRect.width / 2 < padding) {
53
+ dX = dropdawnRect.width / 2 + padding;
42
54
  }
43
- setTop(top);
44
- setLeft(left);
55
+ setTop(dTop);
56
+ setDropdawnX(dX);
57
+ // Arrow Placing
58
+ setArrowTop(aTop);
59
+ setArrowX(aX);
45
60
  }
46
61
  }, [showDropdawn, dropdawnChildren]);
62
+ const joinedClassNames = classNames(boxingStyles.flexColumnBox, { [boxingStyles[align]]: align }, styles.dropdawnCard, { [styles.blur]: blur }, className);
47
63
  return (_jsxs(_Fragment, { children: [_jsx(WithInteractions, { ref: toggleElementRef, onRightClick: () => trigger === "onRightClick" && setShowDropdawn(true), children: children &&
48
64
  cloneElement(children, {
49
65
  onClick: (e) => {
@@ -51,6 +67,12 @@ export const WithDropdawn = (_a) => {
51
67
  (_b = (_a = children.props).onClick) === null || _b === void 0 ? void 0 : _b.call(_a, e);
52
68
  trigger === "onClick" && toggleShowDropdawn();
53
69
  },
54
- }) }), _jsx(WithInteractions, { onOutsideClick: () => setShowDropdawn(false), children: _jsx(Card, Object.assign({ ref: dropdawnRef }, restProps, { style: Object.assign({ position: "fixed", top: top, left: left, maxWidth: "calc(100% - 4rem)", maxHeight: "min(50vh, 50rem)", zIndex: 2, visibility: showDropdawn ? "visible" : "hidden" }, style), children: dropdawnChildren })) })] }));
70
+ }) }), _jsx("span", { className: classNames(styles.arrow, {
71
+ [styles.dropdawnOnTop]: dropdawnOnTop,
72
+ }, { [styles.blur]: blur }), style: {
73
+ top: arrowTop,
74
+ left: arrowX,
75
+ visibility: showDropdawn ? "visible" : "hidden",
76
+ } }), _jsx(WithInteractions, { onOutsideClick: () => setShowDropdawn(false), children: _jsx("div", Object.assign({ ref: dropdawnRef }, restProps, { className: joinedClassNames, style: Object.assign({ top: top, left: dropdawnX, visibility: showDropdawn ? "visible" : "hidden" }, style), children: dropdawnChildren })) })] }));
55
77
  };
56
78
  WithDropdawn.displayName = "WithDropdawn";
@@ -0,0 +1,45 @@
1
+ .dropdawnCard {
2
+ position: fixed;
3
+ max-width: calc(100% - 4rem);
4
+ max-height: min(50vh, 50rem);
5
+ padding: 2rem;
6
+ border-radius: 2rem;
7
+ box-shadow: 0px 3px 3px -2px rgb(0 0 0 / 20%),
8
+ 0px 3px 4px 0px rgb(0 0 0 / 14%), 0px 1px 8px 0px rgb(0 0 0 / 12%);
9
+ background: rgb(var(--surfaceContainerHighestColor, 230 224 233));
10
+ color: rgb(var(--onSurfaceColor, 28 27 31));
11
+ fill: rgb(var(--onSurfaceColor, 28 27 31));
12
+ z-index: 2;
13
+ transform: translate(-50%, 0);
14
+ }
15
+ .dropdawnCard.blur {
16
+ background-color: color-mix(
17
+ in srgb,
18
+ rgb(var(--surfaceContainerHighestColor, 230 224 233)) 85%,
19
+ transparent
20
+ );
21
+ backdrop-filter: blur(0.5rem);
22
+ }
23
+
24
+ /* Arrow */
25
+ .arrow {
26
+ position: fixed;
27
+ width: 0;
28
+ height: 0;
29
+ border-left: 0.6rem solid transparent;
30
+ border-right: 0.6rem solid transparent;
31
+ border-bottom: 0.6rem solid
32
+ rgb(var(--surfaceContainerHighestColor, 230 224 233));
33
+ transform: translate(-50%, -100%);
34
+ }
35
+ .arrow.blur {
36
+ border-bottom: 0.6rem solid
37
+ color-mix(
38
+ in srgb,
39
+ rgb(var(--surfaceContainerHighestColor, 230 224 233)) 85%,
40
+ transparent
41
+ );
42
+ }
43
+ .arrow.dropdawnOnTop {
44
+ transform: translate(-50%, 0) rotate(180deg);
45
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yakad/ui",
3
- "version": "1.3.108",
3
+ "version": "1.3.110",
4
4
  "private": false,
5
5
  "author": "Natiq",
6
6
  "description": "UI components for NextJS/React",