react-use#useCopyToClipboard TypeScript Examples
The following examples show how to use
react-use#useCopyToClipboard.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Input.Copy.tsx From design-system with Apache License 2.0 | 6 votes |
InputCopy = React.forwardRef(
({ label, disabled, readOnly, ...rest }: InputProps, ref: React.Ref<HTMLInputElement | null>) => {
const [state, copyToClipboard] = useCopyToClipboard();
const inputRef = React.useRef<HTMLInputElement | null>(null);
React.useImperativeHandle(ref, () => inputRef.current);
return (
<FieldGroup
label={label}
suffix={
!readOnly && (
<Button.Icon
icon="talend-files-o"
onClick={() => copyToClipboard(inputRef.current?.value || '')}
disabled={disabled}
>
Copy to clipboard
</Button.Icon>
)
}
readOnly={!disabled}
disabled={!!disabled}
hasError={!!state.error}
hasSuccess={!!state.value}
description={state.error ? state.error.message : state.value && 'Copied to clipboard'}
>
{/*
// @ts-ignore */}
<Text {...rest} label="Copy to clipboard" ref={inputRef} />
</FieldGroup>
);
},
)