Skip to Content
文档

剪贴板

用于将文本复制到剪贴板

SourceStorybookRecipeArk

用法

¥Usage

import { Clipboard } from "@chakra-ui/react"
<Clipboard.Root>
  <Clipboard.Trigger>
    <Clipboard.CopyText />
    <Clipboard.Indicator />
  </Clipboard.Trigger>
  <Clipboard.Input />
</Clipboard.Root>

示例

¥Examples

按钮

¥Button

使用 Clipboard.Trigger 组件创建复制按钮。

¥Use the Clipboard.Trigger component to create a copy button.

输入框

¥Input

使用 Clipboard.Input 组件创建复制输入框。

¥Use the Clipboard.Input component to create a copy input.

超时

¥Timeout

使用 timeout 属性更改复制消息的持续时间。

¥Use the timeout prop to change the duration of the copy message.

链接外观

¥Link Appearance

以下是组合 Clipboard.TriggerClipboard.ValueText 组件以创建链接外观的示例。

¥Here's an example that combines the Clipboard.Trigger and Clipboard.ValueText components to create a link appearance.

https://chakra-ui.com

商店

¥Store

或者,你可以使用 useClipboard 钩子创建自定义组件。

¥Alternatively, you can use the useClipboard hook to create a custom component.

属性

¥Props

根元素

¥Root

PropDefaultType
timeout '3000'
number

The timeout for the copy operation

asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior.

For more details, read our Composition guide.
defaultValue
string

The initial value to be copied to the clipboard when rendered. Use when you don't need to control the value of the clipboard.

id
string

The unique identifier of the machine.

ids
Partial<{ root: string; input: string; label: string }>

The ids of the elements in the clipboard. Useful for composition.

onStatusChange
(details: CopyStatusDetails) => void

The function to be called when the value is copied to the clipboard

onValueChange
(details: ValueChangeDetails) => void

The function to be called when the value changes

value
string

The controlled value of the clipboard

Previous

卡片

Next

图片