DisclosureGroup 折叠面板组
管理多个 Disclosure 项展开状态的容器
用法
import { DisclosureGroup } from '@lenso/ui';此预览复用英文版适配,不代表中文源示例已完成本地实现。
"use client";// Independent React adaptation of the excluded pinned Native-preview source.import { NativeReferenceGroup } from "./controlled";export function Basic() { return <NativeReferenceGroup withNavigation={false} />;}Local adaptation source above. Derived from HeroUI v3.2.6 source.
组件结构
import {DisclosureGroup, Disclosure} from '@lenso/ui';
export default () => ( <DisclosureGroup> <Disclosure id="item1"> <Disclosure.Heading> <Disclosure.Trigger> <Disclosure.Indicator /> </Disclosure.Trigger> </Disclosure.Heading> <Disclosure.Content /> </Disclosure> </DisclosureGroup>)示例
受控组件
可使用 expandedKeys 与 onExpandedChange props 配合外部导航控件控制哪些 Disclosure 处于展开状态。
此预览复用英文版适配,不代表中文源示例已完成本地实现。
"use client";// React adaptation of HeroUI v3.2.6 (e385ac2), Apache-2.0. Native preview content is a reference, not an embedded Native runtime.import { ChevronDown, ChevronUp, QrCode } from "@gravity-ui/icons";import { Button, Disclosure, DisclosureGroup, Separator } from "@lenso/ui";import { Icon } from "@iconify/react";import { Fragment, useState } from "react";import * as stylex from "@stylexjs/stylex";import { nativeReferenceStyles as styles } from "./native-reference.stylex";export function NativeReferenceGroup({ withNavigation = true }: { withNavigation?: boolean }) { const [expanded, setExpanded] = useState<unknown[]>(["preview"]); const ids = ["preview", "download"]; const index = ids.findIndex((id) => expanded.includes(id)); return ( <div {...stylex.props(styles.root)}> <div {...stylex.props(withNavigation ? styles.card : styles.basicCard)}> {withNavigation && ( <div {...stylex.props(styles.heading)}> <h3 {...stylex.props(styles.title)}>HeroUI Native</h3> <div {...stylex.props(styles.actions)}> <Button aria-label="Previous disclosure" disabled={index <= 0} size="sm" variant="secondary" onClick={() => setExpanded([ids[index - 1]])} > <Button.Icon> <ChevronUp /> </Button.Icon> </Button> <Button aria-label="Next disclosure" disabled={index >= ids.length - 1} size="sm" variant="secondary" onClick={() => setExpanded([ids[index + 1]])} > <Button.Icon> <ChevronDown /> </Button.Icon> </Button> </div> </div> )} <DisclosureGroup value={expanded} onValueChange={setExpanded}> {ids.map((id, itemIndex) => ( <Fragment key={id}> {itemIndex > 0 && <Separator xstyle={styles.separator} />} <Disclosure value={id} aria-label={id === "preview" ? "Preview HeroUI Native" : "Download HeroUI Native"} > <Disclosure.Heading> <Disclosure.Trigger render={ <Button variant={expanded.includes(id) ? "secondary" : "tertiary"} xstyle={[styles.trigger, !expanded.includes(id) && styles.closed]} /> } > <span {...stylex.props(styles.label)}> <Button.Icon> {id === "preview" ? <QrCode /> : <Icon icon="tabler:brand-apple-filled" />} </Button.Icon> {id === "preview" ? "Preview HeroUI Native" : withNavigation ? "Download HeroUI Native" : "Download App"} </span> <Disclosure.Indicator xstyle={styles.indicator} /> </Disclosure.Trigger> </Disclosure.Heading> <Disclosure.Content> <Disclosure.Body xstyle={styles.body}> <p {...stylex.props(styles.muted)}> {id === "download" && !withNavigation ? "Download the HeroUI native app to explore our mobile components directly on your device." : "Scan this QR code with your camera app to preview the HeroUI native components."} </p> <img alt={ id === "download" && !withNavigation ? "App Store QR Code" : "Expo Go QR Code" } src="https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/images/qr-code-native.png" {...stylex.props(styles.qr)} /> <p {...stylex.props(styles.muted)}> {id === "download" && !withNavigation ? "Available on iOS and Android devices." : "Expo must be installed on your device."} </p> <Button variant="primary" xstyle={styles.action}> <Button.Icon> <Icon icon={id === "preview" ? "logos:expo-icon" : "tabler:brand-apple-filled"} {...stylex.props(id === "preview" && styles.expo)} /> </Button.Icon> {id === "preview" ? "Preview on Expo Go" : "Download on App Store"} </Button> </Disclosure.Body> </Disclosure.Content> </Disclosure> </Fragment> ))} </DisclosureGroup> </div> </div> );}export function Controlled() { return <NativeReferenceGroup />;}Local adaptation source above. Derived from HeroUI v3.2.6 source.
自定义样式
Tailwind CSS
此预览复用英文版适配,不代表中文源示例已完成本地实现。
"use client";// Adapted from HeroUI v3.2.6 (e385ac2), Apache-2.0.import { Button, Disclosure, DisclosureGroup, Separator } from "@lenso/ui";import { styles } from "./source.stylex";export function CustomStyles() { return ( <DisclosureGroup xstyle={styles.custom}> <Disclosure value="billing"> <Disclosure.Heading> <Disclosure.Trigger render={<Button variant="ghost" xstyle={styles.trigger} />}> Billing <Disclosure.Indicator xstyle={styles.muted} /> </Disclosure.Trigger> </Disclosure.Heading> <Disclosure.Content> <Disclosure.Body xstyle={styles.body}> Invoices are issued on the first of each month. </Disclosure.Body> </Disclosure.Content> </Disclosure> <Separator xstyle={styles.separator} /> <Disclosure value="support"> <Disclosure.Heading> <Disclosure.Trigger render={<Button variant="ghost" xstyle={styles.trigger} />}> Support <Disclosure.Indicator xstyle={styles.muted} /> </Disclosure.Trigger> </Disclosure.Heading> <Disclosure.Content> <Disclosure.Body xstyle={styles.body}> Reach us at [email protected]. Typical response time is under one business day. </Disclosure.Body> </Disclosure.Content> </Disclosure> </DisclosureGroup> );}Local adaptation source above. Derived from HeroUI v3.2.6 source.
全局 CSS
可使用 @layer components 指令自定义 DisclosureGroup 组件类。
了解更多。
@layer components { .disclosure-group { @apply w-full;
/* Performance optimization */ contain: layout style; }}样式参考
HeroUI 遵循 BEM 方法论,确保组件变体与状态可复用且易于自定义。
CSS 类
DisclosureGroup 组件使用以下 CSS 类(查看源码样式):
基础类 [!toc]
.disclosure-group- 基础容器样式,含布局 containment
交互状态
组件同时支持 CSS 伪类与 data 属性:
- Disabled:整个分组上
:disabled或[aria-disabled="true"] - Expanded Management:自动管理子 Disclosure 项上的
[data-expanded]状态
API 参考
DisclosureGroup
| Prop | 类型 | 默认值 | 描述 |
|---|---|---|---|
expandedKeys | Set<Key> | - | 当前展开项(受控) |
defaultExpandedKeys | Iterable<Key> | - | 初始展开项(非受控) |
onExpandedChange | (keys: Set<Key>) => void | - | 展开项变化时的回调 |
allowsMultipleExpanded | boolean | false | 是否允许多项同时展开 |
isDisabled | boolean | false | 是否禁用组内所有 Disclosure |
children | ReactNode | RenderFunction | - | 要渲染的 Disclosure 项 |
className | string | - | 附加 CSS 类 |
Render Props
使用 render prop 模式时,提供以下值:
| Prop | 类型 | 描述 |
|---|---|---|
expandedKeys | Set<Key> | 当前展开项的 key |
isDisabled | boolean | 分组是否禁用 |
相关案例
See upstream DisclosureGroup showcases. Product showcases are not part of the local component runtime.