From e9a6a162e8a26c6507938191c4e0b5bd94bdbf8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D5=A1=D3=84=D5=A1?= Date: Sat, 22 Jun 2024 21:44:19 +0800 Subject: [PATCH] fix(accordion): variants for nested accordions (#3291) * feat(accordion): add data-variant * fix(theme): revise accordion styles for variants * feat(changeset): add changeset * chore(theme): rollback content padding * chore(accordion): abandon data-group approach * refactor(theme): pass variant to accordionItem * refactor(accordion): pass variant to accordionItem * fix(accordion): revise accordion variants * refactor(accordion): refine transitionVariants --- .changeset/nasty-forks-explode.md | 6 ++++++ .../components/accordion/src/accordion-item.tsx | 15 +++++++++++---- packages/components/accordion/src/accordion.tsx | 1 + .../accordion/src/use-accordion-item.ts | 7 ++++++- packages/core/theme/src/components/accordion.ts | 14 +++++++------- 5 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 .changeset/nasty-forks-explode.md diff --git a/.changeset/nasty-forks-explode.md b/.changeset/nasty-forks-explode.md new file mode 100644 index 000000000..61412b132 --- /dev/null +++ b/.changeset/nasty-forks-explode.md @@ -0,0 +1,6 @@ +--- +"@nextui-org/accordion": patch +"@nextui-org/theme": patch +--- + +Fixed variants for nested accordions (#3285) diff --git a/packages/components/accordion/src/accordion-item.tsx b/packages/components/accordion/src/accordion-item.tsx index 580c0a160..16022bedd 100644 --- a/packages/components/accordion/src/accordion-item.tsx +++ b/packages/components/accordion/src/accordion-item.tsx @@ -1,3 +1,5 @@ +import type {Variants} from "framer-motion"; + import {forwardRef} from "@nextui-org/system"; import {useMemo, ReactNode} from "react"; import {ChevronIcon} from "@nextui-org/shared-icons"; @@ -53,6 +55,11 @@ const AccordionItem = forwardRef<"button", AccordionItemProps>((props, ref) => { return
{children}
; } + const transitionVariants: Variants = { + exit: {...TRANSITION_VARIANTS.collapse.exit, overflowY: "hidden"}, + enter: {...TRANSITION_VARIANTS.collapse.enter, overflowY: "unset"}, + }; + return keepContentMounted ? ( ((props, ref) => { animate={isOpen ? "enter" : "exit"} exit="exit" initial="exit" - style={{overflowY: "hidden", willChange}} - variants={TRANSITION_VARIANTS.collapse} + style={{willChange}} + variants={transitionVariants} {...motionProps} >
{children}
@@ -76,8 +83,8 @@ const AccordionItem = forwardRef<"button", AccordionItemProps>((props, ref) => { animate="enter" exit="exit" initial="exit" - style={{overflowY: "hidden", willChange}} - variants={TRANSITION_VARIANTS.collapse} + style={{willChange}} + variants={transitionVariants} {...motionProps} >
{children}
diff --git a/packages/components/accordion/src/accordion.tsx b/packages/components/accordion/src/accordion.tsx index 47d7f380f..b14a00413 100644 --- a/packages/components/accordion/src/accordion.tsx +++ b/packages/components/accordion/src/accordion.tsx @@ -36,6 +36,7 @@ const AccordionGroup = forwardRef<"div", AccordionProps>((props, ref) => { extends HTMLNextUIProps<"div"> { } export type UseAccordionItemProps = Props & + AccordionItemVariantProps & Omit; export function useAccordionItem(props: UseAccordionItemProps) { @@ -53,6 +56,7 @@ export function useAccordionItem(props: UseAccordionItemP startContent, motionProps, focusedKey, + variant, isCompact = false, classNames: classNamesProp = {}, isDisabled: isDisabledProp = false, @@ -125,8 +129,9 @@ export function useAccordionItem(props: UseAccordionItemP hideIndicator, disableAnimation, disableIndicatorAnimation, + variant, }), - [isCompact, isDisabled, hideIndicator, disableAnimation, disableIndicatorAnimation], + [isCompact, isDisabled, hideIndicator, disableAnimation, disableIndicatorAnimation, variant], ); const baseStyles = clsx(classNames?.base, className); diff --git a/packages/core/theme/src/components/accordion.ts b/packages/core/theme/src/components/accordion.ts index 8a3e4ad1a..a0bd6b45c 100644 --- a/packages/core/theme/src/components/accordion.ts +++ b/packages/core/theme/src/components/accordion.ts @@ -20,7 +20,7 @@ const accordion = tv({ light: "", shadow: "px-4 shadow-medium rounded-medium bg-content1", bordered: "px-4 border-medium border-divider rounded-medium", - splitted: "group is-splitted flex flex-col gap-2", // the classNames are applied in the accordion-item component + splitted: "flex flex-col gap-2", }, fullWidth: { true: "w-full", @@ -56,12 +56,7 @@ const accordion = tv({ */ const accordionItem = tv({ slots: { - base: [ - "group-[.is-splitted]:px-4", - "group-[.is-splitted]:bg-content1", - "group-[.is-splitted]:shadow-medium", - "group-[.is-splitted]:rounded-medium", - ], + base: "", heading: "", trigger: [ "flex py-4 w-full h-full gap-3 outline-none items-center tap-highlight-transparent", @@ -76,6 +71,11 @@ const accordionItem = tv({ content: "py-2", }, variants: { + variant: { + splitted: { + base: "px-4 bg-content1 shadow-medium rounded-medium", + }, + }, isCompact: { true: { trigger: "py-2",