Skip to content

Commit 76cb796

Browse files
committed
chore: rabbit-review
1 parent 1bd9a4c commit 76cb796

File tree

4 files changed

+19
-24
lines changed

4 files changed

+19
-24
lines changed

src/lib/accordion/accordion-item.tsx

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,19 @@ const AccordionItem: React.FC<AccordionItemProps> = ({
5757
setExpanded,
5858
}) => {
5959
const [ref, { height }] = useElementSize();
60-
const ExpandButton = useMemo(
61-
() =>
62-
expandButton ? (
63-
expandButton({
64-
expanded,
65-
toggle: () => setExpanded(expanded ? -1 : index),
66-
})
67-
) : expanded ? (
68-
<Minus
69-
className={cn("fill-klerosUIComponentsPrimaryText size-4 shrink-0")}
70-
/>
71-
) : (
72-
<Plus
73-
className={cn("fill-klerosUIComponentsPrimaryText size-4 shrink-0")}
74-
/>
75-
),
76-
[expanded, expandButton, index, setExpanded],
77-
);
60+
const ExpandButton = useMemo(() => {
61+
if (expandButton) {
62+
return expandButton({
63+
expanded,
64+
toggle: () => setExpanded(expanded ? -1 : index),
65+
});
66+
}
67+
const IconComponent = expanded ? Minus : Plus;
68+
return (
69+
<IconComponent className="fill-klerosUIComponentsPrimaryText size-4 shrink-0" />
70+
);
71+
}, [expanded, expandButton, index, setExpanded]);
72+
7873
return (
7974
<div className="my-2">
8075
<Button

src/lib/accordion/custom.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export interface CustomAccordionProps {
3535
* expandButton={({ expanded, toggle }) => (
3636
* <Button onPress={toggle}>
3737
* {expanded ? <ChevronUp /> : <ChevronDown />}
38-
* <Button>
38+
* </Button>
3939
* )}
4040
* ```
4141
*/
@@ -56,7 +56,7 @@ function CustomAccordion({
5656
...props
5757
}: Readonly<CustomAccordionProps>) {
5858
const [expanded, setExpanded] = useState(
59-
!isUndefined(defaultExpanded) ? defaultExpanded : -1,
59+
isUndefined(defaultExpanded) ? -1 : defaultExpanded,
6060
);
6161
return (
6262
<div

src/lib/accordion/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function Accordion({
4444
...props
4545
}: Readonly<AccordionProps>) {
4646
const [expanded, setExpanded] = useState(
47-
!isUndefined(defaultExpanded) ? defaultExpanded : -1,
47+
isUndefined(defaultExpanded) ? -1 : defaultExpanded,
4848
);
4949
return (
5050
<div

src/stories/custom-accordion.stories.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,11 @@ export const ItemExpandButton: Story = {
135135
),
136136
},
137137
],
138-
expandButton: (expanded) => {
138+
expandButton: ({ expanded, toggle }) => {
139139
return expanded ? (
140-
<Button text="Close" variant="secondary" />
140+
<Button text="Close" variant="secondary" onPress={toggle} />
141141
) : (
142-
<Button text="Expand" />
142+
<Button text="Expand" onPress={toggle} />
143143
);
144144
},
145145
themeUI: "dark",

0 commit comments

Comments
 (0)