diff --git a/lib/components/attributes/attributes.tsx b/lib/components/attributes/attributes.tsx index 1037907..4aa44af 100644 --- a/lib/components/attributes/attributes.tsx +++ b/lib/components/attributes/attributes.tsx @@ -25,6 +25,10 @@ const Attributes: React.FC> = React.mem Edit this page on GitHub ) diff --git a/lib/components/controls.tsx b/lib/components/controls.tsx index ebc807d..df70c28 100644 --- a/lib/components/controls.tsx +++ b/lib/components/controls.tsx @@ -1,6 +1,5 @@ -import React, { useCallback, useMemo, useRef, useState } from 'react' -import useTheme from 'components/styles/use-theme' -import { Button, Col, Image } from 'components' +import React, { useCallback, useMemo } from 'react' +import { Button, useTheme, Spacer } from 'components' import useConfigs from 'lib/states/use-config' import MoonIcon from './icons/moon' import SunIcon from './icons/sun' @@ -10,10 +9,7 @@ const Controls: React.FC<{}> = React.memo(({ }) => { const theme = useTheme() const config = useConfigs() - const timer = useRef() - const [hover, setHover] = useState(false) const isDark = useMemo(() => theme.type === 'dark', [theme.type]) - const hideLogo = useMemo(() => isDark || hover, [isDark, hover]) const switchThemes = useCallback(() => { const isDark = theme.type === 'dark' config.onChange && config.onChange(!isDark) @@ -25,29 +21,10 @@ const Controls: React.FC<{}> = React.memo(({ } } - const hoverHandler = (next: boolean) => { - if (typeof window === 'undefined') return - if (next) { - timer.current && clearTimeout(timer.current) - return setHover(true) - } - - timer.current = window.setTimeout(() => { - setHover(false) - clearTimeout(timer.current) - }, 300) - } - return (
- hoverHandler(true)} - onMouseLeave={() => hoverHandler(false)}> - - -
hoverHandler(true)} - onMouseLeave={() => hoverHandler(false)}> +
+
) diff --git a/lib/components/icons/toggle.tsx b/lib/components/icons/toggle.tsx new file mode 100644 index 0000000..7cd2f4a --- /dev/null +++ b/lib/components/icons/toggle.tsx @@ -0,0 +1,45 @@ +import React from 'react' +import withDefaults from 'components/utils/with-defaults' +import useTheme from 'components/styles/use-theme' + +interface Props { + width?: number + height?: number + color?: string +} + +const defaultProps = { + width: 15, + height: 15, +} + +export type ToggleIconProps = Props & typeof defaultProps & React.SVGAttributes + +const ToggleIcon: React.FC = React.memo(({ + width, height, color, ...props +}) => { + const theme = useTheme() + return ( + + + + + + + + + + + + + + ) +}) + +export default withDefaults(ToggleIcon, defaultProps) diff --git a/lib/components/layout.tsx b/lib/components/layout.tsx index 3612702..5ac48a1 100644 --- a/lib/components/layout.tsx +++ b/lib/components/layout.tsx @@ -1,9 +1,10 @@ -import React from 'react' +import React, { useState } from 'react' import { withRouter, Router } from 'next/router' import { useTheme } from 'components/index' import Sidebar from './sidebar' import Controls from 'lib/components/controls' import sides from 'lib/data/metadata.json' +import TabbarMobile from './sidebar/tabbar-mobile' export interface Meta { title: string @@ -17,9 +18,14 @@ export interface Props { export const Layout: React.FC> = React.memo(({ children }) => { const theme = useTheme() + const [expanded, setExpanded] = useState(false) + const mobileTabbarClickHandler = () => { + setExpanded(!expanded) + } return (
+
) diff --git a/lib/components/sidebar/active-catalog.tsx b/lib/components/sidebar/active-catalog.tsx index dd2acb5..69db0c3 100644 --- a/lib/components/sidebar/active-catalog.tsx +++ b/lib/components/sidebar/active-catalog.tsx @@ -4,25 +4,24 @@ import useTheme from 'components/styles/use-theme' export interface Props { name: string - onClick: React.MouseEventHandler } const ActiveCatalog: React.FC = React.memo( - ({ name, onClick, ...props }) => { + ({ name, ...props }) => { const theme = useTheme() const { pathname } = useRouter() const isActive = pathname.includes(`/${name}/`) return ( - + {name} -
diff --git a/lib/components/sidebar/side-item.tsx b/lib/components/sidebar/side-item.tsx index 5e521d4..ed352ea 100644 --- a/lib/components/sidebar/side-item.tsx +++ b/lib/components/sidebar/side-item.tsx @@ -1,6 +1,5 @@ -import React, { useState, ReactElement, useCallback } from 'react' +import React, { ReactElement } from 'react' import ActiveLink from './active-link' -import ArrowIcon from '../icons/arrow' import ActiveCatalog from './active-catalog' import { useTheme } from 'components' @@ -14,43 +13,27 @@ export interface SideItemProps { sides: Array } -const getChildrenHeight = (children?: Sides | Array) => { - if (!children || !Array.isArray(children)) return 0 - return children.length * 36 -} - const SideItem: React.FC> = React.memo(({ children, sides, }) => { const theme = useTheme() - const [childrenActived, setChildrenActived] = useState>(() => sides.map(() => true)) - - const next = useCallback((index) => { - setChildrenActived(childrenActived.map((bool, i) => index !== i ? bool : !bool)) - }, [childrenActived]) - + return ( <> {sides.map((side, index) => { - const childrenHeight = getChildrenHeight(side.children) - const isActived = childrenActived[index] - return (
-
- {side.children &&
} - { - !side.url - ? next(index)} /> - : ( - - {side.name} - - ) - } -
- {side.children &&
- + {!side.url && } + {side.url && ( +
+ + {side.name} + +
+ )} + + {side.children &&
+ {/**/} {React.cloneElement(children as ReactElement, { sides: side.children, })} @@ -64,35 +47,33 @@ const SideItem: React.FC> = React.memo(({ flex: 1; flex-direction: column; justify-content: center; + align-items: flex-start; + width: 100%; } .link { + width: 100%; color: ${theme.palette.accents_5}; display: flex; height: 36px; align-items: center; + justify-content: flex-start; cursor: pointer; text-transform: capitalize; } - + .link :global(a) { - color: ${theme.palette.accents_6}; - padding-left: .7rem; - font-size: 14px; + color: ${theme.palette.accents_7}; + font-size: .9rem; + padding: 0 ${theme.layout.gapQuarter}; + transition: color 200ms ease; } .link :global(a.active) { - color: ${theme.palette.success}; - } - - .icon { - margin-right: 10px; - margin-left: 5px; - height: 100%; - display: flex; - align-items: center; - justify-content: center; - user-select: none; + color: ${theme.palette.background}; + font-weight: 700; + background-color: ${theme.palette.accents_7}; + text-transform: uppercase; } .children { @@ -100,8 +81,7 @@ const SideItem: React.FC> = React.memo(({ justify-content: center; align-items: flex-start; flex-direction: column; - margin-left: ${theme.layout.gapHalf}; - padding-left: ${theme.layout.gap}; + padding-left: ${theme.layout.gapHalf}; overflow: hidden; transition: all .2s ease-in-out; position: relative; @@ -111,13 +91,8 @@ const SideItem: React.FC> = React.memo(({ font-weight: bold; } - .line { - position: absolute; - top: 14px; - left: 1px; - bottom: 9px; - width: 1px; - background-color: ${theme.palette.accents_2}; + @media only screen and (max-width: 767px) { + } `} diff --git a/lib/components/sidebar/tabbar-mobile.tsx b/lib/components/sidebar/tabbar-mobile.tsx new file mode 100644 index 0000000..375af90 --- /dev/null +++ b/lib/components/sidebar/tabbar-mobile.tsx @@ -0,0 +1,66 @@ +import React from 'react' +import { Button, useTheme } from 'components' +import ToggleIcon from '../icons/toggle' + +interface Props { + onClick?: (e: React.MouseEvent) => void +} + +const TabbarMobile:React.FC = ({ onClick }) => { + const theme = useTheme() + const handler = (event: React.MouseEvent) => { + onClick && onClick(event) + } + + return ( +
+ + ZEIT-UI React + +
+ ) +} + +export default TabbarMobile diff --git a/pages/_app.tsx b/pages/_app.tsx index 2004d18..f5a7ed6 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -28,7 +28,7 @@ const Application: NextPage = ({ Component, pageProps }) => { - + @@ -76,6 +76,10 @@ const Application: NextPage = ({ Component, pageProps }) => { color: ${theme.palette.accents_3}; } + body { + overflow-x: hidden; + } + body::-webkit-scrollbar { width: 0; background-color: ${theme.palette.accents_1}; diff --git a/pages/docs/index.js b/pages/docs/index.js index 3172fd6..7cfb645 100644 --- a/pages/docs/index.js +++ b/pages/docs/index.js @@ -1,3 +1,3 @@ -import Introduction from './getting-started/introduction.mdx' +import redirect from 'lib/redirect' -export default Introduction +export default redirect('/docs/getting-started/introduction')