-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Faithlife social share to share links to faithlife, email, facebook and twitter #50
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
112f04d
Add Faithlife social share to share links to faithlife, email, facebo…
AuresaNyctea 8789dfd
Use clipboard.js
AuresaNyctea 7c8af36
add input default and rename share-dialog
AuresaNyctea c8cf13c
Move clipboard and use class fields
AuresaNyctea b44051b
Add size options to input to match button
AuresaNyctea 79746cc
Remove unused style properties.
AuresaNyctea 5c1c311
Add documentation page for Share Dialog component
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,7 @@ | ||
This documentation is automatically generated from jsdoc comments. | ||
|
||
```react | ||
noSource: true | ||
--- | ||
<DocgenTable component={Modal} /> | ||
``` |
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,16 @@ | ||
## Share Dialog with default footer | ||
|
||
```react | ||
showSource: true | ||
state: { isOpen: false, shareUrl: 'https://examplecommunity.church/', message: 'Checkout our awesome church website' } | ||
--- | ||
<ModalDemo> | ||
<Button primary medium onClick={() => setState({ isOpen: true })}>Open a modal!</Button> | ||
<ShareDialog | ||
isOpen={state.isOpen} | ||
shareUrl={state.shareUrl} | ||
message={state.message} | ||
onClose={() => setState({ isOpen: false })} | ||
/> | ||
</ModalDemo> | ||
``` |
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,72 @@ | ||
import React, { PureComponent } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { applyVariations } from '../utils'; | ||
import * as Styled from './styled.jsx'; | ||
|
||
export class Input extends PureComponent { | ||
static propTypes = { | ||
value: PropTypes.string, | ||
placeholder: PropTypes.string, | ||
type: PropTypes.string, | ||
readOnly: PropTypes.bool, | ||
autoFocus: PropTypes.bool, | ||
disabled: PropTypes.bool, | ||
onChange: PropTypes.func, | ||
onClick: PropTypes.func, | ||
onEnter: PropTypes.func, | ||
/** Medium variation */ | ||
medium: PropTypes.bool, | ||
/** Small variation */ | ||
small: PropTypes.bool, | ||
/** Large variation */ | ||
large: PropTypes.bool, | ||
}; | ||
|
||
handleChange = () => { | ||
const { onChange } = this.props; | ||
if (onChange) { | ||
onChange(); | ||
} | ||
}; | ||
|
||
handleKeyPress = e => { | ||
const { onEnter } = this.props; | ||
if (onEnter && e.key === 'Enter') { | ||
onEnter(); | ||
} | ||
}; | ||
|
||
render() { | ||
const { | ||
value, | ||
placeholder, | ||
readOnly, | ||
type, | ||
autoFocus, | ||
onClick, | ||
disabled, | ||
...inputProps | ||
} = this.props; | ||
|
||
const { component: MappedStyledComponent, filteredProps } = applyVariations( | ||
Styled.Input, // this is required but we don't want it in the generated docs so don't include it above | ||
Styled.variationMap, | ||
inputProps, | ||
); | ||
|
||
return ( | ||
<MappedStyledComponent | ||
type={type || 'text'} | ||
autoFocus={autoFocus} | ||
readOnly={readOnly} | ||
disabled={disabled} | ||
value={value || ''} | ||
placeholder={placeholder || ''} | ||
onChange={this.handleChange} | ||
onClick={onClick} | ||
onKeyPress={this.handleKeyPress} | ||
{...filteredProps || {}} | ||
/> | ||
); | ||
} | ||
} |
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,40 @@ | ||
import styled from 'styled-components'; | ||
import { thickness, fonts, inputColors, colors } from '../shared-styles'; | ||
import { resetStyles } from '../utils'; | ||
|
||
export const Input = styled.input` | ||
${resetStyles}; | ||
|
||
${fonts.ui16}; | ||
border-radius: 3px; | ||
border: 1px solid ${inputColors.inputBorderColor}; | ||
padding: ${thickness.eight} 0 ${thickness.eight} ${thickness.eight}; | ||
|
||
&:focus { | ||
border-color: ${inputColors.inputFocusedBorderColor}; | ||
box-shadow: 0 0 0 2px ${inputColors.inputFocusedShadowColor}; | ||
outline: 0; | ||
} | ||
|
||
&:disabled { | ||
opacity: 0.5; | ||
} | ||
|
||
&:read-only { | ||
background: ${colors.gray22}; | ||
} | ||
`; | ||
|
||
export const variationMap = { | ||
small: component => component.extend` | ||
${fonts.ui14}; | ||
padding: 6px 0 6px ${thickness.eight}; | ||
`, | ||
medium: component => component.extend` | ||
${fonts.ui16}; | ||
`, | ||
large: component => component.extend` | ||
padding: 13px 0 11px 12px; | ||
${fonts.ui16}; | ||
`, | ||
}; |
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,49 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Modal } from '../modal/modal.jsx'; | ||
import { | ||
FaithlifeShareButton, | ||
TwitterShareButton, | ||
FacebookShareButton, | ||
EmailShareButton, | ||
} from './social-share-buttons.jsx'; | ||
import { CopyToClipboard } from './copy-to-clipboard.jsx'; | ||
import * as Styled from './styled.jsx'; | ||
|
||
/** | ||
* ShareDialog | ||
*/ | ||
export class ShareDialog extends React.Component { | ||
static propTypes = { | ||
shareUrl: PropTypes.string.isRequired, | ||
onClose: PropTypes.func.isRequired, | ||
message: PropTypes.string, | ||
isOpen: PropTypes.bool, | ||
modalTitle: PropTypes.string, | ||
copyButtonText: PropTypes.string, | ||
}; | ||
|
||
render() { | ||
const { shareUrl, message, onClose, isOpen, modalTitle, copyButtonText } = this.props; | ||
|
||
const encodedShareUrl = encodeURIComponent(shareUrl); | ||
const encodedMessage = message ? encodeURIComponent(message) : ''; | ||
|
||
return ( | ||
<Modal | ||
withoutFooter | ||
isOpen={isOpen} | ||
onClose={onClose} | ||
title={modalTitle || 'Share this page'} | ||
> | ||
<Styled.ShareContainer> | ||
<FaithlifeShareButton encodedShareUrl={encodedShareUrl} encodedMessage={encodedMessage} /> | ||
<TwitterShareButton encodedShareUrl={encodedShareUrl} encodedMessage={encodedMessage} /> | ||
<FacebookShareButton encodedShareUrl={encodedShareUrl} /> | ||
<EmailShareButton encodedShareUrl={encodedShareUrl} encodedMessage={encodedMessage} /> | ||
<CopyToClipboard copyValue={shareUrl} copyButtonText={copyButtonText} /> | ||
</Styled.ShareContainer> | ||
</Modal> | ||
); | ||
} | ||
} |
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,66 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import Clipboard from 'clipboard'; | ||
import debounce from 'lodash.debounce'; | ||
import { Button } from '../button/component.jsx'; | ||
import { Input } from '../input/component.jsx'; | ||
import * as Styled from './styled.jsx'; | ||
|
||
export class CopyToClipboard extends React.Component { | ||
static propTypes = { | ||
copyValue: PropTypes.string.isRequired, | ||
copyButtonText: PropTypes.string, | ||
hideInput: PropTypes.bool, | ||
}; | ||
|
||
button = React.createRef(); | ||
state = { | ||
showFeedback: false, | ||
}; | ||
|
||
componentDidMount() { | ||
const button = this.button.current; | ||
|
||
this.clipboard = new Clipboard(button); | ||
|
||
this.clipboard.on('success', () => { | ||
this.showFeedback(); | ||
}); | ||
} | ||
|
||
componentWillUnmount() { | ||
this.clipboard.destroy(); | ||
} | ||
|
||
showFeedback = () => { | ||
this.setState({ showFeedback: true }); | ||
this.hideFeedback(); | ||
}; | ||
|
||
hideFeedback = debounce(() => { | ||
this.setState({ showFeedback: false }); | ||
}, 2000); | ||
|
||
selectSelf = e => e.target.select(); | ||
|
||
render() { | ||
const { copyValue, copyButtonText, hideInput } = this.props; | ||
const { showFeedback } = this.state; | ||
|
||
return ( | ||
<Styled.ShareContainer> | ||
{!hideInput && ( | ||
<Styled.CopyContainer> | ||
<Input small type="text" readOnly value={copyValue} onClick={this.selectSelf} /> | ||
</Styled.CopyContainer> | ||
)} | ||
<div> | ||
<Button small ref={this.button} data-clipboard-text={copyValue} primary> | ||
{copyButtonText || 'Copy'} | ||
</Button> | ||
{showFeedback && <Styled.Copied>Copied!</Styled.Copied>} | ||
</div> | ||
</Styled.ShareContainer> | ||
); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This instance needs to be cleaned up in
componentWillUnmount
: