2021-12-24 17:13:48 +01:00
|
|
|
import React from 'react'
|
2022-05-24 18:55:10 +02:00
|
|
|
import { useTranslation } from 'next-i18next'
|
2021-12-24 17:13:48 +01:00
|
|
|
|
|
|
|
const TextOnPath = (props) => {
|
2022-05-24 18:55:10 +02:00
|
|
|
const { t } = useTranslation(['plugin'])
|
2021-12-24 17:13:48 +01:00
|
|
|
// Handle translation
|
|
|
|
let translated = ''
|
|
|
|
for (let string of props.path.attributes.getAsArray('data-text')) {
|
2022-05-24 18:55:10 +02:00
|
|
|
translated += t(string)
|
2021-12-24 17:13:48 +01:00
|
|
|
translated += ' '
|
|
|
|
}
|
2022-05-24 18:55:10 +02:00
|
|
|
const textPathProps = {
|
2021-12-24 17:13:48 +01:00
|
|
|
xlinkHref: '#' + props.pathId,
|
|
|
|
startOffset: '0%'
|
|
|
|
}
|
2022-05-24 18:55:10 +02:00
|
|
|
const align = props.path.attributes.get('data-text-class')
|
2021-12-24 17:13:48 +01:00
|
|
|
if (align && align.indexOf('center') > -1) textPathProps.startOffset = '50%'
|
|
|
|
else if (align && align.indexOf('right') > -1) textPathProps.startOffset = '100%'
|
|
|
|
|
|
|
|
return (
|
|
|
|
<text>
|
|
|
|
<textPath {...textPathProps}>
|
|
|
|
<tspan {...props.path.attributes.asPropsIfPrefixIs('data-text-')}>{translated}</tspan>
|
|
|
|
</textPath>
|
|
|
|
</text>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default TextOnPath
|