mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
ench: add dynamic height
This commit is contained in:
parent
e9d541498e
commit
bbcdb42708
1 changed files with 9 additions and 1 deletions
|
@ -1,5 +1,5 @@
|
||||||
import { ChevronDownIcon } from "@primer/octicons-react";
|
import { ChevronDownIcon } from "@primer/octicons-react";
|
||||||
import { useRef, useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
|
|
||||||
import * as styles from "./sidebar-section.css";
|
import * as styles from "./sidebar-section.css";
|
||||||
|
|
||||||
|
@ -11,6 +11,13 @@ export interface SidebarSectionProps {
|
||||||
export function SidebarSection({ title, children }: SidebarSectionProps) {
|
export function SidebarSection({ title, children }: SidebarSectionProps) {
|
||||||
const content = useRef<HTMLDivElement>(null);
|
const content = useRef<HTMLDivElement>(null);
|
||||||
const [isOpen, setIsOpen] = useState(true);
|
const [isOpen, setIsOpen] = useState(true);
|
||||||
|
const [height, setHeight] = useState(0);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (content.current) {
|
||||||
|
setHeight(isOpen ? content.current.scrollHeight : 0);
|
||||||
|
}
|
||||||
|
}, [isOpen, children]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
@ -26,6 +33,7 @@ export function SidebarSection({ title, children }: SidebarSectionProps) {
|
||||||
<div
|
<div
|
||||||
ref={content}
|
ref={content}
|
||||||
style={{
|
style={{
|
||||||
|
maxHeight: `${height}px`,
|
||||||
overflow: "hidden",
|
overflow: "hidden",
|
||||||
transition: "max-height 0.4s cubic-bezier(0, 1, 0, 1)",
|
transition: "max-height 0.4s cubic-bezier(0, 1, 0, 1)",
|
||||||
position: "relative",
|
position: "relative",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue