-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
21 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,30 @@ | ||
import { selectConfig, component, mergeConfig } from '@salutejs/plasma-new-hope/styled-components'; | ||
import type { SelectProps as SelectPropsNewHope, ItemOptionSelect } from '@salutejs/plasma-new-hope'; | ||
import { forwardRef, ComponentProps, ForwardedRef } from 'react'; | ||
import React, { forwardRef, ComponentProps, ForwardedRef } from 'react'; | ||
|
||
import { config } from './Select.config'; | ||
|
||
const mergedConfig = mergeConfig(selectConfig, config); | ||
const SelectNewHope = component(mergedConfig); | ||
|
||
type SelectProps<K extends ItemOptionSelect> = Omit< | ||
type DistributiveOmit<T, K extends keyof any> = T extends any ? Omit<T, K> : never; | ||
|
||
type DistributivePick<T, K extends keyof T> = T extends unknown ? Pick<T, K> : never; | ||
|
||
type SelectProps<K extends ItemOptionSelect> = DistributiveOmit< | ||
SelectPropsNewHope<K>, | ||
'size' | 'view' | 'chipView' | 'labelPlacement' | 'disabled' | ||
'size' | 'view' | 'chipView' | 'disabled' | ||
> & | ||
Pick<ComponentProps<typeof SelectNewHope>, 'size' | 'view' | 'chipView' | 'labelPlacement' | 'disabled'>; | ||
DistributivePick<ComponentProps<typeof SelectNewHope>, 'size' | 'view' | 'chipView' | 'disabled'>; | ||
|
||
// eslint-disable-next-line max-len | ||
// const SelectComponent = <K extends ItemOptionSelect>(props: SelectProps<K>, ref: ForwardedRef<HTMLButtonElement>) => ( | ||
// <SelectNewHope ref={ref} {...(props as any)} /> | ||
// ); | ||
// | ||
// const Select = forwardRef(SelectComponent); | ||
function fixedForwardRef<T, P = {}>( | ||
render: (props: P, ref: React.Ref<T>) => React.ReactElement | null, | ||
): (props: P & React.RefAttributes<T>) => React.ReactElement | null { | ||
return forwardRef(render as any) as any; | ||
} | ||
|
||
const Select = forwardRef(SelectNewHope as any) as <K extends ItemOptionSelect = ItemOptionSelect>( | ||
props: SelectProps<K> & { ref?: ForwardedRef<HTMLButtonElement> }, | ||
) => ReturnType<typeof SelectNewHope>; | ||
const SelectComponent = <K extends ItemOptionSelect>(props: SelectProps<K>, ref: ForwardedRef<HTMLButtonElement>) => { | ||
return <SelectNewHope ref={ref} {...(props as any)} />; | ||
}; | ||
|
||
export { Select }; | ||
export const Select = fixedForwardRef(SelectComponent); |