All files / src/presentation/components CopyNickButton.tsx

100% Statements 6/6
100% Branches 6/6
100% Functions 4/4
100% Lines 3/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25                      4x 8x   6x                    
import { type Nick } from '../../domain/model/Nick';
import { Button, CopyButton, Group, Text } from '@mantine/core';
import { IconCheck, IconCopy } from '@tabler/icons-react';
 
 
interface Props {
  nick: Nick;
  onClick?: () => void
}
 
export function CopyNickButton({ nick, onClick }: Props) {
  return (
    <CopyButton value={nick.words.map(w => w.label).join(' ')} timeout={2000}>
      {({ copied, copy }) => (
          <Button fullWidth variant="subtle" onClick={() => {copy(); if(onClick) onClick();}}>
            <Group gap="xs">
            {copied ? <IconCheck size={16} /> : <IconCopy size={16} />} 
            { copied ? <Text>CopiƩ</Text> : <Text>Copier</Text> }
            </Group>
          </Button>
      )}
    </CopyButton>
  );
}