316f2ec38c
as discussed here https://github.com/twentyhq/twenty/issues/13292#issuecomment-3092215050 with @prastoin - [x] introduce optional message param to `copyToClipboard` method in `useCopyToClipboard` and refactor it across app, as in case if user has disallowed clipboard permission in BROWSER unprotected clipboard access breaks without catch. - [x] Email copied to clipboard - [x] run lingui extract
57 lines
1.5 KiB
TypeScript
57 lines
1.5 KiB
TypeScript
import styled from '@emotion/styled';
|
|
import { OverflowingTextWithTooltip } from 'twenty-ui/display';
|
|
import { useDebouncedCallback } from 'use-debounce';
|
|
import { useCopyToClipboard } from '~/hooks/useCopyToClipboard';
|
|
|
|
type SettingsAdminConfigCopyableTextProps = {
|
|
text: string;
|
|
displayText?: React.ReactNode;
|
|
multiline?: boolean;
|
|
maxRows?: number;
|
|
};
|
|
|
|
const StyledEllipsisLabel = styled.div`
|
|
white-space: nowrap;
|
|
text-overflow: ellipsis;
|
|
overflow: hidden;
|
|
`;
|
|
|
|
const StyledExpandedEllipsisLabel = styled.div`
|
|
white-space: normal;
|
|
word-break: break-all;
|
|
`;
|
|
|
|
const StyledCopyContainer = styled.span`
|
|
cursor: pointer;
|
|
`;
|
|
export const SettingsAdminConfigCopyableText = ({
|
|
text,
|
|
displayText,
|
|
multiline = false,
|
|
maxRows,
|
|
}: SettingsAdminConfigCopyableTextProps) => {
|
|
const { copyToClipboard } = useCopyToClipboard();
|
|
|
|
const copyToClipboardDebounced = useDebouncedCallback((value: string) => {
|
|
copyToClipboard(value);
|
|
}, 200);
|
|
|
|
return (
|
|
<StyledCopyContainer onClick={() => copyToClipboardDebounced(text)}>
|
|
{maxRows ? (
|
|
<OverflowingTextWithTooltip
|
|
text={displayText?.toString() || text}
|
|
displayedMaxRows={maxRows}
|
|
isTooltipMultiline={multiline}
|
|
/>
|
|
) : multiline ? (
|
|
<StyledExpandedEllipsisLabel>
|
|
{displayText || text}
|
|
</StyledExpandedEllipsisLabel>
|
|
) : (
|
|
<StyledEllipsisLabel>{displayText || text}</StyledEllipsisLabel>
|
|
)}
|
|
</StyledCopyContainer>
|
|
);
|
|
};
|