SearchCtrlK

  • ↑↓navigate
  • ↵open
  • escclose

Can’t find it? Contact us

copyFromUrl

Copies a document fetched from a URL onto the clipboard when its host button is pressed.

tsx
import { copyFromUrl } from "@sdxc/ui/docs";

Usage

Fetches href with Accept: text/markdown, text/plain on every press and writes the body to the clipboard, then dispatches a ui:copy CopyEvent. A failed fetch or write writes failedLabel into the button's [role="status"] element for four seconds.

Signature

typescript
copyFromUrl(href: string, failedLabel?: string): MixinDescriptor<HTMLButtonElement>

Returns a mixin descriptor for the copy button's mix prop.

Parameters

ParameterTypeRequiredDescription
hrefstringYesURL of the text to copy, such as the page's .md twin.
failedLabelstringNoWhat a screen reader announces when the copy fails.

Examples

tsx
<button type="button" mix={[copyFromUrl("/docs/install.md", t("copyFailed")), copyFeedback(t("copied"))]}>
	{t("copyPage")}
	<span role="status" mix={[visuallyHidden()]} />
</button>
@sdxc/ui

Can’t find it? Contact us