Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: better select prop types to match antd exports #486

Merged
merged 9 commits into from
Nov 13, 2024
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import React from 'react'
import { Select } from 'antd'
import { useMemo, useState } from 'react'
import { DateRangeString, type IDateRangeStringProps } from './DateRangeString'
import type { RangePickerProps } from 'antd/es/date-picker'
import type { BaseOptionType, DefaultOptionType } from 'antd/es/select'
import dayjs from 'dayjs'
import { DatePicker, Divider, Flex, type ISelectProps, Typography } from 'src/components'
import { Select, DatePicker, Divider, Flex, type ISelectProps, Typography } from 'src/components'
import type { IRangePickerProps } from 'src/components/data-entry/DatePicker/DatePicker'
import type { SelectBaseOptionType, SelectDefaultOptionType } from 'src/components/data-entry/Select/Select'

export type SelectWithRangePickerValue<ValueType> = ValueType | [string, string] | null

Expand All @@ -16,7 +15,7 @@ interface SelectWithRangePickerProps<ValueType, OptionType>
'open' | 'value' | 'dropdownRender' | 'defaultValue' | 'mode'
> {
value: SelectWithRangePickerValue<ValueType>
rangePickerProps?: Omit<RangePickerProps, 'value' | 'onChange'>
rangePickerProps?: Omit<IRangePickerProps, 'value' | 'onChange'>
rangePickerLabel?: React.ReactNode
formatOptions?: IDateRangeStringProps['formatOptions']
}
Expand All @@ -25,7 +24,7 @@ const DEFAULT_PICKER_LABEL = <Typography.Text>Custom date range</Typography.Text

export const SelectWithRangePicker = <
ValueType = SelectWithRangePickerValue<unknown>,
OptionType extends BaseOptionType | DefaultOptionType = DefaultOptionType,
OptionType extends SelectBaseOptionType | SelectDefaultOptionType = SelectDefaultOptionType,
>({
value,
rangePickerProps = {},
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mparticle/aquarium",
"version": "1.34.0",
"version": "1.34.1-chore-better-select-prop-types.1",
"description": "mParticle Component Library",
"license": "Apache-2.0",
"keywords": [
Expand Down
24 changes: 15 additions & 9 deletions src/components/data-entry/Select/Select.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import { Select as AntSelect } from 'antd'
import { type SelectProps as AntSelectProps } from 'antd'
import { type BaseOptionType, type DefaultOptionType } from 'antd/es/select'
import { ConfigProvider } from 'src/components'
import type { SelectProps as AntSelectProps } from 'antd'
import type { BaseOptionType as AntBaseOptionType, DefaultOptionType as AntDefaultOptionType } from 'antd/es/select'
import { ConfigProvider, Icon } from 'src/components'

export type { DefaultOptionType }
export type SelectBaseOptionType = AntBaseOptionType
export type SelectDefaultOptionType = AntDefaultOptionType

export interface ISelectProps<
ValueType = any,
OptionType extends BaseOptionType | DefaultOptionType = DefaultOptionType,
> extends AntSelectProps<ValueType, OptionType> {}
SelectValueType = unknown,
SelectOptionType extends SelectBaseOptionType | SelectDefaultOptionType = SelectDefaultOptionType,
> extends AntSelectProps<SelectValueType, SelectOptionType> {}

export const Select = (props: ISelectProps) => {
export const Select = <
SelectValueType,
SelectOptionType extends SelectBaseOptionType | SelectDefaultOptionType = SelectDefaultOptionType,
>(
props: ISelectProps<SelectValueType, SelectOptionType>,
) => {
return (
<ConfigProvider>
<AntSelect {...props} />
<AntSelect suffixIcon={<Icon name="dropdownOpen" size="sm" />} {...props} />
</ConfigProvider>
)
}
Expand Down