dst-rg 1.0.0
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/.gitlab-ci.yml +43 -0
- package/.storybook/main.ts +15 -0
- package/.storybook/preview.ts +15 -0
- package/README.md +254 -0
- package/components.json +21 -0
- package/dist/Avatar.png +0 -0
- package/dist/assets/index-CCq7hmG3.js +186 -0
- package/dist/assets/index-Mg-hjQGu.css +1 -0
- package/dist/index.html +15 -0
- package/dist/test.png +0 -0
- package/dist/vite.svg +1 -0
- package/eslint.config.js +29 -0
- package/index.html +14 -0
- package/package.json +102 -0
- package/postcss.config.mjs +11 -0
- package/rollup.config.mjs +55 -0
- package/src/assets/react.svg +1 -0
- package/src/assets/style/animation.css +27 -0
- package/src/assets/style/box-shadow.css +25 -0
- package/src/assets/style/colors.css +402 -0
- package/src/assets/style/dark-theme.css +288 -0
- package/src/assets/style/font-size.css +14 -0
- package/src/assets/style/gradient.css +3 -0
- package/src/assets/style/index.css +12 -0
- package/src/assets/style/light-theme.css +148 -0
- package/src/assets/style/line-height.css +13 -0
- package/src/assets/style/max-width.css +5 -0
- package/src/assets/style/radius.css +13 -0
- package/src/assets/style/utility-colors.css +166 -0
- package/src/components/Accordion/_.stories.tsx +75 -0
- package/src/components/Accordion/_.test.tsx +77 -0
- package/src/components/Accordion/index.tsx +47 -0
- package/src/components/Accordion/type.ts +24 -0
- package/src/components/Avatar/_.stories.tsx +179 -0
- package/src/components/Avatar/_.style.ts +40 -0
- package/src/components/Avatar/_.test.tsx +150 -0
- package/src/components/Avatar/_.types.ts +66 -0
- package/src/components/Avatar/index.tsx +63 -0
- package/src/components/Badge/_.stories.tsx +75 -0
- package/src/components/Badge/_.style.ts +53 -0
- package/src/components/Badge/_.test.tsx +27 -0
- package/src/components/Badge/_.types.ts +11 -0
- package/src/components/Badge/index.tsx +42 -0
- package/src/components/Breadcrumbs/_.stories.tsx +95 -0
- package/src/components/Breadcrumbs/_.test.tsx +29 -0
- package/src/components/Breadcrumbs/_.type.ts +15 -0
- package/src/components/Breadcrumbs/index.tsx +103 -0
- package/src/components/Button/_.stories.tsx +85 -0
- package/src/components/Button/_.style.ts +56 -0
- package/src/components/Button/_.test.tsx +103 -0
- package/src/components/Button/_.types.ts +14 -0
- package/src/components/Button/index.tsx +70 -0
- package/src/components/Checkbox/_.stories.tsx +96 -0
- package/src/components/Checkbox/_.style.ts +24 -0
- package/src/components/Checkbox/_.test.tsx +85 -0
- package/src/components/Checkbox/_.types.ts +23 -0
- package/src/components/Checkbox/index.tsx +93 -0
- package/src/components/CheckboxGroup/PaymentCard/_.stories.tsx +104 -0
- package/src/components/CheckboxGroup/PaymentCard/_.style.ts +28 -0
- package/src/components/CheckboxGroup/PaymentCard/_.test.tsx +58 -0
- package/src/components/CheckboxGroup/PaymentCard/_.types.ts +28 -0
- package/src/components/CheckboxGroup/PaymentCard/index.tsx +71 -0
- package/src/components/CheckboxGroup/PlanCard/_.stories.tsx +165 -0
- package/src/components/CheckboxGroup/PlanCard/_.style.ts +32 -0
- package/src/components/CheckboxGroup/PlanCard/_.test.tsx +54 -0
- package/src/components/CheckboxGroup/PlanCard/_.types.ts +35 -0
- package/src/components/CheckboxGroup/PlanCard/index.tsx +53 -0
- package/src/components/CheckboxGroup/UserCard/_.stories.tsx +89 -0
- package/src/components/CheckboxGroup/UserCard/_.style.ts +42 -0
- package/src/components/CheckboxGroup/UserCard/_.test.tsx +66 -0
- package/src/components/CheckboxGroup/UserCard/_.types.ts +26 -0
- package/src/components/CheckboxGroup/UserCard/index.tsx +75 -0
- package/src/components/Dropdown/_.stories.tsx +180 -0
- package/src/components/Dropdown/_.style.ts +108 -0
- package/src/components/Dropdown/_.test.tsx +334 -0
- package/src/components/Dropdown/_.types.ts +12 -0
- package/src/components/Dropdown/index.tsx +130 -0
- package/src/components/FileUpload/_.stories.tsx +74 -0
- package/src/components/FileUpload/_.style.ts +0 -0
- package/src/components/FileUpload/_.test.tsx +222 -0
- package/src/components/FileUpload/_.types.ts +53 -0
- package/src/components/FileUpload/index.tsx +44 -0
- package/src/components/ImageMagnify/_.stories.tsx +226 -0
- package/src/components/ImageMagnify/_.style.ts +109 -0
- package/src/components/ImageMagnify/_.types.ts +44 -0
- package/src/components/ImageMagnify/index.tsx +204 -0
- package/src/components/Input/_.stories.tsx +177 -0
- package/src/components/Input/_.style.ts +79 -0
- package/src/components/Input/_.test.tsx +146 -0
- package/src/components/Input/_.types.ts +66 -0
- package/src/components/Input/index.tsx +231 -0
- package/src/components/InputTags/_.stories.tsx +51 -0
- package/src/components/InputTags/_.style.ts +28 -0
- package/src/components/InputTags/_.test.tsx +123 -0
- package/src/components/InputTags/_.types.ts +26 -0
- package/src/components/InputTags/index.tsx +140 -0
- package/src/components/Message/_.stories.tsx +79 -0
- package/src/components/Message/_.style.ts +87 -0
- package/src/components/Message/_.test.tsx +73 -0
- package/src/components/Message/_.types.ts +13 -0
- package/src/components/Message/index.tsx +57 -0
- package/src/components/Metric/_.stories.tsx +142 -0
- package/src/components/Metric/_.style.ts +14 -0
- package/src/components/Metric/_.test.tsx +166 -0
- package/src/components/Metric/_.types.ts +18 -0
- package/src/components/Metric/index.tsx +100 -0
- package/src/components/Modal/_.stories.tsx +93 -0
- package/src/components/Modal/_.style.ts +31 -0
- package/src/components/Modal/_.test.tsx +90 -0
- package/src/components/Modal/_.types.ts +14 -0
- package/src/components/Modal/index.tsx +82 -0
- package/src/components/Pagination/_.stories.tsx +118 -0
- package/src/components/Pagination/_.test.tsx +51 -0
- package/src/components/Pagination/index.tsx +256 -0
- package/src/components/Pagination/type.ts +48 -0
- package/src/components/PriceSlider/_.stories.tsx +107 -0
- package/src/components/PriceSlider/_.test.tsx +63 -0
- package/src/components/PriceSlider/_.type.tsx +19 -0
- package/src/components/PriceSlider/index.tsx +86 -0
- package/src/components/Progress/_.stories.tsx +93 -0
- package/src/components/Progress/_.style.ts +15 -0
- package/src/components/Progress/_.test.tsx +34 -0
- package/src/components/Progress/_.types.ts +17 -0
- package/src/components/Progress/index.tsx +173 -0
- package/src/components/Radio/_.stories.tsx +391 -0
- package/src/components/Radio/_.style.ts +33 -0
- package/src/components/Radio/_.test.tsx +77 -0
- package/src/components/Radio/_.types.ts +14 -0
- package/src/components/Radio/index.tsx +59 -0
- package/src/components/Select/_.stories.tsx +308 -0
- package/src/components/Select/_.style.ts +5 -0
- package/src/components/Select/_.types.ts +24 -0
- package/src/components/Select/index.tsx +172 -0
- package/src/components/Switch/_.stories.tsx +61 -0
- package/src/components/Switch/_.test.tsx +69 -0
- package/src/components/Switch/_.type.ts +12 -0
- package/src/components/Switch/index.tsx +70 -0
- package/src/components/Tabs/_.stories.tsx +508 -0
- package/src/components/Tabs/_.style.ts +63 -0
- package/src/components/Tabs/_.test.tsx +174 -0
- package/src/components/Tabs/_.type.ts +19 -0
- package/src/components/Tabs/index.tsx +35 -0
- package/src/components/Tag/_.stories.tsx +78 -0
- package/src/components/Tag/_.style.ts +71 -0
- package/src/components/Tag/_.test.tsx +44 -0
- package/src/components/Tag/_.types.ts +27 -0
- package/src/components/Tag/index.tsx +46 -0
- package/src/components/TextArea/_.stories.tsx +62 -0
- package/src/components/TextArea/_.style.ts +11 -0
- package/src/components/TextArea/_.test.tsx +43 -0
- package/src/components/TextArea/_.types.ts +29 -0
- package/src/components/TextArea/index.tsx +83 -0
- package/src/components/Toast/_.style.tsx +27 -0
- package/src/components/Toast/_.type.ts +30 -0
- package/src/components/Toast/_.utils.ts +23 -0
- package/src/components/Toast/container.tsx +171 -0
- package/src/components/Toast/index.tsx +29 -0
- package/src/components/Tooltip/_.stories.tsx +106 -0
- package/src/components/Tooltip/_.style.ts +27 -0
- package/src/components/Tooltip/_.test.tsx +54 -0
- package/src/components/Tooltip/_.types.ts +31 -0
- package/src/components/Tooltip/index.tsx +80 -0
- package/src/components/developers/AmirHossein.tsx +149 -0
- package/src/components/developers/Fardin.tsx +130 -0
- package/src/components/developers/Maryam.tsx +260 -0
- package/src/components/developers/Milad.tsx +431 -0
- package/src/components/developers/Rasoul.tsx +198 -0
- package/src/components/index.ts +28 -0
- package/src/components/ui/accordion.tsx +162 -0
- package/src/components/ui/avatars-component/avatar-description.tsx +30 -0
- package/src/components/ui/avatars-component/avatar-groups.tsx +68 -0
- package/src/components/ui/avatars-component/avatar-single.tsx +50 -0
- package/src/components/ui/card.tsx +92 -0
- package/src/components/ui/checkbox-group/plan-card/basic/_.test.tsx +66 -0
- package/src/components/ui/checkbox-group/plan-card/basic/index.tsx +70 -0
- package/src/components/ui/checkbox-group/plan-card/with-header/_.test.tsx +110 -0
- package/src/components/ui/checkbox-group/plan-card/with-header/header.test.tsx +96 -0
- package/src/components/ui/checkbox-group/plan-card/with-header/header.tsx +74 -0
- package/src/components/ui/checkbox-group/plan-card/with-header/index.tsx +65 -0
- package/src/components/ui/file-content/File-content.tsx +43 -0
- package/src/components/ui/file-uploader-components/file-uploader-box.tsx +76 -0
- package/src/components/ui/file-uploader-components/file-uploader-item.tsx +64 -0
- package/src/components/ui/icon-wrapper/_.test.tsx +60 -0
- package/src/components/ui/icon-wrapper/index.tsx +19 -0
- package/src/components/ui/input-component/input-label.tsx +11 -0
- package/src/components/ui/number.tsx +18 -0
- package/src/components/ui/pagination/card-minimal-center-align.tsx +96 -0
- package/src/components/ui/pagination/card-minimal-right-aligne.tsx +90 -0
- package/src/components/ui/pagination/default-pagination.tsx +128 -0
- package/src/components/ui/pagination/get-pagination-item.tsx +36 -0
- package/src/components/ui/pagination/pagination-card-button-group-aligned.tsx +94 -0
- package/src/components/ui/pagination/pagination-card-minimal-left-aligned.tsx +90 -0
- package/src/components/ui/pagination/pagination-content.tsx +15 -0
- package/src/components/ui/pagination/pagination-item.tsx +11 -0
- package/src/components/ui/pagination/pagination-link.tsx +42 -0
- package/src/components/ui/tab-components/tabs-content.tsx +15 -0
- package/src/components/ui/tab-components/tabs-list.tsx +27 -0
- package/src/components/ui/tab-components/tabs-trigger.tsx +25 -0
- package/src/components/ui/text-content-wrapper.tsx +36 -0
- package/src/hooks/useClickOutside.ts +23 -0
- package/src/icons/general/ArrowLeft.tsx +31 -0
- package/src/icons/general/ArrowRight.tsx +31 -0
- package/src/icons/general/activity-heart.tsx +31 -0
- package/src/icons/general/activity.tsx +31 -0
- package/src/icons/general/anchor.tsx +31 -0
- package/src/icons/general/archive.tsx +31 -0
- package/src/icons/general/arrow-left.tsx +25 -0
- package/src/icons/general/arrow-right.tsx +25 -0
- package/src/icons/general/asterisk-01.tsx +31 -0
- package/src/icons/general/asterisk-02.tsx +31 -0
- package/src/icons/general/at-sign.tsx +31 -0
- package/src/icons/general/attention-mark.tsx +43 -0
- package/src/icons/general/bookmark-add.tsx +31 -0
- package/src/icons/general/bookmark.tsx +31 -0
- package/src/icons/general/chevron-left.tsx +25 -0
- package/src/icons/general/chevron-right.tsx +25 -0
- package/src/icons/general/circle-minues.tsx +25 -0
- package/src/icons/general/circle-plus.tsx +25 -0
- package/src/icons/general/circle-question-mark.tsx +32 -0
- package/src/icons/general/circle.tsx +32 -0
- package/src/icons/general/copy.tsx +43 -0
- package/src/icons/general/email.tsx +32 -0
- package/src/icons/general/home.tsx +25 -0
- package/src/icons/general/layer.tsx +36 -0
- package/src/icons/general/leading.tsx +19 -0
- package/src/icons/general/master-card.tsx +37 -0
- package/src/icons/general/minus.tsx +36 -0
- package/src/icons/general/plus.tsx +19 -0
- package/src/icons/general/remove.tsx +32 -0
- package/src/icons/general/slash-divider.tsx +26 -0
- package/src/icons/general/tick-box.tsx +37 -0
- package/src/icons/general/trailing.tsx +19 -0
- package/src/icons/general/unkown-format.tsx +25 -0
- package/src/icons/general/visa-card.tsx +38 -0
- package/src/icons/general/x-close.tsx +35 -0
- package/src/icons/icons.type.ts +7 -0
- package/src/index.css +21 -0
- package/src/index.ts +3 -0
- package/src/lib/utils.ts +6 -0
- package/src/lib/zIndexUtils.ts +2 -0
- package/src/main.tsx +50 -0
- package/src/vite-env.d.ts +1 -0
- package/tests/setup.ts +8 -0
- package/tsconfig.app.json +31 -0
- package/tsconfig.json +7 -0
- package/tsconfig.node.json +24 -0
- package/tsconfig.rollup.json +12 -0
- package/vite.config.ts +20 -0
- package/vitest.config.ts +47 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import {
|
|
2
|
+
destructiveStyles,
|
|
3
|
+
textAreaVariants,
|
|
4
|
+
} from "@/components/TextArea/_.style";
|
|
5
|
+
import { textAreaProps } from "@/components/TextArea/_.types";
|
|
6
|
+
import { InputLabel } from "@/components/ui/input-component/input-label";
|
|
7
|
+
import CircleQuestionMark from "@/icons/general/circle-question-mark";
|
|
8
|
+
import { cn } from "@/lib/utils";
|
|
9
|
+
import { TooltipWrapper } from "../Tooltip";
|
|
10
|
+
|
|
11
|
+
const TextArea = ({
|
|
12
|
+
row = 5,
|
|
13
|
+
label,
|
|
14
|
+
required = false,
|
|
15
|
+
destructive = false,
|
|
16
|
+
disabled = false,
|
|
17
|
+
destructiveText,
|
|
18
|
+
hintText,
|
|
19
|
+
placeholder,
|
|
20
|
+
helpIcon = false,
|
|
21
|
+
onChange,
|
|
22
|
+
id,
|
|
23
|
+
tooltipProps,
|
|
24
|
+
className,
|
|
25
|
+
value,
|
|
26
|
+
name,
|
|
27
|
+
labelClass,
|
|
28
|
+
labelStarClass,
|
|
29
|
+
autoFocus = false,
|
|
30
|
+
...props
|
|
31
|
+
}: Readonly<textAreaProps>) => {
|
|
32
|
+
return (
|
|
33
|
+
<div className="flex flex-col gap-1">
|
|
34
|
+
<div className="flex items-center">
|
|
35
|
+
<InputLabel id={id} label={label} required={required}
|
|
36
|
+
labelClass={labelClass}
|
|
37
|
+
labelStarClass={labelStarClass}
|
|
38
|
+
/>
|
|
39
|
+
{helpIcon && tooltipProps && (
|
|
40
|
+
<TooltipWrapper
|
|
41
|
+
content={tooltipProps?.text}
|
|
42
|
+
description={tooltipProps?.description}
|
|
43
|
+
position={tooltipProps?.position}
|
|
44
|
+
dir={tooltipProps?.dir}
|
|
45
|
+
descriptionClassName={tooltipProps?.descriptionClassName}
|
|
46
|
+
>
|
|
47
|
+
<div>
|
|
48
|
+
<CircleQuestionMark />
|
|
49
|
+
</div>
|
|
50
|
+
</TooltipWrapper>
|
|
51
|
+
)}
|
|
52
|
+
</div>
|
|
53
|
+
<textarea
|
|
54
|
+
value={value}
|
|
55
|
+
name={name}
|
|
56
|
+
disabled={disabled}
|
|
57
|
+
rows={row}
|
|
58
|
+
placeholder={placeholder}
|
|
59
|
+
id={id}
|
|
60
|
+
onChange={onChange}
|
|
61
|
+
className={cn(
|
|
62
|
+
textAreaVariants(),
|
|
63
|
+
className,
|
|
64
|
+
destructive && destructiveStyles,
|
|
65
|
+
destructive && "bg-rbg-disabled-subtle border-rborder-disabled"
|
|
66
|
+
)}
|
|
67
|
+
autoFocus={autoFocus}
|
|
68
|
+
{...props}
|
|
69
|
+
/>
|
|
70
|
+
{destructive === false && hintText && (
|
|
71
|
+
<p className="text-sm text-rtext-tertiary-600">{hintText}</p>
|
|
72
|
+
)}
|
|
73
|
+
{destructive && destructiveText && (
|
|
74
|
+
<p className="text-sm text-rtext-error-primary-600">
|
|
75
|
+
{destructiveText}
|
|
76
|
+
</p>
|
|
77
|
+
)}
|
|
78
|
+
</div>
|
|
79
|
+
);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export { TextArea };
|
|
83
|
+
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AlertTriangle, CheckCircle, Info, XCircle } from "lucide-react";
|
|
2
|
+
|
|
3
|
+
export const iconMap = {
|
|
4
|
+
success: <CheckCircle className="text-green-100" size={20} />,
|
|
5
|
+
error: <XCircle className="text-red-100" size={20} />,
|
|
6
|
+
info: <Info className="text-blue-100" size={20} />,
|
|
7
|
+
warning: <AlertTriangle className="text-yellow-100" size={20} />,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const bgMap = {
|
|
11
|
+
success: "bg-green-500",
|
|
12
|
+
error: "bg-red-500",
|
|
13
|
+
info: "bg-blue-500",
|
|
14
|
+
warning: "bg-yellow-500 text-black",
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const animationMap = {
|
|
18
|
+
fade: "transition-all duration-300",
|
|
19
|
+
slide: "transition-all duration-300 transform translate-x-0",
|
|
20
|
+
scale: "transition-all duration-300 transform scale-100",
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const hiddenAnimationMap = {
|
|
24
|
+
fade: "opacity-0",
|
|
25
|
+
slide: "translate-x-10 opacity-0",
|
|
26
|
+
scale: "scale-0 opacity-0",
|
|
27
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type ToastPosition =
|
|
2
|
+
| "top-left"
|
|
3
|
+
| "top-center"
|
|
4
|
+
| "top-right"
|
|
5
|
+
| "middle-center"
|
|
6
|
+
| "bottom-left"
|
|
7
|
+
| "bottom-center"
|
|
8
|
+
| "bottom-right";
|
|
9
|
+
|
|
10
|
+
export interface ToastContainerProps {
|
|
11
|
+
type?: "success" | "error" | "info" | "warning";
|
|
12
|
+
duration?: number;
|
|
13
|
+
animation?: "fade" | "slide" | "scale";
|
|
14
|
+
position?: ToastPosition;
|
|
15
|
+
showProgress?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type ToastType = ToastContainerProps & {
|
|
19
|
+
id: number;
|
|
20
|
+
message: string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type ToastOptions = ToastContainerProps & {
|
|
24
|
+
message: string;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type InternalToast = ToastType & {
|
|
28
|
+
visible: boolean; // حالت انیمیشن
|
|
29
|
+
progressVisible?: boolean;
|
|
30
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ToastPosition } from "./_.type";
|
|
2
|
+
|
|
3
|
+
export function positionToClass(position: ToastPosition): string {
|
|
4
|
+
switch (position) {
|
|
5
|
+
case "top-left":
|
|
6
|
+
return "top-4 left-4";
|
|
7
|
+
case "top-center":
|
|
8
|
+
return "top-4 left-1/2 -translate-x-1/2";
|
|
9
|
+
case "top-right":
|
|
10
|
+
return "top-4 right-4";
|
|
11
|
+
case "middle-center":
|
|
12
|
+
return "top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2";
|
|
13
|
+
case "bottom-left":
|
|
14
|
+
return "bottom-4 left-4";
|
|
15
|
+
case "bottom-center":
|
|
16
|
+
return "bottom-4 left-1/2 -translate-x-1/2";
|
|
17
|
+
case "bottom-right":
|
|
18
|
+
return "bottom-4 right-4";
|
|
19
|
+
default:
|
|
20
|
+
return "top-4 right-4";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { X } from "lucide-react";
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
import { twMerge } from "tailwind-merge";
|
|
4
|
+
import { setToastDefaults } from ".";
|
|
5
|
+
import { animationMap, bgMap, hiddenAnimationMap, iconMap } from "./_.style";
|
|
6
|
+
import { InternalToast, ToastContainerProps, ToastPosition, ToastType } from "./_.type";
|
|
7
|
+
import { positionToClass } from "./_.utils";
|
|
8
|
+
|
|
9
|
+
const MAX_VISIBLE_TOASTS = 3;
|
|
10
|
+
|
|
11
|
+
const positions: ToastPosition[] = [
|
|
12
|
+
"top-left",
|
|
13
|
+
"top-center",
|
|
14
|
+
"top-right",
|
|
15
|
+
"middle-center",
|
|
16
|
+
"bottom-left",
|
|
17
|
+
"bottom-center",
|
|
18
|
+
"bottom-right",
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
export const ToastContainer = ({
|
|
22
|
+
type = "info",
|
|
23
|
+
position = "top-right",
|
|
24
|
+
duration = 3000,
|
|
25
|
+
animation = "fade",
|
|
26
|
+
showProgress = true,
|
|
27
|
+
}: ToastContainerProps) => {
|
|
28
|
+
const [toasts, setToasts] = useState<InternalToast[]>([]);
|
|
29
|
+
const timers = useRef<{ [id: number]: { timeoutId: any; start: number; remaining: number } }>({});
|
|
30
|
+
|
|
31
|
+
// set global defaults for toast (only once)
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
setToastDefaults({
|
|
34
|
+
type,
|
|
35
|
+
duration,
|
|
36
|
+
animation,
|
|
37
|
+
position,
|
|
38
|
+
showProgress,
|
|
39
|
+
});
|
|
40
|
+
}, []);
|
|
41
|
+
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
const handler = (e: CustomEvent<ToastType>) => {
|
|
44
|
+
const id = Date.now();
|
|
45
|
+
const duration = e.detail.duration ?? 3000;
|
|
46
|
+
|
|
47
|
+
const newToast: InternalToast = {
|
|
48
|
+
...e.detail,
|
|
49
|
+
id,
|
|
50
|
+
visible: true,
|
|
51
|
+
progressVisible: false,
|
|
52
|
+
duration,
|
|
53
|
+
position: e.detail.position ?? "top-right",
|
|
54
|
+
animation: e.detail.animation ?? "fade",
|
|
55
|
+
showProgress: e.detail.showProgress ?? false,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
setToasts((prev) => {
|
|
59
|
+
if (prev.length >= MAX_VISIBLE_TOASTS) return prev;
|
|
60
|
+
|
|
61
|
+
const start = Date.now();
|
|
62
|
+
timers.current[id] = {
|
|
63
|
+
timeoutId: setTimeout(() => hideToast(id), duration),
|
|
64
|
+
start,
|
|
65
|
+
remaining: duration,
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
return [...prev, newToast];
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
requestAnimationFrame(() => {
|
|
72
|
+
setToasts((prev) =>
|
|
73
|
+
prev.map((t) =>
|
|
74
|
+
t.id === id ? { ...t, progressVisible: true } : t
|
|
75
|
+
)
|
|
76
|
+
);
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
window.addEventListener("custom-toast", handler as EventListener);
|
|
82
|
+
return () => window.removeEventListener("custom-toast", handler as EventListener);
|
|
83
|
+
}, []);
|
|
84
|
+
|
|
85
|
+
const hideToast = (id: number) => {
|
|
86
|
+
setToasts((prev) =>
|
|
87
|
+
prev.map((t) => (t.id === id ? { ...t, visible: false } : t))
|
|
88
|
+
);
|
|
89
|
+
setTimeout(() => {
|
|
90
|
+
setToasts((prev) => prev.filter((t) => t.id !== id));
|
|
91
|
+
delete timers.current[id];
|
|
92
|
+
}, 300);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const pauseToast = (id: number) => {
|
|
96
|
+
const timer = timers.current[id];
|
|
97
|
+
if (!timer) return;
|
|
98
|
+
|
|
99
|
+
const now = Date.now();
|
|
100
|
+
const passed = now - timer.start;
|
|
101
|
+
timer.remaining = Math.max(0, timer.remaining - passed);
|
|
102
|
+
|
|
103
|
+
clearTimeout(timer.timeoutId);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const resumeToast = (id: number) => {
|
|
107
|
+
const timer = timers.current[id];
|
|
108
|
+
if (!timer || timer.remaining <= 0) return;
|
|
109
|
+
|
|
110
|
+
timer.start = Date.now();
|
|
111
|
+
timer.timeoutId = setTimeout(() => hideToast(id), timer.remaining);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
return (
|
|
115
|
+
<>
|
|
116
|
+
{positions.map((pos) => {
|
|
117
|
+
const group = toasts
|
|
118
|
+
.filter((t) => t.position === pos)
|
|
119
|
+
.slice(-MAX_VISIBLE_TOASTS);
|
|
120
|
+
|
|
121
|
+
if (group.length === 0) return null;
|
|
122
|
+
|
|
123
|
+
return (
|
|
124
|
+
<div
|
|
125
|
+
key={pos}
|
|
126
|
+
className={`fixed z-50 space-y-2 w-full sm:w-[320px] px-4 ${positionToClass(pos)}`}
|
|
127
|
+
>
|
|
128
|
+
{group.map((toast) => {
|
|
129
|
+
console.log("toast : ", toast)
|
|
130
|
+
return (
|
|
131
|
+
<div
|
|
132
|
+
key={toast.id}
|
|
133
|
+
onMouseEnter={() => pauseToast(toast.id)}
|
|
134
|
+
onMouseLeave={() => resumeToast(toast.id)}
|
|
135
|
+
className={twMerge('relative px-4 py-3 pr-10 rounded shadow text-white flex items-start gap-3',
|
|
136
|
+
bgMap[toast.type ?? "info"],
|
|
137
|
+
animationMap[toast.animation ?? "fade"],
|
|
138
|
+
toast.visible ? "" : hiddenAnimationMap[toast.animation ?? "fade"])}
|
|
139
|
+
>
|
|
140
|
+
<span>{iconMap[toast.type ?? "info"]}</span>
|
|
141
|
+
<div
|
|
142
|
+
className="flex-1 break-words text-sm"
|
|
143
|
+
dangerouslySetInnerHTML={{
|
|
144
|
+
__html: toast.message,
|
|
145
|
+
}}
|
|
146
|
+
/>
|
|
147
|
+
<button
|
|
148
|
+
className="absolute top-2 right-2 text-white hover:opacity-80"
|
|
149
|
+
onClick={() => hideToast(toast.id)}
|
|
150
|
+
>
|
|
151
|
+
<X size={16} />
|
|
152
|
+
</button>
|
|
153
|
+
{toast.showProgress && (
|
|
154
|
+
<div
|
|
155
|
+
className="absolute bottom-0 left-0 h-1 bg-white/50"
|
|
156
|
+
style={{
|
|
157
|
+
width: toast.progressVisible ? "100%" : "0%",
|
|
158
|
+
transition: `width ${toast.duration}ms linear`,
|
|
159
|
+
}}
|
|
160
|
+
/>
|
|
161
|
+
)}
|
|
162
|
+
</div>
|
|
163
|
+
)
|
|
164
|
+
})}
|
|
165
|
+
</div>
|
|
166
|
+
);
|
|
167
|
+
})}
|
|
168
|
+
</>
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ToastOptions } from "./_.type";
|
|
2
|
+
import { ToastContainer } from "./container";
|
|
3
|
+
|
|
4
|
+
// default config to be set by ToastContainer
|
|
5
|
+
let defaultOptions: Partial<Omit<ToastOptions, "message">> = {};
|
|
6
|
+
|
|
7
|
+
export function setToastDefaults(options: Partial<Omit<ToastOptions, "message">>) {
|
|
8
|
+
defaultOptions = options;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function toast(options: ToastOptions): void;
|
|
12
|
+
export function toast(message: string): void;
|
|
13
|
+
export function toast(input: any) {
|
|
14
|
+
const detail: ToastOptions =
|
|
15
|
+
typeof input === "string"
|
|
16
|
+
? { ...defaultOptions, message: input, type: defaultOptions?.type ?? "info" }
|
|
17
|
+
: { ...defaultOptions, ...input };
|
|
18
|
+
|
|
19
|
+
const event = new CustomEvent("custom-toast", { detail });
|
|
20
|
+
window.dispatchEvent(event);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Optional: helper methods for common types
|
|
24
|
+
toast.success = (message: string, opts?: Partial<ToastOptions>) => toast({ ...defaultOptions, ...opts, message, type: "success" });
|
|
25
|
+
toast.error = (message: string, opts?: Partial<ToastOptions>) => toast({ ...defaultOptions, ...opts, message, type: "error" });
|
|
26
|
+
toast.info = (message: string, opts?: Partial<ToastOptions>) => toast({ ...defaultOptions, ...opts, message, type: "info" });
|
|
27
|
+
toast.warning = (message: string, opts?: Partial<ToastOptions>) => toast({ ...defaultOptions, ...opts, message, type: "warning" });
|
|
28
|
+
|
|
29
|
+
export { ToastContainer };
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { StoryObj } from "@storybook/react-vite";
|
|
2
|
+
import { Meta } from "@storybook/react-vite";
|
|
3
|
+
import { TooltipWrapper } from ".";
|
|
4
|
+
import { Button } from "../Button";
|
|
5
|
+
import { TooltipWrapperProps } from "./_.types";
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
title: "Components/TooltipWrapper",
|
|
9
|
+
component: TooltipWrapper,
|
|
10
|
+
tags: ["autodocs"],
|
|
11
|
+
argTypes: {
|
|
12
|
+
dir: {
|
|
13
|
+
control: { type: "radio" },
|
|
14
|
+
options: ["ltr", "rtl"],
|
|
15
|
+
},
|
|
16
|
+
content: {
|
|
17
|
+
control: { type: "text" },
|
|
18
|
+
},
|
|
19
|
+
description: {
|
|
20
|
+
control: { type: "text" },
|
|
21
|
+
},
|
|
22
|
+
position: {
|
|
23
|
+
control: { type: "select" },
|
|
24
|
+
options: ["none", "top", "bottom", "left", "right"],
|
|
25
|
+
},
|
|
26
|
+
sideOffset: {
|
|
27
|
+
control: { type: "number" },
|
|
28
|
+
},
|
|
29
|
+
className: {
|
|
30
|
+
control: false,
|
|
31
|
+
},
|
|
32
|
+
contentClassName: {
|
|
33
|
+
control: false,
|
|
34
|
+
},
|
|
35
|
+
descriptionClassName: {
|
|
36
|
+
control: false,
|
|
37
|
+
},
|
|
38
|
+
children: {
|
|
39
|
+
control: false,
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
args: {
|
|
43
|
+
dir: "ltr",
|
|
44
|
+
content: "This is a tooltip",
|
|
45
|
+
description: "Additional description",
|
|
46
|
+
position: "top",
|
|
47
|
+
sideOffset: 4,
|
|
48
|
+
},
|
|
49
|
+
} as Meta<typeof TooltipWrapper>;
|
|
50
|
+
|
|
51
|
+
type Story = StoryObj<TooltipWrapperProps>;
|
|
52
|
+
|
|
53
|
+
export const Default: Story = {
|
|
54
|
+
render: (args) => (
|
|
55
|
+
<TooltipWrapper {...args}>
|
|
56
|
+
<Button>Hover me</Button>
|
|
57
|
+
</TooltipWrapper>
|
|
58
|
+
),
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const RTL: Story = {
|
|
62
|
+
args: {
|
|
63
|
+
dir: "rtl",
|
|
64
|
+
content: "تولتیپ فارسی",
|
|
65
|
+
description: "توضیحات تکمیلی",
|
|
66
|
+
position: "bottom",
|
|
67
|
+
},
|
|
68
|
+
render: (args) => (
|
|
69
|
+
<TooltipWrapper {...args}>
|
|
70
|
+
<Button>این یک tooltip است</Button>
|
|
71
|
+
</TooltipWrapper>
|
|
72
|
+
),
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export const WithoutDescription: Story = {
|
|
76
|
+
args: {
|
|
77
|
+
description: "",
|
|
78
|
+
},
|
|
79
|
+
render: (args) => (
|
|
80
|
+
<TooltipWrapper {...args}>
|
|
81
|
+
<Button>No description</Button>
|
|
82
|
+
</TooltipWrapper>
|
|
83
|
+
),
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export const WithoutArrow: Story = {
|
|
87
|
+
args: {
|
|
88
|
+
position: "none",
|
|
89
|
+
},
|
|
90
|
+
render: (args) => (
|
|
91
|
+
<TooltipWrapper {...args}>
|
|
92
|
+
<Button>No arrow</Button>
|
|
93
|
+
</TooltipWrapper>
|
|
94
|
+
),
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export const CustomOffset: Story = {
|
|
98
|
+
args: {
|
|
99
|
+
sideOffset: 10,
|
|
100
|
+
},
|
|
101
|
+
render: (args) => (
|
|
102
|
+
<TooltipWrapper {...args}>
|
|
103
|
+
<Button>Offset 10</Button>
|
|
104
|
+
</TooltipWrapper>
|
|
105
|
+
),
|
|
106
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Position } from "./_.types";
|
|
2
|
+
|
|
3
|
+
export const PositionMap: Record<
|
|
4
|
+
Position,
|
|
5
|
+
{
|
|
6
|
+
side: "top" | "bottom" | "left" | "right";
|
|
7
|
+
align: "start" | "center" | "end";
|
|
8
|
+
}
|
|
9
|
+
> = {
|
|
10
|
+
none: { side: "top", align: "center" },
|
|
11
|
+
top: { side: "top", align: "center" },
|
|
12
|
+
topstart: { side: "top", align: "start" },
|
|
13
|
+
topcenter: { side: "top", align: "center" },
|
|
14
|
+
topend: { side: "top", align: "end" },
|
|
15
|
+
bottom: { side: "bottom", align: "center" },
|
|
16
|
+
bottomstart: { side: "bottom", align: "start" },
|
|
17
|
+
bottomcenter: { side: "bottom", align: "center" },
|
|
18
|
+
bottomend: { side: "bottom", align: "end" },
|
|
19
|
+
left: { side: "left", align: "center" },
|
|
20
|
+
leftstart: { side: "left", align: "start" },
|
|
21
|
+
leftcenter: { side: "left", align: "center" },
|
|
22
|
+
leftend: { side: "left", align: "end" },
|
|
23
|
+
right: { side: "right", align: "center" },
|
|
24
|
+
rightstart: { side: "right", align: "start" },
|
|
25
|
+
rightcenter: { side: "right", align: "center" },
|
|
26
|
+
rightend: { side: "right", align: "end" },
|
|
27
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { render, screen, waitFor } from "@testing-library/react";
|
|
2
|
+
import userEvent from "@testing-library/user-event";
|
|
3
|
+
import { describe, it, expect } from "vitest";
|
|
4
|
+
import { TooltipWrapper } from ".";
|
|
5
|
+
import { Button } from "../Button";
|
|
6
|
+
|
|
7
|
+
describe("TooltipWrapper", () => {
|
|
8
|
+
it("renders the tooltip content on hover", async () => {
|
|
9
|
+
render(
|
|
10
|
+
<TooltipWrapper content="Tooltip Text">
|
|
11
|
+
<Button>Hover me</Button>
|
|
12
|
+
</TooltipWrapper>
|
|
13
|
+
);
|
|
14
|
+
const trigger = screen.getByText(/Hover me/i);
|
|
15
|
+
|
|
16
|
+
expect(screen.queryByText(/Tooltip Text/i)).not.toBeInTheDocument();
|
|
17
|
+
|
|
18
|
+
await userEvent.hover(trigger);
|
|
19
|
+
|
|
20
|
+
await waitFor(() => {
|
|
21
|
+
const tooltips = screen.getAllByText("Tooltip Text");
|
|
22
|
+
expect(tooltips.length).toBeGreaterThan(0);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("displays the description if provided", async () => {
|
|
27
|
+
render(
|
|
28
|
+
<TooltipWrapper content="Tooltip Text" description="Extra Info">
|
|
29
|
+
<Button>Hover me</Button>
|
|
30
|
+
</TooltipWrapper>
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
await userEvent.hover(screen.getByText(/Hover me/i));
|
|
34
|
+
|
|
35
|
+
await waitFor(() => {
|
|
36
|
+
const extras = screen.getAllByText(/Extra Info/i);
|
|
37
|
+
expect(extras.length).toBeGreaterThan(0);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("does not render description if not provided", async () => {
|
|
42
|
+
render(
|
|
43
|
+
<TooltipWrapper content="Tooltip Only">
|
|
44
|
+
<Button>Hover me</Button>
|
|
45
|
+
</TooltipWrapper>
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
await userEvent.hover(screen.getByText(/Hover me/i));
|
|
49
|
+
|
|
50
|
+
await waitFor(() => {
|
|
51
|
+
expect(screen.queryByText(/Extra Info/i)).not.toBeInTheDocument();
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
export type Position =
|
|
3
|
+
| "none"
|
|
4
|
+
| "top"
|
|
5
|
+
| "topstart"
|
|
6
|
+
| "topcenter"
|
|
7
|
+
| "topend"
|
|
8
|
+
| "bottom"
|
|
9
|
+
| "bottomstart"
|
|
10
|
+
| "bottomcenter"
|
|
11
|
+
| "bottomend"
|
|
12
|
+
| "left"
|
|
13
|
+
| "leftstart"
|
|
14
|
+
| "leftcenter"
|
|
15
|
+
| "leftend"
|
|
16
|
+
| "right"
|
|
17
|
+
| "rightstart"
|
|
18
|
+
| "rightcenter"
|
|
19
|
+
| "rightend";
|
|
20
|
+
|
|
21
|
+
export interface TooltipWrapperProps {
|
|
22
|
+
children: ReactNode;
|
|
23
|
+
content: string;
|
|
24
|
+
description?: string;
|
|
25
|
+
className?: string;
|
|
26
|
+
contentClassName?: string;
|
|
27
|
+
descriptionClassName?: string;
|
|
28
|
+
sideOffset?: number;
|
|
29
|
+
position?: Position;
|
|
30
|
+
dir?: "rtl" | "ltr";
|
|
31
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import * as TooltipPrimitive from "@radix-ui/react-tooltip";
|
|
3
|
+
import { cn } from "@/lib/utils";
|
|
4
|
+
import { PositionMap } from "./_.style";
|
|
5
|
+
import { TooltipWrapperProps } from "./_.types";
|
|
6
|
+
|
|
7
|
+
const TooltipContent = React.forwardRef<
|
|
8
|
+
React.ComponentRef<typeof TooltipPrimitive.Content>,
|
|
9
|
+
React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Content>
|
|
10
|
+
>(({ className, sideOffset = 4, ...props }, ref) => (
|
|
11
|
+
<TooltipPrimitive.Content
|
|
12
|
+
ref={ref}
|
|
13
|
+
sideOffset={sideOffset}
|
|
14
|
+
className={cn(
|
|
15
|
+
"z-50 overflow-hidden rounded-md border bg-black px-3 py-1.5 text-sm text-white shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-tooltip-content-transform-origin]",
|
|
16
|
+
className
|
|
17
|
+
)}
|
|
18
|
+
{...props}
|
|
19
|
+
>
|
|
20
|
+
{props.children}
|
|
21
|
+
</TooltipPrimitive.Content>
|
|
22
|
+
)); TooltipContent.displayName = TooltipPrimitive.Content.displayName;
|
|
23
|
+
|
|
24
|
+
export const TooltipWrapper = ({
|
|
25
|
+
children,
|
|
26
|
+
content,
|
|
27
|
+
description,
|
|
28
|
+
className,
|
|
29
|
+
contentClassName,
|
|
30
|
+
descriptionClassName,
|
|
31
|
+
sideOffset = 4,
|
|
32
|
+
position = "none",
|
|
33
|
+
dir = "rtl",
|
|
34
|
+
}: TooltipWrapperProps & { dir?: "rtl" | "ltr" }) => {
|
|
35
|
+
const isLTR = dir === "ltr";
|
|
36
|
+
const Position = PositionMap[position] || {
|
|
37
|
+
side: "top",
|
|
38
|
+
align: isLTR ? "start" : "end",
|
|
39
|
+
};
|
|
40
|
+
const shouldRenderArrow = position !== "none";
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<TooltipPrimitive.Provider>
|
|
44
|
+
<TooltipPrimitive.Root delayDuration={50}>
|
|
45
|
+
<TooltipPrimitive.Trigger asChild>{children}</TooltipPrimitive.Trigger>
|
|
46
|
+
<TooltipContent
|
|
47
|
+
className={cn(className)}
|
|
48
|
+
sideOffset={sideOffset}
|
|
49
|
+
side={Position.side}
|
|
50
|
+
align={Position.align}
|
|
51
|
+
dir={dir}
|
|
52
|
+
>
|
|
53
|
+
<div className="flex flex-col" dir={dir}>
|
|
54
|
+
<span className={cn("text-base font-medium", contentClassName)}>
|
|
55
|
+
{content}
|
|
56
|
+
</span>
|
|
57
|
+
{description && (
|
|
58
|
+
<span
|
|
59
|
+
className={cn(
|
|
60
|
+
"text-xs opacity-70 mt-1",
|
|
61
|
+
isLTR ? "text-start" : "text-end",
|
|
62
|
+
descriptionClassName
|
|
63
|
+
)}
|
|
64
|
+
>
|
|
65
|
+
{description}
|
|
66
|
+
</span>
|
|
67
|
+
)}
|
|
68
|
+
</div>
|
|
69
|
+
{shouldRenderArrow && (
|
|
70
|
+
<TooltipPrimitive.Arrow
|
|
71
|
+
className="fill-black"
|
|
72
|
+
width={16}
|
|
73
|
+
height={6}
|
|
74
|
+
/>
|
|
75
|
+
)}
|
|
76
|
+
</TooltipContent>
|
|
77
|
+
</TooltipPrimitive.Root>
|
|
78
|
+
</TooltipPrimitive.Provider>
|
|
79
|
+
);
|
|
80
|
+
};
|