From 79b6081bb4667a91f29dda48b2e7d6b78a78ae4c Mon Sep 17 00:00:00 2001 From: faisolavolut Date: Tue, 18 Feb 2025 13:02:31 +0700 Subject: [PATCH] feat: add side prop to TooltipBetter component for customizable tooltip positioning --- components/form/Field.tsx | 413 ++++++++++++++++--------------- components/ui/tooltip-better.tsx | 7 +- 2 files changed, 215 insertions(+), 205 deletions(-) diff --git a/components/form/Field.tsx b/components/form/Field.tsx index 7a33cb0..0c5a224 100644 --- a/components/form/Field.tsx +++ b/components/form/Field.tsx @@ -10,12 +10,14 @@ import { getNumber } from "@/lib/utils/getNumber"; import { useLocal } from "@/lib/utils/use-local"; import { FieldRadio } from "./field/TypeRadio"; import { cn } from "@/lib/utils"; +import { TooltipBetter } from "../ui/tooltip-better"; export const Field: React.FC<{ fm: any; label?: string; name: string; isBetter?: boolean; + tooltip?: string; onLoad?: () => Promise | any; type?: | "rating" @@ -70,6 +72,7 @@ export const Field: React.FC<{ suffix, allowNew, unique = true, + tooltip, }) => { let result = null; const field = useLocal({ @@ -155,211 +158,215 @@ export const Field: React.FC<{ ) : ( <> )} -
- {before && ( -
+
- {before} -
- )} - {["upload"].includes(type) ? ( - <> - - - ) : ["multi-upload"].includes(type) ? ( - <> - - - ) : ["dropdown"].includes(type) ? ( - <> - - - ) : ["multi-dropdown"].includes(type) ? ( - <> - - - ) : ["checkbox"].includes(type) ? ( - <> - - - ) : ["radio"].includes(type) ? ( - <> - - - ) : ["single-checkbox"].includes(type) ? ( - <> - - - ) : ["richtext"].includes(type) ? ( - <> - - - ) : ["tag"].includes(type) ? ( - <> - - - ) : ( - <> - { - field.focus = true; - field.render(); - }} - className={cx( - before && - css` - padding-left: ${getNumber( - get(prefixRef, "current.clientWidth") - ) + 10}px; - `, - after && - css` - padding-right: ${getNumber( - get(suffixRef, "current.clientWidth") - ) + 10}px; - `, - className - )} - /> - - )} - {after && ( -
- {after} -
- )} -
+ ["upload"].includes(type) && + css` + padding: 0px !important; + `, + classField + )} + > + {before && ( +
+ {before} +
+ )} + + {["upload"].includes(type) ? ( + <> + + + ) : ["multi-upload"].includes(type) ? ( + <> + + + ) : ["dropdown"].includes(type) ? ( + <> + + + ) : ["multi-dropdown"].includes(type) ? ( + <> + + + ) : ["checkbox"].includes(type) ? ( + <> + + + ) : ["radio"].includes(type) ? ( + <> + + + ) : ["single-checkbox"].includes(type) ? ( + <> + + + ) : ["richtext"].includes(type) ? ( + <> + + + ) : ["tag"].includes(type) ? ( + <> + + + ) : ( + <> + { + field.focus = true; + field.render(); + }} + className={cx( + before && + css` + padding-left: ${getNumber( + get(prefixRef, "current.clientWidth") + ) + 10}px; + `, + after && + css` + padding-right: ${getNumber( + get(suffixRef, "current.clientWidth") + ) + 10}px; + `, + className + )} + /> + + )} + {after && ( +
+ {after} +
+ )} +
+ + {error ? (
{error}
) : ( diff --git a/components/ui/tooltip-better.tsx b/components/ui/tooltip-better.tsx index f8e6ca7..6ffcc52 100644 --- a/components/ui/tooltip-better.tsx +++ b/components/ui/tooltip-better.tsx @@ -6,7 +6,7 @@ import { TooltipTrigger, } from "./tooltip"; -export const TooltipBetter: FC = ({ content, children }) => { +export const TooltipBetter: FC = ({ content, children, side = "top" }) => { if (content) { return ( @@ -14,7 +14,10 @@ export const TooltipBetter: FC = ({ content, children }) => {
{children}
- +

{content}