Krishya | 7ec1dd0 | 2025-04-19 15:29:03 +0800 | [diff] [blame] | 1 | import React, { useState } from 'react'; |
| 2 | import './SearchBar.css'; |
| 3 | |
| 4 | const SearchBar = ({ onSearch }) => { |
| 5 | const [query, setQuery] = useState(''); |
| 6 | |
| 7 | const handleSearch = () => onSearch(query); |
| 8 | const handleReset = () => { |
| 9 | setQuery(''); |
| 10 | onSearch(''); |
| 11 | }; |
| 12 | |
| 13 | return ( |
| 14 | <div className="search-bar"> |
| 15 | <input |
| 16 | type="text" |
| 17 | value={query} |
| 18 | onChange={e => setQuery(e.target.value)} |
Krishya | f1d0ea8 | 2025-05-03 17:01:58 +0800 | [diff] [blame] | 19 | placeholder="输入要搜索的帖子" |
Krishya | 7ec1dd0 | 2025-04-19 15:29:03 +0800 | [diff] [blame] | 20 | className="search-input" |
| 21 | /> |
| 22 | <button onClick={handleSearch} className="search-btn">搜索</button> |
| 23 | <button onClick={handleReset} className="search-btn">重置</button> |
| 24 | </div> |
| 25 | ); |
| 26 | }; |
| 27 | |
| 28 | export default SearchBar; |