Skip to content

Commit

Permalink
添加nav动画
Browse files Browse the repository at this point in the history
  • Loading branch information
master1lan committed Jan 9, 2023
1 parent 5a61f15 commit 8ba3867
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 40 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview",
"localdev":"vite --host 192.168.2.250"
"localdev": "vite --host 192.168.2.250"
},
"dependencies": {
"@dnd-kit/core": "^6.0.7",
Expand All @@ -26,6 +26,7 @@
"normalize.css": "^8.0.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-flip-toolkit": "^7.0.17",
"react-intersection-observer": "^9.4.1",
"react-photo-view": "^1.2.3",
"react-router-dom": "^6.6.1",
Expand Down
26 changes: 26 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/routers/layout/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import {
import Header_Nav from "./nav";
import styles from "./layout.module.less";
import { useFocus } from "./hooks";
import { ListShuffler } from "./test";
export default function Header() {
return (
<header>
<Search />
{/* <ListShuffler /> */}
<Header_Nav />
</header>
);
Expand Down
1 change: 1 addition & 0 deletions src/routers/layout/layout.module.less
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
position: relative;
overflow: hidden;
margin: 10px;
background-color: aquamarine;

.navstack {
overflow-x: auto;
Expand Down
89 changes: 50 additions & 39 deletions src/routers/layout/nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { nanoid } from "nanoid";
import styles from "./layout.module.less";
import { FC, useState, useEffect, useMemo, memo } from "react";
import { Pick } from "@utils/index";
import { Flipped, Flipper } from "react-flip-toolkit";
//todo 拆分组件
//todo 修改文件夹
export default function Header_Nav() {
Expand Down Expand Up @@ -68,27 +69,33 @@ export default function Header_Nav() {
[navLists]
);
return (
<div className={styles["nav"]}>
<DndContext
sensors={sensors}
collisionDetection={closestCenter}
onDragEnd={handleDragEnd}
modifiers={[restrictToParentElement]}
>
<Stack
direction='row'
alignItems='center'
className={`${styles["navstack"]}`}
style={{
display: showed ? "grid" : "flex",
}}
data-showed={showed}
>
<SortableContext items={navLists}>{ComRes}</SortableContext>
<NavInViewItem handlerClick={() => setShow((show) => !show)} />
</Stack>
</DndContext>
</div>
<Flipper flipKey={showed} decisionData={showed} spring={"veryGentle"}>
<Flipped flipId={"list"} spring={"veryGentle"}>
<div className={styles["nav"]}>
<DndContext
sensors={sensors}
collisionDetection={closestCenter}
onDragEnd={handleDragEnd}
modifiers={[restrictToParentElement]}
>
<Flipped inverseFlipId='list'>
<Stack
direction='row'
alignItems='center'
className={`${styles["navstack"]}`}
style={{
display: showed ? "grid" : "flex",
}}
data-showed={showed}
>
<SortableContext items={navLists}>{ComRes}</SortableContext>
<NavInViewItem handlerClick={() => setShow((show) => !show)} />
</Stack>
</Flipped>
</DndContext>
</div>
</Flipped>
</Flipper>
);
}

Expand All @@ -106,15 +113,17 @@ const NavInViewItem: FC<{
width: "1px",
}}
></span>
<div
className={styles["nav-right-show-btn"]}
onClick={handlerClick}
style={{
display: inView ? "none" : "flex",
}}
>
<SegmentIcon fontSize='medium' />
</div>
<Flipped flipId={"nav-right"} delayUntil='list'>
<div
className={styles["nav-right-show-btn"]}
onClick={handlerClick}
style={{
display: inView ? "none" : "flex",
}}
>
<SegmentIcon fontSize='medium' />
</div>
</Flipped>
</>
);
};
Expand All @@ -127,15 +136,17 @@ const NavItem: FC<NavListItemType> = memo((props) => {
transition,
};
return (
<div ref={setNodeRef} style={style} {...attributes} {...listeners}>
{props.type === "router" ? (
<NavRouterChipItem
{...Pick(props as NavRouterItemType, "pathname", "name")}
/>
) : (
<NavTagChipItem {...Pick(props as NavQueryItemType, "query")} />
)}
</div>
<Flipped flipId={props.id} translate spring={"veryGentle"}>
<div ref={setNodeRef} style={style} {...attributes} {...listeners}>
{props.type === "router" ? (
<NavRouterChipItem
{...Pick(props as NavRouterItemType, "pathname", "name")}
/>
) : (
<NavTagChipItem {...Pick(props as NavQueryItemType, "query")} />
)}
</div>
</Flipped>
);
});

Expand Down

0 comments on commit 8ba3867

Please sign in to comment.