mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-13 22:54:42 -04:00
fix: Move content into to frontend directory
Doing this BEFORE the merge prevents a lot of merge conflicts. Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
4e18ce38f3
commit
762a0a850e
1051 changed files with 0 additions and 35 deletions
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import React, { useCallback, useMemo } 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 { Logger } from '../../../../utils/logger'
|
||||
import { isClientSideRendering } from '../../../../utils/is-client-side-rendering'
|
||||
import { CopyToClipboardButton } from '../copy-to-clipboard-button/copy-to-clipboard-button'
|
||||
|
||||
export interface CopyableFieldProps {
|
||||
content: string
|
||||
shareOriginUrl?: string
|
||||
}
|
||||
|
||||
const log = new Logger('CopyableField')
|
||||
|
||||
/**
|
||||
* Provides an input field with an attached copy button and a share button (if supported by the browser).
|
||||
*
|
||||
* @param content The content to present
|
||||
* @param shareOriginUrl The URL of the page to which the shared content should be linked. If this value is omitted then the share button won't be shown.
|
||||
*/
|
||||
export const CopyableField: React.FC<CopyableFieldProps> = ({ content, shareOriginUrl }) => {
|
||||
useTranslation()
|
||||
|
||||
const sharingSupported = useMemo(
|
||||
() => shareOriginUrl !== undefined && isClientSideRendering() && typeof navigator.share === 'function',
|
||||
[shareOriginUrl]
|
||||
)
|
||||
|
||||
const doShareAction = useCallback(() => {
|
||||
if (!sharingSupported) {
|
||||
log.error('Native sharing not available')
|
||||
return
|
||||
}
|
||||
navigator
|
||||
.share({
|
||||
text: content,
|
||||
url: shareOriginUrl
|
||||
})
|
||||
.catch((error: Error) => {
|
||||
log.error('Native sharing failed', error)
|
||||
})
|
||||
}, [content, shareOriginUrl, sharingSupported])
|
||||
|
||||
return (
|
||||
<InputGroup className='my-3'>
|
||||
<FormControl readOnly={true} className={'text-center'} value={content} />
|
||||
<InputGroup.Text>
|
||||
<CopyToClipboardButton variant={'outline-secondary'} content={content} />
|
||||
</InputGroup.Text>
|
||||
<ShowIf condition={sharingSupported}>
|
||||
<InputGroup.Text>
|
||||
<Button variant='secondary' title={'Share'} onClick={doShareAction}>
|
||||
<ForkAwesomeIcon icon='share-alt' />
|
||||
</Button>
|
||||
</InputGroup.Text>
|
||||
</ShowIf>
|
||||
</InputGroup>
|
||||
)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue