From ad2b70e819e6a749d1d54ce0dffc426bd7aefe11 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Mon, 3 Jul 2023 19:04:04 -0700 Subject: [PATCH] Update ElementToggle to use CSS modules --- components/ElementToggle/index.module.scss | 4 +- components/ElementToggle/index.tsx | 70 +++++++++++++++++----- 2 files changed, 57 insertions(+), 17 deletions(-) diff --git a/components/ElementToggle/index.module.scss b/components/ElementToggle/index.module.scss index d1910810..4d0589c4 100644 --- a/components/ElementToggle/index.module.scss +++ b/components/ElementToggle/index.module.scss @@ -1,4 +1,4 @@ -.ToggleGroup { +.group { $height: 36px; background-color: var(--toggle-bg); @@ -15,7 +15,7 @@ height: auto; } - .ToggleItem { + .item { background: var(--toggle-bg); border: none; border-radius: 18px; diff --git a/components/ElementToggle/index.tsx b/components/ElementToggle/index.tsx index 0e5cefbb..b87e85fb 100644 --- a/components/ElementToggle/index.tsx +++ b/components/ElementToggle/index.tsx @@ -1,74 +1,114 @@ -import React from 'react' +import React, { useEffect, useState } from 'react' import { useRouter } from 'next/router' import { useTranslation } from 'next-i18next' +import classNames from 'classnames' import * as ToggleGroup from '@radix-ui/react-toggle-group' - import styles from './index.module.scss' interface Props { currentElement: number - sendValue: (value: string) => void + sendValue: (value: number) => void } -const ElementToggle = (props: Props) => { +const ElementToggle = ({ currentElement, sendValue, ...props }: Props) => { + // Router and localization const router = useRouter() - const { t } = useTranslation('common') const locale = router.locale && ['en', 'ja'].includes(router.locale) ? router.locale : 'en' + const { t } = useTranslation('common') + + // State: Component + const [element, setElement] = useState(currentElement) + + // Methods: Handlers + const handleElementChange = (value: string) => { + const newElement = parseInt(value) + setElement(newElement) + sendValue(newElement) + } + + // Methods: Rendering return ( {t('elements.null')} {t('elements.wind')} {t('elements.fire')} {t('elements.water')} {t('elements.earth')} {t('elements.dark')}