mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-14 23:24:46 -04:00
Enhance share dialog (#860)
This commit is contained in:
parent
1c6e6e10fb
commit
721c8c0e5a
10 changed files with 120 additions and 25 deletions
|
@ -4,31 +4,52 @@ SPDX-FileCopyrightText: 2020 The HedgeDoc developers (see AUTHORS file)
|
|||
SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import React, { Fragment, useRef } from 'react'
|
||||
import React, { Fragment, useCallback, useRef } from 'react'
|
||||
import { Button, FormControl, InputGroup } from 'react-bootstrap'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { ForkAwesomeIcon } from '../../fork-awesome/fork-awesome-icon'
|
||||
import { ShowIf } from '../../show-if/show-if'
|
||||
import { CopyOverlay } from '../copy-overlay'
|
||||
|
||||
export interface CopyableFieldProps {
|
||||
content: string
|
||||
nativeShareButton?: boolean
|
||||
url?: string
|
||||
}
|
||||
|
||||
export const CopyableField: React.FC<CopyableFieldProps> = ({ content }) => {
|
||||
export const CopyableField: React.FC<CopyableFieldProps> = ({ content, nativeShareButton, url }) => {
|
||||
useTranslation()
|
||||
const button = useRef<HTMLButtonElement>(null)
|
||||
const copyButton = useRef<HTMLButtonElement>(null)
|
||||
|
||||
const doShareAction = useCallback(() => {
|
||||
navigator.share({
|
||||
text: content,
|
||||
url: url
|
||||
}).catch(err => {
|
||||
console.error('Native sharing failed: ', err)
|
||||
})
|
||||
}, [content, url])
|
||||
|
||||
const sharingSupported = typeof navigator.share === 'function'
|
||||
|
||||
return (
|
||||
<Fragment>
|
||||
<InputGroup className="my-3">
|
||||
<FormControl readOnly={true} className={'text-center'} value={content} />
|
||||
<InputGroup.Append>
|
||||
<Button variant="outline-secondary" ref={button} title={'Copy'}>
|
||||
<Button variant="outline-secondary" ref={copyButton} title={'Copy'}>
|
||||
<ForkAwesomeIcon icon='files-o'/>
|
||||
</Button>
|
||||
</InputGroup.Append>
|
||||
<ShowIf condition={!!nativeShareButton && sharingSupported}>
|
||||
<InputGroup.Append>
|
||||
<Button variant="outline-secondary" title={'Share'} onClick={doShareAction}>
|
||||
<ForkAwesomeIcon icon='share-alt'/>
|
||||
</Button>
|
||||
</InputGroup.Append>
|
||||
</ShowIf>
|
||||
</InputGroup>
|
||||
<CopyOverlay content={content} clickComponent={button}/>
|
||||
<CopyOverlay content={content} clickComponent={copyButton}/>
|
||||
</Fragment>
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue