View event availabilities
This commit is contained in:
parent
cdea567bf3
commit
1a6d34ac59
17 changed files with 483 additions and 68 deletions
7
frontend/src/components/Copyable/Copyable.module.scss
Normal file
7
frontend/src/components/Copyable/Copyable.module.scss
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
.copyable {
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
color: var(--secondary);
|
||||
}
|
||||
}
|
||||
33
frontend/src/components/Copyable/Copyable.tsx
Normal file
33
frontend/src/components/Copyable/Copyable.tsx
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
'use client'
|
||||
|
||||
import { useState } from 'react'
|
||||
|
||||
import { useTranslation } from '/src/i18n/client'
|
||||
import { makeClass } from '/src/utils'
|
||||
|
||||
import styles from './Copyable.module.scss'
|
||||
|
||||
interface CopyableProps extends Omit<React.ComponentProps<'p'>, 'children'> {
|
||||
children: string
|
||||
}
|
||||
|
||||
const Copyable = ({ children, className, ...props }: CopyableProps) => {
|
||||
const { t } = useTranslation('event')
|
||||
|
||||
const [copied, setCopied] = useState<React.ReactNode>()
|
||||
|
||||
return <p
|
||||
onClick={() => navigator.clipboard?.writeText(children)
|
||||
.then(() => {
|
||||
setCopied(t('nav.copied'))
|
||||
setTimeout(() => setCopied(undefined), 1000)
|
||||
})
|
||||
.catch(e => console.error('Failed to copy', e))
|
||||
}
|
||||
title={navigator.clipboard ? t<string>('nav.title') : undefined}
|
||||
className={makeClass(className, 'clipboard' in navigator && styles.copyable)}
|
||||
{...props}
|
||||
>{copied ?? children}</p>
|
||||
}
|
||||
|
||||
export default Copyable
|
||||
Loading…
Add table
Add a link
Reference in a new issue