🔥 遇见我们的新项目 t0ggles - 您终极的项目管理工具! 🔥

导航栏 React 组件

导航栏是屏幕顶部的一个固定区域,包含页面标题和导航元素。

包含以下组件

  • 导航栏
  • NavbarBackLink
名称类型默认值描述
bgClassName字符串

要添加到导航栏的“背景”元素上的额外类

centerTitle布尔值未定义

使导航栏标题居中。如果未指定,则在 iOS 主题中将其设置为居中

colors对象

包含 Tailwind CSS 颜色类的对象

colors.bgIos字符串'bg-ios-light-surface-2 dark:bg-ios-dark-surface-2'
colors.bgMaterial字符串'bg-md-light-surface-2 dark:bg-md-dark-surface-2'
colors.textIos字符串'text-black dark:text-white'
colors.textMaterial字符串'text-md-light-on-surface dark:text-md-dark-on-surface'
component字符串'div'

组件的 HTML 元素

fontSizeIos字符串'text-[17px]'

iOS 主题中字体大小的 Tailwind CSS 类

fontSizeMaterial字符串'text-[16px]'

Material 主题中字体大小的 Tailwind CSS 类

innerClassName字符串

要添加到导航栏的“内部”元素上的额外类

large布尔值false

呈现大型导航栏,带有用于大型标题的额外行,滚动时该标题会变成通常的大小

leftReactNode

导航栏的“左侧”区域的内容

leftClassName字符串

要添加到导航栏的“左侧”元素上的额外类

medium布尔值false

呈现中等大小的导航栏,带有用于中等大小标题的额外行,滚动时该标题会变成通常的大小

outline布尔值未定义

呈现外部细线(边框)。如果未指定,将在 iOS 主题中启用

rightReactNode

导航栏的“右侧”区域的内容

rightClassName字符串

要添加到导航栏的“右侧”元素上的额外类

scrollEl任何未定义

对于中等/大型/透明导航栏的正确“折叠”功能所需的元素。如果未指定,它将使用导航栏的父元素

subnavbarReactNode

导航栏的“子导航栏”区域的内容

subnavbarClassName字符串

要添加到导航栏的“子导航栏”元素上的额外类

subtitleReactNode

导航栏的“副标题”区域的内容

subtitleClassName字符串

要添加到导航栏的“副标题”元素上的额外类

titleReactNode

导航栏的“标题”区域的内容

titleClassName字符串

要添加到导航栏的“标题”元素上的额外类

titleFontSizeIos字符串'text-[17px]'

iOS 主题中导航栏标题字体大小的 Tailwind CSS 类

titleFontSizeMaterial字符串'text-[22px]'

Material 主题中导航栏标题字体大小的 Tailwind CSS 类

titleLargeFontSizeIos字符串'text-[34px]'

iOS 主题中大型导航栏标题字体大小的 Tailwind CSS 类

titleLargeFontSizeMaterial字符串'text-[28px]'

Material 主题中大型导航栏标题字体大小的 Tailwind CSS 类

titleMediumFontSizeIos字符串'text-[24px]'

iOS 主题中中等大小导航栏标题字体大小的 Tailwind CSS 类

titleMediumFontSizeMaterial字符串'text-[24px]'

Material 主题中中等大小导航栏标题字体大小的 Tailwind CSS 类

translucent布尔值true

