Skip to content

Commit 477305d

Browse files
committed
feat: refactored the code for better readability based on codeabbitai suggestion
1 parent a98e9cf commit 477305d

File tree

1 file changed

+45
-48
lines changed

1 file changed

+45
-48
lines changed

packages/ui/src/components/BottomNavigation/BottomNavigationItem.tsx

Lines changed: 45 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,35 @@ export interface BottomNavigationItemProps extends Omit<ComponentProps<"button">
2525
showLabel?: boolean;
2626
}
2727

28+
interface BottomNavItemBtnProps {
29+
reactId: string;
30+
customClassName: string;
31+
icon: FC<ComponentProps<"svg">>;
32+
theme: DeepPartial<FlowbiteBottomNavigationItemTheme>;
33+
label: string;
34+
showLabel: boolean;
35+
}
36+
37+
const BottomNavItemBtn: FC<BottomNavItemBtnProps> = (props) => {
38+
const { icon: Icon, customClassName = "", reactId, label, showLabel, theme: customTheme = {}, ...rest } = props;
39+
40+
const theme = mergeDeep(getTheme().bottomNavigation.item, customTheme);
41+
42+
return (
43+
<button
44+
type="button"
45+
id={reactId}
46+
data-testid="flowbite-bottom-nav-item"
47+
className={twMerge(theme.base, customClassName)}
48+
{...rest}
49+
>
50+
<Icon className={theme.icon.base} data-testid="flowbite-bottom-nav-icon" fill="currentColor" aria-hidden="true" />
51+
52+
{showLabel ? <span className={theme.label}>{label}</span> : null}
53+
</button>
54+
);
55+
};
56+
2857
export const BottomNavigationItem: FC<BottomNavigationItemProps> = ({
2958
icon: Icon,
3059
label,
@@ -36,8 +65,6 @@ export const BottomNavigationItem: FC<BottomNavigationItemProps> = ({
3665
}) => {
3766
const id = useId();
3867

39-
const theme = mergeDeep(getTheme().bottomNavigation.item, customTheme);
40-
4168
return (
4269
<>
4370
{showTooltip ? (
@@ -49,56 +76,26 @@ export const BottomNavigationItem: FC<BottomNavigationItemProps> = ({
4976
}
5077
placement="top"
5178
>
52-
<button
53-
type="button"
54-
id={id}
55-
data-testid="flowbite-bottom-nav-item"
56-
className={twMerge(theme.base, className)}
79+
<BottomNavItemBtn
80+
icon={Icon ? Icon : IoMdHome}
81+
customClassName={className as string}
82+
label={label}
83+
reactId={id}
84+
showLabel={showLabel}
85+
theme={customTheme}
5786
{...props}
58-
>
59-
{Icon ? (
60-
<Icon
61-
className={theme.icon.base}
62-
data-testid="flowbite-bottom-nav-icon"
63-
fill="currentColor"
64-
aria-hidden="true"
65-
/>
66-
) : (
67-
<IoMdHome
68-
className={theme.icon.base}
69-
data-testid="flowbite-bottom-nav-icon"
70-
fill="currentColor"
71-
aria-hidden="true"
72-
/>
73-
)}
74-
{showLabel ? <span className={theme.label}>{label}</span> : null}
75-
</button>
87+
/>
7688
</Tooltip>
7789
) : (
78-
<button
79-
type="button"
80-
id={id}
81-
data-testid="flowbite-bottom-nav-item"
82-
className={twMerge(theme.base, className)}
90+
<BottomNavItemBtn
91+
icon={Icon ? Icon : IoMdHome}
92+
customClassName={className as string}
93+
label={label}
94+
reactId={id}
95+
showLabel={showLabel}
96+
theme={customTheme}
8397
{...props}
84-
>
85-
{Icon ? (
86-
<Icon
87-
className={theme.icon.base}
88-
data-testid="flowbite-bottom-nav-icon"
89-
fill="currentColor"
90-
aria-hidden="true"
91-
/>
92-
) : (
93-
<IoMdHome
94-
className={theme.icon.base}
95-
data-testid="flowbite-bottom-nav-icon"
96-
fill="currentColor"
97-
aria-hidden="true"
98-
/>
99-
)}
100-
{showLabel ? <span className={theme.label}>{label}</span> : null}
101-
</button>
98+
/>
10299
)}
103100
</>
104101
);

0 commit comments

Comments
 (0)