From bb14659a7e68b1d838f41acba55b725f2c6a1c16 Mon Sep 17 00:00:00 2001 From: Kyle Ramachandran Date: Sat, 7 Dec 2024 01:25:38 -0800 Subject: [PATCH] refactored FilterDropdownSingle to use Select --- app/seasonal-planting-guide/page.tsx | 9 ++-- components/FilterDropdownMultiple/index.tsx | 2 +- components/FilterDropdownMultiple/styles.ts | 2 +- components/FilterDropdownSingle/index.tsx | 57 +++++---------------- components/FilterDropdownSingle/styles.ts | 56 ++++++++++++++++++++ components/PlantCalendarList/index.tsx | 2 +- utils/helpers.ts | 3 +- 7 files changed, 77 insertions(+), 54 deletions(-) diff --git a/app/seasonal-planting-guide/page.tsx b/app/seasonal-planting-guide/page.tsx index 8821035..d7328cc 100644 --- a/app/seasonal-planting-guide/page.tsx +++ b/app/seasonal-planting-guide/page.tsx @@ -36,7 +36,7 @@ const plantingTypeOptions: DropdownOption[] = [ { label: 'Start Seeds Indoors', value: 'INDOORS' }, { label: 'Start Seeds Outdoors', value: 'OUTDOORS' }, { - label: 'Plant Seedlings/Transplant Outdoors', + label: 'Plant Seedlings / Transplant Outdoors', value: 'TRANSPLANT', }, ]; @@ -56,9 +56,8 @@ export default function SeasonalPlantingGuide() { const [selectedPlantingType, setSelectedPlantingType] = useState< DropdownOption[] >([]); - const [selectedUsState, setSelectedUsState] = useState< - DropdownOption - >({ label: '', value: '' }); + const [selectedUsState, setSelectedUsState] = + useState | null>(null); const [searchTerm, setSearchTerm] = useState(''); const clearFilters = () => { @@ -92,6 +91,7 @@ export default function SeasonalPlantingGuide() { placeholder="State" options={usStateOptions} disabled={!selectedUsState} + small={false} /> ) : ( diff --git a/components/FilterDropdownMultiple/index.tsx b/components/FilterDropdownMultiple/index.tsx index 53d831b..857c83f 100644 --- a/components/FilterDropdownMultiple/index.tsx +++ b/components/FilterDropdownMultiple/index.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React from 'react'; import Select, { ActionMeta, components, diff --git a/components/FilterDropdownMultiple/styles.ts b/components/FilterDropdownMultiple/styles.ts index cea95eb..3de92be 100644 --- a/components/FilterDropdownMultiple/styles.ts +++ b/components/FilterDropdownMultiple/styles.ts @@ -55,7 +55,7 @@ export const customSelectStyles: StylesConfig, true> = { multiValueLabel: baseStyles => ({ ...baseStyles, fontSize: '0.75rem', - color: `${COLORS.midgray} !important`, + color: `${COLORS.black} !important`, padding: '0px', paddingLeft: '0px', }), diff --git a/components/FilterDropdownSingle/index.tsx b/components/FilterDropdownSingle/index.tsx index d020b30..d263d14 100644 --- a/components/FilterDropdownSingle/index.tsx +++ b/components/FilterDropdownSingle/index.tsx @@ -1,22 +1,19 @@ -import React, { useState } from 'react'; -import Select, { - ActionMeta, - components, - GroupBase, - MultiValue, - OptionProps, - SingleValue, -} from 'react-select'; +import React from 'react'; +import Select, { ActionMeta, MultiValue, SingleValue } from 'react-select'; import { DropdownOption } from '@/types/schema'; -import { customSelectStyles } from '../FilterDropdownMultiple/styles'; -import { FilterDropdownInput } from './styles'; +import { customSelectStyles } from './styles'; interface FilterDropdownProps { - value: DropdownOption; - setStateAction: React.Dispatch>>; + value: DropdownOption | null; + setStateAction: React.Dispatch< + React.SetStateAction | null> + >; options: DropdownOption[]; placeholder: string; disabled?: boolean; + // for custom styling since initial dropdown to select user's state + // is a different size to a normal single dropdown + small: boolean; } export default function FilterDropdownSingle({ @@ -25,14 +22,8 @@ export default function FilterDropdownSingle({ options, placeholder, disabled, + small, }: FilterDropdownProps) { - const [isOpen, setIsOpen] = useState(false); - - // const handleChange = (event: React.ChangeEvent) => { - // setStateAction(event.target.value); - // setIsOpen(false); - // }; - const handleChange = ( selectedOptions: | SingleValue> @@ -44,31 +35,7 @@ export default function FilterDropdownSingle({ } }; - const handleToggle = () => { - setIsOpen(!isOpen); - }; - return ( - // setIsOpen(false)} - // value={value} - // $hasValue={value !== ''} - // disabled={disabled} - // > - // {/*Default placeholder text*/} - // - // {options.map((option, index) => ( - // - // ))} - //