Skip to content

Commit dd5c14f

Browse files
committed
feat(Accordion): Improve handling of according item width
1 parent 5d805c4 commit dd5c14f

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

src/Startpage/LinkContainer/Accordion/Accordion.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { MouseEvent, PropsWithChildren, useState } from "react"
33
import styled from "@emotion/styled"
44

55
const StyledAccordionContainer = styled.div`
6-
margin-left: 100px;
76
display: flex;
8-
width: calc(100% - 400px - 100px);
7+
flex: 1;
8+
overflow: hidden;
99
`
1010

1111
export const AccordionContainer = ({ children }: PropsWithChildren) => (
@@ -15,6 +15,7 @@ export const AccordionContainer = ({ children }: PropsWithChildren) => (
1515
const StyledAccordionGroup = styled.div`
1616
height: 400px;
1717
display: flex;
18+
flex: 1;
1819
padding: 0 10px;
1920
flex-direction: row;
2021
border-right: 3px solid var(--default-color);
@@ -23,9 +24,9 @@ const StyledAccordionGroup = styled.div`
2324
}
2425
`
2526

26-
const AccordionContent = styled.div<{ width: number }>`
27+
const AccordionContent = styled.div<{ width: number | string | null }>`
2728
height: 100%;
28-
width: ${({ width }) => `${width}px`};
29+
width: ${({ width }) => (typeof width !== "number" ? width : `${width}px`)};
2930
display: flex;
3031
flex-direction: column;
3132
justify-content: center;
@@ -144,10 +145,12 @@ type groupProps = PropsWithChildren<{
144145
const getAvailableContentWidth = (element: HTMLElement | null) => {
145146
const parent = element?.parentElement
146147
if (!parent) return 0
148+
if (parent.children.length === 1) return "100%"
147149
const barWidth = [...parent.children].reduce(
148150
(width, element) => Math.min(width, (element as HTMLElement).offsetWidth),
149151
Infinity
150152
)
153+
console.log(barWidth)
151154
return parent.offsetWidth - parent.children.length * barWidth
152155
}
153156

@@ -158,7 +161,7 @@ export const AccordionGroup = ({
158161
onClick,
159162
onMouseDown,
160163
}: groupProps) => {
161-
const [contentWidth, setContentWidth] = useState(active ? 500 : 0)
164+
const [contentWidth, setContentWidth] = useState<number | string | null>(null)
162165

163166
return (
164167
<StyledAccordionGroup

src/Startpage/Startpage.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const Wrapper = styled.div`
1616
`
1717

1818
const StyledStartpage = styled.div`
19+
gap: 100px;
1920
padding: 0px 100px;
2021
display: flex;
2122
flex-direction: row;

0 commit comments

Comments
 (0)