@yakad/ui 1.3.122 → 1.3.125

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.
@@ -1,9 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import "./card.css";
3
- export interface CardProps extends React.HTMLAttributes<HTMLDivElement> {
4
- align?: "start" | "space" | "center" | "end";
5
- blur?: boolean;
3
+ import { BoxProps } from "../boxing";
4
+ export interface CardProps extends BoxProps {
6
5
  level?: "low" | "mid" | "high";
7
- children?: React.ReactNode;
8
6
  }
9
7
  export declare const Card: import("react").ForwardRefExoticComponent<CardProps & import("react").RefAttributes<HTMLDivElement>>;
package/dist/Card/Card.js CHANGED
@@ -16,8 +16,8 @@ import boxingStyles from "../boxing.module.css";
16
16
  import styles from "./Card.module.css";
17
17
  import "./card.css";
18
18
  export const Card = forwardRef(function Card(_a, ref) {
19
- var { align, blur, level, className, children } = _a, restProps = __rest(_a, ["align", "blur", "level", "className", "children"]);
20
- const joinedClassNames = classNames(boxingStyles.flexColumnBox, { [boxingStyles[align]]: align }, { fullWidthLover: true }, styles.card, { [styles.blur]: blur }, {
19
+ var { fullWidth = true, align, blur, level, className, children } = _a, restProps = __rest(_a, ["fullWidth", "align", "blur", "level", "className", "children"]);
20
+ const joinedClassNames = classNames(boxingStyles.flexColumnBox, { [boxingStyles[align]]: align }, { fullWidthLover: fullWidth }, styles.card, { [styles.blur]: blur }, {
21
21
  yakadCardAutoLevel: level === undefined,
22
22
  yakadCardLowLevel: level === "low",
23
23
  yakadCardMidLevel: level === "mid",
@@ -6,7 +6,6 @@
6
6
  background-color: rgb(var(--yakadCardBackgroundColor, 230 224 233));
7
7
  color: rgb(var(--onSurfaceColor, 28 27 31));
8
8
  fill: rgb(var(--onSurfaceColor, 28 27 31));
9
- overflow: hidden;
10
9
  }
11
10
 
12
11
  .card.blur {
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ import { CardProps, OverlayProps } from "..";
3
+ export interface DropdownProps extends CardProps, OverlayProps {
4
+ }
5
+ export declare const Dropdown: import("react").ForwardRefExoticComponent<DropdownProps & import("react").RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,81 @@
1
+ "use client";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
14
+ import { useRef, useState, useEffect, forwardRef, useImperativeHandle, } from "react";
15
+ import classNames from "classnames";
16
+ import { Card, WithInteractions } from "..";
17
+ import styles from "./Dropdown.module.css";
18
+ export const Dropdown = forwardRef(function Dropdown(_a, forwardedRef) {
19
+ var { fullWidth = false, blur, level = "high", triggerRef, onClose, className, style, children } = _a, restProps = __rest(_a, ["fullWidth", "blur", "level", "triggerRef", "onClose", "className", "style", "children"]);
20
+ const fallbackTriggerRef = useRef(null);
21
+ const dropdownRef = useRef(null);
22
+ const placementTargetRef = triggerRef || fallbackTriggerRef;
23
+ // Let the parent access our DOM node
24
+ useImperativeHandle(forwardedRef, () => dropdownRef.current);
25
+ const [arrowPosition, setArrowPosition] = useState({
26
+ top: 0,
27
+ left: 0,
28
+ });
29
+ const [dropdownPosition, setDropdownPosition] = useState({
30
+ top: 0,
31
+ left: 0,
32
+ });
33
+ const [isPlacedAbove, setIsPlacedAbove] = useState(false);
34
+ const [isPlaced, setIsPlaced] = useState(false);
35
+ useEffect(() => {
36
+ if ((placementTargetRef === null || placementTargetRef === void 0 ? void 0 : placementTargetRef.current) && dropdownRef.current) {
37
+ const placementTarget = placementTargetRef.current.getBoundingClientRect();
38
+ const dropdownRect = dropdownRef.current.getBoundingClientRect();
39
+ const padding = 10;
40
+ let dropdownY = placementTarget.bottom + padding;
41
+ let dropdownXPos = placementTarget.left + placementTarget.width / 2;
42
+ let arrowY = dropdownY;
43
+ const arrowX = dropdownXPos;
44
+ // Prevent overflow bottom
45
+ if (dropdownY + dropdownRect.height > window.innerHeight &&
46
+ placementTarget.top > dropdownRect.height) {
47
+ dropdownY = placementTarget.top - padding;
48
+ arrowY = placementTarget.top - padding;
49
+ setIsPlacedAbove(true);
50
+ }
51
+ else
52
+ setIsPlacedAbove(false);
53
+ // Prevent overflow right
54
+ if (dropdownXPos + dropdownRect.width / 2 >
55
+ window.innerWidth - padding) {
56
+ dropdownXPos =
57
+ window.innerWidth - dropdownRect.width / 2 - padding;
58
+ }
59
+ // Prevent overflow left
60
+ if (dropdownXPos - dropdownRect.width / 2 < padding) {
61
+ dropdownXPos = dropdownRect.width / 2 + padding;
62
+ }
63
+ setDropdownPosition({
64
+ top: dropdownY,
65
+ left: dropdownXPos,
66
+ });
67
+ setArrowPosition({
68
+ top: arrowY,
69
+ left: arrowX,
70
+ });
71
+ setIsPlaced(true);
72
+ }
73
+ }, [children, placementTargetRef]);
74
+ return (_jsxs(_Fragment, { children: [!triggerRef && _jsx("div", { ref: fallbackTriggerRef }), _jsx(WithInteractions, { onOutsideClick: onClose, children: _jsx(Card, Object.assign({ ref: dropdownRef, fullWidth: fullWidth, blur: blur, level: level }, restProps, { className: classNames(styles.dropdownCard, { [styles.isPlacedAbove]: isPlacedAbove }, className), style: Object.assign({ top: dropdownPosition.top, left: dropdownPosition.left, visibility: isPlaced ? "visible" : "hidden" }, style), children: children })) }), _jsx("span", { className: classNames(styles.arrow, {
75
+ [styles.isPlacedAbove]: isPlacedAbove,
76
+ }, { [styles.blur]: blur }), style: {
77
+ top: arrowPosition.top,
78
+ left: arrowPosition.left,
79
+ visibility: isPlaced ? "visible" : "hidden",
80
+ } })] }));
81
+ });
@@ -0,0 +1,39 @@
1
+ .dropdownCard {
2
+ position: fixed;
3
+ min-width: 6rem;
4
+ min-height: 10rem;
5
+ max-width: calc(100vw - 10rem);
6
+ max-height: min(50vh, 40rem);
7
+ transform: translate(-50%, 1rem);
8
+ overflow-x: auto;
9
+ visibility: hidden;
10
+ z-index: 4;
11
+ }
12
+ .dropdownCard.isPlacedAbove {
13
+ transform: translate(-50%, calc(-100% - 1rem));
14
+ }
15
+
16
+ /* Arrow */
17
+ .arrow {
18
+ position: fixed;
19
+ width: 0;
20
+ height: 0;
21
+ border-left: 0.8rem solid transparent;
22
+ border-right: 0.8rem solid transparent;
23
+ border-bottom: 1rem solid
24
+ rgb(var(--surfaceContainerHighestColor, 230 224 233));
25
+ transform: translate(-50%, calc(-100% + 1rem));
26
+ visibility: hidden;
27
+ z-index: 4;
28
+ }
29
+ .arrow.isPlacedAbove {
30
+ transform: translate(-50%, -1rem) rotate(180deg);
31
+ }
32
+ .arrow.blur {
33
+ border-bottom: 1rem solid
34
+ color-mix(
35
+ in srgb,
36
+ rgb(var(--surfaceContainerHighestColor, 230 224 233)) 85%,
37
+ transparent
38
+ );
39
+ }
@@ -1,9 +1,8 @@
1
1
  /// <reference types="react" />
2
- import { CardProps } from "..";
3
- export interface PopupProps extends CardProps {
2
+ import { CardProps, OverlayProps } from "..";
3
+ export interface PopupProps extends CardProps, OverlayProps {
4
4
  align?: "start" | "space" | "center" | "end";
5
5
  heading?: string;
6
- onClose?: () => void;
7
6
  children?: React.ReactNode;
8
7
  }
9
8
  export declare const Popup: import("react").ForwardRefExoticComponent<PopupProps & import("react").RefAttributes<HTMLDivElement>>;
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  var __rest = (this && this.__rest) || function (s, e) {
2
3
  var t = {};
3
4
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
@@ -13,9 +14,9 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
14
  import { forwardRef } from "react";
14
15
  import classNames from "classnames";
15
16
  import { Symbol } from "@yakad/symbols";
16
- import { Button, Card, Row, Spacer, Stack, Text, WithInteractions, } from "..";
17
+ import { Button, Card, Row, Screen, Spacer, Stack, Text, WithInteractions, } from "..";
17
18
  import styles from "./Popup.module.css";
18
19
  export const Popup = forwardRef(function Popup(_a, ref) {
19
20
  var { align, heading, onClose, className, children } = _a, restProps = __rest(_a, ["align", "heading", "onClose", "className", "children"]);
20
- return (_jsx("div", { className: styles.popupscreen, children: _jsx(WithInteractions, { onOutsideClick: onClose, children: _jsxs(Card, Object.assign({ ref: ref }, restProps, { className: classNames(styles.popup, className), children: [_jsxs(Row, { style: { marginBottom: "2rem" }, children: [_jsx(Text, { variant: "heading4", children: heading }), _jsx(Spacer, {}), _jsx(Button, { title: "Close", icon: _jsx(Symbol, { icon: "close" }), onClick: onClose })] }), _jsx(Stack, { align: align, style: { width: "100%", overflowY: "auto" }, children: children })] })) }) }));
21
+ return (_jsx(Screen, { align: "center", className: styles.popupscreen, children: _jsx(WithInteractions, { onOutsideClick: onClose, children: _jsxs(Card, Object.assign({ ref: ref }, restProps, { className: classNames(styles.popup, className), children: [_jsxs(Row, { style: { marginBottom: "2rem" }, children: [_jsx(Text, { variant: "heading4", children: heading }), _jsx(Spacer, {}), _jsx(Button, { title: "Close", icon: _jsx(Symbol, { icon: "close" }), onClick: onClose })] }), _jsx(Stack, { align: align, style: { width: "100%", overflowY: "auto" }, children: children })] })) }) }));
21
22
  });
@@ -2,14 +2,9 @@
2
2
  position: fixed;
3
3
  top: 0;
4
4
  left: 0;
5
- right: 0;
6
- bottom: 0;
7
- display: flex;
8
- justify-content: center;
9
- align-items: center;
10
5
  background-color: rgba(var(--surfaceContainerColor, 243 237 247), 0.2);
11
6
  backdrop-filter: blur(0.2rem);
12
- z-index: 3;
7
+ z-index: 4;
13
8
  }
14
9
 
15
10
  .popup {
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ import { BoxProps } from "../boxing";
3
+ export interface RenderOnVisibleProps extends BoxProps {
4
+ }
5
+ export declare const RenderOnVisible: import("react").ForwardRefExoticComponent<RenderOnVisibleProps & import("react").RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,37 @@
1
+ "use client";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ import { jsx as _jsx } from "react/jsx-runtime";
14
+ import { forwardRef, useImperativeHandle, useRef, useState } from "react";
15
+ import classNames from "classnames";
16
+ import boxingStyles from "../boxing.module.css";
17
+ import styles from "./RenderOnVisible.module.css";
18
+ import { WithInteractions } from "../WithInteractions/WithInteractions";
19
+ export const RenderOnVisible = forwardRef(function RenderOnVisible(_a, forwardedRef) {
20
+ var { align, blur, fullWidth, className, style, children } = _a, restProps = __rest(_a, ["align", "blur", "fullWidth", "className", "style", "children"]);
21
+ const localRef = useRef(null);
22
+ // Let the parent access our DOM node
23
+ useImperativeHandle(forwardedRef, () => localRef.current);
24
+ const [boxHeight, setBoxHeight] = useState(0);
25
+ const isVisible = boxHeight === 0;
26
+ const handleOnVisible = () => {
27
+ setBoxHeight(0);
28
+ };
29
+ const handleOnHidden = () => {
30
+ if (localRef.current) {
31
+ const boxRect = localRef.current.getBoundingClientRect();
32
+ setBoxHeight(boxRect.height);
33
+ }
34
+ };
35
+ const joinedClassNames = classNames(boxingStyles.flexColumnBox, { [boxingStyles[align]]: align }, { fullWidthLover: fullWidth }, { [styles.blur]: blur }, className);
36
+ return (_jsx(WithInteractions, { onVisible: handleOnVisible, onHidden: handleOnHidden, children: _jsx("div", Object.assign({ ref: localRef }, restProps, { className: joinedClassNames, style: Object.assign({ height: boxHeight || "auto" }, style), children: isVisible && children })) }));
37
+ });
@@ -0,0 +1,3 @@
1
+ .blur {
2
+ backdrop-filter: blur(0.5rem);
3
+ }
@@ -1,5 +1,7 @@
1
1
  .dropdawnCard {
2
2
  position: fixed;
3
+ min-width: 6rem;
4
+ min-height: 10rem;
3
5
  max-width: calc(100% - 4rem);
4
6
  max-height: min(50vh, 50rem);
5
7
  padding: 2rem;
@@ -14,7 +14,7 @@ export interface WithInteractionsProps {
14
14
  onScrollStart?: () => void;
15
15
  onScrollStop?: () => void;
16
16
  onResize?: (entry: ResizeObserverEntry) => void;
17
- onVisibile?: () => void;
17
+ onVisible?: () => void;
18
18
  onHidden?: () => void;
19
19
  onMouseHoverStart?: (e: MouseEvent) => void;
20
20
  onMouseHoverLeave?: (e: MouseEvent) => void;
@@ -14,7 +14,7 @@ import { mergeRefs } from "@yakad/lib";
14
14
  import { cloneElement, forwardRef, isValidElement, useEffect, useImperativeHandle, useRef, } from "react";
15
15
  export const WithInteractions = forwardRef(function WithInteractions(_a, forwardedRef) {
16
16
  var _b;
17
- var { children, onRightClick, onTap, onDoubleTap, onOutsideClick, onSwipeLeft, onSwipeRight, onSwipeUp, onSwipeDown, onPinchIn, onPinchOut, onRotate, onScrollStart, onScrollStop, onResize, onVisibile, onHidden, onMouseHoverStart, onMouseHoverLeave } = _a, restProps = __rest(_a, ["children", "onRightClick", "onTap", "onDoubleTap", "onOutsideClick", "onSwipeLeft", "onSwipeRight", "onSwipeUp", "onSwipeDown", "onPinchIn", "onPinchOut", "onRotate", "onScrollStart", "onScrollStop", "onResize", "onVisibile", "onHidden", "onMouseHoverStart", "onMouseHoverLeave"]);
17
+ var { children, onRightClick, onTap, onDoubleTap, onOutsideClick, onSwipeLeft, onSwipeRight, onSwipeUp, onSwipeDown, onPinchIn, onPinchOut, onRotate, onScrollStart, onScrollStop, onResize, onVisible, onHidden, onMouseHoverStart, onMouseHoverLeave } = _a, restProps = __rest(_a, ["children", "onRightClick", "onTap", "onDoubleTap", "onOutsideClick", "onSwipeLeft", "onSwipeRight", "onSwipeUp", "onSwipeDown", "onPinchIn", "onPinchOut", "onRotate", "onScrollStart", "onScrollStop", "onResize", "onVisible", "onHidden", "onMouseHoverStart", "onMouseHoverLeave"]);
18
18
  const localRef = useRef(null);
19
19
  // Let the parent access our DOM node
20
20
  useImperativeHandle(forwardedRef, () => localRef.current);
@@ -151,9 +151,9 @@ export const WithInteractions = forwardRef(function WithInteractions(_a, forward
151
151
  }
152
152
  // === VISIBILITY OBSERVER ===
153
153
  let intersectionObserver = null;
154
- if (onVisibile || onHidden) {
154
+ if (onVisible || onHidden) {
155
155
  intersectionObserver = new IntersectionObserver((entries) => {
156
- entries[0].isIntersecting ? onVisibile === null || onVisibile === void 0 ? void 0 : onVisibile() : onHidden === null || onHidden === void 0 ? void 0 : onHidden();
156
+ entries[0].isIntersecting ? onVisible === null || onVisible === void 0 ? void 0 : onVisible() : onHidden === null || onHidden === void 0 ? void 0 : onHidden();
157
157
  });
158
158
  intersectionObserver.observe(el);
159
159
  cleanupFns.push(() => intersectionObserver === null || intersectionObserver === void 0 ? void 0 : intersectionObserver.disconnect());
@@ -207,7 +207,7 @@ export const WithInteractions = forwardRef(function WithInteractions(_a, forward
207
207
  onScrollStart,
208
208
  onScrollStop,
209
209
  onResize,
210
- onVisibile,
210
+ onVisible,
211
211
  onHidden,
212
212
  onMouseHoverStart,
213
213
  onMouseHoverLeave,
@@ -1,11 +1,16 @@
1
- /// <reference types="react" />
2
- export interface WithPopupProps {
1
+ import { RefObject } from "react";
2
+ import { Dropdown, DropdownProps, Popup, PopupProps } from "..";
3
+ export interface OverlayProps {
4
+ triggerRef?: RefObject<HTMLElement | null>;
5
+ onClose?: () => void;
6
+ }
7
+ type AllowedOverlays = React.ReactElement<PopupProps, typeof Popup> | React.ReactElement<DropdownProps, typeof Dropdown>;
8
+ export interface WithOverlayProps {
3
9
  trigger?: "onClick" | "onRightClick";
4
- overlay?: React.ReactElement<{
5
- onClose?: () => void;
6
- }>;
10
+ overlay?: AllowedOverlays;
7
11
  children?: React.ReactElement<{
8
12
  onClick?: (e: React.MouseEvent<HTMLElement>) => void;
9
13
  }>;
10
14
  }
11
- export declare function WithOverlay({ trigger, overlay, children, }: WithPopupProps): import("react/jsx-runtime").JSX.Element;
15
+ export declare function WithOverlay({ trigger, overlay, children, }: WithOverlayProps): import("react/jsx-runtime").JSX.Element;
16
+ export {};
@@ -1,11 +1,24 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useState, cloneElement } from "react";
4
- import { WithInteractions } from "..";
3
+ import { useState, cloneElement, useEffect, useRef } from "react";
4
+ import { WithInteractions, } from "..";
5
+ import { mergeRefs } from "@yakad/lib";
5
6
  export function WithOverlay({ trigger = "onClick", overlay, children, }) {
7
+ var _a;
8
+ const triggerRef = useRef(null);
6
9
  const [showOverlay, setShowOverlay] = useState(false);
10
+ useEffect(() => {
11
+ document.body.style.overflow = showOverlay ? "hidden" : "initial";
12
+ return () => {
13
+ document.body.style.overflow = "initial";
14
+ };
15
+ }, [showOverlay]);
7
16
  return (_jsxs(_Fragment, { children: [_jsx(WithInteractions, { onRightClick: () => trigger === "onRightClick" && setShowOverlay(true), children: children &&
17
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
18
  cloneElement(children, {
19
+ ref: mergeRefs(triggerRef,
20
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
+ (_a = children.props) === null || _a === void 0 ? void 0 : _a.ref),
9
22
  onClick: (e) => {
10
23
  var _a, _b;
11
24
  (_b = (_a = children.props).onClick) === null || _b === void 0 ? void 0 : _b.call(_a, e);
@@ -14,6 +27,7 @@ export function WithOverlay({ trigger = "onClick", overlay, children, }) {
14
27
  }) }), showOverlay &&
15
28
  overlay &&
16
29
  cloneElement(overlay, {
30
+ triggerRef: triggerRef,
17
31
  onClose: () => {
18
32
  var _a, _b;
19
33
  (_b = (_a = overlay.props).onClose) === null || _b === void 0 ? void 0 : _b.call(_a);
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ export interface BoxProps extends React.HTMLAttributes<HTMLDivElement> {
3
+ align?: "start" | "space" | "center" | "end";
4
+ blur?: boolean;
5
+ fullWidth?: boolean;
6
+ children?: React.ReactNode;
7
+ }
package/dist/boxing.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.d.ts CHANGED
@@ -12,6 +12,7 @@ export * from "./Card/Card";
12
12
  export * from "./Theme/Theme";
13
13
  export * from "./Spacer/Spacer";
14
14
  export * from "./Hr/Hr";
15
+ export * from "./Dropdown/Dropdown";
15
16
  export * from "./Popup/Popup";
16
17
  export * from "./List/List";
17
18
  export * from "./ListItem/ListItem";
@@ -32,3 +33,4 @@ export * from "./Display/Display";
32
33
  export * from "./WithInteractions/WithInteractions";
33
34
  export * from "./WithDropdawn/WithDropdawn";
34
35
  export * from "./WithOverlay/WithOverlay";
36
+ export * from "./RenderOnVisible/RenderOnVisible";
package/dist/index.js CHANGED
@@ -15,6 +15,7 @@ export * from "./Theme/Theme";
15
15
  export * from "./Spacer/Spacer";
16
16
  export * from "./Hr/Hr";
17
17
  // UI Components
18
+ export * from "./Dropdown/Dropdown";
18
19
  export * from "./Popup/Popup";
19
20
  export * from "./List/List";
20
21
  export * from "./ListItem/ListItem";
@@ -37,3 +38,4 @@ export * from "./Display/Display";
37
38
  export * from "./WithInteractions/WithInteractions";
38
39
  export * from "./WithDropdawn/WithDropdawn";
39
40
  export * from "./WithOverlay/WithOverlay";
41
+ export * from "./RenderOnVisible/RenderOnVisible";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yakad/ui",
3
- "version": "1.3.122",
3
+ "version": "1.3.125",
4
4
  "private": false,
5
5
  "author": "Natiq",
6
6
  "description": "UI components for NextJS/React",