From c2eae70eb30c838fd5e14001c060b8b11fe4784d Mon Sep 17 00:00:00 2001 From: Pedro Vitor Date: Thu, 21 Dec 2023 16:02:46 -0300 Subject: [PATCH] feat: language switcher component for footer --- .../locale-switcher-footer/index.tsx | 82 +++++++++++++++++++ .../locale-switcher-footer/styles.ts | 52 ++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 src/components/locale-switcher-footer/index.tsx create mode 100644 src/components/locale-switcher-footer/styles.ts diff --git a/src/components/locale-switcher-footer/index.tsx b/src/components/locale-switcher-footer/index.tsx new file mode 100644 index 00000000..aba8ba21 --- /dev/null +++ b/src/components/locale-switcher-footer/index.tsx @@ -0,0 +1,82 @@ +import { useRouter } from 'next/router' +import { Box, IconGlobe, Text, IconCaret, Flex } from '@vtex/brand-ui' +import styles from './styles' +import { Disclosure, DisclosureContent, useDisclosureState } from 'reakit' +import { LocaleOption } from '@vtex/brand-ui/dist/components/Header/LocaleSwitcher' + +interface OptionProps { + screen: 'mobile' | 'large' + option: LocaleOption + active: boolean + onClick?: () => void +} + +export default function LocaleSwitcherFooter() { + const router = useRouter() + const options: LocaleOption[] = [ + { + label: 'EN', + value: 'en', + }, + { + label: 'PT', + value: 'pt', + }, + { + label: 'ES', + value: 'es', + }, + ] + + const handleOptionClick = (option: string) => { + const locale = option + router.push(router.pathname, router.asPath, { locale }) + disclosure.hide() + } + const disclosure = useDisclosureState({ visible: false }) + const Option = ({ screen, option, onClick, active }: OptionProps) => { + const variant = `localeSwitcher.${screen}.option` + + return ( + + {option.label} + + ) + } + + return ( + + + + + {router.locale?.toUpperCase()} + + + + + + {options.map((option) => ( + + + + + ) +} diff --git a/src/components/locale-switcher-footer/styles.ts b/src/components/locale-switcher-footer/styles.ts new file mode 100644 index 00000000..ba85593f --- /dev/null +++ b/src/components/locale-switcher-footer/styles.ts @@ -0,0 +1,52 @@ +import { SxStyleProp } from '@vtex/brand-ui' + +const localeLabel: SxStyleProp = { + color: 'white', + pl: 2, + display: 'block', +} + +const optionContainer: SxStyleProp = { + color: 'black', + position: 'absolute', + display: 'flex', + flexDirection: 'column', + // width: '11rem', + marginRight: '10px', + top: 'auto', + right: '0', + bottom: '100%', + px: 5, + // border: '1px solid #e7e9ed', + borderTop: 'none', + backgroundColor: '#ffffff', + boxShadow: '0px 20px 25px rgba(20, 32, 50, 0.1)', +} + +const baseLocaleSwitcher: SxStyleProp = { + alignItems: 'center', + cursor: 'pointer', + bg: 'transparent', + border: 'none', + outline: 'none', +} + +const localeSwitcher: SxStyleProp = { + position: 'relative', + button: { + ...baseLocaleSwitcher, + display: 'flex', + ':hover': { + color: '#142032', + }, + height: '100%', + justifyContent: 'flex-start', + }, +} + +export default { + localeLabel, + optionContainer, + localeSwitcher, + baseLocaleSwitcher, +}