@lets-events/react 12.11.0 → 12.11.2
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/.turbo/turbo-build.log +8 -8
- package/CHANGELOG.md +12 -0
- package/dist/index.d.mts +7 -4
- package/dist/index.d.ts +7 -4
- package/dist/index.js +151 -85
- package/dist/index.mjs +151 -85
- package/package.json +1 -1
- package/src/components/Modal.tsx +7 -2
- package/src/components/MultiSelect/index.tsx +1 -0
- package/src/components/Tooltip/index.tsx +62 -9
- package/src/hooks/useHasHover.ts +21 -0
package/src/components/Modal.tsx
CHANGED
|
@@ -2,8 +2,8 @@ import { ComponentProps } from "react";
|
|
|
2
2
|
import { styled } from "../styles";
|
|
3
3
|
import { Dialog as ModalRadix } from "radix-ui";
|
|
4
4
|
import Icon from "./Icon";
|
|
5
|
-
import { Box } from "./Box";
|
|
6
5
|
import { Text } from "./Text";
|
|
6
|
+
import { typographyValues } from "../types/typographyValues";
|
|
7
7
|
|
|
8
8
|
const ModalContentStyled = styled(ModalRadix.Content, {
|
|
9
9
|
fontFamily: "$default",
|
|
@@ -58,8 +58,11 @@ const ModalTitleStyled = styled(ModalRadix.Title, {
|
|
|
58
58
|
fontWeight: "medium",
|
|
59
59
|
fontStyle: "normal",
|
|
60
60
|
textTransform: "uppercase",
|
|
61
|
+
width: "calc(100% - 48px)",
|
|
61
62
|
});
|
|
62
63
|
|
|
64
|
+
type Typography = keyof typeof typographyValues;
|
|
65
|
+
|
|
63
66
|
export type ModalProps = ComponentProps<typeof ModalRadix.Root> & {
|
|
64
67
|
trigger?: React.ReactNode;
|
|
65
68
|
title?: string;
|
|
@@ -70,6 +73,7 @@ export type ModalProps = ComponentProps<typeof ModalRadix.Root> & {
|
|
|
70
73
|
height?: string;
|
|
71
74
|
preventAutoFocus?: boolean;
|
|
72
75
|
fitContent?: boolean;
|
|
76
|
+
titleTypography?: Typography;
|
|
73
77
|
};
|
|
74
78
|
|
|
75
79
|
export function Modal({
|
|
@@ -82,6 +86,7 @@ export function Modal({
|
|
|
82
86
|
height,
|
|
83
87
|
preventAutoFocus = false,
|
|
84
88
|
fitContent = false,
|
|
89
|
+
titleTypography = "headline6",
|
|
85
90
|
...props
|
|
86
91
|
}: ModalProps) {
|
|
87
92
|
const { onOpenChange } = props;
|
|
@@ -110,7 +115,7 @@ export function Modal({
|
|
|
110
115
|
{title && (
|
|
111
116
|
<ModalHeaderStyled>
|
|
112
117
|
<ModalTitleStyled asChild>
|
|
113
|
-
<Text typography={
|
|
118
|
+
<Text typography={titleTypography} fontWeight={"medium"}>
|
|
114
119
|
{title}
|
|
115
120
|
</Text>
|
|
116
121
|
</ModalTitleStyled>
|
|
@@ -2,6 +2,7 @@ import * as React from "react";
|
|
|
2
2
|
import * as TooltipPrimitive from "@radix-ui/react-tooltip";
|
|
3
3
|
import { styled } from "../../styles";
|
|
4
4
|
import { Text } from "../Text";
|
|
5
|
+
import { useHasHover } from "../../hooks/useHasHover";
|
|
5
6
|
|
|
6
7
|
const TooltipProvider = TooltipPrimitive.Provider;
|
|
7
8
|
const TooltipRoot = TooltipPrimitive.Root;
|
|
@@ -43,6 +44,21 @@ export interface TooltipProps {
|
|
|
43
44
|
content: React.ReactNode;
|
|
44
45
|
delayDuration?: number;
|
|
45
46
|
side?: "top" | "right" | "bottom" | "left";
|
|
47
|
+
supportMobileTap?: boolean;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function mergeTouchTriggerProps(
|
|
51
|
+
child: React.ReactElement<{ onClick?: (event: React.MouseEvent) => void }>,
|
|
52
|
+
onToggle: () => void
|
|
53
|
+
): React.ReactElement {
|
|
54
|
+
return React.cloneElement(child, {
|
|
55
|
+
onClick: (event: React.MouseEvent) => {
|
|
56
|
+
child.props.onClick?.(event);
|
|
57
|
+
if (!event.defaultPrevented) {
|
|
58
|
+
onToggle();
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
});
|
|
46
62
|
}
|
|
47
63
|
|
|
48
64
|
export function Tooltip({
|
|
@@ -50,19 +66,56 @@ export function Tooltip({
|
|
|
50
66
|
content,
|
|
51
67
|
delayDuration = 200,
|
|
52
68
|
side = "top",
|
|
69
|
+
supportMobileTap = true,
|
|
53
70
|
}: TooltipProps) {
|
|
71
|
+
const hasHover = useHasHover();
|
|
72
|
+
const [open, setOpen] = React.useState(false);
|
|
73
|
+
const isTouchToggleRef = React.useRef(false);
|
|
74
|
+
const useTouchBehavior = supportMobileTap && !hasHover;
|
|
75
|
+
|
|
76
|
+
const handleTouchOpenChange = React.useCallback((nextOpen: boolean) => {
|
|
77
|
+
if (isTouchToggleRef.current) {
|
|
78
|
+
isTouchToggleRef.current = false;
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
setOpen(nextOpen);
|
|
83
|
+
}, []);
|
|
84
|
+
|
|
85
|
+
const triggerChild = React.useMemo(() => {
|
|
86
|
+
if (!useTouchBehavior || !React.isValidElement(children)) {
|
|
87
|
+
return children;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return mergeTouchTriggerProps(
|
|
91
|
+
children as React.ReactElement<{ onClick?: (event: React.MouseEvent) => void }>,
|
|
92
|
+
() => {
|
|
93
|
+
isTouchToggleRef.current = true;
|
|
94
|
+
setOpen((prev) => !prev);
|
|
95
|
+
}
|
|
96
|
+
);
|
|
97
|
+
}, [children, useTouchBehavior]);
|
|
98
|
+
|
|
99
|
+
const tooltipContent =
|
|
100
|
+
typeof content === "string" ? (
|
|
101
|
+
<Text typography={"tooltip"} color="grey50">
|
|
102
|
+
{content}
|
|
103
|
+
</Text>
|
|
104
|
+
) : (
|
|
105
|
+
content
|
|
106
|
+
);
|
|
107
|
+
|
|
54
108
|
return (
|
|
55
109
|
<TooltipProvider>
|
|
56
|
-
<TooltipRoot
|
|
57
|
-
|
|
110
|
+
<TooltipRoot
|
|
111
|
+
delayDuration={useTouchBehavior ? 0 : delayDuration}
|
|
112
|
+
{...(useTouchBehavior
|
|
113
|
+
? { open, onOpenChange: handleTouchOpenChange }
|
|
114
|
+
: {})}
|
|
115
|
+
>
|
|
116
|
+
<TooltipTrigger asChild>{triggerChild}</TooltipTrigger>
|
|
58
117
|
<TooltipContent side={side} sideOffset={5}>
|
|
59
|
-
{
|
|
60
|
-
<Text typography={"tooltip"} color="grey50">
|
|
61
|
-
{content}
|
|
62
|
-
</Text>
|
|
63
|
-
) : (
|
|
64
|
-
content
|
|
65
|
-
)}
|
|
118
|
+
{tooltipContent}
|
|
66
119
|
<TooltipArrow />
|
|
67
120
|
</TooltipContent>
|
|
68
121
|
</TooltipRoot>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
export function useHasHover(): boolean {
|
|
4
|
+
const [hasHover, setHasHover] = useState(true);
|
|
5
|
+
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
const media = window.matchMedia("(hover: hover)");
|
|
8
|
+
|
|
9
|
+
setHasHover(media.matches);
|
|
10
|
+
|
|
11
|
+
const listener = (event: MediaQueryListEvent) => {
|
|
12
|
+
setHasHover(event.matches);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
media.addEventListener("change", listener);
|
|
16
|
+
|
|
17
|
+
return () => media.removeEventListener("change", listener);
|
|
18
|
+
}, []);
|
|
19
|
+
|
|
20
|
+
return hasHover;
|
|
21
|
+
}
|