Skip to content

Commit 7079f13

Browse files
add a copy to clipboard button to PIX and contact info (#124)
* add a copy to clipboard button to PIX and contact info * use && operator instead of ternary
1 parent afa0e25 commit 7079f13

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

src/components/CardAboutShelter/CardAboutShelter.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,13 @@ const CardAboutShelter = (props: ICardAboutShelter) => {
6565
value={
6666
check(shelter.contact) ? `${shelter.contact}` : 'Não informado'
6767
}
68+
clipboardButton={check(shelter.contact)}
6869
/>
6970
<InfoRow
7071
icon={<Landmark />}
7172
label="Chave Pix:"
7273
value={check(shelter.pix) ? `${shelter.pix}` : 'Não informado'}
74+
clipboardButton={check(shelter.pix)}
7375
/>
7476
</div>
7577
</Card>

src/components/CardAboutShelter/components/InfoRow/InfoRow.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { IInfoRowProps } from './types';
44

55
const InfoRow = React.forwardRef<HTMLDivElement, IInfoRowProps>(
66
(props, ref) => {
7-
const { icon, label, value, className = '', ...rest } = props;
7+
const { icon, label, value, clipboardButton = false, className = '', ...rest } = props;
88
const isLink = value?.startsWith('http');
99
const ValueComp = !value ? (
1010
<Fragment />
@@ -35,7 +35,18 @@ const InfoRow = React.forwardRef<HTMLDivElement, IInfoRowProps>(
3535
<span className={cn('font-normal', value ? 'text-nowrap' : '')}>
3636
{label}
3737
</span>
38-
<span className="md:flex">{ValueComp}</span>
38+
<span className="md:flex">
39+
{ValueComp}
40+
{clipboardButton && (
41+
<div
42+
className="text-blue-600 mx-2 hover:cursor-pointer active:text-blue-800"
43+
onClick={() => navigator.clipboard.writeText(value)}
44+
>
45+
copiar
46+
</div>
47+
)}
48+
</span>
49+
3950
</div>
4051
</div>
4152
);

src/components/CardAboutShelter/components/InfoRow/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ export interface IInfoRowProps extends React.ComponentPropsWithoutRef<'div'> {
22
label: React.ReactNode;
33
value?: string;
44
icon: React.ReactNode;
5+
clipboardButton?: boolean;
56
}

0 commit comments

Comments
 (0)