Disabled accordion when it is empty
This commit is contained in:
parent
3b8e72ff1a
commit
06a568f114
4 changed files with 39 additions and 10 deletions
|
|
@ -6,10 +6,13 @@ import {
|
||||||
AccordionTrigger,
|
AccordionTrigger,
|
||||||
} from "../../components/ui/accordion";
|
} from "../../components/ui/accordion";
|
||||||
import { AccordionComponentType } from "../../types/components";
|
import { AccordionComponentType } from "../../types/components";
|
||||||
|
import { cn } from "../../utils/utils";
|
||||||
|
import ShadTooltip from "../shadTooltipComponent";
|
||||||
|
|
||||||
export default function AccordionComponent({
|
export default function AccordionComponent({
|
||||||
trigger,
|
trigger,
|
||||||
children,
|
children,
|
||||||
|
disabled,
|
||||||
open = [],
|
open = [],
|
||||||
keyValue,
|
keyValue,
|
||||||
sideBar,
|
sideBar,
|
||||||
|
|
@ -29,7 +32,9 @@ export default function AccordionComponent({
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleClick(): void {
|
function handleClick(): void {
|
||||||
value === "" ? setValue(keyValue!) : setValue("");
|
if (!disabled) {
|
||||||
|
value === "" ? setValue(keyValue!) : setValue("");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
@ -38,16 +43,18 @@ export default function AccordionComponent({
|
||||||
type="single"
|
type="single"
|
||||||
className="w-full"
|
className="w-full"
|
||||||
value={value}
|
value={value}
|
||||||
onValueChange={setValue}
|
onValueChange={!disabled ? setValue : () => {}}
|
||||||
>
|
>
|
||||||
<AccordionItem value={keyValue!} className="border-b">
|
<AccordionItem value={keyValue!} className="border-b">
|
||||||
<AccordionTrigger
|
<AccordionTrigger
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
handleClick();
|
handleClick();
|
||||||
}}
|
}}
|
||||||
className={
|
disabled={disabled}
|
||||||
sideBar ? "w-full bg-muted px-[0.75rem] py-[0.5rem]" : "ml-3"
|
className={cn(
|
||||||
}
|
sideBar ? "w-full bg-muted px-[0.75rem] py-[0.5rem]" : "ml-3",
|
||||||
|
disabled ? "cursor-not-allowed" : "cursor-pointer",
|
||||||
|
)}
|
||||||
>
|
>
|
||||||
{trigger}
|
{trigger}
|
||||||
</AccordionTrigger>
|
</AccordionTrigger>
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import * as AccordionPrimitive from "@radix-ui/react-accordion";
|
||||||
import { ChevronDownIcon } from "@radix-ui/react-icons";
|
import { ChevronDownIcon } from "@radix-ui/react-icons";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { cn } from "../../utils/utils";
|
import { cn } from "../../utils/utils";
|
||||||
|
import ShadTooltip from "../shadTooltipComponent";
|
||||||
|
|
||||||
const Accordion = AccordionPrimitive.Root;
|
const Accordion = AccordionPrimitive.Root;
|
||||||
|
|
||||||
|
|
@ -22,17 +23,33 @@ AccordionItem.displayName = "AccordionItem";
|
||||||
const AccordionTrigger = React.forwardRef<
|
const AccordionTrigger = React.forwardRef<
|
||||||
React.ElementRef<typeof AccordionPrimitive.Trigger>,
|
React.ElementRef<typeof AccordionPrimitive.Trigger>,
|
||||||
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Trigger>
|
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Trigger>
|
||||||
>(({ className, children, ...props }, ref) => (
|
>(({ className, children, disabled, ...props }, ref) => (
|
||||||
<AccordionPrimitive.Header className="flex">
|
<AccordionPrimitive.Header className="flex">
|
||||||
<AccordionPrimitive.Trigger asChild ref={ref} {...props}>
|
<AccordionPrimitive.Trigger
|
||||||
|
disabled={disabled}
|
||||||
|
asChild
|
||||||
|
ref={ref}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex flex-1 cursor-pointer items-center justify-between py-4 text-sm font-medium transition-all [&[data-state=open]>svg]:rotate-180",
|
"flex flex-1 cursor-pointer items-center justify-between py-4 text-sm font-medium transition-all [&[data-state=open]>svg]:rotate-180",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
<ChevronDownIcon className="h-4 w-4 font-bold text-primary transition-transform duration-200" />
|
<ShadTooltip
|
||||||
|
styleClasses="z-50"
|
||||||
|
content={disabled ? "Empty" : ""}
|
||||||
|
side="top"
|
||||||
|
>
|
||||||
|
<ChevronDownIcon
|
||||||
|
className={cn(
|
||||||
|
"h-4 w-4 font-bold transition-transform duration-200",
|
||||||
|
disabled ? "text-muted-foreground" : "text-primary",
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</ShadTooltip>
|
||||||
</div>
|
</div>
|
||||||
</AccordionPrimitive.Trigger>
|
</AccordionPrimitive.Trigger>
|
||||||
</AccordionPrimitive.Header>
|
</AccordionPrimitive.Header>
|
||||||
|
|
@ -47,7 +64,7 @@ const AccordionContent = React.forwardRef<
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn(
|
className={cn(
|
||||||
"data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down overflow-hidden text-sm",
|
"data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down overflow-hidden text-sm",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
|
|
|
||||||
|
|
@ -253,6 +253,10 @@ export default function IOModal({
|
||||||
key={index}
|
key={index}
|
||||||
>
|
>
|
||||||
<AccordionComponent
|
<AccordionComponent
|
||||||
|
disabled={
|
||||||
|
node.data.node!.template["input_value"]
|
||||||
|
?.value === ""
|
||||||
|
}
|
||||||
trigger={
|
trigger={
|
||||||
<div className="file-component-badge-div">
|
<div className="file-component-badge-div">
|
||||||
<ShadTooltip
|
<ShadTooltip
|
||||||
|
|
|
||||||
|
|
@ -221,6 +221,7 @@ export type AccordionComponentType = {
|
||||||
children?: ReactElement;
|
children?: ReactElement;
|
||||||
open?: string[];
|
open?: string[];
|
||||||
trigger?: string | ReactElement;
|
trigger?: string | ReactElement;
|
||||||
|
disabled?: boolean;
|
||||||
keyValue?: string;
|
keyValue?: string;
|
||||||
openDisc?: boolean;
|
openDisc?: boolean;
|
||||||
sideBar?: boolean;
|
sideBar?: boolean;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue