• Vant React

FixedNav 悬浮导航

介绍

伸缩式交互,用于快捷导航

引入

import { FixedNav } from "@taroify/core"

代码演示

基础用法

const list = [
  {
    id: 1,
    text: "首页",
    icon: <WapHomeOutlined />,
  },
  {
    id: 2,
    text: "分类",
    icon: <AppsOutlined />,
  },
  {
    id: 3,
    text: "购物车",
    num: 2,
    icon: <ShoppingCartOutlined />,
  },
  {
    id: 4,
    text: "我的",
    icon: <UserOutlined />,
  },
]

const App = () => {
  const [open, setOpen] = useState(false)

  return <FixedNav open={open} onChange={setOpen} data={list} position={{ top: "150px" }} />
}

位置在左侧

const list = [
  {
    id: 1,
    text: "首页",
    icon: <WapHomeOutlined />,
  },
  {
    id: 2,
    text: "分类",
    icon: <AppsOutlined />,
  },
  {
    id: 3,
    text: "购物车",
    num: 2,
    icon: <ShoppingCartOutlined />,
  },
  {
    id: 4,
    text: "我的",
    icon: <UserOutlined />,
  },
]

const App = () => {
  const [open, setOpen] = useState(false)

  return (
    <FixedNav
      open={open2}
      onChange={setOpen2}
      data={list}
      type="left"
      backdrop={false}
      position={{ top: "300px" }}
    />
  )
}

自定义内容

const CustomerFixedNav = () => {
  const [open, setOpen] = useState(false)

  return (
    <FixedNav
      open={open}
      onChange={setOpen}
      type="left"
      backdrop={false}
      position={{ top: "400px" }}
      content={
        <>
          <GiftOutlined color="#FFF" />
          <span className="fixed-nav-text">{open ? "开" : "关"}</span>
        </>
      }
    >
      <ul className="taroify-fixed-nav_content customer">
        <li className="taroify-fixed-nav_content_item"></li>
        <li className="taroify-fixed-nav_content_item"></li>
        <li className="taroify-fixed-nav_content_item"></li>
        <li className="taroify-fixed-nav_content_item"></li>
        <li className="taroify-fixed-nav_content_item"></li>
      </ul>
    </FixedNav>
  )
}
.fixed-nav-demo {
  .fixed-nav-text {
    color: #fff;
    line-height: 26px;
    width: 48px;
    font-size: 24px;
  }

  .taroify-fixed-nav_content {
    &.customer {
      border-radius: 0 50px 50px 0;
      margin: 0;
      padding-left: 160px;
      padding-right: 40px;
      right: auto;
    }

    &_item {
      align-items: center;
      color: #1a1a1a;
      display: flex;
      flex: 1;
      flex-direction: column;
      flex-shrink: 0;
      height: 100%;
      justify-content: center;
      min-width: 100px;
      position: relative;
      font-size: 28px;
    }
  }
}

API

Flex Props

参数说明类型默认值
open是否打开booleanfalse
data悬浮导航内数据FixedNavItem[][]
backdrop是否显示遮罩层booleantrue
activeText收起按钮文案string收起导航
inactiveText展开按钮文案string快速导航
type悬浮导航方向left | rightright
position悬浮导航垂直位置FixedNavPosition{top: 'auto', bottom: 'auto'}
content自定义按钮ReactNode-

Events

事件名说明回调参数
onChange展开收起按钮回调value: boolean
onClick选择之后触发item

主题定制

样式变量

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 组件。

名称默认值描述
—fixed-nav-z-index1010-
—fixed-nav-z-content-index1009-
—fixed-nav-button-backgroundvar(—blue, $blue)-
—fixed-nav-button-font-size12px * $hd-
—fixed-nav-background-colorvar(—white, $white)-
—fixed-nav-colorvar(—gray-8, $gray-8)-