Shared: Selector: Fix types

This commit is contained in:
Aleksandr Lushkin 2024-04-04 14:03:34 +02:00
parent 0a7fa09721
commit 62fe4bfc74
4 changed files with 30 additions and 27 deletions

View File

@ -46,7 +46,7 @@ type PropsFromCombobox = Pick<
| "withBlur"
>;
export interface AccessRightSelectProps extends PropsFromCombobox {
export type AccessRightSelectProps = PropsFromCombobox & {
/** List of access options */
accessOptions: ComboboxProps["options"];
}
};

View File

@ -223,29 +223,32 @@ export type TAccessRight = {
access: string | number;
};
export type TSelectorAccessRights =
| {
withAccessRights: true;
accessRights: TAccessRight[];
selectedAccessRight: TAccessRight | null;
onAccessRightsChange: (access: TAccessRight) => void;
accessRightsMode?: SelectorAccessRightsMode;
}
| {
withAccessRights?: undefined;
accessRights?: undefined;
selectedAccessRight?: undefined;
onAccessRightsChange?: undefined;
accessRightsMode?: undefined;
};
export interface AccessSelectorProps {
onAccessRightsChange: (access: TAccessRight) => void;
type TWithAccessRightsProps = {
withAccessRights: true;
accessRights: TAccessRight[];
selectedOption: TAccessRight | null;
footerRef: React.RefObject<HTMLDivElement>;
selectedAccessRight: TAccessRight | null;
onAccessRightsChange: (access: TAccessRight) => void;
accessRightsMode?: SelectorAccessRightsMode;
}
};
type TWithoutAccessRightsProps = {
withAccessRights?: undefined;
accessRights?: undefined;
selectedAccessRight?: undefined;
onAccessRightsChange?: undefined;
accessRightsMode?: undefined;
};
export type TSelectorAccessRights =
| TWithAccessRightsProps
| TWithoutAccessRightsProps;
export type AccessSelectorProps = Omit<
TWithAccessRightsProps,
"withAccessRights"
> & {
footerRef: React.RefObject<HTMLDivElement>;
};
// footer input

View File

@ -12,7 +12,7 @@ const AccessSelector = (props: AccessSelectorProps) => {
const {
onAccessRightsChange,
accessRights,
selectedOption,
selectedAccessRight,
footerRef,
accessRightsMode = SelectorAccessRightsMode.Compact,
} = props;
@ -38,7 +38,7 @@ const AccessSelector = (props: AccessSelectorProps) => {
size={ComboBoxSize.content}
scaled={false}
manualWidth="fit-content"
selectedOption={selectedOption as TOption}
selectedOption={selectedAccessRight as TOption}
showDisabledItems
directionX="right"
directionY="top"
@ -47,7 +47,7 @@ const AccessSelector = (props: AccessSelectorProps) => {
) : (
<StyledAccessSelector
className=""
selectedOption={selectedOption as TOption}
selectedOption={selectedAccessRight as TOption}
onSelect={onSelect}
accessOptions={accessRights as TOption[]}
size={ComboBoxSize.content}

View File

@ -151,7 +151,7 @@ const Footer = React.memo(
{withAccessRights && (
<AccessSelector
accessRights={accessRights}
selectedOption={selectedAccessRight}
selectedAccessRight={selectedAccessRight}
onAccessRightsChange={onAccessRightsChange}
footerRef={ref}
accessRightsMode={accessRightsMode}