Skip to content

Commit b8bd57d

Browse files
committed
chore: move MobileCloseBar to external component
1 parent 76b99d5 commit b8bd57d

File tree

2 files changed

+32
-22
lines changed

2 files changed

+32
-22
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { MouseEventHandler } from "react"
2+
import { useTranslation } from "next-i18next"
3+
import { Flex } from "@chakra-ui/react"
4+
5+
import { Button } from "@/components/Buttons"
6+
7+
type MobileCloseBarProps = {
8+
handleClick: MouseEventHandler<HTMLButtonElement>
9+
}
10+
11+
export const MobileCloseBar = ({ handleClick }: MobileCloseBarProps) => {
12+
const { t } = useTranslation()
13+
14+
return (
15+
<Flex
16+
justifyContent="end"
17+
hideFrom="md"
18+
position="sticky"
19+
zIndex="sticky"
20+
top="0"
21+
bg="background.base"
22+
>
23+
<Button p="4" variant="ghost" alignSelf="end" onClick={handleClick}>
24+
{t("close")}
25+
</Button>
26+
</Flex>
27+
)
28+
}

src/components/LanguagePicker/index.tsx

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ import {
1818

1919
import { LocaleDisplayInfo } from "@/lib/types"
2020

21-
import { Button } from "@/components/Buttons"
2221
import { BaseLink } from "@/components/Link"
2322

2423
import { isMobile } from "@/lib/utils/isMobile"
2524

2625
import MenuItem from "./MenuItem"
26+
import { MobileCloseBar } from "./MobileCloseBar"
2727
import NoResultsCallout from "./NoResultsCallout"
2828
import { useLanguagePicker } from "./useLanguagePicker"
2929

@@ -76,26 +76,6 @@ const LanguagePicker = ({
7676
eventName: "/contributing/translation-program",
7777
})
7878

79-
const MobileCloseBar = () => (
80-
<Flex
81-
justifyContent="end"
82-
hideFrom="md"
83-
position="sticky"
84-
zIndex="sticky"
85-
top="0"
86-
bg="background.base"
87-
>
88-
<Button
89-
p="4"
90-
variant="ghost"
91-
alignSelf="end"
92-
onClick={handleMobileCloseBarClick}
93-
>
94-
{t("common:close")}
95-
</Button>
96-
</Flex>
97-
)
98-
9979
return (
10080
<Menu isLazy placement={placement} autoSelect={false} {...disclosure}>
10181
{children}
@@ -114,7 +94,9 @@ const LanguagePicker = ({
11494
>
11595
{/* Mobile Close bar */}
11696
{/* avoid rendering mobile only feature on desktop */}
117-
{isMobile() && <MobileCloseBar />}
97+
{isMobile() && (
98+
<MobileCloseBar handleClick={handleMobileCloseBarClick} />
99+
)}
118100

119101
{/* Main Language selection menu */}
120102
<Box

0 commit comments

Comments
 (0)