在 iOS 主题中使导航栏背景半透明(使用 backdrop-filter: blur

transparent布尔值false

呈现透明导航栏,滚动时会变成不透明

NavbarBackLink 应该放在导航栏的“左侧”区域

<Navbar
  left={
    <NavbarBackLink text="Back" onClick={() => history.back()} />
  }
  title="My App"
/>
名称类型默认值描述
component字符串'a'

组件的 HTML 元素

showText布尔值 | 'auto''auto'

定义是否显示链接文本。当为 'auto' 时,它会为 Material 主题隐藏链接文本

textReactNode'后退'

后退链接的文本内容

onClickfunction(e)

链接点击处理程序

示例

Navbar.jsx
import React, { useState } from 'react';
import {
Page,
Navbar,
NavbarBackLink,
Link,
Block,
BlockTitle,
BlockHeader,
List,
ListItem,
Radio,
Toggle,
} from 'konsta/react';
export default function NavbarPage() {
const [size, setSize] = useState('Default');
const [isTransparent, setIsTransparent] = useState(false);
return (
<Page>
<Navbar
title="Navbar"
subtitle="Subtitle"
className="top-0 sticky"
medium={size === 'Medium'}
large={size === 'Large'}
transparent={isTransparent}
right={<Link navbar>Right</Link>}
/>
<div className="relative">
<Block strong inset>
<p>
Navbar is a fixed area at the top of a screen that contains Page
title and navigation elements.
</p>
</Block>
<BlockTitle>Size</BlockTitle>
<BlockHeader>
Medium and Large will collapse to usual size on page scroll
</BlockHeader>
<List strong inset>
{['Default', 'Medium', 'Large'].map((v) => (
<ListItem
key={v}
label
title={v}
after={
<Radio
component="div"
value={v}
checked={size === v}
onChange={() => setSize(v)}
/>
}
/>
))}
</List>
<BlockTitle>Transparent</BlockTitle>
<BlockHeader>
When navbar is transparent, its title and background will become
visible on page scroll
</BlockHeader>
<List strong inset>
<ListItem
label
title="Transparent"
after={
<Toggle
component="div"
checked={isTransparent === true}
onChange={() => setIsTransparent(!isTransparent)}
/>
}
/>
</List>
<Block strong inset className="space-y-4">
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Iusto
tempore ratione unde accusantium distinctio nulla quia numquam earum
odio, optio, nisi rem deserunt. Molestiae delectus, ut assumenda
numquam magni enim.
</p>
<p>
Architecto molestias cum dolor dolorem provident consequuntur
incidunt sunt fugiat tenetur odio, recusandae placeat rem veniam.
Voluptates, repellendus odit, magni nesciunt, optio laborum
asperiores repudiandae consectetur suscipit ab cupiditate eum.
</p>
<p>
Aliquam, iste accusamus deleniti temporibus exercitationem neque
perferendis optio, blanditiis quisquam molestias perspiciatis cumque
harum tenetur veniam. Dolorum fugit doloribus est, deserunt,
eligendi, quaerat quidem itaque tempore laborum non illum?
</p>
<p>
Rerum magni sunt quis veniam, dolor ratione saepe ducimus tempore
voluptatum porro quod commodi? Aperiam laudantium deleniti totam
dolorum qui accusantium iste saepe facere optio, soluta maxime
mollitia deserunt cumque.
</p>
<p>
Iusto tempore quis provident, saepe illum ex ipsum cupiditate
explicabo ratione unde facere nemo delectus harum, blanditiis eius
sit asperiores nam. Aut cupiditate est tempore officia, perspiciatis
esse asperiores repudiandae?
</p>
<p>
Consequuntur itaque harum eos vero, reiciendis dolorum iure non
earum molestias tenetur sint enim, maxime recusandae ad perferendis
repudiandae! Sit, quos exercitationem beatae numquam laborum nobis
natus. Obcaecati, ea inventore.
</p>
<p>
Fugit culpa labore sapiente excepturi reiciendis, nulla, nihil neque
ut veritatis quis quibusdam dolorum? Voluptatibus animi officia
perspiciatis doloremque cum voluptatem, quia ratione modi vero,
consequatur ipsum, praesentium quibusdam amet?
</p>
<p>
Laudantium nihil sint nam placeat, nemo rerum ipsam explicabo iusto
dolores molestiae expedita eos consequuntur ut architecto
consequatur soluta ad maiores voluptatem tenetur in velit. Minima
quia molestiae nobis voluptatibus.
</p>
<p>
Expedita soluta quia inventore et placeat id exercitationem quisquam
eligendi est eius sapiente quo, cum nesciunt mollitia, sit veniam
ducimus tempora culpa adipisci commodi in autem nihil voluptatem
corporis? Perspiciatis.
</p>
<p>
Molestias, est? Eligendi vero distinctio voluptatem cumque id
voluptatibus, officia minima repellendus sit illo tempora labore
provident? Eum tenetur consectetur quae, in facilis autem ipsam
doloribus voluptate vitae suscipit nobis.
</p>
<p>
Obcaecati optio iste hic, soluta minus ullam, perferendis pariatur
non possimus autem nostrum libero sapiente. Corporis quo cum iusto
exercitationem velit. Non beatae eveniet asperiores ipsa
consequuntur temporibus sapiente earum!
</p>
<p>
Temporibus, omnis. Excepturi dolorum expedita laudantium quasi quod
id adipisci, esse, nam atque in, incidunt ex ab distinctio
repellendus beatae voluptatem alias odit illum quis. Illo numquam
voluptatibus error voluptatum!
</p>
</Block>
</div>
</Page>
);
}
Subnavbar.jsx
import React from 'react';
import {
Page,
Navbar,
NavbarBackLink,
Block,
Segmented,
SegmentedButton,
} from 'konsta/react';
export default function SubnavbarPage() {
return (
<Page>
<Navbar
title="Subnavbar"
subnavbar={
<Segmented strong>
<SegmentedButton small strong active>
Button
</SegmentedButton>
<SegmentedButton small strong>
Button
</SegmentedButton>
<SegmentedButton small strong>
Button
</SegmentedButton>
</Segmented>
}
/>
<div className="relative">
<Block strongIos outlineIos>
<p>
Subnavbar is useful when you need to put any additional elements
into Navbar, like Tab Links or Search Bar. It also remains visible
when Navbar hidden.
</p>
</Block>
</div>
</Page>
);
}
代码许可证: MIT.
2022 © Konsta UI by nolimits4web.