Files
portainer/app/react/components/form-components/PortainerSelectCustomRenderers.tsx
LP B 0c2f07988a feat(app/sources): source create view (#2680)
Co-authored-by: Chaim Lev-Ari <chaim.lev-ari@portainer.io>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-10 21:34:46 +03:00

50 lines
1.3 KiB
TypeScript

import {
GroupBase,
OptionProps,
SingleValueProps,
SelectComponentsConfig,
components,
} from 'react-select';
import { ReactNode } from 'react';
import { Option } from './PortainerSelect';
export function CustomComponents<TValue>(
render: (data: Option<TValue>) => ReactNode
): SelectComponentsConfig<Option<TValue>, false, GroupBase<Option<TValue>>> {
return {
Option: CustomOption(render),
SingleValue: CustomSingleValue(render),
};
}
function CustomOption<TValue>(render: (data: Option<TValue>) => ReactNode) {
return function CustomOptionRenderer({
data,
...props
}: OptionProps<Option<TValue>, false, GroupBase<Option<TValue>>>) {
return (
// eslint-disable-next-line react/jsx-props-no-spreading
<components.Option data={data} {...props}>
{render(data)}
</components.Option>
);
};
}
function CustomSingleValue<TValue>(
render: (data: Option<TValue>) => ReactNode
) {
return function CustomOptionRenderer({
data,
...props
}: SingleValueProps<Option<TValue>, false, GroupBase<Option<TValue>>>) {
return (
// eslint-disable-next-line react/jsx-props-no-spreading
<components.SingleValue data={data} {...props}>
{render(data)}
</components.SingleValue>
);
};
}