Skip to content

Commit

Permalink
feat(console): animate tree view items when expanding and collapsing (#…
Browse files Browse the repository at this point in the history
…6895)

This changeset animates tree view items when expanding and collapsing.
  • Loading branch information
skyrpex authored Jul 12, 2024
1 parent 98a9766 commit 2acec76
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions apps/wing-console/console/design-system/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@tailwindcss/forms": "^0.5.7",
"@tailwindcss/typography": "^0.5.13",
"classnames": "^2.5.1",
"framer-motion": "^10.18.0",
"lodash.escape": "^4.0.1",
"lodash.uniq": "^4.5.0",
"nanoid": "^4.0.2",
Expand Down
14 changes: 11 additions & 3 deletions apps/wing-console/console/design-system/src/headless/tree-item.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PropsWithChildren, ReactNode, KeyboardEvent } from "react";
import { motion } from "framer-motion";
import {
createContext,
useCallback,
Expand All @@ -8,6 +8,7 @@ import {
useRef,
useState,
} from "react";
import type { PropsWithChildren, ReactNode, KeyboardEvent } from "react";

import { useTreeContext } from "./tree-context.js";

Expand Down Expand Up @@ -162,13 +163,20 @@ export const TreeItem = ({
)}
{Content && typeof Content !== "function" && Content}

<ul role="group" style={{ display: expanded ? undefined : "none" }}>
<motion.ul
role="group"
style={{ overflow: "hidden" }}
initial={{ opacity: 0, height: 0 }}
animate={{ opacity: expanded ? 1 : 0, height: expanded ? "auto" : 0 }}
exit={{ opacity: 0, height: 0 }}
transition={{ duration: 0.15 }}
>
<treeItemContext.Provider
value={{ itemId, indentation: indentation + 1 }}
>
{children}
</treeItemContext.Provider>
</ul>
</motion.ul>
</li>
);
};
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2acec76

Please sign in to comment.