Disclosure 折叠面板
可折叠区块,包含标题、触发按钮与内容面板
用法
import { Disclosure } from '@lenso/ui';此预览复用英文版适配,不代表中文源示例已完成本地实现。
"use client";// Independent React adaptation of the excluded pinned Native-preview source.import { PreviewDisclosure } from "./render-function";export function Basic() { return <PreviewDisclosure />;}Local adaptation source above. Derived from HeroUI v3.2.6 source.
组件结构
import { Disclosure } from '@lenso/ui';
export default () => ( <Disclosure> <Disclosure.Heading> <Disclosure.Trigger> <Disclosure.Indicator /> </Disclosure.Trigger> </Disclosure.Heading> <Disclosure.Content/> </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 { QrCode } from "@gravity-ui/icons";import { Button, Disclosure } from "@lenso/ui";import { Icon } from "@iconify/react";import { useState } from "react";import * as stylex from "@stylexjs/stylex";import { nativeReferenceStyles as styles } from "./native-reference.stylex";export function PreviewDisclosure({ composed = false }: { composed?: boolean }) { const [open, setOpen] = useState(true); return ( <div {...stylex.props(styles.root)}> <Disclosure open={open} onOpenChange={setOpen} render={composed ? <div data-custom="foo" /> : undefined} > <Disclosure.Heading> <Disclosure.Trigger render={<Button variant="secondary" />}> <Button.Icon> <QrCode /> </Button.Icon> Preview HeroUI Native <Disclosure.Indicator /> </Disclosure.Trigger> </Disclosure.Heading> <Disclosure.Content render={composed ? (props) => <div {...props} data-custom="bar" /> : undefined} > <Disclosure.Body xstyle={styles.body}> <p {...stylex.props(styles.muted)}> Scan this QR code with your camera app to preview the HeroUI native components. </p> <img alt="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)}>Expo must be installed on your device.</p> <Button variant="primary" xstyle={styles.action}> <Button.Icon> <Icon icon="tabler:brand-apple-filled" /> </Button.Icon> Download on App Store </Button> </Disclosure.Body> </Disclosure.Content> </Disclosure> </div> );}export function RenderFunction() { return <PreviewDisclosure composed />;}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 { ShoppingBag } from "@gravity-ui/icons";import { Button, Disclosure } from "@lenso/ui";import { useState } from "react";import * as stylex from "@stylexjs/stylex";import { styles } from "./source.stylex";export function CustomStyles() { const [open, setOpen] = useState(false); return ( <div {...stylex.props(styles.root)}> <Disclosure open={open} onOpenChange={setOpen}> <Disclosure.Heading> <Disclosure.Trigger render={<Button variant="ghost" xstyle={styles.trigger} />}> <span {...stylex.props(styles.label)}> <ShoppingBag {...stylex.props(styles.icon)} /> Shipping details </span> <Disclosure.Indicator xstyle={styles.indicator} /> </Disclosure.Trigger> </Disclosure.Heading> <Disclosure.Content> <Disclosure.Body xstyle={styles.body}> Orders ship within 2 business days. Standard delivery takes 3–5 days; express is available at checkout. </Disclosure.Body> </Disclosure.Content> </Disclosure> </div> );}Local adaptation source above. Derived from HeroUI v3.2.6 source.
全局 CSS
可使用 @layer components 指令自定义 Disclosure 组件类。
了解更多。
@layer components { .disclosure { @apply relative; }
.disclosure__trigger { @apply cursor-pointer; }
.disclosure__indicator { @apply transition-transform duration-300; }
.disclosure__content { @apply overflow-hidden transition-all; }}样式参考
HeroUI 遵循 BEM 方法论,确保组件变体与状态可复用且易于自定义。
CSS 类
Disclosure 组件使用以下 CSS 类(查看源码样式):
基础类 [!toc]
.disclosure- 基础容器样式.disclosure__heading- 标题包裹层.disclosure__trigger- 触发按钮样式.disclosure__indicator- 箭头指示器样式.disclosure__content- 带动画的内容容器
交互状态
组件同时支持 CSS 伪类与 data 属性:
- Expanded:指示器上
[data-expanded="true"]用于旋转 - Focus:触发器上
:focus-visible或[data-focus-visible="true"] - Disabled:触发器上
:disabled或[aria-disabled="true"] - Hidden:内容上
[aria-hidden="false"]控制可见性
API 参考
Disclosure
| Prop | 类型 | 默认值 | 描述 |
|---|---|---|---|
isExpanded | boolean | false | 控制展开状态 |
onExpandedChange | (isExpanded: boolean) => void | - | 展开状态变化时的回调 |
isDisabled | boolean | false | 是否禁用 |
children | ReactNode | RenderFunction | - | 要渲染的内容 |
className | string | - | 附加 CSS 类 |
render | DOMRenderFunction<keyof React.JSX.IntrinsicElements, DisclosureRenderProps> | - | 使用自定义 render 函数覆盖默认 DOM 元素 |
DisclosureTrigger
| Prop | 类型 | 默认值 | 描述 |
|---|---|---|---|
children | ReactNode | RenderFunction | - | 触发器内容 |
className | string | - | 附加 CSS 类 |
DisclosureContent
| Prop | 类型 | 默认值 | 描述 |
|---|---|---|---|
children | ReactNode | - | 显示/隐藏的内容 |
className | string | - | 附加 CSS 类 |
render | DOMRenderFunction<keyof React.JSX.IntrinsicElements, DisclosureContentRenderProps> | - | 使用自定义 render 函数覆盖默认 DOM 元素 |
Render Props
使用 render prop 模式时,提供以下值:
| Prop | 类型 | 描述 |
|---|---|---|
isExpanded | boolean | 当前展开状态 |
isDisabled | boolean | 是否禁用 |
相关案例
See upstream Disclosure showcases. Product showcases are not part of the local component runtime.