Skip to content

Commit

Permalink
fix(types): create generic type for CheckPicker and MultiSelect
Browse files Browse the repository at this point in the history
  • Loading branch information
claire2212 authored and maximeperraultdev committed Dec 17, 2024
1 parent 75c5e6d commit b09f859
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 44 deletions.
27 changes: 5 additions & 22 deletions src/fields/CheckPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,19 @@ import { FieldError } from '../elements/FieldError'
import { Label } from '../elements/Label'
import { useFieldUndefineEffect } from '../hooks/useFieldUndefineEffect'
import { useForceUpdate } from '../hooks/useForceUpdate'
import { type CustomSearch } from '../libs/CustomSearch'
import { type Option, type OptionValueType } from '../types/definitions'
import { type OptionValueType } from '../types/definitions'
import { getRsuiteDataItemsFromOptions } from '../utils/getRsuiteDataItemsFromOptions'
import { getRsuiteDataItemValuesFromOptionValues } from '../utils/getRsuiteDataItemValuesFromOptionValues'
import { normalizeString } from '../utils/normalizeString'

import type { Promisable } from 'type-fest'
import type { SelectType } from '@types_/commonTypes'

export type CheckPickerProps<OptionValue extends OptionValueType = string> = Omit<
RsuiteCheckPickerProps<string>,
'as' | 'container' | 'data' | 'defaultValue' | 'id' | 'onChange' | 'renderMenuItem' | 'value' | 'valueKey'
> & {
customSearch?: CustomSearch<Option<OptionValue>>
/** Minimum search query length required to trigger custom search filtering. */
customSearchMinQueryLength?: number | undefined
error?: string | undefined
isErrorMessageHidden?: boolean | undefined
isLabelHidden?: boolean | undefined
isLight?: boolean | undefined
isRequired?: boolean | undefined
isTransparent?: boolean | undefined
isUndefinedWhenDisabled?: boolean | undefined
label: string
name: string
onChange?: (nextValue: OptionValue[] | undefined) => Promisable<void>
optionValueKey?: keyof OptionValue | undefined
options: Option<OptionValue>[]
popupWidth?: number | undefined
value?: OptionValue[] | undefined
}
> &
SelectType<OptionValue>

export function CheckPicker<OptionValue extends OptionValueType = string>({
className,
customSearch,
Expand Down
27 changes: 5 additions & 22 deletions src/fields/MultiSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,19 @@ import { Label } from '../elements/Label'
import { useFieldUndefineEffect } from '../hooks/useFieldUndefineEffect'
import { useForceUpdate } from '../hooks/useForceUpdate'
import { useKey } from '../hooks/useKey'
import { type CustomSearch } from '../libs/CustomSearch'
import { type Option, type OptionValueType } from '../types/definitions'
import { type OptionValueType } from '../types/definitions'
import { getRsuiteDataItemsFromOptions } from '../utils/getRsuiteDataItemsFromOptions'
import { getRsuiteDataItemValueFromOptionValue } from '../utils/getRsuiteDataItemValueFromOptionValue'
import { normalizeString } from '../utils/normalizeString'

import type { Promisable } from 'type-fest'
import type { SelectType } from '@types_/commonTypes'

export type MultiSelectProps<OptionValue extends OptionValueType = string> = Omit<
TagPickerProps,
'as' | 'container' | 'data' | 'defaultValue' | 'id' | 'onChange' | 'renderMenuItem' | 'value' | 'valueKey'
> & {
customSearch?: CustomSearch<Option<OptionValue>>
/** Minimum search query length required to trigger custom search filtering. */
customSearchMinQueryLength?: number | undefined
error?: string | undefined
isErrorMessageHidden?: boolean | undefined
isLabelHidden?: boolean | undefined
isLight?: boolean | undefined
isRequired?: boolean | undefined
isTransparent?: boolean | undefined
isUndefinedWhenDisabled?: boolean | undefined
label: string
name: string
onChange?: (nextValue: OptionValue[] | undefined) => Promisable<void>
optionValueKey?: keyof OptionValue | undefined
options: Option<OptionValue>[]
popupWidth?: number | undefined
value?: OptionValue[] | undefined
}
> &
SelectType<OptionValue>

export function MultiSelect<OptionValue extends OptionValueType = string>({
className,
customSearch,
Expand Down
23 changes: 23 additions & 0 deletions src/types/commonTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { Option, OptionValueType } from './definitions'
import type { CustomSearch } from '@libs/CustomSearch'
import type { Promisable } from 'type-fest'

export interface SelectType<OptionValue extends OptionValueType = string> {
customSearch?: CustomSearch<Option<OptionValue>>
/** Minimum search query length required to trigger custom search filtering. */
customSearchMinQueryLength?: number | undefined
error?: string | undefined
isErrorMessageHidden?: boolean | undefined
isLabelHidden?: boolean | undefined
isLight?: boolean | undefined
isRequired?: boolean | undefined
isTransparent?: boolean | undefined
isUndefinedWhenDisabled?: boolean | undefined
label: string
name: string
onChange?: (nextValue: OptionValue[] | undefined) => Promisable<void>
optionValueKey?: keyof OptionValue | undefined
options: Option<OptionValue>[]
popupWidth?: number | undefined
value?: OptionValue[] | undefined
}

0 comments on commit b09f859

Please sign in to comment.