Skip to content

Commit 8d0ee9d

Browse files
committed
copy truncated text
1 parent 5b80978 commit 8d0ee9d

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

packages/clerk-js/src/ui/elements/LineItems.tsx

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,7 @@ function Description({ text, prefix, suffix, truncateText = false, copyText = fa
178178
/>
179179
) : null}
180180
{typeof text === 'string' && truncateText ? (
181-
<Span
182-
elementDescriptor={descriptors.lineItemsDescriptionText}
183-
sx={t => ({
184-
...common.textVariants(t).body,
185-
display: 'flex',
186-
minWidth: '0',
187-
})}
188-
>
189-
{truncateWithEndVisible(text)}
190-
</Span>
181+
<TruncatedText text={text} />
191182
) : (
192183
<Span
193184
localizationKey={text}
@@ -223,6 +214,26 @@ function Description({ text, prefix, suffix, truncateText = false, copyText = fa
223214
);
224215
}
225216

217+
function TruncatedText({ text }: { text: string }) {
218+
const { onCopy } = useClipboard(text);
219+
return (
220+
<Span
221+
elementDescriptor={descriptors.lineItemsDescriptionText}
222+
sx={t => ({
223+
...common.textVariants(t).body,
224+
display: 'flex',
225+
minWidth: '0',
226+
})}
227+
onCopy={async e => {
228+
e.preventDefault();
229+
await onCopy();
230+
}}
231+
>
232+
{truncateWithEndVisible(text)}
233+
</Span>
234+
);
235+
}
236+
226237
function CopyButton({ text, copyLabel = 'Copy' }: { text: string; copyLabel?: string }) {
227238
const { onCopy, hasCopied } = useClipboard(text);
228239

0 commit comments

Comments
 (0)