-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from user-interviews/feature/UIDS-27-copy-to-c…
…lipboard-component UIDS-27 Add CopyToClipboard and TrackedButton components
- Loading branch information
Showing
15 changed files
with
396 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
$ux-border-radius: 0.25rem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
@import './palette'; | ||
|
||
.btn-link--neutral { | ||
color: $ux-gray-500; | ||
|
||
&:hover { | ||
color: $ux-gray-700; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
@import './box_shadow'; | ||
@import './buttons'; | ||
@import './lists'; | ||
@import './navbar'; | ||
@import './palette'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React, { useState } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
import { faCopy } from '@fortawesome/free-regular-svg-icons'; | ||
import { CopyToClipboard as ReactCopyToClipboard } from 'react-copy-to-clipboard'; | ||
|
||
import Popper from '../Popper/Popper'; | ||
import TrackedButton from '../TrackedButton/TrackedButton'; | ||
|
||
import './CopyToClipboard.scss'; | ||
|
||
function CopyToClipboard(props) { | ||
const [copied, setCopied] = useState(false); | ||
|
||
const handleClickCopy = () => { | ||
setCopied(true); | ||
setTimeout(() => setCopied(false), 1000); | ||
}; | ||
|
||
return ( | ||
<div className="CopyToClipboard"> | ||
<span className="CopyToClipboard__copy-text">{props.copyText}</span> | ||
<ReactCopyToClipboard text={props.copyText} onCopy={handleClickCopy}> | ||
<TrackedButton | ||
className="btn btn-link btn-link--neutral" | ||
event={props.trackingEvent} | ||
type="button" | ||
> | ||
<Popper | ||
dark | ||
text="Copied!" | ||
visible={copied} | ||
> | ||
<FontAwesomeIcon icon={faCopy} /> | ||
</Popper> | ||
</TrackedButton> | ||
</ReactCopyToClipboard> | ||
</div> | ||
); | ||
} | ||
|
||
CopyToClipboard.propTypes = { | ||
copyText: PropTypes.string, | ||
trackingEvent: PropTypes.string.isRequired, | ||
}; | ||
|
||
CopyToClipboard.defaultProps = { | ||
copyText: '', | ||
}; | ||
|
||
export default CopyToClipboard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
@import '../../scss/theme'; | ||
|
||
.CopyToClipboard { | ||
align-items: center; | ||
border: 1px solid $ux-gray-400; | ||
border-radius: .25rem; | ||
color: $ux-gray-800; | ||
display: flex; | ||
font-weight: $font-weight-bold; | ||
justify-content: space-between; | ||
min-height: 2rem; | ||
padding: 0 0 0 .375rem; | ||
|
||
&__copy-text { | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
white-space: nowrap; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import classNames from 'classnames'; | ||
import { Manager, Popper as ReactPopper, Reference } from 'react-popper'; | ||
|
||
import './Popper.scss'; | ||
|
||
function Popper(props) { | ||
return ( | ||
<Manager> | ||
<Reference> | ||
{({ ref }) => <div ref={ref}>{props.children}</div>} | ||
</Reference> | ||
{ | ||
props.visible && ( | ||
<ReactPopper placement={props.placement}> | ||
{ | ||
({ placement, ref, style }) => ( | ||
<div | ||
className={classNames('Popper', { 'Popper--dark': props.dark })} | ||
data-placement={placement} | ||
ref={ref} | ||
style={style} | ||
> | ||
{props.text} | ||
</div> | ||
) | ||
} | ||
</ReactPopper> | ||
) | ||
} | ||
</Manager> | ||
); | ||
} | ||
|
||
Popper.propTypes = { | ||
dark: PropTypes.bool, | ||
placement: PropTypes.string, | ||
text: PropTypes.string.isRequired, | ||
visible: PropTypes.bool, | ||
}; | ||
|
||
Popper.defaultProps = { | ||
dark: false, | ||
placement: 'top', | ||
visible: false, | ||
}; | ||
|
||
export default Popper; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
@import '../../scss/borders'; | ||
@import '../../scss/box_shadow'; | ||
@import '../../scss/palette'; | ||
@import '../../scss/typography'; | ||
|
||
.Popper { | ||
background-color: $ux-white; | ||
border-radius: $ux-border-radius; | ||
border: 1px solid $ux-gray-300; | ||
box-shadow: $ux-box-shadow-card; | ||
max-width: 15rem; | ||
padding: .25rem .5rem; | ||
|
||
&--dark { | ||
background-color: $ux-gray-800; | ||
color: $ux-gray-100; | ||
font-weight: $font-weight-bold; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import withTrackedClick from '../hoc/withTrackedClick'; | ||
|
||
export default withTrackedClick('button'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import track from 'react-tracking'; | ||
|
||
export default function withTrackedClick(Target) { | ||
const TrackedComponent = (props) => { | ||
TrackedComponent.displayName = `${Target.displayName || Target.name}WithTrackedClick`; | ||
|
||
const { eventData, event, ...rest } = props; | ||
|
||
function handleClick(clickEvent) { | ||
props.tracking.trackEvent({ ...eventData, event }); | ||
|
||
if (props.onClick) { | ||
props.onClick(clickEvent); | ||
} | ||
} | ||
|
||
return <Target {...rest} onClick={handleClick} />; | ||
}; | ||
|
||
TrackedComponent.propTypes = { | ||
event: PropTypes.string.isRequired, | ||
eventData: PropTypes.object, | ||
tracking: PropTypes.shape({ | ||
getTrackingData: PropTypes.func, | ||
trackEvent: PropTypes.func, | ||
}).isRequired, | ||
onClick: PropTypes.func, | ||
}; | ||
|
||
TrackedComponent.defaultProps = { | ||
eventData: {}, | ||
onClick: undefined, | ||
}; | ||
|
||
return track()(TrackedComponent); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.