diff --git a/src/components/layouts/BasicLayout/Header/index.module.less b/src/components/layouts/BasicLayout/Header/index.module.less index ed494bb7..8ba34bb4 100644 --- a/src/components/layouts/BasicLayout/Header/index.module.less +++ b/src/components/layouts/BasicLayout/Header/index.module.less @@ -9,7 +9,6 @@ z-index: 250; transition: transform 0.2s; - .wrapper { margin: auto; max-width: 1440px; @@ -122,6 +121,15 @@ display: none; } } +.tab-more { + line-height: 5rem; + font-size: 1.25rem; + height: 100%; + height: 5rem; + color: var(--juejin-text-1); + cursor: pointer; + position: relative; +} .tab-first { line-height: 5rem; margin-left: 1rem; diff --git a/src/components/layouts/BasicLayout/Header/index.tsx b/src/components/layouts/BasicLayout/Header/index.tsx index af7637d2..aa0f1fd9 100644 --- a/src/components/layouts/BasicLayout/Header/index.tsx +++ b/src/components/layouts/BasicLayout/Header/index.tsx @@ -5,6 +5,7 @@ import { useRouter } from 'next/router' import type { FC } from 'react' import { useContext, useState } from 'react' +import { Collapse, Expand } from '~/components/universal/Icons/TabIcon' import { IconNight, IconSun } from '~/components/universal/Icons/dark-mode' import { JuejinFont, Logo as JuejinLogo } from '~/components/universal/Logo' import { InitialContext } from '~/context/initial-data' @@ -22,7 +23,6 @@ export const SwitchTheme = () => { ) } - const TabItem: FC = ({ slug, title, tag }) => { const router = useRouter() return ( @@ -47,6 +47,7 @@ const Header = observer(() => { appStore: { isNarrowThanLaptop, viewport }, } = useStore() const [hidden, setHidden] = useState(true) + const [tabExpand, setTabExpand] = useState(false) const { tab } = useContext(InitialContext) const { appStore } = useStore() return ( @@ -78,7 +79,6 @@ const Header = observer(() => { {tab[0].title} )} - {!(isNarrowThanLaptop ? hidden : false) && (
{ isNarrowThanLaptop && styles['tab-mobile'], )} > - {tab.map((tab) => ( - - ))} + {tab + .slice(0, isNarrowThanLaptop || tabExpand ? undefined : 9) + .map((tab) => ( + + ))} + {tab.length > 9 && !isNarrowThanLaptop && ( +
{ + setTabExpand(!tabExpand) + }} + title={tabExpand ? '收起' : '展开'} + > + {tabExpand ? : } +
+ )}
)} diff --git a/src/components/universal/Icons/TabIcon.tsx b/src/components/universal/Icons/TabIcon.tsx new file mode 100644 index 00000000..8235140c --- /dev/null +++ b/src/components/universal/Icons/TabIcon.tsx @@ -0,0 +1,33 @@ +import style from './icon.module.less' + +export const Expand = () => { + return ( + + + + ) +} +export const Collapse = () => { + return ( + + + + ) +} diff --git a/src/components/universal/Icons/icon.module.less b/src/components/universal/Icons/icon.module.less new file mode 100644 index 00000000..e285d4e9 --- /dev/null +++ b/src/components/universal/Icons/icon.module.less @@ -0,0 +1,4 @@ +.icon { + fill: var(--juejin-font-1); + transition: fill 0.1s; +}