From 6d45c31f98e72f2019d36aedca9ea905753335c5 Mon Sep 17 00:00:00 2001 From: Tal Leibman Date: Mon, 9 Sep 2019 09:59:12 +0300 Subject: [PATCH] Contacts: Add a button to copy fields to clipboard Fixes #39 --- src/components/Contact.tsx | 42 ++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/src/components/Contact.tsx b/src/components/Contact.tsx index b3399f4..b133655 100644 --- a/src/components/Contact.tsx +++ b/src/components/Contact.tsx @@ -7,10 +7,12 @@ import IconDate from '@material-ui/icons/DateRange'; import CommunicationCall from '@material-ui/icons/Call'; import CommunicationChatBubble from '@material-ui/icons/ChatBubble'; import CommunicationEmail from '@material-ui/icons/Email'; +import AssignmentIcon from '@material-ui/icons/Assignment'; import PimItemHeader from './PimItemHeader'; import { ContactType } from '../pim-types'; +import { IconButton } from '@material-ui/core'; class Contact extends React.PureComponent { public props: { @@ -40,15 +42,30 @@ class Contact extends React.PureComponent { return contact.comp.getAllProperties(propName).map((prop, idx) => { const type = prop.toJSON()[1].type; - const values = prop.getValues().map((val) => ( - - )); + const values = prop.getValues().map((val) => { + const primaryText = primaryTransform ? primaryTransform(val, type) : val; + const clipboardButton = ( + { + e.preventDefault(); + (window as any).navigator.clipboard.writeText(primaryText); + }} + > + + + ); + + return ( + + ); + }); return values; }); } @@ -57,7 +74,6 @@ class Contact extends React.PureComponent { 'tel', { leftIcon: , - rightIcon: , }, (x) => ('tel:' + x) )); @@ -111,7 +127,7 @@ class Contact extends React.PureComponent { 'prodid', 'uid', 'fn', 'n', 'version', 'photo']; const theRest = contact.comp.getAllProperties().filter((prop) => ( skips.indexOf(prop.name) === -1 - )).map((prop, idx) => { + )).map((prop, idx) => { const values = prop.getValues().map((_val) => { const val = (_val instanceof String) ? _val : _val.toString(); return ( @@ -147,14 +163,14 @@ class Contact extends React.PureComponent {
{lastModified && ( - {lastModified} + {lastModified} )} {lists.map((list, idx) => ( {listIfNotEmpty(list)} - ))} + ))} {theRest}