From 19eff9e2a69e870ba1b481c9bfff1e955a81c0e3 Mon Sep 17 00:00:00 2001 From: theborakompanioni Date: Wed, 6 Dec 2023 16:54:06 +0100 Subject: [PATCH] refactor: SegmentedTab onChange handler props --- src/components/Earn.tsx | 4 +--- src/components/SegmentedTabs.module.css | 24 +++++++++---------- src/components/SegmentedTabs.tsx | 14 +++++------ .../jar_details/JarDetailsOverlay.tsx | 2 +- 4 files changed, 21 insertions(+), 23 deletions(-) diff --git a/src/components/Earn.tsx b/src/components/Earn.tsx index e2c57c11a..93c3e29b1 100644 --- a/src/components/Earn.tsx +++ b/src/components/Earn.tsx @@ -259,9 +259,7 @@ const EarnForm = ({ value: OFFERTYPE_REL, }, ]} - onChange={(tab, checked) => { - checked && setFieldValue('offertype', tab.value, true) - }} + onChange={(tab) => setFieldValue('offertype', tab.value, true)} value={values.offertype} disabled={isLoading || isSubmitting} /> diff --git a/src/components/SegmentedTabs.module.css b/src/components/SegmentedTabs.module.css index 337ad5f3e..51ca0598c 100644 --- a/src/components/SegmentedTabs.module.css +++ b/src/components/SegmentedTabs.module.css @@ -1,31 +1,31 @@ -.segmented-tabs { +.segmentedTabs { background-color: var(--bs-gray-300); border-radius: 0.25rem; padding: 0.25rem; width: 100%; } -.segmented-tab > label { +.segmentedTab > label { height: 100%; display: flex; flex-direction: column; justify-content: center; } -:root[data-theme='dark'] .segmented-tabs { +:root[data-theme='dark'] .segmentedTabs { color: var(--bs-gray-100); background-color: var(--bs-gray-800); } -.segmented-tab { +.segmentedTab { flex: 1 1 0; } -.segmented-tab input[type='radio'] { +.segmentedTab input[type='radio'] { display: none; } -.segmented-tab label { +.segmentedTab label { background-color: white; padding: 0.25rem 1rem; border-radius: 0.1rem; @@ -34,30 +34,30 @@ text-align: center; } -.segmented-tab input[type='radio']:disabled ~ label { +.segmentedTab input[type='radio']:disabled ~ label { background-color: transparent; color: var(--bs-gray-600); opacity: 0.5; } -:root[data-theme='dark'] .segmented-tab input[type='radio']:disabled ~ label { +:root[data-theme='dark'] .segmentedTab input[type='radio']:disabled ~ label { color: var(--bs-gray-600); opacity: 0.5; } -.segmented-tab input[type='radio']:not(:checked):not(:disabled) ~ label { +.segmentedTab input[type='radio']:not(:checked):not(:disabled) ~ label { background-color: transparent; } -.segmented-tab input[type='radio']:not(:disabled) ~ label { +.segmentedTab input[type='radio']:not(:disabled) ~ label { cursor: pointer; } -.segmented-tab input[type='radio']:checked:not(:disabled) ~ label { +.segmentedTab input[type='radio']:checked:not(:disabled) ~ label { background-color: var(--bs-gray-100); box-shadow: 1px 1px 3px 1px rgba(0, 0, 0, 0.1); } -:root[data-theme='dark'] .segmented-tab input[type='radio']:checked:not(:disabled) ~ label { +:root[data-theme='dark'] .segmentedTab input[type='radio']:checked:not(:disabled) ~ label { background-color: var(--bs-gray-600); } diff --git a/src/components/SegmentedTabs.tsx b/src/components/SegmentedTabs.tsx index b9332fe85..b9367fcef 100644 --- a/src/components/SegmentedTabs.tsx +++ b/src/components/SegmentedTabs.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import { ChangeEvent } from 'react' import * as rb from 'react-bootstrap' import styles from './SegmentedTabs.module.css' @@ -10,14 +10,14 @@ interface SegmentedTab { } function SegmentedTabFormCheck(props: rb.FormCheckProps) { - const _onChange = (e: React.ChangeEvent) => { + const _onChange = (e: ChangeEvent) => { e.stopPropagation() props.onChange && props.onChange(e) } return ( <> - + ) } @@ -25,19 +25,19 @@ function SegmentedTabFormCheck(props: rb.FormCheckProps) { interface SegmentedTabsProps { name: string tabs: SegmentedTab[] - onChange: (tab: SegmentedTab, checked: boolean) => void + onChange: (tab: SegmentedTab) => void value?: SegmentedTabValue disabled?: boolean } export default function SegmentedTabs({ name, tabs, onChange, value, disabled = false }: SegmentedTabsProps) { - const _onChange = (e: React.ChangeEvent, tab: SegmentedTab) => { + const _onChange = (e: ChangeEvent, tab: SegmentedTab) => { e.stopPropagation() - onChange(tab, e.currentTarget.checked) + onChange(tab) } return ( -
+
{tabs.map((tab, index) => { return ( diff --git a/src/components/jar_details/JarDetailsOverlay.tsx b/src/components/jar_details/JarDetailsOverlay.tsx index dc1c3df85..ae5295c00 100644 --- a/src/components/jar_details/JarDetailsOverlay.tsx +++ b/src/components/jar_details/JarDetailsOverlay.tsx @@ -325,7 +325,7 @@ const JarDetailsOverlay = (props: JarDetailsOverlayProps) => { checked && setSelectedTab(tab.value)} + onChange={(tab) => setSelectedTab(tab.value)} value={selectedTab} />