From 9fc27318f62950dea647a3ab9918f17690e542fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ula=C5=9F=20Bayraktar?= Date: Fri, 5 Apr 2024 05:50:42 +0300 Subject: [PATCH] Update LanguageSelect.tsx --- .../src/components/site/LanguageSelect.tsx | 72 ++++++++++++------- 1 file changed, 48 insertions(+), 24 deletions(-) diff --git a/frontend/src/components/site/LanguageSelect.tsx b/frontend/src/components/site/LanguageSelect.tsx index 22073d096..58c5d6828 100644 --- a/frontend/src/components/site/LanguageSelect.tsx +++ b/frontend/src/components/site/LanguageSelect.tsx @@ -1,7 +1,6 @@ import { useDisclosure, useBreakpointValue } from "@chakra-ui/react"; -import { Box, Text, Modal, ModalBody, ModalCloseButton, ModalContent, ModalHeader, ModalOverlay, Grid, Flex, Image } from "@chakra-ui/react"; -import { RadioGroup, useRadio, useRadioGroup, UseRadioProps } from "@chakra-ui/radio"; // Import UseRadioProps -import { VisuallyHidden } from "@chakra-ui/visually-hidden"; +import { Box, Text, Modal, ModalBody, ModalCloseButton, ModalContent, ModalHeader, ModalOverlay, Flex, Image, Grid } from "@chakra-ui/react"; +import { RadioGroup, useRadio, useRadioGroup, UseRadioProps } from "@chakra-ui/radio"; import { useRouter } from "next/router"; import { FC, forwardRef, useCallback, useImperativeHandle, useState } from "react"; import getLanguageName from "src/utils/getLanguageName"; @@ -26,6 +25,7 @@ const LanguageSelect = forwardRef(({ title }: Props, ref) => { const modalSize = useBreakpointValue({ base: "full", md: "5xl" }); const flagSize = useBreakpointValue({ base: 6, md: 10 }); + const isMobile = useBreakpointValue({ base: true, md: false }); // Check if mobile screen const { getRadioProps } = useRadioGroup({ name: "language", @@ -83,26 +83,50 @@ const LanguageSelect = forwardRef(({ title }: Props, ref) => { Change language from {getLanguageName(locale)} - - {locales.map((value: string, index: number) => { - const radio = getRadioProps({ value }); - return ( - handleButtonClick(value, index)} - isActive={index === clickedIndex} - isDisabled={isButtonDisabled} - flagSize={flagSize} - > - - {getLanguageName(value)} - Flag - - - ); - })} - + {/* Conditionally apply flexbox layout for mobile screens */} + {isMobile ? ( + + {locales.map((value: string, index: number) => { + const radio = getRadioProps({ value }); + return ( + handleButtonClick(value, index)} + isActive={index === clickedIndex} + isDisabled={isButtonDisabled} + flagSize={flagSize} + > + + Flag + {getLanguageName(value)} + + + ); + })} + + ) : ( + + {locales.map((value: string, index: number) => { + const radio = getRadioProps({ value }); + return ( + handleButtonClick(value, index)} + isActive={index === clickedIndex} + isDisabled={isButtonDisabled} + flagSize={flagSize} + > + + {getLanguageName(value)} + Flag + + + ); + })} + + )} @@ -110,7 +134,7 @@ const LanguageSelect = forwardRef(({ title }: Props, ref) => { ); }); -const LanguageSelectItem: FC<{ onClick: () => void; isActive: boolean; isDisabled: boolean; flagSize: number } & UseRadioProps> = ({ // Add UseRadioProps to the component props +const LanguageSelectItem: FC<{ onClick: () => void; isActive: boolean; isDisabled: boolean; flagSize: number } & UseRadioProps> = ({ onClick, isActive, isDisabled,