📅  最后修改于: 2023-12-03 15:34:39.800000             🧑  作者: Mango
React-Drop-Down-Lite是一个React组件,它提供了一个轻量级的下拉菜单,具有简单的配置和定制选项。它可以容易地与现有的React应用程序集成,并且非常适合快速添加下拉菜单到网站或Web应用程序中。
npm install react-drop-down-lite --save
import React, { useState } from 'react';
import DropDownLite from 'react-drop-down-lite';
const options = [
{ value: '1', label: 'Option 1' },
{ value: '2', label: 'Option 2' },
{ value: '3', label: 'Option 3' },
];
function App() {
const [selectedOption, setSelectedOption] = useState(null);
const handleSelect = (option) => {
setSelectedOption(option);
};
return (
<div>
<h1>React-Drop-Down-Lite</h1>
<DropDownLite
options={options}
selected={selectedOption}
onSelect={handleSelect}
/>
</div>
);
}
export default App;
| 属性 | 描述 | 类型 | 默认值 | |----------------|------------------------------------------|--------------|----------| | options | 下拉菜单选项数组 | Array
import React, { useState } from 'react';
import DropDownLite from 'react-drop-down-lite';
const options = [
{ value: '1', label: 'Option 1' },
{ value: '2', label: 'Option 2' },
{ value: '3', label: 'Option 3' },
];
function App() {
const [selectedOption, setSelectedOption] = useState(null);
const handleSelect = (option) => {
setSelectedOption(option);
};
return (
<div>
<h2>Default DropDown:</h2>
<DropDownLite
options={options}
selected={selectedOption}
onSelect={handleSelect}
/>
<h2>Disabled DropDown:</h2>
<DropDownLite
options={options}
selected={selectedOption}
onSelect={handleSelect}
disabled
/>
<h2>Custom Styles:</h2>
<DropDownLite
options={options}
selected={selectedOption}
onSelect={handleSelect}
containerStyle={{ padding: '20px', border: '1px solid #ccc' }}
menuStyle={{ backgroundColor: '#fff', borderRadius: '4px', boxShadow: '0 2px 4px rgba(0,0,0,0.1)' }}
toggleStyle={{ color: '#333' }}
itemStyle={{ color: '#333', padding: '5px 10px' }}
placeholder='Please select'
/>
</div>
);
}
export default App;
React-Drop-Down-Lite是一个非常简单易用的React下拉菜单组件,具有很多定制选项,帮助你快速添加下拉菜单到你的React应用程序中。希望你会喜欢并使用它,在你的项目中实现更好的用户体验。