2022-02-08 20:49:19 +01:00
|
|
|
import { useTranslation } from 'next-i18next'
|
|
|
|
|
2022-01-25 11:22:09 +01:00
|
|
|
const TextOnPath = (props) => {
|
2022-02-08 20:49:19 +01:00
|
|
|
const { t } = useTranslation(['app'])
|
2022-01-25 11:22:09 +01:00
|
|
|
const text = []
|
2022-01-28 13:39:07 +01:00
|
|
|
// Handle translation (and spaces)
|
2022-01-25 11:22:09 +01:00
|
|
|
let translated = ''
|
|
|
|
for (let string of props.path.attributes.getAsArray('data-text')) {
|
2022-02-08 20:49:19 +01:00
|
|
|
translated += t(string).replace(/"/g, '"') + ' '
|
2022-01-25 11:22:09 +01:00
|
|
|
}
|
|
|
|
const textPathProps = {
|
|
|
|
xlinkHref: '#' + props.pathId,
|
|
|
|
startOffset: '0%'
|
|
|
|
}
|
|
|
|
const align = props.path.attributes.get('data-text-class')
|
|
|
|
if (align && align.indexOf('center') > -1) textPathProps.startOffset = '50%'
|
|
|
|
else if (align && align.indexOf('right') > -1) textPathProps.startOffset = '100%'
|
|
|
|
|
|
|
|
return (
|
|
|
|
<text>
|
|
|
|
<textPath {...textPathProps}>
|
2022-01-28 13:39:07 +01:00
|
|
|
<tspan
|
|
|
|
{...props.path.attributes.asPropsIfPrefixIs('data-text-')}
|
|
|
|
dangerouslySetInnerHTML={{__html: translated}}
|
|
|
|
/>
|
2022-01-25 11:22:09 +01:00
|
|
|
</textPath>
|
|
|
|
</text>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default TextOnPath
|