Я должен сохранить два типа раскрывающегося списка в одном компоненте. И на основе реквизита я должен сделать это выбрать. PrettyPrint-Override ">import React, { useState } from 'react';
import { Select, TreeSelect, Input, Divider } from 'antd';
import styles from './styles.js'; // For styling
const treeData = [
{
title: 'Fruits',
value: 'fruits',
children: [
{ title: 'Apple', value: 'apple' },
{ title: 'Banana', value: 'banana' },
],
},
{
title: 'Vegetables',
value: 'vegetables',
children: [
{ title: 'Carrot', value: 'carrot' },
{ title: 'Tomato', value: 'tomato' },
],
},
];
const options = [
{ value: 'apple', label: 'Apple' },
{ value: 'banana', label: 'Banana' },
{ value: 'carrot', label: 'Carrot' },
{ value: 'tomato', label: 'Tomato' },
];
function CapUnifiedSelect({ mode, placeholder, onChange }) {
const [search, setSearch] = useState('');
const filteredOptions = options.filter(opt =>
opt.label.toLowerCase().includes(search.toLowerCase())
);
const filteredTreeData = treeData.map(parent => ({
...parent,
children: parent.children?.filter(child =>
child.title.toLowerCase().includes(search.toLowerCase())
),
}));
const renderPopup = (originNode) => (
setSearch(e.target.value)}
style={styles.search}
/>
{originNode}
);
if (mode === 'select' || mode === 'multiselect') {
return (
);
}
return (
);
}
export default CapUnifiedSelect;
Подробнее здесь: https://stackoverflow.com/questions/797 ... ant-design