From 95733902b78d55ec7462d7e60a0f0d93110a54eb Mon Sep 17 00:00:00 2001 From: Aleksandr Vetchinkin Date: Sun, 18 Aug 2024 00:37:48 +0300 Subject: [PATCH] refactor(select): move Select and upgrade types --- .../Ui}/Select/index.sass | 0 .../Ui}/Select/index.tsx | 22 ++++++++----------- 2 files changed, 9 insertions(+), 13 deletions(-) rename src/{Components => Shared/Ui}/Select/index.sass (100%) rename src/{Components => Shared/Ui}/Select/index.tsx (51%) diff --git a/src/Components/Select/index.sass b/src/Shared/Ui/Select/index.sass similarity index 100% rename from src/Components/Select/index.sass rename to src/Shared/Ui/Select/index.sass diff --git a/src/Components/Select/index.tsx b/src/Shared/Ui/Select/index.tsx similarity index 51% rename from src/Components/Select/index.tsx rename to src/Shared/Ui/Select/index.tsx index d5777ab..9529a62 100644 --- a/src/Components/Select/index.tsx +++ b/src/Shared/Ui/Select/index.tsx @@ -1,21 +1,17 @@ +import { ChangeEventHandler } from "react" import "./index.sass" -type value = string +export type SelectOption = { value: string; title: string } -export type Select = Array<{ - value: value - title: string -}> - -type selectProps = { - value: value - options: Select - onChange?: (value: value) => void +interface SelectProps { + value: string + options: SelectOption[] + onChange: (value: string) => void } -export function Select({ value = null, options = [], onChange = null }: selectProps) { - const changeHandler = (e: React.ChangeEvent) => { - if (onChange) onChange(e.target.value) +export function Select({ value, options, onChange }: SelectProps) { + const changeHandler: ChangeEventHandler = (event) => { + onChange(event.target.value) } return (