diff --git a/readme.md b/readme.md index 9354666..c2621d0 100644 --- a/readme.md +++ b/readme.md @@ -34,7 +34,7 @@ $ npm run preview - [x] 基础 tag 栏展示 - [x] tag 栏用户自定义排序 - [x] tag 栏放缩动画 -- [x] 根据tag栏进行重新查询 +- [x] 根据 tag 栏进行重新查询 ## TODO @@ -43,6 +43,7 @@ $ npm run preview - [ ] UI 设计 - [ ] 搜索功能 - [ ] 图片加载序列 +- [ ] header 栏根据滚动进行显示隐藏 ### 现在还没定论的 diff --git a/src/components/proview/searchFocus.tsx b/src/components/proview/searchFocus.tsx new file mode 100644 index 0000000..10dba9b --- /dev/null +++ b/src/components/proview/searchFocus.tsx @@ -0,0 +1,33 @@ +import { useState, useContext, createContext } from "react"; +import { ReactChildrenType } from "./type"; + +type SearchcontextType = { + focused: boolean; + bind: { + onFocus: () => void; + onBlur: () => void; + }; +}; + +const SearchFocusContext = createContext({ + focused: false, + bind: { + onFocus() {}, + onBlur() {}, + }, +}); + +const SearchFocuspreview = ({ children }: ReactChildrenType) => { + const [focused, set] = useState(false), + onFocus = () => set(true), + onBlur = () => set(false); + return ( + + {children} + + ); +}; + +export const useSearchFocus = () => useContext(SearchFocusContext); + +export default SearchFocuspreview; diff --git a/src/main.tsx b/src/main.tsx index 86b6142..4f2681f 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -16,6 +16,7 @@ import "./normalize.css"; import "loading-attribute-polyfill"; import "whatwg-fetch"; import "./index.less"; +import SearchFocuspreview from "@components/proview/searchFocus"; const router = createBrowserRouter([ { @@ -54,9 +55,11 @@ const router = createBrowserRouter([ ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render( - - - + + + + + ); diff --git a/src/routers/layout/header.tsx b/src/routers/layout/header.tsx index 04408e1..3f6ba06 100644 --- a/src/routers/layout/header.tsx +++ b/src/routers/layout/header.tsx @@ -1,46 +1,25 @@ -import SearchSharpIcon from "@mui/icons-material/SearchSharp"; -import { Form } from "react-router-dom"; +import { useSearchFocus } from "@components/proview/searchFocus"; +import { Flipped } from "react-flip-toolkit"; import styles from "./layout.module.less"; -import { useFocus } from "./hooks"; import LOGO from "./logo"; import RightSide from "./rightSide"; +import Search from "./search"; export default function Header() { + const { focused } = useSearchFocus(); return ( -
- - - -
+ +
+ {!focused && } + + {!focused && } +
+
); } //todo 换掉header -//todo 添加搜索 -function Search() { - const { focused, bind } = useFocus(); - return ( - <> -
-
-
- -
-
- -
-
-
- - ); -} diff --git a/src/routers/layout/hooks.ts b/src/routers/layout/hooks.ts deleted file mode 100644 index 1ef3550..0000000 --- a/src/routers/layout/hooks.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { useState } from "react"; - -export const useFocus = () => { - const [focused, set] = useState(false); - return { - focused, - bind: { - onFocus: () => set(true), - onBlur: () => set(false), - }, - }; -}; diff --git a/src/routers/layout/index.tsx b/src/routers/layout/index.tsx index 6a63ba7..20d8952 100644 --- a/src/routers/layout/index.tsx +++ b/src/routers/layout/index.tsx @@ -4,13 +4,26 @@ import Header from "./header"; import Header_Nav from "./nav"; import { useAppSelector } from "@store/hooks"; import { selectNavMoreShowed } from "@store/device/index"; +import { useSearchFocus } from "@components/proview/searchFocus"; +import styles from "./layout.module.less"; export default function Layout() { - const showed = useAppSelector(selectNavMoreShowed); + const showed = useAppSelector(selectNavMoreShowed), + { focused } = useSearchFocus(); return ( <> - +
-