导航栏是屏幕顶部的一个固定区域,包含页面标题和导航元素。
包含以下组件
导航栏
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 | 呈现大型导航栏,带有用于大型标题的额外行,滚动时该标题会变成通常的大小 |
left | ReactNode | 导航栏的“左侧”区域的内容 | |
leftClassName | 字符串 | 要添加到导航栏的“左侧”元素上的额外类 | |
medium | 布尔值 | false | 呈现中等大小的导航栏,带有用于中等大小标题的额外行,滚动时该标题会变成通常的大小 |
outline | 布尔值 | 未定义 | 呈现外部细线(边框)。如果未指定,将在 iOS 主题中启用 |
right | ReactNode | 导航栏的“右侧”区域的内容 | |
rightClassName | 字符串 | 要添加到导航栏的“右侧”元素上的额外类 | |
scrollEl | 任何 | 未定义 | 对于中等/大型/透明导航栏的正确“折叠”功能所需的元素。如果未指定,它将使用导航栏的父元素 |
subnavbar | ReactNode | 导航栏的“子导航栏”区域的内容 | |
subnavbarClassName | 字符串 | 要添加到导航栏的“子导航栏”元素上的额外类 | |
subtitle | ReactNode | 导航栏的“副标题”区域的内容 | |
subtitleClassName | 字符串 | 要添加到导航栏的“副标题”元素上的额外类 | |
title | ReactNode | 导航栏的“标题”区域的内容 | |
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 主题中使导航栏背景半透明(使用 |
transparent | 布尔值 | false | 呈现透明导航栏,滚动时会变成不透明 |
NavbarBackLink
应该放在导航栏的“左侧”区域
<Navbar
left={
<NavbarBackLink text="Back" onClick={() => history.back()} />
}
title="My App"
/>
名称 | 类型 | 默认值 | 描述 |
---|---|---|---|
component | 字符串 | 'a' | 组件的 HTML 元素 |
showText | 布尔值 | 'auto' | 'auto' | 定义是否显示链接文本。当为 'auto' 时,它会为 Material 主题隐藏链接文本 |
text | ReactNode | '后退' | 后退链接的文本内容 |
onClick | function(e) | 链接点击处理程序 |
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><Navbartitle="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 Pagetitle 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) => (<ListItemkey={v}labeltitle={v}after={<Radiocomponent="div"value={v}checked={size === v}onChange={() => setSize(v)}/>}/>))}</List><BlockTitle>Transparent</BlockTitle><BlockHeader>When navbar is transparent, its title and background will becomevisible on page scroll</BlockHeader><List strong inset><ListItemlabeltitle="Transparent"after={<Togglecomponent="div"checked={isTransparent === true}onChange={() => setIsTransparent(!isTransparent)}/>}/></List><Block strong inset className="space-y-4"><p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Iustotempore ratione unde accusantium distinctio nulla quia numquam earumodio, optio, nisi rem deserunt. Molestiae delectus, ut assumendanumquam magni enim.</p><p>Architecto molestias cum dolor dolorem provident consequunturincidunt sunt fugiat tenetur odio, recusandae placeat rem veniam.Voluptates, repellendus odit, magni nesciunt, optio laborumasperiores repudiandae consectetur suscipit ab cupiditate eum.</p><p>Aliquam, iste accusamus deleniti temporibus exercitationem nequeperferendis optio, blanditiis quisquam molestias perspiciatis cumqueharum 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 temporevoluptatum porro quod commodi? Aperiam laudantium deleniti totamdolorum qui accusantium iste saepe facere optio, soluta maximemollitia deserunt cumque.</p><p>Iusto tempore quis provident, saepe illum ex ipsum cupiditateexplicabo ratione unde facere nemo delectus harum, blanditiis eiussit asperiores nam. Aut cupiditate est tempore officia, perspiciatisesse asperiores repudiandae?</p><p>Consequuntur itaque harum eos vero, reiciendis dolorum iure nonearum molestias tenetur sint enim, maxime recusandae ad perferendisrepudiandae! Sit, quos exercitationem beatae numquam laborum nobisnatus. Obcaecati, ea inventore.</p><p>Fugit culpa labore sapiente excepturi reiciendis, nulla, nihil nequeut veritatis quis quibusdam dolorum? Voluptatibus animi officiaperspiciatis doloremque cum voluptatem, quia ratione modi vero,consequatur ipsum, praesentium quibusdam amet?</p><p>Laudantium nihil sint nam placeat, nemo rerum ipsam explicabo iustodolores molestiae expedita eos consequuntur ut architectoconsequatur soluta ad maiores voluptatem tenetur in velit. Minimaquia molestiae nobis voluptatibus.</p><p>Expedita soluta quia inventore et placeat id exercitationem quisquameligendi est eius sapiente quo, cum nesciunt mollitia, sit veniamducimus tempora culpa adipisci commodi in autem nihil voluptatemcorporis? Perspiciatis.</p><p>Molestias, est? Eligendi vero distinctio voluptatem cumque idvoluptatibus, officia minima repellendus sit illo tempora laboreprovident? Eum tenetur consectetur quae, in facilis autem ipsamdoloribus voluptate vitae suscipit nobis.</p><p>Obcaecati optio iste hic, soluta minus ullam, perferendis pariaturnon possimus autem nostrum libero sapiente. Corporis quo cum iustoexercitationem velit. Non beatae eveniet asperiores ipsaconsequuntur temporibus sapiente earum!</p><p>Temporibus, omnis. Excepturi dolorum expedita laudantium quasi quodid adipisci, esse, nam atque in, incidunt ex ab distinctiorepellendus beatae voluptatem alias odit illum quis. Illo numquamvoluptatibus error voluptatum!</p></Block></div></Page>);}
import React from 'react';import {Page,Navbar,NavbarBackLink,Block,Segmented,SegmentedButton,} from 'konsta/react';export default function SubnavbarPage() {return (<Page><Navbartitle="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 elementsinto Navbar, like Tab Links or Search Bar. It also remains visiblewhen Navbar hidden.</p></Block></div></Page>);}