Clipboard

A component that allows users to copy text to their clipboard with visual feedback and customizable indicators.

import { Clipboard } from '@cerberus/react'

Usage

The Clipboard component provides an accessible way to copy text to the user's clipboard with built-in visual feedback. It is unstyled by default, allowing for full customization.

Hello, World!

Custom Variations

You can create custom variations of the Clipboard component by composing it with other components or by using inline style props.

Button

Copy Text

Copy Email

Primitives

You can utilize the primitive components or the css prop to customize the clipboard component.

ComponentDescription
ClipboardRootThe root context provider for the clipboard family.
ClipboardLabelA label element for accessibility.
ClipboardControlThe wrapper for input and trigger elements.
ClipboardInputThe input element containing the text to copy.
ClipboardTriggerThe button that triggers the copy action.
ClipboardIndicatorShows the current state (copy/copied) with icons.
CopyTextShows the current state (copy/copied) with text.

Data Attributes

The Clipboard component exposes several data attributes for better accessibility and customization.

NameValueDescription
data-scopeclipboardThe scope of the components.
data-partrootThe root container part.
data-partlabelThe label part.
data-partcontrolThe control part.
data-partinputThe input part.
data-parttriggerThe trigger part.
data-partindicatorThe indicator part.

API

Root

The Clipboard.Root is an abstraction of the Root component.

Indicator

The indicator accepts the following props:

NameDefaultDescription
size16The size of the indicator (in pixels). Can be 16, 20, 24, or 32.

Parts

The Clipboard API is an Object containing the full family of components.

NameDescription
RootThe ClipboardRoot component which is the Provider for the family.
LabelThe ClipboardLabel component for accessibility.
ControlThe ClipboardControl component wrapper.
InputThe ClipboardInput component displaying the text.
TriggerThe ClipboardTrigger component button.
IndicatorThe CopyIndicator component with default copy/checkmark icons.
CopyTextThe CopyText component with default "Copy"/"Copied" text indicators.
ContextThe raw context for accessing clipboard state within the component hierarchy.